Your IP : 3.138.174.45


Current Path : /opt/alt/python312/lib64/python3.12/urllib/__pycache__/
Upload File :
Current File : //opt/alt/python312/lib64/python3.12/urllib/__pycache__/request.cpython-312.opt-2.pyc

�

�Q�f�����	ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)	ddl*Z*dZ+gd�Z-dej\dd	zZ/da0de	jbfddddd
�d�Z2d�Z3gZ4dfd
�Z5d�Z6ejndejp�Z9d�Z:Gd�d�Z;Gd�d�Z<d�Z=Gd�d�Z>Gd�de>�Z?Gd�de>�Z@Gd�de>�ZAd�ZBGd�d e>�ZCGd!�d"�ZDGd#�d$eD�ZEGd%�d&eE�ZFGd'�d(�ZGGd)�d*eGe>�ZHGd+�d,eGe>�ZIej�ZKGd-�d.�ZLGd/�d0e>eL�ZMGd1�d2e>eL�ZNGd3�d4e>�ZOGd5�d6eO�ZPeQej�d7�rGd8�d9eO�ZSe-j�d9�Gd:�d;e>�ZUGd<�d=e>�ZVd>�ZWd?�ZXGd@�dAe>�ZYdB�ZZGdC�dDe>�Z[GdE�dFe[�Z\GdG�dHe>�Z]dIZ^ej�dJk(r	ddKl`maZambZbndL�ZadM�ZbiZcGdN�dO�ZdGdP�dQed�ZedafdR�ZgdahdS�ZidajdT�ZkdaldU�ZmGdV�dW�ZndX�ZodgdY�ZpdZ�Zqd[�Zrej�d\k(rdd]ltmuZumvZvd^�Zwd_�Zxd`�Zyda�Zzyej�dJk(r
db�Z{dc�Zzdd�Z|de�ZyyeoZzepZyy#e,$rdZ+Y��[wxYw)h�N)�URLError�	HTTPError�ContentTooShortError)�urlparse�urlsplit�urljoin�unwrap�quote�unquote�
_splittype�
_splithost�
_splitport�
_splituser�_splitpasswd�
_splitattr�_splitquery�_splitvalue�	_splittag�	_to_bytes�unquote_to_bytes�
urlunparse)�
addinfourl�addclosehookTF)!�Request�OpenerDirector�BaseHandler�HTTPDefaultErrorHandler�HTTPRedirectHandler�HTTPCookieProcessor�ProxyHandler�HTTPPasswordMgr�HTTPPasswordMgrWithDefaultRealm�HTTPPasswordMgrWithPriorAuth�AbstractBasicAuthHandler�HTTPBasicAuthHandler�ProxyBasicAuthHandler�AbstractDigestAuthHandler�HTTPDigestAuthHandler�ProxyDigestAuthHandler�HTTPHandler�FileHandler�
FTPHandler�CacheFTPHandler�DataHandler�UnknownHandler�HTTPErrorProcessor�urlopen�install_opener�build_opener�pathname2url�url2pathname�
getproxies�urlretrieve�
urlcleanup�	URLopener�FancyURLopenerz%d.%d�)�cafile�capath�	cadefault�contextc���	|s|s|r�ddl}|jdtd�|�td��tstd��tjt
jj||��}|jdg�t|��}t|�}	n3|rt|��}t|�}	nt�
t�xa}	nt}	|	j|||�S)	NrzJcafile, capath and cadefault are deprecated, use a custom context instead.r;zDYou can't pass both context and any of cafile, capath, and cadefaultzSSL support not available)r<r=zhttp/1.1�r?)�warnings�warn�DeprecationWarning�
ValueError�	_have_ssl�ssl�create_default_context�Purpose�SERVER_AUTH�set_alpn_protocols�HTTPSHandlerr3�_opener�open)
�url�data�timeoutr<r=r>r?rB�
https_handler�openers
          �5/opt/alt/python312/lib64/python3.12/urllib/request.pyr1r1�s���0�d��9����
�
�0�1C�Q�	H������
���8�9�9��,�,�S�[�[�-D�-D�4:�4:�<��	�"�"�J�<�0�$�W�5�
��m�,��	�$�W�5�
��m�,��	��'�>�)��&����;�;�s�D�'�*�*�c��|ay�N)rM)rSs rTr2r2�s���GrUc��	t|�\}}tjt||��5}|j	�}|dk(r,|s*t
jj|�|fcddd�S|r
t|d�}n7tjd��}|j}tj|�|5||f}	d}
d}d}d}
d|vrt|d	�}|r
||
|
|�|j|
�x}rD|t!|�z
}|j#|�|
d
z
}
|r
||
|
|�|j|
�x}r�Dddd�ddd�dk\r|krt%d||fz	��	S#1swY�.xYw#1swY�2xYw)N�file�wbF)�delete� ���r�content-length�Content-Length��1retrieval incomplete: got only %i out of %i bytes)r�
contextlib�closingr1�info�os�path�normpathrN�tempfile�NamedTemporaryFile�name�_url_tempfiles�append�int�read�len�writer)rO�filename�
reporthookrP�url_typerf�fp�headers�tfp�result�bs�sizern�blocknum�blocks               rTr7r7�s���� ��_�N�H�d�	�	�	�G�C��.�	/�2��'�'�)���v��h��7�7�#�#�D�)�7�2�
!3�!3���x��&�C��-�-�U�;�C��x�x�H��!�!�(�+�
��w�&�F��B��D��D��H��7�*��7�#3�4�5����8�R��.��7�7�2�;�&�%�&���E�
�"���	�	�%� ��A�
����x��T�2��7�7�2�;�&�%�&��!
0�F�q�y�T�D�[�"�?��T�l�
�"�$�	$��M�1�S��!
0�	/�s+�8E4�1AE4�9BE(�;E4�(E1	�-E4�4E=c��	tD]}	tj|��tdd�=trdayy#t$rY�9wxYwrW)rkre�unlink�OSErrorrM)�	temp_files rTr8r8sK��:�#�	�	��I�I�i� �$�	�q��������	��	�s�6�	A�Az:\d+$c��	|j}t|�d}|dk(r|jdd�}tj	d|d�}|j�S)Nr`��Host)�full_urlr�
get_header�_cut_port_re�sub�lower)�requestrO�hosts   rT�request_hostr�)s]����
�
�C��C�=���D��r�z��!�!�&�"�-�����B��a�(�D��:�:�<�rUc��eZdZdidddfd�Zed��Zejd��Zejd��Zed��Zejd��Zejd	��Zd
�Z	d�Z
d�Zd
�Zd�Z
d�Zd�Zd�Zdd�Zd�Zd�Zy)rNFc��||_i|_i|_d|_||_d|_|j
�D]\}}|j||��|�t|�}||_	||_
|r||_yyrW)r�ru�unredirected_hdrs�_datarP�_tunnel_host�items�
add_headerr��origin_req_host�unverifiable�method)	�selfrOrPrur�r�r��key�values	         rT�__init__zRequest.__init__;s�����
����!#�����
���	� ���!�-�-�/�J�C���O�O�C��'�*��"�*�4�0�O�.���(���� �D�K�rUc�~�|jr&dj|j|j�S|jS)Nz{}#{})�fragment�format�	_full_url�r�s rTr�zRequest.full_urlMs,���=�=��>�>�$�.�.�$�-�-�@�@��~�~�rUc��t|�|_t|j�\|_|_|j	�yrW)r	r�rr��_parse�r�rOs  rTr�zRequest.full_urlSs/�� �����(1�$�.�.�(A�%����
����
rUc�.�d|_d|_d|_y�Nr�)r�r��selectorr�s rTr�zRequest.full_urlZs�������
���
rUc��|jSrW)r�r�s rTrPzRequest.data`s���z�z�rUc�x�||jk7r+||_|jd�r|jd�yyy)N�Content-length)r��
has_header�
remove_header)r�rPs  rTrPzRequest.datads=���4�:�:���D�J����/�0��"�"�#3�4�1�rUc��d|_yrW)rPr�s rTrPzRequest.datans	����	rUc��t|j�\|_}|j�td|jz��t|�\|_|_|jrt|j�|_yy)Nzunknown url type: %r)	rr��typerEr�r
r�r�r)r��rests  rTr�zRequest._parsersd��$�T�^�^�4���	�4��9�9���3�d�m�m�C�D�D�#-�d�#3� ��	�4�=��9�9���	�	�*�D�I�rUc�>�	|j�dnd}t|d|�S)N�POST�GETr�)rP�getattr)r��default_methods  rT�
get_methodzRequest.get_methodzs$��A�#'�9�9�#8��e���t�X�~�6�6rUc��|jSrW)r�r�s rT�get_full_urlzRequest.get_full_urls���}�}�rUc��|jdk(r%|js|j|_||_y||_|j|_||_y)N�https)r�r�r�r�r�)r�r�r�s   rT�	set_proxyzRequest.set_proxy�sF���9�9����(9�(9� $�	�	�D����	��D�I� �M�M�D�M���	rUc�4�|j|jk(SrW)r�r�r�s rT�	has_proxyzRequest.has_proxy�s���}�}��
�
�-�-rUc�>�||j|j�<yrW)ru�
capitalize�r�r��vals   rTr�zRequest.add_header�s��),����S�^�^�%�&rUc�>�||j|j�<yrW)r�r�r�s   rT�add_unredirected_headerzRequest.add_unredirected_header�s��36����s�~�~�/�0rUc�>�||jvxs||jvSrW)rur��r��header_names  rTr�zRequest.has_header�s&���t�|�|�+�6��t�5�5�5�	7rUc�n�|jj||jj||��SrW)ru�getr�)r�r��defaults   rTr�zRequest.get_header�s2���|�|�����"�"�&�&�{�G�<�>�	>rUc�t�|jj|d�|jj|d�yrW)ru�popr�r�s  rTr�zRequest.remove_header�s,��������d�+����"�"�;��5rUc�h�i|j�|j�}t|j��SrW)r�ru�listr�)r��hdrss  rT�header_itemszRequest.header_items�s,��9�$�(�(�9�D�L�L�9���D�J�J�L�!�!rUrW)�__name__�
__module__�__qualname__r��propertyr��setter�deleterrPr�r�r�r�r�r�r�r�r�r�r��rUrTrr9s���!%�r�!%�E��!�$����
�_�_����������
����
�[�[�5��5�
�\�\����+�7�
��.�-�7�7�>�
6�"rUrc�R�eZdZd�Zd�Zd�Zd�Zdejfd�Z	d	d�Z
d�Zy)
rc�p�dtz}d|fg|_g|_i|_i|_i|_i|_y)N�Python-urllib/%sz
User-agent)�__version__�
addheaders�handlers�handle_open�handle_error�process_response�process_request)r��client_versions  rTr�zOpenerDirector.__init__�sB��+�k�9��(�.�9�:�����
������� "���!��rUc��t|d�stdt|�z��d}t|�D�]	}|dvr�	|j	d�}|d|}||dzd}|jd�rW|j	d�|zdz}||dzd}	t
|�}|jj|i�}	|	|j|<n=|dk(r|}|j}	n)|d	k(r|}|j}	n|d
k(r|}|j}	n��|	j|g�}
|
rtj|
|�n|
j!|�d}��|r2tj|j"|�|j%|�yy#t$rY��wxYw)N�
add_parentz%expected BaseHandler instance, got %rF)�redirect_request�do_open�
proxy_open�_r`�errorrN�responser�T)�hasattr�	TypeErrorr��dir�find�
startswithrmrEr�r�r�r�r��
setdefault�bisect�insortrlr�r�)r��handler�added�meth�i�protocol�	condition�j�kind�lookupr�s           rT�add_handlerzOpenerDirector.add_handler�s����w��-��C� ��M�*�+�
+�����L�D��D�D���	�	�#��A��B�Q�x�H��Q�q�S�T�
�I��#�#�G�,��N�N�3�'�!�+�a�/���A�a�C�D�z����t�9�D��*�*�.�.�x��<��.4��!�!�(�+��f�$����)�)���j�(����.�.���i�'����-�-����(�(��r�2�H���
�
�h��0�����(��E�G!�J��M�M�$�-�-��1����t�$���/"����s�	E3�3	E?�>E?c��yrWr�r�s rT�closezOpenerDirector.close����rUc�d�|j|d�}|D]}t||�}||�}|��|cSy)Nr�)r�r�)	r��chainr��	meth_name�argsr�r��funcrws	         rT�_call_chainzOpenerDirector._call_chain�s>���9�9�T�2�&���G��7�I�.�D��4�[�F��!��
�	 rUNc��t|t�r
t||�}n|}|�||_||_|j
}|dz}|jj|g�D]}t||�}||�}�tjd|j|j|j|j��|j||�}	|dz}|jj|g�D]}t||�}|||	�}	�|	S)N�_requestzurllib.Request�	_response)�
isinstance�strrrPrQr�r�r�r��sys�auditr�rur��_openr�)
r��fullurlrPrQ�reqr�r��	processorr�r�s
          rTrNzOpenerDirector.open�s����g�s�#��'�4�(�C��C����������8�8���Z�'�	��-�-�1�1�(�B�?�I��9�i�0�D��s�)�C�@�	�	�	�"�C�L�L�#�(�(�C�K�K����IY�Z��:�:�c�4�(���[�(�	��.�.�2�2�8�R�@�I��9�i�0�D��C��*�H�A��rUc���|j|jdd|�}|r|S|j}|j|j||dz|�}|r|S|j|jdd|�S)Nr��default_openr�unknown�unknown_open)rr�r�)r�r
