示例#1
0
    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()
示例#2
0
文件: bc.py 项目: espectro/JSON-XMPP
    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()
示例#3
0
        auth = client[config["auth_db"]]
        try:
            auth.authenticate(config["user"], config["passwd"])
        except KeyError:
            print 'KeyError: Not authenticating!'
            sys.exit(1)

    # make log
    logging.basicConfig(
        level=getattr(logging, 'DEBUG', None),
        format='%(asctime)s %(levelname)-8s %(name)-10s %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S',
        filename='/tmp/tc.log')
    log = logging.getLogger('qt'),

    db = client.xmpp
    q = Queue(client.xmpp['aaleksandrov'], log)
    msg = {
        "message": {
            "from": '*****@*****.**',
            "to": '*****@*****.**',
            "mime": 'plain/text',
            "content": 'It\'s 100% free, no registration required'
        }
    }
    q.add(msg)


if __name__ == "__main__":
    main()
示例#4
0
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
示例#5
0
文件: bc.py 项目: espectro/JSON-XMPP
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
示例#6
0
文件: qt.py 项目: espectro/JSON-XMPP
        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)

    # make log
    logging.basicConfig(
        level = getattr(logging, 'DEBUG', None),
        format = '%(asctime)s %(levelname)-8s %(name)-10s %(message)s',
        datefmt = '%Y-%m-%d %H:%M:%S',
        filename = '/tmp/tc.log'
    )
    log = logging.getLogger('qt'),
    
    db = client.xmpp
    q = Queue(client.xmpp['aaleksandrov'], log)
    msg = { "message": {
            "from"    : '*****@*****.**',
            "to"      : '*****@*****.**',
            "mime"    : 'plain/text',
            "content" : 'It\'s 100% free, no registration required'
        }}
    q.add(msg)

if __name__ == "__main__":
    main()