We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Pwntools not working on Notebook (Jupyter and Google Colab)
# Pwntools Issue Template

Thanks for contributing to Pwntools!

When reporting an issue, be sure that you are running the latest released version of pwntools (`pip install --upgrade pwntools`).
After executing `pip install --upgrade pwntools` I got:
```
  File "/usr/local/lib/python3.7/dist-packages/pwnlib/term/term.py", line 167
    def goto((r, c)):
             ^
SyntaxError: invalid syntax
```
So I had to use this installation command: `pip3 install git+https://github.com/arthaud/python3-pwntools.git`

After installing **pwntools** with pip and pip3 I tried to use it on a Jupyter Notebook:


```python
from pwn import *
```


    ---------------------------------------------------------------------------

    AttributeError                            Traceback (most recent call last)

    <ipython-input-4-308ef5371a41> in <module>
    ----> 1 from pwn import *
    

    /usr/local/lib/python3.7/dist-packages/pwn/__init__.py in <module>
          1 # Promote useful stuff to toplevel
    ----> 2 from .toplevel import *
          3 
          4 pwnlib.args.initialize()
          5 pwnlib.log.install_default_handler()


    /usr/local/lib/python3.7/dist-packages/pwn/toplevel.py in <module>
         17 import io
         18 
    ---> 19 import pwnlib
         20 from pwnlib import *
         21 from pwnlib.asm import *


    /usr/local/lib/python3.7/dist-packages/pwnlib/__init__.py in <module>
         35 
         36 for module in __all__:
    ---> 37     importlib.import_module('.%s' % module, 'pwnlib')
    

    /usr/lib/python3.7/importlib/__init__.py in import_module(name, package)
        125                 break
        126             level += 1
    --> 127     return _bootstrap._gcd_import(name[level:], package, level)
        128 
        129 


    /usr/local/lib/python3.7/dist-packages/pwnlib/args.py in <module>
          5 import sys
          6 from .context import context
    ----> 7 from . import term
          8 
          9 term_mode = True


    /usr/local/lib/python3.7/dist-packages/pwnlib/term/__init__.py in <module>
          3 from . import key
          4 from . import keymap
    ----> 5 from . import readline
          6 from . import term
          7 from . import termcap


    /usr/local/lib/python3.7/dist-packages/pwnlib/term/readline.py in <module>
          1 from . import keyconsts as kc
          2 from . import keymap as km
    ----> 3 from . import term
          4 from . import text
          5 


    /usr/local/lib/python3.7/dist-packages/pwnlib/term/term.py in <module>
         28 _graphics_mode = False
         29 
    ---> 30 fd = sys.stdout.buffer
         31 
         32 


    AttributeError: 'OutStream' object has no attribute 'buffer'


I tried this also in Google Colab and with different OS like Ubuntu 16 and Debian 10, and getting the same error.
But if I execute `from pwn import *` in a python2, python3, ipython2 and ipython3 terminal I don't get any error.

Thank you.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pwnlib/term/__init__.py`
Content:
```
1 from __future__ import absolute_import
2 from __future__ import division
3 
4 import sys
5 
6 from pwnlib.term import completer
7 from pwnlib.term import key
8 from pwnlib.term import keymap
9 from pwnlib.term import readline
10 from pwnlib.term import term
11 from pwnlib.term import termcap
12 from pwnlib.term import text
13 
14 # Re-exports (XXX: Are these needed?)
15 output = term.output
16 width =  term.width
17 height = term.height
18 getkey = key.get
19 Keymap = keymap.Keymap
20 
21 #: This is True exactly when we have taken over the terminal using :func:`init`.
22 term_mode = False
23 
24 def can_init():
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':
31         return False
32 
33     if not sys.stdout.isatty():
34         return False
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']:
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():
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:
73         return
74 
75     if not can_init():
76         return
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
89
```

Path: `pwnlib/term/unix_termcap.py`
Content:
```
1 from __future__ import division
2 from __future__ import print_function
3 
4 __all__ = ['get']
5 import curses
6 import os
7 import sys
8 
9 cache = None
10 
11 def get(cap, *args, **kwargs):
12     default = kwargs.pop('default', '')
13 
14     if 'PWNLIB_NOTERM' in os.environ:
15         return ''
16 
17     # Hack for readthedocs.org
18     if 'READTHEDOCS' in os.environ:
19         return ''
20 
21     if kwargs != {}:
22         raise TypeError("get(): No such argument %r" % kwargs.popitem()[0])
23 
24     if cache is None:
25         init()
26     s = cache.get(cap)
27     if not s:
28         s = curses.tigetstr(cap)
29         if s is None:
30             s = curses.tigetnum(cap)
31             if s == -2:
32                 s = curses.tigetflag(cap)
33                 if s == -1:
34                     # default to empty string so tparm doesn't fail
35                     s = ''
36                 else:
37                     s = bool(s)
38         cache[cap] = s
39     # if `s' is not set `curses.tparm' will throw an error if given arguments
40     if args and s:
41         return curses.tparm(s, *args)
42     else:
43         return s
44 
45 def init():
46     global cache
47 
48     if 'PWNLIB_NOTERM' not in os.environ:
49         # Fix for BPython
50         try:
51             curses.setupterm()
52         except curses.error as e:
53             import traceback
54             print('Warning:', ''.join(traceback.format_exception_only(e.__class__, e)), file=sys.stderr)
55 
56     cache = {}
57     # Manually add reset sequence into the cache.
58     # Can't look it up using tigetstr.
59     cache['reset'] = '\x1b[m'
60
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pwnlib/term/__init__.py b/pwnlib/term/__init__.py
--- a/pwnlib/term/__init__.py
+++ b/pwnlib/term/__init__.py
@@ -39,7 +39,7 @@
 
     # Check fancy REPLs
     mods = sys.modules.keys()
-    for repl in ['IPython', 'bpython', 'dreampielib']:
+    for repl in ['IPython', 'bpython', 'dreampielib', 'jupyter_client._version']:
         if repl in mods:
             return False
 
diff --git a/pwnlib/term/unix_termcap.py b/pwnlib/term/unix_termcap.py
--- a/pwnlib/term/unix_termcap.py
+++ b/pwnlib/term/unix_termcap.py
@@ -45,6 +45,14 @@
 def init():
     global cache
 
+    # Detect running under Jupyter
+    try:
+        if get_ipython().__class__.__name__ == 'ZMQInteractiveShell':
+            os.environ['PWNLIB_NOTERM'] = '1'
+            os.environ['JUPYTER_DETECTED'] ='yes'
+    except NameError:
+        pass
+
     if 'PWNLIB_NOTERM' not in os.environ:
         # Fix for BPython
         try:

{"golden_diff": "diff --git a/pwnlib/term/__init__.py b/pwnlib/term/__init__.py\n--- a/pwnlib/term/__init__.py\n+++ b/pwnlib/term/__init__.py\n@@ -39,7 +39,7 @@\n \n     # Check fancy REPLs\n     mods = sys.modules.keys()\n-    for repl in ['IPython', 'bpython', 'dreampielib']:\n+    for repl in ['IPython', 'bpython', 'dreampielib', 'jupyter_client._version']:\n         if repl in mods:\n             return False\n \ndiff --git a/pwnlib/term/unix_termcap.py b/pwnlib/term/unix_termcap.py\n--- a/pwnlib/term/unix_termcap.py\n+++ b/pwnlib/term/unix_termcap.py\n@@ -45,6 +45,14 @@\n def init():\n     global cache\n \n+    # Detect running under Jupyter\n+    try:\n+        if get_ipython().__class__.__name__ == 'ZMQInteractiveShell':\n+            os.environ['PWNLIB_NOTERM'] = '1'\n+            os.environ['JUPYTER_DETECTED'] ='yes'\n+    except NameError:\n+        pass\n+\n     if 'PWNLIB_NOTERM' not in os.environ:\n         # Fix for BPython\n         try:\n", "issue": "Pwntools not working on Notebook (Jupyter and Google Colab)\n# Pwntools Issue Template\r\n\r\nThanks for contributing to Pwntools!\r\n\r\nWhen reporting an issue, be sure that you are running the latest released version of pwntools (`pip install --upgrade pwntools`).\r\nAfter executing `pip install --upgrade pwntools` I got:\r\n```\r\n  File \"/usr/local/lib/python3.7/dist-packages/pwnlib/term/term.py\", line 167\r\n    def goto((r, c)):\r\n             ^\r\nSyntaxError: invalid syntax\r\n```\r\nSo I had to use this installation command: `pip3 install git+https://github.com/arthaud/python3-pwntools.git`\r\n\r\nAfter installing **pwntools** with pip and pip3 I tried to use it on a Jupyter Notebook:\r\n\r\n\r\n```python\r\nfrom pwn import *\r\n```\r\n\r\n\r\n    ---------------------------------------------------------------------------\r\n\r\n    AttributeError                            Traceback (most recent call last)\r\n\r\n    <ipython-input-4-308ef5371a41> in <module>\r\n    ----> 1 from pwn import *\r\n    \r\n\r\n    /usr/local/lib/python3.7/dist-packages/pwn/__init__.py in <module>\r\n          1 # Promote useful stuff to toplevel\r\n    ----> 2 from .toplevel import *\r\n          3 \r\n          4 pwnlib.args.initialize()\r\n          5 pwnlib.log.install_default_handler()\r\n\r\n\r\n    /usr/local/lib/python3.7/dist-packages/pwn/toplevel.py in <module>\r\n         17 import io\r\n         18 \r\n    ---> 19 import pwnlib\r\n         20 from pwnlib import *\r\n         21 from pwnlib.asm import *\r\n\r\n\r\n    /usr/local/lib/python3.7/dist-packages/pwnlib/__init__.py in <module>\r\n         35 \r\n         36 for module in __all__:\r\n    ---> 37     importlib.import_module('.%s' % module, 'pwnlib')\r\n    \r\n\r\n    /usr/lib/python3.7/importlib/__init__.py in import_module(name, package)\r\n        125                 break\r\n        126             level += 1\r\n    --> 127     return _bootstrap._gcd_import(name[level:], package, level)\r\n        128 \r\n        129 \r\n\r\n\r\n    /usr/local/lib/python3.7/dist-packages/pwnlib/args.py in <module>\r\n          5 import sys\r\n          6 from .context import context\r\n    ----> 7 from . import term\r\n          8 \r\n          9 term_mode = True\r\n\r\n\r\n    /usr/local/lib/python3.7/dist-packages/pwnlib/term/__init__.py in <module>\r\n          3 from . import key\r\n          4 from . import keymap\r\n    ----> 5 from . import readline\r\n          6 from . import term\r\n          7 from . import termcap\r\n\r\n\r\n    /usr/local/lib/python3.7/dist-packages/pwnlib/term/readline.py in <module>\r\n          1 from . import keyconsts as kc\r\n          2 from . import keymap as km\r\n    ----> 3 from . import term\r\n          4 from . import text\r\n          5 \r\n\r\n\r\n    /usr/local/lib/python3.7/dist-packages/pwnlib/term/term.py in <module>\r\n         28 _graphics_mode = False\r\n         29 \r\n    ---> 30 fd = sys.stdout.buffer\r\n         31 \r\n         32 \r\n\r\n\r\n    AttributeError: 'OutStream' object has no attribute 'buffer'\r\n\r\n\r\nI tried this also in Google Colab and with different OS like Ubuntu 16 and Debian 10, and getting the same error.\r\nBut if I execute `from pwn import *` in a python2, python3, ipython2 and ipython3 terminal I don't get any error.\r\n\r\nThank you.\r\n\n", "before_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import division\n\nimport sys\n\nfrom pwnlib.term import completer\nfrom pwnlib.term import key\nfrom pwnlib.term import keymap\nfrom pwnlib.term import readline\nfrom pwnlib.term import term\nfrom pwnlib.term import termcap\nfrom pwnlib.term import text\n\n# Re-exports (XXX: Are these needed?)\noutput = term.output\nwidth =  term.width\nheight = term.height\ngetkey = key.get\nKeymap = keymap.Keymap\n\n#: This is True exactly when we have taken over the terminal using :func:`init`.\nterm_mode = False\n\ndef can_init():\n    \"\"\"This function returns True iff stderr is a TTY and we are not inside a\n    REPL.  Iff this function returns `True`, a call to :meth:`init` will let\n    ``pwnlib`` manage the terminal.\n    \"\"\"\n\n    if sys.platform == 'win32':\n        return False\n\n    if not sys.stdout.isatty():\n        return False\n\n    # Check for python -i\n    if sys.flags.interactive:\n        return False\n\n    # Check fancy REPLs\n    mods = sys.modules.keys()\n    for repl in ['IPython', 'bpython', 'dreampielib']:\n        if repl in mods:\n            return False\n\n    # The standard python REPL will have co_filename == '<stdin>' for some\n    # frame. We raise an exception to set sys.exc_info so we can unwind the call\n    # stack.\n    try:\n        raise BaseException\n    except BaseException:\n        frame = sys.exc_info()[2].tb_frame\n\n    while frame:\n        if frame.f_code.co_filename == '<stdin>':\n            return False\n        frame = frame.f_back\n\n    return True\n\n\ndef init():\n    \"\"\"Calling this function will take over the terminal (iff :func:`can_init`\n    returns True) until the current python interpreter is closed.\n\n    It is on our TODO, to create a function to \"give back\" the terminal without\n    closing the interpreter.\n    \"\"\"\n\n    global term_mode\n\n    if term_mode:\n        return\n\n    if not can_init():\n        return\n\n    term.init()\n    def update_geometry():\n        global height, width\n        height = term.height\n        width = term.width\n    update_geometry()\n    term.on_winch.append(update_geometry)\n    readline.init()\n\n    term_mode = True\n    text.num_colors = termcap.get('colors', default = 8) or 8\n", "path": "pwnlib/term/__init__.py"}, {"content": "from __future__ import division\nfrom __future__ import print_function\n\n__all__ = ['get']\nimport curses\nimport os\nimport sys\n\ncache = None\n\ndef get(cap, *args, **kwargs):\n    default = kwargs.pop('default', '')\n\n    if 'PWNLIB_NOTERM' in os.environ:\n        return ''\n\n    # Hack for readthedocs.org\n    if 'READTHEDOCS' in os.environ:\n        return ''\n\n    if kwargs != {}:\n        raise TypeError(\"get(): No such argument %r\" % kwargs.popitem()[0])\n\n    if cache is None:\n        init()\n    s = cache.get(cap)\n    if not s:\n        s = curses.tigetstr(cap)\n        if s is None:\n            s = curses.tigetnum(cap)\n            if s == -2:\n                s = curses.tigetflag(cap)\n                if s == -1:\n                    # default to empty string so tparm doesn't fail\n                    s = ''\n                else:\n                    s = bool(s)\n        cache[cap] = s\n    # if `s' is not set `curses.tparm' will throw an error if given arguments\n    if args and s:\n        return curses.tparm(s, *args)\n    else:\n        return s\n\ndef init():\n    global cache\n\n    if 'PWNLIB_NOTERM' not in os.environ:\n        # Fix for BPython\n        try:\n            curses.setupterm()\n        except curses.error as e:\n            import traceback\n            print('Warning:', ''.join(traceback.format_exception_only(e.__class__, e)), file=sys.stderr)\n\n    cache = {}\n    # Manually add reset sequence into the cache.\n    # Can't look it up using tigetstr.\n    cache['reset'] = '\\x1b[m'\n", "path": "pwnlib/term/unix_termcap.py"}], "after_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import division\n\nimport sys\n\nfrom pwnlib.term import completer\nfrom pwnlib.term import key\nfrom pwnlib.term import keymap\nfrom pwnlib.term import readline\nfrom pwnlib.term import term\nfrom pwnlib.term import termcap\nfrom pwnlib.term import text\n\n# Re-exports (XXX: Are these needed?)\noutput = term.output\nwidth =  term.width\nheight = term.height\ngetkey = key.get\nKeymap = keymap.Keymap\n\n#: This is True exactly when we have taken over the terminal using :func:`init`.\nterm_mode = False\n\ndef can_init():\n    \"\"\"This function returns True iff stderr is a TTY and we are not inside a\n    REPL.  Iff this function returns `True`, a call to :meth:`init` will let\n    ``pwnlib`` manage the terminal.\n    \"\"\"\n\n    if sys.platform == 'win32':\n        return False\n\n    if not sys.stdout.isatty():\n        return False\n\n    # Check for python -i\n    if sys.flags.interactive:\n        return False\n\n    # Check fancy REPLs\n    mods = sys.modules.keys()\n    for repl in ['IPython', 'bpython', 'dreampielib', 'jupyter_client._version']:\n        if repl in mods:\n            return False\n\n    # The standard python REPL will have co_filename == '<stdin>' for some\n    # frame. We raise an exception to set sys.exc_info so we can unwind the call\n    # stack.\n    try:\n        raise BaseException\n    except BaseException:\n        frame = sys.exc_info()[2].tb_frame\n\n    while frame:\n        if frame.f_code.co_filename == '<stdin>':\n            return False\n        frame = frame.f_back\n\n    return True\n\n\ndef init():\n    \"\"\"Calling this function will take over the terminal (iff :func:`can_init`\n    returns True) until the current python interpreter is closed.\n\n    It is on our TODO, to create a function to \"give back\" the terminal without\n    closing the interpreter.\n    \"\"\"\n\n    global term_mode\n\n    if term_mode:\n        return\n\n    if not can_init():\n        return\n\n    term.init()\n    def update_geometry():\n        global height, width\n        height = term.height\n        width = term.width\n    update_geometry()\n    term.on_winch.append(update_geometry)\n    readline.init()\n\n    term_mode = True\n    text.num_colors = termcap.get('colors', default = 8) or 8\n", "path": "pwnlib/term/__init__.py"}, {"content": "from __future__ import division\nfrom __future__ import print_function\n\n__all__ = ['get']\nimport curses\nimport os\nimport sys\n\ncache = None\n\ndef get(cap, *args, **kwargs):\n    default = kwargs.pop('default', '')\n\n    if 'PWNLIB_NOTERM' in os.environ:\n        return ''\n\n    # Hack for readthedocs.org\n    if 'READTHEDOCS' in os.environ:\n        return ''\n\n    if kwargs != {}:\n        raise TypeError(\"get(): No such argument %r\" % kwargs.popitem()[0])\n\n    if cache is None:\n        init()\n    s = cache.get(cap)\n    if not s:\n        s = curses.tigetstr(cap)\n        if s is None:\n            s = curses.tigetnum(cap)\n            if s == -2:\n                s = curses.tigetflag(cap)\n                if s == -1:\n                    # default to empty string so tparm doesn't fail\n                    s = ''\n                else:\n                    s = bool(s)\n        cache[cap] = s\n    # if `s' is not set `curses.tparm' will throw an error if given arguments\n    if args and s:\n        return curses.tparm(s, *args)\n    else:\n        return s\n\ndef init():\n    global cache\n\n    # Detect running under Jupyter\n    try:\n        if get_ipython().__class__.__name__ == 'ZMQInteractiveShell':\n            os.environ['PWNLIB_NOTERM'] = '1'\n            os.environ['JUPYTER_DETECTED'] ='yes'\n    except NameError:\n        pass\n\n    if 'PWNLIB_NOTERM' not in os.environ:\n        # Fix for BPython\n        try:\n            curses.setupterm()\n        except curses.error as e:\n            import traceback\n            print('Warning:', ''.join(traceback.format_exception_only(e.__class__, e)), file=sys.stderr)\n\n    cache = {}\n    # Manually add reset sequence into the cache.\n    # Can't look it up using tigetstr.\n    cache['reset'] = '\\x1b[m'\n", "path": "pwnlib/term/unix_termcap.py"}]}