%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core22/current/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core22/current/lib/python3/dist-packages/urwid/__pycache__/util.cpython-310.pyc

o

��o_C4�@s`ddlmZmZddlmZddlmZmZmZddl	Z	ej
Z
e
jZe
jZe
j
Z
e
jZe
jZe
jZdd�Zde�vr>e�ZnJd��dad	ad
d�Zdd
�Zdd�Zee�dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z d d!�Z!d"d#�Z"d$d%�Z#Gd&d'�d'e$�Z%d(d)�Z&d*d+�Z'd,d-�Z(d.d/�Z)Gd0d1�d1e*�Z+d2d3�Z,Gd4d5�d5e-�Z.dS)6�)�division�print_function)�escape)�bytes�	text_type�
text_typesNcCsddl}|��}zfz1z	|�|jd�Wn
|jyYnw|��dp%dWWz	|�|j|�WS|jy:YSwtyn}z(|jri|jd�d�riWYd}~Wz
|�|j|�WdS|jyhYdSw�d}~wwz	|�|j|�Ww|jy�Yww)Nr��zunknown locale)�locale�	getlocale�	setlocale�LC_ALL�Error�
ValueError�args�
startswith)r
�initial�e�r�,/usr/lib/python3/dist-packages/urwid/util.py�detect_encoding)s<��������r�detected_encodingz
It worked!TcCs~|��}|dvrt�d�dan|dvrt�d�dant�d�dadaz|r2d	�|�|aWd
SWd
Sty>Yd
Sw)z~
    Set the byte encoding to assume when processing strings and the
    encoding to use when converting unicode strings.
    )zutf-8�utf8�utfrF)zeuc-jpzeuc-krzeuc-cnzeuc-tw�gb2312�gbk�big5zcn-gb�uhc�eucjp�euckr�euccn�euctw�cncb�wideT�narrow�asciirN)�lower�str_util�set_byte_encoding�_use_dec_special�_target_encoding�encode�LookupError)�encodingrrr�set_encodingHs 




�r.cCst��S)z�
    Get the mode Urwid is using when processing text strings.
    Returns 'narrow' for 8-bit encodings, 'wide' for CJK encodings
    or 'utf8' for UTF-8 encodings.
    )r'�get_byte_encodingrrrr�get_encoding_modejsr0c	Cstr2t|�tkr2z|�tj�}Wn!ty1ttjtj	�D]\}}|�
|tj|tj�}qYnwt|�tkrI|�
tjtjd�}t
�|td�}t|t�sPJ�tj�d�}tj�d�}|�|�}t|dt�sjJ�|d�
|t��}g}g}|r�|�|�|�dt|�f�t|�dkr�||fS|dd�D]f}	t|	t�s�J�t|t�s�J�|	�|d�}
t|
�dkr�|
d}t|t�s�J�|�|�t|tj�d�t|�f�q�|
\}}|�
|t��}|r�|�|�t|tjt|�f�|r�|�|�t|dt|�f�q�t��|�}
|
|fS)z:
    Return (encoded byte string, character set rle).
    r�replacer%rNr	)r)�typer�	translater�DEC_SPECIAL_CHARMAP�NotImplementedError�zip�DEC_SPECIAL_CHARS�ALT_DEC_SPECIAL_CHARSr1�SO�SI�codecsr+r*�
isinstancer�split�append�len�rle_append_modify�DEC_TAG�join)�s�c�altr9r:�sis�sis0�sout�cout�sn�sl�sin�son�outstrrrr�apply_target_encodingss^���




�rOcCstotdkS)zi
    Return True if python is able to convert non-ascii unicode strings
    to the current encoding.
    r%)r*rrrr�supports_unicode�srPcCs~|}d}}|dkr$t||||�\}}||kr$d}t||||d�\}}|||}	t||||	�\}
}||	kr9d}||
||fS)a	
    Calculate the result of trimming text.
    start_offs -- offset into text to treat as screen column 0
    end_offs -- offset into text to treat as the end of the line
    start_col -- screen column to trim at the left
    end_col -- screen column to trim at the right

    Returns (start, end, pad_left, pad_right), where:
    start -- resulting start offset
    end -- resulting end offset
    pad_left -- 0 for no pad or 1 for one space to be added
    pad_right -- 0 for no pad or 1 for one space to be added
    rr	)�
calc_text_pos)�text�
start_offs�end_offs�	start_col�end_col�spos�pad_left�	pad_right�sc�run�posrrr�calc_trim_text�s�r]cCs�t|dt|�||�\}}}}t|||�}	t|||�}
|r/t||d�}t|	|df�t|
d�|rBt||�}t|	|df�t|
d�t��|�|||�t��|�|	|
fS)z<
    Return ( trimmed text, trimmed attr, trimmed cs ).
    rr	)Nr	)r]r?�
rle_subseg�
rle_get_at�rle_prepend_modifyr@r�rjust)rR�attr�csrUrVrW�eposrXrY�attrtr�cstr�alrrr�trim_text_attr_cs�s$�



��rhcCs>d}|dkrdS|D]\}}|||kr|S||7}q
dS)z-
    Return the attribute at offset pos.
    rNr)�rler\�x�ar[rrrr_�s
r_cCs�g}d}|D]9\}}|r#||kr||8}||7}q||7}||8}d}||kr*|S|||kr4||}||7}|�||f�q|S)z$Return a sub segment of an rle list.r�r>)ri�start�end�lrjrkr[rrrr^s&�r^cCs:d}|D]}t|�tksJt|���|\}}||7}q|S)z]
    Return the number of characters covered by a run length
    encoded attribute list.
    r)r2�tuple�repr)rir[�vrk�rrrr�rle_lens
rtcCs`|\}}|s||fg|dd�<dS|d\}}||kr%|||f|d<dS||fg|dd�<dS)z�
    Append (a, r) (unpacked from *a_r*) to BEGINNING of rle.
    Merge with first run when possible

    MODIFIES rle parameter contents. Returns None.
    Nrr)ri�a_rrkrsrgr[rrrr`$sr`cCsN|\}}|r|dd|kr|�||f�dS|d\}}|||f|d<dS)z�
    Append (a, r) (unpacked from *a_r*) to the rle list rle.
    Merge with last run when possible.

    MODIFIES rle parameter contents. Returns None.
    ���rNrl)rirurkrs�la�lrrrrr@6sr@cCs*|sdSt||d�||dd�7}dS)z�
    Append attribute list rle2 to rle.
    Merge last run of rle with first run of rle2 when possible.

    MODIFIES attr parameter contents. Returns None.
    Nrr	�r@)ri�rle2rrr�rle_join_modifyDsr{c
Cs�d}}|r|s
gS|d\}}|d\}}g}|r^|r^t||�}	t|||f|	f�||	8}|dkrB|t|�krB||\}}|d7}||	8}|dkrZ|t|�krZ||\}}|d7}|r^|s|S)a
    Merge the runs of rle1 and rle2 like this:
    eg.
    rle1 = [ ("a", 10), ("b", 5) ]
    rle2 = [ ("Q", 5), ("P", 10) ]
    rle_product: [ (("a","Q"), 5), (("a","P"), 5), (("b","P"), 5) ]

    rle1 and rle2 are assumed to cover the same total run.
    r	r)�minr@r?)
