Current Dir: /snap/core22/2437/usr/lib/python3/dist-packages/urwid/__pycache__/

[FILE] canvas.cpython-310.pyc [ edit | delete | rename ]
[FILE] command_map.cpython-310.pyc [ edit | delete | rename ]
[FILE] compat.cpython-310.pyc [ edit | delete | rename ]
[FILE] container.cpython-310.pyc [ edit | delete | rename ]
[FILE] curses_display.cpython-310.pyc [ edit | delete | rename ]
[FILE] decoration.cpython-310.pyc [ edit | delete | rename ]
[FILE] display_common.cpython-310.pyc [ edit | delete | rename ]
[FILE] escape.cpython-310.pyc [ edit | delete | rename ]
[FILE] font.cpython-310.pyc [ edit | delete | rename ]
[FILE] graphics.cpython-310.pyc [ edit | delete | rename ]
[FILE] html_fragment.cpython-310.pyc [ edit | delete | rename ]
[FILE] lcd_display.cpython-310.pyc [ edit | delete | rename ]
[FILE] listbox.cpython-310.pyc [ edit | delete | rename ]
[FILE] main_loop.cpython-310.pyc [ edit | delete | rename ]
[FILE] monitored_list.cpython-310.pyc [ edit | delete | rename ]
[FILE] numedit.cpython-310.pyc [ edit | delete | rename ]
[FILE] old_str_util.cpython-310.pyc [ edit | delete | rename ]
[FILE] raw_display.cpython-310.pyc [ edit | delete | rename ]
[FILE] signals.cpython-310.pyc [ edit | delete | rename ]
[FILE] split_repr.cpython-310.pyc [ edit | delete | rename ]
[FILE] text_layout.cpython-310.pyc [ edit | delete | rename ]
[FILE] treetools.cpython-310.pyc [ edit | delete | rename ]
[FILE] util.cpython-310.pyc [ edit | delete | rename ]
[FILE] version.cpython-310.pyc [ edit | delete | rename ]
[FILE] vterm.cpython-310.pyc [ edit | delete | rename ]
[FILE] web_display.cpython-310.pyc [ edit | delete | rename ]
[FILE] widget.cpython-310.pyc [ edit | delete | rename ]
[FILE] wimp.cpython-310.pyc [ edit | delete | rename ]
[FILE] _async_kw_event_loop.cpython-310.pyc [ edit | delete | rename ]
[FILE] __init__.cpython-310.pyc [ edit | delete | rename ]

Viewing: /snap/core22/2437/usr/lib/python3/dist-packages/urwid/__pycache__/web_display.cpython-310.pyc

o

��o_4{�@s~ddlmZmZ	ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZdZdZ
dZdZdZd	Zd
Zidd�d
d�dd�dd�dd�dd�dd�dd�dd�dd�dd �d!d"�d#d$�d%d&�d'd(�d)d*�Zd+d,�d-d.�ed/d0�D��Zd1Zd2d3ed4d5ed6gZGd7d8�d8�ZdMd:d;�Zd<d=�Zd>d?�Zd@dA�ZGdBdC�dC�Ze�a	E	FdNdGdH�Z GdIdJ�dJ�Z!dKdL�Z"dS)O�)�division�print_functionN)�utila�2
// Urwid web (CGI/Asynchronous Javascript) display module
//    Copyright (C) 2004-2005  Ian Ward
//
//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Urwid web site: http://excess.org/urwid/

colours = new Object();
colours = {
    '0': "black",
    '1': "#c00000",
    '2': "green",
    '3': "#804000",
    '4': "#0000c0",
    '5': "#c000c0",
    '6': "teal",
    '7': "silver",
    '8': "gray",
    '9': "#ff6060",
    'A': "lime",
    'B': "yellow",
    'C': "#8080ff",
    'D': "#ff40ff",
    'E': "aqua",
    'F': "white"
};

