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
|
delay = 0.100 # seconds
|
||||||
|
|
||||||
basedir = '.'
|
basedir = '.'
|
||||||
if 2 == len(sys.argv): basedir = sys.argv[1]
|
if 2 == len(sys.argv):
|
||||||
|
basedir = sys.argv[1]
|
||||||
|
|
||||||
def debug_enabled():
|
def debug_enabled():
|
||||||
# return True
|
# return True
|
||||||
|
|||||||
@@ -2,9 +2,13 @@
|
|||||||
|
|
||||||
import time, sys
|
import time, sys
|
||||||
|
|
||||||
def _logger(a, b): sys.stderr.write('logger: %s::%s\n' %(a, b))
|
def _logger(a, b):
|
||||||
try: logger
|
sys.stderr.write('logger: %s::%s\n' %(a, b))
|
||||||
except NameError: logger = _logger
|
|
||||||
|
try:
|
||||||
|
logger
|
||||||
|
except NameError:
|
||||||
|
logger = _logger
|
||||||
|
|
||||||
if '__main__' == __name__:
|
if '__main__' == __name__:
|
||||||
print('''this is a config file, which is not meant to be executed''')
|
print('''this is a config file, which is not meant to be executed''')
|
||||||
@@ -26,8 +30,6 @@ config = {
|
|||||||
'uptime': -time.time(),
|
'uptime': -time.time(),
|
||||||
'request_counter': 0,
|
'request_counter': 0,
|
||||||
|
|
||||||
'path_event_files': 'event_files', # XXX obsolete
|
|
||||||
'path_cmdfifo': 'cmdfifo', # XXX obsolete
|
|
||||||
'persistent_storage': 'urlbot.persistent',
|
'persistent_storage': 'urlbot.persistent',
|
||||||
|
|
||||||
'url_blacklist': [
|
'url_blacklist': [
|
||||||
|
|||||||
61
plugins.py
61
plugins.py
@@ -117,7 +117,8 @@ def data_parse_other(msg):
|
|||||||
|
|
||||||
if 'args' in list(p.keys()):
|
if 'args' in list(p.keys()):
|
||||||
for a in p['args']:
|
for a in p['args']:
|
||||||
if None == a: continue
|
if None == a:
|
||||||
|
continue
|
||||||
|
|
||||||
if 'data' == a:
|
if 'data' == a:
|
||||||
args['data'] = data
|
args['data'] = data
|
||||||
@@ -157,7 +158,6 @@ def command_help(args):
|
|||||||
'ratelimit_class': RATE_GLOBAL
|
'ratelimit_class': RATE_GLOBAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cmd = None
|
cmd = None
|
||||||
flag = False
|
flag = False
|
||||||
|
|
||||||
@@ -219,8 +219,7 @@ def command_klammer(args):
|
|||||||
if 'klammer' in args['data']:
|
if 'klammer' in args['data']:
|
||||||
logger('plugin', 'sent karl klammer')
|
logger('plugin', 'sent karl klammer')
|
||||||
return {
|
return {
|
||||||
'msg':
|
'msg': (
|
||||||
(
|
|
||||||
args['reply_user'] + r''': _, Was moechten''',
|
args['reply_user'] + r''': _, Was moechten''',
|
||||||
args['reply_user'] + r''': ( _\_ Sie tun?''',
|
args['reply_user'] + r''': ( _\_ Sie tun?''',
|
||||||
args['reply_user'] + r''': \0 O\ ''',
|
args['reply_user'] + r''': \0 O\ ''',
|
||||||
@@ -242,8 +241,7 @@ def command_unicode(args):
|
|||||||
if 'unikot' in args['data']:
|
if 'unikot' in args['data']:
|
||||||
logger('plugin', 'sent some unicode')
|
logger('plugin', 'sent some unicode')
|
||||||
return {
|
return {
|
||||||
'msg':
|
'msg': (
|
||||||
(
|
|
||||||
args['reply_user'] + ''': ┌────────┐''',
|
args['reply_user'] + ''': ┌────────┐''',
|
||||||
args['reply_user'] + ''': │Unicode!│''',
|
args['reply_user'] + ''': │Unicode!│''',
|
||||||
args['reply_user'] + ''': └────────┘'''
|
args['reply_user'] + ''': └────────┘'''
|
||||||
@@ -301,8 +299,10 @@ def command_uptime(args):
|
|||||||
plural_uptime = 's'
|
plural_uptime = 's'
|
||||||
plural_request = 's'
|
plural_request = 's'
|
||||||
|
|
||||||
if 1 == u: plural_uptime = ''
|
if 1 == u:
|
||||||
if 1 == conf('request_counter'): plural_request = ''
|
plural_uptime = ''
|
||||||
|
if 1 == conf('request_counter'):
|
||||||
|
plural_request = ''
|
||||||
|
|
||||||
logger('plugin', 'sent statistics')
|
logger('plugin', 'sent statistics')
|
||||||
return {
|
return {
|
||||||
@@ -491,7 +491,8 @@ def data_parse_commands(msg):
|
|||||||
|
|
||||||
if 'args' in list(p.keys()):
|
if 'args' in list(p.keys()):
|
||||||
for a in p['args']:
|
for a in p['args']:
|
||||||
if None == a: continue
|
if None == a:
|
||||||
|
continue
|
||||||
|
|
||||||
if 'data' == a:
|
if 'data' == a:
|
||||||
args['data'] = data
|
args['data'] = data
|
||||||
@@ -551,19 +552,37 @@ funcs['command'] = (
|
|||||||
_dir = dir()
|
_dir = dir()
|
||||||
|
|
||||||
if debug_enabled():
|
if debug_enabled():
|
||||||
def _chat_write(a): logger('chat_write', a)
|
def _chat_write(a):
|
||||||
def _conf(a): return 'bot'
|
logger('chat_write', a)
|
||||||
def _ratelimit_exceeded(ignored=None): return False
|
|
||||||
def _ratelimit_touch(ignored=None): return True
|
|
||||||
|
|
||||||
try: chat_write
|
def _conf(a):
|
||||||
except NameError: chat_write = _chat_write
|
return 'bot'
|
||||||
try: conf
|
|
||||||
except NameError: conf = _conf
|
def _ratelimit_exceeded(ignored=None):
|
||||||
try: ratelimit_exceeded
|
return False
|
||||||
except NameError: ratelimit_exceeded = _ratelimit_exceeded
|
|
||||||
try: ratelimit_touch
|
def _ratelimit_touch(ignored=None):
|
||||||
except NameError: ratelimit_touch = _ratelimit_touch
|
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')
|
logger('info', 'debugging enabled')
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,10 @@ def sum_array(array):
|
|||||||
|
|
||||||
def wrapper_print(a, b, comment=''):
|
def wrapper_print(a, b, comment=''):
|
||||||
ret = str_sim(a, b, do_print=True)
|
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))
|
print('[%2dx%2d::%2d]%s' %(len(ret), len(ret[0]), sum_array(ret), comment))
|
||||||
|
|
||||||
if '__main__' == __name__:
|
if '__main__' == __name__:
|
||||||
|
|||||||
@@ -14,4 +14,3 @@ class TestEventlooper(unittest.TestCase):
|
|||||||
broken_url = 'http://foo'
|
broken_url = 'http://foo'
|
||||||
result = fetch_page(url=broken_url)
|
result = fetch_page(url=broken_url)
|
||||||
self.assertEqual(result, (None, None))
|
self.assertEqual(result, (None, None))
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,10 @@ def extract_title(url):
|
|||||||
if 'text/' != headers['content-type'][:len('text/')]:
|
if 'text/' != headers['content-type'][:len('text/')]:
|
||||||
return (1, headers['content-type'])
|
return (1, headers['content-type'])
|
||||||
|
|
||||||
charset = re.sub('.*charset=(?P<charset>\S+).*',
|
charset = re.sub(
|
||||||
'\g<charset>', headers['content-type'], re.IGNORECASE)
|
'.*charset=(?P<charset>\S+).*',
|
||||||
|
'\g<charset>', headers['content-type'], re.IGNORECASE
|
||||||
|
)
|
||||||
|
|
||||||
if '' != charset:
|
if '' != charset:
|
||||||
try:
|
try:
|
||||||
@@ -304,6 +306,7 @@ if '__main__' == __name__:
|
|||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
|
# FIXME: find a way to trigger them
|
||||||
plugins.event_trigger()
|
plugins.event_trigger()
|
||||||
|
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
|
|||||||
Reference in New Issue
Block a user