コード例 #1
0
ファイル: Exceptions.py プロジェクト: vishnur/ufora
def renderTraceback(trace):
    res = []

    for tb in trace:
        if isinstance(tb["path"],tuple):
            path = tb["path"]
            if path[0] == "ModuleImporter":
                path = os.path.join(_pyforaRoot, *path[1:]) + ".fora"
            else:
                path = path[0]
        else:
            path = os.path.abspath(tb["path"])

        if 'range' in tb:
            lineNumber = tb['range']['start']['line']
        else:
            lineNumber = tb["line"]

        from pyfora.pyAst.PyAstUtil import findEnclosingFunctionName, getAstFromFilePath
        inFunction = findEnclosingFunctionName(
            getAstFromFilePath(path),
            lineNumber
            ) if path.endswith(".py") else None
        if inFunction is not None:
            res.append('  File "%s", line %s, in %s' % (path, lineNumber, inFunction))
        else:
            res.append('  File "%s", line %s' % (path, lineNumber))

        lines = PyforaInspect.getlines(os.path.abspath(path))
        if lines is not None and lineNumber >= 1 and lineNumber <= len(lines):
            res.append("    " + lines[lineNumber-1][:-1].lstrip())

    return "\n".join(res)
コード例 #2
0
ファイル: Exceptions.py プロジェクト: ufora/ufora
def renderTraceback(trace):
    res = []

    for tb in trace:
        if isinstance(tb["path"], tuple):
            path = tb["path"]
            if path[0] == "ModuleImporter":
                path = os.path.join(_pyforaRoot, *path[1:]) + ".fora"
            else:
                path = path[0]
        else:
            path = os.path.abspath(tb["path"])

        if 'range' in tb:
            lineNumber = tb['range']['start']['line']
        else:
            lineNumber = tb["line"]

        from pyfora.pyAst.PyAstUtil import findEnclosingFunctionName, getAstFromFilePath
        inFunction = findEnclosingFunctionName(
            getAstFromFilePath(path),
            lineNumber) if path.endswith(".py") else None
        if inFunction is not None:
            res.append('  File "%s", line %s, in %s' %
                       (path, lineNumber, inFunction))
        else:
            res.append('  File "%s", line %s' % (path, lineNumber))

        lines = PyforaInspect.getlines(path)
        if lines is not None and lineNumber >= 1 and lineNumber <= len(lines):
            res.append("    " + lines[lineNumber - 1][:-1].lstrip())

    return "\n".join(res)
コード例 #3
0
ファイル: PyObjectWalker.py プロジェクト: Sandy4321/ufora
    def cachedFromArgs(cls, fileName, fileText=None):
        if fileName in cls._fileTextCache:
            return cls._fileTextCache[fileName]

        if fileText is None:
            fileText = "".join(PyforaInspect.getlines(fileName))

        tr = cls(fileName, fileText)
        cls._fileTextCache[fileName] = tr
        return tr
コード例 #4
0
ファイル: PyAstUtil.py プロジェクト: vishnur/ufora
def getSourceFilenameAndText(pyObject):
    try:
        sourceFile = PyforaInspect.getsourcefile(pyObject)
    except TypeError as e:
        raise Exceptions.CantGetSourceTextError(e.message)

    if sourceFile not in sourceFileCache_:
        sourceFileCache_[sourceFile] = "".join(PyforaInspect.getlines(sourceFile))

    return sourceFileCache_[sourceFile], sourceFile
コード例 #5
0
ファイル: PyObjectWalker.py プロジェクト: vishnur/ufora
    def cachedFromArgs(cls, fileName, fileText=None):
        if fileName in cls._fileTextCache:
            return cls._fileTextCache[fileName]

        if fileText is None:
            fileText = "".join(PyforaInspect.getlines(fileName))

        tr = cls(fileName, fileText)
        cls._fileTextCache[fileName] = tr
        return tr
コード例 #6
0
ファイル: PyAstUtil.py プロジェクト: vishnur/ufora
def getSourceFilenameAndText(pyObject):
    try:
        sourceFile = PyforaInspect.getsourcefile(pyObject)
    except TypeError as e:
        raise Exceptions.CantGetSourceTextError(e.message)

    if sourceFile not in sourceFileCache_:
        sourceFileCache_[sourceFile] = "".join(
            PyforaInspect.getlines(sourceFile))

    return sourceFileCache_[sourceFile], sourceFile
コード例 #7
0
ファイル: WithBlockExecutor.py プロジェクト: lessc0de/ufora
    def __enter__(self):
        self.frame = PyforaInspect.currentframe(1)

        sourceFileName, lineNumber, _, _, _ = PyforaInspect.getframeinfo(self.frame)

        self.sourceFileName = sourceFileName
        self.lineNumber = lineNumber
        self.sourceText = "".join(PyforaInspect.getlines(self.sourceFileName))

        # Seems to "turn on" tracing, otherwise setting
        # frame.f_trace seems to have no effect
        # doesn't seem to have any effects outside of this with context.
        sys.settrace(lambda *args, **keys: None)

        self.frame.f_trace = self.trace
コード例 #8
0
ファイル: PyAstUtil.py プロジェクト: lessc0de/ufora
def getSourceFilenameAndText(pyObject):
    try:
        sourceFile = PyforaInspect.getsourcefile(pyObject)
    except TypeError as e:
        raise Exceptions.CantGetSourceTextError(e.message)

    linesOrNone = PyforaInspect.getlines(sourceFile)

    if linesOrNone is None:
        raise Exceptions.CantGetSourceTextError(
            "can't get source lines for file %s" % sourceFile)

    if sourceFile not in sourceFileCache_:
        sourceFileCache_[sourceFile] = "".join(linesOrNone)

    return sourceFileCache_[sourceFile], sourceFile
コード例 #9
0
ファイル: PyAstUtil.py プロジェクト: Sandy4321/ufora
def getSourceFilenameAndText(pyObject):
    try:
        sourceFile = PyforaInspect.getsourcefile(pyObject)
    except TypeError as e:
        raise Exceptions.CantGetSourceTextError(e.message)

    linesOrNone = PyforaInspect.getlines(sourceFile)

    if linesOrNone is None:
        raise Exceptions.CantGetSourceTextError(
            "can't get source lines for file %s" % sourceFile
            )

    if sourceFile not in sourceFileCache_:
        sourceFileCache_[sourceFile] = "".join(linesOrNone)

    return sourceFileCache_[sourceFile], sourceFile
コード例 #10
0
ファイル: PyAstUtil.py プロジェクト: Sandy4321/ufora
def getAstFromFilePath(filename):
    linesOrNone = PyforaInspect.getlines(filename)
    if linesOrNone is not None:
        return pyAstFromText("".join(linesOrNone))

    return None
コード例 #11
0
def getAstFromFilePath(filename):
    linesOrNone = PyforaInspect.getlines(filename)
    if linesOrNone is not None:
        return pyAstFromText("".join(linesOrNone))

    return None