Skip to content

Commit

Permalink
[term] Automatically set PWNLIB_NOTERM when running inside Jupyter (#…
Browse files Browse the repository at this point in the history
…1632)

* [term] Automatically set PWNLIB_NOTERM when running inside Jupyter

* [changelog] Update changelog
  • Loading branch information
heapcrash authored Jul 10, 2020
1 parent 48a482d commit f1d8d5b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ The table below shows which release corresponds to each branch, and what date th
- [#1602][1602] Fix bytes handling in ssh tubes
- [#1606][1606] Fix `asm()` and `disasm()` for MSP430, S390
- [#1616][1616] Fix `cyclic` cli for 64 bit integers
- [#1632][1632] Enable usage of Pwntools in jupyter

[1602]: https://github.com/Gallopsled/pwntools/pull/1602
[1606]: https://github.com/Gallopsled/pwntools/pull/1606
[1616]: https://github.com/Gallopsled/pwntools/pull/1616
[1632]: https://github.com/Gallopsled/pwntools/pull/1632

## 4.3.0 (`beta`)

Expand Down
2 changes: 1 addition & 1 deletion pwnlib/term/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def can_init():

# 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

Expand Down
8 changes: 8 additions & 0 deletions pwnlib/term/unix_termcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def get(cap, *args, **kwargs):
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:
Expand Down

0 comments on commit f1d8d5b

Please sign in to comment.