
    +hY9                         d dl mZ 	 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 G d de      Zd	d
ddddddZd Z G d de      Z G d de      Zy# e$ r	 d dlmZ Y ^w xY w)    )deepcopy)MutableSequence)current_apprequest)	MultiDictFileStorage)
exceptionsNc                       e Zd Zd Zd Zy)	Namespacec                 >    	 | |   S # t         $ r t        |      w xY wN)KeyErrorAttributeError)selfnames     I/var/www/html/venv/lib/python3.12/site-packages/flask_restful/reqparse.py__getattr__zNamespace.__getattr__   s+    	': 	' &&	's    c                     || |<   y r    )r   r   values      r   __setattr__zNamespace.__setattr__   s    T
    N)__name__
__module____qualname__r   r   r   r   r   r   r      s    'r   r   zthe JSON bodyzthe post bodyzthe query stringz!the post body or the query stringzthe HTTP headerszthe request's cookieszan uploaded file)jsonformargsvaluesheaderscookiesfilesc                 ,    t        j                  |       S r   )six	text_type)xs    r   <lambda>r'   $   s    cmmA& r   c                   Z    e Zd ZdZddddedddddddddfd	Zd
 Zd Zd Zd Z	d Z
ddZy)Argumenta  
    :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. May optionally contain
        an "{error_msg}" interpolation token, which will be replaced with
        the text of the error raised by the 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.
    :param bool nullable: If enabled, allows null value in argument.
    NF)r   r   r   store)=Tc                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        y r   )r   defaultdestrequiredignorelocationtypechoicesactionhelpcase_sensitive	operatorsstore_missingtrimnullable)r   r   r-   r.   r/   r0   r2   r1   r3   r4   r5   r7   r6   r8   r9   r:   s                   r   __init__zArgument.__init__J   so    
 		  		,"*	 r   c                    t        | j                        dkD  r?| j                  dd }|j                  d       |j                  | j                  d          n| j                  }dj                  | j                  | j
                  |      S )N   r      z...z"Name: {0}, type: {1}, choices: {2})lenr3   appendformatr   r2   )r   r3   s     r   __str__zArgument.__str___   sk    t||q ll1Q'GNN5!NN4<<+,llG3::499diiQXYYr   c                    dj                  | j                  j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   | j"                        S )Nz{0}('{1}', default={2}, dest={3}, required={4}, ignore={5}, location={6}, type="{7}", choices={8}, action='{9}', help={10}, case_sensitive={11}, operators={12}, store_missing={13}, trim={14}, nullable={15}))rB   	__class__r   r   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   )r   s    r   __repr__zArgument.__repr__h   s    OOUv''DLL$))T]]\`\g\gimiviv		4<<diiATAT 2 2DIIt}}PN	Nr   c                 h   t        | j                  t        j                        r?t	        || j                  t                     }t        |      r |       }||S t               S t               }| j                  D ]5  }t	        ||d      }t        |      r |       }|%|j                  |       7 |S )zPulls values off the request in the provided location
        :param request: The flask request object to parse arguments from
        N)
isinstancer1   r$   string_typesgetattrr   callableupdate)r   r   r   r   ls        r   sourcezArgument.sourcep   s     dmmS%5%56GT]]IK@E  { [F]] )D1E?!GE$MM%() Mr   c                    || j                   ry t        d      t        |t              r| j                  t        k(  r|S 	 | j	                  || j
                  |      S # t        $ rz 	 | j                  t        j                  u r| j	                  t        |            cY S | j	                  || j
                        cY S # t        $ r | j	                  |      cY cY S w xY ww xY w)NzMust not be null!)
r:   
ValueErrorrH   r   r2   r   	TypeErrordecimalDecimalstr)r   r   ops      r   convertzArgument.convert   s    =}} !455 {+		[0HL		(99UDIIr22 	((99/99SZ0099UDII66 (yy''(	(s<   A 	C!(5B>C! B>;C!>CC!CC!c                    t        j                  |      }| j                  r| j                  j                  |      n|}| j                  |i}t
        j                  j                  dd      s|r||fS t        j                  d|       y)aU  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
        )	error_msgBUNDLE_ERRORSF  messageN)
r$   r%   r5   rB   r   r   configgetflask_restfulabort)r   errorbundle_errors	error_strrX   msgs         r   handle_validation_errorz Argument.handle_validation_error   sq     MM%(	=AYYDII$$y$9I	yy)$!!/59]#:C-r   c           	         | j                  |      }g }d}d}| j                  D ]  }| j                  |j                  ddd      z   }||v s)t	        |d      r|j                  |      }	n3|j                  |      }	t        |	t              r| j                  dk(  s|	g}	|	D ]w  }
t	        |
d      r| j                  r|
j                         }
t	        |
d	      r_| j                  sS|
j                         }
t	        | j                  d
      r-| j                  D cg c]  }|j                          c}| _        	 | j                  |
|      }
| j                  r|
| j                  vrzt&        j(                  j                  dd      s|r.| j%                  t+        dj-                  |
            |      c c S | j%                  t+        dj-                  |
            |       ||j.                  v r|j.                  j1                  |       |j3                  |
       z  |s| j4                  rt        | j6                  t8        j:                        r:dj-                  t<        j                  | j6                  | j6                              }nM| j6                  D cg c]  }t<        j                  ||       }}dj-                  dj?                  |            }t&        j(                  j                  dd      s|r| j%                  t+        |      |      S | j%                  t+        |      |       |s5tA        | jB                        r| jC                         |fS | jB                  |fS | j                  dk(  r||fS | j                  dk(  stE        |      dk(  r|d   |fS ||fS c c}w # t         $ r2}| j"                  rY d}~#| j%                  ||      cY d}~c c S d}~ww xY wc c}w )a^  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 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
        FTr+       getlistrA   striplower__iter__NrY   z{0} is not a valid choicez!Missing required parameter in {0}z or r*   r   )#rN   r7   r   replacehasattrri   r^   rH   r   r4   r9   rj   r6   rk   r3   rV   	Exceptionr0   re   r   r]   rP   rB   unparsed_argumentspoprA   r/   r1   r$   rI   _friendly_locationjoinrK   r-   r@   )r   r   rb   rN   results
_not_found_foundoperatorr   r   r   choicera   rX   locfriendly_locationss                   r   parsezArgument.parse   sz    W% 
 '	*H99x//R;;Dv~69-#^^D1F#ZZ-F&v?DKKS[D["(# *Eug.499 %ug.t7J7J %"4<<<:>,,,H06 -3LLN ,HDLR $UH = ||T\\(A&--11/5I]#'#?#? *+G+N+N$),+ !,-:$< < 44 *+G+N+N$),+ !,-:< w9992266t<NN5)9*'	*R 4==$--)9)9:@GG&**4==$--H	
 26&@*- '9&<&<S#&F &@" &@@GGKK 23	 !!%%ou=33Jy4I=YY((I)>N%||~z11||Z//;;("F?";;'!S\Q%61:v%%c,H
 % R;;$#;;E=QQQR0&@s0   N#8N(O&(	O#1OOO#O#)F)r   r   r   __doc__r%   r;   rC   rF   rN   rV   re   r{   r   r   r   r)   r)   '   sR    B &*uI8KG$& $Du	!*ZN,(0."Tr   r)   c                   @    e Zd ZdZeeddfdZd Zd
dZd Z	d Z
d	 Zy)RequestParsera^  Enables adding and parsing of multiple arguments in the context of a
    single request. Ex::

        from flask_restful import reqparse

        parser = reqparse.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
    Fc                 J    g | _         || _        || _        || _        || _        y r   )r   argument_classnamespace_classr9   rb   )r   r   r   r9   rb   s        r   r;   zRequestParser.__init__  s(    	,.	*r   c                    t        |      dk(  r8t        |d   | j                        r| j                  j	                  |d          n+| j                  j	                   | j                  |i |       | j
                  r@| j                  t        u r.|j                  d| j
                        | j                  d   _        | S )a  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.
        rh   r   r9   r?   )r@   rH   r   r   rA   r9   r)   r^   )r   r   kwargss      r   add_argumentzRequestParser.add_argument   s     t9>ja$2E2EFIIT!W%II0T00$A&AB 99,,8!'FDII!>DIIbMr   Nc                 h   |t         }| j                         }|r)t        | j                  d      j	                  |            ni |_        i }| j                  D ]p  }|j                  || j                        \  }}t        |t              r|j                  |       d}|s|j                  sT|||j                  xs |j                  <   r |rt        j                   ||       |rK|j
                  r?t#        j$                  ddj'                  |j
                  j)                               z        |S )aQ  Parse all arguments from the provided request and return the results
        as a Namespace

        :param req: Can be used to overwrite request from Flask
        :param strict: if req includes args not in parser, throw 400 BadRequest exception
        :param http_error_code: use custom error code for `flask_restful.abort()`
        Nrg   r[   zUnknown arguments: %sz, )r   r   dictr   rN   rp   r   r{   rb   rH   rP   rL   r8   r.   r   r_   r`   r	   
