You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2023/03/20 15:02:13 UTC

svn commit: r1908574 - in /httpd/httpd/trunk/test/modules: http1/htdocs/cgi/ http2/htdocs/cgi/ tls/htdocs/a.mod-tls.test/ tls/htdocs/b.mod-tls.test/

Author: ylavic
Date: Mon Mar 20 15:02:13 2023
New Revision: 1908574

URL: http://svn.apache.org/viewvc?rev=1908574&view=rev
Log:
pytests: Use python3-multipart lib.

Use the API of https://github.com/andrew-d/python-multipart, available as
package python3-multipart on Debian/Ubuntu.


Modified:
    httpd/httpd/trunk/test/modules/http1/htdocs/cgi/upload.py
    httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echohd.py
    httpd/httpd/trunk/test/modules/http2/htdocs/cgi/env.py
    httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hecho.py
    httpd/httpd/trunk/test/modules/http2/htdocs/cgi/mnot164.py
    httpd/httpd/trunk/test/modules/http2/htdocs/cgi/necho.py
    httpd/httpd/trunk/test/modules/http2/htdocs/cgi/upload.py
    httpd/httpd/trunk/test/modules/tls/htdocs/a.mod-tls.test/vars.py
    httpd/httpd/trunk/test/modules/tls/htdocs/b.mod-tls.test/vars.py

Modified: httpd/httpd/trunk/test/modules/http1/htdocs/cgi/upload.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http1/htdocs/cgi/upload.py?rev=1908574&r1=1908573&r2=1908574&view=diff
==============================================================================
--- httpd/httpd/trunk/test/modules/http1/htdocs/cgi/upload.py (original)
+++ httpd/httpd/trunk/test/modules/http1/htdocs/cgi/upload.py Mon Mar 20 15:02:13 2023
@@ -1,8 +1,8 @@
 #!/usr/bin/env python3
 import os
 import sys
-import multipart
 from urllib import parse
+import multipart # https://github.com/andrew-d/python-multipart (`apt install python3-multipart`)
 
 
 try:  # Windows needs stdio set for binary mode.
@@ -16,15 +16,23 @@ except ImportError:
 
 def get_request_params():
     oforms = {}
+    ofiles = {}
     if "REQUEST_URI" in os.environ:
         qforms = parse.parse_qs(parse.urlsplit(os.environ["REQUEST_URI"]).query)
         for name, values in qforms.items():
             oforms[name] = values[0]
-    myenv = os.environ.copy()
-    myenv['wsgi.input'] = sys.stdin.buffer
-    mforms, ofiles = multipart.parse_form_data(environ=myenv)
-    for name, item in mforms.items():
-        oforms[name] = item
+    if "HTTP_CONTENT_TYPE" in os.environ:
+        ctype = os.environ["HTTP_CONTENT_TYPE"]
+        if ctype == "application/x-www-form-urlencoded":
+            qforms = parse.parse_qs(parse.urlsplit(sys.stdin.read()).query)
+            for name, values in qforms.items():
+                oforms[name] = values[0]
+        elif ctype.startswith("multipart/"):
+            def on_field(field):
+                oforms[field.field_name] = field.value
+            def on_file(file):
+                ofiles[field.field_name] = field.value
+            multipart.parse_form(headers={"Content-Type": ctype}, input_stream=sys.stdin.buffer, on_field=on_field, on_file=on_file)
     return oforms, ofiles
 
 

Modified: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echohd.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echohd.py?rev=1908574&r1=1908573&r2=1908574&view=diff
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echohd.py (original)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/echohd.py Mon Mar 20 15:02:13 2023
@@ -1,20 +1,28 @@
 #!/usr/bin/env python3
 import os, sys
-import multipart
 from urllib import parse
+import multipart # https://github.com/andrew-d/python-multipart (`apt install python3-multipart`)
 
 
 def get_request_params():
     oforms = {}
+    ofiles = {}
     if "REQUEST_URI" in os.environ:
         qforms = parse.parse_qs(parse.urlsplit(os.environ["REQUEST_URI"]).query)
         for name, values in qforms.items():
             oforms[name] = values[0]
