<s> """<STR_LIT>""" <EOL> class WSGIAdapter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , doc = None , writer = None ) : <EOL> if writer : <EOL> self . write = writer <EOL> self . _chunks = [ ] <EOL> self . length = <NUM_LIT:0> <EOL> if doc : <EOL> self . mimetype = doc . MIMETYPE <EOL> self . charset = doc . encoding <EOL> else : <EOL> self . mimetype = None <EOL> self . charset = None <EOL> def __iter__ ( self ) : <EOL> return iter ( self . _chunks ) <EOL> def __len__ ( self ) : <EOL> return self . length <EOL> def __del__ ( self ) : <EOL> self . close ( ) <EOL> def close ( self ) : <EOL> self . _chunks = [ ] <EOL> self . length = <NUM_LIT:0> <EOL> def write ( self , data ) : <EOL> data = data . encode ( self . charset ) <EOL> self . length += len ( data ) <EOL> self . _chunks . append ( data ) <EOL> def get_headers ( self ) : <EOL> if self . length : <EOL> rv = [ ( "<STR_LIT>" , str ( self . length ) ) ] <EOL> else : <EOL> rv = [ ] <EOL> if self . mimetype : <EOL> rv . append ( ( "<STR_LIT:Content-Type>" , "<STR_LIT>" % ( self . mimetype , self . charset ) ) ) <EOL> return rv <EOL> headers = property ( get_headers , None , None , "<STR_LIT>" ) <EOL> def get_iterator ( doc , writer = None , encoding = None ) : <EOL> """<STR_LIT>""" <EOL> it = WSGIAdapter ( mimetype = doc . MIMETYPE , writer = writer ) <EOL> doc . emit ( it , encoding ) <EOL> return it </s>
