def get_prefs(name): string_out = ffi.new('char**') int_out = ffi.new('int*') type = lib.hexchat_get_prefs(lib.ph, name.encode(), string_out, int_out) if type is 0: return None elif type is 1: return __decode(ffi.string(string_out[0])) elif type is 2 or type is 3: # XXX: 3 should be a bool, but keeps API return int_out[0] else: assert False
def get_prefs(name): string_out = ffi.new('char**') int_out = ffi.new('int*') _type = lib.hexchat_get_prefs(lib.ph, name.encode(), string_out, int_out) if _type == 0: return None if _type == 1: return __decode(ffi.string(string_out[0])) if _type in (2, 3): # XXX: 3 should be a bool, but keeps API return int_out[0] raise AssertionError('Out of bounds pref storage')
def emit_print(event_name, *args, **kwargs): time = kwargs.pop('time', 0) # For py2 compat cargs = [] for i in range(4): arg = args[i].encode() if len(args) > i else b'' cstring = ffi.new('char[]', arg) cargs.append(cstring) if time is 0: return lib.hexchat_emit_print(lib.ph, event_name.encode(), *cargs) else: attrs = lib.hexchat_event_attrs_create(lib.ph) attrs.server_time_utc = time ret = lib.hexchat_emit_print(lib.ph, attrs, event_name.encode(), *cargs) lib.hexchat_event_attrs_free(lib.ph, attrs) return ret
def emit_print(event_name, *args, **kwargs): time = kwargs.pop('time', 0) # For py2 compat cargs = [] for i in range(4): arg = args[i].encode() if len(args) > i else b'' cstring = ffi.new('char[]', arg) cargs.append(cstring) if time == 0: return lib.hexchat_emit_print(lib.ph, event_name.encode(), *cargs) attrs = lib.hexchat_event_attrs_create(lib.ph) attrs.server_time_utc = time ret = lib.hexchat_emit_print_attrs(lib.ph, attrs, event_name.encode(), *cargs) lib.hexchat_event_attrs_free(lib.ph, attrs) return ret
def get_pluginpref(name): name = name.encode() string_out = ffi.new('char[512]') if lib.hexchat_pluginpref_get_str(lib.ph, name, string_out) != 1: return None string = ffi.string(string_out) # This API stores everything as a string so we have to figure out what # its actual type was supposed to be. if len(string) > 12: # Can't be a number return __decode(string) number = lib.hexchat_pluginpref_get_int(lib.ph, name) if number == -1 and string != b'-1': return __decode(string) return number
import traceback import weakref from contextlib import contextmanager from _hexchat_embedded import ffi, lib if sys.version_info < (3, 0): from io import BytesIO as HelpEater else: from io import StringIO as HelpEater if not hasattr(sys, 'argv'): sys.argv = ['<hexchat>'] VERSION = b'2.0' # Sync with hexchat.__version__ 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_VERSION = ffi.new('char[]', VERSION) # TODO: Constants should be screaming snake case hexchat = None local_interp = None hexchat_stdout = None plugins = set() @contextmanager def redirected_stdout(): sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ yield
import site import traceback 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 if not hasattr(sys, 'argv'): sys.argv = ['<hexchat>'] VERSION = b'2.0' # Sync with hexchat.__version__ 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_VERSION = ffi.new('char[]', VERSION) hexchat = None local_interp = None hexchat_stdout = None plugins = set() @contextmanager def redirected_stdout(): sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ yield
def list_pluginpref(): prefs_str = ffi.new('char[4096]') if lib.hexchat_pluginpref_list(lib.ph, prefs_str) == 1: return __decode(prefs_str).split(',') return []