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

Function getBytes

lib/core/convert.py:280–317  ·  view source on GitHub ↗

Returns byte representation of provided Unicode value >>> getBytes(u"foo\\\\x01\\\\x83\\\\xffbar") == b"foo\\x01\\x83\\xffbar" True

(value, encoding=None, errors="strict", unsafe=True)

Source from the content-addressed store, hash-verified

278 return retVal
279
280def getBytes(value, encoding=None, errors="strict", unsafe=True):
281 """
282 Returns byte representation of provided Unicode value
283
284 >>> getBytes(u"foo\\\\x01\\\\x83\\\\xffbar") == b"foo\\x01\\x83\\xffbar"
285 True
286 """
287
288 retVal = value
289
290 if encoding is None:
291 encoding = conf.get("encoding") or UNICODE_ENCODING
292
293 try:
294 codecs.lookup(encoding)
295 except (LookupError, TypeError):
296 encoding = UNICODE_ENCODING
297
298 if isinstance(value, six.text_type):
299 if INVALID_UNICODE_PRIVATE_AREA:
300 if unsafe:
301 for char in xrange(0xF0000, 0xF00FF + 1):
302 value = value.replace(_unichr(char), "%s%02x" % (SAFE_HEX_MARKER, char - 0xF0000))
303
304 retVal = value.encode(encoding, errors)
305
306 if unsafe:
307 retVal = re.sub((r"%s([0-9a-f]{2})" % SAFE_HEX_MARKER).encode(), lambda _: decodeHex(_.group(1)), retVal)
308 else:
309 try:
310 retVal = value.encode(encoding, errors)
311 except UnicodeError:
312 retVal = value.encode(UNICODE_ENCODING, errors="replace")
313
314 if unsafe:
315 retVal = re.sub(b"\\\\x([0-9a-f]{2})", lambda _: decodeHex(_.group(1)), retVal)
316
317 return retVal
318
319def getOrds(value):
320 """

Callers 15

multipart_encodeMethod · 0.90
mysql_passwdFunction · 0.90
postgres_passwdFunction · 0.90
oracle_passwdFunction · 0.90
md5_generic_passwdFunction · 0.90
sha1_generic_passwdFunction · 0.90
apache_sha1_passwdFunction · 0.90
ssha_passwdFunction · 0.90
ssha256_passwdFunction · 0.90
ssha512_passwdFunction · 0.90
sha224_generic_passwdFunction · 0.90
sha256_generic_passwdFunction · 0.90

Calls 5

xrangeClass · 0.85
decodeHexFunction · 0.85
lookupMethod · 0.80
getMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…