mirror of
https://github.com/syssec-utd/pylingual.git
synced 2026-05-11 10:50:12 -07:00
masking nits
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import ast
|
||||
import sys
|
||||
import re
|
||||
import copy
|
||||
from pylingual.masking.global_masker import Masker
|
||||
@@ -28,7 +29,10 @@ class customUnparser(ast._Unparser):
|
||||
|
||||
def visit_FormattedValue(self, node):
|
||||
def unparse_inner(inner):
|
||||
unparser = type(self)(self.masker, _avoid_backslashes=True)
|
||||
if PythonVersion(sys.version_info) <= (3, 11):
|
||||
unparser = type(self)(self.masker, _avoid_backslashes=True)
|
||||
else:
|
||||
unparser = type(self)(self.masker)
|
||||
unparser.set_precedence(ast._Precedence.TEST.next(), inner)
|
||||
return unparser.visit(inner)
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class Masker:
|
||||
|
||||
def mask(self, tok):
|
||||
"""Mask a token, must be in the global_table."""
|
||||
return self.global_tab[tok] if not any(tok == t and type(tok) == type(t) for t in self.blacklist) else tok
|
||||
return self.global_tab[tok] if not any(tok == t and type(tok) is type(t) for t in self.blacklist) else tok
|
||||
|
||||
def unmask(self, value):
|
||||
"""Unmask a token, value must be a metatoken value in the global_table; or this function will fail loudly"""
|
||||
|
||||
@@ -43,7 +43,7 @@ def create_global_masker(bytecode: EditableBytecode) -> Masker:
|
||||
# add LOAD_SMALL_INT values to consts (3.14+)
|
||||
if bc.version >= (3, 14):
|
||||
for inst in bc.instructions:
|
||||
if inst.opname == "LOAD_SMALL_INT" and inst.argval not in consts:
|
||||
if inst.opname == "LOAD_SMALL_INT": # duplicate consts will be filtered out later
|
||||
consts.append(inst.argval)
|
||||
|
||||
while consts:
|
||||
|
||||
@@ -100,3 +100,6 @@ docstring-code-line-length = "dynamic"
|
||||
members = [
|
||||
"pylingual/tools",
|
||||
]
|
||||
|
||||
[tool.uv.sources]
|
||||
xdis = { git = "https://github.com/jdw170000/python-xdis", rev = "python-3.14" }
|
||||
|
||||
Reference in New Issue
Block a user