Ejemplo n.º 1
0
 def _stream(self):
     """
     Returns a generator of lines instead of a list of lines.
     """
     if self._exception:
         raise self._exception
     try:
         if self._content:
             yield self._content
             raise StopIteration
         filters = get_filters(self.ds) if self.ds else None
         if filters:
             cmd = ["grep", "-F", "\n".join(filters), self.path]
             with streams.stream(cmd, env=SAFE_ENV) as s:
                 yield s
         else:
             with open(self.path, "rU") as f:  # universal newlines
                 yield f
     except StopIteration:
         raise
     except Exception as ex:
         self._exception = ex
         raise ContentException(str(ex))
Ejemplo n.º 2
0
 def stream(self, *args, **kwargs):
     with streams.stream(*args, **kwargs) as s:
         yield s