mirror of
https://github.com/soimort/you-get.git
synced 2025-02-02 16:24:00 +03:00
print Unicode strings on codepage where possible
This commit is contained in:
parent
82f2b8d411
commit
e5d040a208
@ -20,10 +20,11 @@ else:
|
||||
default_encoding = locale.getpreferredencoding().lower()
|
||||
|
||||
def tr(s):
|
||||
if default_encoding.startswith('utf') or default_encoding in ['cp936', '936', 'ms936', 'gbk']:
|
||||
try:
|
||||
s.encode(default_encoding)
|
||||
return s
|
||||
else:
|
||||
return s.encode('utf-8')
|
||||
except:
|
||||
return str(s.encode('utf-8'))[2:-1]
|
||||
|
||||
def r1(pattern, text):
|
||||
m = re.search(pattern, text)
|
||||
|
Loading…
Reference in New Issue
Block a user