예제 #1
0
    def check_login(self, *args):
        if self.request.method != 'GET':
            raise webapp.Error(
                'The check_login decorator can only be used for GET '
                'requests')
        user = users.get_current_user()
        if not user:
            self.redirect(users.create_login_url(self.request.uri))
            return
        else:
            handler_method(self, *args)

    return check_login


_config_handle = lib_config.register('webapp',
                                     {'add_wsgi_middleware': lambda app: app})


def run_wsgi_app(application):
    """Runs your WSGI-compliant application object in a CGI environment.

  Compared to wsgiref.handlers.CGIHandler().run(application), this
  function takes some shortcuts.  Those are possible because the
  app server makes stronger promises than the CGI standard.

  Also, this function may wrap custom WSGI middleware around the
  application.  (You can use run_bare_wsgi_app() to run an application
  without adding WSGI middleware, and add_wsgi_middleware() to wrap
  the configured WSGI middleware around an application without running
  it.  This function is merely a convenient combination of the latter
  two.)
예제 #2
0
           'validate_namespace',
          ]


_ENV_DEFAULT_NAMESPACE = 'HTTP_X_APPENGINE_DEFAULT_NAMESPACE'
_ENV_CURRENT_NAMESPACE = 'HTTP_X_APPENGINE_CURRENT_NAMESPACE'

_NAMESPACE_MAX_LENGTH = 100
_NAMESPACE_PATTERN = r'^[0-9A-Za-z._-]{0,%s}$' % _NAMESPACE_MAX_LENGTH
_NAMESPACE_RE = re.compile(_NAMESPACE_PATTERN)

class _ConfigDefaults(object):
  def default_namespace_for_request():
      return None

_config = lib_config.register('namespace_manager_', _ConfigDefaults.__dict__)

def set_namespace(namespace):
  """Set the default namespace for the current HTTP request.

  Args:
    namespace: A string naming the new namespace to use. A value of None
      will unset the default namespace value.
  """
  if namespace is None:
    os.environ.pop(_ENV_CURRENT_NAMESPACE, None)
  else:
    validate_namespace(namespace)
    os.environ[_ENV_CURRENT_NAMESPACE] = namespace

예제 #3
0
]

_ENV_DEFAULT_NAMESPACE = 'HTTP_X_APPENGINE_DEFAULT_NAMESPACE'
_ENV_CURRENT_NAMESPACE = 'HTTP_X_APPENGINE_CURRENT_NAMESPACE'

_NAMESPACE_MAX_LENGTH = 100
_NAMESPACE_PATTERN = r'^[0-9A-Za-z._-]{0,%s}$' % _NAMESPACE_MAX_LENGTH
_NAMESPACE_RE = re.compile(_NAMESPACE_PATTERN)


class _ConfigDefaults(object):
    def default_namespace_for_request():
        return None


_config = lib_config.register('namespace_manager_', _ConfigDefaults.__dict__)


def set_namespace(namespace):
    """Set the default namespace for the current HTTP request.

  Args:
    namespace: A string naming the new namespace to use. A value of None
      will unset the default namespace value.
  """
    if namespace is None:
        os.environ.pop(_ENV_CURRENT_NAMESPACE, None)
    else:
        validate_namespace(namespace)
        os.environ[_ENV_CURRENT_NAMESPACE] = namespace
예제 #4
0
파일: util.py 프로젝트: anoopjoe/cyclozzo
  """
  def check_login(self, *args):
    if self.request.method != 'GET':
      raise webapp.Error('The check_login decorator can only be used for GET '
                         'requests')
    user = users.get_current_user()
    if not user:
      self.redirect(users.create_login_url(self.request.uri))
      return
    else:
      handler_method(self, *args)
  return check_login


_config_handle = lib_config.register(
    'webapp',
    {'add_wsgi_middleware': lambda app: app})


def run_wsgi_app(application):
  """Runs your WSGI-compliant application object in a CGI environment.

  Compared to wsgiref.handlers.CGIHandler().run(application), this
  function takes some shortcuts.  Those are possible because the
  app server makes stronger promises than the CGI standard.

  Also, this function may wrap custom WSGI middleware around the
  application.  (You can use run_bare_wsgi_app() to run an application
  without adding WSGI middleware, and add_wsgi_middleware() to wrap
  the configured WSGI middleware around an application without running
  it.  This function is merely a convenient combination of the latter