Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/webob/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/webob/__pycache__/request.cpython-37.pyc

B

��vP���@s�ddlZddlZddlZddlZddlZddlZddlZddlZyddlZ	Wne
k
rhddl	Z	YnXddlZddlm
Z
mZmZmZmZmZddlmZmZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:ddl;m<Z<dd	l=m>Z>m?Z?m@Z@mAZAdd
lBmCZCddd
gZDGdd�d�ZEeE�ZFdZGeH�Idd�ZJeJ�KeH�Idd��dZLGdd�deM�ZNGdd
�d
eN�ZOGdd�deM�ZPGdd�dePeN�ZQdd�ZRd5dd�ZSGdd �d eT�ZUGd!d"�d"ejV�ZWd#d$�ZXeXejY_ZGd%d&�d&ejV�Z[d'd(�Z\d6d)d*�Z]d+d,�Z^d-d.�Z_Gd/d0�d0eM�Z`x8d1�a�D],Zbd2ebZce5decd3ebd4�ZdeeeNeced��q�WdS)7�N)�AcceptLanguage�
AcceptCharset�
MIMEAccept�
MIMENilAccept�NoAccept�accept_property)�CacheControl�serialize_cache_control)�PY3�bytes_�
integer_types�native_�parse_qsl_text�reraise�	text_type�
url_encode�	url_quote�url_unquote�
quote_plus�urlparse)�RequestCookies)�
CHARSET_RE�	SCHEME_RE�	converter�converter_date�environ_getter�environ_decoder�
parse_auth�	parse_int�parse_int_safe�parse_range�serialize_auth�serialize_if_range�
serialize_int�serialize_range�upath_property�deprecated_property)�IfRange�AnyETag�NoETag�
etag_property)�EnvironHeaders)�NestedMultiDict�	MultiDict�NoVars�GetDict)�warn_deprecation�BaseRequest�Request�
LegacyRequestc@seZdZdd�ZdS)�
_NoDefaultcCsdS)Nz(No Default)�)�selfr5r5�>/opt/alt/python37/lib/python3.7/site-packages/webob/request.py�__repr__Vsz_NoDefault.__repr__N)�__name__�
__module__�__qualname__r8r5r5r5r7r4Usr4z/:@&+$,)�GETZHEADZDELETEZTRACEF)�POST�PUTT)�asciizlatin-1�latin�latin_1�l1�latin1z
iso-8859-1�	iso8859_1�
iso_8859_1�iso8859�8859c@szeZdZdZdZd�dd�Zer.edfdd�Znedfdd�Zd�dd	�Z	e
d
d��Zejdd��Zd�dd�Z
dZdd�Zdd�Zdd�Ze
eeeejd�Zed�Ze
dd��Zedd�Zed�Zedd�Zed �Zeed!dd"�eed#�Zed$d�Zed%d�Z ed&d'�Z!ed(�Z"eed)�e#ed#�Z$e%d*d'd+d,�Z&e%d-d+d,�Z'e&Z(e'Z)ed.d'�Z*d/d0�Z+d�d1d2�Z,e
e+e,e,e+j�Z-dZ.d3d4�Z/d5d6�Z0e
e/e0e/jd�Z1e
d7d8��Z2e
d9d:��Z3e
d;d<��Z4e
d=d>��Z5e
d?d@��Z6e
dAdB��Z7e
dCdD��Z8e
dEdF��Z9d�dHdI�Z:d�dJdK�Z;dLdM�Z<dNdO�Z=dPdQ�Z>dRdS�Z?e
e=e>e?e=jd�Z@dTdU�ZAdVdW�ZBdXdY�ZCe
eAeBeCeAj�ZDe
dZd[��ZEd\d]�ZFd^d_�ZGd`da�ZHe
eFeGeHeFjd�ZIdbdc�ZJddde�ZKdfdg�ZLe
eJeKeLeJjd�ZMdhdi�ZNdjdk�ZOdldm�ZPe
eNeOeP�ZQZRdndo�ZSdpdq�ZTdrds�ZUe
eSeTeUeSjd�ZVe
dtdu��ZWe
dvdw��ZXdxdy�ZYe
dzd{��ZZe
d|d}��Z[e[jd~d}��Z[dd��Z\d�d��Z]ed�dG�Z^d�d��Z_d�d��Z`e
e_e`e_jd�Zad�d��Zbd�d��Zcd�d��Zdd�d��Zed�d�d��Zfegd�d�ehei�Zjegd�d�ek�Zlegd�d�emd��Znegd�d�eo�Zpeed�dd��eqer�Zsd�d��Ztd�d��Zud�d��Zvd�d��Zwe
eteuevetjd�Zxeyd�ezd��Z{eyd�e|d�dGd��Z}e~ed�dd���Ze~ed�dd���Z�e~ed�dd���Z�eed�dd��e�j�e�d��Z�eed�dd��e#ed#�Z�ed�dd��Z�eed�dd��e�e�d��Z�ed�dd��Z�e�Z�ed�dd��Z�d�d��Z�d�d�d��Z�d�d�dÄZ�d�dńZ�e�Z�e�d�dDŽ�Z�e�d�dɄ�Z�e�d�d˄�Z�e�d�d̈́�Z�d�d�dτZ�dZ�d�d�dфZ�e�Z�d�dӄZ�e�d�d�dՄ�Z�dS)�r1i(Nc
Ks�t|�tk	rtd|f��|dk	r4t�d|ft�|dk	rNt�d|ft�t|�sbtd|��|j}||d<|r�|j}d|kr�|�	d�|_
x:|��D].\}}	t||�s�td||	f��t
|||	�q�WdS)Nz*WSGI environ must be a dict; you passed %rz�You unicode_errors=%r to the Request constructor.  Passing a ``unicode_errors`` value to the Request is no longer supported in WebOb 1.2+.  This value has been ignored z�You passed decode_param_names=%r to the Request constructor. Passing a ``decode_param_names`` value to the Request is no longer supported in WebOb 1.2+.  This value has been ignored z�You passed charset=%r to the Request constructor. As of WebOb 1.2, if your application needs a non-UTF-8 request charset, please construct the request without a charset or with a charset of 'None',  then use ``req = req.decode(charset)``�environ�methodzUnexpected keyword: %s=%r)�type�dict�	TypeError�warnings�warn�DeprecationWarning�_is_utf8�__dict__�	__class__�poprI�items�hasattr�setattr)
r6rH�charsetZunicode_errorsZdecode_param_names�kw�d�cls�name�valuer5r5r7�__init__ns8
zBaseRequest.__init__cCsX|j�||�}|tkrt|��||kr*|S|s2|St||�}|tkrH|St|d��|�S)Nzlatin-1)rH�get�	NoDefault�KeyError�getattr�_LATIN_ENCODINGSr�decode)r6�key�default�encattr�val�encodingr5r5r7�encget�s
zBaseRequest.encgetcCsJ|j�||�}|tkrt|��||kr*|S|dkr6|St||�}|�|�S)N)rHr^r_r`rarc)r6rdrerfrgrhr5r5r7ri�s
cCsD|rt||�}nd}tr0t||��d�|j|<nt||�|j|<dS)Nr?zlatin-1)rar
rrcrH)r6rdrgrfrhr5r5r7�encset�szBaseRequest.encsetcCs,|jdkr&t|j�}t|�r d}||_|jS)NzUTF-8)�_charset�detect_charset�_content_type_rawrP)r6rWr5r5r7rW�s