-    myenv = os.environ.copy()
-    myenv['wsgi.input'] = sys.stdin.buffer
-    mforms, ofiles = multipart.parse_form_data(environ=myenv)
-    for name, item in mforms.items():
-        oforms[name] = item
+    if "HTTP_CONTENT_TYPE" in os.environ:
+        ctype = os.environ["HTTP_CONTENT_TYPE"]
+        if ctype == "application/x-www-form-urlencoded":
+            qforms = parse.parse_qs(parse.urlsplit(sys.stdin.read()).query)
+            for name, values in qforms.items():
+                oforms[name] = values[0]
+        elif ctype.startswith("multipart/"):
+            def on_field(field):
+                oforms[field.field_name] = field.value
+            def on_file(file):
+                ofiles[field.field_name] = field.value
+            multipart.parse_form(headers={"Content-Type": ctype}, input_stream=sys.stdin.buffer, on_field=on_field, on_file=on_file)
     return oforms, ofiles
 
 

Modified: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/env.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/env.py?rev=1908574&r1=1908573&r2=1908574&view=diff
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/env.py (original)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/env.py Mon Mar 20 15:02:13 2023
@@ -1,20 +1,28 @@
 #!/usr/bin/env python3
 import os, sys
-import multipart
 from urllib import parse
+import multipart # https://github.com/andrew-d/python-multipart (`apt install python3-multipart`)
 
 
 def get_request_params():
     oforms = {}
+    ofiles = {}
     if "REQUEST_URI" in os.environ:
         qforms = parse.parse_qs(parse.urlsplit(os.environ["REQUEST_URI"]).query)
         for name, values in qforms.items():
             oforms[name] = values[0]
-    myenv = os.environ.copy()
-    myenv['wsgi.input'] = sys.stdin.buffer
-    mforms, ofiles = multipart.parse_form_data(environ=myenv)
-    for name, item in mforms.items():
-        oforms[name] = item
+    if "HTTP_CONTENT_TYPE" in os.environ:
+        ctype = os.environ["HTTP_CONTENT_TYPE"]
+        if ctype == "application/x-www-form-urlencoded":
+            qforms = parse.parse_qs(parse.urlsplit(sys.stdin.read()).query)
+            for name, values in qforms.items():
+                oforms[name] = values[0]
+        elif ctype.startswith("multipart/"):
+            def on_field(field):
+                oforms[field.field_name] = field.value
+            def on_file(file):
+                ofiles[field.field_name] = field.value
+            multipart.parse_form(headers={"Content-Type": ctype}, input_stream=sys.stdin.buffer, on_field=on_field, on_file=on_file)
     return oforms, ofiles
 
 

Modified: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hecho.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hecho.py?rev=1908574&r1=1908573&r2=1908574&view=diff
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hecho.py (original)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/hecho.py Mon Mar 20 15:02:13 2023
@@ -1,20 +1,28 @@
 #!/usr/bin/env python3
 import os, sys
-import multipart
 from urllib import parse
+import multipart # https://github.com/andrew-d/python-multipart (`apt install python3-multipart`)
 
 
 def get_request_params():
     oforms = {}
+    ofiles = {}
     if "REQUEST_URI" in os.environ:
         qforms = parse.parse_qs(parse.urlsplit(os.environ["REQUEST_URI"]).query)
         for name, values in qforms.items():
             oforms[name] = values[0]
-    myenv = os.environ.copy()
-    myenv['wsgi.input'] = sys.stdin.buffer
-    mforms, ofiles = multipart.parse_form_data(environ=myenv)
-    for name, item in mforms.items():
-        oforms[name] = item
+    if "HTTP_CONTENT_TYPE" in os.environ:
+        ctype = os.environ["HTTP_CONTENT_TYPE"]
+        if ctype == "application/x-www-form-urlencoded":
+            qforms = parse.parse_qs(parse.urlsplit(sys.stdin.read()).query)
+            for name, values in qforms.items():
+                oforms[name] = values[0]
+        elif ctype.startswith("multipart/"):
+            def on_field(field):
+                oforms[field.field_name] = field.value
+            def on_file(file):
+                ofiles[field.field_name] = field.value
+            multipart.parse_form(headers={"Content-Type": ctype}, input_stream=sys.stdin.buffer, on_field=on_field, on_file=on_file)
     return oforms, ofiles
 
 

Modified: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/mnot164.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/mnot164.py?rev=1908574&r1=1908573&r2=1908574&view=diff
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/mnot164.py (original)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/mnot164.py Mon Mar 20 15:02:13 2023
@@ -1,20 +1,28 @@
 #!/usr/bin/env python3
 import os, sys
-import multipart
 from urllib import parse
+import multipart # https://github.com/andrew-d/python-multipart (`apt install python3-multipart`)
 
 
 def get_request_params():
     oforms = {}
