<s> """<STR_LIT>""" <EOL> __version__ = "<STR_LIT>" <EOL> from operator import attrgetter <EOL> import sys <EOL> import os <EOL> import UserDict <EOL> import urlparse <EOL> from warnings import filterwarnings , catch_warnings , warn <EOL> with catch_warnings ( ) : <EOL> if sys . py3kwarning : <EOL> filterwarnings ( "<STR_LIT:ignore>" , "<STR_LIT>" , <EOL> DeprecationWarning ) <EOL> filterwarnings ( "<STR_LIT:ignore>" , "<STR_LIT>" , <EOL> DeprecationWarning ) <EOL> import mimetools <EOL> import rfc822 <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> logfile = "<STR_LIT>" <EOL> logfp = None <EOL> def initlog ( * allargs ) : <EOL> """<STR_LIT>""" <EOL> global logfp , log <EOL> if logfile and not logfp : <EOL> try : <EOL> logfp = open ( logfile , "<STR_LIT:a>" ) <EOL> except IOError : <EOL> pass <EOL> if not logfp : <EOL> log = nolog <EOL> else : <EOL> log = dolog <EOL> log ( * allargs ) <EOL> def dolog ( fmt , * args ) : <EOL> """<STR_LIT>""" <EOL> logfp . write ( fmt % args + "<STR_LIT:\n>" ) <EOL> def nolog ( * allargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> log = initlog <EOL> maxlen = <NUM_LIT:0> <EOL> def parse ( fp = None , environ = os . environ , keep_blank_values = <NUM_LIT:0> , strict_parsing = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if fp is None : <EOL> fp = sys . stdin <EOL> if not '<STR_LIT>' in environ : <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT:GET>' <EOL> if environ [ '<STR_LIT>' ] == '<STR_LIT:POST>' : <EOL> ctype , pdict = parse_header ( environ [ '<STR_LIT>' ] ) <EOL> if ctype == '<STR_LIT>' : <EOL> return parse_multipart ( fp , pdict ) <EOL> elif ctype == '<STR_LIT>' : <EOL> clength = int ( environ [ '<STR_LIT>' ] ) <EOL> if maxlen and clength > maxlen : <EOL> raise ValueError , '<STR_LIT>' <EOL> qs = fp . read ( clength ) <EOL> else : <EOL> qs = '<STR_LIT>' <EOL> if '<STR_LIT>' in environ : <EOL> if qs : qs = qs + '<STR_LIT:&>' <EOL> qs = qs + environ [ '<STR_LIT>' ] <EOL> elif sys . argv [ <NUM_LIT:1> : ] : <EOL> if qs : qs = qs + '<STR_LIT:&>' <EOL> qs = qs + sys . argv [ <NUM_LIT:1> ] <EOL> environ [ '<STR_LIT>' ] = qs <EOL> elif '<STR_LIT>' in environ : <EOL> qs = environ [ '<STR_LIT>' ] <EOL> else : <EOL> if sys . argv [ <NUM_LIT:1> : ] : <EOL> qs = sys . argv [ <NUM_LIT:1> ] <EOL> else : <EOL> qs = "<STR_LIT>" <EOL> environ [ '<STR_LIT>' ] = qs <EOL> return urlparse . parse_qs ( qs , keep_blank_values , strict_parsing ) <EOL> def parse_qs ( qs , keep_blank_values = <NUM_LIT:0> , strict_parsing = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> warn ( "<STR_LIT>" , <EOL> PendingDeprecationWarning , <NUM_LIT:2> ) <EOL> return urlparse . parse_qs ( qs , keep_blank_values , strict_parsing ) <EOL> def parse_qsl ( qs , keep_blank_values = <NUM_LIT:0> , strict_parsing = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> warn ( "<STR_LIT>" , <EOL> PendingDeprecationWarning , <NUM_LIT:2> ) <EOL> return urlparse . parse_qsl ( qs , keep_blank_values , strict_parsing ) <EOL> def parse_multipart ( fp , pdict ) : <EOL> """<STR_LIT>""" <EOL> boundary = "<STR_LIT>" <EOL> if '<STR_LIT>' in pdict : <EOL> boundary = pdict [ '<STR_LIT>' ] <EOL> if not valid_boundary ( boundary ) : <EOL> raise ValueError , ( '<STR_LIT>' <EOL> % ( boundary , ) ) <EOL> nextpart = "<STR_LIT>" + boundary <EOL> lastpart = "<STR_LIT>" + boundary + "<STR_LIT>" <EOL> partdict = { } <EOL> terminator = "<STR_LIT>" <EOL> while terminator != lastpart : <EOL> bytes = - <NUM_LIT:1> <EOL> data = None <EOL> if terminator : <EOL> headers = mimetools . Message ( fp ) <EOL> clength = headers . getheader ( '<STR_LIT>' ) <EOL> if clength : <EOL> try : <EOL> bytes = int ( clength ) <EOL> except ValueError : <EOL> pass <EOL> if bytes > <NUM_LIT:0> : <EOL> if maxlen and bytes > maxlen : <EOL> raise ValueError , '<STR_LIT>' <EOL> data = fp . read ( bytes ) <EOL> else : <EOL> data = "<STR_LIT>" <EOL> lines = [ ] <EOL> while <NUM_LIT:1> : <EOL> line = fp . readline ( ) <EOL> if not line : <EOL> terminator = lastpart <EOL> break <EOL> if line [ : <NUM_LIT:2> ] == "<STR_LIT>" : <EOL> terminator = line . strip ( ) <EOL> if terminator in ( nextpart , lastpart ) : <EOL> break <EOL> lines . append ( line ) <EOL> if data is None : <EOL> continue <EOL> if bytes < <NUM_LIT:0> : <EOL> if lines : <EOL> line = lines [ - <NUM_LIT:1> ] <EOL> if line [ - <NUM_LIT:2> : ] == "<STR_LIT:\r\n>" : <EOL> line = line [ : - <NUM_LIT:2> ] <EOL> elif line [ - <NUM_LIT:1> : ] == "<STR_LIT:\n>" : <EOL> line = line [ : - <NUM_LIT:1> ] <EOL> lines [ - <NUM_LIT:1> ] = line <EOL> data = "<STR_LIT>" . join ( lines ) <EOL> line = headers [ '<STR_LIT>' ] <EOL> if not line : <EOL> continue <EOL> key , params = parse_header ( line ) <EOL> if key != '<STR_LIT>' : <EOL> continue <EOL> if '<STR_LIT:name>' in params : <EOL> name = params [ '<STR_LIT:name>' ] <EOL> else : <EOL> continue <EOL> if name in partdict : <EOL> partdict [ name ] . append ( data ) <EOL> else : <EOL> partdict [ name ] = [ data ] <EOL> return partdict <EOL> def _parseparam ( s ) : <EOL> while s [ : <NUM_LIT:1> ] == '<STR_LIT:;>' : <EOL> s = s [ <NUM_LIT:1> : ] <EOL> end = s . find ( '<STR_LIT:;>' ) <EOL> while end > <NUM_LIT:0> and ( s . count ( '<STR_LIT:">' , <NUM_LIT:0> , end ) - s . count ( '<STR_LIT>' , <NUM_LIT:0> , end ) ) % <NUM_LIT:2> : <EOL> end = s . find ( '<STR_LIT:;>' , end + <NUM_LIT:1> ) <EOL> if end < <NUM_LIT:0> : <EOL> end = len ( s ) <EOL> f = s [ : end ] <EOL> yield f . strip ( ) <EOL> s = s [ end : ] <EOL> def parse_header ( line ) : <EOL> """<STR_LIT>""" <EOL> parts = _parseparam ( '<STR_LIT:;>' + line ) <EOL> key = parts . next ( ) <EOL> pdict = { } <EOL> for p in parts : <EOL> i = p . find ( '<STR_LIT:=>' ) <EOL> if i >= <NUM_LIT:0> : <EOL> name = p [ : i ] . strip ( ) . lower ( ) <EOL> value = p [ i + <NUM_LIT:1> : ] . strip ( ) <EOL> if len ( value ) >= <NUM_LIT:2> and value [ <NUM_LIT:0> ] == value [ - <NUM_LIT:1> ] == '<STR_LIT:">' : <EOL> value = value [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> value = value . replace ( '<STR_LIT>' , '<STR_LIT:\\>' ) . replace ( '<STR_LIT>' , '<STR_LIT:">' ) <EOL> pdict [ name ] = value <EOL> return key , pdict <EOL> class MiniFieldStorage : <EOL> """<STR_LIT>""" <EOL> filename = None <EOL> list = None <EOL> type = None <EOL> file = None <EOL> type_options = { } <EOL> disposition = None <EOL> disposition_options = { } <EOL> headers = { } <EOL> def __init__ ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> self . value = value <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( self . name , self . value ) <EOL> class FieldStorage : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fp = None , headers = None , outerboundary = "<STR_LIT>" , <EOL> environ = os . environ , keep_blank_values = <NUM_LIT:0> , strict_parsing = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> method = '<STR_LIT:GET>' <EOL> self . keep_blank_values = keep_blank_values <EOL> self . strict_parsing = strict_parsing <EOL> if '<STR_LIT>' in environ : <EOL> method = environ [ '<STR_LIT>' ] . upper ( ) <EOL> self . qs_on_post = None <EOL> if method == '<STR_LIT:GET>' or method == '<STR_LIT>' : <EOL> if '<STR_LIT>' in environ : <EOL> qs = environ [ '<STR_LIT>' ] <EOL> elif sys . argv [ <NUM_LIT:1> : ] : <EOL> qs = sys . argv [ <NUM_LIT:1> ] <EOL> else : <EOL> qs = "<STR_LIT>" <EOL> fp = StringIO ( qs ) <EOL> if headers is None : <EOL> headers = { '<STR_LIT>' : <EOL> "<STR_LIT>" } <EOL> if headers is None : <EOL> headers = { } <EOL> if method == '<STR_LIT:POST>' : <EOL> headers [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> if '<STR_LIT>' in environ : <EOL> headers [ '<STR_LIT>' ] = environ [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in environ : <EOL> self . qs_on_post = environ [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in environ : <EOL> headers [ '<STR_LIT>' ] = environ [ '<STR_LIT>' ] <EOL> self . fp = fp or sys . stdin <EOL> self . headers = headers <EOL> self . outerboundary = outerboundary <EOL> cdisp , pdict = "<STR_LIT>" , { } <EOL> if '<STR_LIT>' in self . headers : <EOL> cdisp , pdict = parse_header ( self . headers [ '<STR_LIT>' ] ) <EOL> self . disposition = cdisp <EOL> self . disposition_options = pdict <EOL> self . name = None <EOL> if '<STR_LIT:name>' in pdict : <EOL> self . name = pdict [ '<STR_LIT:name>' ] <EOL> self . filename = None <EOL> if '<STR_LIT:filename>' in pdict : <EOL> self . filename = pdict [ '<STR_LIT:filename>' ] <EOL> if '<STR_LIT>' in self . headers : <EOL> ctype , pdict = parse_header ( self . headers [ '<STR_LIT>' ] ) <EOL> elif self . outerboundary or method != '<STR_LIT:POST>' : <EOL> ctype , pdict = "<STR_LIT>" , { } <EOL> else : <EOL> ctype , pdict = '<STR_LIT>' , { } <EOL> self . type = ctype <EOL> self . type_options = pdict <EOL> self . innerboundary = "<STR_LIT>" <EOL> if '<STR_LIT>' in pdict : <EOL> self . innerboundary = pdict [ '<STR_LIT>' ] <EOL> clen = - <NUM_LIT:1> <EOL> if '<STR_LIT>' in self . headers : <EOL> try : <EOL> clen = int ( self . headers [ '<STR_LIT>' ] ) <EOL> except ValueError : <EOL> pass <EOL> if maxlen and clen > maxlen : <EOL> raise ValueError , '<STR_LIT>' <EOL> self . length = clen <EOL> self . list = self . file = None <EOL> self . done = <NUM_LIT:0> <EOL> if ctype == '<STR_LIT>' : <EOL> self . read_urlencoded ( ) <EOL> elif ctype [ : <NUM_LIT:10> ] == '<STR_LIT>' : <EOL> self . read_multi ( environ , keep_blank_values , strict_parsing ) <EOL> else : <EOL> self . read_single ( ) <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( <EOL> self . name , self . filename , self . value ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . keys ( ) ) <EOL> def __getattr__ ( self , name ) : <EOL> if name != '<STR_LIT:value>' : <EOL> raise AttributeError , name <EOL> if self . file : <EOL> self . file . seek ( <NUM_LIT:0> ) <EOL> value = self . file . read ( ) <EOL> self . file . seek ( <NUM_LIT:0> ) <EOL> elif self . list is not None : <EOL> value = self . list <EOL> else : <EOL> value = None <EOL> return value <EOL> def __getitem__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if self . list is None : <EOL> raise TypeError , "<STR_LIT>" <EOL> found = [ ] <EOL> for item in self . list : <EOL> if item . name == key : found . append ( item ) <EOL> if not found : <EOL> raise KeyError , key <EOL> if len ( found ) == <NUM_LIT:1> : <EOL> return found [ <NUM_LIT:0> ] <EOL> else : <EOL> return found <EOL> def getvalue ( self , key , default = None ) : <EOL> """<STR_LIT>""" <EOL> if key in self : <EOL> value = self [ key ] <EOL> if type ( value ) is type ( [ ] ) : <EOL> return map ( attrgetter ( '<STR_LIT:value>' ) , value ) <EOL> else : <EOL> return value . value <EOL> else : <EOL> return default <EOL> def getfirst ( self , key , default = None ) : <EOL> """<STR_LIT>""" <EOL> if key in self : <EOL> value = self [ key ] <EOL> if type ( value ) is type ( [ ] ) : <EOL> return value [ <NUM_LIT:0> ] . value <EOL> else : <EOL> return value . value <EOL> else : <EOL> return default <EOL> def getlist ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if key in self : <EOL> value = self [ key ] <EOL> if type ( value ) is type ( [ ] ) : <EOL> return map ( attrgetter ( '<STR_LIT:value>' ) , value ) <EOL> else : <EOL> return [ value . value ] <EOL> else : <EOL> return [ ] <EOL> def keys ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . list is None : <EOL> raise TypeError , "<STR_LIT>" <EOL> return list ( set ( item . name for item in self . list ) ) <EOL> def has_key ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if self . list is None : <EOL> raise TypeError , "<STR_LIT>" <EOL> return any ( item . name == key for item in self . list ) <EOL> def __contains__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> if self . list is None : <EOL> raise TypeError , "<STR_LIT>" <EOL> return any ( item . name == key for item in self . list ) <EOL> def __len__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . keys ( ) ) <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . list ) <EOL> def read_urlencoded ( self ) : <EOL> """<STR_LIT>""" <EOL> qs = self . fp . read ( self . length ) <EOL> if self . qs_on_post : <EOL> qs += '<STR_LIT:&>' + self . qs_on_post <EOL> self . list = list = [ ] <EOL> for key , value in urlparse . parse_qsl ( qs , self . keep_blank_values , <EOL> self . strict_parsing ) : <EOL> list . append ( MiniFieldStorage ( key , value ) ) <EOL> self . skip_lines ( ) <EOL> FieldStorageClass = None <EOL> def read_multi ( self , environ , keep_blank_values , strict_parsing ) : <EOL> """<STR_LIT>""" <EOL> ib = self . innerboundary <EOL> if not valid_boundary ( ib ) : <EOL> raise ValueError , '<STR_LIT>' % ( ib , ) <EOL> self . list = [ ] <EOL> if self . qs_on_post : <EOL> for key , value in urlparse . parse_qsl ( self . qs_on_post , <EOL> self . keep_blank_values , self . strict_parsing ) : <EOL> self . list . append ( MiniFieldStorage ( key , value ) ) <EOL> FieldStorageClass = None <EOL> klass = self . FieldStorageClass or self . __class__ <EOL> part = klass ( self . fp , { } , ib , <EOL> environ , keep_blank_values , strict_parsing ) <EOL> while not part . done : <EOL> headers = rfc822 . Message ( self . fp ) <EOL> part = klass ( self . fp , headers , ib , <EOL> environ , keep_blank_values , strict_parsing ) <EOL> self . list . append ( part ) <EOL> self . skip_lines ( ) <EOL> def read_single ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . length >= <NUM_LIT:0> : <EOL> self . read_binary ( ) <EOL> self . skip_lines ( ) <EOL> else : <EOL> self . read_lines ( ) <EOL> self . file . seek ( <NUM_LIT:0> ) <EOL> bufsize = <NUM_LIT:8> * <NUM_LIT> <EOL> def read_binary ( self ) : <EOL> """<STR_LIT>""" <EOL> self . file = self . make_file ( '<STR_LIT:b>' ) <EOL> todo = self . length <EOL> if todo >= <NUM_LIT:0> : <EOL> while todo > <NUM_LIT:0> : <EOL> data = self . fp . read ( min ( todo , self . bufsize ) ) <EOL> if not data : <EOL> self . done = - <NUM_LIT:1> <EOL> break <EOL> self . file . write ( data ) <EOL> todo = todo - len ( data ) <EOL> def read_lines ( self ) : <EOL> """<STR_LIT>""" <EOL> self . file = self . __file = StringIO ( ) <EOL> if self . outerboundary : <EOL> self . read_lines_to_outerboundary ( ) <EOL> else : <EOL> self . read_lines_to_eof ( ) <EOL> def __write ( self , line ) : <EOL> if self . __file is not None : <EOL> if self . __file . tell ( ) + len ( line ) > <NUM_LIT:1000> : <EOL> self . file = self . make_file ( '<STR_LIT>' ) <EOL> self . file . write ( self . __file . getvalue ( ) ) <EOL> self . __file = None <EOL> self . file . write ( line ) <EOL> def read_lines_to_eof ( self ) : <EOL> """<STR_LIT>""" <EOL> while <NUM_LIT:1> : <EOL> line = self . fp . readline ( <NUM_LIT:1> << <NUM_LIT:16> ) <EOL> if not line : <EOL> self . done = - <NUM_LIT:1> <EOL> break <EOL> self . __write ( line ) <EOL> def read_lines_to_outerboundary ( self ) : <EOL> """<STR_LIT>""" <EOL> next = "<STR_LIT>" + self . outerboundary <EOL> last = next + "<STR_LIT>" <EOL> delim = "<STR_LIT>" <EOL> last_line_lfend = True <EOL> while <NUM_LIT:1> : <EOL> line = self . fp . readline ( <NUM_LIT:1> << <NUM_LIT:16> ) <EOL> if not line : <EOL> self . done = - <NUM_LIT:1> <EOL> break <EOL> if line [ : <NUM_LIT:2> ] == "<STR_LIT>" and last_line_lfend : <EOL> strippedline = line . strip ( ) <EOL> if strippedline == next : <EOL> break <EOL> if strippedline == last : <EOL> self . done = <NUM_LIT:1> <EOL> break <EOL> odelim = delim <EOL> if line [ - <NUM_LIT:2> : ] == "<STR_LIT:\r\n>" : <EOL> delim = "<STR_LIT:\r\n>" <EOL> line = line [ : - <NUM_LIT:2> ] <EOL> last_line_lfend = True <EOL> elif line [ - <NUM_LIT:1> ] == "<STR_LIT:\n>" : <EOL> delim = "<STR_LIT:\n>" <EOL> line = line [ : - <NUM_LIT:1> ] <EOL> last_line_lfend = True <EOL> else : <EOL> delim = "<STR_LIT>" <EOL> last_line_lfend = False <EOL> self . __write ( odelim + line ) <EOL> def skip_lines ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . outerboundary or self . done : <EOL> return <EOL> next = "<STR_LIT>" + self . outerboundary <EOL> last = next + "<STR_LIT>" <EOL> last_line_lfend = True <EOL> while <NUM_LIT:1> : <EOL> line = self . fp . readline ( <NUM_LIT:1> << <NUM_LIT:16> ) <EOL> if not line : <EOL> self . done = - <NUM_LIT:1> <EOL> break <EOL> if line [ : <NUM_LIT:2> ] == "<STR_LIT>" and last_line_lfend : <EOL> strippedline = line . strip ( ) <EOL> if strippedline == next : <EOL> break <EOL> if strippedline == last : <EOL> self . done = <NUM_LIT:1> <EOL> break <EOL> last_line_lfend = line . endswith ( '<STR_LIT:\n>' ) <EOL> def make_file ( self , binary = None ) : <EOL> """<STR_LIT>""" <EOL> import tempfile <EOL> return tempfile . TemporaryFile ( "<STR_LIT>" ) <EOL> class FormContentDict ( UserDict . UserDict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , environ = os . environ , keep_blank_values = <NUM_LIT:0> , strict_parsing = <NUM_LIT:0> ) : <EOL> self . dict = self . data = parse ( environ = environ , <EOL> keep_blank_values = keep_blank_values , <EOL> strict_parsing = strict_parsing ) <EOL> self . query_string = environ [ '<STR_LIT>' ] <EOL> class SvFormContentDict ( FormContentDict ) : <EOL> """<STR_LIT>""" <EOL> def __getitem__ ( self , key ) : <EOL> if len ( self . dict [ key ] ) > <NUM_LIT:1> : <EOL> raise IndexError , '<STR_LIT>' <EOL> return self . dict [ key ] [ <NUM_LIT:0> ] <EOL> def getlist ( self , key ) : <EOL> return self . dict [ key ] <EOL> def values ( self ) : <EOL> result = [ ] <EOL> for value in self . dict . values ( ) : <EOL> if len ( value ) == <NUM_LIT:1> : <EOL> result . append ( value [ <NUM_LIT:0> ] ) <EOL> else : result . append ( value ) <EOL> return result <EOL> def items ( self ) : <EOL> result = [ ] <EOL> for key , value in self . dict . items ( ) : <EOL> if len ( value ) == <NUM_LIT:1> : <EOL> result . append ( ( key , value [ <NUM_LIT:0> ] ) ) <EOL> else : result . append ( ( key , value ) ) <EOL> return result <EOL> class InterpFormContentDict ( SvFormContentDict ) : <EOL> """<STR_LIT>""" <EOL> def __getitem__ ( self , key ) : <EOL> v = SvFormContentDict . __getitem__ ( self , key ) <EOL> if v [ <NUM_LIT:0> ] in '<STR_LIT>' : <EOL> try : return int ( v ) <EOL> except ValueError : <EOL> try : return float ( v ) <EOL> except ValueError : pass <EOL> return v . strip ( ) <EOL> def values ( self ) : <EOL> result = [ ] <EOL> for key in self . keys ( ) : <EOL> try : <EOL> result . append ( self [ key ] ) <EOL> except IndexError : <EOL> result . append ( self . dict [ key ] ) <EOL> return result <EOL> def items ( self ) : <EOL> result = [ ] <EOL> for key in self . keys ( ) : <EOL> try : <EOL> result . append ( ( key , self [ key ] ) ) <EOL> except IndexError : <EOL> result . append ( ( key , self . dict [ key ] ) ) <EOL> return result <EOL> class FormContent ( FormContentDict ) : <EOL> """<STR_LIT>""" <EOL> def values ( self , key ) : <EOL> if key in self . dict : return self . dict [ key ] <EOL> else : return None <EOL> def indexed_value ( self , key , location ) : <EOL> if key in self . dict : <EOL> if len ( self . dict [ key ] ) > location : <EOL> return self . dict [ key ] [ location ] <EOL> else : return None <EOL> else : return None <EOL> def value ( self , key ) : <EOL> if key in self . dict : return self . dict [ key ] [ <NUM_LIT:0> ] <EOL> else : return None <EOL> def length ( self , key ) : <EOL> return len ( self . dict [ key ] ) <EOL> def stripped ( self , key ) : <EOL> if key in self . dict : return self . dict [ key ] [ <NUM_LIT:0> ] . strip ( ) <EOL> else : return None <EOL> def pars ( self ) : <EOL> return self . dict <EOL> def test ( environ = os . environ ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> print <EOL> sys . stderr = sys . stdout <EOL> try : <EOL> form = FieldStorage ( ) <EOL> print_directory ( ) <EOL> print_arguments ( ) <EOL> print_form ( form ) <EOL> print_environ ( environ ) <EOL> print_environ_usage ( ) <EOL> def f ( ) : <EOL> exec "<STR_LIT>" <EOL> def g ( f = f ) : <EOL> f ( ) <EOL> print "<STR_LIT>" <EOL> g ( ) <EOL> except : <EOL> print_exception ( ) <EOL> print "<STR_LIT>" <EOL> global maxlen <EOL> maxlen = <NUM_LIT:50> <EOL> try : <EOL> form = FieldStorage ( ) <EOL> print_directory ( ) <EOL> print_arguments ( ) <EOL> print_form ( form ) <EOL> print_environ ( environ ) <EOL> except : <EOL> print_exception ( ) <EOL> def print_exception ( type = None , value = None , tb = None , limit = None ) : <EOL> if type is None : <EOL> type , value , tb = sys . exc_info ( ) <EOL> import traceback <EOL> print <EOL> print "<STR_LIT>" <EOL> list = traceback . format_tb ( tb , limit ) + traceback . format_exception_only ( type , value ) <EOL> print "<STR_LIT>" % ( <EOL> escape ( "<STR_LIT>" . join ( list [ : - <NUM_LIT:1> ] ) ) , <EOL> escape ( list [ - <NUM_LIT:1> ] ) , <EOL> ) <EOL> del tb <EOL> def print_environ ( environ = os . environ ) : <EOL> """<STR_LIT>""" <EOL> keys = environ . keys ( ) <EOL> keys . sort ( ) <EOL> print <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> for key in keys : <EOL> print "<STR_LIT>" , escape ( key ) , "<STR_LIT>" , escape ( environ [ key ] ) <EOL> print "<STR_LIT>" <EOL> print <EOL> def print_form ( form ) : <EOL> """<STR_LIT>""" <EOL> keys = form . keys ( ) <EOL> keys . sort ( ) <EOL> print <EOL> print "<STR_LIT>" <EOL> if not keys : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> for key in keys : <EOL> print "<STR_LIT>" + escape ( key ) + "<STR_LIT::>" , <EOL> value = form [ key ] <EOL> print "<STR_LIT>" + escape ( repr ( type ( value ) ) ) + "<STR_LIT>" <EOL> print "<STR_LIT>" + escape ( repr ( value ) ) <EOL> print "<STR_LIT>" <EOL> print <EOL> def print_directory ( ) : <EOL> """<STR_LIT>""" <EOL> print <EOL> print "<STR_LIT>" <EOL> try : <EOL> pwd = os . getcwd ( ) <EOL> except os . error , msg : <EOL> print "<STR_LIT>" , escape ( str ( msg ) ) <EOL> else : <EOL> print escape ( pwd ) <EOL> print <EOL> def print_arguments ( ) : <EOL> print <EOL> print "<STR_LIT>" <EOL> print <EOL> print sys . argv <EOL> print <EOL> def print_environ_usage ( ) : <EOL> """<STR_LIT>""" <EOL> print """<STR_LIT>""" <EOL> def escape ( s , quote = None ) : <EOL> '''<STR_LIT>''' <EOL> s = s . replace ( "<STR_LIT:&>" , "<STR_LIT>" ) <EOL> s = s . replace ( "<STR_LIT:<>" , "<STR_LIT>" ) <EOL> s = s . replace ( "<STR_LIT:>>" , "<STR_LIT>" ) <EOL> if quote : <EOL> s = s . replace ( '<STR_LIT:">' , "<STR_LIT>" ) <EOL> return s <EOL> def valid_boundary ( s , _vb_pattern = "<STR_LIT>" ) : <EOL> import re <EOL> return re . match ( _vb_pattern , s ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test ( ) </s>
