o
    ;i                     @   s<  U d Z ddlZddlmZ ddlmZmZmZmZm	Z	 ddl
mZmZ edZejdd ejd	d ejd
d ejdd ejdd ejdd ejdd ejdd ejdd ejdd ejdd ejdd ejdd ejdd ejdd iZeeeegef f e d< dededdfddZ!d de"e dee defddZ#dS )!zUtilities to generate random valid Protobuf messages for testing.

This is based on https://github.com/yupingso/randomproto but customizable for
Modal, with random seeds, and it supports oneofs, and Protobuf v4.
    N)Random)AnyCallableOptionalTypeVarUnion)
DescriptorFieldDescriptorTc                 C      |  ddS Nr      normalvariaterand r   P/home/ubuntu/.local/lib/python3.10/site-packages/modal/_utils/rand_pb_testing.py<lambda>       r   c                 C   r   r   r   r   r   r   r   r      r   c                 C      t j| ddddS N   littleTsignedint
from_bytes	randbytesr   r   r   r   r          c                 C   r   N   r   Tr   r   r   r   r   r   r      r    c                 C      t | ddS Nr   r   r   r   r   r   r   r          c                 C   r#   Nr"   r   r   r   r   r   r   r      r%   c                 C   r   r   r   r   r   r   r   r      r    c                 C   r   r!   r   r   r   r   r   r      r    c                 C   r#   r$   r   r   r   r   r   r      r%   c                 C   r#   r&   r   r   r   r   r   r      r%   c                 C   r   r   r   r   r   r   r   r      r    c                 C   r   r!   r   r   r   r   r   r      r    c                 C   s   |  ddgS )NTFchoicer   r   r   r   r      s    c                    s&   d  fddtt dD S )N c                 3   s    | ]	}  tjV  qd S N)r(   string	printable).0_r   r   r   	<genexpr>   s    
z<lambda>.<locals>.<genexpr>333333?)joinranger   expovariater   r   r   r   r      s    c                 C   s   |  t| dS )Nr0   )r   r   r3   r   r   r   r   r   !   s    _FIELD_RANDOM_GENERATORdescr   returnc                    sd  t  }|jD ]}|t|jd g }|d ur||j q|jD ]}|jd ur.|j|vr.q!|jt	j
k}t|dr=|j}n|jt	jk}|rnt| |j}	|rf|dd}
t|
D ]}|	 }t||j| qWq!t|	|j| q!|jt	jkrdd |jjD   fdd}nt|j }|r|dd}
t| |j}	t|
D ]	}|	|| qq!t| |j|| q!d S )Nis_repeatedr      c                 S   s   g | ]}|j qS r   )number)r-   xr   r   r   
<listcomp>C   r%   z_fill.<locals>.<listcomp>c                    s
   |   S r*   r'   r   enum_valuesr   r   r   D   s   
 z_fill.<locals>.<lambda>)setoneofsr(   listfieldsaddnamecontaining_oneoftyper	   TYPE_MESSAGEhasattrr7   labelLABEL_REPEATEDgetattrrandintr2   _fillmessage_type	TYPE_ENUM	enum_typevaluesr4   appendsetattr)msgr5   r   oneof_fieldsoneofoneof_fieldfield
is_messager7   	msg_fieldnumr.   element	generatorr   r<   r   rL   %   sD   



rL   protoc                 C   s(   |du rt d}|  }t|| j| |S )zGenerate a pseudorandom protobuf message.

    ```python notest
    rand = random.Random(42)
    definition = rand_pb(api_pb2.Function, rand)
    ```
    Nr   )r   rL   
DESCRIPTOR)r]   r   rS   r   r   r   rand_pbQ   s
   r_   r*   )$__doc__r+   randomr   typingr   r   r   r   r   google.protobuf.descriptorr   r	   r
   TYPE_DOUBLE
TYPE_FLOAT
TYPE_INT32
TYPE_INT64TYPE_UINT32TYPE_UINT64TYPE_SINT32TYPE_SINT64TYPE_FIXED32TYPE_FIXED64TYPE_SFIXED32TYPE_SFIXED64	TYPE_BOOLTYPE_STRING
TYPE_BYTESr4   dictr   __annotations__rL   rE   r_   r   r   r   r   <module>   s0   














$,