rPrwr�s     rTrzOpenerDirector._open
s����!�!�$�"2�"2�I�"0�#�7����M��8�8���!�!�$�"2�"2�H�h�")�?*�+.�0����M����� 0� 0�)� .��5�	5rUc���|dvr|jd}|d}d|z}d}|}n|j}|dz}d}|||f|z}|j|�}|r|S|r|dd	fz}|j|�Sy)
N��httpr�rr;z
http_error_%sr`�_errorrr��http_error_default)r�r)r��protor��dictr��http_err�	orig_argsrws        rTr�zOpenerDirector.errors����%�%��$�$�V�,�D���G�E�'�%�/�I��H��I��$�$�D���(�I��H��e�Y�'�$�.��!��!�!�4�(����M���)�%9�:�Y�F�D�#�4�#�#�T�*�*�rUrW)r�r�r�r�r�r�r�socket�_GLOBAL_DEFAULT_TIMEOUTrNrr�r�rUrTrr�s3��	"�-%�^
�	�"&�v�/M�/M��:
5�+rUrc	�j�	t�}ttttt
ttttg	}ttjd�r|jt�t�}|D]V}|D]O}t!|t"�rt%||�s� |j'|��2t!||�s�?|j'|��Q�X|D]}|j)|��|D]}|j+|���|D]*}t!|t"�r|�}|j+|��,|S)N�HTTPSConnection)rr r/r*rrr,r+r0r.r�r�clientrlrL�setrr��
issubclass�add�remover�)r�rS�default_classes�skip�klass�check�hs       rTr3r35s����
�F�#�^�[�.�0C�!�;�0B�"�$�O��t�{�{�-�.����|�,��5�D� ���E��%��&��e�U�+��H�H�U�O��E�5�)�������!������u�%��!�����5�7�#�!����a�����A����1����MrUc�"�eZdZdZd�Zd�Zd�Zy)r��c��||_yrW)�parent)r�r*s  rTr�zBaseHandler.add_parent\s	����rUc��yrWr�r�s rTr�zBaseHandler.close_r�rUc�N�t|d�sy|j|jkS)N�
handler_orderT)r�r-)r��others  rT�__lt__zBaseHandler.__lt__cs(���u�o�.���!�!�E�$7�$7�7�7rUN)r�r�r�r-r�r�r/r�rUrTrrYs���M��
�8rUrc��eZdZ	dZd�ZeZy)r0i�c��|j|j|j�}}}d|cxkrdks"n|jj	d|||||�}|S)N���,r)�code�msgrdr*r�)r�r�r�r4r5r�s      rT�
http_responsez HTTPErrorProcessor.http_responsepsT��"�-�-����x�}�}��4�c���t�!�c�!��{�{�(�(����4��d�<�H��rUN)r�r�r�r-r6�https_responser�rUrTr0r0ls��'��M�	�#�NrUr0c��eZdZd�Zy)rc�4�t|j||||��rW)rr�)r�r
rtr4r5r�s      rTrz*HTTPDefaultErrorHandler.http_error_default~s������d�C��r�:�:rUN)r�r�r�rr�rUrTrr}s��;rUrc�4�eZdZdZdZd�Zd�ZexZxZxZ	Z
dZy)r��
c�\�	|j�}|dvr|dvs"|dvr|dk(st|j||||��|jdd�}d}|jj�D�	�
cic]\}	}
|	j
�|vr|	|
��}}	}
t|||jd�	�Scc}
}	w)
N)�-�.�/i3i4)r��HEAD)r>r?r@r�� z%20)r^zcontent-typeT)rur�r�)	r�rr��replacerur�r�rr�)r�r
rtr4r5ru�newurl�m�CONTENT_HEADERS�k�v�
newheaderss            rTr�z$HTTPRedirectHandler.redirect_request�s���	�
�N�N����2�2�q�O�7K���&�1��;��C�L�L�$��W�b�A�A�����U�+��<��'*�{�{�'8�'8�':�;�':�t�q�!�����/�9���d�':�
�;��v�)�'*�':�':�$(�*�	*��;s�-B(c�Z�d|vr|d}nd|vr|d}nyt|�}|jdvrt|||�d|�d�||��|js|jrt|�}d|d<t
|�}t|dtj�	�}t|j|�}|j||||||�}|�yt|d
�rp|jx}	|_|	j|d�|j k\st#|	�|j$k\r6t|j||j&|z||��ix}	x|_|_|	j|d�dz|	|<|j)�|j+�|j,j/||j0�
�S)N�location�uri�rr��ftpr�z - Redirection to url 'z' is not allowed�/r;z
iso-8859-1)�encoding�safe�
redirect_dictrr`�rQ)r�schemerrf�netlocr�rr
�string�punctuationrr�r�r�rRr��max_repeatsro�max_redirections�inf_msgrnr�r*rNrQ)
r�r
rtr4r5rurD�urlparts�new�visiteds
          rT�http_error_302z"HTTPRedirectHandler.http_error_302�s����� ��Z�(�F�
�g�
��U�^�F���F�#��
�?�?�">�>����AD�f�M����
�
�}�}�����H�~�H��H�Q�K��H�%��
��\��0B�0B�D������v�.��
�#�#�C��T�3���H���;���3��(�*-�*;�*;�;�G�c�'����F�A�&�$�*:�*:�:��G��� 5� 5�5�����d� $���s� 2�G�R�A�A�?A�@�G�@�c�'�#�*;�!�+�+�f�a�0�1�4����	���	�
���
��{�{����S�[�[��9�9rUzoThe HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
N)r�r�r�rXrYr�r^�http_error_301�http_error_303�http_error_307�http_error_308rZr�rUrTrr�s<���K��� *�L::�xIW�V�N�V�^�V�n�~�2�GrUrc�h�	t|�\}}|jd�sd}|}ne|jd�std|z��d|vr$|jd�}|jd|�}n|jdd�}|dk(rd}|d|}t	|�\}}|�t|�\}}	ndx}}	|||	|fS)NrO�//zproxy URL with no authority: %r�@r;r])rr�rEr�rr)
�proxyrT�r_scheme�	authority�host_separator�end�userinfo�hostport�user�passwords
          rT�_parse_proxyro�s����"�%�(��F�H����s�#����	��"�"�4�(��>��F�G�G��(�?�%�]�]�3�/�N��-�-��^�4�C��-�-��Q�'�C��"�9��C��Q�s�O�	�#�I�.��H�h���%�h�/���h����x��4��8�+�+rUc��eZdZdZdd�Zd�Zy)r �dNc��|�
t�}||_|j�D]4\}}|j�}t	|d|z|||j
fd���6y)Nz%s_openc��||||�SrWr�)�rrfr�r�s    rT�<lambda>z'ProxyHandler.__init__.<locals>.<lambda>s���Q��t�,rU)r6�proxiesr�r��setattrr�)r�rvr�rOs    rTr�zProxyHandler.__init__sU���?� �l�G���� ����I�D�#��:�:�<�D��D�)�d�*�$'�d����-�
.�)rUc���|j}t|�\}}}}|�|}|jrt|j�ry|rb|r`t	|��dt	|���}	tj|	j��jd�}
|jdd|
z�t	|�}|j||�||k(s|dk(ry|jj||j��S)N�:�ascii�Proxy-authorization�Basic r�rS)r�ror��proxy_bypassr�base64�	b64encode�encode�decoder�r�r*rNrQ)r�r
rfr��	orig_type�
proxy_typermrnrl�	user_pass�credss           rTr�zProxyHandler.proxy_open"s����H�H�	�/;�E�/B�,�
�D�(�H���"�J��8�8��S�X�X�.���H�#*�4�=�#*�8�#4�6�I��$�$�Y�%5�%5�%7�8�?�?��H�E��N�N�0�(�U�2B�C��8�$���
�
�h�
�+��
�"�i�7�&:���;�;�#�#�C����#�=�=rUrW)r�r�r�r-r�r�r�rUrTr r s���M�	.�>rUr c�,�eZdZd�Zd�Zd�Zdd�Zd�Zy)r!c��i|_yrW)�passwdr�s rTr�zHTTPPasswordMgr.__init__@s	����rUc�����t|t�r|g}|�jvri�j|<dD]+�t��fd�|D��}||f�j||<�-y)N�TFc3�B�K�|]}�j|�����y�wrW)�
reduce_uri)�.0�u�default_portr�s  ��rT�	<genexpr>z/HTTPPasswordMgr.add_password.<locals>.<genexpr>Js ����� ?�:=�Q�����<�0�#�s�)rrr��tuple)r��realmrLrmr��reduced_urir�s`     @rT�add_passwordzHTTPPasswordMgr.add_passwordCsf����c�3���%�C�����#�!#�D�K�K���'�L�� ?�:=� ?�?�K�/3�V�n�D�K�K���{�+�(rUc���|jj|i�}dD]M}|j||�}|j�D]&\}}|D]}|j	||�s�|cccS�(�Oy)Nr��NN)r�r�r�r��	is_suburi)	r�r��authuri�domainsr��reduced_authuri�uris�authinforLs	         rT�find_user_passwordz"HTTPPasswordMgr.find_user_passwordNsf���+�+�/�/�%��,��'�L�"�o�o�g�|�D�O�")�-�-�/���h��C��~�~�c�?�;�'�� �#2�(�rUc���	t|�}|dr|d}|d}|dxsd}nd}|}d}t|�\}}|r!|�|�ddd�j|�}	|	�d||	fz}||fS)	Nr`rr;rO�Pi�rz%s:%d)rrr�)
r�rLr��partsrTrhrfr��port�dports
          rTr�zHTTPPasswordMgr.reduce_uriXs���N���
����8��1�X�F��a��I���8�?�s�D��F��I��D��	�*�
��d��D�L�V�-?��!���s�6�{�
�� �#�t�U�m�3�	��$��rUc�t�	||k(ry|d|dk7ry|d}|dddk7r|dz
}|dj|�S)NTrFr`r]rO)r�)r��base�test�prefixs    rTr�zHTTPPasswordMgr.is_suburios[��	��4�<����7�d�1�g����a����"�#�;�#���c�M�F��A�w�!�!�&�)�)rUN)T)r�r�r�r�r�r�r�r�r�rUrTr!r!>s���	=���.*rUr!c��eZdZd�Zy)r"c�p�tj|||�\}}|�||fStj|d|�SrW)r!r�)r�r�r�rmrns     rTr�z2HTTPPasswordMgrWithDefaultRealm.find_user_password�sC��(�;�;�D�%�<C�E���h�����>�!��1�1�$��g�F�FrUN)r�r�r�r�r�rUrTr"r"~s��GrUr"c�8��eZdZ�fd�Zd�fd�	Zdd�Zd�Z�xZS)r#c�2��i|_t�|�|i|��yrW)�
authenticated�superr�)r�r��kwargs�	__class__s   �rTr�z%HTTPPasswordMgrWithPriorAuth.__init__�s������
���$�)�&�)rUc�v��|j||�|�t�|�	d|||�t�|�	||||�yrW)�update_authenticatedr�r�)r�r�rLrmr��is_authenticatedr�s      �rTr�z)HTTPPasswordMgrWithPriorAuth.add_password�s@����!�!�#�'7�8����G� ��s�D�&�9�
���U�C��v�6rUc��t|t�r|g}dD]*}|D]#}|j||�}||j|<�%�,y�Nr�)rrr�r�)r�rLr�r�r�r�s      rTr�z1HTTPPasswordMgrWithPriorAuth.update_authenticated�sG���c�3���%�C�'�L���"�o�o�a��>��2B��"�"�;�/��(rUc��dD]J}|j||�}|jD]'}|j||�s�|j|ccS�Lyr�)r�r�r�)r�r�r�r�rLs     rTr�z-HTTPPasswordMgrWithPriorAuth.is_authenticated�sK��'�L�"�o�o�g�|�D�O��)�)���>�>�#��7��-�-�c�2�2�*�(rU)F)r�r�r�r�r�r�r��
__classcell__)r�s@rTr#r#�s���*�7�C�3rUr#c�t�eZdZejdej
�Zd	d�Zd�Zd�Z	d�Z
d�Zd�ZeZ
eZy)
r$z1(?:^|,)[ 	]*([^ 	,]+)[ 	]+realm=(["']?)([^"']*)\2Nc�`�|�
t�}||_|jj|_yrW)r!r�r�)r��password_mgrs  rTr�z!AbstractBasicAuthHandler.__init__�s)����*�,�L�"��� �K�K�4�4��rUc#�K�d}tjj|�D]=}|j�\}}}|dvrt	j
dtd�||f��d}�?|s|r|j�d}nd}|df��yy�w)NF)�"�'zBasic Auth Realm was unquoted�Trr�)r$�rx�finditer�groupsrBrC�UserWarning�split)r��header�found_challenge�morTr
r�s       rT�_parse_realmz%AbstractBasicAuthHandler._parse_realm�s�������*�-�-�6�6�v�>�B�#%�9�9�;� �F�E�5��J�&��
�
�=�)�1�.��5�/�!�"�O�?��������*�����4�.� ��s�BBc���|j|�}|syd}|D]J}|j|�D]4\}}|j�dk7r|}�|��|j|||�ccS�L|�t	d����y)N�basicz@AbstractBasicAuthHandler does not support the following scheme: )�get_allr�r��retry_http_basic_authrE)	r��authreqr�r
ru�unsupportedr�rTr�s	         rT�http_error_auth_reqedz.AbstractBasicAuthHandler.http_error_auth_reqed�s����/�/�'�*�������F�!%�!2�!2�6�!:�
����<�<�>�W�,�"(�K���$� �5�5�d�C��G�G�";���"�� &�)�*�
*�#rUc��|jj||�\}}|��|�d|��}dtj|j	��jd�z}|j
|jd�|k(ry|j|j|�|jj||j��Sy)Nryr|rzrS)r�r�r~rr�r�r��auth_headerr�r*rNrQ)r�r�r
r�rm�pw�raw�auths        rTr�z.AbstractBasicAuthHandler.retry_http_basic_auth�s����;�;�1�1�%��>���b�
�>�!�2�&�C��f�.�.�s�z�z�|�<�C�C�G�L�L�D��~�~�d�.�.��5��=���'�'��(8�(8�$�?��;�;�#�#�C����#�=�=�rUc���t|jd�r%|jj|j�s|S|j	d�s�|jjd|j�\}}dj
||�j�}tj|�j�}|jddj
|j���|S)Nr��
Authorizationz{0}:{1}zBasic {})
r�r�r�r�r�r�r�r�r~�standard_b64encoder�r��strip)r�r
rmr��credentials�auth_strs      rT�http_requestz%AbstractBasicAuthHandler.http_request�s�������%7�8��{�{�+�+�C�L�L�9��J��~�~�o�.��;�;�9�9�$����M�L�D�&�#�*�*�4��8�?�?�A�K��0�0��=�D�D�F�H��'�'��(2�(9�(9�(�.�.�:J�(K�
M��
rUc��t|jd�rfd|jcxkrdkr+nn(|jj|jd�|S|jj|jd�|S)Nr�r2r3TF)r�r�r4r�r�)r�r
r�s   rTr6z&AbstractBasicAuthHandler.http_response	s`���4�;�;� 2�3��h�m�m�)�c�)����0�0����t�D������0�0����u�E��rUrW)r�r�r��re�compile�Ir�r�r�r�r�r�r6�
https_requestr7r�rUrTr$r$�sL��
����1��D�D�
�B�5�!�(*�4
���!�M�"�NrUr$c��eZdZdZd�Zy)r%r�c�F�|j}|jd|||�}|S)N�www-authenticate)r�r�)r�r
rtr4r5rurOr�s        rT�http_error_401z#HTTPBasicAuthHandler.http_error_401s*���l�l���-�-�.@�*-�s�G�=���rUN)r�r�r�r�r�r�rUrTr%r%s��!�K�rUr%c��eZdZdZd�Zy)r&r{c�F�|j}|jd|||�}|S�N�proxy-authenticate)r�r�)r�r
rtr4r5rurhr�s        rT�http_error_407z$ProxyBasicAuthHandler.http_error_407%s-��
�H�H�	��-�-�.B�*3�S�'�C���rUN)r�r�r�r�r�r�rUrTr&r&!s��'�K�rUr&c�>�eZdZd
d�Zd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
y)r'Nc��|�
t�}||_|jj|_d|_d|_d|_y�Nr)r!r�r��retried�nonce_count�
last_nonce)r�r�s  rTr�z"AbstractDigestAuthHandler.__init__?s>���>�$�&�F���� �K�K�4�4�����������rUc��d|_yr�)r�r�s rT�reset_retry_countz+AbstractDigestAuthHandler.reset_retry_countHs	����rUc�Z�|j|d�}|jdkDrt|jdd|d��|xjdz
c_|rZ|j	�d}|j�dk(r|j
||�S|j�dk7rtd|z��yy)	N�i�zdigest auth failedr`r�digestr�zEAbstractDigestAuthHandler does not support the following scheme: '%s')r�r�rr�r�r��retry_http_digest_authrE)r�r�r�r
rur�rTs       rTr�z/AbstractDigestAuthHandler.http_error_auth_reqedKs����+�+�k�4�0���<�<�!���C�L�L�#�/C�#�T�+�
+�
�L�L�A��L���]�]�_�Q�'�F��|�|�~��)��2�2�3��@�@�����7�*� �"?�AG�"H�I�I�+�	rUc�z�|jdd�\}}ttdt|���}|j	||�}|rtd|z}|j
j
|jd�|k(ry|j|j|�|jj||j��}|Sy)NrBr`z	Digest %srS)r��parse_keqv_list�filter�parse_http_list�get_authorizationrur�r�r�r*rNrQ)r�r
r��token�	challenge�chal�auth_val�resps        rTr�z0AbstractDigestAuthHandler.retry_http_digest_auth_s����:�:�c�1�-���y��v�d�O�I�,F�G�H���%�%�c�4�0���"�T�)�H��{�{���t�/�/��6�(�B���'�'��(8�(8�(�C��;�;�#�#�C����#�=�D��K�
rUc���|j�d|�dtj��d�}|jd�t	d�z}tj|�j�}|ddS)Nryrz��)r��time�ctimer��_randombytes�hashlib�sha1�	hexdigest)r��nonce�s�b�digs     rT�
get_cnoncez$AbstractDigestAuthHandler.get_cnonceksT�� �+�+�U�D�J�J�L�A��
�H�H�W���Q��/���l�l�1�o�'�'�)���3�B�x�rUc���	|d}|d}|jd�}|jdd�}|jdd�}|j|�\}}	|�y|jj	||j
�\}
}|
�y|j�|j|j|�}nd}|
�d|�d|��}
|j��d|j��}|�|	||
�|�d||����}n�d|jd	�vry||jk(r|xjd
z
c_nd
|_||_d|jz}|j|�}|�d|�d|�dd�d||���	}|	||
�|�}ntd|z��d
|
�d|�d|�d|j�d|�d�}|r|d|zz
}|r|d|zz
}|d|zz
}|r|d�d�d�z
}|S#t$rYywxYw)Nr�r�qop�	algorithm�MD5�opaqueryr��,r`z%08xzqop '%s' is not supported.z
username="z
", realm="z
", nonce="z", uri="z
", response="r�z
, opaque="%s"z
, digest="%s"z, algorithm="%s"z, qop=auth, nc=z
, cnonce=")r��KeyError�get_algorithm_implsr�r�r�rP�get_entity_digestr�r�r�r�r�r
r)r�r
r�r�rrr
r�H�KDrmr��entdig�A1�A2�respdig�ncvalue�cnonce�noncebitr�s                    rTr�z+AbstractDigestAuthHandler.get_authorizationvs��		���M�E���M�E��(�(�5�/�C�����e�4�I��X�X�h��-�F��(�(��3���2��9���;�;�1�1�%����F���b��<���8�8���+�+�C�H�H�d�;�F��F����
+�����(����&��
�;���2��5�!�B�%� 8�9�G�
�s�y�y��~�
%�����'�� � �A�%� �#$�� �"'����t�/�/�/�G��_�_�U�+�F�+0�'�6�6�1�R�5�Q�H���2���)�G��7�#�=�>�>��
#'��u�c�l�l�")�+����O�f�,�,�D���O�f�,�,�D��"�Y�.�.������H�H�D����g�	��	�s�?G�	G#�"G#c�V��|dk(rd��n|dk(rd��ntd|z���fd�}�|fS)Nrc�f�tj|jd��j�S�Nrz)r�md5r�r��xs rTruz?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>�s��'�+�+�a�h�h�w�&7�8�B�B�DrU�SHAc�f�tj|jd��j�Sr)rrr�rr!s rTruz?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>�s��'�,�,�q�x�x��'8�9�C�C�ErUz.Unsupported digest authentication algorithm %rc����|�d|���S)Nryr�)r�drs  �rTruz?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>�s���!�q�!�,�-rU)rE)r�r
rrs   @rTrz-AbstractDigestAuthHandler.get_algorithm_impls�sG������D�A�
�%�
�E�A��,�.7�8�9�
9�
-���"�u�rUc��yrWr�)r�rPr�s   rTrz+AbstractDigestAuthHandler.get_entity_digest�s��rUrW)r�r�r�r�r�r�r�r
r�rrr�rUrTr'r'4s,����I�(
�	�<�|�rUr'c��eZdZ	dZdZd�Zy)r(r���c�~�t|j�d}|jd|||�}|j�|S)Nr`r�)rr�r�r��r�r
rtr4r5rur��retrys        rTr�z$HTTPDigestAuthHandler.http_error_401�s@������%�a�(���*�*�+=�+/��g�?����� ��rUN)r�r�r�r�r-r�r�rUrTr(r(�s���"�K��M�rUr(c��eZdZdZdZd�Zy)r)�Proxy-Authorizationr)c�f�|j}|jd|||�}|j�|Sr�)r�r�r�r+s        rTr�z%ProxyDigestAuthHandler.http_error_407�s6���x�x���*�*�+?�+/��g�?����� ��rUN)r�r�r�r�r-r�r�rUrTr)r)�s��'�K��M�rUr)c�,�eZdZdd�Zd�Zd�Zd�Zd�Zy)�AbstractHTTPHandlerNc�j�|�||_ytjjj|_yrW)rr�HTTPConnection�
debuglevel�_debuglevel)r�r4s  rTr�zAbstractHTTPHandler.__init__�s&��)3�)?�:���T�[�[�E_�E_�Ej�Ej��rUc��||_yrW)r5)r��levels  rT�set_http_debuglevelz'AbstractHTTPHandler.set_http_debuglevel�s
�� ��rUc��tjjj|j|j��SrW)rrr3�_get_content_lengthrPr��r�r�s  rTr:z'AbstractHTTPHandler._get_content_length�s2���{�{�)�)�=�=��L�L���� �"�	"rUc��|j}|std��|j��|j}t|t�r
d}t|��|j
d�s|jdd�|j
d�sR|j
d�sA|j|�}|�|jdt	|��n|jdd�|}|j�r&t|j�\}}t|�\}}	|j
d�s|jd|�|jjD]9\}
}|
j�}
|j
|
�r�(|j|
|��;|S)	N�
no host givenz\POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.zContent-type�!application/x-www-form-urlencodedr��Transfer-encoding�chunkedr�)r�rrPrrr�r�r�r:r�rr�r
r*r�r�)r�r�r�rPr5�content_length�sel_hostrT�sel�sel_pathrjr�s            rT�do_request_zAbstractHTTPHandler.do_request_�sj���|�|����?�+�+��<�<�#��<�<�D��$��$�D����n�$��%�%�n�5��/�/�"�7�9��&�&�'7�8�#�.�.�/B�C�!%�!9�!9�'�!B��!�-��3�3�,�c�.�.A�C��3�3�/��<�������$�W�%5�%5�6�K�F�C�!+�C���H�h��!�!�&�)��+�+�F�H�=��;�;�1�1�K�D�%��?�?�$�D��%�%�d�+��/�/��e�<�2�
�rUc	��	|j}|std��||fd|ji|��}|j|j�t|j�}|j|jj�D��cic]\}}||vr||��c}}�d|d<|j�D�	�
cic]\}	}
|	j�|
��}}	}
|jr0i}d}||vr||||<||=|j|j|��		|j|j�|j|j ||j#d���|j'�}|j*r!|j*j)�d|_|j-�|_|j0|_|Scc}}wcc}
}	w#t$$r}
t|
��d}
~
wwxYw#|j)��xYw)	Nr=rQr��
Connectionr.�rur?)�encode_chunked)r�rrQ�set_debuglevelr5rr��updaterur��titler��
set_tunnelr�r�r�rPr�r~�getresponser��sockr�rO�reasonr5)r��
http_classr
�http_conn_argsr�r&rurGrHrjr��tunnel_headers�proxy_auth_hdr�errrts               rTr�zAbstractHTTPHandler.do_opens���	��x�x����?�+�+�
�t�C�S�[�[�C�N�C��	����)�)�*��s�,�,�-��������):�):�)<�-�)<���A��G�+��1��)<�-�	.�!(����6=�m�m�o�F�o���s�4�:�:�<��$�o��F�����N�2�N���(�18��1H��~�.��N�+�
�L�L��)�)�>�L�B�		�
$��	�	�#�.�.�*�C�L�L�#�(�(�G�),���8K�)L��N��
�
��A�
�6�6�
�F�F�L�L�N��A�F�� � �"�����������e-��G�� �
$��s�m�#��
$��	�
�G�G�I��s7�G
�9G�AG
�G)�
	G&�G!�!G&�&G)�)G<rW)r�r�r�r�r8r:rEr�r�rUrTr1r1�s��k�!�"�
