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


Python lazyjson.ljdump函数代码示例

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


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

示例1: test_lazy_load_index

def test_lazy_load_index():
    f = StringIO()
    ljdump({"wakka": 42}, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert {"wakka": 10, "__total__": 0} == lj.offsets
    assert {"wakka": 2, "__total__": 14} == lj.sizes
开发者ID:ericmharris,项目名称:xonsh,代码行数:7,代码来源:test_lazyjson.py

示例2: dump

 def dump(self):
     """Write the cached history to external storage."""
     opts = builtins.__xonsh_env__.get('HISTCONTROL')
     last_inp = None
     cmds = []
     for cmd in self.buffer:
         if 'ignoredups' in opts and cmd['inp'] == last_inp:
             # Skipping dup cmd
             continue
         if 'ignoreerr' in opts and cmd['rtn'] != 0:
             # Skipping failed cmd
             continue
         cmds.append(cmd)
         last_inp = cmd['inp']
     with open(self.filename, 'r', newline='\n') as f:
         hist = xlj.LazyJSON(f).load()
     load_hist_len = len(hist['cmds'])
     hist['cmds'].extend(cmds)
     if self.at_exit:
         hist['ts'][1] = time.time()  # apply end time
         hist['locked'] = False
     if not builtins.__xonsh_env__.get('XONSH_STORE_STDOUT', False):
         [cmd.pop('out') for cmd in hist['cmds'][load_hist_len:]
             if 'out' in cmd]
     with open(self.filename, 'w', newline='\n') as f:
         xlj.ljdump(hist, f, sort_keys=True)
开发者ID:VHarisop,项目名称:xonsh,代码行数:26,代码来源:json.py

示例3: test_lazy_load_index

def test_lazy_load_index():
    f = StringIO()
    ljdump({'wakka': 42}, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal({'wakka': 10, '__total__': 0}, lj.offsets)
    assert_equal({'wakka': 2, '__total__': 14}, lj.sizes)
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:7,代码来源:test_lazyjson.py

示例4: dump

 def dump(self):
     """Write the cached history to external storage."""
     opts = builtins.__xonsh__.env.get("HISTCONTROL")
     last_inp = None
     cmds = []
     for cmd in self.buffer:
         if "ignoredups" in opts and cmd["inp"] == last_inp:
             # Skipping dup cmd
             continue
         if "ignoreerr" in opts and cmd["rtn"] != 0:
             # Skipping failed cmd
             continue
         cmds.append(cmd)
         last_inp = cmd["inp"]
     with open(self.filename, "r", newline="\n") as f:
         hist = xlj.LazyJSON(f).load()
     load_hist_len = len(hist["cmds"])
     hist["cmds"].extend(cmds)
     if self.at_exit:
         hist["ts"][1] = time.time()  # apply end time
         hist["locked"] = False
     if not builtins.__xonsh__.env.get("XONSH_STORE_STDOUT", False):
         [cmd.pop("out") for cmd in hist["cmds"][load_hist_len:] if "out" in cmd]
     with open(self.filename, "w", newline="\n") as f:
         xlj.ljdump(hist, f, sort_keys=True)
开发者ID:donnemartin,项目名称:gitsome,代码行数:25,代码来源:json.py

示例5: test_lazy_list_empty

def test_lazy_list_empty():
    x = []
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 0 == len(lj)
    assert x == lj.load()
开发者ID:ericmharris,项目名称:xonsh,代码行数:8,代码来源:test_lazyjson.py

示例6: test_lazy_list_empty

def test_lazy_list_empty():
    x = []
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(0, len(lj))
    assert_equal(x, lj.load())
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:8,代码来源:test_lazyjson.py

示例7: test_lazy_dict

def test_lazy_dict():
    f = StringIO()
    ljdump({"wakka": 42}, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert ["wakka"] == list(lj.keys())
    assert 42 == lj["wakka"]
    assert 1 == len(lj)
    assert {"wakka": 42} == lj.load()
开发者ID:ericmharris,项目名称:xonsh,代码行数:9,代码来源:test_lazyjson.py

示例8: test_lazy_dict

def test_lazy_dict():
    f = StringIO()
    ljdump({'wakka': 42}, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(['wakka'], list(lj.keys()))
    assert_equal(42, lj['wakka'])
    assert_equal(1, len(lj))
    assert_equal({'wakka': 42}, lj.load())
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:9,代码来源:test_lazyjson.py

示例9: test_lazy_list_list_ints

def test_lazy_list_list_ints():
    x = [[0, 1], [6, 28], [496, 8128]]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert isinstance(lj[1], LJNode)
    assert 28 == lj[1][1]
    assert [6 == 28], lj[1].load()
    assert x == lj.load()
开发者ID:ericmharris,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py

示例10: test_lazy_list_list_ints

def test_lazy_list_list_ints():
    x = [[0, 1], [6, 28], [496, 8128]]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_is_instance(lj[1], LJNode)
    assert_equal(28, lj[1][1])
    assert_equal([6, 28], lj[1].load())
    assert_equal(x, lj.load())
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py

示例11: test_lazy_list_ints

def test_lazy_list_ints():
    x = [0, 1, 6, 28, 496, 8128]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert 28 == lj[3]
    assert x[:2:-2] == lj[:2:-2]
    assert x == [_ for _ in lj]
    assert x == lj.load()
开发者ID:ericmharris,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py

示例12: dump

 def dump(self):
     """Write the cached history to external storage."""
     with open(self.filename, 'r', newline='\n') as f:
         hist = LazyJSON(f).load()
     hist['cmds'].extend(self.buffer)
     if self.at_exit:
         hist['ts'][1] = time.time()  # apply end time
         hist['locked'] = False
     with open(self.filename, 'w', newline='\n') as f:
         ljdump(hist, f, sort_keys=True)
开发者ID:astronouth7303,项目名称:xonsh,代码行数:10,代码来源:history.py

示例13: test_lazy_list_str

def test_lazy_list_str():
    x = ["I", "have", "seen", "the", "wind", "blow"]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert "the" == lj[3]
    assert x[:2:-2] == lj[:2:-2]
    assert x == [_ for _ in lj]
    assert x == lj.load()
开发者ID:ericmharris,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py

示例14: test_lazy_list_ints

def test_lazy_list_ints():
    x = [0, 1, 6, 28, 496, 8128]
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal(28, lj[3])
    assert_equal(x[:2:-2], lj[:2:-2])
    assert_equal(x, [_ for _ in lj])
    assert_equal(x, lj.load())
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py

示例15: test_lazy_list_str

def test_lazy_list_str():
    x = ['I', 'have', 'seen', 'the', 'wind', 'blow']
    f = StringIO()
    ljdump(x, f)
    f.seek(0)
    lj = LazyJSON(f)
    assert_equal('the', lj[3])
    assert_equal(x[:2:-2], lj[:2:-2])
    assert_equal(x, [_ for _ in lj])
    assert_equal(x, lj.load())
开发者ID:DangerOnTheRanger,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py


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