zBaseRequest.charsetcCs&t|�rd}||jkr"td|��dS)NzUTF-8zUse req = req.decode(%r))rPrWrO)r6rWr5r5r7rW�s
�strictc
Cs�|p|j}|dkr|St||�}t�d|j�}|j}|j|j��|�	|j
�|d�}|dkrtt|�	t|j
���|_
|S|dkr�|S|j��}|�dd�d|d	<tr�tj|j|d
||d�}ntj|j|d
d�}|�||j�}	|	|_|	��|_|	�d
�|S)NzUTF-8z; charset="UTF-8")�query_string�content_typez!application/x-www-form-urlencodedzmultipart/form-data�CONTENT_LENGTH�0��QUERY_STRINGT)�fprH�keep_blank_valuesrh�errors)rurHrvr)rW�
Transcoderr�subrmrprRrH�copy�transcode_queryrorr
�body�
setdefaultr
�cgi�FieldStorage�	body_file�transcode_fs�tell�content_length�seek)
r6rWrw�tZnew_content_typerp�r�
fs_environ�fs�foutr5r5r7rc�sB






zBaseRequest.decode�cCsn|jst��S|j}|j}|jsj|dk	rj|j}|�dd�\}}||k	rft||�}t�	|�}||f|d<|}|S)z�
            Input stream of the request (wsgi.input).
            Setting this property resets the content_length and seekable flag
            (unlike setting req.body_file_raw).
        Nzwebob._body_file)rr)
�is_body_readable�io�BytesIO�
body_file_rawr��is_body_seekablerHr^�LimitedLengthFile�BufferedReader)r6r��clen�env�wrapped�rawr5r5r7�_body_file__gets

zBaseRequest._body_file__getcCs4t|t�rtdd|j�d|_||_d|_d|_dS)Nz9Please use req.body = b'bytes' or req.body_file = fileobjz1.2FT)�
isinstance�bytesr0�_setattr_stacklevelr�r�r�r�)r6r\r5r5r7�_body_file__sets
zBaseRequest._body_file__setcCs
d|_dS)N�)r|)r6r5r5r7�_body_file__del&szBaseRequest._body_file__del)�docz
wsgi.inputcCs|js|��|jS)a
            Get the body of the request (wsgi.input) as a seekable file-like
            object. Middleware and routing applications should use this
            attribute over .body_file.

            If you access this value, CONTENT_LENGTH will also be updated.
        )r��make_body_seekabler�)r6r5r5r7�body_file_seekable-s	zBaseRequest.body_file_seekablezwebob.url_encodingzUTF-8zwsgi.url_scheme�REQUEST_METHODr<�SERVER_PROTOCOLrqz14.13�intZREMOTE_USER�REMOTE_ADDRrtrs�SERVER_NAME�SERVER_PORT�SCRIPT_NAME�url_encoding)rf�	PATH_INFO�CONTENT_TYPEcCs|j�dd�dS)aUReturn the content type, but leaving off any parameters (like
        charset, but also things like the type in ``application/atom+xml;
        type=entry``)

        If you set this property, you can include parameters, or if
        you don't include any parameters in the value then existing
        parameters will be preserved.
        �;�r)rm�split)r6r5r5r7�_content_type__getRs	zBaseRequest._content_type__getcCsH|dk	r>t|�}d|kr>|j}d|kr>|d|�dd�d7}||_dS)Nr�r�)�strrmr�)r6r\rpr5r5r7�_content_type__set\szBaseRequest._content_type__setcCs|jdkrt|j�|_|jS)z_
        All the request headers as a case-insensitive dictionary-like
        object.
        N)�_headersr+rH)r6r5r5r7�
_headers__getls
zBaseRequest._headers__getcCs|j��|j�|�dS)N)�headers�clear�update)r6r\r5r5r7�
_headers__setus
zBaseRequest._headers__setcCs:|j}|�d�}|dk	r,|�d�d��}n
|�d�}|S)a_
        The effective client IP address as a string.  If the
        ``HTTP_X_FORWARDED_FOR`` header exists in the WSGI environ, this
        attribute returns the client IP address present in that header
        (e.g. if the header value is ``192.168.1.1, 192.168.1.2``, the value
        will be ``192.168.1.1``). If no ``HTTP_X_FORWARDED_FOR`` header is
        present in the environ at all, this attribute will return the value
        of the ``REMOTE_ADDR`` header.  If the ``REMOTE_ADDR`` header is
        unset, this attribute will return the value ``None``.

        .. warning::

           It is possible for user agents to put someone else's IP or just
           any string in ``HTTP_X_FORWARDED_FOR`` as it is a normal HTTP
           header. Forward proxies can also provide incorrect values (private
           IP addresses etc).  You cannot "blindly" trust the result of this
           method to provide you with valid data unless you're certain that
           ``HTTP_X_FORWARDED_FOR`` has the correct values.  The WSGI server
           must be behind a trusted proxy for this to be true.
        ZHTTP_X_FORWARDED_FORN�,rr�)rHr^r��strip)r6�eZxff�addrr5r5r7�client_addr{s

zBaseRequest.client_addrcCsZ|j}|�d�}|dk	rNd|kr2|�dd�\}}qV|d}|dkrHd}qVd}n|d	}|S)
a`
        The effective server port number as a string.  If the ``HTTP_HOST``
        header exists in the WSGI environ, this attribute returns the port
        number present in that header. If the ``HTTP_HOST`` header exists but
        contains no explicit port number: if the WSGI url scheme is "https" ,
        this attribute returns "443", if the WSGI url scheme is "http", this
        attribute returns "80" .  If no ``HTTP_HOST`` header is present in
        the environ at all, this attribute will return the value of the
        ``SERVER_PORT`` header (which is guaranteed to be present).
        �	HTTP_HOSTN�:r�zwsgi.url_scheme�https�443�80r�)rHr^r�)r6r��host�portZ
url_schemer5r5r7�	host_port�s
zBaseRequest.host_portcCs�|j}|�d�}|d}|�d�}|dk	rJd|krD|�dd�\}}q^d}n|�d�}|�d�}|d	krt|d
kr�d}n|dkr�|dkr�d}||7}|r�|d
|7}|S)z4
        The URL through the host (no path)
        zwsgi.url_schemez://r�Nr�r�r�r�r�r��httpr�z:%s)rHr^r�)r6r��scheme�urlr�r�r5r5r7�host_url�s(



zBaseRequest.host_urlcCst|j|j�}|jt|t�S)zN
        The URL including SCRIPT_NAME (no PATH_INFO or query string)
        )r�script_namer�r�r�	PATH_SAFE)r6Zbscript_namer5r5r7�application_url�szBaseRequest.application_urlcCst|j|j�}|jt|t�S)zS
        The URL including SCRIPT_NAME and PATH_INFO, but not QUERY_STRING
        )r�	path_infor�r�rr�)r6Z
bpath_infor5r5r7�path_url�szBaseRequest.path_urlcCs0t|j|j�}t|j|j�}t|t�t|t�S)zG
        The path of the request, without host or query string
        )rr�r�r�rr�)r6Zbscript�bpathr5r5r7�path�szBaseRequest.pathcCs&|j}|j�d�}|r"|d|7}|S)zM
        The path of the request, without host but with query string
        rt�?)r�rHr^)r6r��qsr5r5r7�path_qs�s
zBaseRequest.path_qscCs&|j}|j�d�}|r"|d|7}|S)z>
        The full request URL, including QUERY_STRING
        rtr�)r�rHr^)r6r�r�r5r5r7r��s
zBaseRequest.urlFcCs0|r|j}|�d�s$|d7}n|j}t�||�S)z�
        Resolve other_url relative to the request URL.

        If ``to_application`` is True, then resolve it relative to the
        URL with only SCRIPT_NAME
        �/)r��endswithr�r�urljoin)r6Z	other_urlZto_applicationr�r5r5r7�relative_url�s

zBaseRequest.relative_urlcCs�|j}|sdSd}x"|�d�r4|d7}|dd�}qW|�d�}|dkrPt|�}|d|�}|dkspt�||�r�|j||7_||d�|_|SdS)a�
        'Pops' off the next segment of PATH_INFO, pushing it onto
        SCRIPT_NAME, and returning the popped segment.  Returns None if
        there is nothing left on PATH_INFO.

        Does not return ``''`` when there's an empty segment (like
        ``/path//path``); these segments are just ignored.

        Optional ``pattern`` argument is a regexp to match the return value
        before returning. If there is no match, no changes are made to the
        request and None is returned.
        Nrsr�r����)r��
startswith�find�len�re�matchr�)r6�patternr�Zslashes�idxr�r5r5r7�
path_info_pops

zBaseRequest.path_info_popcCs(|j}|sdS|�d�}|�dd�dS)z�
        Returns the next segment on PATH_INFO, or None if there is no
        next segment.  Doesn't modify the environment.
        Nr�r�r)r��lstripr�)r6r�r5r5r7�path_info_peek+s

zBaseRequest.path_info_peekcCsFd|jkr|jdSd|jkr,|jddSi}d|f|jd<|SdS)z�
        Return any *named* variables matched in the URL.

        Takes values from ``environ['wsgiorg.routing_args']``.
        Systems like ``routes`` set this value.
        z
paste.urlvarszwsgiorg.routing_argsr�r5N)rH)r6�resultr5r5r7�
_urlvars__get6s


zBaseRequest._urlvars__getcCsT|j}d|kr2|dd|f|d<d|krP|d=nd|krD||d<nd|f|d<dS)Nzwsgiorg.routing_argsrz
paste.urlvarsr5)rH)r6r\rHr5r5r7�
_urlvars__setFs
zBaseRequest._urlvars__setcCsPd|jkr|jd=d|jkrL|jdds4|jd=n|jddif|jd<dS)Nz
paste.urlvarszwsgiorg.routing_argsr)rH)r6r5r5r7�
_urlvars__delRs


zBaseRequest._urlvars__delcCs d|jkr|jddSdSdS)z�
        Return any *positional* variables matched in the URL.

        Takes values from ``environ['wsgiorg.routing_args']``.
        Systems like ``routes`` set this value.
        zwsgiorg.routing_argsrr5N)rH)r6r5r5r7�
_urlargs__getas
zBaseRequest._urlargs__getcCsL|j}d|kr||�d�f}n"d|kr8||ddf}n|if}||d<dS)Nz
paste.urlvarszwsgiorg.routing_argsr�)rHrS)r6r\rHZrouting_argsr5r5r7�
_urlargs__setoszBaseRequest._urlargs__setcCs>d|jkr:|jdds"|jd=nd|jddf|jd<dS)Nzwsgiorg.routing_argsr�r5)rH)r6r5r5r7�
_urlargs__del{s

zBaseRequest._urlargs__delcCs|j�dd�dkS)aEIs X-Requested-With header present and equal to ``XMLHttpRequest``?

        Note: this isn't set by every XMLHttpRequest request, it is
        only set if you are using a Javascript library that sets it
        (or you set the header yourself manually).  Currently
        Prototype and jQuery are known to set this header.ZHTTP_X_REQUESTED_WITHrsZXMLHttpRequest)rHr^)r6r5r5r7�is_xhr�szBaseRequest.is_xhrcCs"d|jkr|jdSd|jSdS)z>Host name provided in HTTP_HOST, with fall-back to SERVER_NAMEr�z%(SERVER_NAME)s:%(SERVER_PORT)sN)rH)r6r5r5r7�
_host__get�s

zBaseRequest._host__getcCs||jd<dS)Nr�)rH)r6r\r5r5r7�
_host__set�szBaseRequest._host__setcCsd|jkr|jd=dS)Nr�)rH)r6r5r5r7�
_host__del�s
zBaseRequest._host__delcCs0|js
dS|��|j�|j�}|j�d�|S)z9
        Return the content of the request body.
        r�r)r�r�r��readr�r�r�)r6r�r5r5r7�
_body__get�szBaseRequest._body__getcCsl|dkrd}t|t�s&tdt|���t�|jd�sL|sLd|_t�	�|_
dSt|�|_t�	|�|_
d|_dS)Nr�z/You can only set Request.body to bytes (not %r)T)
r�r�rLrJ�http_method_probably_has_bodyr^rIr�r�r�r�r�r�)r6r\r5r5r7�
_body__set�s


zBaseRequest._body__setcCs
d|_dS)Nr�)r|)r6r5r5r7�
_body__del�szBaseRequest._body__delcCst�|j�|j��S)z&Access the body of the request as JSON)�json�loadsr|rcrW)r6r5r5r7�_json_body__get�szBaseRequest._json_body__getcCstj|dd��|j�|_dS)N)r�r�)Z
separators)r��dumps�encoderWr|)r6r\r5r5r7�_json_body__set�szBaseRequest._json_body__setcCs|`dS)N)r|)r6r5r5r7�_json_body__del�szBaseRequest._json_body__delcCs |jstd��|j}|�|j�S)z4
        Get/set the text value of the body
        z4You cannot access Request.text unless charset is set)rW�AttributeErrorr|rc)r6r|r5r5r7�
_text__get�s
zBaseRequest._text__getcCs:|jstd��t|t�s(tdt|���|�|j�|_dS)Nz5You cannot access Response.text unless charset is setz:You can only set Request.text to a unicode string (not %s))rWr�r�rrLrJr�r|)r6r\r5r5r7�
_text__set�s
zBaseRequest._text__setcCs|`dS)N)r|)r6r5r5r7�
_text__del�szBaseRequest._text__delc	Cs
|j}|jdkrtd�Sd|kr:|d\}}||jkr:|S|j}|jdkrN|rV|dkrbtd|�S|��|jr||j�d�|��}|�	dd	�d
|d<t
r�tj|j
|dd
d�}t�|�}ntj|j
|dd�}t�|�}|jp�d}t||�}t�|�|_
||jf|d<|S)a
        Return a MultiDict containing all the variables from a form
        request. Returns an empty dict-like object for non-form requests.

        Form requests are typically POST requests, however PUT requests with
        an appropriate Content-Type are also supported.
        )r=r>zNot a form requestzwebob._parsed_post_varsr>)rsz!application/x-www-form-urlencodedzmultipart/form-dataz.Not an HTML form submission (Content-Type: %s)rrqrrrsrtT�utf8)rurHrvrh)rurHrvz!application/x-www-form-urlencoded)rHrIr.r�rp�_check_charsetr�r�rzr}r
r~rr�r-Zfrom_fieldstoragerm�FakeCGIBodyr�r�)	r6r��varsr�rpr�r��ctype�fr5r5r7r=�sH	




zBaseRequest.POSTcCs\|j}|�dd�}d|kr2|d\}}||kr2|Sg}|rBt|�}t||�}||f|d<|S)z`
        Return a MultiDict containing all the variables from the
        QUERY_STRING.
        rtrszwebob._parsed_query_vars)rHr^rr/)r6r��sourcer�r��datar5r5r7r<s
zBaseRequest.GETcCs"|jdkrtd|j|jf��dS)NzUTF-8zhRequests are expected to be submitted in UTF-8, not %s. You can fix this by doing req = req.decode('%s'))rWrO)r6r5r5r7r�2s
zBaseRequest._check_charsetcCst|j|j�}|S)zy
        A dictionary-like object containing both the parameters from
        the query string and request body.
        )r,r<r=)r6�paramsr5r5r7r:szBaseRequest.paramscCs
t|j�S)zI
        Return a dictionary of cookies as found in the request.
        )rrH)r6r5r5r7�cookiesDszBaseRequest.cookiescCs&|j�dd�t|j�}|�|�dS)NZHTTP_COOKIE)rHrSrr�)r6rgr�r5r5r7rKs
