]> granicus.if.org Git - python/commitdiff
Patch #1541463: optimize performance of cgi.FieldStorage operations.
authorGeorg Brandl <georg@python.org>
Thu, 20 Sep 2007 16:06:07 +0000 (16:06 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 20 Sep 2007 16:06:07 +0000 (16:06 +0000)
Lib/cgi.py
Misc/NEWS

index 818567e5fdcd2e745a28e0081dee9f75b711f10b..8760f960549d977f7a4bd0d31d96316da3568003 100755 (executable)
@@ -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)
index 4503875f853cee9d8ba56baf9bffde23dbf96a0d..2dadbbfeca4e3beefb4d98b6076843df5482438d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -260,6 +260,8 @@ Core and builtins
 Library
 -------
 
+- Patch #1541463: optimize performance of cgi.FieldStorage operations.
+
 - Decimal is fully updated to the latest Decimal Specification (v1.66).
 
 - Bug #1153: repr.repr() now doesn't require set and dictionary items