Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib/python3.7/site-packages/future/backports/urllib/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/future/backports/urllib/__pycache__/request.cpython-37.pyc

B

�A�[�w�@sdZddlmZmZmZmZddlmZmZm	Z	m
Z
mZmZm
Z
mZddlmZmZmZddlZddlZddlZddlZddlmZddlmZdd	lmZmZmZdd
l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4ddl5Z5ddl6Z6ddl7Z7ddl8Z8ddl9Z9ddl:Z:ddl;Z;ddl<Z<ddl=Z=ddl>Z>ddl?Z?yddl@Z@ddl@mAZAWneBk
�r�d
ZCYnXdZCdddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-gZDe:jEdd.�ZFdaGde9jHfd/d$�ZId0d%�ZJgZKdd1d*�ZLd2d+�ZMe�r(e8�Nd3e8jO�ZPn
e8�Nd3�ZPd4d5�ZQGd6d�deR�ZSGd7d�deR�ZTd8d&�ZUGd9d�deR�ZVGd:d#�d#eV�ZWGd;d�deV�ZXGd<d�deV�ZYd=d>�ZZGd?d�deV�Z[Gd@d�deR�Z\GdAd�de\�Z]GdBd�deR�Z^GdCd�de^eV�Z_GdDd�de^eV�Z`e6jaZbGdEd�deR�ZcGdFd�deVec�ZdGdGd�deVec�ZeGdHdI�dIeV�ZfGdJd�def�ZgehedK��r�GdLdM�dMef�ZieD�jdM�GdNd�deV�ZkGdOd"�d"eV�ZldPdQ�ZmdRdS�ZnGdTd�deV�ZodUdV�ZpGdWd �d eV�ZqGdXd!�d!eq�ZrdYZse6jtdZk�rdd[lumvZvmwZwnd\d(�Zvd]d'�ZwiZxGd^d,�d,eR�ZyGd_d-�d-ey�Zzda{d`da�Z|da}dbdc�Z~daddde�Z�da�dfdg�Z�Gdhdi�dieR�Z�djdk�Z�dldm�Z�dndo�Z�e:j�dpk�r�ddql�m�Z�m�Z�drds�Z�dtdu�Z�dvdw�Z�dxd)�Z�n6e6jtdZk�rdydz�Z�d{d)�Z�d|d}�Z�d~dw�Z�ne�Z�e�Z�dS)�a�

Ported using Python-Future from the Python 3.3 standard library.

An extensible library for opening URLs using a variety of protocols

The simplest way to use this module is to call the urlopen function,
which accepts a string containing a URL or a Request object (described
below).  It opens the URL and returns the results as file-like
object; the returned object has some extra methods described below.

The OpenerDirector manages a collection of Handler objects that do
all the actual work.  Each Handler implements a particular protocol or
option.  The OpenerDirector is a composite object that invokes the
Handlers needed to open the requested URL.  For example, the
HTTPHandler performs HTTP GET and POST requests and deals with
non-error returns.  The HTTPRedirectHandler automatically deals with
HTTP 301, 302, 303 and 307 redirect errors, and the HTTPDigestAuthHandler
deals with digest authentication.

urlopen(url, data=None) -- Basic usage is the same as original
urllib.  pass the url and optionally data to post to an HTTP URL, and
get a file-like object back.  One difference is that you can also pass
a Request instance instead of URL.  Raises a URLError (subclass of
IOError); for HTTP errors, raises an HTTPError, which can also be
treated as a valid response.

build_opener -- Function that creates a new OpenerDirector instance.
Will install the default handlers.  Accepts one or more Handlers as
arguments, either instances or Handler classes that it will
instantiate.  If one of the argument is a subclass of the default
handler, the argument will be installed instead of the default.

install_opener -- Installs a new opener as the default opener.

objects of interest:

OpenerDirector -- Sets up the User Agent as the Python-urllib client and manages
the Handler classes, while dealing with requests and responses.

Request -- An object that encapsulates the state of a request.  The
state can be as simple as the URL.  It can also include extra HTTP
headers, e.g. a User-Agent.

BaseHandler --

internals:
BaseHandler and parent
_call_chain conventions

Example usage:

import urllib.request

# set up authentication info
authinfo = urllib.request.HTTPBasicAuthHandler()
authinfo.add_password(realm='PDQ Application',
                      uri='https://mahler:8092/site-updates.py',
                      user='klem',
                      passwd='geheim$parole')

proxy_support = urllib.request.ProxyHandler({"http" : "http://ahad-haam:3128"})

# build a new opener that adds authentication and caching FTP handlers
opener = urllib.request.build_opener(proxy_support, authinfo,
                                     urllib.request.CacheFTPHandler)

# install it
urllib.request.install_opener(opener)

f = urllib.request.urlopen('http://www.python.org/')
�)�absolute_import�division�print_function�unicode_literals)�bytes�dict�filter�input�int�map�open�str)�PY2�PY3�raise_with_tracebackN)�email)�client�)�URLError�	HTTPError�ContentTooShortError)�urlparse�urlsplit�urljoin�unwrap�quote�unquote�	splittype�	splithost�	splitport�	splituser�splitpasswd�	splitattr�
splitquery�
splitvalue�splittag�to_bytes�
urlunparse)�
addinfourl�addclosehook)�
SSLContextFT�Request�OpenerDirector�BaseHandler�HTTPDefaultErrorHandler�HTTPRedirectHandler�HTTPCookieProcessor�ProxyHandler�HTTPPasswordMgr�HTTPPasswordMgrWithDefaultRealm�AbstractBasicAuthHandler�HTTPBasicAuthHandler�ProxyBasicAuthHandler�AbstractDigestAuthHandler�HTTPDigestAuthHandler�ProxyDigestAuthHandler�HTTPHandler�FileHandler�
FTPHandler�CacheFTPHandler�UnknownHandler�HTTPErrorProcessor�urlopen�install_opener�build_opener�pathname2url�url2pathname�
getproxies�urlretrieve�
urlcleanup�	URLopener�FancyURLopener�c
Ks�d|kr|d}|d=nd}d|kr4|d}|d=nd}d|krP|d}|d=nd}|s`|s`|r�tsltd��t�tj�}|jtjO_tj|_|s�|r�|�	||�n|�
�t|dd�}t|�}	nt
dkr�t�a
}	nt
}	|	�|||�S)N�	cadefaultF�capath�cafilezSSL support not availableT)�context�check_hostname)�	_have_ssl�
ValueError�sslr*ZPROTOCOL_SSLv23�optionsZOP_NO_SSLv2Z
CERT_REQUIREDZverify_modeZload_verify_locationsZset_default_verify_paths�HTTPSHandlerrB�_openerr)
�url�data�timeoutZ_3to2kwargsrKrLrMrNZ
https_handler�opener�rZ�P/opt/alt/python37/lib/python3.7/site-packages/future/backports/urllib/request.pyr@�s6
cCs|adS)N)rU)rYrZrZr[rA�sc
Cs2t|�\}}t�t||����}|��}|dkrB|sBtj�|�|fS|rRt|d�}nt	j
dd�}|j}t�
|�|��||f}	d}
d}d}d}
d|kr�t|d	�}|r�||
|
|�xB|�|
�}|s�P|t|�7}|�|�|
d
7}
|r�||
|
|�q�WWdQRXWdQRX|dk�r.||k�r.td||f|	��|	S)
aW
    Retrieve a URL into a temporary location on disk.

    Requires a URL argument. If a filename is passed, it is used as
    the temporary file location. The reporthook argument should be
    a callable that accepts a block number, a read size, and the
    total file size of the URL target. The data argument should be
    valid URL encoded data.

    If a filename is passed and the URL points to a local resource,
    the result is a copy from local file to new file.

    Returns a tuple containing the path to the newly created
    data file as well as the resulting HTTPMessage object.
    �file�wbF)�deletei ���rzcontent-lengthzContent-LengthrNz1retrieval incomplete: got only %i out of %i bytes)r�
contextlib�closingr@�info�os�path�normpathr�tempfile�NamedTemporaryFile�name�_url_tempfiles�appendr
�read�len�writer)rV�filename�
reporthookrWZurl_typerd�fp�headers�tfp�result�bs�sizerk�blocknum�blockrZrZr[rF�sD


$c	CsHx0tD](}yt�|�Wqtk
r,YqXqWtdd�=trDdadS)N)rirc�unlink�EnvironmentErrorrU)Z	temp_filerZrZr[rG�s


z:\d+$cCs<|j}t|�d}|dkr&|�dd�}t�d|d�}|��S)z�Return request-host, as defined by RFC 2965.

    Variation from RFC: returned value is lowercased, for convenient
    comparison.

    r��Host)�full_urlr�
