当前位置: 首页>>代码示例>>Python>>正文


Python api.memcache方法代码示例

本文整理汇总了Python中google.appengine.api.memcache方法的典型用法代码示例。如果您正苦于以下问题:Python api.memcache方法的具体用法?Python api.memcache怎么用?Python api.memcache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.api的用法示例。


在下文中一共展示了api.memcache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: VerifyIdToken

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def VerifyIdToken(self, cls, *args):
    with mock.patch.object(users_id_token, 'time') as mock_time,\
          mock.patch.object(users_id_token, '_get_id_token_user') as mock_get:
      mock_time.time.return_value = 1001
      mock_get.return_value = users.User('test@gmail.com')
      os.environ['HTTP_AUTHORIZATION'] = ('Bearer ' + self._SAMPLE_TOKEN)
      if args:
        cls.method(*args)
      else:
        users_id_token._maybe_set_current_user_vars(cls.method)
      mock_time.time.assert_called_once_with()
      mock_get.assert_called_once_with(
        self._SAMPLE_TOKEN,
        users_id_token._DEFAULT_GOOGLE_ISSUER,
        self._SAMPLE_AUDIENCES,
        (constants.API_EXPLORER_CLIENT_ID,) + self._SAMPLE_ALLOWED_CLIENT_IDS,
        1001,
        memcache,
      ) 
开发者ID:cloudendpoints,项目名称:endpoints-python,代码行数:21,代码来源:users_id_token_test.py

示例2: load_cache

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def load_cache(filename=None):
  """Returns a cache service.

  If Google App Engine Standard Environment's memcache is available, this uses
  memcache as the backend. Otherwise, this uses :obj:`pickle` to cache
  the outputs in the local file system.

  Args:
    filename (str, optional): The file path to the cache file. This is
        used only when :obj:`pickle` is used as the backend.

  Returns:
    A cache system (:obj:`budou.cachefactory.BudouCache`)
  """
  try:
    return AppEngineMemcache()
  except ImportError:
    return PickleCache(filename) 
开发者ID:google,项目名称:budou,代码行数:20,代码来源:cachefactory.py

示例3: remote_api_shell

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def remote_api_shell(servername, appid, path, secure, rpc_server_factory):
  """Actually run the remote_api_shell."""


  remote_api_stub.ConfigureRemoteApi(appid, path, auth_func,
                                     servername=servername,
                                     save_cookies=True, secure=secure,
                                     rpc_server_factory=rpc_server_factory)
  remote_api_stub.MaybeInvokeAuthentication()


  os.environ['SERVER_SOFTWARE'] = 'Development (remote_api_shell)/1.0'

  if not appid:

    appid = os.environ['APPLICATION_ID']
  sys.ps1 = '%s> ' % appid
  if readline is not None:

    readline.parse_and_bind('tab: complete')
    atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
    if os.path.exists(HISTORY_PATH):
      readline.read_history_file(HISTORY_PATH)


  if '' not in sys.path:
    sys.path.insert(0, '')

  preimported_locals = {
      'memcache': memcache,
      'urlfetch': urlfetch,
      'users': users,
      'db': db,
      'ndb': ndb,
      }


  code.interact(banner=BANNER, local=preimported_locals) 
开发者ID:elsigh,项目名称:browserscope,代码行数:40,代码来源:remote_api_shell.py

示例4: get_Auth

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def get_Auth():
    credentials = ServiceAccountCredentials.from_json_keyfile_name(cfg.CREDENTIAL_SERVICE, cfg.DEFAULT_SCOPES)
    http = httplib2.Http(memcache, timeout=60)
    #http = httplib2.Http()
    return credentials.authorize(http) 
开发者ID:jroakes,项目名称:gsc-logger,代码行数:7,代码来源:utils_auth.py

示例5: get_client_from_credentials

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def get_client_from_credentials(credentials):
    """Creates Pub/Sub client from a given credentials and returns it."""
    if credentials.create_scoped_required():
        credentials = credentials.create_scoped(PUBSUB_SCOPES)

    http = httplib2.Http(memcache)
    credentials.authorize(http)

    return discovery.build('pubsub', 'v1', http=http) 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-python,代码行数:11,代码来源:pubsub_utils.py

