Ejemplo n.º 1
0
 def evaluate(self, static, dynamic, local):
     left = utils.get_single(self.left.evaluate(static, dynamic, local))
     right = utils.get_single(self.right.evaluate(static, dynamic, local))
     if left.jpath_type != right.jpath_type:
         raise e.TypeException("Left and right values to the ++ operator "
                 "have to be of the same type, but the left value was of "
                 "type " + str(type(left)) + " and the right value was of "
                 "type " + str(type(right)))
     if isinstance(left, d.String): # String concatenation
         return utils.singleton(d.StandardString(left.get_value() + right.get_value()))
     if isinstance(left, d.List): # List concatenation
         return utils.singleton(d.StandardList(left.to_python_list() + right.to_python_list()))
     if isinstance(left, d.Object): # Object union; take the object on the
         # left side, create a new copy of it, then update it with the
         # pairs of the object on the right side. The right side should
         # override the left side in the case of a key conflict.
         dictionary = {}
         for k, v in left:
             dictionary[k] = v
         for k, v in right:
             dictionary[k] = v
         return utils.singleton(d.StandardObject([d.StandardPair(k, v) for k, v in dictionary.iteritems()]))
     raise e.TypeException("Values of type " + str(type(left)) + " can't "
             "be concatenated using the ++ operator. Only values of type "
             "string, list, or object can be given to ++. To convert "
             "values to strings, you can use the string() function.")
Ejemplo n.º 2
0
 def run_query(self, query, update, vars={}):
     interpreter = self.interpreter_constructor()
     module = interpreter.get_binder("jpath").create_query(query)
     wrapped_vars = utils.singleton(translate.json_to_jpath(vars))
     result = module.call_with_values(self.make_context(), [wrapped_vars])
     result = self.process_result(result, update)
     return result
Ejemplo n.º 3
0
 def run_module(self, module, update, vars={}):
     interpreter = self.interpreter_constructor()
     module = interpreter.bind_module("jpath", module)
     wrapped_vars = utils.singleton(translate.json_to_jpath(vars))
     result = module.call_with_values(self.make_context(), [wrapped_vars])
     result = self.process_result(result, update)
     return result
Ejemplo n.º 4
0
 def evaluate(self, static, dynamic, local):
     value = utils.get_single(self.value.evaluate(static, dynamic, local))
     reference = utils.get_single(self.reference.evaluate(static, dynamic, local))
     if isinstance(self.position, Production):
         position = self.position.evaluate(static, dynamic, local)
         position = utils.get_single_instance(position, d.Number).get_as_int()
     else:
         position = self.position
     return utils.singleton(d.StandardInsert(value, reference, position))
Ejemplo n.º 5
0
def root(dynamic):
    function = dynamic.userland.get("db.get_root", None)
    if function is None:
        raise e.OtherException("Query is not running in the context of a "
                "database, so the root function cannot be called. "
                "Specifically, the dynamic context userland does not have an "
                "entry named db.get_root; this should be a function that "
                "returns the root database object.")
    root = function()
    if not isinstance(root, d.Item):
        raise e.OtherException("Dynamic context userland db.get_root "
                "function returned a value that was not an instance of Item; "
                "specifically, it was an instance of " + str(type(root)))
    return utils.singleton(root)
Ejemplo n.º 6
0
def input(dynamic):
    return utils.singleton(d.StandardString(raw_input()))
Ejemplo n.º 7
0
 def get_for_pair_indexer(self, value):
     result = self.get_pair(utils.get_single(value))
     if result is None:
         return EmptySequence()
     return utils.singleton(result)
Ejemplo n.º 8
0
 def get_for_pair_pattern(self, pattern):
     value = self.get_pair(StandardString(pattern))
     if value is None:
         return EmptySequence()
     return utils.singleton(value)
Ejemplo n.º 9
0
 def evaluate(self, static, dynamic, local):
     source = self.source.evaluate(static, dynamic, local)
     target = self.target.evaluate(static, dynamic, local)
     return utils.singleton(d.StandardMerge(source, target))
Ejemplo n.º 10
0
 def evaluate(self, static, dynamic, local):
     target = self.target.evaluate(static, dynamic, local)
     replacement = self.replacement.evaluate(static, dynamic, local)
     return utils.singleton(d.StandardReplace(target, replacement))
Ejemplo n.º 11
0
 def evaluate(self, static, dynamic, local):
     value = self.expr.evaluate(static, dynamic, local)
     return utils.singleton(d.StandardDelete(value))