o
    ugP                     @   s8  d Z ddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ d
d Zdd ZejdkrIdadZdd Zdd Zdd Zdd Zdd Zdd Zdadd Zdd Zd d! Z d1d#d$Z!d a" a#a$d%d& Z%d'd( Z&d2d)d*Z'd+d, Z(				d3d-d.Z)d/d0 Z*dS )4zudistutils.util

Miscellaneous utility functions -- anything that doesn't fit into
one of the other *util.py modules.
    N)DistutilsPlatformError)newer)spawn)log)DistutilsByteCompileError   )"_optim_args_from_interpreter_flagsc                  C   s  t jdkr#dtj v rdS dtj v rdS dtj v r dS tjS dt jv r-t jd S t jd	ks7tt d
s:tjS t  \} }}}}|  	dd} |	dd}|	dd}| dd dkred| |f S | dd dkr|d dkrd} dt
|d d |dd f }ddd}|d|tj  7 }nO| dd dkrd d!lm} || ||S | dd" d#krd#} td$tj}||}|r| }n| dd" d%krddl}	ddl}
|	|
j | ||\} }}d&| ||f S )'a  Return a string that identifies the current platform.  This is used mainly to
    distinguish platform-specific build directories and platform-specific built
    distributions.  Typically includes the OS name and version and the
    architecture (as supplied by 'os.uname()'), although the exact information
    included depends on the OS; eg. on Linux, the kernel version isn't
    particularly important.

    Examples of returned values:
       linux-i586
       linux-alpha (?)
       solaris-2.6-sun4u

    Windows will return one of:
       win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
       win32 (all others - specifically, sys.platform is returned)

    For other non-POSIX platforms, currently just returns 'sys.platform'.

    ntamd64	win-amd64z(arm)	win-arm32z(arm64)	win-arm64_PYTHON_HOST_PLATFORMposixuname/  _-N   linuxz%s-%ssunosr   5solarisz%d.%s      32bit64bit)il    z.%saixr   )aix_platform   cygwinz[\d.]+darwinz%s-%s-%s)osnamesysversionlowerplatformenvironhasattrr   replaceintmaxsize
py38compatr    recompileASCIImatchgroup_osx_supportdistutils.sysconfigget_platform_osx	sysconfigget_config_vars)osnamehostreleaser'   machinebitnessr    rel_remr5   	distutils rB   \/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/setuptools/_distutils/util.pyget_host_platform   sT   


 


rD   c                  C   s6   t jdkrddddd} | t jdpt S t S )Nr	   win32r   r   r   )x86x64armarm64VSCMD_ARG_TGT_ARCH)r$   r%   getr*   rD   )TARGET_TO_PLATrB   rB   rC   get_platformd   s   
rM   r#   MACOSX_DEPLOYMENT_TARGETc                   C   s   da dS )zFor testing only. Do not call.N)_syscfg_macosx_verrB   rB   rB   rC   _clear_cached_macosx_veru   s   rP   c                  C   s.   t du rddlm}  | tpd}|r|a t S )zGet 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   )r8   r   )rO   rA   r8   get_config_varMACOSX_VERSION_VAR)r8   verrB   rB   rC   !get_macosx_target_ver_from_syscfgz   s   rT   c                  C   s^   t  } tjt}|r-| r+t| ddgkr+t|ddgk r+dt d|| f  }t||S | S )a  Return 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)rT   r$   r*   rK   rR   split_versionr   )
syscfg_verenv_vermy_msgrB   rB   rC   get_macosx_target_ver   s   r[   c                 C   s   dd |  dD S )zEConvert a dot-separated string into a list of numbers for comparisonsc                 S   s   g | ]}t |qS rB   )r-   ).0nrB   rB   rC   
<listcomp>   s    z!split_version.<locals>.<listcomp>.)split)srB   rB   rC   rW      s   rW   c                 C   s   t jdkr| S | s| S | d dkrtd|  | d dkr#td|  | d}d|v r5|d d|v s,|s:t jS t jj| 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.
    r   r   zpath '%s' cannot be absolutezpath '%s' cannot end with '/'r_   )r$   sep
ValueErrorr`   removecurdirpathjoin)pathnamepathsrB   rB   rC   convert_path   s   
	

rk   c                 C   s   t jdkrt j|st j| |S t j| |dd S t jdkr=t j|\}}|d dkr6|dd }t j| |S tdt j )a	  Return 'pathname' with 'new_root' prepended.  If 'pathname' is
    relative, this is equivalent to "os.path.join(new_root,pathname)".
    Otherwise, it requires making 'pathname' relative and then joining the
    two, which is tricky on DOS/Windows and Mac OS.
    r   r   Nr	   r   \z!nothing known about platform '%s')r$   r%   rg   isabsrh   
splitdriver   )new_rootri   driverg   rB   rB   rC   change_root   s   

rq   c               	   C   sv   t rdS tjdkr,dtjvr,zddl} | t d tjd< W n ttfy+   Y nw dtjvr7t	 tjd< da dS )aL  Ensure 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()')
    Nr   HOMEr   r   PLATr   )
_environ_checkedr$   r%   r*   pwdgetpwuidgetuidImportErrorKeyErrorrM   )ru   rB   rB   rC   check_environ   s   	
rz   c              
   C   s`   t   ttj}|dd | D  zt| |W S  ty/ } zt	d| d}~ww )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'.
    c                 s   s     | ]\}}|t |fV  qd S Nstr)r\   r%   valuerB   rB   rC   	<genexpr>   s    zsubst_vars.<locals>.<genexpr>zinvalid variable N)
