PolyCruise icon indicating copy to clipboard operation
PolyCruise copied to clipboard

Create a variable to hold the bytes constants

Open Zayat opened this issue 3 years ago • 0 comments

Before/After Testing

Setup: prepare file test_bytes.py based on an instruction in python3.7/re.py as follows:

_special_chars_map = {i: '\\' + chr(i) for i in b'()[]{}?*+-|^$\\.&~# \t\n\r\v\f'}
print(_special_chars_map)

Before:

python pyinspect.py -c test_bytes.py
AttributeError: 'Bytes' object has no attribute 'id'

After:

$ python pyinspect.py -c test_bytes.py
$ cat Temp/test_bytes.py
import builtins
v1 = {}
v4 = b'()[]{}?*+-|^$\\.&~# \t\n\r\x0b\x0c'
for (v2, v3) in builtins.enumerate(v4):
    i = v3
    v6 = '\\'
    v7 = chr(i)
    v5 = (v6 + v7)
    v1[i] = v5
_special_chars_map = v1
print(_special_chars_map)
$ python Temp/test_bytes.py
{40: '\\(', 41: '\\)', 91: '\\[', 93: '\\]', 123: '\\{', 125: '\\}', 63: '\\?', 42: '\\*', 43: '\\+', 45: '\\-', 124: '\\|', 94: '\\^', 36: '\\$', 92: '\\\\', 46: '\\.', 38: '\\&', 126: '\\~', 35: '\\#', 32: '\\ ', 9: '\\\t', 10: '\\\n', 13: '\\\r', 11: '\\\x0b', 12: '\\\x0c'}

Zayat avatar Nov 29 '22 21:11 Zayat