mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
whitespace fixes according to pep8; cleanup
pep8 --ignore=W191,E225,E501,E401,E302,E122,E123 *.py
This commit is contained in:
@@ -18,7 +18,8 @@ BUFSIZ = 8192
|
||||
delay = 0.100 # seconds
|
||||
|
||||
basedir = '.'
|
||||
if 2 == len(sys.argv): basedir = sys.argv[1]
|
||||
if 2 == len(sys.argv):
|
||||
basedir = sys.argv[1]
|
||||
|
||||
def debug_enabled():
|
||||
# return True
|
||||
@@ -42,7 +43,7 @@ def conf_load():
|
||||
def levenshtein(a, b, return_table=False):
|
||||
'''returns the levenshtein distance between a and b'''
|
||||
# initialisize a table with 0, but the 0-rows/cols with their index
|
||||
d = [[ (i if 0 == j else j if 0 == i else 0) for j in range(len(b)+1) ] for i in range(len(a)+1) ]
|
||||
d = [[(i if 0 == j else j if 0 == i else 0) for j in range(len(b)+1)] for i in range(len(a)+1)]
|
||||
|
||||
i = j = 0
|
||||
for i in range(1, len(a)+1):
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
import time, sys
|
||||
|
||||
def _logger(a, b): sys.stderr.write('logger: %s::%s\n' %(a, b))
|
||||
try: logger
|
||||
except NameError: logger = _logger
|
||||
def _logger(a, b):
|
||||
sys.stderr.write('logger: %s::%s\n' %(a, b))
|
||||
|
||||
try:
|
||||
logger
|
||||
except NameError:
|
||||
logger = _logger
|
||||
|
||||
if '__main__' == __name__:
|
||||
print('''this is a config file, which is not meant to be executed''')
|
||||
@@ -26,8 +30,6 @@ config = {
|
||||
'uptime': -time.time(),
|
||||
'request_counter': 0,
|
||||
|
||||
'path_event_files': 'event_files', # XXX obsolete
|
||||
'path_cmdfifo': 'cmdfifo', # XXX obsolete
|
||||
'persistent_storage': 'urlbot.persistent',
|
||||
|
||||
'url_blacklist': [
|
||||
@@ -35,8 +37,8 @@ config = {
|
||||
r'^.*wikipedia\.org/wiki/.*$'
|
||||
],
|
||||
|
||||
# the "dice" feature will use more efficient random data (0) for given users
|
||||
'enhanced-random-user': ( 'FIXME', 'FIXME' ),
|
||||
# the "dice" feature will use more efficient random data (0) for given users
|
||||
'enhanced-random-user': ('FIXME', 'FIXME'),
|
||||
|
||||
'tea_steep_time': (3*60 + 40),
|
||||
|
||||
|
||||
61
plugins.py
61
plugins.py
@@ -117,7 +117,8 @@ def data_parse_other(msg):
|
||||
|
||||
if 'args' in list(p.keys()):
|
||||
for a in p['args']:
|
||||
if None == a: continue
|
||||
if None == a:
|
||||
continue
|
||||
|
||||
if 'data' == a:
|
||||
args['data'] = data
|
||||
@@ -157,7 +158,6 @@ def command_help(args):
|
||||
'ratelimit_class': RATE_GLOBAL
|
||||
}
|
||||
|
||||
|
||||
cmd = None
|
||||
flag = False
|
||||
|
||||
@@ -219,8 +219,7 @@ def command_klammer(args):
|
||||
if 'klammer' in args['data']:
|
||||
logger('plugin', 'sent karl klammer')
|
||||
return {
|
||||
'msg':
|
||||
(
|
||||
'msg': (
|
||||
args['reply_user'] + r''': _, Was moechten''',
|
||||
args['reply_user'] + r''': ( _\_ Sie tun?''',
|
||||
args['reply_user'] + r''': \0 O\ ''',
|
||||
@@ -242,8 +241,7 @@ def command_unicode(args):
|
||||
if 'unikot' in args['data']:
|
||||
logger('plugin', 'sent some unicode')
|
||||
return {
|
||||
'msg':
|
||||
(
|
||||
'msg': (
|
||||
args['reply_user'] + ''': ┌────────┐''',
|
||||
args['reply_user'] + ''': │Unicode!│''',
|
||||
args['reply_user'] + ''': └────────┘'''
|
||||
@@ -301,8 +299,10 @@ def command_uptime(args):
|
||||
plural_uptime = 's'
|
||||
plural_request = 's'
|
||||
|
||||
if 1 == u: plural_uptime = ''
|
||||
if 1 == conf('request_counter'): plural_request = ''
|
||||
if 1 == u:
|
||||
plural_uptime = ''
|
||||
if 1 == conf('request_counter'):
|
||||
plural_request = ''
|
||||
|
||||
logger('plugin', 'sent statistics')
|
||||
return {
|
||||
@@ -491,7 +491,8 @@ def data_parse_commands(msg):
|
||||
|
||||
if 'args' in list(p.keys()):
|
||||
for a in p['args']:
|
||||
if None == a: continue
|
||||
if None == a:
|
||||
continue
|
||||
|
||||
if 'data' == a:
|
||||
args['data'] = data
|
||||
@@ -551,19 +552,37 @@ funcs['command'] = (
|
||||
_dir = dir()
|
||||
|
||||
if debug_enabled():
|
||||
def _chat_write(a): logger('chat_write', a)
|
||||
def _conf(a): return 'bot'
|
||||
def _ratelimit_exceeded(ignored=None): return False
|
||||
def _ratelimit_touch(ignored=None): return True
|
||||
def _chat_write(a):
|
||||
logger('chat_write', a)
|
||||
|
||||
try: chat_write
|
||||
except NameError: chat_write = _chat_write
|
||||
try: conf
|
||||
except NameError: conf = _conf
|
||||
try: ratelimit_exceeded
|
||||
except NameError: ratelimit_exceeded = _ratelimit_exceeded
|
||||
try: ratelimit_touch
|
||||
except NameError: ratelimit_touch = _ratelimit_touch
|
||||
def _conf(a):
|
||||
return 'bot'
|
||||
|
||||
def _ratelimit_exceeded(ignored=None):
|
||||
return False
|
||||
|
||||
def _ratelimit_touch(ignored=None):
|
||||
return True
|
||||
|
||||
try:
|
||||
chat_write
|
||||
except NameError:
|
||||
chat_write = _chat_write
|
||||
|
||||
try:
|
||||
conf
|
||||
except NameError:
|
||||
conf = _conf
|
||||
|
||||
try:
|
||||
ratelimit_exceeded
|
||||
except NameError:
|
||||
ratelimit_exceeded = _ratelimit_exceeded
|
||||
|
||||
try:
|
||||
ratelimit_touch
|
||||
except NameError:
|
||||
ratelimit_touch = _ratelimit_touch
|
||||
|
||||
logger('info', 'debugging enabled')
|
||||
|
||||
|
||||
@@ -41,7 +41,10 @@ def sum_array(array):
|
||||
|
||||
def wrapper_print(a, b, comment=''):
|
||||
ret = str_sim(a, b, do_print=True)
|
||||
if '' != comment: comment = ' ^ ' + comment
|
||||
|
||||
if '' != comment:
|
||||
comment = ' ^ ' + comment
|
||||
|
||||
print('[%2dx%2d::%2d]%s' %(len(ret), len(ret[0]), sum_array(ret), comment))
|
||||
|
||||
if '__main__' == __name__:
|
||||
|
||||
@@ -14,4 +14,3 @@ class TestEventlooper(unittest.TestCase):
|
||||
broken_url = 'http://foo'
|
||||
result = fetch_page(url=broken_url)
|
||||
self.assertEqual(result, (None, None))
|
||||
|
||||
|
||||
@@ -71,8 +71,10 @@ def extract_title(url):
|
||||
if 'text/' != headers['content-type'][:len('text/')]:
|
||||
return (1, headers['content-type'])
|
||||
|
||||
charset = re.sub('.*charset=(?P<charset>\S+).*',
|
||||
'\g<charset>', headers['content-type'], re.IGNORECASE)
|
||||
charset = re.sub(
|
||||
'.*charset=(?P<charset>\S+).*',
|
||||
'\g<charset>', headers['content-type'], re.IGNORECASE
|
||||
)
|
||||
|
||||
if '' != charset:
|
||||
try:
|
||||
@@ -304,6 +306,7 @@ if '__main__' == __name__:
|
||||
|
||||
while 1:
|
||||
try:
|
||||
# FIXME: find a way to trigger them
|
||||
plugins.event_trigger()
|
||||
|
||||
time.sleep(delay)
|
||||
|
||||
Reference in New Issue
Block a user