o
    FDi                     @  s   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dZd*ddZddd+ddZd,ddZd-ddZd.dd Zd/d0d'd(ZdS )1z)Utilities to get schema instances/classes    )annotationsN)fields)
Components)onlyexclude	load_only	dump_onlypartialschema3type[marshmallow.Schema] | marshmallow.Schema | strreturnmarshmallow.Schemac                 C  s:   t | trt| tjr|  S t | tjr| S t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r
    r   W/var/www/Datamplify/venv/lib/python3.10/site-packages/apispec/ext/marshmallow/common.pyresolve_schema_instance   s
   r   3type[marshmallow.Schema] | str | marshmallow.Schema9type[marshmallow.Schema] | list[type[marshmallow.Schema]]c                 C  s>   t | trt| tjr| S t | tjrt| S t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   r   r   r   resolve_schema_cls    s
   r   Fexclude_dump_only-type[marshmallow.Schema] | marshmallow.Schemar   booldict[str, fields.Field]c                C  sj   t | tjr
| j}nt | trt| tjrt| j}nt	| dt
| dd}t|| t|||d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"   r   r   r   
get_fields/   s   
r*   r   c                 C  sl   t |ddst |ddr2t|  }tt |dt |ks(tt |dt |kr4tjdtdd dS dS dS )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_fieldsr   r   r   r(   E   s   
r(   c                  sB   t t|dg  r t|dg   fdd|  D }|S )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   c                   s(   i | ]\}}| vrr|j s||qS r   )r   ).0keyvaluer   r   r   r   
<dictcomp>f   s
    z*filter_excluded_fields.<locals>.<dictcomp>)r/   r'   updateitems)r   r"   r   filtered_fieldsr   r8   r   r)   Y   s   	r)   $tuple[type[marshmallow.Schema], ...]c              	   C  sn   t | tjs
tdg }tD ] }t| |}zt| W n ty(   t|}Y nw || qt	| j
g|S )Nz6can only make a schema key based on a Schema instance.)r   r   r   	TypeError	MODIFIERSr'   hash	frozensetappendtuple	__class__)r
   	modifiersmodifier	attributer   r   r   make_schema_keyo   s   
rH   
componentsr   namer   counterintc                 C  s^   || j vr|S |stjd| dtdd n|dtt|  }|d7 }t| |t| |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   )schemasr1   r2   r3   lenr   get_unique_schema_name)rI   rJ   rK   r   r   r   rP      s   


rP   )r
   r   r   r   )r
   r   r   r   )r
   r   r   r    r   r!   )r   r!   )r   r!   r   r    r   r!   )r
   r   r   r=   )r   )rI   r   rJ   r   rK   rL   r   r   )__doc__
__future__r   r#   r1   r   marshmallow.class_registryr   apispec.corer   r?   r   r   r*   r(   r)   rH   rP   r   r   r   r   <module>   s"    




