Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def visit_Attribute(self, node):
full_name = self.__get_attribute_name(node)
line = node.lineno
if len(full_name) > 0:
for mod in self.__modules:
if full_name[0] == mod:
self.__add_module(dotted_name(full_name), line)
elif mod.endswith(full_name[0]):
self.__add_member(dotted_name([mod, full_name[1:]]), line)
self.__add_member(dotted_name(full_name), line)
if full_name[0] in self.__name_res:
res = self.__name_res[full_name[0]]
if res in self.__import_mem_mod:
mod = self.__import_mem_mod[res]
self.__add_member(dotted_name([mod, res, full_name[1:]]), line)
# Try as a fully-qualified name.
else:
self.__add_member(dotted_name([res, full_name[1:]]), line)
self.generic_visit(node)
self.__is_int(node.args[2]):
self.__mod_inverse_pow = True
self.__vvprint("modular inverse pow() requires 3.8+")
elif hasattr(func, "attr"):
attr = func.attr
if attr == "format" and hasattr(func, "value") and isinstance(func.value, ast.Str) and \
"{}" in func.value.s:
self.__vvprint("`\"..{}..\".format(..)` requires (2.7, 3.0)")
self.__format27 = True
elif (attr == "strftime" or attr == "strptime") and hasattr(node, "args"):
for arg in node.args:
if hasattr(arg, "s"):
for directive in STRFTIME_DIRECTIVE_REGEX.findall(arg.s):
self.__add_strftime_directive(directive, node.lineno)
if isinstance(func, ast.Attribute):
self.__function_name = dotted_name(self.__get_attribute_name(func))
self.__check_codecs_function(self.__function_name, node)
# Visit arguments and keywords.
if hasattr(node, "args"):
for arg in node.args:
self.generic_visit(arg)
if hasattr(node, "keywords"):
for kw in node.keywords:
self.generic_visit(kw)
self.generic_visit(node)
self.__function_name = None
def visit_Attribute(self, node):
full_name = self.__get_attribute_name(node)
line = node.lineno
if len(full_name) > 0:
for mod in self.__modules:
if full_name[0] == mod:
self.__add_module(dotted_name(full_name), line)
elif mod.endswith(full_name[0]):
self.__add_member(dotted_name([mod, full_name[1:]]), line)
self.__add_member(dotted_name(full_name), line)
if full_name[0] in self.__name_res:
res = self.__name_res[full_name[0]]
if res in self.__import_mem_mod:
mod = self.__import_mem_mod[res]
self.__add_member(dotted_name([mod, res, full_name[1:]]), line)
# Try as a fully-qualified name.
else:
self.__add_member(dotted_name([res, full_name[1:]]), line)
self.generic_visit(node)
# Don't show incompatible versions when -i is given, unless there are no non-incompatible versions
# found then we need must show the incompatible versions - nothing will be shown otherwise. That
# case is when both py2 and py3 incompatibilities were found - in which case `incomps = [2, 3]`
# and `reqs = []`. But if `incomps = [2]` and `reqs = [3.4]`, for instance, then it makes sense
# not to show incompatible versions with -i specified.
if len(incomps) > 0 and (not config.ignore_incomp() or len(reqs) == 0):
print("Incompatible versions: {}".format(version_strings(incomps)))
if args["versions"] and len(unique_versions) > 0:
print("Version range: {}".format(version_strings(unique_versions)))
if len(targets) > 0:
if not (len(reqs) == len(targets) and
all(((exact and target == req) or (not exact and target >= req)) for
((exact, target), req) in zip(targets, reqs))):
vers = ["{}{}".format(dotted_name(t), "-" if not e else "") for (e, t) in targets]
print("Target versions not met: {}".format(version_strings(vers)))
if len(targets) < len(reqs):
print("Note: Number of specified targets ({}) doesn't match number of detected minimum "
"versions ({}).".format(len(targets), len(reqs)))
sys.exit(1)
sys.exit(0)
def visit_Attribute(self, node):
full_name = self.__get_attribute_name(node)
line = node.lineno
if len(full_name) > 0:
for mod in self.__modules:
if full_name[0] == mod:
self.__add_module(dotted_name(full_name), line)
elif mod.endswith(full_name[0]):
self.__add_member(dotted_name([mod, full_name[1:]]), line)
self.__add_member(dotted_name(full_name), line)
if full_name[0] in self.__name_res:
res = self.__name_res[full_name[0]]
if res in self.__import_mem_mod:
mod = self.__import_mem_mod[res]
self.__add_member(dotted_name([mod, res, full_name[1:]]), line)
# Try as a fully-qualified name.
else:
self.__add_member(dotted_name([res, full_name[1:]]), line)
self.generic_visit(node)
def visit_Attribute(self, node):
full_name = self.__get_attribute_name(node)
line = node.lineno
if len(full_name) > 0:
for mod in self.__modules:
if full_name[0] == mod:
self.__add_module(dotted_name(full_name), line)
elif mod.endswith(full_name[0]):
self.__add_member(dotted_name([mod, full_name[1:]]), line)
self.__add_member(dotted_name(full_name), line)
if full_name[0] in self.__name_res:
res = self.__name_res[full_name[0]]
if res in self.__import_mem_mod:
mod = self.__import_mem_mod[res]
self.__add_member(dotted_name([mod, res, full_name[1:]]), line)
# Try as a fully-qualified name.
else:
self.__add_member(dotted_name([res, full_name[1:]]), line)
self.generic_visit(node)
def visit_keyword(self, node):
if self.__function_name is not None:
self.__add_kwargs(self.__function_name, node.arg, self.__line)
if self.__function_name in self.__import_mem_mod:
mod = self.__import_mem_mod[self.__function_name]
self.__add_kwargs(dotted_name([mod, self.__function_name]), node.arg, self.__line)
# When having "ElementTree.tostringlist", for instance, and include mapping "{'ElementTree':
# 'xml.etree'}" then try piecing them together to form a match.
exp_name = self.__function_name.split(".")
if exp_name[0] in self.__import_mem_mod:
mod = self.__import_mem_mod[exp_name[0]]
self.__add_kwargs(dotted_name([mod, self.__function_name]), node.arg, self.__line)
# Lookup indirect names via variables.
if exp_name[0] in self.__name_res:
res = self.__name_res[exp_name[0]]
if res in self.__import_mem_mod:
mod = self.__import_mem_mod[res]
self.__add_kwargs(dotted_name([mod, res, exp_name[1:]]), node.arg, self.__line)
# Try as FQN.
def __add_name_res_assign_node(self, node):
if not hasattr(node, "value"):
return
value_name = None
# If rvalue is a Call.
if isinstance(node.value, ast.Call):
if isinstance(node.value.func, ast.Name):
value_name = node.value.func.id
elif isinstance(node.value.func, ast.Attribute):
value_name = dotted_name(self.__get_attribute_name(node.value.func))
# If rvalue is an Attribute list
elif isinstance(node.value, ast.Attribute):
value_name = dotted_name(self.__get_attribute_name(node.value))
elif isinstance(node.value, ast.Dict):
value_name = "dict"
elif isinstance(node.value, ast.Set):
value_name = "set"
elif isinstance(node.value, ast.List):
value_name = "list"
elif isinstance(node.value, ast.Str):
if sys.version_info.major == 2 and type(node.value.s) == unicode:
value_name = "unicode"
else:
value_name = "str"
elif isinstance(node.value, ast.Num):
t = type(node.value.n)
if t == int:
value_name = "int"
def __add_name_res_assign_node(self, node):
if not hasattr(node, "value"):
return
value_name = None
# If rvalue is a Call.
if isinstance(node.value, ast.Call):
if isinstance(node.value.func, ast.Name):
value_name = node.value.func.id
elif isinstance(node.value.func, ast.Attribute):
value_name = dotted_name(self.__get_attribute_name(node.value.func))
# If rvalue is an Attribute list
elif isinstance(node.value, ast.Attribute):
value_name = dotted_name(self.__get_attribute_name(node.value))
elif isinstance(node.value, ast.Dict):
value_name = "dict"
elif isinstance(node.value, ast.Set):
value_name = "set"
elif isinstance(node.value, ast.List):
value_name = "list"
elif isinstance(node.value, ast.Str):
if sys.version_info.major == 2 and type(node.value.s) == unicode:
value_name = "unicode"
else:
value_name = "str"