minor refactoring

This commit is contained in:
Miroslav Stampar
2011-04-10 07:16:19 +00:00
parent c714ac6421
commit 723a7447b2
3 changed files with 21 additions and 20 deletions

View File

@@ -2510,21 +2510,3 @@ def isBinaryData(value):
if isinstance(value, basestring):
retVal = reduce(lambda x, y: x or not (y in string.printable or ord(y) > 255), value, False)
return retVal
def getSafeHexEncodedBinaryData(value):
"""
Returns safe representation of given basestring value
>>> getSafeEncodedBinaryData(u'test123')
u'test123'
>>> getSafeEncodedBinaryData(u'test\01\02\03')
u'test\\1\\2\\3'
"""
retVal = value
if isinstance(value, basestring):
retVal = reduce(lambda x, y: x + (y if (y in string.printable or ord(y) > 255) else '\%x' % ord(y)), value, unicode())
elif isinstance(value, list):
for i in xrange(len(value)):
retVal[i] = getSafeHexEncodedBinaryData(value[i])
return retVal