o
    he                     @   sx  U d dl Z d dlZd dlZd dlmZmZmZ d dlmZ d dl	m
Z
mZ d dlmZmZmZmZmZmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% d dl&m'Z' d dl(m)Z) d d	l*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 d d
l3m4Z4 erd dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d dl*mAZAmBZBmCZCmDZDmEZE ee%ee"e e"eFef e"eFeef f  ZGdZHdZIeJeKeLeFeMeNeOe+eeeejPeeeQjReSjRhZTe!e#e  eUd< eVeWeXeYeZeeehZ[e!e#e  eUd< deFdefddZ\ddde%eF deJdeFfddZ]dedeMfd d!Z^d"ee#e  d#eFddfd$d%Z_d&ed'e%e#e e"e#e d(f df deMfd)d*Z`d+ed'e%e#e e"e#e d(f df deMfd,d-ZadeMfd.d/Zbd0eFdeMfd1d2Zce$d3Zdd4eedef d5eedef deedef fd6d7Zed4eeef d8eddfd9d:Zfd;d<d=eKd>eKd?eKdeMfd@dAZgdBedC dDeeFdEf dFe#dG ddHfdIdJZhdKe%e#dL e#dM f de#dL fdNdOZidPeFdeFfdQdRZjdPeFdeFfdSdTZke$dUZleFdVdWe%eel e"eld(f f dXeelgeFf deel fdYdZZmG d[d\ d\eFZnG d]d^ d^ZoG d_d` d`eoZpG dadb dbeoZqG dcdd ddZrdedfdgdhdidjdkdldmZsdndodeFfdpdqZte$drZudKeudeufdsdtZvdueFdeMfdvdwZwh dxZxdueFdeMfdydzZyez Z{d{ee d|ee deMfd}d~Z|dKedeFdefddZ}deeF deFdeFfddZ~dedeFde"eFe"eFd(f f fddZde#e deFde"eFe"e"eFd(f d(f f fddZdS )    N)OrderedDictdefaultdictdeque)deepcopy)islicezip_longest)BuiltinFunctionTypeCodeTypeFunctionTypeGeneratorType
LambdaType
ModuleType)TYPE_CHECKINGAbstractSetAnyCallable
CollectionDict	GeneratorIterableIteratorListMappingNoReturnOptionalSetTupleTypeTypeVarUnion)	Annotated)ConfigError)NoneTypeWithArgsTypesall_literal_valuesdisplay_as_typeget_args
get_originis_literal_typeis_union)version_info)	Signature)Path)
BaseConfig)	Dataclass)
ModelField	BaseModel)AbstractSetIntStrDictIntStrAnyIntStrMappingIntStrAnyReprArgs)import_stringsequence_likevalidate_field_namelenient_isinstancelenient_issubclass
in_ipythonis_valid_identifierdeep_updateupdate_not_nonealmost_equal_floats	get_modelto_camelto_lower_camelis_valid_fieldsmart_deepcopyPyObjectStrRepresentation
GetterDict
ValueItemsr*   ClassAttribute	path_typeROOT_KEYget_unique_discriminator_alias"get_discriminator_alias_and_valuesDUNDER_ATTRIBUTES__root__IMMUTABLE_NON_COLLECTIONS_TYPESBUILTIN_COLLECTIONSdotted_pathreturnc              
   C   s   ddl m} z| ddd\}}W n ty( } z	td|  d|d}~ww ||}zt||W S  tyK } ztd	| d
| d|d}~ww )z
    Stolen approximately from django. Import a dotted module path and return the attribute/class designated by the
    last name in the path. Raise ImportError if the import fails.
    r   )import_module .   "z!" doesn't look like a module pathNzModule "z" does not define a "z" attribute)	importlibrU   striprsplit
ValueErrorImportErrorgetattrAttributeError)rS   rU   module_path
class_nameemodule re   e/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/pydantic/v1/utils.pyr7   z   s   r7   P   )max_lenvrh   c                C   s   t dt t| trt| |d kr| d|d  d  S z|  } W n ty4   | j| } Y nw t| |krE| d|d  d } | S )z`
    Truncate a value and add a unicode ellipsis (three dots) to the end if it was too long
    z:`truncate` is no-longer used by pydantic and is deprecated   N   u   …rX   )	warningswarnDeprecationWarning
isinstancestrlen__repr__	TypeError	__class__)ri   rh   re   re   rf   truncate   s   ru   c                 C   s   t | ttttttfS N)ro   listtupleset	frozensetr   r   ri   re   re   rf   r8      s   r8   bases
field_namec                 C   s0   | D ]}t ||drtd| d| dqdS )zZ
    Ensure that the field's name does not shadow an existing attribute of the model.
    NzField name "zI" shadows a BaseModel attribute; use a different field name with "alias='z'".)r_   	NameError)r|   r}   basere   re   rf   r9      s   r9   oclass_or_tuple.c                 C   s"   zt | |W S  ty   Y dS w NF)ro   rs   )r   r   re   re   rf   r:      s
   r:   clsc                 C   s8   zt | to
t| |W S  ty   t | trY dS  w r   )ro   type
issubclassrs   r#   )r   r   re   re   rf   r;      s   
r;   c                   C   s$   zt d W dS  ty   Y dS w )zU
    Check whether we're in an ipython environment, including jupyter notebooks.
    __IPYTHON__FT)evalr~   re   re   re   rf   r<      s   
r<   
identifierc                 C   s   |   o	t|  S )z
    Checks that a string is a valid identifier and not a Python keyword.
    :param identifier: The identifier to test.
    :return: True if the identifier is valid.
    )isidentifierkeyword	iskeyword)r   re   re   rf   r=      s   r=   KeyTypemappingupdating_mappingsc                 G   sd   |   }|D ])}| D ]"\}}||v r*t|| tr*t|tr*t|| |||< q|||< qq|S rv   )copyitemsro   dictr>   )r   r   updated_mappingupdating_mappingkri   re   re   rf   r>      s    
r>   updatec                 K   s   |  dd | D  d S )Nc                 S   s   i | ]\}}|d ur||qS rv   re   ).0r   ri   re   re   rf   
<dictcomp>   s    z#update_not_none.<locals>.<dictcomp>)r   r   )r   r   re   re   rf   r?      s   r?   g:0yE>)deltavalue_1value_2r   c                C   s   t | | |kS )z4
    Return True if two floats are almost equal
    )abs)r   r   r   re   re   rf   r@      s   r@   init).Nfieldsr/   configr-   r+   c                 C   st  ddl m}m}m} ddlm} || j }i }d}	d}
t|ddD ]}|j	|j
u r.|}	q#|||j< q#|	rw|j}| D ]9\}}|j}||v sL||v rMq=t|s]|rZt|rZ|}nd}
q=|jsed|jini }|||jfd	|ji|||< q=|j|ju rd}
|	r|
rd
|jfd|j
fg}dd |D |krd}n|	j}||v r|d7 }||v s|	j|d||< |t| ddS )z:
    Generate signature for model based on its fields
    r   )	Parameterr+   	signature)ExtraNFrX   Tdefault
annotation__pydantic_self__datac                 S   s   g | ]}|j |jfqS re   )namekind)r   pre   re   rf   
<listcomp>      z,generate_model_signature.<locals>.<listcomp>
extra_data_r   )
parametersreturn_annotation)inspectr   r+   r   pydantic.v1.configr   r   valuesr   r   VAR_KEYWORDr   allow_population_by_field_namer   aliasr=   requiredr   KEYWORD_ONLYr   extraallowPOSITIONAL_OR_KEYWORDreplacerw   )r   r   r   r   r+   r   r   present_paramsmerged_paramsvar_kw
use_var_kwparamallow_namesr}   field
param_namekwargsdefault_model_signaturevar_kw_namere   re   rf   generate_model_signature   sX   r   objr1   r.   c                 C   sD   ddl m} z| j}W n ty   | }Y nw t||s td|S )Nr   r0   z7Unsupported type, must be either BaseModel or dataclass)pydantic.v1.mainr1   __pydantic_model__r`   r   rs   )r   r1   	model_clsre   re   rf   rA   -  s   

