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


Python Site.sessionFactory方法代码示例

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


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

示例1: whenRunning

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import sessionFactory [as 别名]
    def whenRunning(cls, config: Configuration) -> None:
        """
        Called after the reactor has started.
        """
        async def start() -> None:
            await config.store.upgradeSchema()
            await config.store.validate()

        d = ensureDeferred(start())

        host = config.HostName
        port = config.Port

        application = Application(config=config)

        cls.log.info(
            "Setting up web service at http://{host}:{port}/",
            host=host, port=port,
        )

        patchCombinedLogFormatter()

        factory = Site(application.router.resource())
        factory.sessionFactory = IMSSession

        from twisted.internet import reactor
        reactor.listenTCP(port, factory, interface=host)

        return d
开发者ID:burningmantech,项目名称:ranger-ims-server,代码行数:31,代码来源:_server.py

示例2: makeService

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import sessionFactory [as 别名]
    def makeService(self, options):
        class LongSession(Session):
            sessionTimeout = 3600

        if options['steamkey'] is None:
            raise ValueError('Must specify steam API key.')
        if options['strport'] is None:
            raise ValueError('Must specify strport description.')
        if options['dbdir'] is None:
            raise ValueError('Must specify database path.')
        steamAPI = API(key=options['steamkey'])

        store = Store(options['dbdir'])
        keyPath = FilePath(options['dbdir']).child('fernet.key')

        database = Database(store)

        loginRedirect = '/'
        portal = Portal(MapListRealm(database, options['bundle-path'],
                                     steamAPI, loginRedirect))
        portal.registerChecker(PreauthenticatedChecker())
        portal.registerChecker(AllowAnonymousAccess())

        root = HTTPOpenIDAuthSessionWrapper(portal, [], loginRedirect, keyPath,
                                            database)

        site = Site(root)
        site.sessionFactory = LongSession
        return strports.service(options['strport'], site)
开发者ID:jsza,项目名称:jump-map-list,代码行数:31,代码来源:map_list_service.py

