optimization of CPU intensive sanitizeAsciiString

This commit is contained in:
Miroslav Stampar 2010-05-14 13:55:25 +00:00
parent 5396f13bab
commit 7107e8fd6a

View File

@ -1027,10 +1027,19 @@ def safeStringFormat(formatStr, params):
return retVal
def sanitizeAsciiString(subject):
retVal = None
if subject:
retVal = "".join(char if ord(char) < 128 else '?' for char in subject)
index = None
for i in xrange(len(subject)):
if ord(subject[i]) >= 128:
index = i
break
if not index:
return subject
else:
retVal = subject[:index] + "".join(subject[i] if ord(subject[i]) < 128 else '?' for i in xrange(index, len(subject)))
return retVal
else:
return None
def decloakToNamedTemporaryFile(filepath, name=None):
retVal = NamedTemporaryFile()