rA   stringc                 C   s   d dd | dD S )N c                 s   s    | ]}|  V  qd S rv   )
capitalize)r   wordre   re   rf   	<genexpr>;  s    zto_camel.<locals>.<genexpr>r   )joinsplit)r   re   re   rf   rB   :     rB   c                 C   s4   t | dkrt| }|d  |dd   S |  S )NrX   r   )rq   rB   lower)r   pascal_stringre   re   rf   rC   >  s   rC   T)name_factory
input_listr   c                C   sJ   g }g }| D ]}||}||vr| | | | q||||< q|S )z
    Make a list unique while maintaining order.
    We update the list if another one with the same name is set
    (e.g. root validator overridden in subclass)
    )appendindex)r   r   resultresult_namesri   v_namere   re   rf   unique_listH  s   

r   c                   @   s   e Zd ZdZdefddZdS )rF   z
    String class where repr doesn't include quotes. Useful with Representation when you want to return a string
    representation of something that valid (or pseudo-valid) python.
    rT   c                 C      t | S rv   )rp   selfre   re   rf   rr   e  s   zPyObjectStr.__repr__N)__name__
__module____qualname____doc__rp   rr   re   re   re   rf   rF   _  s    rF   c                	   @   s   e Zd ZU dZe Zeedf ed< dddZ	defdd	Z
d
edefddZdeegef dedeeddf fddZdefddZdefddZdddZdS )rG   z
    Mixin to provide __str__, __repr__, and __pretty__ methods. See #884 for more details.

    __pretty__ is used by [devtools](https://python-devtools.helpmanual.io/) to provide human readable representations
    of objects.
    .	__slots__rT   r6   c                    s"    fdd j D }dd |D S )a6  
        Returns the attributes to show in __str__, __repr__, and __pretty__ this is generally overridden.

        Can either return:
        * name - value pairs, e.g.: `[('foo_name', 'foo'), ('bar_name', ['b', 'a', 'r'])]`
        * or, just values, e.g.: `[(None, 'foo'), (None, ['b', 'a', 'r'])]`
        c                 3   s    | ]
}|t  |fV  qd S rv   )r_   )r   sr   re   rf   r   {      z/Representation.__repr_args__.<locals>.<genexpr>c                 S   s    g | ]\}}|d ur||fqS rv   re   r   ari   re   re   rf   r   |  s     z0Representation.__repr_args__.<locals>.<listcomp>)r   )r   attrsre   r   rf   __repr_args__s  s   zRepresentation.__repr_args__c                 C   s   | j jS )zA
        Name of the instance's class, used in __repr__.
        )rt   r   r   re   re   rf   __repr_name__~  s   zRepresentation.__repr_name__join_strc                 C   s   | dd |  D S )Nc                 s   s2    | ]\}}|d u rt |n| d|V  qd S )N=)reprr   re   re   rf   r     s   0 z.Representation.__repr_str__.<locals>.<genexpr>)r   r   )r   r   re   re   rf   __repr_str__  s   zRepresentation.__repr_str__fmtr   Nc                 k   s`    |   d V  dV  |  D ]\}}|dur|d V  ||V  dV  dV  qdV  dV  dS )	z
        Used by devtools (https://python-devtools.helpmanual.io/) to provide a human readable representations of objects
        (rX   Nr   ,r   ))r   r   )r   r   r   r   valuere   re   rf   
__pretty__  s   


zRepresentation.__pretty__c                 C   s
   |  dS )NrV   )r   r   re   re   rf   __str__     
zRepresentation.__str__c                 C   s   |    d| d dS )Nr   , r   )r   r   r   re   re   rf   rr     r   zRepresentation.__repr__RichReprResultc                 c   s2    |   D ]\}}|du r|V  q||fV  qdS )zGet fields for Rich libraryN)r   )r   r   
field_reprre   re   rf   __rich_repr__  s   zRepresentation.__rich_repr__rT   r6   )rT   r   )r   r   r   r   rx   r   r   rp   __annotations__r   r   r   r   r   r   r   r   rr   r   re   re   re   rf   rG   i  s   
 
*rG   c                   @   s   e Zd ZdZdZdefddZdedefdd	Zd%dededefddZ	de
e fddZdee fddZdee fddZdeeeef  fddZdee fddZdefddZdedefddZdedefddZd&d!d"Zdefd#d$Zd
S )'rH   z
    Hack to make object's smell just enough like dicts for validate_model.

    We can't inherit from Mapping[str, Any] because it upsets cython so we have to implement all methods ourselves.
    _objr   c                 C   s
   || _ d S rv   r  )r   r   re   re   rf   __init__  r   zGetterDict.__init__keyrT   c              
   C   s2   zt | j|W S  ty } zt||d }~ww rv   )r_   r  r`   KeyError)r   r  rc   re   re   rf   __getitem__  s   
