forked from tinode/chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtn_globals.py
67 lines (54 loc) · 1.66 KB
/
tn_globals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Global objects for Tinode command line client."""
# To make print() compatible between p2 and p3
from __future__ import print_function
import sys
from collections import deque
try:
import Queue as queue
except ImportError:
import queue
# Dictionary wich contains lambdas to be executed when server {ctrl} response is received.
OnCompletion = {}
# Outstanding request for a synchronous message.
WaitingFor = None
# Last obtained authentication token
AuthToken = ''
# IO queues and a thread for asynchronous input/output
#InputQueue = queue.Queue()
InputQueue = deque()
OutputQueue = queue.Queue()
InputThread = None
# Detect if the tn-cli is running interactively or being piped.
IsInteractive = sys.stdin.isatty()
Prompt = None
# Default values for user and topic
DefaultUser = None
DefaultTopic = None
# Variables: results of command execution
Variables = {}
# Print prompts in interactive mode only.
def printout(*args):
if IsInteractive:
print(*args)
def printerr(*args):
text = ""
for a in args:
text = text + str(a) + " "
# Strip just the spaces here, don't strip the newline or tabs.
text = text.strip(" ")
if text:
sys.stderr.write(text + "\n")
# Support for asynchronous input-output to/from stdin/stdout
# Stdout asynchronously writes to sys.stdout
def stdout(*args):
text = ""
for a in args:
text = text + str(a) + " "
# Strip just the spaces here, don't strip the newline or tabs.
text = text.strip(" ")
if text:
OutputQueue.put(text)
# Stdoutln asynchronously writes to sys.stdout and adds a new line to input.
def stdoutln(*args):
args = args + ("\n",)
stdout(*args)