%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/paste/
Upload File :
Create Path :
Current File : //proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyo

�
a�Nc	@s�dZddlZddlmZmZddlmZddlZddlZyddlm	Z	Wn!e
k
r�ddlm	Z	nXddlm
Z
ddd	d
ddd
ddg	Zd�Zd�Zd�Zd�Zed�Zeedddd�Zd�Zd�Zd�Zidd6dd6dd6Zd�Zde	fd ��YZd!�Zeej_e d"kr�ddl!Z!e!j"�ndS(#s�
This module provides helper routines with work directly on a WSGI
environment to solve common requirements.

   * get_cookies(environ)
   * parse_querystring(environ)
   * parse_formvars(environ, include_get_vars=True)
   * construct_url(environ, with_query_string=True, with_path_info=True,
                   script_name=None, path_info=None, querystring=None)
   * path_info_split(path_info)
   * path_info_pop(environ)
   * resolve_relative_url(url, environ)

i����N(tSimpleCookietCookieError(tStringIO(t	DictMixin(t	MultiDicttget_cookiestget_cookie_dicttparse_querystringtparse_formvarst
construct_urltpath_info_splitt
path_info_poptresolve_relative_urltEnvironHeaderscCs�|jdd�}|jd�rD|d\}}||krD|Snt�}y|j|�Wntk
rqnX||f|d<|S(s�
    Gets a cookie object (which is a dictionary-like object) from the
    request environment; caches this value in case get_cookies is
    called again for the same request.

    tHTTP_COOKIEts
paste.cookies(tgetthas_keyRtloadR(tenvirontheadertcookiestcheck_header((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR#s	
cCs�|jd�}|siS|jd�rK|d\}}||krK|Snt�}y|j|�Wntk
rxnXi}x|D]}||j||<q�W||f|d<|S(s#Return a *plain* dictionary of cookies as found in the request.

    Unlike ``get_cookies`` this returns a dictionary, not a
    ``SimpleCookie`` object.  For incoming cookies a dictionary fully
    represents the information.  Like ``get_cookies`` this caches and
    checks the cache.
    Rspaste.cookies.dict(RRRRRtvalue(RRRRtresulttname((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR7s"	

cCsz|jdd�}|sgSd|krK|d\}}||krK|Sntj|dtdt�}||f|d<|S(s<
    Parses a query string into a list like ``[(name, value)]``.
    Caches this value in case parse_querystring is called again
    for the same request.

    You can pass the result to ``dict()``, but be aware that keys that
    appear multiple times will be lost (only the last value will be
    preserved).

    tQUERY_STRINGRspaste.parsed_querystringtkeep_blank_valueststrict_parsing(Rtcgit	parse_qsltTruetFalse(Rtsourcetparsedtcheck_source((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyRQs	cCs�|jdd�}|st�Sd|krN|d\}}||krN|Sntj|dtdt�}t|�}||f|d<|S(s�Parses a query string like parse_querystring, but returns a MultiDict

    Caches this value in case parse_dict_querystring is called again
    for the same request.

    Example::

        >>> environ = {'QUERY_STRING': 'day=Monday&user=fred&user=jane'}
        >>> parsed = parse_dict_querystring(environ)

        >>> parsed['day']
        'Monday'
        >>> parsed['user']
        'fred'
        >>> parsed.getall('user')
        ['fred', 'jane']

    RRspaste.parsed_dict_querystringRR(RRRRRR (RR!R"R#tmulti((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pytparse_dict_querystringhs	cCs,|d}d|krU|d\}}||krU|rN|jt|��n|Sn|jdd�j�}d|kr�|jdd�d}n|dk}|jd
�s�d|d
<n|jdd�}d|d<|rtd�}|jd�}	|jd
�}
d|d
<d|d<n
|d}tjd
|d|dd�}||d<|rl|	|d<|
|d
<nt�}t	|j
t�r�xr|j�D]a}
||
}t	|t�s�|g}nx3|D]+}|j
s�|j
}n|j|
|�q�Wq�Wn||f|d<|r(|jt|��n|S(s�Parses the request, returning a MultiDict of form variables.

    If ``include_get_vars`` is true then GET (query string) variables
    will also be folded into the MultiDict.

    All values should be strings, except for file uploads which are
    left as ``FieldStorage`` instances.

    If the request was not a normal form request (e.g., a POST with an
    XML body) then ``environ['wsgi.input']`` won't be read.
    s
wsgi.inputspaste.parsed_formvarstCONTENT_TYPERt;iis!application/x-www-form-urlencodedsmultipart/form-datatCONTENT_LENGTHt0RtfpRR(Rs!application/x-www-form-urlencodedsmultipart/form-data(tupdateRRtlowertsplitRRtFieldStorageRt
isinstanceRtlisttkeystfilenametadd(Rtinclude_get_varsR!R"R#ttypetfake_out_cgitold_query_stringtinputtold_content_typetold_content_lengthtfstformvarsRtvaluesR((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR�sX
	




	


	

	c	Cs|dd}|jd�r�|d}d}d|kr�|jdd�\}}|ddkry|dkr�d}q�q�|ddkr�|d	kr�d}q�q�n||7}|r3|d
