Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_prefix(word, length):
"""
Return the prefix for the given word,
of length length.
:param word: the word string
:type word: unicode
:param length: prefix length
:type length: int
:rtype: unicode
"""
if not word:
return None
word = toStr(word)
if "Z" < word[0] < "a":
return "SPECIAL"
return word[:length] ## return a unicode? FIXME
def rawDumpFileWriteText(self, text): # FIXME
text = toStr(text)
if self.rawDumpFile:
self.rawDumpFile.write(text)
def rawDumpFileWriteData(self, text):
text = toStr(text)
# the next function escapes too many chars, for example, it escapes äöü
# self.rawDumpFile.write(text.encode("unicode_escape"))
if self.rawDumpFile:
self.rawDumpFile.write(text)
def samplesDumpFileWrite(self, text):
text = toStr(text)
if self.samplesDumpFile:
offset = self.samplesDumpFile.tell()
self.samplesDumpFile.write("\noffset = {0:#X}\n" % offset)
self.samplesDumpFile.write(text+"\n")
else:
log.debug(text)
def msgLogFileWrite(self, text):
text = toStr(text)
if self.msgLogFile:
offset = self.msgLogFile.tell()
# print offset in the log file to facilitate navigating this
# log in hex editor
# intended usage:
# the log file is opened in a text editor and hex editor
# use text editor to read error messages, use hex editor to
# inspect char codes offsets allows to quickly jump to the right
# place of the file hex editor
self.msgLogFile.write("\noffset = {0:#X}\n" % offset)
self.msgLogFile.write(text+"\n")
else:
log.debug(text)
def processDefiStat(self, fields, b_defi, b_key):
if fields.singleEncoding:
self.findAndPrintCharSamples(
fields.b_defi,
"defi, key = %s" + b_key,
fields.encoding,
)
if self.metadata2:
self.metadata2.defiProcessedCount += 1
if isASCII(toStr(fields.b_defi)):
self.metadata2.defiAsciiCount += 1
try:
fields.b_defi.decode("utf8")
except UnicodeError:
pass
else:
self.metadata2.defiUtf8Count += 1
if self.metadata2 and self.metadata2.isDefiASCII:
if not isASCII(fields.u_defi):
self.metadata2.isDefiASCII = False