def iprocess(self, req: Plumbing.Request) -> ElementTree: """The inner request pipeline processor. :param req: The request to run through the pipeline """ # log.debug("Processing {}".format(self.pipeline)) for p in self.pipeline: try: pipefn, opts, name, args = load_pipe(p) log.debug( "{!s}: calling '{}' using args:\n{} and opts:\n{}".format( self.pipeline, name, repr(args), repr(opts))) if is_text(args): args = [args] if args is not None and type(args) is not dict and type( args) is not list and type(args) is not tuple: raise PipeException("Unknown argument type %s" % repr(args)) req.args = args req.name = name ot = pipefn(req, *opts) if ot is not None: req.t = ot if req.done: break except BaseException as ex: log.debug(traceback.format_exc()) log.error(f'Got exception when loading/executing pipe: {ex}') req.exception = ex if req.raise_exceptions: raise ex break return req.t
def _select(self, member=None): if member is None: member = "entities" if is_text(member): if '!' in member: (src, xp) = member.split("!") if len(src) == 0: src = None return self.select(src, xp=xp) log.debug("calling store lookup %s" % member) return self.lookup(member)
def find_in_document(t, member): relt = root(t) if is_text(member): if '!' in member: (src, xp) = member.split("!") return relt.xpath(xp, namespaces=NS, smart_strings=False) else: lst = [] for e in iter_entities(relt): if e.get('entityID') == member: lst.append(e) return lst raise MetadataException("unknown format for filtr member: %s" % member)
def load_pipe( d: Any) -> Tuple[Callable, Any, str, Optional[Union[str, Dict, List]]]: """Return a triple callable,name,args of the pipe specified by the object d. :param d: The following alternatives for d are allowed: - d is a string (or unicode) in which case the pipe is named d called with None as args. - d is a dict of the form {name: args} (i.e one key) in which case the pipe named *name* is called with args - d is an iterable (a list) in which case d[0] is treated as the pipe name and d[1:] becomes the args """ def _n(_d: str) -> Tuple[str, List[str]]: lst = _d.split() _name = lst[0] _opts = lst[1:] return _name, _opts name = None args = None opts: List[str] = [] if is_text(d): name, opts = _n(d) elif hasattr(d, '__iter__') and not type(d) is dict: if not len(d): raise PipeException( "This does not look like a length of pipe... \n%s" % repr(d)) name, opts = _n(d[0]) elif type(d) is dict: k = list(d.keys())[0] name, opts = _n(k) args = d[k] else: raise PipeException( "This does not look like a length of pipe... \n%s" % repr(d)) if name is None: raise PipeException("Anonymous length of pipe... \n%s" % repr(d)) func = None if name in registry: func = registry[name] if func is None or not hasattr(func, '__call__'): raise PipeException('No pipe named %s is installed' % name) return func, opts, name, args