Added inspect() command

This commit is contained in:
2020-06-23 16:45:44 +02:00
parent 7310bc5522
commit d4468da8a3
2 changed files with 29 additions and 3 deletions
+13 -3
View File
@@ -296,8 +296,8 @@ class SheerkaFilter(BaseService):
# s.send(data)
@staticmethod
def pipe_traverse(args):
for arg in args:
def pipe_traverse(iterable):
for arg in iterable:
try:
if isinstance(arg, str):
yield arg
@@ -342,7 +342,7 @@ class SheerkaFilter(BaseService):
yield item
@staticmethod
def pipe_write(iterable, fname, glue="\n"):
def pipe_to_file(iterable, fname, glue="\n"):
with open(fname, "w") as f:
for item in iterable:
f.write(str(item) + glue)
@@ -432,3 +432,13 @@ class SheerkaFilter(BaseService):
yield item
except NameError:
pass
def pipe_inspect(self, iterable, path, when=None):
compiled = self.get_compiled("inspect", path)
for item in iterable:
try:
context = {} if is_primitive(item) else as_bag(item)
context["self"] = item
yield eval(compiled, context)
except Exception as ex:
yield ex