cCs(|��|j��}|�|�}|��|S)zw
        Copy the request and environment object.

        This only does a shallow copy, except of wsgi.input
        )r�rHrzrR�	copy_body)r6r�Znew_reqr5r5r7rzQs


zBaseRequest.copycCs|j��}|j|dddd�S)z�
        Copies the request and environment object, but turning this request
        into a GET along the way.  If this was a POST request (or any other
        verb) then it becomes GET, and the request body is thrown away.
        r<Nr�)rIrpr|)rHrzrR)r6r�r5r5r7�copy_get]s

zBaseRequest.copy_getzwebob.is_body_seekablecCs0t�|j�rdS|jdk	rdS|j�dd�SdS)ai
            webob.is_body_readable is a flag that tells us
            that we can read the input stream even though
            CONTENT_LENGTH is missing. This allows FakeCGIBody
            to work and can be used by servers to support
            chunked encoding in requests.
            For background see https://bitbucket.org/ianb/webob/issue/6
        TNzwebob.is_body_readableF)r�r^rIr�rH)r6r5r5r7�_is_body_readable__getms
	
z"BaseRequest._is_body_readable__getcCst|�|jd<dS)Nzwebob.is_body_readable)�boolrH)r6�flagr5r5r7�_is_body_readable__set�sz"BaseRequest._is_body_readable__setcCs |jr|j�d�n|��dS)a�
        This forces ``environ['wsgi.input']`` to be seekable.
        That means that, the content is copied into a BytesIO or temporary
        file and flagged as seekable, so that it will not be unnecessarily
        copied again.

        After calling this method the .body_file is always seeked to the
        start of file and .content_length is not None.

        The choice to copy to BytesIO is made from
        ``self.request_body_tempfile_limit``
        rN)r�r�r�r)r6r5r5r7r��s
zBaseRequest.make_body_seekablecCsN|jsd|_n<|jdkr.|j��|_|��n|��}|sJ|j�|j�|_dS)z�
        Copies the body, in cases where it might be shared with
        another request object and that is not desired.

        This copies the body in-place, either into a BytesIO object
        or a temporary file.
        r�N)r�r|r�r�r��_copy_body_tempfiler�)r6Zdid_copyr5r5r7r�s

zBaseRequest.copy_bodycCs�|j}|j}t|t�st|��|r*||kr.dS|��}|j}xB|dkr~|�t|d��}|sft	d|��|�
|�|t|�8}q>W|�d�||_
d|_dS)zW
            Copy wsgi.input to tempfile if necessary. Returns True if it did.
        Friz1Client disconnected (%s more bytes were expected)T)�request_body_tempfile_limitr�r�r�AssertionError�
make_tempfiler�r��min�DisconnectionError�writer�r�r�r�)r6Ztempfile_limitZtodo�fileobj�inputrr5r5r7r�s&


zBaseRequest._copy_body_tempfilecCst��S)z�
            Create a tempfile to store big request body.
            This API is not stable yet. A 'size' argument might be added.
        )�tempfile�
TemporaryFile)r6r5r5r7r�szBaseRequest.make_tempfileTcCsbg}|r|ddg7}|r"|�d�|r0|�d�|r>|�d�x|D]}||jkrD|j|=qDWdS)a*
        Remove headers that make the request conditional.

        These headers can cause the response to be 304 Not Modified,
        which in some cases you may not want to be possible.

        This does not remove headers like If-Match, which are used for
        conflict detection.
        �
HTTP_IF_RANGE�
HTTP_RANGE�HTTP_IF_NONE_MATCH�HTTP_IF_MODIFIED_SINCEZHTTP_ACCEPT_ENCODINGN)�appendrH)r6Zremove_encodingZremove_rangeZremove_matchZremove_modifiedZ
check_keysrdr5r5r7�remove_conditional_headers�s




z&BaseRequest.remove_conditional_headersZAcceptz14.1zAccept-Charsetz14.2zAccept-Encodingz14.3)ZNilClasszAccept-Languagez14.4ZHTTP_AUTHORIZATIONz14.8cCsX|j}|�dd�}|�dd�\}}|dk	r6||kr6|Stj||jdd�}||f|d<|S)z�
        Get/set/modify the Cache-Control header (`HTTP spec section 14.9
        <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9>`_)
        �HTTP_CACHE_CONTROLrszwebob._cache_control)NNN�request)Z
updates_torJ)rHr^r�parse�_update_cache_control)r6r�r\Zcache_headerZ	cache_objr5r5r7�_cache_control__getszBaseRequest._cache_control__getcCsd|j}|pd}t|t�r$t|dd�}t|t�rLt|�}||d<||f|d<nt|�|d<d|d<dS)Nrsr)rJrzwebob._cache_control)NN)rHr�rKrr�)r6r\r�Z	str_valuer5r5r7�_cache_control__sets

