def __init__(self, userid, jid, password, useragent): """ Initially, :param userid: :param jid: :param displayname: :param password: :param useragent: """ xmpp.ClientXMPP.__init__(self, jid, password) self.password = password self.message_queue = queue.PriorityQueue() self.registration_status = 0 self.connection_status = 0 setdefaultencoding('utf8') logging.info("Beginning Registration") self.register_plugin('xep_0077') self.register_plugin('xep_0066') self.register_plugin('xep_0004') self.register_plugin('xep_0030') self['xep_0077'].force_registration = True self.add_event_handler("session_start", self.start, threaded=True) self.add_event_handler("register", self.register, threaded=True) self.add_event_handler("message", self.getmessage, threaded=True) dispatcher = {'send_messsage': self.sendmessage, 'test': self.test}
def main(args=None, _bot_cls=MucChatBot, _cmd_cls=JibberCmd): if args is None: args = sys.argv[1:] _default = 'console' parser, sp = get_argparsers() # workaround for python2.7's incorrect(?) default usage. # won't be needed in python3.3. if not set.intersection(set(args), set(sp.choices.keys())): args.append(_default) parsed_args = parser.parse_args(args) # Python versions before 3.0 do not use UTF-8 encoding # by default. To ensure that Unicode is handled properly # throughout SleekXMPP, we will set the default encoding # ourselves to UTF-8. if sys.version_info < (3, 0): # pragma: no cover from sleekxmpp.util.misc_ops import setdefaultencoding setdefaultencoding('utf8') bot = _bot_cls() if bot.load_server_config_from_path(parsed_args.server_config) is None: print("Server config file `%s` not found." % parsed_args.server_config) return if bot.load_client_config_from_path(parsed_args.client_config) is None: print("Client config file `%s` not found." % parsed_args.client_config) return c = _cmd_cls(bot) # TODO make these logging configurable from the client_config logging.basicConfig( level='INFO', format='%(asctime)s %(levelname)s %(name)s %(message)s' ) try: import readline except ImportError: # pragma: no cover pass if parsed_args.command and parsed_args.command != _default: cmdarg = getattr(parsed_args, 'cmdarg', '') return c.onecmd(parsed_args.command + ' ' + cmdarg) else: # interactive mode c.cmdloop()
# Channel 2 is the DHT Humidity Channel2_Sensor = Adafruit_DHT.DHT11 Channel2_GPIO = 23 # Channel 1 is the DHT Temperature Channel1_Sensor = Adafruit_DHT.DHT11 Channel1_GPIO = 23 # - Python versions before 3.0 do not use UTF-8 encoding # by default. To ensure that Unicode is handled properly # throughout SleekXMPP, we will set the default encoding # ourselves to UTF-8. if sys.version_info < (3, 0): from sleekxmpp.util.misc_ops import setdefaultencoding setdefaultencoding('utf8') else: raw_input = input ####################################################### # UART function def readlineCR(port): print 'ReadlineCR' ch = port.read() rv = '' n = 0 while (ch != '!') & (ch != '\r'): # & (ch!=''): rv += ch
#!/usr/bin/env python # -*- coding: utf-8 -*- import firenado.core import firenado.core.websocket import logging import tornado.escape import uuid import sys from diaspora_jetpack.handlers import JetpackHandler # Study this https://gist.github.com/mywaiting/4643396 if sys.version_info < (3, 0): from sleekxmpp.util.misc_ops import setdefaultencoding setdefaultencoding('utf8') else: raw_input = input class ChatHandler(firenado.core.TornadoHandler): def get(self): cache = [] if self.session.id in self.component.xmpp_manager.connections: cache = self.component.xmpp_manager.connections[ self.session.id]['cache'] self.render("jetpack:chat/demo.html", messages=cache) class ChatSocketHandler(firenado.core.websocket.TornadoWebSocketHandler, JetpackHandler):
from glob import glob from os.path import splitext, basename, join as pjoin from optparse import OptionParser from urllib import urlopen import sleekxmpp # Python versions before 3.0 do not use UTF-8 encoding # by default. To ensure that Unicode is handled properly # throughout SleekXMPP, we will set the default encoding # ourselves to UTF-8. if sys.version_info < (3, 0): from sleekxmpp.util.misc_ops import setdefaultencoding setdefaultencoding("utf8") else: raw_input = input from sleekxmpp.plugins.xep_0323.device import Device # from sleekxmpp.exceptions import IqError, IqTimeout class IoT_TestDevice(sleekxmpp.ClientXMPP): """ A simple IoT device that can act as server or client """ def __init__(self, jid, password):
import os import sys import sleekxmpp from bson import json_util from optparse import OptionParser runPath = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(runPath, "..")) from web.templates._old_.api import API if sys.version_info < (3, 0): from sleekxmpp.util.misc_ops import setdefaultencoding setdefaultencoding("utf8") else: raw_input = input rankinglookup = True helpmessage = ( "last [<n>] - last n cve entries (default: 10) (output: JSON)\n" ) helpmessage += "get <cve-id> - get cve info (output: JSON)\n" helpmessage += "browse - list of vendors (output: JSON)\n" helpmessage += "browse <vendor> - list of products of vendor (output: JSON)\n" helpmessage += "search <vendor> <product> - list of cves for product (output: JSON)\n" helpmessage += ( "cvetweet <n> - summary of <n> last cve entries (output: Text)\n" )