Conversion of http escape characters

N.G.Smith (ngs@ukc.ac.uk)
Tue, 14 Jun 94 16:31:46 BST

I am a python beginner, so go easy.

Is there a neat canned solution to the problem of converting the escaped
characters used in http back to normal characters?

e.g. The string 'foo%41bar' -> 'fooAbar' (0x41 == ASCII letter 'A')

The perl solution is something like this...

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

... but python's hex() has the opposite effect to that required, i.e. it
converts a number to a hex string, rather than converting a hex string to
a number.

Thanks,

Neil.