U
    bV                  
   @   s8  d dl mZmZmZmZ d dl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 d dl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mZm Z  ddl!m"Z"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.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ee6Z7G dd de8Z9G dd de9dZ:dd Z;dd Z<d d! Z=i Z>d"d# Z?G d$d% d%edZ@G d&d' d'eAZBG d(d) d)eBe@ZCG d*d+ d+eCZDG d,d- d-eBe@ZEG d.d/ d/eEZFG d0d1 d1e@ZGG d2d3 d3e@ZHG d4d5 d5eEZIG d6d7 d7eFZJeIeFeeEeeHeHeJeJd8	ZKdS )9    )absolute_importdivisionprint_functionunicode_literals)ABCMetaabstractmethodabstractproperty)Mapping)reduce)	getLogger)
attrgetter)basenameN   )Channel)BuildNumberMatchVersionSpec   )
frozendict)memoizedproperty)concatconcatvgroupby)CONDA_PACKAGE_EXTENSION_V1CONDA_PACKAGE_EXTENSION_V2)
isiterable)dashlist)expandurl_to_pathstrip_pkg_extensionis_package_file)is_urlpath_to_urlunquote)CondaValueErrorInvalidMatchSpec)contextc                       s   e Zd Zd fdd	Z  ZS )MatchSpecTypeNc                    s<  |r&t |tr|s|S t |trpt|j}|d|j |d|j |j|d< |jf | t	t
| jf |S t |trt|}|rt|f|}t|ddh r|dd  t	t
| jf |S t |trt|f|}t	t
| jf |S t|dr| }|rt|f|S |S ntd||f nt	t
| jf |S d S )Noptionaltarget_original_spec_strto_match_specz,Invalid MatchSpec:
  spec_arg=%s
  kwargs=%s)
isinstance	MatchSpecdict_match_components
setdefaultr'   r(   original_spec_strupdatesuperr&   __call__str_parse_spec_strsetpopr	   hasattrr*   r#   )clsZspec_argkwargsZ
new_kwargsZparsedspec	__class__ 6lib/python3.8/site-packages/conda/models/match_spec.pyr3   !   s:    




