本文整理匯總了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()