
    fj1=                       d dl mZ d dlZd dlZd dlZd dlmZmZmZm	Z	 d dl
mZm
Z
 d dlmZmZmZmZ d dlZd dlZddlmZmZmZmZmZ dd	lmZ dd
lmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'  ed          Z(ed         Z) G d d          Z*d<dZ+d=dZ, ed          d>d            Z-d?dZ.d@d"Z/dd#dAd%Z0dBd*Z1dCd,Z2d<d-Z3d=d.Z4dd#dAd/Z5dBd0Z6dCd1Z7 ed          	 	 	 dDdEd;            ZdS )F    )annotationsN)AnyMappingTypeVarcast)datedatetime)Literalget_argsoverrideget_type_hints   )is_listis_given	lru_cache
is_mappingis_iterable   )is_base64_file_input)is_list_typeis_union_typeextract_type_argis_iterable_typeis_required_typeis_annotated_typestrip_annotated_type)
get_origin
model_dumpis_typeddict_T)iso8601base64customc                  h    e Zd ZU dZded<   ded<   ded<   ded<   ddddd	ddZedd            ZdS )PropertyInfoao  Metadata class to be used in Annotated types to provide information about a given type.

    For example:

    class MyParams(TypedDict):
        account_holder_name: Annotated[str, PropertyInfo(alias='accountHolderName')]

    This means that {'account_holder_name': 'Robert'} will be transformed to {'accountHolderName': 'Robert'} before being sent to the API.
    
