File: //usr/lib/python3/dist-packages/future/backports/urllib/__pycache__/request.cpython-310.pyc
o
,�]x � @ s d Z ddlmZmZmZmZ ddlmZmZm Z m
Z
mZmZm
Z
mZ ddlmZmZmZ ddlZddlZddlZddlZddlmZ ddlmZ dd lmZmZmZ dd
l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4 ddl5Z5ddl6Z6ddl7Z7ddl8Z8ddl9Z9ddl:Z:ddl;Z;ddl<Z<ddl=Z=ddl>Z>ddlmZ er�dd
l?m@Z@ ndd
lAm@Z@ zddlBZBddlBmCZC W n eDy� dZEY nw dZEg d�ZFe:jGdd� ZHdaIde9jJfdd�ZKdd� ZLg ZMd�dd�ZNdd� ZOe�re8�Pde8jQ�ZRne8�Pd�ZRdd� ZSG dd� deT�ZUG d d!� d!eT�ZVd"d#� ZWG d$d%� d%eT�ZXG d&d'� d'eX�ZYG d(d)� d)eX�ZZG d*d+� d+eX�Z[d,d-� Z\G d.d/� d/eX�Z]G d0d1� d1eT�Z^G d2d3� d3e^�Z_G d4d5� d5eT�Z`G d6d7� d7e`eX�ZaG d8d9� d9e`eX�Zbe6jcZdG d:d;� d;eT�ZeG d<d=� d=eXee�ZfG d>d?� d?eXee�ZgG d@dA� dAeX�ZhG dBdC� dCeh�ZiejedD��r�G dEdF� dFeh�ZkeF�ldF� G dGdH� dHeX�ZmG dIdJ� dJeX�ZndKdL� ZodMdN� ZpG dOdP� dPeX�ZqdQdR� ZrG dSdT� dTeX�ZsG dUdV� dVes�ZtdWZue6jvdXk�r�ddYlwmxZxmyZy ndZd[� Zxd\d]� Zyi ZzG d^d_� d_eT�Z{G d`da� dae{�Z|da}dbdc� Z~daddde� Z�da�dfdg� Z�da�dhdi� Z�G djdk� dkeT�Z�dldm� Z�dndo� Z�dpdq� Z�e:j�drk�rdddsl�m�Z�m�Z� dtdu� Z�dvdw� Z�dxdy� Z�dzd{� Z�dS e6jvdXk�r|d|d}� Z�d~d{� Z�dd�� Z�d�dy� Z�dS e�Z�e�Z�dS )�a�
Ported using Python-Future from the Python 3.3 standard library.
An extensible library for opening URLs using a variety of protocols
The simplest way to use this module is to call the urlopen function,
which accepts a string containing a URL or a Request object (described
below). It opens the URL and returns the results as file-like
object; the returned object has some extra methods described below.
The OpenerDirector manages a collection of Handler objects that do
all the actual work. Each Handler implements a particular protocol or
option. The OpenerDirector is a composite object that invokes the
Handlers needed to open the requested URL. For example, the
HTTPHandler performs HTTP GET and POST requests and deals with
non-error returns. The HTTPRedirectHandler automatically deals with
HTTP 301, 302, 303 and 307 redirect errors, and the HTTPDigestAuthHandler
deals with digest authentication.
urlopen(url, data=None) -- Basic usage is the same as original
urllib. pass the url and optionally data to post to an HTTP URL, and
get a file-like object back. One difference is that you can also pass
a Request instance instead of URL. Raises a URLError (subclass of
IOError); for HTTP errors, raises an HTTPError, which can also be
treated as a valid response.
build_opener -- Function that creates a new OpenerDirector instance.
Will install the default handlers. Accepts one or more Handlers as
arguments, either instances or Handler classes that it will
instantiate. If one of the argument is a subclass of the default
handler, the argument will be installed instead of the default.
install_opener -- Installs a new opener as the default opener.
objects of interest:
OpenerDirector -- Sets up the User Agent as the Python-urllib client and manages
the Handler classes, while dealing with requests and responses.
Request -- An object that encapsulates the state of a request. The
state can be as simple as the URL. It can also include extra HTTP
headers, e.g. a User-Agent.
BaseHandler --
internals:
BaseHandler and parent
_call_chain conventions
Example usage:
import urllib.request
# set up authentication info
authinfo = urllib.request.HTTPBasicAuthHandler()
authinfo.add_password(realm='PDQ Application',
uri='https://mahler:8092/site-updates.py',
user='klem',
passwd='geheim$parole')
proxy_support = urllib.request.ProxyHandler({"http" : "http://ahad-haam:3128"})
# build a new opener that adds authentication and caching FTP handlers
opener = urllib.request.build_opener(proxy_support, authinfo,
urllib.request.CacheFTPHandler)
# install it
urllib.request.install_opener(opener)
f = urllib.request.urlopen('http://www.python.org/')
� )�absolute_import�division�print_function�unicode_literals)�bytes�dict�filter�input�int�map�open�str)�PY2�PY3�raise_with_tracebackN)�email)�client� )�URLError� HTTPError�ContentTooShortError)�urlparse�urlsplit�urljoin�unwrap�quote�unquote� splittype� splithost� splitport� splituser�splitpasswd� splitattr�
splitquery�
splitvalue�splittag�to_bytes�
urlunparse)�
addinfourl�addclosehook)r )�Iterable)�
SSLContextFT)�Request�OpenerDirector�BaseHandler�HTTPDefaultErrorHandler�HTTPRedirectHandler�HTTPCookieProcessor�ProxyHandler�HTTPPasswordMgr�HTTPPasswordMgrWithDefaultRealm�AbstractBasicAuthHandler�HTTPBasicAuthHandler�ProxyBasicAuthHandler�AbstractDigestAuthHandler�HTTPDigestAuthHandler�ProxyDigestAuthHandler�HTTPHandler�FileHandler�
FTPHandler�CacheFTPHandler�UnknownHandler�HTTPErrorProcessor�urlopen�install_opener�build_opener�pathname2url�url2pathname�
getproxies�urlretrieve�
urlcleanup� URLopener�FancyURLopener� c
K s� d|v r|d }|d= nd}d|v r|d }|d= nd }d|v r(|d }|d= nd }|s0|s0|rbt s6td��t�tj�}| jtjO _tj|_|sL|rS|� ||� n|�
� t|dd�}t|�} nt
d u rlt� a
} nt
} | �| ||�S )N� cadefaultF�capath�cafilezSSL support not availableT��context�check_hostname)� _have_ssl�
ValueError�sslr+ �PROTOCOL_SSLv23�options�OP_NO_SSLv2�
CERT_REQUIRED�verify_mode�load_verify_locations�set_default_verify_paths�HTTPSHandlerrC �_openerr )
�url�data�timeout�_3to2kwargsrL rM rN rP �
https_handler�opener� rd �A/usr/lib/python3/dist-packages/future/backports/urllib/request.pyrA � s*
rA c C s | a d S �N)r] )rc rd rd re rB � s rB c C sb t | �\}}t�t| |����}|�� }|dkr(|s(tj�|�|fW d � S |r0t|d�}nt j
dd�}|j}t�
|� |�G ||f} d}
d}d}d}
d |v rWt|d
�}|r_||
|
|� |�|
�}|shn|t|�7 }|�|� |
d7 }
|r||
|
|� q`W d � n1 s�w Y W d � n1 s�w Y |dkr�||k r�td
||f | ��| S )aW
Retrieve a URL into a temporary location on disk.
Requires a URL argument. If a filename is passed, it is used as
the temporary file location. The reporthook argument should be
a callable that accepts a block number, a read size, and the
total file size of the URL target. The data argument should be
valid URL encoded data.
If a filename is passed and the URL points to a local resource,
the result is a copy from local file to new file.
Returns a tuple containing the path to the newly created
data file as well as the resulting HTTPMessage object.
�fileN�wbF)�delete� ���r �content-length�Content-LengthTr �1retrieval incomplete: got only %i out of %i bytes)r �
contextlib�closingrA �info�os�path�normpathr �tempfile�NamedTemporaryFile�name�_url_tempfiles�appendr
�read�len�writer )r^ �filename�
reporthookr_ �url_typers �fp�headers�tfp�result�bs�sizerz �blocknum�blockrd rd re rG � sV �
����&��rG c C sD t D ]} zt�| � W q ty Y qw t d d �= tr d ad S d S rf )rx rr �unlink�EnvironmentErrorr] )� temp_filerd rd re rH � s �
�rH z:\d+$c C s<