prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Bpython
  Hi,
  
  Unfortunately pwntools doesn't seem to work with bpython 0.12 in conjunction of python 2.7.9.
  
  from pwn import *
  
  results in:
  
  Traceback (most recent call last):
    File "<input>", line 1, in <module>
    File "/usr/local/lib/python2.7/dist-packages/pwn/**init**.py", line 2, in <module>
      from .toplevel import *
    File "/usr/local/lib/python2.7/dist-packages/pwn/toplevel.py", line 2, in <module>
      from pwnlib                  import *
    File "/usr/local/lib/python2.7/dist-packages/pwnlib/**init**.py", line 10, in <module>
      from . import \
    File "/usr/local/lib/python2.7/dist-packages/pwnlib/asm.py", line 45, in <module>
      from . import log
    File "/usr/local/lib/python2.7/dist-packages/pwnlib/log.py", line 69, in <module>
      from .term      import spinners, text
    File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/**init**.py", line 1, in <module>
      from . import key, readline, text, termcap, keymap, term
    File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/readline.py", line 2, in <module>
      from . import term, text
    File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/text.py", line 111, in <module>
      sys.modules[**name**] = Module()
    File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/text.py", line 22, in **init**
      self.num_colors = termcap.get('colors', default = 8)
    File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/termcap.py", line 15, in get
      init()
    File "/usr/local/lib/python2.7/dist-packages/pwnlib/term/termcap.py", line 39, in init
      curses.setupterm()
  TypeError: argument must be an int, or have a fileno() method.
  
  
  --- 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/termcap.py`
  Content:
  ```
  1 __all__ = ['get']
  2 import os, curses
  3 
  4 cache = None
  5 def get(cap, *args, **kwargs):
  6     default = kwargs.pop('default', '')
  7 
  8     if 'PWNLIB_NOTERM' in os.environ:
  9         return ''
  10 
  11     if kwargs != {}:
  12         raise TypeError("get(): No such argument %r" % kwargs.popitem()[0])
  13 
  14     if cache == None:
  15         init()
  16     s = cache.get(cap)
  17     if not s:
  18         s = curses.tigetstr(cap)
  19         if s == None:
  20             s = curses.tigetnum(cap)
  21             if s == -2:
  22                 s = curses.tigetflag(cap)
  23                 if s == -1:
  24                     # default to empty string so tparm doesn't fail
  25                     s = ''
  26                 else:
  27                     s = bool(s)
  28         cache[cap] = s
  29     # if `s' is not set `curses.tparm' will throw an error if given arguments
  30     if args and s:
  31         return curses.tparm(s, *args)
  32     else:
  33         return s
  34 
  35 def init():
  36     global cache
  37 
  38     if 'PWNLIB_NOTERM' not in os.environ:
  39         curses.setupterm()
  40 
  41     cache = {}
  42
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/pwnlib/term/termcap.py b/pwnlib/term/termcap.py
  --- a/pwnlib/term/termcap.py
  +++ b/pwnlib/term/termcap.py
  @@ -36,6 +36,10 @@
       global cache
   
       if 'PWNLIB_NOTERM' not in os.environ:
  -        curses.setupterm()
  +        # Fix for BPython
  +        try:
  +            curses.setupterm()
  +        except:
  +            pass
   
       cache = {}
  
verification_info: {"golden_diff": "diff --git a/pwnlib/term/termcap.py b/pwnlib/term/termcap.py\n--- a/pwnlib/term/termcap.py\n+++ b/pwnlib/term/termcap.py\n@@ -36,6 +36,10 @@\n     global cache\n \n     if 'PWNLIB_NOTERM' not in os.environ:\n-        curses.setupterm()\n+        # Fix for BPython\n+        try:\n+            curses.setupterm()\n+        except:\n+            pass\n \n     cache = {}\n", "issue": "Bpython\nHi,\n\nUnfortunately pwntools doesn't seem to work with bpython 0.12 in conjunction of python 2.7.9.\n\nfrom pwn import *\n\nresults in:\n\nTraceback (most recent call last):\n  File \"<input>\", line 1, in <module>\n  File \"/usr/local/lib/python2.7/dist-packages/pwn/**init**.py\", line 2, in <module>\n    from .toplevel import *\n  File \"/usr/local/lib/python2.7/dist-packages/pwn/toplevel.py\", line 2, in <module>\n    from pwnlib                  import *\n  File \"/usr/local/lib/python2.7/dist-packages/pwnlib/**init**.py\", line 10, in <module>\n    from . import \\\n  File \"/usr/local/lib/python2.7/dist-packages/pwnlib/asm.py\", line 45, in <module>\n    from . import log\n  File \"/usr/local/lib/python2.7/dist-packages/pwnlib/log.py\", line 69, in <module>\n    from .term      import spinners, text\n  File \"/usr/local/lib/python2.7/dist-packages/pwnlib/term/**init**.py\", line 1, in <module>\n    from . import key, readline, text, termcap, keymap, term\n  File \"/usr/local/lib/python2.7/dist-packages/pwnlib/term/readline.py\", line 2, in <module>\n    from . import term, text\n  File \"/usr/local/lib/python2.7/dist-packages/pwnlib/term/text.py\", line 111, in <module>\n    sys.modules[**name**] = Module()\n  File \"/usr/local/lib/python2.7/dist-packages/pwnlib/term/text.py\", line 22, in **init**\n    self.num_colors = termcap.get('colors', default = 8)\n  File \"/usr/local/lib/python2.7/dist-packages/pwnlib/term/termcap.py\", line 15, in get\n    init()\n  File \"/usr/local/lib/python2.7/dist-packages/pwnlib/term/termcap.py\", line 39, in init\n    curses.setupterm()\nTypeError: argument must be an int, or have a fileno() method.\n\n", "before_files": [{"content": "__all__ = ['get']\nimport os, curses\n\ncache = None\ndef get(cap, *args, **kwargs):\n    default = kwargs.pop('default', '')\n\n    if 'PWNLIB_NOTERM' in os.environ:\n        return ''\n\n    if kwargs != {}:\n        raise TypeError(\"get(): No such argument %r\" % kwargs.popitem()[0])\n\n    if cache == None:\n        init()\n    s = cache.get(cap)\n    if not s:\n        s = curses.tigetstr(cap)\n        if s == 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        curses.setupterm()\n\n    cache = {}\n", "path": "pwnlib/term/termcap.py"}], "after_files": [{"content": "__all__ = ['get']\nimport os, curses\n\ncache = None\ndef get(cap, *args, **kwargs):\n    default = kwargs.pop('default', '')\n\n    if 'PWNLIB_NOTERM' in os.environ:\n        return ''\n\n    if kwargs != {}:\n        raise TypeError(\"get(): No such argument %r\" % kwargs.popitem()[0])\n\n    if cache == None:\n        init()\n    s = cache.get(cap)\n    if not s:\n        s = curses.tigetstr(cap)\n        if s == 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:\n            pass\n\n    cache = {}\n", "path": "pwnlib/term/termcap.py"}]}