B
    '\              
   @   sf  d dl mZmZmZmZ d dlmZmZmZ yd dl	m
Z
 W n  ek
r\   d dlm
Z
 Y nX 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$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7 ee8Z9G dd de:Z;e+e;G dd de<Z=dd Z>dd Z?dd Z@i ZAd d! ZBe+eG d"d# d#e<ZCG d$d% d%e<ZDG d&d' d'eDeCZEG d(d) d)eEZFG d*d+ d+eDeCZGG d,d- d-eGZHG d.d/ d/eCZIG d0d1 d1eCZJG d2d3 d3eGZKG d4d5 d5eHZLeKeHeeGeeJeJeLeLd6	ZMdS )7    )absolute_importdivisionprint_functionunicode_literals)ABCMetaabstractmethodabstractproperty)Mapping)reduce)	getLogger)
attrgetter)basenameN   )Channel)BuildNumberMatchVersionSpec   )
frozendict)memoizedproperty)concatconcatvgroupby)CONDA_TARBALL_EXTENSION)
isiterable	iteritems
itervaluesstring_types	text_typewith_metaclass)dashlist)expandurl_to_path)is_urlpath_to_urlunquote)CondaValueErrorInvalidMatchSpecc                   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__r   _parse_spec_strsetpopr	   hasattrr+   r%   )clsZspec_argkwargsZ
new_kwargsZparsedspec)	__class__ 6lib/python3.7/site-packages/conda/models/match_spec.pyr4   "   s8    




zMatchSpecType.__call__)N)__name__
__module____qualname__r4   __classcell__r=   r=   )r<   r>   r'       s   r'   c               @   sX  e Zd ZdZdZeeZi ZdEddZe	dd Z
d	d
 Zdd ZdFd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	dAdB Z*dCdD Z+dS )Gr-   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   sn   i }| tr |d tt  }d|kr@|dd\}}||d< |dd\}}}||||d | f |S )Nz::r   rC   -r   )rE   rF   rG   )endswithr   lensplitrsplitr2   )r9   dist_strpartschannel_strrE   rF   rG   r=   r=   r>   from_dist_str   s    

