本文整理汇总了Python中weechat.infolist_free函数的典型用法代码示例。如果您正苦于以下问题:Python infolist_free函数的具体用法?Python infolist_free怎么用?Python infolist_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了infolist_free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_nicklist
def get_nicklist(server, channel):
global options
regex_flags = 0
if options['ignore_case']:
regex_flags = re.IGNORECASE
ignore_list = w.config_get_plugin('ignore_list')
if ignore_list == '':
ignore_match = lambda x: False
else:
ignore_match = re.compile('(%s)$' % ignore_list.replace(',', '|'), regex_flags).match
server = w.buffer_get_string(w.current_buffer(), 'localvar_server')
my_nick = w.info_get('irc_nick', server)
nicklist = {}
infolist_nicklist = w.infolist_get('nicklist', w.current_buffer(), '')
while w.infolist_next(infolist_nicklist):
nick = w.infolist_string(infolist_nicklist, 'name')
prefix = w.infolist_string(infolist_nicklist, 'prefix')
nick_type = w.infolist_string(infolist_nicklist, 'type')
if nick_type != 'nick' or (options['ignore_self'] and nick == my_nick) or ignore_match(nick):
pass
else:
if not nicklist.has_key(prefix):
nicklist[prefix]=[]
nicklist[prefix].append(nick)
w.infolist_free(infolist_nicklist)
return nicklist
示例2: match_against_nicklist
def match_against_nicklist(server, channel, hostmask):
"""Compare the hostmask against all users in the channel"""
infolist = w.infolist_get("irc_nick", "", "{},{}".format(server, channel))
if "$a:" in hostmask or "$~a" in hostmask:
field = "account"
hostmask = hostmask.replace("$a:", "")
hostfield = False
else:
field = "host"
hostfield = True
extban_unreg = hostmask == "$~a"
matches = []
while w.infolist_next(infolist):
name = w.infolist_string(infolist, "name")
if hostfield:
host = name + "!" + w.infolist_string(infolist, field)
else:
host = w.infolist_string(infolist, field)
if ((extban_unreg and host == "*") or
(not extban_unreg and w.string_match(host, hostmask, 0))):
matches.append(name)
w.infolist_free(infolist)
return matches
示例3: update_user_count
def update_user_count(server=None, channel=None):
if isinstance(channel, str):
channel = set((channel, ))
elif channel:
channel = set(channel)
def update_channel(server, channel=None):
channel_infolist = weechat.infolist_get('irc_channel', '', server)
while weechat.infolist_next(channel_infolist):
_channel = weechat.infolist_string(channel_infolist, 'name')
if channel:
_channel = caseInsensibleKey(_channel)
if _channel not in channel:
continue
channel_stats[server, _channel] = weechat.infolist_integer(channel_infolist, 'nicks_count')
weechat.infolist_free(channel_infolist)
if not server:
server_infolist = weechat.infolist_get('irc_server', '', '')
while weechat.infolist_next(server_infolist):
server = weechat.infolist_string(server_infolist, 'name')
update_channel(server)
weechat.infolist_free(server_infolist)
else:
update_channel(server, channel)
示例4: allquery_command_cb
def allquery_command_cb(data, buffer, args):
""" Callback for /allquery command """
args = args.strip()
if args == "":
weechat.command("", "/help %s" % SCRIPT_COMMAND)
return weechat.WEECHAT_RC_OK
argv = args.split(" ")
exclude_nick = None
if argv[0].startswith("-exclude="):
exclude_nick = make_list(argv[0])
command = " ".join(argv[1::])
else:
command = args
if not command.startswith("/"):
weechat.command("", "/help %s" % SCRIPT_COMMAND)
return weechat.WEECHAT_RC_OK
infolist = weechat.infolist_get("buffer", "", "")
while weechat.infolist_next(infolist):
if weechat.infolist_string(infolist, "plugin_name") == "irc":
ptr = weechat.infolist_pointer(infolist, "pointer")
server = weechat.buffer_get_string(ptr, "localvar_server")
query = weechat.buffer_get_string(ptr, "localvar_channel")
execute_command = re.sub(r'\b\$nick\b', query, command)
if weechat.buffer_get_string(ptr, "localvar_type") == "private":
if exclude_nick is not None:
if not query in exclude_nick:
weechat.command(ptr, execute_command)
else:
weechat.command(ptr, execute_command)
weechat.infolist_free(infolist)
return weechat.WEECHAT_RC_OK
示例5: get_help_command
def get_help_command(plugin, input_cmd, input_args):
"""Get help for command in input."""
global cmdhelp_settings
if input_cmd == 'set' and input_args:
return get_help_option(input_args)
infolist = weechat.infolist_get('hook', '', 'command,%s' % input_cmd)
cmd_plugin_name = ''
cmd_command = ''
cmd_args = ''
cmd_desc = ''
while weechat.infolist_next(infolist):
cmd_plugin_name = (weechat.infolist_string(infolist, 'plugin_name') or
'core')
cmd_command = weechat.infolist_string(infolist, 'command')
cmd_args = weechat.infolist_string(infolist, 'args_nls')
cmd_desc = weechat.infolist_string(infolist, 'description')
if weechat.infolist_pointer(infolist, 'plugin') == plugin:
break
weechat.infolist_free(infolist)
if cmd_plugin_name == 'alias':
return '%sAlias %s%s%s => %s%s' % (
weechat.color(cmdhelp_settings['color_alias']),
weechat.color(cmdhelp_settings['color_alias_name']),
cmd_command,
weechat.color(cmdhelp_settings['color_alias']),
weechat.color(cmdhelp_settings['color_alias_value']),
cmd_desc,
)
if input_args:
cmd_args = get_command_arguments(input_args, cmd_args)
if not cmd_args:
return None
return '%s%s' % (weechat.color(cmdhelp_settings['color_arguments']),
cmd_args)
示例6: get_matching_buffers
def get_matching_buffers(input):
""" Return list with buffers matching user input """
global buffers_pos
list = []
if len(input) == 0:
buffers_pos = 0
input = input.lower()
infolist = weechat.infolist_get("buffer", "", "")
while weechat.infolist_next(infolist):
if weechat.config_get_plugin("short_name") == "on":
name = weechat.infolist_string(infolist, "short_name")
else:
name = weechat.infolist_string(infolist, "name")
number = weechat.infolist_integer(infolist, "number")
matching = name.lower().find(input) >= 0
if not matching and input[-1] == ' ':
matching = name.lower().endswith(input.strip())
if not matching and input.isdigit():
matching = str(number).startswith(input)
if len(input) == 0 or matching:
list.append({"number": number, "name": name})
if len(input) == 0 and weechat.infolist_pointer(infolist, "pointer") == weechat.current_buffer():
buffers_pos = len(list) - 1
weechat.infolist_free(infolist)
return list
示例7: gen_infolist_get
def gen_infolist_get(infolist_name, arguments, pointer=""):
"""
Same as infolist_get(), but yields it's elements.
Be sure to iterate through the whole list, to ensure
weechat.infolist_free() is called.
"""
infolist = weechat.infolist_get(infolist_name, pointer, arguments)
if infolist:
while weechat.infolist_next(infolist):
fields = weechat.infolist_fields(infolist).split(',')
field_names = []
list_element = {}
for field in fields:
field_type, field_name = field.split(':')
field_names.append(field_name)
# decide which function to use
info_func = {
'i': weechat.infolist_integer,
's': weechat.infolist_string,
'p': weechat.infolist_pointer,
# 'b': weechat.infolist_buffer,
't': weechat.infolist_time,
}[field_type]
value = info_func(infolist, field_name)
list_element[field_name] = value
# create a temporary namedtuple type using field_names
item_tpl = namedtuple('InfolistItem', field_names)
yield item_tpl(**list_element)
weechat.infolist_free(infolist)
示例8: keydict_update
def keydict_update(*args):
'''Populate a python dictionary with relevant key=>buffer mappings.'''
global keydict
keylist = w.infolist_get('key', '', '')
if w.config_get_plugin('use_keybindings') == 'on':
while w.infolist_next(keylist):
key = w.infolist_string(keylist, 'key')
# we dont want jump sequences
if 'j' in key:
continue
key = key.replace('meta-', '')
key = key.replace('ctrl-', '^')
if w.config_get_plugin('skip_number_binds') == 'on':
# skip entries where buffer number = key, typically entries below 11
if key.isdigit():
continue
command = w.infolist_string(keylist, 'command')
# we only care about commands that leads to buffers
if command.startswith('/buffer'):
command = command.replace('/buffer ', '')
buffer = command.lstrip('*')
keydict[buffer] = key
w.infolist_free(keylist)
return w.WEECHAT_RC_OK
示例9: reorder_buffers
def reorder_buffers():
"""Reorders the buffers once the whitelist has changed
"""
count = 2
chan = ""
ilist = weechat.infolist_get("buffer", "", "")
for chan in whitelist:
if -1 == chan.find(".#"): #network name is not set, matching by short_name
weechat.infolist_reset_item_cursor(ilist)
while weechat.infolist_next(ilist):
if weechat.infolist_string(ilist, "short_name") == chan:
chan = weechat.infolist_string(ilist, "name")
break
buff = weechat.buffer_search("irc", chan)
if buff:
weechat.buffer_set(buff, "number", str(count))
count += 1
weechat.infolist_free(ilist)
return weechat.WEECHAT_RC_OK
示例10: disable_logging
def disable_logging(self):
"""Return the previous logger level and set the buffer logger level
to 0. If it was already 0, return None."""
# If previous_log_level has not been previously set, return the level
# we detect now.
if not hasattr(self, 'previous_log_level'):
infolist = weechat.infolist_get('logger_buffer', '', '')
buf = self.buffer()
previous_log_level = 0
while weechat.infolist_next(infolist):
if weechat.infolist_pointer(infolist, 'buffer') == buf:
previous_log_level = weechat.infolist_integer(
infolist, 'log_level')
if self.is_logged():
weechat.command(buf, '/mute logger disable')
self.print_buffer(
'Logs have been temporarily disabled for the session. They will be restored upon finishing the OTR session.')
break
weechat.infolist_free(infolist)
return previous_log_level
# If previous_log_level was already set, it means we already altered it
# and that we just detected an already modified logging level.
# Return the pre-existing value so it doesn't get lost, and we can
# restore it later.
else:
return self.previous_log_level
示例11: find_channels
def find_channels():
"""Return list of servers and channels"""
#@TODO: make it return a dict with more options like "nicks_count etc."
items = {}
infolist = w.infolist_get('irc_server', '', '')
# populate servers
while w.infolist_next(infolist):
items[w.infolist_string(infolist, 'name')] = ''
w.infolist_free(infolist)
# populate channels per server
for server in items.keys():
items[server] = '' #init if connected but no channels
infolist = w.infolist_get('irc_channel', '', server)
while w.infolist_next(infolist):
if w.infolist_integer(infolist, 'nicks_count') == 0:
#parted but still open in a buffer: bit hackish
continue
if w.infolist_integer(infolist, 'type') == 0:
channel = w.infolist_string(infolist, "buffer_short_name")
items[server] += '%s,' %channel
w.infolist_free(infolist)
return items
示例12: buffer_opened_closed_cb
def buffer_opened_closed_cb(data, signal, signal_data):
global OPTIONS
# localvar not set in this moment? :-(
# server = weechat.buffer_get_string(signal_data, 'localvar_server') # get internal servername
infolist = weechat.infolist_get('buffer', signal_data, '')
weechat.infolist_next(infolist)
plugin_name = weechat.infolist_string(infolist, 'plugin_name')
name = weechat.infolist_string(infolist, 'name')
weechat.infolist_free(infolist)
# TODO how about matrix script or other non-irc channel buffer? no idea! help is welcome
if plugin_name != "irc": # for example /fset, /color etc.pp buffer
return weechat.WEECHAT_RC_OK
if OPTIONS['activity'].lower() == 'no' or OPTIONS['activity'].lower() == 'off' or OPTIONS['activity'].lower() == '0':
weechat.command('','/allchan -exclude=%s /buffer hide' % OPTIONS['channel_exclude'])
if not signal_data: # signal_data available?
weechat.command(signal_data,'/allchan -current /buffer unhide')
else: # signal_data empty!
weechat.command('','/allchan /buffer hide')
exclude_server('')
single_channel_exclude()
else:
weechat.command('','/allchan /buffer hide')
exclude_hotlist()
return weechat.WEECHAT_RC_OK
示例13: find_channels
def find_channels():
"""Return list of servers and channels"""
#@TODO: make it return a dict with more options like "nicks_count etc."
items = {}
infolist = w.infolist_get('irc_server', '', '')
# populate servers
while w.infolist_next(infolist):
items[w.infolist_string(infolist, 'name')] = ''
w.infolist_free(infolist)
# populate channels per server
for server in items.keys():
keys = []
keyed_channels = []
unkeyed_channels = []
items[server] = '' #init if connected but no channels
infolist = w.infolist_get('irc_channel', '', server)
while w.infolist_next(infolist):
if w.infolist_integer(infolist, 'nicks_count') == 0:
#parted but still open in a buffer: bit hackish
continue
if w.infolist_integer(infolist, 'type') == 0:
key = w.infolist_string(infolist, "key")
if len(key) > 0:
keys.append(key)
keyed_channels.append(w.infolist_string(infolist, "name"))
else :
unkeyed_channels.append(w.infolist_string(infolist, "name"))
items[server] = ','.join(keyed_channels + unkeyed_channels)
if len(keys) > 0:
items[server] += ' %s' % ','.join(keys)
w.infolist_free(infolist)
return items
示例14: save_query_buffer_to_file
def save_query_buffer_to_file():
global query_buffer_list
ptr_infolist_buffer = weechat.infolist_get("buffer", "", "")
while weechat.infolist_next(ptr_infolist_buffer):
ptr_buffer = weechat.infolist_pointer(ptr_infolist_buffer, "pointer")
type = weechat.buffer_get_string(ptr_buffer, "localvar_type")
if type == "private":
server = weechat.buffer_get_string(ptr_buffer, "localvar_server")
channel = weechat.buffer_get_string(ptr_buffer, "localvar_channel")
query_buffer_list.insert(0, "%s %s" % (server, channel))
weechat.infolist_free(ptr_infolist_buffer)
filename = get_filename_with_path()
if len(query_buffer_list):
try:
f = open(filename, "w")
i = 0
while i < len(query_buffer_list):
f.write("%s\n" % query_buffer_list[i])
i = i + 1
f.close()
except:
weechat.prnt(
"", '%s%s: Error writing query buffer to "%s"' % (weechat.prefix("error"), SCRIPT_NAME, filename)
)
raise
else: # no query buffer(s). remove file
if os.path.isfile(filename):
os.remove(filename)
return
示例15: get_patterns_in_config
def get_patterns_in_config(filter):
d = {}
infolist = weechat.infolist_get('option', '', 'plugins.var.python.%s.%s' %(SCRIPT_NAME, filter))
while weechat.infolist_next(infolist):
name = weechat.infolist_string(infolist, 'option_name')
name = name[len('python.%s.' %SCRIPT_NAME):]
# channels might have dots in their names, so we'll strip type from right and server
# from left. Lets hope that users doesn't use dots in server names.
name, _, type = name.rpartition('.')
if type not in ('op', 'halfop', 'voice'):
# invalid option
continue
server, _, channel = name.partition('.')
value = weechat.infolist_string(infolist, 'value')
if not value:
continue
else:
value = value.split(',')
key = (server, channel)
if key not in d:
d[key] = {type:value}
else:
d[key][type] = value
weechat.infolist_free(infolist)
return d