Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_async_forbidden(self):
from birdseye.tracer import TreeTracerBase
tracer = TreeTracerBase()
with self.assertRaises(ValueError):
exec("""
@tracer
async def f(): pass""")
if sys.version_info >= (3, 6):
with self.assertRaises(ValueError):
exec("""
@tracer
class Series(object):
pass
try:
from django.db.models import QuerySet
except ImportError:
class QuerySet(object):
pass
warn_if_outdated('birdseye', __version__)
CodeInfo = namedtuple('CodeInfo', 'db_func traced_file arg_names')
class BirdsEye(TreeTracerBase):
"""
Decorate functions with an instance of this class to debug them,
or just use the existing instance `eye`.
"""
def __init__(self, db_uri=None, num_samples=None):
"""
Set db_uri to specify where the database lives, as an alternative to
the environment variable BIRDSEYE_DB.
"""
super(BirdsEye, self).__init__()
self._db_uri = db_uri
self._code_infos = {} # type: Dict[CodeType, CodeInfo]
self._last_call_id = None
self._ipython_cell_value = None
self.num_samples = num_samples or dict(
def visit_expr(self, node):
# type: (ast.expr) -> ast.Call
"""
each expression e gets wrapped like this:
_treetrace_hidden_after_expr(_treetrace_hidden_before_expr(_tree_index), e)
where the _treetrace_* functions are the corresponding methods with the
TreeTracerBase and traced_file arguments already filled in (see _trace_methods_dict)
"""
before_marker = self._create_simple_marker_call(node, TreeTracerBase._treetrace_hidden_before_expr)
ast.copy_location(before_marker, node)
after_marker = ast.Call(
func=ast.Name(id=TreeTracerBase._treetrace_hidden_after_expr.__name__,
ctx=ast.Load()),
args=[
before_marker,
super(_NodeVisitor, self).generic_visit(node),
],
keywords=[],
)
ast.copy_location(after_marker, node)
ast.fix_missing_locations(after_marker)
return after_marker
def visit_expr(self, node):
# type: (ast.expr) -> ast.Call
"""
each expression e gets wrapped like this:
_treetrace_hidden_after_expr(_treetrace_hidden_before_expr(_tree_index), e)
where the _treetrace_* functions are the corresponding methods with the
TreeTracerBase and traced_file arguments already filled in (see _trace_methods_dict)
"""
before_marker = self._create_simple_marker_call(node, TreeTracerBase._treetrace_hidden_before_expr)
ast.copy_location(before_marker, node)
after_marker = ast.Call(
func=ast.Name(id=TreeTracerBase._treetrace_hidden_after_expr.__name__,
ctx=ast.Load()),
args=[
before_marker,
super(_NodeVisitor, self).generic_visit(node),
],
keywords=[],
)
ast.copy_location(after_marker, node)
ast.fix_missing_locations(after_marker)
return after_marker
def visit_stmt(self, node):
# type: (ast.stmt) -> ast.With
"""
Every statement in the original code becomes:
with _treetrace_hidden_with_stmt(_tree_index):
where the _treetrace_hidden_with_stmt function is the the corresponding method with the
TreeTracerBase and traced_file arguments already filled in (see _trace_methods_dict)
"""
context_expr = self._create_simple_marker_call(
super(_NodeVisitor, self).generic_visit(node),
TreeTracerBase._treetrace_hidden_with_stmt)
if PY3:
wrapped = ast.With(
items=[ast.withitem(context_expr=context_expr)],
body=[node],
)
else:
wrapped = ast.With(
context_expr=context_expr,
body=[node],
)
ast.copy_location(wrapped, node)
ast.fix_missing_locations(wrapped)
return wrapped
class Series(object):
pass
try:
from django.db.models import QuerySet
except ImportError:
class QuerySet(object):
pass
warn_if_outdated('birdseye', __version__)
CodeInfo = namedtuple('CodeInfo', 'db_func traced_file arg_names')
class BirdsEye(TreeTracerBase):
"""
Decorate functions with an instance of this class to debug them,
or just use the existing instance `eye`.
"""
def __init__(self, db_uri=None, num_samples=None):
"""
Set db_uri to specify where the database lives, as an alternative to
the environment variable BIRDSEYE_DB.
"""
super(BirdsEye, self).__init__()
self._db_uri = db_uri
self._code_infos = {} # type: Dict[CodeType, CodeInfo]
self._last_call_id = None
self._ipython_cell_value = None
self.num_samples = num_samples or dict(