�rle1rz�i1�i2�a1�r1�a2�r2rorsrrr�rle_productPs$

�r�cCs>g}g}|D]\\}}}t|||f�t|||f�q||fS)z!
    Inverse of rle_product.
    ry)rir}rzr�r�rsrrr�
rle_factornsr�c@seZdZdS)�TagMarkupExceptionN)�__name__�
__module__�__qualname__rrrrr�zsr�cCsFt|d�\}}|ddd��|�}|r|dddur|d=||fS)z:Return (text string, attribute list) for tagmarkup passed.Nrrv)�_tagmarkup_recurserB)�tm�tlrgrRrrr�decompose_tagmarkup|s
r�cCs�t|�tkr?g}g}|D].}t||�\}}|r2|d\}}|d\}	}
||	kr2|	||
f|d<|d=||7}||7}q||fSt|�tkr[t|�dkrRtd|f��|\}}t||�St|ttf�sitd|��|g|t|�fgfS)zsReturn (text list, attribute list) for tagmarkup passed.

    tm -- tagmarkup
    attr -- current attribute or Nonervr�z5Tuples must be in the form (attribute, tagmarkup): %rzInvalid markup element: %r)	r2�listr�rpr?r�r<rr)r�rb�rtl�ral�elementr�rg�	last_attr�last_run�top_attr�top_runrrrr��s,

r�cCs*t|�tkot|�dko|d�d�dkS)N�r�mouse)r2rpr?�find��evrrr�is_mouse_event�s*r�cCs|�d�dkS)N�pressr)r�r�rrr�is_mouse_press��r�cs eZdZdZ�fdd�Z�ZS)�	MetaSuperzadding .__supercsBtt|��|||�t|d|�rtd��t|d|t|��dS)Nz
_%s__superz/Class has same name as one of its super classes)�superr��__init__�hasattr�AttributeError�setattr)�cls�name�bases�d��	__class__rrr��szMetaSuper.__init__)r�r�r��__doc__r��
__classcell__rrr�rr��sr�cCs0t||dd|d�}|dd}||S)aW
    Scale val in the range [0, val_range-1] to an integer in the range
    [0, out_range-1].  This implementation uses the "round-half-up" rounding
    method.

    >>> "%x" % int_scale(0x7, 0x10, 0x10000)
    '7777'
    >>> "%x" % int_scale(0x5f, 0x100, 0x10)
    '6'
    >>> int_scale(2, 6, 101)
    40
    >>> int_scale(1, 3, 4)
    2
    r	r�)�int)�val�	val_range�	out_range�num�demrrr�	int_scale�sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�StoppingContextz�Context manager that calls ``stop`` on a given object on exit.  Used to
    make the ``start`` method on `MainLoop` and `BaseScreen` optionally act as
    context managers.
    cCs
||_dS�N)�_wrapped)�self�wrappedrrrr��s
zStoppingContext.__init__cCs|Sr�r)r�rrr�	__enter__�szStoppingContext.__enter__cGs|j��dSr�)r��stop)r��exc_inforrr�__exit__�r�zStoppingContext.__exit__N)r�r�r�r�r�r�r�rrrrr��s
r�)/�
__future__rr�urwidr�urwid.compatrrrr;r'rQ�
calc_width�is_wide_char�move_next_char�move_prev_char�within_double_byter�localsrr*r)r.r0rOrPr]rhr_r^rtr`r@r{r�r��	Exceptionr�r�r�r�r�r2r�r��objectr�rrrr�<module>sP
"	=
'


Zerion Mini Shell 1.0