Re: [PyCS-devel] bug in medusa that creates problems for both pycs and pyds (functionality bug, not
Status: Alpha
Brought to you by:
myelin
|
From: Phillip P. <pp...@my...> - 2003-03-04 10:06:19
|
On Tue, Mar 04, 2003 at 09:01:26AM +0100, Georg Bauer wrote: > >We could always fix it ourselves and send a patch to the Medusa > >maintainers - there seems to be a reasonable amount of activity going > >on in that project, so I'm sure they'd be happy to hear from us ... > > Sure, we can. But I have to admit that I don't have an idea how to do > that _right_, the only ideas coming up to me currently are bad and ugly > hacks (like tearing the request apart, unquoting partial stuff, > reconstructing it - must be the binary/textfile issues Hal pointed me > to, those make my brain hurt ;-) ). But I am not sure that things won't > break. Hmm. Do you have a nice idea? If yes, go ahead :-) Hmm ... I'll take a look. I didn't think it was that hard -- basically, given an HTTP request: >>> import urllib >>> url = 'http://foo.com/bar/baz?' + urllib.urlencode((('baz','boz'), ('abc', 'a=b&c?d'))) >>> url 'http://foo.com/bar/baz?baz=boz&abc=a%3Db%26c%3Fd' We can just split by &, then by =, then unquote to get the values: >>> path, qs = urllib.splitquery(url) >>> path 'http://foo.com/bar/baz' >>> qs 'baz=boz&abc=a%3Db%26c%3Fd' >>> bits = qs.split('&') >>> bits ['baz=boz', 'abc=a%3Db%26c%3Fd'] >>> for bit in bits: ... key,value = urllib.splitvalue(bit) ... (key, urllib.unquote(value)) ... ('baz', 'boz') ('abc', 'a=b&c?d') That gives you all the bits out of the query string ... presumably Medusa gets the rest right already ... (BTW doesn't Medusa give us a copy of the full query string anyway? In PyCS I think each script calls pycs_http_util to split it up ...) Cheers, Phil :) BTW - here's the raw code for the above, if you want to hack around: import urllib url = 'http://foo.com/bar/baz?' + urllib.urlencode((('baz','boz'), ('abc', 'a=b&c?d'))) url path, qs = urllib.splitquery(url) path qs bits = qs.split('&') bits for bit in bits: key,value = urllib.splitvalue(bit) (key, urllib.unquote(value)) so I guess: def urldecode(url): path, qs = urllib.splitquery(url) return [(key,urllib.unquote(value)) for key,value in qs.split('&')] |