python: Various cffi fixes
- fixed /py exec behaviour - fixed hexchat.unload_hook() failing when passed a hook id - fixed get_list() calls in python3
This commit is contained in:
@@ -150,6 +150,15 @@ class ListItem:
|
|||||||
return '<{} list item at {}>'.format(self._listname, id(self))
|
return '<{} list item at {}>'.format(self._listname, id(self))
|
||||||
|
|
||||||
|
|
||||||
|
# done this way for speed
|
||||||
|
if sys.version_info[0] == 2:
|
||||||
|
def get_getter(name):
|
||||||
|
return ord(name[0])
|
||||||
|
else:
|
||||||
|
def get_getter(name):
|
||||||
|
return name[0]
|
||||||
|
|
||||||
|
|
||||||
def get_list(name):
|
def get_list(name):
|
||||||
# XXX: This function is extremely inefficient and could be interators and
|
# XXX: This function is extremely inefficient and could be interators and
|
||||||
# lazily loaded properties, but for API compat we stay slow
|
# lazily loaded properties, but for API compat we stay slow
|
||||||
@@ -189,7 +198,7 @@ def get_list(name):
|
|||||||
while lib.hexchat_list_next(lib.ph, list_) is 1:
|
while lib.hexchat_list_next(lib.ph, list_) is 1:
|
||||||
item = ListItem(orig_name)
|
item = ListItem(orig_name)
|
||||||
for field in fields:
|
for field in fields:
|
||||||
getter = getters.get(ord(field[0]))
|
getter = getters.get(get_getter(field))
|
||||||
if getter is not None:
|
if getter is not None:
|
||||||
field_name = field[1:]
|
field_name = field[1:]
|
||||||
setattr(item, __cached_decoded_str(field_name), getter(field_name))
|
setattr(item, __cached_decoded_str(field_name), getter(field_name))
|
||||||
|
@@ -98,7 +98,8 @@ else:
|
|||||||
return compile(data, filename, 'exec', optimize=2, dont_inherit=True)
|
return compile(data, filename, 'exec', optimize=2, dont_inherit=True)
|
||||||
|
|
||||||
def compile_line(string):
|
def compile_line(string):
|
||||||
return compile(string, '<string>', 'eval', optimize=2, dont_inherit=True)
|
# newline appended to solve unexpected EOF issues
|
||||||
|
return compile(string + '\n', '<string>', 'single', optimize=2, dont_inherit=True)
|
||||||
|
|
||||||
|
|
||||||
class Plugin:
|
class Plugin:
|
||||||
@@ -122,7 +123,7 @@ class Plugin:
|
|||||||
def remove_hook(self, hook):
|
def remove_hook(self, hook):
|
||||||
for h in self.hooks:
|
for h in self.hooks:
|
||||||
if id(h) == hook:
|
if id(h) == hook:
|
||||||
ud = hook.userdata
|
ud = h.userdata
|
||||||
self.hooks.remove(h)
|
self.hooks.remove(h)
|
||||||
return ud
|
return ud
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user