def makeresource(name, xtrapath=None): """Factory function that returns a resource subclass. NAME is the logical or physical name of a resource. XTRAPTH is a path or list of paths to search first. return one of the resource subclasses. Warning - logical names can conflict; archive might return a directory, when the module archive.py was desired.""" typ, nm, fullname = finder.identify(name, xtrapath) fullname = os.path.normpath(fullname) if _cache.has_key(fullname): return _cache[fullname] elif typ in (finder.SCRIPT, finder.GSCRIPT): rsrc = scriptresource(nm, fullname) elif typ == finder.MODULE: rsrc = moduleresource(nm, fullname) elif typ == finder.PACKAGE: rsrc = pkgresource(nm, fullname) elif typ in (finder.PBINARY, finder.BINARY): rsrc = binaryresource(nm, fullname) elif typ == finder.ZLIB: rsrc = zlibresource(nm, fullname) elif typ == finder.DIRECTORY: rsrc = dirresource(nm, fullname) else: try: carchive.CArchive(fullname) except: rsrc = dataresource(nm, fullname) else: rsrc = archiveresource(nm, fullname) _cache[fullname] = rsrc return rsrc
def makeresource(name, xtrapath=None): """Factory function that returns a resource subclass. NAME is the logical or physical name of a resource. XTRAPTH is a path or list of paths to search first. return one of the resource subclasses. Warning - logical names can conflict; archive might return a directory, when the module archive.py was desired.""" typ, nm, fullname = finder.identify(name, xtrapath) fullname = os.path.normpath(fullname) if fullname in _cache: return _cache[fullname] elif typ in (finder.SCRIPT, finder.GSCRIPT): rsrc = scriptresource(nm, fullname) elif typ == finder.MODULE: rsrc = moduleresource(nm, fullname) elif typ == finder.PACKAGE: rsrc = pkgresource(nm, fullname) elif typ in (finder.PBINARY, finder.BINARY): rsrc = binaryresource(nm, fullname) elif typ == finder.ZLIB: rsrc = zlibresource(nm, fullname) elif typ == finder.DIRECTORY: rsrc = dirresource(nm, fullname) else: try: carchive.CArchive(fullname) except: rsrc = dataresource(nm, fullname) else: rsrc = archiveresource(nm, fullname) _cache[fullname] = rsrc return rsrc
def makefilter(name, xtrapath=None): typ, nm, fullname = finder.identify(name, xtrapath) if typ in (finder.SCRIPT, finder.GSCRIPT, finder.MODULE): return ModFilter([os.path.splitext(nm)[0]]) if typ == finder.PACKAGE: return PkgFilter([fullname]) if typ == finder.DIRECTORY: return DirFilter([fullname]) if typ in (finder.BINARY, finder.PBINARY): return FileFilter([nm]) return FileFilter([fullname])