Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 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, unicode):
                code = code.encode('ascii', 'backslashreplace')
            return compiler_parse(code, mode)
    except Exception, e:
        raise exceptions.SyntaxException(
            "(%s) %s (%r)" % (e.__class__.__name__, e, code[0:50]),
            **exception_kwargs)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 6
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)