????

Your IP : 216.73.216.152


Current Path : /usr/lib/python2.7/site-packages/pip/_vendor/urllib3/packages/rfc3986/
Upload File :
Current File : //usr/lib/python2.7/site-packages/pip/_vendor/urllib3/packages/rfc3986/validators.pyc

�
}�\]c@sdZddlmZddlmZddlmZdefd��YZd�Zd�Zd	�Z	d
�Z
ded�Z
ed�Zed
�Zed�Zed�Zed�Zd�Zied6ed6ed6ed6Zedddg�Zd�Zd�ZdS(s3Module containing the validation logic for rfc3986.i(t
exceptions(tmisc(tnormalizerst	ValidatorcBs�eZdZedddddddg�Zd�Zd	�Zd
�Zd�Zd�Z	d
�Z
d�Zd�Zd�Z
RS(s�Object used to configure validation of all objects in rfc3986.

    .. versionadded:: 1.0

    Example usage::

         >>> from rfc3986 import api, validators
         >>> uri = api.uri_reference('https://github.com/')
         >>> validator = validators.Validator().require_presence_of(
         ...    'scheme', 'host', 'path',
         ... ).allow_schemes(
         ...    'http', 'https',
         ... ).allow_hosts(
         ...    '127.0.0.1', 'github.com',
         ... )
         >>> validator.validate(uri)
         >>> invalid_uri = rfc3986.uri_reference('imap://mail.google.com')
         >>> validator.validate(invalid_uri)
         Traceback (most recent call last):
         ...
         rfc3986.exceptions.MissingComponentError: ('path was required but
         missing', URIReference(scheme=u'imap', authority=u'mail.google.com',
         path=None, query=None, fragment=None), ['path'])

    tschemetuserinfothosttporttpathtquerytfragmentcCs}t�|_t�|_t�|_t|_itd6td6td6td6td6td6td6|_|jj�|_	dS(	s#Initialize our default validations.RRRRRR	R
N(
tsettallowed_schemest
allowed_hostst
allowed_portstTruetallow_passwordtFalsetrequired_componentstcopytvalidated_components(tself((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyt__init__:s	
cGs.x'|D]}|jjtj|��qW|S(s	Require the scheme to be one of the provided schemes.

        .. versionadded:: 1.0

        :param schemes:
            Schemes, without ``://`` that are allowed.
        :returns:
            The validator instance.
        :rtype:
            Validator
        (RtaddRtnormalize_scheme(RtschemesR((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyt
allow_schemesKs
cGs.x'|D]}|jjtj|��qW|S(s�Require the host to be one of the provided hosts.

        .. versionadded:: 1.0

        :param hosts:
            Hosts that are allowed.
        :returns:
            The validator instance.
        :rtype:
            Validator
        (R
RRtnormalize_host(RthostsR((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytallow_hosts[s
cGsVxO|D]G}t|dd�}d|ko6dknr|jj|�qqW|S(s�Require the port to be one of the provided ports.

        .. versionadded:: 1.0

        :param ports:
            Ports that are allowed.
        :returns:
            The validator instance.
        :rtype:
            Validator
        tbasei
ii��(tintRR(RtportsRtport_int((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytallow_portsks

cCs
t|_|S(s�Allow passwords to be present in the URI.

        .. versionadded:: 1.0

        :returns:
            The validator instance.
        :rtype:
            Validator
        (RR(R((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytallow_use_of_password}s
	cCs
t|_|S(s�Prevent passwords from being included in the URI.

        .. versionadded:: 1.0

        :returns:
            The validator instance.
        :rtype:
            Validator
        (RR(R((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytforbid_use_of_password�s
	cGsug|D]}|j�^q}x5|D]-}||jkr&tdj|���q&q&W|jjd�|D��|S(sACheck the validity of the components provided.

        This can be specified repeatedly.

        .. versionadded:: 1.1

        :param components:
            Names of components from :attr:`Validator.COMPONENT_NAMES`.
        :returns:
            The validator instance.
        :rtype:
            Validator
        s"{}" is not a valid componentcSsi|]}t|�qS((R(t.0t	component((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pys
<dictcomp>�s	(tlowertCOMPONENT_NAMESt
ValueErrortformatRtupdate(Rt
componentstcR&((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytcheck_validity_of�s
	cGsug|D]}|j�^q}x5|D]-}||jkr&tdj|���q&q&W|jjd�|D��|S(s3Require the components provided.

        This can be specified repeatedly.

        .. versionadded:: 1.0

        :param components:
            Names of components from :attr:`Validator.COMPONENT_NAMES`.
        :returns:
            The validator instance.
        :rtype:
            Validator
        s"{}" is not a valid componentcSsi|]}t|�qS((R(R%R&((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pys
<dictcomp>�s	(R'R(R)R*RR+(RR,R-R&((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytrequire_presence_of�s
	cCs�|jst|�ng|jj�D]\}}|r&|^q&}g|jj�D]\}}|rT|^qT}|r�t||�n|r�t||�nt|j|d�t|j	|d�t|j
|d�dS(s�Check a URI for conditions specified on this validator.

        .. versionadded:: 1.0

        :param uri:
            Parsed URI to validate.
        :type uri:
            rfc3986.uri.URIReference
        :raises MissingComponentError:
            When a required component is missing.
        :raises UnpermittedComponentError:
            When a component is not one of those allowed.
        :raises PasswordForbidden:
            When a password is present in the userinfo component but is
            not permitted by configuration.
        :raises InvalidComponentsError:
            When a component was found to be invalid.
        RRRN(Rtcheck_passwordRtitemsRt ensure_required_components_existtensure_components_are_validt
ensure_one_ofRR
R(RturiR&trequiredRR((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytvalidate�s	
(t__name__t
__module__t__doc__t	frozensetR(RRRR"R#R$R.R/R7(((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyRs$					
	
		cCsN|j}|sdS|jdd�}t|�dkr;dStj|��dS(s4Assert that there is no password present in the uri.Nt:i(RtsplittlenRtPasswordForbidden(R5Rtcredentials((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyR0�s	cCsIt||�}|dk	rE|rE||krEtj|||��ndS(s=Assert that the uri's attribute is one of the allowed values.N(tgetattrtNoneRtUnpermittedComponentError(tallowed_valuesR5t	attributetvalue((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyR4�scCsStg|D]!}t||�dkr
|^q
�}|rOtj||��ndS(s;Assert that all required components are present in the URI.N(tsortedRARBRtMissingComponentError(R5RR&tmissing_components((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyR2s
$cCs8|r|dk	o|j|�S|dkp7|j|�S(sDetermine if a value is valid based on the provided matcher.

    :param str value:
        Value to validate.
    :param matcher:
        Compiled regular expression to use to validate the value.
    :param require:
        Whether or not the value is required.
    N(RBtmatch(RFtmatchertrequire((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytis_valids

cCs8t|tj|�}|r4|dk	r4t||�S|S(snDetermine if the authority string is valid.

    :param str authority:
        The authority to validate.
    :param str host:
        (optional) The host portion of the authority to validate.
    :param bool require:
        (optional) Specify if authority must not be None.
    :returns:
        ``True`` if valid, ``False`` otherwise
    :rtype:
        bool
    N(RMRtSUBAUTHORITY_MATCHERRBt
host_is_valid(t	authorityRRLt	validated((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytauthority_is_valid$s
cCs�t|tj|�}|rC|dk	rCtjj|�rCt|�S|r}|dk	r}tjj|�r}tjj|�dk	S|S(sDetermine if the host string is valid.

    :param str host:
        The host to validate.
    :param bool require:
        (optional) Specify if host must not be None.
    :returns:
        ``True`` if valid, ``False`` otherwise
    :rtype:
        bool
    N(	RMRtHOST_MATCHERRBtIPv4_MATCHERRJtvalid_ipv4_host_addresstIPv6_MATCHERtIPv6_NO_RFC4007_MATCHER(RRLRQ((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyRO8s$
$cCst|tj|�S(s+Determine if the scheme is valid.

    :param str scheme:
        The scheme string to validate.
    :param bool require:
        (optional) Set to ``True`` to require the presence of a scheme.
    :returns:
        ``True`` if the scheme is valid. ``False`` otherwise.
    :rtype:
        bool
    (RMRtSCHEME_MATCHER(RRL((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytscheme_is_validLscCst|tj|�S(s+Determine if the path component is valid.

    :param str path:
        The path string to validate.
    :param bool require:
        (optional) Set to ``True`` to require the presence of a path.
    :returns:
        ``True`` if the path is valid. ``False`` otherwise.
    :rtype:
        bool
    (RMRtPATH_MATCHER(RRL((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyt
path_is_valid[scCst|tj|�S(s0Determine if the query component is valid.

    :param str query:
        The query string to validate.
    :param bool require:
        (optional) Set to ``True`` to require the presence of a query.
    :returns:
        ``True`` if the query is valid. ``False`` otherwise.
    :rtype:
        bool
    (RMRt
QUERY_MATCHER(R	RL((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytquery_is_validjscCst|tj|�S(s?Determine if the fragment component is valid.

    :param str fragment:
        The fragment string to validate.
    :param bool require:
        (optional) Set to ``True`` to require the presence of a fragment.
    :returns:
        ``True`` if the fragment is valid. ``False`` otherwise.
    :rtype:
        bool
    (RMRtFRAGMENT_MATCHER(R
RL((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytfragment_is_validyscCsHtg|jd�D].}dt|dd�ko<dkn^q�S(s4Determine if the given host is a valid IPv4 address.t.iRi
i�(tallR=R(Rtbyte((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyRU�sRRR	R
RRRcCs�y|j�}Wntjk
r'tSX|dkrBt|d�S|dkrRtSyt|d�}Wntk
rztSXd|ko�dkSS(s4Determine if the userinfo, host, and port are valid.RRii��(tauthority_infoRtInvalidAuthorityRRORRt	TypeError(R5R&tsubauthority_dictR((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pytsubauthority_component_is_valid�s
cCs�tg�}xn|D]f}|tkrJt||�s|j|�qqnt|}|t||��s|j|�qqW|r�tj||��ndS(s0Assert that all components are valid in the URI.N(Rt_SUBAUTHORITY_VALIDATORSRgRt_COMPONENT_VALIDATORSRARtInvalidComponentsError(R5Rtinvalid_componentsR&t	validator((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyR3�s

N(R:tRRRtobjectRR0R4R2RMRBRRRRORYR[R]R_RURiRRhRgR3(((sN/tmp/pip-install-ewDPok/pip/pip/_vendor/urllib3/packages/rfc3986/validators.pyt<module>s.