minor refactoring

This commit is contained in:
Miroslav Stampar
2011-04-29 15:22:32 +00:00
parent a2bb0d72e8
commit 6bb4dce3aa
4 changed files with 24 additions and 24 deletions

View File

@@ -124,8 +124,24 @@ def urlencode(value, safe="%&=", convall=False, limit=False):
return result
def unicodeencode(value, encoding=None):
"""
Return 8-bit string representation of the supplied unicode value:
>>> unicodeencode(u'test')
'test'
"""
retVal = value
if isinstance(value, unicode):
try:
retVal = value.encode(encoding or UNICODE_ENCODING)
except UnicodeEncodeError:
retVal = value.encode(UNICODE_ENCODING, errors="replace")
return retVal
def utf8encode(value):
return value.encode("utf-8")
return unicodeencode(value, "utf-8")
def utf8decode(value):
return value.decode("utf-8")