本文整理汇总了Python中xonsh.lazyjson.LazyJSON类的典型用法代码示例。如果您正苦于以下问题:Python LazyJSON类的具体用法?Python LazyJSON怎么用?Python LazyJSON使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LazyJSON类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: files
def files(self, only_unlocked=False):
"""Find and return the history files. Optionally locked files may be
excluded.
This is sorted by the last closed time. Returns a list of
(timestamp, number of cmds, file name) tuples.
"""
# pylint: disable=no-member
env = getattr(builtins, '__xonsh_env__', None)
if env is None:
return []
fs = _get_history_files(sort=False)
files = []
for f in fs:
try:
if os.path.getsize(f) == 0:
# collect empty files (for gc)
files.append((time.time(), 0, f))
continue
lj = LazyJSON(f, reopen=False)
if only_unlocked and lj['locked']:
continue
# info: closing timestamp, number of commands, filename
files.append((lj['ts'][1] or time.time(),
len(lj.sizes['cmds']) - 1,
f))
lj.close()
except (IOError, OSError, ValueError):
continue
files.sort()
return files
开发者ID:nicfit,项目名称:xonsh,代码行数:32,代码来源:history.py
示例2: files
def files(self, only_unlocked=False):
"""Find and return the history files. Optionally locked files may be
excluded.
This is sorted by the last closed time. Returns a list of (timestamp,
file) tuples.
"""
# pylint: disable=no-member
xdd = builtins.__xonsh_env__.get('XONSH_DATA_DIR')
xdd = expanduser_abs_path(xdd)
fs = [f for f in glob.iglob(os.path.join(xdd, 'xonsh-*.json'))]
files = []
for f in fs:
try:
lj = LazyJSON(f, reopen=False)
if only_unlocked and lj['locked']:
continue
# info: closing timestamp, number of commands, filename
files.append((lj['ts'][1] or time.time(),
len(lj.sizes['cmds']) - 1,
f))
lj.close()
except (IOError, OSError, ValueError):
continue
files.sort()
return files
开发者ID:astronouth7303,项目名称:xonsh,代码行数:27,代码来源:history.py
示例3: run
def run(self):
try:
import readline
except ImportError:
return
hist = builtins.__xonsh_history__
while self.wait_for_gc and hist.gc.is_alive():
time.sleep(0.011) # gc sleeps for 0.01 secs, sleep a beat longer
files = hist.gc.files()
i = 1
for _, _, f in files:
try:
lj = LazyJSON(f, reopen=False)
for command in lj['cmds']:
inp = command['inp'].splitlines()
for line in inp:
if line == 'EOF':
continue
readline.add_history(line)
if RL_LIB is not None:
RL_LIB.history_set_pos(i)
i += 1
lj.close()
except (IOError, OSError, ValueError):
continue
开发者ID:PaulReiber,项目名称:xonsh,代码行数:25,代码来源:readline_shell.py
示例4: Replayer
class Replayer(object):
"""Replays a xonsh history file."""
def __init__(self, f, reopen=True):
"""
Parameters
----------
f : file handle or str
Path to xonsh history file.
reopen : bool, optional
Whether new file handle should be opened for each load, passed directly into
LazyJSON class.
"""
self._lj = LazyJSON(f, reopen=reopen)
def __del__(self):
self._lj.close()
def replay(self, merge_envs=DEFAULT_MERGE_ENVS, target=None):
"""Replays the history specified, returns the history object where the code
was executed.
Parameters
----------
merge_env : tuple of str or Mappings, optional
Describes how to merge the environments, in order of increasing precednce.
Available strings are 'replay' and 'native'. The 'replay' env comes from the
history file that we are replaying. The 'native' env comes from what this
instance of xonsh was started up with. Instead of a string, a dict or other
mapping may be passed in as well. Defaults to ('replay', 'native').
target : str, optional
Path to new history file.
"""
shell = builtins.__xonsh_shell__
re_env = self._lj['env'].load()
new_env = self._merge_envs(merge_envs, re_env)
new_hist = History(env=new_env.detype(), locked=True, ts=[time.time(), None],
gc=False, filename=target)
with swap(builtins, '__xonsh_env__', new_env), swap(builtins, '__xonsh_history__', new_hist):
for cmd in self._lj['cmds']:
inp = cmd['inp']
shell.default(inp)
if builtins.__xonsh_exit__: # prevent premature exit
builtins.__xonsh_exit__ = False
new_hist.flush(at_exit=True)
return new_hist
def _merge_envs(self, merge_envs, re_env):
new_env = {}
for e in merge_envs:
if e == 'replay':
new_env.update(re_env)
elif e == 'native':
new_env.update(builtins.__xonsh_env__)
elif isinstance(e, cabc.Mapping):
new_env.update(e)
else:
raise TypeError('Type of env not understood: {0!r}'.format(e))
new_env = Env(**new_env)
return new_env
开发者ID:astronouth7303,项目名称:xonsh,代码行数:60,代码来源:replay.py
示例5: 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
示例6: 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
示例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()
dump({'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:Cynary,项目名称: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_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
示例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: 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:AndreaCrotti,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py
示例13: test_lazy_list_ints
def test_lazy_list_ints():
x = [0, 1, 6, 28, 496, 8128]
f = StringIO()
dump(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:Cynary,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py
示例14: test_lazy_list_list_ints
def test_lazy_list_list_ints():
x = [[0, 1], [6, 28], [496, 8128]]
f = StringIO()
dump(x, f)
f.seek(0)
lj = LazyJSON(f)
assert_is_instance(lj[1], Node)
assert_equal(28, lj[1][1])
assert_equal([6, 28], lj[1].load())
assert_equal(x, lj.load())
开发者ID:Cynary,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py
示例15: test_lazy_list_str
def test_lazy_list_str():
x = ['I', 'have', 'seen', 'the', 'wind', 'blow']
f = StringIO()
dump(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:Cynary,项目名称:xonsh,代码行数:10,代码来源:test_lazyjson.py
示例16: test_lazy_dict_dict_int
def test_lazy_dict_dict_int():
x = {'wakka': {'jawaka': 42}}
f = StringIO()
dump(x, f)
f.seek(0)
lj = LazyJSON(f)
assert_equal(['wakka'], list(lj.keys()))
assert_is_instance(lj['wakka'], Node)
assert_equal(42, lj['wakka']['jawaka'])
assert_equal(1, len(lj))
assert_equal(x, lj.load())
开发者ID:Cynary,项目名称:xonsh,代码行数:11,代码来源:test_lazyjson.py
示例17: test_lazy_dict_dict_int
def test_lazy_dict_dict_int():
x = {'wakka': {'jawaka': 42}}
f = StringIO()
ljdump(x, f)
f.seek(0)
lj = LazyJSON(f)
assert ['wakka'] == list(lj.keys())
assert isinstance(lj['wakka'], LJNode)
assert 42 == lj['wakka']['jawaka']
assert 1 == len(lj)
assert x == lj.load()
开发者ID:AndreaCrotti,项目名称:xonsh,代码行数:11,代码来源:test_lazyjson.py
示例18: test_lazy_dict_dict_int
def test_lazy_dict_dict_int():
x = {"wakka": {"jawaka": 42}}
f = StringIO()
ljdump(x, f)
f.seek(0)
lj = LazyJSON(f)
assert ["wakka"] == list(lj.keys())
assert isinstance(lj["wakka"], LJNode)
assert 42 == lj["wakka"]["jawaka"]
assert 1 == len(lj)
assert x == lj.load()
开发者ID:ericmharris,项目名称:xonsh,代码行数:11,代码来源:test_lazyjson.py
示例19: _all_xonsh_parser
def _all_xonsh_parser(**kwargs):
"""
Returns all history as found in XONSH_DATA_DIR.
return format: (cmd, start_time, index)
"""
ind = 0
for f in _get_history_files():
try:
json_file = LazyJSON(f, reopen=False)
except ValueError:
# Invalid json file
continue
commands = json_file.load()['cmds']
for c in commands:
yield (c['inp'].rstrip(), c['ts'][0], ind)
ind += 1
开发者ID:nicfit,项目名称:xonsh,代码行数:17,代码来源:history.py
示例20: __init__
def __init__(self, afile, bfile, reopen=False, verbose=False):
"""
Parameters
----------
afile : file handle or str
The first file to diff
bfile : file handle or str
The second file to diff
reopen : bool, optional
Whether or not to reopen the file handles each time. The default here is
opposite from the LazyJSON default because we know that we will be doing
a lot of reading so it is best to keep the handles open.
verbose : bool, optional
Whether to print a verbose amount of information.
"""
self.a = LazyJSON(afile, reopen=reopen)
self.b = LazyJSON(bfile, reopen=reopen)
self.verbose = verbose
self.sm = difflib.SequenceMatcher(autojunk=False)
开发者ID:BlaXpirit,项目名称:xonsh,代码行数:19,代码来源:diff_history.py
注:本文中的xonsh.lazyjson.LazyJSON类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论