mirror of https://github.com/python/cpython.git
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.
This commit is contained in:
parent
ca54982b2a
commit
a5e9fb6a65
23
Lib/cgi.py
23
Lib/cgi.py
|
@ -419,6 +419,11 @@
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import urllib
|
||||||
|
import regsub
|
||||||
|
import mimetools
|
||||||
|
import rfc822
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
|
||||||
# Logging support
|
# 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 false (the default), errors are silently ignored.
|
||||||
If true, errors raise a ValueError exception.
|
If true, errors raise a ValueError exception.
|
||||||
"""
|
"""
|
||||||
import urllib, regsub
|
|
||||||
name_value_pairs = string.splitfields(qs, '&')
|
name_value_pairs = string.splitfields(qs, '&')
|
||||||
dict = {}
|
dict = {}
|
||||||
for name_value in name_value_pairs:
|
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.
|
point in having two implementations of the same parsing algorithm.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import mimetools
|
|
||||||
if pdict.has_key('boundary'):
|
if pdict.has_key('boundary'):
|
||||||
boundary = pdict['boundary']
|
boundary = pdict['boundary']
|
||||||
else:
|
else:
|
||||||
|
@ -702,7 +705,6 @@ class MiniFieldStorage:
|
||||||
|
|
||||||
def __init__(self, name, value):
|
def __init__(self, name, value):
|
||||||
"""Constructor from field name and value."""
|
"""Constructor from field name and value."""
|
||||||
from StringIO import StringIO
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.value = value
|
self.value = value
|
||||||
# self.file = StringIO(value)
|
# self.file = StringIO(value)
|
||||||
|
@ -795,7 +797,6 @@ def __init__(self, fp=None, headers=None, outerboundary="",
|
||||||
qs = sys.argv[1]
|
qs = sys.argv[1]
|
||||||
else:
|
else:
|
||||||
qs = ""
|
qs = ""
|
||||||
from StringIO import StringIO
|
|
||||||
fp = StringIO(qs)
|
fp = StringIO(qs)
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = {'content-type':
|
headers = {'content-type':
|
||||||
|
@ -917,7 +918,6 @@ def read_urlencoded(self):
|
||||||
|
|
||||||
def read_multi(self):
|
def read_multi(self):
|
||||||
"""Internal: read a part that is itself multipart."""
|
"""Internal: read a part that is itself multipart."""
|
||||||
import rfc822
|
|
||||||
self.list = []
|
self.list = []
|
||||||
part = self.__class__(self.fp, {}, self.innerboundary)
|
part = self.__class__(self.fp, {}, self.innerboundary)
|
||||||
# Throw first part away
|
# Throw first part away
|
||||||
|
@ -1018,7 +1018,7 @@ def skip_lines(self):
|
||||||
self.done = 1
|
self.done = 1
|
||||||
break
|
break
|
||||||
|
|
||||||
def make_file(self, binary):
|
def make_file(self, binary=None):
|
||||||
"""Overridable: return a readable & writable file.
|
"""Overridable: return a readable & writable file.
|
||||||
|
|
||||||
The file will be used as follows:
|
The file will be used as follows:
|
||||||
|
@ -1026,8 +1026,8 @@ def make_file(self, binary):
|
||||||
- seek(0)
|
- seek(0)
|
||||||
- data is read from it
|
- data is read from it
|
||||||
|
|
||||||
The 'binary' argument is 'b' if the file should be created in
|
The 'binary' argument is unused -- the file is always opened
|
||||||
binary mode (on non-Unix systems), '' otherwise.
|
in binary mode.
|
||||||
|
|
||||||
This version opens a temporary file for reading and writing,
|
This version opens a temporary file for reading and writing,
|
||||||
and immediately deletes (unlinks) it. The trick (on Unix!) is
|
and immediately deletes (unlinks) it. The trick (on Unix!) is
|
||||||
|
@ -1043,10 +1043,8 @@ def make_file(self, binary):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import tempfile
|
import tempfile
|
||||||
tfn = tempfile.mktemp()
|
return tempfile.TemporaryFile("w+b")
|
||||||
f = open(tfn, "w%s+" % binary)
|
|
||||||
os.unlink(tfn)
|
|
||||||
return f
|
|
||||||
|
|
||||||
|
|
||||||
# Backwards Compatibility Classes
|
# Backwards Compatibility Classes
|
||||||
|
@ -1318,7 +1316,6 @@ def print_environ_usage():
|
||||||
|
|
||||||
def escape(s, quote=None):
|
def escape(s, quote=None):
|
||||||
"""Replace special characters '&', '<' and '>' by SGML entities."""
|
"""Replace special characters '&', '<' and '>' by SGML entities."""
|
||||||
import regsub
|
|
||||||
s = regsub.gsub("&", "&", s) # Must be done first!
|
s = regsub.gsub("&", "&", s) # Must be done first!
|
||||||
s = regsub.gsub("<", "<", s)
|
s = regsub.gsub("<", "<", s)
|
||||||
s = regsub.gsub(">", ">", s)
|
s = regsub.gsub(">", ">", s)
|
||||||
|
|
Loading…
Reference in New Issue