File: //lib/python3.6/site-packages/ndg/httpsclient/__pycache__/utils.cpython-36.pyc
3
�<�YS= � @ s� d Z dZdZdZdZdZdZddlZdd lm Z ddl
Z
ddlZejd d
kr�ddl
jZddljZddlmZ ddlmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddl m!Z" ddl#j$Z%nlddl&Zddl'Zddl(mZ ddl(mZ dd
l(mZ ddl(mZ ddl(mZ ddl(mZ ddl(m!Z" ddl)Z%ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ej0e1�Z2G dd� de�Z3G dd� de4�Z5d*dd�Z6d+dd�Z7d,dd�Z8d-dd �Z9d.d!d"�Z:d#d$� Z;G d%d&� d&e<�Z=d'd(� Z>e1d)k�r�ej?� e>� dS )/z`Utilities using NDG HTTPS Client, including a main module that can be used to
fetch from a URL.
z
R B Wilkinsonz09/12/11z2(C) 2011 Science and Technology Facilities Councilz-BSD - see LICENSE file in top-level directoryzPhilip.Kershaw@stfc.ac.ukz$Id$� N)�OptionParser� )�Request)�HTTPHandler)�HTTPCookieProcessor)�HTTPBasicAuthHandler)�HTTPPasswordMgrWithDefaultRealm)�ProxyHandler)� HTTPError)�build_opener)�HTTPSContextHandler)�ssl_context_utilc @ s e Zd ZdZdd� ZeZdS )�AccumulatingHTTPCookieProcessorztCookie processor that adds new cookies (instead of replacing the existing
ones as HTTPCookieProcessor does)
c C sx d}t |j� |ji |j|j�}| jj|� |j|�}|rt|j|�rh|j|�}dj ||g�}|j
||� n|j
||� |S )z�Processes cookies for a HTTP request.
@param request: request to process
@type request: urllib2.Request
@return: request
@rtype: urllib2.Request
ZCookiez; )�Request_�get_full_url�dataZorigin_req_hostZunverifiable� cookiejarZadd_cookie_headerZ
get_headerZ
has_header�joinZadd_unredirected_header)�self�requestZCOOKIE_HEADER_NAMEZtmp_requestZnew_cookiesZold_cookiesZmerged_cookies� r �/usr/lib/python3.6/utils.py�http_request3 s
z,AccumulatingHTTPCookieProcessor.http_requestN)�__name__�
__module__�__qualname__�__doc__r Z
https_requestr r r r r / s r c @ s e Zd ZdZdS )�
URLFetchErrorzError fetching content from URLN)r r r r r r r r r Q s r c C sD t | |||d�\}}}|r8|tjkr8|j� }|j� |S t|��dS )z�Returns data retrieved from a URL.
@param url: URL to attempt to open
@type url: basestring
@param config: SSL context configuration
@type config: Configuration
@return data retrieved from URL or None
)r �handlersN)�open_url�http_client_�OK�read�closer )�url�configr r �return_code�return_message�response�return_datar r r �fetch_from_urlU s r* c
C s\ t | |||d�\}}}|tjkrL|j� }|j� t|d�} | j|� | j� |||tjkfS )a� Writes data retrieved from a URL to a file.
@param url: URL to attempt to open
@type url: basestring
@param config: SSL context configuration
@type config: Configuration
@param output_file: output file
@type output_file: basestring
@return: tuple (
returned HTTP status code or 0 if an error occurred
returned message
boolean indicating whether access was successful)
)r r �w)r r r! r"