rz   dictr$   r*   updateitems_subst_compat
format_mapry   rd   )ra   
local_varslookupvarrB   rB   rC   
subst_vars   s   

r   c                 C   s6   dd }t d|| }|| krddl}|dt |S )zb
    Replace shell/Perl-style variable substitution with
    format-style. For compatibility.
    c                 S   s   d|  d dS )N{r   })r4   )r3   rB   rB   rC   _subst  s   z_subst_compat.<locals>._substz\$([a-zA-Z_][a-zA-Z_0-9]*)r   Nz+shell/Perl-style substitions are deprecated)r0   subwarningswarnDeprecationWarning)ra   r   replr   rB   rB   rC   r   	  s   r   error: c                 C   s   |t |  S r{   r|   )excprefixrB   rB   rC   grok_environment_error  s   r   c                   C   s(   t dtj at dat dad S )Nz[^\\\'\"%s ]*z'(?:[^'\\]|\\.)*'z"(?:[^"\\]|\\.)*")r0   r1   string
whitespace_wordchars_re
_squote_re
_dquote_rerB   rB   rB   rC   _init_regex#  s   
r   c                 C   s  t du rt  |  } g }d}| rt | |}| }|t| kr-|| d|  	 |S | | tjv rH|| d|  | |d 	 } d}ni| | dkra| d| | |d d  } |d }nP| | dkrnt
| |}n| | dkr{t| |}ntd| |  |du rtd| |  | \}}| d| | |d |d   | |d  } | d	 }|t| kr||  	 |S | s|S )
a  Split 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.
    Nr   rl   r   '"z!this can't happen (bad char '%c')z"bad string (mismatched %s quotes?)r   )r   r   stripr3   endlenappendr   r   lstripr   r   RuntimeErrorrd   span)ra   wordsposr@   r   begrB   rB   rC   split_quoted)  sD   
,
$r   c                 C   sT   |du rd| j |f }|dd dkr|dd d }t| |s(| |  dS dS )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%s%rz,)r   ))__name__r   info)funcargsmsgverbosedry_runrB   rB   rC   executef  s   	
r   c                 C   s.   |   } | dv r
dS | dv rdS td| f )zConvert 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.
    )yyesttrueon1r   )r]   noffalseoff0r   zinvalid truth value %r)r(   rd   )valrB   rB   rC   	strtobooly  s   r   c              	   C   sN  ddl }tjrtd|du r|dk}|szddlm}	 |	d\}
}W n ty9   ddlm} d|d}
}Y nw t	d| |s|
durMt
|
d	}nt|d	}|& |d
 |dtt| d  |d|||||f  W d   n1 s}w   Y  tjg}|t  || t||d tt
j|fd| |d dS ddlm} | D ]w}|dd dkrq|dkr|dkrdn|}tjj||d}ntj|}|}|r|dt| |krtd||f |t|d }|rt
j||}t
j |}|r$|st!||rt	d|| |s|||| qt"d|| qdS )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.
    r   Nzbyte-compiling is disabled.T)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)r1   r   )optimizationz1invalid prefix: filename %r doesn't start with %rzbyte-compiling %s to %sz%skipping byte-compilation of %s to %s)#
subprocessr&   dont_write_bytecoder   tempfiler   rx   r   r   r   r$   fdopenopenwriterh   maprepr
executableextendr   r   r   r   re   
py_compiler1   	importlibutilcache_from_sourcer   rd   rg   basenamer   debug)py_filesoptimizeforcer   base_dirr   r   directr   r   	script_fdscript_namer   scriptcmdr1   fileoptcfiledfile
cfile_baserB   rB   rC   byte_compile  s~   $



r   c                 C   s   |  d}d}||S )zReturn a version of the string escaped for inclusion in an
    RFC-822 header, by ensuring there are 8 spaces space after each newline.
    
z	
        )r`   rh   )headerlinesrc   rB   rB   rC   rfc822_escape  s   

r   )r   )Nr   r   )r   r   NNr   r   N)+__doc__r$   r0   importlib.utilr   r   r&   distutils.errorsr   distutils.dep_utilr   distutils.spawnr   rA   r   r   
py35compatr   rD   rM   r)   rO   rR   rP   rT   r[   rW   rk   rq   rt   rz   r   r   r   r   r   r   r   r   r   r   r   r   rB   rB   rB   rC   <module>   sP    P


=
 