zGetterDict.__getitem__Nr   c                 C   s   t | j||S rv   )r_   r  )r   r  r   re   re   rf   get     zGetterDict.getc                 C   s   t  S )zn
        We don't want to get any other attributes of obj if the model didn't explicitly ask for them
        )ry   r   re   re   rf   
extra_keys  s   zGetterDict.extra_keysc                 C   r   )z
        Keys of the pseudo dictionary, uses a list not set so order information can be maintained like python
        dictionaries.
        )rw   r   re   re   rf   keys  s   zGetterDict.keysc                    s    fdd D S )Nc                    s   g | ]} | qS re   re   r   r   r   re   rf   r     s    z%GetterDict.values.<locals>.<listcomp>re   r   re   r   rf   r        zGetterDict.valuesc                 c   s     | D ]
}||  |fV  qd S rv   )r  )r   r   re   re   rf   r     s   zGetterDict.itemsc                 c   s&    t | jD ]
}|ds|V  qd S )Nr   )dirr  
startswith)r   r   re   re   rf   __iter__  s   
zGetterDict.__iter__c                 C   s   t dd | D S )Nc                 s   s    | ]}d V  qdS )rX   Nre   )r   r   re   re   rf   r     s    z%GetterDict.__len__.<locals>.<genexpr>)sumr   re   re   rf   __len__  r  zGetterDict.__len__itemc                 C   s   ||   v S rv   )r
  r   r  re   re   rf   __contains__     zGetterDict.__contains__otherc                 C   s   t | t | kS rv   )r   r   )r   r  re   re   rf   __eq__  s   zGetterDict.__eq__r6   c                 C   s   d t | fgS rv   )r   r   re   re   rf   r     r  zGetterDict.__repr_args__c                 C   s   dt | j dS )NzGetterDict[])r%   r  r   re   re   rf   r     r  zGetterDict.__repr_name__rv   r   )r   r   r   r   r   r   r  rp   r  r  r   r	  r   r
  r   r   r   r   r  intr  boolr  r  r   r   re   re   re   rf   rH     s     
rH   c                
   @   s   e Zd ZdZdZdeded ddfdd	Zd
edefddZ	d
edefddZ
dddeed  fddZdddeddfddZed(dedededefddZeded ddfddZededefd d!Zed"edefd#d$Zd)d&d'ZdS )*rI   zY
    Class for more convenient calculation of excluded or included fields on values.
    )_items_typer   r   )r2   r5   rT   Nc                 C   s2   |  |}t|ttfr| |t|}|| _d S rv   )_coerce_itemsro   rw   rx   _normalize_indexesrq   r  )r   r   r   re   re   rf   r    s   

