
    ~i5@                       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        r/root/.openclaw/workspace/.venvs/ark-sdk/lib/python3.11/site-packages/volcenginesdkarkruntime/_utils/_transform.py__init__zPropertyInfo.__init__E   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__R   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%   5   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   W   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   e   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   |   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               r   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	          S t1                    }|| S t          |          dd         }|D ];t          t2                    r$j        t7          | 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>   =     
 
 
U %e
CCC
 
 
r4   r   c                4    g | ]}t          |           S )rJ   r^   rc   re   drJ   r^   s     r2   
<listcomp>z(_transform_recursive.<locals>.<listcomp>   s8     
 
 
 !zjQQQ
 
 
r4   rk   Tjsonexclude_unsetmode)r   r   r   r   _transform_typeddictdictr   itemsr   r   r   r   rV   r5   r   r@   r   r]   listr   rK   pydantic	BaseModelr   rS   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/

 
 
 
"jjll
 
 
 	
 
m	$	$
)0

 ]++
 D!!
 tS))
 dD!! 	&%%%%mQ77

++ 	
 t}} ::
 
 
 
 

 
 
 	

 ]## 
  .. 	Y 	YG'PWXXXDD$*++ A$d@@@@(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   ry   ry      s>    $x()) 2i>>###h?#>==111(3D99%)dGL)) 	)__&&FFbi(( 	)YY[[F&#&& )&%(( 	LTLLd6llLL   ''..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   ru   r   getrK   rX   r?   rA   resultr   rT   rf   rP   s          r2   rs   rs     s     !#F tDDDKjjll  
U 	 $$=F3KK7K%8 8 8F'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   1  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   >  s[      & 3dM22        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>s  ri   r4   r   c                D   K   g | ]}t          |            d{V S )rk   N)r   rl   s     r2   rn   z._async_transform_recursive.<locals>.<listcomp>  sc       
 
 
  -jZ        
 
 
r4   rk   Tro   rp   )r   r   r   r   _async_transform_typeddictrt   r   ru   r   r   r   r   rV   r5   r   r@   r   r]   rv   r   r   rw   rx   r   rS   r%   r)   _async_format_datar*   rz   s	    ``     @r2   r   r   W  s     $ 
(44M&&7-FM"" Ez$'7'7 E/mDDDDDDDDD~~*T**~m,,Q/

 
 
 
"jjll
 
 
 	
 
m	$	$
)0

 ]++
 D!!
 tS))
 dD!! 	&%%%%mQ77

++ 	
 t}} ::
 
 
 
 
 	
 
 
 
 
 
 
 
 
 	
 ]## 	
  .. 	 	G3        DD $*++ A$d@@@@(44N >**122.K!  
j,// 	J4E4Q+j')C           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     s`      $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&#&& )&%(( 	LTLLd6llLL   ''..w777Kr4   c                  K   i }t          |d          }|                                 D ]U\  }}t          |          s |j        |          }||||<   -t	          ||           d {V |t          ||          <   V|S r   )r   ru   r   r   r   rX   r   s          r2   r   r     s       !#F tDDDKjjll  
U 	 $$=F3KK=W%> > > 8 8 8 8 8 8F'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$     h   r4   )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   rw   _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   ry   rs   r   r   r   r   r   r>   r4   r2   <module>r      so   # " " " " " 				   . . . . . . . . . . . . # # # # # # # #                           * ) ) ) ) )                  ; : : : : : : : : :WT]]67h h h h h h h hD
* 
* 
* 
*! ! ! !. 4      &4 4 4 4 #	U U U U U Up   >   .
6 
6 
6 
6! ! ! !: #	[ [ [ [ [ [|   >   . 4 '+(, 	      r4   