def __init__(self, config, debug): logging.basicConfig(level=getattr(logging, config['logging']['level'].upper(), None), format=config['logging']['format'], datefmt=config['logging']['datetime'], filename=config['logging']['filename']) self.luhn = Luhn(config['apps']['identity']['salts']) self.auth = self.luhn.make(1) self.__dict__.update({ 'log': logging.getLogger('jbot'), 'store': self._connect(config['mongodb']), 'config': config, 'user': '******' % (self.auth['uid'], config["xmpp"]["host"]), 'token': self.auth['access_token'] }) self._init(debug)
def __init__(self, config, debug): logging.basicConfig( level = getattr(logging, config['logging']['level'].upper(), None), format = config['logging']['format'], datefmt = config['logging']['datetime'], filename = config['logging']['filename'] ) self.luhn = Luhn(config['apps']['identity']['salts']) self.auth = self.luhn.make(1) self.__dict__.update({ 'log': logging.getLogger('jbot'), 'store': self._connect(config['mongodb']), 'config': config, 'user': '******' % (self.auth['uid'], config["xmpp"]["host"]), 'token': self.auth['access_token'] }) self._init(debug)
class JBot(object): def __init__(self, config, debug): logging.basicConfig(level=getattr(logging, config['logging']['level'].upper(), None), format=config['logging']['format'], datefmt=config['logging']['datetime'], filename=config['logging']['filename']) self.luhn = Luhn(config['apps']['identity']['salts']) self.auth = self.luhn.make(1) self.__dict__.update({ 'log': logging.getLogger('jbot'), 'store': self._connect(config['mongodb']), 'config': config, 'user': '******' % (self.auth['uid'], config["xmpp"]["host"]), 'token': self.auth['access_token'] }) self._init(debug) def _init(self, debug): self._inbox = Queue(self.store.xmpp.inbox, self.log) self._outbox = Queue(self.store.xmpp[self.config["xmpp"]["user"]], self.log) #self._inbox.clear() self._outbox.timeout(-1) JID = xmpp.JID(self.user) self.connection = xmpp.Client(JID.getDomain(), debug=debug) server = self.config["xmpp"]["server"] port = int(self.config["xmpp"]["port"]) if self.connection.connect((server, port)) == '': self.log.error('Cannot connect to server %s port %d' % (server, port)) sys.exit(1) if self.connection.auth(JID.getNode(), self.token, self.user + '-') == None: self.log.error('Authentication %s failed!' % self.user) sys.exit(1) self.connection.RegisterDisconnectHandler( self.connection.reconnectAndReauth()) self.connection.RegisterHandler('message', self.receive) self.connection.getRoster() self.connection.sendInitPresence() def _connect(self, config): try: client = pymongo.MongoClient(config["host"], config["port"]) except pymongo.errors.ConnectionFailure, messages: print 'Error:', messages sys.exit(1) if config["auth"]: auth = client[config["auth_db"]] try: auth.authenticate(config["user"], config["passwd"]) except KeyError: print 'KeyError: Not authenticating!' sys.exit(1) return client
class JBot(object): def __init__(self, config, debug): logging.basicConfig( level = getattr(logging, config['logging']['level'].upper(), None), format = config['logging']['format'], datefmt = config['logging']['datetime'], filename = config['logging']['filename'] ) self.luhn = Luhn(config['apps']['identity']['salts']) self.auth = self.luhn.make(1) self.__dict__.update({ 'log': logging.getLogger('jbot'), 'store': self._connect(config['mongodb']), 'config': config, 'user': '******' % (self.auth['uid'], config["xmpp"]["host"]), 'token': self.auth['access_token'] }) self._init(debug) def _init(self, debug): self._inbox = Queue(self.store.xmpp.inbox, self.log) self._outbox = Queue(self.store.xmpp[self.config["xmpp"]["user"]], self.log) #self._inbox.clear() self._outbox.timeout(-1) JID = xmpp.JID(self.user) self.connection = xmpp.Client(JID.getDomain(), debug=debug) server = self.config["xmpp"]["server"] port = int(self.config["xmpp"]["port"]) if self.connection.connect((server, port)) == '': self.log.error('Cannot connect to server %s port %d' % (server, port)) sys.exit(1) if self.connection.auth( JID.getNode(), self.token, self.user + '-' ) == None: self.log.error('Authentication %s failed!' % self.user) sys.exit(1) self.connection.RegisterDisconnectHandler(self.connection.reconnectAndReauth()) self.connection.RegisterHandler('message', self.receive) self.connection.getRoster() self.connection.sendInitPresence() def _connect(self, config): try: client = pymongo.MongoClient( config["host"], config["port"] ) except pymongo.errors.ConnectionFailure, messages: print 'Error:', messages sys.exit(1) if config["auth"]: auth = client[config["auth_db"]] try: auth.authenticate(config["user"], config["passwd"]) except KeyError: print 'KeyError: Not authenticating!' sys.exit(1) return client