当前位置: 首页>>代码示例>>Python>>正文


Python webob.Response方法代码示例

本文整理汇总了Python中webob.Response方法的典型用法代码示例。如果您正苦于以下问题:Python webob.Response方法的具体用法?Python webob.Response怎么用?Python webob.Response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webob的用法示例。


在下文中一共展示了webob.Response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: lti_1p3_launch_handler

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def lti_1p3_launch_handler(self, request, suffix=''):  # pylint: disable=unused-argument
        """
        XBlock handler for launching the LTI 1.3 tools.

        Displays a form with the OIDC preflight request and
        submits it to the tool.

        Arguments:
            request (xblock.django.request.DjangoWebobRequest): Request object for current HTTP request

        Returns:
            webob.response: HTML LTI launch form
        """
        lti_consumer = self._get_lti1p3_consumer()
        context = lti_consumer.prepare_preflight_url(
            callback_url=get_lms_lti_launch_link(),
            hint=str(self.location),  # pylint: disable=no-member
            lti_hint=str(self.location)  # pylint: disable=no-member
        )

        loader = ResourceLoader(__name__)
        template = loader.render_mako_template('/templates/html/lti_1p3_oidc.html', context)
        return Response(template, content_type='text/html') 
开发者ID:edx,项目名称:xblock-lti-consumer,代码行数:25,代码来源:lti_xblock.py

示例2: __call__

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def __call__(self, request):
        try:
            method = request.method.lower()
            f = getattr(self, method, self.invalid)
            self.request = request
            self.response = webob.Response()
            params = request.environ['wsgiorg.routing_args'][1]
            del params['controller']
            f(**params)
        except Exception:
            # TODO(andrey-mp): improve this block
            LOG.exception('Unhandled error')
            self.render_xml({"Error": {
                "Code": "BadRequest",
                "Message": "Unhandled error"
            }})
            self.set_status(501)

        return self.response 
开发者ID:openstack,项目名称:ec2-api,代码行数:21,代码来源:s3server.py

示例3: __init__

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def __init__(self, message, *args):
        if isinstance(message, binary_type):
            message = message.decode('utf8')
        str_args = ()
        for arg in args:
            if isinstance(arg, webob.Response):
                body = arg.body
                if isinstance(body, binary_type):
                    if arg.charset:
                        arg = body.decode(arg.charset)
                    else:
                        arg = repr(body)
            elif isinstance(arg, binary_type):
                try:
                    arg = arg.decode('utf8')
                except UnicodeDecodeError:
                    arg = repr(arg)
            str_args += (arg,)
        message = message % str_args
        Exception.__init__(self, message) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:22,代码来源:app.py

示例4: wrapper

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def wrapper(self, environ, start_response):
        """Wrap the wsgi application to override some path:

        ``/__application__``: allow to ping the server.

        ``/__file__?__file__={path}``: serve the file found at ``path``
        """
        if '__file__' in environ['PATH_INFO']:
            req = webob.Request(environ)
            resp = webob.Response()
            resp.content_type = 'text/html; charset=UTF-8'
            filename = req.params.get('__file__')
            if os.path.isfile(filename):
                body = open(filename, 'rb').read()
                body = body.replace(six.b('http://localhost/'),
                                    six.b('http://%s/' % req.host))
                resp.body = body
            else:
                resp.status = '404 Not Found'
            return resp(environ, start_response)
        elif '__application__' in environ['PATH_INFO']:
            return webob.Response('server started')(environ, start_response)
        return self.test_app(environ, start_response) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:25,代码来源:http.py

