
    @|h[                    0   U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZ i ej                  j                  dej                  j                  dej                  j                   dej                  j"                  dej                  j$                  dej                  j&                  d	ej                  j(                  d
ej                  j*                  dej                  j,                  dej                  j.                  dej                  j0                  dej                  j2                  dej                  j4                  dej                  j6                  dej                  j8                  dej                  j:                  dej                  j<                  dej                  j>                  dej                  j@                  dej                  jB                  diZ"de#d<   h dZ$dZ% G d d      Z&d Z'ddZ(y)zUtilities for generating OpenAPI Specification (fka Swagger) entities from
:class:`Fields <marshmallow.fields.Field>`.

.. warning::

    This module is treated as private API.
    Users should not need to use this module directly.
    )annotationsN)
OrderedSet)Version)integerN)numberNstringN)booleanN)r	   uuid)r	   z	date-time)r	   date)r	   email)r	   url)objectN)NN)arrayN)r	   ip)r	   ipv4)r	   ipv6)dict[type, tuple[str | None, str | None]]DEFAULT_FIELD_MAPPING>"   notxmlenumtypeallOfanyOfitemsoneOftitleformatdefaultexamplemaximumminimumpatternmaxItemsminItemsnullablereadOnlyrequired	maxLength	minLength	writeOnly
deprecated
multipleOf
propertiesdescriptionuniqueItemsexternalDocsmaxPropertiesminPropertiesexclusiveMaximumexclusiveMinimumadditionalPropertieszx-c                  ,   e Zd ZU dZeZded<   ded<   d Zd Zd Z	dd	Z
	 	 	 	 	 	 dd
Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZddZddZddZddZddZy)FieldConverterMixinzHAdds methods for converting marshmallow fields to an OpenAPI properties.r   field_mappingr   openapi_versionc                   | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   g| _        y N)field2type_and_formatfield2defaultfield2choicesfield2read_onlyfield2write_onlyfield2rangefield2lengthfield2patternmetadata2propertiesenum2propertiesnested2propertiespluck2propertieslist2propertiesdict2propertiestimedelta2propertiesdatetime2propertiesfield2nullableattribute_functions)selfs    f/var/www/html/test/engine/venv/lib/python3.12/site-packages/apispec/ext/marshmallow/field_converter.pyinit_attribute_functionsz,FieldConverterMixin.init_attribute_functionsa   s     &&  !!$$  ""!!    %%$$'$
     c                    t        |      dk(  r$|d   | j                  v r| j                  |d      }nt        |      dk(  r|}nt        d      || j                  |<   y)a  Set mapping for custom field class.

        :param type field_cls: Field class to set mapping for.

        ``*args`` can be:

        - a pair of the form ``(type, format)``
        - a core marshmallow field type (in which case we reuse that type's mapping)
           r      z5Pass core marshmallow field type or (type, fmt) pair.N)lenr:   	TypeError)rP   	field_clsargsopenapi_type_fields       rQ   map_to_openapi_typez'FieldConverterMixin.map_to_openapi_typex   sb     t9>d1g););;!%!3!3DG!<Y!^!%STT(:9%rS   c                    |j                  |       }t        | |j                  |       | j                  j	                  |       y)aJ  Method to add an attribute function to the list of attribute functions
        that will be called on a field to convert it from a field to an OpenAPI
        property.

        :param func func: the attribute function to add
            The attribute function will be bound to the
            `OpenAPIConverter <apispec.ext.marshmallow.openapi.OpenAPIConverter>`
            instance.
            It will be called for each field in a schema with
            `self <apispec.ext.marshmallow.openapi.OpenAPIConverter>` and a
            `field <marshmallow.fields.Field>` instance
            positional arguments and `ret <dict>` keyword argument.
            Must return a dictionary of OpenAPI properties that will be shallow
            merged with the return values of all other attribute functions called on the field.
            User added attribute functions will be called after all built-in attribute
            functions in the order they were added. The merged results of all
            previously called attribute functions are accessible via the `ret`
            argument.
        N)__get__setattr__name__rO   append)rP   func
bound_funcs      rQ   add_attribute_functionz*FieldConverterMixin.add_attribute_function   s6    ( \\$'
dmmZ0  ''
3rS   c                ^    i }| j                   D ]  }|j                   |||              |S )a  Return the JSON Schema property definition given a marshmallow
        :class:`Field <marshmallow.fields.Field>`.

        Will include field metadata that are valid properties of OpenAPI schema objects
        (e.g. "description", "enum", "example").

        https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject

        :param Field field: A marshmallow field.
        :rtype: dict, a Property Object
        )ret)rO   update)rP   fieldrf   	attr_funcs       rQ   field2propertyz"FieldConverterMixin.field2property   s8     11 	2IJJyC01	2 
rS   c                    t        |      j                  D ]$  }|| j                  v s| j                  |   \  }} n/ t        j                  dt        |       dt
        d       d\  }}i }|r||d<   |r||d<   |S )zReturn the dictionary of OpenAPI type and format based on the field type.

        :param Field field: A marshmallow field.
        :rtype: dict
        zField of type z) does not inherit from marshmallow.Field.rV   
stacklevelr   r   r   )r   __mro__r:   warningswarnUserWarning)rP   rh   kwargsfield_classtype_fmtrf   s          rQ   r>   z)FieldConverterMixin.field2type_and_format   s      ;.. 
	(Kd000!//<
s
	(
 MM e-VW
 (JE3CKCM
rS   c                    i }d|j                   v r|j                   d   |d<   |S |j                  }|t        j                  ur#t	        |      s|j                  |dd      }||d<   |S )a[  Return the dictionary containing the field's default value.

        Will first look for a `default` key in the field's metadata and then
        fall back on the field's `missing` parameter. A callable passed to the
        field's missing parameter will be ignored.

        :param Field field: A marshmallow field.
        :rtype: dict
        r    N)metadataload_defaultmarshmallowmissingcallable
_serialize)rP   rh   rr   rf   r    s        rQ   r?   z!FieldConverterMixin.field2default   sr     &"^^I6C	N 
	 ((Gk111(7:K**7D$?!(I
rS   c                   i }|j                   D cg c]  }t        |d      r|j                   }}|r||d<   nj|j                   D cg c]#  }t        |d      rt        |j                        % }}|r0t        t        j                  t        j                  |            |d<   |j                  r+|j                  d      }|d|vr|d   j                  d       |S c c}w c c}w )zReturn the dictionary of OpenAPI field attributes for valid choices definition.

        :param Field field: A marshmallow field.
        :rtype: dict
        
comparabler   choicesN)
validatorshasattrr~   r   r   list	functoolsreduceoperatorand_
allow_nonegetra   )rP   rh   rr   
attributes	validatorr~   r   r   s           rQ   r@   z!FieldConverterMixin.field2choices   s     
 #--
y,/   

 

 !+Jv "'!1!19i0 9,,-G 
 %))*:*:8=='*R%S
6">>&)DD$46"))$/+
s   C(C"c                ,    i }|j                   rd|d<   |S )zReturn the dictionary of OpenAPI field attributes for a dump_only field.

        :param Field field: A marshmallow field.
        :rtype: dict
        Tr(   )	dump_onlyrP   rh   rr   r   s       rQ   rA   z#FieldConverterMixin.field2read_only  s      
??%)Jz"rS   c                ^    i }|j                   r| j                  j                  dk\  rd|d<   |S )zReturn the dictionary of OpenAPI field attributes for a load_only field.

        :param Field field: A marshmallow field.
        :rtype: dict
           Tr,   )	load_onlyr;   majorr   s       rQ   rB   z$FieldConverterMixin.field2write_only  s3     
??t3399Q>&*J{#rS   c                   i }|j                   r| j                  j                  dk  rd|d<   |S | j                  j                  dk  rId|v rdddd|j	                  d      ig|d<   |S d	|v rg |j	                  d	      ddd|d<   |S d|d
<   |S d|v rd|j	                  d      iddig|d<   |S d	|v rg |j	                  d	      ddi|d<   |S d|v r!g t        |j                  d            d|d<   |S )zReturn the dictionary of OpenAPI field attributes for a nullable field.

        :param Field field: A marshmallow field.
        :rtype: dict
        r   Tz
