
    	h>                       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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&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"Z0dd#dAd%Z1dBd*Z2dCd,Z3d<d-Z4d=d.Z5dd#dAd/Z6dBd0Z7dCd1Z8 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_sequence   )is_base64_file_input)
get_originis_typeddict)is_list_typeis_union_typeextract_type_argis_iterable_typeis_required_typeis_sequence_typeis_annotated_typestrip_annotated_type_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        e/var/www/html/web-builder-api.evdpl.com/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,   )r2   s    r3   __repr__zPropertyInfo.__repr__I   sn    .)  h  h4:  h  h  h  himi}  h  h  RV  Rd  h  h  h  	hr5   )
r(   r'   r*   r)   r+   r'   r,   r'   r.   r/   )r.   r6   )r9   
__module____qualname____doc____annotations__r4   r   r:    r5   r3   r&   r&   ,   s           !!!!
 !(,&*$(+ + + + + + h h h Xh h hr5   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@   rB   s     r3   maybe_transformrG   N   s     |tT=)))r5   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@   rB   transformeds      r3   rE   rE   \   s0    & 'tT=8Q8QRRRKK   r5   i  )maxsizetype_rM   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   )rQ   s    r3   _get_annotated_typerT   s   s>      #" 4r5   keyr6   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   )rT   r   
isinstancer&   r(   )rU   rQ   annotated_typer   rK   s        r3   _maybe_transform_keyrY      sr    
 )//N
 >**122.K! $ $
j,// 	$J4D4P####Jr5   rK   boolc                .    | t           k    p
| t          k    S r1   )floatintrJ   s    r3   _no_transform_neededr^      s    3*"33r5   )
inner_typer_   c          
       	 ddl m} t                    }t          |          p|}t	          |          rt          |           rt          | |          S |t          k    rDt          |           r5t          |          d         		fd| 	                                D             S t          |          rt          |           sft          |          r$t          |           rt          | t                    r3t!          |          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 ]}t1          | |          } | S t          | t2          j                  r || d	d
t7          | dd                    S t9                    }|| S t          |          dd         }|D ];t          t:                    r$j        t?          | 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.
    r   
model_dumpNr   c                :    i | ]\  }}|t          |           S rJ   rL   .0rU   value
items_types      r3   
<dictcomp>z(_transform_recursive.<locals>.<dictcomp>   .    gggJCQV)%JGGGgggr5   r   c                4    g | ]}t          |           S )rK   r_   rf   rh   drK   r_   s     r3   
<listcomp>z(_transform_recursive.<locals>.<listcomp>   s*    dddZ[$Q:*UUUdddr5   rn   Tjson__api_exclude__)exclude_unsetmodeexclude)!_compatrc   r    r   r   r   _transform_typeddictdictr   itemsr   r   r   r   rW   r6   r   r   r   rA   r   r^   listr   rL   pydantic	BaseModelgetattrrT   r&   r*   _format_datar+   
r@   rK   r_   rc   stripped_typeoriginsubtyperX   r   rj   s
    ``      @r3   rL   rL      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 ]++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z$dQUWhjnIoIopppp(44N >**122.K! U U
j,// 	UJ4E4Qj&79STTTTTKr5   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)rW   r   r	   	isoformatstrftimer   pathlibPath
read_bytesioIOBasereadr6   encodebytesRuntimeErrorrM   r#   	b64encodedecoder@   r   r+   binarys       r3   r   r      s6   $x()) 2i>>###h?#>==111(3D99%)dGL)) 	)__&&FFbi(( 	)YY[[F&#&& )&%(( 	][D[[TRX\\[[\\\''..w777Kr5   Mapping[str, object]c                    i }t          |d          }|                                 D ]O\  }}t          |          s |j        |          }||||<   -t	          ||          |t          ||          <   P|S NT)include_extrasrJ   )r   rz   r   getrL   rY   r@   rB   resultr   rU   ri   rQ   s          r3   rx   rx     s     !#F tDDDKjjll e e
U 	 $$=F3KK7KE^c7d7d7dF'U3344Mr5   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_transformrF   s     r3   async_maybe_transformr     s4       |t }555555555r5   c                   K   t          | t          t          |                     d{V }t          t          |          S )rI   rJ   N)_async_transform_recursiver   rM   r!   rN   s      r3   r   r   )  sF      & 34D}D]D]^^^^^^^^^KK   r5   c                 	K   ddl m} t                    }t          |          p|}t	          |          r%t          |           rt          | |           d{V S |t          k    rDt          |           r5t          |          d         		fd| 	                                D             S t          |          rt          |           sft          |          r$t          |           rt          | t                    r3t!          |          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 ]}t1          | |           d{V } | S t          | t2          j                  r || d	d
          S t7                    }|| S t          |          dd         }|D ]At          t8                    r*j        #t=          | j        j                   d{V c S B| S )ra   r   rb   Nr   c                :    i | ]\  }}|t          |           S re   rf   rg   s      r3   rk   z._async_transform_recursive.<locals>.<dictcomp>^  rl   r5   r   c                D   K   g | ]}t          |            d{V S )rn   N)r   ro   s     r3   rq   z._async_transform_recursive.<locals>.<listcomp>w  sA      pppfg0zV`aaaaaaaaapppr5   rn   Trr   )rt   ru   ) rw   rc   r    r   r   r   _async_transform_typeddictry   r   rz   r   r   r   r   rW   r6   r   r   r   rA   r   r^   r{   r   r   r|   r}   rT   r&   r*   _async_format_datar+   r   s
    ``      @r3   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 ]++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z$d@@@@(44N >**122.K! a a
j,// 	aJ4E4Q+D*2CZE_```````````Kr5   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   )rW   r   r	   r   r   r   r   r   anyior   r   r   r   r6   r   r   r   rM   r#   r   r   r   s       r3   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Kr5   c                  K   i }t          |d          }|                                 D ]U\  }}t          |          s |j        |          }||||<   -t	          ||           d {V |t          ||          <   V|S r   )r   rz   r   r   r   rY   r   s          r3   r   r     s       !#F tDDDKjjll q q
U 	 $$=F3KK=WX]jo=p=p=p7p7p7p7p7p7pF'U3344Mr5   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       r3   r   r     s     37Sabbbbr5   )r@   rA   rB   rA   r.   rC   )r@   r!   rB   rA   r.   r!   )rQ   rM   r.   rR   )rU   r6   rQ   rM   r.   r6   )rK   rM   r.   rZ   )r@   rA   rK   rM   r_   rR   r.   rA   )r@   rA   r   r   r+   r'   r.   rA   )r@   r   rB   rM   r.   r   )NNF)
r   r   r   r   r   r   r   rZ   r.   r   )9
__future__r   r   r#   r   typingr   r   r   r   r	   r   typing_extensionsr
   r   r   r   r   r   r|   _utilsr   r   r   r   r   r   _filesr   rw   r   r   _typingr   r   r   r   r   r   r   r    r!   r   r&   rG   rE   rT   rY   r^   rL   r   rx   r   r   r   r   r   r?   r5   r3   <module>r      sj   " " " " " " 				   . . . . . . . . . . . . # # # # # # # # \ \ \ \ \ \ \ \ \ \ \ \                  * ) ) ) ) ) - - - - - - - -	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 WT]] 67h h h h h h h hD
* 
* 
* 
*! ! ! !. 4      &4 4 4 4 #	O O O O O Od   6   *
6 
6 
6 
6! ! ! !6 #	O O O O O Od   6   * 4 '+(, 	c c c c c c cr5   