+    ofiles = {}
     if "REQUEST_URI" in os.environ:
         qforms = parse.parse_qs(parse.urlsplit(os.environ["REQUEST_URI"]).query)
         for name, values in qforms.items():
             oforms[name] = values[0]
-    myenv = os.environ.copy()
-    myenv['wsgi.input'] = sys.stdin.buffer
-    mforms, ofiles = multipart.parse_form_data(environ=myenv)
-    for name, item in mforms.items():
-        oforms[name] = item
+    if "HTTP_CONTENT_TYPE" in os.environ:
+        ctype = os.environ["HTTP_CONTENT_TYPE"]
+        if ctype == "application/x-www-form-urlencoded":
+            qforms = parse.parse_qs(parse.urlsplit(sys.stdin.read()).query)
+            for name, values in qforms.items():
+                oforms[name] = values[0]
+        elif ctype.startswith("multipart/"):
+            def on_field(field):
+                oforms[field.field_name] = field.value
+            def on_file(file):
+                ofiles[field.field_name] = field.value
+            multipart.parse_form(headers={"Content-Type": ctype}, input_stream=sys.stdin.buffer, on_field=on_field, on_file=on_file)
     return oforms, ofiles
 
 

Modified: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/necho.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/necho.py?rev=1908574&r1=1908573&r2=1908574&view=diff
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/necho.py (original)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/necho.py Mon Mar 20 15:02:13 2023
@@ -1,21 +1,29 @@
 #!/usr/bin/env python3
 import time
 import os, sys
-import multipart
 from urllib import parse
+import multipart # https://github.com/andrew-d/python-multipart (`apt install python3-multipart`)
 
 
 def get_request_params():
     oforms = {}
+    ofiles = {}
     if "REQUEST_URI" in os.environ:
         qforms = parse.parse_qs(parse.urlsplit(os.environ["REQUEST_URI"]).query)
         for name, values in qforms.items():
             oforms[name] = values[0]
-    myenv = os.environ.copy()
-    myenv['wsgi.input'] = sys.stdin.buffer
-    mforms, ofiles = multipart.parse_form_data(environ=myenv)
-    for name, item in mforms.items():
-        oforms[name] = item
+    if "HTTP_CONTENT_TYPE" in os.environ:
+        ctype = os.environ["HTTP_CONTENT_TYPE"]
+        if ctype == "application/x-www-form-urlencoded":
+            qforms = parse.parse_qs(parse.urlsplit(sys.stdin.read()).query)
+            for name, values in qforms.items():
+                oforms[name] = values[0]
+        elif ctype.startswith("multipart/"):
+            def on_field(field):
+                oforms[field.field_name] = field.value
+            def on_file(file):
+                ofiles[field.field_name] = field.value
+            multipart.parse_form(headers={"Content-Type": ctype}, input_stream=sys.stdin.buffer, on_field=on_field, on_file=on_file)
     return oforms, ofiles
 
 

Modified: httpd/httpd/trunk/test/modules/http2/htdocs/cgi/upload.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/http2/htdocs/cgi/upload.py?rev=1908574&r1=1908573&r2=1908574&view=diff
==============================================================================
--- httpd/httpd/trunk/test/modules/http2/htdocs/cgi/upload.py (original)
+++ httpd/httpd/trunk/test/modules/http2/htdocs/cgi/upload.py Mon Mar 20 15:02:13 2023
@@ -1,8 +1,8 @@
 #!/usr/bin/env python3
 import os
 import sys
-import multipart
 from urllib import parse
+import multipart # https://github.com/andrew-d/python-multipart (`apt install python3-multipart`)
 
 
 try:  # Windows needs stdio set for binary mode.
@@ -15,15 +15,23 @@ except ImportError:
 
 def get_request_params():
     oforms = {}
+    ofiles = {}
     if "REQUEST_URI" in os.environ:
         qforms = parse.parse_qs(parse.urlsplit(os.environ["REQUEST_URI"]).query)
         for name, values in qforms.items():
             oforms[name] = values[0]
-    myenv = os.environ.copy()
-    myenv['wsgi.input'] = sys.stdin.buffer
-    mforms, ofiles = multipart.parse_form_data(environ=myenv)
-    for name, item in mforms.items():
-        oforms[name] = item
+    if "HTTP_CONTENT_TYPE" in os.environ:
+        ctype = os.environ["HTTP_CONTENT_TYPE"]
+        if ctype == "application/x-www-form-urlencoded":
+            qforms = parse.parse_qs(parse.urlsplit(sys.stdin.read()).query)
+            for name, values in qforms.items():
+                oforms[name] = values[0]
+        elif ctype.startswith("multipart/"):
+            def on_field(field):
+                oforms[field.field_name] = field.value
+            def on_file(file):
+                ofiles[field.field_name] = field.value
+            multipart.parse_form(headers={"Content-Type": ctype}, input_stream=sys.stdin.buffer, on_field=on_field, on_file=on_file)
     return oforms, ofiles
 
 