zMatchSpec.from_dist_strc             C   s   | j |}|o|jS )N)r/   getexact_value)rR   
field_namevr=   r=   r>   get_exact_value   s    zMatchSpec.get_exact_valuec             C   s   | j |}|o|jS )N)r/   r]   	raw_value)rR   r_   r`   r=   r=   r>   get_raw_value   s    zMatchSpec.get_raw_valuec             C   s   |  |}|d kr|S |S )N)rc   )rR   r_   defaultr`   r=   r=   r>   r]      s    
zMatchSpec.getc             C   s"   t | jdko d| jko | jdkS )Nr   rE   *)rV   r/   rE   )rR   r=   r=   r>   is_name_only_spec   s    
zMatchSpec.is_name_only_specc             C   s   |   S )N)__str__)rR   r=   r=   r>   rY      s    zMatchSpec.dist_strc             C   s   | j S )N)rO   )rR   r=   r=   r>   r(      s    zMatchSpec.optionalc             C   s   | j S )N)rP   )rR   r=   r=   r>   r)      s    zMatchSpec.targetc             C   s   | j S )N)r*   )rR   r=   r=   r>   r1      s    zMatchSpec.original_spec_strc             C   sN   t |tr ddlm} ||}x(t| jD ]\}}| |||s,dS q,W 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recordsrh   Zfrom_objectsr   r/   _match_individual)rR   Zrecrh   r_   r`   r=   r=   r>   match   s    

zMatchSpec.matchc             C   s2   t ||}y
||S  tk
r,   ||kS X d S )N)getattrrj   AttributeError)rR   recordr_   Zmatch_componentvalr=   r=   r>   ri      s
    

zMatchSpec._match_individualc             C   s   t | jdko| dd k	S )Nr   rE   )rV   r/   ra   )rR   r=   r=   r>   
_is_simple   s    zMatchSpec._is_simplec             C   s   t | jdkS )Nr   )rV   r/   )rR   r=   r=   r>   
_is_single   s    zMatchSpec._is_singlec                sJ     d}|r|S t fdddD }tdd |D sBd| S d S d S )NrN   c             3   s   | ]}  |V  qd S )N)ra   ).0x)rR   r=   r>   	<genexpr>  s    z4MatchSpec._to_filename_do_not_use.<locals>.<genexpr>)rE   rF   rG   c             s   s   | ]}|d kV  qd S )Nr=   )rq   rr   r=   r=   r>   rs     s    z%s-%s-%s.tar.bz2)ra   tupleany)rR   Zfn_fieldZvalsr=   )rR   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)rR   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 x| j	D ]|}||krT|| j krT|dkr|rqTt| j | tfdddD r|d |f  n|d!|f  qTW |r|d"d#
|  d$
|S )%NrC   z
channel=%srD   z/%sz	subdir=%srE   re   z::%sz%srF   rG   Fc             3   s   | ]}| kV  qd S )Nr=   )rq   s)rF   r=   r>   rs   +  s    z$MatchSpec.__str__.<locals>.<genexpr>z><$^|,zversion='%s'r   )z!=z~=z.*=z==Tc             3   s   | ]}| kV  qd S )Nr=   )rq   r}   )rG   r=   r>   rs   ?  s    z
build='%s'zbuild=%srK   rN   c             3   s   | ]}| kV  qd S )Nr=   )rq   r}   )valuer=   r>   rs   Q  s    z, =z%s='%s'z%s=%sz[%s],rx   )r/   r]   r^   ry   r   matches_allru   
startswithaddFIELD_NAMESrz   )	rR   r{   bracketsZchannel_matcherZsubdir_matcherZname_matcherZversion_exactZ_skipkeyr=   )rG   r   rF   r>   rg     sr    





zMatchSpec.__str__c             C   s   |   S )N)rg   )rR   r=   r=   r>   __json__[  s    zMatchSpec.__json__c             C   sf   g }|  d}|st|| | d}| d}|rN|s@t|||g7 }n|r\|| d|S )NrE   rG   rF    )ra   AssertionErrorry   rc   rz   )rR   r{   rE   rG   rF   r=   r=   r>   conda_build_form^  s    




zMatchSpec.conda_build_formc             C   s   t |tr| j|jkS dS d S )NF)r,   r-   	_hash_key)rR   otherr=   r=   r>   __eq__o  s    
zMatchSpec.__eq__c             C   s
   t | jS )N)hashr   )rR   r=   r=   r>   __hash__u  s    zMatchSpec.__hash__c             C   s   | j | j| jfS )N)r/   r(   r)   )rR   r=   r=   r>   r   x  s    zMatchSpec._hash_keyc             C   s
   || j kS )N)r/   )rR   Zfieldr=   r=   r>   __contains__|  s    zMatchSpec.__contains__c                sB   t |tj }|r"t| jd| tj t fddt|D S )NzCannot match on field(s): %sc             3   s   | ]\}} ||V  qd S )Nr=   )rq   r   r   )_make_componentr=   r>   rs     s    z.MatchSpec._build_components.<locals>.<genexpr>)r6   r-   FIELD_NAMES_SETr&   r*   r   r   r   )rR   r:   Z
not_fieldsr=   )r   r>   rQ     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 )Nrj   )r8   r-   _MATCHER_CACHEr]   _implementorsExactStrMatchr   )r_   r   Zmatcherr   Z	cache_keyZcached_matcherr=   r=   r>   r     s    

zMatchSpec._make_componentc             C   s   |  dpdS )NrE   re   )ra   )rR   r=   r=   r>   rE     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 )N)r/   )rq   f)rR   r=   r>   rs     s    z'MatchSpec.strictness.<locals>.<genexpr>)rE   rF   rG      rE   rG   rF   r   r   )sumrV   r/   ra   )rR   r}   r=   )rR   r>   
strictness  s    
zMatchSpec.strictnessc             C   s   |   S )N)r   )rR   r=   r=   r>   r;     s    zMatchSpec.specc             C   s   | j dS )NrF   )r/   r]   )rR   r=   r=   r>   rF     s    zMatchSpec.versionc             C   s,   |  dp|  d}|r t|}|s(t|S )NrN   rK   )rc   r   r   )rR   rn   r=   r=   r>   rN     s
    zMatchSpec.fnc                s   t  fdd|D }ttd|}|dg |d g  }g }t tdd t|D }xj|D ]b}ttd|}|d d  t|dkrtdt| |	t|dkrt
d	d
 |n|d  q`W t t||S )Nc             3   s   | ]}|r |V  qd S )Nr=   )rq   r}   )r9   r=   r>   rs     s    z"MatchSpec.merge.<locals>.<genexpr>rE   re   c             s   s    | ]}t td d |V  qdS )c             S   s   | j S )N)r(   )r}   r=   r=   r>   <lambda>      z+MatchSpec.merge.<locals>.<genexpr>.<lambda>N)r   r   )rq   groupr=   r=   r>   rs     s   r)   r   zIncompatible MatchSpec merge:%sc             S   s
   |  |S )N)_merge)rr   yr=   r=   r>   r     r   z!MatchSpec.merge.<locals>.<lambda>r   )rt   r   r   r7   r   r   rV   
