B ¿öY“ã@sNdZddlmZddlmZmZdd„Zdd„Zdd „Zdd d „Z d d„Z dS)zà 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. é)Úabsolute_import)Ú iteritemsÚ urllib_quoteccsrxlt|ƒD]`\}}t|ƒ}| d¡rL|dkrL|dd… dd¡ ¡|fVq |dkr | dd¡ ¡|fVq WdS)z+ Returns only proper HTTP headers. ZHTTP_)ZHTTP_CONTENT_TYPEZHTTP_CONTENT_LENGTHéNÚ_ú-)Z CONTENT_TYPEZCONTENT_LENGTH)rÚstrÚ startswithÚreplaceÚtitle)ÚenvironÚkeyÚvalue©rúA/opt/alt/python37/lib/python3.7/site-packages/raven/utils/wsgi.pyÚ get_headers s  rccs(x"dD]}||kr|||fVqWdS)z8 Returns our whitelisted environment variables. )Ú REMOTE_ADDRÚ SERVER_NAMEÚ SERVER_PORTNr)r r rrrÚ get_environs rcCsœ| d¡}d|kr|d}n>d|kr.|d}n,|d}|t|dƒfdkrZ|d|d7}| d¡rz|d krz|d d …}n| d ¡r˜|d kr˜|d d…}|S)z®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. zwsgi.url_schemeZHTTP_X_FORWARDED_HOSTZ HTTP_HOSTrr))ÚhttpsZ443)ÚhttpZ80ú:z:80rNéýÿÿÿz:443réüÿÿÿ)ÚgetrÚendswith)r ÚschemeÚresultrrrÚget_host$s    rFcCs˜|ddt|ƒg}|j}|r*d |¡dS|t| dd¡ d¡ƒƒ|rR|dƒn<|td| dd¡ d¡ƒƒ|sŽ| d¡}|rŽ|d|ƒd |¡S) a3A 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. zwsgi.url_schemez://Úú/Z SCRIPT_NAMEZ PATH_INFOZ QUERY_STRINGú?)rÚappendÚjoinrrÚrstripÚlstrip)r Z root_onlyZstrip_querystringZ host_onlyÚtmpÚcatÚqsrrrÚget_current_url<s   r*c Cs:y|d d¡d ¡Sttfk r4| d¡SXdS)zÕ 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. ZHTTP_X_FORWARDED_FORú,rrN)ÚsplitÚstripÚKeyErrorÚ IndexErrorr)r rrrÚ get_client_ipasr0N)FFF) Ú__doc__Ú __future__rZraven.utils.compatrrrrrr*r0rrrrÚs    $