
    #)di                     f   d Z dZddlZddlZej        d         dk    rVdZd Zd Zej        d         dk    rej        j        nej        j	        Z
efZeZeZeZd	 Zd
 Zd Zd ZddlmZmZ d Zd ZdS dZeZeZej        j	        Z
eefZeZeZd ZeZd Zd Zd ZddlmZ eZddlZd Z d Zd ZdS )zCompatibility functions for python 2 and 3.

@author     Bernhard Leiner (bleiner AT gmail com)
@author     Alexander Belchenko (alexander belchenko AT gmail com)
javadoc    N   c                 Z    t          | t                    r| S |                     d          S Nlatin1)
isinstancebytesencodess    V/var/www/menimich/repos/protonApp/venv/lib/python3.11/site-packages/intelhex/compat.pyasbytesr   3   s+    a 	Hxx!!!    c                 Z    t          | t                    r| S |                     d          S r   )r   strdecoder   s    r   asstrr   7   s+    a 	Hxx!!!r         c                  .    t          t          |            S N)listrange)argss    r   range_lr   D   s    E4L!!!r   c                 D    t          |                                           S r   )r   keysdikts    r   	dict_keysr    G   s    DIIKK   r   c                 *    |                                  S r   r   r   s    r   dict_keys_gr#   I       yy{{r   c                 *    |                                  S r   itemsr   s    r   dict_items_gr(   K       zz||r   )StringIOBytesIOc                  $    t           j        j        S r   )sysstdoutbuffer r   r   get_binary_stdoutr1   P   s    z  r   c                  $    t           j        j        S r   )r-   stdinr/   r0   r   r   get_binary_stdinr4   S   s    yr   c                  H   	 t          |  S # t          $ r d}d}d}t          |           }|dk    r	| d         }n(|dk    r| \  }}n|dk    r| \  }}}nt          d          |dk    rt	          d          |dk    rd } ||||          cY S d } ||||          cY S w xY w)	Nr   r   r   r   z*wrong number of arguments in range_g call!zstep cannot be zeroc              3   8   K   | |k     r| V  | |z  } | |k     d S d S r   r0   startstopsteps      r   upzrange_g.<locals>.upx   4      $,,#  $,,,,,,r   c              3   8   K   | |k    r| V  | |z  } | |k    d S d S r   r0   r7   s      r   downzrange_g.<locals>.down~   r<   r   )xrangeOverflowErrorlen	TypeError
ValueError)r   r8   r9   r:   nr;   r>   s          r   range_grE   d   s   	/4=  	/ 	/ 	/EDDD		AAvvAwa"tta$(!tTT LMMMqyy !6777axx& & & r%t,,,,,& & & tE4.....5	/s    BB!B! B!c                 *    |                                  S r   r"   r   s    r   r    r       r$   r   c                 *    |                                  S r   r"   r   s    r   r#   r#      r$   r   c                 *    |                                  S r   r&   r   s    r   r(   r(      r)   r   )r*   c                     t           j        dk    rGt          | dd          }|r4 |            }|dk    r$ddl}|                    |t           j                   | S )z(Force binary mode for stream on Windows.ntfilenoNr   )osnamegetattrmsvcrtsetmodeO_BINARY)streamf_filenorK   rO   s       r   _force_stream_binaryrT      s^    7d??vx66H 8!Q;;!MMMNN62;777r   c                  4    t          t          j                  S r   )rT   r-   r.   r0   r   r   r1   r1      s    #CJ///r   c                  4    t          t          j                  S r   )rT   r-   r3   r0   r   r   r4   r4      s    #CI...r   )!__doc____docformat__r-   arrayversion_infoPythonr   r   tobytestostringarray_tobytesintIntTypesr   StrTypeUnicodeTyper   rE   r   r    r#   r(   ior*   r+   r1   r4   long
basestringunicode	cStringIOrL   rT   r0   r   r   <module>rh      s  F           A!F" " "" " " ,/+;A+>!+C+CEK''I]MvHGKG" " "! ! !     %$$$$$$$! ! !         
 FGEK(MT{HGK/ / /@ G       #"""""GIII	 	 	0 0 0/ / / / /r   