ValueErrorr   ry   r
   r   )r9   Zmatch_specsZname_groupsZunmergeableZmerged_specsZmergeable_groupsr   Ztarget_groupsr=   )r9   r>   merge  s    
(zMatchSpec.mergec             C   s   | j |j ks| j|jkr(td| |f i }t| jt|jB }xj|D ]b}| j|}|j|}|d krv|d krvqFqF|d kr|||< qF|d kr|||< qF||||< qFW | jf | j | jd|S )Nz*Incompatible MatchSpec merge:  - %s
  - %s)r(   r)   )r(   r)   r   r6   r/   r]   r   r<   )rR   r   Zfinal_componentsZcomponent_namesZcomponent_nameZthis_componentZthat_componentr=   r=   r>   r     s    


zMatchSpec._merge)FN)N),r?   r@   rA   __doc__r   	frozensetr   r   rS   classmethodr\   ra   rc   r]   propertyrf   rY   r(   r)   r1   rj   ri   ro   rp   rv   r|   rg   r   r   r   r   r   r   r   rQ   staticmethodr   rE   r   r;   rF   rN   r   r   r=   r=   r=   r>   r-   F   sH   Q

	Ir-   c             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   rx   )researchgroupsstripreplace)Zv_plus_brZ   rF   rG   r=   r=   r>   _parse_version_plus_build  s    
r   c             C   s8   |  tr| dt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')
    NrT   r   )rU   r   rV   rX   )rY   rE   rF   rG   r=   r=   r>   _parse_legacy_dist  s    
