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


Python simplejson.OrderedDict方法代码示例

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


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

示例1: main

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import OrderedDict [as 别名]
def main():
    if len(sys.argv) == 1:
        infile = sys.stdin
        outfile = sys.stdout
    elif len(sys.argv) == 2:
        infile = open(sys.argv[1], 'r')
        outfile = sys.stdout
    elif len(sys.argv) == 3:
        infile = open(sys.argv[1], 'r')
        outfile = open(sys.argv[2], 'w')
    else:
        raise SystemExit(sys.argv[0] + " [infile [outfile]]")
    with infile:
        try:
            obj = json.load(infile,
                            object_pairs_hook=json.OrderedDict,
                            use_decimal=True)
        except ValueError:
            raise SystemExit(sys.exc_info()[1])
    with outfile:
        json.dump(obj, outfile, sort_keys=True, indent='    ', use_decimal=True)
        outfile.write('\n') 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:24,代码来源:tool.py

示例2: test_object_pairs_hook

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import OrderedDict [as 别名]
def test_object_pairs_hook(self):
        s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
        p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
             ("qrt", 5), ("pad", 6), ("hoy", 7)]
        self.assertEqual(json.loads(s), eval(s))
        self.assertEqual(json.loads(s, object_pairs_hook=lambda x: x), p)
        self.assertEqual(json.load(StringIO(s),
                                   object_pairs_hook=lambda x: x), p)
        od = json.loads(s, object_pairs_hook=OrderedDict)
        self.assertEqual(od, OrderedDict(p))
        self.assertEqual(type(od), OrderedDict)
        # the object_pairs_hook takes priority over the object_hook
        self.assertEqual(json.loads(s,
                                    object_pairs_hook=OrderedDict,
                                    object_hook=lambda x: None),
                         OrderedDict(p)) 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:18,代码来源:test_decode.py

示例3: main

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import OrderedDict [as 别名]
def main():
    if len(sys.argv) == 1:
        infile = sys.stdin
        outfile = sys.stdout
    elif len(sys.argv) == 2:
        infile = open(sys.argv[1], 'rb')
        outfile = sys.stdout
    elif len(sys.argv) == 3:
        infile = open(sys.argv[1], 'rb')
        outfile = open(sys.argv[2], 'wb')
    else:
        raise SystemExit(sys.argv[0] + " [infile [outfile]]")
    try:
        obj = json.load(infile,
                        object_pairs_hook=json.OrderedDict,
                        use_decimal=True)
    except ValueError, e:
        raise SystemExit(e) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:20,代码来源:tool.py

示例4: render_notification_block

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import OrderedDict [as 别名]
def render_notification_block(config, env_key, skip_envs=None):
    j2 = get_datadog_jinja_environment()
    template = j2.get_template('notification_block.j2')
    envs = config.env_notifications
    if skip_envs:
        # copy but maintain ordering
        envs = OrderedDict(sorted(config.env_notifications.items()))
        for env in skip_envs:
            envs.pop(env, None)
    return template.render(
        env_key=env_key,
        catchall_alert_channel=config.catchall_alert_channel,
        envs=envs,
        start_block=BLOCK.format(env_key=env_key, start_or_end='START'),
        end_block=BLOCK.format(env_key=env_key, start_or_end='END'),
    ) 
开发者ID:dimagi,项目名称:commcare-cloud,代码行数:18,代码来源:datadog_monitors.py

示例5: main

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import OrderedDict [as 别名]
def main():
    if len(sys.argv) == 1:
        infile = sys.stdin
        outfile = sys.stdout
    elif len(sys.argv) == 2:
        infile = open(sys.argv[1], 'rb')
        outfile = sys.stdout
    elif len(sys.argv) == 3:
        infile = open(sys.argv[1], 'rb')
        outfile = open(sys.argv[2], 'wb')
    else:
        raise SystemExit(sys.argv[0] + " [infile [outfile]]")
    try:
        try:
            obj = json.load(infile,
                            object_pairs_hook=json.OrderedDict,
                            use_decimal=True)
        except ValueError, e:
            raise SystemExit(e)
        json.dump(obj, outfile, sort_keys=True, indent='    ', use_decimal=True)
        outfile.write('\n') 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:23,代码来源:tool.py

示例6: test_object_pairs_hook_with_unicode

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import OrderedDict [as 别名]
def test_object_pairs_hook_with_unicode(self):
        s = u'{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
        p = [(u"xkd", 1), (u"kcw", 2), (u"art", 3), (u"hxm", 4),
             (u"qrt", 5), (u"pad", 6), (u"hoy", 7)]
        self.assertEqual(json.loads(s), eval(s))
        self.assertEqual(json.loads(s, object_pairs_hook=lambda x: x), p)
        od = json.loads(s, object_pairs_hook=json.OrderedDict)
        self.assertEqual(od, json.OrderedDict(p))
        self.assertEqual(type(od), json.OrderedDict)
        # the object_pairs_hook takes priority over the object_hook
        self.assertEqual(json.loads(s,
                                    object_pairs_hook=json.OrderedDict,
                                    object_hook=lambda x: None),
                         json.OrderedDict(p)) 
开发者ID:gkudos,项目名称:qgis-cartodb,代码行数:16,代码来源:test_unicode.py

示例7: get_config

# 需要导入模块: import simplejson [as 别名]
# 或者: from simplejson import OrderedDict [as 别名]
def get_config(config_path):
    with open(config_path, 'r') as config_file:
        config = Config(yaml.safe_load(config_file))
        config.env_notifications = OrderedDict(sorted(config.env_notifications.items()))
    return config 
开发者ID:dimagi,项目名称:commcare-cloud,代码行数:7,代码来源:datadog_monitors.py


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