Include Channel API changes from the 1.6.2 SDK
@@ -45,9 +45,13 @@ from google.appengine.runtime import apiproxy_errors
+
MAXIMUM_CLIENT_ID_LENGTH = 256
+MAXIMUM_TOKEN_DURATION_MINUTES = 24 * 60
+
+
@@ -63,6 +67,10 @@ class InvalidChannelClientIdError(Error):
"""Error that indicates a bad client id."""
+class InvalidChannelTokenDurationError(Error):
+ """Error that indicates the requested duration is invalid."""
+
+
class InvalidMessageError(Error):
"""Error that indicates a message is malformed."""
@@ -129,24 +137,35 @@ def create_channel(client_id, duration_minutes=None):
Args:
client_id: A string to identify this channel on the server side.
- duration_minutes: A string, the maximum number of minutes the channel
- should be open.
+ duration_minutes: An int specifying the number of minutes for which the
+ returned token should be valid.
+
Returns:
A token that the client can use to connect to the channel.
Raises:
InvalidChannelClientIdError: if clientid is not an instance of str or
unicode, or if the (utf-8 encoded) string is longer than 64 characters.
+ InvalidChannelTokenDurationError: if duration_minutes is not a number, less
+ than 1, or greater than 1440 (the number of minutes in a day).
Other errors returned by _ToChannelError
"""
client_id = _ValidateClientId(client_id)
+ if (not duration_minutes is None and
+ (not isinstance(duration_minutes, (int, long)) or
+ duration_minutes < 1 or
+ duration_minutes > MAXIMUM_TOKEN_DURATION_MINUTES)):
+ raise InvalidChannelTokenDurationError
+
request = channel_service_pb.CreateChannelRequest()
response = channel_service_pb.CreateChannelResponse()
request.set_application_key(client_id)
+ if not duration_minutes is None:
+ request.set_duration_minutes(duration_minutes)
try:
apiproxy_stub_map.MakeSyncCall(_GetService(),
