o
    5eG                     @   s  d 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	m
Z
mZmZ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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l#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7 ddl8m9Z9 e	rddl:m;Z; e<e=Z>ded fddZ?G dd deZ@G d d! d!ee@ZAe7jBe7jCe7jDgZEd)d"d#ZFd$e
de
fd%d&ZGG d'd( d(eAZHdS )*a  Contains the Command base classes that depend on PipSession.

The classes in this module are in a separate module so the commands not
needing download / PackageFinder capability don't unnecessarily import the
PackageFinder machinery and all its vendored dependencies, etc.
    N)partial)Values)TYPE_CHECKINGAnyListOptionalTuple)
WheelCache)
cmdoptions)Command)CommandContextMixIn)CommandErrorPreviousBuildDirError)LinkCollector)PackageFinder)SelectionPreferences)TargetPython)
PipSession)BuildTracker)RequirementPreparer)install_req_from_editableinstall_req_from_line#install_req_from_parsed_requirementinstall_req_from_req_string)parse_requirements)InstallRequirement)BaseResolver)pip_self_version_check)TempDirectoryTempDirectoryTypeRegistrytempdir_kinds)running_under_virtualenv)
SSLContextreturnr"   c               
   C   s   t jdk r	tdzdd l} W n ty   td Y d S w zddlm} W n ty: } ztd| d }~ww |	| j
S )N)   
   z9The truststore feature is only available for Python 3.10+r   z1Disabling truststore since ssl support is missing)
truststorez'The truststore feature is unavailable: )sysversion_infor   sslImportErrorloggerwarningpip._vendorr&   r"   PROTOCOL_TLS_CLIENT)r)   r&   e r0   P/var/www/html/venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py_create_truststore_ssl_context2   s   

r2   c                       s   e Zd ZdZd fddZededeee	  fddZ
dedefd	d
Z			ddedee dee dedef
ddZ  ZS )SessionCommandMixinzE
    A class mixin for command classes needing _build_session().
    r#   Nc                    s   t    d | _d S N)super__init___session)self	__class__r0   r1   r6   J   s   

zSessionCommandMixin.__init__optionsc                 C   sL   g }t |ddst |dd}|r|| t |dd}|r"|| |p%dS )z7Return a list of index urls from user-provided options.no_indexF	index_urlNextra_index_urls)getattrappendextend)clsr;   
index_urlsurlurlsr0   r0   r1   _get_index_urlsN   s   

z#SessionCommandMixin._get_index_urlsc                 C   s0   | j du r| | || _ | j dusJ | j S )zGet a default-managed session.N)r7   enter_context_build_session)r8   r;   r0   r0   r1   get_default_session\   s   
z'SessionCommandMixin.get_default_sessionFretriestimeoutfallback_to_certific                 C   s   |j }|rtj|sJ d|jv r&zt }W n ty%   |s! d }Y nw d }t|r2tj|dnd |d ur9|n|j	|j
| ||d}|jrL|j|_|jrS|j|_|jsX|rb|d ur^|n|j|_|jrm|j|jd|_|j |j_|j|j_|S )Nr&   zhttp-v2)cacherJ   trusted_hostsrC   ssl_context)httphttps)	cache_dirospathisabsfeatures_enabledr2   	Exceptionr   joinrJ   rN   rF   certverifyclient_certrK   proxyproxiesno_inputauth	promptingkeyring_provider)r8   r;   rJ   rK   rL   rR   rO   sessionr0   r0   r1   rH   f   s>   

	

z"SessionCommandMixin._build_sessionr#   N)NNF)__name__
__module____qualname____doc__r6   classmethodr   r   r   strrF   r   rI   intboolrH   __classcell__r0   r0   r9   r1   r3   D   s(    r3   c                   @   s"   e Zd ZdZdeddfddZdS )IndexGroupCommandz
    Abstract base class for commands with the index_group options.

    This also corresponds to the commands that permit the pip version check.
    r;   r#   Nc                 C   sl   t |dsJ |js|jrdS | j|dtd|jdd}| t|| W d   dS 1 s/w   Y  dS )z
        Do the pip version check if not disabled.

        This overrides the default behavior of not doing the check.
        r<   Nr      T)rJ   rK   rL   )hasattrdisable_pip_version_checkr<   rH   minrK   r   )r8   r;   rb   r0   r0   r1   handle_pip_version_check   s   