zMatchSpecType.__call__)N)__name__
__module____qualname__r3   __classcell__r>   r>   r<   r?   r&      s   r&   c                   @   sh  e Zd ZdZdZeeZi ZdGddZe	dd Z
d	d
 Zdd ZdHddZedd Zdd Zedd Zed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'd( Zd)d* Zd+d, Zd-d. Zed/d0 Z d1d2 Z!d3d4 Z"e#d5d6 Z$ed7d8 Z%ed9d: Z&ed;d< Z'ed=d> Z(ed?d@ Z)e	dIdAdBZ*e	dCdD Z+dJdEdFZ,dS )Kr,   a  
    :class:`MatchSpec` is, fundamentally, a query language for conda packages.  Any of the fields
    that comprise a :class:`PackageRecord` can be used to compose a :class:`MatchSpec`.

    :class:`MatchSpec` can be composed with keyword arguments, where keys are any of the
    attributes of :class:`PackageRecord`.  Values for keyword arguments are the exact values the
    attribute should match against.  Many fields can also be matched against non-exact values--by
    including wildcard `*` and `>`/`<` ranges--where supported.  Any non-specified field is
    the equivalent of a full wildcard match.

    :class:`MatchSpec` can also be composed using a single positional argument, with optional
    keyword arguments.  Keyword arguments also override any conflicting information provided in
    the positional argument.  The positional argument can be either an existing :class:`MatchSpec`
    instance or a string.  Conda has historically had several string representations for equivalent
    :class:`MatchSpec`s.  This :class:`MatchSpec` should accept any existing valid spec string, and
    correctly compose a :class:`MatchSpec` instance.

    A series of rules are now followed for creating the canonical string representation of a
    :class:`MatchSpec` instance.  The canonical string representation can generically be
    represented by

        (channel(/subdir):(namespace):)name(version(build))[key1=value1,key2=value2]

    where `()` indicate optional fields.  The rules for constructing a canonical string
    representation are:

    1. `name` (i.e. "package name") is required, but its value can be '*'.  Its position is always
       outside the key-value brackets.
    2. If `version` is an exact version, it goes outside the key-value brackets and is prepended
       by `==`. If `version` is a "fuzzy" value (e.g. `1.11.*`), it goes outside the key-value
       brackets with the `.*` left off and is prepended by `=`.  Otherwise `version` is included
       inside key-value brackets.
    3. If `version` is an exact version, and `build` is an exact value, `build` goes outside
       key-value brackets prepended by a `=`.  Otherwise, `build` goes inside key-value brackets.
       `build_string` is an alias for `build`.
    4. The `namespace` position is being held for a future conda feature.
    5. If `channel` is included and is an exact value, a `::` separator is ued between `channel`
       and `name`.  `channel` can either be a canonical channel name or a channel url.  In the
       canonical string representation, the canonical channel name will always be used.
    6. If `channel` is an exact value and `subdir` is an exact value, `subdir` is appended to
       `channel` with a `/` separator.  Otherwise, `subdir` is included in the key-value brackets.
    7. Key-value brackets can be delimited by comma, space, or comma+space.  Value can optionally
       be wrapped in single or double quotes, but must be wrapped if `value` contains a comma,
       space, or equal sign.  The canonical format uses comma delimiters and single quotes.
    8. When constructing a :class:`MatchSpec` instance from a string, any key-value pair given
       inside the key-value brackets overrides any matching parameter given outside the brackets.

    When :class:`MatchSpec` attribute values are simple strings, the are interpreted using the
    following conventions:

      - If the string begins with `^` and ends with `$`, it is converted to a regex.
      - If the string contains an asterisk (`*`), it is transformed from a glob to a regex.
      - Otherwise, an exact match to the string is sought.


    Examples:

        >>> str(MatchSpec(name='foo', build='py2*', channel='conda-forge'))
        'conda-forge::foo[build=py2*]'
        >>> str(MatchSpec('foo 1.0 py27_0'))
        'foo==1.0=py27_0'
        >>> str(MatchSpec('foo=1.0=py27_0'))
        'foo==1.0=py27_0'
        >>> str(MatchSpec('conda-forge::foo[version=1.0.*]'))
        'conda-forge::foo=1.0'
        >>> str(MatchSpec('conda-forge/linux-64::foo>=1.0'))
        "conda-forge/linux-64::foo[version='>=1.0']"
        >>> str(MatchSpec('*/linux-64::foo>=1.0'))
        "foo[subdir=linux-64,version='>=1.0']"

    To fully-specify a package with a full, exact spec, the fields
      - channel
      - subdir
      - name
      - version
      - build
    must be given as exact values.  In the future, the namespace field will be added to this list.
    Alternatively, an exact spec is given by '*[md5=12345678901234567890123456789012]'.

    )channelsubdirnameversionbuildbuild_numbertrack_featuresfeaturesurlZmd5licenselicense_familyfnFNc                 K   s,   || _ || _|dd | _| jf || _d S )Nr)   )	_optional_targetr7   r)   _build_componentsr.   )selfr'   r(   r:   r>   r>   r?   __init__   s    zMatchSpec.__init__c           	      C   s   i }|t t d  tkr.|d t t  }n(|t t d  tkrV|d t t  }d|kr|dd\}}d|kr|dd\}}|tjkr|}d }||d< |r||d< n||d< |dd\}}}||||d | f |S )	Nz::r   /rD   rE   -r   rF   rG   rH   )lenr   r   splitrsplitr%   Zknown_subdirsr1   )	r9   dist_strpartsZchannel_subdir_strchannel_strrE   rF   rG   rH   r>   r>   r?   from_dist_str   s.    

