<s> import _base <EOL> class Filter ( _base . Filter ) : <EOL> def __init__ ( self , source , encoding ) : <EOL> _base . Filter . __init__ ( self , source ) <EOL> self . encoding = encoding <EOL> def __iter__ ( self ) : <EOL> state = "<STR_LIT>" <EOL> meta_found = ( self . encoding is None ) <EOL> pending = [ ] <EOL> for token in _base . Filter . __iter__ ( self ) : <EOL> type = token [ "<STR_LIT:type>" ] <EOL> if type == "<STR_LIT>" : <EOL> if token [ "<STR_LIT:name>" ] . lower ( ) == u"<STR_LIT>" : <EOL> state = "<STR_LIT>" <EOL> elif type == "<STR_LIT>" : <EOL> if token [ "<STR_LIT:name>" ] . lower ( ) == u"<STR_LIT>" : <EOL> has_http_equiv_content_type = False <EOL> for ( namespace , name ) , value in token [ "<STR_LIT:data>" ] . iteritems ( ) : <EOL> if namespace != None : <EOL> continue <EOL> elif name . lower ( ) == u'<STR_LIT>' : <EOL> token [ "<STR_LIT:data>" ] [ ( namespace , name ) ] = self . encoding <EOL> meta_found = True <EOL> break <EOL> elif name == u'<STR_LIT>' and value . lower ( ) == u'<STR_LIT>' : <EOL> has_http_equiv_content_type = True <EOL> else : <EOL> if has_http_equiv_content_type and ( None , u"<STR_LIT:content>" ) in token [ "<STR_LIT:data>" ] : <EOL> token [ "<STR_LIT:data>" ] [ ( None , u"<STR_LIT:content>" ) ] = u'<STR_LIT>' % self . encoding <EOL> meta_found = True <EOL> elif token [ "<STR_LIT:name>" ] . lower ( ) == u"<STR_LIT>" and not meta_found : <EOL> yield { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:name>" : u"<STR_LIT>" , <EOL> "<STR_LIT:data>" : token [ "<STR_LIT:data>" ] } <EOL> yield { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:name>" : u"<STR_LIT>" , <EOL> "<STR_LIT:data>" : { ( None , u"<STR_LIT>" ) : self . encoding } } <EOL> yield { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:name>" : u"<STR_LIT>" } <EOL> meta_found = True <EOL> continue <EOL> elif type == "<STR_LIT>" : <EOL> if token [ "<STR_LIT:name>" ] . lower ( ) == u"<STR_LIT>" and pending : <EOL> yield pending . pop ( <NUM_LIT:0> ) <EOL> if not meta_found : <EOL> yield { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:name>" : u"<STR_LIT>" , <EOL> "<STR_LIT:data>" : { ( None , u"<STR_LIT>" ) : self . encoding } } <EOL> while pending : <EOL> yield pending . pop ( <NUM_LIT:0> ) <EOL> meta_found = True <EOL> state = "<STR_LIT>" <EOL> if state == "<STR_LIT>" : <EOL> pending . append ( token ) <EOL> else : <EOL> yield token </s>
