Пример #1
0
def _or(*args):
    unwrapped_args = (unwrap_val(arg) for arg in args)
    vals = (val for val in unwrapped_args if val is not None and val != [])
    try:
        return next(vals)
    except StopIteration:
        pass
 def get_location_ancestor(self, resource_uri, location_type_code):
     unwrapped_uri = unwrap_val(resource_uri)
     if unwrapped_uri in self.location_hierarchy:
         location_hierarchy = self.location_hierarchy[unwrapped_uri]
         if location_type_code in location_hierarchy:
             return location_hierarchy[location_type_code]
     return None
Пример #3
0
def _or(*args):
    unwrapped_args = (unwrap_val(arg) for arg in args)
    vals = (val for val in unwrapped_args if val is not None and val != [])
    try:
        return next(vals)
    except StopIteration:
        pass
 def get_location_info(self, resource_uri, field):
     unwrapped_uri = unwrap_val(resource_uri)
     if unwrapped_uri in self.location_types:
         location_type = self.location_types[unwrapped_uri]
         if field in self.location_types[unwrapped_uri]:
             return location_type[field]
     return None
Пример #5
0
    def eval(self, env):
        fn_result = self.fn.eval(env)
        args_results = [arg.eval(env) for arg in self.args]

        try:
            result = fn_result(*args_results)
            if isinstance(result, MiniLinq):
                return result.eval(env)
        except Exception as e:
            args = ', '.join([str(unwrap_val(arg)) for arg in args_results])
            try:
                doc_id = unwrap_val(Reference('id').eval(env))
            except:
                doc_id = 'unknown'

            message = e.args[0] + (
                ": Error processing document '%s'. "
                "Failure to evaluating expression '%r' with arguments '%s'"
            ) % (doc_id, self, args)

            e.args = (message, ) + e.args[1:]
            raise
        return result
Пример #6
0
    def eval(self, env):
        fn_result = self.fn.eval(env)
        args_results = [arg.eval(env) for arg in self.args]

        try:
            result = fn_result(*args_results)
            if isinstance(result, MiniLinq):
                return result.eval(env)
        except Exception as e:
            args = ', '.join([str(unwrap_val(arg)) for arg in args_results])
            try:
                doc_id = unwrap_val(Reference('id').eval(env))
            except:
                doc_id = 'unknown'

            message = e.args[0] + (
                ": Error processing document '%s'. "
                "Failure to evaluating expression '%r' with arguments '%s'"
            ) % (doc_id, self, args)

            e.args = (message,) + e.args[1:]
            raise
        return result
Пример #7
0
    def lookup(self, name):
        "str|JsonPath -> ??"
        if isinstance(name, six.string_types):
            jsonpath_expr = self.parse(name)
        elif isinstance(name, jsonpath.JSONPath):
            jsonpath_expr = name
        else:
            raise NotFound(unwrap_val(name))

        def iter(jsonpath_expr=jsonpath_expr): # Capture closure
            for datum in jsonpath_expr.find(self.__bindings):
                # HACK: The auto id from jsonpath_rw is good, but we lose it when we do .value here,
                # so just slap it on if not present
                if isinstance(datum.value, dict) and 'id' not in datum.value:
                    datum.value['id'] = jsonpath.AutoIdForDatum(datum).value
                yield datum
        return RepeatableIterator(iter)
Пример #8
0
    def lookup(self, name):
        "str|JsonPath -> ??"
        if isinstance(name, six.string_types):
            jsonpath_expr = self.parse(name)
        elif isinstance(name, jsonpath.JSONPath):
            jsonpath_expr = name
        else:
            raise NotFound(unwrap_val(name))

        def iter(jsonpath_expr=jsonpath_expr):  # Capture closure
            for datum in jsonpath_expr.find(self.__bindings):
                # HACK: The auto id from jsonpath_rw is good, but we lose it when we do .value here,
                # so just slap it on if not present
                if isinstance(datum.value, dict) and 'id' not in datum.value:
                    datum.value['id'] = jsonpath.AutoIdForDatum(datum).value
                yield datum

        return RepeatableIterator(iter)
Пример #9
0
def template(format_template, *args):
    args = [unwrap_val(arg) for arg in args]
    return format_template.format(*args)
Пример #10
0
def join(*args):
    args = [unwrap_val(arg) for arg in args]
    try:
        return args[0].join(args[1:])
    except TypeError:
        return '""'
Пример #11
0
 def lookup(self, name):
     try:
         return self.d[name]
     except KeyError:
         raise NotFound(unwrap_val(name))
Пример #12
0
def template(format_template, *args):
    args = [unwrap_val(arg) for arg in args]
    return format_template.format(*args)
Пример #13
0
def join(*args):
    args = [unwrap_val(arg)for arg in args]
    return args[0].join(args[1:])
Пример #14
0
 def lookup(self, name):
     try:             return self.d[name]
     except KeyError: raise NotFound(unwrap_val(name))
Пример #15
0
def join(*args):
    args = [unwrap_val(arg) for arg in args]
    return args[0].join(args[1:])