BadRequestrs   keys)	r   reqstricthttp_error_code	namespaceerrorsargr   founds	            r   
parse_argszRequestParser.parse_args6  s    ;C((*	 OUd&9&9"&=&D&DS&I!JZ\99 	8C99S$*<*<=LE5%,e$))27	#((.chh/	8 @c,,''(?*.))C4J4J4O4O4Q*R)S T T r   c                     | j                  | j                  | j                        }t        | j                        |_        | j
                  |_        | j                  |_        |S )zE Creates a copy of this RequestParser with the same set of arguments )rE   r   r   r   r   r9   rb   )r   parser_copys     r   copyzRequestParser.copyW  sO    nnT%8%8$:N:NO#DII.99$($6$6!r   c                      | j                   |g|i |}t        | j                  dd       D ]I  \  }}|j                  |j                  k(  s | j                  |= | j                  j	                  |        | S  | S )zB Replace the argument matching the given name with a new version. N)r   	enumerater   r   rA   )r   r   r   r   new_argindexr   s          r   replace_argumentzRequestParser.replace_argument_  s{    %$%%d<T<V<#DIIaL1 	JE3||sxx'IIe$		  )	
 r   c                     t        | j                  dd       D ]$  \  }}||j                  k(  s| j                  |=  | S  | S )z. Remove the argument matching the given name. N)r   r   r   )r   r   r   r   s       r   remove_argumentzRequestParser.remove_argumenti  sI    #DIIaL1 	JE3sxxIIe$		 r   )NFrZ   )r   r   r   r|   r)   r   r;   r   r   r   r   r   r   r   r   r~   r~     s2    " '/	5+,Br   r~   )r   r   collections.abcr   ImportErrorcollectionsflaskr   r   werkzeug.datastructuresr   r   werkzeugr	   r_   rR   r$   r   r   rr   r%   objectr)   r~   r   r   r   <module>r      s    ,/ ' :    
   3#)!  '	\v \~iF iC  ,+,s   A A-,A-