a �DOg�@stdZddlZddlmZddlmZgd�ZGdd�de�ZGdd �d e�Z d d �Z Gd d �d �Z Gdd�d�Z dS)zRImplements (a subset of) Sun XDR -- eXternal Data Representation. See: RFC 1014 �N)�BytesIO��wraps)�Error�Packer�Unpacker�ConversionErrorc@s(eZdZdZdd�Zdd�Zdd�ZdS) rz�Exception class for this module. Use: except xdrlib.Error as var: # var has the Error instance for the exception Public ivars: msg -- contains the message cCs ||_dS�N)�msg)�selfr �r �/usr/lib64/python3.9/xdrlib.py�__init__szError.__init__cCs t|j�Sr )�reprr �r r r r �__repr__szError.__repr__cCs t|j�Sr )�strr rr r r �__str__sz Error.__str__N)�__name__� __module__� __qualname__�__doc__rrrr r r r rs rc@s eZdZdS)rN)rrrr r r r r srcst���fdd��}|S)z5 Wrap any raised struct.errors in a ConversionError. c sHz �||�WStjyB}zt|jd�d�WYd}~n d}~00dS�Nr)�struct�errorr�args)r �value�e��functionr r �result&s z&raise_conversion_error..resultr)rr r rr �raise_conversion_error#sr!c@s�eZdZdZdd�Zdd�Zdd�ZeZedd ��Z ed d ��Z e Z d d �Z dd�Z e Zedd��Zedd��Zdd�ZeZdd�ZeZeZdd�Zdd�Zdd�ZdS)rz0Pack various data representations into a buffer.cCs |��dSr ��resetrr r r r2szPacker.__init__cCs t�|_dSr )r� _Packer__bufrr r r r#5sz Packer.resetcCs |j��Sr )r$�getvaluerr r r � get_buffer8szPacker.get_buffercCs|j�t�d|��dS)N�>L�r$�writer�pack�r �xr r r � pack_uint=szPacker.pack_uintcCs|j�t�d|��dS)N�>lr(r+r r r �pack_intAszPacker.pack_intcCs"|r|j�d�n |j�d�dS)Nss)r$r)r+r r r � pack_boolGszPacker.pack_boolc Cs�z|�|d?d@�Wn:ttjfyP}zt|jd�d�WYd}~n d}~00z|�|d@�Wn:ttjfy�}zt|jd�d�WYd}~n d}~00dS)N� l��r)r-� TypeErrorrrrr)r r,rr r r � pack_uhyperKs&zPacker.pack_uhypercCs|j�t�d|��dS)N�>fr(r+r r r � pack_floatWszPacker.pack_floatcCs|j�t�d|��dS)N�>dr(r+r r r � pack_double[szPacker.pack_doublecCsP|dkrtd��|d|�}|ddd}||t|�d}|j�|�dS)Nr� fstring size must be nonnegative���)� ValueError�lenr$r))r �n�s�datar r r � pack_fstring_s  zPacker.pack_fstringcCs"t|�}|�|�|�||�dSr )r=r-rA)r r?r>r r r � pack_stringis zPacker.pack_stringcCs*|D]}|�d�||�q|�d�dS)N�r)r-)r �list� pack_item�itemr r r � pack_listqs  zPacker.pack_listcCs*t|�|krtd��|D] }||�qdS)Nzwrong array size)r=r<)r r>rDrErFr r r � pack_farrayws zPacker.pack_farraycCs$t|�}|�|�|�|||�dSr )r=r-rH)r rDrEr>r r r � pack_array}s zPacker.pack_arrayN)rrrrrr#r&Zget_bufr!r-r/Z pack_enumr0r3Z pack_hyperr5r7rAZ pack_fopaquerBZ pack_opaqueZ pack_bytesrGrHrIr r r r r/s2     rc@s�eZdZdZdd�Zdd�Zdd�Zdd �Zd d �Zd d �Z dd�Z dd�Z e Z dd�Z dd�Zdd�Zdd�Zdd�Zdd�ZeZdd�ZeZeZd d!�Zd"d#�Zd$d%�Zd&S)'rz;Unpacks various data representations from the given buffer.cCs|�|�dSr r"�r r@r r r r�szUnpacker.__init__cCs||_d|_dSr)�_Unpacker__buf�_Unpacker__posrJr r r r#�szUnpacker.resetcCs|jSr �rLrr r r � get_position�szUnpacker.get_positioncCs ||_dSr rM)r Zpositionr r r � set_position�szUnpacker.set_positioncCs|jSr )rKrr r r r&�szUnpacker.get_buffercCs|jt|j�krtd��dS)Nzunextracted data remains)rLr=rKrrr r r �done�sz Unpacker.donecCsB|j}|d|_}|j||�}t|�dkr2t�t�d|�dS)Nr:r'r�rLrKr=�EOFErrorr�unpack�r �i�jr@r r r � unpack_uint�s  zUnpacker.unpack_uintcCsB|j}|d|_}|j||�}t|�dkr2t�t�d|�dS)Nr:r.rrQrTr r r � unpack_int�s  zUnpacker.unpack_intcCs t|���Sr )�boolrXrr r r � unpack_bool�szUnpacker.unpack_boolcCs |��}|��}t|�d>|BS)Nr1)rW�int)r �hi�lor r r � unpack_uhyper�szUnpacker.unpack_uhypercCs|��}|dkr|d}|S)Nll)r^r+r r r � unpack_hyper�szUnpacker.unpack_hypercCsB|j}|d|_}|j||�}t|�dkr2t�t�d|�dS)Nr:r4rrQrTr r r � unpack_float�s  zUnpacker.unpack_floatcCsB|j}|d|_}|j||�}t|�dkr2t�t�d|�dS)N�r6rrQrTr r r � unpack_double�s  zUnpacker.unpack_doublecCsT|dkrtd��|j}||ddd}|t|j�krrUrVr r r �unpack_fstring�szUnpacker.unpack_fstringcCs|��}|�|�Sr )rWrc)r r>r r r � unpack_string�szUnpacker.unpack_stringcCsBg}|��}|dkrq>|dkr,td|f��|�}|�|�q|S)NrrCz0 or 1 expected, got %r)rWr�append)r � unpack_itemrDr,rFr r r � unpack_list�s  zUnpacker.unpack_listcCs"g}t|�D]}|�|��q |Sr )�rangere)r r>rfrDrUr r r � unpack_farray�s zUnpacker.unpack_farraycCs|��}|�||�Sr )rWri)r rfr>r r r � unpack_array�szUnpacker.unpack_arrayN)rrrrrr#rNrOr&rPrWrXZ unpack_enumrZr^r_r`rbrcZunpack_fopaquerdZ unpack_opaqueZ unpack_bytesrgrirjr r r r r�s.  r) rr�ior� functoolsr�__all__� Exceptionrrr!rrr r r r �s   U