zMatchSpec.from_dist_strc                 C   s   | j |}|o|jS N)r.   getexact_valuerS   
field_namevr>   r>   r?   get_exact_value   s    zMatchSpec.get_exact_valuec                 C   s   | j |}|o|jS r_   )r.   r`   	raw_valuerb   r>   r>   r?   get_raw_value   s    zMatchSpec.get_raw_valuec                 C   s   |  |}|d kr|S |S r_   )rg   )rS   rc   defaultrd   r>   r>   r?   r`      s    
zMatchSpec.getc                 C   s"   t | jdko d| jko | jdkS )Nr   rF   *)rX   r.   rF   rS   r>   r>   r?   is_name_only_spec   s
    zMatchSpec.is_name_only_specc                 C   s   |   S r_   __str__rj   r>   r>   r?   r[      s    zMatchSpec.dist_strc                 C   s   | j S r_   )rP   rj   r>   r>   r?   r'      s    zMatchSpec.optionalc                 C   s   | j S r_   )rQ   rj   r>   r>   r?   r(      s    zMatchSpec.targetc                 C   s   | j S r_   )r)   rj   r>   r>   r?   r0      s    zMatchSpec.original_spec_strc                 C   sL   t |tr ddlm} ||}| j D ]\}}| |||s* dS q*dS )z
        Accepts an `IndexRecord` or a dict, and matches can pull from any field
        in that record.  Returns True for a match, and False for no match.
        r   )PackageRecordFT)r+   r-   Zrecordsrn   Zfrom_objectsr.   items_match_individual)rS   Zrecrn   rc   rd   r>   r>   r?   match   s    

zMatchSpec.matchc                 C   s8   t ||}z||W S  tk
r2   ||k Y S X d S r_   )getattrrq   AttributeError)rS   recordrc   Zmatch_componentvalr>   r>   r?   rp      s
    
zMatchSpec._match_individualc                 C   s   t | jdko| dd k	S )Nr   rF   )rX   r.   re   rj   r>   r>   r?   
_is_simple  s    zMatchSpec._is_simplec                 C   s   t | jdkS )Nr   )rX   r.   rj   r>   r>   r?   
_is_single  s    zMatchSpec._is_singlec                    sN     d}|r|S t fdddD }tdd |D sFd| t S d S d S )NrO   c                 3   s   | ]}  |V  qd S r_   re   .0xrj   r>   r?   	<genexpr>  s     z4MatchSpec._to_filename_do_not_use.<locals>.<genexpr>rW   c                 s   s   | ]}|d kV  qd S r_   r>   ry   r>   r>   r?   r|     s     z%s-%s-%s)re   tupleanyr   )rS   Zfn_fieldZvalsr>   rj   r?   _to_filename_do_not_use  s    
z!MatchSpec._to_filename_do_not_usec                 C   sL   d| j j| f g}| jr(|d| j  | jr8|d |d d|S )Nz%s("%s"z, target="%s"z, optional=True) )r=   r@   r(   appendr'   join)rS   builderr>   r>   r?   __repr__  s    

zMatchSpec.__repr__c           	         s  g }g }| j d}|r.|jr.|t| n|rJ|jsJ|dt|  | j d}|r|rt|jrt|d|  n|d|  | j dd}||rdnd	|  | j d
| j d d}rttfdddD r|d  nd d dkr* r|d  n
| n~dd  dkrT|dd d   nTd dkrz|dd d   n.dr| d}n|d  d} rt  t fdddD r|d   n>d kr|d   n$|r|d   n|d   dddd
dh}d| j krLd| j krL|d | j	D ]|}||krR|| j krR|dkr|rqRt| j | tfdddD r|d |f  n|d!|f  qR|r|d"d#
|  d$
|S )%NrD   z
channel=%srE   z/%sz	subdir=%srF   ri   z::%s%srG   rH   Fc                 3   s   | ]}| kV  qd S r_   r>   rz   s)rG   r>   r?   r|   5  s     z$MatchSpec.__str__.<locals>.<genexpr>z><$^|,zversion='%s'r   )z!=z~=.*===Tc                 3   s   | ]}| kV  qd S r_   r>   r   )rH   r>   r?   r|   I  s     z
build='%s'zbuild=%srL   rO   c                 3   s   | ]}| kV  qd S r_   r>   r   )valuer>   r?   r|   [  s     z, =z%s='%s'z%s=%s[%s],r   )r.   r`   ra   r   r4   matches_allr~   
startswithaddFIELD_NAMESr   )	rS   r   bracketsZchannel_matcherZsubdir_matcherZname_matcherZversion_exactZ_skipkeyr>   )rH   r   rG   r?   rm     sr    






zMatchSpec.__str__c                 C   s   |   S r_   rl   rj   r>   r>   r?   __json__e  s    zMatchSpec.__json__c                 C   sf   g }|  d}|st|| | d}| d}|rN|s@t|||g7 }n|r\|| d|S )NrF   rH   rG    )re   AssertionErrorr   rg   r   )rS   r   rF   rH   rG   r>   r>   r?   conda_build_formh  s    




zMatchSpec.conda_build_formc                 C   s   t |tr| j|jkS dS d S )NF)r+   r,   	_hash_keyrS   otherr>   r>   r?   __eq__y  s    
zMatchSpec.__eq__c                 C   s
   t | jS r_   )hashr   rj   r>   r>   r?   __hash__  s    zMatchSpec.__hash__c                 C   s   | j | j| jfS r_   )r.   r'   r(   rj   r>   r>   r?   r     s    zMatchSpec._hash_keyc                 C   s
   || j kS r_   r.   )rS   Zfieldr>   r>   r?   __contains__  s    zMatchSpec.__contains__c                    sB   t |tj }|r"t| jd| tj t fdd| D S )NzCannot match on field(s): %sc                 3   s   | ]\}} ||V  qd S r_   r>   )rz   r   r   _make_componentr>   r?   r|     s     z.MatchSpec._build_components.<locals>.<genexpr>)r6   r,   FIELD_NAMES_SETr$   r)   r   r   ro   )rS   r:   Z
not_fieldsr>   r   r?   rR     s    zMatchSpec._build_componentsc                 C   sp   t |dr|}| |fS tj}| |f}||}|r:| |fS | tkrPt|  |}ntt|}||| |f< | |fS )Nrq   )r8   r,   _MATCHER_CACHEr`   _implementorsExactStrMatchr4   )rc   r   Zmatcherr   Z	cache_keyZcached_matcherr>   r>   r?   r     s    