keycodes = new Object();
keycodes = {
    8: "backspace", 9: "tab", 13: "enter", 27: "esc",
    33: "page up", 34: "page down", 35: "end", 36: "home",
    37: "left", 38: "up", 39: "right", 40: "down",
    45: "insert", 46: "delete",
    112: "f1", 113: "f2", 114: "f3", 115: "f4",
    116: "f5", 117: "f6", 118: "f7", 119: "f8",
    120: "f9", 121: "f10", 122: "f11", 123: "f12"
    };

var conn = null;
var char_width = null;
var char_height = null;
var screen_x = null;
var screen_y = null;

var urwid_id = null;
var send_conn = null;
var send_queue_max = 32;
var send_queue = new Array(send_queue_max);
var send_queue_in = 0;
var send_queue_out = 0;

var check_font_delay = 1000;
var send_more_delay = 100;
var poll_again_delay = 500;

var document_location = null;

var update_method = "multipart";

var sending = false;
var lastkeydown = null;

function setup_connection() {
    if (window.XMLHttpRequest) {
        conn = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        conn = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (conn == null) {
        set_status("Connection Failed");
        alert( "Can't figure out how to send request." );
        return;
    }
    try{
        conn.multipart = true;
    }catch(e){
        update_method = "polling";
    }
    conn.onreadystatechange = handle_recv;
    conn.open("POST", document_location, true);
    conn.setRequestHeader("X-Urwid-Method",update_method);
    conn.setRequestHeader("Content-type","text/plain");
    conn.send("window resize " +screen_x+" "+screen_y+"\n");
}

function do_poll() {
    if (urwid_id == null){
        alert("that's unpossible!");
        return;
    }
    if (window.XMLHttpRequest) {
        conn = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        conn = new ActiveXObject("Microsoft.XMLHTTP");
    }
    conn.onreadystatechange = handle_recv;
    conn.open("POST", document_location, true);
    conn.setRequestHeader("X-Urwid-Method","polling");
    conn.setRequestHeader("X-Urwid-ID",urwid_id);
    conn.setRequestHeader("Content-type","text/plain");
    conn.send("eh?");
}

function handle_recv() {
    if( ! conn ){ return;}
    if( conn.readyState != 4) {
        return;
    }
    if( conn.status == 404 && urwid_id != null) {
        set_status("Connection Closed");
        return;
    }
    if( conn.status == 403 && update_method == "polling" ) {
        set_status("Server Refused Connection");
        alert("This server does not allow polling clients.\n\n" +
            "Please use a web browser with multipart support " +
            "such as Mozilla Firefox");
        return;
    }
    if( conn.status == 503 ) {
        set_status("Connection Failed");
        alert("The server has reached its maximum number of "+
            "connections.\n\nPlease try again later.");
        return;
    }
    if( conn.status != 200) {
        set_status("Connection Failed");
        alert("Error from server: "+conn.statusText);
        return;
    }
    if( urwid_id == null ){
        urwid_id = conn.getResponseHeader("X-Urwid-ID");
        if( send_queue_in != send_queue_out ){
            // keys waiting
            do_send();
        }
        if(update_method=="polling"){
            set_status("Polling");
        }else if(update_method=="multipart"){
            set_status("Connected");
        }

    }

    if( conn.responseText == "" ){
        if(update_method=="polling"){
            poll_again();
        }
        return; // keepalive
    }
    if( conn.responseText == "Z" ){
        set_status("Connection Closed");
        update_method = null;
        return;
    }

    var text = document.getElementById('text');

    var last_screen = Array(text.childNodes.length);
    for( var i=0; i<text.childNodes.length; i++ ){
        last_screen[i] = text.childNodes[i];
    }

    var frags = conn.responseText.split("\n");
    var ln = document.createElement('span');
    var k = 0;
    for( var i=0; i<frags.length; i++ ){
        var f = frags[i];
        if( f == "" ){
            var br = document.getElementById('br').cloneNode(true);
            ln.appendChild( br );
            if( text.childNodes.length > k ){
                text.replaceChild(ln, text.childNodes[k]);
            }else{
                text.appendChild(ln);
            }
            k = k+1;
            ln = document.createElement('span');
        }else if( f.charAt(0) == "<" ){
            line_number = parseInt(f.substr(1));
            if( line_number == k ){
                k = k +1;
                continue;
            }
            var clone = last_screen[line_number].cloneNode(true);
            if( text.childNodes.length > k ){
                text.replaceChild(clone, text.childNodes[k]);
            }else{
                text.appendChild(clone);
            }
            k = k+1;
        }else{
            var span=make_span(f.substr(2),f.charAt(0),f.charAt(1));
            ln.appendChild( span );
        }
    }
    for( var i=k; i < text.childNodes.length; i++ ){
        text.removeChild(last_screen[i]);
    }

    if(update_method=="polling"){
        poll_again();
    }
}

function poll_again(){
    if(conn.status == 200){
        setTimeout("do_poll();",poll_again_delay);
    }
}


function load_web_display(){
    if( document.documentURI ){
        document_location = document.documentURI;
    }else{
        document_location = document.location;
    }

    document.onkeypress = body_keypress;
    document.onkeydown = body_keydown;
    document.onresize = body_resize;

    body_resize();
    send_queue_out = send_queue_in; // don't queue the first resize

    set_status("Connecting");
    setup_connection();

    setTimeout("check_fontsize();",check_font_delay);
}

function set_status( status ){
    var s = document.getElementById('status');
    var t = document.createTextNode(status);
    s.replaceChild(t, s.firstChild);
}

function make_span(s, fg, bg){
    d = document.createElement('span');
    d.style.backgroundColor = colours[bg];
    d.style.color = colours[fg];
    d.appendChild(document.createTextNode(s));

    return d;
}

function body_keydown(e){
    if (conn == null){
        return;
    }
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;

    var mod = "";
    var key;

    if( e.ctrlKey ){ mod = "ctrl " + mod; }
    if( e.altKey || e.metaKey ){ mod = "meta " + mod; }
    if( e.shiftKey && e.charCode == 0 ){ mod = "shift " + mod; }

    key = keycodes[code];

    if( key != undefined ){
        lastkeydown = key;
        send_key( mod + key );
        stop_key_event(e);
        return false;
    }
}

function body_keypress(e){
    if (conn == null){
        return;
    }

    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;

    var mod = "";
    var key;

    if( e.ctrlKey ){ mod = "ctrl " + mod; }
    if( e.altKey || e.metaKey ){ mod = "meta " + mod; }
    if( e.shiftKey && e.charCode == 0 ){ mod = "shift " + mod; }

    if( e.charCode != null && e.charCode != 0 ){
        key = String.fromCharCode(e.charCode);
    }else if( e.charCode == null ){
        key = String.fromCharCode(code);
    }else{
        key = keycodes[code];
        if( key == undefined || lastkeydown == key ){
            lastkeydown = null;
            stop_key_event(e);
            return false;
        }
    }

    send_key( mod + key );
    stop_key_event(e);
    return false;
}

function stop_key_event(e){
    e.cancelBubble = true;
    if( e.stopPropagation ){
        e.stopPropagation();
    }
    if( e.preventDefault  ){
        e.preventDefault();
    }
}

function send_key( key ){
    if( (send_queue_in+1)%send_queue_max == send_queue_out ){
        // buffer overrun
        return;
    }
    send_queue[send_queue_in] = key;
    send_queue_in = (send_queue_in+1)%send_queue_max;

    if( urwid_id != null ){
        if (send_conn == undefined || send_conn.ready_state != 4 ){
            send_more();
            return;
        }
        do_send();
    }
}

function do_send() {
    if( ! urwid_id ){ return; }
    if( ! update_method ){ return; } // connection closed
    if( send_queue_in == send_queue_out ){ return; }
    if( sending ){
        //var queue_delta = send_queue_in - send_queue_out;
        //if( queue_delta < 0 ){ queue_delta += send_queue_max; }
        //set_status("Sending (queued "+queue_delta+")");
        return;
    }
    try{
        sending = true;
        //set_status("starting send");
        if( send_conn == null ){
            if (window.XMLHttpRequest) {
                send_conn = new XMLHttpRequest();
            } else if (window.ActiveXObject) {
                send_conn = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }else if( send_conn.status != 200) {
            alert("Error from server: "+send_conn.statusText);
            return;
        }else if(send_conn.readyState != 4 ){
            alert("not ready on send connection");
            return;
        }
    } catch(e) {
        alert(e);
        sending = false;
        return;
    }
    send_conn.open("POST", document_location, true);
    send_conn.onreadystatechange = send_handle_recv;
    send_conn.setRequestHeader("Content-type","text/plain");
    send_conn.setRequestHeader("X-Urwid-ID",urwid_id);
    var tmp_send_queue_in = send_queue_in;
    var out = null;
    if( send_queue_out > tmp_send_queue_in ){
        out = send_queue.slice(send_queue_out).join("\n")
        if( tmp_send_queue_in > 0 ){
            out += "\n"  + send_queue.slice(0,tmp_send_queue_in).join("\n");
        }
    }else{
        out = send_queue.slice(send_queue_out,
             tmp_send_queue_in).join("\n");
    }
    send_queue_out = tmp_send_queue_in;
    //set_status("Sending");
    send_conn.send( out +"\n" );
}

function send_handle_recv() {
    if( send_conn.readyState != 4) {
        return;
    }
    if( send_conn.status == 404) {
        set_status("Connection Closed");
        update_method = null;
        return;
    }
    if( send_conn.status != 200) {
        alert("Error from server: "+send_conn.statusText);
        return;
    }

    sending = false;

    if( send_queue_out != send_queue_in ){
        send_more();
    }
}

function send_more(){
    setTimeout("do_send();",send_more_delay);
}

function check_fontsize(){
    body_resize()
    setTimeout("check_fontsize();",check_font_delay);
}

function body_resize(){
    var t = document.getElementById('testchar');
    var t2 = document.getElementById('testchar2');
    var text = document.getElementById('text');

    var window_width;
    var window_height;
    if (window.innerHeight) {
        window_width = window.innerWidth;
        window_height = window.innerHeight;
    }else{
        window_width = document.documentElement.clientWidth;
        window_height = document.documentElement.clientHeight;
        //var z = "CI:"; for(var i in bod){z = z + " " + i;} alert(z);
    }

    char_width = t.offsetLeft / 44;
    var avail_width = window_width-18;
    var avail_width_mod = avail_width % char_width;
    var x_size = (avail_width - avail_width_mod)/char_width;

    char_height = t2.offsetTop - t.offsetTop;
    var avail_height = window_height-text.offsetTop-10;
    var avail_height_mod = avail_height % char_height;
    var y_size = (avail_height - avail_height_mod)/char_height;

    text.style.width = x_size*char_width+"px";
    text.style.height = y_size*char_height+"px";

    if( screen_x != x_size || screen_y != y_size ){
        send_key("window resize "+x_size+" "+y_size);
    }
    screen_x = x_size;
    screen_y = y_size;
}

�<����dii@�black�0zdark red�1z
dark green�2�brown�3z	dark blue�4zdark magenta�5z	dark cyan�6�
light gray�7z	dark gray�8z	light red�9zlight green�A�yellow�Bz
light blue�Cz
light magenta�Dz
light cyan�E�white�Fz ????????????????????????????????�cCsg|]}t|��qS�)�chr)�.0�xrr�3/usr/lib/python3/dist-packages/urwid/web_display.py�
<listcomp>sr$� �ah
body {    margin: 8px 8px 8px 8px; border: 0;
    color: black; background-color: silver;
    font-family: fixed; overflow: hidden; }