get_header�_cut_port_re�sub�lower)�requestrV�hostrZrZr[�request_hostsr�c@s�eZdZdidddfdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd)d%d&�Zd'd(�ZdS)*r+NFc	Cs�t|�|_t|j�\|_|_||_i|_d|_x |��D]\}}|�||�q8Wi|_	|dkrft
|�}||_||_||_
|��dS)N)rr|r%�fragmentrWrq�_tunnel_host�items�
add_header�unredirected_hdrsr��origin_req_host�unverifiable�method�_parse)	�selfrVrWrqr�r�r��key�valuerZrZr[�__init__s
zRequest.__init__cCsNt|j�\|_}|jdkr(td|j��t|�\|_|_|jrJt|j�|_dS)Nzunknown url type: %r)rr|�typerQrr��selectorr)r��restrZrZr[r�(s
zRequest._parsecCs&|jdk	r|jS|jdk	rdSdSdS)z3Return a string indicating the HTTP request method.N�POST�GET)r�rW)r�rZrZr[�
get_method0s


zRequest.get_methodcCs |jrd|j|jfS|jSdS)Nz%s#%s)r�r|)r�rZrZr[�get_full_url9szRequest.get_full_urlcCsd}tj|tdd�||_dS)Nz&Request.add_data method is deprecated.r)�
stacklevel)�warnings�warn�DeprecationWarningrW)r�rW�msgrZrZr[�add_dataAszRequest.add_datacCsd}tj|tdd�|jdk	S)Nz&Request.has_data method is deprecated.r)r�)r�r�r�rW)r�r�rZrZr[�has_dataFszRequest.has_datacCsd}tj|tdd�|jS)Nz&Request.get_data method is deprecated.r)r�)r�r�r�rW)r�r�rZrZr[�get_dataKszRequest.get_datacCsd}tj|tdd�|jS)Nz&Request.get_type method is deprecated.r)r�)r�r�r�r�)r�r�rZrZr[�get_typePszRequest.get_typecCsd}tj|tdd�|jS)Nz&Request.get_host method is deprecated.r)r�)r�r�r�r�)r�r�rZrZr[�get_hostUszRequest.get_hostcCsd}tj|tdd�|jS)Nz*Request.get_selector method is deprecated.r)r�)r�r�r�r�)r�r�rZrZr[�get_selectorZszRequest.get_selectorcCsd}tj|tdd�|jS)Nz-Request.is_unverifiable method is deprecated.r)r�)r�r�r�r�)r�r�rZrZr[�is_unverifiable_szRequest.is_unverifiablecCsd}tj|tdd�|jS)Nz1Request.get_origin_req_host method is deprecated.r)r�)r�r�r�r�)r�r�rZrZr[�get_origin_req_hostdszRequest.get_origin_req_hostcCs2|jdkr|js|j|_n||_|j|_||_dS)N�https)r�r�r�r|r�)r�r�r�rZrZr[�	set_proxyks

zRequest.set_proxycCs|j|jkS)N)r�r|)r�rZrZr[�	has_proxysszRequest.has_proxycCs||j|��<dS)N)rq�
capitalize)r�r��valrZrZr[r�vszRequest.add_headercCs||j|��<dS)N)r�r�)r�r�r�rZrZr[�add_unredirected_headerzszRequest.add_unredirected_headercCs||jkp||jkS)N)rqr�)r��header_namerZrZr[�
has_header~s
zRequest.has_headercCs|j�||j�||��S)N)rq�getr�)r�r��defaultrZrZr[r}�szRequest.get_headercCs"|j��}|�|j�t|���S)N)r��copy�updaterq�listr�)r��hdrsrZrZr[�header_items�s
zRequest.header_items)N)�__name__�
__module__�__qualname__r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r}r�rZrZrZr[r+s*	
c@sNeZdZdd�Zdd�Zdd�Zdd�Zd	ejfd
d�Z	ddd
�Z
dd�Zd	S)r,cCs6dt}d|fg|_g|_i|_i|_i|_i|_dS)NzPython-urllib/%sz
User-agent)�__version__�
addheaders�handlers�handle_open�handle_error�process_response�process_request)r�Zclient_versionrZrZr[r��szOpenerDirector.__init__c	CsZt|d�stdt|���d}�xt|�D�]}|dkr:q*|�d�}|d|�}||dd�}|�d�r�|�d�|d}||dd�}yt|�}Wntk
r�YnX|j�	|i�}	|	|j|<n>|dkr�|}|j
}	n*|d	kr�|}|j}	n|d
kr*|}|j}	nq*|	�
|g�}
|
�r&t�|
|�n
|
�|�d}q*W|�rVt�|j|�|�|�dS)N�
add_parentz%expected BaseHandler instance, got %rF)�redirect_request�do_open�
proxy_open�_r�errorr�responser�T)�hasattr�	TypeErrorr��dir�find�
startswithr
rQr�r�r�r�r��
setdefault�bisect�insortrjr�r�)r��handlerZadded�meth�i�protocolZ	condition�j�kind�lookupr�rZrZr[�add_handler�sJ



zOpenerDirector.add_handlercCsdS)NrZ)r�rZrZr[�close�szOpenerDirector.closec	Gs<|�|d�}x*|D]"}t||�}||�}|dk	r|SqWdS)NrZ)r��getattr)	r��chainr��	meth_name�argsr�r��funcrsrZrZr[�_call_chain�s

zOpenerDirector._call_chainNc
Cs�t|t�r|��}t|t�r(t||�}n|}|dk	r:||_||_|j}|d}x(|j�	|g�D]}t
||�}||�}q^W|�||�}	|d}x*|j�	|g�D]}t
||�}|||	�}	q�W|	S)z�
        Accept a URL or a Request object

        Python-Future: if the URL is passed as a byte-string, decode it first.
        NZ_requestZ	_response)
�
isinstancer�decoder
r+rWrXr�r�r�r��_openr�)
r��fullurlrWrX�reqr�r��	processorr�r�rZrZr[r�s&



zOpenerDirector.opencCsP|�|jdd|�}|r|S|j}|�|j||d|�}|r>|S|�|jdd|�S)Nr�Zdefault_openr��unknown�unknown_open)r�r�r�)r�r�rWrsr�rZrZr[r��s


zOpenerDirector._opencGs~|dkr,|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|�}|r^|S|rz|dd	f|}|j|�SdS)
N)�httpr�r��z
http_error_%sr�_errorrr��http_error_default)r�r�)r��protor�rr�Zhttp_errZ	orig_argsrsrZrZr[r�s 

zOpenerDirector.error)N)r�r�r�r�r�r�r��socket�_GLOBAL_DEFAULT_TIMEOUTrr�r�rZrZrZr[r,�s/"
cGs�dd�}t�}ttttttttg}t	t
d�r6|�t�t
�}xL|D]D}x>|D]6}||�rnt||�r�|�|�qLt||�rL|�|�qLWqBWx|D]}|�|�q�Wx|D]}|�|��q�Wx$|D]}||�r�|�}|�|�q�W|S)a*Create an opener object from a list of handlers.

    The opener will use several default handlers, including support
    for HTTP, FTP and when applicable HTTPS.

    If any of the handlers passed as arguments are subclasses of the
    default handlers, the default handlers will not be used.
    cSst|t�pt|d�S)N�	__bases__)r�r�r�)�objrZrZr[�isclass)szbuild_opener.<locals>.isclass�HTTPSConnection)r,r1r>r:r.r/r<r;r?r��http_clientrjrT�set�
