<s> """<STR_LIT>""" <EOL> from __future__ import ( print_function , unicode_literals ) <EOL> import os <EOL> import abc <EOL> import codecs <EOL> import warnings <EOL> import errno <EOL> try : <EOL> from thread import allocate_lock as Lock <EOL> except ImportError : <EOL> from dummy_thread import allocate_lock as Lock <EOL> import io <EOL> from io import ( __all__ , SEEK_SET , SEEK_CUR , SEEK_END ) <EOL> from errno import EINTR <EOL> __metaclass__ = type <EOL> DEFAULT_BUFFER_SIZE = <NUM_LIT:8> * <NUM_LIT> <EOL> class BlockingIOError ( IOError ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , errno , strerror , characters_written = <NUM_LIT:0> ) : <EOL> super ( IOError , self ) . __init__ ( errno , strerror ) <EOL> if not isinstance ( characters_written , ( int , long ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> self . characters_written = characters_written <EOL> def open ( file , mode = "<STR_LIT:r>" , buffering = - <NUM_LIT:1> , <EOL> encoding = None , errors = None , <EOL> newline = None , closefd = True ) : <EOL> r"""<STR_LIT>""" <EOL> if not isinstance ( file , ( basestring , int , long ) ) : <EOL> raise TypeError ( "<STR_LIT>" % file ) <EOL> if not isinstance ( mode , basestring ) : <EOL> raise TypeError ( "<STR_LIT>" % mode ) <EOL> if not isinstance ( buffering , ( int , long ) ) : <EOL> raise TypeError ( "<STR_LIT>" % buffering ) <EOL> if encoding is not None and not isinstance ( encoding , basestring ) : <EOL> raise TypeError ( "<STR_LIT>" % encoding ) <EOL> if errors is not None and not isinstance ( errors , basestring ) : <EOL> raise TypeError ( "<STR_LIT>" % errors ) <EOL> modes = set ( mode ) <EOL> if modes - set ( "<STR_LIT>" ) or len ( mode ) > len ( modes ) : <EOL> raise ValueError ( "<STR_LIT>" % mode ) <EOL> reading = "<STR_LIT:r>" in modes <EOL> writing = "<STR_LIT:w>" in modes <EOL> appending = "<STR_LIT:a>" in modes <EOL> updating = "<STR_LIT:+>" in modes <EOL> text = "<STR_LIT:t>" in modes <EOL> binary = "<STR_LIT:b>" in modes <EOL> if "<STR_LIT>" in modes : <EOL> if writing or appending : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> reading = True <EOL> if text and binary : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if reading + writing + appending > <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not ( reading or writing or appending ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if binary and encoding is not None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if binary and errors is not None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if binary and newline is not None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> raw = FileIO ( file , <EOL> ( reading and "<STR_LIT:r>" or "<STR_LIT>" ) + <EOL> ( writing and "<STR_LIT:w>" or "<STR_LIT>" ) + <EOL> ( appending and "<STR_LIT:a>" or "<STR_LIT>" ) + <EOL> ( updating and "<STR_LIT:+>" or "<STR_LIT>" ) , <EOL> closefd ) <EOL> result = raw <EOL> try : <EOL> line_buffering = False <EOL> if buffering == <NUM_LIT:1> or buffering < <NUM_LIT:0> and raw . isatty ( ) : <EOL> buffering = - <NUM_LIT:1> <EOL> line_buffering = True <EOL> if buffering < <NUM_LIT:0> : <EOL> buffering = DEFAULT_BUFFER_SIZE <EOL> try : <EOL> bs = os . fstat ( raw . fileno ( ) ) . st_blksize <EOL> except ( os . error , AttributeError ) : <EOL> pass <EOL> else : <EOL> if bs > <NUM_LIT:1> : <EOL> buffering = bs <EOL> if buffering < <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if buffering == <NUM_LIT:0> : <EOL> if binary : <EOL> return result <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if updating : <EOL> buffer = BufferedRandom ( raw , buffering ) <EOL> elif writing or appending : <EOL> buffer = BufferedWriter ( raw , buffering ) <EOL> elif reading : <EOL> buffer = BufferedReader ( raw , buffering ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % mode ) <EOL> result = buffer <EOL> if binary : <EOL> return result <EOL> text = TextIOWrapper ( buffer , encoding , errors , newline , line_buffering ) <EOL> result = text <EOL> text . mode = mode <EOL> return result <EOL> except : <EOL> result . close ( ) <EOL> raise <EOL> class DocDescriptor : <EOL> """<STR_LIT>""" <EOL> def __get__ ( self , obj , typ ) : <EOL> return ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" + <EOL> open . __doc__ ) <EOL> class OpenWrapper : <EOL> """<STR_LIT>""" <EOL> __doc__ = DocDescriptor ( ) <EOL> def __new__ ( cls , * args , ** kwargs ) : <EOL> return open ( * args , ** kwargs ) <EOL> class UnsupportedOperation ( ValueError , IOError ) : <EOL> pass <EOL> class IOBase : <EOL> __metaclass__ = abc . ABCMeta <EOL> """<STR_LIT>""" <EOL> def _unsupported ( self , name ) : <EOL> """<STR_LIT>""" <EOL> raise UnsupportedOperation ( "<STR_LIT>" % <EOL> ( self . __class__ . __name__ , name ) ) <EOL> def seek ( self , pos , whence = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def tell ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . seek ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> def truncate ( self , pos = None ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def flush ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _checkClosed ( ) <EOL> __closed = False <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . __closed : <EOL> try : <EOL> self . flush ( ) <EOL> finally : <EOL> self . __closed = True <EOL> def __del__ ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . close ( ) <EOL> except : <EOL> pass <EOL> def seekable ( self ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> def _checkSeekable ( self , msg = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . seekable ( ) : <EOL> raise IOError ( "<STR_LIT>" <EOL> if msg is None else msg ) <EOL> def readable ( self ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> def _checkReadable ( self , msg = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . readable ( ) : <EOL> raise IOError ( "<STR_LIT>" <EOL> if msg is None else msg ) <EOL> def writable ( self ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> def _checkWritable ( self , msg = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . writable ( ) : <EOL> raise IOError ( "<STR_LIT>" <EOL> if msg is None else msg ) <EOL> @ property <EOL> def closed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __closed <EOL> def _checkClosed ( self , msg = None ) : <EOL> """<STR_LIT>""" <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" <EOL> if msg is None else msg ) <EOL> def __enter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _checkClosed ( ) <EOL> return self <EOL> def __exit__ ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> self . close ( ) <EOL> def fileno ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def isatty ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _checkClosed ( ) <EOL> return False <EOL> def readline ( self , limit = - <NUM_LIT:1> ) : <EOL> r"""<STR_LIT>""" <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> def nreadahead ( ) : <EOL> readahead = self . peek ( <NUM_LIT:1> ) <EOL> if not readahead : <EOL> return <NUM_LIT:1> <EOL> n = ( readahead . find ( b"<STR_LIT:\n>" ) + <NUM_LIT:1> ) or len ( readahead ) <EOL> if limit >= <NUM_LIT:0> : <EOL> n = min ( n , limit ) <EOL> return n <EOL> else : <EOL> def nreadahead ( ) : <EOL> return <NUM_LIT:1> <EOL> if limit is None : <EOL> limit = - <NUM_LIT:1> <EOL> elif not isinstance ( limit , ( int , long ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> res = bytearray ( ) <EOL> while limit < <NUM_LIT:0> or len ( res ) < limit : <EOL> b = self . read ( nreadahead ( ) ) <EOL> if not b : <EOL> break <EOL> res += b <EOL> if res . endswith ( b"<STR_LIT:\n>" ) : <EOL> break <EOL> return bytes ( res ) <EOL> def __iter__ ( self ) : <EOL> self . _checkClosed ( ) <EOL> return self <EOL> def next ( self ) : <EOL> line = self . readline ( ) <EOL> if not line : <EOL> raise StopIteration <EOL> return line <EOL> def readlines ( self , hint = None ) : <EOL> """<STR_LIT>""" <EOL> if hint is not None and not isinstance ( hint , ( int , long ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if hint is None or hint <= <NUM_LIT:0> : <EOL> return list ( self ) <EOL> n = <NUM_LIT:0> <EOL> lines = [ ] <EOL> for line in self : <EOL> lines . append ( line ) <EOL> n += len ( line ) <EOL> if n >= hint : <EOL> break <EOL> return lines <EOL> def writelines ( self , lines ) : <EOL> self . _checkClosed ( ) <EOL> for line in lines : <EOL> self . write ( line ) <EOL> io . IOBase . register ( IOBase ) <EOL> class RawIOBase ( IOBase ) : <EOL> """<STR_LIT>""" <EOL> def read ( self , n = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if n is None : <EOL> n = - <NUM_LIT:1> <EOL> if n < <NUM_LIT:0> : <EOL> return self . readall ( ) <EOL> b = bytearray ( n . __index__ ( ) ) <EOL> n = self . readinto ( b ) <EOL> if n is None : <EOL> return None <EOL> del b [ n : ] <EOL> return bytes ( b ) <EOL> def readall ( self ) : <EOL> """<STR_LIT>""" <EOL> res = bytearray ( ) <EOL> while True : <EOL> data = self . read ( DEFAULT_BUFFER_SIZE ) <EOL> if not data : <EOL> break <EOL> res += data <EOL> if res : <EOL> return bytes ( res ) <EOL> else : <EOL> return data <EOL> def readinto ( self , b ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def write ( self , b ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> io . RawIOBase . register ( RawIOBase ) <EOL> from _io import FileIO <EOL> RawIOBase . register ( FileIO ) <EOL> class BufferedIOBase ( IOBase ) : <EOL> """<STR_LIT>""" <EOL> def read ( self , n = None ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def read1 ( self , n = None ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def readinto ( self , b ) : <EOL> """<STR_LIT>""" <EOL> data = self . read ( len ( b ) ) <EOL> n = len ( data ) <EOL> try : <EOL> b [ : n ] = data <EOL> except TypeError as err : <EOL> import array <EOL> if not isinstance ( b , array . array ) : <EOL> raise err <EOL> b [ : n ] = array . array ( b'<STR_LIT:b>' , data ) <EOL> return n <EOL> def write ( self , b ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def detach ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> io . BufferedIOBase . register ( BufferedIOBase ) <EOL> class _BufferedIOMixin ( BufferedIOBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , raw ) : <EOL> self . _raw = raw <EOL> def seek ( self , pos , whence = <NUM_LIT:0> ) : <EOL> new_position = self . raw . seek ( pos , whence ) <EOL> if new_position < <NUM_LIT:0> : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> return new_position <EOL> def tell ( self ) : <EOL> pos = self . raw . tell ( ) <EOL> if pos < <NUM_LIT:0> : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> return pos <EOL> def truncate ( self , pos = None ) : <EOL> self . flush ( ) <EOL> if pos is None : <EOL> pos = self . tell ( ) <EOL> return self . raw . truncate ( pos ) <EOL> def flush ( self ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . raw . flush ( ) <EOL> def close ( self ) : <EOL> if self . raw is not None and not self . closed : <EOL> try : <EOL> self . flush ( ) <EOL> finally : <EOL> self . raw . close ( ) <EOL> def detach ( self ) : <EOL> if self . raw is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . flush ( ) <EOL> raw = self . _raw <EOL> self . _raw = None <EOL> return raw <EOL> def seekable ( self ) : <EOL> return self . raw . seekable ( ) <EOL> def readable ( self ) : <EOL> return self . raw . readable ( ) <EOL> def writable ( self ) : <EOL> return self . raw . writable ( ) <EOL> @ property <EOL> def raw ( self ) : <EOL> return self . _raw <EOL> @ property <EOL> def closed ( self ) : <EOL> return self . raw . closed <EOL> @ property <EOL> def name ( self ) : <EOL> return self . raw . name <EOL> @ property <EOL> def mode ( self ) : <EOL> return self . raw . mode <EOL> def __repr__ ( self ) : <EOL> clsname = self . __class__ . __name__ <EOL> try : <EOL> name = self . name <EOL> except Exception : <EOL> return "<STR_LIT>" . format ( clsname ) <EOL> else : <EOL> return "<STR_LIT>" . format ( clsname , name ) <EOL> def fileno ( self ) : <EOL> return self . raw . fileno ( ) <EOL> def isatty ( self ) : <EOL> return self . raw . isatty ( ) <EOL> class BytesIO ( BufferedIOBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , initial_bytes = None ) : <EOL> buf = bytearray ( ) <EOL> if initial_bytes is not None : <EOL> buf . extend ( initial_bytes ) <EOL> self . _buffer = buf <EOL> self . _pos = <NUM_LIT:0> <EOL> def __getstate__ ( self ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return self . __dict__ . copy ( ) <EOL> def getvalue ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return bytes ( self . _buffer ) <EOL> def read ( self , n = None ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if n is None : <EOL> n = - <NUM_LIT:1> <EOL> if not isinstance ( n , ( int , long ) ) : <EOL> raise TypeError ( "<STR_LIT>" . format ( <EOL> type ( n ) ) ) <EOL> if n < <NUM_LIT:0> : <EOL> n = len ( self . _buffer ) <EOL> if len ( self . _buffer ) <= self . _pos : <EOL> return b"<STR_LIT>" <EOL> newpos = min ( len ( self . _buffer ) , self . _pos + n ) <EOL> b = self . _buffer [ self . _pos : newpos ] <EOL> self . _pos = newpos <EOL> return bytes ( b ) <EOL> def read1 ( self , n ) : <EOL> """<STR_LIT>""" <EOL> return self . read ( n ) <EOL> def write ( self , b ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if isinstance ( b , unicode ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> n = len ( b ) <EOL> if n == <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> pos = self . _pos <EOL> if pos > len ( self . _buffer ) : <EOL> padding = b'<STR_LIT:\x00>' * ( pos - len ( self . _buffer ) ) <EOL> self . _buffer += padding <EOL> self . _buffer [ pos : pos + n ] = b <EOL> self . _pos += n <EOL> return n <EOL> def seek ( self , pos , whence = <NUM_LIT:0> ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> try : <EOL> pos . __index__ <EOL> except AttributeError : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if whence == <NUM_LIT:0> : <EOL> if pos < <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" % ( pos , ) ) <EOL> self . _pos = pos <EOL> elif whence == <NUM_LIT:1> : <EOL> self . _pos = max ( <NUM_LIT:0> , self . _pos + pos ) <EOL> elif whence == <NUM_LIT:2> : <EOL> self . _pos = max ( <NUM_LIT:0> , len ( self . _buffer ) + pos ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return self . _pos <EOL> def tell ( self ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return self . _pos <EOL> def truncate ( self , pos = None ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if pos is None : <EOL> pos = self . _pos <EOL> else : <EOL> try : <EOL> pos . __index__ <EOL> except AttributeError : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if pos < <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" % ( pos , ) ) <EOL> del self . _buffer [ pos : ] <EOL> return pos <EOL> def readable ( self ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return True <EOL> def writable ( self ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return True <EOL> def seekable ( self ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return True <EOL> class BufferedReader ( _BufferedIOMixin ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , raw , buffer_size = DEFAULT_BUFFER_SIZE ) : <EOL> """<STR_LIT>""" <EOL> if not raw . readable ( ) : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> _BufferedIOMixin . __init__ ( self , raw ) <EOL> if buffer_size <= <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . buffer_size = buffer_size <EOL> self . _reset_read_buf ( ) <EOL> self . _read_lock = Lock ( ) <EOL> def _reset_read_buf ( self ) : <EOL> self . _read_buf = b"<STR_LIT>" <EOL> self . _read_pos = <NUM_LIT:0> <EOL> def read ( self , n = None ) : <EOL> """<STR_LIT>""" <EOL> if n is not None and n < - <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> with self . _read_lock : <EOL> return self . _read_unlocked ( n ) <EOL> def _read_unlocked ( self , n = None ) : <EOL> nodata_val = b"<STR_LIT>" <EOL> empty_values = ( b"<STR_LIT>" , None ) <EOL> buf = self . _read_buf <EOL> pos = self . _read_pos <EOL> if n is None or n == - <NUM_LIT:1> : <EOL> self . _reset_read_buf ( ) <EOL> chunks = [ buf [ pos : ] ] <EOL> current_size = <NUM_LIT:0> <EOL> while True : <EOL> try : <EOL> chunk = self . raw . read ( ) <EOL> except IOError as e : <EOL> if e . errno != EINTR : <EOL> raise <EOL> continue <EOL> if chunk in empty_values : <EOL> nodata_val = chunk <EOL> break <EOL> current_size += len ( chunk ) <EOL> chunks . append ( chunk ) <EOL> return b"<STR_LIT>" . join ( chunks ) or nodata_val <EOL> avail = len ( buf ) - pos <EOL> if n <= avail : <EOL> self . _read_pos += n <EOL> return buf [ pos : pos + n ] <EOL> chunks = [ buf [ pos : ] ] <EOL> wanted = max ( self . buffer_size , n ) <EOL> while avail < n : <EOL> try : <EOL> chunk = self . raw . read ( wanted ) <EOL> except IOError as e : <EOL> if e . errno != EINTR : <EOL> raise <EOL> continue <EOL> if chunk in empty_values : <EOL> nodata_val = chunk <EOL> break <EOL> avail += len ( chunk ) <EOL> chunks . append ( chunk ) <EOL> n = min ( n , avail ) <EOL> out = b"<STR_LIT>" . join ( chunks ) <EOL> self . _read_buf = out [ n : ] <EOL> self . _read_pos = <NUM_LIT:0> <EOL> return out [ : n ] if out else nodata_val <EOL> def peek ( self , n = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> with self . _read_lock : <EOL> return self . _peek_unlocked ( n ) <EOL> def _peek_unlocked ( self , n = <NUM_LIT:0> ) : <EOL> want = min ( n , self . buffer_size ) <EOL> have = len ( self . _read_buf ) - self . _read_pos <EOL> if have < want or have <= <NUM_LIT:0> : <EOL> to_read = self . buffer_size - have <EOL> while True : <EOL> try : <EOL> current = self . raw . read ( to_read ) <EOL> except IOError as e : <EOL> if e . errno != EINTR : <EOL> raise <EOL> continue <EOL> break <EOL> if current : <EOL> self . _read_buf = self . _read_buf [ self . _read_pos : ] + current <EOL> self . _read_pos = <NUM_LIT:0> <EOL> return self . _read_buf [ self . _read_pos : ] <EOL> def read1 ( self , n ) : <EOL> """<STR_LIT>""" <EOL> if n < <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if n == <NUM_LIT:0> : <EOL> return b"<STR_LIT>" <EOL> with self . _read_lock : <EOL> self . _peek_unlocked ( <NUM_LIT:1> ) <EOL> return self . _read_unlocked ( <EOL> min ( n , len ( self . _read_buf ) - self . _read_pos ) ) <EOL> def tell ( self ) : <EOL> return _BufferedIOMixin . tell ( self ) - len ( self . _read_buf ) + self . _read_pos <EOL> def seek ( self , pos , whence = <NUM_LIT:0> ) : <EOL> if not ( <NUM_LIT:0> <= whence <= <NUM_LIT:2> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> with self . _read_lock : <EOL> if whence == <NUM_LIT:1> : <EOL> pos -= len ( self . _read_buf ) - self . _read_pos <EOL> pos = _BufferedIOMixin . seek ( self , pos , whence ) <EOL> self . _reset_read_buf ( ) <EOL> return pos <EOL> class BufferedWriter ( _BufferedIOMixin ) : <EOL> """<STR_LIT>""" <EOL> _warning_stack_offset = <NUM_LIT:2> <EOL> def __init__ ( self , raw , <EOL> buffer_size = DEFAULT_BUFFER_SIZE , max_buffer_size = None ) : <EOL> if not raw . writable ( ) : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> _BufferedIOMixin . __init__ ( self , raw ) <EOL> if buffer_size <= <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if max_buffer_size is not None : <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning , <EOL> self . _warning_stack_offset ) <EOL> self . buffer_size = buffer_size <EOL> self . _write_buf = bytearray ( ) <EOL> self . _write_lock = Lock ( ) <EOL> def write ( self , b ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if isinstance ( b , unicode ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> with self . _write_lock : <EOL> if len ( self . _write_buf ) > self . buffer_size : <EOL> self . _flush_unlocked ( ) <EOL> before = len ( self . _write_buf ) <EOL> self . _write_buf . extend ( b ) <EOL> written = len ( self . _write_buf ) - before <EOL> if len ( self . _write_buf ) > self . buffer_size : <EOL> try : <EOL> self . _flush_unlocked ( ) <EOL> except BlockingIOError as e : <EOL> if len ( self . _write_buf ) > self . buffer_size : <EOL> overage = len ( self . _write_buf ) - self . buffer_size <EOL> written -= overage <EOL> self . _write_buf = self . _write_buf [ : self . buffer_size ] <EOL> raise BlockingIOError ( e . errno , e . strerror , written ) <EOL> return written <EOL> def truncate ( self , pos = None ) : <EOL> with self . _write_lock : <EOL> self . _flush_unlocked ( ) <EOL> if pos is None : <EOL> pos = self . raw . tell ( ) <EOL> return self . raw . truncate ( pos ) <EOL> def flush ( self ) : <EOL> with self . _write_lock : <EOL> self . _flush_unlocked ( ) <EOL> def _flush_unlocked ( self ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> while self . _write_buf : <EOL> try : <EOL> n = self . raw . write ( self . _write_buf ) <EOL> except BlockingIOError : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> except IOError as e : <EOL> if e . errno != EINTR : <EOL> raise <EOL> continue <EOL> if n is None : <EOL> raise BlockingIOError ( <EOL> errno . EAGAIN , <EOL> "<STR_LIT>" , <NUM_LIT:0> ) <EOL> if n > len ( self . _write_buf ) or n < <NUM_LIT:0> : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> del self . _write_buf [ : n ] <EOL> def tell ( self ) : <EOL> return _BufferedIOMixin . tell ( self ) + len ( self . _write_buf ) <EOL> def seek ( self , pos , whence = <NUM_LIT:0> ) : <EOL> if not ( <NUM_LIT:0> <= whence <= <NUM_LIT:2> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> with self . _write_lock : <EOL> self . _flush_unlocked ( ) <EOL> return _BufferedIOMixin . seek ( self , pos , whence ) <EOL> class BufferedRWPair ( BufferedIOBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , reader , writer , <EOL> buffer_size = DEFAULT_BUFFER_SIZE , max_buffer_size = None ) : <EOL> """<STR_LIT>""" <EOL> if max_buffer_size is not None : <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning , <NUM_LIT:2> ) <EOL> if not reader . readable ( ) : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> if not writer . writable ( ) : <EOL> raise IOError ( '<STR_LIT>' ) <EOL> self . reader = BufferedReader ( reader , buffer_size ) <EOL> self . writer = BufferedWriter ( writer , buffer_size ) <EOL> def read ( self , n = None ) : <EOL> if n is None : <EOL> n = - <NUM_LIT:1> <EOL> return self . reader . read ( n ) <EOL> def readinto ( self , b ) : <EOL> return self . reader . readinto ( b ) <EOL> def write ( self , b ) : <EOL> return self . writer . write ( b ) <EOL> def peek ( self , n = <NUM_LIT:0> ) : <EOL> return self . reader . peek ( n ) <EOL> def read1 ( self , n ) : <EOL> return self . reader . read1 ( n ) <EOL> def readable ( self ) : <EOL> return self . reader . readable ( ) <EOL> def writable ( self ) : <EOL> return self . writer . writable ( ) <EOL> def flush ( self ) : <EOL> return self . writer . flush ( ) <EOL> def close ( self ) : <EOL> try : <EOL> self . writer . close ( ) <EOL> finally : <EOL> self . reader . close ( ) <EOL> def isatty ( self ) : <EOL> return self . reader . isatty ( ) or self . writer . isatty ( ) <EOL> @ property <EOL> def closed ( self ) : <EOL> return self . writer . closed <EOL> class BufferedRandom ( BufferedWriter , BufferedReader ) : <EOL> """<STR_LIT>""" <EOL> _warning_stack_offset = <NUM_LIT:3> <EOL> def __init__ ( self , raw , <EOL> buffer_size = DEFAULT_BUFFER_SIZE , max_buffer_size = None ) : <EOL> raw . _checkSeekable ( ) <EOL> BufferedReader . __init__ ( self , raw , buffer_size ) <EOL> BufferedWriter . __init__ ( self , raw , buffer_size , max_buffer_size ) <EOL> def seek ( self , pos , whence = <NUM_LIT:0> ) : <EOL> if not ( <NUM_LIT:0> <= whence <= <NUM_LIT:2> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . flush ( ) <EOL> if self . _read_buf : <EOL> with self . _read_lock : <EOL> self . raw . seek ( self . _read_pos - len ( self . _read_buf ) , <NUM_LIT:1> ) <EOL> pos = self . raw . seek ( pos , whence ) <EOL> with self . _read_lock : <EOL> self . _reset_read_buf ( ) <EOL> if pos < <NUM_LIT:0> : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> return pos <EOL> def tell ( self ) : <EOL> if self . _write_buf : <EOL> return BufferedWriter . tell ( self ) <EOL> else : <EOL> return BufferedReader . tell ( self ) <EOL> def truncate ( self , pos = None ) : <EOL> if pos is None : <EOL> pos = self . tell ( ) <EOL> return BufferedWriter . truncate ( self , pos ) <EOL> def read ( self , n = None ) : <EOL> if n is None : <EOL> n = - <NUM_LIT:1> <EOL> self . flush ( ) <EOL> return BufferedReader . read ( self , n ) <EOL> def readinto ( self , b ) : <EOL> self . flush ( ) <EOL> return BufferedReader . readinto ( self , b ) <EOL> def peek ( self , n = <NUM_LIT:0> ) : <EOL> self . flush ( ) <EOL> return BufferedReader . peek ( self , n ) <EOL> def read1 ( self , n ) : <EOL> self . flush ( ) <EOL> return BufferedReader . read1 ( self , n ) <EOL> def write ( self , b ) : <EOL> if self . _read_buf : <EOL> with self . _read_lock : <EOL> self . raw . seek ( self . _read_pos - len ( self . _read_buf ) , <NUM_LIT:1> ) <EOL> self . _reset_read_buf ( ) <EOL> return BufferedWriter . write ( self , b ) <EOL> class TextIOBase ( IOBase ) : <EOL> """<STR_LIT>""" <EOL> def read ( self , n = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def write ( self , s ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def truncate ( self , pos = None ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def readline ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> def detach ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _unsupported ( "<STR_LIT>" ) <EOL> @ property <EOL> def encoding ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> @ property <EOL> def newlines ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> @ property <EOL> def errors ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> io . TextIOBase . register ( TextIOBase ) <EOL> class IncrementalNewlineDecoder ( codecs . IncrementalDecoder ) : <EOL> r"""<STR_LIT>""" <EOL> def __init__ ( self , decoder , translate , errors = '<STR_LIT:strict>' ) : <EOL> codecs . IncrementalDecoder . __init__ ( self , errors = errors ) <EOL> self . translate = translate <EOL> self . decoder = decoder <EOL> self . seennl = <NUM_LIT:0> <EOL> self . pendingcr = False <EOL> def decode ( self , input , final = False ) : <EOL> if self . decoder is None : <EOL> output = input <EOL> else : <EOL> output = self . decoder . decode ( input , final = final ) <EOL> if self . pendingcr and ( output or final ) : <EOL> output = "<STR_LIT:\r>" + output <EOL> self . pendingcr = False <EOL> if output . endswith ( "<STR_LIT:\r>" ) and not final : <EOL> output = output [ : - <NUM_LIT:1> ] <EOL> self . pendingcr = True <EOL> crlf = output . count ( '<STR_LIT:\r\n>' ) <EOL> cr = output . count ( '<STR_LIT:\r>' ) - crlf <EOL> lf = output . count ( '<STR_LIT:\n>' ) - crlf <EOL> self . seennl |= ( lf and self . _LF ) | ( cr and self . _CR ) | ( crlf and self . _CRLF ) <EOL> if self . translate : <EOL> if crlf : <EOL> output = output . replace ( "<STR_LIT:\r\n>" , "<STR_LIT:\n>" ) <EOL> if cr : <EOL> output = output . replace ( "<STR_LIT:\r>" , "<STR_LIT:\n>" ) <EOL> return output <EOL> def getstate ( self ) : <EOL> if self . decoder is None : <EOL> buf = b"<STR_LIT>" <EOL> flag = <NUM_LIT:0> <EOL> else : <EOL> buf , flag = self . decoder . getstate ( ) <EOL> flag <<= <NUM_LIT:1> <EOL> if self . pendingcr : <EOL> flag |= <NUM_LIT:1> <EOL> return buf , flag <EOL> def setstate ( self , state ) : <EOL> buf , flag = state <EOL> self . pendingcr = bool ( flag & <NUM_LIT:1> ) <EOL> if self . decoder is not None : <EOL> self . decoder . setstate ( ( buf , flag >> <NUM_LIT:1> ) ) <EOL> def reset ( self ) : <EOL> self . seennl = <NUM_LIT:0> <EOL> self . pendingcr = False <EOL> if self . decoder is not None : <EOL> self . decoder . reset ( ) <EOL> _LF = <NUM_LIT:1> <EOL> _CR = <NUM_LIT:2> <EOL> _CRLF = <NUM_LIT:4> <EOL> @ property <EOL> def newlines ( self ) : <EOL> return ( None , <EOL> "<STR_LIT:\n>" , <EOL> "<STR_LIT:\r>" , <EOL> ( "<STR_LIT:\r>" , "<STR_LIT:\n>" ) , <EOL> "<STR_LIT:\r\n>" , <EOL> ( "<STR_LIT:\n>" , "<STR_LIT:\r\n>" ) , <EOL> ( "<STR_LIT:\r>" , "<STR_LIT:\r\n>" ) , <EOL> ( "<STR_LIT:\r>" , "<STR_LIT:\n>" , "<STR_LIT:\r\n>" ) <EOL> ) [ self . seennl ] <EOL> class TextIOWrapper ( TextIOBase ) : <EOL> r"""<STR_LIT>""" <EOL> _CHUNK_SIZE = <NUM_LIT> <EOL> def __init__ ( self , buffer , encoding = None , errors = None , newline = None , <EOL> line_buffering = False ) : <EOL> if newline is not None and not isinstance ( newline , basestring ) : <EOL> raise TypeError ( "<STR_LIT>" % ( type ( newline ) , ) ) <EOL> if newline not in ( None , "<STR_LIT>" , "<STR_LIT:\n>" , "<STR_LIT:\r>" , "<STR_LIT:\r\n>" ) : <EOL> raise ValueError ( "<STR_LIT>" % ( newline , ) ) <EOL> if encoding is None : <EOL> try : <EOL> import locale <EOL> except ImportError : <EOL> encoding = "<STR_LIT:ascii>" <EOL> else : <EOL> encoding = locale . getpreferredencoding ( ) <EOL> if not isinstance ( encoding , basestring ) : <EOL> raise ValueError ( "<STR_LIT>" % encoding ) <EOL> if errors is None : <EOL> errors = "<STR_LIT:strict>" <EOL> else : <EOL> if not isinstance ( errors , basestring ) : <EOL> raise ValueError ( "<STR_LIT>" % errors ) <EOL> self . _buffer = buffer <EOL> self . _line_buffering = line_buffering <EOL> self . _encoding = encoding <EOL> self . _errors = errors <EOL> self . _readuniversal = not newline <EOL> self . _readtranslate = newline is None <EOL> self . _readnl = newline <EOL> self . _writetranslate = newline != '<STR_LIT>' <EOL> self . _writenl = newline or os . linesep <EOL> self . _encoder = None <EOL> self . _decoder = None <EOL> self . _decoded_chars = '<STR_LIT>' <EOL> self . _decoded_chars_used = <NUM_LIT:0> <EOL> self . _snapshot = None <EOL> self . _seekable = self . _telling = self . buffer . seekable ( ) <EOL> if self . _seekable and self . writable ( ) : <EOL> position = self . buffer . tell ( ) <EOL> if position != <NUM_LIT:0> : <EOL> try : <EOL> self . _get_encoder ( ) . setstate ( <NUM_LIT:0> ) <EOL> except LookupError : <EOL> pass <EOL> def __repr__ ( self ) : <EOL> try : <EOL> name = self . name <EOL> except Exception : <EOL> return "<STR_LIT>" . format ( self . encoding ) <EOL> else : <EOL> return "<STR_LIT>" . format ( <EOL> name , self . encoding ) <EOL> @ property <EOL> def encoding ( self ) : <EOL> return self . _encoding <EOL> @ property <EOL> def errors ( self ) : <EOL> return self . _errors <EOL> @ property <EOL> def line_buffering ( self ) : <EOL> return self . _line_buffering <EOL> @ property <EOL> def buffer ( self ) : <EOL> return self . _buffer <EOL> def seekable ( self ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return self . _seekable <EOL> def readable ( self ) : <EOL> return self . buffer . readable ( ) <EOL> def writable ( self ) : <EOL> return self . buffer . writable ( ) <EOL> def flush ( self ) : <EOL> self . buffer . flush ( ) <EOL> self . _telling = self . _seekable <EOL> def close ( self ) : <EOL> if self . buffer is not None and not self . closed : <EOL> try : <EOL> self . flush ( ) <EOL> finally : <EOL> self . buffer . close ( ) <EOL> @ property <EOL> def closed ( self ) : <EOL> return self . buffer . closed <EOL> @ property <EOL> def name ( self ) : <EOL> return self . buffer . name <EOL> def fileno ( self ) : <EOL> return self . buffer . fileno ( ) <EOL> def isatty ( self ) : <EOL> return self . buffer . isatty ( ) <EOL> def write ( self , s ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not isinstance ( s , unicode ) : <EOL> raise TypeError ( "<STR_LIT>" % <EOL> s . __class__ . __name__ ) <EOL> length = len ( s ) <EOL> haslf = ( self . _writetranslate or self . _line_buffering ) and "<STR_LIT:\n>" in s <EOL> if haslf and self . _writetranslate and self . _writenl != "<STR_LIT:\n>" : <EOL> s = s . replace ( "<STR_LIT:\n>" , self . _writenl ) <EOL> encoder = self . _encoder or self . _get_encoder ( ) <EOL> b = encoder . encode ( s ) <EOL> self . buffer . write ( b ) <EOL> if self . _line_buffering and ( haslf or "<STR_LIT:\r>" in s ) : <EOL> self . flush ( ) <EOL> self . _snapshot = None <EOL> if self . _decoder : <EOL> self . _decoder . reset ( ) <EOL> return length <EOL> def _get_encoder ( self ) : <EOL> make_encoder = codecs . getincrementalencoder ( self . _encoding ) <EOL> self . _encoder = make_encoder ( self . _errors ) <EOL> return self . _encoder <EOL> def _get_decoder ( self ) : <EOL> make_decoder = codecs . getincrementaldecoder ( self . _encoding ) <EOL> decoder = make_decoder ( self . _errors ) <EOL> if self . _readuniversal : <EOL> decoder = IncrementalNewlineDecoder ( decoder , self . _readtranslate ) <EOL> self . _decoder = decoder <EOL> return decoder <EOL> def _set_decoded_chars ( self , chars ) : <EOL> """<STR_LIT>""" <EOL> self . _decoded_chars = chars <EOL> self . _decoded_chars_used = <NUM_LIT:0> <EOL> def _get_decoded_chars ( self , n = None ) : <EOL> """<STR_LIT>""" <EOL> offset = self . _decoded_chars_used <EOL> if n is None : <EOL> chars = self . _decoded_chars [ offset : ] <EOL> else : <EOL> chars = self . _decoded_chars [ offset : offset + n ] <EOL> self . _decoded_chars_used += len ( chars ) <EOL> return chars <EOL> def _rewind_decoded_chars ( self , n ) : <EOL> """<STR_LIT>""" <EOL> if self . _decoded_chars_used < n : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> self . _decoded_chars_used -= n <EOL> def _read_chunk ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _decoder is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . _telling : <EOL> dec_buffer , dec_flags = self . _decoder . getstate ( ) <EOL> input_chunk = self . buffer . read1 ( self . _CHUNK_SIZE ) <EOL> eof = not input_chunk <EOL> self . _set_decoded_chars ( self . _decoder . decode ( input_chunk , eof ) ) <EOL> if self . _telling : <EOL> self . _snapshot = ( dec_flags , dec_buffer + input_chunk ) <EOL> return not eof <EOL> def _pack_cookie ( self , position , dec_flags = <NUM_LIT:0> , <EOL> bytes_to_feed = <NUM_LIT:0> , need_eof = <NUM_LIT:0> , chars_to_skip = <NUM_LIT:0> ) : <EOL> return ( position | ( dec_flags << <NUM_LIT:64> ) | ( bytes_to_feed << <NUM_LIT> ) | <EOL> ( chars_to_skip << <NUM_LIT> ) | bool ( need_eof ) << <NUM_LIT> ) <EOL> def _unpack_cookie ( self , bigint ) : <EOL> rest , position = divmod ( bigint , <NUM_LIT:1> << <NUM_LIT:64> ) <EOL> rest , dec_flags = divmod ( rest , <NUM_LIT:1> << <NUM_LIT:64> ) <EOL> rest , bytes_to_feed = divmod ( rest , <NUM_LIT:1> << <NUM_LIT:64> ) <EOL> need_eof , chars_to_skip = divmod ( rest , <NUM_LIT:1> << <NUM_LIT:64> ) <EOL> return position , dec_flags , bytes_to_feed , need_eof , chars_to_skip <EOL> def tell ( self ) : <EOL> if not self . _seekable : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> if not self . _telling : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> self . flush ( ) <EOL> position = self . buffer . tell ( ) <EOL> decoder = self . _decoder <EOL> if decoder is None or self . _snapshot is None : <EOL> if self . _decoded_chars : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> return position <EOL> dec_flags , next_input = self . _snapshot <EOL> position -= len ( next_input ) <EOL> chars_to_skip = self . _decoded_chars_used <EOL> if chars_to_skip == <NUM_LIT:0> : <EOL> return self . _pack_cookie ( position , dec_flags ) <EOL> saved_state = decoder . getstate ( ) <EOL> try : <EOL> decoder . setstate ( ( b'<STR_LIT>' , dec_flags ) ) <EOL> start_pos = position <EOL> start_flags , bytes_fed , chars_decoded = dec_flags , <NUM_LIT:0> , <NUM_LIT:0> <EOL> need_eof = <NUM_LIT:0> <EOL> for next_byte in next_input : <EOL> bytes_fed += <NUM_LIT:1> <EOL> chars_decoded += len ( decoder . decode ( next_byte ) ) <EOL> dec_buffer , dec_flags = decoder . getstate ( ) <EOL> if not dec_buffer and chars_decoded <= chars_to_skip : <EOL> start_pos += bytes_fed <EOL> chars_to_skip -= chars_decoded <EOL> start_flags , bytes_fed , chars_decoded = dec_flags , <NUM_LIT:0> , <NUM_LIT:0> <EOL> if chars_decoded >= chars_to_skip : <EOL> break <EOL> else : <EOL> chars_decoded += len ( decoder . decode ( b'<STR_LIT>' , final = True ) ) <EOL> need_eof = <NUM_LIT:1> <EOL> if chars_decoded < chars_to_skip : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> return self . _pack_cookie ( <EOL> start_pos , start_flags , bytes_fed , need_eof , chars_to_skip ) <EOL> finally : <EOL> decoder . setstate ( saved_state ) <EOL> def truncate ( self , pos = None ) : <EOL> self . flush ( ) <EOL> if pos is None : <EOL> pos = self . tell ( ) <EOL> return self . buffer . truncate ( pos ) <EOL> def detach ( self ) : <EOL> if self . buffer is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . flush ( ) <EOL> buffer = self . _buffer <EOL> self . _buffer = None <EOL> return buffer <EOL> def seek ( self , cookie , whence = <NUM_LIT:0> ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not self . _seekable : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> if whence == <NUM_LIT:1> : <EOL> if cookie != <NUM_LIT:0> : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> whence = <NUM_LIT:0> <EOL> cookie = self . tell ( ) <EOL> if whence == <NUM_LIT:2> : <EOL> if cookie != <NUM_LIT:0> : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> self . flush ( ) <EOL> position = self . buffer . seek ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> self . _set_decoded_chars ( '<STR_LIT>' ) <EOL> self . _snapshot = None <EOL> if self . _decoder : <EOL> self . _decoder . reset ( ) <EOL> return position <EOL> if whence != <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> ( whence , ) ) <EOL> if cookie < <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" % ( cookie , ) ) <EOL> self . flush ( ) <EOL> start_pos , dec_flags , bytes_to_feed , need_eof , chars_to_skip = self . _unpack_cookie ( cookie ) <EOL> self . buffer . seek ( start_pos ) <EOL> self . _set_decoded_chars ( '<STR_LIT>' ) <EOL> self . _snapshot = None <EOL> if cookie == <NUM_LIT:0> and self . _decoder : <EOL> self . _decoder . reset ( ) <EOL> elif self . _decoder or dec_flags or chars_to_skip : <EOL> self . _decoder = self . _decoder or self . _get_decoder ( ) <EOL> self . _decoder . setstate ( ( b'<STR_LIT>' , dec_flags ) ) <EOL> self . _snapshot = ( dec_flags , b'<STR_LIT>' ) <EOL> if chars_to_skip : <EOL> input_chunk = self . buffer . read ( bytes_to_feed ) <EOL> self . _set_decoded_chars ( <EOL> self . _decoder . decode ( input_chunk , need_eof ) ) <EOL> self . _snapshot = ( dec_flags , input_chunk ) <EOL> if len ( self . _decoded_chars ) < chars_to_skip : <EOL> raise IOError ( "<STR_LIT>" ) <EOL> self . _decoded_chars_used = chars_to_skip <EOL> try : <EOL> encoder = self . _encoder or self . _get_encoder ( ) <EOL> except LookupError : <EOL> pass <EOL> else : <EOL> if cookie != <NUM_LIT:0> : <EOL> encoder . setstate ( <NUM_LIT:0> ) <EOL> else : <EOL> encoder . reset ( ) <EOL> return cookie <EOL> def read ( self , n = None ) : <EOL> self . _checkReadable ( ) <EOL> if n is None : <EOL> n = - <NUM_LIT:1> <EOL> decoder = self . _decoder or self . _get_decoder ( ) <EOL> try : <EOL> n . __index__ <EOL> except AttributeError : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if n < <NUM_LIT:0> : <EOL> result = ( self . _get_decoded_chars ( ) + <EOL> decoder . decode ( self . buffer . read ( ) , final = True ) ) <EOL> self . _set_decoded_chars ( '<STR_LIT>' ) <EOL> self . _snapshot = None <EOL> return result <EOL> else : <EOL> eof = False <EOL> result = self . _get_decoded_chars ( n ) <EOL> while len ( result ) < n and not eof : <EOL> eof = not self . _read_chunk ( ) <EOL> result += self . _get_decoded_chars ( n - len ( result ) ) <EOL> return result <EOL> def next ( self ) : <EOL> self . _telling = False <EOL> line = self . readline ( ) <EOL> if not line : <EOL> self . _snapshot = None <EOL> self . _telling = self . _seekable <EOL> raise StopIteration <EOL> return line <EOL> def readline ( self , limit = None ) : <EOL> if self . closed : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if limit is None : <EOL> limit = - <NUM_LIT:1> <EOL> elif not isinstance ( limit , ( int , long ) ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> line = self . _get_decoded_chars ( ) <EOL> start = <NUM_LIT:0> <EOL> if not self . _decoder : <EOL> self . _get_decoder ( ) <EOL> pos = endpos = None <EOL> while True : <EOL> if self . _readtranslate : <EOL> pos = line . find ( '<STR_LIT:\n>' , start ) <EOL> if pos >= <NUM_LIT:0> : <EOL> endpos = pos + <NUM_LIT:1> <EOL> break <EOL> else : <EOL> start = len ( line ) <EOL> elif self . _readuniversal : <EOL> nlpos = line . find ( "<STR_LIT:\n>" , start ) <EOL> crpos = line . find ( "<STR_LIT:\r>" , start ) <EOL> if crpos == - <NUM_LIT:1> : <EOL> if nlpos == - <NUM_LIT:1> : <EOL> start = len ( line ) <EOL> else : <EOL> endpos = nlpos + <NUM_LIT:1> <EOL> break <EOL> elif nlpos == - <NUM_LIT:1> : <EOL> endpos = crpos + <NUM_LIT:1> <EOL> break <EOL> elif nlpos < crpos : <EOL> endpos = nlpos + <NUM_LIT:1> <EOL> break <EOL> elif nlpos == crpos + <NUM_LIT:1> : <EOL> endpos = crpos + <NUM_LIT:2> <EOL> break <EOL> else : <EOL> endpos = crpos + <NUM_LIT:1> <EOL> break <EOL> else : <EOL> pos = line . find ( self . _readnl ) <EOL> if pos >= <NUM_LIT:0> : <EOL> endpos = pos + len ( self . _readnl ) <EOL> break <EOL> if limit >= <NUM_LIT:0> and len ( line ) >= limit : <EOL> endpos = limit <EOL> break <EOL> while self . _read_chunk ( ) : <EOL> if self . _decoded_chars : <EOL> break <EOL> if self . _decoded_chars : <EOL> line += self . _get_decoded_chars ( ) <EOL> else : <EOL> self . _set_decoded_chars ( '<STR_LIT>' ) <EOL> self . _snapshot = None <EOL> return line <EOL> if limit >= <NUM_LIT:0> and endpos > limit : <EOL> endpos = limit <EOL> self . _rewind_decoded_chars ( len ( line ) - endpos ) <EOL> return line [ : endpos ] <EOL> @ property <EOL> def newlines ( self ) : <EOL> return self . _decoder . newlines if self . _decoder else None <EOL> class StringIO ( TextIOWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , initial_value = "<STR_LIT>" , newline = "<STR_LIT:\n>" ) : <EOL> super ( StringIO , self ) . __init__ ( BytesIO ( ) , <EOL> encoding = "<STR_LIT:utf-8>" , <EOL> errors = "<STR_LIT:strict>" , <EOL> newline = newline ) <EOL> if newline is None : <EOL> self . _writetranslate = False <EOL> if initial_value : <EOL> if not isinstance ( initial_value , unicode ) : <EOL> initial_value = unicode ( initial_value ) <EOL> self . write ( initial_value ) <EOL> self . seek ( <NUM_LIT:0> ) <EOL> def getvalue ( self ) : <EOL> self . flush ( ) <EOL> decoder = self . _decoder or self . _get_decoder ( ) <EOL> old_state = decoder . getstate ( ) <EOL> decoder . reset ( ) <EOL> try : <EOL> return decoder . decode ( self . buffer . getvalue ( ) , final = True ) <EOL> finally : <EOL> decoder . setstate ( old_state ) <EOL> def __repr__ ( self ) : <EOL> return object . __repr__ ( self ) <EOL> @ property <EOL> def errors ( self ) : <EOL> return None <EOL> @ property <EOL> def encoding ( self ) : <EOL> return None <EOL> def detach ( self ) : <EOL> self . _unsupported ( "<STR_LIT>" ) </s>
