本文整理汇总了Python中supybot.log.debug函数的典型用法代码示例。如果您正苦于以下问题:Python debug函数的具体用法?Python debug怎么用?Python debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, plugin_name, filename, addressing_mode=DEFAULT_MODE, case_sensitive=False):
"""
Loads the existing database, creating a new one in memory if none
exists.
"""
self.db = {}
self._plugin_name = plugin_name
self.filename = conf.supybot.directories.data.dirize(filename)
self.case_sensitive = case_sensitive
self.addressing_mode = addressing_mode
try:
with open(self.filename, 'rb') as f:
self.db = pickle.load(f)
except Exception as e:
log.debug('%s: Unable to load database, creating '
'a new one: %s', self._plugin_name, e)
else:
if not case_sensitive:
for key, val in self.db.copy().items():
if not key.islower():
log.debug('%s: case-shifting key %s to %s', self._plugin_name, key, key.lower())
self.db[key.lower()] = val
del self.db[key]
示例2: do_http_msg
def do_http_msg(self, handler, headers, msg):
log.debug("headers: {}".format(headers))
log.debug("text: {}".format(msg))
params = msg
important_fields = {
'key': params.get('key', None),
'channel': params.get('channel', None),
'text': params.get('msg', None)
}
if important_fields['channel'] is None or important_fields['text'] is None or important_fields['key'] is None:
missing_fields = list(filter(lambda x: important_fields[x] is None, important_fields.keys()))
handler.send_response(403)
handler.send_header("Content-Type", "application/json")
handler.end_headers()
handler.wfile.write(bytes(json.dumps({"success": False, "msg": "Missing field(s).", "fields": missing_fields}), "utf-8"))
elif important_fields['key'] == self.registryValue("sendingKey"):
self.send_msg(important_fields['channel'], important_fields['text'])
handler.send_response(200)
handler.send_header("Content-Type", "application/json")
handler.end_headers()
handler.wfile.write(bytes(json.dumps({"success": True, "msg": "Thanks!"}), "utf-8"))
else:
handler.send_response(403)
handler.send_header("Content-Type", "application/json")
handler.end_headers()
handler.wfile.write(bytes(json.dumps({"success": False, "msg": "Invalid sendingKey"}), "utf-8"))
示例3: _debian_vlist_fetcher
def _debian_vlist_fetcher(self, pkg, dist, reverse=False):
"""Parser for the madison API at https://qa.debian.org/madison.php."""
# This arch value implies 'all' (architecture-independent packages)
# and 'source' (source packages), in order to prevent misleading
# "Not found" errors.
archs = self.registryValue('archs') + ['source', 'all']
arg = {'package': pkg, 'table': dist, 'a': ','.join(set(archs))}
url = 'https://qa.debian.org/madison.php?text=on&' + urlencode(arg)
log.debug("PkgInfo: Using url %s for debian_vlist_fetcher", url)
d = OrderedDict()
fd = utils.web.getUrlFd(url)
for line in fd.readlines():
L = line.decode("utf-8").split("|")
name, version, release, archs = map(str.strip, L)
d[release] = (version, archs)
if d:
if reverse:
# *sigh*... I wish there was a better way to do this
d = OrderedDict(reversed(tuple(d.items())))
if self.registryValue('verbose'):
items = ["{name} \x02({version} [{archs}])\x02".format(name=k,
version=v[0], archs=v[1]) for (k, v) in d.items()]
else:
items = ["{name} \x02({version})\x02".format(name=k,
version=v[0]) for (k, v) in d.items()]
s = format('Found %n: %L', (len(d), 'result'), items)
return s
else:
log.debug("PkgInfo: No results found for URL %s", url)
示例4: _translateQuery
def _translateQuery(self, function, parameters={}):
if self.registryValue("appId") == "":
log.error("Translate: Set your appId and restart the plugin")
return
log.debug("Translate.query: %s" % (repr(parameters)))
if self.registryValue("httpProxy") != "":
opener = urllib2.build_opener(urllib2.ProxyHandler({"http": self.registryValue("httpProxy")}))
else:
opener = urllib2.build_opener()
response = opener.open(
self.registryValue("queryURL")
+ function
+ "?"
+ "appId="
+ self.registryValue("appId")
+ "&"
+ urllib.urlencode(parameters)
)
try:
data = json.loads(json.dumps(response.read()))
data = json.loads(data[1:])
log.debug("Translate.reply: %s" % repr(data))
return data
except:
log.error("Translate.query error")
return None
示例5: _radioQuery
def _radioQuery(self, function, parameters={}):
parameters['w'] = function
log.debug('Radio.query: %s' % (repr(parameters)))
if (self.registryValue('httpProxy') != ''):
opener = urllib2.build_opener(
urllib2.ProxyHandler({'http': self.registryValue('httpProxy')}))
else:
opener = urllib2.build_opener()
response = opener.open(self.registryValue('queryURL') + '?'+
'apikey=' + self.registryValue('queryPass') + '&' +
urllib.urlencode(parameters))
data = json.loads(response.read())
# teddy cannot into integer :3
if ('listener' in data):
for stream in data['listener']:
stream['c'] = int(stream['c'])
def convertInteger(d, key):
if ((key in d) and (d[key] != None)):
d[key] = int(d[key])
for key in ['trackid', 'showbegin', 'showend', 'showid', 'djid']:
convertInteger(data, key)
log.debug('Radio.reply: %s' % repr(data))
return(data)
示例6: parse
def parse(self, pkg, dist, archs, codenames='', suite='', reverse=False, verbose=False):
"""Parser for the madison API at https://qa.debian.org/madison.php."""
# This arch value implies 'all' (architecture-independent packages)
# and 'source' (source packages), in order to prevent misleading
# "Not found" errors.
self.arg = {'package': pkg, 'table': dist, 'a': archs, 'c': codenames,
's': suite}
self.arg = urlencode(self.arg)
url = 'https://qa.debian.org/madison.php?text=on&' + self.arg
log.debug("PkgInfo: Using url %s for 'vlist' command", url)
d = OrderedDict()
fd = utils.web.getUrlFd(url)
for line in fd.readlines():
L = line.decode("utf-8").split("|")
try:
L = map(unicode.strip, L)
except:
L = map(str.strip, L)
name, version, release, archs = L
d[release] = (version, archs)
if d:
if reverse:
# *sigh*... I wish there was a better way to do this
d = OrderedDict(reversed(tuple(d.items())))
if verbose:
items = ["{name} \x02({version} [{archs}])\x02".format(name=k,
version=v[0], archs=v[1]) for (k, v) in d.items()]
else:
items = ["{name} \x02({version})\x02".format(name=k,
version=v[0]) for (k, v) in d.items()]
s = format('Found %n: %L', (len(d), 'result'), items)
return s
else:
log.debug("PkgInfo: No results found for URL %s", url)
示例7: _translateQuery
def _translateQuery(self, function, parameters={}):
if (self.registryValue('appId') == ''):
log.error('Translate: Set your appId and restart the plugin')
return
log.debug('Translate.query: %s' % (repr(parameters)))
if (self.registryValue('httpProxy') != ''):
opener = urllib2.build_opener(
urllib2.ProxyHandler({'http': self.registryValue('httpProxy')}))
else:
opener = urllib2.build_opener()
response = opener.open(self.registryValue('queryURL') + function + '?'+
'appId=' + self.registryValue('appId') + '&' +
urllib.urlencode(parameters))
try:
data = json.loads(json.dumps(response.read()))
data = json.loads(data[1:])
log.debug('Translate.reply: %s' % repr(data))
return(data)
except:
log.error('Translate.query error')
return(None)
示例8: __call__
def __call__(self, irc, msg, args, state):
try:
super(optional, self).__call__(irc, msg, args, state)
except (callbacks.ArgumentError, callbacks.Error), e:
log.debug('Got %s, returning default.', utils.exnToString(e))
state.errored = False
setDefault(state, self.default)
示例9: requestURL
def requestURL(self, url):
# Use a needsRetry flag in case we catch a login failure outside of the SSL exception we seem to always get
needsRetry = False
response = None
try:
response = self.session.get(url, verify=True)
logger.debug("Request to " + url + " returned code " + str(response.status_code))
needsRetry = self.responseRequiresAuthentication(response)
except Exception as e:
# If this is an SSL error, we may be being redirected to the login page
logger.info("Caught exception on " + url + " request." + str(e))
needsRetry = True
if needsRetry:
logger.info("Logging in...")
response = self.login()
if response != None and not self.responseRequiresAuthentication(response):
logger.info("Request returned " + str(response.status_code) + " status code")
return response
return None
示例10: initialize_imgur_client
def initialize_imgur_client(self, channel):
"""
Check if imgur client id or secret are set, and if so initialize
imgur API client
"""
if self.imgur_client is None:
imgur_client_id = self.registryValue("imgurClientID")
imgur_client_secret = self.registryValue("imgurClientSecret")
imgur_handler_enabled = self.registryValue("imgurHandlerEnabled", channel=channel)
if imgur_handler_enabled and imgur_client_id and imgur_client_secret:
log.debug("SpiffyTitles: enabling imgur handler")
# Initialize API client
try:
from imgurpython import ImgurClient
from imgurpython.helpers.error import ImgurClientError
try:
self.imgur_client = ImgurClient(imgur_client_id, imgur_client_secret)
except ImgurClientError as e:
log.error("SpiffyTitles: imgur client error: %s" % (e.error_message))
except ImportError as e:
log.error("SpiffyTitles ImportError: %s" % str(e))
else:
log.debug("SpiffyTitles: imgur handler disabled or empty client id/secret")
示例11: _query
def _query(self, function, **params):
# filter out empty params
params = {key: value for key, value in params.iteritems() if value}
log.debug('RfK._query: %s' % repr(params))
if self.registryValue('httpProxy'):
opener = urllib2.build_opener(
urllib2.ProxyHandler({'http': self.registryValue('httpProxy')}))
else:
opener = urllib2.build_opener()
request_url = '%s%s?key=%s&%s' % (
self.registryValue('queryURL'),
function,
self.registryValue('queryPass'),
urllib.urlencode(params)
)
try:
response = opener.open(request_url)
except IOError, e:
log.error('RfK._query: %s' % repr(e))
return None
示例12: makeIrcsDie
def makeIrcsDie():
"""Kills Ircs."""
log.info("Killing Irc objects.")
for irc in ircs[:]:
if not irc.zombie:
irc.die()
else:
log.debug("Not killing %s, it's already a zombie.", irc)
示例13: stopticker
def stopticker(self, irc, msg, args):
self.stop = True
while self._threads:
t = self._threads.pop()
log.debug("waiting for %r to finish", t.name)
t.join()
log.debug("%r exited", t.name)
irc.reply("Stopped monitoring.")
示例14: handler_imgur_image
def handler_imgur_image(self, url, info, channel):
"""
Handles retrieving information about images from the imgur API.
Used for both direct images and imgur.com/some_image_id_here type links, as
they're both single images.
"""
self.initialize_imgur_client(channel)
from imgurpython.helpers.error import ImgurClientRateLimitError
from imgurpython.helpers.error import ImgurClientError
title = None
if self.imgur_client:
"""
If there is a period in the path, it's a direct link to an image. If not, then
it's a imgur.com/some_image_id_here type link
"""
if "." in info.path:
path = info.path.lstrip("/")
image_id = path.split(".")[0]
else:
image_id = info.path.lstrip("/")
if self.is_valid_imgur_id(image_id):
log.debug("SpiffyTitles: found image id %s" % (image_id))
try:
image = self.imgur_client.get_image(image_id)
if image:
imgur_template = Template(self.registryValue("imgurTemplate", channel=channel))
readable_file_size = self.get_readable_file_size(image.size)
compiled_template = imgur_template.render({
"title": image.title,
"type": image.type,
"nsfw": image.nsfw,
"width": image.width,
"height": image.height,
"view_count": "{:,}".format(image.views),
"file_size": readable_file_size,
"section": image.section
})
title = compiled_template
else:
log.error("SpiffyTitles: imgur API returned unexpected results!")
except ImgurClientRateLimitError as e:
log.error("SpiffyTitles: imgur rate limit error: %s" % (e.error_message))
except ImgurClientError as e:
log.error("SpiffyTitles: imgur client error: %s" % (e.error_message))
else:
log.error("SpiffyTitles: error retrieving image id for %s" % (url))
if title is not None:
return title
else:
return self.handler_default(url, channel)
示例15: _loadPlugins
def _loadPlugins(self, irc):
self.log.info('Loading plugins (connecting to %s).', irc.network)
alwaysLoadImportant = conf.supybot.plugins.alwaysLoadImportant()
important = conf.supybot.commands.defaultPlugins.importantPlugins()
for (name, value) in conf.supybot.plugins.getValues(fullNames=False):
if irc.getCallback(name) is None:
load = value()
if not load and name in important:
if alwaysLoadImportant:
s = '%s is configured not to be loaded, but is being '\
'loaded anyway because ' \
'supybot.plugins.alwaysLoadImportant is True.'
self.log.warning(s, name)
load = True
if load:
# We don't load plugins that don't start with a capital
# letter.
if name[0].isupper() and not irc.getCallback(name):
# This is debug because each log logs its beginning.
self.log.debug('Loading %s.', name)
try:
m = plugin.loadPluginModule(name,
ignoreDeprecation=True)
plugin.loadPluginClass(irc, m)
except callbacks.Error as e:
# This is just an error message.
log.warning(str(e))
except plugins.NoSuitableDatabase as e:
s = 'Failed to load %s: no suitable database(%s).' % (
name, e)
log.warning(s)
except ImportError as e:
e = str(e)
if e.endswith(name):
s = 'Failed to load {0}: No plugin named {0} exists.'.format(
utils.str.dqrepr(name))
elif "No module named 'config'" in e:
s = (
"Failed to load %s: This plugin may be incompatible "
"with your current Python version. If this error is appearing "
"with stock Supybot plugins, remove the stock plugins directory "
"(usually ~/Limnoria/plugins) from 'config directories.plugins'." %
name)
else:
s = 'Failed to load %s: import error (%s).' % (
name, e)
log.warning(s)
except Exception as e:
log.exception('Failed to load %s:', name)
else:
# Let's import the module so configuration is preserved.
try:
_ = plugin.loadPluginModule(name)
except Exception as e:
log.debug('Attempted to load %s to preserve its '
'configuration, but load failed: %s',
name, e)
world.starting = False