
    Si                       S SK Jr  S SKrS/rS SKrS SKJrJrJr  S SKr	S SK
r	S SKr	S SKr\R                  (       a  S SKJr  \" S\	R                   R"                  R$                  S9rSr " S	 S
\5      r " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\" 5       r\R9                  \" 5       5        \R9                  \" 5       5        \R9                  \" 5       5        \R9                  \" 5       5        g)    )annotationsNregistry)AnyProtocolTypeVar)
Collection_Proto)boundzutf-8c                  B    \ rS rSr% SrS\S'   S\S'   SS jrSS jrS	rg
)ProtoSerializer   zQA serializer-deserializer to and from in-memory Protocol Buffers representations.strsupported_formatzCollection[str]file_extensionsc                    g)z6Serialize a in-memory proto to a serialized data type.N )selfprotos     Q/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnx/serialization.pyserialize_protoProtoSerializer.serialize_proto,           c                    g)z4Parse a serialized data type into a in-memory proto.Nr   r   
serializedr   s      r   deserialize_proto!ProtoSerializer.deserialize_proto/   r   r   r   N)r   r	   returnr   )r   r   r   r	   r   r	   )	__name__
__module____qualname____firstlineno____doc____annotations__r   r   __static_attributes__r   r   r   r   r      s!    [  %$ECr   r   c                  <    \ rS rSrSS jrS	S jrS
S jrSS jrSrg)	_Registry3   c                     0 U l         0 U l        g N)_serializers_extension_to_format)r   s    r   __init___Registry.__init__4   s    8:46!r   c                    XR                   UR                  '   U R                  R                  [        R                  UR                  UR                  5      5        g r+   )r,   r   r-   updatedictfromkeysr   )r   
serializers     r   register_Registry.register9   sD    9C*556!!((MM*44j6Q6QR	
r   c                     U R                   U   $ ! [         a+    [        SU SU R                   R                  5        35      Sef = f)zGet a serializer for a format.

Args:
    fmt: The format to get a serializer for.

Returns:
    ProtoSerializer: The serializer for the format.

Raises:
    ValueError: If the format is not supported.
zUnsupported format: 'z'. Supported formats are: N)r,   KeyError
ValueErrorkeys)r   fmts     r   get_Registry.get?   sX    	$$S)) 	'u,FtGXGXG]G]G_F`a	s	    5Ac                8    U R                   R                  U5      $ )zGet the corresponding format from a file extension.

Args:
    file_extension: The file extension to get a format for.

Returns:
    The format for the file extension, or None if not found.
)r-   r<   )r   file_extensions     r   get_format_from_file_extension(_Registry.get_format_from_file_extensionR   s     ((,,^<<r   )r-   r,   N)r   None)r4   r   r   rB   )r;   r   r   r   )r?   r   r   z
str | None)	r    r!   r"   r#   r.   r5   r<   r@   r&   r   r   r   r(   r(   3   s    7

