summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-09-20 16:06:07 (GMT)
committerGeorg Brandl <georg@python.org>2007-09-20 16:06:07 (GMT)
commitaff85e2d26db4bedbfe620b282eafb78ff6b6653 (patch)
tree5f2852f8a694bff60f6c6468f483b9c4a6c84220 /Lib
parent5d242eef748de2a48e171decce4a1ed73d079f32 (diff)
downloadcpython-aff85e2d26db4bedbfe620b282eafb78ff6b6653.zip
cpython-aff85e2d26db4bedbfe620b282eafb78ff6b6653.tar.gz
cpython-aff85e2d26db4bedbfe620b282eafb78ff6b6653.tar.bz2
Patch #1541463: optimize performance of cgi.FieldStorage operations.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/cgi.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/Lib/cgi.py b/Lib/cgi.py
index 818567e..8760f96 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -607,31 +607,27 @@ class FieldStorage:
"""Dictionary style keys() method."""
if self.list is None:
raise TypeError, "not indexable"
- keys = []
- for item in self.list:
- if item.name not in keys: keys.append(item.name)
- return keys
+ return list(set(item.name for item in self.list))
def has_key(self, key):
"""Dictionary style has_key() method."""
if self.list is None:
raise TypeError, "not indexable"
- for item in self.list:
- if item.name == key: return True
- return False
+ return any(item.name == key for item in self.list)
def __contains__(self, key):
"""Dictionary style __contains__ method."""
if self.list is None:
raise TypeError, "not indexable"
- for item in self.list:
- if item.name == key: return True
- return False
+ return any(item.name == key for item in self.list)
def __len__(self):
"""Dictionary style len(x) support."""
return len(self.keys())
+ def __nonzero__(self):
+ return bool(self.list)
+
def read_urlencoded(self):
"""Internal: read data in query string format."""
qs = self.fp.read(self.length)