|7}q3nk||d7}|ddkr|ddkr3|d|d7}q3n%|dd	kr3|d|d7}n|dkra|tj|jd
d��7}n|tj|�7}|r�|dkr�|tj|jdd��7}q�|tj|�7}n|r|dkr�|jd�r|d|d7}qq|r|d|7}qn|S(s�Reconstructs the URL from the WSGI environment.

    You may override SCRIPT_NAME, PATH_INFO, and QUERYSTRING with
    the keyword arguments.

    swsgi.url_schemes://t	HTTP_HOSTt:ithttpst443thttpt80s:%stSERVER_NAMEtSERVER_PORTtSCRIPT_NAMERt	PATH_INFORt?N(RtNoneR-turllibtquote(	Rtwith_query_stringtwith_path_infotscript_namet	path_infotquerystringturlthosttport((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR	�sF

""cCs"t|dt�}tj||�S(s

    Resolve the given relative URL as being relative to the
    location represented by the environment.  This can be used
    for redirecting to a relative path.  Note: if url is already
    absolute, this function will (intentionally) have no effect
    on it.

    RL(R	R turlparseturljoin(RQRtcur_url((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR�s	cCsY|s
dS|jd�}d|krK|jdd�\}}|d|fS|dfSdS(s
    Splits off the first segment of the path.  Returns (first_part,
    rest_of_path).  first_part can be None (if PATH_INFO is empty), ''
    (if PATH_INFO is '/'), or a name without any /'s.  rest_of_path
    can be '' or a string starting with /.

    Rt/iN(NR(RItlstripR-(ROtfirsttrest((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR
scCs�|jdd�}|sdSx-|jd�rK|dcd7<|d}qWd|krv|dc|7<d|d<|S|jdd�\}}d||d<|dc|7<|SdS(s�
    'Pops' off the next segment of PATH_INFO, pushing it onto
    SCRIPT_NAME, and returning that segment.

    For instance::

        >>> def call_it(script_name, path_info):
        ...     env = {'SCRIPT_NAME': script_name, 'PATH_INFO': path_info}
        ...     result = path_info_pop(env)
        ...     print 'SCRIPT_NAME=%r; PATH_INFO=%r; returns=%r' % (
        ...         env['SCRIPT_NAME'], env['PATH_INFO'], result)
        >>> call_it('/foo', '/bar')
        SCRIPT_NAME='/foo/bar'; PATH_INFO=''; returns='bar'
        >>> call_it('/foo/bar', '')
        SCRIPT_NAME='/foo/bar'; PATH_INFO=''; returns=None
        >>> call_it('/foo/bar', '/')
        SCRIPT_NAME='/foo/bar/'; PATH_INFO=''; returns=''
        >>> call_it('', '/1/2/3')
        SCRIPT_NAME='/1'; PATH_INFO='/2/3'; returns='1'
        >>> call_it('', '//1/2')
        SCRIPT_NAME='//1'; PATH_INFO='/2'; returns='1'

    RGRRWRFiN(RRIt
startswithR-(Rtpathtsegment((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyRs
t
AuthorizationtHTTP_CGI_AUTHORIZATIONsContent-LengthR(sContent-TypeR&ccsrxk|j�D]]\}}|tkr7t||fVq
|jd�r
|dj�jdd�|fVq
q
WdS(s�
    Parse the headers in the environment (like ``HTTP_HOST``) and
    yield a sequence of those (header_name, value) tuples.
    tHTTP_it_t-N(t	iteritemst_parse_headers_specialR[ttitletreplace(Rtcgi_varR((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt
parse_headersHs
cBs_eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�ZRS(
sgAn object that represents the headers as present in a
    WSGI environment.

    This object is a wrapper (with no internal state) for a WSGI
    request object, representing the CGI-style HTTP_* keys as a
    dictionary.  Because a CGI environment can only hold one value for
    each key, this dictionary is single-valued (unlike outgoing
    headers).
    cCs
||_dS(N(R(tselfR((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__init___scCsJd|jdd�j�}|dkr1d}n|dkrFd}n|S(NR`RbRatHTTP_CONTENT_LENGTHR(tHTTP_CONTENT_TYPER&(Rftupper(RiRtkey((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt_trans_namebs		cCsQ|dkrdS|dkr dS|jd�rI|djdd�j�SdSdS(	NR&sContent-TypeR(sContent-LengthR`iRaRb(R[RfReRI(RiRn((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt
_trans_keyjscCs|j|j|�S(N(RRo(Rititem((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__getitem__tscCs||j|j|�<dS(N(RRo(RiRqR((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__setitem__wscCs|j|j|�=dS(N(RRo(RiRq((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__delitem__{sccs;x4|jD])}|j|�}|dk	r
|Vq
q
WdS(N(RRpRI(RiRnR((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__iter__~scCstt|��S(N(R0titer(Ri((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR1�scCs|j|�|jkS(N(RoR(RiRq((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__contains__�s(t__name__t
__module__t__doc__RjRoRpRrRsRtRuR1Rw(((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR
Ts				
					cCs7|jrd|j|jfSd|j|j|jfS(s� monkey patch for FieldStorage.__repr__

    Unbelievely, 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
    sFieldStorage(%r, %r)sFieldStorage(%r, %r, %r)(tfileRR2R(Ri((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt_cgi_FieldStorage__repr__patch�s
	t__main__(#RzRtCookieRRRRTRJtUserDictRtImportErrortpaste.util.UserDict24tpaste.util.multidictRt__all__RRRR%RRRIR	RR
RRdRhR
R|R.t__repr__Rxtdoctestttestmod(((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt<module>sD
						 @1			(
	6	


Zerion Mini Shell 1.0