issubclass�addr��remover�)r�r�rYZdefault_classes�skip�klass�check�hrZrZr[rB s0	









c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r-i�cCs
||_dS)N)�parent)r�r�rZrZr[r�IszBaseHandler.add_parentcCsdS)NrZ)r�rZrZr[r�LszBaseHandler.closecCst|d�sdS|j|jkS)N�
handler_orderT)r�r�)r��otherrZrZr[�__lt__Ps
zBaseHandler.__lt__N)r�r�r�r�r�r�r�rZrZrZr[r-Fsc@s eZdZdZdZdd�ZeZdS)r?zProcess HTTP error responses.i�cCsH|j|j|��}}}d|kr,dksDn|j�d|||||�}|S)N��i,r�)�coder�rbr�r�)r�r�r�r�r�r�rZrZr[�
http_response]s
z HTTPErrorProcessor.http_responseN)r�r�r��__doc__r�r��https_responserZrZrZr[r?Ysc@seZdZdd�ZdS)r.cCst|j||||��dS)N)rr|)r�r�rpr�r�r�rZrZr[r�ksz*HTTPDefaultErrorHandler.http_error_defaultN)r�r�r�r�rZrZrZr[r.jsc@s4eZdZdZdZdd�Zdd�ZeZZZ	dZ
dS)	r/��
c	sx|��}|dkr|dks:|dkr(|dks:t|j||||��|�dd�}d�t�fdd	�|j��D��}t|||jd
d�S)a�Return a Request or None in response to a redirect.

        This is called by the http_error_30x methods when a
        redirection response is received.  If a redirection should
        take place, return a new Request to allow http_error_30x to
        perform the redirect.  Otherwise, raise HTTPError if no-one
        else should try to handle this url.  Return None if you can't
        but another Handler might.
        )i-i.i/i3)r�ZHEAD)i-i.i/r�� z%20)zcontent-lengthzcontent-typec3s&|]\}}|���kr||fVqdS)N)r�)�.0�k�v)�CONTENT_HEADERSrZr[�	<genexpr>�sz7HTTPRedirectHandler.redirect_request.<locals>.<genexpr>T)rqr�r�)	r�rr|�replacerrqr�r+r�)	r�r�rpr�r�rq�newurl�m�
newheadersrZ)rr[r�vs
z$HTTPRedirectHandler.redirect_requestc
Cs2d|kr|d}nd|kr$|d}ndSt|�}|jdkrRt||d||f||��|jsht|�}d|d<t|�}t|j|�}|�||||||�}|dkr�dSt	|d�r�|j
}	|_
|	�|d�|jks�t
|	�|jkr�t|j||j|||��ni}	|_
|_
|	�|d�d	|	|<|��|��|jj||jd
�S)N�location�uri)r�r��ftprzz+%s - Redirection to url '%s' is not allowed�/r��
redirect_dictrr)rX)r�schemerrdr�r'rr|r�r�rr��max_repeatsrl�max_redirections�inf_msgrkr�r�rrX)
r�r�rpr�r�rqr
�urlparts�newZvisitedrZrZr[�http_error_302�s<




z"HTTPRedirectHandler.http_error_302zoThe HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
N)r�r�r�rrr�r�http_error_301�http_error_303�http_error_307rrZrZrZr[r/ns"7c	Cs�t|�\}}|�d�s d}|}n:|�d�s6td|��|�dd�}|dkrNd}|d|�}t|�\}}|dk	r|t|�\}}nd}}||||fS)a3Return (scheme, user, password, host/port) given a URL or an authority.

    If a URL is supplied, it must have an authority (host:port) component.
    According to RFC 3986, having an authority component means the URL must
    have two slashes after the scheme:

    >>> _parse_proxy('file:/ftp.example.com/')
    Traceback (most recent call last):
    ValueError: proxy URL with no authority: 'file:/ftp.example.com/'

    The first three items of the returned tuple may be None.

    Examples of authority parsing:

    >>> _parse_proxy('proxy.example.com')
    (None, None, None, 'proxy.example.com')
    >>> _parse_proxy('proxy.example.com:3128')
    (None, None, None, 'proxy.example.com:3128')

    The authority component may optionally include userinfo (assumed to be
    username:password):

    >>> _parse_proxy('joe:password@proxy.example.com')
    (None, 'joe', 'password', 'proxy.example.com')
    >>> _parse_proxy('joe:password@proxy.example.com:3128')
    (None, 'joe', 'password', 'proxy.example.com:3128')

    Same examples, but with URLs instead:

    >>> _parse_proxy('http://proxy.example.com/')
    ('http', None, None, 'proxy.example.com')
    >>> _parse_proxy('http://proxy.example.com:3128/')
    ('http', None, None, 'proxy.example.com:3128')
    >>> _parse_proxy('http://joe:password@proxy.example.com/')
    ('http', 'joe', 'password', 'proxy.example.com')
    >>> _parse_proxy('http://joe:password@proxy.example.com:3128')
    ('http', 'joe', 'password', 'proxy.example.com:3128')

    Everything after the authority is ignored:

    >>> _parse_proxy('ftp://joe:password@proxy.example.com/rubbish:3128')
    ('ftp', 'joe', 'password', 'proxy.example.com')

    Test for no trailing '/' case:

    >>> _parse_proxy('http://joe:password@proxy.example.com')
    ('http', 'joe', 'password', 'proxy.example.com')

    rNz//zproxy URL with no authority: %rr�r_)rr�rQr�r r!)	�proxyrZr_scheme�	authority�end�userinfo�hostport�user�passwordrZrZr[�_parse_proxy�s2

r#c@s"eZdZdZddd�Zdd�ZdS)r1�dNcCs^|dkrt�}t|d�s td��||_x2|��D]&\}}t|d||||jfdd��q0WdS)N�keyszproxies must be a mappingz%s_opencSs||||�S)NrZ)�rrr�r�rZrZr[�<lambda>)sz'ProxyHandler.__init__.<locals>.<lambda>)rEr��AssertionError�proxiesr��setattrr�)r�r)r�rVrZrZr[r�"s
zProxyHandler.__init__cCs�|j}t|�\}}}}|dkr"|}|jr6t|j�r6dS|rv|rvdt|�t|�f}	t�|	����d�}
|�	dd|
�t|�}|�
||�||ks�|dkr�dS|jj||j
d�SdS)Nz%s:%s�asciizProxy-authorizationzBasic r�)rX)r�r#r��proxy_bypassr�base64�	b64encode�encoder�r�r�r�rrX)r�r�rr�Z	orig_typeZ
proxy_typer!r"r Z	user_passZcredsrZrZr[r�,s zProxyHandler.proxy_open)N)r�r�r�r�r�r�rZrZrZr[r1s

c@s6eZdZdd�Zdd�Zdd�Zd
dd	�Zd
d�ZdS)r2cCs
i|_dS)N)�passwd)r�rZrZr[r�JszHTTPPasswordMgr.__init__cs`t|t�r|g}|�jkr$i�j|<x6dD].�t��fdd�|D��}||f�j||<q*WdS)N)TFcsg|]}��|���qSrZ)�
reduce_uri)r�u)�default_portr�rZr[�
<listcomp>Usz0HTTPPasswordMgr.add_password.<locals>.<listcomp>)r�r
r0�tuple)r��realmrr!r0Zreduced_urirZ)r3r�r[�add_passwordMs



zHTTPPasswordMgr.add_passwordc	Cs`|j�|i�}xLdD]D}|�||�}x2|��D]&\}}x|D]}|�||�r<|Sq<Wq.WqWdS)N)TF)NN)r0r�r1r��	is_suburi)	r�r6�authuriZdomainsr3Zreduced_authuriZurisZauthinforrZrZr[�find_user_passwordXs

z"HTTPPasswordMgr.find_user_passwordTc
Cs�t|�}|dr.|d}|d}|dp*d}nd}|}d}t|�\}}|r~|dkr~|dk	r~ddd��|�}	|	dk	r~d	||	f}||fS)
z@Accept authority or URI and extract only the authority and path.rrr�rN�Pi�)r�r�z%s:%d)rrr�)
r�rr3�partsrrrdr��portZdportrZrZr[r1bs zHTTPPasswordMgr.reduce_uricCsR||krdS|d|dkr dSt�|d|df�}t|�t|d�krNdSdS)zcCheck if test is below base in a URI tree

        Both args must be URIs in reduced form.
        TrFr)�	posixpath�commonprefixrl)r��base�test�commonrZrZr[r8yszHTTPPasswordMgr.is_suburiN)T)r�r�r�r�r7r:r1r8rZrZrZr[r2Hs


c@seZdZdd�ZdS)r3cCs0t�|||�\}}|dk	r"||fSt�|d|�S)N)r2r:)r�r6r9r!r"rZrZr[r:�s

z2HTTPPasswordMgrWithDefaultRealm.find_user_passwordN)r�r�r�r:rZrZrZr[r3�sc@s<eZdZe�dej�Zddd�Zdd�Zdd�Z	d	d
�Z
dS)r4z1(?:.*,)*[ 	]*([^ 	]+)[ 	]+realm=(["']?)([^"']*)\2NcCs(|dkrt�}||_|jj|_d|_dS)Nr)r2r0r7�retried)r�Zpassword_mgrrZrZr[r��s

z!AbstractBasicAuthHandler.__init__cCs
d|_dS)Nr)rC)r�rZrZr[�reset_retry_count�sz*AbstractBasicAuthHandler.reset_retry_countc
Cs�|�|d�}|jdkr,t|��dd|d��n|jd7_|r�|��d}|��dkrdtd|��nftj�	|�}|r�|�
�\}}}|dkr�t�d	t
d
�|��dkr�|�|||�}	|	r�|	jdkr�d|_|	SdS)N�i�zbasic auth failedrr�basiczDAbstractBasicAuthHandler does not support the following scheme: '%s')�"�'zBasic Auth Realm was unquotedr�)r�rCrr��splitr�rQr4�rx�search�groupsr�r��UserWarning�retry_http_basic_authr�)
r��authreqr�r�rqr�morr6r�rZrZr[�http_error_auth_reqed�s*


z.AbstractBasicAuthHandler.http_error_auth_reqedcCs~|j�||�\}}|dk	rvd||f}dt�|����d�}|j�|jd�|krVdS|�	|j|�|j
j||jd�SdSdS)Nz%s:%szBasic r+)rX)
r0r:r-r.r/r�rqr��auth_headerr�r�rrX)r�r�r�r6r!�pw�raw�authrZrZr[rN�sz.AbstractBasicAuthHandler.retry_http_basic_auth)N)r�r�r��re�compile�IrJr�rDrQrNrZrZrZr[r4�s
 c@seZdZdZdd�ZdS)r5�
