本文整理汇总了Python中session.Session.set_ivars_from_str方法的典型用法代码示例。如果您正苦于以下问题:Python Session.set_ivars_from_str方法的具体用法?Python Session.set_ivars_from_str怎么用?Python Session.set_ivars_from_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类session.Session
的用法示例。
在下文中一共展示了Session.set_ivars_from_str方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Connection
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import set_ivars_from_str [as 别名]
class Connection(basic.LineReceiver):
implements(twisted.internet.interfaces.IProtocol)
# the telnet transport changes all '\r\n' to '\n',
# so we can just use '\n' here
delimiter = '\n'
MAX_LENGTH = 1024
state = 'prelogin'
user = None
logged_in_again = False
buffer_output = False
ivar_pat = re.compile(r'%b([01]{32})')
timeout_check = None
def connectionMade(self):
lang.langs['en'].install(names=['ngettext'])
self.session = Session(self)
if self.transport.getHost().port == config.zipseal_port:
self.session.use_zipseal = True
self.transport.encoder = timeseal.compress_zipseal
self.session.check_for_timeseal = False
self.factory.connections.append(self)
self.write(db.get_server_message('welcome'))
self.login()
self.session.login_last_command = time.time()
self.ip = self.transport.getPeer().host
self.timeout_check = reactor.callLater(config.login_timeout, self.login_timeout)
def login_timeout(self):
assert(self.state in ['login', 'passwd'])
self.timeout_check = None
self.write(_("\n**** LOGIN TIMEOUT ****\n"))
self.loseConnection('login timeout')
def idle_timeout(self, mins):
assert(self.state in ['prompt'])
self.write(_("\n**** Auto-logout because you were idle more than %d minutes. ****\n") % mins)
self.loseConnection('idle timeout')
def login(self):
self.state = 'login'
self.write(db.get_server_message('login'))
if self.transport.compatibility:
# the string "freechess.org" must appear somewhere in this message;
# otherwise, Babs will refuse to connect
self.write('You are connected to the backwards-compatibility port for old FICS clients.\nYou will not be able to use zipseal or international characters.\nThis server is not endorsed by freechess.org.\n\n')
self.write("login: ")
def lineReceived(self, line):
#print '((%s,%s))\n' % (self.state, repr(line))
if self.session.use_timeseal:
(t, dline) = timeseal.decode_timeseal(line)
elif self.session.use_zipseal:
(t, dline) = timeseal.decode_zipseal(line)
else:
t = None
dline = line
if t != None and t < 0:
self.log('timeseal/zipseal error on line: {%r} {%r}' % (line, dline))
self.write('timeseal error\n')
self.loseConnection('timeseal error')
return
elif t == 0:
# it seems the Jin application's timeseal sometimes sends
# a timeptamp of 0, but still expects the command
# to be executed
self.log('warning: got timeseal/zipseal 0 on line: {%r} {%r}' % (line, dline))
self.session.timeseal_last_timestamp = t
if self.state:
getattr(self, "handleLine_" + self.state)(dline)
def handleLine_prelogin(self, line):
""" Shouldn't happen normally. """
self.log('got line in prelogin state')
def handleLine_quitting(self, line):
# ignore
pass
def handleLine_login(self, line):
self.timeout_check.cancel()
self.timeout_check = reactor.callLater(config.login_timeout, self.login_timeout)
self.session.login_last_command = time.time()
if self.session.check_for_timeseal:
self.session.check_for_timeseal = False
(t, dec) = timeseal.decode_timeseal(line)
if t != 0:
if dec[0:10] == 'TIMESTAMP|':
self.session.use_timeseal = True
return
elif dec[0:10] == 'TIMESEAL2|':
self.session.use_timeseal = True
return
# we don't detect zipseal here, because we use
# the port number to detect it
# no timeseal; continue
m = self.ivar_pat.match(line)
if m:
self.session.set_ivars_from_str(m.group(1))
#.........这里部分代码省略.........