Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def export(*names):
- """A decorator to export the specified local variables.
- Before returning, set self._locals = locals()
- self._locals will be deleted by the decorator.
- """
- def wrapper(func):
- def export(self, *args, **kwargs):
- func(self, *args, **kwargs)
- for name in names:
- if name in self._locals:
- self.__dict__[name] = self._locals[name]
- del self._locals
- return export
- return wrapper
- class Arguments(object):
- """Selector-specific arguments.
- The mode used during construction limits parsing to only the attributes
- specified by that mode, and the attributes necessary to derive them.
- """
- class Mode(object):
- _ALWAYS = set(['form', 'args_ctrl',
- 'select_type', 'input_ctrl', 'query_ctrl', 'child_paths'])
- _FIELDS = set(['link_ctrl', 'field_ctrls'])
- _LINKS = set(['link_button', 'link_paths'])
- _DELIMITERS = set(['prefix', 'delimiter'])
- _INPUTS = set(['input', 'inputs'])
- _COMPONENTS = set(['components'])
- SELECT = _ALWAYS | _FIELDS | _LINKS | _INPUTS | _COMPONENTS | set(['form_ops'])
- QUERY = _ALWAYS | set(['substitutions', 'query'])
- LINK_INPUTS = SELECT | set(['link_inputs'])
- VISIBLE = _ALWAYS | _COMPONENTS | set(['link_ctrls'])
- REFRESH = _ALWAYS | _FIELDS | _LINKS | _DELIMITERS
- ALL = SELECT | QUERY | LINK_INPUTS | VISIBLE | REFRESH
- @export(*Mode.ALL)
- def __init__(self, form, args_ctrl, parse=Mode.SELECT):
- # Always parsed
- args, child_paths = extractArgs(args_ctrl)
- select_type = SelectType.types[args[0]]
- input_ctrl, query_ctrl = [getByPath(form, path) for path in args[1:3]]
- # Conditional parsing
- if 'substitutions' in parse:
- args.substitutions = safeSplit(args.query_ctrl.HiddenValue, LIST_SEP)[2:]
- if 'query' in parse:
- args.query = args.query_ctrl.Tag
- if not parse.isdisjoint(Arguments.Mode._INPUTS):
- input = input_ctrl.Text
- if select_type == SelectType.MULTIPLE and 'components' in parse:
- components = []
- for path in args[3:]:
- ctrl = getByPath(form, path)
- q_ctrl = getByPath(ctrl.Parent, ctrl.HiddenValue.split(LIST_SEP, 3)[2])
- components.append( (q_ctrl.HiddenValue.split(LIST_SEP, 1)[0], ctrl) )
- need_inputs = 'inputs' in parse
- if not parse.isdisjoint(Arguments.Mode._DELIMITERS) or need_inputs:
- prefix, delimiter = query_ctrl.HiddenValue.split(LIST_SEP, 2)[:2]
- need_fields = not parse.isdisjoint(Arguments.Mode._FIELDS)
- need_links = not parse.isdisjoint(Arguments.Mode._LINKS)
- need_link_ctrls = 'link_ctrls' in parse
- need_link_inputs = 'link_inputs' in parse
- type_link = select_type in (SelectType.LINKED, SelectType.LINKING)
- if need_fields or need_links or need_link_ctrls or need_inputs or need_link_inputs:
- ctrls = [getByPath(form, path) for path in args[3:]]
- if type_link:
- link_ctrl, field_ctrls = ctrls[0], ctrls[1:]
- else:
- field_ctrls = ctrls
- if type_link and (need_links or need_link_ctrls):
- link_paths = safeSplit(link_ctrl.HiddenValue, LIST_SEP)
- if select_type == SelectType.LINKING:
- link_button = getByPath(form, link_paths[0])
- link_paths = link_paths[1:]
- if type_link and need_link_ctrls:
- link_ctrls = [getByPath(form, path) for path in link_paths]
- if need_inputs:
- inputs = safeSplit(input[len(prefix):], delimiter,
- len(field_ctrls) - 1, empty_list=False)
- if 'form_ops' in parse:
- # ThisComponent = XSCRIPTCONTEXT.getDocument()
- form_ops = (XSCRIPTCONTEXT.getDocument().CurrentController
- .getFormController(form).FormOperations)
- if type_link and need_link_inputs:
- link_inputs = [getValue(getByPath(form, path)) for path in safeSplit(link_ctrl.Tag, LIST_SEP)]
- self._locals = locals()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement