509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
ÄvhVF  ã               @   sÈ   d dl mZm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mZ d dlmZmZ d dlmZ dd
d„Zdd„ Zddd„ZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    )Úabsolute_importÚunicode_literalsN)Údefaultdict)Úpartial)Úimport_module)ÚDistutilsOptionErrorÚDistutilsFileError)ÚLegacyVersionÚparse)Ústring_typesFc       	      C   s®   ddl m}m} tjj| ƒ} tjj| ƒs4td|  ƒ‚tjƒ }tj	tjj
| ƒƒ zJ|ƒ }|rb|jƒ ng }| |krx|j| ƒ |j||d� t||j|d�}W dtj	|ƒ X t|ƒS )a,  Read given configuration file and returns options from it as a dict.

    :param str|unicode filepath: Path to configuration file
        to get options from.

    :param bool find_others: Whether to search for other configuration files
        which could be on in various places.

    :param bool ignore_option_errors: Whether to silently ignore
        options, values of which could not be resolved (e.g. due to exceptions
        in directives such as file:, attr:, etc.).
        If False exceptions are propagated as expected.

    :rtype: dict
    r   )ÚDistributionÚ_Distributionz%Configuration file %s does not exist.)Ú	filenames)Úignore_option_errorsN)Zsetuptools.distr   r   ÚosÚpathÚabspathÚisfiler   ÚgetcwdÚchdirÚdirnameZfind_config_filesÚappendZparse_config_filesÚparse_configurationÚcommand_optionsÚconfiguration_to_dict)	ÚfilepathZfind_othersr   r   r   Zcurrent_directoryZdistr   Úhandlers© r   ú/usr/lib/python3.6/config.pyÚread_configuration   s$    

r   c             C   sl   t tƒ}x^| D ]V}|j}|j}xD|jD ]:}t|d| dƒ}|dkrNt||ƒ}n|ƒ }||| |< q&W qW |S )z»Returns configuration data gathered by given handlers as a dict.

    :param list[ConfigHandler] handlers: Handlers list,
        usually from parse_configuration()

    :rtype: dict
    zget_%sN)r   ÚdictÚsection_prefixÚ
target_objÚset_optionsÚgetattr)r   Zconfig_dictZhandlerZ	obj_aliasr"   ZoptionÚgetterÚvaluer   r   r   r   =   s    
r   c             C   s6   t | ||ƒ}|jƒ  t| j||| jƒ}|jƒ  ||fS )aÒ  Performs additional parsing of configuration options
    for a distribution.

    Returns a list of used option handlers.

    :param Distribution distribution:
    :param dict command_options:
    :param bool ignore_option_errors: Whether to silently ignore
        options, values of which could not be resolved (e.g. due to exceptions
        in directives such as file:, attr:, etc.).
        If False exceptions are propagated as expected.
    :rtype: list
    )ÚConfigOptionsHandlerr
   ÚConfigMetadataHandlerÚmetadataÚpackage_dir)Zdistributionr   r   ÚoptionsÚmetar   r   r   r   Z   s    
r   c               @   s¸   e Zd ZdZdZi Zd!dd„Zedd„ ƒZdd	„ Z	e
d"dd„ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZedd„ ƒZedd„ ƒZe
d#dd„ƒZe
dd„ ƒZe
d$dd„ƒZdd„ Zdd „ ZdS )%ÚConfigHandlerz1Handles metadata supplied in configuration files.NFc             C   sb   i }| j }x:|jƒ D ].\}}|j|ƒs(q|j|dƒjdƒ}|||< qW || _|| _|| _g | _d S )NÚ Ú.)	r!   ÚitemsÚ
startswithÚreplaceÚstripr   r"   Úsectionsr#   )Úselfr"   r+   r   r4   r!   Úsection_nameÚsection_optionsr   r   r   Ú__init__„   s    
zConfigHandler.__init__c             C   s   t d| jj ƒ‚dS )z.Metadata item name to parser function mapping.z!%s must provide .parsers propertyN)ÚNotImplementedErrorÚ	__class__Ú__name__)r5   r   r   r   Úparsers”   s    zConfigHandler.parsersc       	      C   sÆ   t ƒ }| j}| jj||ƒ}t|||ƒ}||kr6t|ƒ‚|r>d S d}| jj|ƒ}|r€y||ƒ}W n  tk
r~   d}| jsz‚ Y nX |rˆd S t|d| d ƒ}|d kr®t	|||ƒ n||ƒ | j
j|ƒ d S )NFTzset_%s)Útupler"   ÚaliasesÚgetr$   ÚKeyErrorr<   Ú	Exceptionr   Úsetattrr#   r   )	r5   Zoption_namer&   Úunknownr"   Zcurrent_valueZskip_optionÚparserÚsetterr   r   r   Ú__setitem__š   s0    zConfigHandler.__setitem__ú,c             C   s8   t |tƒr|S d|kr |jƒ }n
|j|ƒ}dd„ |D ƒS )z×Represents value as a list.

        Value is split either by separator (defaults to comma) or by lines.

        :param value:
        :param separator: List items separator character.
        :rtype: list
        Ú
c             S   s   g | ]}|j ƒ r|j ƒ ‘qS r   )r3   )Ú.0Úchunkr   r   r   ú
<listcomp>Ò   s    z-ConfigHandler._parse_list.<locals>.<listcomp>)Ú
isinstanceÚlistÚ
splitlinesÚsplit)Úclsr&   Ú	separatorr   r   r   Ú_parse_listÀ   s    



zConfigHandler._parse_listc             C   sT   d}i }xF| j |ƒD ]8}|j|ƒ\}}}||kr<td| ƒ‚|jƒ ||jƒ < qW |S )zPRepresents value as a dict.

        :param value:
        :rtype: dict
        ú=z(Unable to parse option value to dict: %s)rR   Ú	partitionr   r3   )rP   r&   rQ   ÚresultÚlineÚkeyÚsepÚvalr   r   r   Ú_parse_dictÔ   s    
zConfigHandler._parse_dictc             C   s   |j ƒ }|dkS )zQRepresents value as boolean.

        :param value:
        :rtype: bool
        Ú1ÚtrueÚyes)r[   r\   r]   )Úlower)rP   r&   r   r   r   Ú_parse_boolæ   s    zConfigHandler._parse_boolc                s\   d}t |tƒs|S |j|ƒs |S |t|ƒd… }dd„ |jdƒD ƒ}dj‡ fdd„|D ƒƒS )ai  Represents value as a string, allowing including text
        from nearest files using `file:` directive.

        Directive is sandboxed and won't reach anything outside
        directory with setup.py.

        Examples:
            file: LICENSE
            file: README.rst, CHANGELOG.md, src/file.txt

        :param str value:
        :rtype: str
        zfile:Nc             s   s   | ]}t jj|jƒ ƒV  qd S )N)r   r   r   r3   )rI   r   r   r   r   ú	<genexpr>  s    z,ConfigHandler._parse_file.<locals>.<genexpr>rG   rH   c             3   s2   | ]*}ˆ j |ƒsd rtjj|ƒrˆ j|ƒV  qdS )TN)Ú_assert_localr   r   r   Ú
_read_file)rI   r   )rP   r   r   r`   
  s   )rL   r   r1   ÚlenrO   Újoin)rP   r&   Zinclude_directiveÚspecZ	filepathsr   )rP   r   Ú_parse_fileð   s    


zConfigHandler._parse_filec             C   s   | j tjƒ ƒstd|  ƒ‚d S )Nz#`file:` directive can not access %s)r1   r   r   r   )r   r   r   r   ra     s    zConfigHandler._assert_localc          	   C   s"   t j| dd��
}|jƒ S Q R X d S )Nzutf-8)Úencoding)ÚioÚopenÚread)r   Úfr   r   r   rb     s    zConfigHandler._read_filec             C   sþ   d}|j |ƒs|S |j|dƒjƒ jdƒ}|jƒ }dj|ƒ}|p@d}tjƒ }|rÂ|d |kr¤||d  }|jddƒ}	t	|	ƒdkržtj
jtjƒ |	d ƒ}|	d }qÂ|}nd|krÂtj
jtjƒ |d ƒ}tj
jd|ƒ zt|ƒ}
t|
|ƒ}W dtj
dd… t_
X |S )	z·Represents value as a module attribute.

        Examples:
            attr: package.attr
            attr: package.module.attr

        :param str value:
        :rtype: str
        zattr:r.   r/   r8   r   ú/é   N)r1   r2   r3   rO   Úpoprd   r   r   Úrsplitrc   r   ÚsysÚinsertr   r$   )rP   r&   r*   Zattr_directiveZ
attrs_pathZ	attr_nameZmodule_nameÚparent_pathZcustom_pathÚpartsÚmoduler   r   r   Ú_parse_attr  s0    


zConfigHandler._parse_attrc                s   ‡ fdd„}|S )z¹Returns parser function to represents value as a list.

        Parses a value applying given methods one after another.

        :param parse_methods:
        :rtype: callable
        c                s   | }xˆ D ]}||ƒ}q
W |S )Nr   )r&   ÚparsedÚmethod)Úparse_methodsr   r   r
   Q  s    
z1ConfigHandler._get_parser_compound.<locals>.parser   )rP   rx   r
   r   )rx   r   Ú_get_parser_compoundH  s    	z"ConfigHandler._get_parser_compoundc             C   s:   i }|pdd„ }x$|j ƒ D ]\}\}}||ƒ||< qW |S )zÊParses section options into a dictionary.

        Optionally applies a given parser to values.

        :param dict section_options:
        :param callable values_parser:
        :rtype: dict
        c             S   s   | S )Nr   )rY   r   r   r   Ú<lambda>f  s    z6ConfigHandler._parse_section_to_dict.<locals>.<lambda>)r0   )rP   r7   Zvalues_parserr&   rW   Ú_rY   r   r   r   Ú_parse_section_to_dict[  s
    
z$ConfigHandler._parse_section_to_dictc             C   s@   x:|j ƒ D ].\}\}}y|| |< W q
 tk
r6   Y q
X q
W dS )zQParses configuration file section.

        :param dict section_options:
        N)r0   r@   )r5   r7   Únamer{   r&   r   r   r   Úparse_sectionk  s
    zConfigHandler.parse_sectionc             C   sf   x`| j jƒ D ]R\}}d}|r$d| }t| d| jddƒdƒ}|dkrVtd| j|f ƒ‚||ƒ qW dS )zTParses configuration file items from one
        or more related sections.

        r.   z_%szparse_section%sr/   Ú__Nz0Unsupported distribution option section: [%s.%s])r4   r0   r$   r2   r   r!   )r5   r6   r7   Zmethod_postfixZsection_parser_methodr   r   r   r
   w  s    zConfigHandler.parse)F)rG   )N)N)r;   Ú
__module__Ú__qualname__Ú__doc__r!   r>   r8   Úpropertyr<   rF   ÚclassmethodrR   rZ   r_   rf   Ústaticmethodra   rb   ru   ry   r|   r~   r
   r   r   r   r   r-   t   s(   
&
 ,r-   c                   sH   e Zd ZdZdddddœZdZd‡ fd	d
„	Zedd„ ƒZdd„ Z	‡  Z
S )r(   r)   ZurlÚdescriptionÚclassifiersÚ	platforms)Z	home_pageZsummaryZ
classifierÚplatformFNc                s   t t| ƒj|||ƒ || _d S )N)Úsuperr(   r8   r*   )r5   r"   r+   r   r*   )r:   r   r   r8   ¡  s    zConfigMetadataHandler.__init__c             C   s8   | j }| j}| j}|||||| j||ƒ|||| j|dœS )z.Metadata item name to parser function mapping.)rˆ   ÚkeywordsZprovidesZrequiresZ	obsoletesr‡   Úlicenser†   Zlong_descriptionÚversionZproject_urls)rR   rf   rZ   ry   Ú_parse_version)r5   Ú
parse_listZ
parse_fileÚ
parse_dictr   r   r   r<   §  s    
zConfigMetadataHandler.parsersc             C   sŠ   | j |ƒ}||kr<|jƒ }tt|ƒtƒr8td||f ƒ‚|S | j|| jƒ}t|ƒrX|ƒ }t|t	ƒs†t
|dƒr~djtt|ƒƒ}nd| }|S )zSParses `version` option value.

        :param value:
        :rtype: str

        z7Version loaded from %s does not comply with PEP 440: %sÚ__iter__r/   z%s)rf   r3   rL   r
   r	   r   ru   r*   Úcallabler   Úhasattrrd   ÚmapÚstr)r5   r&   r�   r   r   r   rŽ   ¼  s    


