pylint; whitespace cleanup

This commit is contained in:
urlbot
2015-08-21 23:36:25 +02:00
parent 5f27fea8fc
commit 29aa2b4872
2 changed files with 33 additions and 33 deletions

View File

@@ -57,7 +57,7 @@ def plugin_enabled_set(plugin, enabled):
return True return True
def pluginfunction(name, desc, plugin_type, ratelimit_class = RATE_GLOBAL, enabled = True): def pluginfunction(name, desc, plugin_type, ratelimit_class=RATE_GLOBAL, enabled=True):
''' A decorator to make a plugin out of a function ''' ''' A decorator to make a plugin out of a function '''
if plugin_type not in ptypes: if plugin_type not in ptypes:
raise TypeError('Illegal plugin_type: %s' % plugin_type) raise TypeError('Illegal plugin_type: %s' % plugin_type)
@@ -75,7 +75,7 @@ def pluginfunction(name, desc, plugin_type, ratelimit_class = RATE_GLOBAL, enabl
def register_event(t, callback, args): def register_event(t, callback, args):
joblist.append((t, callback, args)) joblist.append((t, callback, args))
@pluginfunction('mental_ill', 'parse mental illness', ptypes_PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL) @pluginfunction('mental_ill', 'parse mental illness', ptypes_PARSE, ratelimit_class=RATE_NO_SILENCE | RATE_GLOBAL)
def parse_mental_ill(**args): def parse_mental_ill(**args):
min_ill = 3 min_ill = 3
c = 0 c = 0
@@ -87,7 +87,7 @@ def parse_mental_ill(**args):
c += 1 c += 1
else: else:
c = 0 c = 0
if (min_ill <= c): if min_ill <= c:
flag = True flag = True
break break
@@ -97,7 +97,7 @@ def parse_mental_ill(**args):
'msg': '''Multiple exclamation/question marks are a sure sign of mental disease, with %s as a living example.''' % args['reply_user'] 'msg': '''Multiple exclamation/question marks are a sure sign of mental disease, with %s as a living example.''' % args['reply_user']
} }
@pluginfunction('debbug', 'parse Debian bug numbers', ptypes_PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL) @pluginfunction('debbug', 'parse Debian bug numbers', ptypes_PARSE, ratelimit_class=RATE_NO_SILENCE | RATE_GLOBAL)
def parse_debbug(**args): def parse_debbug(**args):
bugs = re.findall(r'#(\d{4,})', args['data']) bugs = re.findall(r'#(\d{4,})', args['data'])
if not bugs: if not bugs:
@@ -121,7 +121,7 @@ def parse_debbug(**args):
'msg': out 'msg': out
} }
@pluginfunction('cve', 'parse a CVE handle', ptypes_PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL) @pluginfunction('cve', 'parse a CVE handle', ptypes_PARSE, ratelimit_class=RATE_NO_SILENCE | RATE_GLOBAL)
def parse_cve(**args): def parse_cve(**args):
cves = re.findall(r'(CVE-\d\d\d\d-\d+)', args['data'].upper()) cves = re.findall(r'(CVE-\d\d\d\d-\d+)', args['data'].upper())
if not cves: if not cves:
@@ -132,7 +132,7 @@ def parse_cve(**args):
'msg': ['https://security-tracker.debian.org/tracker/%s' % c for c in cves] 'msg': ['https://security-tracker.debian.org/tracker/%s' % c for c in cves]
} }
@pluginfunction('dsa', 'parse a DSA handle', ptypes_PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL) @pluginfunction('dsa', 'parse a DSA handle', ptypes_PARSE, ratelimit_class=RATE_NO_SILENCE | RATE_GLOBAL)
def parse_dsa(**args): def parse_dsa(**args):
dsas = re.findall(r'(DSA-\d\d\d\d-\d+)', args['data'].upper()) dsas = re.findall(r'(DSA-\d\d\d\d-\d+)', args['data'].upper())
if not dsas: if not dsas:
@@ -333,7 +333,7 @@ def command_source(argv, **args):
'msg': 'My source code can be found at %s' % conf('src-url') 'msg': 'My source code can be found at %s' % conf('src-url')
} }
@pluginfunction('dice', 'rolls a dice, optional N times', ptypes_COMMAND, ratelimit_class = RATE_INTERACTIVE) @pluginfunction('dice', 'rolls a dice, optional N times', ptypes_COMMAND, ratelimit_class=RATE_INTERACTIVE)
def command_dice(argv, **args): def command_dice(argv, **args):
if 'dice' != argv[0]: if 'dice' != argv[0]:
return return
@@ -396,7 +396,7 @@ def command_uptime(argv, **args):
'msg': args['reply_user'] + (''': happily serving for %d second%s, %d request%s so far.''' % (u, plural_uptime, conf('request_counter'), plural_request)) 'msg': args['reply_user'] + (''': happily serving for %d second%s, %d request%s so far.''' % (u, plural_uptime, conf('request_counter'), plural_request))
} }
@pluginfunction('ping', 'sends pong', ptypes_COMMAND, ratelimit_class = RATE_INTERACTIVE) @pluginfunction('ping', 'sends pong', ptypes_COMMAND, ratelimit_class=RATE_INTERACTIVE)
def command_ping(argv, **args): def command_ping(argv, **args):
if 'ping' != argv[0]: if 'ping' != argv[0]:
return return
@@ -870,7 +870,7 @@ def command_dsa_watcher(argv, **args):
if 2 != len(argv): if 2 != len(argv):
msg = 'wrong number of arguments' msg = 'wrong number of arguments'
log.warn(msg) log.warn(msg)
return { 'msg': msg } return {'msg': msg}
if 'crawl' == argv[1]: if 'crawl' == argv[1]:
out = [] out = []
@@ -936,11 +936,11 @@ def command_dsa_watcher(argv, **args):
msg = 'next crawl set to %s' % time.strftime('%F.%T', time.localtime(crawl_at)) msg = 'next crawl set to %s' % time.strftime('%F.%T', time.localtime(crawl_at))
log.plugin(msg) log.plugin(msg)
out.append(msg) out.append(msg)
return { 'msg': out } return {'msg': out}
else: else:
msg = 'wrong argument' msg = 'wrong argument'
log.warn(msg) log.warn(msg)
return { 'msg': msg } return {'msg': msg}
#@pluginfunction('dummy', 'dummy description', ptypes_COMMAND) #@pluginfunction('dummy', 'dummy description', ptypes_COMMAND)
#def command_dummy(argv, **args): #def command_dummy(argv, **args):
@@ -988,12 +988,12 @@ def data_parse_commands(msg_obj):
continue continue
ret = p( ret = p(
data = data, data=data,
cmd_list = [pl.plugin_name for pl in plugins[ptypes_COMMAND]], cmd_list=[pl.plugin_name for pl in plugins[ptypes_COMMAND]],
parser_list = [pl.plugin_name for pl in plugins[ptypes_PARSE]], parser_list=[pl.plugin_name for pl in plugins[ptypes_PARSE]],
reply_user = reply_user, reply_user=reply_user,
msg_obj = msg_obj, msg_obj=msg_obj,
argv = words[1:] argv=words[1:]
) )
if None != ret: if None != ret:

View File

@@ -69,8 +69,8 @@ def extract_title(url):
return (1, headers['content-type']) return (1, headers['content-type'])
charset = re.sub( charset = re.sub(
'.*charset=(?P<charset>\S+).*', r'.*charset=(?P<charset>\S+).*',
'\g<charset>', headers['content-type'], re.IGNORECASE r'\g<charset>', headers['content-type'], re.IGNORECASE
) )
if '' != charset: if '' != charset:
@@ -109,16 +109,16 @@ def send_reply(message, msg_obj=None):
else: else:
if msg_obj: if msg_obj:
xmpp.send_message( xmpp.send_message(
mto = msg_obj['from'].bare, mto=msg_obj['from'].bare,
mbody = message, mbody=message,
mtype = 'groupchat' mtype='groupchat'
) )
else: # unset msg_obj == broadcast else: # unset msg_obj == broadcast
for room in xmpp.rooms: for room in xmpp.rooms:
xmpp.send_message( xmpp.send_message(
mto = room, mto=room,
mbody = message, mbody=message,
mtype = 'groupchat' mtype='groupchat'
) )
def ratelimit_touch(ignored=None): # FIXME: separate counters def ratelimit_touch(ignored=None): # FIXME: separate counters
@@ -145,7 +145,7 @@ def ratelimit_exceeded(ignored=None): # FIXME: separate counters
return False return False
def extract_url(data, msg_obj): def extract_url(data, msg_obj):
result = re.findall("(https?://[^\s>]+)", data) result = re.findall(r'(https?://[^\s>]+)', data)
if not result: if not result:
return return
@@ -189,7 +189,7 @@ def extract_url(data, msg_obj):
elif 1 == status: elif 1 == status:
if conf('image_preview'): if conf('image_preview'):
# of course it's fake, but it looks interesting at least # of course it's fake, but it looks interesting at least
char = """,._-+=\|/*`~"'""" char = r""",._-+=\|/*`~"'"""
message = 'No text but %s, 1-bit ASCII art preview: [%c]' % ( message = 'No text but %s, 1-bit ASCII art preview: [%c]' % (
title, random.choice(char) title, random.choice(char)
) )