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


Python exc.HTTPNotAcceptable方法代码示例

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


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

示例1: __init__

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def __init__(self, headers, default_version, latest_version,
                 from_string=None):
        """Create an API Version object from the supplied headers.

        :param headers: webob headers
        :param default_version: version to use if not specified in headers
        :param latest_version: version to use if latest is requested
        :param from_string: create the version from string not headers
        :raises: webob.HTTPNotAcceptable
        """
        if from_string:
            (self.major, self.minor) = tuple(int(i)
                                             for i in from_string.split('.'))

        else:
            (self.major, self.minor) = Version.parse_headers(headers,
                                                             default_version,
                                                             latest_version) 
开发者ID:openstack,项目名称:zun,代码行数:20,代码来源:versions.py

示例2: test_controller_get_attr_version_not_found

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def test_controller_get_attr_version_not_found(self,
                                                   mock_pecan_request):

        class MyController(base.Controller):
            @base.Controller.api_version('1.0', '1.1')
            def testapi1(self):
                return 'API1_1.0_1.1'

            @base.Controller.api_version('1.3', '1.4')  # noqa
            def testapi1(self):
                return 'API1_1.3_1.4'

        controller = MyController()
        mock_pecan_request.version = versions.Version("", "",
                                                      "", "1.2")
        controller.request = mock_pecan_request

        method = controller.__getattribute__('testapi1')
        self.assertRaises(exc.HTTPNotAcceptable, method) 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:test_base.py

示例3: _check_version

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def _check_version(self, version, headers=None):
        if headers is None:
            headers = {}
        # ensure that major version in the URL matches the header
        if version.major != versions.BASE_VERSION:
            raise exc.HTTPNotAcceptable(
                "Mutually exclusive versions requested. Version %(ver)s "
                "requested but not supported by this service. The supported "
                "version range is: [%(min)s, %(max)s]." %
                {'ver': version, 'min': versions.min_version_string(),
                 'max': versions.max_version_string()},
                headers=headers)
        # ensure the minor version is within the supported range
        if version < min_version() or version > max_version():
            raise exc.HTTPNotAcceptable(
                "Version %(ver)s was requested but the minor version is not "
                "supported by this service. The supported version range is: "
                "[%(min)s, %(max)s]." %
                {'ver': version, 'min': versions.min_version_string(),
                 'max': versions.max_version_string()},
                headers=headers) 
开发者ID:openstack,项目名称:watcher,代码行数:23,代码来源:__init__.py

示例4: _no_version_match

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def _no_version_match(self, *args, **kwargs):
        from pecan import request

        raise exc.HTTPNotAcceptable(_(
            "Version %(ver)s was requested but the requested API is not "
            "supported for this version.") % {'ver': request.version}) 
开发者ID:openstack,项目名称:zun,代码行数:8,代码来源:base.py

示例5: __getattribute__

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def __getattribute__(self, key):

        def version_select():
            """Select the correct method based on version

            @return: Returns the correct versioned method
            @raises: HTTPNotAcceptable if there is no method which
                 matches the name and version constraints
            """

            from pecan import request
            ver = request.version

            func_list = self.versioned_methods[key]
            for func in func_list:
                if ver.matches(func.start_version, func.end_version):
                    return func.func

            return self._no_version_match

        try:
            version_meth_dict = object.__getattribute__(self, VER_METHOD_ATTR)
        except AttributeError:
            # No versioning on this class
            return object.__getattribute__(self, key)
        if version_meth_dict and key in version_meth_dict:
            return version_select().__get__(self, self.__class__)

        return object.__getattribute__(self, key)

    # NOTE: This decorator MUST appear first (the outermost
    # decorator) on an API method for it to work correctly 
开发者ID:openstack,项目名称:zun,代码行数:34,代码来源:base.py

示例6: parse_headers

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def parse_headers(headers, default_version, latest_version):
        """Determine the API version requested based on the headers supplied.

        :param headers: webob headers
        :param default_version: version to use if not specified in headers
        :param latest_version: version to use if latest is requested
        :returns: a tuple of (major, minor) version numbers
        :raises: webob.HTTPNotAcceptable
        """

        version_hdr = headers.get(Version.string, default_version)

        try:
            version_service, version_str = version_hdr.split()
        except ValueError:
            raise exc.HTTPNotAcceptable(_(
                "Invalid service type for %s header") % Version.string)

        if version_str.lower() == 'latest':
            version_service, version_str = latest_version.split()

        if version_service != Version.service_string:
            raise exc.HTTPNotAcceptable(_(
                "Invalid service type for %s header") % Version.string)
        try:
            version = tuple(int(i) for i in version_str.split('.'))
        except ValueError:
            version = ()

        if len(version) != 2:
            raise exc.HTTPNotAcceptable(_(
                "Invalid value for %s header") % Version.string)
        return version 
开发者ID:openstack,项目名称:zun,代码行数:35,代码来源:versions.py

示例7: test_parse_headers_bad_length

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def test_parse_headers_bad_length(self):
        self.assertRaises(
            exc.HTTPNotAcceptable,
            versions.Version.parse_headers,
            {versions.Version.string: 'container 1'},
            mock.ANY,
            mock.ANY)
        self.assertRaises(
            exc.HTTPNotAcceptable,
            versions.Version.parse_headers,
            {versions.Version.string: 'container 1.2.3'},
            mock.ANY,
            mock.ANY) 
