MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / getUnicode

Function getUnicode

lib/core/convert.py:331–381  ·  view source on GitHub ↗

Returns the unicode representation of the supplied value >>> getUnicode('test') == u'test' True >>> getUnicode(1) == u'1' True >>> getUnicode(None) == 'None' True >>> getUnicode(b'/etc/passwd') == '/etc/passwd' True

(value, encoding=None, noneToNull=False)

Source from the content-addressed store, hash-verified

329 return [_ if isinstance(_, int) else ord(_) for _ in value]
330
331def getUnicode(value, encoding=None, noneToNull=False):
332 """
333 Returns the unicode representation of the supplied value
334
335 >>> getUnicode('test') == u'test'
336 True
337 >>> getUnicode(1) == u'1'
338 True
339 >>> getUnicode(None) == 'None'
340 True
341 >>> getUnicode(b'/etc/passwd') == '/etc/passwd'
342 True
343 """
344
345 # Best position for --time-limit mechanism
346 if conf.get("timeLimit") and kb.get("startTime") and (time.time() - kb.startTime > conf.timeLimit):
347 raise SystemExit
348
349 if noneToNull and value is None:
350 return NULL
351
352 if isinstance(value, six.text_type):
353 return value
354 elif isinstance(value, six.binary_type):
355 # Heuristics (if encoding not explicitly specified)
356 candidates = filterNone((encoding, kb.get("pageEncoding") if kb.get("originalPage") else None, conf.get("encoding"), UNICODE_ENCODING, sys.getfilesystemencoding()))
357 if all(_ in value for _ in (b'<', b'>')):
358 pass
359 elif b'\n' not in value and re.search(r"(?i)\w+\.\w{2,3}\Z|\A(\w:\\|/\w+)", six.text_type(value, UNICODE_ENCODING, errors="ignore")):
360 candidates = filterNone((encoding, sys.getfilesystemencoding(), kb.get("pageEncoding") if kb.get("originalPage") else None, UNICODE_ENCODING, conf.get("encoding")))
361 elif conf.get("encoding") and b'\n' not in value:
362 candidates = filterNone((encoding, conf.get("encoding"), kb.get("pageEncoding") if kb.get("originalPage") else None, sys.getfilesystemencoding(), UNICODE_ENCODING))
363
364 for candidate in candidates:
365 try:
366 return six.text_type(value, candidate)
367 except (UnicodeDecodeError, LookupError):
368 pass
369
370 try:
371 return six.text_type(value, encoding or (kb.get("pageEncoding") if kb.get("originalPage") else None) or UNICODE_ENCODING)
372 except UnicodeDecodeError:
373 return six.text_type(value, UNICODE_ENCODING, errors="reversible")
374 elif isListLike(value):
375 value = list(getUnicode(_, encoding, noneToNull) for _ in value)
376 return value
377 else:
378 try:
379 return six.text_type(value)
380 except UnicodeDecodeError:
381 return six.text_type(str(value), errors="ignore") # encoding ignored for non-basestring instances
382
383def getText(value, encoding=None):
384 """

Callers 15

modulePathFunction · 0.90
attackDumpedTableFunction · 0.90
_bruteProcessVariantAFunction · 0.90
_bruteProcessVariantBFunction · 0.90
pivotDumpTableFunction · 0.90
updateMethod · 0.90
__str__Method · 0.90
writeMethod · 0.90
purgeFunction · 0.90
_searchFunction · 0.90
checkFalsePositivesFunction · 0.90
checkDynParamFunction · 0.90

Calls 4

filterNoneFunction · 0.70
isListLikeFunction · 0.70
getMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…