<s> """<STR_LIT>""" <EOL> class FileLikeIter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , iterable , limit = None ) : <EOL> self . iterator = iter ( iterable ) <EOL> self . limit = limit <EOL> self . left = limit <EOL> self . buf = None <EOL> self . closed = False <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def __next__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . closed : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if self . buf : <EOL> rv = self . buf <EOL> self . buf = None <EOL> return rv <EOL> else : <EOL> return next ( self . iterator ) <EOL> def reset_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> self . left = self . limit <EOL> def read ( self , size = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if self . left is not None : <EOL> size = min ( size , self . left ) <EOL> if self . closed : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if size < <NUM_LIT:0> : <EOL> return '<STR_LIT>' . join ( self ) <EOL> elif not size : <EOL> chunk = '<STR_LIT>' <EOL> elif self . buf : <EOL> chunk = self . buf <EOL> self . buf = None <EOL> else : <EOL> try : <EOL> chunk = next ( self . iterator ) <EOL> except StopIteration : <EOL> return '<STR_LIT>' <EOL> if len ( chunk ) > size : <EOL> self . buf = chunk [ size : ] <EOL> chunk = chunk [ : size ] <EOL> if self . left is not None : <EOL> self . left -= len ( chunk ) <EOL> return chunk <EOL> def readline ( self , size = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if self . closed : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> data = '<STR_LIT>' <EOL> while '<STR_LIT:\n>' not in data and ( size < <NUM_LIT:0> or len ( data ) < size ) : <EOL> if size < <NUM_LIT:0> : <EOL> chunk = self . read ( <NUM_LIT> ) <EOL> else : <EOL> chunk = self . read ( size - len ( data ) ) <EOL> if not chunk : <EOL> break <EOL> data += chunk <EOL> if '<STR_LIT:\n>' in data : <EOL> data , sep , rest = data . partition ( '<STR_LIT:\n>' ) <EOL> data += sep <EOL> if self . buf : <EOL> self . buf = rest + self . buf <EOL> else : <EOL> self . buf = rest <EOL> return data <EOL> def readlines ( self , sizehint = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if self . closed : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> lines = [ ] <EOL> while True : <EOL> line = self . readline ( sizehint ) <EOL> if not line : <EOL> break <EOL> lines . append ( line ) <EOL> if sizehint >= <NUM_LIT:0> : <EOL> sizehint -= len ( line ) <EOL> if sizehint <= <NUM_LIT:0> : <EOL> break <EOL> return lines <EOL> def is_empty ( self ) : <EOL> """<STR_LIT>""" <EOL> something = self . read ( <NUM_LIT:1> ) <EOL> if something : <EOL> if self . buf : <EOL> self . buf = something + self . buf <EOL> else : <EOL> self . buf = something <EOL> return False <EOL> else : <EOL> return True <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . iterator = None <EOL> self . closed = True </s>
