home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyo (Python 2.5) from __future__ import with_statement import sys import path import StringIO import zipfile import util from contextlib import closing def zipopen(fpath, dirs = None, zip = None): fpath = path.path(fpath) if dirs is None: dirs = fpath.splitall() if dirs[0] == '\\\\': uncstart = dirs[0] hostname = dirs[1] sharename = dirs[2] rest = dirs[3:] dirs = [ uncstart + hostname + '\\' + sharename] + rest if not dirs: raise IOError('No such file or directory: %r' % fpath) if zip is None: nextdir = dirs.pop(0) if nextdir: curpath = fpath / nextdir else: curpath = fpath for ext in ('', '.zip', '.egg'): possible = curpath + ext if possible.exists(): if possible.isdir(): try: return zipopen(possible, dirs = dirs, zip = None) except IOError: pass except: None<EXCEPTION MATCH>IOError None<EXCEPTION MATCH>IOError if not dirs: return open(possible, 'rb') try: zip = zipfile.ZipFile(possible) except zipfile.BadZipfile: raise IOError('Could not open %r because %r is not a valid zip file' % (possible.joinpath(*dirs), curpath)) return zipopen(possible, dirs = dirs, zip = zip) continue else: raise IOError('No such file or directory: %r' % possible.joinpath(*dirs)) else: bytes = None curpath = fpath while dirs and bytes is None: nextdir = dirs.pop(0) curpath = curpath / nextdir for ext in ('', '.zip', '.egg'): possible = curpath + ext relpath = fpath.relpathto(curpath).replace('\\', '/') try: bytes = zip.read(relpath) continue except KeyError: continue continue continue None<EXCEPTION MATCH>KeyError if dirs and bytes: try: fobj = _[2] try: fobj = zipfile.ZipFile(fobj) except zipfile.BadZipfile: closing(StringIO.StringIO(bytes)) closing(StringIO.StringIO(bytes)) raise IOError('Could not open %r because %r was found inside a zip file but the embedded file is not the endpoint nor another zip file.' % (curpath.join(*dirs), curpath)) except: closing(StringIO.StringIO(bytes)) return zipopen(fpath, dirs = dirs, zip = fobj) finally: pass elif bytes: fobj = StringIO.StringIO(bytes) fobj.name = curpath return fobj else: raise IOError('No such file or directory %r' % curpath) def ext_importer(*exts): exts = list(exts) def wrapped1(f): def wrapped2(dotted, loadpath = (None, None)): pth = find_dotted_resource(dotted, exts, loadpath = loadpath) if pth is None: raise ImportError('%r was not found' % dotted) return f(pth) return wrapped2 return wrapped1 class YAMLModule(dict): def __init__(self, fname, d): self.__file__ = fname dict.__init__(self, d) def __getattr__(self, a): try: return dict.__getitem__(self, a) except KeyError: return dict.__getattribute__(self, a) def yaml_import(fname): import syck as yaml try: f = _[2] modulefier = (util.dictrecurse,)((lambda x: YAMLModule(fname, x))) raw_values = yaml.load(f) if not isinstance(raw_values, dict): val = dict(__content__ = raw_values) else: val = raw_values mod = modulefier(val) mod.__content__ = raw_values return mod finally: pass yaml_import = ext_importer('.yaml')(yaml_import) def file_import(fname, loadpath = None): try: (dotted_path, ext) = fname.rsplit('.', 1) ext = '.' + ext except ValueError: dotted_path = fname ext = '' pth = find_dotted_resource(dotted_path, exts = [ ext], loadpath = None, do_no_ext = False) if pth is None: raise ImportError('No file named %r was found' % fname) else: return zipopen(pth) def find_dotted_resource(dotted, exts = [], loadpath = None, do_no_ext = True): try: (pth, name) = dotted.rsplit('.', 1) except ValueError: pth = '' name = dotted if not '/' in pth or '\\' in pth: pth = pth.replace('.', '/') if loadpath is None: loadpath = sys.path if do_no_ext: exts = list(exts) + [ ''] else: exts = list(exts) for pathdir in map(path.path, loadpath): for ext in exts: if (pathdir / pth).isdir(): to_check = pathdir / pth / (name + ext) to_check = to_check.expand() if to_check.exists(): return to_check full = pathdir / pth / name + ext if full.exists(): try: try: f = _[2] return f.name finally: pass except IOError: continue except: None<EXCEPTION MATCH>IOError None<EXCEPTION MATCH>IOError if __name__ == '__main__': from pprint import pprint sys.path.append('c:\\workspace\\digsby\\') sys.path.insert(0, 'c:\\') netpath = path.path('\\\\mini\\mike\\test') sys.path.insert(0, netpath) print repr(yaml_import('test'))