|
courtney ludwin
courtneyludwin at yahoo.com
Sat Jan 7 23:13:55 EST 2006
I misread, My reply was for "URL" (encode/decode)ing not html (ecnode/decode)ing. Sorry bout that, Courtney --- courtney ludwin <courtneyludwin at yahoo.com> wrote: > Yo Sean, > I just wrote the encode/decode functions recently > and > posted them on by blog: > http://2centspoorer.blogspot.com/2006/01/urlencoderdecoder-for-python.html > > regards, > Courtney > > > anyway here it is... > > > _keys = [ > "$", "&", "+", ",", "/", ":", ";", "=", "?", "@", > " > ", '"', > "<", ">", "#", "%", "{", "}", "|", "\\", "^", "~", > "[", "]", "`"] > > _vals = [ > '%24', '%26', '%2B', '%2C', '%2F', '%3A', '%3B', > '%3D', '%3F', > '%40', '%20', '%22', '%3C', '%3E', '%23', '%25', > '%7B', '%7D', > '%7C', '%5C', '%5E', '%7E', '%5B', '%5D', '%60'] > > def encode(str=""): > """ URL Encodes a string with out side effects > """ > return "".join([_swap(x) for x in str]) > > def decode(str=""): > """ Takes a URL encoded string and decodes it with > out side effects > """ > if not str: return None > for v in _vals: > if v in str: str = str.replace(v, > _keys[_vals.index(v)]) > return str > > def _swap(x): > """ Helper function for encode. > """ > if x in _keys: return _vals[_keys.index(x)] > return x > > ### units ### > if __name__ == "__main__": > assert("".join(_keys) == > decode(encode("".join(_keys)))) > assert("".join(_vals) == > encode(decode("".join(_vals)))) > print "passed all unit tests." > > > > > --- Sean Jamieson <sean at barriescene.com> wrote: > > > Hi, I don't know if what I'm about to ask has > > already been requested, or > > if this is the right list, but here I go: > > > > I have been using mod_python for about 3 weeks > now, > > and have come up > > with a few things that I'd like to see added into > > the util module (I'm > > assuming this might be the right place for them). > > > > 1. a refresh() sibling to the redirect() function; > I > > use the Refresh > > header quite often in my applications. > |