
    (iD	                     B    d dl mZ d dlmZmZ  G d d      Z e       Zy)    )Atomic)DeserializationErrorSerializationErrorc                   N    e Zd ZdZ	 d	dZed
d       Zed        Zd Zd Z	d Z
y)Texta  
    A sedes object for encoded text data of certain length.

    :param min_length: the minimal length in encoded characters or `None` for no lower
                       limit
    :param max_length: the maximal length in encoded characters or `None` for no upper
                       limit
    :param allow_empty: if true, empty strings are considered valid even if
                        a minimum length is required otherwise
    Nc                 j    |xs d| _         |t        d      | _        n|| _        || _        || _        y )Nr   inf)
min_lengthfloat
max_lengthallow_emptyencoding)selfr
   r   r   r   s        ?/var/www/br/venv/lib/python3.12/site-packages/rlp/sedes/text.py__init__zText.__init__   s6     %/#ElDO(DO&     c                      | |||      S )zFCreate a sedes for text data with exactly `length` encoded characters.)r    )clslengthr   s      r   fixed_lengthzText.fixed_length!   s     66{;;r   c                 "    t        |t              S )N)
isinstancestr)r   objs     r   is_valid_typezText.is_valid_type&   s    #s##r   c                     t        | j                  |cxk  xr | j                  k  nc | j                  xr |dk(  f      S )Nr   )anyr
   r   r   )r   r   s     r   is_valid_lengthzText.is_valid_length*   s;    6<T__<  0Vq[
 	
r   c                     | j                  |      st        dt        |       d|      | j                  t	        |            st        d|      |j                  | j                        S )NzObject is not a serializable ()zObject has invalid length)r   r   typer   lenencoder   )r   r   s     r   	serializezText.serialize2   s`    !!#&$'Ed3i[PQ%RTWXX##CH-$%@#FFzz$--((r   c                 T   t        |t              s#t        dt        |      j                   d|      	 |j                  | j                        }| j                  t        |            r|S t        t        |       d|      # t        $ r}t        t        |      |      d }~ww xY w)NzObjects of type z cannot be deserializedz has invalid length)r   r   r   r"   __name__decoder   UnicodeDecodeErrorr   r   r#   )r   serial
text_valueerrs       r   deserializezText.deserialize;   s    &&)&"4<#8#8"99PQ 
	9t}}5J J0&$v,7J'KVTT " 	9&s3x88	9s   B 	B'B""B')NNFutf8)F)r'   
__module____qualname____doc__r   classmethodr   r   r   r%   r-   r   r   r   r   r   
   sK    	 MS	! < < $ $
)Ur   r   N)
rlp.atomicr   rlp.exceptionsr   r   r   textr   r   r   <module>r6      s'   @U @UF vr   