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

Function stdoutEncode

lib/core/convert.py:406–451  ·  view source on GitHub ↗

Returns textual representation of a given value safe for writing to stdout >>> stdoutEncode(b"foobar") 'foobar'

(value)

Source from the content-addressed store, hash-verified

404 return retVal
405
406def stdoutEncode(value):
407 """
408 Returns textual representation of a given value safe for writing to stdout
409 >>> stdoutEncode(b"foobar")
410 'foobar'
411 """
412
413 if value is None:
414 value = ""
415
416 if IS_WIN and IS_TTY and kb.get("codePage", -1) is None:
417 output = shellExec("chcp")
418 match = re.search(r": (\d{3,})", output or "")
419
420 if match:
421 try:
422 candidate = "cp%s" % match.group(1)
423 codecs.lookup(candidate)
424 kb.codePage = candidate
425 except (LookupError, TypeError):
426 pass
427
428 kb.codePage = kb.codePage or ""
429
430 encoding = kb.get("codePage") or getattr(sys.stdout, "encoding", None) or UNICODE_ENCODING
431
432 if six.PY3:
433 if isinstance(value, (bytes, bytearray)):
434 value = getUnicode(value, encoding)
435 elif not isinstance(value, str):
436 value = str(value)
437
438 try:
439 retVal = value.encode(encoding, errors="replace").decode(encoding, errors="replace")
440 except (LookupError, TypeError):
441 retVal = value.encode("ascii", errors="replace").decode("ascii", errors="replace")
442 else:
443 if isinstance(value, six.text_type):
444 try:
445 retVal = value.encode(encoding, errors="replace")
446 except (LookupError, TypeError):
447 retVal = value.encode("ascii", errors="replace")
448 else:
449 retVal = value
450
451 return retVal
452
453def getConsoleLength(value):
454 """

Callers 1

dataToStdoutFunction · 0.90

Calls 6

getUnicodeFunction · 0.85
lookupMethod · 0.80
decodeMethod · 0.80
shellExecFunction · 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…