U
    «ÃT_Û  ã                   @   sº   d dl mZ d dl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 erŒd d	lmZmZ d d
lmZ d dlmZ e e¡Zdd„ Zdd„ Zdd„ Zdd„ ZdS )é    )Úabsolute_importN)Ú
FeedParser)Úpkg_resources)Ú
specifiersÚversion)ÚNoneMetadataError)Údisplay_path)ÚMYPY_CHECK_RUNNING)ÚOptionalÚTuple)ÚMessage)ÚDistributionc                 C   s4   | dkrdS t  | ¡}t d tt|ƒ¡¡}||kS )a˜  
    Check if the given Python version matches a "Requires-Python" specifier.

    :param version_info: A 3-tuple of ints representing a Python
        major-minor-micro version to check (e.g. `sys.version_info[:3]`).

    :return: `True` if the given Python version satisfies the requirement.
        Otherwise, return `False`.

    :raises InvalidSpecifier: If `requires_python` has an invalid format.
    NTÚ.)r   ÚSpecifierSetr   ÚparseÚjoinÚmapÚstr)Úrequires_pythonÚversion_infoÚrequires_python_specifierÚpython_version© r   úA/tmp/pip-unpacked-wheel-8u7dkzi1/pip/_internal/utils/packaging.pyÚcheck_requires_python   s
    
r   c                 C   s€   d}t | tjƒr&|  |¡r&|  |¡}n0|  d¡r@d}|  |¡}nt dt| jƒ¡ d}|dkrht	| |ƒ‚t
ƒ }| |¡ | ¡ S )z�
    :raises NoneMetadataError: if the distribution reports `has_metadata()`
        True but `get_metadata()` returns None.
    ÚMETADATAzPKG-INFOzNo metadata found in %sÚ N)Ú
isinstancer   ÚDistInfoDistributionÚhas_metadataÚget_metadataÚloggerÚwarningr   Úlocationr   r   ÚfeedÚclose)ÚdistÚmetadata_nameÚmetadataÚfeed_parserr   r   r   r    ,   s    ÿ


r    c                 C   s&   t | ƒ}| d¡}|dk	r"t|ƒ}|S )z_
    Return the "Requires-Python" metadata for a distribution, or None
    if not present.
    zRequires-PythonN)r    Úgetr   )r&   Úpkg_info_dictr   r   r   r   Úget_requires_pythonG   s
    
r,   c                 C   s2   |   d¡r.|  d¡D ]}| ¡ r| ¡   S qdS )NÚ	INSTALLERr   )r   Úget_metadata_linesÚstrip)r&   Úliner   r   r   Úget_installerX   s
    
r1   )Ú
__future__r   ÚloggingÚemail.parserr   Úpip._vendorr   Zpip._vendor.packagingr   r   Úpip._internal.exceptionsr   Úpip._internal.utils.miscr   Úpip._internal.utils.typingr	   Útypingr
   r   Úemail.messager   Zpip._vendor.pkg_resourcesr   Ú	getLoggerÚ__name__r!   r   r    r,   r1   r   r   r   r   Ú<module>   s    
