
    E6i?              
       2   d dl Z 	 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mZmZ dd	lmZ dd
lmZ ddlmZ  G d de      ZddddddddZdddddddZededededddiZ d Z! G d! d"e"      Z# G d# d$e"      Z$d% Z%y# e$ r	 d dlmZ Y w xY w)&    N)Hashable)deepcopy)current_apprequest)	MultiDictFileStorage)
exceptions   )abort
SpecsError)marshal)Model)
HTTPStatusc                       e Zd ZdZd Zd Zy)ParseResultz9
    The default result container as an Object dict.
    c                 >    	 | |   S # t         $ r t        |      w xY wN)KeyErrorAttributeError)selfnames     W/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/flask_restx/reqparse.py__getattr__zParseResult.__getattr__   s+    	': 	' &&	's    c                     || |<   y r    )r   r   values      r   __setattr__zParseResult.__setattr__   s    T
    N)__name__
__module____qualname____doc__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filesqueryformDataheaderbody)r%   r$   r'   r#   r&   r)   integerstringbooleannumbervoid,c                   ^    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dZ	e
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 string action: The basic type of action to be taken when this argument
        is encountered in the request. Valid options are "store" and "append".
    :param bool 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:`str`.
    :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   r9   r:   r;   r<   r>   r=   r?   r@   rA   rC   rB   rD   rE   rF   s                   r   __init__zArgument.__init___   so    * 		  		,"*	 r   c                    t        | j                  t              ra| j                  dv r |j                  d      }nt	        || j                  t                     }t        |      r |       }||S t               S t               }| j                  D ]M  }|dv r |j                  d      }nt	        ||d      }t        |      r |       }|=|j                  |       O |S )z
        Pulls values off the request in the provided location
        :param request: The flask request object to parse arguments from
        >   r#   get_jsonT)silentN)
isinstancer=   strrI   getattrr   callableupdate)r   r   r   r&   ls        r   sourcezArgument.source   s    
 dmmS)}} 44(((5	D  { [F]] ),,,G,,D9E#GQ5EE?!GE$MM%() Mr   c                 ^   || j                   st        d      y t        | j                  t              r&t        |t
              rt        || j                        S t        |t              r| j                  t        k(  r|S 	 | j                  || j                  |      S # t        $ r 	 | j                  t        j                  u r'| j                  t        |      | j                        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!)rF   
ValueErrorrK   r>   r   dictr   r   r   	TypeErrordecimalDecimalrL   )r   r   ops      r   convertzArgument.convert   s    === !455		5)j.E5$)),, {+		[0HL		(99UDIIr22 	((99/99SZ;;99UDII66 (yy''(	(s=   B 	D,(A D	(D,+D	D,	D(#D,'D((D,c                     t        |      }| j                  r&dj                  t        | j                        |g      n|}| j                  |i}|rt	        |      |fS t        t        j                  d|       y)ac  
        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 bool 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
         Input payload validation failederrorsN)rL   rA   joinr   rS   r   r   BAD_REQUEST)r   errorbundle_errors	error_str	error_msgr^   s         r   handle_validation_errorz Argument.handle_validation_error   se     J	=AYYCHHc$))ni89I	))Y'e$f,,j$$&GPVWr   c           	         t         j                  j                  dd      xs |}| j                  |      }g }d}d}| j                  D ]  }| j
                  |j                  ddd      z   }||v s)t        |d      r|j                  |      }	n|j                  |      g}	|	D ]g  }
t        |
d      r| j                  r|
j                         }
t        |
d	      r_| j                  sS|
j                         }
t        | j                  d
      r-| j                  D cg c]  }|j                          c}| _        	 | j                  dk(  r3|
j                  t               D cg c]  }| j#                  ||       }
}n| j#                  |
|      }
| j                  r6|
| j                  vr(dj+                  |
|      }| j)                  ||      c c S ||j,                  v r|j,                  j/                  |       |j1                  |
       j  |s| j2                  rt5        | j6                  t8              r+t:        j                  | j6                  | j6                        }n>| j6                  D cg c]  }t:        j                  ||       }}dj=                  |      }dj+                  |      }| j)                  ||      S |s5t?        | j@                        r| jA                         |fS | j@                  |fS | j                  dk(  r||fS | j                  dk(  stC        |      dk(  r|d   |fS ||fS c c}w 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 )al  
        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 bool 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
        BUNDLE_ERRORSFTr7    r
   getliststriplower__iter__splitNz0The value '{0}' is not a valid choice for '{1}'.z or z!Missing required parameter in {0}appendr6   r   )"r   configgetrQ   rC   r   replacehasattrri   rE   rj   rB   rk   r?   r@   rm   
