� c��jN����dZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZmZmZddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z* ddl+Z+dZ,gd�Z.d e j^dd zZ0da1de jdfddddd �d �Z3d �Z4gZ5dgd�Z6d�Z7e jpde jr�Z:d�Z;Gd�d�Z<Gd�d�Z=d�Z>Gd�d�Z?Gd�de?�Z@Gd�de?�ZAGd�de?�ZBd�ZCGd �d!e?�ZDGd"�d#�ZEGd$�d%eE�ZFGd&�d'eF�ZGGd(�d)�ZHGd*�d+eHe?�ZIGd,�d-eHe?�ZJej�ZLGd.�d/�ZMGd0�d1e?eM�ZNGd2�d3e?eM�ZOGd4�d5e?�ZPGd6�d7eP�ZQeRej�d8�rGd9�d:eP�ZTe.j�d:�Gd;�de?�ZWd?�ZXd@�ZYGdA�dBe?�ZZdC�Z[GdD�dEe?�Z\GdF�dGe\�Z]GdH�dIe?�Z^dJZ_ej�dKk(r ddLlambZbmcZcndM�ZbdN�ZciZdGdO�dP�ZeGdQ�dRee�ZfdagdS�ZhdaidT�ZjdakdU�ZldamdV�ZnGdW�dX�ZodY�ZpdhdZ�Zqd[�Zrd\�Zse j�d]k(rdd^lumvZvmwZwd_�Zxd`�Zyda�Zzdb�Z{yej�dKk(r dc�Z|dd�Z{de�Z}df�ZzyepZ{eqZzy#e-$rdZ,Y��[wxYw)ia� 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, 307, and 308 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 OSError); 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('https://www.python.org/') �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��ts td��t j t jj||��}|jdg�t|� �}t|�} n3|rt|� �}t|�} nt� t�xa } nt} | j|||�S) a�Open the URL url, which can be either a string or a Request object. *data* must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details. urllib.request module uses HTTP/1.1 and includes a "Connection:close" header in its HTTP requests. The optional *timeout* parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This only works for HTTP, HTTPS and FTP connections. If *context* is specified, it must be a ssl.SSLContext instance describing the various SSL options. See HTTPSConnection for more details. The optional *cafile* and *capath* parameters specify a set of trusted CA certificates for HTTPS requests. cafile should point to a single file containing a bundle of CA certificates, whereas capath should point to a directory of hashed certificate files. More information can be found in ssl.SSLContext.load_verify_locations(). The *cadefault* parameter is ignored. This function always returns an object which can work as a context manager and has the properties url, headers, and status. See urllib.response.addinfourl for more detail on these properties. For HTTP and HTTPS URLs, this function returns a http.client.HTTPResponse object slightly modified. In addition to the three new methods above, the msg attribute contains the same information as the reason attribute --- the reason phrase returned by the server --- instead of the response headers as it is specified in the documentation for HTTPResponse. For FTP, file, and data URLs and requests explicitly handled by legacy URLopener and FancyURLopener classes, this function returns a urllib.response.addinfourl object. Note that None may be returned if no handler handles the request (though the default installed global OpenerDirector uses UnknownHandler to ensure this never happens). In addition, if proxy settings are detected (for example, when a *_proxy environment variable like http_proxy is set), ProxyHandler is default installed and makes sure the requests are handled through the proxy. rNzJcafile, 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 �'/usr/lib64/python3.12/urllib/request.pyr1r1�s���h��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) 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. �fileN�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� 0� /� ��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+�8E3�0AE3�8BE'�:E3�'E0 �,E3�3E<c��tD]} tj|��tdd�=trdayy#t$rY�9wxYw)z0Clean up temporary files from urlretrieve calls.N)rkre�unlink�OSErrorrM)� temp_files rTr8r8sH��#� � � �I�I�i� �$� �q������� � � � �s�5� A�Az:\d+$c��|j}t|�d}|dk(r|jdd�}tj d|d�}|j �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)�requestrO�hosts rT� request_hostr�)sX�� � � �C� �C�=�� �D� �r�z��!�!�&�"�-�� � � �B��a� (�D� �:�:�<�rUc��eZdZdidddfd�Zed��Zej d��Zejd��Zed��Zej d��Zejd ��Zd �Z d �Z d �Z d �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)z3Return a string indicating the HTTP request method.�POST�GETr�)rP�getattr)r��default_methods rT� get_methodzRequest.get_methodzs!��#'�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�Z y) 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}|j d�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)r�r�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 �h�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)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. �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��eZdZdZdZd�ZeZy)r0zProcess HTTP error responses.i�c��|j|j|j�}}}d|cxkrdks"n|jj d|||||�}|S)N���,r)�code�msgrdr)r�)r�r�r�r3r4r�s rT� http_responsez HTTPErrorProcessor.http_responsepsT��"�-�-����x�}�}��4�c���t�!�c�!��{�{�(�(����4��d�<�H��rUN)r�r�r��__doc__r,r5�https_responser�rUrTr0r0ls��'��M� �#�NrUr0c��eZdZd�Zy)rc�4�t|j||||��rW)rr�)r�r rtr3r4r�s rTrz*HTTPDefaultErrorHandler.http_error_default~s���� � �d�C��r�:�:rUN)r�r�r�rr�rUrTrr}s��;rUrc�4�eZdZdZdZd�Zd�ZexZxZxZ Z dZ y)r�� c�Z�|j�}|dvr|dvs"|dvr|dk(st|j||||��|jdd�}d}|jj �D� � cic]\} } | j �|vr| | ��} } } t|| |jd� �Scc} } w) 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. )�-�.�/i3i4)r��HEAD)r>r?r@r�� z%20)r^z content-typeT)rur�r�) r�rr��replacerur�r�rr�) r�r rtr3r4ru�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}n d|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 rtr3r4rurD�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�f�t|�\}}|jd�sd}|}ne|jd�std|z��d|vr$|jd�}|jd|�}n|jdd�}|dk(rd}|d|}t |�\}}|�t |�\}} ndx}} ||| |fS)a Return (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. rON�//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�}t|d�sJd��||_|j�D]4\}}|j �}t |d|z|||j fd���6y)N�keys�proxies must be a mappingz%s_openc��||||�SrWr�)�rrfr�r�s rT�z'ProxyHandler.__init__..s���Q��t�,rU)r6r��proxiesr�r��setattrr�)r�rxr�rOs rTr�zProxyHandler.__init__sk�� �?� �l�G��w��'�D�)D�D�'��� � ����I�D�#��:�:�<�D� �D�)�d�*�$'�d����-� .�)rUc���|j}t|�\}}}}|�|}|jrt|j�ry|rb|r`t |��dt |���} t j | 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�Zd d�Zd d�Zd�Zd�Z y) 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_with_scheme)�.0�u� default_portr�s ��rT� z/HTTPPasswordMgr.add_password..Js#����� L�GJ�!��,�,�Q� �=�s�s�)rrr��tuple)r��realmrLrmr�� reduced_urir�s` @rT� add_passwordzHTTPPasswordMgr.add_passwordCsi��� �c�3� ��%�C� �� � � #�!#�D�K�K�� �'�L�� L�GJ� L�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_with_scheme) r�r��authuri�domainsr��reduced_authuri�uris�authinforLs rT�find_user_passwordz"HTTPPasswordMgr.find_user_passwordNsm���+�+�/�/�%��,��'�L�"�:�:���'�O�")�-�-�/���h��C��2�2�3��H�'�� �#2�(�rUc���t|�}|dr|d}|d}|dxsd}nd}|}d}t|�\}}|r!|�|�ddd�j|�} | �d || fz}||fS) z@Accept authority or URI and extract only the authority and path.r`rr;rON�Pi�rz%s:%d)rrr�) r�rLr��partsrTrhrfr��port�dports rT� reduce_urizHTTPPasswordMgr.reduce_uriYs����� �� ��8��1�X�F��a��I���8�?�s�D��F��I��D�� �*� ��d� �D�L�V�-?��!���s�6�{� �� �#�t�U�m�3� ��$��rUc�d�t|�}|dr|dnd}|xsdg|j||���S�Nr`r)rr�)r�rLr�r�rTs rTr�z'HTTPPasswordMgr._reduce_uri_with_schemeps9���� ��"�1�X��q��4����$�D�����l�!C�D�DrUc�^�|d�|d� |d|dk7ry|j|dd|dd�S)NrFr`)� is_suburi)r��base�tests rTr�z&HTTPPasswordMgr._is_suburi_with_schemeusE�� ��G� �D��G�$7��Q��4��7�"���~�~�d�1�2�h��Q�R��1�1rUc�r�||k(ry|d|dk7ry|d}|dddk7r|dz }|dj|�S)zcCheck if test is below base in a URI tree Both args must be URIs in reduced form. TrFr`r]NrO)r�)r�r�r��prefixs rTr�zHTTPPasswordMgr.is_suburi{sV�� �4�<�� ��7�d�1�g� ���a��� �"�#�;�#� � �c�M�F��A�w�!�!�&�)�)rUN)T) r�r�r�r�r�r�r�r�r�r�r�rUrTr!r!>s&��� =� ��.E� 2� *rUr!c��eZdZd�Zy)r"c�p�tj|||�\}}|�||fStj|d|�SrW)r!r�)r�r�r�rmrns rTr�z2HTTPPasswordMgrWithDefaultRealm.find_user_password�sC��(�;�;�D�%�� !��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�0��i|_t�|� �yrW)� authenticated�superr�)r�� __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�sI�� �c�3� ��%�C�'�L���"�:�:�1�l�K� �2B��"�"�;�/��(rUc��dD]J}|j||�}|jD]'}|j||�s�|j|ccS�Lyr�)r�r�r�)r�r�r�r�rLs rTr�z-HTTPPasswordMgrWithPriorAuth.is_authenticated�sR��'�L�"�:�:���'�O��)�)���.�.�s�O�D��-�-�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�Z d�Z e Z 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 ��j d�z}|j |jd�|k(ry|j|j|�|jj||j��Sy)Nr{r~r|rS) r�r�r�r�r�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�|jj d|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�r1r2TF)r�r�r3r�r�)r�r r�s rTr5z&AbstractBasicAuthHandler.http_responses`�� �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�r5� 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 rtr3r4rurOr�s rT�http_error_401z#HTTPBasicAuthHandler.http_error_401's*���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 rtr3r4rurhr�s rT�http_error_407z$ProxyBasicAuthHandler.http_error_4072s-�� �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__Ls>�� �>�$�&�F��� � �K�K�4�4����� ������rUc��d|_yr�)r�r�s rT�reset_retry_countz+AbstractDigestAuthHandler.reset_retry_countUs ���� 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_reqedXs����+�+�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_authls����:�:�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}t j |�j�}|ddS)Nr{r|��)r��time�ctimer�� _randombytes�hashlib�sha1� hexdigest)r��nonce�s�b�digs rT� get_cnoncez$AbstractDigestAuthHandler.get_cnoncexsT��  �+�+�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�opaquer{r��,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�rr)r�r rr�r rrr�H�KDrmr��entdig�A1�A2�respdig�ncvalue�cnonce�noncebitr�s rTr�z+AbstractDigestAuthHandler.get_authorization�s�� ���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�Nr|)r �md5r�r ��xs rTrwz?AbstractDigestAuthHandler.get_algorithm_impls..�s��'�+�+�a�h�h�w�&7�8�B�B�DrU�SHAc�f�tj|jd��j�Sr%)r r r�r r's rTrwz?AbstractDigestAuthHandler.get_algorithm_impls..�s��'�,�,�q�x�x��'8�9�C�C�ErUz.Unsupported digest authentication algorithm %rc����|�d|���S)Nr{r�)r �drs �rTrwz?AbstractDigestAuthHandler.get_algorithm_impls..�s���!�q�!�,�-rU)rE)r�rrrs @rTrz-AbstractDigestAuthHandler.get_algorithm_impls�sG��� �� �D�A� �%� �E�A��,�.7�8�9� 9� -���"�u� rUc��yrWr�)r�rPrs rTrz+AbstractDigestAuthHandler.get_entity_digest�s��rUrW) r�r�r�r�r�r�r�rr�rrr�rUrTr'r'As,����I�( � �<�| �rUr'c��eZdZdZdZdZd�Zy)r(z�An authentication protocol defined by RFC 2069 Digest authentication improves on basic authentication because it does not transmit passwords in the clear. r���c�~�t|j�d}|jd|||�}|j�|S)Nr`r�)rr�r�r��r�r rtr3r4rur��retrys rTr�z$HTTPDigestAuthHandler.http_error_401�s@���� � �%�a�(���*�*�+=�+/��g�?�� ��� �� rUN)r�r�r�r6r�r,r�r�rUrTr(r(�s��� "�K��M�rUr(c��eZdZdZdZd�Zy)r)�Proxy-Authorizationr/c�f�|j}|jd|||�}|j�|Sr�)r�r�r�r1s 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�r:s rTr�zAbstractHTTPHandler.__init__�s&��)3�)?�:���T�[�[�E_�E_�Ej�Ej��rUc��||_yrW)r;)r��levels rT�set_http_debuglevelz'AbstractHTTPHandler.set_http_debuglevel�s �� ��rUc��tjjj|j|j ��SrW)rrr9�_get_content_lengthrPr��r�r�s rTr@z'AbstractHTTPHandler._get_content_length�s2���{�{�)�)�=�=� �L�L� � � � �"� "rUc��|j}|s td��|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�rPr4�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}|s td��||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) z�Return an HTTPResponse object for the request, using http_class. http_class must implement the HTTPConnection API from http.client. rCrQr�� Connectionr4�rurE)�encode_chunkedN)r�rrQ�set_debuglevelr;rr��updaterur��titler�� set_tunnelr�r�r�rPr�r~� getresponser��sockr�rO�reasonr4)r�� http_classr �http_conn_argsr�r%rurGrHrjr��tunnel_headers�proxy_auth_hdr�errrvs rTr�zAbstractHTTPHandler.do_open$s��� �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 �8G�AG �G(� G%� G � G%�%G(�(G;rW)r�r�r�r�r>r@rKr�r�rUrTr7r7�s��k�!�"� $�L@rUr7c�*�eZdZd�Zej Zy)r*c�V�|jtjj|�SrW)r�rrr9�r�r s rT� http_openzHTTPHandler.http_openis���|�|�D�K�K�6�6��<��|jj||�|SrW)rm�extract_cookies)r�r�r�s rTr5z!HTTPCookieProcessor.http_response�s�� ���&�&�x��9��rUrW)r�r�r�r�r�r5r�r7r�rUrTrr�s��#� ��!�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�v�i}|D]1}|jdd�\}}|ddk(r |ddk(r|dd}|||<�3|S)z>Parse list of key=value strings where keys are not duplicated.�=r`rr�r])r�)�l�parsed�eltrGrHs rTr�r��sU�� �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)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. r�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�vr td��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 � C c�D�ddl}ddl}|j}|j}t |�} t j |�}|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 rTr�zFileHandler.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�r�r�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}|s td��t |�\}}|� |j }n t |�}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_PORTrmrrr rr�r~rr�r�r��map� connect_ftprQrr��upper�retrfiler�r�r�r�r� all_errors)r�r r�r�r�r�rmr�r4rf�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/�B G/� G,� G'�'G,�/H�> H � Hc �&�t||||||d��S)NF)� persistent)� ftpwrapper)r�rmr�r�r�r�rQs rTr�zFTPHandler.connect_ftp>s���$���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__Es%���� ��� ��� ��� ���rUc��||_yrW)r�)r��ts rT� setTimeoutzCacheFTPHandler.setTimeoutLs ���� rUc��||_yrW)r�)r�rEs rT� setMaxConnszCacheFTPHandler.setMaxConnsOs ����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_ftpRs����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_cache]s �� �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_cacheqsB���J�J�%�%�'�D� �J�J�L�(� � � ���� � � ���rUN) r�r�r�r�r�r�r�r�r�r�rUrTr-r-Bs ����� �<�(rUr-c��eZdZd�Zy)r.c��|j}|jdd�\}}|jdd�\}}tjd|�r t d��t |�}|j d�rtj|�}|dd}|sd}tjd |t|�fz�}ttj|�||�S) Nr{r`rz[\x00-\x1F\x7F]z1Control characters not allowed in data: mediatypez;base64i�����text/plain;charset=US-ASCIIz$Content-type: %s Content-length: %d )r�r�r��searchrEr�endswithr�� decodebytesr�r�ror�io�BytesIO)r�r rOrTrP� mediatyperus rT� data_openzDataHandler.data_openxs����l�l���y�y��Q�'� ����*�*�S��+�� �4� �9�9�'�� 3��C�E� E� ��%�� � � �i� (��%�%�d�+�D�!�#�2��I��5�I��+�+�,T� ��D� � "�-#�$���"�*�*�T�*�G�S�9�9rUN)r�r�r�r�r�rUrTr.r.ws�� :rUr.r<�nt)r5r4c��|dddk(r|dd}n |dddk(r|dd}tj�}tj�}t|||��S) zOS-specific conversion from a relative URL of the 'file' scheme to a file system path; not recommended for general use.Nr�z///r;� z //localhost/� �rP�errors)r�getfilesystemencoding�getfilesystemencodeerrorsr ��pathnamerPr�s rTr5r5�sc�� �B�Q�<�5� � ���|�H� �c�r�]�n� ,����}�H��,�,�.���.�.�0���x�(�6�B�BrUc��|dddk(rd|z}tj�}tj�}t|||��S)zOS-specific conversion from a file system path to a relative URL of the 'file' scheme; not recommended for general use.Nr;rdr�)rr�r�r r�s rTr4r4�sH�� �B�Q�<�4� ��h��H��,�,�.���.�.�0���X���@�@rUc��eZdZdZdZdezZdd�Zd�Zd�Z d�Z d�Z dd �Z dd �Z dd �Zdd �Zd �Zdd�Zdd�Zd�Zerd�Zdd�Zd�Zd�Zd�Zdd�Zy)r9a,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).Nr�c ��dd|jjiz}tj|td��|� t �}t |d�sJd��||_|jd�|_ |jd�|_ d |jfd g|_ g|_ tj|_d|_t$|_y) NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methods�classr�)� stacklevelrsrt�key_file� cert_filez User-Agent)�Acceptz*/*)r�r�rBrCrDr6r�rxr�r�r��versionr��_URLopener__tempfilesrer}�_URLopener__unlink� tempcache�ftpcache)r�rx�x509r4s rTr�zURLopener.__init__�s���4�7>����@W�@W�6X�Y��� � �c�-�!�<� �?� �l�G��w��'�D�)D�D�'��� �����,�� ����+�.���(�$�,�,�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|�y)zdAdd a header to be used by the HTTP interface only e.g. u.addheader('Accept', 'sound/basic')N)r�rl)r�r�s rT� addheaderzURLopener.addheader�s�� �����t�$rUc���tt|��}t|d��}|jr9||jvr+|j|\}}t |d�}t |||�St |�\}}|sd}||jvr0|j|}t |�\}} t| �\} } | |f}nd}d|z} ||_ | jdd�} t|| �r| d k(r'|r|j|||�S|j||�S |�t|| �|�St|| �||�S#tt f$r�t"$r} t#d | �| �d} ~ wwxYw) z6Use URLopener().open(file) instead of open(file, 'r').z%/:=&?~#+!$,;'@()*[]|�rQr�rYN�open_�-r�r�z socket error)r rr r�rNrr rxr r�rCr��open_unknown_proxy� open_unknownr�rrr~)r�rrPrqrurt�urltyperOrf� proxyhostr�r�rjr4s rTrNzURLopener.opensz����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�D7�$D7�7E!� E�E!c�8�t|�\}}tdd|��)�/Overridable interface to open unknown URL type.� url errorzunknown url type�r r~)r�rrPr�rOs rTrzURLopener.open_unknown%s ���w�'� ��c��k�#5�t�<��t|�\}}tdd|z|��)rrzinvalid proxy for %sr)r�rfrrPr�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) ztretrieve(url) returns (filename, headers) for a local object or (tempfilename, headers) for a remote object.rYr`rZr�r\r]rr^r_ra)r rr�r r�rdr�r5r r~rNrrrerf�splitextrh�mkstempr�rl�fdopenrmrnrorpr)r�rOrqrrrPr��url1rtr�rurv�garbagerf�suffix�fdrwrxryrnrzr{s rT�retrievezURLopener.retrieve0s����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�3CJ�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)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. Nrz://z http errorrCr|zBasic %sr4r�r�r�rMrDz Content-Typer�r�rNz$http protocol error: bad status liner1r2�http:)rrr rr r r�rr~r�r�r�r�r�r�rTrr� BadStatusLiner�statusrr4� http_errorrtrV)r��connection_factoryrOrP� user_passwd� proxy_passwdr�r��realhostrr�� proxy_authr�� http_connrur�r�r�s rT�_open_generic_httpzURLopener._open_generic_httpns���� �� � �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 �8I�)I,c�X�|jtjj||�S)zUse HTTP protocol.)rrrr9�r�rOrPs rT� open_httpzURLopener.open_http�s!���&�&�t�{�{�'A�'A�3��M�MrUc��d|z}t||�r,t||�}|� ||||||�} n |||||||�} | r| S|j|||||�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_%d)r�r�r) r�rOrt�errcode�errmsgrurPrjr�rws rTrzURLopener.http_error�so�� ��(�� �4�� ��T�4�(�F��|���R��&�'�B����R��&�'�4�H���f�}��&�&�s�B����I�IrUc�@�|j�t||||d��)z>Default error handler: close the connection and raise OSError.N)r�r�r�rOrtr!r"rus rTrzURLopener.http_error_default�s�� ��� ���W�f�g�t�<��?�?���%� ��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&�AI8�(I8�-B I8�8 J�J�Jc �T�t|t�s td�� |jdd�\}}|sd}|j d�}|dk\rd ||d vr||dzd }|d |}nd }g}|jd tjd tjtj���z�|jd|z�|dk(r4tj|jd��jd�}n t|�}|jdt!|�z�|jd �|j|�dj#|�}t%j&|�}t)j*|�}t-|||�S#t$r t dd��wxYw)zUse "data" URL.zEdata error: proxy support for data protocol currently not implementedrr`z data errorz bad data URLr��;rrvNr�zDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %sr�r|zlatin-1zContent-Length: %d� )rrrr�rEr~�rfindrlr�strftime�gmtimer�r�r�r�r ror�r�r�r��StringIOr) r�rOrPr��semirPr4ru�fs rT� open_datazURLopener.open_dataXs����#�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'rWri)r�r�r�r6r�r�r�r�r�r�r�r�rNrr�rrrrrrFr(r*r,r�r7rAr�rUrTr9r9�s�����K� �;�.�G�!�4�� #�%� "8�H=� I� :�|ZF�xN�J� =� � F� N�-�>�@89�t'+rUr9c��eZdZdZd�Zd�Zdd�Zd�Zdd�Zdd�Z dd �Z dd �Z dd �Z dd �Z dd �Zdd�Zdd�Zdd�Zdd�Zd�Zy)r:z?Derived class with handlers for errors we can handle (perhaps).c�`�tj|g|��i|��i|_d|_d|_y)Nrr<)r9r�� auth_cache�tries�maxtries)r�r��kwargss rTr�zFancyURLopener.__init__�s/�����4�1�$�1�&�1������ ��� rUc�$�t||d|z|�S)z3Default error handling -- don't raise an exception.r)rr$s rTrz!FancyURLopener.http_error_default�s���"�g�w��}�g�>�>rUNc�>�|xjdz c_ |jrQ|j|jk\r8t|d�r |j}n |j}|||dd|�d|_S|j ||||||�}|d|_S#d|_wxYw)z%Error 302 -- relocated (temporarily).r`�http_error_500r'z)Internal Server Error: Redirect Recursionr)rErFr�rJr�redirect_internal) r�rOrtr!r"rurPr�rws rTr^zFancyURLopener.http_error_302�s��� � � �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�4B� Bc��d|vr|d}n d|vr|d}ny|j�t|jdz|z|�}t|�}|jdvrt |||d|zz||��|j |�S)NrKrLr{rMz( Redirection to url '%s' is not allowed.)r�rr�rrTrrN) r�rOrtr!r"rurPrDr[s rTrKz FancyURLopener.redirect_internal�s��� �� ��Z�(�F� �g� ��U�^�F� � ��� �����S��3�.��7���F�#�� �?�?�">� >��F�G�"�F��O�P�#�R�)� )� �y�y�� � rUc�.�|j||||||�S)z*Error 301 -- also relocated (permanently).�r^�r�rOrtr!r"rurPs rTr_zFancyURLopener.http_error_301�����"�"�3��G�V�W�d�K�KrUc�.�|j||||||�S)z;Error 303 -- also relocated (essentially identical to 302).rNrOs rTr`zFancyURLopener.http_error_303�rPrUc�\�|�|j||||||�S|j|||||�S)z1Error 307 -- relocated, but turn POST into error.)r^rrOs rTrazFancyURLopener.http_error_307��;�� �<��&�&�s�B����$�O� O��*�*�3��G�V�W�M� MrUc�\�|�|j||||||�S|j|||||�S)z1Error 308 -- relocated, but turn POST into error.)r_rrOs rTrbzFancyURLopener.http_error_308�rSrUc���d|vrtj||||||�|d}tjd|�} | stj||||||�| j �\} } | j �dk7rtj||||||�|stj||||||�d|j zdz} |�t|| �|| �St|| �|| |�S)z_Error 401 -- authentication required. This function supports Basic authentication only.r��![ ]*([^ ]+)[ ]+realm="([^"]*)"r��retry_� _basic_auth�r9rr��matchr�r�r�r�� r�rOrtr!r"rurPr2�stuffrZrTr�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)zeError 407 -- proxy authentication required. This function supports Basic authentication only.r�rVr�� retry_proxy_rXrYr[s 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�r{�r rxr r��get_user_passwdr rN�r�rOr�rPr�r�rDrfrr� 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�r{rarcs 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�r{r`�r r�rbr 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�r{rgrjrks rT�retry_https_basic_authz%FancyURLopener.retry_https_basic_auth7 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�rD�prompt_user_passwd)r�r�r�r�r�rmr�s rTrbzFancyURLopener.get_user_passwdE 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) z#Override this in a GUI environment!rNzEnter username for z at z: zEnter password for z in r�)�getpass�input�KeyboardInterrupt�print)r�r�r�rqrmr�s rTroz!FancyURLopener.prompt_user_passwdP sT��� ��E�4�H�I�D��_�_��u�d�&$�%�F���<� �� � � �G�� �s�07�A � A rW)NF)r)r�r�r�r6r�rr^rKr_r`rarbr�r�rerhr�rmrbror�rUrTr:r:�sm��I�� ?��$!�8L�L�N�N�FJ��8�2FJ��8�2+�$+�$ +� +� � rUr:c�D�t�tjd�atS)z8Return the IP address of the magic hostname 'localhost'.r�)� _localhostrr�r�rUrTr�r�` s �����)�)�+�6� � �rUc� �t�: ttjtj��d�atStS#tj $r)ttjd�d�aYtSwxYw)z,Return the IP addresses of the current host.r;r�)� _thishostr�rr�r�r�r�rUrTr/r/h sw���� 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}|jatS)z1Return the set of errors raised by the FTP class.Nr)� _ftperrorsr�r�)r�s rTr6r6s s������&�&� � �rUc�D�t�tjd�atS)z%Return an empty email Message object.r�)� _noheadersr�r�r�rUrT� noheadersr}| s �����.�.�r�2� � �rUc�@�eZdZdZ d d�Zd�Zd�Zd�Zd�Zd�Z d �Z y) r�z;Class used by open_ftp() for cache of open FTP connections.Nc���||_||_||_||_||_||_d|_||_ |j�y#|j��xYwr�) rmr�r�r�r�rQ�refcount� keepalive�initr�)r�rmr�r�r�r�rQr�s rTr�zftpwrapper.__init__� 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 rTr�zftpwrapper.init� 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��550r4z ftp error: %rzLIST �LISTr�)r�� endtransferrN�voidcmdr�r�� ntransfercmd� error_permrr�pwdr�r�r�makefile� file_closer�r�) r�rYr�r��cmd�isdirr�r�rVr��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�)r�rN�voidrespr6r�s rTr�zftpwrapper.endtransfer� s<���y�y� ��� � � �H�H� � � ���{� � � �s�1� A�Ac�R�d|_|jdkr|j�yy)NFr)r�r�� real_closer�s rTr�zftpwrapper.close� s$����� �=�=�A� � �O�O� � rUc��|j�|xjdzc_|jdkr|js|j�yyyr�)r�r�r�r�r�s rTr�zftpwrapper.file_close� s@�� ���� � � ��� � �=�=�A� �d�n�n� �O�O� �'5� rUc��|j� |jj�y#t�$rYywxYwrW)r�rNr�r6r�s rTr�zftpwrapper.real_close� s5�� ���� � �H�H�N�N� ���{� � � �s �-� =�=)NT) r�r�r�r6r�r�r�r�r�r�r�r�rUrTr�r�� 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])\}}}|ddd k(s�|r|||<�|j |d��+|S) aReturn a dictionary of scheme -> proxy server URL mappings. Scan the environment for variables named _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. r�i����r������Nrf�REQUEST_METHODr�_proxy)re�environrsror�rlr�)rx� 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)z�Test if proxies should not be used for a particular host. Checks the proxy dict for the value of no_proxy, which should be a list of comma separated DNS suffixes, or '*' for all hosts. �noF�*Tr�.)r�rr�rr�r��lstripr�)r�rx�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�B7�7 C�Cc� �ddlm}ddlm}m}t |�\}}d�}d|vr|dryd} t ||��}|j d d �D]�} | s�tjd | �} | �|�}|| jd ��} | jd �} | �'d| jd �jd�d zz} nt | d d�} | dks| dkDr��d| z } || z | | z k(s��y||| �s��yy#|$rY��wxYw)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��fnmatch)�AddressValueError� IPv4Addressc���|jd�}ttt|��}t |�dk7r |gd�zdd}|ddz|ddzz|dd zz|d zS) Nr�r;)rrrrr�r`rr;rr�)r�r�r�rmro)�ipAddrr�s rT�ip2numz,_proxy_bypass_macosx_sysconf..ip2numE 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_simpleTN� exceptionsr�z(\d+(?:\.\d+)*)(/\d+)?r`r;r� F) r�� ipaddressr�r�rrmr�r�rZ�group�count) r��proxy_settingsr�r�r�r�r�r��hostIPr�rEr��masks rT�_proxy_bypass_macosx_sysconfr�4 s,�� �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)a Return True if the host should bypass the proxy server. The proxy override list is obtained from the Windows Internet settings proxy override registry value. An example of a proxy override value is: "www.example.com;*.example.net; 192.168.0.1" rr�r9zr�TF)r�rr�r�)r��overrider�r��proxy_overrider�s rT�_proxy_bypass_winreg_overrider�t s\�� ����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�� s��,�.��+�D�.�A�ArUc��t�S)z�Return a dictionary of scheme -> proxy server URL mappings. This function uses the MacOSX framework SystemConfiguration to fetch the proxy information. )r�r�rUrT�getproxies_macosx_sysconfr�� s �� �~�rUc�H�t�}|r t||�St|�S)z�Return True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or from the MacOSX framework SystemConfiguration. )r�r�r��r�rxs rTrr� 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)zxReturn a dictionary of scheme -> proxy server URL mappings. Win32 uses the registry to store proxies. rN�;Software\Microsoft\Windows\CurrentVersion\Internet Settings� ProxyEnable� ProxyServerrvr9zhttp={0};https={0};ftp={0}r`z (?:[^/:]+)://)rr�rNr`�sockszsocks://z ^socks://z socks4://rr�)�winreg� ImportError�OpenKey�HKEY_CURRENT_USER� QueryValueExrr�r�r�rZr�r��Closer~rEr�)rxr��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�.�t�xs t�S)z�Return a dictionary of scheme -> proxy server URL mappings. Returns settings gathered from the environment, if specified, or the registry. )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�H�t�}|r t||�St|�S)z�Return True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. )r�r�r�r�s rTrr� s'��)�*�� �+�D�'�:� :�(��.� .rUrirW)~r6r�r�r�r � http.clientrr�rer�rrVrrrhrbrB� urllib.errorrrr� urllib.parserrrr r r r r rrrrrrrrrr�urllib.responserrrGrFr��__all__� version_infor�rMrr1r2rkr7r8r��ASCIIr�r�rrr3rr0rrror r!r"r#r$r%r&�urandomrr'r(r)r7r*r�rrLrlrr/r�r�r+r�r,r-r.r5rj� nturl2pathr5r4r�r9r:rvr�rxr/rzr6r|r}r�r�r�r�r��platform�_scproxyr�r�r�r�rr6r�r�r�rUrT�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)>�;�)>�VI*�I*�XG�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!:�+�!:�L� ��7�7�d�?�5�5� C� A� ��+�+�DX�Y�X�z� �� � ��� ��� ��a�a�H#�J �J<�@�0�<�<�8��:�B�� 5�G��W�W��_�/�bA�B�( /�(�J�+�L��{T���I��s�:K�K�K