form { margin: 0 0 8px 0; }

#text { position: relative;
    background-color: silver;
    width: 100%; height: 100%;
    margin: 3px 0 0 0; border: 1px solid #999; }

#page { position: relative;  width: 100%;height: 100%;}
z�<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Urwid Web Display - z!</title>
<style type="text/css">
a
</style>
</head>
<body id="body" onload="load_web_display()">
<div style="position:absolute; visibility:hidden;">
<br id="br"\>
<pre>The quick brown fox jumps over the lazy dog.<span id="testchar">X</span>
<span id="testchar2">Y</span></pre>
</div>
Urwid Web Display - <b>z[</b> -
Status: <span id="status">Set up</span>
<script type="text/javascript">
//<![CDATA[
z7
//]]>
</script>
<pre id="text"></pre>
</body>
</html>
c@s�eZdZdd�Zedd��Zdd�Z	d*dd	�Zd+dd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd,d(d)�ZdS)-�ScreencCsi|_d|_d|_dS)NTF)�palette�	has_color�_started��selfrrr#�__init__@s
zScreen.__init__cC�|jS�N)r*r+rrr#�<lambda>EszScreen.<lambda>cCsh|D]/}t|�dvr|j|�qt|�dksJd��|\}}||jvr)td|��|j||j|<qdS)z�Register a list of palette entries.

        l -- list of (name, foreground, background) or
             (name, same_as_other_name) palette entries.

        calls self.register_palette_entry for each item in l
        )r��zInvalid register_palette usagez palette entry '%s' doesn't existN)�len�register_palette_entryr(�	Exception)r,�l�item�name�	like_namerrr#�register_paletteGs	

