本文整理汇总了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
示例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)
示例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)
示例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)
示例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()
示例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())
示例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()
示例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())
示例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()
示例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())
示例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()
示例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)
示例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()
示例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())
示例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())