• File: request.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/proc/self/root/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyc
  • Date Modified: 08/01/2016 7:39 PM
  • File size: 13.61 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

aNc	@sdZddlZddlmZmZddlmZddlZddlZyddlm	Z	Wn!e
k
rddlm	Z	nXddlm
Z
ddd	d
ddd
ddg	ZdZdZdZdZedZeeddddZdZdZdZidd6dd6dd6ZdZde	fd YZd!Zeej_e d"krddl!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)

iN(tSimpleCookietCookieError(tStringIO(t	DictMixin(t	MultiDicttget_cookiestget_cookie_dicttparse_querystringtparse_formvarst
construct_urltpath_info_splitt
path_info_poptresolve_relative_urltEnvironHeaderscCs|jdd}|jdrD|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|jdrK|d\}}||krK|Snt}y|j|Wntk
rxnXi}x|D]}||j||<qW||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}|stSd|krN|d\}}||krN|Sntj|dtdt}t|}||f|d<|S(sParses 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|jddj}d|kr|jddd}n|dk}|jd
sd|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
trxr|jD]a}
||
}t	|ts|g}nx3|D]+}|j
s|j
}n|j|
|qWqWn||f|d<|r(|jt|n|S(sParses 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.pyRsX
	




	


	

	c	Cs|dd}|jdr|d}d}d|kr|jdd\}}|ddkry|dkrd}qq|ddkr|d	krd}qqn||7}|r3|d
|7}q3nk||d7}|ddkr|ddkr3|d|d7}q3n%|dd	kr3|d|d7}n|dkra|tj|jd
d7}n|tj|7}|r|dkr|tj|jdd7}q|tj|7}n|r|dkr|jdr|d|d7}qq|r|d|7}qn|S(sReconstructs 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	cCsx|s
dS|jds)td||jd}d|krj|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/s!PATH_INFO should start with /: %riN(NR(RIt
startswithtAssertionErrortlstripR-(ROtfirsttrest((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR
s
cCs|jdd}|sdSx-|jdrK|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(RRIRXR-(Rtpathtsegment((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyRs
t
AuthorizationtHTTP_CGI_AUTHORIZATIONsContent-LengthR(sContent-TypeR&ccsrxk|jD]]\}}|tkr7t||fVq
|jdr
|djjdd|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_specialRXttitletreplace(Rtcgi_varR((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt
parse_headersHs
cBs_eZdZdZdZdZdZdZdZdZ	dZ
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|jddj}|dkr1d}n|dkrFd}n|S(NRaRcRbtHTTP_CONTENT_LENGTHR(tHTTP_CONTENT_TYPER&(Rgtupper(RjRtkey((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt_trans_namebs		cCsQ|dkrdS|dkr dS|jdrI|djddjSdSdS(	NR&sContent-TypeR(sContent-LengthRaiRbRc(RXRgRfRI(RjRo((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt
_trans_keyjscCs|j|j|S(N(RRp(Rjtitem((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__getitem__tscCs||j|j|<dS(N(RRp(RjRrR((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__setitem__wscCs|j|j|=dS(N(RRp(RjRr((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__delitem__{sccs;x4|jD])}|j|}|dk	r
|Vq
q
WdS(N(RRqRI(RjRoR((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__iter__~scCstt|S(N(R0titer(Rj((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyR1scCs|j||jkS(N(RpR(RjRr((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt__contains__s(t__name__t
__module__t__doc__RkRpRqRsRtRuRvR1Rx(((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(Rj((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt_cgi_FieldStorage__repr__patchs
	t__main__(#R{RtCookieRRRRTRJtUserDictRtImportErrortpaste.util.UserDict24tpaste.util.multidictRt__all__RRRR%RRRIR	RR
RReRiR
R}R.t__repr__Rytdoctestttestmod(((s>/opt/alt/python27/lib/python2.7/site-packages/paste/request.pyt<module>sD
						 @1			(
	6