def StoreCalendarSessionToken(relative_url): """Extract calendar auth tokens from url and store them in the datastore. Args: relative_url: The url that was called by the calendar token system with token information in it. """ # Get auth token from url. auth_token = auth.extract_auth_sub_token_from_url(relative_url) assert auth_token # Upgrade to session token. calendar_client = calendar_service.CalendarService() gdata_appengine.run_on_appengine(calendar_client, store_tokens=False, single_user_mode=True, deadline=10) session_token = calendar_client.upgrade_to_session_token(auth_token) assert session_token # Write session token to datastore. session_token_str = session_token.get_token_string() config = models.Configuration(key_name=_CALENDAR_TOKEN_KEY_NAME, config_value=session_token_str, config_key=_CALENDAR_TOKEN_KEY_NAME) config.put() # Refresh memcache session token and make sure a usable calendar client can be # created. calendar_client = _GetCalendarService(refresh_memcache=True) assert calendar_client is not None