예제 #1
0
def tryExtensions(filePath, recorder):
    # Leaving this in loop form in case we change formats again.
    for extension in [".mast"]:
        path = filePath + extension
        try:
            with open(path, "rb") as handle:
                debugPrint("Reading:", path)
                source = handle.read()
                return obtainModuleFromSource(source, recorder,
                                              path.decode('utf-8'))[0]
        except IOError:
            continue
    return None
예제 #2
0
파일: importing.py 프로젝트: washort/typhon
def tryExtensions(filePath, recorder):
    # Leaving this in loop form in case we change formats again.
    for extension in [".mast"]:
        path = filePath + extension
        try:
            with open(path, "rb") as handle:
                debugPrint("Reading:", path)
                source = handle.read()
                return obtainModuleFromSource(source, recorder,
                                              path.decode('utf-8'))[0]
        except IOError:
            continue
    return None
예제 #3
0
def obtainModule(libraryPaths, recorder, filePath):
    for libraryPath in libraryPaths:
        path = rjoin(libraryPath, filePath)

        if path in moduleCache.cache:
            log.log(["import"],
                    u"Importing %s (cached)" % path.decode("utf-8"))
            return moduleCache.cache[path]

        log.log(["import"], u"Importing %s" % path.decode("utf-8"))
        code = tryExtensions(path, recorder)
        if code is None:
            continue
        # Cache.
        moduleCache.cache[path] = code
        return code
    else:
        log.log(["import", "error"],
                u"Failed to import from %s" % filePath.decode("utf-8"))
        debugPrint("Failed to import:", filePath)
        raise userError(u"Module '%s' couldn't be found" %
                        filePath.decode("utf-8"))
예제 #4
0
def obtainModule(libraryPaths, recorder, filePath):
    for libraryPath in libraryPaths:
        path = rjoin(libraryPath, filePath)

        if path in moduleCache.cache:
            log.log(["import"], u"Importing %s (cached)" %
                    path.decode("utf-8"))
            return moduleCache.cache[path]

        log.log(["import"], u"Importing %s" % path.decode("utf-8"))
        code = tryExtensions(path, recorder)
        if code is None:
            continue
        # Cache.
        moduleCache.cache[path] = code
        return code
    else:
        log.log(["import", "error"], u"Failed to import from %s" %
                filePath.decode("utf-8"))
        debugPrint("Failed to import:", filePath)
        raise userError(u"Module '%s' couldn't be found" %
                        filePath.decode("utf-8"))