本文整理汇总了Python中src.server.sessionhandler.SESSIONS.session_from_sessid方法的典型用法代码示例。如果您正苦于以下问题:Python SESSIONS.session_from_sessid方法的具体用法?Python SESSIONS.session_from_sessid怎么用?Python SESSIONS.session_from_sessid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.server.sessionhandler.SESSIONS
的用法示例。
在下文中一共展示了SESSIONS.session_from_sessid方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from src.server.sessionhandler import SESSIONS [as 别名]
# 或者: from src.server.sessionhandler.SESSIONS import session_from_sessid [as 别名]
def setUp(self):
"sets up testing environment"
settings.DEFAULT_HOME = "#2"
# print "creating player %i: %s" % (self.CID, self.__class__.__name__)
self.player = create.create_player(
"TestPlayer%i" % self.CID, "[email protected]", "testpassword", typeclass=TestPlayerClass
)
self.player2 = create.create_player(
"TestPlayer%ib" % self.CID, "[email protected]", "testpassword", typeclass=TestPlayerClass
)
self.room1 = create.create_object("src.objects.objects.Room", key="Room%i" % self.CID, nohome=True)
self.room1.db.desc = "room_desc"
self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID)
self.obj1 = create.create_object(TestObjectClass, key="Obj%i" % self.CID, location=self.room1, home=self.room1)
self.obj2 = create.create_object(TestObjectClass, key="Obj%ib" % self.CID, location=self.room1, home=self.room1)
self.char1 = create.create_object(
TestCharacterClass, key="Char%i" % self.CID, location=self.room1, home=self.room1
)
self.char1.permissions.add("Immortals")
self.char2 = create.create_object(
TestCharacterClass, key="Char%ib" % self.CID, location=self.room1, home=self.room1
)
self.char1.player = self.player
self.char2.player = self.player2
self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID)
self.player.permissions.add("Immortals")
# set up a fake session
global SESSIONS
session = ServerSession()
session.init_session("telnet", ("localhost", "testmode"), SESSIONS)
session.sessid = self.CID
SESSIONS.portal_connect(session.get_sync_data())
SESSIONS.login(SESSIONS.session_from_sessid(self.CID), self.player, testmode=True)
示例2: at_repeat
# 需要导入模块: from src.server.sessionhandler import SESSIONS [as 别名]
# 或者: from src.server.sessionhandler.SESSIONS import session_from_sessid [as 别名]
def at_repeat(self):
"""
Calls subscriptions every self.interval seconds
"""
for (func_key, sessid, interval, args, kwargs) in self.ndb.subscriptions.values():
session = SESSIONS.session_from_sessid(sessid)
OOB_HANDLER.execute_cmd(session, func_key, *args, **kwargs)
示例3: msg
# 需要导入模块: from src.server.sessionhandler import SESSIONS [as 别名]
# 或者: from src.server.sessionhandler.SESSIONS import session_from_sessid [as 别名]
def msg(self, text=None, from_obj=None, sessid=0, **kwargs):
"""
Emits something to a session attached to the object.
message (str): The message to send
from_obj (obj): object that is sending.
data (object): an optional data object that may or may not
be used by the protocol.
sessid (int): sessid to relay to, if any.
If set to 0 (default), use either from_obj.sessid (if set) or self.sessid automatically
If None, echo to all connected sessions
"""
global _SESSIONS
if not _SESSIONS:
from src.server.sessionhandler import SESSIONS as _SESSIONS
text = to_str(text, force_string=True) if text else ""
if "data" in kwargs:
# deprecation warning
logger.log_depmsg("ObjectDB.msg(): 'data'-dict keyword is deprecated. Use **kwargs instead.")
data = kwargs.pop("data")
if isinstance(data, dict):
kwargs.update(data)
if from_obj:
# call hook
try:
_GA(from_obj, "at_msg_send")(text=text, to_obj=self, **kwargs)
except Exception:
pass
session = _SESSIONS.session_from_sessid(sessid if sessid else _GA(self, "sessid"))
if session:
session.msg(text=text, **kwargs)
示例4: _callback
# 需要导入模块: from src.server.sessionhandler import SESSIONS [as 别名]
# 或者: from src.server.sessionhandler.SESSIONS import session_from_sessid [as 别名]
def _callback(self):
"See original for more info"
for key, (_, args, kwargs) in self.subscriptions.items():
# args = (sessid, callback_function)
session = SESSIONS.session_from_sessid(args[0])
try:
# execute the oob callback
yield args[1](OOB_HANDLER, session, *args[2:], **kwargs)
except Exception:
logger.log_trace()
示例5: msg
# 需要导入模块: from src.server.sessionhandler import SESSIONS [as 别名]
# 或者: from src.server.sessionhandler.SESSIONS import session_from_sessid [as 别名]
def msg(self, text=None, from_obj=None, sessid=0, **kwargs):
"""
Emits something to a session attached to the object.
message (str): The message to send
from_obj (obj): object that is sending.
data (object): an optional data object that may or may not
be used by the protocol.
sessid (int): sessid to relay to, if any.
If set to 0 (default), use either from_obj.sessid (if set) or self.sessid automatically
If None, echo to all connected sessions
When this message is called, from_obj.at_msg_send and self.at_msg_receive are called.
"""
global _SESSIONS
if not _SESSIONS:
from src.server.sessionhandler import SESSIONS as _SESSIONS
text = to_str(text, force_string=True) if text else ""
if "data" in kwargs:
# deprecation warning
logger.log_depmsg("ObjectDB.msg(): 'data'-dict keyword is deprecated. Use **kwargs instead.")
data = kwargs.pop("data")
if isinstance(data, dict):
kwargs.update(data)
if from_obj:
# call hook
try:
_GA(from_obj, "at_msg_send")(text=text, to_obj=_GA(self, "typeclass"), **kwargs)
except Exception:
logger.log_trace()
try:
if not _GA(_GA(self, "typeclass"), "at_msg_receive")(text=text, **kwargs):
# if at_msg_receive returns false, we abort message to this object
return
except Exception:
logger.log_trace()
sessions = _SESSIONS.session_from_sessid([sessid] if sessid else make_iter(_GA(self, "sessid").get()))
for session in sessions:
session.msg(text=text, **kwargs)
示例6: call
# 需要导入模块: from src.server.sessionhandler import SESSIONS [as 别名]
# 或者: from src.server.sessionhandler.SESSIONS import session_from_sessid [as 别名]
def call(self, cmdobj, args, msg=None, cmdset=None, noansi=True, caller=None):
"""
Test a command by assigning all the needed
properties to cmdobj and running
cmdobj.at_pre_cmd()
cmdobj.parse()
cmdobj.func()
cmdobj.at_post_cmd()
The msgreturn value is compared to eventual
output sent to caller.msg in the game
"""
cmdobj.caller = caller if caller else self.char1
# print "call:", cmdobj.key, cmdobj.caller, caller if caller else cmdobj.caller.player
# print "perms:", cmdobj.caller.permissions.all()
cmdobj.cmdstring = cmdobj.key
cmdobj.args = args
cmdobj.cmdset = cmdset
cmdobj.sessid = self.CID
cmdobj.session = SESSIONS.session_from_sessid(self.CID)
cmdobj.player = self.player
cmdobj.raw_string = cmdobj.key + " " + args
cmdobj.obj = caller if caller else self.char1
# test
self.char1.player.ndb.stored_msg = []
cmdobj.at_pre_cmd()
cmdobj.parse()
cmdobj.func()
cmdobj.at_post_cmd()
# clean out prettytable sugar
stored_msg = self.char1.player.ndb.stored_msg if self.char1.player else self.char1.ndb.stored_msg
returned_msg = "|".join(_RE.sub("", mess) for mess in stored_msg)
# returned_msg = "|".join(self.char1.player.ndb.stored_msg)
returned_msg = ansi.parse_ansi(returned_msg, strip_ansi=noansi).strip()
if msg != None:
if msg == "" and returned_msg or not returned_msg.startswith(msg.strip()):
sep1 = "\n" + "=" * 30 + "Wanted message" + "=" * 34 + "\n"
sep2 = "\n" + "=" * 30 + "Returned message" + "=" * 32 + "\n"
sep3 = "\n" + "=" * 78
retval = sep1 + msg.strip() + sep2 + returned_msg + sep3
raise AssertionError(retval)