a �DOg�9�@s dZddlZddlZddlZddlZddlZddlZejdedd�gd�Z Gdd�de �Z dZ d Z d Zd 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)%z�Macintosh binhex compression/decompression. easy interface: binhex(inputfilename, outputfilename) hexbin(inputfilename, outputfilename) �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@s0eZdZdZdd�Zdd�Zdd�Zdd �Zd S) �_Hqxcoderenginez(Write data to the coder in 3-byte chunkscCs ||_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 �__doc__rr/rBr0r r r r r8_s   r8c@s(eZdZdZdd�Zdd�Zdd�ZdS) �_Rlecoderenginez4Write data to the RLE-coder in suitably large chunkscCs||_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@rJr9r/r0)rrKr r r r0�s *  z_Rlecoderengine.closeN)rrr rGrr/r0r r r r rH�s rHc@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/r8rHr9�crcr�dlen�rlen� _writeinfo� _DID_HEADER�stater0) rZname_finfo_dlen_rlenr9r"r#rQrRZclose_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�encoderrrNrO�struct�packrrQrR�_write� _writecrc) rr"r#�nl�d�tpZcrZd2Zd3Zd4�infor r r rS�s     zBinHex._writeinfocCs t�||j�|_|j�|�dSr*)r@�crc_hqxrPr9r/�rr%r r r r]�sz BinHex._writecCs4|jdkrd}nd}|j�t�||j��d|_dS)NrrXz>H)rPr9r/r[r\)r�fmtr r r r^�s  zBinHex._writecrccCs0|jtkrtd��|jt|�|_|�|�dS)NzWriting data at the wrong time)rUrTrrQr?r]rdr r r r/�s z BinHex.writecCs,|jdkrtd|jf��|��t|_dS)NrzIncorrect data size, diff=%r)rQrrRr^� _DID_DATArUrr r r � close_data�s zBinHex.close_datacCsB|jtkr|��|jtkr$td��|jt|�|_|�|�dS)Nz'Writing resource data at the wrong time)rUrfrgrrRr?r]rdr 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)rUrfrgrrRr^r9r0r=r r r r0�s$      �z BinHex.closeN) rrr rrSr]r^r/rgrhr0r r r r rL�s rLcCs�t|�}t||�}t�|d��4}|�d�}|s0q<|�|�q |��Wd�n1sX0Yt|d�}|�d�}|s|q�|�|�ql|� �|� �dS)zEbinhex(infilename, outfilename): create binhex-encoded copy of a filer��N) r(rLrrrr/rgr)rhr0)�inp�outr#r9�ifpr`r r r r�s   &   rc@s(eZdZdZdd�Zdd�Zdd�ZdS) �_Hqxdecoderenginez*Read data via the decoder in 4-byte chunkscCs||_d|_dS)Nr)rl�eof�rrlr 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) z&Read at least wtd bytes (or until EOF)r.rrr>�Nr zPremature EOF on binhex file) rnrlrr7r@Za2b_hqxZ Incompleterr?)rZtotalwtdZdecdata�wtdr%Z decdatacur�newdatar r r rs*  .     z_Hqxdecoderengine.readcCs|j��dSr*�rlr0rr r r r0:sz_Hqxdecoderengine.closeN)rrr rGrrr0r r r r rms!rmc@s0eZdZdZdd�Zdd�Zdd�Zdd �Zd S) �_RledecoderenginezRead data via the RLE-codercCs||_d|_d|_d|_dS)Nr.r)rl� pre_buffer� post_bufferrnror r r r@sz_Rledecoderengine.__init__cCsD|t|j�kr"|�|t|j��|jd|�}|j|d�|_|Sr*)r?rv�_fill)rrq�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) Nrpr.�����rWr>�����r�����r ) rurlrrnr7rvr@Z rledecode_hqxr?�RUNCHAR)rrqZmarkr r r rwMs. �$    �&z_Rledecoderengine._fillcCs|j��dSr*rsrr r r r0rsz_Rledecoderengine.closeN)rrr rGrrrwr0r r r r rt=s %rtc@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) rNrOrrrrrmrtrlrP� _readheader)rrlZchZhqxifpr r r rvs    zHexBin.__init__cCs |j�|�}t�||j�|_|Sr*)rlrr@rcrP)rr?r%r r r �_read�s z HexBin._readcCsNt�d|j�d��dd@}|jd@|_||jkrDtd|j|f��d|_dS)NrXrri��zCRC error, computed %x, read %x)r[�unpackrlrrPr)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 ��� rX� rz>l�)r��ordr�r[r�rQrR�FNamerrrrrTrU)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.)rUrTr�minrQr?r�)r�nrxr r r r�s   z HexBin.readcCs6|jtkrtd��|jr$|�|j�}|��t|_dS)Nzclose_data at wrong time)rUrTrrQr�r�rf�r�dummyr r r rg�s   zHexBin.close_datacGsZ|jtkr|��|jtkr$td��|r>|d}t||j�}n|j}|j||_|�|�S)Nz Read resource data at wrong timer)rUrTrgrfrr�rRr�)rr�r r r � read_rsrc�s   zHexBin.read_rsrccCsT|jdurdSz.|jr"|�|j�}|��Wd|_|j��nd|_|j��0dSr*)rUrRr�r�rlr0r�r r r r0�s    �z HexBin.closeN) rrr rr�r�rrrgr�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)z6hexbin(infilename, outfilename) - Decode binhexed filerMriN) r}rr�rrrr/rgr�r)r0)rjrkrlr#r9r`r r r r�s$ *     r)rGr@� contextlibrrr[r3�warnr6�__all__� ExceptionrrTrfrIr;r|rr(r)�contextmanagerr7r8rHrLrrmrtr}rr r r r �s:�  (^+8h