本文整理汇总了Python中weechat.string_eval_expression函数的典型用法代码示例。如果您正苦于以下问题:Python string_eval_expression函数的具体用法?Python string_eval_expression怎么用?Python string_eval_expression使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了string_eval_expression函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_strings
def test_strings():
"""Test string functions."""
check(weechat.charset_set('iso-8859-15') == 1)
check(weechat.charset_set('') == 1)
check(weechat.iconv_to_internal('iso-8859-15', 'abc') == 'abc')
check(weechat.iconv_from_internal('iso-8859-15', 'abcd') == 'abcd')
check(weechat.gettext('abcdef') == 'abcdef')
check(weechat.ngettext('file', 'files', 1) == 'file')
check(weechat.ngettext('file', 'files', 2) == 'files')
check(weechat.strlen_screen('abcd') == 4)
check(weechat.string_match('abcdef', 'abc*', 0) == 1)
check(weechat.string_match('abcdef', 'abc*', 1) == 1)
check(weechat.string_match('ABCDEF', 'abc*', 1) == 0)
check(weechat.string_match_list('abcdef', '*,!abc*', 0) == 0)
check(weechat.string_match_list('ABCDEF', '*,!abc*', 1) == 1)
check(weechat.string_match_list('def', '*,!abc*', 0) == 1)
check(weechat.string_eval_path_home('test ${abc}', {}, {'abc': '123'}, {}) == 'test 123')
check(weechat.string_mask_to_regex('test*mask') == 'test.*mask')
check(weechat.string_has_highlight('my test string', 'test,word2') == 1)
check(weechat.string_has_highlight_regex('my test string', 'test|word2') == 1)
check(weechat.string_format_size(0) == '0 bytes')
check(weechat.string_format_size(1) == '1 byte')
check(weechat.string_format_size(2097152) == '2.10 MB')
check(weechat.string_format_size(420000000) == '420.00 MB')
check(weechat.string_remove_color('test', '?') == 'test')
check(weechat.string_is_command_char('/test') == 1)
check(weechat.string_is_command_char('test') == 0)
check(weechat.string_input_for_buffer('test') == 'test')
check(weechat.string_input_for_buffer('/test') == '')
check(weechat.string_input_for_buffer('//test') == '/test')
check(weechat.string_eval_expression("100 > 50", {}, {}, {"type": "condition"}) == '1')
check(weechat.string_eval_expression("-50 < 100", {}, {}, {"type": "condition"}) == '1')
check(weechat.string_eval_expression("18.2 > 5", {}, {}, {"type": "condition"}) == '1')
check(weechat.string_eval_expression("0xA3 > 2", {}, {}, {"type": "condition"}) == '1')
check(weechat.string_eval_expression("${buffer.full_name}", {}, {}, {}) == 'core.weechat')
示例2: key
def key(buffer):
extra_vars = {}
for helper_name, helper in sorted(helpers.items()):
expanded = weechat.string_eval_expression(helper, {"buffer": buffer}, {}, {})
extra_vars[helper_name] = expanded if case_sensitive else casefold(expanded)
result = []
for rule in rules:
expanded = weechat.string_eval_expression(rule, {"buffer": buffer}, extra_vars, {})
result.append(expanded if case_sensitive else casefold(expanded))
return result
示例3: privmsg
def privmsg(data, signal, signal_data):
(server, signal) = signal.split(',')
channels = wc.config_get_plugin('channels').replace(',', '|')
consumer_key = wc.config_get_plugin('consumer_key')
consumer_secret = wc.config_get_plugin('consumer_secret')
access_token_key = wc.config_get_plugin('access_token_key')
access_token_secret = wc.config_get_plugin('access_token_secret')
sec = re.compile('^\${sec\.data\.(.*)}$')
if sec.match(consumer_key):
consumer_key = wc.string_eval_expression(consumer_key, {}, {}, {})
if sec.match(consumer_secret):
consumer_secret = wc.string_eval_expression(consumer_secret, {}, {}, {})
if sec.match(access_token_key):
access_token_key = wc.string_eval_expression(access_token_key, {}, {}, {})
if sec.match(access_token_secret):
access_token_secret = wc.string_eval_expression(access_token_secret, {}, {}, {})
bots_list = wc.config_get_plugin('other_bots').split(',')
details = wc.info_get_hashtable('irc_message_parse', {'message': signal_data, 'server': server})
twitter_regex_match = re.compile(r'(.*https?://)?twitter\.com/.*/status/([0-9]{18})(.*)').match(details['text'])
buffer_name = details['channel']
buffer_pointer = wc.info_get('irc_buffer', '%s,%s' % (server, buffer_name))
channels_regex = re.compile(r'(%s)' % (channels), re.I)
bots_exist = False
if channels_regex.match(buffer_name) and twitter_regex_match:
if not bots_list == 'not_set':
for other_bots in bots_list:
bots_test = wc.nicklist_search_nick(buffer_pointer, '', other_bots)
if bots_test:
bots_exist = True
if not bots_exist:
if consumer_key == 'not_set':
wc.command('', r'/msg {0} Twitter consumer_key not set.'.format(buffer_name))
elif consumer_secret == 'not_set':
wc.command('', r'/msg {0} Twitter consumer_secret not set.'.format(buffer_name))
elif access_token_key == 'not_set':
wc.command('', r'/msg {0} Twitter access_token_key not set.'.format(buffer_name))
elif access_token_secret == 'not_set':
wc.command('', r'/msg {0} Twitter access_token_secret not set.'.format(buffer_name))
else:
tweet_id = twitter_regex_match.group(2)
tweet = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret).request('statuses/show/:{0}'.format(tweet_id))
try:
tweet_message = tweet.json()['text'].replace('\n', ' ').encode('utf-8')
tweet_message = HTMLParser().unescape(tweet_message)
tweet_user = tweet.json()['user']['screen_name'].encode('utf-8')
wc.command('', r'/msg {0} [Twitter] "{1}" by @{2}'.format(buffer_name, tweet_message, tweet_user))
except:
wc.command('', r'/msg {0} [Twitter] Error getting tweet info.'.format(buffer_name))
return wc.WEECHAT_RC_OK
示例4: privmsg
def privmsg(data, signal, signal_data):
(server, signal) = signal.split(",")
channels = wc.config_get_plugin('channels').replace(',', '|')
api_key = wc.config_get_plugin('api_key')
if re.match('^\${sec\.data\.(.*)}$', api_key):
api_key = wc.string_eval_expression(api_key, {}, {}, {})
bots_list = wc.config_get_plugin('other_bots').split(",")
details = wc.info_get_hashtable("irc_message_parse", {"message": signal_data, "server": server})
youtube_regex_match = re.compile(r'(.*https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?([a-zA-Z0-9_-]{11})').match(details['text'])
buffer_name = details['channel']
buffer_pointer = wc.info_get("irc_buffer", "%s,%s" % (server, buffer_name))
channels_regex = re.compile(r'(%s)' % (channels), re.I)
bots_exist = False
if channels_regex.match(buffer_name) and youtube_regex_match:
if not bots_list == "not_set":
for other_bots in bots_list:
bots_test = wc.nicklist_search_nick(buffer_pointer, "", other_bots)
if bots_test:
bots_exist = True
if not bots_exist:
if not api_key == "not_set":
vid_id = youtube_regex_match.group(6)
rvt = requests.get('https://www.googleapis.com/youtube/v3/videos/?id={0}&part=snippet&key={1}'.format(vid_id, api_key))
rvc = requests.get('https://www.googleapis.com/youtube/v3/videos/?id={0}&part=statistics&key={1}'.format(vid_id, api_key))
try:
vid_title = rvt.json()['items'][0]['snippet']['title'].encode('utf-8')
vid_channel = rvt.json()['items'][0]['snippet']['channelTitle'].encode('utf-8')
vid_views = rvc.json()['items'][0]['statistics']['viewCount']
wc.command("", r"/msg {0} [Youtube] {1} | Channel: {2} | Views: {3}".format(buffer_name, vid_title, vid_channel, vid_views))
except:
wc.command("", r"/msg {0} [Youtube] Error getting video info.".format(buffer_name))
else:
wc.command("", r"/msg {0} Youtube api key not set.".format(buffer_name))
return wc.WEECHAT_RC_OK
示例5: redirect_isonhandler
def redirect_isonhandler(data, signal, hashtable):
if hashtable["output"] == "":
return weechat.WEECHAT_RC_OK
# ISON_nicks contains nicks that are online on server (separated with space)
# nicks in ISON_nicks are lowercase
message, ISON_nicks = hashtable["output"].split(":")[1:]
ISON_nicks = [nick.lower() for nick in ISON_nicks.split()]
for nick in server_nicks(hashtable["server"]):
mynick = weechat.info_get("irc_nick", hashtable["server"])
if nick.lower() == mynick.lower():
return weechat.WEECHAT_RC_OK
elif nick.lower() not in ISON_nicks and nick != "":
# get password for given server (evaluated)
if int(version) >= 0x00040200:
password = weechat.string_eval_expression(
weechat.config_get_plugin("%s.password" % hashtable["server"]), {}, {}, {}
)
else:
password = weechat.config_get_plugin("%s.password" % hashtable["server"])
grabnick(hashtable["server"], nick) # get your nick back
if password != "" and OPTIONS["nickserv"] != "":
# command stored in "keepnick.nickserv" option
t = Template(OPTIONS["nickserv"])
run_msg = t.safe_substitute(server=hashtable["server"], passwd=password)
weechat.command("", run_msg)
return weechat.WEECHAT_RC_OK
示例6: substitute_colors
def substitute_colors(text,window):
if int(version) >= 0x00040200:
bufpointer = weechat.window_get_pointer(window,"buffer")
return weechat.string_eval_expression(text, {"buffer": bufpointer}, {}, {})
# return weechat.string_eval_expression(text,{},{},{})
# substitute colors in output
return re.sub(regex_color, lambda match: weechat.color(match.group(1)), text)
示例7: fish_secure_key_cb
def fish_secure_key_cb(data, option, value):
global fish_secure_key, fish_secure_cipher
fish_secure_key = weechat.config_string(
weechat.config_get("fish.secure.key")
)
if fish_secure_key == "":
fish_secure_cipher = None
return weechat.WEECHAT_RC_OK
if fish_secure_key[:6] == "${sec.":
decrypted = weechat.string_eval_expression(
fish_secure_key, {}, {}, {}
)
if decrypted:
fish_secure_cipher = Blowfish(decrypted)
return weechat.WEECHAT_RC_OK
else:
weechat.config_option_set(fish_config_option["key"], "", 0)
weechat.prnt("", "Decrypt sec.conf first\n")
return weechat.WEECHAT_RC_OK
if fish_secure_key != "":
fish_secure_cipher = Blowfish(fish_secure_key)
return weechat.WEECHAT_RC_OK
示例8: disabled_servers
def disabled_servers():
""" Return a list of configured TOTP servers that are currently disabled. """
serverlist = get_irc_servers()
server_seed_list = [server for server in serverlist
if weechat.string_eval_expression("${sec.data.%s_seed}" % server, {}, {}, {})
and server not in get_config_as_list('otp_server_names')]
return [s for s in server_seed_list if s in serverlist]
示例9: process_pushbullet_cb
def process_pushbullet_cb(data, url, status, response, err):
body = None
headers = {}
lines = response.rstrip().splitlines()
status_code = int(lines.pop(0).split()[1])
for line in lines:
if body == "":
body += line
continue
header_line = line.split(":", 2)
if len(header_line) != 2:
body = ""
continue
headers[header_line[0].strip()] = header_line[1].strip()
# response is the string of http body
if status == w.WEECHAT_HOOK_PROCESS_ERROR:
w.prnt("", "[weebullet] Error sending to pushbullet: %s - %s" % (status, url))
return w.WEECHAT_RC_ERROR
if status_code is 401 or status_code is 403:
w.prnt("", "[weebullet] Invalid API Token: %s" % (w.string_eval_expression(w.config_get_plugin("api_key"), {}, {}, {})))
return w.WEECHAT_RC_ERROR
if status_code is not 200:
w.prnt("", "[weebullet] Error sending to pushbullet: %s - %s - %s" % (url, status_code, body))
return w.WEECHAT_RC_ERROR
return w.WEECHAT_RC_OK
示例10: encrypt
def encrypt(text):
encryption_password = weechat.config_get_plugin("encryption_password")
# decrypt the password if it is stored as secured data
if encryption_password.startswith("${sec."):
encryption_password = weechat.string_eval_expression(encryption_password, {}, {}, {})
if PY3:
text = text.encode("UTF-8")
command="openssl enc -aes-128-cbc -salt -base64 -md md5 -A -pass env:OpenSSLEncPW"
opensslenv = os.environ.copy();
# Unknown whether the encryption password should or should not be
# (UTF8-)encoded before being passed to the environment in python 3.
opensslenv['OpenSSLEncPW'] = encryption_password
output, errors = Popen(shlex.split(command), stdin=PIPE, stdout=PIPE,
stderr=PIPE,env=opensslenv).communicate(text + b" ")
output = output.replace(b"/", b"_")
output = output.replace(b"+", b"-")
output = output.replace(b"=", b"")
if PY3:
output = output.decode("UTF-8")
return output
示例11: keys_create_option_cb
def keys_create_option_cb(data, config_file, section, option, value):
if not keys_check_option_cb('', option, value):
weechat.prnt('',
"WeeSodium keys must be stored using WeeChat's secured "
"data storage. See /help secure for info on this.")
return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR
option_split = option.split('.')
if len(option_split) != 2:
weechat.prnt('',
"Both a server and a channel are required to be entered "
"as the key for the config option. For example: "
"/set weesodium.keys.example.#weesodium "
"${sec.data.wskey}")
return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR
weeopt = weechat.config_new_option(config_file, section, option, 'string',
'key', '', 0, 0, '', value, 0,
'keys_check_option_cb', '', '', '',
'', '')
if not weeopt:
return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR
option_split = option.split('.')
if len(option_split) == 2 and value.startswith('${sec.data.'):
channel_key = weechat.string_eval_expression(value, {}, {}, {})
channel_data[option] = WeeSodiumChannel(channel_key)
return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED
示例12: remove_server
def remove_server(server, remove_seed=False):
""" Remove server from the plugin configuration. """
if remove_seed and weechat.string_eval_expression("${sec.data.%s_seed}" % server, {}, {}, {}):
weechat.command("", "/secure del %s_seed" % server)
servers = get_config_as_list("otp_server_names")
if server in servers:
servers = [v for v in servers if v != server]
weechat.config_set_plugin("otp_server_names", ','.join(servers))
示例13: show_notification
def show_notification(chan, nick, message):
API_TOKEN = weechat.config_get_plugin("api_token")
# decrypt the API token if it is stored as secured data
if API_TOKEN.startswith("${sec."):
API_TOKEN = weechat.string_eval_expression(API_TOKEN, {}, {}, {})
if API_TOKEN != "":
url = "https://irssinotifier.appspot.com/API/Message"
postdata = urllib.urlencode({'apiToken':API_TOKEN,'nick':encrypt(nick),'channel':encrypt(chan),'message':encrypt(message),'version':13})
version = weechat.info_get("version_number", "") or 0
hook1 = weechat.hook_process_hashtable("url:"+url, { "postfields": postdata}, 2000, "", "")
示例14: urlserver_check_auth
def urlserver_check_auth(data):
"""Check user/password to access a page/URL."""
global urlserver_settings
if not urlserver_settings['http_auth']:
return True
http_auth = weechat.string_eval_expression(
urlserver_settings['http_auth'], {}, {}, {})
auth = re.search('^Authorization: Basic (\S+)$', data,
re.MULTILINE | re.IGNORECASE)
if auth and (base64_decode(auth.group(1)).decode('utf-8') == http_auth):
return True
return False
示例15: cmd_help
def cmd_help(data, buffer, args):
# Get current list of ignored channels in list form
ignored_channels = get_ignored_channels()
# Used for checking for ignore/unignore commands and getting the arguments
ignore_command = re.match("^ignore\s+(.+)", args)
unignore_command = re.match("^unignore\s+(.+)", args)
if(ignore_command is not None):
channels_to_ignore = ignore_command.group(1).split(' ')
for channel in channels_to_ignore:
if channel not in ignored_channels:
ignored_channels.append(channel)
w.config_set_plugin("ignored_channels", ','.join(ignored_channels))
w.prnt("", "Updated. Ignored channels: %s" % w.config_get_plugin("ignored_channels"))
elif(unignore_command is not None):
channels_to_unignore = unignore_command.group(1).split(' ')
for channel in channels_to_unignore:
if channel in ignored_channels:
ignored_channels.remove(channel)
w.config_set_plugin("ignored_channels", ','.join(ignored_channels))
w.prnt("", "Updated. Ignored channels: %s" % w.config_get_plugin("ignored_channels"))
elif(args == "listignores"):
w.prnt("", "Ignored channels: %s" % w.config_get_plugin("ignored_channels"))
elif(args == "listdevices"):
apikey = w.string_eval_expression(w.config_get_plugin("api_key"), {}, {}, {})
apiurl = "https://%[email protected]/v2/devices" % (apikey)
w.hook_process("url:" + apiurl, 20000, "process_devicelist_cb", "")
else:
w.prnt("", """
Weebullet requires an API key from your Pushbullet account to work. Set your API key with (evaluated):
/set plugins.var.python.weebullet.api_key <KEY>
Weebullet will by default only send notifications when you are marked away on IRC. You can change this with:
/set plugins.var.python.weebullet.away_only [0|1]
Weebullet will by default send to all devices associated with your Pushbullet account. You can change this with:
/set plugins.var.python.weebullet.device_iden <ID>
Weebullet can ignore repeated notifications if they arrive too often. You can set this with (0 or blank to disable):
/set plugins.var.python.weebullet.min_notify_interval <NUMBER>
You can get a list of your devices from the Pushbullet website, or by using
/weebullet listdevices
""")
return w.WEECHAT_RC_OK