zBaseRequest._cache_control__setcCs&|j}d|kr|d=d|kr"|d=dS)Nrzwebob._cache_control)rH)r6r�r5r5r7�_cache_control__dels
zBaseRequest._cache_control__delcCst|�|jd<dS)Nr)r	rH)r6Z	prop_dictr5r5r7r$sz!BaseRequest._update_cache_controlZ
HTTP_IF_MATCHz14.24rz14.26)ZstrongZ	HTTP_DATErz14.25ZHTTP_IF_UNMODIFIED_SINCEz14.28rz14.27zIfRange objectZHTTP_MAX_FORWARDSz14.31ZHTTP_PRAGMAz14.32rz14.35zRange objectZHTTP_REFERERz14.36ZHTTP_USER_AGENTz14.43cCsLyd|j|jf}Wntk
r,d}YnXd|jjtt|��|f}|S)Nz%s %sz(invalid WSGI environ)z<%s at 0x%x %s>)rIr�r`rRr9�abs�id)r6r[�msgr5r5r7r8Js
zBaseRequest.__repr__c	Cs�|j}|j}|�|�st�|t|�d�}td|j||jf�g}d}|jdkr�|dkr~t|j�|krztdt|j��}nd}|s�|j}x4t	|j
���D]"\}}td||f�}|�|�q�W|r�|�
d|g�d	�|�S)
z�
            Return HTTP bytes representing this request.
            If skip_body is True, exclude the body.
            If skip_body is an integer larger than one, skip body
            only if its length is bigger than that number.
        Nz%s %s %s)r>r=r�z<body skipped (len=%s)>Fz%s: %sr�s
)r�r�r�r
r�rrI�http_versionr|�sortedr�rTr�extend�join)	r6�	skip_bodyr�r��partsr|�k�v�headerr5r5r7�as_bytesTs&
zBaseRequest.as_bytescCstdd|j�|j|d�S)NzPlease use req.as_bytesz1.3)r*)r0r�r/)r6r*r5r5r7�	as_stringws
zBaseRequest.as_stringcCs|��}|�|j�S)N)r/rcrW)r6r�r5r5r7�as_textszBaseRequest.as_textcCs0t�|�}|�|�}|��t|�kr,td��|S)z�
            Create a request from HTTP bytes data. If the bytes contain
            extra data after the request, raise a ValueError.
        z+The string contains more data than expected)r�r��	from_filer�r��
ValueError)rZ�brr�r5r5r7�
from_bytes�s


zBaseRequest.from_bytescCstdd|j�|�|�S)NzPlease use req.from_bytesz1.3)r0r�r5)rZr4r5r5r7�from_string�s
zBaseRequest.from_stringcCst|d�}|�|�S)Nzutf-8)rr5)rZ�sr4r5r5r7�	from_text�s
zBaseRequest.from_textcCsV|��}t|t�}|r d}d}nd}d}y>|�|�}|�dd�\}}}	t|d�}t|d�}t|	d�}	Wn tk
r�td|��YnX|t|�|	|��d	�}
|
j	d
=xd|��}|�
�s�P|�|d�\}}
t|d�}t|
d��
�}
||
jkr�|
j|d|
}
|
|
j|<q�W|
jd
k�rR|
j
}|dk�r2|��}n
|�|�}|�rLt|d�}||
_|
S)a�Read a request from a file-like object (it must implement
        ``.read(size)`` and ``.readline()``).

        It will read up to the end of the request, not the end of the
        file (unless the request is a POST or PUT and has no
        Content-Length, in that case, the entire file is read).

        This reads the request as represented by ``str(req)``; it may
        not read every valid HTTP request properly.
        z
r�s
�:Nr�zutf-8zBad HTTP request line: %r)r&rIr�r�z, )r>r=)�readliner�r�rstripr�r
r3�environ_from_url�upperrHr�r�rIr�r�rr|)rZruZ
start_lineZis_textZcrlfZcolonr.rI�resourcer&r��lineZhnameZhvalr�r|r5r5r7r2�sL









zBaseRequest.from_filec	s�|jr|j�d�g�g�d���fdd�	}||j|�}�s@�shz��|�Wdt|d�rb|��X�}�r��d�d|�dfS�d�d|fSdS)	a�
        Call the given WSGI application, returning ``(status_string,
        headerlist, app_iter)``

        Be sure to call ``app_iter.close()`` if it's there.

        If catch_exc_info is true, then returns ``(status_string,
        headerlist, app_iter, exc_info)``, where the fourth item may
        be None, but won't be if there was an exception.  If you don't
        do this and there was an exception, the exception will be
        raised directly.
        rNcs,|dk	r�st|�|||g�dd�<�jS)N)rr)�statusr��exc_info)�captured�catch_exc_info�outputr5r7�start_response�sz4BaseRequest.call_application.<locals>.start_response�closer�r�)N)r�r�r�rHr(rUrF)r6�applicationrCrE�app_iterr5)rBrCrDr7�call_application�s


zBaseRequest.call_applicationcCsV|dkr|��}|r.|j|dd�\}}}}~n|j|dd�\}}}|j|t|�|d�S)a�
        Like ``.call_application(application)``, except returns a
        response object with ``.status``, ``.headers``, and ``.body``
        attributes.

        This will use ``self.ResponseClass`` to figure out the class
        of the response object to return.

        If ``application`` is not given, this will send the request to
        ``self.make_default_send_app()``
        NT)rCF)r@Z
headerlistrH)�make_default_send_apprI�
ResponseClass�list)r6rGrCr@r�rHrAr5r5r7�send�szBaseRequest.sendcCs4yt}Wn$tk
r,ddlm}|aYnX|jS)Nr)�client)Z_client�	NameError�webobrNZsend_request_app)r6rNr5r5r7rJs
z!BaseRequest.make_default_send_appcKs,t|�}|r�t�|�\}}	}}
}|
s(|r4td|��|r@||d<|	r�d|	kr||dkr^|	d7}	n|dkrp|	d7}	ntd|��|	�dd	�\}}
|
|d
<||d<|	|d<|r�t|�|d
<|r�|�|�|�d|�d��}|r�d|kr�|d}|dk	r�||d<t|||d�||f|�}|dk	�r(|j	�|�|S)a(
        Create a blank request environ (and Request wrapper) with the
        given path (path should be urlencoded), and any keys from
        environ.

        The path will become path_info, with any query string split
        off and used.

        All necessary keys will be added to the environ, but the
        values you pass in will take precedence.  If you pass in
        base_url then wsgi.url_scheme, HTTP_HOST, and SCRIPT_NAME will
        be filled in from that value.

        Any extra keyword will be passed to ``__init__``.
        z-base_url (%r) cannot have a query or fragmentzwsgi.url_schemer�r�z:80r�z:443zUnknown scheme: %rr�r�r�r�r�rpr�zContent-TypeN)rp)
r<r�urlsplitr3r�rr�r^�environ_add_POSTr�)rZr�rHZbase_urlr�r=rXr�r��netloc�query�fragmentr�r�rp�objr5r5r7�blanksF




zBaseRequest.blank)NNN)N)Nrn)N)F)N)TTTT)F)F)F)NF)NNNN)�r9r:r;rrkr]r
r_rirj�propertyrW�setterrcr�r�r�r��__doc__r�rr�r�r�r�rIr&rrr#r�Zremote_userZremote_addrroZserver_namerZserver_portrr�r��uscript_name�
upath_informr�r�rpr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zurlvarsr�r�r�Zurlargsr�r�r�r�r�r�r�r�r|r�r�r�r�Z	json_bodyr�r�r��textr=r<r�rrrzrr�rr
r�r�rrrrrrr�acceptrZaccept_charsetrZaccept_encodingrZaccept_languagerr!Z
authorizationr r!r"rZ
cache_controlr*r(Zif_matchr)Z
if_none_matchr�dateZif_modified_sinceZif_unmodified_sincer'rr"Zif_rangeZmax_forwardsZpragmar r$�rangeZrefererZreferrerZ
user_agentr8r/r0r1�__str__�classmethodr5r6r8r2rIrKrMZget_responserJrWr5r5r5r7r1fsN
,


	
1











			







8


	










#
	7
$
	c@s*eZdZed�Zed�Zedfdd�ZdS)r3r�r�NcCs.|j�||�}|tkrt|��||kr*|S|S)N)rHr^r_r`)r6rdrerfrgr5r5r7riZszLegacyRequest.encget)r9r:r;r%r[r\r_rir5r5r5r7r3Vsc@s:eZdZdZe�fdd�Ze�fdd�Ze�fdd�ZdS)	�AdhocAttrMixin�cCsBt|j||�|k	s|�d�r,t�|||�n||j�di�|<dS)N�_zwebob.adhoc_attrs)rarRr��object�__setattr__rHr})r6�attrr\�DEFAULTr5r5r7rges