示例5: upload_config

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def upload_config(self):
        try:
            stream = flask.request.stream
            file_path = cfg.find_config_files(project=CONF.project,
                                              prog=CONF.prog)[0]
            flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC
            # mode 00600
            mode = stat.S_IRUSR | stat.S_IWUSR
            with os.fdopen(os.open(file_path, flags, mode), 'wb') as cfg_file:
                b = stream.read(BUFFER)
                while b:
                    cfg_file.write(b)
                    b = stream.read(BUFFER)

            CONF.mutate_config_files()
        except Exception as e:
            LOG.error("Unable to update amphora-agent configuration: "
                      "{}".format(str(e)))
            return webob.Response(json=dict(
                message="Unable to update amphora-agent configuration.",
                details=str(e)), status=500)

        return webob.Response(json={'message': 'OK'}, status=202) 
开发者ID:openstack,项目名称:octavia,代码行数:25,代码来源:server.py

示例6: get_all_listeners_status

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def get_all_listeners_status(self, other_listeners=None):
        """Gets the status of all listeners

        This method will not consult the stats socket
        so a listener might show as ACTIVE but still be
        in ERROR

        Currently type==SSL is also not detected
        """
        listeners = list()

        for lb in util.get_loadbalancers():
            stats_socket, listeners_on_lb = util.parse_haproxy_file(lb)

            for listener_id, listener in listeners_on_lb.items():
                listeners.append({
                    'status': consts.ACTIVE,
                    'uuid': listener_id,
                    'type': listener['mode'],
                })

        if other_listeners:
            listeners = listeners + other_listeners
        return webob.Response(json=listeners, content_type='application/json') 
开发者ID:openstack,项目名称:octavia,代码行数:26,代码来源:loadbalancer.py

示例7: upload_certificate

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def upload_certificate(self, lb_id, filename):
        self._check_ssl_filename_format(filename)

        # create directory if not already there
        if not os.path.exists(self._cert_dir(lb_id)):
            os.makedirs(self._cert_dir(lb_id))

        stream = Wrapped(flask.request.stream)
        file = self._cert_file_path(lb_id, filename)
        flags = os.O_WRONLY | os.O_CREAT
        # mode 00600
        mode = stat.S_IRUSR | stat.S_IWUSR
        with os.fdopen(os.open(file, flags, mode), 'wb') as crt_file:
            b = stream.read(BUFFER)
            while b:
                crt_file.write(b)
                b = stream.read(BUFFER)

        resp = webob.Response(json=dict(message='OK'))
        resp.headers['ETag'] = stream.get_md5()
        return resp 
开发者ID:openstack,项目名称:octavia,代码行数:23,代码来源:loadbalancer.py

示例8: _interface_by_mac

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def _interface_by_mac(self, mac):
        try:
            with pyroute2.IPRoute() as ipr:
                idx = ipr.link_lookup(address=mac)[0]
                addr = ipr.get_links(idx)[0]
                for attr in addr['attrs']:
                    if attr[0] == 'IFLA_IFNAME':
                        return attr[1]
        except Exception as e:
            LOG.info('Unable to find interface with MAC: %s, rescanning '
                     'and returning 404. Reported error: %s', mac, str(e))

        # Poke the kernel to re-enumerate the PCI bus.
        # We have had cases where nova hot plugs the interface but
        # the kernel doesn't get the memo.
        filename = '/sys/bus/pci/rescan'
        flags = os.O_WRONLY
        if os.path.isfile(filename):
            with os.fdopen(os.open(filename, flags), 'w') as rescan_file:
                rescan_file.write('1')
        raise exceptions.HTTPException(
            response=webob.Response(json=dict(
                details="No suitable network interface found"), status=404)) 
开发者ID:openstack,项目名称:octavia,代码行数:25,代码来源:plug.py

示例9: test_webob_response_normalization

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def test_webob_response_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'

    raw_response = webob.Response()
    raw_response.content_type = 'application/json'

    response = normalize_response(raw_response, raw_request)

    assert response.path == '/get'
    assert response.content_type == 'application/json'
    assert response.url == httpbin.url + '/get?key=val'
    assert response.status_code == '200' 
开发者ID:pipermerriam,项目名称:flex,代码行数:19,代码来源:test_response_normalization.py

