當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。