관리-도구
편집 파일: appengine.cpython-36.pyc
3 nf�\�* � @ s d Z ddlmZ ddlZddlZddlZddlmZ ddlm Z m Z mZmZm Z mZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZ ydd lmZ W n ek r� dZY nX eje�ZG dd� de �ZG dd� de �Z G dd� de�Z!ej"Z"ej#Z#ej$Z$ej%Z%ej&Z&dS )aC This module provides a pool manager that uses Google App Engine's `URLFetch Service <https://cloud.google.com/appengine/docs/python/urlfetch>`_. Example usage:: from urllib3 import PoolManager from urllib3.contrib.appengine import AppEngineManager, is_appengine_sandbox if is_appengine_sandbox(): # AppEngineManager uses AppEngine's URLFetch API behind the scenes http = AppEngineManager() else: # PoolManager uses a socket-level API behind the scenes http = PoolManager() r = http.request('GET', 'https://google.com/') There are `limitations <https://cloud.google.com/appengine/docs/python/urlfetch/#Python_Quotas_and_limits>`_ to the URLFetch service and it may not be the best choice for your application. There are three options for using urllib3 on Google App Engine: 1. You can use :class:`AppEngineManager` with URLFetch. URLFetch is cost-effective in many circumstances as long as your usage is within the limitations. 2. You can use a normal :class:`~urllib3.PoolManager` by enabling sockets. Sockets also have `limitations and restrictions <https://cloud.google.com/appengine/docs/python/sockets/ #limitations-and-restrictions>`_ and have a lower free quota than URLFetch. To use sockets, be sure to specify the following in your ``app.yaml``:: env_variables: GAE_USE_SOCKETS_HTTPLIB : 'true' 3. If you are using `App Engine Flexible <https://cloud.google.com/appengine/docs/flexible/>`_, you can use the standard :class:`PoolManager` without any configuration or special environment variables. � )�absolute_importN� )�urljoin)� HTTPError�HTTPWarning� MaxRetryError� ProtocolError�TimeoutError�SSLError)�RequestMethods)�HTTPResponse)�Timeout)�Retry� )�_appengine_environ)�urlfetchc @ s e Zd ZdS )�AppEnginePlatformWarningN)�__name__� __module__�__qualname__� r r �/usr/lib/python3.6/appengine.pyr G s r c @ s e Zd ZdS )�AppEnginePlatformErrorN)r r r r r r r r K s r c @ sX e Zd ZdZddd�Zdd� Zdd � Zddddejfd d�Z dd � Z dd� Zdd� ZdS )�AppEngineManagera Connection manager for Google App Engine sandbox applications. This manager uses the URLFetch service directly instead of using the emulated httplib, and is subject to URLFetch limitations as described in the App Engine documentation `here <https://cloud.google.com/appengine/docs/python/urlfetch>`_. Notably it will raise an :class:`AppEnginePlatformError` if: * URLFetch is not available. * If you attempt to use this on App Engine Flexible, as full socket support is available. * If a request size is more than 10 megabytes. * If a response size is more than 32 megabtyes. * If you use an unsupported request method such as OPTIONS. Beyond those cases, it will raise normal urllib3 errors. NTc C sN t std��t� rtd��tjdt� tj| |� || _|| _ |pFt j| _d S )Nz.URLFetch is not available in this environment.z�Use normal urllib3.PoolManager instead of AppEngineManageron Managed VMs, as using URLFetch is not necessary in this environment.z�urllib3 is using URLFetch on Google App Engine sandbox instead of sockets. To use sockets directly instead of URLFetch see https://urllib3.readthedocs.io/en/latest/reference/urllib3.contrib.html.) r r �is_prod_appengine_mvms�warnings�warnr r �__init__�validate_certificate�urlfetch_retriesr ZDEFAULT�retries)�self�headersr r r r r r r c s zAppEngineManager.__init__c C s | S )Nr )r! r r r � __enter__{ s zAppEngineManager.__enter__c C s dS )NFr )r! �exc_typeZexc_valZexc_tbr r r �__exit__~ s zAppEngineManager.__exit__c K s� | j ||�}yF|o |jdko |j} tj||||p2i d| jo<| | j|�| jd�} W �nB tjk r� } zt | |��W Y d d }~X �n tj k r� } z$dt|�kr�td|��t |��W Y d d }~X n� tjk �r } z(dt|�kr�t| ||d��t |��W Y d d }~X n� tjk �r6 } ztd|��W Y d d }~X n` tjk �rb } zt|��W Y d d }~X n4 tjk �r� } ztd | |��W Y d d }~X nX | j| fd |i|��}|�o�|j� } | �rr| j�r�|j�r�t| |d��n�|jdk�r�d }y|j|||| d�}W n* tk �r. |j�r*t| |d��|S X |j|� tjd|| � t|| �}| j||||f|||d�|��S t|jd��}|j ||j|��r�|j|||| d�}tjd|� |j!|� | j||f|||||d�|��S |S )Nr F)Zpayload�methodr"