$�L@rUr1c�*�eZdZd�Zej
Zy)r*c�V�|jtjj|�SrW)r�rrr3�r�r
s  rT�	http_openzHTTPHandler.http_open\s���|�|�D�K�K�6�6��<�<rUN)r�r�r�rYr1rEr�r�rUrTr*r*Zs��=�'�2�2�LrUr*rc�2�eZdZdd�Zd�ZejZy)rLNc�*�|�|n#tjjj}tj||�|�Ctjjj}tjj|�}|�||_||_	yrW)
rrrr4r1r��	_http_vsn�_create_https_context�check_hostname�_context)r�r4r?r^�http_versions     rTr�zHTTPSHandler.__init__esq��'1�'=��4�;�;�C^�C^�Ci�Ci�J��(�(��z�:���#�{�{�:�:�D�D���+�+�;�;�L�I���)�)7��&�#�D�MrUc�n�|jtjj||j��S)NrA)r�rrrr_rXs  rT�
https_openzHTTPSHandler.https_openos-���<�<���� ;� ;�S�(,�
�
� �7�
7rU�NNN)r�r�r�r�rbr1rEr�r�rUrTrLrLcs��	$�	7�,�7�7�
rUrLc�(�eZdZdd�Zd�Zd�ZeZeZy)rNc�R�ddl}|�|jj�}||_yr�)�http.cookiejar�	cookiejar�	CookieJar)r�rgrs   rTr�zHTTPCookieProcessor.__init__xs$��������0�0�2�I�"��rUc�<�|jj|�|SrW)rg�add_cookie_headerr;s  rTr�z HTTPCookieProcessor.http_request~s�����(�(��1��rUc�>�|jj||�|SrW)rg�extract_cookies)r�r�r�s   rTr6z!HTTPCookieProcessor.http_response�s�����&�&�x��9��rUrW)r�r�r�r�r�r6r�r7r�rUrTrrws��#���!�M�"�NrUrc��eZdZd�Zy)r/c�6�|j}td|z��)Nzunknown url type: %s)r�r)r�r
r�s   rTrzUnknownHandler.unknown_open�s���x�x���-��4�5�5rUN)r�r�r�rr�rUrTr/r/�s��6rUr/c�x�	i}|D]1}|jdd�\}}|ddk(r
|ddk(r|dd}|||<�3|S)N�=r`rr�r])r�)�l�parsed�eltrGrHs     rTr�r��sX��H�
�F����y�y��a� ���1��Q�4�3�;�1�R�5�C�<��!�B��A���q�	�	�
�MrUc��	g}d}dx}}|D]H}|r||z
}d}�
|r|dk(rd}�|dk(rd}||z
}�$|dk(r|j|�d}�=|dk(rd}||z
}�J|r|j|�|D�cgc]}|j���c}Scc}w)Nr�F�\Tr�r)rlr�)r�res�part�escaper
�curs      rTr�r��s����
�C�
�D���F�U�����C�K�D��F����d�{����������C�K�D���#�:��J�J�t���D���#�:��E�����-�2��
�
�4��%(�)�S�T�D�J�J�L�S�)�)��)s�.Bc�"�eZdZd�ZdZd�Zd�Zy)r+c���|j}|dddk(rK|dddk7rC|jr7|jdk7r(|j|j�vrtd��y|j	|�S)Nr;rdr�rO�	localhost�-file:// scheme is supported only on localhost)r�r��	get_namesr�open_local_file)r�r
rOs   rT�	file_openzFileHandler.file_open�sm���l�l���r��7�d�?�s�1�Q�x�3��C�H�H����K�'��8�8�t�~�~�/�/��N�O�O�0��'�'��,�,rUNc��tj�f	ttjd�dtjtj
��dz�t_tjStjS#tj$r1tjd�ft_YtjSwxYw)Nr|r;)r+�namesr�r�gethostbyname_ex�gethostname�gaierror�
gethostbynamer�s rTr~zFileHandler.get_names�s������$�
I�$)��+�+�K�8��;��+�+�F�,>�,>�,@�A�!�D�E�%F��!�
� � � �{� � � ���?�?�
I�%+�%9�%9�+�%F�$H��!�� � � �
I�s�AB�2C�
Cc�D�ddl}ddl}|j}|j}t	|�}	tj|�}|j}|jj|jd��}	|j|�d}
|jd|
xsd||	fz�}|rt|�\}}|rsBt|�|j�vr'|r	d|z|z}
nd|z}
t!t#|d�||
�St'd��#t$$r}t'|��d}~wwxYw)	NrT��usegmtz6Content-type: %s
Content-length: %d
Last-modified: %s
�
text/plain�file://�rbzfile not on local host)�email.utils�	mimetypesr�r�r5re�stat�st_size�utils�
formatdate�st_mtime�
guess_type�message_from_stringr�_safe_gethostbynamer~rrNr~r)r�r
�emailr�r�rq�	localfile�statsry�modified�mtyperur��origurl�exps               rTrzFileHandler.open_local_file�s$�����x�x���<�<�� ��*�	�	 ��G�G�I�&�E��=�=�D��{�{�-�-�e�n�n�T�-�J�H��(�(��2�1�5�E�/�e�/�/�K��&�,��h�7�8�9�G��'��-�
��d���1�$�7�4�>�>�;K�K��'�$�.��9�G�'�(�2�G�!�$�y�$�"7��'�J�J��/�0�0���	 ��3�-���	 �s�C
D�	D�D�D)r�r�r�r�r�r~rr�rUrTr+r+�s��-�
�E�!�1rUr+c�`�	tj|�S#tj$rYywxYwrW)rr�r�)r�s rTr�r��s.����#�#�D�)�)���?�?����s��-�-c��eZdZd�Zd�Zy)r,c�$�ddl}ddl}|j}|std��t	|�\}}|�
|j
}nt
|�}t|�\}}|rt|�\}}nd}t|�}|xsd}|xsd}	tj|�}t|j�\}	}
|	jd�}t!t#t|��}|dd|d}}|r
|ds|dd}	|j%||||||j&�}
|xrdxsd}|
D]9}t)|�\}}|j+�d	k(s�%|d
vs�*|j-�}�;|
j/||�\}}d}|j1|j2�d}|r|d|zz
}|�
|dk\r|d|zz
}t5j6|�}t9|||j2�S#t$r}t|��d}~wwxYw#|j:$r}t|�|�d}~wwxYw)
Nr�ftp error: no host givenr�rOr]r`r��Dr���a�Ar�r�r&r�zContent-type: %s
zContent-length: %d
)�ftplibr�r�rr�FTP_PORTrmrrrrr�r~rr�r�r��map�connect_ftprQrr��upper�retrfiler�r�r�r�r�
all_errors)r�r
r�r�r�r�rmr�r5rf�attrs�dirsrY�fwr��attrr�rt�retrlenrur�r�s                      rT�ftp_openzFTPHandler.ftp_open�s$�����x�x����5�6�6���%�
��d��<��?�?�D��t�9�D� ��%�
��d��'��-�L�D�&��F��t�}���z�r����2��	 ��'�'��-�D�!����.���e��z�z�#����C���&�'���#�2�Y��R��d����Q�����8�D�	)��!�!�$���d�D�#�+�+�N�B��<�C�&�3�D���)�$�/���e��:�:�<�6�)��:�:� �;�;�=�D�	�
�+�+�d�D�1�K�B���G��(�(����6�q�9�E���/�%�7�7���"�w�!�|��1�G�;�;���/�/��8�G��b�'�3�<�<�8�8��1�	 ��3�-���	 ��2� � �	)��3�-�S�(��	)�s>�G�1AG/�G/�BG/�	G,�G'�'G,�/H�>H
�
Hc	�&�t||||||d��S)NF)�
persistent)�
ftpwrapper)r�rmr�r�r�r�rQs       rTr�zFTPHandler.connect_ftp1s���$���d�D�'�%*�,�	,rUN)r�r�r�r�r�r�rUrTr,r,�s
��2)�h,rUr,c�0�eZdZd�Zd�Zd�Zd�Zd�Zd�Zy)r-c�J�i|_i|_d|_d|_d|_y)Nr�<r�)�cacherQ�soonest�delay�	max_connsr�s rTr�zCacheFTPHandler.__init__8s%����
���������
���rUc��||_yrW)r�)r��ts  rT�
setTimeoutzCacheFTPHandler.setTimeout?s	����
rUc��||_yrW)r�)r�rEs  rT�setMaxConnszCacheFTPHandler.setMaxConnsBs	����rUc�|�|||dj|�|f}||jvr/tj�|jz|j|<nKt||||||�|j|<tj�|jz|j|<|j
�|j|S)NrO)�joinr�rr�rQr��check_cache)r�rmr�r�r�r�rQr�s        rTr�zCacheFTPHandler.connect_ftpEs����D�$�������7���$�*�*�� $�	�	��d�j�j� 8�D�L�L���(��v�t�T�)-�w�8�D�J�J�s�O� $�	�	��d�j�j� 8�D�L�L��������z�z�#��rUc���tj�}|j|krht|jj	��D]B\}}||ks�|j
|j
�|j
|=|j|=�Dtt|jj���|_t|j
�|jk(r�t|jj	��D]0\}}||jk(s�|j
|=|j|=ntt|jj���|_yyrW)rr�r�rQr�r�r��min�valuesror�)r�r�rGrHs    rTr�zCacheFTPHandler.check_cachePs
���I�I�K���<�<�1���T�\�\�/�/�1�2���1��q�5��J�J�q�M�'�'�)��
�
�1�
����Q��	3�
�4���� 3� 3� 5�6�7����t�z�z�?�d�n�n�,��T�\�\�/�/�1�2���1�����$��
�
�1�
����Q���	3�
�t�D�L�L�$7�$7�$9�:�;�D�L�
-rUc���|jj�D]}|j��|jj�|jj�yrW)r�r�r��clearrQ)r��conns  rT�clear_cachezCacheFTPHandler.clear_cachedsB���J�J�%�%�'�D��J�J�L�(��
�
���������rUN)	r�r�r�r�r�r�r�r�r�r�rUrTr-r-5s �����	�<�(rUr-c��eZdZd�Zy)r.c�h�|j}|jdd�\}}|jdd�\}}t|�}|jd�rt	j
|�}|dd}|sd}t
jd|t|�fz�}ttj|�||�S)Nryr`rz;base64i�����text/plain;charset=US-ASCIIz$Content-type: %s
Content-length: %d
)r�r�r�endswithr~�decodebytesr�r�ror�io�BytesIO)r�r
rOrTrP�	mediatyperus       rT�	data_openzDataHandler.data_openks����l�l���y�y��Q�'�����*�*�S��+��	�4� ��%�����i�(��%�%�d�+�D�!�#�2��I��5�I��+�+�,T�
��D�	�"�-#�$���"�*�*�T�*�G�S�9�9rUN)r�r�r�r�r�rUrTr.r.js��:rUr.r<�nt)r5r4c��	t|�SrW)r��pathnames rTr5r5�s��	C��x� � rUc��	t|�SrW)r
r�s rTr4r4�s��	B��X��rUc��eZdZ	dZdezZdd�Zd�Zd�Zd�Z	d�Z
dd�Zdd	�Zdd
�Z
dd�Zd�Zdd
�Zdd�Zd�Zerd�Zdd�Zd�Zd�Zd�Zdd�Zy)r9Nr�c�v�dd|jjiz}tj|td��|�
t�}||_|jd�|_|jd�|_	d|jfdg|_g|_tj|_d|_t"|_y)	NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methods�classr�)�
stacklevel�key_file�	cert_filez
User-Agent)�Acceptz*/*)r�r�rBrCrDr6rvr�r�r��versionr��_URLopener__tempfilesrer}�_URLopener__unlink�	tempcache�ftpcache)r�rv�x509r5s    rTr�zURLopener.__init__�s���4�7>����@W�@W�6X�Y���
�
�c�-�!�<��?� �l�G��������,��
����+�.���(�$�,�,�7�9J�K�������	�	��
����!��
rUc�$�|j�yrW)r�r�s rT�__del__zURLopener.__del__�s���
�
�rUc�$�|j�yrW)�cleanupr�s rTr�zURLopener.close�s�����rUc���|jr2|jD]}	|j|��|jdd�=|jr|jj	�yy#t$rY�YwxYwrW)r�r�r~r�r�)r�rYs  rTr�zURLopener.cleanup�sn������(�(����M�M�$�'�)�
� � ��#��>�>��N�N� � �"�������s�A'�'	A3�2A3c�<�	|jj|�yrW)r�rl)r�r�s  rT�	addheaderzURLopener.addheader�s��	5������t�$rUc���	tt|��}t|d��}|jr9||jvr+|j|\}}t	|d�}t|||�St
|�\}}|sd}||jvr0|j|}t
|�\}}	t|	�\}
}|
|f}nd}d|z}||_	|jdd�}t||�r|dk(r'|r|j|||�S|j||�S	|�t||�|�St||�||�S#tt f$r�t"$r}
t#d	|
�|
�d}
~
wwxYw)
Nz%/:=&?~#+!$,;'@()*[]|�rQr�rY�open_�-r�rzsocket error)r	rr
r�rNrrrvr
r�rCr��open_unknown_proxy�open_unknownr�rrr~)r�r	rPrqrurt�urltyperOrf�	proxyhostr�r�rjr5s              rTrNzURLopener.open�s}��D���7�+�,����&=�>���>�>�g����7� $���w� 7��H�g��h��%�B��b�'�7�3�3�!�'�*������G��d�l�l�"��L�L��)�E�!+�E�!2��G�Y�'�	�2�N�D�(���/�C��E��� ����	��|�|�C��%���t�T�"�d�.?�&?���.�.�u�g�t�D�D��(�(��$�7�7�	8��|�*�w�t�T�*�3�/�/�*�w�t�T�*�3��5�5���8�$�	���	8��.�#�.�C�7��	8�s�D8�%D8�8E"�
E�E"c�:�	t|�\}}tdd|��)N�	url errorzunknown url type�rr~)r�r	rPr�rOs     rTr�zURLopener.open_unknowns#��=��w�'�	��c��k�#5�t�<�<rUc�@�	t|�\}}tdd|z|��)Nr�zinvalid proxy for %sr�)r�rfr	rPr�rOs      rTr�zURLopener.open_unknown_proxy	s(��=��w�'�	��c��k�#9�D�#@�%�H�HrUc�.�	tt|��}|jr||jvr|j|St|�\}}|�R|r|dk(rK	|j	|�}|j�}|j
�tt|�d�|fS|j||�}	|j�}	|r
t|d�}
n�t|�\}}t|xsd�\}}t|xsd�\}}t|xsd�\}}tjj|�d}
t!j"|
�\}}|j$j'|�tj(|d�}
	||	f}|j�||j|<d}d}d}d}d|	vrt+|	d	�}|r
||||�|j-|�x}rD|t/|�z
}|
j1|�|dz
}|r
||||�|j-|�x}r�D|
j
�	|j
�|dk\r||krt3d
||fz|��|S#t$rY���wxYw#|
j
�wxYw#|j
�wxYw)NrYr`rZr�r\r]rr^r_ra)r	rr�rrrdr�r5r
r~rNrrrerf�splitextrh�mkstempr�rl�fdopenrmrnrorpr)r�rOrqrrrPr��url1rtr�rurv�garbagerf�suffix�fdrwrxryrnrzr{s                     rT�retrievezURLopener.retrieves���	;��Y�s�^�$���>�>�c�T�^�^�3��>�>�#�&�&���_�
��d���T�T�V�^�
��)�)�$�/���w�w�y�����
�#�J�t�$4�Q�$7�8�$�>�>��Y�Y�s�D�
!��"	��g�g�i�G���8�T�*�� *�3��
��� *�4�:�2� 6�
��� +�D�J�B� 7�
��g� *�4�:�2� 6�
��g����)�)�$�/��2��!)�!1�!1�&�!9���X�� � �'�'��1��i�i��D�)��
�!�7�*���>�>�-�*0�D�N�N�3�'���������#�w�.��w�'7�8�9�D���x��T�2�!�w�w�r�{�*�e�*��C��J�&�D��I�I�e�$���M�H�!�"�8�R��6� "�w�w�r�{�*�e�*��	�	���H�H�J��1�9����&�C���,�� &�(�
(��
��[�
��
��F�	�	����H�H�J�s9�A	I�4CJ�BI-�J�	I*�)I*�-I?�?J�Jc���	d}d}t|t�r,t|�\}}|rt|�\}}t	|�}|}nq|\}}t|�\}}t|�\}	}
|
}d}|	j
�dk7rd}n6t|
�\}}
|rt|�\}}|r	|	�d|�|
��}t|�r|}|stdd��|r>t	|�}tj|j��jd�}nd}|r>t	|�}tj|j��jd�}nd}||�}
i}|rd|z|d<|rd|z|d<|r||d	<d
|d<|jD]
\}}|||<�|�d|d
<|
jd|||�n|
jd||��	|
j�}d|j(cxkrdkr(nn%t+||j,d|z|j(�S|j/||j0|j(|j2|j,|�S#t j"j$$rt'd��wxYw)Nrz://z
http errorr=rzzBasic %sr.r�r�r�rGr>zContent-Typer�r�rHz$http protocol error: bad status liner2r3�http:)rrr
rrrr�r}r~r~rr�r�r�r�rNrr�
BadStatusLiner�statusrr5�
http_errorrtrP)r��connection_factoryrOrP�user_passwd�proxy_passwdr�r��realhostr�r��
proxy_authr��	http_connrur�r�r�s                  rT�_open_generic_httpzURLopener._open_generic_httpMs���
	������c�3��'��_�N�D�(��$.�t�$4�!��T��t�}���H� �N�D�(�!+�D�!1��L�$�&�x�0�M�G�T��C��K��}�}��&�(���!+�D�!1���$��,6�x�,@�)�K���.5�x��F�H���)�#�D��7�<��A�A��"�<�0�L��)�)�,�*=�*=�*?�@�G�G��P�J��J��!�+�.�K��#�#�K�$6�$6�$8�9�@�@��I�D��D�&�t�,�	����-7�*�-D�G�)�*��(2�T�(9�G�O�$��&�G�F�O�
!(����!�_�_�M�F�E�#�G�F�O�-���&I�G�N�#����f�h��g�>����e�X�w��?�	C� �,�,�.�H��(�/�/�'�C�'��h����g��m�&�o�o�/�
/��?�?��X�[�[�������(�,�,��F�
F���{�{�(�(�	C��A�B�B�	C�s�9I�)I-c�Z�	|jtjj||�SrW)rrrr3�r�rOrPs   rT�	open_httpzURLopener.open_http�s$�� ��&�&�t�{�{�'A�'A�3��M�MrUc��	d|z}t||�r,t||�}|�
||||||�}	n
|||||||�}	|	r|	S|j|||||�S)Nz
http_error_%d)r�r�r)
r�rOrt�errcode�errmsgrurPrjr�rws
          rTrzURLopener.http_error�su��	E�
��(���4����T�4�(�F��|���R��&�'�B����R��&�'�4�H���f�}��&�&�s�B����I�IrUc�B�	|j�t||||d��rW)r�r�r�rOrtrrrus      rTrzURLopener.http_error_default�s!��L�
���
���W�f�g�t�<�<rUc�r�|js|jr}tjjj
}tjj
|�}|j|j|j�|j�
d|_nd}tjj	||��S)NTrA)	r�r�rrrr\r]�load_cert_chain�post_handshake_auth)r�r�r`r?s    rT�_https_connectionzURLopener._https_connection�s����}�}����#�{�{�:�:�D�D���+�+�;�;�L�I���'�'�����
�
�F��.�.�:�26�G�/����;�;�.�.�t�W�.�E�ErUc�>�	|j|j||�SrW)rrrs   rT�
open_httpszURLopener.open_https�s ��%��*�*�4�+A�+A�3��M�MrUc��	t|t�std��|dddk(r)|dddk7r!|ddj�dk7rt	d��|j|�S)	NzEfile error: proxy support for file protocol currently not implementedr;rdr�rO�z
localhost/r})rrrr�rErr�s  rT�	open_filezURLopener.open_file�se��=��#�s�#��b�c�c��r��7�d�?�s�1�Q�x�3��3�q��9�?�?�3D��3T��L�M�M��'�'��,�,rUc���	ddl}ddl}t|�\}}t|�}	t	j
|�}|j}	|jj|jd��}
|j|�d}|jd|xsd|	|
fz�}|s&|}
|dddk(rd|z}
t!t#|d	�||
�St%|�\}}|sht'j(|�t+�ft-�zvr=|}
|dddk(rd|z}
n|dd
dk(rt/d|z��t!t#|d	�||
�Std
��#t$r%}t|j|j��d}~wwxYw)NrTr�z6Content-Type: %s
Content-Length: %d
Last-modified: %s
r�r`rOr�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�r
r5rer�r~r�strerrorrqr�r�r�r�r�r�rrNrrr�r|�thishostrE)r�rOr�r�r�rY�	localnamer��eryr�r�ru�urlfiler�s               rTrzURLopener.open_local_file�s��������_�
��d� ��&�	�	3��G�G�I�&�E��}�}���;�;�)�)�%�.�.��)�F���$�$�S�)�!�,��+�%�+�+�G�
�
"�l�D�(�3�
4�5����G��B�Q�x�3��#�d�*���d�9�d�3�W�g�F�F���%�
��d���#�#�D�)�y�{�n�x�z�.I�J��G��B�Q�x�3��#�d�*���b�q��T�!� �!d�gj�!j�k�k��d�9�d�3�W�g�F�F��<�=�=��-�	3��1�:�:�q�z�z�2�2��	3�s�E�	E5� E0�0E5c�:�	t|t�std��ddl}t	|�\}}|std��t|�\}}t
|�\}}|rt|�\}}nd}t|�}t|xsd�}t|xsd�}tj|�}|sddl}|j}nt|�}t|�\}}	t|�}|jd�}
|
dd|
d}}
|
r
|
ds|
dd}
|
r
|
dsd|
d<|||dj!|
�f}t#|j$�t&kDrLt)|j$�D]4}
|
|k7s�	|j$|
}|j$|
=|j+��6	||j$vrt-|||||
�|j$|<|sd}nd	}|	D]9}t/|�\}}|j1�d
k(s�%|dvs�*|j3�}�;|j$|j5||�\}}|j7d|z�d}d}|r|d
|zz
}|�
|dk\r|d|zz
}t9j:|�}t=||d|z�S#t?�$r}td|���|�d}~wwxYw)NzCftp error: proxy support for ftp protocol currently not implementedrr�r�rOr]r`r�r�r�r�zftp:zContent-Type: %s
zContent-Length: %d
�ftp error: ) rrrr�r
rrrrrr�r�r�rmrr�r�ror��MAXFTPCACHEr�r�r�rr�r�r�r�r�r�r�	ftperrors)r�rOr�r�rfr�rmr�r�r�r�rYr�rGrHr�r�r�rtr�r�rur�s                       rT�open_ftpzURLopener.open_ftp�s�����#�s�#��`�a�a����_�
��d��8�$>�?�?���%�
��d���%�
��d���T� 2���v��f��t�}���t�z�r�"�����2�&���#�#�D�)�����?�?�D��t�9�D� ��&���e��t�}���z�z�#����#�2�Y��R��d����Q���Q�R�����Q��3��a���D�$������.���t�}�}���+��$�-�-�(����8��
�
�a�(�A��
�
�a�(��G�G�I�	)�
	9��$�-�-�'��t�V�T�4��>��
�
�c�"�����$���)�$�/���e��:�:�<�6�)��:�:� �;�;�=�D�	�
!�M�M�#�.�7�7��d�C�M�R���(�(��#��6�q�9�E��G���/�%�7�7���"�w�!�|��1�G�;�;���/�/��8�G��b�'�6�C�<�8�8���{�	9��[���.�/�S�8��	9�s&�AI9�)I9�.B
I9�9
J�J�Jc
�V�	t|t�std��	|jdd�\}}|sd}|j
d�}|dk\rd	||dvr||dzd}|d|}nd
}g}|jdtjdtjtj���z�|jd
|z�|dk(r4tj|jd��jd�}nt|�}|jdt!|�z�|jd
�|j|�dj#|�}t%j&|�}t)j*|�}t-|||�S#t$r
tdd��wxYw)NzEdata error: proxy support for data protocol currently not implementedrr`z
data errorzbad data URLr��;rrpr�zDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %sr~rzzlatin-1zContent-Length: %d�
)rrrr�rEr~�rfindrlr�strftime�gmtimer~r�r�r�rror�r�r�r��StringIOr)	r�rOrPr��semirPr5ru�fs	         rT�	open_datazURLopener.open_data7s�����#�s�#��b�c�c�	8��9�9�S�!�,�L�T�4��0�D��z�z�#����1�9��D���K�/��D��F�G�}�H����;�D��H����
�
�:�d�m�m�,G�,0�K�K��	�	��,D�F�F�	G��
�
�%��,�-��x���%�%�d�k�k�'�&:�;�B�B�9�M�D��4�=�D��
�
�'�#�d�)�3�4��
�
�2���
�
�4���i�i��n���+�+�C�0���K�K�����!�W�c�*�*��5�	8��,��7�7�	8�s�F�F(rWrc)r�r�r�r�r�r�r�r�r�r�r�rNr�r�rrrrrrFrrrrr*r4r�rUrTr9r9�s�����K� �;�.�G�!�4��#�%�"8�H=�
I�:�|ZF�xN�J� =�
�	F�	N�-�>�@89�t'+rUr9c��eZdZ	d�Zd�Zdd�Zd�Zdd�Zdd�Zdd�Z	dd	�Z
		dd
�Z		dd�Zdd�Z
dd
�Zdd�Zdd�Zdd�Zd�Zy)r:c�`�tj|g|��i|��i|_d|_d|_y)Nrr<)r9r��
auth_cache�tries�maxtries)r�r�r�s   rTr�zFancyURLopener.__init__ds/�����4�1�$�1�&�1������
���
rUc�&�	t||d|z|�S)Nr)rrs      rTrz!FancyURLopener.http_error_defaultjs��A��"�g�w��}�g�>�>rUNc�@�	|xjdz
c_	|jrQ|j|jk\r8t|d�r
|j}n|j}|||dd|�d|_S|j||||||�}|d|_S#d|_wxYw)Nr`�http_error_500r(z)Internal Server Error: Redirect Recursionr)r8r9r�r<r�redirect_internal)	r�rOrtrrrurPr�rws	         rTr^zFancyURLopener.http_error_302ns���3��
�
�a��
�
	��}�}����t�}�}�!<��4�!1�2��.�.�D��2�2�D��C��S�G�#�%��D�J�	�+�+�C��W�f�,3�T�;�F���D�J���D�J�s�AB�5B�	Bc��d|vr|d}nd|vr|d}ny|j�t|jdz|z|�}t|�}|jdvrt|||d|zz||��|j
|�S)NrKrLryrMz( Redirection to url '%s' is not allowed.)r�rr�rrTrrN)	r�rOrtrrrurPrDr[s	         rTr=z FancyURLopener.redirect_internal�s����� ��Z�(�F�
�g�
��U�^�F��
���
�����S��3�.��7���F�#���?�?�">�>��F�G�"�F��O�P�#�R�)�
)�
�y�y�� � rUc�0�	|j||||||�SrW�r^�r�rOrtrrrurPs       rTr_zFancyURLopener.http_error_301�s ��8��"�"�3��G�V�W�d�K�KrUc�0�	|j||||||�SrWr@rAs       rTr`zFancyURLopener.http_error_303�s ��I��"�"�3��G�V�W�d�K�KrUc�^�	|�|j||||||�S|j|||||�SrW)r^rrAs       rTrazFancyURLopener.http_error_307��>��?��<��&�&�s�B����$�O�O��*�*�3��G�V�W�M�MrUc�^�	|�|j||||||�S|j|||||�SrW)r_rrAs       rTrbzFancyURLopener.http_error_308�rDrUc���	d|vrtj||||||�|d}tjd|�}	|	stj||||||�|	j	�\}
}|
j�dk7rtj||||||�|stj||||||�d|jzdz}|�t||�||�St||�|||�S)Nr��![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"r��retry_�_basic_auth�r9rr��matchr�r�r�r��
r�rOrtrrrurPr,�stuffrKrTr�rjs
             rTr�zFancyURLopener.http_error_401�s��	=��W�,��(�(��s�B�)0�&�'�
C��*�+�����?��G����(�(��s�B�)0�&�'�
C�����
����<�<�>�W�$��(�(��s�B�)0�&�'�
C���(�(��s�B����
��$�)�)�#�m�3���<�%�7�4��%�c�5�1�1�%�7�4��%�c�5�$�7�7rUc���	d|vrtj||||||�|d}tjd|�}	|	stj||||||�|	j	�\}
}|
j�dk7rtj||||||�|stj||||||�d|jzdz}|�t||�||�St||�|||�S)Nr�rGr��retry_proxy_rIrJrLs
             rTr�zFancyURLopener.http_error_407�s��	=��w�.��(�(��s�B�)0�&�'�
C��,�-�����?��G����(�(��s�B�)0�&�'�
C�����
����<�<�>�W�$��(�(��s�B�)0�&�'�
C���(�(��s�B����
���	�	�)�M�9���<�%�7�4��%�c�5�1�1�%�7�4��%�c�5�$�7�7rUc��t|�\}}d|z|z}|jd}t|�\}}	t|	�\}	}
|	jd�dz}|	|d}	|j	|	||�\}}
|s|
syt|d���dt|
d���d|	��}	d|	z|
z|jd<|�|j
|�S|j
||�S)N�http://rrer`r�r�ry�r
rvrr��get_user_passwdr
rN�r�rOr�rPr�r�rDrfr�r��
proxyselectorr�rmr�s              rT�retry_proxy_http_basic_authz*FancyURLopener.retry_proxy_http_basic_auth�s���#�C����h��T�!�H�,�����V�$��'��.����#-�i�#8� �	�=��N�N�3��!�#���a�b�M�	��+�+�I�u�a�@���f����"'��2�"6�"'��R�"8�)�E�	�(�9�4�}�D����V���<��9�9�V�$�$��9�9�V�T�*�*rUc��t|�\}}d|z|z}|jd}t|�\}}	t|	�\}	}
|	jd�dz}|	|d}	|j	|	||�\}}
|s|
syt|d���dt|
d���d|	��}	d|	z|
z|jd<|�|j
|�S|j
||�S)N�https://r�rer`r�r�ryrRrTs              rT�retry_proxy_https_basic_authz+FancyURLopener.retry_proxy_https_basic_auth�s���#�C����h��d�"�X�-�����W�%��'��.����#-�i�#8� �	�=��N�N�3��!�#���a�b�M�	��+�+�I�u�a�@���f����"'��2�"6�"'��R�"8�)�E�	� *�Y� 6�� F����W���<��9�9�V�$�$��9�9�V�T�*�*rUc� �t|�\}}|jd�dz}||d}|j|||�\}}|s|syt|d���dt|d���d|��}d|z|z}	|�|j	|	�S|j	|	|�S)Nrer`r�r�ryrQ�r
r�rSr
rN�
r�rOr�rPr�r�r�rmr�rDs
          rTr�z$FancyURLopener.retry_http_basic_auth	s���#�C����h��I�I�c�N�Q����A�B�x���+�+�D�%��;���f����"�4�b�1�"�6��3�T�;���T�!�H�,���<��9�9�V�$�$��9�9�V�T�*�*rUc� �t|�\}}|jd�dz}||d}|j|||�\}}|s|syt|d���dt|d���d|��}d|z|z}	|�|j	|	�S|j	|	|�S)Nrer`r�r�ryrXr[r\s
          rT�retry_https_basic_authz%FancyURLopener.retry_https_basic_auth	s���#�C����h��I�I�c�N�Q����A�B�x���+�+�D�%��;���f����"�4�b�1�"�6��3�T�;���d�"�X�-���<��9�9�V�$�$��9�9�V�T�*�*rUc���|dz|j�z}||jvr|r|j|=n|j|S|j||�\}}|s|r||f|j|<||fS)Nre)r�r7�prompt_user_passwd)r�r�r�r�r�rmr�s       rTrSzFancyURLopener.get_user_passwd$	sv���c�k�D�J�J�L�(���$�/�/�!���O�O�C�(����s�+�+��.�.�t�U�;���f��6�4��.�4�?�?�3�/��V�|�rUc	��	ddl}	td|�d|�d��}|jd|�d|�d|�d��}||fS#t$r
t�YywxYw)NrzEnter username for z at z: zEnter password for z in r�)�getpass�input�KeyboardInterrupt�print)r�r�r�rbrmr�s      rTr`z!FancyURLopener.prompt_user_passwd/	sW��1��	��E�4�H�I�D��_�_��u�d�&$�%�F���<��� �	��G��	�s�08�A�
ArW)NF)r)r�r�r�r�rr^r=r_r`rarbr�r�rVrYr�r^rSr`r�rUrTr:r:asm��I��?��$!�8L�L�N�N�FJ��8�2FJ��8�2+�$+�$+�+�	�
rUr:c�F�	t�tjd�atS)Nr|)�
_localhostrr�r�rUrTr|r|?	s!��B����)�)�+�6�
��rUc��	t�:	ttjtj��d�atStS#tj
$r)ttjd�d�aYtSwxYw)Nr;r|)�	_thishostr�rr�r�r�r�rUrTr"r"G	sx��6���	G��f�5�5�f�6H�6H�6J�K�A�N�O�I���9������	G��f�5�5�k�B�1�E�F�I���	G�s�3A�4B�Bc�<�	t�ddl}|jatSr�)�
_ftperrorsr�r�)r�s rTr)r)R	s��;�����&�&�
��rUc�F�	t�tjd�atSr�)�
_noheadersr�r�r�rUrT�	noheadersrn[	s!��/����.�.�r�2�
��rUc�>�eZdZ			d	d�Zd�Zd�Zd�Zd�Zd�Zd�Z	y)
r�Nc���||_||_||_||_||_||_d|_||_	|j�y#|j��xYwr�)
rmr�r�r�r�rQ�refcount�	keepalive�initr�)r�rmr�r�r�r�rQr�s        rTr�zftpwrapper.__init__h	s[����	������	���	���	������
�#���	��I�I�K��	��J�J�L��s�A�Ac��ddl}d|_|j�|_|jj	|j
|j|j�|jj|j|j�dj|j�}|jj|�y)NrrO)r��busy�FTPrN�connectr�r�rQ�loginrmr�r�r��cwd)r�r��_targets   rTrszftpwrapper.initx	sw�����	��:�:�<�����������D�I�I�t�|�|�<������t�y�y�$�+�+�.��(�(�4�9�9�%�������W�rUc�8�ddl}|j�|dvrd}d}nd|z}d}	|jj|�d}|r&|s$	d|z}|jj
|�\}}|s�|jjd�|rY|jj�}			|jj|�	|jj|	�d|z}nd}|jj
|�\}}d|_t|jd
�|j�}
|xj dz
c_|j#�|
fS#|j$r/|j�|jj|�Y��TwxYw#|j$r+}t|�dddk7rtd	|���|�Yd}~��cd}~wwxYw#|j$r}td
|z�|�d}~wwxYw#|jj|	�wxYw)Nr)r&r�zTYPE Ar`zTYPE zRETR r��550r'z
ftp error: %rzLIST �LISTr�)r��endtransferrN�voidcmdr�rs�ntransfercmd�
error_permrr�pwdryrur�makefile�
file_closerqr�)r�rYr�r��cmd�isdirr�r�rPr��ftpobjs           rTr�zftpwrapper.retrfile�	s���������:��X�s�q�u��d�N�c�A�E�	"��H�H���S�!�����
G���n�� $��� 5� 5�c� :�
��g���H�H���X�&���h�h�l�l�n��&�M������T�*��H�H�L�L��%���n���� �H�H�1�1�#�6�M�D�'���	��d�m�m�D�1�4�?�?�C���
�
���
��
�
���� � ��G� � �	"��I�I�K��H�H���S�!�	"���$�$�
G��v�;�r��?�e�+�"�[���#9�:��F�,��
G��"�,�,�M�&���'?�@�f�L��M���H�H�L�L��%�sM�E�#F�&G�:F�F�G�( G�G�G9�%G4�4G9�9G<�<Hc��|jsyd|_	|jj�y#t�$rYywxYwr�)rurN�voidrespr)r�s rTr~zftpwrapper.endtransfer�	s<���y�y����	�	��H�H������{�	��	�s�1�
A�Ac�R�d|_|jdkr|j�yy)NFr)rrrq�
real_closer�s rTr�zftpwrapper.close�	s$������=�=�A���O�O��rUc��|j�|xjdzc_|jdkr|js|j�yyy)Nr`r)r~rqrrr�r�s rTr�zftpwrapper.file_close�	s@�������
�
���
��=�=�A��d�n�n��O�O��'5�rUc��|j�	|jj�y#t�$rYywxYwrW)r~rNr�r)r�s rTr�zftpwrapper.real_close�	s5������	��H�H�N�N����{�	��	�s�-�
=�=)NT)
r�r�r�r�rsr�r~r�r�r�r�rUrTr�r�e	s/��E�?C� �� �*!�X��
�rUr�c���	i}g}tjj�D]s}t|�dkDs�|ddk(s�|ddj	�dk(s�2tj|}|ddj	�}|j|||f�|s�o|||<�udtjvr|j
dd�|D])\}}}|dddk(s�|r|||<�|j
|d��+|S)	Nr�i����r����rf�REQUEST_METHODr�_proxy)re�environ�keysror�rlr�)rv�environmentrjr��
proxy_names     rT�getproxies_environmentr��	s�����G��K��
�
���!���t�9�q�=�T�"�X��_��b�c����1B�g�1M��J�J�t�$�E��c�r����*�J�����e�Z�8�9��&+��
�#�"��2�:�:�%����F�D�!�#.���e�Z����9�� ��&+��
�#����J��-�
$/��NrUc��	|�
t�}	|d}|dk(ry|j�}t|�\}}|j	d�D]k}|j�}|s�|j
d�}|j�}||k(s||k(ryd|z}|j|�s|j|�s�kyy#t$rYywxYw)N�noF�*Tr�.)r�rr�rr�r��lstripr�)r�rv�no_proxy�hostonlyr�rjs      rT�proxy_bypass_environmentr��	s������(�*����4�=���3����:�:�<�D���%�N�H�d����s�#���z�z�|����;�;�s�#�D��:�:�<�D��4��4�4�<����:�D�� � ��&�$�-�-��*=��$���)����s�B8�8	C�Cc��	ddlm}ddlm}m}t	|�\}}d�}d|vr|dryd}	t||��}|j
dd	�D]�}	|	s�tjd
|	�}
|
�|�}||
jd��}|
jd�}|�'d
|
jd�jd�dzz}nt|dd�}|dks|dkDr��d|z
}||z	||z	k(s��y|||	�s��yy#|$rY��wxYw)Nr��fnmatch)�AddressValueError�IPv4Addressc���|jd�}ttt|��}t	|�dk7r
|gd�zdd}|ddz|ddzz|dd	zz|d
zS)Nr�r;)rrrrr�r`r�r;r�r�)r�r�r�rmro)�ipAddrr�s  rT�ip2numz,_proxy_bypass_macosx_sysconf.<locals>.ip2num$
sm�����S�!���S��e�_�%���u�:��?��\�)�2�A�.�E��a��B��5��8�r�>�2�e�A�h�!�m�D�u�Q�x�O�OrUr��exclude_simpleT�
exceptionsr�z(\d+(?:\.\d+)*)(/\d+)?r`r;r�� F)r��	ipaddressr�r�rrmr�r�rK�group�count)
r��proxy_settingsr�r�r�r�r�r��hostIPr�rEr��masks
             rT�_proxy_bypass_macosx_sysconfr�
s1��
� �8���%�N�H�d�P��$���*�+��
�F�
��[��*�+�� �#�#�L�"�5���h��H�H�.��6���=�V�/��!�'�'�!�*�%�D��7�7�1�:�D��|��A�G�G�A�J�,�,�S�1�A�5�6���4���8�}���a�x�4�"�9����9�D��$��D�D�L�1��
�T�5�
!��/6�2��9�
��
�s�C<�<D�Dc��	ddlm}t|�\}}|jd�}|D])}|j�}|dk(rd|vs�y|||�s�)yy)Nrr�r,z<local>r�TF)r�rr�r�)r��overrider�r��proxy_overrider�s      rT�_proxy_bypass_winreg_overrider�S
sa��� ����G�D�!��^�^�C�(�N����z�z�|���9���$���
�T�4�
 ���rU�darwin)�_get_proxy_settings�_get_proxiesc�.�t�}t||�SrW)r�r�)r�r�s  rT�proxy_bypass_macosx_sysconfr�n
s��,�.��+�D�.�A�ArUc��	t�SrW)r�r�rUrT�getproxies_macosx_sysconfr�r
s��	�
�~�rUc�J�	t�}|rt||�St|�SrW)r�r�r��r�rvs  rTr}r}|
s,��	�)�*���+�D�'�:�:�.�t�4�4rUc�.�t�xs
t�SrW)r�r�r�rUrTr6r6�
s��%�'�F�+D�+F�FrUc���	i}	ddl}	|j|jd�}|j	|d�d}|r�t|j	|d�d�}d|vrd|vrdj
|�}|jd�D]F}|jdd�\}}tjd	|�s|d
vrd|z}n
|dk(rd
|z}|||<�H|jd�rJtjdd|d�}|jd�xs||d<|jd�xs||d<|j�|S#t$r|cYSwxYw#tttf$rY|SwxYw)Nr�;Software\Microsoft\Windows\CurrentVersion\Internet Settings�ProxyEnable�ProxyServerrpr,zhttp={0};https={0};ftp={0}r`z
(?:[^/:]+)://)rr�rNrQ�sockszsocks://z	^socks://z	socks4://rr�)�winreg�ImportError�OpenKey�HKEY_CURRENT_USER�QueryValueExrr�r�r�rKr�r��Closer~rEr�)rvr��internetSettings�proxyEnable�proxyServer�pr��addresss        rT�getproxies_registryr��
s���	�
��	��"	�%�~�~�f�.F�.F�N� P�� �-�-�.>�/<�>�>?�A�K��!�&�"5�"5�6F�7D�#F�FG�#I�J���k�)�c��.D�">�"E�"E�k�"R�K�$�*�*�3�/�A�()����Q��%�H�g��8�8�O�W�=�#�'?�?�&/�'�&9�G�%��0�&0�7�&:�G�(/�G�H�%�0��;�;�w�'� �f�f�\�;���@P�Q�G�&-�k�k�&�&9�&D�W�G�F�O�'.�{�{�7�';�'F�w�G�G�$��"�"�$����M�	��N�	��B��Y�/�	�
���	�s#�D;�D/E�;E	�E	�E$�#E$c�0�	t�xs
t�SrW)r�r�r�rUrTr6r6�
s��	�&�'�@�+>�+@�@rUc�
�	ddl}	|j|jd�}|j	|d�d}t|j	|d�d�}|r|syt||�S#t$rYywxYw#t$rYywxYw)NrFr�r��
ProxyOverride)r�r�r�r�r�rr~r�)r�r�r�r��
proxyOverrides     rT�proxy_bypass_registryr��
s���	��		�%�~�~�f�.F�.F�N� P�� �-�-�.>�/<�>�>?�A�K��� 3� 3�4D�5D�!F�FG�!I�J�M�
�-��,�T�=�A�A���	��	���	��	�s#�A'�AA6�'	A3�2A3�6	B�Bc�J�	t�}|rt||�St|�SrW)r�r�r�r�s  rTr}r}�
s,��	�)�*���+�D�'�:�:�(��.�.rUrcrW)}r~r�r�r�http.clientrr�rer�rrVrrrhrbrB�urllib.errorrrr�urllib.parserrrr	r
rrr
rrrrrrrrrr�urllib.responserrrGrFr��__all__�version_infor�rMrr1r2rkr7r8r��ASCIIr�r�rrr3rr0rrror r!r"r#r$r%r&�urandomrr'r(r)r1r*r�rrLrlrr/r�r�r+r�r,r-r.r(rj�
nturl2pathr5r4r�r9r:rgr|rir"rkr)rmrnr�r�r�r�r��platform�_scproxyr�r�r�r�r}r6r�r�r�rUrT�<module>r�s���C�f�
����	�	�	�
�
�
�����C�B�"�"�"�"�"�
5����I���$��(�(��!�,�,��
���F�$B�$B�M+��4�5�$�M+�^���:�x��r�z�z�(�B�H�H�-��� k"�k"�ZI+�I+�^"�H8�8�&#��#�";�k�;�n2�+�n2�b,�B)>�;�)>�V=*�=*�@G�o�G�3�#B�3�>k#�k#�^�3�[���4�k�� �z�z��O�O�d�K�)B��$
�[�*C�
�s�+�s�l3�%�3��4�;�;�)�*�8�*�8�$�N�N�>�"�#�+�#�$6�[�6�
�)*�V11�+�11�f�7,��7,�r3�j�3�j:�+�:�B���7�7�d�?�5�5�!�
���+�+�DX�Y�X�z�
��
�	���
���
��a�a�H#�J �J<�@�0�<�<�8��:�B��5�G��W�W��_�/�bA�B�(/�(�J�+�L��yS���I��s�9K�K�K

?>