Exemple #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
         else:
             args = self.create_args()
             if args:
                 with streams.connect(*args, env=SAFE_ENV) as s:
                     yield s
             else:
                 if six.PY3:
                     with open(self.path, "r", encoding="utf-8", errors="surrogateescape") as f:
                         yield f
                 else:
                     with codecs.open(self.path, "r", encoding="utf-8", errors="surrogateescape") as f:
                         yield f
     except StopIteration:
         raise
     except Exception as ex:
         self._exception = ex
         raise ContentException(str(ex))
Exemple #2
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
         else:
             args = self.create_args()
             if args:
                 with streams.connect(*args, 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))
Exemple #3
0
 def connect(self, *args, **kwargs):
     with streams.connect(*args, **kwargs) as s:
         yield s