zMatchSpec._make_componentc                 C   s   |  dpdS )NrF   ri   rx   rj   r>   r>   r?   rF     s    zMatchSpec.namec                    sV   t  fdddD }|t jk r(dS  dr<d jkr@dS d jkrNdS d	S d S )
Nc                 3   s   | ]}| j kV  qd S r_   r   rz   frj   r>   r?   r|     s     z'MatchSpec.strictness.<locals>.<genexpr>rW      rF   rH   rG   r   r   )sumrX   r.   re   )rS   r   r>   rj   r?   
strictness  s    
zMatchSpec.strictnessc                 C   s   |   S r_   )r   rj   r>   r>   r?   r;     s    zMatchSpec.specc                 C   s   | j dS )NrG   )r.   r`   rj   r>   r>   r?   rG     s    zMatchSpec.versionc                 C   s,   |  dp|  d}|r t|}|s(t|S )NrO   rL   )rg   r   r   )rS   ru   r>   r>   r?   rO     s
    zMatchSpec.fnc           	         s   t t fdd|D td}ttd|}|dg |d g  }g }ttdd | D }|D ]f}ttd|}|d d  t|dkrt	d	t
| |t|dkrtfd
d|n|d  qftt||S )Nc                 3   s   | ]}|r |V  qd S r_   r>   r   )r9   r>   r?   r|     s      z"MatchSpec.merge.<locals>.<genexpr>)r   rF   ri   c                 s   s    | ]}t d d | V  qdS )c                 S   s   | j S r_   )r'   )r   r>   r>   r?   <lambda>      z+MatchSpec.merge.<locals>.<genexpr>.<lambda>N)r   values)rz   groupr>   r>   r?   r|     s   r(   r   zIncompatible MatchSpec merge:%sc                    s   |  | S r_   )_merge)r{   yunionr>   r?   r     r   z!MatchSpec.merge.<locals>.<lambda>r   )sortedr}   r4   r   r   r7   r   r   rX   
ValueErrorr   r   r
   r   )	r9   match_specsr   Zname_groupsZunmergeableZmerged_specsZmergeable_groupsr   Ztarget_groupsr>   )r9   r   r?   merge  s     

$zMatchSpec.mergec                 C   s   | j |ddS )NTr   )r   )r9   r   r>   r>   r?   r     s    zMatchSpec.unionc           	      C   s  | j |j ks| j|jkr(td| |f i }t| jt|jB }|D ]}| j|}|j|}|d krt|d krtqDqD|d kr|||< qD|d kr|||< qD|rz||}W q tttfk
r   d||f }Y qX n
|	|}|||< qD| j
f | j | jd|S )Nz*Incompatible MatchSpec merge:  - %s
  - %sz%s|%s)r'   r(   )r'   r(   r   r6   r.   r`   r   rs   	TypeErrorr   r=   )	rS   r   r   Zfinal_componentsZcomponent_namesZcomponent_nameZthis_componentZthat_componentfinalr>   r>   r?   r     s*    



