You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by hu...@apache.org on 2016/03/27 12:44:35 UTC

svn commit: r1736731 - /steve/trunk/pysteve/lib/form.py

Author: humbedooh
Date: Sun Mar 27 10:44:34 2016
New Revision: 1736731

URL: http://svn.apache.org/viewvc?rev=1736731&view=rev
Log:
fix to handle multipart form data as well

Modified:
    steve/trunk/pysteve/lib/form.py

Modified: steve/trunk/pysteve/lib/form.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/lib/form.py?rev=1736731&r1=1736730&r2=1736731&view=diff
==============================================================================
--- steve/trunk/pysteve/lib/form.py (original)
+++ steve/trunk/pysteve/lib/form.py Sun Mar 27 10:44:34 2016
@@ -17,12 +17,21 @@
 import hashlib, json, random, os, sys, time
 import cgi
 
+ctype, pdict = cgi.parse_header(os.environ['CONTENT_TYPE'] if 'CONTENT_TYPE' in os.environ else "")
+if ctype == 'multipart/form-data':
+    xform = cgi.parse_multipart(sys.stdin, pdict)
+else:
+    xform = cgi.FieldStorage();
 
-xform = cgi.FieldStorage();
 
 def getvalue(key):
-    val = xform.getvalue(key)
+    try:
+        val = str("".join(xform.get(key)))
+        if val == "":
+            val = None
+    except:
+        val = xform.getvalue(key)
     if val:
         return val.replace("<", "&lt;")
     else:
-        return None
\ No newline at end of file
+        return None