From 88d1d53d98c5e24896710dfeb829de01a85b2d2f Mon Sep 17 00:00:00 2001 From: YummyBian Date: Mon, 8 Sep 2014 22:43:53 +0800 Subject: [PATCH] Too many if clauses in the _clean_incoming_headers and the _clean_outgoing_headers routines of the tempurl module Too many if clauses make code complicated. For more pythonic, you'd better to use the for ... else clause instead of them. Fix Bug #1363125 Change-Id: I837235ecb08dd912e56cdfb363c4b4a6cc053e7d --- swift/common/middleware/tempurl.py | 46 +++++++++++++----------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/swift/common/middleware/tempurl.py b/swift/common/middleware/tempurl.py index 8cf6703a75..c2381b3183 100644 --- a/swift/common/middleware/tempurl.py +++ b/swift/common/middleware/tempurl.py @@ -464,22 +464,19 @@ class TempURL(object): :param env: The WSGI environment for the request. """ for h in env.keys(): - remove = h in self.incoming_remove_headers - if not remove: + if h in self.incoming_allow_headers: + continue + for p in self.incoming_allow_headers_startswith: + if h.startswith(p): + break + else: + if h in self.incoming_remove_headers: + del env[h] + continue for p in self.incoming_remove_headers_startswith: if h.startswith(p): - remove = True + del env[h] break - if remove: - if h in self.incoming_allow_headers: - remove = False - if remove: - for p in self.incoming_allow_headers_startswith: - if h.startswith(p): - remove = False - break - if remove: - del env[h] def _clean_outgoing_headers(self, headers): """ @@ -495,22 +492,19 @@ class TempURL(object): """ headers = HeaderKeyDict(headers) for h in headers.keys(): - remove = h in self.outgoing_remove_headers - if not remove: + if h in self.outgoing_allow_headers: + continue + for p in self.outgoing_allow_headers_startswith: + if h.startswith(p): + break + else: + if h in self.outgoing_remove_headers: + del headers[h] + continue for p in self.outgoing_remove_headers_startswith: if h.startswith(p): - remove = True + del headers[h] break - if remove: - if h in self.outgoing_allow_headers: - remove = False - if remove: - for p in self.outgoing_allow_headers_startswith: - if h.startswith(p): - remove = False - break - if remove: - del headers[h] return headers.items()