當前位置: 首頁>>代碼示例>>Python>>正文


Python webapp2.RequestHandler方法代碼示例

本文整理匯總了Python中webapp2.RequestHandler方法的典型用法代碼示例。如果您正苦於以下問題:Python webapp2.RequestHandler方法的具體用法?Python webapp2.RequestHandler怎麽用?Python webapp2.RequestHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在webapp2的用法示例。


在下文中一共展示了webapp2.RequestHandler方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: MakeCommandHandler

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def MakeCommandHandler(cmd_cls):
  """Takes a command class and returns a route tuple which allows that command
     to be executed.
  """
  class H(webapp2.RequestHandler):
    def get(self):
      self.response.write("""
      <h1>You are about to run command "{}". Are you sure?</h1>
      <form action="" method="POST">
      <button>Punch it</button>
      </form>""".format(self._get_cmd().NAME))

    def post(self):
      deferred.defer(self._get_cmd().run)
      self.response.write('Command started.')

    def _get_cmd(self):
      if 'cmds' not in self.app.registry:
        self.app.registry['cmds'] = {}
      if cmd_cls.SHORT_NAME not in self.app.registry['cmds']:
        self.app.registry['cmds'][cmd_cls.SHORT_NAME] = cmd_cls(self.app.config)
      return self.app.registry['cmds'][cmd_cls.SHORT_NAME]

  return ('/admin/command/' + cmd_cls.SHORT_NAME, H) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:26,代碼來源:admin.py

示例2: _build_state_value

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def _build_state_value(request_handler, user):
    """Composes the value for the 'state' parameter.

    Packs the current request URI and an XSRF token into an opaque string that
    can be passed to the authentication server via the 'state' parameter.

    Args:
        request_handler: webapp.RequestHandler, The request.
        user: google.appengine.api.users.User, The current user.

    Returns:
        The state value as a string.
    """
    uri = request_handler.request.url
    token = xsrfutil.generate_token(xsrf_secret_key(), user.user_id(),
                                    action_id=str(uri))
    return uri + ':' + token 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:19,代碼來源:appengine.py

示例3: _create_flow

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def _create_flow(self, request_handler):
        """Create the Flow object.

        The Flow is calculated lazily since we don't know where this app is
        running until it receives a request, at which point redirect_uri can be
        calculated and then the Flow object can be constructed.

        Args:
            request_handler: webapp.RequestHandler, the request handler.
        """
        if self.flow is None:
            redirect_uri = request_handler.request.relative_url(
                self._callback_path)  # Usually /oauth2callback
            self.flow = OAuth2WebServerFlow(
                self._client_id, self._client_secret, self._scope,
                redirect_uri=redirect_uri, user_agent=self._user_agent,
                auth_uri=self._auth_uri, token_uri=self._token_uri,
                revoke_uri=self._revoke_uri, **self._kwargs) 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:20,代碼來源:appengine.py

示例4: _create_flow

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def _create_flow(self, request_handler):
        """Create the Flow object.

        The Flow is calculated lazily since we don't know where this app is
        running until it receives a request, at which point redirect_uri can be
        calculated and then the Flow object can be constructed.

        Args:
            request_handler: webapp.RequestHandler, the request handler.
        """
        if self.flow is None:
            redirect_uri = request_handler.request.relative_url(
                self._callback_path)  # Usually /oauth2callback
            self.flow = client.OAuth2WebServerFlow(
                self._client_id, self._client_secret, self._scope,
                redirect_uri=redirect_uri, user_agent=self._user_agent,
                auth_uri=self._auth_uri, token_uri=self._token_uri,
                revoke_uri=self._revoke_uri, **self._kwargs) 
開發者ID:fniephaus,項目名稱:alfred-gmail,代碼行數:20,代碼來源:appengine.py

示例5: forbid_ui_on_replica

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def forbid_ui_on_replica(method):
  """Decorator for methods that are not allowed to be called on Replica.

  If such method is called on a service in Replica mode, it would return
  HTTP 405 "Method Not Allowed".
  """
  @functools.wraps(method)
  def wrapper(self, *args, **kwargs):
    assert isinstance(self, webapp2.RequestHandler)
    if model.is_replica():
      primary_url = model.get_replication_state().primary_url
      self.abort(
          405,
          detail='Not allowed on a replica, see primary at %s' % primary_url)
    return method(self, *args, **kwargs)
  return wrapper 
開發者ID:luci,項目名稱:luci-py,代碼行數:18,代碼來源:ui.py

示例6: forbid_api_on_replica

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def forbid_api_on_replica(method):
  """Decorator for methods that are not allowed to be called on Replica.

  If such method is called on a service in Replica mode, it would return
  HTTP 405 "Method Not Allowed".
  """
  @functools.wraps(method)
  def wrapper(self, *args, **kwargs):
    assert isinstance(self, webapp2.RequestHandler)
    if model.is_replica():
      self.abort(
          405,
          json={
            'primary_url': model.get_replication_state().primary_url,
            'text': 'Use Primary service for API requests',
          },
          headers={
            'Content-Type': 'application/json; charset=utf-8',
          })
    return method(self, *args, **kwargs)
  return wrapper 
