From kde-devel Tue Mar 29 07:55:13 2005 From: Frans Englich Date: Tue, 29 Mar 2005 07:55:13 +0000 To: kde-devel Subject: KURL, encode/decode Message-Id: <200503290803.10920.frans.englich () telia ! com> X-MARC-Message: https://marc.info/?l=kde-devel&m=111208291304500 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_+uQSCO18o0meX2d" --Boundary-00=_+uQSCO18o0meX2d Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --Boundary-00=_+uQSCO18o0meX2d Content-Type: application/x-python; name="yo.py" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="yo.py" import libxml2 import libxslt import sys def openXmlFile( uri, schemaURL ): return libxml2.parseFile( uri ) #return openXmlDocument( document, schemaURL ) file = "t.xsl" xsltDoc = openXmlFile( file, None ) xslt = libxslt.parseStylesheetDoc( xsltDoc ) self.sheets[key][0] = xsltDoc self.sheets[key][1] = xslt for xslt in self.sheets.values(): if xslt[0]: xslt[0].freeDoc() # vim: set et tw=80 ts=4 sw=4 sts=4: --Boundary-00=_+uQSCO18o0meX2d Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << --Boundary-00=_+uQSCO18o0meX2d--