\d>`dZddlmZddlmZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlZgdZeddZd e_d Zd Zdd Zd dZed!dZd!dZeejjedZGddZGddZ ddlZddlmZd!dZeeen #e $rYnwxYwdZ!d!dZ"dZ#dZ$dZ%dZ&da'dZ(dS)"zUtilities to support packages.) namedtuple)singledispatchN) ModuleType) get_importeriter_importers get_loader find_loader walk_packages iter_modulesget_data ImpImporter ImpLoader read_code extend_path ModuleInforzmodule_finder name ispkgz.A namedtuple with minimal info about a module.c |j}||S#t$r=||}|YdStj||cYSwxYw)z'Return the finder-specific module spec.N) find_specAttributeError find_module importlibutilspec_from_loader)findernamerloaders ..\python\lib\pkgutil.py _get_specrsy$ y ===##D)) >44~..tV<<<<< =s!A AAcddl}|d}|tjjkrdS|d||S)Nr )marshalreadrr MAGIC_NUMBERload)streamr!magics rrr(sRNNN KKNNE +++t KKOOO <<  c#Kifdt||D]}|V|jr t|jt t j|jddpg}fd|D}t||jdz|Ed{Vx#t$r|||jYt$r|||jnYwxYwdS)aYields ModuleInfo 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__+'.') c||vrdSd||<dS)NT)pms rseenzwalk_packages..seenRs 664!r'__path__Nc*g|]}| |Sr+r+).0r,r.s r z!walk_packages..is&777attAww7777r'.) r ispkg __import__rgetattrsysmodulesr ImportError Exception)pathprefixonerrorinfor.s @rr r 5sQ: T6**GG : G G49%%%s{495z4HHNB87774777(ty}gFFFFFFFFFF ' ' '&GDI&&&   &GDI&&&&'&   GGGsBC/CCc#K|t}n9t|trtdt t |}i}|D]4}t ||D]!\}}||vrd||<t|||V"5dS)aYields ModuleInfo 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. Nz9path must be None or list of paths to look for modules in)r isinstancestr ValueErrormapriter_importer_modulesr)r;r< importersyieldedirr4s rr r ns |"$$ D#  ,%&& & d++ G 110F;; 1 1KD%7"" !  D%00000 111r'cPt|dsgS||S)Nr )hasattrr )importerr<s rrErEs- 8^ , ,   ( ((r'c#K|j$tj|jsdSi}ddl} tj|j}n#t $rg}YnwxYw||D]}||}|dks||vr"tj|j|}d}|srtj|rSd|vrO|} tj|} n#t $rg} YnwxYw| D]!}||} | dkrd}n"|rd|vrd||<||z|fVdSNr__init__Fr3Tr@ r;osisdirinspectlistdirOSErrorsort getmodulenamejoin) rKr<rGrR filenamesfnmodnamer;r4 dircontentssubnames r_iter_file_finder_modulesr]s}BGMM(-$@$@GNNNJx}--  NN**''++ J  'W"4"4 w||HM2.. 27==.. 3b==G ! j..  ! ! !  !"  !//33J&& EE'  *s')) GG 7"E) ) ) )3**#A A A *C?? D Dctj5tjdtt jdaddddS#1swxYwYdS)Nignoreimp)warningscatch_warnings simplefilterDeprecationWarningr import_modulerar+r'r _import_imprgs  " "--h(:;;;%e,,------------------s/AAAc*eZdZdZddZddZddZdS) r aPEP 302 Finder that wraps Python's "classic" import algorithm ImpImporter(dirname) produces a PEP 302 finder that searches that directory. ImpImporter(None) produces a PEP 302 finder 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. Ncdtjdtt||_dSNz[This emulation is deprecated and slated for removal in Python 3.12; use 'importlib' instead)rbwarnrergr;)selfr;s rrNzImpImporter.__init__s5 @  ! ! !   r'c<|dd}||kr |jdS|jd}n%tj|jg} t||\}}}n#t $rYdSwxYwt||||S)Nr3)splitr;rPrealpathrarr9r)rlfullnamer;r\filefilenameetcs rrzImpImporter.find_modules..%%b) h  49#44 9 DDG$$TY//0D "%//'4"@"@ D(CC   44 43777sA;; B B r(c#K|j$tj|jsdSi}ddl} tj|j}n#t $rg}YnwxYw||D]}||}|dks||vr"tj|j|}d}|srtj|rSd|vrO|} tj|} n#t $rg} YnwxYw| D]!}||} | dkrd}n"|rd|vrd||<||z|fVdSrMrO) rlr<rGrRrXrYrZr;r4r[r\s rr zImpImporter.iter_moduless 9 BGMM$)$<$<  F  49--II   III   . .B++B//G ""g&8&87<< 2..DE rw}}T22 s"}}%"$*T"2"2KK%%%"$KKK%&B%33B77G ** $+ .3g--#$ w&----3 . .r^Nr()__name__ __module__ __qualname____doc__rNrr r+r'rr r sZ 8 8 8 8&.&.&.&.&.&.r'r c\eZdZdZdxZZdZdZdZdZ dZ dZ d d Z d d Z d Zd d ZdS)rzBPEP 302 Loader that wraps Python's "classic" import algorithm Nctjdtt||_||_||_||_dSrj)rbrkrergrrrsrqrt)rlrqrrrsrts rrNzImpLoader.__init__sI =( * * *       r'c| t||j|j|j}|jr|jn&#|jr|jwwxYw|Srv)_reopenra load_modulerrrsrtclose)rlrqmods rrzImpLoader.load_modules  "//(DIt}dhOOCy " !!!y " !!!! " s ,A###Bc~t|d5}|cdddS#1swxYwYdS)Nrb)openr")rlpathnamerrs rr zImpLoader.get_data's~ (D ! ! T99;;                  s 266c|jr{|jjrq|jd}|tjkrt |jd|_dS|tjtjfvr t |jd|_dSdSdSdS)Nrr) rrclosedrtra PY_SOURCErrs PY_COMPILED C_EXTENSION)rlmod_types rrzImpLoader._reopen+s 9 6) 6x{H&& 44 cos??? 55  6 6 6 6@?r'cd||j}n%||jkrtd|jd||S)NzLoader for module z cannot handle module )rqr9rlrqs r _fix_namezImpLoader._fix_name3sM  }HH  & &+-1]]]HHFGG Gr'cb||}|jdtjkSNr)rrtra PKG_DIRECTORYrs r is_packagezImpLoader.is_package;s'>>(++x{C---r'cF||}|j|jd}|tjkr1||}t ||jd|_n|tjkrf|  t|j |_|j nY#|j wxYw|tj kr+||_|jS)Nrexec)rcodertrar get_sourcecompilersrrrrrrr _get_delegateget_code)rlrqrsources rrzImpLoader.get_code?s>>(++ 9 x{H&&22#FDM6BB 3?** & )$) 4 4DIIOO%%%%DIOO%%%%3,,, ..0099;; ys CCc||}|jN|jd}|tjkrk| |j|_|jn#|jwxYw|tj kr{tj |j ddrNt|j ddd5}||_dddn #1swxYwYn;|tjkr+||_|jS)Nrrnr)rrrtrarrrrr"rrrPr;existsrsrrrr)rlrqrfs rrzImpLoader.get_sourcePse>>(++ ; x{H&& &"&).."2"2DKIOO%%%%DIOO%%%%3?**7>>$-"455/dmCRC0#66/!&'ffhh ///////////////3,,,"0022==?? {sBB#?D%%D),D)cXt|j}t|d}|jS)NrN)r rsrr)rlrspecs rrzImpLoader._get_delegatebs(T]++,,{r'c||}|jd}|tjkr&|S|tjtjtjfvr|j SdSr) rrtrarr get_filenamerrrrs)rlrqrs rrzImpLoader.get_filenamegso>>(++8A; S& & &%%''4466 6 #-#/J J J= tr'rv)rxryrzr{rrrNrr rrrrrrrr+r'rrr sD6   666..."$ r'r) zipimporterc#NKttj|j}|j}t |}i}ddl}|D]}||s||dtj }t |dkr?|ddr$|d|vrd||d<||dzdfVt |dkr| |d}|dkr|rd|vr||vrd||<||zdfVdS) Nrrr@z __init__.pyTrNr3F) sorted zipimport_zip_directory_cachearchiver<lenrR startswithrorPseprV) rKr<dirlist_prefixplenrGrRrYrZs riter_zipimport_modulesrusW78HIJJ/7|| . .B==)) DEE((B2wwzzbe..}==za5''%&GBqEN 2a5.$....2wwzz++BqE22G "" .3g--'2H2H#$ w&----) . .r'ctj|} tj|}n^#t$rQtjD]?} ||}tj||n#t$rY>xHH# h&&s++A.%h//sJ-- < F =       x!!4      !!r'c|tjvrtj|}|dSt|tr2|}t |dd}||St |dddS|j}n|}t |S)zGet a "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__. N __loader____spec__)r7r8rArr6rxr )module_or_namemodulerrqs rrrs$$^4  !4.*-- "t44  M 6:t , , 44?! x  r'c ~|dr$d|}t| tj|}nY#tt ttf$r9}d}t||t|||d}~wwxYw||j ndS)zFind a "loader" object for fullname This is a backwards compatibility wrapper around importlib.util.find_spec that converts most failures to ImportError and only returns the loader rather than the full spec r3rz,Error while finding loader for {!r} ({}: {})N) rrr9rrrr TypeErrorrCtyper)rqrrexs rr r s37>>xHH#F~''11 J ?FFF=#**XtBxx<<==2E F *4;;4sAB184B,,B1c 4t|ts|S|dz}|dd}|d\}}}|r2 tj|j}n%#t tf$r|cYSwxYwtj}|D]}t|tst|}|yg} t|dr!| |} | | j pg} n(t|dr||\}} | D]} | |vr|| t j||} t j| r t'| } | 5| D]D}|d}|r|dr/||E dddn #1swxYwYV#t,$r1}tjd| d |dYd}~d}~wwxYw|S) aExtend 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__) For each directory on sys.path that has a subdirectory that matches the package name, add the subdirectory to the package's __path__. 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). z.pkgNr3rr  #z Can't open z: )rAlistrr7r8r/rrr;rBrrJrsubmodule_search_locationsr appendrPrWisfilerrstriprrTstderrwrite)r;r sname_pkgparent_package_ final_name search_pathdirrportionsrportionpkgfilerliners rrrsB dD ! ! v I 7D$(OOC$8$8!NAz +n5>KK.)   KKK  h $*$*#s##  c""  Hv{++ ='' 33##>D"H// =$00<< 8# ) )$&&KK(((',,sI.. 7>>' " " * *MM ** !**#{{400#%ts';';%$ D)))) ****************  1 1 1    ")''333"011111111 1 * Ks=AA10A1%G6AG  G G  H"&HHc tj|}|dS|j}|t |dsdSt j|ptj |}|t |dsdS| d}| dtj |jtj j|}||S)afGet 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. Nr __file__/r)rrrrrJr7r8get _bootstrap_loadroinsertrPr;dirnamerrWr )packageresourcerrrparts resource_names rr r Xs, > # #G , ,D |t [F ~WVZ88~t ;??7 # # ,   % %d + + {'#z22{t NN3  E LLBGOOCL11222GL%(M ??= ) ))r'ct(ddl}d}|d|d|d|jat|}|st d||}|drItj |d }|d }|r| d ng}n| d }| d}tj |}|rN|d}|d |} tj | }| d| }n#t$rYnwxYw|N|} |D]}t| |} | S) a Resolve a name to an object. It is expected that `name` will be a string in one of the following formats, where W is shorthand for a valid Python identifier and dot stands for a literal period in these pseudo-regexes: W(.W)* W(.W)*:(W(.W)*)? The first form is intended for backward compatibility only. It assumes that some part of the dotted name is a package, and the rest is an object somewhere within that package, possibly nested inside other objects. Because the place where the package stops and the object hierarchy starts can't be inferred by inspection, repeated attempts to import must be done with this form. In the second form, the caller makes the division point clear through the provision of a single colon: the dotted name to the left of the colon is a package to be imported, and the dotted name to the right is the object hierarchy within that package. Only one import is needed in this form. If it ends with the colon, then a module object is returned. The function will return an object (which might be a module), or raise one of the following exceptions: ValueError - if `name` isn't in a recognised format ImportError - if an import failed when it shouldn't have AttributeError - if a failure occurred when traversing the object hierarchy within the imported package to get to the desired object. Nrz(?!\d)(\w+)(\.(?!\d)(\w+))*z ^(?Pz)(?P:(?Pz)?)?$zinvalid format: clnrobjr3) _NAME_PATTERNrerUNICODEmatchrC groupdictrrrfropopr9r6) rr dotted_wordsr-gdrrrZr,sresults r resolve_namersB 5  $K|$K$K7C$K$K$K#%://  D!!A 64D44555 B vve}}%bi00u $)1 C   r 3))A,,%g.. aA  Q  A -a00 !      F $$## Ms +E EE)Nr(N)Nr(rw))r{ collectionsr functoolsr simplegenericrimportlib.utilimportlib.machineryrPos.pathr7typesrrb__all__rrrr r rEr]register machinery FileFinderrgr rrrrr9rrrr rr rrr+r'rrs$$""""""555555     Z &@ A A E        6G6G6G6Gr11114))))&*&*&*&*P "$=???--- H.H.H.H.H.H.H.H.VaaaaaaaaH# %%%%%%....8"";0FGGGG   D 2!!!!:!!!0555*[[[|(*(*(*V GGGGGs$$C CC