def mini(response, input={}): """ display start html so that bot output can follow. """ inputdict = LazyDict({'version': getversion()}) if input: inputdict.update(input) temp = os.path.join(os.getcwd(), 'templates/mini.html') outstr = template.render(temp) response.out.write(outstr)
def options(self): self.response.headers.add_header('Content-Type', 'application/x-www-form-urlencoded') #self.response.headers.add_header("Cache-Control", "private") self.response.headers.add_header("Server", getversion()) self.response.headers.add_header("Public", "*") self.response.headers.add_header('Accept', '*') self.response.headers.add_header('Access-Control-Allow-Origin', self.request.headers['Origin']) self.response.out.write("Allow: *") self.response.out.write('Access-Control-Allow-Origin: *') logging.warn("dispatch - options response send to %s - %s" % (self.request.remote_addr, str(self.request.headers)))
def login(response, input={}): """ display start html so that bot output can follow. """ try: host = socket.gethostname() except AttributeError: if os.environ.get('HTTP_HOST'): host = os.environ['HTTP_HOST'] else: host = os.environ['SERVER_NAME'] template = LazyDict({'version': getversion(), 'host': host, 'color': Config().color or "#C54848"}) if input: template.update(input) temp = os.path.join(os.getcwd(), 'templates/login.html') outstr = template.render(temp) response.out.write(outstr)
def get(self): try: cont = self.request.get('continue') logging.info('openid - login form %s' % cont) urlstring = self.create_openid_url(cont) template_values = LazyDict({ 'continue': cont, 'urlstring': urlstring, 'appname': getversion() }) try: host = socket.gethostname() except AttributeError: if os.environ.get('HTTP_HOST'): host = os.environ['HTTP_HOST'] else: host = os.environ['SERVER_NAME'] inputdict = {'version': getversion(), 'host': host} template_values.update(inputdict) temp = os.path.join(os.getcwd(), 'templates/login.html') outstr = template_values.render(temp) self.response.out.write(outstr) except Exception, ex: handle_exception()
## jsb imports from jsb.lib.version import getversion from jsb.lib.errors import NoSuchCommand from jsb.lib.boot import boot ## gaelib imports from jsb.lib.gae.wave.bot import WaveBot ## basic imports import logging import os ## defines logging.info(getversion('GAE WAVE')) boot() # the bot bot = WaveBot(domain="googlewave.com") def main(): bot.run() if __name__ == "__main__": main()
from waveapi.simplejson import loads ## basic imports import wsgiref.handlers import logging import google ## vars periodicals = ['jsb.plugs.common.rss', 'jsb.plugs.core.botevent'] mountpoints = ['rss', 'botevent'] ## logging.info(getversion('TASK')) for plugin in periodicals: plugs.reload(plugin) class TaskHandler(webapp.RequestHandler): """ the bots task handler. """ def get(self): try: """ this is where the task gets dispatched. """ path = self.request.path if path.endswith('/'): path = path[:-1]
from jsb.lib.version import getversion ## google imports import webapp2 ## basic imports import sys import time import types import logging ## greet logging.warn(getversion('WARMUP')) ## classes class WarmupHandler(webapp2.RequestHandler): def get(self, url=None): logging.warn("warmup") post = get application = webapp2.WSGIApplication([webapp2.Route(r'<url:.*>', WarmupHandler)], debug=True) def main(): global application
from jsb.lib.version import getversion ## google imports import webapp2 ## basic imports import sys import time import types import logging ## greet logging.warn(getversion('REDIRECT')) ## classes class DocsHandler(webapp2.RequestHandler): def get(self, url=None): try: if not url.endswith(".html"): if not url.endswith('/'): url += u"/index.html" else: url += u"index.html" splitted = url.split('/') splitted.insert(2, 'html') goto = '/'.join(splitted)
from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.api import users as gusers from google.appengine.ext import db from google.appengine.ext.webapp import xmpp_handlers ## basic imports import wsgiref.handlers import sys import time import types import logging ## boot logging.info(getversion('GAE XMPP')) boot() ## defines bot = XMPPBot() ## functions def xmppbox(response): response.out.write(""" <form action="/_ah/xmpp/message/chat/" method="post"> <div><b>enter command:</b> <input type="commit" name="body"> </form> """)
def handle_notice(self, ievent): """ handle notice event .. check for version request. """ if ievent.txt and ievent.txt.find('VERSION') != -1: from jsb.lib.version import getversion self.say(ievent.nick, getversion(), None, 'notice') return 1
def handle_version(bot, ievent): """ show bot's version. """ from jsb.lib.version import getversion ievent.reply(getversion(bot.type.upper()))
## google imports from webapp2 import RequestHandler, Route, WSGIApplication from google.appengine.api import users as gusers ## basic imports import sys import time import types import os import logging import google logging.warn(getversion('GAE DISPATCH')) bot = WebBot() class Dispatch_Handler(RequestHandler): """ the bots remote command dispatcher. """ def options(self): self.response.headers.add_header('Content-Type', 'application/x-www-form-urlencoded') #self.response.headers.add_header("Cache-Control", "private") self.response.headers.add_header("Server", getversion()) self.response.headers.add_header("Public", "*") self.response.headers.add_header('Accept', '*') self.response.headers.add_header('Access-Control-Allow-Origin', self.request.headers['Origin']) self.response.out.write("Allow: *")
## google imports from webapp2 import RequestHandler, Route, WSGIApplication from google.appengine.api import users as gusers ## basic imports import sys import time import types import os import logging import google logging.warn(getversion('GAE DISPATCH')) bot = WebBot() class Dispatch_Handler(RequestHandler): """ the bots remote command dispatcher. """ def options(self): self.response.headers.add_header('Content-Type', 'application/x-www-form-urlencoded') #self.response.headers.add_header("Cache-Control", "private") self.response.headers.add_header("Server", getversion()) self.response.headers.add_header("Public", "*") self.response.headers.add_header('Accept', '*') self.response.headers.add_header('Access-Control-Allow-Origin', self.request.headers['Origin'])
def makeircopts(txt=""): """ create commandline parser options. """ parser = optparse.OptionParser(usage='usage: %prog [options]', version=getversion()) parser.add_option('', '-r', type='string', default=False, dest='doresume', metavar='PATH', help="resume the bot from the folder specified") parser.add_option('-d', '--datadir', type='string', default=False, dest='datadir', help="datadir of the bot") parser.add_option('-o', '--owner', type='string', default=False, dest='owner', help="owner of the bot") parser.add_option('-s', '--server', type='string', default=False, dest='server', help="server to connect to (irc)") parser.add_option('-c', '--channel', type='string', default=False, dest='channel', help="channel to join") parser.add_option('-l', '--loglevel', type='string', default="", dest='loglevel', help="loglevel of the bot") parser.add_option('-p', '--password', type='string', default=False, dest='password', help="set password used to connect to the server") parser.add_option('', '--name', type='string', default=False, dest='name', help="bot's name") parser.add_option('', '--port', type='string', default=False, dest='port', help="set port of server to connect to") parser.add_option('', '--save', action='store_true', default=False, dest='save', help="save to config file") parser.add_option('-n', '--nick', type='string', default=False, dest='nick', help="nick of the bot") parser.add_option('', '--ssl', action='store_true', default=False, dest='ssl', help="use ssl") parser.add_option('-y', '--nossl', action='store_true', default=False, dest='nossl', help="don't use ssl") parser.add_option('-6', '--ipv6', action='store_true', default=False, dest='ipv6', help="enable ipv6 bot") if txt: opts, args = parser.parse_args(txt.split()) else: opts, args = parser.parse_args() opts.args = args return opts
def OnSelfAdded(self, event, wavelet): """ invoked when the robot has been added. """ logging.warn('wave - joined "%s" (%s) wave' % (wavelet._wave_id, wavelet._title)) wevent = WaveEvent() wevent.parse(self, event, wavelet) logging.debug("wave - owner is %s" % wevent.chan.data.owner) wevent.chan.data.json_data = wavelet.serialize() wevent.chan.save() wevent.reply("Welcome to %s (see !help) or http://jsonbot.appspot.com/docs/html/index.html" % getversion()) callbacks.check(self, wevent)
from google.appengine.api import urlfetch from google.appengine.api import xmpp from google.appengine.ext import db from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext.webapp import xmpp_handlers ## basic imports import base64 import logging import urllib import urlparse import uuid logging.warn(getversion('GAE HUBBUB')) if not plugs.has_key("jsb.plugs.common.hubbub"): p = plugs.load("jsb.plugs.common.hubbub") else: p = plugs["jsb.plugs.common.hubbub"] class CallbackHandler(webapp.RequestHandler): def get(self): logging.warn('hubbub - incoming GET') if self.request.GET['hub.mode'] == 'unsubscribe': self.response.headers['Content-Type'] = 'text/plain' self.response.out.write(self.request.GET['hub.challenge']) return