�zScreen.register_paletteNcCs,|dkrd}|dkrd}|||f|j|<dS)aRegister a single palette entry.

        name -- new entry/attribute name
        foreground -- foreground colour
        background -- background colour
        mono -- monochrome terminal attribute

        See curses_display.register_palette_entry for more info.
        �defaultr	rN)r()r,r8�
foreground�
background�monorrr#r4Zs
zScreen.register_palette_entryTcC�dS)zNot yet implementedNr)r,�enablerrr#�set_mouse_trackingk�zScreen.set_mouse_trackingcOr?)zDo nothing.Nr)r,�args�vargsrrr#�tty_signal_keysorBzScreen.tty_signal_keyscCs�|jrt�|�Stj�d�}|�d�sJ|��|�dd�\}}}}t|�}t|�}|�	||�i|_
d|_tj
d|_|jdvsBJ�|jdkrUtjsUtj�d	�t�d�t�tj�tjd
��}t|�tjkrrtj�d�t�d�dt�d
�t�d
�f}tj�tjd|�|_t�|jdd�t�tj|j �t�!|jdtj"tj#B�|_$d|_%d|d|_&|jdkr�d|d|_&t�tj'|j(�t�)t*�d|_t�|�S)z�
        This function reads the initial screen size, generates a
        unique id and handles cleanup when fn exits.

        web_display.set_preferences(..) must be called before calling
        this function for the preferences to take effect
        �2�window resize � rr�HTTP_X_URWID_METHOD)�	multipart�pollingrK�Status: 403 Forbidden

z	urwid*.inzStatus: 503 Sever Busy

z%09d%09diʚ;�urwid�.ini�rzAContent-type: multipart/x-mixed-replace;boundary=ZZ
X-Urwid-ID: z


--ZZ
z&Content-type: text/plain
X-Urwid-ID: z


T)+r*r�StoppingContext�sys�stdin�read�
startswith�split�int�_set_screen_size�last_screen�last_screen_width�os�environ�
update_method�_prefs�
allow_polling�stdout�write�exit�glob�path�join�pipe_dirr3�max_clients�random�	randrange�	pipe_name�mkfifo�signal�SIGTERM�
_cleanup_pipe�open�
O_NONBLOCK�O_RDONLY�input_fd�
input_tail�content_head�SIGALRM�
_handle_alarm�alarm�ALARM_DELAY)r,�client_init�ignore1�ignore2r"�y�clients�urwid_idrrr#�startssZ




�
���
���

zScreen.startcCsL|jsdSz|��Wn	tyYnwt�tjtj�|��d|_dS)z0
        Restore settings and clean up.
        NF)r*�_close_connectionr5rjrk�SIG_DFLrlr+rrr#�stop�s�
zScreen.stopcGsdSr/r�r,rCrrr#�set_input_timeouts�szScreen.set_input_timeoutscCs$z|��|�W|��S|��w)zb
        Run the application main loop, calling start() first
        and stop() on exit.
        )r}r�)r,�fnrrr#�run_wrapper�szScreen.run_wrappercCs^|jdkr|j�d�|j��\}}|�d�|��|jdkr-tj�d�tj�	�dSdS)N�
polling childr�ZrJz

Z
--ZZ--
)
r[�
server_socket�
settimeout�accept�sendall�closerPr^r_�flush)r,�sock�addrrrr#r~�s


�zScreen._close_connectioncGsF|jsdSzt�|jd�t�|jd�WdSty"YdSw)NrN�.update)rhrY�remover5r�rrr#rl�s
�zScreen._cleanup_pipecCs&|tkrt}|tkrt}||f|_dS)z&Set the screen size (within max size).N)�MAX_COLS�MAX_ROWS�screen_size)r,�cols�rowsrrr#rV�s
zScreen._set_screen_sizec
Cs�|\}}||jkri|_|jg}|jdkr|j}n6|jdkr@t�d�z	|j��\}}Wnt	j
y;t�d�Ynw|j
}nt�d�|j}|d�d|_|��|ksWJ�|jdurb|j\}	}
nd}	}
i}d}|��D]�}
|d7}t|
�}
g}t|
�}||
kr�||	f}|�|g�|g||<|j�|d�}|dur�||vr�|}n|d}|d	|�qnd}|
D]Y\}}}|�t�}|dur�d
\}}}n|j|\}}}||
k�r||	k�rt�|dt|��}|||	kr�|�t||||	|��n	|�t|||��||7}q�|�t|||��q�|d�|�d�qn||_||_|jdk�r;tj�d�|��tj��tj��|� �n|jdk�rF|��n|d�tj�d�|��tj��t�t!�dS)
z#Send a screen update to the client.rKr�rz
rN����z<%d
)r	rN�
z
--ZZ
)"rXrWrrr[�appendrjrur�r��socket�timeoutrPr`r�r��cursor�content�list�tuple�get�	translate�_trans_tabler(r�
calc_widthr3�	code_spanrcr^r_r�r��_fork_childrv)r,�size�rr�r��sendq�send�sr��cx�cy�
new_screenrz�rowr6�sig�old_line_numbers�old_line�col�a�cs�run�fg�bgr>�	run_widthrrr#�draw_screen�s�



�


��





zScreen.draw_screencCr?)z�
        Force the screen to be completely repainted on the next
        call to draw_screen().

        (does nothing for web_display)
        Nrr+rrr#�clearGszScreen.clearcCsnt|jd�t�|jdtjtjB�|_d|_t�tj	tj
�}|�|jd�|�d�|�
t�||_dS)zw
        Fork a child to run CGI disconnected for polling update method.
        Force parent process to exit.
        z.errrNr�r�r�N)�	daemonizerhrYrmrnrorpr[r��AF_UNIX�SOCK_STREAM�bind�listenr��POLL_CONNECTr�)r,r�rrr#r�Qs
�


zScreen._fork_childcCsv|jdvsJ�|jdkr)z
|j��\}}|��Wntjy(t�d�Ynwtj�	d�tj�
�t�t
�dS)N)rJr�r�rz


--ZZ
)r[r�r�r�r�r�rPr`r^r_r�rjrurv)r,r��framer�r�rrr#rt`s
�
zScreen._handle_alarmcCr.)zReturn the screen size.)r�r+rrr#�
get_cols_rowspszScreen.get_cols_rowsFc
Csdg}d}zt�|jgggd�\}}}Wn)tjy<}z|jddkr7|r/ggfWYd}~SgWYd}~S�d}~ww|sG|rEggfSgSt�|jt�}t�|j�t�|j	dtj
tjB�|_|�d�}	|j
|	d|	d<|	d|_
|	dd�D]'}
|
�d	�r�|
�d
d�\}}}
}t|
�}
t|�}|�|
|�d}q{|�|
�q{|r�|�d
�|r�|gfS|S)zReturn pending input as a list.Fg�?rr1NrNr�r�rGrHrTz
window resize)�selectrp�errorrCrYrR�MAX_READr�rmrhrnrorTrqrSrUrVr�)r,�raw_keysr6�resized�iready�oready�eready�e�keydata�keys�k�ign1�ign2r"rzrrr#�	get_inputtsN���
�



zScreen.get_inputr/)T)F)�__name__�
__module__�__qualname__r-�property�startedr:r4rArEr}r�r�r�r~rlrVr�r�r�rtr�r�rrrr#r'?s*
�
<		[
r'r�c	Cs�t|}t|}|dkrEt�|dt|�|�\}}t�||t|��}|||d|�d|||||�d||||d�dS|||dS)Nrr�)�
_code_coloursr�
calc_text_posr3�move_next_char)	r�r�r�r��code_fg�code_bg�c_off�_ign�c2_offrrr#r��s.��
����
��r�cCs(|�dd�}|�dd�}|�dd�}|S)z;Escape text so that it will be displayed safely within HTML�&z&amp;�<z&lt;�>z&gt;)�replace)�textrrr#�html_escape�sr�cCs
dtjvS)z3
    Return True if this is a CGI web request.
    �REQUEST_METHOD)rYrZrrrr#�is_web_request�s
r�cCs�t�sdStjddkrtj�dttj��	t
��dStjddkr%dSdtjvr,dStjd}t|�dkr?tj�d	�dS|D]}|d
vrPtj�d�dSqAtj�dd
�dkr�t
�
t
jt
j�}z(|�tj�	tjd|d��d|�t�}|r�tj�|�|�t�}|s{WdSt
jy�tj�d�YdSwzt�tj�	tjd|d�tj�}Wnty�tj�d�YdSwtj�t�}t�||�d��t�|�tj�d�dS)ar
    Handle short requests such as passing keystrokes to the application
    or sending the initial html page.  If returns True, then this
    function recognised and handled a short request, and the calling
    script should immediately exit.

    web_display.set_preferences(..) should be called before calling this
    function for the preferences to take effect
    Fr��GETzContent-type: text/html

T�POST�HTTP_X_URWID_ID�zStatus: 414 URI Too Long

�
0123456789rLrINrKrMr�zContent-type: text/plain

zStatus: 404 Not Found

rN�ascii)r�rYrZrPr^r_r�r\�app_namerc�
_html_pager3r�r�r�r��connectrbrd�recv�BUF_SZr�rm�O_WRONLY�OSErrorrQrRr��encoder�)r|�cr��data�fdr�rrr#�handle_short_request�sf�

�
�
��
���
r�c@seZdZdZdZdZdZdS)�_PreferenceszUnnamed Application�/tmpTr�N)r�r�r�r�rdr]rerrrr#r�
s
r�r�Tr�cCs|t_|t_|t_|t_dS)a�
    Set web_display preferences.

    app_name -- application name to appear in html interface
    pipe_dir -- directory for input pipes, daemon update sockets
                and daemon error logs
    allow_polling -- allow creation of daemon processes for
                     browsers without multipart support
    max_clients -- maximum concurrent client connections. This
               pool is shared by all urwid applications
               using the same pipe_dir
    N)r\r�rdr]re)r�rdr]rerrr#�set_preferencess
r�c@seZdZdd�Zdd�ZdS)�ErrorLogcCs
||_dSr/)�errfile)r,r�rrr#r-(s
zErrorLog.__init__cCst|jd��|�dS)Nr�)rmr�r_)r,�errrrr#r_*szErrorLog.writeN)r�r�r�r-r_rrrr#r�'sr�c	Cs�t��}|rt�d�t��t�tjtj�t�d�t��}|r't�d�t�d�t	dd�D]}zt�
|�Wq1tyCYq1wtdd�t
_tdd�t
_t|�t
_dS)z-
    Detach process and become a daemon.
    r�/r�z	/dev/nullr��wN)rY�fork�_exit�setsidrj�SIGHUP�SIG_IGN�umask�chdir�ranger�r�rmrPrQr^r��stderr)r��pidr�rrr#r�.s&



�r�)r�)r�Tr�)#�
__future__rrrYrPrjrfr�r�rarMr�_js_codervr�r�r�r�r�r�rcrr��
_css_styler�r'r�r�r�r�r�r\r�r�r�rrrr#�<module>s�U��������	�
���
���������
fJ
�
Upload File: