
    @|h                        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mZ ddlm	Z	 g dZ
	 	 	 	 ddZ	 	 	 	 ddZd	d
	 	 	 	 	 ddZddZ	 	 	 	 	 	 ddZddZdddZy)z)Utilities to get schema instances/classes    )annotationsN)fields)
Components)onlyexclude	load_only	dump_onlypartialc                    t        | t              r!t        | t        j                        r |        S t        | t        j                        r| S t        j
                  j                  |              S )zReturn schema instance for given schema (instance or class).

    :param type|Schema|str schema: instance, class or class name of marshmallow.Schema
    :return: schema instance of given schema (instance or class)
    )
isinstancetype
issubclassmarshmallowSchemaclass_registry	get_classschemas    ]/var/www/html/test/engine/venv/lib/python3.12/site-packages/apispec/ext/marshmallow/common.pyresolve_schema_instancer      sS     &$Jv{7I7I$Jx&+,,-%%//799    c                    t        | t              rt        | t        j                        r| S t        | t        j                        rt        |       S t        j
                  j                  t        |             S )zReturn schema class for given schema (instance or class).

    :param type|Schema|str: instance, class or class name of marshmallow.Schema
    :return: schema class of given schema (instance or class)
    )r   r   r   r   r   r   r   strr   s    r   resolve_schema_clsr       sW     &$Jv{7I7I$J&+,,-F|%%//F<<r   Fexclude_dump_onlyc               N   t        | t        j                        r| j                  }nXt        | t              r:t        | t        j                        r t        j                  | j                        }nt        | d      t        | dd      }t        ||       t        |||      S )zReturn fields from schema.

    :param Schema schema: A marshmallow Schema instance or a class object
    :param bool exclude_dump_only: whether to filter fields in Meta.dump_only
    :rtype: dict, of field name field object pairs
    z1 is neither a Schema class nor a Schema instance.MetaNr   )r   r   r   r   r   r   copydeepcopy_declared_fields
ValueErrorgetattrwarn_if_fields_defined_in_metafilter_excluded_fields)r   r   r   r   s       r   
get_fieldsr&   /   s     &+,,-	FD	!j9K9K&Lv667F:%VWXX664(D"640!&$BSTTr   c                ,   t        |dd      st        |dd      rzt         | j                               }t        t        |dt                           |kD  s!t        t        |dt                           |kD  rt        j                  dt
        d       yyy)zWarns user that fields defined in Meta.fields or Meta.additional will be ignored.

    :param dict fields: A dictionary of fields name field object pairs
    :param Meta: the schema's Meta class
    r   N
additionalzOnly explicitly-declared fields will be included in the Schema Object. Fields defined in Meta.fields or Meta.additional are ignored.   
stacklevel)r#   setkeyswarningswarnUserWarning)r   r   declared_fieldss      r   r$   r$   E   s     tXt$lD(Ikfkkm,h.//A74su56HMMP	 I	 )Jr   c                   t        t        |dg             }|r|j                  t        |dg               | j                         D ci c]  \  }}||vr|r|j                  s|| }}}|S c c}}w )zFilter fields that should be ignored in the OpenAPI spec.

    :param dict fields: A dictionary of fields name field object pairs
    :param Meta: the schema's Meta class
    :param bool exclude_dump_only: whether to filter dump_only fields
    r   r	   )listr#   extenditemsr	   )r   r   r   r   keyvaluefiltered_fieldss          r   r%   r%   Y   s|     74B/0Gwt["56 '&,,.Cg'8U__ 	U
O  s   	A-c                   t        | t        j                        st        d      g }t        D ]+  }t        | |      }	 t        |       |j                  |       - t        | j                  g|      S # t        $ r t        |      }Y Aw xY w)Nz6can only make a schema key based on a Schema instance.)r   r   r   	TypeError	MODIFIERSr#   hash	frozensetappendtuple	__class__)r   	modifiersmodifier	attributes       r   make_schema_keyrD   o   s    fk001PQQI $FH-		-O 	#$ &""/Y/00	  	-!),I	-s   A44B
Bc                    || j                   vr|S |s!t        j                  d| dt        d       n|dt	        t        |              }|dz  }t        | |t        |      z   |      S )a  Function to generate a unique name based on the provided name and names
    already in the spec.  Will append a number to the name to make it unique if
    the name is already in the spec.

    :param Components components: instance of the components of the spec
    :param string name: the name to use as a basis for the unique name
    :param int counter: the counter of the number of recursions
    :return: the unique name
    z&Multiple schemas resolved to the name z. The name has been modified. Either manually add each of the schemas with a different name or provide a custom schema_name_resolver.r)   r*   N   )schemasr.   r/   r0   lenr   get_unique_schema_name)
componentsnamecounters      r   rI   rI      s{     :%%%4TF ;5 5 	
 (s3w<(()qLG!*dS\.A7KKr   )r   z3type[marshmallow.Schema] | marshmallow.Schema | strreturnmarshmallow.Schema)r   z3type[marshmallow.Schema] | str | marshmallow.SchemarM   z9type[marshmallow.Schema] | list[type[marshmallow.Schema]])r   z-type[marshmallow.Schema] | marshmallow.Schemar   boolrM   dict[str, fields.Field])r   rP   )r   rP   r   rO   rM   rP   )r   rN   rM   z$tuple[type[marshmallow.Schema], ...])r   )rJ   r   rK   r   rL   intrM   r   )__doc__
__future__r   r   r.   r   marshmallow.class_registryr   apispec.corer   r;   r   r   r&   r$   r%   rD   rI    r   r   <module>rW      s    / "    !  #D	:?::=?=>=$ $U9U U 	U,(#AE,1 Lr   