text
stringlengths 0
828
|
---|
""""""
|
SEARCHING, MATCHED = 1, 2
|
state = SEARCHING
|
result = ''
|
stacksize = 0
|
for op in dis.get_instructions(frame.f_code):
|
if state == SEARCHING and op.offset == frame.f_lasti:
|
if not op.opname.startswith('CALL_FUNCTION'):
|
raise RuntimeError('get_assigned_name() requires entry at CALL_FUNCTION')
|
state = MATCHED
|
# For a top-level expression, the stack-size should be 1 after
|
# the function at which we entered was executed.
|
stacksize = 1
|
elif state == MATCHED:
|
# Update the would-be size of the stack after this instruction.
|
# If we're at zero, we found the last instruction of the expression.
|
try:
|
stacksize += get_stackdelta(op)
|
except KeyError:
|
raise RuntimeError('could not determined assigned name, instruction '
|
'{} is not supported'.format(op.opname))
|
if stacksize == 0:
|
if op.opname not in ('STORE_NAME', 'STORE_ATTR', 'STORE_GLOBAL', 'STORE_FAST'):
|
raise ValueError('expression is not assigned or branch is not first part of the expression')
|
return result + op.argval
|
elif stacksize < 0:
|
raise ValueError('not a top-level expression')
|
if op.opname.startswith('CALL_FUNCTION'):
|
# Chained or nested function call.
|
raise ValueError('inside a chained or nested function call')
|
elif op.opname == 'LOAD_ATTR':
|
result += op.argval + '.'
|
if not result:
|
raise RuntimeError('last frame instruction not found')
|
assert False"
|
267,"def load_actions(spec, group=None, expr_parser=None):
|
""""""Each item can be an action name as a string or a dict. When using a dict,
|
one key/item pair must be the action name and its options and the rest action
|
decorator names and their options.
|
Example:
|
load_actions([""login_required"", {""flash"": {""message"": ""hello world"", ""label"": ""warning""}}])
|
""""""
|
if expr_parser is None:
|
expr_parser = ExpressionParser()
|
actions = ActionList()
|
for name in spec:
|
options = {}
|
as_ = None
|
decorators = []
|
if isinstance(name, dict):
|
actionspec = dict(name)
|
as_ = actionspec.pop(""as"", None)
|
for dec, dec_cls in action_decorators:
|
if dec in actionspec:
|
decorators.append((dec_cls, expr_parser.compile(actionspec.pop(dec))))
|
name, options = actionspec.popitem()
|
if options:
|
options = expr_parser.compile(options)
|
if isinstance(name, Action):
|
action = name
|
elif isinstance(name, ActionFunction):
|
action = name.action
|
else:
|
action = action_resolver.resolve_or_delayed(name, options, group, as_)
|
for dec_cls, arg in decorators:
|
action = dec_cls(action, arg)
|
actions.append(action)
|
return actions"
|
268,"def load_grouped_actions(spec, default_group=None, key_prefix=""actions"", pop_keys=False, expr_parser=None):
|
""""""Instanciates actions from a dict. Will look for a key name key_prefix and
|
for key starting with key_prefix followed by a dot and a group name. A group
|
name can be any string and will can be used later to filter actions.
|
Values associated to these keys should be lists that will be loaded using load_actions()
|
""""""
|
actions = ActionList()
|
if expr_parser is None:
|
expr_parser = ExpressionParser()
|
for key in spec.keys():
|
if key != key_prefix and not key.startswith(key_prefix + "".""):
|
continue
|
group = default_group
|
if ""."" in key:
|
(_, group) = key.split(""."")
|
actions.extend(load_actions(spec[key], group, expr_parser))
|
if pop_keys:
|
spec.pop(key)
|
return actions"
|
269,"def create_action_from_dict(name, spec, base_class=ActionsAction, metaclass=type, pop_keys=False):
|
""""""Creates an action class based on a dict loaded using load_grouped_actions()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.