本文整理汇总了Python中models.Actor.by_socket方法的典型用法代码示例。如果您正苦于以下问题:Python Actor.by_socket方法的具体用法?Python Actor.by_socket怎么用?Python Actor.by_socket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Actor
的用法示例。
在下文中一共展示了Actor.by_socket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import by_socket [as 别名]
def handle(socket, address):
fileobj = socket.makefile('rw')
while not Actor.by_socket(socket).disconnected:
line = fileobj.readline()
if not line:
Actor.by_socket(socket).flush()
Actor.by_socket(socket).disconnect()
continue
try:
msg = Message.from_string(line)
log.debug('<= %s %s' % (repr(msg.target), repr(msg)))
resp = dispatcher.dispatch(socket, msg)
except Exception as e:
log.exception(e)
actor = Actor.by_socket(socket)
if actor.is_user() and actor.get_user().registered.nick and actor.get_user().registered.user:
resp = [
Message(actor, 'NOTICE', 'The message your client has just sent could not be parsed or processed.'),
Message(actor, 'NOTICE', 'If this is a problem with the server, please open an issue at:'),
Message(actor, 'NOTICE', 'https://github.com/abesto/python-ircd'),
Message(actor, 'NOTICE', '---'),
Message(actor, 'NOTICE', 'The message sent by your client was:'),
Message(actor, 'NOTICE', line.strip("\n")),
Message(actor, 'NOTICE', 'The error was:'),
Message(actor, 'NOTICE', str(e)),
Message(actor, 'NOTICE', '---'),
Message(actor, 'NOTICE', 'Closing connection.')
]
quit_resp = dispatcher.dispatch(socket, Message(None, 'QUIT', 'Protocol error'))
if isinstance(quit_resp, list):
resp += quit_resp
else:
resp.append(quit_resp)
else:
resp = Message(actor, 'ERROR')
Actor.by_socket(socket).disconnect()
try:
router.send(resp)
except Exception as e:
log.exception(e)
Actor.by_socket(socket).disconnect()