AuthorizationcCs"|j}|�d|||�}|��|S)Nzwww-authenticate)r|rQrD)r�r�rpr�r�rqrVr�rZrZr[�http_error_401�s

z#HTTPBasicAuthHandler.http_error_401N)r�r�r�rRrZrZrZrZr[r5�sc@seZdZdZdd�ZdS)r6zProxy-authorizationcCs"|j}|�d|||�}|��|S)Nzproxy-authenticate)r�rQrD)r�r�rpr�r�rqrr�rZrZr[�http_error_407�s

z$ProxyBasicAuthHandler.http_error_407N)r�r�r�rRr[rZrZrZr[r6�sc@sNeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)r7NcCs4|dkrt�}||_|jj|_d|_d|_d|_dS)Nr)r2r0r7rC�nonce_count�
last_nonce)r�r0rZrZr[r�s
z"AbstractDigestAuthHandler.__init__cCs
d|_dS)Nr)rC)r�rZrZr[rDsz+AbstractDigestAuthHandler.reset_retry_countcCs||�|d�}|jdkr*t|jdd|d��n|jd7_|rx|��d}|��dkr`|�||�S|��dkrxtd|��dS)	NrEi�zdigest auth failedrr�digestrFzEAbstractDigestAuthHandler does not support the following scheme: '%s')r�rCrr|rIr��retry_http_digest_authrQ)r�rRr�r�rqrOrrZrZr[rQs


z/AbstractDigestAuthHandler.http_error_auth_reqedcCsz|�dd�\}}ttdt|���}|�||�}|rvd|}|j�|jd�|krRdS|�|j|�|j	j
||jd�}|SdS)Nrrz	Digest %s)rX)rI�parse_keqv_listr�parse_http_list�get_authorizationrqr�rRr�r�rrX)r�r�rU�tokenZ	challenge�chalZauth_valZresprZrZr[r_"sz0AbstractDigestAuthHandler.retry_http_digest_authcCs@d|j|t��f}|�d�td�}t�|���}|dd�S)Nz	%s:%s:%s:r+��)r\�time�ctimer/�_randombytes�hashlib�sha1�	hexdigest)r��nonce�s�b�digrZrZr[�
get_cnonce.sz$AbstractDigestAuthHandler.get_cnoncecCs�y6|d}|d}|�d�}|�dd�}|�dd�}Wntk
rJdSX|�|�\}}	|dkrfdS|j�||j�\}
}|
dkr�dS|jdk	r�|�|j|�}nd}d|
||f}
d|��|j	f}|d	k�r.||j
kr�|jd
7_nd
|_||_
d|j}|�|�}d||||||�f}|	||
�|�}n2|dk�rT|	||
�d|||�f�}nt
d
|��d|
|||j	|f}|�r�|d|7}|�r�|d|7}|d|7}|�r�|d||f7}|S)Nr6rm�qop�	algorithm�MD5�opaquez%s:%s:%sz%s:%srUrz%08xz%s:%s:%s:%s:%szqop '%s' is not supported.z>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"z
, opaque="%s"z
, digest="%s"z, algorithm="%s"z, qop=auth, nc=%s, cnonce="%s")r��KeyError�get_algorithm_implsr0r:r|rW�get_entity_digestr�r�r]r\rqr)r�r�rdr6rmrrrsru�H�KDr!rSZentdigZA1ZA2ZncvalueZcnonceZnoncebitZrespdigr@rZrZr[rb9sV








z+AbstractDigestAuthHandler.get_authorizationcs6|dkrdd��n|dkr"dd���fdd�}�|fS)NrtcSst�|�d����S)Nr+)rj�md5r/rl)�xrZrZr[r'x�z?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>ZSHAcSst�|�d����S)Nr+)rjrkr/rl)r|rZrZr[r'zr}cs�d||f�S)Nz%s:%srZ)rn�d)ryrZr[r'|r}rZ)r�rsrzrZ)ryr[rwus
z-AbstractDigestAuthHandler.get_algorithm_implscCsdS)NrZ)r�rWrdrZrZr[rxsz+AbstractDigestAuthHandler.get_entity_digest)N)r�r�r�r�rDrQr_rqrbrwrxrZrZrZr[r7�s
	<
c@s eZdZdZdZdZdd�ZdS)r8z�An authentication protocol defined by RFC 2069

    Digest authentication improves on basic authentication because it
    does not transmit passwords in the clear.
    rYi�cCs*t|j�d}|�d|||�}|��|S)Nrzwww-authenticate)rr|rQrD)r�r�rpr�r�rqr��retryrZrZr[rZ�s

z$HTTPDigestAuthHandler.http_error_401N)r�r�r�r�rRr�rZrZrZrZr[r8�sc@seZdZdZdZdd�ZdS)r9zProxy-Authorizationi�cCs"|j}|�d|||�}|��|S)Nzproxy-authenticate)r�rQrD)r�r�rpr�r�rqr�rrZrZr[r[�s

z%ProxyDigestAuthHandler.http_error_407N)r�r�r�rRr�r[rZrZrZr[r9�sc@s.eZdZddd�Zdd�Zdd�Zdd	�Zd
S)�AbstractHTTPHandlerrcCs
||_dS)N)�_debuglevel)r��
debuglevelrZrZr[r��szAbstractHTTPHandler.__init__cCs
||_dS)N)r�)r��levelrZrZr[�set_http_debuglevel�sz'AbstractHTTPHandler.set_http_debuglevelc
CsX|j}|std��|jdk	r�|j}t|t�r8d}t|��|�d�sN|�dd�|�d�s�d}y:tr~t|t	j	�r~t
|�|j}nt|�}t
|�|j}Wn4tk
r�t|t
j�r�tdt|�|f��YnX|�dd|�|}|���rt|j�\}}	t|	�\}}
|�d��s|�d|�x6|jjD]*\}}|��}|�|��s&|�||��q&W|S)	Nz
no host givenzLPOST data should be bytes or an iterable of bytes. It cannot be of type str.zContent-typez!application/x-www-form-urlencodedzContent-lengthzBContent-Length should be specified for iterable data of type %r %rz%dr{)r�rrWr�r
r�r�r�r�arrayrl�itemsize�
memoryview�collections�IterablerQr�r�rr�rr�r�r�)
r�r�r�rWr�ru�mvZsel_hostrZselZsel_pathrhr�rZrZr[�do_request_�sJ




zAbstractHTTPHandler.do_request_c

s2|j}|std��||fd|ji|��}t|j����t�fdd�|j��D���d�d<tdd����D���|jr�i}d}|�kr��|||<�|=|j	|j|d	�y|�
|��|j|j
��Wn4tjk
r�}z|��t|��Wd
d
}~XYn"X|��}	|j�r|j��d
|_|��|	_|	j|	_|	S)z�Return an HTTPResponse object for the request, using http_class.

        http_class must implement the HTTPConnection API from http.client.
        z
no host givenrXc3s"|]\}}|�kr||fVqdS)NrZ)rrr)rqrZr[r�sz.AbstractHTTPHandler.do_open.<locals>.<genexpr>r��
Connectioncss|]\}}|��|fVqdS)N)�title)rrhr�rZrZr[r�szProxy-Authorization)rqN)r�rrXrr�r�rqr�r�Z
set_tunnelr�r�r�rWr�r�r��getresponse�sockr�rV�reasonr�)
r�Z
http_classr�Zhttp_conn_argsr�r�Ztunnel_headersZproxy_auth_hdr�errr&rZ)rqr[r��s6
"

zAbstractHTTPHandler.do_openN)r)r�r�r�r�r�r�r�rZrZrZr[r��s
3r�c@seZdZdd�ZejZdS)r:cCs|�tj|�S)N)r�r��HTTPConnection)r�r�rZrZr[�	http_openszHTTPHandler.http_openN)r�r�r�r�r�r��http_requestrZrZrZr[r:sr�c@s$eZdZddd�Zdd�ZejZdS)rTrNcCst�||�||_||_dS)N)r�r��_context�_check_hostname)r�r�rNrOrZrZr[r�'szHTTPSHandler.__init__cCs|jtj||j|jd�S)N)rNrO)r�r�r�r�r�)r�r�rZrZr[�
https_open,s
zHTTPSHandler.https_open)rNN)r�r�r�r�r�r�r��
https_requestrZrZrZr[rT%s
rTc@s.eZdZddd�Zdd�Zdd�ZeZeZdS)	r0NcCs2ddlmmm}|dkr(|��}||_dS)Nr)Zfuture.backports.http.cookiejar�	backportsr��	cookiejarZ	CookieJar)r�r�Zhttp_cookiejarrZrZr[r�5szHTTPCookieProcessor.__init__cCs|j�|�|S)N)r�Zadd_cookie_header)r�r�rZrZr[r�;sz HTTPCookieProcessor.http_requestcCs|j�||�|S)N)r�Zextract_cookies)r�r�r�rZrZr[r�?sz!HTTPCookieProcessor.http_response)N)r�r�r�r�r�r�r�rrZrZrZr[r04s

c@seZdZdd�ZdS)r>cCs|j}td|��dS)Nzunknown url type: %s)r�r)r�r�r�rZrZr[r�GszUnknownHandler.unknown_openN)r�r�r�r�rZrZrZr[r>FscCsRi}xH|D]@}|�dd�\}}|ddkrB|ddkrB|dd�}|||<q
W|S)z>Parse list of key=value strings where keys are not duplicated.�=rrrGr_)rI)�l�parsed�eltrrrZrZr[r`Ks
r`cCs�g}d}d}}xt|D]l}|r,||7}d}q|rV|dkr@d}qn|dkrLd}||7}q|dkrn|�|�d}q|dkrzd}||7}qW|r�|�|�dd�|D�S)	apParse lists as described by RFC 2068 Section 2.

    In particular, parse comma-separated lists where the elements of
    the list may include quoted-strings.  A quoted-string could
    contain a comma.  A non-quoted string could have quotes in the
    middle.  Neither commas nor quotes count if they are escaped.
    Only double-quotes count, not single-quotes.
    rzF�\TrG�,cSsg|]}|���qSrZ)�strip)r�partrZrZr[r4~sz#parse_http_list.<locals>.<listcomp>)rj)rn�resr��escaper�currZrZr[raUs4	


rac@s(eZdZdd�ZdZdd�Zdd�ZdS)r;cCs\|j}|dd�dkrN|dd�dkrN|jrN|jdkrN|j|��k	rXtd��n
|�|�SdS)Nr�z//rJr�	localhostz-file:// scheme is supported only on localhost)r�r��	get_namesr�open_local_file)r�r�rVrZrZr[�	file_open�s&

zFileHandler.file_openNcCs`tjdkrZy*tt�d�dt�t���d�t_Wn$tjk
rXt�d�ft_YnXtjS)Nr�r�)r;�namesr5r��gethostbyname_ex�gethostname�gaierror�
gethostbyname)r�rZrZr[r��s
zFileHandler.get_namesc
Cs
ddlmmm}ddl}|j}|j}t|�}y�t�	|�}|j
}|j|jdd�}	|�
|�d}
t�d|
ppd||	f�}|r�t|�\}}|r�|s�t|�|��kr�|r�d||}
nd|}
tt|d�||
�SWn*tk
r�}zt|��Wdd}~XYnXtd��dS)	NrT)�usegmtz6Content-type: %s
Content-length: %d
Last-modified: %s
z
text/plainzfile://�rbzfile not on local host)�future.backports.email.utilsr�r�utils�	mimetypesr�r�rDrc�stat�st_size�
formatdate�st_mtime�
guess_type�message_from_stringr�_safe_gethostbynamer�r(r�OSErrorr)r�r��email_utilsr�r�rnZ	localfile�statsru�modified�mtyperqr=Zorigurl�exprZrZr[r��s0
zFileHandler.open_local_file)r�r�r�r�r�r�r�rZrZrZr[r;�s
cCs&y
t�|�Stjk
r dSXdS)N)r�r�r�)r�rZrZr[r��s
r�c@seZdZdd�Zdd�ZdS)r<c
Cs$ddl}ddl}|j}|s"td��t|�\}}|dkr>|j}nt|�}t|�\}}|rdt|�\}}nd}t	|�}|pvd}|p~d}yt
�|�}Wn,t
jk
r�}zt|��Wdd}~XYnXt
|j�\}	}
|	�d�}ttt	|��}|dd�|d}}|�r|d�s|dd�}y�|�||||||j�}
|�r8d�p:d}x:|
D]2}t|�\}}|��d	k�rB|d
k�rB|��}�qBW|
�||�\}}d}|�|j�d}|�r�|d|7}|dk	�r�|dk�r�|d|7}t�|�}t|||j�S|jk
�r}ztd
|�}t|�Wdd}~XYnXdS)Nrzftp error: no host givenrzrr_rrX�Dr�)�a�Ar�rXr~r�zContent-type: %s
zContent-length: %d
z
ftp error: %r)�ftplibr�r�rr�FTP_PORTr
r r!rr�r�r�r"r�rIr�r�connect_ftprXr$r��upper�retrfiler�r|rr�r(�
all_errorsr)r�r�r�r�r�r=r!r0r�rd�attrs�dirsr\�fwr��attrr�rp�retrlenrqr�r��excrZrZr[�ftp_open�s\



zFTPHandler.ftp_openc	Cst||||||dd�S)NF)�
persistent)�
ftpwrapper)r�r!r0r�r=r�rXrZrZr[r��szFTPHandler.connect_ftpN)r�r�r�r�r�rZrZrZr[r<�s5c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)r=cCs"i|_i|_d|_d|_d|_dS)Nr�<rf)�cacherX�soonest�delay�	max_conns)r�rZrZr[r��s
zCacheFTPHandler.__init__cCs
||_dS)N)r�)r��trZrZr[�
setTimeout�szCacheFTPHandler.setTimeoutcCs
||_dS)N)r�)r�rrZrZr[�setMaxConnsszCacheFTPHandler.setMaxConnscCsr|||d�|�|f}||jkr4t��|j|j|<n,t||||||�|j|<t��|j|j|<|��|j|S)Nr)�joinr�rgr�rXr��check_cache)r�r!r0r�r=r�rXr�rZrZr[r�s

zCacheFTPHandler.connect_ftpcCs�t��}|j|krTx@t|j���D].\}}||kr"|j|��|j|=|j|=q"Wtt|j����|_t	|j�|j
kr�x6t|j���D]$\}}||jkr�|j|=|j|=Pq�Wtt|j����|_dS)N)rgr�r�rXr�r�r��min�valuesrlr�)r�r�rrrZrZr[r�s

zCacheFTPHandler.check_cachecCs4x|j��D]}|��qW|j��|j��dS)N)r�r�r��clearrX)r��connrZrZr[�clear_cache#s
zCacheFTPHandler.clear_cacheN)	r�r�r�r�r�r�r�r�r�rZrZrZr[r=�sr�nt)rDrCcCst|�S)zOS-specific conversion from a relative URL of the 'file' scheme
        to a file system path; not recommended for general use.)r)�pathnamerZrZr[rD2scCst|�S)zOS-specific conversion from a file system path to a relative URL
        of the 'file' scheme; not recommended for general use.)r)r�rZrZr[rC7sc@s�eZdZdZdZdeZd*dd�Zdd�Zdd	�Z	d
d�Z
dd
�Zd+dd�Zd,dd�Z
d-dd�Zd.dd�Zdd�Zd/dd�Zd0dd�Zdd�Zer�dd�Zd1d d!�Zd"d#�Zd$d%�Zd&d'�Zd2d(d)�ZdS)3rHa,Class to open URLs.
    This is a class rather than just a subroutine because we may need
    more than one set of global protocol-specific options.
    Note -- this is a base class for those who don't want the
    automatic handling of errors type 302 (relocated) and 401
    (authorization needed).NzPython-urllib/%scKs�dd|jji}tj|tdd�|dkr.t�}t|d�s@td��||_|�	d�|_
