???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................ó
æöYc           @@  sf   d  Z  d d l m Z d d l m Z m Z d   Z d   Z d   Z e	 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    (   t   absolute_import(   t	   iteritemst   urllib_quotec         c@  s   x t  |   D] \ } } t |  } | j d  rd | d
 k rd | d j d d  j   | f Vq | d k r | j d d  j   | f Vq q Wd	 S(   s+   
    Returns only proper HTTP headers.
    t   HTTP_t   HTTP_CONTENT_TYPEt   HTTP_CONTENT_LENGTHi   t   _t   -t   CONTENT_TYPEt   CONTENT_LENGTHN(   R   R   (   R   R	   (   R   t   strt
   startswitht   replacet   title(   t   environt   keyt   value(    (    sA   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyt   get_headers   s    	$c         c@  s3   x, d D]$ } | |  k r | |  | f Vq q Wd S(   s8   
    Returns our whitelisted environment variables.
    t   REMOTE_ADDRt   SERVER_NAMEt   SERVER_PORTN(   R   R   R   (    (   R   R   (    (    sA   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyt   get_environ   s    c         C@  sÖ   |  j  d  } d |  k r( |  d } nZ d |  k rA |  d } nA |  d } | t |  d  f d d f k r | d
 |  d 7} n  | j d  rŖ | d k rŖ | d  } n( | j d  rŅ | d k rŅ | 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.
    s   wsgi.url_schemet   HTTP_X_FORWARDED_HOSTt	   HTTP_HOSTR   R   t   httpst   443t   httpt   80t   :s   :80iż’’’s   :443iü’’’(   R   R   (   R   R   (   t   getR
   t   endswith(   R   t   schemet   result(    (    sA   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyt   get_host$   s    
c         C@  sÖ   |  d d t  |   g } | j } | r9 d j |  d S| t |  j d d  j d    | rq | d  nX | t d |  j d d  j d    | sÉ |  j d  } | rÉ | d |  qÉ n  d j |  S(	   s3  A 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.
    s   wsgi.url_schemes   ://t    t   /t   SCRIPT_NAMEt	   PATH_INFOt   QUERY_STRINGt   ?(   R!   t   appendt   joinR   R   t   rstript   lstrip(   R   t	   root_onlyt   strip_querystringt	   host_onlyt   tmpt   catt   qs(    (    sA   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyt   get_current_url<   s    	%)c         C@  sG   y |  d j  d  d j   SWn! t t f k
 rB |  j d  SXd S(   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.
    t   HTTP_X_FORWARDED_FORt   ,i    R   N(   t   splitt   stript   KeyErrort
   IndexErrorR   (   R   (    (    sA   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyt   get_client_ipa   s    N(   t   __doc__t
   __future__R    t   raven.utils.compatR   R   R   R   R!   t   FalseR2   R9   (    (    (    sA   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/wsgi.pyt   <module>   s   		
	$