zValueItems.__init__r  c                 C   s   |  | j|S )z`
        Check if item is fully excluded.

        :param item: key or index of a value
        )is_truer  r  r  re   re   rf   is_excluded  s   zValueItems.is_excludedc                 C   s
   || j v S )zh
        Check if value is contained in self._items

        :param item: key or index of value
        r  r  re   re   rf   is_included  s   
zValueItems.is_includedrc   r4   c                 C   s   | j |}| |s|S dS )z
        :param e: key or index of element on value
        :return: raw values for element if self._items is dict and contain needed element
        N)r  r  r  )r   rc   r  re   re   rf   for_element  s   zValueItems.for_elementr5   v_lengthr3   c           	      C   s  i }d}|  D ]F\}}t|ts&t|ts&| |s&td| d|j |dkr0| |}qt|ts9td|dk rA|| n|}| 	||
|||< q|sS|S | |rgt|D ]}||d q\|S t|D ]}||i }| |s| 	||||< qk|S )af  
        :param items: dict or set of indexes which will be normalized
        :param v_length: length of sequence indexes of which will be

        >>> self._normalize_indexes({0: True, -2: True, -1: True}, 4)
        {0: True, 2: True, 3: True}
        >>> self._normalize_indexes({'__all__': True}, 4)
        {0: True, 1: True, 2: True, 3: True}
        Nz,Unexpected type of exclude value for index "z" __all__zExcluding fields from a sequence of sub-models or dicts must be performed index-wise: expected integer keys or keyword "__all__"r   .)r   ro   r   r   r  rs   rt   _coerce_valuer  merger  range
setdefault)	r   r   r$  normalized_items	all_itemsiri   normalized_inormalized_itemre   re   rf   r    s4   



zValueItems._normalize_indexesFr   override	intersectc                    s   |  |    du r S |  s du rS | r&|r$ S S |r;fdd D  fddD  }nt  fddD  }i }|D ]}| j |||d}|durd|||< qL|S )ae  
        Merge a ``base`` item with an ``override`` item.

        Both ``base`` and ``override`` are converted to dictionaries if possible.
        Sets are converted to dictionaries with the sets entries as keys and
        Ellipsis as values.

        Each key-value pair existing in ``base`` is merged with ``override``,
        while the rest of the key-value pairs are updated recursively with this function.

        Merging takes place based on the "union" of keys if ``intersect`` is
        set to ``False`` (default) and on the intersection of keys if
        ``intersect`` is set to ``True``.
        Nc                       g | ]}| v r|qS re   re   r  )r/  re   rf   r   M  r   z$ValueItems.merge.<locals>.<listcomp>c                    r1  re   re   r  r   re   rf   r   M  r   c                    s   g | ]}| vr|qS re   re   r  r2  re   rf   r   O  r   )r0  )r&  r  rw   r'  r  )r   r   r/  r0  
merge_keysmergedr   merged_itemre   )r   r/  rf   r'  2  s$   


&zValueItems.mergec                 C   sJ   t | tr	 | S t | trt| d} | S t| dd}t| d|  | S )N.rt   z???z!Unexpected type of exclude value )ro   r   r   r   fromkeysr_   assert_never)r   rb   re   re   rf   r  Y  s   
	
zValueItems._coerce_itemsc                 C   s    |d u s	|  |r|S | |S rv   )r  r  )r   r   re   re   rf   r&  g  s   
zValueItems._coerce_valueri   c                 C   s   | du p| du S )NT.re   r{   re   re   rf   r  m  s   zValueItems.is_truer6   c                 C   s   d | j fgS rv   r!  r   re   re   rf   r   q  r  zValueItems.__repr_args__)Fr   )r   r   r   r   r   r   r   r  r  r   r"  r   r#  r  r  classmethodr'  staticmethodr  r&  r  r   re   re   re   rf   rI     s"    	'&rI   c                   @   sD   e Zd ZdZdZdededdfddZd	ed
ee ddfddZ	dS )rJ   z1
    Hide class attribute from its instances
    r   r   r   r   rT   Nc                 C   s   || _ || _d S rv   r:  )r   r   r   re   re   rf   r    s   
zClassAttribute.__init__instanceownerc                 C   s&   |d u r| j S t| jd|jd)Nz attribute of z is class-only)r   r`   r   r   )r   r;  r<  re   re   rf   __get__  s   zClassAttribute.__get__)
r   r   r   r   r   rp   r   r  r   r=  re   re   re   rf   rJ   u  s
    rJ   	directoryfilezmount pointsymlinkzblock devicezchar deviceFIFOsocket)is_diris_fileis_mount
is_symlinkis_block_deviceis_char_deviceis_fifo	is_socketr   r,   c                 C   s:   |   sJ dt D ]\}}t| | r|  S qdS )z0
    Find out what sort of thing a path is.
    zpath does not existunknown)exists
path_typesr   r_   )r   methodr   re   re   rf   rK     s   rK   Objc              
   C   sj   | j }|tv r	| S z| s|tv r!|tu r| W S |  W S W t| S W t| S  tttfy4   Y t| S w )z
    Return type as is for immutable built-in types
    Use obj.copy() for built-in empty collections
    Use copy.deepcopy() for non-empty collections and unknown objects
    )	rt   rQ   rR   rx   r   rs   r]   RuntimeErrorr   )r   obj_typere   re   rf   rE     s   rE   r   c                 C   s   |  dsdS t| kS )Nr   T)r  rL   r   re   re   rf   rD     s   