zAdhocAttrMixin.__setattr__cCs0y|jd|Stk
r*t|��YnXdS)Nzwebob.adhoc_attrs)rHr`r�)r6rhrir5r5r7�__getattr__lszAdhocAttrMixin.__getattr__cCsPt|j||�|k	rt�||�Sy|jd|=Wntk
rJt|��YnXdS)Nzwebob.adhoc_attrs)rarRrf�__delattr__rHr`r�)r6rhrir5r5r7rkrszAdhocAttrMixin.__delattr__N)r9r:r;r�rfrgrjrkr5r5r5r7rcbsrcc@seZdZdZdS)r2z$ The default request implementation N)r9r:r;rZr5r5r5r7r2zscCs�t�|�rxt�|�\}}}}}|r.td|��|r>|d|7}d|kr�|dkrX|d7}q�|dkrj|d7}q�td|��nd}d	}|r�d|kr�|�dd
�\}}t|�}nt|�}d}dd|p�d||�d�d
|�d�d
|dd|t��t	j
dddd�}|S)Nz#Path cannot contain a fragment (%r)r�r�r�z:80r�z:443zUnknown scheme: %rzlocalhost:80r�rsr<rzHTTP/1.0)r�rF)r�r�r�rtr�r�r�r�zwsgi.versionzwsgi.url_schemez
wsgi.inputzwsgi.errorszwsgi.multithreadzwsgi.multiprocessz
wsgi.run_once)r�searchrrQrLr�rr�r��sys�stderr)r�r�rSr�rUr�ror�r5r5r7r<}sF



r<cCs.|dkrdSt|t�r |�d�}|ddkr4d|d<d}t|d�rtt|���}x$|D]\}}t|ttf�rTd}PqTW|dkr�|r�d}nd	}|�d�r�t|t	�s�t
||�\}}nD|�d	�r�|r�td
|��t|t	�s�t|�}nt|t	�s�td|��t
|d�}t�|�|d
<d|d<tt|��|d<||d<dS)Nr?r�)r=r>r=FrTTzmultipart/form-dataz!application/x-www-form-urlencodedz4Submiting files is not allowed for content type `%s`z:Please provide `POST` data as string for content type `%s`r�z
wsgi.inputzwebob.is_body_seekablerqr�)r�rr�rUr'rT�tuplerLr�r��_encode_multipartr3rrr�r�r�r�)r�rrpZ	has_filesr,r-r5r5r7rR�sD