|�	d�|_d	|jfg|_
g|_tj|_d|_t|_dS)
NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methods�classrJ)r�r%zproxies must be a mapping�key_file�	cert_filez
User-Agent)�	__class__r�r�r�r�rEr�r(r)r�r�r��versionr��_URLopener__tempfilesrcrx�_URLopener__unlink�	tempcache�ftpcache)r�r)Zx509r�rZrZr[r�QszURLopener.__init__cCs|��dS)N)r�)r�rZrZr[�__del__kszURLopener.__del__cCs|��dS)N)�cleanup)r�rZrZr[r�nszURLopener.closec	CsZ|jrFx2|jD](}y|�|�Wqtk
r4YqXqW|jdd�=|jrV|j��dS)N)r�r�r�r�r�)r�r\rZrZr[r�qs
zURLopener.cleanupcGs|j�|�dS)zdAdd a header to be used by the HTTP interface only
        e.g. u.addheader('Accept', 'sound/basic')N)r�rj)r�r�rZrZr[�	addheaderszURLopener.addheaderc
CsVtt|��}t|dd�}|jrL||jkrL|j|\}}t|d�}t|||�St|�\}}|s`d}||jkr�|j|}t|�\}}	t|	�\}
}|
|f}nd}d|}||_	|�
dd�}t||�s�|r�|�|||�S|�
||�Sy*|dkr�t||�|�St||�||�SWnJtk
�r�Yn4tjk
�rP}
zttd	|
��Wdd}
~
XYnXdS)
z6Use URLopener().open(file) instead of open(file, 'r').z%/:=&?~#+!$,;'@()*[]|)�safer�r\NZopen_�-r�zsocket error)rr&rr�rr(rr)rr�r	r��open_unknown_proxy�open_unknownr�rr�r�r�IOError)r�r�rWrnrqrp�urltyperVr�	proxyhostr�r�rhr�rZrZr[r�s<




zURLopener.opencCst|�\}}tdd|��dS)z/Overridable interface to open unknown URL type.z	url errorzunknown url typeN)rr�)r�r�rWr�rVrZrZr[r��szURLopener.open_unknowncCs t|�\}}tdd||��dS)z/Overridable interface to open unknown URL type.z	url errorzinvalid proxy for %sN)rr�)r�rr�rWr�rVrZrZr[r��szURLopener.open_unknown_proxyc
Cs$tt|��}|jr&||jkr&|j|St|�\}}|dkr�|rF|dkr�y.|�|�}|��}|��tt|�d�|fSt	k
r�}	zWdd}	~	XYnX|�
||�}�zH|��}
|r�t
|d�}n|ddl}t|�\}
}t|p�d�\}
}t|p�d�\}}
t
|�p�d�\}}
tj�|�d}|�|�\}}|j�|�t�|d�}z�||
f}|jdk	�r\||j|<d}d}d}d}d	|
k�r�t|
d
�}|�r�||||�xH|�|�}|�s�P|t|�7}|�|�|d7}|�r�||||��q�WWd|��XWd|��X|dk�r ||k�r td||f|��|S)ztretrieve(url) returns (filename, headers) for a local object
        or (tempfilename, headers) for a remote object.Nr\rr]rrzi r_zcontent-lengthzContent-Lengthz1retrieval incomplete: got only %i out of %i bytes)rr&r�rr�rbr�rDrr�rrfr#r"rcrd�splitext�mkstempr�rj�fdopenr
rkrlrmr)r�rVrnrorWr�Zurl1rpr�r�rqrrrfZgarbagerd�suffix�fdrsrtrurkrvrwrZrZr[�retrieve�sl






zURLopener.retrievecCs&d}d}t|t�r<t|�\}}|r6t|�\}}t|�}|}nt|\}}t|�\}}t|�\}	}
|
}d}|	��dkrvd}n:t|
�\}}
|r�t|�\}}|r�d|	||
f}t|�r�|}|s�tdd��|r�t|�}t	�
|����d�}nd}|�rt|�}t	�
|����d�}nd}||�}
i}|�r*d||d<|�r<d||d	<|�rJ||d
<d|d<x|j
D]\}}|||<�qZW|dk	�r�d
|d<|
�d|||�n|
jd||d�y|
��}Wn tjk
�r�td��YnXd|jk�r�dk�rnnt||jd||j�S|�||j|j|j|j|�SdS)a�Make an HTTP connection using connection_class.

        This is an internal method that should be called from
        open_http() or open_https().

        Arguments:
        - connection_factory should take a host name and return an
          HTTPConnection instance.
        - url is the url to retrieval or a host, relative-path pair.
        - data is payload for a POST request or None.
        Nr�z	%s://%s%sz
http errorz
no host givenr+zBasic %szProxy-AuthorizationrYr{r�r�z!application/x-www-form-urlencodedzContent-Typer�r�)rqz$http protocol error: bad status liner�i,zhttp:)r�r
rr rrr�r,r�r-r.r/r�r�r�r�r�Z
BadStatusLiner�statusr(r��
http_errorrpr�)r�Zconnection_factoryrVrWZuser_passwdZproxy_passwdr�r�Zrealhostr�r�Z
proxy_authrUZ	http_connrq�headerr�r�rZrZr[�_open_generic_http�sr



zURLopener._open_generic_httpcCs|�tj||�S)zUse HTTP protocol.)rr�r�)r�rVrWrZrZr[�	open_httpRszURLopener.open_httpc
Csbd|}t||�rPt||�}|dkr6||||||�}	n|||||||�}	|	rP|	S|�|||||�S)z�Handle http errors.

        Derived class can override this, or provide specific handlers
        named http_error_DDD where DDD is the 3-digit error code.z
http_error_%dN)r�r�r�)
r�rVrp�errcode�errmsgrqrWrhr�rsrZrZr[r�Vs

zURLopener.http_errorcCs|��t||||d��dS)z>Default error handler: close the connection and raise IOError.N)r�r)r�rVrprrrqrZrZr[r�fszURLopener.http_error_defaultcCstj||j|jd�S)N)r�r�)r�r�r�r�)r�r�rZrZr[�_https_connectionlszURLopener._https_connectioncCs|�|j||�S)zUse HTTPS protocol.)rr)r�rVrWrZrZr[�
open_httpsqszURLopener.open_httpscCs^t|t�std��|dd�dkrP|dd�dkrP|dd���dkrPtd	��n
|�|�SdS)
z/Use local file or FTP depending on form of URL.zEfile error: proxy support for file protocol currently not implementedNr�z//rJr�z
localhost/z-file:// scheme is supported only on localhost)r�r
rr�rQr�)r�rVrZrZr[�	open_fileus

4
zURLopener.open_filec
Csjddlmmm}ddl}t|�\}}t|�}yt�|�}Wn0t	k
rr}zt
|j|j��Wdd}~XYnX|j
}	|j|jdd�}
|�|�d}t�d|p�d|	|
f�}|s�|}
|dd�dkr�d	|}
tt|d
�||
�St|�\}}|�s^t�|�t�ft�k�r^|}
|dd�dk�r.d	|}
n|dd�dk�rLtd
|��tt|d
�||
�St
d��dS)zUse local file.rNT)r�z6Content-Type: %s
Content-Length: %d
Last-modified: %s
z
text/plainrrzfile://r�r�z./zAlocal file url may start with / or file:. Unknown url of type: %sz#local file error: not on local host)r�r�rr�r�rrDrcr�r�r�strerrorrnr�r�r�r�r�r(rrr�r�r��thishostrQ)r�rVr�r�r�r\Z	localnamer��erur�r�rqZurlfiler=rZrZr[r�~s: 
zURLopener.open_local_filec
Cs�t|t�std��ddl}t|�\}}|s2td��t|�\}}t|�\}}|r\t|�\}}nd}t|�}t|ppd�}t|p|d�}t	�
|�}|s�ddl}|j}nt
|�}t|�\}}	t|�}|�d�}
|
dd�|
d}
}|
r�|
ds�|
dd�}
|
�r
|
d�s
d|
d<|||d�|
�f}t|j�tk�rfx8|j��D]*}
|
|k�r8|j|
}|j|
=|���q8Wy�||jk�r�t|||||
�|j|<|�s�d	}nd
}x:|	D]2}t|�\}}|��dk�r�|dk�r�|��}�q�W|j|�||�\}}|�d
|�d}d}|�r|d|7}|dk	�r4|dk�r4|d|7}t�|�}t||d
|�St�k
�r�}zt td|��Wdd}~XYnXdS)zUse FTP protocol.zCftp error: proxy support for ftp protocol currently not implementedrNzftp error: no host givenrzrr_rr�rXr�)r�r�r�rXr~r�zftp:zContent-Type: %s
zContent-Length: %d
zftp error %r)!r�r
rr�rrr r!rr�r�r�r�r
r"rIr�rlr��MAXFTPCACHEr%r�r�r$r�r�r�r�rr�r(�	ftperrorsr)r�rVr�r�rdr=r!r0r�r�r�r\r�rrr�r�r�rpr�r�rqr�rZrZr[�open_ftp�sp







zURLopener.open_ftpc	
Cs<t|t�std��y|�dd�\}}Wntk
rDtdd��YnX|sNd}|�d�}|dkr�d	||d
�kr�||dd
�}|d
|�}nd}g}|�dt�	d
t�
t�����|�d|�|dkr�t�|�
d���d�}nt|�}|�dt|��|�d�|�|�d�|�}t�|�}t�|�}t|||�S)zUse "data" URL.zEdata error: proxy support for data protocol currently not implementedr�rz
data errorzbad data URLztext/plain;charset=US-ASCII�;rr�NrzzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %sr-r+zlatin-1zContent-Length: %d�
)r�r
rrIrQr��rfindrjrg�strftime�gmtimer-�decodebytesr/r�rrlr�rr��io�StringIOr()	r�rVrWr�Zsemi�encodingr�rq�frZrZr[�	open_data�s6






zURLopener.open_data)N)N)N)N)NNN)N)N)N)N)r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�rrr�r�rPrrrr�r
rrZrZrZr[rHDs.

$


B\


	 :c@s�eZdZdZdd�Zdd�Zd#dd�Zd	d
�Zd$dd�Zd%d
d�Z	d&dd�Z
d'dd�Zd(dd�Zd)dd�Z
d*dd�Zd+dd�Zd,dd�Zd-dd �Zd!d"�ZdS).rIz?Derived class with handlers for errors we can handle (perhaps).cOs(tj|f|�|�i|_d|_d|_dS)Nrr)rHr��
auth_cache�tries�maxtries)r�r��kwargsrZrZr[r�szFancyURLopener.__init__cCst||d||�S)z3Default error handling -- don't raise an exception.zhttp:)r()r�rVrprrrqrZrZr[r�sz!FancyURLopener.http_error_defaultNc	Csl|jd7_|jrN|j|jkrNt|d�r2|j}n|j}d|_|||dd|�S|�||||||�}d|_|S)z%Error 302 -- relocated (temporarily).r�http_error_500ri�z)Internal Server Error: Redirect Recursion)rrr�rr��redirect_internal)	r�rVrprrrqrWr�rsrZrZr[rs
zFancyURLopener.http_error_302c	Csxd|kr|d}nd|kr$|d}ndS|��t|jd||�}t|�}|jdkrnt|||d|||��|�|�S)Nr
r�:)r�r�rrzz( Redirection to url '%s' is not allowed.)r�rr�rrrr)	r�rVrprrrqrWr
rrZrZr[rs


z FancyURLopener.redirect_internalcCs|�||||||�S)z*Error 301 -- also relocated (permanently).)r)r�rVrprrrqrWrZrZr[r;szFancyURLopener.http_error_301cCs|�||||||�S)z;Error 303 -- also relocated (essentially identical to 302).)r)r�rVrprrrqrWrZrZr[r?szFancyURLopener.http_error_303cCs2|dkr|�||||||�S|�|||||�SdS)z1Error 307 -- relocated, but turn POST into error.N)rr�)r�rVrprrrqrWrZrZr[rCszFancyURLopener.http_error_307Fc
Cs�d|krt�||||||�|d}t�d|�}	|	sHt�||||||�|	��\}
}|
��dkrtt�||||||�|s�t�||||||�d|jd}|dkr�t||�||�St||�|||�SdS)z_Error 401 -- authentication required.
        This function supports Basic authentication only.zwww-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"rFZretry_�_basic_authN)rHr�rV�matchrLr�r�r�)
r�rVrprrrqrWr�stuffr!rr6rhrZrZr[rZJs&





zFancyURLopener.http_error_401c
Cs�d|krt�||||||�|d}t�d|�}	|	sHt�||||||�|	��\}
}|
��dkrtt�||||||�|s�t�||||||�d|jd}|dkr�t||�||�St||�|||�SdS)zeError 407 -- proxy authentication required.
        This function supports Basic authentication only.zproxy-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"rFZretry_proxy_r N)rHr�rVr!rLr�r�r�)
r�rVrprrrqrWrr"r!rr6rhrZrZr[r[cs&





zFancyURLopener.http_error_407cCs�t|�\}}d||}|jd}t|�\}}	t|	�\}	}
|	�d�d}|	|d�}	|�|	||�\}}
|sr|
srdSdt|dd�t|
dd�|	f}	d|	|
|jd<|dkr�|�|�S|�||�SdS)Nzhttp://r��@rz%s:%s@%srz)r�)rr)rr��get_user_passwdrr)r�rVr6rWr�r�r
rr�r��
proxyselectorr�r!r0rZrZr[�retry_proxy_http_basic_auth|s 

z*FancyURLopener.retry_proxy_http_basic_authcCs�t|�\}}d||}|jd}t|�\}}	t|	�\}	}
|	�d�d}|	|d�}	|�|	||�\}}
|sr|
srdSdt|dd�t|
dd�|	f}	d|	|
|jd<|dkr�|�|�S|�||�SdS)Nzhttps://r�r#rz%s:%s@%srz)r�)rr)rr�r$rr)r�rVr6rWr�r�r
rr�r�r%r�r!r0rZrZr[�retry_proxy_https_basic_auth�s 

z+FancyURLopener.retry_proxy_https_basic_authc
Cs�t|�\}}|�d�d}||d�}|�|||�\}}|sD|sDdSdt|dd�t|dd�|f}d||}	|dkr�|�|	�S|�|	|�SdS)Nr#rz%s:%s@%srz)r�zhttp://)rr�r$rr)
r�rVr6rWr�r�r�r!r0r
rZrZr[rN�s
z$FancyURLopener.retry_http_basic_authc
Cs�t|�\}}|�d�d}||d�}|�|||�\}}|sD|sDdSdt|dd�t|dd�|f}d||}	|dkr�|�|	�S|�|	|�SdS)Nr#rz%s:%s@%srz)r�zhttps://)rr�r$rr)
r�rVr6rWr�r�r�r!r0r
rZrZr[�retry_https_basic_auth�s
z%FancyURLopener.retry_https_basic_authrcCs`|d|��}||jkr2|r(|j|=n
|j|S|�||�\}}|sJ|rX||f|j|<||fS)Nr#)r�r�prompt_user_passwd)r�r�r6r�r�r!r0rZrZr[r$�s


