• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python json.fromjson函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wsme.rest.json.fromjson函数的典型用法代码示例。如果您正苦于以下问题:Python fromjson函数的具体用法?Python fromjson怎么用?Python fromjson使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_vip

 def test_vip(self):
     body = {"vip": {"ip_address": "10.0.0.1",
                     "net_port_id": uuidutils.generate_uuid(),
                     "subnet_id": uuidutils.generate_uuid(),
                     "floating_ip_id": uuidutils.generate_uuid(),
                     "floating_ip_network_id": uuidutils.generate_uuid()}}
     wsme_json.fromjson(self._type, body)
开发者ID:TrevorV,项目名称:octavia,代码行数:7,代码来源:test_load_balancers.py


示例2: valid_composite_rule

    def valid_composite_rule(rules):
        if isinstance(rules, dict) and len(rules) == 1:
            and_or_key = list(rules)[0]
            if and_or_key not in ('and', 'or'):
                raise base.ClientSideError(
                    _('Threshold rules should be combined with "and" or "or"'))
            if isinstance(rules[and_or_key], list):
                for sub_rule in rules[and_or_key]:
                    CompositeRule.valid_composite_rule(sub_rule)
            else:
                raise InvalidCompositeRule(rules)
        elif isinstance(rules, dict):
            rule_type = rules.pop('type', None)
            if not rule_type:
                raise base.ClientSideError(_('type must be set in every rule'))

            if rule_type not in CompositeRule.threshold_plugins:
                plugins = sorted(CompositeRule.threshold_plugins.names())
                err = _('Unsupported sub-rule type :%(rule)s in composite '
                        'rule, should be one of: %(plugins)s') % {
                            'rule': rule_type,
                            'plugins': plugins}
                raise base.ClientSideError(err)
            plugin = CompositeRule.threshold_plugins[rule_type].plugin
            wjson.fromjson(plugin, rules)
            rule_dict = plugin(**rules).as_dict()
            rules.update(rule_dict)
            rules.update(type=rule_type)
        else:
            raise InvalidCompositeRule(rules)
开发者ID:ISCAS-VDI,项目名称:aodh-base,代码行数:30,代码来源:composite.py


示例3: test_jsonObject

def test_jsonObject():
    # dictionaries work fine
    obj = AType()
    obj.data = {"a": 1}
    eq_(obj.data, {"a": 1})
    # other types don't
    assert_raises(wsme.exc.InvalidInput, lambda: setattr(obj, "data", ["a"]))
    # and un-JSONable Python data doesn't
    assert_raises(wsme.exc.InvalidInput, lambda: setattr(obj, "data", {"a": lambda: 1}))

    # valid JSON objects work fine
    obj = fromjson(AType, {"data": {"b": 2}})
    # other types don't
    assert_raises(wsme.exc.InvalidInput, lambda: fromjson(AType, {"data": ["b", 2]}))
开发者ID:acmiyaguchi,项目名称:build-relengapi,代码行数:14,代码来源:test_lib_api.py


示例4: test_l7policy

 def test_l7policy(self):
     body = {"action": constants.L7POLICY_ACTION_REJECT}
     l7policy = wsme_json.fromjson(self._type, body)
     self.assertEqual(sys.maxsize, l7policy.position)
     self.assertEqual(wsme_types.Unset, l7policy.redirect_url)
     self.assertEqual(wsme_types.Unset, l7policy.redirect_pool_id)
     self.assertTrue(l7policy.enabled)
开发者ID:evgenyfedoruk,项目名称:octavia,代码行数:7,代码来源:test_l7policies.py


示例5: test_l7rule

 def test_l7rule(self):
     body = {"type": constants.L7RULE_TYPE_PATH,
             "compare_type": constants.L7RULE_COMPARE_TYPE_STARTS_WITH,
             "value": "/api", "tags": ['test_tag']}
     l7rule = wsme_json.fromjson(self._type, body)
     self.assertEqual(wsme_types.Unset, l7rule.key)
     self.assertFalse(l7rule.invert)
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_l7rules.py


示例6: test_max_weight

 def test_max_weight(self):
     body = {"weight": constants.MAX_WEIGHT + 1}
     self.assertRaises(
         exc.InvalidInput, wsme_json.fromjson, self._type, body)
     body = {"weight": constants.MAX_WEIGHT}
     member = wsme_json.fromjson(self._type, body)
     self.assertEqual(constants.MAX_WEIGHT, member.weight)
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_members.py


示例7: test_non_uuid_project_id

 def test_non_uuid_project_id(self):
     body = {"loadbalancer_id": uuidutils.generate_uuid(),
             "protocol": constants.PROTOCOL_HTTP,
             "lb_algorithm": constants.LB_ALGORITHM_ROUND_ROBIN,
             "project_id": "non-uuid"}
     pool = wsme_json.fromjson(self._type, body)
     self.assertEqual(pool.project_id, body['project_id'])
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_pools.py


示例8: test_member

 def test_member(self):
     body = {"name": "member1", "address": "10.0.0.1",
             "protocol_port": 80, "tags": ['test_tag']}
     member = wsme_json.fromjson(self._type, body)
     self.assertTrue(member.admin_state_up)
     self.assertEqual(1, member.weight)
     self.assertEqual(wsme_types.Unset, member.subnet_id)
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_members.py


示例9: test_l7policy_max_position

 def test_l7policy_max_position(self):
     body = {"position": constants.MAX_POLICY_POSITION + 1}
     self.assertRaises(
         exc.InvalidInput, wsme_json.fromjson, self._type, body)
     body = {"position": constants.MAX_POLICY_POSITION}
     l7policy = wsme_json.fromjson(self._type, body)
     self.assertEqual(constants.MAX_POLICY_POSITION, l7policy.position)
开发者ID:openstack,项目名称:octavia,代码行数:7,代码来源:test_l7policies.py


示例10: test_date_formatting

def test_date_formatting():
    """ISO 8601 formatted dates with timezones are correctly translated to
    datetime instances and back"""
    d = TypeWithDate()
    d.when = datetime(2015, 2, 28, 1, 2, 3, tzinfo=UTC)
    j = {'when': '2015-02-28T01:02:03+00:00'}
    eq_(tojson(TypeWithDate, d), j)
    eq_(fromjson(TypeWithDate, j).when, d.when)
开发者ID:lundjordan,项目名称:build-relengapi,代码行数:8,代码来源:test_lib_api.py


示例11: test_with_redirect_url

 def test_with_redirect_url(self):
     url = "http://www.example.com/"
     body = {"action": constants.L7POLICY_ACTION_REDIRECT_TO_URL,
             "redirect_url": url}
     l7policy = wsme_json.fromjson(self._type, body)
     self.assertEqual(sys.maxsize, l7policy.position)
     self.assertEqual(url, l7policy.redirect_url)
     self.assertEqual(wsme_types.Unset, l7policy.redirect_pool_id)
开发者ID:evgenyfedoruk,项目名称:octavia,代码行数:8,代码来源:test_l7policies.py


示例12: test_jsonObject

def test_jsonObject():
    # dictionaries work fine
    obj = AType()
    obj.data = {'a': 1}
    eq_(obj.data, {'a': 1})
    # other types don't
    assert_raises(wsme.exc.InvalidInput, lambda:
                  setattr(obj, 'data', ['a']))
    # and un-JSONable Python data doesn't
    assert_raises(wsme.exc.InvalidInput, lambda:
                  setattr(obj, 'data', {'a': lambda: 1}))

    # valid JSON objects work fine
    obj = fromjson(AType, {'data': {'b': 2}})
    # other types don't
    assert_raises(wsme.exc.InvalidInput, lambda:
                  fromjson(AType, {'data': ['b', 2]}))
开发者ID:lundjordan,项目名称:build-relengapi,代码行数:17,代码来源:test_lib_api.py


