コード例 #1
0
ファイル: engine.py プロジェクト: giflw/afn-tools
 def _evaluate(self, context, query):
     """
     DON'T USE THIS EXTERNALLY UNLESS YOU KNOW WHAT YOU'RE DOING. It's for
     JPath internal use. I'll get a tutorial up soon on how to properly run a
     query.
     """
     # Figure out the method to dispatch to based on the type of AST node that
     # this is
     function = self.get_evaluator(type(query))
     try:
         if function is None:
             raise Exception("Evaluate not implemented for AST component type " + 
                     str(type(query)) + " containing " + trimTo(200, repr(query)) + ". "
                     + JPATH_INTERNAL_ERROR_MESSAGE)
         result = function(context, query)
         if not isinstance(result, list):
             raise Exception("Result was not a list (representing a collection) "
                     "for AST component type " + str(type(query)) + " containing " + 
                     trimTo(200, repr(query)) + ". " + JPATH_INTERNAL_ERROR_MESSAGE)
         return result
     except errors.EvaluationError as e:
         # TODO: in the future, add additional information to this as we travel
         # up the stack
         raise
     except Exception as e:
         if context.get_option("jpath.python_traceback", False):
             print_exc()
         raise errors.EvaluationError(query.parse_location, type(e).__name__ + ": " + str(e), sys.exc_info())
コード例 #2
0
ファイル: engine.py プロジェクト: giflw/afn-tools
 def get_evaluator(self, production_class):
     try:
         return self.evaluators[production_class]
     except KeyError:
         raise Exception("No evaluator could be found for production class " 
                 + str(type(production_class)) + ", and specifically the instance "
                 + trimTo(200, repr(production_class)) + ". This means that an "
                 "evaluator for this production class wasn't installed "
                 "using set_evaluator ")