zMatchSpec._merge)FN)N)F)F)-r@   rA   rB   __doc__r   	frozensetr   r   rT   classmethodr^   re   rg   r`   propertyrk   r[   r'   r(   r0   rq   rp   rv   rw   r   r   rm   r   r   r   r   r   r   r   rR   staticmethodr   rF   r   r;   rG   rO   r   r   r   r>   r>   r>   r?   r,   E   sf   Q






	I







r,   )	metaclassc                 C   sH   t d| }|r*| \}}|o&| }n
| d }}|oB|dd|fS )a  This should reliably pull the build string out of a version + build string combo.
    Examples:
        >>> _parse_version_plus_build("=1.2.3 0")
        ('=1.2.3', '0')
        >>> _parse_version_plus_build("1.2.3=0")
        ('1.2.3', '0')
        >>> _parse_version_plus_build(">=1.0 , < 2.0 py34_0")
        ('>=1.0,<2.0', 'py34_0')
        >>> _parse_version_plus_build(">=1.0 , < 2.0 =py34_0")
        ('>=1.0,<2.0', 'py34_0')
        >>> _parse_version_plus_build("=1.2.3 ")
        ('=1.2.3', None)
        >>> _parse_version_plus_build(">1.8,<2|==1.7")
        ('>1.8,<2|==1.7', None)
        >>> _parse_version_plus_build("* openblas_0")
        ('*', 'openblas_0')
        >>> _parse_version_plus_build("* *")
        ('*', '*')
    z<((?:.+?)[^><!,|]?)(?:(?<![=!|,<>~])(?:[ =])([^-=,|<>~]+?))?$Nr   r   )researchgroupsstripreplace)Zv_plus_br\   rG   rH   r>   r>   r?   _parse_version_plus_build   s    
r   c                 C   s(   t | \} }| dd\}}}|||fS )z
    Examples:
        >>> _parse_legacy_dist("_license-1.1-py27_1.tar.bz2")
        ('_license', '1.1', 'py27_1')
        >>> _parse_legacy_dist("_license-1.1-py27_1")
        ('_license', '1.1', 'py27_1')
    rV   r   )r   rZ   )r[   _rF   rG   rH   r>   r>   r?   _parse_legacy_dist  s    r   c                 C   s&   | sdS t | }|jp|j}||jfS )NNN)r   rF   Zbase_urlrE   )Zchannel_valZchnZchannel_namer>   r>   r?   _parse_channel*  s
    r   c                     sV  t | }|r|S | }| dr8| d d }d|fdS d| krl| d}| d | | |d   } }|   | dd}t|dkrtd|  |d	 } t	| r"t
| sttt| } t| }|jrt|j\}}	}
|j|j||	|
|j| d
}n*| dr
t| }n| }dt|| dS |S i }td| }|r| d	 }| |d} |dd }td|}|D ]4}| \}}}}|r|st|d|||< qltd| }i }|r| d	 }| |d} |dd }td|}|D ]}| \}}}}|||< qd|krd|d< | dd}t|}|dkrH|\}}} n6|dkr`|\}} d }n|rx|d	 } d\}}nt t|\}}d|krt|d\}}|r|}|r|}d|kr|d}td| }|r| \}} |d krt|d|  n
t|d| o|  } | rd| kr8t|dt | \}	}
|	d	 dkr|	dd   |	d d d kr|
d kr|	dd  }	n>t! fd!d"d#D s|
d kr d dkr d }	n }	nd\}	}
i }|r|nd|d$< |d k	r||d< |d k	r
||d< |d k	r|	d k	r&|	|d%< |
d k	r8|
|d&< |"| ||d'< |t |< |S )(N@r   ri   )rF   rJ   #z if r   zIgnoring conditional in spec %sr   )rD   rE   rF   rG   rH   rO   rL   zfile://)rF   rO   rL   z.*(?:(\[.*\]))r   z2([a-zA-Z0-9_-]+?)=(["\']?)([^\'"]*?)(\2)(?:[, ]|$)zkey-value mismatch in bracketsz.*(?:(\(.*\)))r'   T:r   r   r   rD   rE   z([^ =<>!~]+)?([><!=~ ].+)?zno package name found in '%s'zno package name found[z&multiple brackets sections not allowedr   r   c                 3   s   | ]}| kV  qd S r_   r>   )rz   cZtest_strr>   r?   r|     s     z"_parse_spec_str.<locals>.<genexpr>z=,|rF   rG   rH   r)   )#_PARSE_CACHEr`   endswithindexr   rY   rX   logdebugr   r    r"   r!   r   r   rE   r   Zpackage_filenamecanonical_namer   r   r   r   rq   r   r   finditerr$   rZ   NotImplementedErrorr   r7   r   r~   r1   ) Zspec_strZcached_resultr0   Zfeature_nameZndxr   Z
spec_splitrD   rF   rG   rH   resultZpath_or_urlr   Zm3Zbrackets_strZm3brq   r   r   Zm4ZparensZ
parens_strZm4bZm5Zm5_lenr]   	namespacerE   Z	b_channelZb_subdirZ
componentsr>   r   r?   r5   5  s    























