%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/urwid/__pycache__/util.cpython-35.pyc



8$�Va3�@s�ddlmZddlmZddlZejZejZejZejZej	Z	ej
Z
ejZdd�Zde
�kr�e�Znds�td��dadad	d
�Zdd�Zd
d�Zee�dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZGd%d&�d&e �Z!d'd(�Z"d)d*�Z#d+d,�Z$d-d.�Z%Gd/d0�d0e&�Z'd1d2�Z(Gd3d4�d4e)�Z*dS)5�)�escape)�bytesNcCs�ddl}yGy|j|jd�Wn|jk
r=YnX|j�dpQdSWnKtk
r�}z+|jr�|jdjd�r�dS�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'sr�detected_encodingz
It worked!TcCs�|j�}|dkr.tjd�dan5|dkrPtjd�dantjd�daday|r�dj|�|aWntk
r�YnXdS)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)rzutf8zutf)rrrrzgb2312zgbkzbig5rzuhczeucjpzeuckrzeuccnr!r")�lower�str_utilZset_byte_encoding�_use_dec_special�_target_encoding�encode�LookupError)�encodingrrr�set_encoding@s&
		
	



r+cCs
tj�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_modebsr,cCs�tr�t|�tkr�y|jtj�}WnXtk
r�xCttjtj	�D],\}}|j
|tj|tj�}qTWYnXt|�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|�dkr�||fSx6|dd�D]$}	t|	t�s�t�t|t�s�t�|	j|d�}
t|
�dkrS|
d}t|t�st�|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&�type�str�	translaterZDEC_SPECIAL_CHARMAP�NotImplementedError�zipZDEC_SPECIAL_CHARSZALT_DEC_SPECIAL_CHARSr-�SO�SI�codecsr(r'�
isinstancer�AssertionError�split�append�len�rle_append_modifyZDEC_TAG�join)�s�cZaltr3r4ZsisZsis0ZsoutZcoutZsnZslZsinZsonZoutstrrrr�apply_target_encodingksV
)



%

r?cCstotdkS)zi
    Return True if python is able to convert non-ascii unicode strings
    to the current encoding.
    r#)r'rrrr�supports_unicode�sr@cCs�|}d}}|dkrht||||�\}}||krhd}t||||d�\}}|||}	t||||	�\}
}||	kr�d}||
||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
	rJc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 ).
    rrN)Nr)Nr)rJr:�
rle_subseg�
rle_get_at�rle_append_beginning_modifyr;r�rjust)rB�attrZcsrCrDrE�eposrFrGZattrtrZcstr�alrrr�trim_text_attr_cs�s'

rRcCsOd}|dkrdSx2|D]*\}}|||kr=|S||7}qWdS)z-
    Return the attribute at offset pos.
    rNr)�rlerI�x�arHrrrrL�srLcCs�g}d}x�|D]�\}}|rb||krH||8}||7}q||7}||8}d}||kroP|||kr�||}||7}|j||f�qW|S)z$Return a sub segment of an rle list.r)r9)rS�start�end�lrTrUrHrrrrK�s$





rKcCsUd}xH|D]@}t|�tks7tt|���|\}}||7}q
W|S)z]
    Return the number of characters covered by a run length
    encoded attribute list.
    r)r.�tupler7�repr)rSrH�vrU�rrrr�rle_lens
$r]cCs~|\}}|s.||fg|dd�<nL|d\}}||kra|||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)rS�a_rrUr\rQrHrrrrMsrMcCsf|\}}|s'|dd|kr>|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.
    rrN���r_r_)r9)rSr^rUr\ZlaZlrrrrr;.sr;cCs3|s
dSt||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;)rS�rle2rrr�rle_join_modify<srac
Csd}}|s|rgS|d\}}|d\}}g}x�|r|rt||�}	t|||f|	f�||	8}|dkr�|t|�kr�||\}}|d7}||	8}|dkrE|t|�krE||\}}|d7}qEW|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.
    rr)�minr;r:)
�rle1r`Zi1Zi2�a1Zr1�a2Zr2rXr\rrr�rle_productHs$




rfcCsYg}g}x@|D]8\\}}}t|||f�t|||f�qW||fS)z!
    Inverse of rle_product.
    )r;)rSrcr`rdrer\rrr�
rle_factorfsrgc@seZdZdS)�TagMarkupExceptionN)�__name__�
__module__�__qualname__rrrrrhrsrhcCs]t|d�\}}|ddd�j|�}|rS|dddkrS|d=||fS)z:Return (text string, attribute list) for tagmarkup passed.Nrrr_r_)�_tagmarkup_recurser<)�tm�tlrQrBrrr�decompose_tagmarkupts
rocCs@t|�tkr�g}g}x�|D]|}t||�\}}|r�|d\}}|d\}	}
||	kr�|	||
f|d<|d=||7}||7}q%W||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 Nonerr�z5Tuples must be in the form (attribute, tagmarkup): %rzInvalid markup element: %rr_r_r_)	r.�listrlrYr:rhr6r/r)rmrOZrtlZral�elementrnrQZ	last_attrZlast_runZtop_attrZtop_runrrrrl�s,



rlcCs;t|�tko:t|�dko:|djd�dkS)N�rZmouse)r.rYr:�find)�evrrr�is_mouse_event�srvcCs|jd�dkS)NZpressr)rt)rurrr�is_mouse_press�srwcs(eZdZdZ�fdd�Z�S)�	MetaSuperzadding .__supercsYtt|�j|||�t|d|�r;td��t|d|t|��dS)Nz
_%s__superz/Class has same name as one of its super classes)�superrx�__init__�hasattr�AttributeError�setattr)�cls�name�bases�d)�	__class__rrrz�szMetaSuper.__init__)rirjrk�__doc__rzrr)r�rrx�srxcCs6t||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
    rrp)�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�wrappedrrrrz�szStoppingContext.__init__cCs|S)Nr)r�rrr�	__enter__�szStoppingContext.__enter__cGs|jj�dS)N)r��stop)r��exc_inforrr�__exit__�szStoppingContext.__exit__N)rirjrkr�rzr�r�rrrrr��sr�)+ZurwidrZurwid.compatrr5r%rAZ
calc_widthZis_wide_charZmove_next_charZmove_prev_charZwithin_double_byter�localsrr7r'r&r+r,r?r@rJrRrLrKr]rMr;rarfrg�	Exceptionrhrorlrvrwr.rxr��objectr�rrrr�<module>sL							"	=

'


Zerion Mini Shell 1.0