
    1;ji                    T   d dl mZ d dlZdgZd dlZd dlmZmZmZ d dlZ	d dl
Z	d dlZ	d dlZej        rd dlmZ  ede	j        j        j                  ZdZ G d	 d
e          Z G d d          Z G d de          Z G d de          Z G d de          Z G d de          Z e            Ze                     e                       e                     e                       e                     e                       e                     e                       dS )    )annotationsNregistry)AnyProtocolTypeVar)
Collection_Proto)boundzutf-8c                  8    e Zd ZU dZded<   ded<   dd
ZddZdS )ProtoSerializerzQA serializer-deserializer to and from in-memory Protocol Buffers representations.strsupported_formatzCollection[str]file_extensionsprotor	   returnr   c                    dS )z6Serialize a in-memory proto to a serialized data type.N )selfr   s     L/root/voice-cloning/.venv/lib/python3.11/site-packages/onnx/serialization.pyserialize_protozProtoSerializer.serialize_proto,             
serializedc                    dS )z4Parse a serialized data type into a in-memory proto.Nr   r   r   r   s      r   deserialize_protoz!ProtoSerializer.deserialize_proto/   r   r   N)r   r	   r   r   )r   r   r   r	   r   r	   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   r      sj         [[  %$$$E E E EC C C C C Cr   r   c                  .    e Zd ZddZddZdd	ZddZdS )	_Registryr   Nonec                "    i | _         i | _        d S N)_serializers_extension_to_format)r   s    r   __init__z_Registry.__init__4   s    8:46!!!r   
serializerr   c                    || j         |j        <   | j                            t                              |j        |j                             d S r&   )r'   r   r(   updatedictfromkeysr   )r   r*   s     r   registerz_Registry.register9   sN    9C*56!((MM*4j6QRR	
 	
 	
 	
 	
r   fmtr   c                    	 | j         |         S # t          $ r. t          d| d| j                                                    dw xY w)a  Get 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   r0   s     r   getz_Registry.get?   sg    	$S)) 	 	 	aaatGXG]G]G_G_aa 	s	    8Afile_extension
str | Nonec                6    | j                             |          S )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(   r5   )r   r6   s     r   get_format_from_file_extensionz(_Registry.get_format_from_file_extensionR   s     (,,^<<<r   N)r   r$   )r*   r   r   r$   )r0   r   r   r   )r6   r   r   r7   )r   r   r   r)   r/   r5   r9   r   r   r   r#   r#   3   sd        7 7 7 7

 
 
 
   &	= 	= 	= 	= 	= 	=r   r#   c                  @    e Zd ZdZdZ eddh          Zdd	ZddZdS )_ProtobufSerializerz+Serialize and deserialize protobuf message.protobufz.onnxz.pbr   r	   r   bytesc                L   t          |d          rvt          |j                  rb	 |                                }nJ# t          $ r=}|                                t
          j        j        k    rt          d          | d }~ww xY w|S t          dt          |                     )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callabler?   r3   ByteSizeonnxcheckerMAXIMUM_PROTOBUF	TypeErrortype)r   r   resultes       r   r   z#_ProtobufSerializer.serialize_protod   s    5-.. 
	8E<S3T3T 
	0022   >>##t|'DDD$k    MNeNN
 
 	
s   ; 
B8A==Br   c                V   t          |t                    st          dt          |                     t	          j        d|                    |                    }|J|t          |          k    r7t          j	        j
                            d| dt          |                     |S )Nz4Parameter 'serialized' must be bytes, but got type: z
int | Nonez*Protobuf decoding consumed too few bytes: z out of )
isinstancer=   rF   rG   typingcastParseFromStringlengoogler<   messageDecodeError)r   r   r   decodeds       r   r   z%_ProtobufSerializer.deserialize_protot   s    *e,, 	YtJGWGWYY   +lE,A,A*,M,MNN7c*oo#=#=/)55_W__cR\oo__   r   Nr   r	   r   r=   )r   r=   r   r	   r   r	   	r   r   r   r    r   	frozensetr   r   r   r   r   r   r;   r;   ^   s\        55!i% 011O
 
 
 
 
 
 
 
 
 