str | NonealiasPropertyFormat | Noneformatformat_templatediscriminatorNr'   r)   r*   r+   returnNonec               >    || _         || _        || _        || _        d S Nr,   )selfr'   r)   r*   r+   s        \/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/openai/_utils/_transform.py__init__zPropertyInfo.__init__:   s(     
.*    strc           
     `    | j         j         d| j         d| j         d| j         d| j         d
S )Nz(alias='z
', format=z, format_template='z', discriminator='z'))	__class____name__r'   r)   r*   r+   )r1   s    r2   __repr__zPropertyInfo.__repr__G   sn    .)  h  h4:  h  h  h  himi}  h  h  RV  Rd  h  h  h  	hr4   )
r'   r&   r)   r(   r*   r&   r+   r&   r-   r.   )r-   r5   )r8   
__module____qualname____doc____annotations__r3   r   r9    r4   r2   r%   r%   *   s           !!!!
 !(,&*$(+ + + + + + h h h Xh h hr4   r%   dataobjectexpected_typer-   
Any | Nonec                *    | dS t          | |          S )ziWrapper over `transform()` that allows `None` to be passed.

    See `transform()` for more details.
    N)	transformr?   rA   s     r2   maybe_transformrF   L   s     |tT=)))r4   c                t    t          | t          t          |                    }t          t          |          S )  Transform dictionaries based off of type information from the given type, for example:

    ```py
    class Params(TypedDict, total=False):
        card_id: Required[Annotated[str, PropertyInfo(alias="cardID")]]


    transformed = transform({"card_id": "<my card ID>"}, Params)
    # {'cardID': '<my card ID>'}
    ```

    Any keys / data that does not have type information given will be included as is.

    It should be noted that the transformations that this function does are not represented in the type system.
    
annotation)_transform_recursiver   typer    r?   rA   transformeds      r2   rD   rD   Z   s0    & 'tT=8Q8QRRRKK   r4   i  )maxsizetype_rL   type | Nonec                p    t          |           rt          |           d         } t          |           r| S dS )zIf the given type is an `Annotated` type then it is returned, if not `None` is returned.

    This also unwraps the type when applicable, e.g. `Required[Annotated[T, ...]]`
    r   N)r   r   r   )rP   s    r2   _get_annotated_typerS   q   s>      #" 4r4   keyr5   c                    t          |          }|| S t          |          dd         }|D ]'}t          |t                    r|j        	|j        c S (| S )zTransform the given `data` based on the annotations provided in `type_`.

    Note: this function only looks at `Annotated` types that contain `PropertyInfo` metadata.
    Nr   )rS   r   
isinstancer%   r'   )rT   rP   annotated_typer   rJ   s        r2   _maybe_transform_keyrX      sr    
 )//N
 >**122.K! $ $
j,// 	$J4D4P####Jr4   rJ   boolc                .    | t           k    p
| t          k    S r0   )floatintrI   s    r2   _no_transform_neededr]      s    3*"33r4   )
inner_typer^   c          
        t                    }t          |          p|}t          |          rt          |           rt	          | |          S |t
          k    rDt          |           r5t          |          d         fd|                                 D             S t          |          rt          |           s3t          |          rt          |           rt          | t                    sxt          | t
                    rt          t          |           S t!          |d          t#                    r t          |           r| S t%          |           S fd| D             S t'          |          r&t          |          D ]}t)          | |          } | S t          | t*          j                  r"t/          | ddt1          | d	d          
          S t3                    }|| S t          |          dd         }|D ];t          t4                    r$j        t9          | j        j                  c S <| S )  Transform the given data against the expected type.

    Args:
        annotation: The direct type annotation given to the particular piece of data.
            This may or may not be wrapped in metadata types, e.g. `Required[T]`, `Annotated[T, ...]` etc

        inner_type: If applicable, this is the "inside" type. This is useful in certain cases where the outside type
            is a container type such as `List[T]`. In that case `inner_type` should be set to `T` so that each entry in
            the list can be transformed using the metadata from the container type.

            Defaults to the same value as the `annotation` argument.
    Nr   c                :    i | ]\  }}|t          |           S rI   rK   .0rT   value
items_types      r2   
<dictcomp>z(_transform_recursive.<locals>.<dictcomp>   .    gggJCQV)%JGGGgggr4   r   c                4    g | ]}t          |           S )rJ   r^   rc   re   drJ   r^   s     r2   
<listcomp>z(_transform_recursive.<locals>.<listcomp>   s*    dddZ[$Q:*UUUdddr4   rk   Tjson__api_exclude__)exclude_unsetmodeexclude)r   r   r   r   _transform_typeddictdictr   itemsr   r   r   r   rV   r5   r   r@   r   r]   listr   rK   pydantic	BaseModelr   getattrrS   r%   r)   _format_datar*   	r?   rJ   r^   stripped_typeoriginsubtyperW   r   rg   s	    ``     @r2   rK   rK      s   $ 
(44M&&7-FM"" 9z$'7'7 9#D-888~~*T**~m,,Q/
ggggZ^ZdZdZfZfgggg 
m	$	$e)0e ]++	e 1<D0A0A	e KUUY[^J_J_	e dD!! 	&%%%%mQ77

++ 	
 t}} ::ddddd_cdddd]## 
  .. 	Y 	YG'PWXXXDD$*++ q$dQUWhjnIoIopppp(44N >**122.K! U U
j,// 	UJ4E4Qj&79STTTTTKr4   format_PropertyFormatr*   r&   c                   t          | t          t          f          r7|dk    r|                                 S |dk    r||                     |          S |dk    rt          |           rd }t          | t          j                  r|                                 }nWt          | t          j
                  r=|                                 }t          |t                    r|                                }t          |t                    s"t          d|  dt!          |                     t#          j        |                              d          S | S Nr!   r#   r"   zCould not read bytes from z; Received ascii)rV   r   r	   	isoformatstrftimer   pathlibPath
read_bytesioIOBasereadr5   encodebytesRuntimeErrorrL   r"   	b64encodedecoder?   r   r*   binarys       r2   r{   r{      s6   $x()) 2i>>###h?#>==111(3D99%)dGL)) 	)__&&FFbi(( 	)YY[[F&#&& )&%(( 	][D[[TRX\\[[\\\''..w777Kr4   Mapping[str, object]c                    i }t          |d          }|                                 D ]O\  }}t          |          s |j        |          }||||<   -t	          ||          |t          ||          <   P|S NT)include_extrasrI   )r   rv   r   getrK   rX   r?   rA   resultr   rT   rf   rP   s          r2   rt   rt     s     !#F tDDDKjjll e e
U 	 $$=F3KK7KE^c7d7d7dF'U3344Mr4   c                :   K   | dS t          | |           d{V S )zuWrapper over `async_transform()` that allows `None` to be passed.

    See `async_transform()` for more details.
    N)async_transformrE   s     r2   async_maybe_transformr     s4       |t }555555555r4   c                   K   t          | t          t          |                     d{V }t          t          |          S )rH   rI   N)_async_transform_recursiver   rL   r    rM   s      r2   r   r   #  sF      & 34D}D]D]^^^^^^^^^KK   r4   c                 K   t                    }t          |          p|}t          |          r%t          |           rt	          | |           d{V S |t
          k    rDt          |           r5t          |          d         fd|                                 D             S t          |          rt          |           s3t          |          rt          |           rt          | t                    s~t          | t
                    rt          t          |           S t!          |d          t#                    r t          |           r| S t%          |           S fd| D              d{V S t'          |          r,t          |          D ]}t)          | |           d{V } | S t          | t*          j                  rt/          | dd	          S t1                    }|| S t          |          dd         }|D ]At          t2                    r*j        #t7          | j        j                   d{V c S B| S )
r`   Nr   c                :    i | ]\  }}|t          |           S rb   rc   rd   s      r2   rh   z._async_transform_recursive.<locals>.<dictcomp>V  ri   r4   r   c                D   K   g | ]}t          |            d{V S )rk   N)r   rl   s     r2   rn   z._async_transform_recursive.<locals>.<listcomp>m  sA      pppfg0zV`aaaaaaaaapppr4   rk   Tro   )rq   rr   )r   r   r   r   _async_transform_typeddictru   r   rv   r   r   r   r   rV   r5   r   r@   r   r]   rw   r   r   rx   ry   r   rS   r%   r)   _async_format_datar*   r|   s	    ``     @r2   r   r   :  s     $ 
(44M&&7-FM"" Ez$'7'7 E/mDDDDDDDDD~~*T**~m,,Q/
ggggZ^ZdZdZfZfgggg 
m	$	$q)0q ]++	q 1<D0A0A	q KUUY[^J_J_	q dD!! 	&%%%%mQ77

++ 	
 t}} ::pppppkopppppppppp]## 
  .. 	e 	eG3DZ\cdddddddddDD$*++ A$d@@@@(44N >**122.K! a a
j,// 	aJ4E4Q+D*2CZE_```````````Kr4   c                  K   t          | t          t          f          r7|dk    r|                                 S |dk    r||                     |          S |dk    rt          |           rd }t          | t          j                  r-t          j        |           	                                 d {V }nWt          | t          j                  r=|                                 }t          |t                    r|                                }t          |t                    s"t!          d|  dt#          |                     t%          j        |                              d          S | S r   )rV   r   r	   r   r   r   r   r   anyior   r   r   r   r5   r   r   r   rL   r"   r   r   r   s       r2   r   r     sX     $x()) 2i>>###h?#>==111(3D99%)dGL)) 	) :d++6688888888FFbi(( 	)YY[[F&#&& )&%(( 	][D[[TRX\\[[\\\''..w777Kr4   c                  K   i }t          |d          }|                                 D ]U\  }}t          |          s |j        |          }||||<   -t	          ||           d {V |t          ||          <   V|S r   )r   rv   r   r   r   rX   r   s          r2   r   r     s       !#F tDDDKjjll q q
U 	 $$=F3KK=WX]jo=p=p=p7p7p7p7p7p7pF'U3344Mr4   Fobjr   globalnsdict[str, Any] | NonelocalnsMapping[str, Any] | Noner   dict[str, Any]c                (    t          | |||          S )N)r   r   r   )_get_type_hints)r   r   r   r   s       r2   r   r     s     37Sabbbbr4   )r?   r@   rA   r@   r-   rB   )r?   r    rA   r@   r-   r    )rP   rL   r-   rQ   )rT   r5   rP   rL   r-   r5   )rJ   rL   r-   rY   )r?   r@   rJ   rL   r^   rQ   r-   r@   )r?   r@   r   r   r*   r&   r-   r@   )r?   r   rA   rL   r-   r   )NNF)
r   r   r   r   r   r   r   rY   r-   r   )8
__future__r   r   r"   r   typingr   r   r   r   r	   r   typing_extensionsr
   r   r   r   r   r   rx   _utilsr   r   r   r   r   _filesr   _typingr   r   r   r   r   r   r   _compatr   r   r   r    r   r%   rF   rD   rS   rX   r]   rK   r{   rt   r   r   r   r   r   r>   r4   r2   <module>r      s\   " " " " " " 				   . . . . . . . . . . . . # # # # # # # # \ \ \ \ \ \ \ \ \ \ \ \                * ) ) ) ) )                  ; : : : : : : : : :WT]] 67h h h h h h h hD
* 
* 
* 
*! ! ! !. 4      &4 4 4 4 #	K K K K K K\   6   *
6 
6 
6 
6! ! ! !6 #	K K K K K K\   6   * 4 '+(, 	c c c c c c cr4   