zFancyURLopener.get_user_passwdcCsTddl}y,td||f�}|�d|||f�}||fStk
rNt�dSXdS)z#Override this in a GUI environment!rNzEnter username for %s at %s: z#Enter password for %s in %s at %s: )NN)�getpassr	�KeyboardInterrupt�print)r�r�r6r*r!r0rZrZr[r)�sz!FancyURLopener.prompt_user_passwd)N)N)N)N)NF)NF)N)N)N)N)r)r�r�r�r�r�r�rrrrrrZr[r&r'rNr(r$r)rZrZrZr[rIs$










cCstdkrt�d�atS)z8Return the IP address of the magic hostname 'localhost'.Nr�)�
_localhostr�r�rZrZrZr[r��s
r�cCsPtdkrLytt�t���d�aWn(tjk
rJtt�d�d�aYnXtS)z,Return the IP addresses of the current host.Nr�r�)�	_thishostr5r�r�r�r�rZrZrZr[r	�sr	cCstdkrddl}|jatS)z1Return the set of errors raised by the FTP class.Nr)�
_ftperrorsr�r�)r�rZrZr[r�srcCstdkrt�d�atS)z%Return an empty email Message object.Nrz)�
_noheadersrr�rZrZrZr[�	noheaders�s
r1c@sJeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)r�z;Class used by open_ftp() for cache of open FTP connections.NTcCs<||_||_||_||_||_||_d|_||_|��dS)Nr)	r!r0r�r=r�rX�refcount�	keepalive�init)r�r!r0r�r=r�rXr�rZrZr[r�	szftpwrapper.__init__cCs\ddl}d|_|��|_|j�|j|j|j�|j�|j	|j
�d�|j�}|j�
|�dS)Nrr)r��busyZFTPr�connectr�r=rXZloginr!r0r�r��cwd)r�r��_targetrZrZr[r4	s
zftpwrapper.initc
Cs�ddl}|��|dkr"d}d}nd|}d}y|j�|�Wn*|jk
rh|��|j�|�YnXd}|r�|s�yd|}|j�|�\}}WnH|jk
r�}z(t|�dd�dkr�t	t
d	|��Wdd}~XYnX|�s~|j�d�|�rj|j��}	zRy|j�|�Wn<|jk
�rL}zt
d	|�}
||
_
|
�Wdd}~XYnXWd|j�|	�Xd
|}nd}|j�|�\}}d|_t|�d�|j�}|jd7_|��||fS)
Nr)r~r�zTYPE ArzTYPE zRETR rJZ550z
ftp error: %rzLIST ZLISTr�)r��endtransferrZvoidcmdr�r4ZntransfercmdZ
error_permr
rr�pwdr7�	__cause__r5r)�makefile�
file_closer2r�)r�r\r�r��cmd�isdirr�r�r�r:r�ZftpobjrZrZr[r�	sP"

zftpwrapper.retrfilecCs
d|_dS)Nr)r5)r�rZrZr[r9E	szftpwrapper.endtransfercCsd|_|jdkr|��dS)NFr)r3r2�
real_close)r�rZrZr[r�H	s
zftpwrapper.closecCs2|��|jd8_|jdkr.|js.|��dS)Nrr)r9r2r3r@)r�rZrZr[r=M	szftpwrapper.file_closecCs2|��y|j��Wnt�k
r,YnXdS)N)r9rr�r)r�rZrZr[r@S	s
zftpwrapper.real_close)NT)r�r�r�r�r�r4r�r9r�r=r@rZrZrZr[r��s
	0r�cCsLi}xBtj��D]4\}}|��}|r|dd�dkr|||dd�<qW|S)aReturn a dictionary of scheme -> proxy server URL mappings.

    Scan the environment for variables named <scheme>_proxy;
    this seems to be the standard convention.  If you need a
    different way, you can pass a proxies dictionary to the
    [Fancy]URLopener constructor.

    i����N�_proxy)rc�environr�r�)r)rhr�rZrZr[�getproxies_environment[	s	rCcCsvtj�dd�ptj�dd�}|dkr(dSt|�\}}dd�|�d�D�}x(|D] }|rN|�|�sj|�|�rNdSqNWd	S)
