示例#1
0
def parse(code, mode='exec', **exception_kwargs):
    """Parse an expression into AST"""

    try:
        return _ast_util.parse(code, '<unknown>', mode)
    except Exception:
        raise exceptions.SyntaxException(
            "(%s) %s (%r)" % (compat.exception_as().__class__.__name__,
                              compat.exception_as(), code[0:50]),
            **exception_kwargs)
示例#2
0
文件: pyparser.py 项目: 2mny/mylar
def parse(code, mode='exec', **exception_kwargs):
    """Parse an expression into AST"""

    try:
        return _ast_util.parse(code, '<unknown>', mode)
    except Exception:
        raise exceptions.SyntaxException(
            "(%s) %s (%r)" % (
                compat.exception_as().__class__.__name__,
                compat.exception_as(),
                code[0:50]
            ), **exception_kwargs)
示例#3
0
def parse(code, mode='exec', **exception_kwargs):
    """Parse an expression into AST"""

    try:
        if _ast:
            return _ast_util.parse(code, '<unknown>', mode)
        else:
            if isinstance(code, compat.text_type):
                code = code.encode('ascii', 'backslashreplace')
            return compiler_parse(code, mode)
    except Exception:
        raise exceptions.SyntaxException(
            "(%s) %s (%r)" % (compat.exception_as().__class__.__name__,
                              compat.exception_as(), code[0:50]),
            **exception_kwargs)
示例#4
0
def parse(code, mode="exec", **exception_kwargs):
    """Parse an expression into AST"""

    try:
        return _ast_util.parse(code, "<unknown>", mode)
    except Exception as e:
        raise exceptions.SyntaxException(
            "(%s) %s (%r)"
            % (
                compat.exception_as().__class__.__name__,
                compat.exception_as(),
                code[0:50],
            ),
            **exception_kwargs,
        ) from e
示例#5
0
def parse(code, mode='exec', **exception_kwargs):
    """Parse an expression into AST"""

    try:
        return _ast_util.parse(code, '<unknown>', mode)
    except Exception:
        import sys, traceback                          ##################  Added by Christopher Sebastian
        print >> sys.stderr, '\nOriginal Exception:'   ##################  Added by Christopher Sebastian
        traceback.print_exc()                          ##################  Added by Christopher Sebastian
        print >> sys.stderr                            ##################  Added by Christopher Sebastian
        raise exceptions.SyntaxException(
            "(%s) %s :\n%s" % (                        ##################  Edited by Christopher Sebastian
                compat.exception_as().__class__.__name__,
                compat.exception_as(),
                (u'\n'.join(['%03d: %s'%(i+1,l) for i,l in enumerate(code.splitlines())])).encode('ascii', 'backslashreplace')   ##################  Edited by Christopher Sebastian
            ), **exception_kwargs)
示例#6
0
文件: pyparser.py 项目: pjenvey/mako
def parse(code, mode='exec', **exception_kwargs):
    """Parse an expression into AST"""


    try:
        if _ast:
            return _ast_util.parse(code, '<unknown>', mode)
        else:
            if isinstance(code, compat.text_type):
                code = code.encode('ascii', 'backslashreplace')
            return compiler_parse(code, mode)
    except Exception:
        raise exceptions.SyntaxException(
                    "(%s) %s (%r)" % (
                        compat.exception_as().__class__.__name__,
                        compat.exception_as(),
                        code[0:50]
                    ), **exception_kwargs)
示例#7
0
文件: runtime.py 项目: 10sr/hue
def _lookup_template(context, uri, relativeto):
    lookup = context._with_template.lookup
    if lookup is None:
        raise exceptions.TemplateLookupException(
                            "Template '%s' has no TemplateLookup associated" %
                            context._with_template.uri)
    uri = lookup.adjust_uri(uri, relativeto)
    try:
        return lookup.get_template(uri)
    except exceptions.TopLevelLookupException:
        raise exceptions.TemplateLookupException(str(compat.exception_as()))
