Skip to content

Commit 58a25d6

Browse files
committed
add fake termios
1 parent 4c47901 commit 58a25d6

File tree

2 files changed

+376
-0
lines changed

2 files changed

+376
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ private static final String[] initializeCoreFiles() {
221221
"_thread",
222222
"ctypes",
223223
"zlib",
224+
"termios",
224225
"zipimport"));
225226

226227
return coreFiles.toArray(new String[coreFiles.size()]);
Lines changed: 375 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,375 @@
1+
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
41+
__doc__ = """
42+
This module provides an interface to the Posix calls for tty I/O control.
43+
For a complete description of these calls, see the Posix or Unix manual
44+
pages. It is only available for those Unix versions that support Posix
45+
termios style tty I/O control.
46+
47+
All functions in this module take a file descriptor fd as their first
48+
argument. This can be an integer file descriptor, such as returned by
49+
sys.stdin.fileno(), or a file object, such as sys.stdin itself.
50+
"""
51+
52+
53+
def tcdrain(fd):
54+
"""
55+
tcdrain(fd) -> None
56+
57+
Wait until all output written to file descriptor fd has been transmitted.
58+
"""
59+
60+
61+
def tcflow(fd, action):
62+
"""
63+
tcflow(fd, action) -> None
64+
65+
Suspend or resume input or output on file descriptor fd.
66+
The action argument can be termios.TCOOFF to suspend output,
67+
termios.TCOON to restart output, termios.TCIOFF to suspend input,
68+
or termios.TCION to restart input.
69+
"""
70+
71+
72+
def tcflush(fd, queue):
73+
"""
74+
tcflush(fd, queue) -> None
75+
76+
Discard queued data on file descriptor fd.
77+
The queue selector specifies which queue: termios.TCIFLUSH for the input
78+
queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for
79+
both queues.
80+
"""
81+
82+
83+
def tcgetattr(fd):
84+
"""
85+
tcgetattr(fd) -> list_of_attrs
86+
87+
Get the tty attributes for file descriptor fd, as follows:
88+
[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list
89+
of the tty special characters (each a string of length 1, except the items
90+
with indices VMIN and VTIME, which are integers when these fields are
91+
defined). The interpretation of the flags and the speeds as well as the
92+
indexing in the cc array must be done using the symbolic constants defined
93+
in this module.
94+
"""
95+
# Values taken from CPython 3.6.5 for the standard streams on Linux
96+
return [
97+
17664,
98+
5,
99+
191,
100+
35387,
101+
15,
102+
15,
103+
[b'\x03', b'\x1c', b'\x7f', b'\x15',
104+
b'\x04', b'\x00', b'\x01', b'\x00', b'\x11', b'\x13', b'\x1a',
105+
b'\x00', b'\x12', b'\x0f', b'\x17', b'\x16', b'\x00', b'\x00',
106+
b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00',
107+
b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00']
108+
]
109+
110+
111+
def tcsendbreak(fd, duration):
112+
"""
113+
tcsendbreak(fd, duration) -> None
114+
115+
Send a break on file descriptor fd.
116+
A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration
117+
has a system dependent meaning.
118+
"""
119+
120+
121+
def tcsetattr(fd, when, attributes):
122+
"""
123+
tcsetattr(fd, when, attributes) -> None
124+
125+
Set the tty attributes for file descriptor fd.
126+
The attributes to be set are taken from the attributes argument, which
127+
is a list like the one returned by tcgetattr(). The when argument
128+
determines when the attributes are changed: termios.TCSANOW to
129+
change immediately, termios.TCSADRAIN to change after transmitting all
130+
queued output, or termios.TCSAFLUSH to change after transmitting all
131+
queued output and discarding all queued input.
132+
"""
133+
134+
135+
# Note: copied from CPython 3.6.5
136+
B0 = 0
137+
B1000000 = 4104
138+
B110 = 3
139+
B115200 = 4098
140+
B1152000 = 4105
141+
B1200 = 9
142+
B134 = 4
143+
B150 = 5
144+
B1500000 = 4106
145+
B1800 = 10
146+
B19200 = 14
147+
B200 = 6
148+
B2000000 = 4107
149+
B230400 = 4099
150+
B2400 = 11
151+
B2500000 = 4108
152+
B300 = 7
153+
B3000000 = 4109
154+
B3500000 = 4110
155+
B38400 = 15
156+
B4000000 = 4111
157+
B460800 = 4100
158+
B4800 = 12
159+
B50 = 1
160+
B500000 = 4101
161+
B57600 = 4097
162+
B576000 = 4102
163+
B600 = 8
164+
B75 = 2
165+
B921600 = 4103
166+
B9600 = 13
167+
BRKINT = 2
168+
BS0 = 0
169+
BS1 = 8192
170+
BSDLY = 8192
171+
CBAUD = 4111
172+
CBAUDEX = 4096
173+
CDSUSP = 25
174+
CEOF = 4
175+
CEOL = 0
176+
CEOT = 4
177+
CERASE = 127
178+
CFLUSH = 15
179+
CIBAUD = 269418496
180+
CINTR = 3
181+
CKILL = 21
182+
CLNEXT = 22
183+
CLOCAL = 2048
184+
CQUIT = 28
185+
CR0 = 0
186+
CR1 = 512
187+
CR2 = 1024
188+
CR3 = 1536
189+
CRDLY = 1536
190+
CREAD = 128
191+
CRPRNT = 18
192+
CRTSCTS = 2147483648
193+
CS5 = 0
194+
CS6 = 16
195+
CS7 = 32
196+
CS8 = 48
197+
CSIZE = 48
198+
CSTART = 17
199+
CSTOP = 19
200+
CSTOPB = 64
201+
CSUSP = 26
202+
CWERASE = 23
203+
ECHO = 8
204+
ECHOCTL = 512
205+
ECHOE = 16
206+
ECHOK = 32
207+
ECHOKE = 2048
208+
ECHONL = 64
209+
ECHOPRT = 1024
210+
EXTA = 14
211+
EXTB = 15
212+
FF0 = 0
213+
FF1 = 32768
214+
FFDLY = 32768
215+
FIOASYNC = 21586
216+
FIOCLEX = 21585
217+
FIONBIO = 21537
218+
FIONCLEX = 21584
219+
FIONREAD = 21531
220+
FLUSHO = 4096
221+
HUPCL = 1024
222+
ICANON = 2
223+
ICRNL = 256
224+
IEXTEN = 32768
225+
IGNBRK = 1
226+
IGNCR = 128
227+
IGNPAR = 4
228+
IMAXBEL = 8192
229+
INLCR = 64
230+
INPCK = 16
231+
IOCSIZE_MASK = 1073676288
232+
IOCSIZE_SHIFT = 16
233+
ISIG = 1
234+
ISTRIP = 32
235+
IUCLC = 512
236+
IXANY = 2048
237+
IXOFF = 4096
238+
IXON = 1024
239+
NCC = 8
240+
NCCS = 32
241+
NL0 = 0
242+
NL1 = 256
243+
NLDLY = 256
244+
NOFLSH = 128
245+
N_MOUSE = 2
246+
N_PPP = 3
247+
N_SLIP = 1
248+
N_STRIP = 4
249+
N_TTY = 0
250+
OCRNL = 8
251+
OFDEL = 128
252+
OFILL = 64
253+
OLCUC = 2
254+
ONLCR = 4
255+
ONLRET = 32
256+
ONOCR = 16
257+
OPOST = 1
258+
PARENB = 256
259+
PARMRK = 8
260+
PARODD = 512
261+
PENDIN = 16384
262+
TAB0 = 0
263+
TAB1 = 2048
264+
TAB2 = 4096
265+
TAB3 = 6144
266+
TABDLY = 6144
267+
TCFLSH = 21515
268+
TCGETA = 21509
269+
TCGETS = 21505
270+
TCIFLUSH = 0
271+
TCIOFF = 2
272+
TCIOFLUSH = 2
273+
TCION = 3
274+
TCOFLUSH = 1
275+
TCOOFF = 0
276+
TCOON = 1
277+
TCSADRAIN = 1
278+
TCSAFLUSH = 2
279+
TCSANOW = 0
280+
TCSBRK = 21513
281+
TCSBRKP = 21541
282+
TCSETA = 21510
283+
TCSETAF = 21512
284+
TCSETAW = 21511
285+
TCSETS = 21506
286+
TCSETSF = 21508
287+
TCSETSW = 21507
288+
TCXONC = 21514
289+
TIOCCONS = 21533
290+
TIOCEXCL = 21516
291+
TIOCGETD = 21540
292+
TIOCGICOUNT = 21597
293+
TIOCGLCKTRMIOS = 21590
294+
TIOCGPGRP = 21519
295+
TIOCGSERIAL = 21534
296+
TIOCGSOFTCAR = 21529
297+
TIOCGWINSZ = 21523
298+
TIOCINQ = 21531
299+
TIOCLINUX = 21532
300+
TIOCMBIC = 21527
301+
TIOCMBIS = 21526
302+
TIOCMGET = 21525
303+
TIOCMIWAIT = 21596
304+
TIOCMSET = 21528
305+
TIOCM_CAR = 64
306+
TIOCM_CD = 64
307+
TIOCM_CTS = 32
308+
TIOCM_DSR = 256
309+
TIOCM_DTR = 2
310+
TIOCM_LE = 1
311+
TIOCM_RI = 128
312+
TIOCM_RNG = 128
313+
TIOCM_RTS = 4
314+
TIOCM_SR = 16
315+
TIOCM_ST = 8
316+
TIOCNOTTY = 21538
317+
TIOCNXCL = 21517
318+
TIOCOUTQ = 21521
319+
TIOCPKT = 21536
320+
TIOCPKT_DATA = 0
321+
TIOCPKT_DOSTOP = 32
322+
TIOCPKT_FLUSHREAD = 1
323+
TIOCPKT_FLUSHWRITE = 2
324+
TIOCPKT_NOSTOP = 16
325+
TIOCPKT_START = 8
326+
TIOCPKT_STOP = 4
327+
TIOCSCTTY = 21518
328+
TIOCSERCONFIG = 21587
329+
TIOCSERGETLSR = 21593
330+
TIOCSERGETMULTI = 21594
331+
TIOCSERGSTRUCT = 21592
332+
TIOCSERGWILD = 21588
333+
TIOCSERSETMULTI = 21595
334+
TIOCSERSWILD = 21589
335+
TIOCSER_TEMT = 1
336+
TIOCSETD = 21539
337+
TIOCSLCKTRMIOS = 21591
338+
TIOCSPGRP = 21520
339+
TIOCSSERIAL = 21535
340+
TIOCSSOFTCAR = 21530
341+
TIOCSTI = 21522
342+
TIOCSWINSZ = 21524
343+
TOSTOP = 256
344+
VDISCARD = 13
345+
VEOF = 4
346+
VEOL = 11
347+
VEOL2 = 16
348+
VERASE = 2
349+
VINTR = 0
350+
VKILL = 3
351+
VLNEXT = 15
352+
VMIN = 6
353+
VQUIT = 1
354+
VREPRINT = 12
355+
VSTART = 8
356+
VSTOP = 9
357+
VSUSP = 10
358+
VSWTC = 7
359+
VSWTCH = 7
360+
VT0 = 0
361+
VT1 = 16384
362+
VTDLY = 16384
363+
VTIME = 5
364+
VWERASE = 14
365+
XCASE = 4
366+
XTABS = 6144
367+
368+
369+
def init_module():
370+
import sys
371+
sys.modules["termios"] = type(sys)("termios")
372+
sys.modules["termios"].__dict__.update(globals())
373+
374+
375+
init_module()

0 commit comments

Comments
 (0)