x-nullablerU   $refr   )r   r'   r   r   r'   r   null)r   r;   r   minorpopmake_type_listr   )rP   rh   rf   r   s       rQ   rN   z"FieldConverterMixin.field2nullable%  se    
##))A-+/
<(* ) %%++a/S=!)t<1+Jw'$  ^+)+!)t<+Jw'  .2Jz*  S=,2CGGFO+DvvFV*WJw'
 	 ^*OCGGG,<*Ovv>N*OJw'  s])S>#''&/+J)SF)SJv&rS   c           
     p   |j                   D cg c](  }t        |d      rt        |d      rt        |d      s|* }}t        t        |j	                  d                  ddhz  rdnd\  }}t        |||      j                         D ci c]  \  }}||j                  |d	d	       c}}S c c}w c c}}w )
zReturn the dictionary of OpenAPI field attributes for a set of
        :class:`Range <marshmallow.validators.Range>` validators.

        :param Field field: A marshmallow field.
        :rtype: dict
        minmaxequalr   r   r   )r#   r"   )z	x-minimumz	x-maximumN)r   r   setr   r   make_min_max_attributesr   r|   )	rP   rh   rf   r   r   min_attrmax_attrkvs	            rQ   rC   zFieldConverterMixin.field2rangeE  s     #--
	5)Iu-	73 

 
 >#''&/23x6KK #+ 	( 0
HhOUUW
1 u4..
 	
#
"
s   -B-B2c                   |j                   D cg c](  }t        |d      rt        |d      rt        |d      r|* }}t        |t        j                  j
                  t        j                  j                  f      }|rdnd}|rdnd}|D cg c]  }|j                  |j                   }}|r||d   ||d   iS t        |||      S c c}w c c}w )	zReturn the dictionary of OpenAPI field attributes for a set of
        :class:`Length <marshmallow.validators.Length>` validators.

        :param Field field: A marshmallow field.
        :rtype: dict
        r   r   r   r&   r+   r%   r*   r   )	r   r   
isinstancery   fieldsNestedListr   r   )	rP   rh   rr   r   r   is_arrayr   r   
equal_lists	            rQ   rD   z FieldConverterMixin.field2lengthb  s     #--
	5)Iu-Iw/ 

 
 K&&--{/A/A/F/FG
 "*:{!):{ .8
 )9??;VIOO

 
 jmXz!}EE&z8XFF-
 
s   -C	CCc                    d |j                   D        }t        |d      }|i nd|j                  j                  i}t        |d      )t	        j
                  dt        |       dt        d       |S )a0  Return the dictionary of OpenAPI field attributes for a
        :class:`Regexp <marshmallow.validators.Regexp>` validator.

        If there is more than one such validator, only the first
        is used in the output spec.

        :param Field field: A marshmallow field.
        :rtype: dict
        c              3  j   K   | ]+  }t        t        |d d      t        j                        r| - yw)regexN)r   getattrrePattern).0r   s     rQ   	<genexpr>z4FieldConverterMixin.field2pattern.<locals>.<genexpr>  s/      
'!Wd3RZZ@ 
s   13Nr$   z)More than one regex validator defined on z; field. Only the first one will be used in the output spec.rV   rl   )r   nextr   r$   ro   rp   r   rq   )rP   rh   rr   regex_validatorsr   r   s         rQ   rE   z!FieldConverterMixin.field2pattern  s}    
%%

 !4(9R9aggoo*F
 $'3MM;DK= I= =	 rS   c                ^   |j                   j                         D ci c];  \  }}t        |t              r&|j	                  d      r|j                  dd      n||= }}}|j                         D ci c]%  \  }}|t        v s|j	                  t              r||' }}}|S c c}}w c c}}w )a  Return a dictionary of properties extracted from field metadata.

        Will include field metadata that are valid properties of `OpenAPI schema
        objects
        <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject>`_
        (e.g. "description", "enum", "example").

        In addition, `specification extensions
        <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#specification-extensions>`_
        are supported.  Prefix `x_` to the desired extension when passing the
        keyword argument to the field constructor. apispec will convert `x_` to
        `x-` to comply with OpenAPI.

        :param Field field: A marshmallow field.
        :rtype: dict
        x__-)rw   r   r   str
startswithreplace_VALID_PROPERTIES_VALID_PREFIX)rP   rh   rr   keyvaluerw   rf   s          rQ   rF   z'FieldConverterMixin.metadata2properties  s    , $nn224
U#s# &)^^D%9CKKS!sEI
 
 'nn.
U''3>>-+H J
 

 


s   A B#4*B)c                   t        |t        j                  j                        rt        |t        j                  j                        s| j                  |j                        }|red|v ra| j                  j                  dk  s2| j                  j                  dk(  r/| j                  j                  dk(  r|j                  d|gi       |S |j                  |       |S )a  Return a dictionary of properties from :class:`Nested <marshmallow.fields.Nested` fields.

        Typically provides a reference object and will add the schema to the spec
        if it is not already present
        If a custom `schema_name_resolver` function returns `None` for the nested
        schema a JSON schema object will be returned

        :param Field field: A marshmallow field.
        :rtype: dict
        r   r   r   r   )r   ry   r   r   Pluckresolve_nested_schemaschemar;   r   r   rg   )rP   rh   rf   schema_dicts       rQ   rH   z%FieldConverterMixin.nested2properties  s     e[//667
;%%++A
 44U\\BKk)((..2,,22a7 0066!; 

Gk]34 
 

;'
rS   c                    t        |t        j                  j                        rG|j                  j                  |j
                     }| j                  |      }|j                  rd|dS |S i S )a,  Return a dictionary of properties from :class:`Pluck <marshmallow.fields.Pluck` fields.

        Pluck effectively trans-includes a field from another schema into this,
        possibly wrapped in an array (`many=True`).

        :param Field field: A marshmallow field.
        :rtype: dict
        r   )r   r   )r   ry   r   r   r   
field_namerj   many)rP   rh   rr   plucked_fieldrf   s        rQ   rI   z$FieldConverterMixin.pluck2properties  s_     e[//556!LL//0@0@AM%%m4C6;jjGc2IcI	rS   c                    i }t        |t        j                  j                        r| j	                  |j
                        |d<   |S )zReturn a dictionary of properties from :class:`List <marshmallow.fields.List>` fields.

        Will provide an `items` property based on the field's `inner` attribute

        :param Field field: A marshmallow field.
        :rtype: dict
        r   )r   ry   r   r   rj   innerrP   rh   rr   rf   s       rQ   rJ   z#FieldConverterMixin.list2properties  s<     e[//445..u{{;CL
rS   c                    i }t        |t        j                  j                        r)|j                  }|r| j                  |      |d<   |S i |d<   |S )aM  Return a dictionary of properties from :class:`Dict <marshmallow.fields.Dict>` fields.

        Only applicable for Marshmallow versions greater than 3. Will provide an
        `additionalProperties` property based on the field's `value_field` attribute

        :param Field field: A marshmallow field.
        :rtype: dict
        r7   )r   ry   r   Dictvalue_fieldrj   )rP   rh   rr   rf   r   s        rQ   rK   z#FieldConverterMixin.dict2properties   s\     e[//445++K.2.A.A+.N*+ 
 /1*+