"z*IndexGroupCommand.handle_pip_version_check)rd   re   rf   rg   r   rr   r0   r0   r0   r1   rm      s    rm   c                   C   sN   t  rdS ttdsdS tjdkstjdkrdS t dkr dS td dS )zOutput a warning for sudo users on Unix.

    In a virtual environment, sudo pip still writes to virtualenv.
    On Windows, users may run pip as Administrator without issues.
    This warning only applies to Unix root users outside of virtualenv.
    Ngetuidwin32cygwinr   zRunning pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv)r!   ro   rS   r'   platformrs   r+   r,   r0   r0   r0   r1   warn_if_run_as_root   s   
rw   funcc              	      s>   dt ddfdd dtdtdtt dtt f fd	d
}|S )zNDecorator for common logic related to managing temporary
    directories.
    registryr#   Nc                 S   s   t D ]}| |d qd S )NF)KEEPABLE_TEMPDIR_TYPES
set_delete)ry   tr0   r0   r1   configure_tempdir_registry   s   z0with_cleanup.<locals>.configure_tempdir_registryr8   r;   argsc                    sH   | j d usJ |jr | j  z| ||W S  ty#    | j   w r4   )tempdir_registryno_cleanr   )r8   r;   r~   r}   rx   r0   r1   wrapper   s   

zwith_cleanup.<locals>.wrapper)r   RequirementCommandr   r   r   r   rj   )rx   r   r0   r   r1   with_cleanup   s   r   c                       sH  e Zd Zdededdf fddZededefdd	Ze			
d)de
dedededededee dedefddZe									d*dedededee dedededededee deeedf  defd d!Zdee dedededee f
d"d#Zededdfd$d%Z		d+deded&ee dee def
d'd(Z  ZS ),r   r~   kwr#   Nc                    s&   t  j|i | | jt  d S r4   )r5   r6   cmd_opts
add_optionr
   r   )r8   r~   r   r9   r0   r1   r6     s   zRequirementCommand.__init__r;   c                 C   s   d| j v rdS dS )zEDetermines which resolver should be used, based on the given options.zlegacy-resolverlegacy
resolvelib)deprecated_features_enabledr;   r0   r0   r1   determine_resolver_variant  s   
z-RequirementCommand.determine_resolver_variantr   temp_build_dirbuild_trackerrb   finderuse_user_sitedownload_dir	verbosityc	                 C   s   |j }	|	dus	J d}
| |}|dkr!d|jv }|r td nd}
d}d|jv r/td t|	|j||j|j|||j	||j
||||
dS )	zQ
        Create a RequirementPreparer instance for the given parameters.
        NFr   z	fast-depszpip is using lazily downloaded wheels using HTTP range requests to obtain dependency information. This experimental feature is enabled through --use-feature=fast-deps and it is not ready for production.Tz;fast-deps has no effect when used with the legacy resolver.)	build_dirsrc_dirr   build_isolationcheck_build_depsr   rb   progress_barr   require_hashesr   
lazy_wheelr   legacy_resolver)rT   r   rV   r+   r,   r   r   r   r   r   r   )rB   r   r;   r   rb   r   r   r   r   temp_build_dir_pathr   resolver_variantr   r0   r0   r1   make_requirement_preparer  sB   


z,RequirementCommand.make_requirement_preparerFTto-satisfy-onlypreparerwheel_cacheignore_installedignore_requires_pythonforce_reinstallupgrade_strategy
use_pep517py_version_info.c                 C   s   t t|j|
d}| |}|dkr*ddl}|jjjjj	||||||j
||||	|dS ddl}|jjjjj	||||||j
||||	|dS )zF
        Create a Resolver instance for the given parameters.
        )isolatedr   r   r   N)r   r   r   make_install_reqr   ignore_dependenciesr   r   r   r   r   )r   r   isolated_moder   ,pip._internal.resolution.resolvelib.resolver	_internal
