ó
•9Vc           @   sö   d  d l  m Z d  d l m Z m Z d  d l m Z m Z d  d l m	 Z	 d  d l
 Z
 d  d l Z d  d l Z d e f d „  ƒ  YZ i d d	 6d
 d 6d d 6d d 6d d 6d d 6d d 6Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   deepcopy(   t   current_appt   request(   t	   MultiDictt   FileStorage(   t
   exceptionsNt	   Namespacec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s0   y |  | SWn t  k
 r+ t | ƒ ‚ n Xd  S(   N(   t   KeyErrort   AttributeError(   t   selft   name(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   __getattr__   s    c         C   s   | |  | <d  S(   N(    (   R	   R
   t   value(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   __setattr__   s    (   t   __name__t
   __module__R   R   (    (    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyR   
   s   	u   the JSON bodyu   jsonu   the post bodyu   formu   the query stringu   argsu!   the post body or the query stringu   valuesu   the HTTP headersu   headersu   the request's cookiesu   cookiesu   an uploaded fileu   filesc         C   s   t  j |  ƒ S(   N(   t   sixt	   text_type(   t   x(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   <lambda>   s    t   Argumentc           B   se   e  Z d  Z d
 d
 e e e d d d d
 d e e e d „ Z d „  Z d „  Z	 d „  Z
 e d	 „ Z RS(   s  
    :param name: Either a name or a list of option strings, e.g. foo or
        -f, --foo.
    :param default: The value produced if the argument is absent from the
        request.
    :param dest: The name of the attribute to be added to the object
        returned by :meth:`~reqparse.RequestParser.parse_args()`.
    :param bool required: Whether or not the argument may be omitted (optionals
        only).
    :param action: The basic type of action to be taken when this argument
        is encountered in the request. Valid options are "store" and "append".
    :param ignore: Whether to ignore cases where the argument fails type
        conversion
    :param type: The type to which the request argument should be
        converted. If a type raises an exception, the message in the
        error will be returned in the response. Defaults to :class:`unicode`
        in python2 and :class:`str` in python3.
    :param location: The attributes of the :class:`flask.Request` object
        to source the arguments from (ex: headers, args, etc.), can be an
        iterator. The last item listed takes precedence in the result set.
    :param choices: A container of the allowable values for the argument.
    :param help: A brief description of the argument, returned in the
        response when the argument is invalid with the name of the argument and
        the message passed to any exception raised by a type converter.
    :param bool case_sensitive: Whether argument values in the request are
        case sensitive or not (this will convert all values to lowercase)
    :param bool store_missing: Whether the arguments default value should
        be stored if the argument is missing from the request.
    :param bool trim: If enabled, trims whitespace around the argument.
    t   jsont   valuest   storet   =c         C   s‚   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ |
 |  _	 | |  _
 | |  _ | |  _ | |  _ d  S(   N(   R
   t   defaultt   destt   requiredt   ignoret   locationt   typet   choicest   actiont   helpt   case_sensitivet	   operatorst   store_missingt   trim(   R	   R
   R   R   R   R   R   R   R   R    R!   R#   R"   R$   R%   (    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   __init__B   s    													c         C   sÆ   t  |  j t j ƒ rX t | |  j t ƒ  ƒ } t | ƒ rE | ƒ  } n  | d k	 r¿ | Sng t ƒ  } xW |  j D]L } t | | d ƒ } t | ƒ r› | ƒ  } n  | d k	 rk | j | ƒ qk qk W| St ƒ  S(   s‡   Pulls values off the request in the provided location
        :param request: The flask request object to parse arguments from
        N(	   t
   isinstanceR   R   t   string_typest   getattrR   t   callablet   Nonet   update(   R	   R   R   R   t   l(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   sourceU   s    	c         C   sÄ   | d  k r d  St | t ƒ r2 |  j t k r2 | Sy |  j | |  j | ƒ SWnq t k
 r¿ yB |  j t j k rŠ |  j t | ƒ |  j ƒ S|  j | |  j ƒ SWqÀ t k
 r» |  j | ƒ SXn Xd  S(   N(	   R+   R'   R   R   R
   t	   TypeErrort   decimalt   Decimalt   str(   R	   R   t   op(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   convertk   s    c         C   s­   |  j  r d |  j  n d } | r= d j | t | ƒ g ƒ n	 t | ƒ } t j j d t ƒ sd | r‚ i d | |  j 6} | | f Si d | |  j 6} t j	 d d | ƒd S(	   sU  Called when an error is raised while parsing. Aborts the request
        with a 400 status and an error message

        :param error: the error that was raised
        :param bundle_errors: do not abort when first error occurs, return a
            dict with the name of the argument and the error message to be
            bundled
        s   (%s) t    t    t   BUNDLE_ERRORSs   %si  t   messageN(
   R!   t   joinR2   R   t   configt   gett   FalseR
   t   flask_restfult   abort(   R	   t   errort   bundle_errorst   help_strt	   error_msgt   msg(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   handle_validation_error€   s    	-
c      
   C   sr  |  j  | ƒ } g  } t } t } xô|  j D]é} |  j | j d d d ƒ } | | k r+ t | d ƒ rz | j | ƒ }	 n | j | ƒ g }	 x…|	 D]z}
 t |
 d ƒ rÀ |  j	 rÀ |
 j
 ƒ  }
 n  t |
 d ƒ r"|  j r"|
 j ƒ  }
 t |  j d ƒ r"g  |  j D] } | j ƒ  ^ q|  _ q"n  y |  j |
 | ƒ }
 Wn/ t k
 ri} |  j rYq“ n  |  j | | ƒ SX|  j rÞ|
 |  j k rÞt j j d t ƒ s| r¼|  j t d	 j |
 ƒ ƒ | ƒ S|  j t d	 j |
 ƒ ƒ | ƒ n  | | j k r | j j | ƒ n  | j |
 ƒ q“ Wq+ q+ W| rë|  j rët |  j t j ƒ rad
 j t j |  j |  j ƒ ƒ } n@ g  |  j D] } t j | | ƒ ^ qk} d
 j d j | ƒ ƒ } t j j d t ƒ s¼| rÒ|  j t | ƒ | ƒ S|  j t | ƒ | ƒ n  | s t  |  j! ƒ r|  j! ƒ  | f S|  j! | f Sn  |  j" d k r9| | f S|  j" d k sZt# | ƒ d k rh| d | f S| | f S(   sO  Parses argument value(s) from the request, converting according to
        the argument's type.

        :param request: The flask request object to parse arguments from
        :param do not abort when first error occurs, return a
            dict with the name of the argument and the error message to be
            bundled
        R   R5   i   t   getlistt   stript   lowert   __iter__R7   u   {0} is not a valid choiceu!   Missing required parameter in {0}s    or t   appendR   i    ($   R.   R<   t   TrueR#   R
   t   replacet   hasattrRE   R;   R%   RF   R"   RG   R   R4   t	   ExceptionR   RD   R   R:   t
   ValueErrort   formatt   unparsed_argumentst   popRI   R   R'   R   R   R(   t   _friendly_locationR9   R*   R   R    t   len(   R	   R   R@   R.   t   resultst
   _not_foundt   _foundt   operatorR
   R   R   t   choiceR?   RB   t   loct   friendly_locations(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   parse‘   sn    	(			%
!N(   s   jsons   values(    (   R   (   R   R   t   __doc__R+   R<   R   RJ   R&   R.   R4   RD   R[   (    (    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyR   !   s   					t   RequestParserc           B   sV   e  Z d  Z e e e e d „ Z d „  Z d e d „ Z	 d „  Z
 d „  Z d „  Z RS(   sL  Enables adding and parsing of multiple arguments in the context of a
    single request. Ex::

        from flask import request

        parser = RequestParser()
        parser.add_argument('foo')
        parser.add_argument('int_bar', type=int)
        args = parser.parse_args()

    :param bool trim: If enabled, trims whitespace on all arguments in this
        parser
    :param bool bundle_errors: If enabled, do not abort when first error occurs,
        return a dict with the name of the argument and the error message to be
        bundled and return all validation errors
    c         C   s1   g  |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   argst   argument_classt   namespace_classR%   R@   (   R	   R_   R`   R%   R@   (    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyR&   ø   s
    				c         O   s™   t  | ƒ d k r? t | d |  j ƒ r? |  j j | d ƒ n |  j j |  j | | Ž  ƒ |  j r• |  j t k r• | j d |  j ƒ |  j d _ n  |  S(   s  Adds an argument to be parsed.

        Accepts either a single instance of Argument or arguments to be passed
        into :class:`Argument`'s constructor.

        See :class:`Argument`'s constructor for documentation on the
        available options.
        i   i    R%   iÿÿÿÿ(   RS   R'   R_   R^   RI   R%   R   R;   (   R	   R^   t   kwargs(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   add_argument   s    
("c         C   s'  | d k r t } n  |  j ƒ  } | rE t |  j d ƒ j | ƒ ƒ n i  | _ i  } xy |  j D]n } | j | |  j	 ƒ \ } } t
 | t ƒ r¤ | j | ƒ d } n  | s³ | j r^ | | | j pÈ | j <q^ q^ W| rì t j d d | ƒn  | r#| j r#t j d d j | j j ƒ  ƒ ƒ ‚ n  | S(   s¿   Parse all arguments from the provided request and return the results
        as a Namespace

        :param strict: if req includes args not in parser, throw 400 BadRequest exception
        R5   i  R8   s   Unknown arguments: %ss   , N(   R+   R   R`   t   dictR_   R.   RP   R^   R[   R@   R'   RN   R,   R$   R   R
   R=   R>   R   t
   BadRequestR9   t   keys(   R	   t   reqt   strictt	   namespacet   errorst   argR   t   found(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt
   parse_args  s$    	-		c         C   sF   |  j  |  j |  j ƒ } t |  j ƒ | _ |  j | _ |  j | _ | S(   sE    Creates a copy of this RequestParser with the same set of arguments (   t	   __class__R_   R`   R    R^   R%   R@   (   R	   t   parser_copy(    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   copy5  s
    c         O   sj   |  j  | | | Ž } xN t |  j ƒ D]< \ } } | j | j k r& |  j | =|  j j | ƒ Pq& q& W|  S(   sB    Replace the argument matching the given name with a new version. (   R_   t	   enumerateR^   R
   RI   (   R	   R
   R^   Ra   t   new_argt   indexRj   (    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   replace_argument=  s    
c         C   sB   x; t  |  j ƒ D]) \ } } | | j k r |  j | =Pq q W|  S(   s.    Remove the argument matching the given name. (   Rp   R^   R
   (   R	   R
   Rr   Rj   (    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   remove_argumentG  s
    
N(   R   R   R\   R   R   R<   R&   Rb   R+   Rl   Ro   Rs   Rt   (    (    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyR]   æ   s   			
(   Ro   R    t   flaskR   R   t   werkzeug.datastructuresR   R   t   werkzeugR   R=   R0   R   Rc   R   RR   R   t   objectR   R]   (    (    (    s=   /tmp/pip-build-Q6F9ld/flask-restful/flask_restful/reqparse.pyt   <module>   s$   

	Å