示例3: setup_finalize

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import sessionFactory [as 别名]
def setup_finalize(event, application):
       
    from twisted.application import service, internet
    from twisted.internet import reactor, ssl
    from twisted.web.server import Site
    from twisted.python import log
    #from twisted.enterprise import adbapi
    import OpenSSL.SSL
    
    from services import ServiceEventHandler
    
    import socket_transport
    import http_transport
    #import websocket_transport
    import irc
    
    from stratum import settings
    
    try:
        import signature
        signing_key = signature.load_privkey_pem(settings.SIGNING_KEY)
    except:
        print "Loading of signing key '%s' failed, protocol messages cannot be signed." % settings.SIGNING_KEY
        signing_key = None
        
    # Attach HTTPS Poll Transport service to application
    try:
        sslContext = ssl.DefaultOpenSSLContextFactory(settings.SSL_PRIVKEY, settings.SSL_CACERT)
    except OpenSSL.SSL.Error:
        sslContext = None
        print "Cannot initiate SSL context, are SSL_PRIVKEY or SSL_CACERT missing?"
        print "This will skip all SSL-based transports."
        
    # Set up thread pool size for service threads
    reactor.suggestThreadPoolSize(settings.THREAD_POOL_SIZE) 
    
    if settings.LISTEN_SOCKET_TRANSPORT:
        # Attach Socket Transport service to application
        socket = internet.TCPServer(settings.LISTEN_SOCKET_TRANSPORT,
                                socket_transport.SocketTransportFactory(debug=settings.DEBUG,
                                                                        signing_key=signing_key,
                                                                        signing_id=settings.SIGNING_ID,
                                                                        event_handler=ServiceEventHandler,
                                                                        tcp_proxy_protocol_enable=settings.TCP_PROXY_PROTOCOL))
        socket.setServiceParent(application)

    # Build the HTTP interface
    httpsite = Site(http_transport.Root(debug=settings.DEBUG, signing_key=signing_key, signing_id=settings.SIGNING_ID,
                                        event_handler=ServiceEventHandler))
    httpsite.sessionFactory = http_transport.HttpSession

    if settings.LISTEN_HTTP_TRANSPORT:    
        # Attach HTTP Poll Transport service to application
        http = internet.TCPServer(settings.LISTEN_HTTP_TRANSPORT, httpsite)
        http.setServiceParent(application)

    if settings.LISTEN_HTTPS_TRANSPORT and sslContext:
            https = internet.SSLServer(settings.LISTEN_HTTPS_TRANSPORT, httpsite, contextFactory = sslContext)
            https.setServiceParent(application)
    
    #if settings.LISTEN_WS_TRANSPORT:
    #    from autobahn.websocket import listenWS
    #    log.msg("Starting WS transport on %d" % settings.LISTEN_WS_TRANSPORT)
    #    ws = websocket_transport.WebsocketTransportFactory(settings.LISTEN_WS_TRANSPORT,
    #                                                       debug=settings.DEBUG,
    #                                                       signing_key=signing_key,
    #                                                       signing_id=settings.SIGNING_ID,
    #                                                       event_handler=ServiceEventHandler)
    #    listenWS(ws)
    
    #if settings.LISTEN_WSS_TRANSPORT and sslContext:  
    #    from autobahn.websocket import listenWS
    #    log.msg("Starting WSS transport on %d" % settings.LISTEN_WSS_TRANSPORT)
    #    wss = websocket_transport.WebsocketTransportFactory(settings.LISTEN_WSS_TRANSPORT, is_secure=True,
    #                                                        debug=settings.DEBUG,
    #                                                        signing_key=signing_key,
    #                                                        signing_id=settings.SIGNING_ID,
    #                                                        event_handler=ServiceEventHandler)
    #    listenWS(wss, contextFactory=sslContext)
    
    if settings.IRC_NICK:
        reactor.connectTCP(settings.IRC_SERVER, settings.IRC_PORT, irc.IrcLurkerFactory(settings.IRC_ROOM, settings.IRC_NICK, settings.IRC_HOSTNAME))

    return event
开发者ID:Lietmotiv,项目名称:stratum,代码行数:86,代码来源:server.py

示例4: _expired

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import sessionFactory [as 别名]
        try:
            answer = json.loads(request.content.getvalue())['answer']
        except ValueError:
            return 'You should be submitting as JSON'

        print "DBG Submission: |" + answer + "|" 
        print "DBG Answer was: |" + self.solution + "|" 

        # check submitted answer
        if answer == self.solution:
	    print "DBG: challenge solved"
            return self.get_answer('challenge4')
        else:
            return 'wrong answer\n'

    def _expired(self, uid):
        try:
            self.sessions.remove(uid)
        except:
            pass

# if __name__ == __main__
print "LOG: starting bit twiddling slash logic gate challenge"
rootResource = Resource()
rootResource.putChild("challenge4", Challenge4())
factory = Site(rootResource)
factory.sessionFactory = LongSession

reactor.listenTCP(8084, factory)
reactor.run()
开发者ID:thepythonclub,项目名称:challenges,代码行数:32,代码来源:challenge4.py

示例5: _expired

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import sessionFactory [as 别名]
        if answer == self.solution:
            return self.get_answer('challengeb1')
        else:
            return 'Try again'
            

    def _expired(self, uid):
        try:
            self.sessions.remove(uid)
        except KeyError:
            pass

class GetBook(Resource):
    def render_POST(self, request):
        return "You shouldn't be posting here"
    
    def render_GET(self, request):
        orginalFile = open('Alice_in_Wonderland.txt','r')
        data = orginalFile.read()
        orginalFile.close()
        return data

rootResource = Resource()
rootResource.putChild("challengeb1", Challengeb1())
rootResource.putChild("book.txt", GetBook())
factory = Site(rootResource)
factory.sessionFactory = ShortSession

reactor.listenTCP(8091, factory)
reactor.run()
开发者ID:thepythonclub,项目名称:challenges,代码行数:32,代码来源:challengeb1.py


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