z�Test if proxies should not be used for a particular host.

    Checks the environment for a variable named no_proxy, which should
    be a list of DNS suffixes separated by commas, or '*' for all hosts.
    �no_proxyrzZNO_PROXY�*rcSsg|]}|���qSrZ)r�)rrrZrZr[r4x	sz,proxy_bypass_environment.<locals>.<listcomp>r�r)rcrBr�rrI�endswith)r�rD�hostonlyr=Z
no_proxy_listrhrZrZr[�proxy_bypass_environmentk	s
rHc	Csddlm}t|�\}}dd�}d|kr4|dr4dSd}x�|�d	d
�D]�}|sPqFt�d|�}|dk	�r|dkr�yt�|�}||�}Wntjk
r�wFYnX||�d��}	|�d
�}
|
dkr�d|�d��	d�d}
nt
|
dd��}
d|
}
||
?|	|
?k�rdSqF|||�rFdSqFWdS)aj
    Return True iff this host shouldn't be accessed using a proxy

    This function uses the MacOSX framework SystemConfiguration
    to fetch the proxy information.

    proxy_settings come from _scproxy._get_proxy_settings or get mocked ie:
    { 'exclude_simple': bool,
      'exceptions': ['foo.bar', '*.bar.com', '127.0.0.1', '10.1', '10.0/16']
    }
    r)�fnmatchcSsh|�d�}ttt|��}t|�dkr<|ddddgdd�}|dd>|dd>B|dd>B|d	BS)
