
    "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dS )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__littleFN)signednamenbytes	precision	byteorderr   r   returnc                    |d| d}t                                          |d           |dk    sJ |dv sJ |dk    sJ || _        d|z  }||||f| _        || _        d S )NzDecimal (precision=)r   )hintr   >   bigr   
   )super__init__r   r   r   )selfr   r   r   r   r   divisor	__class__s          P/mounts/lovelace/software/anaconda3/lib/python3.11/site-packages/plum/decimal.pyr"   zDecimalX.__init__   s     <5555DI...zzzz-----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          |          }n"# t          $ r t          d|d          d w xY w||z  }t	          |                                          }	|-|                    |	                    |||                     d S t          |          |_	        |	                    |||          }
||_	        |
|_
        |                    |
           d S )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	#ENNMM 	 	 	BBBB 	
 	 7799::	<MM),,VYv,NNOOOOOeDJ&&vy&HHEDJDKMM%     s    =bufferoffsetc                    | j         \  }}}}|b||z   }t          |          |k     rt          d          t                              |||         ||          }	t          |	          |z  }
|
|fS t          ||||          \  }}t                              |||          }	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HvfSj'99VTTI#I..8M #%%ffdF;;
sNN5)FNC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      s        ::OOOM3T12222 $,	' "' ' '' ' !	' ' sm' 
' ' ' ' ' '.  =       X          X  "3 " " " X" "&	! !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 6 - - - - - - - - / / / / / / / / / / / / $ $ $ $ $ $       3 3 3 3 3 3 # # # # # # " " " " " "`" `" `" `" `"y `" `" `" `" `"r'   