title: How does cgi.FieldStorage store files?
body: <p>So I've been playing around with raw WSGI, cgi.FieldStorage and file uploads. And I just can't understand how it deals with file uploads. </p>
  
  <p>At first it seemed that it just stores the whole file in memory. And I thought hm, that should be easy to test - a big file should clog up the memory!.. And it didn't. Still, when I request the file, it's a string, not an iterator, file object or anything.</p>
  
  <p>I've tried reading the cgi module's source and found some things about temporary files, but it returns a freaking string, not a file(-like) object! So... how does it fscking work?!</p>
  
  <p>Here's the code I've used:</p>
  
  <pre><code>import cgi
  from wsgiref.simple_server import make_server
  
  def app(environ,start_response):
      start_response('200 OK',[('Content-Type','text/html')])
      output = """
      &lt;form action="" method="post" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="failas" /&gt;
      &lt;input type="submit" value="Varom" /&gt;
      &lt;/form&gt;
      """
      fs = cgi.FieldStorage(fp=environ['wsgi.input'],environ=environ)
      f = fs.getfirst('failas')
      print type(f)
      return output
  
  
  if __name__ == '__main__' :
      httpd = make_server('',8000,app)
      print 'Serving'
      httpd.serve_forever()
  </code></pre>
  
  <p>Thanks in advance! :)</p>