How to use the wsgiref.util function in wsgiref

To help you get started, we’ve selected a few wsgiref examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mw44118 / pitz / tests / test_webapp.py View on Github external
def setUp(self):
        self.p = Project(title='Bogus project for testing webapp')
        self.app = webapp.SimpleWSGIApp(self.p)
        self.app.handlers = []

        self.bogus_environ = dict(
            PATH_INFO='/fibityfoo',
            QUERY_STRING='?a=1')

        wsgiref.util.setup_testing_defaults(self.bogus_environ)
github minixalpha / SourceLearning / wsgiref-0.1.2 / src / test_wsgiref.py View on Github external
def checkShift(self,sn_in,pi_in,part,sn_out,pi_out):
        env = {'SCRIPT_NAME':sn_in,'PATH_INFO':pi_in}
        util.setup_testing_defaults(env)
        self.assertEqual(util.shift_path_info(env),part)
        self.assertEqual(env['PATH_INFO'],pi_out)
        self.assertEqual(env['SCRIPT_NAME'],sn_out)
        return env
github gevent / gevent / src / greentest / 3.6pypy / test_wsgiref.py View on Github external
def checkShift(self,sn_in,pi_in,part,sn_out,pi_out):
        env = {'SCRIPT_NAME':sn_in,'PATH_INFO':pi_in}
        util.setup_testing_defaults(env)
        self.assertEqual(util.shift_path_info(env),part)
        self.assertEqual(env['PATH_INFO'],pi_out)
        self.assertEqual(env['SCRIPT_NAME'],sn_out)
        return env
github bottlepy / bottle / test / test_sendfile.py View on Github external
def setUp(self):
        e = dict()
        wsgiref.util.setup_testing_defaults(e)
        b = Bottle()
        request.bind(e)
        response.bind()
github gevent / gevent / src / greentest / 3.8 / test_wsgiref.py View on Github external
def test_filewrapper_getitem_deprecation(self):
        wrapper = util.FileWrapper(StringIO('foobar'), 3)
        with self.assertWarnsRegex(DeprecationWarning,
                                   r'Use iterator protocol instead'):
            # This should have returned 'bar'.
            self.assertEqual(wrapper[1], 'foo')
github rongarret / microWiki / src / yaro.py View on Github external
def __call__(self, instance, environ, start_response):
        """Create Request, call thing, unwrap results and respond."""
        req = Request(environ, start_response, self.extra_props)
        body = self.app(instance, req)
        req.save_to_environ()
        if body is None:
            body = req.res.body
        if not req.start_response_called:
            req.start_response(req.res.status, req.res._headers, req.exc_info)
            req.start_response_called = True
        if isinstance(body, str):
            return [body]
        elif isiterable(body):
            return body
        else:
            return util.FileWrapper(body)
github watsonpy / watson-framework / watson / framework / support / console / commands / project.py View on Github external
"""Aids in the debugging of routes associated.

        Args:
            path: Validate the specified path against the router
            method: The http request method
            format: The http request format
            server: The hostname of the request
        """
        try:
            router = self.router
            if not router.routes:
                raise ConsoleError(
                    'There are no routes associated with the application.')
            if path:
                environ = {}
                util.setup_testing_defaults(environ)
                server = server or '127.0.0.1'
                environ.update({
                    'REQUEST_METHOD': method or 'GET',
                    'HTTP_ACCEPT': format or 'text/html',
                    'PATH_INFO': path,
                    'SERVER_NAME': server,
                    'HTTP_HOST': server
                })
                request = Request.from_environ(environ)
                matches = [match for match in router.matches(request)]

                if matches:
                    longest_route = max([match.route.name for match in matches], key=len)
                    self.write(
                        colors.header('Displaying {} matching routes for {}:\n'.format(
                            len(matches), request.url)))
github Khan / frankenserver / python / google / appengine / tools / devappserver2 / url_handler.py View on Github external
cookies = environ.get('HTTP_COOKIE')
    email_addr, admin, _ = login.get_user_info(cookies)

    if constants.FAKE_IS_ADMIN_HEADER in environ:
      admin = True

    if constants.FAKE_LOGGED_IN_HEADER in environ:
      email_addr = 'Fake User'

    # admin has an effect only with login: admin (not login: required).
    if requires_login and not email_addr and not (admin and admin_only):
      if auth_fail_action == appinfo.AUTH_FAIL_ACTION_REDIRECT:
        logging.debug('login required, redirecting user')
        return login.login_redirect(wsgiref.util.application_uri(environ),
                                    wsgiref.util.request_uri(environ),
                                    start_response)
      elif auth_fail_action == appinfo.AUTH_FAIL_ACTION_UNAUTHORIZED:
        logging.debug('login required, user unauthorized')
        start_response('401 Not authorized', [('Content-Type', 'text/html'),
                                              ('Cache-Control', 'no-cache')])
        return ['Login required to view page.']
    elif admin_only and not admin:
      logging.debug('admin required, user unauthorized')
      start_response('401 Not authorized', [('Content-Type', 'text/html'),
                                            ('Cache-Control', 'no-cache')])
      return ['Current logged in user %s is not '
              'authorized to view this page.'
              % email_addr]

    # Authorization check succeeded
    return None
github alangpierce / appengine-python3 / google / appengine / api / appinfo.py View on Github external
if not _HTTP_TOKEN_RE.match(name):
        raise appinfo_errors.InvalidHttpHeaderName(
            'An HTTP header must be a non-empty RFC 2616 token.')


      if name in _HTTP_REQUEST_HEADERS:
        raise appinfo_errors.InvalidHttpHeaderName(
            '%r can only be used in HTTP requests, not responses.'
            % original_name)


      if name.startswith('x-appengine'):
        raise appinfo_errors.InvalidHttpHeaderName(
            'HTTP header names that begin with X-Appengine are reserved.')

      if wsgiref.util.is_hop_by_hop(name):
        raise appinfo_errors.InvalidHttpHeaderName(
            'Only use end-to-end headers may be used. See RFC 2616 section'
            ' 13.5.1.')

      if name in HttpHeadersDict.DISALLOWED_HEADERS:
        raise appinfo_errors.InvalidHttpHeaderName(
            '%s is a disallowed header.' % name)

      return original_name