ó
`¾Tc           @   s!  d  Z  d d l Z y d d l m Z Wn! e k
 rI d d l m Z n Xd d l m Z d d l m	 Z	 d d l
 m Z m Z d d l m Z d „  Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sŒ  
    werkzeug.contrib.wrappers
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Extra wrappers or mixins contributed by the community.  These wrappers can
    be mixed in into request objects to add extra functionality.

    Example::

        from werkzeug.wrappers import Request as RequestBase
        from werkzeug.contrib.wrappers import JSONRequestMixin

        class Request(RequestBase, JSONRequestMixin):
            pass

    Afterwards this request object provides the extra functionality of the
    :class:`JSONRequestMixin`.

    :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t   loads(   t
   BadRequest(   t   cached_property(   t   dump_options_headert   parse_options_header(   t   wsgi_decoding_dancec         C   s*   y t  j |  ƒ Wn t k
 r% t SXt S(   s/   Checks if the given charset is known to Python.(   t   codecst   lookupt   LookupErrort   Falset   True(   t   charset(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   is_known_charset#   s
    t   JSONRequestMixinc           B   s   e  Z d  Z e d „  ƒ Z RS(   sü   Add json method to a request object.  This will parse the input data
    through simplejson if possible.

    :exc:`~werkzeug.exceptions.BadRequest` will be raised if the content-type
    is not json or if the data itself cannot be parsed as json.
    c         C   s_   d |  j  j d d ƒ k r* t d ƒ ‚ n  y t |  j ƒ SWn t k
 rZ t d ƒ ‚ n Xd S(   s/   Get the result of simplejson.loads if possible.t   jsont   CONTENT_TYPEt    s   Not a JSON requests   Unable to read JSON requestN(   t   environt   getR   R    t   datat	   Exception(   t   self(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyR   4   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyR   ,   s   t   ProtobufRequestMixinc           B   s   e  Z d  Z e Z d „  Z RS(   sD  Add protobuf parsing method to a request object.  This will parse the
    input data through `protobuf`_ if possible.

    :exc:`~werkzeug.exceptions.BadRequest` will be raised if the content-type
    is not protobuf or if the data itself cannot be parsed property.

    .. _protobuf: http://code.google.com/p/protobuf/
    c         C   s   d |  j  j d d ƒ k r* t d ƒ ‚ n  | ƒ  } y | j |  j ƒ Wn t k
 rf t d ƒ ‚ n X|  j rŒ | j ƒ  rŒ t d ƒ ‚ n  | S(   s.   Parse the data into an instance of proto_type.t   protobufR   R   s   Not a Protobuf requests    Unable to parse Protobuf requests   Partial Protobuf request(   R   R   R   t   ParseFromStringR   R   t   protobuf_check_initializationt   IsInitialized(   R   t
   proto_typet   obj(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   parse_protobufO   s    	(   R   R   R   R
   R   R    (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyR   ?   s   t   RoutingArgsRequestMixinc           B   sh   e  Z d  Z d „  Z d „  Z e e e d d ƒZ [ [ d „  Z d „  Z e e e d d ƒZ	 [ [ RS(   s¤   This request mixin adds support for the wsgiorg routing args
    `specification`_.

    .. _specification: http://www.wsgi.org/wsgi/Specifications/routing_args
    c         C   s   |  j  j d d ƒ d S(   Ns   wsgiorg.routing_argsi    (    (   R   R   (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   _get_routing_argsh   s    c         C   s2   |  j  r t d ƒ ‚ n  | |  j f |  j d <d  S(   Nso   A shallow request tried to modify the WSGI environment.  If you really want to do that, set `shallow` to False.s   wsgiorg.routing_args(   t   shallowt   RuntimeErrort   routing_varsR   (   R   t   value(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   _set_routing_argsk   s    	t   docs1   
        The positional URL arguments as `tuple`.c         C   sE   |  j  j d ƒ } | d  k	 r& | d Si  } |  j sA | |  _ n  | S(   Ns   wsgiorg.routing_argsi   (   R   R   t   NoneR#   R%   (   R   t   rv(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   _get_routing_varsv   s    	c         C   s2   |  j  r t d ƒ ‚ n  |  j | f |  j d <d  S(   Nso   A shallow request tried to modify the WSGI environment.  If you really want to do that, set `shallow` to False.s   wsgiorg.routing_args(   R#   R$   t   routing_argsR   (   R   R&   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   _set_routing_vars   s    	s-   
        The keyword URL arguments as `dict`.(
   R   R   R   R"   R'   t   propertyR,   R+   R-   R%   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyR!   a   s   							t    ReverseSlashBehaviorRequestMixinc           B   s,   e  Z d  Z e d „  ƒ Z e d „  ƒ Z RS(   só  This mixin reverses the trailing slash behavior of :attr:`script_root`
    and :attr:`path`.  This makes it possible to use :func:`~urlparse.urljoin`
    directly on the paths.

    Because it changes the behavior or :class:`Request` this class has to be
    mixed in *before* the actual request class::

        class MyRequest(ReverseSlashBehaviorRequestMixin, Request):
            pass

    This example shows the differences (for an application mounted on
    `/application` and the request going to `/application/foo/bar`):

        +---------------+-------------------+---------------------+
        |               | normal behavior   | reverse behavior    |
        +===============+===================+=====================+
        | `script_root` | ``/application``  | ``/application/``   |
        +---------------+-------------------+---------------------+
        | `path`        | ``/foo/bar``      | ``foo/bar``         |
        +---------------+-------------------+---------------------+
    c         C   s7   t  |  j j d ƒ p d |  j |  j ƒ } | j d ƒ S(   s–   Requested path as unicode.  This works a bit like the regular path
        info in the WSGI environment but will not include a leading slash.
        t	   PATH_INFOR   t   /(   R   R   R   R   t   encoding_errorst   lstrip(   R   t   path(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyR4   ¢   s    c         C   s;   t  |  j j d ƒ p d |  j |  j ƒ } | j d ƒ d S(   s8   The root path of the script includling a trailing slash.t   SCRIPT_NAMER   R1   (   R   R   R   R   R2   t   rstrip(   R   R4   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   script_root«   s    (   R   R   R   R   R4   R7   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyR/   ‹   s   	t   DynamicCharsetRequestMixinc           B   s,   e  Z d  Z d Z d „  Z e d „  ƒ Z RS(   s¤  "If this mixin is mixed into a request class it will provide
    a dynamic `charset` attribute.  This means that if the charset is
    transmitted in the content type headers it's used from there.

    Because it changes the behavior or :class:`Request` this class has
    to be mixed in *before* the actual request class::

        class MyRequest(DynamicCharsetRequestMixin, Request):
            pass

    By default the request object assumes that the URL charset is the
    same as the data charset.  If the charset varies on each request
    based on the transmitted data it's not a good idea to let the URLs
    change based on that.  Most browsers assume either utf-8 or latin1
    for the URLs if they have troubles figuring out.  It's strongly
    recommended to set the URL charset to utf-8::

        class MyRequest(DynamicCharsetRequestMixin, Request):
            url_charset = 'utf-8'

    .. versionadded:: 0.6
    t   latin1c         C   s   d S(   sK  Called if a charset was provided but is not supported by
        the Python codecs module.  By default latin1 is assumed then
        to not lose any information, you may override this method to
        change the behavior.

        :param charset: the charset that was not found.
        :return: the replacement charset.
        R9   (    (   R   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   unknown_charsetÒ   s    	c         C   sf   |  j  j d ƒ } | r_ t | ƒ \ } } | j d ƒ } | r_ t | ƒ rO | S|  j | ƒ Sn  |  j S(   s"   The charset from the content type.R   R   (   R   R   R   R   R:   t   default_charset(   R   t   headert   ctt   optionsR   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyR   Ý   s    (   R   R   R   R;   R:   R   R   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyR8   ³   s   	t   DynamicCharsetResponseMixinc           B   sA   e  Z d  Z d Z d „  Z d „  Z e e e d d ƒZ [ [ RS(   sÇ  If this mixin is mixed into a response class it will provide
    a dynamic `charset` attribute.  This means that if the charset is
    looked up and stored in the `Content-Type` header and updates
    itself automatically.  This also means a small performance hit but
    can be useful if you're working with different charsets on
    responses.

    Because the charset attribute is no a property at class-level, the
    default value is stored in `default_charset`.

    Because it changes the behavior or :class:`Response` this class has
    to be mixed in *before* the actual response class::

        class MyResponse(DynamicCharsetResponseMixin, Response):
            pass

    .. versionadded:: 0.6
    s   utf-8c         C   sE   |  j  j d ƒ } | r> t | ƒ d j d ƒ } | r> | Sn  |  j S(   Ns   content-typei   R   (   t   headersR   R   R;   (   R   R<   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   _get_charset  s    c         C   s]   |  j  j d ƒ } t | ƒ \ } } | s9 t d ƒ ‚ n  | | d <t | | ƒ |  j  d <d  S(   Ns   content-types5   Cannot set charset if Content-Type header is missing.R   s   Content-Type(   R@   R   R   t	   TypeErrorR   (   R   R   R<   R=   R>   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   _set_charset
  s    
R(   sj   
        The charset for the response.  It's stored inside the
        Content-Type header as a parameter.(   R   R   R   R;   RA   RC   R.   R   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyR?   ë   s   				(   R   R   t
   simplejsonR    t   ImportErrorR   t   werkzeug.exceptionsR   t   werkzeug.utilsR   t   werkzeug.httpR   R   t   werkzeug._compatR   R   t   objectR   R   R!   R/   R8   R?   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/wrappers.pyt   <module>   s    		"*(8