当前位置: 首页>>代码示例>>Python>>正文


Python XMPPClient.setServiceParent方法代码示例

本文整理汇总了Python中wokkel.client.XMPPClient.setServiceParent方法的典型用法代码示例。如果您正苦于以下问题:Python XMPPClient.setServiceParent方法的具体用法?Python XMPPClient.setServiceParent怎么用?Python XMPPClient.setServiceParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wokkel.client.XMPPClient的用法示例。


在下文中一共展示了XMPPClient.setServiceParent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: makeService

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
    def makeService(self, options):
        with open(options.config, "r") as config_file:
            config = json.load(config_file)

        root = resource.Resource()
        root.putChild('jsMath', static.File(config["global"]["jsmath"]))

        bot = service.MultiService()
        xmppclient = XMPPClient(JID(config["global"]["jid"]),
                                config["global"]["password"])
        xmppclient.logTraffic = options['verbose']
        xmppclient.setServiceParent(bot)
        xmppclient.dbpool = DatabaseRunner(config["global"]["database"])
        xmppclient.rooms = dict()

        xmlrpc_port = config["global"].get("xml-rpc-port", None)
        if xmlrpc_port is not None:
            xmlrpcinterface = XMLRPCInterface(xmppclient)
            rpc = internet.TCPServer(xmlrpc_port, server.Site(xmlrpcinterface))
            rpc.setName('XML-RPC')
            rpc.setServiceParent(bot)

        for muc_config in config["mucs"]:
            room_jid = JID(muc_config["jid"])
            mucbot = KITBot(room_jid, muc_config.get("password", None),
                            config["global"]["logpath"])
            mucbot.setHandlerParent(xmppclient)

            if "xml-rpc-id" in muc_config:
                xmppclient.rooms[muc_config["xml-rpc-id"]] = mucbot

            # Log resource
            portal = Portal(
                LogViewRealm(os.path.join(config["global"]['logpath'],
                                          room_jid.user + '.log')),
                [strcred.makeChecker(muc_config["log-auth"])]
            )
            credential_factory = DigestCredentialFactory('md5', 'Hello Kitty!')
            auth_resource = HTTPAuthSessionWrapper(portal, [credential_factory])
            root.putChild(room_jid.user, auth_resource)

        httpd_log_view = internet.TCPServer(config["global"]["http-port"],
                                            server.Site(root))
        httpd_log_view.setServiceParent(bot)

        # REPL over SSH
        def makeREPLProtocol():
            namespace = dict(bot=xmppclient)
            return insults.ServerProtocol(manhole.ColoredManhole, namespace)
        repl_realm = manhole_ssh.TerminalRealm()
        repl_realm.chainedProtocolFactory = makeREPLProtocol
        repl_checker = checkers.SSHPublicKeyDatabase()
        repl_portal = Portal(repl_realm, [repl_checker])
        repl_factory = manhole_ssh.ConchFactory(repl_portal)
        repl = internet.TCPServer(config["global"]["ssh-port"], repl_factory)
        repl.setServiceParent(bot)

        return bot
开发者ID:lorenzhs,项目名称:kitbot,代码行数:60,代码来源:kitbot_plugin.py

示例2: connect

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
    def connect(self):
        application = service.Application("gbot")

        xmppclient = XMPPClient(jid.internJID(self.username), self.password)
        xmppclient.logTraffic = False
        self.protocol = GBotProtocol()
        self.protocol.bot = self
        self.protocol.setHandlerParent(xmppclient)
        xmppclient.setServiceParent(application)
        return application
开发者ID:B-Rich,项目名称:Watson,代码行数:12,代码来源:gbot.py

示例3: connect

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
    def connect(self):
        application = service.Application('UniblabXMPP')

        xmppclient = XMPPClient(jid.internJID(self.xmpp_user), self.xmpp_pass)
        self.client=UniblabXMPPProtocol()
        self.client.transport = self
        self.client.setHandlerParent(xmppclient)
        xmppclient.setServiceParent(application)

        xmppclient.startService()
开发者ID:hogrewe,项目名称:uniblab,代码行数:12,代码来源:xmpp_transport.py

示例4: setupConnection

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
    def setupConnection(self):
        xmppclient = XMPPClient(self.jid, self.password, self.jabber_server)
        xmppclient.logTraffic = False

        xmppbot = XMPPCassBot(self, self.state['nickname'])
        xmppbot.conference_server = self.conference_server
        xmppbot.setHandlerParent(xmppclient)

        xmppclient.setServiceParent(self)

        self.xmppbot = xmppbot
        self.xmppclient = xmppclient
开发者ID:joaquincasares,项目名称:cassbot,代码行数:14,代码来源:xmppbot.py

示例5: makeService

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
    def makeService(self, options):
        """
        Make services to handle push event notifications.
        """
        # check confguration file is specified and exists
        if not options["config"]:
            raise ValueError('Configuration file not specified (try to check --help option)')
        cfgFileName = options["config"];
        if not os.path.isfile(cfgFileName):
            raise ValueError('Configuration file not found:', cfgFileName)

        # read configuration file
        cfg = ConfigParser()
        cfg.read(cfgFileName)

        # create Twisted application
        application = service.Application("gitlab-webhook-xmpp")
        serviceCollection = service.IServiceCollection(application)

        # create XMPP client
        client = XMPPClient(JID(cfg.get('xmpp', 'jid')), cfg.get('xmpp', 'password'))
#         client.logTraffic = True
        client.setServiceParent(application)
        # join to all MUC rooms
        nickname = cfg.get('xmpp', 'nickname') if cfg.has_option('xmpp', 'nickname') else DEFAULT_NICKNAME
        notifications = cfg.items('notifications')
        for room, repositoryMasks in notifications:
            mucHandler = MUCHandler(JID(room), nickname, repositoryMasks.split(','))
            mucHandler.setHandlerParent(client)
            self.mucHandlers.append(mucHandler)

        templateLoader = None
        if cfg.has_option('message', 'template'):
            templateFullName = cfg.get('message', 'template')
            templatePath, self.templateName = os.path.split(templateFullName)
            templateLoader = FileSystemLoader(templatePath)
        else:
            self.templateName = DEFAULT_TEMPLATE_NAME
            templateLoader = PackageLoader('xmpp_webhook', 'templates')
        self.templateEnvironment = Environment(loader=templateLoader, extensions=['jinja2.ext.i18n'])
        self.templateEnvironment.install_null_translations() # use i18n to pluralize only

        # create web hook handler
        rootHttpResource = Resource()
        rootHttpResource.putChild('', WebHookHandler(self))
        site = server.Site(rootHttpResource)
        httpPort = cfg.getint('http', 'port') if cfg.has_option('http', 'port') else DEFAULT_HTTP_PORT
        httpServer = internet.TCPServer(httpPort, site)
        httpServer.setServiceParent(serviceCollection)

        return serviceCollection
开发者ID:3cky,项目名称:gitlab-webhook-xmpp,代码行数:53,代码来源:xmpp_webhook_plugin.py

示例6: Output

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
class Output(cowrie.core.output.Output):

    def __init__(self):
        cowrie.core.output.Output.__init__(self)

    def start(self):
        from random import choice
        import string

        server = CONFIG.get('output_xmpp', 'server')
        user = CONFIG.get('output_xmpp', 'user')
        password = CONFIG.get('output_xmpp', 'password')
        muc = CONFIG.get('output_xmpp', 'muc')
        resource = ''.join([choice(string.ascii_letters)
                            for i in range(8)])
        jid = user + '/' + resource
        application = service.Application('honeypot')
        self.run(application, jid, password, JID(None, [muc, server, None]), server)

    def run(self, application, jidstr, password, muc, server):

        self.xmppclient = XMPPClient(JID(jidstr), password)
        if CONFIG.has_option('output_xmpp', 'debug') and \
                CONFIG.getboolean('output_xmpp', 'debug') is True:
            self.xmppclient.logTraffic = True  # DEBUG HERE
        (user, host, resource) = jid.parse(jidstr)
        self.muc = XMPPLoggerProtocol(
            muc, server, user + '-' + resource)
        self.muc.setHandlerParent(self.xmppclient)
        self.xmppclient.setServiceParent(application)
        self.anonymous = True
        self.xmppclient.startService()

    def write(self, logentry):
        for i in list(logentry.keys()):
            # Remove twisted 15 legacy keys
            if i.startswith('log_'):
                del logentry[i]
            elif i == "time":
                del logentry[i]
        msgJson = json.dumps(logentry, indent=5)

        self.muc.groupChat(self.muc.jrooms, msgJson)

    def stop(self):
        self.xmppclient.stopService()
开发者ID:davegermiquet,项目名称:cowrie,代码行数:48,代码来源:xmpp.py

示例7: initIrcJabberRelay

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
def initIrcJabberRelay(application):
    manager = RelayManager()

    # Configure IRC
    ircfactory = IrcBotFactory(manager, cfg["ircchannel"], cfg["ircnick"], manager.sendJabber)
    # point = TCP4ClientEndpoint(reactor, 'irc.freenode.net', 6667)
    # d = point.connect(ircfactory)
    # d.addCallback(gotProtocol)
    connector = internet.TCPClient(cfg["ircserver"], cfg["ircport"], ircfactory)
    connector.setServiceParent(application)

    # Configure Jabber
    xmppclient = XMPPClient(jid.internJID(cfg["jabberjid"]), cfg["jabberpass"])
    jabberbot = JabberBot(manager, cfg["jabberserver"], cfg["jabberchannel"], cfg["jabbernick"], manager.sendIRC)
    xmppclient.logTraffic = False
    jabberbot.setHandlerParent(xmppclient)
    xmppclient.setServiceParent(application)
    manager.setJabber(jabberbot)
开发者ID:atorkhov,项目名称:ircjabberrelay,代码行数:20,代码来源:manager.py

示例8: makeService

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
	def makeService(cls, config):
		"""
		Setup the necessary network services for the application server.
		"""
		if(conf.get('suppress-deprecation-warnings')):
			warnings.filterwarnings('ignore', r'.*', DeprecationWarning)

		master_service = service.MultiService()
		
		xmpp_client = XMPPClient(jid.internJID(conf.get('jid')), conf.get('secret'))
		xmpp_client.setName("xmpp-client")
		xmpp_client.setServiceParent(master_service)
		
		bot = xmpp.BotProtocol()
		bot.setHandlerParent(xmpp_client)
		
		for room in conf.get('join-rooms'):
			print 'creating room client for %s' % room
			muc_client = xmpp.MUCBotClient(*room)
			muc_client.setHandlerParent(xmpp_client)
		
		return master_service
开发者ID:philchristensen,项目名称:TJ,代码行数:24,代码来源:tj_server.py

示例9: botService

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
class botService(service.MultiService):
    """
        xmpp botService
    """
    name = "xmppClient"

    def __init__(self, root, parent):
        self.root = root
        self.parent = parent
        self.logger = logging.getLogger("xmppClient")
        self.config = self.root.getServiceNamed('config')
        self.config.set("enabled", False, "main", network="xmpp")
        service.MultiService.__init__(self)
        self.protocol=None
        try:
            self.myjid=self.config.get("jid", "", "main.xmppClient")
            password=self.config.get("password", "", "main.xmppClient")
            if not (self.myjid and password):
                self.logger.warn("please set main.xmppClient.jid "+\
                    "and main.xmppClient.password")
                return
            self.client = XMPPClient(jid.internJID(self.myjid+"/otfbot"), password)
            self.client.logTraffic = False
            self.protocol=Bot(root, self)
            self.messageProtocol=myMessageProtocol(self.protocol)
            self.messageProtocol.setHandlerParent(self.client)
            self.presenceClientProtocol=myPresenceClientProtocol(self.protocol)
            self.presenceClientProtocol.setHandlerParent(self.client)
            self.rosterClientProtocol=myRosterClientProtocol(self.protocol)
            self.rosterClientProtocol.setHandlerParent(self.client)

            self.protocol.messageProtocol=self.messageProtocol
            self.protocol.rosterClientProtocol=self.rosterClientProtocol
            self.protocol.presenceClientProtocol=self.presenceClientProtocol

            self.client.setServiceParent(self)
        except Exception, e:
            self.logger.error(e)
开发者ID:otfbot,项目名称:otfbot,代码行数:40,代码来源:xmppClient.py

示例10: DBLogger

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
class DBLogger(dblog.DBLogger):
    def start(self, cfg):
        from random import choice
        import string

        server      = cfg.get('database_xmpp', 'server')
        user        = cfg.get('database_xmpp', 'user')
        password    = cfg.get('database_xmpp', 'password')
        muc         = cfg.get('database_xmpp', 'muc')
        channels = {}
        for i in ('createsession', 'connectionlost', 'loginfailed',
                  'loginsucceeded', 'command', 'clientversion'):
            x = cfg.get('database_xmpp', 'signal_' + i)
            if not x in channels:
                channels[x] = []
            channels[x].append(i)

        resource = ''.join([choice(string.ascii_letters)
            for i in range(8)])
        jid = user + '/' + resource
        application = service.Application('honeypot')
        self.run(application, jid, password, JID(None,[muc,server,None]), channels)

    def run(self, application, jidstr, password, muc, channels, anon=True):

        self.xmppclient = XMPPClient(JID(jidstr), password)
        if self.cfg.has_option('database_xmpp', 'debug') and \
                self.cfg.get('database_xmpp', 'debug') in ('1', 'true', 'yes'):
            self.xmppclient.logTraffic = True # DEBUG HERE
        (user, host, resource) = jid.parse(jidstr)
        self.muc = XMPPLoggerProtocol(
            muc, channels.keys(), user + '-' + resource)
        self.muc.setHandlerParent(self.xmppclient)
        self.xmppclient.setServiceParent(application)
        self.signals = {}
        for channel in channels:
            for signal in channels[channel]:
                self.signals[signal] = channel
        self.anonymous = True
        self.xmppclient.startService()

    def broadcast(self, msgtype, msg):
        if msgtype in self.signals:
            self.report(msgtype, '%[email protected]%s' %
                (self.signals[msgtype], self.muc.server) , msg)

    def report(self, msgtype, to, xmsg):
        msg = {}
        msg['type'] = msgtype
        msg['message'] = xmsg
        msgJson = json.dumps(msg,indent=5)
        self.muc.groupChat(self.muc.jrooms, msgJson)

    # We have to return an unique ID
    def createSession(self, peerIP, peerPort, hostIP, hostPort):
        session = uuid.uuid4().hex
        ses = {}
        ses['session'] = session
        ses['remote_host'] = peerIP
        ses['remote_port'] = str(peerPort)
        if self.anonymous == True:
            ses['local_host'] = '127.0.0.1'
        else:
            ses['local_host'] = hostIP
        ses['local_port'] = str(hostPort)

        self.broadcast('createsession', ses)
        return session

    def handleTTYLogOpened(self, session, args):
        pass

    def handleConnectionLost(self, session, args):
        ses = {}
        ses['session'] = session
        self.broadcast('connectionlost', ses)

    def handleLoginFailed(self, session, args):
        ses = {}
        ses['session'] = session
        ses['username'] = args['username']
        ses['password'] = args['password']
        self.broadcast('loginfailed', ses)

    def handleLoginSucceeded(self, session, args):
        ses = {}
        ses['session'] = session
        ses['username'] = args['username']
        ses['password'] = args['password']
        self.broadcast('loginsucceeded', ses)

    def handleCommand(self, session, args):
        ses = {}
        ses['session'] = session
        ses['command'] = 'known'
        ses['input'] = args['input']
        self.broadcast('command', ses)

    def handleUnknownCommand(self, session, args):
        ses = {}
#.........这里部分代码省略.........
开发者ID:Guff,项目名称:cowrie,代码行数:103,代码来源:xmpp.py

示例11: JID

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
# Configuration parameters
config = ConfigParser.RawConfigParser()
config.read('bot.conf')

myJID = JID(config.get('Connection', 'my_jid'))
roomJID = JID(config.get('Connection', 'room_jid'))
roomPassword = config.get('Connection', 'room_password')

my_nick = config.get('Connection', 'my_nick')
my_secret = config.get('Connection', 'my_secret')

rt_url = config.get('RT', 'url')
rt_display_url = config.get('RT','display_url')
rt_user = config.get('RT', 'user')
rt_pwd = config.get('RT', 'pwd')
rt_default_queue = config.get('RT','default_queue')

LOG_TRAFFIC = False
#LOG_TRAFFIC = True

# Set up the Twisted application
application = service.Application("MUC Client")

client = XMPPClient(myJID, my_secret)
client.logTraffic = LOG_TRAFFIC
client.setServiceParent(application)

mucHandler = RTBot(roomJID, my_nick, rt_url, rt_user, rt_pwd, roomPassword, rt_display_url, output_format)
mucHandler.setHandlerParent(client)
开发者ID:GOVCERT-LU,项目名称:rt_bot,代码行数:31,代码来源:rt_bot.py

示例12: abort_job

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
            output = (self.PACKET.get_packet(packet_id), None)  # Return status.

        return output

    def abort_job(self, vm_jid, job_id):
        """ Terminate a job. """

        self.__send__(self.abort_job_packet(vm_jid, job_id))

    def terminate_vm(self, vm_jid):
        """ Terminate a VM. """

        self.__send__(packet)


# Misc.

if __name__ == "__main__":
    FARM_JID = raw_input("Farm JID: ")
    MY_JID = raw_input("My JID: ")
    PASSWORD = raw_input("My password: ")

    app = service.Application("TestVillein")

    test_villein = villein(MY_JID, PASSWORD, FARM_JID)
    xmpp_client = XMPPClient(test_villein.JID, PASSWORD)
    xmpp_client.logTraffic = False
    test_villein.setHandlerParent(xmpp_client)
    xmpp_client.setServiceParent(app)
开发者ID:ameetkini,项目名称:tinkubator,代码行数:31,代码来源:villein.py

示例13: makeService

# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import setServiceParent [as 别名]
    def makeService(self, options):
        # create Twisted application
        application = service.Application(TAP_NAME)
        serviceCollection = service.IServiceCollection(application)

        # check confguration file is specified and exists
        if not options["config"]:
            raise ValueError('Configuration file not specified (try to check --help option)')
        cfgFileName = options["config"];
        if not os.path.isfile(cfgFileName):
            raise ConfigurationError('Configuration file not found:', cfgFileName)

        # read configuration file
        cfg = ConfigParser()
        with codecs.open(cfgFileName, 'r', encoding='utf-8') as f:
            cfg.readfp(f)

        # get Google login and password from configuration
        if not cfg.has_option('account', 'login') or not cfg.has_option('account', 'password'):
            raise ConfigurationError('Google account login and password must be specified '
                                     'in configuration file [account] section')
        self.googleLogin = cfg.get('account', 'login')
        self.googlePassword = cfg.get('account', 'password')
        self.googleDeveloperId = cfg.get('account', 'developer_id') \
            if cfg.has_option('account', 'developer_id') else None
        # get ANDROID_ID from configuration
        if not cfg.has_option('account', 'android_id'):
            raise ConfigurationError('ANDROID_ID must be specified in configuration file [account] section')
        self.androidId = cfg.get('account', 'android_id')

        # get apps to monitor reviews
        apps = cfg.items('apps')
        if not apps:
            raise ConfigurationError('No apps to monitor reviews defined '
                                     'in configuration file [apps] section')
        for appId, appName in apps:
            self.apps.append(Application(appId, appName))

        # open database
        dbFilename = cfg.get('db', 'filename') if cfg.has_option('db', 'filename') else DEFAULT_DB_FILENAME
        self.dbpool = adbapi.ConnectionPool("sqlite3", dbFilename, check_same_thread=False)

        # create XMPP client
        client = XMPPClient(JID(cfg.get('xmpp', 'jid')), cfg.get('xmpp', 'password'))
#         client.logTraffic = True
        client.setServiceParent(application)
        # join to all MUC rooms
        nickname = cfg.get('xmpp', 'nickname') if cfg.has_option('xmpp', 'nickname') else DEFAULT_NICKNAME
        notifications = cfg.items('chats')
        for chat, appIdPatterns in notifications:
            mucNotifier = MUCNotifier(JID(chat), nickname, appIdPatterns.split(','))
            mucNotifier.setHandlerParent(client)
            self.mucNotifiers.append(mucNotifier)

        self.pollPeriod = humanfriendly.parse_timespan(cfg.get('poll', 'period')) \
                if cfg.has_option('poll', 'period') else DEFAULT_POLL_PERIOD
        self.pollDelay = humanfriendly.parse_timespan(cfg.get('poll', 'delay')) \
                if cfg.has_option('poll', 'delay') else DEFAULT_POLL_DELAY
        self.langs = [lang.strip() for lang in cfg.get('poll', 'lang').split(',')] \
                if cfg.has_option('poll', 'lang') else [ DEFAULT_LANG ]
        templateLoader = None
        if cfg.has_option('notification', 'template'):
            templateFullName = cfg.get('notification', 'template')
            templatePath, self.templateName = os.path.split(templateFullName)
            templateLoader = FileSystemLoader(templatePath)
        else:
            self.templateName = DEFAULT_TEMPLATE_NAME
            templateLoader = PackageLoader('reviewnotify', 'templates')
        self.templateEnvironment = Environment(loader=templateLoader, extensions=['jinja2.ext.i18n'])
        localeDir = pkg_resources.resource_filename('reviewnotify', 'locales')
        locale = None
        if cfg.has_option('i18n', 'locale'):
            locale = cfg.get('i18n', 'locale')
        translations = babel.support.Translations.load(dirname=localeDir, locales=locale)
        self.templateEnvironment.install_gettext_translations(translations)
        self.templateEnvironment.filters['datetime'] = format_datetime
        self.templateEnvironment.filters['review_url'] = review_url

        reactor.callLater(3.0, self.run) # TODO make initial delay configurable

        return serviceCollection
开发者ID:3cky,项目名称:google-play-review-notify,代码行数:83,代码来源:review_notify_plugin.py


注:本文中的wokkel.client.XMPPClient.setServiceParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。