<?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>David Andrzejewski &#187; Programming</title> <atom:link href="http://www.davidandrzejewski.com/category/computing/programming/feed/" rel="self" type="application/rss+xml" /><link>http://www.davidandrzejewski.com</link> <description></description> <lastBuildDate>Fri, 18 Nov 2011 23:01:39 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Python: Get XML Representation of an Object</title><link>http://www.davidandrzejewski.com/2011/11/18/python-get-xml-representation-of-an-object/</link> <comments>http://www.davidandrzejewski.com/2011/11/18/python-get-xml-representation-of-an-object/#comments</comments> <pubDate>Fri, 18 Nov 2011 23:01:39 +0000</pubDate> <dc:creator>David Andrzejewski</dc:creator> <category><![CDATA[Computing]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Python]]></category> <guid
isPermaLink="false">http://www.davidandrzejewski.com/?p=510</guid> <description><![CDATA[TweetI needed to return all the members of an object as an XML document in Python. I used the ElementTree library to do this. The class in question is pretty basic: It has a constructor, member variables, getters and setters for the member variables, and now this new function. Every Python class has a built-in <a
href='http://www.davidandrzejewski.com/2011/11/18/python-get-xml-representation-of-an-object/'>[...]</a>]]></description> <content:encoded><![CDATA[<div
id="tweetbutton510" class="tw_button" style=""><a
href="http://twitter.com/share?url=http%3A%2F%2Fwww.davidandrzejewski.com%2F2011%2F11%2F18%2Fpython-get-xml-representation-of-an-object%2F&amp;via=dandrzejewski&amp;text=Python%3A%20Get%20XML%20Representation%20of%20an%20Object&amp;related=&amp;lang=en&amp;count=horizontal" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.davidandrzejewski.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>I needed to return all the members of an object as an XML document in Python. I used the ElementTree library to do this.</p><p>The class in question is pretty basic: It has a constructor, member variables, getters and setters for the member variables, and now this new function.</p><p>Every Python class has a built-in __dict__ member, which is a dictionary ({}) of key/value pairs for all of the member variables, so I use that to get all of the variables to add to the ElementTree.</p><p>This function returns an xml.etree.ElementTree.Element object, which can be turned into a string if needed by using ElementTree&#8217;s tostring() method.</p><div
class="wp_syntax"><div
class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> getXML<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; Returns an XML representation of the object &quot;&quot;&quot;</span>
    topElem = Element<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;item&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> key <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span>.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        elem = SubElement<span style="color: black;">&#40;</span>topElem, key<span style="color: black;">&#41;</span>
        elem.<span style="color: black;">text</span> = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> topElem</pre></div></div><div
id="tweetbutton510" class="tw_button" style=""><a
href="http://twitter.com/share?url=http%3A%2F%2Fwww.davidandrzejewski.com%2F2011%2F11%2F18%2Fpython-get-xml-representation-of-an-object%2F&amp;via=dandrzejewski&amp;text=Python%3A%20Get%20XML%20Representation%20of%20an%20Object&amp;related=&amp;lang=en&amp;count=horizontal" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.davidandrzejewski.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded> <wfw:commentRss>http://www.davidandrzejewski.com/2011/11/18/python-get-xml-representation-of-an-object/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>CSS: Make an element unselectable</title><link>http://www.davidandrzejewski.com/2011/10/28/css-make-an-element-unselectable/</link> <comments>http://www.davidandrzejewski.com/2011/10/28/css-make-an-element-unselectable/#comments</comments> <pubDate>Fri, 28 Oct 2011 23:31:12 +0000</pubDate> <dc:creator>David Andrzejewski</dc:creator> <category><![CDATA[Computing]]></category> <category><![CDATA[Programming]]></category> <guid
isPermaLink="false">http://www.davidandrzejewski.com/?p=471</guid> <description><![CDATA[TweetApparently, it&#8217;s necessary to use separate CSS properties for each browser. .unselectable &#123; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; &#125; Tweet]]></description> <content:encoded><![CDATA[<div
id="tweetbutton471" class="tw_button" style=""><a
href="http://twitter.com/share?url=http%3A%2F%2Fwww.davidandrzejewski.com%2F2011%2F10%2F28%2Fcss-make-an-element-unselectable%2F&amp;via=dandrzejewski&amp;text=CSS%3A%20Make%20an%20element%20unselectable&amp;related=&amp;lang=en&amp;count=horizontal" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.davidandrzejewski.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Apparently, it&#8217;s necessary to use separate CSS properties for each browser.</p><div
class="wp_syntax"><div
class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.unselectable</span> <span style="color: #00AA00;">&#123;</span>
	-webkit-user-select<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	-khtml-user-select<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	-moz-user-select<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	-o-user-select<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	user-select<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div><div
id="tweetbutton471" class="tw_button" style=""><a
href="http://twitter.com/share?url=http%3A%2F%2Fwww.davidandrzejewski.com%2F2011%2F10%2F28%2Fcss-make-an-element-unselectable%2F&amp;via=dandrzejewski&amp;text=CSS%3A%20Make%20an%20element%20unselectable&amp;related=&amp;lang=en&amp;count=horizontal" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.davidandrzejewski.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded> <wfw:commentRss>http://www.davidandrzejewski.com/2011/10/28/css-make-an-element-unselectable/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Python URLGrabber: Ignore System Proxy Settings</title><link>http://www.davidandrzejewski.com/2009/07/04/python-urlgrabber-ignore-system-proxy-settings/</link> <comments>http://www.davidandrzejewski.com/2009/07/04/python-urlgrabber-ignore-system-proxy-settings/#comments</comments> <pubDate>Sat, 04 Jul 2009 18:41:36 +0000</pubDate> <dc:creator>David Andrzejewski</dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[python]]></category> <category><![CDATA[urlgrabber]]></category> <category><![CDATA[urllib]]></category> <category><![CDATA[urllib2]]></category> <guid
isPermaLink="false">http://www.davidandrzejewski.com/?p=269</guid> <description><![CDATA[TweetThe Duke URLGrabber package for Python makes it incredibly easy to retrieve files from remote servers, and it abstracts urllib2 for you in a protocol-independent way, so you can focus on your application instead of spending time working with Python&#8217;s built-in urllib2. On Windows and Mac OSX, by default, urllib2 (and therefore URLGrabber) will use <a
href='http://www.davidandrzejewski.com/2009/07/04/python-urlgrabber-ignore-system-proxy-settings/'>[...]</a>]]></description> <content:encoded><![CDATA[<div
id="tweetbutton269" class="tw_button" style=""><a
href="http://twitter.com/share?url=http%3A%2F%2Fwww.davidandrzejewski.com%2F2009%2F07%2F04%2Fpython-urlgrabber-ignore-system-proxy-settings%2F&amp;via=dandrzejewski&amp;text=Python%20URLGrabber%3A%20Ignore%20System%20Proxy%20Settings&amp;related=&amp;lang=en&amp;count=horizontal" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.davidandrzejewski.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>The <a
href="http://linux.duke.edu/projects/urlgrabber/">Duke URLGrabber</a> package for Python makes it incredibly easy to retrieve files from remote servers, and it abstracts <a
href="http://docs.python.org/library/urllib2.html">urllib2</a> for you in a protocol-independent way, so you can focus on your application instead of spending time working with Python&#8217;s built-in urllib2.</p><p>On Windows and Mac OSX, by default, urllib2 (and therefore URLGrabber) will use the built-in proxy settings of the system &#8211; but sometimes you don&#8217;t want that.  For example, let&#8217;s say you&#8217;re using a Windows box that&#8217;s on a domain, and proxy settings have been pushed down by group policy.  You want to access local network resources without needing to route through the proxy or authenticate to it.</p><p>With urllib2, you would simply add code like the following:</p><div
class="wp_syntax"><div
class="code"><pre class="python" style="font-family:monospace;">proxy_support = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">ProxyHandler</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span></pre></div></div><p>Note the empty dictionary &#8220;{}&#8221; to specify no proxies.  Doing the same for URLGrabber was suggested on a mailing list post &#8211; and it apparently worked for the poster.  However, I wasn&#8217;t able to get it to work, so I came up with another way.  I just specified a dummy proxy for a dummy protocol, as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="python" style="font-family:monospace;">kwargs<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;proxies&quot;</span><span style="color: black;">&#93;</span> = <span style="color: black;">&#123;</span> <span style="color: #483d8b;">'nothing'</span>: <span style="color: #483d8b;">'http://nothing'</span> <span style="color: black;">&#125;</span></pre></div></div><p>Have fun!</p><div
id="tweetbutton269" class="tw_button" style=""><a
href="http://twitter.com/share?url=http%3A%2F%2Fwww.davidandrzejewski.com%2F2009%2F07%2F04%2Fpython-urlgrabber-ignore-system-proxy-settings%2F&amp;via=dandrzejewski&amp;text=Python%20URLGrabber%3A%20Ignore%20System%20Proxy%20Settings&amp;related=&amp;lang=en&amp;count=horizontal" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.davidandrzejewski.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded> <wfw:commentRss>http://www.davidandrzejewski.com/2009/07/04/python-urlgrabber-ignore-system-proxy-settings/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