N�.rr�rrfr�rerJ)rIr�rr
rl)ZipAddrr<rZrZr[�ip2num�	s

z,_proxy_bypass_macosx_sysconf.<locals>.ip2numrJZexclude_simpleTN�
exceptionsrZz(\d+(?:\.\d+)*)(/\d+)?rr�re� F)rIrr�rVr!r�r�r��group�countr
)r��proxy_settingsrIrGr=rLZhostIPr�rr@�maskrZrZr[�_proxy_bypass_macosx_sysconf�	s:



rS�darwin)�_get_proxy_settings�_get_proxiescCst�}t||�S)N)rUrS)r�rQrZrZr[�proxy_bypass_macosx_sysconf�	srWcCst�S)z�Return a dictionary of scheme -> proxy server URL mappings.

        This function uses the MacOSX framework SystemConfiguration
        to fetch the proxy information.
        )rVrZrZrZr[�getproxies_macosx_sysconf�	srXcCst�rt|�St|�SdS)N)rCrHrW)r�rZrZr[r,�	sr,cCst�p
t�S)N)rCrXrZrZrZr[rE�	sc
Csi}yddl}Wntk
r$|SXy�|�|jd�}|�|d�d}|r�t|�|d�d�}d|kr�x�|�d�D]4}|�dd�\}}t�d	|�s�d
||f}|||<qrWn>|dd�dkr�||d
<n$d||d
<d||d<d||d<|�	�Wnt
ttfk
�rYnX|S)zxReturn a dictionary of scheme -> proxy server URL mappings.

        Win32 uses the registry to store proxies.

        rNz;Software\Microsoft\Windows\CurrentVersion\Internet Settings�ProxyEnableZProxyServerr�rrz^([^/:]+)://z%s://%srEzhttp:r�z	http://%sz
https://%sr�zftp://%sr)
�winreg�ImportError�OpenKey�HKEY_CURRENT_USER�QueryValueExr
rIrVr!�Close�WindowsErrorrQr�)r)rZ�internetSettings�proxyEnableZproxyServer�pr��addressrZrZr[�getproxies_registry�	s8

recCst�p
t�S)z�Return a dictionary of scheme -> proxy server URL mappings.

        Returns settings gathered from the environment, if specified,
        or the registry.

        )rCrerZrZrZr[rE
scCs~yddl}Wntk
r dSXy6|�|jd�}|�|d�d}t|�|d�d�}Wntk
rldSX|rv|szdSt|�\}}|g}y t�	|�}||kr�|�
|�Wntjk
r�YnXy t�|�}||kr�|�
|�Wntjk
�r�YnX|�
d�}xp|D]h}	|	dk�r*d|k�r*dS|	�dd	�}	|	�d
d�}	|	�dd�}	x$|D]}
t�|	|
tj��rTdS�qTW�qWdS)
Nrz;Software\Microsoft\Windows\CurrentVersion\Internet SettingsrYZ
ProxyOverriderz<local>rJrz\.rEz.*�?)rZr[r\r]r^r
r`rr�r�rjr��getfqdnrIr	rVr!rX)r�rZrarbZ
proxyOverrideZrawHostr=�addrZfqdnrAr�rZrZr[�proxy_bypass_registry
sR







ricCst�rt|�St|�SdS)z�Return a dictionary of scheme -> proxy server URL mappings.

        Returns settings gathered from the environment, if specified,
        or the registry.

        N)rCrHri)r�rZrZr[r,B
s)NNN)�r��
__future__rrrrZfuture.builtinsrrrr	r
rrr
Zfuture.utilsrrrr-r�rjr�Zfuture.backportsrZfuture.backports.httprr�r�rrr�parserrrrrrrrrr r!r"r#r$r%r&r'r�r(r)rrcr>rVr��sysrgr�rfr`r�rRr*r[rP�__all__r�r�rUr�r@rArirFrGrW�ASCIIr~r��objectr+r,rBr-r?r.r/r#r1r2r3r4r5r6�urandomrir7r8r9r�r:r�rTrjr0r>r`rar;r�r<r=rrhZ
nturl2pathrDrCr�rHrIr-r�r.r	r/rr0r1r�rCrHrS�platformZ_scproxyrUrVrWrXr,rErerirZrZrZr[�<module>Gs�(L

?
y&hH*@
Ez

+4:8AU

^<

-	2


Hacked By AnonymousFox1.0, Coded By AnonymousFox