a „oe´Fã@s8dZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z ddl mZddlmZddlmZdd „Zd d „Zejd kr–dad Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Ze  ¡dd„ƒZdd„Zdd„Z d/d!d"„Z!da"a#a$d#d$„Z%d%d&„Z&d0d'd(„Z'd)d*„Z(d1d+d,„Z)d-d.„Z*dS)2zudistutils.util Miscellaneous utility functions -- anything that doesn't fit into one of the other *util.py modules. éNé)ÚDistutilsPlatformErrorÚDistutilsByteCompileError)Únewer)Úspawn)ÚlogcCs˜tjdkr8tjdkr8dtj ¡vr&dSdtj ¡vr8dStjdkr�tjdkr�ttd ƒr�t ¡\}}}}}|d d …d kr�d dlm }||||ƒSt   ¡S)z· Return a string that identifies the current platform. Use this function to distinguish platform-specific build directories and platform-specific built distributions. )ééÚntz(arm)ú win-arm32z(arm64)ú win-arm64)ré ÚposixÚunameNrZaixr)Ú aix_platform) ÚsysÚ version_infoÚosÚnameÚversionÚlowerÚhasattrrZ py38compatrÚ sysconfigÚ get_platform)ZosnameÚhostÚreleaserÚmachiner©rú;C:\Program Files\Certbot\pkgs\setuptools\_distutils\util.pyÚget_host_platforms     rcCs:tjdkr4dddddœ}tj d¡}| |¡p2tƒStƒS)Nr Úwin32z win-amd64r r )Zx86Zx64ZarmZarm64ZVSCMD_ARG_TGT_ARCH)rrÚenvironÚgetr)ZTARGET_TO_PLATÚtargetrrrr3s ü rÚdarwinZMACOSX_DEPLOYMENT_TARGETcCsdadS)zFor testing only. Do not call.N)Ú_syscfg_macosx_verrrrrÚ_clear_cached_macosx_verEsr&cCs.tdur*ddlm}| t¡p d}|r*|atS)z’Get the version of macOS latched in the Python interpreter configuration. Returns the version as a string or None if can't obtain one. Cached.Nr)rÚ)r%Z distutilsrZget_config_varÚMACOSX_VERSION_VAR)rZverrrrÚ!get_macosx_target_ver_from_syscfgKs  r)cCs^tƒ}tj t¡}|rZ|rVt|ƒddgkrVt|ƒddgkrVdtd||f}t|ƒ‚|S|S)aReturn the version of macOS for which we are building. The target version defaults to the version in sysconfig latched at time the Python interpreter was built, unless overridden by an environment variable. If neither source has a value, then None is returnedé rú$zE mismatch: now "%s" but "%s" during configure; must use 10.3 or later)r)rr!r"r(Ú split_versionr)Z syscfg_verZenv_verZmy_msgrrrÚget_macosx_target_verXs  ÿþýþÿr-cCsdd„| d¡DƒS)zEConvert a dot-separated string into a list of numbers for comparisonscSsg|] }t|ƒ‘qSr)Úint)Ú.0ÚnrrrÚ zóz!split_version..Ú.)Úsplit)Úsrrrr,xsr,cCsztjdkr|S|s|S|ddkr.td|ƒ‚|ddkrFtd|ƒ‚| d¡}d|vrd| d¡qP|sntjStjj|ŽS)aÎReturn 'pathname' as a name that will work on the native filesystem, i.e. split it on '/' and put it back together again using the current directory separator. Needed because filenames in the setup script are always supplied in Unix style, and have to be converted to the local convention before we can actually use them in the filesystem. Raises ValueError on non-Unix-ish systems if 'pathname' either starts or ends with a slash. ú/rzpath '%s' cannot be absoluteéÿÿÿÿzpath '%s' cannot end with '/'r3)rÚsepÚ ValueErrorr4ÚremoveÚcurdirÚpathÚjoin)ÚpathnameÚpathsrrrÚ convert_path}s       r@cCs’tjdkrÚdriver<rrrÚ change_rootšs     rGc CsjtjdkrPdtjvrPz$ddl}| t ¡¡dtjd<WnttfyNYn0dtjvrftƒtjd<dS)aLEnsure that 'os.environ' has all the environment variables we guarantee that users can use in config files, command-line options, etc. Currently this includes: HOME - user's home directory (Unix only) PLAT - description of the current platform, including hardware and OS (see 'get_platform()') rÚHOMErNéZPLAT) rrr!ÚpwdÚgetpwuidÚgetuidÚ ImportErrorÚKeyErrorr)rJrrrÚ check_environ¯s  rOc Csptƒttjƒ}| dd„| ¡Dƒ¡zt|ƒ |¡WStyj}zt d|›�ƒ‚WYd}~n d}~00dS)aà Perform variable substitution on 'string'. Variables are indicated by format-style braces ("{var}"). Variable is substituted by the value found in the 'local_vars' dictionary or in 'os.environ' if it's not in 'local_vars'. 'os.environ' is first checked/augmented to guarantee that it contains certain values: see 'check_environ()'. Raise ValueError for any variables not found in either 'local_vars' or 'os.environ'. css|]\}}|t|ƒfVqdS©N©Ústr)r/rÚvaluerrrÚ Òr2zsubst_vars..zinvalid variable N) rOÚdictrr!ÚupdateÚitemsÚ _subst_compatÚ format_maprNr9)r5Z local_varsÚlookupÚvarrrrÚ subst_varsÆs  r\cCs6dd„}t d||¡}||kr2ddl}| dt¡|S)zb Replace shell/Perl-style variable substitution with format-style. For compatibility. cSsd| d¡›d�S)NÚ{rÚ})Úgroup)ÚmatchrrrÚ_substßsz_subst_compat.._substz\$([a-zA-Z_][a-zA-Z_0-9]*)rNz-shell/Perl-style substitutions are deprecated)ÚreÚsubÚwarningsÚwarnÚDeprecationWarning)r5raÚreplrdrrrrXÙsþrXúerror: cCs |t|ƒSrPrQ)ÚexcÚprefixrrrÚgrok_environment_errorísrkcCs(t dtj¡at d¡at d¡adS)Nz [^\\\'\"%s ]*z'(?:[^'\\]|\\.)*'z"(?:[^"\\]|\\.)*")rbÚcompileÚstringÚ whitespaceÚ _wordchars_reÚ _squote_reÚ _dquote_rerrrrÚ _init_regexøs rrcCs„tdurtƒ| ¡}g}d}|�r€t ||¡}| ¡}|t|ƒkrZ| |d|…¡�q€||tjvr�| |d|…¡||d…  ¡}d}nÔ||dkrÂ|d|…||dd…}|d}n¢||dkrÜt  ||¡}n*||dkröt  ||¡}nt d||ƒ‚|du�r t d||ƒ‚| ¡\}}|d|…||d|d…||d…}| ¡d }|t|ƒkr| |¡�q€q|S) aSplit a string up according to Unix shell-like rules for quotes and backslashes. In short: words are delimited by spaces, as long as those spaces are not escaped by a backslash, or inside a quoted string. Single and double quotes are equivalent, and the quote characters can be backslash-escaped. The backslash is stripped from any two-character escape sequence, leaving only the escaped character. The quote characters are stripped from any quoted string. Returns a list of words. NrrArrBú"z!this can't happen (bad char '%c')z"bad string (mismatched %s quotes?)é)rorrÚstripr`ÚendÚlenÚappendrmrnÚlstriprprqÚ RuntimeErrorr9Úspan)r5ÚwordsÚposÚmrvZbegrrrÚ split_quotedÿs@        ,   rcCsP|dur6d |j|¡}|dd…dkr6|dd…d}t |¡|sL||ŽdS)aœPerform some action that affects the outside world (eg. by writing to the filesystem). Such actions are special because they are disabled by the 'dry_run' flag. This method takes care of all that bureaucracy for you; all you have to do is supply the function to call and an argument tuple for it (to embody the "external action" being performed), and an optional message to print. Nz{}{!r}éþÿÿÿz,)rú))ÚformatÚ__name__rÚinfo)ÚfuncÚargsÚmsgÚverboseÚdry_runrrrÚexecuteAs  rŠcCs2| ¡}|dvrdS|dvr dStd |¡ƒ‚dS)zôConvert a string representation of truth to true (1) or false (0). True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if 'val' is anything else. )ÚyZyesÚtÚtrueZonÚ1r)r0ÚnoÚfZfalseZoffÚ0rzinvalid truth value {!r}N)rr9r‚)ÚvalrrrÚ strtoboolTs r“c Cs`tjrtdƒ‚|dur"do |dk}|�sLzddlm}|dƒ\} } Wn,typddlm} d| dƒ} } Yn0t d| ¡|�s| duršt   | d ¡} n t | d ƒ} | �L|   d ¡|   d   tt|ƒ¡d ¡|   d |||||f¡Wdƒn1sú0Ytjg} |  t ¡¡|  | ¡t| |d�tt j| fd| |d��nddlm}|D]þ}|dd…dk�rv�q\|dk�r¤|dk�rŽdn|}tjj||d�}n tj |¡}|}|�rð|dt|ƒ…|k�ràtd||fƒ‚|t|ƒd…}|�rt j  ||¡}t j  |¡}|�r\|�s(t!||ƒ�rJt d||¡|�sX||||ƒnt "d||¡�q\dS)a~Byte-compile a collection of Python source files to .pyc files in a __pycache__ subdirectory. 'py_files' is a list of files to compile; any files that don't end in ".py" are silently skipped. 'optimize' must be one of the following: 0 - don't optimize 1 - normal optimization (like "python -O") 2 - extra optimization (like "python -OO") If 'force' is true, all files are recompiled regardless of timestamps. The source filename encoded in each bytecode file defaults to the filenames listed in 'py_files'; you can modify these with 'prefix' and 'basedir'. 'prefix' is a string that will be stripped off of each source filename, and 'base_dir' is a directory name that will be prepended (after 'prefix' is stripped). You can supply either or both (or neither) of 'prefix' and 'base_dir', as you wish. If 'dry_run' is true, doesn't actually do anything that would affect the filesystem. Byte-compilation is either done directly in this interpreter process with the standard py_compile module, or indirectly by writing a temporary script and executing it. Normally, you should let 'byte_compile()' figure out to use direct compilation or not (see the source for details). The 'direct' flag is used by the script generated in indirect mode; unless you know what you're doing, leave it set to None. zbyte-compiling is disabled.NTr)Úmkstempz.py)Úmktempz$writing byte-compilation script '%s'Úwz2from distutils.util import byte_compile files = [ z, z] zŒ byte_compile(files, optimize=%r, force=%r, prefix=%r, base_dir=%r, verbose=%r, dry_run=0, direct=1) )r‰z removing %s)rléýÿÿÿr')Ú optimizationz1invalid prefix: filename %r doesn't start with %rzbyte-compiling %s to %sz%skipping byte-compilation of %s to %s)#rÚdont_write_bytecoderZtempfiler”rMr•rr„rÚfdopenÚopenÚwriter=ÚmapÚreprÚ executableÚextendÚ subprocessZ"_optim_args_from_interpreter_flagsrxrrŠr:Ú py_compilerlÚ importlibÚutilÚcache_from_sourcerwr9r<ÚbasenamerÚdebug)Zpy_filesÚoptimizeÚforcerjÚbase_dirrˆr‰Zdirectr”Z script_fdÚ script_namer•ZscriptÚcmdrlÚfileÚoptÚcfileÚdfileZ cfile_baserrrÚ byte_compiledsr(       ÿ úÿ"      ÿÿ r±cCs| d¡}d}| |¡S)zŒReturn a version of the string escaped for inclusion in an RFC-822 header, by ensuring there are 8 spaces space after each newline. Ú z )r4r=)ÚheaderÚlinesr8rrrÚ rfc822_escapeûs rµ)rh)Nrr)rrNNrrN)+Ú__doc__Úimportlib.utilr£rrbrmr¡rrÚ functoolsÚerrorsrrZ _modifiedrrZ_logrrrÚplatformr%r(r&r)r-r,r@rGÚ lru_cacherOr\rXrkrorprqrrrrŠr“r±rµrrrrÚsV         B ø