<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Intrepid Blog &#187; encodng</title>
	<atom:link href="http://blog.affien.com/archives/tag/encodng/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.affien.com</link>
	<description>A few thoughts</description>
	<lastBuildDate>Mon, 23 Jan 2012 08:47:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Python Url Encoding</title>
		<link>http://blog.affien.com/archives/2005/06/25/python-url-encoding/</link>
		<comments>http://blog.affien.com/archives/2005/06/25/python-url-encoding/#comments</comments>
		<pubDate>Fri, 24 Jun 2005 23:00:20 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[Code sniplets]]></category>
		<category><![CDATA[encodng]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://blog.w-nz.com/?p=102</guid>
		<description><![CDATA[I looked in the Python Library Reference for a function [...]]]></description>
			<content:encoded><![CDATA[<p>I looked in the <a href="http://docs.python.org/lib/lib.html">Python Library Reference</a> for a function to encode special characters in strings to be able to be put in Urls (and Uri&#8217;s), but found none.</p>
<p>Maybe I missed it?</p>
<p>Anyways, here is an implementation I wrote based on <a href="http://www.blooberry.com/indexdot/html/topics/urlencoding.htm">this article</a>:</p>
<blockquote><pre style='font-size:larger;'>HexCharacters = &quot;0123456789abcdef&quot;

def UrlEncode(s):
    r = ''
    for c in s:
        o = ord(c)
        if (o &gt;= 48 and o &lt;= 57) or \
            (o &gt;= 97 and o &lt;= 122) or \
            (o &gt;= 65 and o &lt;= 90) or \
            o == 36 or o == 45 or o == 95 or \
            o == 46 or o == 43 or o == 33 or \
            o == 42 or o == 39 or o == 40 or \
            o == 41 or o == 44:
            r += c
        else:
            r += '%' + CleanCharHex(c)
    return r

def CleanCharHex(c):
    o = ord(c)
    r = HexCharacters[o / 16]
    r += HexCharacters[o % 16]
    return r</pre>
</blockquote>
<p>note: I used the character numbers instead the characters to compare with so I could do greater than and lesser than for the alphanumeric numbers. Maybe testing with a bitmask would be more efficient.</p>
<p>I have to write almost everytime I work with python my own <em>something to hex</em> function which doesn&#8217;t add the &#8217;0x&#8217; in front the built-in <em>hex</em> does.</p>
<p>Either I can&#8217;t search or Python hasn&#8217;t got enough batteries included. I guess the first, if not I`ll submit my batteries.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2005/06/25/python-url-encoding/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