r   c             C   s&   | sdS t | }|jp|j}||jfS )N)NN)r   rE   Zbase_urlrD   )Zchannel_valZchnZchannel_namer=   r=   r>   _parse_channel  s
    r   c                 s`  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|}x<|D ]4}| \}}}}|r|st|d|||< qpW td| }i }|r(| d	 }| |d} |dd }td|}x&|D ]}| \}}}}|||< qW d|kr(d|d< | dd}t|}|dkrR|\}}} n6|dkrj|\}} d }n|r|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rBt|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	r0|	|d%< |
d k	rB|
|d&< |"| ||d'< |t |< |S )(N@r   re   )rE   rI   #z if r   zIgnoring conditional in spec %sr   )rC   rD   rE   rF   rG   rN   rK   zfile://)rE   rN   rK   z.*(?:(\[.*\]))rx   z2([a-zA-Z0-9_-]+?)=(["\']?)([^\'"]*?)(\2)(?:[, ]|$)zkey-value mismatch in bracketsz.*(?:(\(.*\)))r(   T:r   r   )NNrC   rD   z([^ =<>!~]+)?([><!=~ ].+)?zno package name found in '%s'zno package name found[z&multiple brackets sections not allowedr   z==c             3   s   | ]}| kV  qd S )Nr=   )rq   c)test_strr=   r>   rs     s    z"_parse_spec_str.<locals>.<genexpr>z=,|rE   rF   rG   r*   )#_PARSE_CACHEr]   rU   indexr   rW   rV   logdebugr   r"   r$   r#   r    r   rD   r   Zpackage_filenamecanonical_namer   r!   r   r   rj   r   r   finditerr&   rX   NotImplementedErrorr   r7   r   ru   r2   ) Zspec_strZcached_resultr1   Zfeature_nameZndx_Z
spec_splitrC   rE   rF   rG   resultZpath_or_urlr   Zm3Zbrackets_strZm3brj   r   r   Zm4ZparensZ
parens_strZm4bZm5Zm5_lenr[   	namespacerD   Z	b_channelZb_subdirZ
componentsr=   )r   r>   r5   !  s    


























r5   c               @   sH   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S )MatchInterfacec             C   s
   || _ d S )N)
_raw_value)rR   r   r=   r=   r>   rS     s    zMatchInterface.__init__c             C   s
   t  d S )N)r   )rR   r   r=   r=   r>   rj     s    zMatchInterface.matchc             C   s
   |  |S )N)rj   )rR   r   r=   r=   r>   matches  s    zMatchInterface.matchesc             C   s   | j S )N)r   )rR   r=   r=   r>   rb     s    zMatchInterface.raw_valuec             C   s
   t  dS )ziIf the match value is an exact specification, returns the value.
        Otherwise returns None.
        N)r   )rR   r=   r=   r>   r^     s    zMatchInterface.exact_valuec             C   s&   | j |j kr td| j |j f | j S )Nz+Incompatible component merge:
  - %r
  - %r)rb   r   )rR   r   r=   r=   r>   r     s    zMatchInterface.mergeN)r?   r@   rA   rS   r   rj   r   r   rb   r   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 )N)r   )rR   r=   r=   r>   rg     s    z_StrMatchMixin.__str__c             C   s   d| j j| jf S )Nz%s('%s'))r<   r?   r   )rR   r=   r=   r>   r|     s    z_StrMatchMixin.__repr__c             C   s   t || jo| j|jkS )N)r,   r<   r   )rR   r   r=   r=   r>   r     s    z_StrMatchMixin.__eq__c             C   s
   t | jS )N)r   r   )rR   r=   r=   r>   r     s    z_StrMatchMixin.__hash__c             C   s   | j S )N)r   )rR   r=   r=   r>   r^     s    z_StrMatchMixin.exact_valueN)	r?   r@   rA   rg   r|   r   r   r   r^   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 )N)r3   r   rS   )rR   r   )r<   r=   r>   rS     s    zExactStrMatch.__init__c             C   s2   y
|j }W n tk
r&   t|}Y nX | j |kS )N)r   rl   r   )rR   r   
_other_valr=   r=   r>   rj     s
    
zExactStrMatch.match)r?   r@   rA   	__slots__rS   rj   rB   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 )N)r3   r   rS   lower)rR   r   )r<   r=   r>   rS     s    zExactLowerStrMatch.__init__c             C   s6   y
|j }W n tk
r&   t|}Y nX | j | kS )N)r   rl   r   r   )rR   r   r   r=   r=   r>   rj     s
    
zExactLowerStrMatch.match)r?   r@   rA   rS   rj   rB   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^$re   z\*z.*z^(?:%s)$)r3   r   rS   r   r   rU   r   compilerj   escaper   )rR   r   )r<   r=   r>   rS     s    zGlobStrMatch.__init__c             C   sF   y
|j }W n tk
r&   t|}Y nX | jr8| |S | j |kS d S )N)r   rl   r   r   )rR   r   r   r=   r=   r>   rj   #  s    

zGlobStrMatch.matchc             C   s   | j d kr| jS d S )N)r   r   )rR   r=   r=   r>   r^   .  s    zGlobStrMatch.exact_valuec             C   s
   | j dkS )Nre   )r   )rR   r=   r=   r>   r   2  s    zGlobStrMatch.matches_all)
r?   r@   rA   r   rS   rj   r   r^   r   rB   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 )N)r3   r   rS   r   )rR   r   )r<   r=   r>   rS   9  s    zGlobLowerStrMatch.__init__)r?   r@   rA   rS   rB   r=   r=   )r<   r>   r   7  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 )SplitStrMatch)r   c                s   t t| | | d S )N)r3   r   rS   _convert)rR   r   )r<   r=   r>   rS   @  s    zSplitStrMatch.__init__c             C   sB   yt |dddS  tk
r<   t|r6t |S  Y nX d S )Nr   r   )r   r   rW   rl   r   )rR   r   r=   r=   r>   r   C  s    zSplitStrMatch._convertc             C   s6   y|o| j |j @ S  tk
r0   | j | |@ S X d S )N)r   rl   r   )rR   r   r=   r=   r>   rj   K  s    zSplitStrMatch.matchc             C   s,   | j r$dddd t| j D  S dS d S )Nz{%s}z, c             s   s   | ]}d | V  qdS )z'%s'Nr=   )rq   r}   r=   r=   r>   rs   S  s    z)SplitStrMatch.__repr__.<locals>.<genexpr>zset())r   rz   sorted)rR   r=   r=   r>   r|   Q  s    zSplitStrMatch.__repr__c             C   s   d t| jS )Nr   )rz   r   r   )rR   r=   r=   r>   rg   W  s    zSplitStrMatch.__str__c             C   s   t || jo| j|jkS )N)r,   r<   r   )rR   r   r=   r=   r>   r   [  s    zSplitStrMatch.__eq__c             C   s
   t | jS )N)r   r   )rR   r=   r=   r>   r   ^  s    zSplitStrMatch.__hash__c             C   s   | j S )N)r   )rR   r=   r=   r>   r^   a  s    zSplitStrMatch.exact_value)r?   r@   rA   r   rS   r   rj   r|   rg   r   r   r   r^   rB   r=   r=   )r<   r>   r   =  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 )FeatureMatch)r   c                s   t t| | | d S )N)r3   r   rS   r   )rR   r   )r<   r=   r>   rS   i  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 )Nr=   )rq   r   r=   r=   r>   rs   p  s    z(FeatureMatch._convert.<locals>.<genexpr>c             s   s   | ]}|  V  qd S )N)r   )rq   ffr=   r=   r>   rs   q  s    r   r   c             s   s   | ]}|r|V  qd S )Nr=   )rq   r   r=   r=   r>   rs   t  s    c             s   s   | ]}|  V  qd S )N)r   )rq   r   r=   r=   r>   rs   t  s    )r   r,   r   r   rW   )rR   r   r=   r=   r>   r   l  s    
"zFeatureMatch._convertc             C   s   |  |}| j|kS )N)r   r   )rR   r   r=   r=   r>   rj   v  s    
zFeatureMatch.matchc             C   s   dd dd t| jD  S )Nz[%s]z, c             s   s   | ]}d | V  qdS )z'%s'Nr=   )rq   kr=   r=   r>   rs   {  s    z(FeatureMatch.__repr__.<locals>.<genexpr>)rz   r   r   )rR   r=   r=   r>   r|   z  s    zFeatureMatch.__repr__c             C   s   d t| jS )Nr   )rz   r   r   )rR   r=   r=   r>   rg   }  s    zFeatureMatch.__str__c             C   s   t || jo| j|jkS )N)r,   r<   r   )rR   r   r=   r=   r>   r     s    zFeatureMatch.__eq__c             C   s
   t | jS )N)r   r   )rR   r=   r=   r>   r     s    zFeatureMatch.__hash__c             C   s   | j S )N)r   )rR   r=   r=   r>   r^     s    zFeatureMatch.exact_value)r?   r@   rA   r   rS   r   rj   r|   rg   r   r   r   r^   rB   r=   r=   )r<   r>   r   f  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   re   z^(?:%s)$z.*)r   r,   r   r   rU   r   r   rj   r   r   r3   r   rS   )rR   r   )r<   r=   r>   rS     s    
zChannelMatch.__init__c             C   s^   y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 )N)r   r   rl   r   r   rE   )rR   r   r   r=   r=   r>   rj     s    zChannelMatch.matchc             C   s,   yd| j j S  tk
r&   d| j  S X d S )Nz%s)r   rE   rl   )rR   r=   r=   r>   rg     s    zChannelMatch.__str__c             C   s   d|    S )Nz'%s')rg   )rR   r=   r=   r>   r|     s    zChannelMatch.__repr__)r?   r@   rA   rS   rj   rg   r|   rB   r=   r=   )r<   r>   r     s   r   c               @   s   e Zd Zdd ZdS )CaseInsensitiveStrMatchc             C   sN   y
|j }W n tk
r&   t|}Y nX | }| jr@| |S | j |kS d S )N)r   rl   r   r   r   )rR   r   r   r=   r=   r>   rj     s    

zCaseInsensitiveStrMatch.matchN)r?   r@   rA   rj   r=   r=   r=   r>   r     s   r   )	rC   rE   rF   rG   rH   rI   rJ   rL   rM   )NZ
__future__r   r   r   r   abcr   r   r   Zcollections.abcr	   ImportErrorcollections	functoolsr
   Zloggingr   operatorr   os.pathr   r   rC   r   rF   r   r   Z_vendor.auxlib.collectionr   Z_vendor.auxlib.decoratorsr   Z_vendor.toolzr   r   r   Zbase.constantsr   Zcommon.compatr   r   r   r   r   r   Z	common.ior   Zcommon.pathr    r!   Z
common.urlr"   r#   r$   
exceptionsr%   r&   r?   r   typer'   objectr-   r   r   r   r   r5   r   r   r   r   r   r   r   r   r   r   r   r=   r=   r=   r>   <module>   sl    &   ' *!)%'