관리-도구
편집 파일: request.cpython-37.opt-1.pyc
B �A�[�w � @ 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>ddl?Z?yddl@Z@ddl@mAZA W n eBk �r� d ZCY nX dZCdddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-gZDe:jEdd.� ZFdaGde9jHfd/d$�ZId0d%� ZJg ZKdd1d*�ZLd2d+� ZMe�r(e8�Nd3e8jO�ZPn e8�Nd3�ZPd4d5� ZQG d6d� deR�ZSG d7d� deR�ZTd8d&� ZUG d9d� deR�ZVG d:d#� d#eV�ZWG d;d� deV�ZXG d<d� deV�ZYd=d>� ZZG d?d� deV�Z[G d@d� deR�Z\G dAd� de\�Z]G dBd� deR�Z^G dCd� de^eV�Z_G dDd� de^eV�Z`e6jaZbG dEd� deR�ZcG dFd� deVec�ZdG dGd� deVec�ZeG dHdI� dIeV�ZfG dJd� def�ZgehedK��r�G dLdM� dMef�ZieD�jdM� G dNd� deV�ZkG dOd"� d"eV�ZldPdQ� ZmdRdS� ZnG dTd� deV�ZodUdV� ZpG dWd � d eV�ZqG dXd!� d!eq�ZrdYZse6jtdZk�rdd[lumvZvmwZw nd\d(� Zvd]d'� Zwi ZxG d^d,� d,eR�ZyG d_d-� d-ey�Zzda{d`da� Z|da}dbdc� Z~daddde� Z�da�dfdg� Z�G dhdi� dieR�Z�djdk� Z�dldm� Z�dndo� Z�e:j�dpk�r�ddql�m�Z�m�Z� drds� Z�dtdu� Z�dvdw� Z�dxd)� Z�n6e6jtdZk�rdydz� Z�d{d)� Z�d|d}� Z�d~dw� Z�ne�Z�e�Z�dS )�a� Ported using Python-Future from the Python 3.3 standard library. An extensible library for opening URLs using a variety of protocols The simplest way to use this module is to call the urlopen function, which accepts a string containing a URL or a Request object (described below). It opens the URL and returns the results as file-like object; the returned object has some extra methods described below. The OpenerDirector manages a collection of Handler objects that do all the actual work. Each Handler implements a particular protocol or option. The OpenerDirector is a composite object that invokes the Handlers needed to open the requested URL. For example, the HTTPHandler performs HTTP GET and POST requests and deals with non-error returns. The HTTPRedirectHandler automatically deals with HTTP 301, 302, 303 and 307 redirect errors, and the HTTPDigestAuthHandler deals with digest authentication. urlopen(url, data=None) -- Basic usage is the same as original urllib. pass the url and optionally data to post to an HTTP URL, and get a file-like object back. One difference is that you can also pass a Request instance instead of URL. Raises a URLError (subclass of IOError); for HTTP errors, raises an HTTPError, which can also be treated as a valid response. build_opener -- Function that creates a new OpenerDirector instance. Will install the default handlers. Accepts one or more Handlers as arguments, either instances or Handler classes that it will instantiate. If one of the argument is a subclass of the default handler, the argument will be installed instead of the default. install_opener -- Installs a new opener as the default opener. objects of interest: OpenerDirector -- Sets up the User Agent as the Python-urllib client and manages the Handler classes, while dealing with requests and responses. Request -- An object that encapsulates the state of a request. The state can be as simple as the URL. It can also include extra HTTP headers, e.g. a User-Agent. BaseHandler -- internals: BaseHandler and parent _call_chain conventions Example usage: import urllib.request # set up authentication info authinfo = urllib.request.HTTPBasicAuthHandler() authinfo.add_password(realm='PDQ Application', uri='https://mahler:8092/site-updates.py', user='klem', passwd='geheim$parole') proxy_support = urllib.request.ProxyHandler({"http" : "http://ahad-haam:3128"}) # build a new opener that adds authentication and caching FTP handlers opener = urllib.request.build_opener(proxy_support, authinfo, urllib.request.CacheFTPHandler) # install it urllib.request.install_opener(opener) f = urllib.request.urlopen('http://www.python.org/') � )�absolute_import�division�print_function�unicode_literals)�bytes�dict�filter�input�int�map�open�str)�PY2�PY3�raise_with_tracebackN)�email)�client� )�URLError� HTTPError�ContentTooShortError)�urlparse�urlsplit�urljoin�unwrap�quote�unquote� splittype� splithost� splitport� splituser�splitpasswd� splitattr� splitquery� splitvalue�splittag�to_bytes� urlunparse)� addinfourl�addclosehook)� SSLContextFT�Request�OpenerDirector�BaseHandler�HTTPDefaultErrorHandler�HTTPRedirectHandler�HTTPCookieProcessor�ProxyHandler�HTTPPasswordMgr�HTTPPasswordMgrWithDefaultRealm�AbstractBasicAuthHandler�HTTPBasicAuthHandler�ProxyBasicAuthHandler�AbstractDigestAuthHandler�HTTPDigestAuthHandler�ProxyDigestAuthHandler�HTTPHandler�FileHandler� FTPHandler�CacheFTPHandler�UnknownHandler�HTTPErrorProcessor�urlopen�install_opener�build_opener�pathname2url�url2pathname� getproxies�urlretrieve� urlcleanup� URLopener�FancyURLopener� c K s� d|kr|d }|d= nd}d|kr4|d }|d= nd }d|krP|d }|d= nd }|s`|s`|r�t sltd��t�tj�}| jtjO _tj|_|s�|r�|� ||� n|� � t|dd�}t|�} nt d kr�t� a } nt } | �| ||�S )N� cadefaultF�capath�cafilezSSL support not availableT)�context�check_hostname)� _have_ssl� ValueError�sslr* ZPROTOCOL_SSLv23�optionsZOP_NO_SSLv2Z CERT_REQUIREDZverify_modeZload_verify_locationsZset_default_verify_paths�HTTPSHandlerrB �_openerr ) �url�data�timeoutZ_3to2kwargsrK rL rM rN Z https_handler�opener� rZ �P/opt/alt/python37/lib/python3.7/site-packages/future/backports/urllib/request.pyr@ � s6 c C s | a d S )N)rU )rY rZ rZ r[ rA � s c C s2 t | �\}}t�t| |����}|�� }|dkrB|sBtj�|�|fS |rRt|d�}nt j dd�}|j}t� |� |�� ||f} d} d}d}d} d|kr�t|d �}|r�|| | |� xB|�| �}|s�P |t|�7 }|�|� | d 7 } |r�|| | |� q�W W dQ R X W dQ R X |dk�r.||k �r.td||f | ��| S ) aW Retrieve a URL into a temporary location on disk. Requires a URL argument. If a filename is passed, it is used as the temporary file location. The reporthook argument should be a callable that accepts a block number, a read size, and the total file size of the URL target. The data argument should be valid URL encoded data. If a filename is passed and the URL points to a local resource, the result is a copy from local file to new file. Returns a tuple containing the path to the newly created data file as well as the resulting HTTPMessage object. �file�wbF)�deletei ���r zcontent-lengthzContent-Lengthr Nz1retrieval incomplete: got only %i out of %i bytes)r � contextlib�closingr@ �info�os�path�normpathr �tempfileZNamedTemporaryFile�name�_url_tempfiles�appendr �read�len�writer )rV �filename� reporthookrW Zurl_typerd �fp�headers�tfp�result�bs�sizerj �blocknum�blockrZ rZ r[ rF � sD $c C sH x0t D ](} yt�| � W q tk r, Y qX qW t d d �= trDd ad S )N)rh rc �unlink�EnvironmentErrorrU )Z temp_filerZ rZ r[ rG � s z:\d+$c C s<