r5   c                   @   sP   e Zd Zdd Zedd Zdd Zedd Ze	d	d
 Z
dd Zdd ZdS )MatchInterfacec                 C   s
   || _ d S r_   
_raw_valuerS   r   r>   r>   r?   rT     s    zMatchInterface.__init__c                 C   s
   t  d S r_   r   r   r>   r>   r?   rq     s    zMatchInterface.matchc                 C   s
   |  |S r_   )rq   r   r>   r>   r?   matches  s    zMatchInterface.matchesc                 C   s   | j S r_   r   rj   r>   r>   r?   rf     s    zMatchInterface.raw_valuec                 C   s
   t  dS )ziIf the match value is an exact specification, returns the value.
        Otherwise returns None.
        Nr   rj   r>   r>   r?   ra     s    zMatchInterface.exact_valuec                 C   s&   | j |j kr td| j |j f | j S )Nz+Incompatible component merge:
  - %r
  - %r)rf   r   r   r>   r>   r?   r     s
    
zMatchInterface.mergec                 C   s   t | j|jf}d|S )N|)r6   rf   r   )rS   r   Zoptionsr>   r>   r?   r     s    zMatchInterface.unionN)r@   rA   rB   rT   r   rq   r   r   rf   r   ra   r   r   r>   r>   r>   r?   r     s   


r   c                   @   s8   e Zd Zdd Zdd Zdd Zdd Zed	d
 ZdS )_StrMatchMixinc                 C   s   | j S r_   r   rj   r>   r>   r?   rm     s    z_StrMatchMixin.__str__c                 C   s   d| j j| jf S )Nz%s('%s'))r=   r@   r   rj   r>   r>   r?   r     s    z_StrMatchMixin.__repr__c                 C   s   t || jo| j|jkS r_   r+   r=   r   r   r>   r>   r?   r     s    z_StrMatchMixin.__eq__c                 C   s
   t | jS r_   r   r   rj   r>   r>   r?   r   
  s    z_StrMatchMixin.__hash__c                 C   s   | j S r_   r   rj   r>   r>   r?   ra     s    z_StrMatchMixin.exact_valueN)	r@   rA   rB   rm   r   r   r   r   ra   r>   r>   r>   r?   r     s   r   c                       s(   e Zd ZdZ fddZdd Z  ZS )r   r   c                    s   t t| | d S r_   )r2   r   rT   r   r<   r>   r?   rT     s    zExactStrMatch.__init__c                 C   s2   z
