add bytes support to ascii/utf8
This commit is contained in:
parent
8e946afeac
commit
3f01e48a00
1 changed files with 6 additions and 2 deletions
|
@ -13,13 +13,17 @@ except NameError:
|
||||||
unicode = str
|
unicode = str
|
||||||
|
|
||||||
def ascii(s):
|
def ascii(s):
|
||||||
if isinstance(s, unicode):
|
if isinstance(s, bytes):
|
||||||
|
return s
|
||||||
|
elif isinstance(s, unicode):
|
||||||
return s.encode(u'ascii')
|
return s.encode(u'ascii')
|
||||||
else:
|
else:
|
||||||
return str(s)
|
return str(s)
|
||||||
|
|
||||||
def utf8(s):
|
def utf8(s):
|
||||||
if isinstance(s, unicode):
|
if isinstance(s, bytes):
|
||||||
|
return s
|
||||||
|
elif isinstance(s, unicode):
|
||||||
return s.encode(u'utf-8')
|
return s.encode(u'utf-8')
|
||||||
else:
|
else:
|
||||||
return str(s)
|
return str(s)
|
||||||
|
|
Loading…
Add table
Reference in a new issue