SPLIT_CHARrY   	Exceptionr<   re   formatunparsed_argumentspoprn   r;   rK   r=   rL   _friendly_locationr_   rN   r9   len)r   r   rb   rQ   results
_not_found_foundoperatorr   r&   r   choicevra   msgr=   loc	locationsrd   s                      r   parsezArgument.parse   s    $**..FW-W% 
 '	*H99x//R;;Dv~69-#^^D1F$jj./F# *Eug.499 %ug.t7J7J %"4<<<IM+VvFLLN+VDLR;;'1 */Z)@%$% !%Q 9%E %
 %)LL$AE ||T\\(APWW!4  $;;COOw9992266t<NN5)=*'	*R 4==$----11$--OIMW#/33C=W	W!;;y1;BB8LI//	=II%||~z11||Z//;;("F?";;'!S\Q%61:v%%[ ,W% % R;;$#;;E=QQQR& XsB   L7;&M!L<:M2M?<M	M<
M7M7-M<7M<c                 h   | j                   dk(  ry | j                  t        j                  | j                   d      d}t	        | |       | j
                  rd|d<   | j                  r| j                  |d<   | j                  4t        | j                        r| j                         n| j                  |d<   | j                  dk(  r/d	|d	   i|d
<   d|v r|j                  d      |d
   d<   d|d	<   d|d<   | j                  dk(  rd	|d	   i|d
<   d|d	<   d|d<   | j                  r| j                  |d<   |S )Ncookier*   )r   inTr;   descriptionr9   rn   r>   itemspatternarraymulticollectionFormatrm   csvenum)r=   r   	LOCATIONSrp   _handle_arg_typer;   rA   r9   rN   r@   rw   r?   )r   params     r   
__schema__zArgument.__schema__  s*   ==H$)--w*OPu%== $E*99#'99E- <<#"*4<<"8dll ) ;;("$eFm4E'NE!,1IIi,@gy)#E&M(/E$%;;'!$eFm4E'N#E&M(-E$%<< LLE&Mr   )F)r   r    r!   r"   rL   rG   rQ   rY   re   r   propertyr   r   r   r   r5   r5   B   sh    > 
 '#!J:(4X$Pd  r   r5   c                   P    e Zd ZdZeeddfdZd ZddZd Z	d Z
d	 Zed
        Zy)RequestParseraU  
    Enables adding and parsing of multiple arguments in the context of a single request.
    Ex::

        from flask_restx import RequestParser

        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
    Fc                 J    g | _         || _        || _        || _        || _        y r   )r%   argument_classresult_classrE   rb   )r   r   r   rE   rb   s        r   rG   zRequestParser.__init__N  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.
        r
   r   rE   )ry   rK   r   r%   rn   rE   r5   rp   )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                    |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        t         j"                  d|       |r[|j
                  rOdj%                  |j
                  j'                               }dj)                  |      }	t+        j,                  |	      |S )aN  
        Parse all arguments from the provided request and return the results as a ParseResult

        :param bool strict: if req includes args not in parser, throw 400 BadRequest exception
        :return: the parsed results as :class:`ParseResult` (or any class defined as :attr:`result_class`)
        :rtype: ParseResult
        Nrh   r\   r]   z, zUnknown arguments: {0})r   r   rT   r   rQ   rv   r%   r   rb   rK   rS   rO   rD   r:   r   r   r   r`   r_   keysru   r	   
BadRequest)
r   reqstrictresultr^   argr   found	argumentsr   s
             r   
parse_argszRequestParser.parse_argsq  s&    ;C""$
 :@D$$R(//45R 	 99 	5C99S$*<*<=LE5%,e$))/4sxx+388,	5 &&(IRX c,,		#"8"8"="="?@I*11)<C'',,r   c                     | j                  | j                  | j                        }t        | j                        |_        | j
                  |_        | j                  |_        |S )zCCreates a copy of this RequestParser with the same set of arguments)	__class__r   r   r   r%   rE   rb   )r   parser_copys     r   copyzRequestParser.copy  sO    nnT%8%8$:K:KL#DII.99$($6$6!r   c                      | j                   |g|i |}t        | j                  dd       D ]I  \  }}|j                  |j                  k(  s | j                  |= | j                  j	                  |        | S  | S )z@Replace the argument matching the given name with a new version.N)r   	enumerater%   r   rn   )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_argument  sI    #DIIaL1 	JE3sxxIIe$		 r   c                     g }t               }| j                  D ]6  }|j                  }|s|j                  |       |j	                  |d          8 d|v rd|v rt        d      |S )Nr   r-   r+   z,Can't use formData and body at the same time)setr%   r   rn   addr   )r   paramsr   r   r   s        r   r   zRequestParser.__schema__  sk    E	99 	+CNNEe$eDk*		+
 Y:#:KLLr   )NF)r   r    r!   r"   r5   r   rG   r   r   r   r   r   r   r   r   r   r   r   r   <  sH    &   +,$L 
 
r   r   c                    t        | j                  t              r)| j                  t        v rt        | j                     |d<   y t	        | j                  d      r"| j                  j
                  d   |d<   d|d<   y t	        | j                  d      r&|j                  | j                  j                         y | j                  dk(  rd|d<   y d	|d<   y )
Nr>   
__apidoc__r   r-   r   r   r)   filer/   )	rK   r>   r   PY_TYPESrr   r   rO   r   r=   )r   r   s     r   r   r     s    #((H%#((h*> *f	<	(++F3fd	<	(SXX(()		 f fr   )&rV   collections.abcr   ImportErrorcollectionsr   r   flaskr   r   werkzeug.datastructuresr   r   werkzeugr	   r^   r   r   marshallingr   modelr   _httpr   rT   r   rx   r   intrL   boolfloatr   rs   objectr5   r   r   r   r   r   <module>r      s    %(  & :  %    $   1!&  	 )	8& 
wv wt@F @F!u  %$%s   B BB