|j }W n tk
r&   t|}Y nX | j |kS r_   )r   rs   r4   rS   r   Z
_other_valr>   r>   r?   rq     s
    
zExactStrMatch.match)r@   rA   rB   	__slots__rT   rq   rC   r>   r>   r<   r?   r     s   r   c                       s$   e Zd Z fddZdd Z  ZS )ExactLowerStrMatchc                    s   t t| |  d S r_   )r2   r   rT   lowerr   r<   r>   r?   rT   "  s    zExactLowerStrMatch.__init__c                 C   s6   z
|j }W n tk
r&   t|}Y nX | j | kS r_   )r   rs   r4   r   r   r>   r>   r?   rq   %  s
    
zExactLowerStrMatch.match)r@   rA   rB   rT   rq   rC   r>   r>   r<   r?   r      s   r   c                       s@   e Zd ZdZ fddZdd Zedd Zedd	 Z  Z	S )
GlobStrMatch)r   	_re_matchc                    sj   t t| | d | _|dr:|dr:t|j| _n,d|krft	|
dd}td| j| _d S )N^$ri   z\*r   ^(?:%s)$)r2   r   rT   r   r   r   r   compilerq   escaper   r   r<   r>   r?   rT   0  s    zGlobStrMatch.__init__c                 C   sF   z
|j }W n tk
r&   t|}Y nX | jr8| |S | j |kS d S r_   )r   rs   r4   r   r   r>   r>   r?   rq   :  s    

zGlobStrMatch.matchc                 C   s   | j d kr| jS d S r_   )r   r   rj   r>   r>   r?   ra   E  s    zGlobStrMatch.exact_valuec                 C   s
   | j dkS )Nri   r   rj   r>   r>   r?   r   I  s    zGlobStrMatch.matches_all)
r@   rA   rB   r   rT   rq   r   ra   r   rC   r>   r>   r<   r?   r   -  s   

r   c                       s   e Zd Z fddZ  ZS )GlobLowerStrMatchc                    s   t t| |  d S r_   )r2   r   rT   r   r   r<   r>   r?   rT   P  s    zGlobLowerStrMatch.__init__)r@   rA   rB   rT   rC   r>   r>   r<   r?   r   N  s   r   c                       s\   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
edd Z  ZS )SplitStrMatchr   c                    s   t t| | | d S r_   )r2   r   rT   _convertr   r<   r>   r?   rT   W  s    zSplitStrMatch.__init__c                 C   sH   zt |dddW S  tk
rB   t|r<t | Y S  Y nX d S )Nr   r   )r   r   rY   rs   r   r   r>   r>   r?   r   Z  s    zSplitStrMatch._convertc                 C   s<   z|o| j |j @ W S  tk
r6   | j | |@  Y S X d S r_   )r   rs   r   r   r>   r>   r?   rq   b  s    zSplitStrMatch.matchc                 C   s,   | j r$dddd t| j D  S dS d S )Nz{%s}, c                 s   s   | ]}d | V  qdS '%s'Nr>   r   r>   r>   r?   r|   j  s     z)SplitStrMatch.__repr__.<locals>.<genexpr>zset())r   r   r   rj   r>   r>   r?   r   h  s    zSplitStrMatch.__repr__c                 C   s   d t| jS Nr   r   r   r   rj   r>   r>   r?   rm   n  s    zSplitStrMatch.__str__c                 C   s   t || jo| j|jkS r_   r   r   r>   r>   r?   r   r  s    zSplitStrMatch.__eq__c                 C   s
   t | jS r_   r   rj   r>   r>   r?   r   u  s    zSplitStrMatch.__hash__c                 C   s   | j S r_   r   rj   r>   r>   r?   ra   x  s    zSplitStrMatch.exact_valuer@   rA   rB   r   rT   r   rq   r   rm   r   r   r   ra   rC   r>   r>   r<   r?   r   T  s   r   c                       s\   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