resolutionr   resolverResolverr   (pip._internal.resolution.legacy.resolverr   )rB   r   r   r;   r   r   r   r   r   r   r   r   r   r   pipr0   r0   r1   make_resolverE  sF   
z RequirementCommand.make_resolverc                 C   sr  g }|j D ]}t|d|||dD ]}t||jdd}|| qq|D ]}	t|	d|j|jdt|ddd}|| q#|jD ]}	t	|	d|j|jt|ddd}|| q>|j
D ]&}t||||d	D ]}t||j|jd|jrt|jdndd
}|| qbqXtdd |D rd|_|s|js|j
sd| ji}
|jrtdjdi t|
d|jdtdjdi |
|S )zS
        Parse command-line arguments into the corresponding requirements.
        T)
constraintr   r;   rb   F)r   user_suppliedNconfig_settings)
comes_fromr   r   r   r   )r   r   r   r   )r   r;   rb   )r   r   r   r   c                 s   s    | ]}|j V  qd S r4   )has_hash_options).0reqr0   r0   r1   	<genexpr>  s    z6RequirementCommand.get_requirements.<locals>.<genexpr>namezXYou must give at least one requirement to {name} (maybe you meant "pip {name} {links}"?) )linkszHYou must give at least one requirement to {name} (see "pip help {name}")r0   )constraintsr   r   r   r@   r   r   r?   	editablesr   requirementsr;   getanyr   r   
find_linksr   formatdictrX   )r8   r~   r;   r   rb   r   filename
parsed_req
req_to_addr   optsr0   r0   r1   get_requirements  s   







	
z#RequirementCommand.get_requirementsc                 C   s$   | j }| }|rt| dS dS )zE
        Trace basic information about the provided objects.
        N)search_scopeget_formatted_locationsr+   info)r   r   	locationsr0   r0   r1   trace_basic_info  s
   z#RequirementCommand.trace_basic_infotarget_pythonc                 C   s6   t j||d}td|j|j|j|d}tj|||dS )z
        Create a package finder appropriate to this requirement command.

        :param ignore_requires_python: Whether to ignore incompatible
            "Requires-Python" values in links. Defaults to False.
        r   T)allow_yankedformat_controlallow_all_prereleasesprefer_binaryr   )link_collectorselection_prefsr   )r   creater   r   prer   r   )r8   r;   rb   r   r   r   r   r0   r0   r1   _build_package_finder  s   z(RequirementCommand._build_package_finder)Nr   )NFTFFr   NN)NN)rd   re   rf   r   r6   staticmethodr   ri   r   rh   r   r   r   r   rk   r   rj   r   r   r	   r   r   r   r   r   r   r   r   r   rl   r0   r0   r9   r1   r      s    		
6	
:
Tr   rc   )Irg   loggingrS   r'   	functoolsr   optparser   typingr   r   r   r   r   pip._internal.cacher	   pip._internal.clir
   pip._internal.cli.base_commandr   !pip._internal.cli.command_contextr   pip._internal.exceptionsr   r   pip._internal.index.collectorr   "pip._internal.index.package_finderr   $pip._internal.models.selection_prefsr   "pip._internal.models.target_pythonr   pip._internal.network.sessionr   ,pip._internal.operations.build.build_trackerr    pip._internal.operations.preparer   pip._internal.req.constructorsr   r   r   r   pip._internal.req.req_filer   pip._internal.req.req_installr   pip._internal.resolution.baser   !pip._internal.self_outdated_checkr   pip._internal.utils.temp_dirr   r   r    pip._internal.utils.virtualenvr!   r)   r"   	getLoggerrd   r+   r2   r3   rm   	BUILD_ENVEPHEM_WHEEL_CACHE	REQ_BUILDrz   rw   r   r   r0   r0   r0   r1   <module>   sN    
X$