示例#8
0
def _lookup_template(context, uri, relativeto):
    lookup = context._with_template.lookup
    if lookup is None:
        raise exceptions.TemplateLookupException(
            "Template '%s' has no TemplateLookup associated" %
            context._with_template.uri)
    uri = lookup.adjust_uri(uri, relativeto)
    try:
        return lookup.get_template(uri)
    except exceptions.TopLevelLookupException:
        raise exceptions.TemplateLookupException(str(compat.exception_as()))
示例#9
0
 def test_no_lookup(self):
     t = Template("hi <%include file='foo.html'/>")
     try:
         t.render()
         assert False
     except exceptions.TemplateLookupException:
         eq_(
             str(compat.exception_as()),
         "Template 'memory:%s' has no TemplateLookup associated" % \
                         hex(id(t))
             )
示例#10
0
    def test_unclosed_tag(self):
        template = """

            <%def name="foo()">
             other text
        """
        try:
            nodes = Lexer(template).parse()
            assert False
        except exceptions.SyntaxException:
            eq_(str(compat.exception_as()),
                "Unclosed tag: <%def> at line: 5 char: 9")
示例#11
0
文件: test_lexer.py 项目: 10sr/hue
    def test_unclosed_tag(self):
        template = """

            <%def name="foo()">
             other text
        """
        try:
            nodes = Lexer(template).parse()
            assert False
        except exceptions.SyntaxException:
            eq_(
                str(compat.exception_as()),
                "Unclosed tag: <%def> at line: 5 char: 9"
            )
示例#12
0
def _include_file(context, uri, calling_uri, **kwargs):
    """locate the template from the given uri and include it in
    the current output."""

    template = _lookup_template(context, uri, calling_uri)
    (callable_,
     ctx) = _populate_self_namespace(context._clean_inheritance_tokens(),
                                     template)
    kwargs = _kwargs_for_include(callable_, context._data, **kwargs)
    if template.include_error_handler:
        try:
            callable_(ctx, **kwargs)
        except Exception:
            result = template.include_error_handler(ctx, compat.exception_as())
            if not result:
                compat.reraise(*sys.exc_info())
    else:
        callable_(ctx, **kwargs)
示例#13
0
文件: runtime.py 项目: 2mny/mylar
def _include_file(context, uri, calling_uri, **kwargs):
    """locate the template from the given uri and include it in
    the current output."""

    template = _lookup_template(context, uri, calling_uri)
    (callable_, ctx) = _populate_self_namespace(
        context._clean_inheritance_tokens(),
        template)
    kwargs = _kwargs_for_include(callable_, context._data, **kwargs)
    if template.include_error_handler:
        try:
            callable_(ctx, **kwargs)
        except Exception:
            result = template.include_error_handler(ctx, compat.exception_as())
            if not result:
                compat.reraise(*sys.exc_info())
    else:
        callable_(ctx, **kwargs)
示例#14
0
def _exec_template(callable_, context, args=None, kwargs=None):
    """execute a rendering callable given the callable, a
    Context, and optional explicit arguments

    the contextual Template will be located if it exists, and
    the error handling options specified on that Template will
    be interpreted here.
    """
    template = context._with_template
    if template is not None and (template.format_exceptions or template.error_handler):
        try:
            callable_(context, *args, **kwargs)
        except Exception:
            _render_error(template, context, compat.exception_as())
        except:
            e = sys.exc_info()[0]
            _render_error(template, context, e)
    else:
        callable_(context, *args, **kwargs)
示例#15
0
文件: runtime.py 项目: 1025ryu/sns
def _exec_template(callable_, context, args=None, kwargs=None):
    """execute a rendering callable given the callable, a
    Context, and optional explicit arguments

    the contextual Template will be located if it exists, and
    the error handling options specified on that Template will
    be interpreted here.
    """
    template = context._with_template
    if template is not None and \
            (template.format_exceptions or template.error_handler):
        try:
            callable_(context, *args, **kwargs)
        except Exception:
            _render_error(template, context, compat.exception_as())
        except:
            e = sys.exc_info()[0]
            _render_error(template, context, e)
    else:
        callable_(context, *args, **kwargs)