r   r;   c                  @    e Zd ZdZdZ eh d          ZddZddZdS )_TextProtoSerializerz%Serialize and deserialize text proto.	textproto>   .pbtxt.txtpb	.prototxt
.textprotor   r	   r   r=   c                ~    t           j        j                            |          }|                    t
                    S r&   )rP   r<   text_formatMessageToStringencode	_ENCODING)r   r   rY   s      r   r   z$_TextProtoSerializer.serialize_proto   s.    O/??FF		***r   r   bytes | strc                N   t          |t          t          f          st          dt	          |                     t          |t                    r|                    t                    }t          |t                    sJ t          j        j	        
                    ||          S N;Parameter 'serialized' must be bytes or str, but got type: )rK   r=   r   rF   rG   decoderb   rP   r<   r_   Parser   s      r   r   z&_TextProtoSerializer.deserialize_proto       *ucl33 	`dS]N^N^``   j%(( 	6#**955J*c******00UCCCr   NrT   r   rc   r   r	   r   r	   rU   r   r   r   rX   rX      sd        //"i O O OPPO+ + + +D D D D D Dr   rX   c                  @    e Zd ZdZdZ eddh          Zdd	ZddZdS )_JsonSerializerzSerialize and deserialize JSON.jsonz.jsonz	.onnxjsonr   r	   r   r=   c                    t           j        j                            |d          }|                    t
                    S )NT)preserving_proto_field_name)rP   r<   json_formatMessageToJsonra   rb   )r   r   json_messages      r   r   z_JsonSerializer.serialize_proto   s=    2@@t A 
 
 ""9---r   r   rc   c                N   t          |t          t          f          st          dt	          |                     t          |t                    r|                    t                    }t          |t                    sJ t          j        j	        
                    ||          S re   )rK   r=   r   rF   rG   rg   rb   rP   r<   rp   rh   r   s      r   r   z!_JsonSerializer.deserialize_proto   ri   r   NrT   rj   rU   r   r   r   rl   rl      sb        ))i+ 677O. . . .D D D D D Dr   rl   c                  @    e Zd ZdZdZ eddh          Zdd	ZddZdS )_TextualSerializerz:Serialize and deserialize the ONNX textual representation.onnxtxtz.onnxtxtz	.onnxtextr   r	   r   r=   c                t    t           j                            |          }|                    t                    S r&   )rC   printerto_textra   rb   )r   r   texts      r   r   z"_TextualSerializer.serialize_proto   s)    |##E**{{9%%%r   r   rc   c                   t          j        dd           t          |t          t          f          st          dt          |                     t          |t                    r|                    t                    }n|}t          |t          j
                  rt          j                            |          S t          |t          j                  rt          j                            |          S t          |t          j                  rt          j                            |          S t          |t          j                  rt          j                            |          S t'          dt          |                     )Nz[The onnxtxt format is experimental. Please report any errors to the ONNX GitHub repository.   )
stacklevelrf   zUnsupported proto type: )warningswarnrK   r=   r   rF   rG   rg   rb   rC   
ModelProtoparserparse_model
GraphProtoparse_graphFunctionProtoparse_function	NodeProto
parse_noder3   )r   r   r   rz   s       r   r   z$_TextualSerializer.deserialize_proto   sS   i	
 	
 	
 	
 *ucl33 	`dS]N^N^``   j%(( 	$$Y//DDDeT_-- 	1;**4000eT_-- 	1;**4000eT/00 	4;--d333eT^,, 	0;))$///ADKKAABBBr   NrT   rj   rU   r   r   r   ru   ru      sb        DD i[ 9::O& & & &C C C C C Cr   ru   )
__future__r   r~   __all__rL   r   r   r   google.protobuf.json_formatrP   google.protobuf.messagegoogle.protobuf.text_formatrC   TYPE_CHECKINGcollections.abcr   r<   rQ   Messager	   rb   r   r#   r;   rX   rl   ru   r   r/   r   r   r   <module>r      sh  
 # " " " " "    ) ) ) ) ) ) ) ) ) ) " " " "     " " " " 	 +******	!8!@	A	A	A	C C C C Ch C C C*(= (= (= (= (= (= (= (=V         /      FD D D D D? D D D*D D D D Do D D D.C C C C C C C CF 9;;   %%'' ( ( (   &&(( ) ) )   //## $ $ $   $$&& ' ' ' ' 'r   