z$ConfigMetadataHandler._parse_version)FN)r;   r€   r�   r!   r>   Zstrict_moder8   rƒ   r<   rŽ   Ú__classcell__r   r   )r:   r   r(   �  s    r(   c               @   sT   e Zd ZdZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ ZdS )r'   r+   c             C   sL   | j }t| j dd�}| j}| j}||||||||||||||| j| j|dœS )z.Metadata item name to parser function mapping.ú;)rQ   )Zzip_safeZuse_2to3Zinclude_package_datar*   Zuse_2to3_fixersZuse_2to3_exclude_fixersZconvert_2to3_doctestsÚscriptsZeager_resourcesZdependency_linksZnamespace_packagesZinstall_requiresZsetup_requiresZtests_requireZpackagesÚentry_pointsZ
py_modules)rR   r   r_   rZ   Ú_parse_packagesrf   )r5   r�   Zparse_list_semicolonZ
parse_boolr�   r   r   r   r<   á  s*    zConfigOptionsHandler.parsersc             C   sB   d}|j |ƒs| j|ƒS | j| jjdi ƒƒ}ddlm} |f |ŽS )zTParses `packages` option value.

        :param value:
        :rtype: list
        zfind:zpackages.findr   )Úfind_packages)r1   rR   Úparse_section_packages__findr4   r?   Z
setuptoolsr›   )r5   r&   Zfind_directiveÚfind_kwargsr›   r   r   r   rš   ý  s    

z$ConfigOptionsHandler._parse_packagesc                sT   | j || jƒ}dddg‰ t‡ fdd„|jƒ D ƒƒ}|jdƒ}|dk	rP|d |d< |S )zœParses `packages.find` configuration file section.

        To be used in conjunction with _parse_packages().

        :param dict section_options:
        ÚwhereÚincludeÚexcludec                s$   g | ]\}}|ˆ kr|r||f‘qS r   r   )rI   ÚkÚv)Ú
valid_keysr   r   rK     s    zEConfigOptionsHandler.parse_section_packages__find.<locals>.<listcomp>Nr   )r|   rR   r    r0   r?   )r5   r7   Zsection_datar�   rž   r   )r£   r   rœ     s    


z1ConfigOptionsHandler.parse_section_packages__findc             C   s   | j || jƒ}|| d< dS )z`Parses `entry_points` configuration file section.

        :param dict section_options:
        r™   N)r|   rR   )r5   r7   rv   r   r   r   Úparse_section_entry_points%  s    z/ConfigOptionsHandler.parse_section_entry_pointsc             C   s.   | j || jƒ}|jdƒ}|r*||d< |d= |S )NÚ*r.   )r|   rR   r?   )r5   r7   rv   Úrootr   r   r   Ú_parse_package_data-  s    
z(ConfigOptionsHandler._parse_package_datac             C   s   | j |ƒ| d< dS )z`Parses `package_data` configuration file section.

        :param dict section_options:
        Zpackage_dataN)r§   )r5   r7   r   r   r   Úparse_section_package_data7  s    z/ConfigOptionsHandler.parse_section_package_datac             C   s   | j |ƒ| d< dS )zhParses `exclude_package_data` configuration file section.

        :param dict section_options:
        Zexclude_package_dataN)r§   )r5   r7   r   r   r   Ú"parse_section_exclude_package_data>  s    z7ConfigOptionsHandler.parse_section_exclude_package_datac             C   s"   t | jdd�}| j||ƒ| d< dS )zbParses `extras_require` configuration file section.

        :param dict section_options:
        r—   )rQ   Zextras_requireN)r   rR   r|   )r5   r7   r�   r   r   r   Úparse_section_extras_requireF  s    z1ConfigOptionsHandler.parse_section_extras_requireN)r;   r€   r�   r!   rƒ   r<   rš   rœ   r¤   r§   r¨   r©   rª   r   r   r   r   r'   Ý  s   
r'   )FF)F)Z
__future__r   r   rh   r   rp   Úcollectionsr   Ú	functoolsr   Ú	importlibr   Zdistutils.errorsr   r   Z#setuptools.extern.packaging.versionr	   r
   Zsetuptools.extern.sixr   r   r   r   Úobjectr-   r(   r'   r   r   r   r   Ú<module>   s"   
.
  M