How to use the webob.Request function in WebOb

To help you get started, we’ve selected a few WebOb 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 pipermerriam / flex / tests / http / test_request_normalization.py View on Github external
def test_webob_client_request_normalization(httpbin):
    import webob

    raw_request = webob.Request.blank(httpbin.url + '/get')
    raw_request.query_string = 'key=val'
    raw_request.method = 'GET'
    raw_request.content_type = 'application/json'

    request = normalize_request(raw_request)

    assert request.path == '/get'
    assert request.content_type == 'application/json'
    assert request.url == httpbin.url + '/get?key=val'
    assert request.method == 'get'
github toscawidgets / tw2.core / tests / test_resources.py View on Github external
def simple_app(environ, start_response):
    req = wo.Request(environ)
    ct = 'text/html' if req.path == '/' else 'test/plain'
    resp = wo.Response(request=req, content_type="%s; charset=UTF8" % ct)
    inject_widget.display()
    if six.PY3:
        resp.text = html
    else:
        resp.body = html
    return resp(environ, start_response)
github mozilla / geodude / tests.py View on Github external
def request(path, allow_post=False, **kwargs):
    app = geodude.make_application(fake_geo_data, allow_post)
    request = Request.blank(path, **kwargs)
    return request.get_response(app)
github Pylons / webtest / webtest / debugapp.py View on Github external
def __call__(self, environ, start_response):
        req = webob.Request(environ)
        if req.path_info == '/form.html' and req.method == 'GET':
            resp = webob.Response(content_type='text/html')
            resp.body = self.form
            return resp(environ, start_response)

        if 'error' in req.GET:
            raise Exception('Exception requested')

        if 'errorlog' in req.GET:
            log = req.GET['errorlog']
            if not six.PY3 and not isinstance(log, six.binary_type):
                log = log.encode('utf8')
            req.environ['wsgi.errors'].write(log)

        status = str(req.GET.get('status', '200 OK'))
github pneff / wsgiservice / tests / test_resource_json.py View on Github external
def test_accept_non_dict():
    """Input data are not necessarily dictionaries.

    Make sure nothing breaks, but the `data` won't contain those values.
    """

    class User(wsgiservice.Resource):
        def POST(self):
            return self.data

    req = webob.Request.blank('/', headers={'Accept': 'application/json',
                                            'Content-Type': 'application/json'},
                              method='POST', body='123')
    res = webob.Response()
    usr = User(request=req, response=res, path_params={})
    res = usr()
    print res
    assert res.status_int == 200
    obj = json.loads(res.body)
    assert obj == {}
github Pylons / webtest / docs / testresponse_fixt.py View on Github external
def application(environ, start_response):
    req = Request(environ)
    if req.path_info.endswith('.html'):
        content_type = 'text/html'
        body = six.b('<div id="content">hey!</div>')
    elif req.path_info.endswith('.xml'):
        content_type = 'text/xml'
        body = six.b('hey!')
    elif req.path_info.endswith('.json'):
        content_type = 'application/json'
        body = six.b(json.dumps({"a": 1, "b": 2}))
    resp = Response(body, content_type=content_type)
    return resp(environ, start_response)
github c00w / bitHopper / work.py View on Github external
def handle_LP(self, env, start_response):
        start_response('200 OK', [('Content-Type', 'text/json')])
        
        request = webob.Request(env)
        j_id = None
        try:
            rpc_request = json.loads(request.body)
            j_id = rpc_request['id']

        except Exception, e:
            logging.debug('Error in json handle_LP')
            logging.debug(e)
            if not j_id:
                j_id = 1
        
        value = self.bitHopper.lp_callback.read()

        try:
            data = env.get('HTTP_AUTHORIZATION').split(None, 1)[1]
            username = data.decode('base64').split(':', 1)[0] # Returns ['username', 'password']
github toscawidgets / tw2.forms / examples / myapp.py View on Github external
def app(environ, start_response):
    req = wo.Request(environ)
    resp = wo.Response(request=req, content_type="text/html; charset=UTF8")
    if req.method == 'GET':
        resp.body = TestPage.display().encode('utf-8')
    elif req.method == 'POST':
        try:
            data = TestPage.validate(req.POST)
            resp.body = 'Posted successfully ' + wo.html_escape(repr(data))
        except twc.ValidationError, e:
            resp.body = e.widget.display().encode('utf-8')
    return resp(environ, start_response)
github openstack / python-keystoneclient / keystoneclient / middleware / s3_token.py View on Github external
def __call__(self, environ, start_response):
        """Handle incoming request. authenticate and send downstream."""
        req = webob.Request(environ)
        self.logger.debug('Calling S3Token middleware.')

        try:
            parts = split_path(req.path, 1, 4, True)
            version, account, container, obj = parts
        except ValueError:
            msg = 'Not a path query, skipping.'
            self.logger.debug(msg)
            return self.app(environ, start_response)

        # Read request signature and access id.
        if 'Authorization' not in req.headers:
            msg = 'No Authorization header. skipping.'
            self.logger.debug(msg)
            return self.app(environ, start_response)
github pneff / wsgiservice / wsgiservice / application.py View on Github external
def __call__(self, environ, start_response):
        """WSGI entry point. Serve the best matching resource for the current
        request. See :pep:`333` for details of this method.

        :param environ: Environment dictionary.
        :param start_response: Function called when the response is ready to
               be served.
        """
        try:
            request = webob.Request(environ)
            self._log_request(request)
            response = self._handle_request(request)
            return response(environ, start_response)
        except Exception as e:
            logger.exception('Uncaught exception in service: %s', e)
            raise