def _deliver(cls, message, upn="AUTHENTICATED", session=None):
"""
Writes the given *message* (string) to all users matching *upn* using
the write_message() function. If *upn* is not provided or is
"AUTHENTICATED", will send the *message* to all users.
Alternatively a *session* ID may be specified instead of a *upn*. This
is useful when more than one user shares a UPN (i.e. ANONYMOUS).
"""
#print 'deliver message',message
logging.debug("_deliver(%s, upn=%s, session=%s)" %
(message, upn, session))
for instance in cls.instances:
try: # Only send to users that have authenticated
user = instance.current_user
except (WebSocketClosedError, AttributeError):
continue
if session and user and user.get('session', None) == session:
instance.write_message(message)
elif upn == "AUTHENTICATED":
instance.write_message(message)
elif user and upn == user.get('upn', None):
instance.write_message(message)
评论列表
文章目录