<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import tempfile <EOL> from warnings import filterwarnings , catch_warnings <EOL> with catch_warnings ( ) : <EOL> if sys . py3kwarning : <EOL> filterwarnings ( "<STR_LIT:ignore>" , "<STR_LIT>" , DeprecationWarning ) <EOL> import rfc822 <EOL> from warnings import warnpy3k <EOL> warnpy3k ( "<STR_LIT>" , <EOL> stacklevel = <NUM_LIT:2> ) <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> class Message ( rfc822 . Message ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fp , seekable = <NUM_LIT:1> ) : <EOL> rfc822 . Message . __init__ ( self , fp , seekable ) <EOL> self . encodingheader = self . getheader ( '<STR_LIT>' ) <EOL> self . typeheader = self . getheader ( '<STR_LIT>' ) <EOL> self . parsetype ( ) <EOL> self . parseplist ( ) <EOL> def parsetype ( self ) : <EOL> str = self . typeheader <EOL> if str is None : <EOL> str = '<STR_LIT>' <EOL> if '<STR_LIT:;>' in str : <EOL> i = str . index ( '<STR_LIT:;>' ) <EOL> self . plisttext = str [ i : ] <EOL> str = str [ : i ] <EOL> else : <EOL> self . plisttext = '<STR_LIT>' <EOL> fields = str . split ( '<STR_LIT:/>' ) <EOL> for i in range ( len ( fields ) ) : <EOL> fields [ i ] = fields [ i ] . strip ( ) . lower ( ) <EOL> self . type = '<STR_LIT:/>' . join ( fields ) <EOL> self . maintype = fields [ <NUM_LIT:0> ] <EOL> self . subtype = '<STR_LIT:/>' . join ( fields [ <NUM_LIT:1> : ] ) <EOL> def parseplist ( self ) : <EOL> str = self . plisttext <EOL> self . plist = [ ] <EOL> while str [ : <NUM_LIT:1> ] == '<STR_LIT:;>' : <EOL> str = str [ <NUM_LIT:1> : ] <EOL> if '<STR_LIT:;>' in str : <EOL> end = str . index ( '<STR_LIT:;>' ) <EOL> else : <EOL> end = len ( str ) <EOL> f = str [ : end ] <EOL> if '<STR_LIT:=>' in f : <EOL> i = f . index ( '<STR_LIT:=>' ) <EOL> f = f [ : i ] . strip ( ) . lower ( ) + '<STR_LIT:=>' + f [ i + <NUM_LIT:1> : ] . strip ( ) <EOL> self . plist . append ( f . strip ( ) ) <EOL> str = str [ end : ] <EOL> def getplist ( self ) : <EOL> return self . plist <EOL> def getparam ( self , name ) : <EOL> name = name . lower ( ) + '<STR_LIT:=>' <EOL> n = len ( name ) <EOL> for p in self . plist : <EOL> if p [ : n ] == name : <EOL> return rfc822 . unquote ( p [ n : ] ) <EOL> return None <EOL> def getparamnames ( self ) : <EOL> result = [ ] <EOL> for p in self . plist : <EOL> i = p . find ( '<STR_LIT:=>' ) <EOL> if i >= <NUM_LIT:0> : <EOL> result . append ( p [ : i ] . lower ( ) ) <EOL> return result <EOL> def getencoding ( self ) : <EOL> if self . encodingheader is None : <EOL> return '<STR_LIT>' <EOL> return self . encodingheader . lower ( ) <EOL> def gettype ( self ) : <EOL> return self . type <EOL> def getmaintype ( self ) : <EOL> return self . maintype <EOL> def getsubtype ( self ) : <EOL> return self . subtype <EOL> try : <EOL> import thread <EOL> except ImportError : <EOL> import dummy_thread as thread <EOL> _counter_lock = thread . allocate_lock ( ) <EOL> del thread <EOL> _counter = <NUM_LIT:0> <EOL> def _get_next_counter ( ) : <EOL> global _counter <EOL> _counter_lock . acquire ( ) <EOL> _counter += <NUM_LIT:1> <EOL> result = _counter <EOL> _counter_lock . release ( ) <EOL> return result <EOL> _prefix = None <EOL> def choose_boundary ( ) : <EOL> """<STR_LIT>""" <EOL> global _prefix <EOL> import time <EOL> if _prefix is None : <EOL> import socket <EOL> try : <EOL> hostid = socket . gethostbyname ( socket . gethostname ( ) ) <EOL> except socket . gaierror : <EOL> hostid = '<STR_LIT:127.0.0.1>' <EOL> try : <EOL> uid = repr ( os . getuid ( ) ) <EOL> except AttributeError : <EOL> uid = '<STR_LIT:1>' <EOL> try : <EOL> pid = repr ( os . getpid ( ) ) <EOL> except AttributeError : <EOL> pid = '<STR_LIT:1>' <EOL> _prefix = hostid + '<STR_LIT:.>' + uid + '<STR_LIT:.>' + pid <EOL> return "<STR_LIT>" % ( _prefix , time . time ( ) , _get_next_counter ( ) ) <EOL> def decode ( input , output , encoding ) : <EOL> """<STR_LIT>""" <EOL> if encoding == '<STR_LIT>' : <EOL> import base64 <EOL> return base64 . decode ( input , output ) <EOL> if encoding == '<STR_LIT>' : <EOL> import quopri <EOL> return quopri . decode ( input , output ) <EOL> if encoding in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> import uu <EOL> return uu . decode ( input , output ) <EOL> if encoding in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return output . write ( input . read ( ) ) <EOL> if encoding in decodetab : <EOL> pipethrough ( input , decodetab [ encoding ] , output ) <EOL> else : <EOL> raise ValueError , '<STR_LIT>' % encoding <EOL> def encode ( input , output , encoding ) : <EOL> """<STR_LIT>""" <EOL> if encoding == '<STR_LIT>' : <EOL> import base64 <EOL> return base64 . encode ( input , output ) <EOL> if encoding == '<STR_LIT>' : <EOL> import quopri <EOL> return quopri . encode ( input , output , <NUM_LIT:0> ) <EOL> if encoding in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> import uu <EOL> return uu . encode ( input , output ) <EOL> if encoding in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return output . write ( input . read ( ) ) <EOL> if encoding in encodetab : <EOL> pipethrough ( input , encodetab [ encoding ] , output ) <EOL> else : <EOL> raise ValueError , '<STR_LIT>' % encoding <EOL> uudecode_pipe = '''<STR_LIT>''' <EOL> decodetab = { <EOL> '<STR_LIT>' : uudecode_pipe , <EOL> '<STR_LIT>' : uudecode_pipe , <EOL> '<STR_LIT>' : uudecode_pipe , <EOL> '<STR_LIT>' : uudecode_pipe , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> encodetab = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def pipeto ( input , command ) : <EOL> pipe = os . popen ( command , '<STR_LIT:w>' ) <EOL> copyliteral ( input , pipe ) <EOL> pipe . close ( ) <EOL> def pipethrough ( input , command , output ) : <EOL> ( fd , tempname ) = tempfile . mkstemp ( ) <EOL> temp = os . fdopen ( fd , '<STR_LIT:w>' ) <EOL> copyliteral ( input , temp ) <EOL> temp . close ( ) <EOL> pipe = os . popen ( command + '<STR_LIT>' + tempname , '<STR_LIT:r>' ) <EOL> copybinary ( pipe , output ) <EOL> pipe . close ( ) <EOL> os . unlink ( tempname ) <EOL> def copyliteral ( input , output ) : <EOL> while <NUM_LIT:1> : <EOL> line = input . readline ( ) <EOL> if not line : break <EOL> output . write ( line ) <EOL> def copybinary ( input , output ) : <EOL> BUFSIZE = <NUM_LIT> <EOL> while <NUM_LIT:1> : <EOL> line = input . read ( BUFSIZE ) <EOL> if not line : break <EOL> output . write ( line ) </s>
