<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> from __future__ import division <EOL> from __future__ import absolute_import <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> import sys <EOL> from io import StringIO <EOL> def walk ( self ) : <EOL> """<STR_LIT>""" <EOL> yield self <EOL> if self . is_multipart ( ) : <EOL> for subpart in self . get_payload ( ) : <EOL> for subsubpart in subpart . walk ( ) : <EOL> yield subsubpart <EOL> def body_line_iterator ( msg , decode = False ) : <EOL> """<STR_LIT>""" <EOL> for subpart in msg . walk ( ) : <EOL> payload = subpart . get_payload ( decode = decode ) <EOL> if isinstance ( payload , str ) : <EOL> for line in StringIO ( payload ) : <EOL> yield line <EOL> def typed_subpart_iterator ( msg , maintype = '<STR_LIT:text>' , subtype = None ) : <EOL> """<STR_LIT>""" <EOL> for subpart in msg . walk ( ) : <EOL> if subpart . get_content_maintype ( ) == maintype : <EOL> if subtype is None or subpart . get_content_subtype ( ) == subtype : <EOL> yield subpart <EOL> def _structure ( msg , fp = None , level = <NUM_LIT:0> , include_default = False ) : <EOL> """<STR_LIT>""" <EOL> if fp is None : <EOL> fp = sys . stdout <EOL> tab = '<STR_LIT:U+0020>' * ( level * <NUM_LIT:4> ) <EOL> print ( tab + msg . get_content_type ( ) , end = '<STR_LIT>' , file = fp ) <EOL> if include_default : <EOL> print ( '<STR_LIT>' % msg . get_default_type ( ) , file = fp ) <EOL> else : <EOL> print ( file = fp ) <EOL> if msg . is_multipart ( ) : <EOL> for subpart in msg . get_payload ( ) : <EOL> _structure ( subpart , fp , level + <NUM_LIT:1> , include_default ) </s>
