0x1949 Team - FAZEMRX - MANAGER
Edit File: appengine.cpython-310.pyc
o �g�* � @ s d Z ddlmZ ddlZddlZddlZddlmZmZm Z m Z mZmZ ddl mZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZ zdd lmZ W n ey[ dZY nw e�e�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� )� HTTPError�HTTPWarning� MaxRetryError� ProtocolError�SSLError�TimeoutError)�urljoin)�RequestMethods)�HTTPResponse)�Retry)�Timeout� )�_appengine_environ)�urlfetchc @ � e Zd ZdS )�AppEnginePlatformWarningN��__name__� __module__�__qualname__� r r �;/usr/lib/python3/dist-packages/urllib3/contrib/appengine.pyr G � r c @ r )�AppEnginePlatformErrorNr r r r r r K r r c @ s` e Zd ZdZ ddd�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 megabytes. * If you use an unsupported request method such as OPTIONS. Beyond those cases, it will raise normal urllib3 errors. NTc C s@ t std��t�dt� t�| |� || _|| _|pt j | _d S )Nz.URLFetch is not available 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 �warnings�warnr r �__init__�validate_certificate�urlfetch_retriesr �DEFAULT�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_type�exc_val�exc_tbr r r �__exit__ s zAppEngineManager.__exit__c K s� | � ||�}z"|o|jdko|j} tj||||pi d| jo| | �|�| jd�} W n~ tjy: } zt | |��d }~w tj yU } zdt|�v rMtd|��t |��d }~w tjyr } zdt|�v rjt| ||d��t |��d }~w tjy� } ztd|��d }~w tjy� } zt|��d }~w tjy� } ztd | |��d }~ww | j| fd |i|��}|o�|�� } | �r| jr�|jr�t| |d��|jdkr�d }z|j|||| d�}W n ty� |jr�t| |d��| Y S w |�|� t�d|| � t|| �}| j||||f|||d�|��S t|�d��}|� ||j|��rC|j|||| d�}t�d|� |�!|� | j||f|||||d�|��S |S )Nr F)�payload�methodr% �allow_truncated�follow_redirects�deadliner z too largezOURLFetch request too large, URLFetch only supports requests up to 10mb in size.zToo many redirects)�reasonzPURLFetch response too large, URLFetch only supportsresponses up to 32mb in size.z$URLFetch does not support method: %sr# ztoo many redirectsi/ �GET)�response�_poolzRedirecting %s -> %s)r# �redirect�timeoutzRetry-Afterz Retry: %s)�bodyr% r# r4 r5 )"�_get_retriesr4 �totalr �fetchr! �_get_absolute_timeoutr �DeadlineExceededErrorr �InvalidURLError�strr r � DownloadErrorr �ResponseTooLargeError�SSLCertificateErrorr �InvalidMethodError�#_urlfetch_response_to_http_response�get_redirect_location�raise_on_redirect�status� increment�sleep_for_retry�log�debugr �urlopen�bool� getheader�is_retry�sleep)r$ r, �urlr6 r% r# r4 r5 �response_kwr. r2 �e� http_response�redirect_location�redirect_url�has_retry_afterr r r rJ � s� � ������������� �� ��� ���zAppEngineManager.urlopenc K s� t � r|j�d�}|dkr|jd= |j�d�}|dkr-|�d�}|�d� d�|�|jd<