Exemple #1
0
def test_list_readline():
    l = ['a', 'b']
    readline = openpy._list_readline(l)
    nt.assert_equal(readline(), 'a')
    nt.assert_equal(readline(), 'b')
    with nt.assert_raises(StopIteration):
        readline()
Exemple #2
0
    def getlines(filename, module_globals=None):
        """Get the lines (as unicode) for a file from the cache.
        Update the cache if it doesn't contain an entry for this file already."""
        filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding())
        lines = linecache.getlines(filename, module_globals=module_globals)

        if (not lines) or isinstance(lines[0], str):
            return lines

        readline = openpy._list_readline(lines)
        try:
            encoding, _ = openpy.detect_encoding(readline)
        except SyntaxError:
            encoding = 'ascii'
        return [l.decode(encoding, 'replace') for l in lines]
Exemple #3
0
 def getlines(filename, module_globals=None):
     """Get the lines (as unicode) for a file from the cache.
     Update the cache if it doesn't contain an entry for this file already."""
     filename = py3compat.cast_bytes(filename, sys.getfilesystemencoding())
     lines = linecache.getlines(filename, module_globals=module_globals)
     
     # The bits we cache ourselves can be unicode.
     if (not lines) or isinstance(lines[0], unicode):
         return lines
     
     readline = openpy._list_readline(lines)
     try:
         encoding, _ = openpy.detect_encoding(readline)
     except SyntaxError:
         encoding = 'ascii'
     return [l.decode(encoding, 'replace') for l in lines]