U e5dS @stddlmZddlmZddlZddlZddlZddlZddl Zddl Z ddl m Z ddl Z ddddd d d d d dddg ZeddZde_ddZddZd*dd Zd+dd Zed,ddZd-ddZeejjeddZGdd d ZGd d d Zz.ddlZdd!lmZd.d"d#ZeeeWne k r<YnXd$dZ!d/d%dZ"d&dZ#d'dZ$d(dZ%d)d Z&dS)0) namedtuple)singledispatchN) ModuleType get_importeriter_importers get_loader find_loader walk_packages iter_modulesget_data ImpImporter ImpLoader read_code extend_path ModuleInfozmodule_finder name ispkgz.A namedtuple with minimal info about a module.cCsRz |j}Wn:tk rD||}|dkr2YdStj||YSX||SdSN) find_specAttributeError find_module importlibutilspec_from_loader)findernamerloaderr/usr/lib64/python3.8/pkgutil.py _get_specs  rcCs6ddl}|d}|tjjkr"dS|d||S)Nr )marshalreadrr MAGIC_NUMBERload)streamr magicrrrr(s    c #sifddt||D]}|V|jrzt|jWnNtk rZ|dk rV||jYqtk r|dk r|||jnYqXttj|jddpg}fdd|D}t ||jd|EdHqdS)NcSs||kr dSd||<dS)NTr)pmrrrseenRszwalk_packages..seen__path__csg|]}|s|qSrr).0r'r)rr isz!walk_packages...) r ispkg __import__r ImportError Exceptiongetattrsysmodulesr )pathprefixonerrorinforr,rr 5s   ccsr|dkrt}nt|tr$tdn tt|}i}|D]6}t||D]&\}}||krDd||<t|||VqDq6dS)Nz9path must be None or list of paths to look for modules in)r isinstancestr ValueErrormapriter_importer_modulesr)r6r7Z importersyieldedirr/rrrr ns    cCst|dsgS||S)Nr )hasattrr )importerr7rrrr?s r?c cs$|jdkstj|jsdSi}ddl}zt|j}Wntk rPg}YnX||D]}||}|dks^||kr~q^tj|j|}d}|stj|rd|kr|}zt|} Wntk rg} YnX| D]}||} | dkrd}qqq^|r^d|kr^d||<|||fVq^dSNr__init__Fr.Tr: r6osisdirinspectlistdirOSErrorsort getmodulenamejoin) rCr7r@rI filenamesfnmodnamer6r/ dircontentssubnamerrr_iter_file_finder_moduless<     rTc Cs.ttdttdaW5QRXdS)Nignoreimp)warningscatch_warnings simplefilterDeprecationWarningr import_modulerVrrrr _import_imps  r\c@s*eZdZd ddZd ddZd ddZdS) r NcCstdtt||_dSNz5This emulation is deprecated, use 'importlib' instead)rWwarnrZr\r6)selfr6rrrrEs zImpImporter.__init__cCs|dd}||kr$|jdkr$dS|jdkr4d}ntj|jg}zt||\}}}Wntk rpYdSXt||||S)Nr.)splitr6rGrealpathrVrr1r )r_fullnamer6rSfilefilenameetcrrrrs zImpImporter.find_moduler&c cs$|jdkstj|jsdSi}ddl}zt|j}Wntk rPg}YnX||D]}||}|dks^||kr~q^tj|j|}d}|stj|rd|kr|}zt|} Wntk rg} YnX| D]}||} | dkrd}qqq^|r^d|kr^d||<|||fVq^dSrDrF) r_r7r@rIrOrPrQr6r/rRrSrrrr s<     zImpImporter.iter_modules)N)N)r&)__name__ __module__ __qualname__rErr rrrrr s  c@sjeZdZdZZddZddZddZdd Zd d Z d d Z dddZ dddZ ddZ dddZdS)r NcCs.tdtt||_||_||_||_dSr])rWr^rZr\rdrercrf)r_rcrdrerfrrrrEszImpLoader.__init__cCs:|zt||j|j|j}W5|jr4|jX|Sr)_reopenrdcloserV load_modulererf)r_rcmodrrrrls  zImpLoader.load_modulec Cs*t|d}|W5QRSQRXdS)Nrb)openr!)r_pathnamerdrrrr %s zImpLoader.get_datacCsT|jrP|jjrP|jd}|tjkr2t|jd|_n|tjtjfkrPt|jd|_dS)Nrrn) rdclosedrfrV PY_SOURCErore PY_COMPILED C_EXTENSION)r_mod_typerrrrj)s   zImpLoader._reopencCs0|dkr|j}n||jkr,td|j|f|S)Nz,Loader for module %s cannot handle module %s)rcr1r_rcrrr _fix_name1s zImpLoader._fix_namecCs||}|jdtjkSNrq)ryrfrV PKG_DIRECTORYrxrrr is_package9s zImpLoader.is_packagecCs||}|jdkr|jd}|tjkrD||}t||jd|_nJ|tjkrv| zt |j |_W5|j Xn|tj kr||_|jS)Nrqexec)rycoderfrVrt get_sourcecompilererurjrdrkrr{ _get_delegateget_code)r_rcrwsourcerrrr=s       zImpLoader.get_codec Cs||}|jdkr|jd}|tjkrP|z|j|_W5|jXnd|tj krt j |j ddrt|j ddd}||_W5QRXn|tjkr||_|jS)Nrqr`rr)ryrrfrVrtrjrdrkr!rurGr6existsreror{rr)r_rcrwfrrrrNs      zImpLoader.get_sourcecCst|j}t|d}|jS)NrE)r rerr)r_rspecrrrr`s  zImpLoader._get_delegatecCsH||}|jd}|tjkr*|S|tjtjtjfkrD|j SdSrz) ryrfrVr{r get_filenamertrurvre)r_rcrwrrrres    zImpLoader.get_filename)N)N)N)rgrhrir~rrErlr rjryr|rrrrrrrrr s    ) zipimporterc csttj|j}|j}t|}i}ddl}|D]}||s>q.||dt j }t|dkr|ddr|d|krd||d<||ddfVt|dkrq.| |d}|dkrq.|r.d|kr.||kr.d||<||dfVq.dS) Nrrqr:z __init__.pyTrEr.F) sorted zipimport_zip_directory_cachearchiver7lenrI startswithrarGseprM) rCr7Zdirlist_prefixZplenr@rIrPrQrrriter_zipimport_modulesss*    rc Csxt|}ztj|}WnZtk rrtjD]:}z ||}tj||WqnWq.tk rfYq.Xq.d}YnX|Sr)rGfsdecoder4path_importer_cacheKeyError path_hooks setdefaultr1)Z path_itemrC path_hookrrrrs    ccs|drd|}t|d|krV|dd}t|}t|dd}|dkrhdSntjEdHtj }|D]}t |VqldS)Nr.'Relative module name {!r} not supportedrr*) rformatr1 rpartitionrr[r3r4 meta_pathr6r)rcmsgZpkg_nameZpkgr6itemrrrrs     cCsn|tjkr tj|}|dkr dSt|trb|}t|dd}|dk rF|St|dddkrZdS|j}n|}t|S)N __loader____spec__)r4r5r;rr3rgr)Zmodule_or_namemodulerrcrrrrs    c Cs|drd|}t|ztj|}WnFttttfk rr}z d}t||t |||W5d}~XYnX|dk r|j SdS)Nr.rz,Error while finding loader for {!r} ({}: {})) rrr1rrrr TypeErrorr=typer)rcrrZexrrrrs  *c Cst|ts|S|d}|dd}|d\}}}|rfztj|j}Wqlttfk rb|YSXntj}|D]&}t|t sqpt |}|dk rg} t |dr| |} | dk r| j pg} nt |dr||\}} | D]} | |kr|| qtj||} tj| rpz t| } Wn8tk rP}ztjd| |fW5d}~XYqpX| <| D]0}|d}|r\|drq\||q\W5QRXqp|S)Nz.pkgr.rrzCan't open %s: %s  #)r;listrr4r5r*rrr6r<rrBrsubmodule_search_locationsrappendrGrNisfilerorKstderrwriterstripr)r6rZ sname_pkgZparent_package_Z final_nameZ search_pathdirrportionsrZportionZpkgfilerrlinerrrrsR!             cCstj|}|dkrdS|j}|dks0t|ds4dStj|pJtj |}|dks^t|dsbdS| d}| dt j |jt j j|}||S)Nr __file__/r)rrrrrBr4r5get _bootstrap_loadrainsertrGr6dirnamerrNr )packageresourcerrrmpartsZ resource_namerrrr Vs     )Nr&N)Nr&)r&)r&)r&)r&)' collectionsr functoolsrZ simplegenericrimportlib.utilimportlib.machineryrGZos.pathr4typesrrW__all__r__doc__rrr r r?rTregister machinery FileFinderr\r r rrrr1rrrrrr rrrrsf     9   (Jc   ^