Modified: httpd/httpd/trunk/test/modules/tls/htdocs/a.mod-tls.test/vars.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/tls/htdocs/a.mod-tls.test/vars.py?rev=1908574&r1=1908573&r2=1908574&view=diff
==============================================================================
--- httpd/httpd/trunk/test/modules/tls/htdocs/a.mod-tls.test/vars.py (original)
+++ httpd/httpd/trunk/test/modules/tls/htdocs/a.mod-tls.test/vars.py Mon Mar 20 15:02:13 2023
@@ -1,21 +1,29 @@
 #!/usr/bin/env python3
 import json
 import os, sys
-import multipart
 from urllib import parse
+import multipart # https://github.com/andrew-d/python-multipart (`apt install python3-multipart`)
 
 
 def get_request_params():
     oforms = {}
+    ofiles = {}
     if "REQUEST_URI" in os.environ:
         qforms = parse.parse_qs(parse.urlsplit(os.environ["REQUEST_URI"]).query)
         for name, values in qforms.items():
             oforms[name] = values[0]
-    myenv = os.environ.copy()
-    myenv['wsgi.input'] = sys.stdin.buffer
-    mforms, ofiles = multipart.parse_form_data(environ=myenv)
-    for name, item in mforms.items():
-        oforms[name] = item
+    if "HTTP_CONTENT_TYPE" in os.environ:
+        ctype = os.environ["HTTP_CONTENT_TYPE"]
+        if ctype == "application/x-www-form-urlencoded":
+            qforms = parse.parse_qs(parse.urlsplit(sys.stdin.read()).query)
+            for name, values in qforms.items():
+                oforms[name] = values[0]
+        elif ctype.startswith("multipart/"):
+            def on_field(field):
+                oforms[field.field_name] = field.value
+            def on_file(file):
+                ofiles[field.field_name] = field.value
+            multipart.parse_form(headers={"Content-Type": ctype}, input_stream=sys.stdin.buffer, on_field=on_field, on_file=on_file)
     return oforms, ofiles
 
 

Modified: httpd/httpd/trunk/test/modules/tls/htdocs/b.mod-tls.test/vars.py
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/test/modules/tls/htdocs/b.mod-tls.test/vars.py?rev=1908574&r1=1908573&r2=1908574&view=diff
==============================================================================
--- httpd/httpd/trunk/test/modules/tls/htdocs/b.mod-tls.test/vars.py (original)
+++ httpd/httpd/trunk/test/modules/tls/htdocs/b.mod-tls.test/vars.py Mon Mar 20 15:02:13 2023
@@ -1,21 +1,29 @@
 #!/usr/bin/env python3
 import json
 import os, sys
-import multipart
 from urllib import parse
+import multipart # https://github.com/andrew-d/python-multipart (`apt install python3-multipart`)
 
 
 def get_request_params():
     oforms = {}
+    ofiles = {}
     if "REQUEST_URI" in os.environ:
         qforms = parse.parse_qs(parse.urlsplit(os.environ["REQUEST_URI"]).query)
         for name, values in qforms.items():
             oforms[name] = values[0]
-    myenv = os.environ.copy()
-    myenv['wsgi.input'] = sys.stdin.buffer
-    mforms, ofiles = multipart.parse_form_data(environ=myenv)
-    for name, item in mforms.items():
-        oforms[name] = item
+    if "HTTP_CONTENT_TYPE" in os.environ:
+        ctype = os.environ["HTTP_CONTENT_TYPE"]
+        if ctype == "application/x-www-form-urlencoded":
+            qforms = parse.parse_qs(parse.urlsplit(sys.stdin.read()).query)
+            for name, values in qforms.items():
+                oforms[name] = values[0]
+        elif ctype.startswith("multipart/"):
+            def on_field(field):
+                oforms[field.field_name] = field.value
+            def on_file(file):
+                ofiles[field.field_name] = field.value
+            multipart.parse_form(headers={"Content-Type": ctype}, input_stream=sys.stdin.buffer, on_field=on_field, on_file=on_file)
     return oforms, ofiles