python: Make sure help()
doesn't cause hexchat to hang (#2290)
* Make sure `help()` doesn't cause hexchat to hang Replace `pydoc.help` with a copy of `pydoc.Helper` with an empty `StringIO` instead of stdin * Handle BytesIO vs StringIO on 2.7
This commit is contained in:
parent
f7713a6a64
commit
a5a727122b
@ -1,6 +1,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import pydoc
|
||||||
import sys
|
import sys
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import importlib
|
import importlib
|
||||||
@ -8,6 +9,12 @@ import signal
|
|||||||
import site
|
import site
|
||||||
import traceback
|
import traceback
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
from io import BytesIO as HelpEater
|
||||||
|
else:
|
||||||
|
from io import StringIO as HelpEater
|
||||||
|
|
||||||
from _hexchat_embedded import ffi, lib
|
from _hexchat_embedded import ffi, lib
|
||||||
|
|
||||||
if not hasattr(sys, 'argv'):
|
if not hasattr(sys, 'argv'):
|
||||||
@ -57,7 +64,6 @@ class Stdout:
|
|||||||
self.buffer += string
|
self.buffer += string
|
||||||
|
|
||||||
def isatty(self):
|
def isatty(self):
|
||||||
# FIXME: help() locks app despite this?
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -474,6 +480,7 @@ def _on_plugin_init(plugin_name, plugin_desc, plugin_version, arg, libdir):
|
|||||||
hexchat_stdout = Stdout()
|
hexchat_stdout = Stdout()
|
||||||
sys.stdout = hexchat_stdout
|
sys.stdout = hexchat_stdout
|
||||||
sys.stderr = hexchat_stdout
|
sys.stderr = hexchat_stdout
|
||||||
|
pydoc.help = pydoc.Helper(HelpEater(), HelpEater())
|
||||||
|
|
||||||
lib.hexchat_hook_command(lib.ph, b'', 0, lib._on_say_command, ffi.NULL, ffi.NULL)
|
lib.hexchat_hook_command(lib.ph, b'', 0, lib._on_say_command, ffi.NULL, ffi.NULL)
|
||||||
lib.hexchat_hook_command(lib.ph, b'LOAD', 0, lib._on_load_command, ffi.NULL, ffi.NULL)
|
lib.hexchat_hook_command(lib.ph, b'LOAD', 0, lib._on_load_command, ffi.NULL, ffi.NULL)
|
||||||
@ -505,6 +512,7 @@ def _on_plugin_deinit():
|
|||||||
hexchat_stdout = None
|
hexchat_stdout = None
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
sys.stderr = sys.__stderr__
|
sys.stderr = sys.__stderr__
|
||||||
|
pydoc.help = pydoc.Helper()
|
||||||
|
|
||||||
for mod in ('_hexchat', 'hexchat', 'xchat', '_hexchat_embedded'):
|
for mod in ('_hexchat', 'hexchat', 'xchat', '_hexchat_embedded'):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user