本文整理汇总了Python中autobahn.twisted.wamp.RouterSessionFactory.session方法的典型用法代码示例。如果您正苦于以下问题:Python RouterSessionFactory.session方法的具体用法?Python RouterSessionFactory.session怎么用?Python RouterSessionFactory.session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autobahn.twisted.wamp.RouterSessionFactory
的用法示例。
在下文中一共展示了RouterSessionFactory.session方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_minimal
# 需要导入模块: from autobahn.twisted.wamp import RouterSessionFactory [as 别名]
# 或者: from autobahn.twisted.wamp.RouterSessionFactory import session [as 别名]
def test_minimal(self):
embedded_components, client_components = [], [Case2_Backend, Case2_Frontend]
## create a WAMP router factory
##
router_factory = RouterFactory()
## create a WAMP router session factory
##
session_factory = RouterSessionFactory(router_factory)
## .. and create and add an WAMP application session to
## run next to the router
##
config = types.ComponentConfig(realm = self.realm,
extra = {
'caselog': 'case1.log'
}
)
try:
log = io.open('caselog.log', 'w')
except Exception as e:
print(e)
return
# log = io.open(config.extra['caselog'], 'w')
config.log = log
config.dlog = []
config.components = []
config.all_done = []
for C in embedded_components:
one_done = Deferred()
config.all_done.append(one_done)
c = C(config, one_done)
config.components.append(c)
session_factory.add(c)
if self.transport == "websocket":
## create a WAMP-over-WebSocket transport server factory
##
transport_factory = WampWebSocketServerFactory(session_factory, debug_wamp = self.debug)
transport_factory.setProtocolOptions(failByDrop = False, openHandshakeTimeout = 0, closeHandshakeTimeout = 0)
elif self.transport in ['rawsocket-json', 'rawsocket-msgpack']:
## create a WAMP-over-RawSocket transport server factory
##
if self.transport == 'rawsocket-msgpack':
serializer = MsgPackSerializer()
elif self.transport == 'rawsocket-json':
serializer = JsonSerializer()
else:
raise Exception("should not arrive here")
transport_factory = WampRawSocketServerFactory(session_factory, serializer, debug = self.debug)
else:
raise Exception("should not arrive here")
## start the server from an endpoint
##
from twisted.internet import reactor
server = serverFromString(reactor, self.server)
d = server.listen(transport_factory)
def onlisten(port):
config.port = port
d.addCallback(onlisten)
clients = []
clients_d = []
for C in client_components:
## create a WAMP application session factory
##
session_factory = ApplicationSessionFactory(config)
one_done = Deferred()
config.all_done.append(one_done)
def make_make(Klass, done):
def make(config):
c = Klass(config, done)
config.components.append(c)
return c
return make
## .. and set the session class on the factory
##
session_factory.session = make_make(C, one_done)
if self.transport == "websocket":
#.........这里部分代码省略.........
示例2: install_reactor
# 需要导入模块: from autobahn.twisted.wamp import RouterSessionFactory [as 别名]
# 或者: from autobahn.twisted.wamp.RouterSessionFactory import session [as 别名]
##
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
if args.debug:
print("Running on reactor {}".format(reactor))
# create a WAMP router factory
##
from autobahn.twisted.wamp import RouterFactory
router_factory = RouterFactory()
# create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
session_factory.session = MyRouterSession
# start an embedded application component ..
##
component_config = types.ComponentConfig(realm="realm1")
component_session = TimeService(component_config)
session_factory.add(component_session)
# create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
transport_factory = WampWebSocketServerFactory(session_factory, args.wsurl, debug=False, debug_wamp=args.debug)
transport_factory.protocol = ServerProtocol
transport_factory._cookies = {}
transport_factory.setProtocolOptions(failByDrop=False)
示例3: ApplicationSessionFactory
# 需要导入模块: from autobahn.twisted.wamp import RouterSessionFactory [as 别名]
# 或者: from autobahn.twisted.wamp.RouterSessionFactory import session [as 别名]
from autobahn.twisted.wamp import ApplicationSessionFactory
session_factory = ApplicationSessionFactory(config)
one_done = Deferred()
config.all_done.append(one_done)
def make_make(Klass, done):
def make(config):
c = Klass(config, done)
config.components.append(c)
return c
return make
## .. and set the session class on the factory
##
session_factory.session = make_make(C, one_done)
if args.transport == "websocket":
from autobahn.wamp.serializer import JsonSerializer
serializers = [JsonSerializer()]
## create a WAMP-over-WebSocket transport client factory
##
transport_factory = WampWebSocketClientFactory(session_factory, serializers = serializers, url = args.url, debug_wamp = args.debug)
if False:
def maker(Klass):
class TestClientProtocol(WampWebSocketClientProtocol):
示例4: run
# 需要导入模块: from autobahn.twisted.wamp import RouterSessionFactory [as 别名]
# 或者: from autobahn.twisted.wamp.RouterSessionFactory import session [as 别名]
def run():
import sys, argparse
from twisted.python import log
from twisted.internet.endpoints import serverFromString
## parse command line arguments
##
def_wsocket = 'ws://127.0.0.1:8080/ws'
def_realm = 'realm1'
def_topic_base = 'sys'
def_dsn = 'dbname=autobahn host=localhost user=autouser'
def_endpoint='tcp:8080'
def_engine = 'PG9_4'
p = argparse.ArgumentParser(description="basicrouter example with database")
p.add_argument('-w', '--websocket', action='store', dest='wsocket', default=def_wsocket,
help='web socket '+def_wsocket)
p.add_argument('-r', '--realm', action='store', dest='realm', default=def_realm,
help='connect to websocket using "realm", default '+def_realm)
p.add_argument('-v', '--verbose', action='store_true', dest='verbose',
default=False, help='Verbose logging for debugging')
p.add_argument('--debug', action='store_true', dest='debug',
default=False, help='Autobahn layer debugging')
p.add_argument('-e', '--engine', action='store', dest='engine', default=def_engine,
help='if specified, a database engine will be attached. Note engine is rooted on --topic')
p.add_argument("--endpoint", type = str, default = "tcp:8080",
help = 'Twisted server endpoint descriptor, e.g. "tcp:8080" or "unix:/tmp/mywebsocket", default is "' + def_endpoint + '"')
p.add_argument('-d', '--dsn', action='store', dest='dsn', default=def_dsn,
help='if specified the database in dsn will be connected and ready')
p.add_argument('-t', '--topic', action='store', dest='topic_base', default=def_topic_base,
help='if you specify --dsn then you will need a topic to root it on, the default ' + def_topic_base + ' is fine.')
args = p.parse_args()
if args.verbose:
log.startLogging(sys.stdout)
## we use an Autobahn utility to install the "best" available Twisted reactor
##
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
log.msg("Running on reactor {}".format(reactor))
# database workers...
userdb = UserDb(topic_base=args.topic_base+'.db',debug=args.verbose)
sessiondb = SessionDb(topic_base=args.topic_base,debug=args.verbose)
## create a WAMP router factory
##
component_config = types.ComponentConfig(realm = args.realm)
from autobahn.twisted.wamp import RouterFactory
router_factory = RouterFactory()
authorization_session = AuthorizeSession(component_config,
topic_base=args.topic_base+'.db',debug=args.verbose,db=sessiondb,router=AuthorizeRouter)
router_factory.router = authorization_session.ret_func
## create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
session_factory.session = MyRouterSession
log.msg("session_factory.session")
session_factory.userdb = userdb
session_factory.sessiondb = sessiondb
log.msg("userdb, sessiondb")
sessiondb_component = SessionData(component_config,session_factory.sessiondb,
topic_base=args.topic_base)
session_factory.add(sessiondb_component)
session_factory.add(authorization_session)
log.msg("session_factory")
db_session = DB(component_config, engine=args.engine,
topic_base=args.topic_base+'.db', dsn=args.dsn, debug=args.verbose)
session_factory.add(db_session)
session_factory.userdb.set_session(db_session)
session_factory.sessiondb.set_session(db_session)
## create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
transport_factory = WampWebSocketServerFactory(session_factory, debug = args.debug)
transport_factory.setProtocolOptions(failByDrop = False)
## start the server from an endpoint
##
## this address clash detection was a goody I got from stackoverflow:
## http://stackoverflow.com/questions/12007316/exiting-twisted-application-after-listenfailure
server = serverFromString(reactor, args.endpoint)
def listen():
srv = server.listen(transport_factory)
def ListenFailed(reason):
log.msg("On Startup Listen Failed with {}".format(reason))
#.........这里部分代码省略.........
示例5: start_webserver
# 需要导入模块: from autobahn.twisted.wamp import RouterSessionFactory [as 别名]
# 或者: from autobahn.twisted.wamp.RouterSessionFactory import session [as 别名]
def start_webserver(options, protocol=vtk_wamp.ServerProtocol, disableLogging=False):
"""
Starts the web-server with the given protocol. Options must be an object
with the following members:
options.host : the interface for the web-server to listen on
options.port : port number for the web-server to listen on
options.timeout : timeout for reaping process on idle in seconds
options.content : root for web-pages to serve.
"""
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.static import File
from twisted.web.resource import Resource
import sys
if not disableLogging:
log.startLogging(sys.stdout)
contextFactory = None
use_SSL = False
if options.sslKey and options.sslCert:
use_SSL = True
wsProtocol = "wss"
from twisted.internet import ssl
contextFactory = ssl.DefaultOpenSSLContextFactory(options.sslKey, options.sslCert)
else:
wsProtocol = "ws"
# Create WAMP router factory
from autobahn.twisted.wamp import RouterFactory
router_factory = RouterFactory()
# create a user DB
authdb = vtk_wamp.AuthDb()
# create a WAMP router session factory
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
session_factory.session = vtk_wamp.CustomWampCraRouterSession
session_factory.authdb = authdb
# Register protocol
session_factory.add(protocol(authdb=authdb))
# create a WAMP-over-WebSocket transport server factory
transport_factory = vtk_wamp.TimeoutWampWebSocketServerFactory(session_factory, \
url = "%s://%s:%d" % (wsProtocol, options.host, options.port), \
debug = options.debug, \
debug_wamp = options.debug, \
timeout = options.timeout )
root = Resource()
# Do we serve static content or just websocket ?
if len(options.content) > 0:
# Static HTTP + WebSocket
root = File(options.content)
# Handle possibly complex ws endpoint
if not options.nows:
wsResource = WebSocketResource(transport_factory)
handle_complex_resource_path(options.ws, root, wsResource)
# Handle possibly complex lp endpoint
if not options.nolp:
lpResource = WampLongPollResource(session_factory)
handle_complex_resource_path(options.lp, root, lpResource)
if options.uploadPath != None :
from upload import UploadPage
uploadResource = UploadPage(options.uploadPath)
root.putChild("upload", uploadResource)
site = Site(root)
if use_SSL:
reactor.listenSSL(options.port, site, contextFactory)
else:
reactor.listenTCP(options.port, site)
# Work around to force the output buffer to be flushed
# This allow the process launcher to parse the output and
# wait for "Start factory" to know that the WebServer
# is running.
if options.forceFlush :
for i in range(200):
log.msg("+"*80, logLevel=logging.CRITICAL)
# Give test client a chance to initialize a thread for itself
# testing.initialize(opts=options)
# Initialize testing: checks if we're doing a test and sets it up
testing.initialize(options, reactor)
# Start the reactor
if options.nosignalhandlers:
reactor.run(installSignalHandlers=0)
else:
reactor.run()
#.........这里部分代码省略.........
示例6: install_reactor
# 需要导入模块: from autobahn.twisted.wamp import RouterSessionFactory [as 别名]
# 或者: from autobahn.twisted.wamp.RouterSessionFactory import session [as 别名]
# we use an Autobahn utility to install the "best" available Twisted reactor
##
from autobahn.twisted.choosereactor import install_reactor
reactor = install_reactor()
if args.debug:
print("Running on reactor {}".format(reactor))
# create a WAMP router factory
##
from autobahn.wamp.router import RouterFactory
router_factory = RouterFactory()
# create a WAMP router session factory
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
session_factory.session = WebServiceLoginRouterSession
session_factory.add(TimeService(args.realm))
# create a WAMP-over-WebSocket transport server factory
transport_factory = WampWebSocketServerFactory(
session_factory, args.wsurl, debug_wamp=args.debug)
#transport_factory.protocol = ServerProtocol
transport_factory.setProtocolOptions(failByDrop=False)
from twisted.web.server import Site
from twisted.web.static import File
from autobahn.twisted.resource import WebSocketResource
# we serve static files under "/" ..