開發者ID:luci,項目名稱:luci-py,代碼行數:23,代碼來源:rest_api.py

示例7: test_forbidden_on_replica

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def test_forbidden_on_replica(self):
    calls = []

    class Handler(webapp2.RequestHandler):
      @rest_api.forbid_api_on_replica
      def get(self):
        calls.append(1)

    mock_replication_state('http://locahost:1234')
    response = call_get(Handler, status=405)

    self.assertEqual(0, len(calls))
    expected = {
      'primary_url': 'http://locahost:1234',
      'text': 'Use Primary service for API requests',
    }
    self.assertEqual(expected, json.loads(response.body)) 
開發者ID:luci,項目名稱:luci-py,代碼行數:19,代碼來源:rest_api_test.py

示例8: directory_handler_factory

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def directory_handler_factory(api_classes, base_path):
  """Returns a directory request handler which knows about the given services.

  Args:
    api_classes: A list of protorpc.remote.Service classes the handler should
      know about.
    base_path: The base path under which all service paths exist.

  Returns:
    A webapp2.RequestHandler.
  """
  class DirectoryHandler(webapp2.RequestHandler):
    """Returns a directory list for known services."""

    def get(self):
      host = self.request.headers['Host']
      self.response.headers['Content-Type'] = 'application/json'
      json.dump(
          discovery.directory(api_classes, host, base_path),
          self.response, indent=2, sort_keys=True, separators=(',', ':'))

  return DirectoryHandler 
開發者ID:luci,項目名稱:luci-py,代碼行數:24,代碼來源:adapter.py

示例9: explorer_redirect_route

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def explorer_redirect_route(base_path):
  """Returns a route to a handler which redirects to the API explorer.

  Args:
    base_path: The base path under which all service paths exist.

  Returns:
    A webapp2.Route.
  """
  class RedirectHandler(webapp2.RequestHandler):
    """Returns a handler redirecting to the API explorer."""

    def get(self):
      host = self.request.headers['Host']
      self.redirect('https://apis-explorer.appspot.com/apis-explorer'
                    '/?base=https://%s%s' % (host, base_path))

  return webapp2.Route('%s/explorer' % base_path, RedirectHandler) 
開發者ID:luci,項目名稱:luci-py,代碼行數:20,代碼來源:adapter.py

示例10: redirect_ui_on_replica

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def redirect_ui_on_replica(method):
  """Decorator for methods that redirect to Primary when called on replica.

  If such method is called on a service in Replica mode, it would return
  HTTP 302 redirect to corresponding method on Primary.
  """
  @functools.wraps(method)
  def wrapper(self, *args, **kwargs):
    assert isinstance(self, webapp2.RequestHandler)
    assert self.request.method == 'GET'
    if model.is_replica():
      primary_url = model.get_replication_state().primary_url
      protocol = 'http://' if utils.is_local_dev_server() else 'https://'
      assert primary_url and primary_url.startswith(protocol), primary_url
      assert self.request.path_qs.startswith('/'), self.request.path_qs
      self.redirect(primary_url.rstrip('/') + self.request.path_qs, abort=True)
    return method(self, *args, **kwargs)
  return wrapper


################################################################################
## Admin routes. The use cookies and GAE's "is_current_user_admin" for authn. 
開發者ID:luci,項目名稱:luci-py,代碼行數:24,代碼來源:ui.py

示例11: explorer_proxy_route

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def explorer_proxy_route(base_path):
  """Returns a route to a handler which serves an API explorer proxy.

  Args:
    base_path: The base path under which all service paths exist.

  Returns:
    A webapp2.Route.
  """
  class ProxyHandler(webapp2.RequestHandler):
    """Returns a proxy capable of handling requests from API explorer."""

    def get(self):
      self.response.write(template.render(
          'adapter/proxy.html', params={'base_path': base_path}))

  template.bootstrap({
      'adapter': os.path.join(THIS_DIR, 'templates'),
  })
  return webapp2.Route('%s/static/proxy.html' % base_path, ProxyHandler) 
開發者ID:luci,項目名稱:luci-py,代碼行數:22,代碼來源:adapter.py

示例12: __init__

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def __init__(self, *args, **kwargs):
    """Override RequestHandler init to track app readiness."""
    super(FrontendHandler, self).__init__(*args, **kwargs)
    self.bootstrap_started = bootstrap.is_bootstrap_started()
    self.bootstrap_completed = bootstrap.is_bootstrap_completed() 
開發者ID:google,項目名稱:loaner,代碼行數:7,代碼來源:frontend.py

示例13: dispatch

# 需要導入模塊: import webapp2 [as 別名]
# 或者: from webapp2 import RequestHandler [as 別名]
def dispatch(self):
        # Get a session store for this request.
        self.session_store = sessions.get_store(request=self.request)

        try:
            # Dispatch the request.
            webapp2.RequestHandler.dispatch(self)
        finally:
            # Save all sessions.
            self.session_store.save_sessions(self.response) 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:12,代碼來源:session.py


注:本文中的webapp2.RequestHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。