ž §ÿf#Tc @sÑdZddlZddlZddlZddlZddlZddlmZddlm Z ddddd d d d d ddg Z dd„Z dd„Z ddddd „Zdddd „Zddd„Ze eƒZddd„ZejejjeƒGdd „d ƒZGdd „d ƒZy?ddlZddlmZddd„ZejeeƒWnek rYnXdd„Zdd d„Zd!d„Zd"d„Zd#d„Zd$d „Z dS(%uUtilities to support packages.iN(uwarn(u ModuleTypeu get_importeruiter_importersu get_loaderu find_loaderu walk_packagesu iter_modulesuget_datau ImpImporteru ImpLoaderu read_codeu extend_pathcCsKddl}|jdƒ}|tjƒkr1dS|jdƒ|j|ƒS(Niii(umarshalureaduimpu get_magicuNoneuload(ustreamumarshalumagic((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu read_codes   c sƒi‰‡‡fdd†}yˆj|_Wnttfk rEYnXd‡‡fdd†‰ˆj|_ˆj|_ˆ|_|S(u/Make a trivial single-dispatch generic functioncsç|d}y |j}Wntk r7t|ƒ}YnXy |j}Wn`tk r§y0Gdd„d|tƒ}|jdd…}Wntk r¢tf}YnXYnXx8|D]#}|ˆkr¯ˆ|||ŽSq¯Wˆ||ŽSdS(NicBs|EeZdZdS(u+simplegeneric..wrapper..clsN(u__name__u __module__u __qualname__(u __locals__((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyucls+suclsi(u __class__uAttributeErrorutypeu__mro__uobjectu TypeError(uargsukwuobuclsumrout(ufuncuregistry(u,/opt/alt/python33/lib64/python3.3/pkgutil.pyuwrapper!s"        usimplegeneric..wrappercs-|dkr‡‡fdd†S|ˆˆ<|S(Ncs ˆˆ|ƒS(N((uf(uregisterutyp(u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu<su1simplegeneric..register..(uNone(utypufunc(uregisteruregistry(utypu,/opt/alt/python33/lib64/python3.3/pkgutil.pyuregister:s  usimplegeneric..registerN(u__name__u TypeErroruAttributeErroruNoneu__dict__u__doc__uregister(ufuncuwrapper((ufuncuregisteruregistryu,/opt/alt/python33/lib64/python3.3/pkgutil.pyu simplegenerics   u simplegenericuc#sidd„‰xþt||ƒD]í\}}}|||fV|ryt|ƒWnXtk r}|dk ry||ƒnYq tk rª|dk r£||ƒn‚Yq Xttj|ddƒpÇg}‡fdd†|Dƒ}x&t||d|ƒD] }|VqúWqqWdS(u½Yields (module_loader, name, ispkg) for all modules recursively on path, or, if path is None, all accessible modules. 'path' should be either None or a list of paths to look for modules in. 'prefix' is a string to output on the front of every module name on output. Note that this function must import all *packages* (NOT all modules!) on the given path, in order to access the __path__ attribute to find submodules. 'onerror' is a function which gets called with one argument (the name of the package which was being imported) if any exception occurs while trying to import a package. If no onerror function is supplied, ImportErrors are caught and ignored, while all other exceptions are propagated, terminating the search. Examples: # list all modules python can access walk_packages() # list all submodules of ctypes walk_packages(ctypes.__path__, ctypes.__name__+'.') cSs||krdSd||.seenu__path__cs"g|]}ˆ|ƒs|‘qS(((u.0up(useen(u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu zs u!walk_packages..u.N( u iter_modulesu __import__u ImportErroruNoneu Exceptionugetattrusysumodulesu walk_packages(upathuprefixuonerroruimporterunameuispkguitem((useenu,/opt/alt/python33/lib64/python3.3/pkgutil.pyu walk_packagesFs"     ccs‰|dkrtƒ}ntt|ƒ}i}xU|D]M}xDt||ƒD]3\}}||krJd||<|||fVqJqJWq4WdS(u&Yields (module_loader, name, ispkg) for all submodules on path, or, if path is None, all top-level modules on sys.path. 'path' should be either None or a list of paths to look for modules in. 'prefix' is a string to output on the front of every module name on output. iN(uNoneuiter_importersumapu get_importeruiter_importer_modules(upathuprefixu importersuyieldeduiunameuispkg((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu iter_modules€s     cCs t|dƒsgS|j|ƒS(Nu iter_modules(uhasattru iter_modules(uimporteruprefix((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyuiter_importer_modules™suiter_importer_modulesc cs™|jdks%tjj|jƒ r)dSi}ddl}ytj|jƒ}Wntk rkg}YnX|jƒx|D]}|j|ƒ}|dks}||kr°q}ntjj |j|ƒ}d}| rctjj|ƒrcd|krc|}ytj|ƒ} Wntk r&g} YnXx9| D]+}|j|ƒ} | dkr.d}Pq.q.Wq}n|r}d|kr}d||<|||fVq}q}WdS(Niu__init__u.iFT( upathuNoneuosuisdiruinspectulistdiruOSErrorusortu getmodulenameujoinuFalseuTrue( uimporteruprefixuyieldeduinspectu filenamesufnumodnameupathuispkgu dircontentsusubname((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu_iter_file_finder_modules¡s<%     %     u_iter_file_finder_modulescBsG|EeZdZdZd dd„Zd dd„Zddd„Zd S( u ImpImporteru…PEP 302 Importer that wraps Python's "classic" import algorithm ImpImporter(dirname) produces a PEP 302 importer that searches that directory. ImpImporter(None) produces a PEP 302 importer that searches the current sys.path, plus any modules that are frozen or built-in. Note that ImpImporter does not currently support being used by placement on sys.meta_path. cCstdtƒ||_dS(Nu5This emulation is deprecated, use 'importlib' instead(uwarnuDeprecationWarningupath(uselfupath((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu__init__×suImpImporter.__init__cCs­|jdƒd}||kr2|jdkr2dS|jdkrJd}ntjj|jƒg}ytj||ƒ\}}}Wntk r™dSYnXt||||ƒS(Nu.iiÿÿÿÿ( usplitupathuNoneuosurealpathuimpu find_moduleu ImportErroru ImpLoader(uselfufullnameupathusubnameufileufilenameuetc((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu find_moduleÜs   uImpImporter.find_moduleuc cs™|jdks%tjj|jƒ r)dSi}ddl}ytj|jƒ}Wntk rkg}YnX|jƒx|D]}|j|ƒ}|dks}||kr°q}ntjj |j|ƒ}d}| rctjj|ƒrcd|krc|}ytj|ƒ} Wntk r&g} YnXx9| D]+}|j|ƒ} | dkr.d}Pq.q.Wq}n|r}d|kr}d||<|||fVq}q}WdS(Niu__init__u.iFT( upathuNoneuosuisdiruinspectulistdiruOSErrorusortu getmodulenameujoinuFalseuTrue( uselfuprefixuyieldeduinspectu filenamesufnumodnameupathuispkgu dircontentsusubname((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu iter_modulesës<%     %     uImpImporter.iter_modulesN(u__name__u __module__u __qualname__u__doc__uNoneu__init__u find_moduleu iter_modules(u __locals__((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu ImpImporterÌs cBs¥|EeZdZdZdZZdd„Zdd„Zdd„Z dd „Z d d „Z d d „Z ddd„Z ddd„Zdd„Zddd„ZdS(u ImpLoaderuBPEP 302 Loader that wraps Python's "classic" import algorithm cCs5tdtƒ||_||_||_||_dS(Nu5This emulation is deprecated, use 'importlib' instead(uwarnuDeprecationWarningufileufilenameufullnameuetc(uselfufullnameufileufilenameuetc((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu__init__s    uImpLoader.__init__c CsP|jƒz%tj||j|j|jƒ}Wd|jrK|jjƒnX|S(N(u_reopenuimpu load_moduleufileufilenameuetcuclose(uselfufullnameumod((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu load_module!s  % uImpLoader.load_modulecCs&t|dƒ}|jƒSWdQXdS(Nurb(uopenuread(uselfupathnameufile((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyuget_data,suImpLoader.get_datacCs€|jr||jjr||jd}|tjkrIt|jdƒ|_q||tjtjfkr|t|jdƒ|_q|ndS(Niururb( ufileucloseduetcuimpu PY_SOURCEuopenufilenameu PY_COMPILEDu C_EXTENSION(uselfumod_type((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu_reopen0s  uImpLoader._reopencCsG|dkr|j}n+||jkrCtd|j|fƒ‚n|S(Nu,Loader for module %s cannot handle module %s(uNoneufullnameu ImportError(uselfufullname((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu _fix_name8s   uImpLoader._fix_namecCs#|j|ƒ}|jdtjkS(Ni(u _fix_nameuetcuimpu PKG_DIRECTORY(uselfufullname((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu is_package@suImpLoader.is_packagec CsØ|j|ƒ}|jdkrÑ|jd}|tjkrd|j|ƒ}t||jdƒ|_qÑ|tj kr§|j ƒzt |j ƒ|_Wd|j j ƒXqÑ|tjkrÑ|jƒjƒ|_qÑn|jS(Niuexec(u _fix_nameucodeuNoneuetcuimpu PY_SOURCEu get_sourceucompileufilenameu PY_COMPILEDu_reopenu read_codeufileucloseu PKG_DIRECTORYu _get_delegateuget_code(uselfufullnameumod_typeusource((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyuget_codeDs  uImpLoader.get_codec Cs|j|ƒ}|jdkr|jd}|tjkrn|jƒz|jjƒ|_Wd|jj ƒXq|tj kr×t j j |jdd…ƒrþt|jdd…dƒ}|jƒ|_|j ƒqþq|tjkr|jƒjƒ|_qn|jS(Niiuriÿÿÿÿiÿÿÿÿ(u _fix_nameusourceuNoneuetcuimpu PY_SOURCEu_reopenufileureaducloseu PY_COMPILEDuosupathuexistsufilenameuopenu PKG_DIRECTORYu _get_delegateu get_source(uselfufullnameumod_typeuf((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu get_sourceUs   uImpLoader.get_sourcecCst|jƒjdƒS(Nu__init__(u ImpImporterufilenameu find_module(uself((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu _get_delegateisuImpLoader._get_delegatecCsd|j|ƒ}|jd}|tjkr;|jƒjƒS|tjtjtjfkr`|j SdS(Ni( u _fix_nameuetcuimpu PKG_DIRECTORYu _get_delegateu get_filenameu PY_SOURCEu PY_COMPILEDu C_EXTENSIONufilenameuNone(uselfufullnameumod_type((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu get_filenamels uImpLoader.get_filenameN(u__name__u __module__u __qualname__u__doc__uNoneucodeusourceu__init__u load_moduleuget_datau_reopenu _fix_nameu is_packageuget_codeu get_sourceu _get_delegateu get_filename(u __locals__((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu ImpLoaders       (u zipimporterc csRttj|jƒ}|j}t|ƒ}i}ddl}x|D]}|j|ƒs_qDn||d…jt j ƒ}t|ƒdkrÓ|djdƒrÓ|d|krÓd||d<|ddfVqÓnt|ƒdkrëqDn|j |dƒ}|dkrqDn|rDd|krD||krDd||<||dfVqDqDWdS( Niiiu __init__.pyu__init__u.TF(usortedu zipimportu_zip_directory_cacheuarchiveuprefixulenuinspectu startswithusplituosusepuTrueu getmodulenameuFalse( uimporteruprefixudirlistu_prefixuplenuyieldeduinspectufnumodname((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyuiter_zipimport_moduleszs*    %  uiter_zipimport_modulescCs}ytj|}Wnetk rxxPtjD]?}y$||ƒ}tjj||ƒPWq+tk riYq+Xq+Wd}YnX|S(u Retrieve a PEP 302 importer for the given path item The returned importer is cached in sys.path_importer_cache if it was newly created by a path hook. The cache (or part of it) can be cleared manually if a rescan of sys.path_hooks is necessary. N(usysupath_importer_cacheuKeyErroru path_hooksu setdefaultu ImportErroruNone(u path_itemuimporteru path_hook((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu get_importerœs      ccsÂ|jdƒr-dj|ƒ}t|ƒ‚nd|kr€|jdƒd}tj|ƒ}t|ddƒ}|dkr¢dSn"xtj D] }|VqŠWtj }x|D]}t |ƒVq©WdS(uÉYield PEP 302 importers for the given module name If fullname contains a '.', the importers will be for the package containing fullname, otherwise they will be all registered top level importers (i.e. those on both sys.meta_path and sys.path_hooks). If the named module is in a package, that package is imported as a side effect of invoking this function. If no module name is specified, all top level importers are produced. u.u'Relative module name {!r} not supportediu__path__N( u startswithuformatu ImportErroru rpartitionu importlibu import_moduleugetattruNoneusysu meta_pathupathu get_importer(ufullnameumsgupkg_nameupkgupathuimporteruitem((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyuiter_importers´s      cCsr|tjkrtj|}nt|tƒrb|}t|ddƒ}|dk rV|S|j}n|}t|ƒS(uGet a PEP 302 "loader" object for module_or_name Returns None if the module cannot be found or imported. If the named module is not already imported, its containing package (if any) is imported, in order to establish the package __path__. u __loader__N(usysumodulesu isinstanceu ModuleTypeugetattruNoneu__name__u find_loader(umodule_or_nameumoduleuloaderufullname((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu get_loaderÑs  cCsö|jdƒr-dj|ƒ}t|ƒ‚nd}|jdƒd}|r€tj|ƒ}t|ddƒ}|dkr€dSnytj||ƒSWn[tt t t fk rñ}z/d}t|j|t |ƒ|ƒƒ|‚WYdd}~XnXdS(u#Find a PEP 302 "loader" object for fullname This is s convenience wrapper around :func:`importlib.find_loader` that sets the *path* argument correctly when searching for submodules, and also ensures parent packages (if any) are imported before searching for submodules. u.u'Relative module name {!r} not supportediu__path__u,Error while finding loader for {!r} ({}: {})N( u startswithuformatu ImportErroruNoneu rpartitionu importlibu import_moduleugetattru find_loaderuAttributeErroru TypeErroru ValueErrorutype(ufullnameumsgupathupkg_nameupkguex((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu find_loaderås cCsþt|tƒs|S|d}|dd…}|jdƒ\}}}|rytj|j}WqŠttfk r}|SYqŠXn tj}xm|D]e}t|t ƒs¬q‘nt |ƒ}|dk r't |dƒrë|j |ƒ\} } n d} g} x-| D]"} | |krþ|j| ƒqþqþWntjj||ƒ} tjj| ƒr‘yt| ƒ} Wn?tk rŸ}ztjjd| |fƒWYdd}~XqöXxF| D]>}|jdƒ}| s§|jdƒrØq§n|j|ƒq§W| jƒq‘q‘W|S(u‹Extend a package's path. Intended use is to place the following code in a package's __init__.py: from pkgutil import extend_path __path__ = extend_path(__path__, __name__) This will add to the package's __path__ all subdirectories of directories on sys.path named after the package. This is useful if one wants to distribute different parts of a single logical package as multiple directories. It also looks for *.pkg files beginning where * matches the name argument. This feature is similar to *.pth files (see site.py), except that it doesn't special-case lines starting with 'import'. A *.pkg file is trusted at face value: apart from checking for duplicates, all entries found in a *.pkg file are added to the path, regardless of whether they are exist the filesystem. (This is a feature.) If the input path is not a list (as is the case for frozen packages) it is returned unchanged. The input path is not modified; an extended copy is returned. Items are only appended to the copy at the end. It is assumed that sys.path is a sequence. Items of sys.path that are not (unicode or 8-bit) strings referring to existing directories are ignored. Unicode items of sys.path that cause errors when used as filenames may cause this function to raise an exception (in line with os.path.isdir() behavior). u.pkgNu.u find_loaderuCan't open %s: %s u u#(u isinstanceulistu rpartitionusysumodulesu__path__uKeyErroruAttributeErrorupathustru get_importeruNoneuhasattru find_loaderuappenduosujoinuisfileuopenuIOErrorustderruwriteurstripu startswithuclose(upathunameu sname_pkguparent_packageu_u final_nameu search_pathudirufinderuloaderuportionsuportionupkgfileufumsguline((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyu extend_pathsJ!         ! cCsºt|ƒ}|dks(t|dƒ r,dStjj|ƒpJ|j|ƒ}|dksit|dƒ rmdS|jdƒ}|jdt j j |j ƒƒt j j |Œ}|j|ƒS(ufGet a resource from a package. This is a wrapper round the PEP 302 loader get_data API. The package argument should be the name of a package, in standard module format (foo.bar). The resource argument should be in the form of a relative filename, using '/' as the path separator. The parent directory name '..' is not allowed, and nor is a rooted name (starting with a '/'). The function returns a binary string, which is the contents of the specified resource. For packages located in the filesystem, which have already been imported, this is the rough equivalent of d = os.path.dirname(sys.modules[package].__file__) data = open(os.path.join(d, resource), 'rb').read() If the package cannot be located or loaded, or it uses a PEP 302 loader which does not support get_data(), then None is returned. uget_datau__file__u/iN(u get_loaderuNoneuhasattrusysumodulesugetu load_moduleusplituinsertuosupathudirnameu__file__ujoinuget_data(upackageuresourceuloaderumodupartsu resource_name((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyuget_data]s !(!u__doc__uosusysu importlibuimpuos.pathuwarningsuwarnutypesu ModuleTypeu__all__u read_codeu simplegenericuNoneu walk_packagesu iter_modulesuiter_importer_modulesu_iter_file_finder_modulesuregisteru machineryu FileFinderu ImpImporteru ImpLoaderu zipimportu zipimporteruiter_zipimport_modulesu ImportErroru get_importeruiter_importersu get_loaderu find_loaderu extend_pathuget_data(((u,/opt/alt/python33/lib64/python3.3/pkgutil.pyusD        (: (Hb      \