summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-12 18:18:13 (GMT)
committerGuido van Rossum <guido@python.org>1997-08-12 18:18:13 (GMT)
commita5e9fb6a65c37e769e8a1eb4e7e2cac6c9500b9c (patch)
tree898e25ef06aa5ff44f69c779d40db26f0fa5e385
parentca54982b2af62c7de315ccd6307d16e2f2323cde (diff)
downloadcpython-a5e9fb6a65c37e769e8a1eb4e7e2cac6c9500b9c.zip
cpython-a5e9fb6a65c37e769e8a1eb4e7e2cac6c9500b9c.tar.gz
cpython-a5e9fb6a65c37e769e8a1eb4e7e2cac6c9500b9c.tar.bz2
Changes suggested by Jim fulton:
- Moved most imports to the top, for faster loadingf when using ni. - Always open the temp file in binary mode.
-rwxr-xr-xLib/cgi.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/Lib/cgi.py b/Lib/cgi.py
index 4f1b459..388e440 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -419,6 +419,11 @@ __version__ = "2.2"
import string
import sys
import os
+import urllib
+import regsub
+import mimetools
+import rfc822
+from StringIO import StringIO
# Logging support
@@ -551,7 +556,6 @@ def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
If false (the default), errors are silently ignored.
If true, errors raise a ValueError exception.
"""
- import urllib, regsub
name_value_pairs = string.splitfields(qs, '&')
dict = {}
for name_value in name_value_pairs:
@@ -591,7 +595,6 @@ def parse_multipart(fp, pdict):
point in having two implementations of the same parsing algorithm.
"""
- import mimetools
if pdict.has_key('boundary'):
boundary = pdict['boundary']
else:
@@ -702,7 +705,6 @@ class MiniFieldStorage:
def __init__(self, name, value):
"""Constructor from field name and value."""
- from StringIO import StringIO
self.name = name
self.value = value
# self.file = StringIO(value)
@@ -795,7 +797,6 @@ class FieldStorage:
qs = sys.argv[1]
else:
qs = ""
- from StringIO import StringIO
fp = StringIO(qs)
if headers is None:
headers = {'content-type':
@@ -917,7 +918,6 @@ class FieldStorage:
def read_multi(self):
"""Internal: read a part that is itself multipart."""
- import rfc822
self.list = []
part = self.__class__(self.fp, {}, self.innerboundary)
# Throw first part away
@@ -1018,7 +1018,7 @@ class FieldStorage:
self.done = 1
break
- def make_file(self, binary):
+ def make_file(self, binary=None):
"""Overridable: return a readable & writable file.
The file will be used as follows:
@@ -1026,8 +1026,8 @@ class FieldStorage:
- seek(0)
- data is read from it
- The 'binary' argument is 'b' if the file should be created in
- binary mode (on non-Unix systems), '' otherwise.
+ The 'binary' argument is unused -- the file is always opened
+ in binary mode.
This version opens a temporary file for reading and writing,
and immediately deletes (unlinks) it. The trick (on Unix!) is
@@ -1043,10 +1043,8 @@ class FieldStorage:
"""
import tempfile
- tfn = tempfile.mktemp()
- f = open(tfn, "w%s+" % binary)
- os.unlink(tfn)
- return f
+ return tempfile.TemporaryFile("w+b")
+
# Backwards Compatibility Classes
@@ -1318,7 +1316,6 @@ environment as well. Here are some common variable names:
def escape(s, quote=None):
"""Replace special characters '&', '<' and '>' by SGML entities."""
- import regsub
s = regsub.gsub("&", "&amp;", s) # Must be done first!
s = regsub.gsub("<", "&lt;", s)
s = regsub.gsub(">", "&gt;", s)