a „oe@ã@spdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddlmZmZmZmZmZmZmZmZmZmZmZmZddlmZdd lmZdd lmZd d l m!Z"d d l#m$Z$erøddl%m&Z&ddl'm(Z(ddl)m*Z*e j+Z,ee-ej.fZ/edƒZ0eddd�Z1Gdd„dƒZ2dOee-ee/ee-dœdd„Z3dPee-e4ee/fe-dœdd„Z5ee/ee/dœdd„Z6ee4e/fe-dœd d!„Z7e/e-d"œd#d$„Z8dQe-eee-e-fee/d%œd&d'„Z9e-ee/e d(œd)d*„Z:e e-ed+œd,d-„Z;e-eee-e-fe/ee/ee-e-fd.œd/d0„Zdddd7œeee-e-fee/ee-d8œd9d:„Z?e/e/e-d;œdœd?d@„ZBeCeCdAœdBdC„ZDdTeeEeCfee/eee-ee-fdDœdEdF„ZFdUe-ee-eCfdHœdIdJ„ZGGdKdL„dLƒZHGdMdN„dNee0e1fƒZIdS)VaiUtility functions to expand configuration directives or special values (such glob patterns). We can split the process of interpreting configuration files into 2 steps: 1. The parsing the file contents from strings to value objects that can be understand by Python (for example a string with a comma separated list of keywords into an actual Python list of strings). 2. The expansion (or post-processing) of these values according to the semantics ``setuptools`` assign to them (for example a configuration field with the ``file:`` directive should be expanded from a list of file paths to a single string with the contents of those files concatenated) This module focus on the second step, and therefore allow sharing the expansion functions among several configuration file formats. **PRIVATE MODULE**: API reserved for setuptools internal usage only. éN)Úiglob)Ú ConfigParser)Ú ModuleSpec)Úchain) Ú TYPE_CHECKINGÚCallableÚDictÚIterableÚIteratorÚListÚMappingÚOptionalÚTupleÚTypeVarÚUnionÚcast)ÚPath)Ú ModuleType)ÚDistutilsOptionErroré)Ú same_path)ÚSetuptoolsWarning)Ú Distribution)ÚConfigDiscovery)ÚDistributionMetadataÚ_KÚ_VT)Ú covariantc@sFeZdZdZeedœdd„Zeee j e j fdœdd„Z dd „Z d S) Ú StaticModulez>Proxy to a module object that avoids executing arbitrary code.)ÚnameÚspeccCs.t t |j¡ ¡¡}t|ƒ tƒ¡|` dS©N) ÚastÚparseÚpathlibrÚoriginÚ read_bytesÚvarsÚupdateÚlocalsÚself)r*rr Úmodule©r,ú9C:\Program Files\Certbot\pkgs\setuptools\config\expand.pyÚ__init__AszStaticModule.__init__©Úreturnc#sZ|jjD]L‰tˆtjƒr4‡fdd„ˆjDƒEdHqtˆtjƒrˆjrˆjˆjfVqdS)Nc3s|]}|ˆjfVqdSr!©Úvalue)Ú.0Útarget©Z statementr,r-Ú Ióz1StaticModule._find_assignments..) r+ÚbodyÚ isinstancer"ZAssignÚtargetsZ AnnAssignr2r4©r*r,r5r-Ú_find_assignmentsFs   zStaticModule._find_assignmentsc s\zt‡fdd„| ¡DƒƒWStyV}z"t|j›dˆ›�ƒ|‚WYd}~n d}~00dS)zHAttempt to load an attribute "statically", via :func:`ast.literal_eval`.c3s2|]*\}}t|tjƒr|jˆkrt |¡VqdSr!)r9r"ÚNameÚidZ literal_eval)r3r4r2©Úattrr,r-r6Psþz+StaticModule.__getattr__..z has no attribute N)Únextr<Ú ExceptionÚAttributeErrorr)r*r@Úer,r?r-Ú __getattr__Ms  þ zStaticModule.__getattr__N) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ústrrr.r rr"ZASTr<rEr,r,r,r-r>sr)ÚpatternsÚroot_dirr0c sšhd£}g}ˆpt ¡‰|D]x‰t‡fdd„|Dƒƒrrtj tj ˆˆ¡¡}| t‡fdd„t|dd�Dƒƒ¡qtj  ˆˆ¡  tj d¡}|  |¡q|S)aExpand the list of glob patterns, but preserving relative paths. :param list[str] patterns: List of glob patterns :param str root_dir: Path to which globs should be relative (current directory by default) :rtype: list >Ú*ú]ú?Ú}ú[Ú{c3s|]}|ˆvVqdSr!r,)r3Úcharr1r,r-r6hr7z glob_relative..c3s&|]}tj |ˆ¡ tjd¡VqdS)ú/N)ÚosÚpathÚrelpathÚreplaceÚsep©r3rV©rLr,r-r6lsÿT)Ú recursiverT) rUÚgetcwdÚanyrVÚabspathÚjoinÚextendÚsortedrrWrXrYÚappend)rKrLZglob_charactersZexpanded_valuesZ glob_pathrVr,)rLr2r-Ú glob_relativeYs    þÿ  rd)Ú filepathsr0csRddlm}tj ˆpt ¡¡‰‡fdd„||ƒDƒ}d ‡fdd„t|ƒDƒ¡S)zËReturn the content of the files concatenated using `` `` as str This function is sandboxed and won't reach anything outside ``root_dir`` (By default ``root_dir`` is the current directory). r)Úalways_iterablec3s|]}tj ˆ|¡VqdSr!)rUrVr`rZr[r,r-r6„r7zread_files..Ú c3s |]}t|ˆƒrt|ƒVqdSr!)Ú _assert_localÚ _read_filerZr[r,r-r6…s þ)Ú setuptools.extern.more_itertoolsrfrUrVr_r]r`Ú_filter_existing_files)rerLrfZ _filepathsr,r[r-Ú read_fileszs  þrlccs4|D]*}tj |¡r|Vqt d|›d�¡qdS)NzFile z cannot be found)rUrVÚisfilerÚemit)rerVr,r,r-rkŒs rk)Úfilepathr0cCs8t|dd��}| ¡WdƒS1s*0YdS)Nzutf-8)Úencoding)ÚopenÚread)roÚfr,r,r-ri”sri)rorLcCs@ttj |¡ƒttj |¡ƒjvr.) r{ÚrsplitÚlenrUrVr`rrrA) r�rxrLÚ parent_pathZ module_partsZ custom_pathÚpartsÚ parent_moduleZ path_startZ candidatesr„r,r,r-r}Ûs(       þr})Úqualified_class_namerxrLr0c Cs^|p t ¡}| d¡}||dd…}|d|…}t|||ƒ\}}}tt||ƒ|ƒ} t| |ƒS)z@Given a qualified class name, return the associated class objectryr�N)rUr]Úrfindr}r€r~r) r˜rxrLÚidxÚ class_nameÚpkg_namer‚rVr�r+r,r,r-Ú resolve_classýs   r�)ÚvaluesrxrLr0cs‡‡fdd„| ¡DƒS)z‡Given a dictionary mapping command names to strings for qualified class names, apply :func:`resolve_class` to the dict values. csi|]\}}|t|ˆˆƒ“qSr,)r�©r3ÚkÚv©rxrLr,r-Ú r7zcmdclass..)Úitems)ržrxrLr,r¢r-Úcmdclass sr¥)Ú namespacesÚfill_package_dirrL)r§rLr0c  sddlm}ddlm}m}|r.ddlm}n ddlm}|pBtj}|  ddg¡}g} |durbin|}t |||ƒƒƒ‰t ˆƒd kr¬t ‡fd d „d|fDƒƒr¬|  d ˆd¡ˆD]Z} t|| ƒ} |j| fi|¤Ž} |  | ¡| r°| d ¡| ks°tj | |¡s°| || | ƒ¡q°| S) aWorks similarly to :func:`setuptools.find_packages`, but with all arguments given as keyword arguments. Moreover, ``where`` can be given as a list (the results will be simply concatenated). When the additional keyword argument ``namespaces`` is ``True``, it will behave like :func:`setuptools.find_namespace_packages`` (i.e. include implicit namespaces as per :pep:`420`). The ``where`` argument will be considered relative to ``root_dir`` (or the current working directory when ``root_dir`` is not given). If the ``fill_package_dir`` argument is passed, this function will consider it as a similar data structure to the ``package_dir`` configuration parameter add fill-in any missing package location. :rtype: list r)Úconstruct_package_dir)Úunique_everseenrf)ÚPEP420PackageFinder)Ú PackageFinderÚwhereryNr�c3s|]}tˆd|ƒ VqdS)rN)Ú _same_pathr‘©Úsearchr,r-r6>r7z find_packages..r�)Úsetuptools.discoveryr¨rjr©rfrªr«rUÚcurdirr|Úlistr”ÚallÚ setdefaultÚ _nest_pathÚfindraÚgetrVÚsamefiler() r¦r§rLÚkwargsr¨r©rfr«r¬ZpackagesrVÚ package_pathZpkgsr,r®r-Ú find_packagess.   &   ÿ ÿr»)ÚparentrVr0cCs&|dvr |n tj ||¡}tj |¡S)N>r�ry)rUrVr`Únormpath)r¼rVr,r,r-rµMsrµ)r2r0cCsVt|ƒr|ƒ}tttttf|ƒ}t|tƒsRt|dƒrJd t t|ƒ¡}nd|}|S)z`When getting the version directly from an attribute, it should be normalised to string. Ú__iter__ryz%s) Úcallablerr rrJÚintr9Úhasattrr`Úmapr1r,r,r-ÚversionRs  rÃ)Ú package_datar0cCsd|vr| d¡|d<|S)NrMr�)r|)rÄr,r,r-Úcanonic_package_datadsrÅ)Ú data_filesrLr0cs$t|tƒr|S‡fdd„| ¡DƒS)z˜For compatibility with ``setup.py``, ``data_files`` should be a list of pairs instead of a dict. This function also expands glob patterns. csg|]\}}|t|ˆƒf‘qSr,)rd)r3ÚdestrKr[r,r-Ú usÿz&canonic_data_files..)r9r²r¤)rÆrLr,r[r-Úcanonic_data_filesjs   þrÉú entry-points)Útextr0cCsBtddd�}t|_| ||¡dd„| ¡Dƒ}| |jd¡|S)a?Given the contents of entry-points file, process it into a 2-level dictionary (``dict[str, dict[str, str]]``). The first level keys are entry-point groups, the second level keys are entry-point names, and the second level values are references to objects (that correspond to the entry-point value). N)ú=)Údefault_sectionZ delimiterscSsi|]\}}|t| ¡ƒ“qSr,)Údictr¤rŸr,r,r-r£…r7z entry_points..)rrJZ optionxformZ read_stringr¤r|rÍ)rËZ text_sourceÚparserÚgroupsr,r,r-Ú entry_points{s   rÑc@sfeZdZdZddœdd„Zdd„Zdd „Zd d „Zee e fd œd d„Z e ee e fd œdd„ƒZ dS)ÚEnsurePackagesDiscoveredaØSome expand functions require all the packages to already be discovered before they run, e.g. :func:`read_attr`, :func:`resolve_class`, :func:`cmdclass`. Therefore in some cases we will need to run autodiscovery during the evaluation of the configuration. However, it is better to postpone calling package discovery as much as possible, because some parameters can influence it (e.g. ``package_dir``), and those might not have been processed yet. r)Ú distributioncCs||_d|_dS)NF)Ú_distÚ_called)r*rÓr,r,r-r.”sz!EnsurePackagesDiscovered.__init__cCs|jsd|_|jjdd�dS)zBTrigger the automatic package discovery, if it is still necessary.TF)rN)rÕrÔÚ set_defaultsr;r,r,r-Ú__call__˜sz!EnsurePackagesDiscovered.__call__cCs|Sr!r,r;r,r,r-Ú __enter__žsz"EnsurePackagesDiscovered.__enter__cCs|jr|jj ¡dSr!)rÕrÔrÖZ analyse_name)r*Z _exc_typeZ _exc_valueZ _tracebackr,r,r-Ú__exit__¡sz!EnsurePackagesDiscovered.__exit__r/cCs|ƒ|jj}|duriS|Sr!)rÔrx)r*Zpkg_dirr,r,r-Ú_get_package_dir¥sz)EnsurePackagesDiscovered._get_package_dircCs t|jƒS)zCProxy to ``package_dir`` that may trigger auto-discovery when used.)ÚLazyMappingProxyrÚr;r,r,r-rxªsz$EnsurePackagesDiscovered.package_dirN) rFrGrHrIr.r×rØrÙr rJrÚÚpropertyrxr,r,r,r-rÒŠs rÒc@steZdZdZegeeeffdœdd„Zeeefdœdd„Z eedœd d „Z e dœd d „Z e edœd d„ZdS)rÛa…Mapping proxy that delays resolving the target object, until really needed. >>> def obtain_mapping(): ... print("Running expensive function!") ... return {"key": "value", "other key": "other value"} >>> mapping = LazyMappingProxy(obtain_mapping) >>> mapping["key"] Running expensive function! 'value' >>> mapping["other key"] 'other value' )Úobtain_mapping_valuecCs||_d|_dSr!)Ú_obtainÚ_value)r*rÝr,r,r-r.¾szLazyMappingProxy.__init__r/cCs|jdur| ¡|_|jSr!)rßrÞr;r,r,r-Ú_targetÂs  zLazyMappingProxy._target)Úkeyr0cCs | ¡|Sr!)rà)r*rár,r,r-Ú __getitem__ÇszLazyMappingProxy.__getitem__cCs t| ¡ƒSr!)r”ràr;r,r,r-Ú__len__ÊszLazyMappingProxy.__len__cCs t| ¡ƒSr!)Úiterràr;r,r,r-r¾ÍszLazyMappingProxy.__iter__N)rFrGrHrIrr rrr.ràrârÀrãr r¾r,r,r,r-rÛ°s  rÛ)N)N)NN)NN)NN)N)rÊ)JrIr"r…rUr$rŠÚglobrZ configparserrÚimportlib.machineryrÚ itertoolsrÚtypingrrrr r r r r rrrrrÚtypesrZdistutils.errorsrÚ_pathrr­ÚwarningsrZsetuptools.distrr°rZdistutils.distrÚ from_iterableZ chain_iterrJÚPathLikeZ_PathrrrrdÚbytesrlrkrirhrƒr~r€r}r�r¥r»rµrÀrÃrÎrÅr²rÉrÑrÒrÛr,r,r,r-Ús     8         ÿ þ !  ýý &  þ $ýü ý  ü üú 5&ÿþ &