ó æöYc@@sfdZddlmZddlmZmZd„Zd„Zd„Ze e e d„Z d„Z d S( sĆ This module implements WSGI related helpers adapted from ``werkzeug.wsgi`` :copyright: (c) 2010 by the Werkzeug Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. i(tabsolute_import(t iteritemst urllib_quotecc@s˜x‘t|ƒD]ƒ\}}t|ƒ}|jdƒrd|d krd|djddƒjƒ|fVq |d kr |jddƒjƒ|fVq q Wd S( s+ Returns only proper HTTP headers. tHTTP_tHTTP_CONTENT_TYPEtHTTP_CONTENT_LENGTHit_t-t CONTENT_TYPEtCONTENT_LENGTHN(RR(RR (Rtstrt startswithtreplacettitle(tenvirontkeytvalue((sA/opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyt get_headers s  $ cc@s3x,dD]$}||kr|||fVqqWdS(s8 Returns our whitelisted environment variables. t REMOTE_ADDRt SERVER_NAMEt SERVER_PORTN(RRR((RR((sA/opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyt get_environs  cC@sÖ|jdƒ}d|kr(|d}nZd|krA|d}nA|d}|t|dƒfddfkr‚|d |d7}n|jd ƒrŖ|dkrŖ|d }n(|jd ƒrŅ|dkrŅ|d }n|S(s®Return the real host for the given WSGI environment. This takes care of the `X-Forwarded-Host` header. :param environ: the WSGI environment to get the host of. swsgi.url_schemetHTTP_X_FORWARDED_HOSTt HTTP_HOSTRRthttpst443thttpt80t:s:80iż’’’s:443iü’’’(RR(RR(tgetR tendswith(Rtschemetresult((sA/opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pytget_host$s       cC@sÖ|ddt|ƒg}|j}|r9dj|ƒdS|t|jddƒjdƒƒƒ|rq|dƒnX|td|jddƒjdƒƒƒ|sÉ|jdƒ}|rÉ|d|ƒqÉndj|ƒS( s3A handy helper function that recreates the full URL for the current request or parts of it. Here an example: >>> from werkzeug import create_environ >>> env = create_environ("/?param=foo", "http://localhost/script") >>> get_current_url(env) 'http://localhost/script/?param=foo' >>> get_current_url(env, root_only=True) 'http://localhost/script/' >>> get_current_url(env, host_only=True) 'http://localhost/' >>> get_current_url(env, strip_querystring=True) 'http://localhost/script/' :param environ: the WSGI environment to get the current URL from. :param root_only: set `True` if you only want the root URL. :param strip_querystring: set to `True` if you don't want the querystring. :param host_only: set to `True` if the host URL should be returned. swsgi.url_schemes://tt/t SCRIPT_NAMEt PATH_INFOt QUERY_STRINGt?(R!tappendtjoinRRtrstriptlstrip(Rt root_onlytstrip_querystringt host_onlyttmptcattqs((sA/opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pytget_current_url<s % )cC@sGy|djdƒdjƒSWn!ttfk rB|jdƒSXdS(sÕ Naively yank the first IP address in an X-Forwarded-For header and assume this is correct. Note: Don't use this in security sensitive situations since this value may be forged from a client. tHTTP_X_FORWARDED_FORt,iRN(tsplittstriptKeyErrort IndexErrorR(R((sA/opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyt get_client_ipasN( t__doc__t __future__Rtraven.utils.compatRRRRR!tFalseR2R9(((sA/opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyts  $