rD   >	   r   r   r   __classcell____orig_bases____orig_class__r   __firstlineno____static_attributes__c                 C   s   t |  o| tvS rv   )rD   rO   r   re   re   rf   is_valid_private_name  r  rW  leftrightc                 C   s*   t | |tdD ]\}}||ur dS qdS )a  
    Check that the items of `left` are the same objects as those in `right`.

    >>> a, b = object(), object()
    >>> all_identical([a, b, a], [a, b, a])
    True
    >>> all_identical([a, b, [a]], [a, b, [a]])  # new list object, while "equal" is not "identical"
    False
    )	fillvalueFT)r   _EMPTY)rX  rY  	left_item
right_itemre   re   rf   all_identical  s
   
r^  msgc                 C   s   t |)z
    Helper to make sure that we have covered all possible types.

    This is mostly useful for ``mypy``, docs:
    https://mypy.readthedocs.io/en/latest/literal_types.html#exhaustive-checks
    )rs   )r   r_  re   re   rf   r7    s   r7  all_aliasesdiscriminator_keyc                 C   s<   t | }t|dkrtd|ddt|  d| S )zNValidate that all aliases are the same and if that's the case return the aliasrX   zAliases for discriminator z must be the same (got r   r   )ry   rq   r!   r   sortedpop)r`  ra  unique_aliasesre   re   rf   rM     s   rM   tpc              
   C   sV  t | dd}t| tu rt| d } t| dr| j} tt| r2t| |\}}|tdd |D fS |r[| j	t
 j}t||\}}tt|dkrUtd|d	t| ||d fS z| j	| j}W n- tyy } z
td
| jd|d}~w ty } ztd| jd||d}~ww t|std|d| jd| j	| jt|fS )z
    Get alias and all valid values in the `Literal` type of the discriminator field
    `tp` can be a `BaseModel` class or directly an `Annotated` `Union` of many.
    __custom_root_type__Fr   r   c                 s   s    | ]
}|D ]}|V  qqd S rv   re   )r   r   ri   re   re   rf   r     r   z5get_discriminator_alias_and_values.<locals>.<genexpr>rX   zField z& is not the same for all submodels of zType z* is not a valid `BaseModel` or `dataclass`NzModel z% needs a discriminator field for key z
 of model z needs to be a `Literal`)r_   r'   r    r&   hasattrr   r)   _get_union_alias_and_all_valuesrx   
__fields__rL   type_rq   ry   r!   r%   r`   rs   r   r  r(   r   r$   )re  ra  is_root_modelr   
all_values
union_typet_discriminator_typerc   re   re   rf   rN     s8   
rN   rm  c                    s0    fddt | D }t| \}}t| |fS )Nc                    s   g | ]}t | qS re   )rN   )r   tra  re   rf   r   #  s    z3_get_union_alias_and_all_values.<locals>.<listcomp>)r&   ziprM   )rm  ra  zipped_aliases_valuesr`  rl  re   rp  rf   rh     s   rh  )r   rl   weakrefcollectionsr   r   r   r   r   	itertoolsr   r   typesr   r	   r
   r   r   r   typingr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typing_extensionsr    pydantic.v1.errorsr!   pydantic.v1.typingr"   r#   r$   r%   r&   r'   r(   r)   pydantic.v1.versionr*   r   r+   pathlibr,   r   r-   pydantic.v1.dataclassesr.   pydantic.v1.fieldsr/   r   r1   r2   r3   r4   r5   r6   rp   r   r%  rL   r  floatcomplexr  bytesr   refNotImplementedrt   EllipsisrQ   r   rw   ry   rx   rz   r   rR   r7   ru   r8   r9   r:   r;   r<   r=   r   r>   r?   r@   r   rA   rB   rC   r   r   rF   rG   rH   rI   rJ   rM  rK   rO  rE   rD   rO   rW  objectr[  r^  r7  rM   rN   rh  re   re   re   rf   <module>   s   
  P(
* 00		. 

&A

<> 
&
)