示例13: test_listener

 def test_listener(self):
     body = {"name": "test", "description": "test", "connection_limit": 10,
             "protocol": constants.PROTOCOL_HTTP, "protocol_port": 80,
             "default_pool_id": uuidutils.generate_uuid(),
             "loadbalancer_id": uuidutils.generate_uuid(),
             "tags": ['test_tag']}
     listener = wsme_json.fromjson(self._type, body)
     self.assertTrue(listener.admin_state_up)
开发者ID:openstack,项目名称:octavia,代码行数:8,代码来源:test_listeners.py


示例14: test_non_uuid_project_id

 def test_non_uuid_project_id(self):
     body = {"name": "test", "description": "test", "connection_limit": 10,
             "protocol": constants.PROTOCOL_HTTP, "protocol_port": 80,
             "default_pool_id": uuidutils.generate_uuid(),
             "loadbalancer_id": uuidutils.generate_uuid(),
             "project_id": "non-uuid"}
     listener = wsme_json.fromjson(self._type, body)
     self.assertEqual(listener.project_id, body['project_id'])
开发者ID:openstack,项目名称:octavia,代码行数:8,代码来源:test_listeners.py


示例15: test_pool

 def test_pool(self):
     body = {
         "loadbalancer_id": uuidutils.generate_uuid(),
         "listener_id": uuidutils.generate_uuid(),
         "protocol": constants.PROTOCOL_HTTP,
         "lb_algorithm": constants.LB_ALGORITHM_ROUND_ROBIN,
         "tags": ['test_tag']}
     pool = wsme_json.fromjson(self._type, body)
     self.assertTrue(pool.admin_state_up)
开发者ID:openstack,项目名称:octavia,代码行数:9,代码来源:test_pools.py


示例16: to_model_properties

    def to_model_properties(db_property_types):
        property_types = {}
        for db_property_type in db_property_types:
            # Convert the persisted json schema to a dict of PropertyTypes
            property_type = json.fromjson(PropertyType, db_property_type.schema)
            property_type_name = db_property_type.name
            property_types[property_type_name] = property_type

        return property_types
开发者ID:dlq84,项目名称:glance,代码行数:9,代码来源:metadef_namespace.py


示例17: update

 def update(self, request):
     body = self._get_request_body(request)
     self._check_allowed(body)
     try:
         self.schema.validate(body)
     except exception.InvalidObject as e:
         raise webob.exc.HTTPBadRequest(explanation=e.msg)
     property_type = json.fromjson(PropertyType, body)
     return dict(property_type=property_type)
开发者ID:Dynavisor,项目名称:glance,代码行数:9,代码来源:metadef_properties.py


示例18: update

 def update(self, request):
     body = self._get_request_body(request)
     self._check_allowed(body)
     try:
         self.schema.validate(body)
     except exception.InvalidObject as e:
         raise webob.exc.HTTPBadRequest(explanation=e.msg)
     namespace = json.fromjson(Namespace, body)
     return dict(user_ns=namespace)
开发者ID:froyobin,项目名称:xmonitor,代码行数:9,代码来源:metadef_namespaces.py


示例19: test_member_full

 def test_member_full(self):
     name = "new_name"
     weight = 1
     admin_state = True
     body = {"name": name, "weight": weight, "admin_state_up": admin_state}
     member = wsme_json.fromjson(self._type, body)
     self.assertEqual(name, member.name)
     self.assertEqual(weight, member.weight)
     self.assertEqual(admin_state, member.admin_state_up)
开发者ID:openstack,项目名称:octavia,代码行数:9,代码来源:test_members.py


示例20: update

 def update(self, request):
     body = self._get_request_body(request)
     self._check_allowed(body)
     try:
         self.schema.validate(body)
     except exception.InvalidObject as e:
         raise webob.exc.HTTPBadRequest(explanation=e.msg)
     metadata_object = json.fromjson(MetadefObject, body)
     return dict(metadata_object=metadata_object)
开发者ID:qianqunyi,项目名称:glance,代码行数:9,代码来源:metadef_objects.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python json.tojson函数代码示例发布时间:2022-05-26
下一篇:
Python wskutil.responseError函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap