a �DOg�9�@sddlZddlZddlZddlZddlZddlZejdedd�gd�ZGdd�de �Z dZ dZ d Z d Zd ZGd d �d �Zdd�ZGdd�d�Zejdd��ZGdd�d�ZGdd�d�ZGdd�d�Zdd�ZGdd�d�ZGdd�d�ZGd d!�d!�Zd"d#�ZdS)$�Nzthe binhex module is deprecated�)� stacklevel)�binhex�hexbin�Errorc@s eZdZdS)rN)�__name__� __module__� __qualname__�r r �/usr/lib64/python3.9/binhex.pyr%sr�i��@��c@seZdZdd�ZdS)�FInfocCsd|_d|_d|_dS)Nz????r)�Type�Creator�Flags��selfr r r �__init__6szFInfo.__init__N)rrr rr r r r r5srcCs�t�}t�|d��<}|�d�}d|vr,d|_|�dd�|��}Wd�n1sT0Ytj� |�\}}|� ddd�}|||dfS) N�rbirZTEXTr�:�-r ) r�io�open�readr�seek�tell�os�path�split�replace)�name�finfo�fp�dataZdsize�dir�filer r r � getfileinfo;s  &r(c@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) �openrsrccGsdS�Nr �r�argsr r r rIszopenrsrc.__init__cGsdS�N�r r+r r r rLsz openrsrc.readcGsdSr*r r+r r r �writeOszopenrsrc.writecCsdSr*r rr r r �closeRszopenrsrc.closeN)rrr rrr/r0r r r r r)Hsr)ccs@t���$t�ddt�dVWd�n1s20YdS)N�ignore�)�warnings�catch_warnings�filterwarnings�DeprecationWarningr r r r �_ignore_deprecation_warningXs r7c@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) �_HqxcoderenginecCs ||_d|_d|_td|_dS)Nr.r )�ofpr%�hqxdata�LINELEN�linelen�rr9r r r rbsz_Hqxcoderengine.__init__cCs�|j||_t|j�}|dd}|jd|�}|j|d�|_|sHdSt��"|jt�|�|_Wd�n1sv0Y|�d�dS)N�r)r%�lenr7r:�binascii�b2a_hqx�_flush)rr%ZdatalenZtodor r r r/hs   0z_Hqxcoderengine.writecCsrd}|t|j�|jkrH||j}|j�|j||�d�t|_|}q|j|d�|_|rn|j�|jd�dS)Nr� s: )r?r:r<r9r/r;)r�force�first�lastr r r rBts z_Hqxcoderengine._flushcCs\|jr@t��$|jt�|j�|_Wd�n1s60Y|�d�|j��|`dS)Nr )r%r7r:r@rArBr9r0rr r r r0s 2  z_Hqxcoderengine.closeN)rrr rr/rBr0r r r r r8_s  r8c@s$eZdZdd�Zdd�Zdd�ZdS)�_RlecoderenginecCs||_d|_dSr-)r9r%r=r r r r�sz_Rlecoderengine.__init__cCsf|j||_t|j�tkrdSt��t�|j�}Wd�n1sF0Y|j�|�d|_dSr-)r%r?�REASONABLY_LARGEr7r@� rlecode_hqxr9r/)rr%�rledatar r r r/�s * z_Rlecoderengine.writecCsV|jrDt��t�|j�}Wd�n1s.0Y|j�|�|j��|`dSr*)r%r7r@rIr9r/r0)rrJr r r r0�s *  z_Rlecoderengine.closeN)rrr rr/r0r r r r rG�s rGc@sLeZdZdd�Zdd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z dS)�BinHexc Cs�|\}}}}d}t|t�r.|}t�|d�}d}zR|�d�t|�} t| �|_d|_|dur`t �}||_ ||_ |� ||�t |_Wn|r�|���Yn0dS)NF�wbTs0(This file must be converted with BinHex 4.0) :r)� isinstance�strrrr/r8rGr9�crcr�dlen�rlen� _writeinfo� _DID_HEADER�stater0) rZname_finfo_dlen_rlenr9r"r#rPrQZclose_on_errorZofnameZhqxerr r r r�s*       zBinHex.__init__c Cs�t|�}|dkrtd��t|g�|�d�d}|j|j}}t|t�rR|�d�}t|t�rf|�d�}||}t� d|j �}t� d|j |j �} |||| } |� | �|��dS)N�?zFilename too longzlatin-1��>hz>ii)r?r�bytes�encoderrrMrN�struct�packrrPrQ�_write� _writecrc) rr"r#�nl�d�tpZcrZd2Zd3Zd4�infor r r rR�s     zBinHex._writeinfocCs t�||j�|_|j�|�dSr*)r@�crc_hqxrOr9r/�rr%r r r r\�sz BinHex._writecCs4|jdkrd}nd}|j�t�||j��d|_dS)NrrWz>H)rOr9r/rZr[)r�fmtr r r r]�s  zBinHex._writecrccCs0|jtkrtd��|jt|�|_|�|�dS)NzWriting data at the wrong time)rTrSrrPr?r\rcr r r r/�s z BinHex.writecCs,|jdkrtd|jf��|��t|_dS)NrzIncorrect data size, diff=%r)rPrrQr]� _DID_DATArTrr r r � close_data�s zBinHex.close_datacCsB|jtkr|��|jtkr$td��|jt|�|_|�|�dS)Nz'Writing resource data at the wrong time)rTrerfrrQr?r\rcr r r � write_rsrc�s   zBinHex.write_rsrccCs�|jdurdSzb|jtkr"|��|jtkr4td��|jdkrNtd|jf��|��Wd|_|j}|`|��nd|_|j}|`|��0dS)NzClose at the wrong timerz$Incorrect resource-datasize, diff=%r)rTrerfrrQr]r9r0r=r r r r0�s$      �z BinHex.closeN) rrr rrRr\r]r/rfrgr0r r r r rK�s rKcCs�t|�}t||�}t�|d��4}|�d�}|s0q<|�|�q |��Wd�n1sX0Yt|d�}|�d�}|s|q�|�|�ql|� �|� �dS)Nr��) r(rKrrrr/rfr)rgr0)�inp�outr#r9�ifpr_r r r r�s   &   rc@s$eZdZdd�Zdd�Zdd�ZdS)�_HqxdecoderenginecCs||_d|_dS)Nr)rk�eof�rrkr r r rsz_Hqxdecoderengine.__init__cCs�d}|}|dkr�|jr|S|ddd}|j�|�}z>t�� t�|�\}|_Wd�n1sd0YWq�Wntjy�Yn0|j�d�}|s�td��||}q6||}|t|�}|s|jstd��q|S)Nr.rrr>�r zPremature EOF on binhex file) rmrkrr7r@Za2b_hqxZ Incompleterr?)rZtotalwtdZdecdata�wtdr%Z decdatacur�newdatar r r rs*  .     z_Hqxdecoderengine.readcCs|j��dSr*�rkr0rr r r r0:sz_Hqxdecoderengine.closeN)rrr rrr0r r r r rls!rlc@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) �_RledecoderenginecCs||_d|_d|_d|_dS)Nr.r)rk� pre_buffer� post_bufferrmrnr r r r@sz_Rledecoderengine.__init__cCsD|t|j�kr"|�|t|j��|jd|�}|j|d�|_|Sr*)r?ru�_fill)rrp�rvr r r rFs z_Rledecoderengine.readcCsB|j|j�|d�|_|jjrdt��$|jt�|j�|_Wd�n1sP0Yd|_dSt|j�}|jdd�t dt kr�|d}nX|jdd�t kr�|d}n<|jdd�t dkr�|d}n|jdd�t kr�n|d }t��,|jt�|jd|��|_Wd�n1�s$0Y|j|d�|_dS) Nror.�����rVr>�����r�����r ) rtrkrrmr7rur@Z rledecode_hqxr?�RUNCHAR)rrpZmarkr r r rvMs. �$    �&z_Rledecoderengine._fillcCs|j��dSr*rrrr r r r0rsz_Rledecoderengine.closeN)rrr rrrvr0r r r r rs=s%rsc@sLeZdZdd�Zdd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z dS)�HexBincCsft|t�rt�|d�}|�d�}|s,td��|dkr6q|dkrqBqt|�}t|�|_d|_ |� �dS)Nrr zNo binhex data foundrC�:r) rMrNrrrrrlrsrkrO� _readheader)rrkZchZhqxifpr r r rvs    zHexBin.__init__cCs |j�|�}t�||j�|_|Sr*)rkrr@rbrO)rr?r%r r r �_read�s z HexBin._readcCsNt�d|j�d��dd@}|jd@|_||jkrDtd|j|f��d|_dS)NrWrri��zCRC error, computed %x, read %x)rZ�unpackrkrrOr)rZfilecrcr r r � _checkcrc�s  �zHexBin._checkcrccCs�|�d�}|�t|��}|�d�}|��|dd�}|dd�}t�d|dd��d}t�d|dd ��d|_t�d|d d��d|_||_t�|_||j_ ||j_ ||j_ t |_ dS) Nr ��� rW� rz>l�)r�ordr�rZr�rPrQ�FNamerrrrrSrT)rr?�fname�rest�typeZcreator�flagsr r r r~�s    zHexBin._readheadercGsj|jtkrtd��|r,|d}t||j�}n|j}d}t|�|krZ||�|t|��}q6|j||_|S)NzRead data at wrong timerr.)rTrSr�minrPr?r)r�nrwr r r r�s   z HexBin.readcCs6|jtkrtd��|jr$|�|j�}|��t|_dS)Nzclose_data at wrong time)rTrSrrPrr�re�r�dummyr r r rf�s   zHexBin.close_datacGsZ|jtkr|��|jtkr$td��|r>|d}t||j�}n|j}|j||_|�|�S)Nz Read resource data at wrong timer)rTrSrfrerr�rQr)rr�r r r � read_rsrc�s   zHexBin.read_rsrccCsT|jdurdSz.|jr"|�|j�}|��Wd|_|j��nd|_|j��0dSr*)rTrQr�r�rkr0r�r r r r0�s    �z HexBin.closeN) rrr rrr�r~rrfr�r0r r r r r|us  r|cCs�t|�}|j}|s|j}t�|d��,}|�d�}|s6qB|�|�q&Wd�n1sV0Y|��|�d�}|r�t |d�}|�|�|�d�}|s�q�|�|�q�|� �|� �dS)NrLrh) r|rr�rrrr/rfr�r)r0)rirjrkr#r9r_r r r r�s$ *     r)r@� contextlibrrrZr3�warnr6�__all__� ExceptionrrSrerHr;r{rr(r)�contextmanagerr7r8rGrKrrlrsr|rr r r r �s8�  (^+8h