Re*@sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZejeZdaGdddeZGdd d eZGd d d eZGd d d eZGdddeZGdddeZedee jeiZyRyddl Z!Wne"k rddl#Z!YnXeee!j$.allowedcs"g|]}|r|qSrr).0r%)rXrr s z0ResourceFinder.get_resources..)setr listdirr )rrr)rXrrr7szResourceFinder.get_resourcescCs|j|jS)N)rPr )rrrrrr5szResourceFinder.is_containerccs|j|}|dk r|g}x|r|jd}|V|jr'|j}xb|jD]W}|sr|}ndj||g}|j|}|jr|j|q]|Vq]Wq'WdS)NrrG)rQpopr5r+r8r append)rrKrtodornamer+new_namechildrrriterators        zResourceFinder.iteratorN)r;r<r=)r;r<)r'r(r)r4sysplatform startswithrWrrErNrOrrQr-r1r2r7r5 staticmethodr r rrPrcrrrrr9ws"           r9cseZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ S)ZipResourceFinderz6 Resource finder for resources in .zip files. cstt|j||jj}dt||_t|jdrY|jj|_nt j ||_t |j|_ dS)Nr_files) rrhrrCarchivelen prefix_lenhasattrri zipimport_zip_directory_cachesortedindex)rrArj)rrrrs zZipResourceFinder.__init__cCs|S)Nr)rr rrrrEszZipResourceFinder._adjust_pathc Cs||jd}||jkr+d}np|rQ|dtjkrQ|tj}tj|j|}y|j|j|}Wntk rd}YnX|stj d||j j ntj d||j j |S)NTrFz_find failed: %r %rz_find worked: %r %r) rlrir rLbisectrqrf IndexErrorloggerdebugrCr")rr r#irrrrOs    zZipResourceFinder._findcCs3|jj}|jdt|d}||fS)Nr)rCrjr rk)rrr"r rrrrs z ZipResourceFinder.get_cache_infocCs|jj|jS)N)rCget_datar )rrrrrr1szZipResourceFinder.get_bytescCstj|j|S)N)ioBytesIOr1)rrrrrr-szZipResourceFinder.get_streamcCs%|j|jd}|j|dS)N)r rlri)rrr rrrr2szZipResourceFinder.get_sizecCs|j|jd}|r<|dtjkr<|tj7}t|}t}tj|j|}xq|t|jkr|j|j|sP|j||d}|j |j tjdd|d7}qiW|S)Nrrrr) r rlr rLrkr[rsrqrfaddrI)rrr plenr#rwsrrrr7s    zZipResourceFinder.get_resourcesc Cs||jd}|r9|dtjkr9|tj7}tj|j|}y|j|j|}Wntk rd}YnX|S)NrFrr)rlr rLrsrqrfrt)rr rwr#rrrrPs   zZipResourceFinder._is_directory) r'r(r)r4rrErOrr1r-r2r7rPrr)rrrhs        rhcCs|tt|zUnable to locate finder for %r) _finder_cacherdmodules __import__rBrrr&r)packager#rAr rCrrrrr6s         r __dummy__cCswd}tj|tjj|}tjt|}|rst}tj j |d|_ ||_ ||}|S)z Return a resource finder for a path, which should represent a container. :param path: The path. :return: A :class:`ResourceFinder` instance for the path. Nr@) pkgutil get_importerrdpath_importer_cacher&rr _dummy_moduler r r r?r>)r r#rCrrArrrfinder_for_pathRs   r). __future__rrsryloggingr rshutilrdtypesrnr@rutilrrrr getLoggerr'rur/r objectr*r,r6r9rhr zipimporterr_frozen_importlib_externalZ_fi ImportError_frozen_importlibSourceFileLoader FileFinderAttributeErrorrrr ModuleTyper rrrrrrsH         ",!ZN