示例6: __init__

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def __init__(self):
    from google.appengine.api import memcache
    self.memcache = memcache 
开发者ID:google,项目名称:budou,代码行数:5,代码来源:cachefactory.py

示例7: get

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def get(self, key):
    """Gets a value by a key.

    Args:
      key (str): Key to retrieve the value.

    Returns:
      Retrieved value (str or None).
    """
    return self.memcache.get(key, None) 
开发者ID:google,项目名称:budou,代码行数:12,代码来源:cachefactory.py

示例8: set

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def set(self, key, val):
    """Sets a value in a key.

    Args:
      key (str): Key for the value.
      val (str): Value to set.
    """
    self.memcache.set(key, val) 
开发者ID:google,项目名称:budou,代码行数:10,代码来源:cachefactory.py

示例9: suite

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(SimpleCacheTestCase))
    suite.addTest(unittest.makeSuite(FileSystemCacheTestCase))
    if redis is not None:
        suite.addTest(unittest.makeSuite(RedisCacheTestCase))
    if memcache is not None:
        suite.addTest(unittest.makeSuite(MemcachedCacheTestCase))
    return suite 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:11,代码来源:cache.py

示例10: _get_id_token_user

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def _get_id_token_user(token, issuers, audiences, allowed_client_ids, time_now, cache):
  """Get a User for the given id token, if the token is valid.

  Args:
    token: The id_token to check.
    issuers: dict of Issuers
    audiences: List of audiences that are acceptable.
    allowed_client_ids: List of client IDs that are acceptable.
    time_now: The current time as a long (eg. long(time.time())).
    cache: Cache to use (eg. the memcache module).

  Returns:
    A User if the token is valid, None otherwise.
  """
  # Verify that the token is valid before we try to extract anything from it.
  # This verifies the signature and some of the basic info in the token.
  for issuer_key, issuer in issuers.items():
    issuer_cert_uri = convert_jwks_uri(issuer.jwks_uri)
    try:
      parsed_token = _verify_signed_jwt_with_certs(
          token, time_now, cache, cert_uri=issuer_cert_uri)
    except Exception:  # pylint: disable=broad-except
      _logger.debug(
          'id_token verification failed for issuer %s', issuer_key, exc_info=True)
      continue

    issuer_values = _listlike_guard(issuer.issuer, 'issuer', log_warning=False)
    if isinstance(audiences, _Mapping):
      audiences = audiences[issuer_key]
    if _verify_parsed_token(
        parsed_token, issuer_values, audiences, allowed_client_ids,
        # There's some special handling we do for Google issuers.
        # ESP doesn't do this, and it's both unnecessary and invalid for other issuers.
        # So we'll turn it off except in the Google issuer case.
        is_legacy_google_auth=(issuer.issuer == _ISSUERS)):
      email = parsed_token['email']
      # The token might have an id, but it's a Gaia ID that's been
      # obfuscated with the Focus key, rather than the AppEngine (igoogle)
      # key.  If the developer ever put this email into the user DB
      # and retrieved the ID from that, it'd be different from the ID we'd
      # return here, so it's safer to not return the ID.
      # Instead, we'll only return the email.
      return users.User(email)


# pylint: disable=unused-argument 
开发者ID:cloudendpoints,项目名称:endpoints-python,代码行数:48,代码来源:users_id_token.py