示例10: test_werkzeug_response_normalization

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def test_werkzeug_response_normalization(httpbin):
    from werkzeug.wrappers import Request, Response
    from werkzeug.test import create_environ

    raw_request = Request(create_environ(
        path='/get',
        base_url=httpbin.url,
        query_string='key=val',
        method='GET',
    ))

    raw_response = Response(
        response=b'{"key2": "val2"}',
        content_type='application/json',
    )

    response = normalize_response(raw_response, raw_request)

    assert response.path == '/get'
    assert response.content_type == 'application/json'
    assert response.url == httpbin.url + '/get?key=val'
    assert response.status_code == '200' 
开发者ID:pipermerriam,项目名称:flex,代码行数:24,代码来源:test_response_normalization.py

示例11: _normalize_django_response

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def _normalize_django_response(response, request=None):
    if not _django_available:
        raise TypeError("django is not installed")

    if not isinstance(response, (django.http.response.HttpResponse)):
        raise TypeError("Cannot normalize this request object")

    url = None

    if isinstance(response, django.http.response.HttpResponseRedirect):
        url = response.url
    elif request:
        url = request.url
    else:
        raise TypeError("Normalized django object needs a path")

    return Response(
        request=request,
        content=response.content,
        url=url,
        status_code=response.status_code,
        content_type=response.get('Content-Type'),
        response=response) 
开发者ID:pipermerriam,项目名称:flex,代码行数:25,代码来源:http.py

示例12: _normalize_requests_response

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def _normalize_requests_response(response, request=None):
    import requests
    if not isinstance(response, requests.Response):
        raise TypeError("Cannot normalize this response object")

    url = response.url
    status_code = response.status_code
    content_type = response.headers.get('Content-Type')

    return Response(
        request=request,
        content=response.content,
        url=url,
        status_code=status_code,
        content_type=content_type,
        response=response,
    ) 
开发者ID:pipermerriam,项目名称:flex,代码行数:19,代码来源:http.py

示例13: _normalize_urllib_response

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def _normalize_urllib_response(response, request=None):
    if six.PY2:
        if not isinstance(response, urllib.addinfourl):
            raise TypeError("Cannot normalize this response object")
    else:
        if not isinstance(response, http.client.HTTPResponse):
            raise TypeError("Cannot normalize this response object")

    url = response.url
    status_code = response.getcode()
    content_type = response.headers.get('Content-Type')

    return Response(
        request=request,
        content=response.read(),
        url=url,
        status_code=status_code,
        content_type=content_type,
        response=response,
    ) 
开发者ID:pipermerriam,项目名称:flex,代码行数:22,代码来源:http.py

示例14: _normalize_webob_response

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def _normalize_webob_response(response, request=None):
    if not _webob_available:
        raise TypeError("webob is not installed")

    if not isinstance(response, webob.Response):
        raise TypeError("Cannot normalize this response object")

    url = None

    if request:
        url = request.url
    elif response.request:
        url = response.request.url
    else:
        raise TypeError("Normalized webob object needs a path")

    return Response(
        request=request,
        content=response.body,
        url=url,
        status_code=response.status.split()[0],
        content_type=response.content_type,
        response=response,
    ) 
开发者ID:pipermerriam,项目名称:flex,代码行数:26,代码来源:http.py

示例15: _normalize_werkzeug_response

# 需要导入模块: import webob [as 别名]
# 或者: from webob import Response [as 别名]
def _normalize_werkzeug_response(response, request=None):
    if not _werkzeug_available:
        raise TypeError("werkzeug is not installed")

    if not isinstance(response, werkzeug.wrappers.BaseResponse):
        raise TypeError("Cannot normalize this response object")

    if request is None:
        raise TypeError("Cannot normalize this response object")

    return Response(
        url=request.url,
        request=request,
        content=response.data,
        status_code=response.status_code,
        content_type=response.headers.get('Content-Type'),
        response=response,
    ) 
开发者ID:pipermerriam,项目名称:flex,代码行数:20,代码来源:http.py


注:本文中的webob.Response方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。