
`Tc           @   s[  d  Z  d d l Z d d l Z d d l Z d d l Z y d d l m Z Wn! e k
 rm d d l m Z n Xd d l	 m
 Z
 m Z m Z m Z m Z m Z d d l m Z m Z m Z e j d d5  Z e j d	  Z e j d
  Z d6 Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ e d  Z e d  Z d    Z  d!   Z! d"   Z" d d#  Z$ d$   Z% d% d&  Z& d' d(  Z' e( d)  Z) e( e( d*  Z* e+ d+  Z, d,   Z- d- e. f d.     YZ/ d/ e f d0     YZ0 d d1 l1 m2 Z2 m3 Z3 m4 Z4 d d2 l5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 d d3 l1 m: Z: m; Z; d S(7   s  
    werkzeug.utils
    ~~~~~~~~~~~~~~

    This module implements various utilities for WSGI applications.  Most of
    them are used by the request and response wrappers but especially for
    middleware development it makes sense to use them without the wrappers.

    :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
iN(   t   name2codepoint(   t   unichrt	   text_typet   string_typest	   iteritemst   reraiset   PY2(   t   _DictAccessorPropertyt   _parse_signaturet   _missings   \$(?:(%s)|\{(%s)\})s   [a-zA-Z_][a-zA-Z0-9_]*i   s	   &([^;]+);s   [^A-Za-z0-9_.-]t   CONt   AUXt   COM1t   COM2t   COM3t   COM4t   LPT1t   LPT2t   LPT3t   PRNt   NULt   cached_propertyc           B   s)   e  Z d  Z d d d  Z d d  Z RS(   s  A decorator that converts a function into a lazy property.  The
    function wrapped is called the first time to retrieve the result
    and then that calculated result is used the next time you access
    the value::

        class Foo(object):

            @cached_property
            def foo(self):
                # calculate something important here
                return 42

    The class has to have a `__dict__` in order for this property to
    work.
    c         C   s=   | p | j  |  _  | j |  _ | p* | j |  _ | |  _ d  S(   N(   t   __name__t
   __module__t   __doc__t   func(   t   selfR   t   namet   doc(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   __init__<   s    c         C   sZ   | d  k r |  S| j j |  j t  } | t k rV |  j |  } | | j |  j <n  | S(   N(   t   Nonet   __dict__t   getR   R	   R   (   R   t   objt   typet   value(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   __get__B   s    N(   R   R   R   R   R   R$   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR   #   s   
t   environ_propertyc           B   s   e  Z d  Z e Z d   Z RS(   s  Maps request attributes to environment variables. This works not only
    for the Werzeug request object, but also any other class with an
    environ attribute:

    >>> class Test(object):
    ...     environ = {'key': 'value'}
    ...     test = environ_property('key')
    >>> var = Test()
    >>> var.test
    'value'

    If you pass it a second value it's used as default if the key does not
    exist, the third one can be a converter that takes a value and converts
    it.  If it raises :exc:`ValueError` or :exc:`TypeError` the default value
    is used. If no default value is provided `None` is used.

    Per default the property is read only.  You have to explicitly enable it
    by passing ``read_only=False`` to the constructor.
    c         C   s   | j  S(   N(   t   environ(   R   R!   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   lookupc   s    (   R   R   R   t   Truet	   read_onlyR'   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR%   L   s   t   header_propertyc           B   s   e  Z d  Z d   Z RS(   s(   Like `environ_property` but for headers.c         C   s   | j  S(   N(   t   headers(   R   R!   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR'   j   s    (   R   R   R   R'   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR*   g   s   t   HTMLBuilderc           B   s   e  Z d  Z e j d  Z e j   Z d e d <e	 d d d d d d	 d
 d d d d d d d d d d d g  Z
 e	 d d d d d d d d d d d  d! g  Z e	 d" g  Z e	 d# d$ g  Z d%   Z d&   Z d'   Z d(   Z RS()   s  Helper object for HTML generation.

    Per default there are two instances of that class.  The `html` one, and
    the `xhtml` one for those two dialects.  The class uses keyword parameters
    and positional parameters to generate small snippets of HTML.

    Keyword parameters are converted to XML/SGML attributes, positional
    arguments are used as children.  Because Python accepts positional
    arguments before keyword arguments it's a good idea to use a list with the
    star-syntax for some children:

    >>> html.p(class_='foo', *[html.a('foo', href='foo.html'), ' ',
    ...                        html.a('bar', href='bar.html')])
    u'<p class="foo"><a href="foo.html">foo</a> <a href="bar.html">bar</a></p>'

    This class works around some browser limitations and can not be used for
    arbitrary SGML/XML generation.  For that purpose lxml and similar
    libraries exist.

    Calling the builder escapes the string passed:

    >>> html.p(html("<foo>"))
    u'<p>&lt;foo&gt;</p>'
    s	   &([^;]+);i'   t   apost   areat   baset   basefontt   brt   colt   commandt   embedt   framet   hrt   imgt   inputt   keygent   isindext   linkt   metat   paramt   sourcet   wbrt   selectedt   checkedt   compactt   declaret   defert   disabledt   ismapt   multiplet   nohreft   noresizet   noshadet   nowrapt   textareat   scriptt   stylec         C   s   | |  _  d  S(   N(   t   _dialect(   R   t   dialect(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR      s    c         C   s
   t  |  S(   N(   t   escape(   R   t   s(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   __call__   s    c            s5    d  d k r t     n     f d   } | S(   Ni   t   __c             s  d  } x t  |  D] \ } } | d  k r5 q n  | d d k rR | d  } n  |   j k r | sm q n    j d k r d | d } q d } n d t |  d } | d | | 7} q W|  r    j k r   j d k r | d	 7} n
 | d
 7} | S| d
 7} d j g  |  D] } | d  k	 rt |  ^ q } | r   j k rbt |  } q   j	 k r  j d k rd | d } qn  | | d  d
 7} | S(   Nt   <it   _t   xhtmls   ="t   "t    t    s    />t   >s   /*<![CDATA[*/s   /*]]>*/s   </(
   R   R   t   _boolean_attributesRO   RQ   t   _empty_elementst   joinR   t   _plaintext_elementst   _c_like_cdata(   t   childrent	   argumentst   buffert   keyR#   t   xt   children_as_string(   R   t   tag(    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   proxy   s:    
	

!(   t   AttributeError(   R   Rg   Rh   (    (   R   Rg   sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   __getattr__   s    $c         C   s   d |  j  j |  j f S(   Ns   <%s for %r>(   t	   __class__R   RO   (   R   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   __repr__   s    	(   R   R   R   t   ret   compilet
   _entity_reR    t   copyt	   _entitiest   setR]   R\   R_   R`   R   RS   Rj   Rl   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR,   n   s"   
			)t   htmlRW   c         C   sN   |  j  d  s9 |  d k s9 |  j  d  rJ |  j d  rJ |  d | 7}  n  |  S(   s|  Return the full content type string with charset for a mimetype.

    If the mimetype represents text the charset will be appended as charset
    parameter, otherwise the mimetype is returned unchanged.

    :param mimetype: the mimetype to be used as content type.
    :param charset: the charset to be appended in case it was a text mimetype.
    :return: the content type.
    s   text/s   application/xmls   application/s   +xmls
   ; charset=(   t
   startswitht   endswith(   t   mimetypet   charset(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   get_content_type   s    
c            s"      f d   } t  j |    S(   sX  String-template format a string:

    >>> format_string('$foo and ${foo}s', dict(foo=42))
    '42 and 42s'

    This does not do any attribute lookup etc.  For more advanced string
    formattings have a look at the `werkzeug.template` module.

    :param string: the format string.
    :param context: a dict with the variables to insert.
    c            sJ    |  j  d  p |  j  d  } t | t  sF t    |  } n  | S(   Ni   i   (   t   groupt
   isinstanceR   R"   (   t   matchRe   (   t   stringt   context(    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt
   lookup_arg   s    "(   t
   _format_ret   sub(   R|   R}   R~   (    (   R|   R}   sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   format_string   s    c         C   s  t  |  t  rU d d l m } | d |   j d d  }  t sU |  j d  }  qU n  x; t j j	 t j j
 f D]! } | rn |  j | d  }  qn qn Wt t j d d j |  j      j d	  }  t j d
 k r|  r|  j d  d j   t k rd |  }  n  |  S(   si  Pass it a filename and it will return a secure version of it.  This
    filename can then safely be stored on a regular file system and passed
    to :func:`os.path.join`.  The filename returned is an ASCII only string
    for maximum portability.

    On windows system the function also makes sure that the file is not
    named after one of the special device files.

    >>> secure_filename("My cool movie.mov")
    'My_cool_movie.mov'
    >>> secure_filename("../../../etc/passwd")
    'etc_passwd'
    >>> secure_filename(u'i contain cool \xfcml\xe4uts.txt')
    'i_contain_cool_umlauts.txt'

    The function might return an empty filename.  It's your responsibility
    to ensure that the filename is unique and that you generate random
    filename if the function returned an empty one.

    .. versionadded:: 0.5

    :param filename: the filename to secure
    i(   t	   normalizet   NFKDt   asciit   ignoreRZ   RY   RV   s   ._t   ntt   .i    (   Rz   R   t   unicodedataR   t   encodeR   t   decodet   ost   patht   sept   altsept   replacet   strt   _filename_ascii_strip_reR   R^   t   splitt   stripR   t   uppert   _windows_device_files(   t   filenameR   R   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   secure_filename   s    c         C   s   |  d k r d St |  d  r/ t |  j    St |  t  sM t |   }  n  | d k	 r d d l m } | t d  d d n  |  j	 d d	  j	 d
 d  j	 d d  j	 d d  }  |  S(   s  Replace special characters "&", "<", ">" and (") to HTML-safe sequences.

    There is a special handling for `None` which escapes to an empty string.

    .. versionchanged:: 0.9
       `quote` is now implicitly on.

    :param s: the string to escape.
    :param quote: ignored.
    RY   t   __html__i(   t   warns   quote parameter is implicit nowt
   stackleveli   t   &s   &amp;RU   s   &lt;R[   s   &gt;RX   s   &quot;N(
   R   t   hasattrR   R   Rz   R   t   warningsR   t   DeprecationWarningR   (   RR   t   quoteR   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyRQ   $  s    c         C   s   d   } t  j | |   S(   s   The reverse function of `escape`.  This unescapes all the HTML
    entities, not only the XML entities inserted by `escape`.

    :param s: the string to unescape.
    c         S   s   |  j  d  } | t j k r/ t t j |  SyN | d  d k rY t t | d d   S| j d  r| t t | d   SWn t k
 r n Xd S(	   Ni   i   s   #xs   #Xi   t   #u    (   s   #xs   #X(   Ry   R,   Rq   R   t   intRt   t
   ValueError(   t   mR   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   handle_matchC  s    (   Ro   R   (   RR   R   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   unescape=  s    	i.  c         C   s   d d l  m } t |   } t |  t  rP d d l m } | |  d t }  n  | d t |   | f | d d } |  | j d <| S(	   sW  Return a response object (a WSGI application) that, if called,
    redirects the client to the target location.  Supported codes are 301,
    302, 303, 305, and 307.  300 is not supported because it's not a real
    redirect and 304 because it's the answer for a request with a request
    with defined If-Modified-Since headers.

    .. versionadded:: 0.6
       The location can now be a unicode string that is encoded using
       the :func:`iri_to_uri` function.

    :param location: the location the response should redirect to.
    :param code: the redirect status code. defaults to 302.
    i(   t   Response(   t
   iri_to_urit   safe_conversions   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="%s">%s</a>.  If not click the link.Rv   s	   text/htmlt   Location(	   t   werkzeug.wrappersR   RQ   Rz   R   t   werkzeug.urlsR   R(   R+   (   t   locationt   codeR   t   display_locationR   t   response(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   redirectR  s    i-  c         C   sJ   |  d j  d  d } |  j d  } | r= | d | 7} n  t | |  S(   s,  Redirect to the same URL but with a slash appended.  The behavior
    of this function is undefined if the path ends with a slash already.

    :param environ: the WSGI environment for the request that triggers
                    the redirect.
    :param code: the status code for the redirect.
    t	   PATH_INFOt   /t   QUERY_STRINGt   ?(   R   R    R   (   R&   R   t   new_patht   query_string(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   append_slash_redirectr  s
    c         C   sG  t  |  t  s t  t |   }  y d |  k rK |  j d d  \ } } n1 d |  k rr |  j d d  \ } } n
 t |   St r t  | t  r | j	 d  } n  y# t
 t | d d | g  |  SWn7 t t f k
 r | d | } t |  t j | SXWn? t k
 rB} | sCt t t |  |  t j   d  qCn Xd S(   sC  Imports an object based on a string.  This is useful if you want to
    use import paths as endpoints or something similar.  An import path can
    be specified either in dotted notation (``xml.sax.saxutils.escape``)
    or with a colon as object delimiter (``xml.sax.saxutils:escape``).

    If `silent` is True the return value will be `None` if the import fails.

    :param import_name: the dotted name for the object to import.
    :param silent: if set to `True` import errors are ignored and
                   `None` is returned instead.
    :return: imported object
    t   :i   R   s   utf-8i   N(   Rz   R   t   AssertionErrorR   R   t   rsplitt
   __import__R   t   unicodeR   t   getattrR   t   ImportErrorRi   t   syst   modulesR   t   ImportStringErrort   exc_info(   t   import_namet   silentt   moduleR!   t   modnamet   e(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   import_string  s,    
#
c   
      c   s   t  |   } t | d d  } | d k r= t d |    n  | j d } xq t j |  D]` \ } } } | | } | r | r | Vn  | r x" t | | t  D] }	 |	 Vq Wq qZ | VqZ Wd S(   s  Find all the modules below a package.  This can be useful to
    automatically import all views / controllers so that their metaclasses /
    function decorators have a chance to register themselves on the
    application.

    Packages are not returned unless `include_packages` is `True`.  This can
    also recursively list modules but in that case it will import all the
    packages to get the correct load path of that module.

    :param import_name: the dotted name for the package to find child modules.
    :param include_packages: set to `True` if packages should be returned, too.
    :param recursive: set to `True` if recursion should happen.
    :return: generator
    t   __path__s   %r is not a packageR   N(	   R   R   R   R   R   t   pkgutilt   iter_modulest   find_modulesR(   (
   t   import_patht   include_packagest	   recursiveR   R   t   basenamet   importerR   t   ispkgt   item(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR     s    
c         C   s   t  |   } | | |  d  \ } } } } } | rI t t |    n( | sU | rq | rq t d | |   n  t |  | f S(   s  Check if the function accepts the arguments and keyword arguments.
    Returns a new ``(args, kwargs)`` tuple that can safely be passed to
    the function without causing a `TypeError` because the function signature
    is incompatible.  If `drop_extra` is set to `True` (which is the default)
    any extra positional or keyword arguments are dropped automatically.

    The exception raised provides three attributes:

    `missing`
        A set of argument names that the function expected but where
        missing.

    `extra`
        A dict of keyword arguments that the function can not handle but
        where provided.

    `extra_positional`
        A list of values that where given by positional argument but the
        function cannot accept.

    This can be useful for decorators that forward user submitted data to
    a view function::

        from werkzeug.utils import ArgumentValidationError, validate_arguments

        def sanitize(f):
            def proxy(request):
                data = request.values.to_dict()
                try:
                    args, kwargs = validate_arguments(f, (request,), data)
                except ArgumentValidationError:
                    raise BadRequest('The browser failed to transmit all '
                                     'the data expected.')
                return f(*args, **kwargs)
            return proxy

    :param func: the function the validation is performed against.
    :param args: a tuple of positional arguments.
    :param kwargs: a dict of keyword arguments.
    :param drop_extra: set to `False` if you don't want extra arguments
                       to be silently dropped.
    :return: tuple in the form ``(args, kwargs)``.
    i   N(   R   t   ArgumentValidationErrort   tupleR   (   R   t   argst   kwargst
   drop_extrat   parsert   missingt   extrat   extra_positional(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   validate_arguments  s    ,"c         C   s:  t  |   | |  \ } } } } } } } } i  }	 x0 t | |  D] \ \ }
 } } } | |	 |
 <qC W| d k	 r t |  |	 | <n | r t d   n  | d k	 rt |  t g  | D] } | d ^ q  @} | r t d t t t |      n  | |	 | <n+ | r6t d t t t |      n  |	 S(   s>  Bind the arguments provided into a dict.  When passed a function,
    a tuple of arguments and a dict of keyword arguments `bind_arguments`
    returns a dict of names as the function would see it.  This can be useful
    to implement a cache decorator that uses the function arguments to build
    the cache key based on the values of the arguments.

    :param func: the function the arguments should be bound for.
    :param args: tuple of positional arguments.
    :param kwargs: a dict of keyword arguments.
    :return: a :class:`dict` of bound keyword arguments.
    s   too many positional argumentsi    s)   got multiple values for keyword argument s    got unexpected keyword argument N(	   R   t   zipR   R   t	   TypeErrorRr   t   reprt   nextt   iter(   R   R   R   R   R   R   t   arg_spect
   vararg_vart	   kwarg_vart   valuesR   t   has_defaultt   defaultR#   Re   t   multikw(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   bind_arguments  s$    -%-R   c           B   s    e  Z d  Z d d d d  Z RS(   s6   Raised if :func:`validate_arguments` fails to validatec      
   C   sp   t  | p d  |  _ | p i  |  _ | p- g  |  _ t j |  d t |  j  t |  j  t |  j  f  d  S(   Ns8   function arguments invalid.  (%d missing, %d additional)(    (   Rr   R   R   R   R   R   t   len(   R   R   R   R   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR   &  s    N(   R   R   R   R   R   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR   #  s   R   c           B   s,   e  Z d  Z d Z d Z d   Z d   Z RS(   sB   Provides information about a failed :func:`import_string` attempt.c         C   s  | |  _  | |  _ d } d } g  } x | j d d  j d  D] } | | oR d | 7} t | d t } | r | j | t | d d   f  q@ g  | D] \ } }	 d | |	 f ^ q }
 |
 j d |  | | d	 j	 |
  | j
 j t |  f } Pq@ Wt j |  |  d  S(
   Ns1  import_string() failed for %r. Possible reasons are:

- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;

Debugged import:

%s

Original exception:

%s: %sRY   R   R   R   t   __file__s   - %r found in %r.s   - %r not found.s   
(   R   t	   exceptionR   R   R   R(   t   appendR   R   R^   Rk   R   R   R   R   (   R   R   R   t   msgR   t   trackedt   partt   importedt   nt   it   track(    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR   9  s     			"")c         C   s   d |  j  j |  j |  j f S(   Ns   <%s(%r, %r)>(   Rk   R   R   R   (   R   (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyRl   W  s    N(   R   R   R   R   R   R   R   Rl   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyR   1  s
   	(   t   quote_header_valuet   unquote_header_valuet   cookie_date(   t	   MultiDictt   CombinedMultiDictt   Headerst   EnvironHeaders(   t   parse_cookiet   dump_cookie(   s   [a-zA-Z_][a-zA-Z0-9_]*(   s   [a-zA-Z_][a-zA-Z0-9_]*s   [a-zA-Z_][a-zA-Z0-9_]*(   R
   R   R   R   R   R   R   R   R   R   R   (<   R   Rm   R   R   R   t   html.entitiesR    R   t   htmlentitydefst   werkzeug._compatR   R   R   R   R   R   t   werkzeug._internalR   R   R	   Rn   R   Ro   R   R   t   objectR   R%   R*   R,   Rs   RW   Rx   R   R   R   RQ   R   R   R   t   FalseR   R   R(   R   R   R   R   R   t   werkzeug.httpR   R   R   t   werkzeug.datastructuresR   R   R   R   R   R   (    (    (    sT   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/utils.pyt   <module>   sJ   . )_			-	 , 5	!,"