示例11: get_verified_jwt

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def get_verified_jwt(
    providers, audiences,
    check_authorization_header=True, check_query_arg=True,
    request=None, cache=memcache):
  """
  This function will extract, verify, and parse a JWT token from the
  Authorization header or access_token query argument.

  The JWT is assumed to contain an issuer and audience claim, as well
  as issued-at and expiration timestamps. The signature will be
  cryptographically verified, the claims and timestamps will be
  checked, and the resulting parsed JWT body is returned.

  If at any point the JWT is missing or found to be invalid, the
  return result will be None.

  Arguments:
  providers - An iterable of dicts each containing 'issuer' and 'cert_uri' keys
  audiences - An iterable of valid audiences

  check_authorization_header - Boolean; check 'Authorization: Bearer' header
  check_query_arg - Boolean; check 'access_token' query arg

  request - Must be the request object if check_query_arg is true; otherwise ignored.
  cache - In testing, override the certificate cache
  """
  if not (check_authorization_header or check_query_arg):
      raise ValueError(
          'Either check_authorization_header or check_query_arg must be True.')
  if check_query_arg and request is None:
      raise ValueError(
          'Cannot check query arg without request object.')
  schemes = ('Bearer',) if check_authorization_header else ()
  keys = ('access_token',) if check_query_arg else ()
  token = _get_token(
      request=request, allowed_auth_schemes=schemes, allowed_query_keys=keys)
  if token is None:
    return None
  time_now = long(time.time())
  for provider in providers:
    parsed_token = _parse_and_verify_jwt(
        token, time_now, (provider['issuer'],), audiences, provider['cert_uri'], cache)
    if parsed_token is not None:
      return parsed_token
  return None 
开发者ID:cloudendpoints,项目名称:endpoints-python,代码行数:47,代码来源:users_id_token.py

示例12: testMaybeSetVarsFail

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def testMaybeSetVarsFail(self, mock_time, mock_get_id_token_user):
    mock_time.return_value = 1001
    mock_get_id_token_user.return_value = users.User('test@gmail.com')

    # This token should correctly result in _get_id_token_user being called
    os.environ['HTTP_AUTHORIZATION'] = ('Bearer ' + self._SAMPLE_TOKEN)
    api_instance = self.TestApiAnnotatedAtApi()

    # No im_self is present and no api_info can be used, so the method itself
    # has no access to scopes, hence scopes will be null and neither of the
    # token checks will occur
    users_id_token._maybe_set_current_user_vars(api_instance.method.im_func)
    self.assertNotIn('ENDPOINTS_USE_OAUTH_SCOPE', os.environ)
    self.assertEqual(os.getenv('ENDPOINTS_AUTH_EMAIL'), '')
    self.assertEqual(os.getenv('ENDPOINTS_AUTH_DOMAIN'), '')

    # Test the same works when using the method and not im_func
    os.environ.pop('ENDPOINTS_AUTH_EMAIL')
    os.environ.pop('ENDPOINTS_AUTH_DOMAIN')
    users_id_token._maybe_set_current_user_vars(api_instance.method)
    self.assertEqual(os.getenv('ENDPOINTS_AUTH_EMAIL'), 'test@gmail.com')
    mock_get_id_token_user.assert_called_once_with(
        self._SAMPLE_TOKEN,
        users_id_token._DEFAULT_GOOGLE_ISSUER,
        self._SAMPLE_AUDIENCES,
        (constants.API_EXPLORER_CLIENT_ID,) + self._SAMPLE_ALLOWED_CLIENT_IDS,
        1001,
        memcache)
    mock_get_id_token_user.reset_mock()

    # Test that it works using the api info from the API
    os.environ.pop('ENDPOINTS_AUTH_EMAIL')
    os.environ.pop('ENDPOINTS_AUTH_DOMAIN')
    users_id_token._maybe_set_current_user_vars(api_instance.method.im_func,
                                                api_info=api_instance.api_info)
    self.assertEqual(os.getenv('ENDPOINTS_AUTH_EMAIL'), 'test@gmail.com')

    mock_get_id_token_user.assert_called_once_with(
        self._SAMPLE_TOKEN,
        users_id_token._DEFAULT_GOOGLE_ISSUER,
        self._SAMPLE_AUDIENCES,
        (constants.API_EXPLORER_CLIENT_ID,) + self._SAMPLE_ALLOWED_CLIENT_IDS,
        1001,
        memcache) 
开发者ID:cloudendpoints,项目名称:endpoints-python,代码行数:46,代码来源:users_id_token_test.py

示例13: loadfile

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def loadfile(filename, cache=None):
  """Loading of client_secrets JSON file, optionally backed by a cache.

  Typical cache storage would be App Engine memcache service,
  but you can pass in any other cache client that implements
  these methods:
    - get(key, namespace=ns)
    - set(key, value, namespace=ns)

  Usage:
    # without caching
    client_type, client_info = loadfile('secrets.json')
    # using App Engine memcache service
    from google.appengine.api import memcache
    client_type, client_info = loadfile('secrets.json', cache=memcache)

  Args:
    filename: string, Path to a client_secrets.json file on a filesystem.
    cache: An optional cache service client that implements get() and set()
      methods. If not specified, the file is always being loaded from
      a filesystem.

  Raises:
    InvalidClientSecretsError: In case of a validation error or some
      I/O failure. Can happen only on cache miss.

  Returns:
    (client_type, client_info) tuple, as _loadfile() normally would.
    JSON contents is validated only during first load. Cache hits are not
    validated.
  """
  _SECRET_NAMESPACE = 'oauth2client:secrets#ns'

  if not cache:
    return _loadfile(filename)

  obj = cache.get(filename, namespace=_SECRET_NAMESPACE)
  if obj is None:
    client_type, client_info = _loadfile(filename)
    obj = {client_type: client_info}
    cache.set(filename, obj, namespace=_SECRET_NAMESPACE)

  return obj.iteritems().next() 
开发者ID:mortcanty,项目名称:earthengine,代码行数:45,代码来源:clientsecrets.py

示例14: loadfile

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def loadfile(filename, cache=None):
    """Loading of client_secrets JSON file, optionally backed by a cache.

    Typical cache storage would be App Engine memcache service,
    but you can pass in any other cache client that implements
    these methods:

    * ``get(key, namespace=ns)``
    * ``set(key, value, namespace=ns)``

    Usage::

        # without caching
        client_type, client_info = loadfile('secrets.json')
        # using App Engine memcache service
        from google.appengine.api import memcache
        client_type, client_info = loadfile('secrets.json', cache=memcache)

    Args:
        filename: string, Path to a client_secrets.json file on a filesystem.
        cache: An optional cache service client that implements get() and set()
        methods. If not specified, the file is always being loaded from
                 a filesystem.

    Raises:
        InvalidClientSecretsError: In case of a validation error or some
                                   I/O failure. Can happen only on cache miss.

    Returns:
        (client_type, client_info) tuple, as _loadfile() normally would.
        JSON contents is validated only during first load. Cache hits are not
        validated.
    """
    _SECRET_NAMESPACE = 'oauth2client:secrets#ns'

    if not cache:
        return _loadfile(filename)

    obj = cache.get(filename, namespace=_SECRET_NAMESPACE)
    if obj is None:
        client_type, client_info = _loadfile(filename)
        obj = {client_type: client_info}
        cache.set(filename, obj, namespace=_SECRET_NAMESPACE)

    return next(six.iteritems(obj)) 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:47,代码来源:clientsecrets.py

示例15: remote_api_shell

# 需要导入模块: from google.appengine import api [as 别名]
# 或者: from google.appengine.api import memcache [as 别名]
def remote_api_shell(servername, appid, path, secure,
                     rpc_server_factory, oauth2=False):
  """Actually run the remote_api_shell."""


  if oauth2:
    remote_api_stub.ConfigureRemoteApiForOAuth(servername, path,
                                               secure=secure, app_id=appid)
  else:
    remote_api_stub.ConfigureRemoteApi(appid, path, auth_func,
                                       servername=servername,
                                       save_cookies=True, secure=secure,
                                       rpc_server_factory=rpc_server_factory)
  remote_api_stub.MaybeInvokeAuthentication()


  os.environ['SERVER_SOFTWARE'] = 'Development (remote_api_shell)/1.0'

  if not appid:

    appid = os.environ['APPLICATION_ID']
  sys.ps1 = '%s> ' % appid
  if readline is not None:

    readline.parse_and_bind('tab: complete')
    atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
    if os.path.exists(HISTORY_PATH):
      readline.read_history_file(HISTORY_PATH)


  if '' not in sys.path:
    sys.path.insert(0, '')

  preimported_locals = {
      'memcache': memcache,
      'urlfetch': urlfetch,
      'users': users,
      'db': db,
      'ndb': ndb,
      }


  code.interact(banner=BANNER, local=preimported_locals) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:45,代码来源:remote_api_shell.py


注:本文中的google.appengine.api.memcache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。