<s> try : <EOL> basestring = basestring <EOL> except NameError : <EOL> basestring = str <EOL> from . nmea import NMEASentence <EOL> class NMEAFile ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , f , * args , ** kwargs ) : <EOL> super ( NMEAFile , self ) . __init__ ( ) <EOL> if isinstance ( f , basestring ) or args or kwargs : <EOL> self . _file = self . open ( f , * args , ** kwargs ) <EOL> else : <EOL> self . _file = f <EOL> self . _context = None <EOL> def open ( self , fp , mode = '<STR_LIT:r>' ) : <EOL> """<STR_LIT>""" <EOL> self . _file = open ( fp , mode = mode ) <EOL> return self . _file <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _file . close ( ) <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> for line in self . _file : <EOL> yield self . parse ( line ) <EOL> def __enter__ ( self ) : <EOL> if hasattr ( self . _file , '<STR_LIT>' ) : <EOL> self . _context = self . _file . __enter__ ( ) <EOL> return self <EOL> def __exit__ ( self , exc_type , exc_val , exc_tb ) : <EOL> if self . _context : <EOL> ctx = self . _context <EOL> self . _context = None <EOL> ctx . __exit__ ( exc_type , exc_val , exc_tb ) <EOL> def next ( self ) : <EOL> """<STR_LIT>""" <EOL> data = self . _file . readline ( ) <EOL> return self . parse ( data ) <EOL> def parse ( self , s ) : <EOL> return NMEASentence . parse ( s ) <EOL> def readline ( self ) : <EOL> """<STR_LIT>""" <EOL> data = self . _file . readline ( ) <EOL> s = self . parse ( data ) <EOL> return s <EOL> def read ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ s for s in self ] </s>