开发者ID:openstack,项目名称:zun,代码行数:15,代码来源:test_base.py

示例8: __getattribute__

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def __getattribute__(self, key):

        def version_select():
            """Select the correct method based on version

            @return: Returns the correct versioned method
            @raises: HTTPNotAcceptable if there is no method which
                 matches the name and version constraints
            """

            from pecan import request
            ver = request.version

            func_list = self.versioned_methods[key]
            for func in func_list:
                if ver.matches(func.start_version, func.end_version):
                    return func.func

            raise exc.HTTPNotAcceptable(_(
                "Version %(ver)s was requested but the requested API %(api)s "
                "is not supported for this version.") % {'ver': ver,
                                                         'api': key})

        try:
            version_meth_dict = object.__getattribute__(self, VER_METHOD_ATTR)
        except AttributeError:
            # No versioning on this class
            return object.__getattribute__(self, key)
        if version_meth_dict and key in version_meth_dict:
            return version_select().__get__(self, self.__class__)

        return object.__getattribute__(self, key)

    # NOTE: This decorator MUST appear first (the outermost
    # decorator) on an API method for it to work correctly 
开发者ID:openstack,项目名称:magnum,代码行数:37,代码来源:base.py

示例9: test_parse_headers_bad_length

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def test_parse_headers_bad_length(self):
        self.assertRaises(
            exc.HTTPNotAcceptable,
            versions.Version.parse_headers,
            {versions.Version.string: 'container-infra 1'},
            mock.ANY,
            mock.ANY)
        self.assertRaises(
            exc.HTTPNotAcceptable,
            versions.Version.parse_headers,
            {versions.Version.string: 'container-infra 1.2.3'},
            mock.ANY,
            mock.ANY) 
开发者ID:openstack,项目名称:magnum,代码行数:15,代码来源:test_base.py

示例10: test_parse_incorrect_service_type

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def test_parse_incorrect_service_type(self):
        self.assertRaises(
            exc.HTTPNotAcceptable,
            versions.Version.parse_headers,
            {versions.Version.string: '1.1'},
            'container-infra 1.1',
            'container-infra 1.1')
        self.assertRaises(
            exc.HTTPNotAcceptable,
            versions.Version.parse_headers,
            {versions.Version.string: 'nova 1.1'},
            'container-infra 1.1',
            'container-infra 1.1') 
开发者ID:openstack,项目名称:magnum,代码行数:15,代码来源:test_base.py

示例11: test_check_version_invalid_major_version

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def test_check_version_invalid_major_version(self):
        self.version.major = v1_api.BASE_VERSION + 1
        self.version.minor = v1_api.MIN_VER.minor
        self.assertRaises(webob_exc.HTTPNotAcceptable,
                          v1_api.Controller()._check_version,
                          self.version) 
开发者ID:openstack,项目名称:magnum,代码行数:8,代码来源:test_root.py

示例12: test_check_version_too_low

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def test_check_version_too_low(self):
        self.version.major = v1_api.BASE_VERSION
        self.version.minor = v1_api.MIN_VER.minor - 1
        self.assertRaises(webob_exc.HTTPNotAcceptable,
                          v1_api.Controller()._check_version,
                          self.version) 
开发者ID:openstack,项目名称:magnum,代码行数:8,代码来源:test_root.py

示例13: test_check_version_too_high

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def test_check_version_too_high(self):
        self.version.major = v1_api.BASE_VERSION
        self.version.minor = v1_api.MAX_VER.minor + 1
        e = self.assertRaises(webob_exc.HTTPNotAcceptable,
                              v1_api.Controller()._check_version,
                              self.version, {'fake-headers':
                                             v1_api.MAX_VER.minor})

        self.assertEqual(v1_api.MAX_VER.minor, e.headers['fake-headers']) 
开发者ID:openstack,项目名称:magnum,代码行数:11,代码来源:test_root.py

示例14: test_get_vnf_package_vnfd_with_invalid_accept_header

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def test_get_vnf_package_vnfd_with_invalid_accept_header(
            self, mock_vnf_by_id):
        mock_vnf_by_id.return_value = fakes.return_vnfpkg_obj()
        req = fake_request.HTTPRequest.blank(
            '/vnf_packages/%s/vnfd'
            % constants.UUID)
        req.headers['Accept'] = 'test-invalid-header'
        req.method = 'GET'
        self.assertRaises(exc.HTTPNotAcceptable,
                          self.controller.get_vnf_package_vnfd,
                          req, constants.UUID) 
开发者ID:openstack,项目名称:tacker,代码行数:13,代码来源:test_controller.py

示例15: __init__

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPNotAcceptable [as 别名]
def __init__(self, headers, default_version, latest_version):
        """Create an API Version object from the supplied headers.

        :param headers: webob headers
        :param default_version: version to use if not specified in headers
        :param latest_version: version to use if latest is requested
        :raises: webob.HTTPNotAcceptable

        """
        (self.major, self.minor) = Version.parse_headers(
            headers, default_version, latest_version) 
开发者ID:openstack,项目名称:watcher,代码行数:13,代码来源:base.py


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