[Zope-dev] Pointless code in ZPublisher.HTTPRequest ?
Paul Winkler
pw_lists at slinkp.com
Tue Aug 31 13:08:50 EDT 2004
Can anyone enlighten me on what this is for?
>From ZPublisher.HTTPRequest.HTTPRequest.keys:
n=0
while 1:
n=n+1
key = "URL%s" % n
if not self.has_key(key): break
n=0
while 1:
n=n+1
key = "BASE%s" % n
if not self.has_key(key): break
Unless I am particularly stupid today (quite possible),
the above has no affect on the return value, and no
direct side effects.
I tried commenting it out and ran all unit tests
with no apparent difference.
While digging deeper for indirect side effects, I see that
self.has_key() calls self.__getitem__() which calls self.get().
The only side effect of self.get('URLn') that I see is that if
self.other.has_key('PUBLISHED'), the calculated URL will get
cached for the duration of the request in self.other['URLn'].
(And also in self._urls which AFAICT is used only to keep
track of which keys we've written to self.other, so we can
quickly clean them out in _resetURLS().**)
So maybe that's the sole purpose of the code in question;
some extra logging suggests that it does in fact have that effect.
But it's hard for me to be sure.
Can anyone confirm or deny?
Or is there something else that I'm missing?
** btw, this too smells a bit funny to me... why bother to keep a
separate data structure in sync, when we could just do:
for i in range(9):
try:
del(self.other['URL%d' % i])
i += 1
except KeyError:
break
--
Paul Winkler
http://www.slinkp.com
More information about the Zope-Dev
mailing list