edd Z  ZS )FeatureMatchr   c                    s   t t| | | d S r_   )r2   r   rT   r   r   r<   r>   r?   rT     s    zFeatureMatch.__init__c                 C   s^   |s
t  S t|tr>t dd dd |dddD D S t dd dd |D D S d S )Nc                 s   s   | ]}|r|V  qd S r_   r>   r   r>   r>   r?   r|     s    z(FeatureMatch._convert.<locals>.<genexpr>c                 s   s   | ]}|  V  qd S r_   r   rz   Zffr>   r>   r?   r|     s    r   r   c                 s   s   | ]}|r|V  qd S r_   r>   r   r>   r>   r?   r|     s      c                 s   s   | ]}|  V  qd S r_   r   r   r>   r>   r?   r|     s     )r   r+   r4   r   rY   r   r>   r>   r?   r     s    
zFeatureMatch._convertc                 C   s   |  |}| j|kS r_   )r   r   r   r>   r>   r?   rq     s    
zFeatureMatch.matchc                 C   s   dd dd t| jD  S )Nr   r   c                 s   s   | ]}d | V  qdS r   r>   )rz   kr>   r>   r?   r|     s     z(FeatureMatch.__repr__.<locals>.<genexpr>r   rj   r>   r>   r?   r     s    zFeatureMatch.__repr__c                 C   s   d t| jS r   r   rj   r>   r>   r?   rm     s    zFeatureMatch.__str__c                 C   s   t || jo| j|jkS r_   r   r   r>   r>   r?   r     s    zFeatureMatch.__eq__c                 C   s
   t | jS r_   r   rj   r>   r>   r?   r     s    zFeatureMatch.__hash__c                 C   s   | j S r_   r   rj   r>   r>   r?   ra     s    zFeatureMatch.exact_valuer   r>   r>   r<   r?   r   }  s   
r   c                       s4   e Zd Z fddZdd Zdd Zdd Z  ZS )	ChannelMatchc                    st   d | _ t|tr`|dr4|dr4t|j| _ n,d|krXtd|dd j| _ nt	|}t
t| | d S )Nr   r   ri   r   r   )r   r+   r4   r   r   r   r   rq   r   r   r2   r   rT   r   r<   r>   r?   rT     s    
zChannelMatch.__init__c                 C   s^   zt |j}W n tk
r*   t |}Y nX | jr>| |jS | jj|jkpX| jj|jkS d S r_   )r   r   rs   r   r   rF   r   r>   r>   r?   rq     s    zChannelMatch.matchc                 C   s2   zd| j j W S  tk
r,   d| j   Y S X d S )Nr   )r   rF   rs   rj   r>   r>   r?   rm     s    zChannelMatch.__str__c                 C   s   d|    S )Nr   rl   rj   r>   r>   r?   r     s    zChannelMatch.__repr__)r@   rA   rB   rT   rq   rm   r   rC   r>   r>   r<   r?   r     s   r   c                   @   s   e Zd Zdd ZdS )CaseInsensitiveStrMatchc                 C   sN   z
|j }W n tk
r&   t|}Y nX | }| jr@| |S | j |kS d S r_   )r   rs   r4   r   r   r   r>   r>   r?   rq     s    

zCaseInsensitiveStrMatch.matchN)r@   rA   rB   rq   r>   r>   r>   r?   r     s   r   )	rD   rF   rG   rH   rI   rJ   rK   rM   rN   )LZ
__future__r   r   r   r   abcr   r   r   Zcollections.abcr	   	functoolsr
   Zloggingr   operatorr   os.pathr   r   rD   r   rG   r   r   Zauxlib.collectionr   Zauxlib.decoratorsr   Z_vendor.toolzr   r   r   Zbase.constantsr   r   Zcommon.compatr   Z	common.ior   Zcommon.pathr   r   r   r   Z
common.urlr    r!   r"   
exceptionsr#   r$   Zbase.contextr%   r@   r   typer&   r,   r   r   r   r   r5   r   objectr   r   r   r   r   r   r   r   r   r   r>   r>   r>   r?   <module>   sf   &   > *!!)%'