Exemple #1
0
    def open(self, file, sourced=False):
        """
        Return an open stream that can be used to read the given file.
        If the file's encoding is not C{None}, then the stream will
        automatically decode the file's contents into unicode.

        @param file: The file identifier of the file to read.
        """
        encoding = self.encoding(file)
        stream = self._root.join(file).open(encoding)
        if sourced:
            stream = SourcedStringStream(stream, file)
        return stream
Exemple #2
0
 def _open(self):
     """
     Open the file stream associated with this corpus view.  This
     will be called performed if any value is read from the view
     while its file stream is closed.
     """
     if isinstance(self._fileid, PathPointer):
         self._stream = self._fileid.open(self._encoding)
     elif self._encoding:
         self._stream = SeekableUnicodeStreamReader(
             open(self._fileid, 'rb'), self._encoding)
     else:
         self._stream = open(self._fileid, 'rb')
     if self._source is not None:
         self._stream = SourcedStringStream(self._stream, self._source)