'Constructor.  Read multipart/* until last part.
Arguments, all optional:
fp              : file pointer; default: sys.stdin
(not used when the request method is GET)
headers         : header dictionary-like object; default:
taken from environ as per CGI spec
outerboundary   : terminating multipart boundary
(for internal use only)
environ         : environment dictionary; default: os.environ
keep_blank_values: flag indicating whether blank values in
percent-encoded forms should be treated as blank strings.
A true value indicates that blanks should be retained as
blank strings.  The default false value indicates that
blank values are to be ignored and treated as if they were
not included.
strict_parsing: flag indicating what to do with parsing errors.
If false (the default), errors are silently ignored.
If true, errors raise a ValueError exception.'

def __init__(self, fp=None, headers=None, outerboundary='', environ=os.environ, keep_blank_values=0, strict_parsing=0):

    method = 'GET'
    self.keep_blank_values = keep_blank_values
    self.strict_parsing = strict_parsing
    if ('REQUEST_METHOD' in environ):
        method = environ['REQUEST_METHOD'].upper()
    self.qs_on_post = None
    if ((method == 'GET') or (method == 'HEAD')):
        if ('QUERY_STRING' in environ):
            qs = environ['QUERY_STRING']
        elif sys.argv[1:]:
            qs = sys.argv[1]
        else:
            qs = ''
        fp = StringIO(qs)
        if (headers is None):
            headers = {'content-type': 'application/x-www-form-urlencoded'}
    if (headers is None):
        headers = {}
        if (method == 'POST'):
            headers['content-type'] = 'application/x-www-form-urlencoded'
        if ('CONTENT_TYPE' in environ):
            headers['content-type'] = environ['CONTENT_TYPE']
        if ('QUERY_STRING' in environ):
            self.qs_on_post = environ['QUERY_STRING']
        if ('CONTENT_LENGTH' in environ):
            headers['content-length'] = environ['CONTENT_LENGTH']
    self.fp = (fp or sys.stdin)
    self.headers = headers
    self.outerboundary = outerboundary
    (cdisp, pdict) = ('', {})
    if ('content-disposition' in self.headers):
        (cdisp, pdict) = parse_header(self.headers['content-disposition'])
    self.disposition = cdisp
    self.disposition_options = pdict
    self.name = None
    if ('name' in pdict):
        self.name = pdict['name']
    self.filename = None
    if ('filename' in pdict):
        self.filename = pdict['filename']
    if ('content-type' in self.headers):
        (ctype, pdict) = parse_header(self.headers['content-type'])
    elif (self.outerboundary or (method != 'POST')):
        (ctype, pdict) = ('text/plain', {})
    else:
        (ctype, pdict) = ('application/x-www-form-urlencoded', {})
    self.type = ctype
    self.type_options = pdict
    self.innerboundary = ''
    if ('boundary' in pdict):
        self.innerboundary = pdict['boundary']
    clen = (-1)
    if ('content-length' in self.headers):
        try:
            clen = int(self.headers['content-length'])
        except ValueError:
            pass
        if (maxlen and (clen > maxlen)):
            raise ValueError, 'Maximum    content    length    exceeded'
    self.length = clen
    self.list = self.file = None
    self.done = 0
    if (ctype == 'application/x-www-form-urlencoded'):
        self.read_urlencoded()
    elif (ctype[:10] == 'multipart/'):
        self.read_multi(environ, keep_blank_values, strict_parsing)
    else:
        self.read_single()
