• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Gallopsled / pwntools / 5500918732

pending completion
5500918732

Pull #2221

github-actions

web-flow
Merge 80334e8e4 into f1d5afe32
Pull Request #2221: Add shellcraft.sleep template wrapping SYS_nanosleep

3702 of 6659 branches covered (55.59%)

11579 of 16977 relevant lines covered (68.2%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

41.18
/pwnlib/term/__init__.py
1
from __future__ import absolute_import
1✔
2
from __future__ import division
1✔
3

4
import sys
1✔
5

6
from pwnlib.term import completer
1✔
7
from pwnlib.term import key
1✔
8
from pwnlib.term import keymap
1✔
9
from pwnlib.term import readline
1✔
10
from pwnlib.term import term
1✔
11
from pwnlib.term import termcap
1✔
12
from pwnlib.term import text
1✔
13

14
# Re-exports (XXX: Are these needed?)
15
output = term.output
1✔
16
width =  term.width
1✔
17
height = term.height
1✔
18
getkey = key.get
1✔
19
Keymap = keymap.Keymap
1✔
20

21
#: This is True exactly when we have taken over the terminal using :func:`init`.
22
term_mode = False
1✔
23

24
def can_init():
1✔
25
    """This function returns True iff stderr is a TTY and we are not inside a
26
    REPL.  Iff this function returns `True`, a call to :meth:`init` will let
27
    ``pwnlib`` manage the terminal.
28
    """
29

30
    if sys.platform == 'win32':
1!
31
        return False
×
32

33
    if not sys.stdout.isatty():
1!
34
        return False
1✔
35

36
    # Check for python -i
37
    if sys.flags.interactive:
×
38
        return False
×
39

40
    # Check fancy REPLs
41
    mods = sys.modules.keys()
×
42
    for repl in ['IPython', 'bpython', 'dreampielib', 'jupyter_client._version']:
×
43
        if repl in mods:
×
44
            return False
×
45

46
    # The standard python REPL will have co_filename == '<stdin>' for some
47
    # frame. We raise an exception to set sys.exc_info so we can unwind the call
48
    # stack.
49
    try:
×
50
        raise BaseException
×
51
    except BaseException:
×
52
        frame = sys.exc_info()[2].tb_frame
×
53

54
    while frame:
×
55
        if frame.f_code.co_filename == '<stdin>':
×
56
            return False
×
57
        frame = frame.f_back
×
58

59
    return True
×
60

61

62
def init():
1✔
63
    """Calling this function will take over the terminal (iff :func:`can_init`
64
    returns True) until the current python interpreter is closed.
65

66
    It is on our TODO, to create a function to "give back" the terminal without
67
    closing the interpreter.
68
    """
69

70
    global term_mode
71

72
    if term_mode:
1!
73
        return
×
74

75
    if not can_init():
1!
76
        return
1✔
77

78
    term.init()
×
79
    def update_geometry():
×
80
        global height, width
81
        height = term.height
×
82
        width = term.width
×
83
    update_geometry()
×
84
    term.on_winch.append(update_geometry)
×
85
    readline.init()
×
86

87
    term_mode = True
×
88
    text.num_colors = termcap.get('colors', default = 8) or 8
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc