mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-21 13:10:19 +00:00
Cleaned up unneeded inline comments in plugins/python/python.py while keeping runtime behavior unchanged (comment-only cleanup around version declaration, compile helpers, wordlist/timer handling, and autoload path handling).
This commit is contained in:
@@ -19,7 +19,7 @@ else:
|
|||||||
if not hasattr(sys, 'argv'):
|
if not hasattr(sys, 'argv'):
|
||||||
sys.argv = ['<zoitechat>']
|
sys.argv = ['<zoitechat>']
|
||||||
|
|
||||||
VERSION = b'2.18.0~pre2' # Sync with zoitechat.__version__
|
VERSION = b'2.18.0~pre2'
|
||||||
PLUGIN_NAME = ffi.new('char[]', b'Python')
|
PLUGIN_NAME = ffi.new('char[]', b'Python')
|
||||||
PLUGIN_DESC = ffi.new('char[]', b'Python %d.%d scripting interface' % (sys.version_info[0], sys.version_info[1]))
|
PLUGIN_DESC = ffi.new('char[]', b'Python %d.%d scripting interface' % (sys.version_info[0], sys.version_info[1]))
|
||||||
PLUGIN_VERSION = ffi.new('char[]', VERSION)
|
PLUGIN_VERSION = ffi.new('char[]', VERSION)
|
||||||
@@ -105,8 +105,6 @@ if sys.version_info[0] == 2:
|
|||||||
return compile(string, '<string>', 'eval', dont_inherit=True)
|
return compile(string, '<string>', 'eval', dont_inherit=True)
|
||||||
|
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
# For some reason `print` is invalid for eval
|
|
||||||
# This will hide any return value though
|
|
||||||
return compile(string, '<string>', 'exec', dont_inherit=True)
|
return compile(string, '<string>', 'exec', dont_inherit=True)
|
||||||
else:
|
else:
|
||||||
def compile_file(data, filename):
|
def compile_file(data, filename):
|
||||||
@@ -114,7 +112,6 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
def compile_line(string):
|
def compile_line(string):
|
||||||
# newline appended to solve unexpected EOF issues
|
|
||||||
return compile(string + '\n', '<string>', 'single', optimize=2, dont_inherit=True)
|
return compile(string + '\n', '<string>', 'single', optimize=2, dont_inherit=True)
|
||||||
|
|
||||||
|
|
||||||
@@ -199,8 +196,6 @@ else:
|
|||||||
return string.decode()
|
return string.decode()
|
||||||
|
|
||||||
|
|
||||||
# There can be empty entries between non-empty ones so find the actual last value
|
|
||||||
|
|
||||||
def _cstr(ptr):
|
def _cstr(ptr):
|
||||||
"""Safely convert a C char* (possibly NULL) to bytes."""
|
"""Safely convert a C char* (possibly NULL) to bytes."""
|
||||||
if ptr == ffi.NULL:
|
if ptr == ffi.NULL:
|
||||||
@@ -211,7 +206,6 @@ def _cstr(ptr):
|
|||||||
return b''
|
return b''
|
||||||
|
|
||||||
def wordlist_len(words):
|
def wordlist_len(words):
|
||||||
# ZoiteChat passes a fixed-size array (typically 32) where unused entries may be NULL.
|
|
||||||
for i in range(31, 0, -1):
|
for i in range(31, 0, -1):
|
||||||
if _cstr(words[i]):
|
if _cstr(words[i]):
|
||||||
return i
|
return i
|
||||||
@@ -298,12 +292,8 @@ def _on_timer_hook(userdata):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Avoid calling zoitechat_unhook twice if unnecessary
|
|
||||||
hook.is_unload = True
|
hook.is_unload = True
|
||||||
except ReferenceError:
|
except ReferenceError:
|
||||||
# hook is a weak reference, it might have been destroyed by the callback
|
|
||||||
# in which case it has already been removed from hook.plugin.hooks and
|
|
||||||
# we wouldn't be able to test it with h == hook anyway.
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
for h in hook.plugin.hooks:
|
for h in hook.plugin.hooks:
|
||||||
@@ -337,11 +327,9 @@ def _on_say_command(word, word_eol, userdata):
|
|||||||
if not python:
|
if not python:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# Don’t let exceptions here swallow core commands or wedge the UI.
|
|
||||||
try:
|
try:
|
||||||
exec_in_interp(python)
|
exec_in_interp(python)
|
||||||
except Exception:
|
except Exception:
|
||||||
# Best effort: surface the traceback in the python tab.
|
|
||||||
exc = traceback.format_exc().encode('utf-8', errors='replace')
|
exc = traceback.format_exc().encode('utf-8', errors='replace')
|
||||||
lib.zoitechat_print(lib.ph, exc)
|
lib.zoitechat_print(lib.ph, exc)
|
||||||
return 1
|
return 1
|
||||||
@@ -396,11 +384,10 @@ def autoload():
|
|||||||
configdir = __decode(_cstr(lib.zoitechat_get_info(lib.ph, b'configdir')))
|
configdir = __decode(_cstr(lib.zoitechat_get_info(lib.ph, b'configdir')))
|
||||||
addondir = os.path.join(configdir, 'addons')
|
addondir = os.path.join(configdir, 'addons')
|
||||||
try:
|
try:
|
||||||
with change_cwd(addondir): # Maintaining old behavior
|
with change_cwd(addondir):
|
||||||
for f in os.listdir(addondir):
|
for f in os.listdir(addondir):
|
||||||
if f.endswith('.py'):
|
if f.endswith('.py'):
|
||||||
log('Autoloading', f)
|
log('Autoloading', f)
|
||||||
# TODO: Set cwd
|
|
||||||
load_filename(os.path.join(addondir, f))
|
load_filename(os.path.join(addondir, f))
|
||||||
|
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user