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


Python webapp2.Request方法代码示例

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


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

示例1: get_auth

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def get_auth(factory=Auth, key=_auth_registry_key, request=None):
    """Returns an instance of :class:`Auth` from the request registry.

    It'll try to get it from the current request registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`Auth` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param request:
        A :class:`webapp2.Request` instance used to store the instance. The
        active request is used if it is not set.
    """
    request = request or webapp2.get_request()
    auth = request.registry.get(key)
    if not auth:
        auth = request.registry[key] = factory(request)

    return auth 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:25,代码来源:auth.py

示例2: __init__

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def __init__(self, request, config=None):
        """Initializes the session store.

        :param request:
            A :class:`webapp2.Request` instance.
        :param config:
            A dictionary of configuration values to be overridden. See
            the available keys in :data:`default_config`.
        """
        self.request = request
        # Base configuration.
        self.config = request.app.config.load_config(self.config_key,
            default_values=default_config, user_values=config,
            required_keys=('secret_key',))
        # Tracked sessions.
        self.sessions = {} 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:18,代码来源:sessions.py

示例3: get_store

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def get_store(factory=SessionStore, key=_registry_key, request=None):
    """Returns an instance of :class:`SessionStore` from the request registry.

    It'll try to get it from the current request registry, and if it is not
    registered it'll be instantiated and registered. A second call to this
    function will return the same instance.

    :param factory:
        The callable used to build and register the instance if it is not yet
        registered. The default is the class :class:`SessionStore` itself.
    :param key:
        The key used to store the instance in the registry. A default is used
        if it is not set.
    :param request:
        A :class:`webapp2.Request` instance used to store the instance. The
        active request is used if it is not set.
    """
    request = request or webapp2.get_request()
    store = request.registry.get(key)
    if not store:
        store = request.registry[key] = factory(request)

    return store 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:25,代码来源:sessions.py

示例4: set_store

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def set_store(store, key=_registry_key, request=None):
    """Sets an instance of :class:`SessionStore` in the request registry.

    :param store:
        An instance of :class:`SessionStore`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.Request` instance used to retrieve the instance. The
        active request is used if it is not set.
    """
    request = request or webapp2.get_request()
    request.registry[key] = store


# Don't need to import it. :) 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:19,代码来源:sessions.py

示例5: parse_body

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def parse_body(self):
    """Parses JSON body and verifies it's a dict.

    webob.Request doesn't cache the decoded json body, this function does.
    """
    if self._json_body is None:
      if (self.CONTENT_TYPE_BASE and
          self.request.content_type != self.CONTENT_TYPE_BASE):
        msg = (
            'Expecting JSON body with content type \'%s\'' %
            self.CONTENT_TYPE_BASE)
        self.abort_with_error(400, text=msg)
      try:
        self._json_body = self.request.json
        if not isinstance(self._json_body, dict):
          raise ValueError()
      except (LookupError, ValueError):
        self.abort_with_error(400, text='Not a valid json dict body')
    return self._json_body.copy() 
开发者ID:luci,项目名称:luci-py,代码行数:21,代码来源:handler.py

示例6: get_session

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def get_session(self, request):
        """Returns an auth session.

        :param request:
            A :class:`webapp2.Request` instance.
        :returns:
            A session dict.
        """
        store = sessions.get_store(request=request)
        return store.get_session(self.config['cookie_name'],
                                 backend=self.config['session_backend']) 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:13,代码来源:auth.py

示例7: __init__

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def __init__(self, request):
        """Initializes the auth provider for a request.

        :param request:
            A :class:`webapp2.Request` instance.
        """
        self.request = request
        self.store = get_store(app=request.app)

    # Retrieving a user ------------------------------------------------------- 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:12,代码来源:auth.py

示例8: set_auth

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def set_auth(auth, key=_auth_registry_key, request=None):
    """Sets an instance of :class:`Auth` in the request registry.

    :param auth:
        An instance of :class:`Auth`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.Request` instance used to retrieve the instance. The
        active request is used if it is not set.
    """
    request = request or webapp2.get_request()
    request.registry[key] = auth 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:16,代码来源:auth.py

示例9: __init__

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def __init__(self, request):
        """Initializes the i18n provider for a request.

        :param request:
            A :class:`webapp2.Request` instance.
        """
        self.store = store = get_store(app=request.app)
        self.set_locale(store.locale_selector(request))
        self.set_timezone(store.timezone_selector(request)) 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:11,代码来源:i18n.py

示例10: set_i18n

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def set_i18n(i18n, key=_i18n_registry_key, request=None):
    """Sets an instance of :class:`I18n` in the request registry.

    :param store:
        An instance of :class:`I18n`.
    :param key:
        The key used to retrieve the instance from the registry. A default
        is used if it is not set.
    :param request:
        A :class:`webapp2.Request` instance used to retrieve the instance. The
        active request is used if it is not set.
    """
    request = request or webapp2.get_request()
    request.registry[key] = i18n 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:16,代码来源:i18n.py

示例11: call

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def call(self, body=None, raw_token=None):
    if body:
      env = machine_token_pb2.MachineTokenEnvelope()
      env.token_body = body.SerializeToString()
      env.key_id = 'signing_key'
      env.rsa_sha256 = 'signature'
      raw_token = base64.b64encode(env.SerializeToString())
    req = webapp2.Request({})
    if raw_token:
      req.headers['X-Luci-Machine-Token'] = raw_token
    return machine_auth.machine_authentication(req) 
开发者ID:luci,项目名称:luci-py,代码行数:13,代码来源:machine_auth_test.py

示例12: require_xsrf_token_request

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def require_xsrf_token_request(f):
  """Use for handshaking APIs."""
  @functools.wraps(f)
  def hook(self, *args, **kwargs):
    if not self.request.headers.get('X-XSRF-Token-Request'):
      raise api.AuthorizationError('Missing required XSRF request header')
    return f(self, *args, **kwargs)
  return hook 
开发者ID:luci,项目名称:luci-py,代码行数:10,代码来源:handler.py

示例13: get_auth_methods

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def get_auth_methods(cls, conf):  # pylint: disable=unused-argument
    """Returns an enumerable of functions to use to authenticate request.

    The handler will try to apply auth methods sequentially one by one by until
    it finds one that works.

    Each auth method is a function that accepts webapp2.Request and can finish
    with 3 outcomes:

    * Return (None, ...): authentication method is not applicable to that
      request and next method should be tried (for example cookie-based
      authentication is not applicable when there's no cookies).

    * Returns (Identity, AuthDetails). It means the authentication method
      is applicable and the caller is authenticated as 'Identity'. All
      additional information extracted from the credentials (like if the caller
      is a GAE-level admin) is returned through AuthDetails tuple. It can be
      None if there are no extra information.

    * Raises AuthenticationError: authentication method is applicable, but
      request contains bad credentials or invalid token, etc. For example,
      OAuth2 token is given, but it is revoked.

    A chosen auth method function will be stored in request's auth_method field.

    Args:
      conf: components.auth GAE config, see config.py.
    """
    return (
        oauth_authentication,
        gae_cookie_authentication,
        service_to_service_authentication) 
开发者ID:luci,项目名称:luci-py,代码行数:34,代码来源:handler.py

示例14: do_get

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def do_get(cls, name, request):  # pylint: disable=unused-argument
    """Returns an entity given its name or None if no such entity.

    Can be called in any mode (including on replicas).

    Args:
      name: name of the entity to fetch (use get_entity_key to convert to key).
      request: webapp2.Request object.
    """
    return cls.get_entity_key(name).get() 
开发者ID:luci,项目名称:luci-py,代码行数:12,代码来源:rest_api.py

示例15: test_applicable_non_admin

# 需要导入模块: import webapp2 [as 别名]
# 或者: from webapp2 import Request [as 别名]
def test_applicable_non_admin(self):
    os.environ.update({
      'USER_EMAIL': 'joe@example.com',
      'USER_ID': '123',
      'USER_IS_ADMIN': '0',
    })
    # Actual request is not used by CookieAuthentication.
    self.assertEqual(
        (
          model.Identity(model.IDENTITY_USER, 'joe@example.com'),
          api.new_auth_details(is_superuser=False),
        ),
        handler.gae_cookie_authentication(webapp2.Request({}))) 
开发者ID:luci,项目名称:luci-py,代码行数:15,代码来源:handler_test.py


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