本文整理汇总了Python中autobahn.twisted.wamp.RouterSessionFactory.sessiondb方法的典型用法代码示例。如果您正苦于以下问题:Python RouterSessionFactory.sessiondb方法的具体用法?Python RouterSessionFactory.sessiondb怎么用?Python RouterSessionFactory.sessiondb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autobahn.twisted.wamp.RouterSessionFactory
的用法示例。
在下文中一共展示了RouterSessionFactory.sessiondb方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from autobahn.twisted.wamp import RouterSessionFactory [as 别名]
# 或者: from autobahn.twisted.wamp.RouterSessionFactory import sessiondb [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))
#.........这里部分代码省略.........