def getBufferDisassembled(content, encoding, path, optimization): """Disassembles a memory buffer""" tempSrcFile = makeTempFile(suffix='.py') tempPycFile = makeTempFile(suffix='.pyc') try: saveToFile(tempSrcFile, content, allowException=True, enc=encoding) py_compile.compile(tempSrcFile, tempPycFile, path, doraise=True, optimize=optimization) except Exception as exc: safeUnlink(tempSrcFile) safeUnlink(tempPycFile) raise try: result = getCompiledfileDisassembled(tempPycFile, path, optimization, True) except: safeUnlink(tempSrcFile) safeUnlink(tempPycFile) raise safeUnlink(tempSrcFile) safeUnlink(tempPycFile) if path: return result.replace('file "' + path + '",', 'unsaved buffer "' + path + '",') return result
def getBufferBinary(content, encoding, path, optimization): """Provides the binary pyc content""" tempSrcFile = makeTempFile(suffix='.py') tempPycFile = makeTempFile(suffix='.pyc') try: saveToFile(tempSrcFile, content, allowException=True, enc=encoding) py_compile.compile(tempSrcFile, tempPycFile, path, doraise=True, optimize=optimization) except Exception: safeUnlink(tempSrcFile) safeUnlink(tempPycFile) raise try: props, content = getCompiledfileBinary(tempPycFile, path, optimization, True) except: safeUnlink(tempSrcFile) safeUnlink(tempPycFile) raise safeUnlink(tempSrcFile) safeUnlink(tempPycFile) return props, content
def getFileDisassembled(path, optimization): """Dsassembles a file""" if not os.path.exists(path): raise Exception("Cannot find " + path + " to disassemble") if not os.access(path, os.R_OK): raise Exception("No read permissions for " + path) tempPycFile = makeTempFile(suffix='.pyc') try: py_compile.compile(path, tempPycFile, doraise=True, optimize=optimization) except Exception as exc: safeUnlink(tempPycFile) raise Exception("Cannot disassemble file " + path + ': ' + str(exc)) try: result = getCompiledfileDisassembled(tempPycFile, path, optimization) except: safeUnlink(tempPycFile) raise safeUnlink(tempPycFile) return result
def getFileBinary(path, optimization): """Provides the binary pyc content""" if not os.path.exists(path): raise Exception("Cannot find " + path + " to provide binary") if not os.access(path, os.R_OK): raise Exception("No read permissions for " + path) tempPycFile = makeTempFile(suffix='.pyc') try: py_compile.compile(path, tempPycFile, doraise=True, optimize=optimization) except Exception as exc: safeUnlink(tempPycFile) raise Exception("Cannot provide binary for file " + path + ': ' + str(exc)) try: props, content = getCompiledfileBinary(tempPycFile, path, optimization) except: safeUnlink(tempPycFile) raise safeUnlink(tempPycFile) return props, content
def getGraphFromDescriptionData(content): """Runs dot and then parses and builds normalized graph""" tempFileName = makeTempFile() saveToFile(tempFileName, content) try: graph = getGraphFromDescrptionFile(tempFileName) finally: os.unlink(tempFileName) return graph