Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/raven/utils/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/raven/utils/__pycache__/wsgi.cpython-35.pyc



��Y��@sudZddlmZddlmZmZdd�Zdd�Zdd	�Zd
d
d
dd�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_quoteccs�x�t|�D]�\}}t|�}|jd�rj|d
krj|dd�jdd�j�|fVq
|dkr
|jdd�j�|fVq
WdS)z+
    Returns only proper HTTP headers.
    ZHTTP_�HTTP_CONTENT_TYPE�HTTP_CONTENT_LENGTH�N�_�-�CONTENT_TYPE�CONTENT_LENGTH)rr)r
r)r�str�
startswith�replace�title)�environ�key�value�r�A/opt/alt/python35/lib/python3.5/site-packages/raven/utils/wsgi.py�get_headers
s	*rccs0x)dD]!}||kr|||fVqWdS)z8
    Returns our whitelisted environment variables.
    �REMOTE_ADDR�SERVER_NAME�SERVER_PORTN)rrrr)rrrrr�get_environs
rcCs�|jd�}d|kr(|d}nQd|krA|d}n8|d}|t|d�fdkry|d
|d7}|jd�r�|dkr�|dd�}n+|jd�r�|dkr�|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�https�443�http�80�:z:80N�z:443��rr�rr)r!r"������)�getr�endswith)r�scheme�resultrrr�get_host$s


	r)FcCs�|ddt|�g}|j}|r9dj|�dS|t|jdd�jd���|rq|d�nR|td|jdd�jd���|s�|jd�}|r�|d|�dj|�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://��/ZSCRIPT_NAMEZ	PATH_INFOZQUERY_STRING�?)r)�append�joinrr%�rstrip�lstrip)rZ	root_onlyZstrip_querystringZ	host_only�tmp�cat�qsrrr�get_current_url<s	%
)r4cCsKy|djd�dj�SWn%ttfk
rF|jd�SYnXdS)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%)rrrr�
get_client_ipasr:N)�__doc__�
__future__rZraven.utils.compatrrrrr)r4r:rrrr�<module>s

$