From 523e485414d16c836509063a85d189f95ad79fb8 Mon Sep 17 00:00:00 2001 From: kongr45gpen Date: Tue, 23 Jul 2013 23:53:29 +0300 Subject: Tidy up a bit --- plugin.py | 115 ++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 66 insertions(+), 49 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 301b251..cd6c445 100644 --- a/plugin.py +++ b/plugin.py @@ -1,4 +1,5 @@ -### +#!/usr/bin/python +# -*- coding: utf-8 -*- import random import json @@ -12,69 +13,85 @@ import supybot.plugins as plugins import supybot.ircutils as ircutils import supybot.callbacks as callbacks + class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): - def do_POST(s): - """Respond to a POST request.""" - length = int(s.headers['Content-Length']) - data = json.loads(s.rfile.read(length).decode('utf-8')) - - s.send_response(200) - s.send_header("Content-type", "text/html") - s.end_headers() - s.wfile.write("Hello") - s.wfile.write("

Thanks, you're great.

") - #s.wfile.write("

POST: You accessed path: %s

" % s.path) - s.wfile.write("") - s.wfile.write(vars(s)) - print json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')) + + def do_POST(s): + """Respond to a POST request.""" + + length = int(s.headers['Content-Length']) + data = json.loads(s.rfile.read(length).decode('utf-8')) + + s.send_response(200) + s.send_header('Content-type', 'text/html') + s.end_headers() + s.wfile.write('Hello') + s.wfile.write("

Thanks, you're great.

") + + s.wfile.write('') + s.wfile.write(vars(s)) + print json.dumps(data, sort_keys=True, indent=4, separators=(',' + , ': ')) + class Github(callbacks.Plugin): - """Add the help for "@plugin help Github" here + + """Add the help for \"@plugin help Github\" here This should describe how to use this plugin.""" + threaded = True pass - def ServerStart(main,httpd,irc): - try: - print time.asctime(), "Server Starts - %s:%s" % ('', 8093) - httpd.serve_forever() - except: + def ServerStart(main, httpd, irc): + try: + print time.asctime(), 'Server Starts - %s:%s' % ('', 8093) + httpd.serve_forever() + except: return def __init__(self, irc): - self.__parent = super(Github, self) - self.__parent.__init__(irc) - self.rng = random.Random() # create our rng - self.rng.seed() # automatically seeds with current time - server_class = BaseHTTPServer.HTTPServer - self.httpd = server_class(('', 8093), GithubHandler) - t = threading.Thread(target=self.ServerStart,args=(self.httpd,irc)) - t.daemon = False - t.start() - - + self.__parent = super(Github, self) + self.__parent.__init__(irc) + self.rng = random.Random() # create our rng + self.rng.seed() # automatically seeds with current time + server_class = BaseHTTPServer.HTTPServer + self.httpd = server_class(('', 8093), GithubHandler) + t = threading.Thread(target=self.ServerStart, args=(self.httpd, + irc)) + t.daemon = False + t.start() + def __call__(self, irc, msg): - self.__parent.__call__(irc, msg) - print "I have no idea what is happeninig" - + self.__parent.__call__(irc, msg) + print 'I have no idea what is happeninig' + def die(self): - print "OH NOES IM DYING" - self.httpd.server_close() - self.__parent.die() + print 'OH NOES IM DYING' + self.httpd.server_close() + self.__parent.die() - def toast(self, irc, msg, args, seed, items): - """ [ ...] + def toast( + self, + irc, + msg, + args, + seed, + items, + ): + """ [ ...] - Returns the next random number from the random number generator. - """ - if seed < len(items): - irc.error(' must be less than the number of arguments.') - return - irc.reply(str(seed) + str(self.rng.random()) + utils.str.commaAndify(items)) - toast = wrap(toast,['float', many('anything')]) +........Returns the next random number from the random number generator. +........""" + if seed < len(items): + irc.error(' must be less than the number of arguments.' + ) + return + irc.reply(str(seed) + str(self.rng.random()) + + utils.str.commaAndify(items)) + + toast = wrap(toast, ['float', many('anything')]) -Class = Github +Class = Github -# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: -- cgit v1.2.3