Include Channel stub changes from the 1.7.2 SDK
@@ -99,7 +99,7 @@ class ChannelServiceStub(apiproxy_stub.APIProxyStub):
def _Dynamic_CreateChannel(self, request, response):
- """Implementation of channel.get_channel.
+ """Implementation of channel.create_channel.
Args:
request: A ChannelServiceRequest.
@@ -175,24 +175,28 @@ class ChannelServiceStub(apiproxy_stub.APIProxyStub):
else:
return None
- def is_valid_token(self, token):
- """Checks if a token is valid and not expired.
+
+ def check_token_validity(self, token):
+ """Checks if a token is well-formed and its expiration status.
Args:
token: a token returned by CreateChannel.
Returns:
- True if the token is well-formed and not expired. False otherwise.
+ A tuple (syntax_valid, time_valid) where syntax_valid is true if the
+ token is well-formed and time_valid is true if the token is not expired.
+ In other words, a usable token will return (true, true).
"""
pieces = token.split('-', 3)
if len(pieces) != 4:
- return False
+ return False, False
(constant_identifier, token_id, expiration_sec, clientid) = pieces
-
- return (constant_identifier == ChannelServiceStub.CHANNEL_TOKEN_IDENTIFIER
- and all(c.isdigit() for c in expiration_sec)
- and long(expiration_sec) > self._time_func())
+ syntax_valid = (
+ constant_identifier == ChannelServiceStub.CHANNEL_TOKEN_IDENTIFIER
+ and expiration_sec.isdigit())
+ time_valid = syntax_valid and long(expiration_sec) > self._time_func()
+ return (syntax_valid, time_valid)
@apiproxy_stub.Synchronized
def get_channel_messages(self, token):
@@ -266,7 +270,7 @@ class ChannelServiceStub(apiproxy_stub.APIProxyStub):
self._log('Ignoring clear messages for nonexistent token (' +
token + ')')
- class ChannelPresenceSocket():
+ class ChannelPresenceSocket(object):
"""A socket object to update channel client presence."""
def __init__(self, path, client_id):
@@ -297,7 +301,6 @@ class ChannelServiceStub(apiproxy_stub.APIProxyStub):
def shutdown(self, how):
pass
-
def connect_channel_event(self, client_id):
"""Tell the application that the client has connected."""
return (self.ChannelPresenceSocket('connected/', client_id),
@@ -307,6 +310,9 @@ class ChannelServiceStub(apiproxy_stub.APIProxyStub):
def add_connect_event(self, client_id):
"""Add an event to make a POST to the /_ah/channel/connect path.
+ Args:
+ client_id: A client ID used for a particular channel.
+
In production, the BuzzBot will make an HttpOverRpc call to the above path
when it receives a presence stanza. We simulate the same thing here by using
the dev_appserver's eventing architecture to make a request. Note that this
@@ -317,9 +323,11 @@ class ChannelServiceStub(apiproxy_stub.APIProxyStub):
"""
+
def DefineSendConnectPresenceCallback(client_id):
return lambda: self.connect_channel_event(client_id)
+
self._add_event(0, DefineSendConnectPresenceCallback(client_id),
'channel-connect', client_id)
@@ -336,6 +344,9 @@ class ChannelServiceStub(apiproxy_stub.APIProxyStub):
def add_disconnect_event(self, client_id):
"""Add an event to notify the app if a client has disconnected.
+ Args:
+ client_id: A client ID used for a particular channel.
+
See the comments in add_connect_event above.
"""
timeout = self._time_func() + ChannelServiceStub.CHANNEL_TIMEOUT_SECONDS