rRc@seZdZdS)rN)r9r:r;r5r5r5r7r�src@s8eZdZdd�Zdd�Zdd�Zedd��Zd	d
�ZdS)r�cCs||_||_||_dS)N)�file�maxlen�	remaining)r6rqrrr5r5r7r]�szLimitedLengthFile.__init__cCsd|jj|j|jfS)Nz<%s(%r, maxlen=%s)>)rRr9rqrr)r6r5r5r7r8�szLimitedLengthFile.__repr__cCs
|j��S)N)rq�fileno)r6r5r5r7rt�szLimitedLengthFile.filenocCsdS)NTr5r5r5r5r7�readable�szLimitedLengthFile.readablecCsl|js
dStt|�|j�}|j�|�}t|�}|j|8_||kr\|jr\tdd|j��||d|�<|S)Nrz8The client disconnected while sending the POST/PUT body z(%d more bytes were expected))rsrr�rqr�r)r6�buffZsz0r�szr5r5r7�readinto�szLimitedLengthFile.readintoN)	r9r:r;r]r8rt�staticmethodrurxr5r5r5r7r��s
r�cCs*|jrd|j|jfSd|j|j|jfS)z� monkey patch for FieldStorage.__repr__

    Unbelievably, the default __repr__ on FieldStorage reads
    the entire file content instead of being sane about it.
    This is a simple replacement that doesn't do that
    zFieldStorage(%r, %r)zFieldStorage(%r, %r, %r))rqr[�filenamer\)r6r5r5r7�_cgi_FieldStorage__repr__patch�sr{c@s8eZdZdd�Zdd�Zdd�Zedd��Zd	d
�ZdS)r�cCs4|�d�rt|�std|��||_||_d|_dS)Nzmultipart/form-dataz*Content-type: %r does not contain boundary)r��_get_multipart_boundaryr3r�rprq)r6r�rpr5r5r7r]s
zFakeCGIBody.__init__cCsLt|j�}t|�dkr2|dd�d|dd�}d|jjtt|��|fS)N��z...���z<%s at 0x%x viewing %s>)�reprr�r�rRr9r#r$)r6�innerr5r5r7r8s
zFakeCGIBody.__repr__cCsdS)Nr5)r6r5r5r7rtszFakeCGIBody.filenocCsdS)NTr5r5r5r5r7ru szFakeCGIBody.readablecCs�|jdkr�|j�d�rBd�dd�|j��D��}t�t|��|_nL|j�d�r|t	|j��|jt��d�d|_|j�
d�nds�td	|j��|j�|�S)
Nz!application/x-www-form-urlencoded�&css2|]*\}}dtt|d��tt|d��fVqdS)z%s=%sr�N)rr)�.0r,r-r5r5r7�	<genexpr>)sz'FakeCGIBody.readinto.<locals>.<genexpr>zmultipart/form-data)r�r�rzBad content type: %r)
rqrpr�r)r�rTr�r�rrpr�r
rx)r6rvrr5r5r7rx$s 

zFakeCGIBody.readintoN)	r9r:r;r]r8rtryrurxr5r5r5r7r�s
	r�cCs,t�d|tj�}|r(t|�d��d��SdS)Nzboundary=([^ ]+)r��")r�rl�Ir
�groupr�)r��mr5r5r7r|9sr|c
s�|p
t����j}�fdd�}d}t|�}|sNtt�t�d���}|d|7}�xp|D�]f\}}|d�||�||�|dk	s�t	d|��|d	|�d}	t
|d
d�r�|j}	n(t|t
tf�r�|\}	}t|d�r�|��}|	dk	r�|d|	�t�|	�d
}
nd}
||�t
|dd��rd|d|j�|j�rZx,t|j���D]\}}|d||f��q<W||�n|
�r~|d|
�||�||�t|d��r�|j}t|t��r�||�n||�||�qVW|d|�|�r�||fS|���fSdS)z-Encode a multipart request body into a stringcs��|�d��S)Nr�)rr�)r�)rr5r7�<lambda>Cr�z#_encode_multipart.<locals>.<lambda>s
�
z
; boundary=%ss--Nz!Value associated with no name: %rz)Content-Disposition: form-data; name="%s"rzr�z; filename="%s"rrJzContent-type: %sz	; %s="%s"r\z--%s--)r�r�rr|r
�binascii�hexlify�os�urandomr
rarzr�rLrorUr��	mimetypesZ
guess_typerJZtype_optionsr'rTr\r��getvalue)
r�rpr��w�wt�CRLF�boundaryr[r\rzZ	mime_typeZct_nameZct_valuer5)rr7rp?s\


rpcCs&t�|�}|r"|�d��d���SdS)Nr�r�)rrlr�r�)r�r�r5r5r7rlws
rlcCs |sdS|���dd�dkSdS)NT�-rsr�)�lower�replace)rWr5r5r7rP|srPc@s&eZdZd	dd�Zdd�Zdd�ZdS)
rxrncs �|_�|_��fdd�|_dS)Ncs|�����d�S)Nr�)rcr�)r4)rWrwr5r7r��r�z%Transcoder.__init__.<locals>.<lambda>)rWrw�_trans)r6rWrwr5)rWrwr7r]�szTranscoder.__init__csntr,|}d|kr|Stt||j��}t|�S|}d|kr<|St�||j�}|j��fdd�|D�}t|�SdS)N�=cs g|]\}}�|��|�f�qSr5r5)r�r,r-)r�r5r7�
<listcomp>�sz.Transcoder.transcode_query.<locals>.<listcomp>)r
rLrrWrr�	parse_qslr�)r6�qZq_origr5)r�r7r{�szTranscoder.transcode_querycs�trdd�}n�fdd�}g}xX|jp(dD]J}||j�|_|jr^||j�|_|�|j|f�q*|�|j||j�f�q*Wt||t��d�\}}|S)NcSs|S)Nr5)r4r5r5r7r��r�z)Transcoder.transcode_fs.<locals>.<lambda>cs|��j�j�S)N)rcrWrw)r4)r6r5r7r��r�r5)r�)	r
rLr[rzrr\rpr�r�)r6r�rprcr�fieldr�r5)r6r7r��s
zTranscoder.transcode_fsN)rn)r9r:r;r]r{r�r5r5r5r7rx�s
rxzGET POST params cookiesZstr_z+disabled starting WebOb 1.2, use %s insteadz1.2)N)N)fr�r~r�r�r�rmrr�Z
simplejsonr��ImportErrorrMZwebob.acceptparserrrrrrZwebob.cachecontrolrr	Zwebob.compatr
rrr
rrrrrrrrZ
webob.cookiesrZwebob.descriptorsrrrrrrrrrr r!r"r#r$r%r&Z
webob.etagr'r(r)r*Z
webob.headersr+Zwebob.multidictr,r-r.r/Z
webob.utilr0�__all__r4r_r�rK�fromkeysr�r�rbrfr1r3rcr2r<rR�IOErrorr�	RawIOBaser�r{rr8r�r|rprlrPrxr��_nameZ	_str_nameZ_proprVr5r5r5r7�<module>sz 	8H
y,
,%.
80