[OpenLayers-Users] Problems setting up TileCache

Christopher Schmidt crschmidt at metacarta.com
Mon Nov 27 08:55:15 EST 2006


On Mon, Nov 27, 2006 at 10:14:35PM +1300, Follower/OL wrote:
> While the TypeError error may well be solved by changing to a later 
> Python version, I feel the need to point out a bug in the code:
> 
> Christopher Schmidt wrote:
>  >Ben Wrote:
> >>"/home/httpd/cf2/cgi-bin/tilecache-1.1/TileCache/Service.py", line 232, 
> >>in _loadFromSection
> >>[Wed Nov 22 08:48:23 2006] [error] [client 192.168.50.1]     if opt not 
> >>in ("type"):
> >>[Wed Nov 22 08:48:23 2006] [error] [client 192.168.50.1] TypeError: 'in 
> >><string>' requires character as left operand
> > 
> > However, it does explain why you got this message: Python2.2 doesn't
> > support the construct:
> > 'string' in ("type")
> > 
> > A single element tuple is converted immediately to a string. (Python2.3
> > and python 2.4 apparently don't do this.)
> Please note that this:
> 
>     ("foo")
> 
> is *not* a single element tuple. See:
> 
>      Python 2.3.5 (#1, Mar 20 2005, 20:38:20)
> 
>      >>> type(("foo"))
>      <type 'str'>
> 
> But this is:
> 
>      >>> type(("foo",))
>      <type 'tuple'>
> 
> (Note the trailing comma.)
> 
> That the construct doesn't throw a TypeError in 2.3+ doesn't mean it's 
> working correctly. Essentially, if the content of `opt` is a string then 
>   it will never be true that 'opt' (a string) can be found in ("type") 
> (a sequence of single characters).
> 
> Hope this is some use... :-)

When working around the bug, I noticed that, but it does seem that Python 
*does* treat "foo" in ("foo") as true... Oh, I see why, it's because it
supports that operation on operators. So, with the single element, we
should probably just change that to a string and check equality. I think
that's there for 'historical reasons' :)

Thanks for the catch.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list