&	=r   r(   c                  D    \ rS rSrSrSr\" SS15      rS
S jrSS jr	Sr
g	)_ProtobufSerializer^   z+Serialize and deserialize protobuf message.protobufz.onnxz.pbc                B   [        US5      (       a-  [        UR                  5      (       a   UR                  5       nU$ [        S[        U5       35      e! [         a>  nUR	                  5       [
        R                  R                  :  a  [        S5      Uee S nAff = f)NSerializeToStringz~The proto size is larger than the 2 GB limit. Please use save_as_external_data to save tensors separately from the model file.z1No SerializeToString method is detected.
type is )
hasattrcallablerH   r9   ByteSizeonnxcheckerMAXIMUM_PROTOBUF	TypeErrortype)r   r   resultes       r   r   #_ProtobufSerializer.serialize_protod   s    5-..8E<S<S3T3T002 M@eN
 	
  >>#t||'D'DD$k  s   A 
B 9BBc                >   [        U[        5      (       d  [        S[        U5       35      e[        R
                  " SUR                  U5      5      nUbG  U[        U5      :w  a8  [        R                  R                  R                  SU S[        U5       35      eU$ )Nz4Parameter 'serialized' must be bytes, but got type: z
int | Nonez*Protobuf decoding consumed too few bytes: z out of )
isinstancebytesrO   rP   typingcastParseFromStringlengooglerF   messageDecodeError)r   r   r   decodeds       r   r   %_ProtobufSerializer.deserialize_protot   s    *e,,FtJGWFXY  ++lE,A,A*,MN7c*o#=//))55<WIXcR\oM^_  r   r   Nr   r	   r   rV   )r   rV   r   r	   r   r	   r    r!   r"   r#   r$   r   	frozensetr   r   r   r&   r   r   r   rD   rD   ^   s$    5!% 01O
 
r   rD   c                  D    \ rS rSrSrSr\" 1 Sk5      rS	S jrS
S jr	Sr
g)_TextProtoSerializer   z%Serialize and deserialize text proto.	textproto>   .pbtxt.txtpb	.prototxt
.textprotoc                ~    [         R                  R                  R                  U5      nUR	                  [
        5      $ r+   )r[   rF   text_formatMessageToStringencode	_ENCODING)r   r   rf   s      r   r   $_TextProtoSerializer.serialize_proto   s-    OO//??F		**r   c                :   [        U[        [        45      (       d  [        S[	        U5       35      e[        U[        5      (       a  UR                  [        5      n[        U[        5      (       d   e[        R                  R                  R                  X5      $ N;Parameter 'serialized' must be bytes or str, but got type: )rU   rV   r   rO   rP   decodero   r[   rF   rl   Parser   s      r   r   &_TextProtoSerializer.deserialize_proto   ~    *ucl33MdS]N^M_`  j%((#**95J*c******00CCr   r   Nr`   r   zbytes | strr   r	   r   r	   ra   r   r   r   rd   rd      s!    /" OPO+Dr   rd   c                  D    \ rS rSrSrSr\" SS15      rS
S jrSS jr	Sr
g	)_JsonSerializer   zSerialize and deserialize JSON.jsonz.jsonz	.onnxjsonc                |    [         R                  R                  R                  USS9nUR	                  [
        5      $ )NT)preserving_proto_field_name)r[   rF   json_formatMessageToJsonrn   ro   )r   r   json_messages      r   r   _JsonSerializer.serialize_proto   s:    22@@t A 
 ""9--r   c                :   [        U[        [        45      (       d  [        S[	        U5       35      e[        U[        5      (       a  UR                  [        5      n[        U[        5      (       d   e[        R                  R                  R                  X5      $ rr   )rU   rV   r   rO   rP   rt   ro   r[   rF   r   ru   r   s      r   r   !_JsonSerializer.deserialize_proto   rw   r   r   Nr`   rx   ra   r   r   r   rz   rz      s%    )+ 67O.Dr   rz   c                  D    \ rS rSrSrSr\" SS15      rS
S jrSS jr	Sr
g	)_TextualSerializer   z:Serialize and deserialize the ONNX textual representation.onnxtxtz.onnxtxtz	.onnxtextc                j    [         R                  R                  U5      nUR                  [        5      $ r+   )rL   printerto_textrn   ro   )r   r   texts      r   r   "_TextualSerializer.serialize_proto   s%    ||##E*{{9%%r   c                   [         R                  " SSS9  [        U[        [        45      (       d  [        S[        U5       35      e[        U[        5      (       a  UR                  [        5      nOUn[        U[        R                  5      (       a  [        R                  R                  U5      $ [        U[        R                  5      (       a  [        R                  R                  U5      $ [        U[        R                  5      (       a  [        R                  R!                  U5      $ [        U[        R"                  5      (       a  [        R                  R%                  U5      $ ['        S[        U5       35      e)Nz[The onnxtxt format is experimental. Please report any errors to the ONNX GitHub repository.   )
stacklevelrs   zUnsupported proto type: )warningswarnrU   rV   r   rO   rP   rt   ro   rL   
ModelProtoparserparse_model
GraphProtoparse_graphFunctionProtoparse_function	NodeProto
parse_noder9   )r   r   r   r   s       r   r   $_TextualSerializer.deserialize_proto   s   i	
 *ucl33MdS]N^M_`  j%(($$Y/DDeT__--;;**400eT__--;;**400eT//00;;--d33eT^^,,;;))$//3DK=ABBr   r   Nr`   rx   ra   r   r   r   r   r      s%    D [ 9:O&Cr   r   )
__future__r   r   __all__rW   r   r   r   google.protobuf.json_formatr[   google.protobuf.messagegoogle.protobuf.text_formatrL   TYPE_CHECKINGcollections.abcr   rF   r\   Messager	   ro   r   r(   rD   rd   rz   r   r   r5   r   r   r   <module>r      s   
 #    ) ) "  " 	*	!8!8!@!@	A	Ch C*(= (=V /  FD? D*Do D.C CF ;   %' (   &( )   /# $   $& 'r   