[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    KURL, encode/decode
From:       Frans Englich <frans.englich () telia ! com>
Date:       2005-03-29 7:55:13
Message-ID: 200503290803.10920.frans.englich () telia ! com
[Download RAW message or body]

Hello,

In a scenario, I need to, when given a string which either is an properly 
encoded URI or an un-encoded(invalid) URI, transform it to a valid URI.

For example, no matter if the input is "test with spaces" or 
"test%20with%20spaces", the output should be "test%20with%20spaces". The 
algorithm should be idempotent, in other words.

The following algorithm /appears/ to achieve what I want, but I find it 
costly(python example):

def absolutizeURI(string):

        u = KURL(string)

        if u.isValid():
                return u.url()
        else:
                return KURL.encode_string(KURL.decode_string(string))


E.g, a handful of encode/decode loops have parsed the string.

I wonder, what is the proper way of achieving what I want?

BTW, I've attached a small Python test case to play with.


Cheers,

		Frans

["yo.py" (application/x-python)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic