本文整理汇总了Python中document.Document.subscribe_user方法的典型用法代码示例。如果您正苦于以下问题:Python Document.subscribe_user方法的具体用法?Python Document.subscribe_user怎么用?Python Document.subscribe_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类document.Document
的用法示例。
在下文中一共展示了Document.subscribe_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import subscribe_user [as 别名]
class Root:
def __init__(self, name, tagline):
self.gb = Gutenborg(name, tagline)
# Some server test things.
self.DocTest = Document(self.gb, "Doc1", "")
self.DocTwo = Document(self.gb, "Test Document 2", "")
self.gb.add_document(self.DocTest)
self.gb.add_document(self.DocTwo)
self.u = User(self.gb, "Becca", "#008888")
self.gb.add_user(self.u)
self.DocTest.subscribe_user(self.u)
self.DocTest.insert(self.u, 0, "Testing ", 0)
self.DocTest.insert(self.u, 8, "Hello World!", 1)
def quit(self):
sys.exit();
quit.exposed = True
def is_logged_in(self):
""" Private method: Returns true if your session username is in
the active user list, false if your session username is not in
the active user list."""
if 'user' in cherrypy.session and cherrypy.session['user'] in self.gb.active_users:
return True
else:
return False
def login(self, **args):
"""
Creates a new user and adds them to the gutenborg object if
they aren't already.
"""
cherrypy.session.acquire_lock()
assert not self.is_logged_in(), "This session already has a logged in user."
assert 'name' in args and 'color' in args, "Bad request. Args: " + repr(args)
cherrypy.session['user'] = User(self.gb, args['name'], args['color'])
try:
self.gb.add_user(cherrypy.session['user'])
except NameError:
del cherrypy.session['user']
return "User could not be added because this user exists on another computer."
return "User added"
login.exposed = True
def logout(self, **args):
"""
Logs a user out
"""
cherrypy.session.acquire_lock()
assert self.is_logged_in(), "User not logged in, no need to logout."
self.gb.disconnect_user(cherrypy.session['user'], "logout")
del cherrypy.session['user']
raise cherrypy.HTTPRedirect("/")
logout.exposed = True
def info(self, **args):
# TODO: We must make this an event!
"""
Returns a JSON object containing lots of server information
"""
cherrypy.session.acquire_lock()
cherrypy.response.headers['Content-Type'] = 'text/json'
response = {}
response['name'] = self.gb.name
response['tag'] = self.gb.tagline
response['active_users'] = []
response['dead_users'] = []
response['documents'] = []
for u in self.gb.active_users[:]:
response['active_users'].append(u.get_state())
for u in self.gb.dead_users[:]:
response['dead_users'].append(u.get_state())
for d in self.gb.documents[:]:
response['documents'].append(d.name)
# Are we logged in?
if self.is_logged_in():
response['logged_in_username'] = cherrypy.session['user'].name
return json.write(response)
info.exposed = True
def wait(self, **args):
"""
Sends the events of a logged-in user
"""
cherrypy.session.acquire_lock()
assert self.is_logged_in(), "User is not logged in"
assert 'last' in args, "History required."
user = cherrypy.session['user']
cherrypy.session.release_lock()
# Update the user's time so they don't timeout
user.touch_time()
# Timeout all the users
self.gb.timeout_users(20)
return user.get_events(int(args['last']))
wait.exposed = True
#.........这里部分代码省略.........