rS   c                p    i }t        |t        j                  j                        r|j                  |d<   |S )a  Return a dictionary of properties from :class:`TimeDelta <marshmallow.fields.TimeDelta>` fields.

        Adds a `x-unit` vendor property based on the field's `precision` attribute

        :param Field field: A marshmallow field.
        :rtype: dict
        zx-unit)r   ry   r   	TimeDelta	precisionr   s       rQ   rL   z(FieldConverterMixin.timedelta2properties  s1     e[//99:!OOCM
rS   c                   i }t        |t        j                  j                        r| j	                  |j
                        }|j                  du rd |j                  j                  D        }nd |j                  D        }|D cg c]  }|j
                  j                  |dd      ! c}|d<   |j                  rd|d   vr|d   j                  d       |S c c}w )zReturn a dictionary of properties from :class:`Enum <marshmallow.fields.Enum` fields.

        :param Field field: A marshmallow field.
        :rtype: dict
        Fc              3      K   | ]  }|  y wr=    r   ms     rQ   r   z6FieldConverterMixin.enum2properties.<locals>.<genexpr>)  s     =1=s   c              3  4   K   | ]  }|j                     y wr=   )r   r   s     rQ   r   z6FieldConverterMixin.enum2properties.<locals>.<genexpr>+  s     7q1777s   Nr   )r   ry   r   Enumrj   rh   by_valuer   __members__r|   r   ra   )rP   rh   rr   rf   r   r   s         rQ   rG   z#FieldConverterMixin.enum2properties  s     e[//445%%ekk2C~~&=ejj&<&<=7EJJ7JQRQ5;;11!T4@RCKDF$;F""4(
 Ss   $Cc                   i }t        |t        j                  j                        rt        |t        j                  j                        s|j
                  dk(  s|j
                  	 |S |j
                  dk(  r	ddddd}|S |j
                  dk(  r	d	d
ddd}|S |j
                  dk(  r	d	d
ddd}|S dd|j                  j                  d      r|j                  d   ndd}|S )zReturn a dictionary of properties from :class:`DateTime <marshmallow.fields.DateTime` fields.

        :param Field field: A marshmallow field.
        :rtype: dict
        isoNrfcr	   zWed, 02 Oct 2002 13:00:00 GMTz((Mon|Tue|Wed|Thu|Fri|Sat|Sun), ){0,1}\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} (UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|(Z|A|M|N)|(\+|-)\d{4}))r   r   r!   r$   	timestampr   floatz1676451245.5960)r   r   r!   r   timestamp_msz1676451277514.654r$   )r   r   r$   )r   ry   r   DateTimeDater   rw   r   r   s       rQ   rM   z'FieldConverterMixin.datetime2properties1  s    e[//889*;%%**C
 ||u$(< D 
C &$"> X	@ 
1 ,$%/	. 
# /$%2	  
 %" !>>--i8 y1! 
rS   N)rh   marshmallow.fields.Fieldreturndict)rh   r   rr   
typing.Anyr   r   )rr   r   r   r   )r`   
__module____qualname____doc__r   r:   __annotations__rR   r\   rd   rj   r>   r?   r@   rA   rB   rN   rC   rD   rE   rF   rH   rI   rJ   rK   rL   rG   rM   r   rS   rQ   r9   r9   [   sH   R?TM<T
.;&40&-9C	<-9C	,-9C	B-9C	-9C	@
:G-G9CG	GB-9C	< - 9C 	 DB$$/rS   r9   c                4    | g S t        | t              r| gS | S )a]  Return a list of types from a type attribute

    Since OpenAPI 3.1.0, "type" can be a single type as string or a list of
    types, including 'null'. This function takes a "type" attribute as input
    and returns it as a list, be it an empty or single-element list.
    This is useful to factorize type-conditional code or code adding a type.
    )r   r   )typess    rQ   r   r   c  s$     }	%wLrS   c                    i }| D cg c]  }|j                   |j                    }}| D cg c]  }|j                  |j                   }}|rt        |      ||<   |rt        |      ||<   |S c c}w c c}w )a  Return a dictionary of minimum and maximum attributes based on a list
    of validators. If either minimum or maximum values are not present in any
    of the validator objects that attribute will be omitted.

    :param validators list: A list of `Marshmallow` validator objects. Each
        objct is inspected for a minimum and maximum values
    :param min_attr string: The OpenAPI attribute for the minimum value
    :param max_attr string: The OpenAPI attribute for the maximum value
    )r   r   )r   r   r   r   r   min_listmax_lists          rQ   r   r   r  sz     J/9W)Y]]=V	WHW/9W)Y]]=V	WHW"8}
8"8}
8 XWs   A1A1A6A6)r   r   ))r   
__future__r   r   r   r   typingro   ry   marshmallow.orderedsetr   packaging.versionr   r   IntegerNumberFloatDecimalStringBooleanUUIDr   r   Timer   EmailURLr   FieldRawr   IPIPv4IPv6r   r   r   r   r9   r   r   r   rS   rQ   <module>r     sP   #   	    - %D 1D/D .D  0	D
 /D  1D /D !8D /D -D   "3D 1D -D -D lD  L!D" _#D$ +//)D @ 6# L E EPrS   