From: Georg Brandl Date: Thu, 20 Sep 2007 16:06:07 +0000 (+0000) Subject: Patch #1541463: optimize performance of cgi.FieldStorage operations. X-Git-Tag: v2.6a1~1260 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aff85e2d26db4bedbfe620b282eafb78ff6b6653;p=python Patch #1541463: optimize performance of cgi.FieldStorage operations. --- diff --git a/Lib/cgi.py b/Lib/cgi.py index 818567e5fd..8760f96054 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) diff --git a/Misc/NEWS b/Misc/NEWS index 4503875f85..2dadbbfeca 100644 --- 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