
    [f                         d Z ddlmZmZ ddlmZmZmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ  G d
 de
      Zy)0Decimal to bytes and bytes to decimal transform.    )DecimalInvalidOperation)OptionalUnionTupleList)	Transform)Record)InsufficientMemoryError)getbytes   )ByteOrderHintc                        e Zd ZU dZeed<   eeeeef   ed<   eed<   	 ddddded	ed
edede	e
   ddf fdZedefd       Zedefd       Zedefd       Z	 ddeeee
ef   dee   de	e   ddfdZ	 ddedede	e   deeef   fdZ xZS )DecimalXr   
__nbytes____bdns____precision__FN)signednamenbytes	precision	byteorderr   r   returnc                    |d| d}t         |   |d       |dkD  sJ |dv sJ |dk\  sJ || _        d|z  }||||f| _        || _        y )NzDecimal (precision=)r   )hintr   >   biglittle
   )super__init__r   r   r   )selfr   r   r   r   r   divisor	__class__s          [/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/plum/decimal.pyr"   zDecimalX.__init__   sr     <(15DI.z---A~ i-!7FF:&    c                      | j                   d   S )zByte order ("little" or "big").r   r   r#   s    r&   r   zDecimalX.byteorder+        }}Qr'   c                      | j                   d   S )zSigned decimal.   r)   r*   s    r&   r   zDecimalX.signed0   r+   r'   c                     | j                   S )z
Precision.)r   r*   s    r&   r   zDecimalX.precision5   s     !!!r'   valuepiecesdumpc                    | j                   \  }}}}	 t        |      }||z  }t	        |j                               }	|$|j                  |	j                  |||             y t        |      |_	        |	j                  |||      }
||_	        |
|_
        |j                  |
       y # t        $ r t        d|d      d w xY w)NzValue z  cannot be converted to decimal.r   )r   r   r   
ValueErrorintto_integral_valueappendto_bytesreprr/   memory)r#   r/   r0   r1   r   r$   r   r   decimal_value	int_valuepieces              r&   __pack__zDecimalX.__pack__:   s     .2]]*	7FF	#ENM 	 779:	<MM),,VYv,NOeDJ&&vy&HEDJDKMM% #   		!AB	s   B& &C bufferoffsetc                 B   | j                   \  }}}}|K||z   }t        |      |k  rt        d      t        j	                  ||| ||      }	t        |	      |z  }
|
|fS t        ||||      \  }}t        j	                  |||      }	t        |	      |z  }
|
|_        |
|fS )Nztoo few bytes to unpackr3   )r   lenr   r5   
from_bytesr   r   r/   )r#   r?   r@   r1   r   r$   r   r   endr<   r;   chunks               r&   
__unpack__zDecimalX.__unpack__W   s     .2]]*	7FF<6/C6{S -.GHHvfS'99VTI#I.8M #%%ffdF;
sNN5)FNC		*W4"
c!!r'   )r   )N)__name__
__module____qualname____doc__r5   __annotations__r   r   boolr   strr"   propertyr   r   r   r   floatr   r	   bytesr   r>   rF   __classcell__)r%   s   @r&   r   r      sL   :OM3T122 $,	' "'' ' !	' ' sm' 
'.  =           "3 " " "&	!S%g-.! U! v	!
 
!< DH""%("080@"	w|	"r'   r   N)rJ   decimalr   r   typingr   r   r   r	   plum.transformr
   	plum.dumpr   plum.exceptionsr   plum._getbytesr   _typingr   r    r'   r&   <module>rZ      s.    6 - / / $  3 # "`"y `"r'   