Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def assert_qualname(self, func, qn, check_actual_qualname=True):
qualname = Source.for_filename(__file__).code_qualname(func.__code__)
self.assertEqual(qn, qualname)
if PY3 and check_actual_qualname:
self.assertEqual(qn, func.__qualname__)
self.assertTrue(qn.endswith(func.__name__))
def test_invalid_python(self):
path = os.path.join(os.path.dirname(__file__), 'not_code.txt', )
source = Source.for_filename(path)
self.assertIsNone(source.tree)
def check_filename(self, filename):
print(filename)
source = Source.for_filename(filename)
nodes = defaultdict(list)
for node in ast.walk(source.tree):
if isinstance(node, (
ast.UnaryOp,
ast.BinOp,
ast.Subscript,
ast.Call,
ast.Compare,
ast.Attribute
)):
nodes[node] = []
code = compile(source.tree, source.filename, 'exec')
result = list(self.check_code(code, nodes))
if not re.search(r'^\s*if 0(:| and )', source.text, re.MULTILINE):
def test_invalid_python(self):
path = os.path.join(os.path.dirname(__file__), 'not_code.txt', )
source = Source.for_filename(path)
self.assertIsNone(source.tree)
def assert_qualname(self, func, qn, check_actual_qualname=True):
qualname = Source.for_filename(__file__).code_qualname(func.__code__)
self.assertEqual(qn, qualname)
if PY3 and check_actual_qualname:
self.assertEqual(qn, func.__qualname__)
self.assertTrue(qn.endswith(func.__name__))
def file_table_context():
filename = request.args['filename']
source = Source.for_filename(filename)
queue = queues[filename]
highlighted = highlight_ranges(source, frames_matching(filename))
highlighted = highlight_python_and_ranges(highlighted)
highlighted_lines = list(enumerate(highlighted.splitlines()))
counters = [
queue_counter(queue, 2 ** i)
for i in range(levels + 1)
]
ratios = [
[
counter[i + 1] / min(2 ** c, len(queue) or 1)
* (c + 1) / levels
for c, counter in enumerate(counters)