<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Python</title>
  <link rel="alternate" type="text/html" href="http://samat.org/topic/python.html"/>
  <link rel="self" type="application/atom+xml" href="http://samat.org/taxonomy/term/8/atom/feed"/>
  <id>http://samat.org/taxonomy/term/8/atom/feed</id>
  <updated>2006-05-23T23:20:57-06:00</updated>
  <entry>
    <title>Python-like tuple unpacking for PHP</title>
    <link rel="alternate" type="text/html" href="http://samat.org/weblog/20081029-python-tuple-unpacking-php.html" />
    <id>http://samat.org/weblog/20081029-python-tuple-unpacking-php.html</id>
    <published>2008-10-29T15:55:47-06:00</published>
    <updated>2008-11-01T02:30:56-06:00</updated>
    <author>
      <name>Samat Jain</name>
    </author>
    <category term="Article" />
    <category term="PHP" />
    <category term="Programming" />
    <category term="Python" />
    <summary type="html"><![CDATA[<p>Python provides a neat way for functions to return multiple arguments via "tuple unpacking". For example:</p>

<div class="codeblock"><code>def blah:&lt;br /&gt;&amp;nbsp; return (&amp;#039;one&amp;#039;, &amp;#039;two&amp;#039;)&lt;br /&gt;&lt;br /&gt;rval_1, rval_2 = blah()</code></div>

<p>The same can be done in PHP relatively easily via the <a href="http://php.net/list">list construct</a>:</p>

<div class="codeblock"><code>function blah()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; return array(&amp;#039;one&amp;#039;, &amp;#039;two&amp;#039;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;list($rval_1, $rval_2) = blah();</code></div>
    ]]></summary>
  </entry>
  <entry>
    <title>GPG public key signing post-party automation with KMail</title>
    <link rel="alternate" type="text/html" href="http://samat.org/weblog/20070218-gpg-public-key-signing-post-party-automation-with-kmail.html" />
    <id>http://samat.org/weblog/20070218-gpg-public-key-signing-post-party-automation-with-kmail.html</id>
    <published>2007-02-18T20:24:32-07:00</published>
    <updated>2007-12-25T14:00:39-07:00</updated>
    <author>
      <name>Samat Jain</name>
    </author>
    <category term="Article" />
    <category term="Crypto" />
    <category term="KDE" />
    <category term="Linux" />
    <category term="Python" />
    <summary type="html"><![CDATA[<p>This past <a href="https://wiki.ubuntu.com/TheUbucon">Ubucon</a>'s key signing party was my first key signing party. One thing I noticed--signing keys after a <a href="http://en.wikipedia.org/wiki/Key_signing_party">key signing party</a> is a boring repetitive task. Summarized from the <a href="https://wiki.ubuntu.com/KeySigningParty">Ubuntu wiki entry on typical key signing post-party protocol</a>:</p>

<ol>
<li>Retrieve all public keys of key signing party participants, using gpg –-recv-key <keyID></li>
<li>Compare the hardcopy fingerprint from the keysigning party to the fingerprint of the retrieved public keys, using gpg –-fingerprint <keyID></li>
<li>Sign the key, using gpg –-sign <keyID>
Send the signed key back, either by

<ul>
<li>E-mail: export the key, then e-mail it to the key owner, using gpg –-export -a <keyID> | mail -s “Your signed key” user@example.com</li>
<li>Key server: send the key to a public keyserver, using gpg –send-keys <keyID></li>
</ul></li>
</ol>

<p>This is incredibly monotonous—and people have to wonder why <a href="http://en.wikipedia.org/wiki/Web_of_trust">Web of Trust-based encryption</a> is not more popular?</p>

<p>The <a href="http://debaday.debian.net/2007/02/18/signing-party-complete-toolkit-for-efficient-key-signing/">Debian signing-party package</a> provides the utility caff to automate some of this. It's not very friendly to “desktop” users, however:</p>

<ul>
<li>it's a <acronym title="Command Line Interface">CLI</acronym> application</li>
<li>it requires a local <acronym title="Mail Transfer Agent">MTA</acronym> (/usr/sbin/sendmail in particular), or an “open” SMTP server, with no support for authenticated SMTP or SMTP/SSL</li>
<li>the configuration file syntax is Perl and confusing; there are also few examples on the Internet</li>
</ul>

<p>You could add authenticated SMTP or SMTP/SSL support to the script, but having to know how to hack Perl definitely disqualifies caffe from being a desktop-friendly application.</p>

<p>So, I hacked together <a href="/sites/samat.org/files/key-signing-party-batch-process-via-kmail.py.txt">my own key signing party script</a> in Python that would send signed keys back to people via KMail. To use it, create a text file listing all key IDs you wish to sign, one per line. Pipe the contents of this list into the script:</p>

<div class="codeblock"><code>cat list-of-ids.txt | key-signing-party-batch-process-via-kmail.py</code></div>

<p>The script will download each key, ask you to verify the fingerprint, and then sign it. It then will open a KMail composer window, pre-filled with the key owner's e-mail address, a friendly template message (customizable in the script), and attached key. Review each e-mail to make sure it is kosher, and click send. Other than continuing to be a CLI program, I think this is much friendlier--the only manual work done is the creation of list of keys to sign, comparing fingerprints (this could be automated, but it seems in the spirit of the Web of Trust-based systems not to), and clicking send in a familiar desktop e-mail client.</p>

<p>Now for some notes...</p>

<p>It uses the <a href="http://en.wikipedia.org/wiki/DCOP">DCOP automation</a> features of KDE's Kmail to send messages. You could similarly use Evolution and D-Bus, but I don't use Evolution so I can't contribute that bit of functionality. Mozilla's Thunderbird unfortunately does not yet support any kind of automation features (as far as I know, anyway), so you're completely out of luck if you use it.</p>

<p>DCOP with Python is a complete, utter, pain. The easy way to drag-and-drop boiler-plate code with kdcop did not work, as it appears the APIs have changed. A problem with KDE/Python dcopext's module and multiple identically-named-functions sealed the deal for me and I gave up trying to use DCOP with Python, and instead settled for a hack of using the shell instead. I'm looking forward the one Linux desktop <acronym title="Inter-Process Communication">IPC</acronym> protocol to rule them all, <a href="http://en.wikipedia.org/wiki/D-Bus">D-Bus</a>, to debut in KDE4.</p>

<p>My script does not provide all the functionality of caffe. It, for example, does not encrypt the messages and their keys back to their owners. There doesn't appear to be an easy way to do this with KMail and DCOP, so it's a feature that will have to wait.</p>
    ]]></summary>
  </entry>
  <entry>
    <title>T-Mobile WiFi Hotspot login script</title>
    <link rel="alternate" type="text/html" href="http://samat.org/weblog/20060729-t-mobile-wifi-hotspot-login-script.html" />
    <id>http://samat.org/weblog/20060729-t-mobile-wifi-hotspot-login-script.html</id>
    <published>2006-07-29T00:53:05-06:00</published>
    <updated>2006-11-22T22:35:16-07:00</updated>
    <author>
      <name>Samat Jain</name>
    </author>
    <category term="Article" />
    <category term="Linux" />
    <category term="Python" />
    <category term="Wireless" />
    <summary type="html"><![CDATA[<p><a href="http://hotspot.t-mobile.com/">T-Mobile's WiFi Hotspot service</a>, thankfully, forgoes a proprietary authentication mechanism for a solution that while cross platform (i.e. it works with Linux), can be extremely annoying. On opening a web browser and attempting to go to any website, you're required to login on an SSL-protected website with your account username and password before you can use the connection. If your web browser automatically tries to open many pages on startup, such as when you're using the <a href="https://addons.mozilla.org/firefox/436/">Session Saving extension for Firefox</a>, you get T-Mobile's Hotspot login page in every tab--extremely annoying!</p>

<p>I've written a small Python script that can login programatically without use of a web browser.</p>
    ]]></summary>
  </entry>
  <entry>
    <title>A quick shell include for setting paths for programs installed in non-traditional locations</title>
    <link rel="alternate" type="text/html" href="http://samat.org/weblog/20060628-a-quick-shell-include-for-setting-paths-for-programs-installed-in-non-traditional-locations.html" />
    <id>http://samat.org/weblog/20060628-a-quick-shell-include-for-setting-paths-for-programs-installed-in-non-traditional-locations.html</id>
    <published>2006-06-28T09:34:05-06:00</published>
    <updated>2006-10-26T13:42:16-06:00</updated>
    <author>
      <name>Samat Jain</name>
    </author>
    <category term="Article" />
    <category term="Bash Shell" />
    <category term="Linux" />
    <category term="Python" />
    <summary type="html"><![CDATA[<p>A <a href="http://www.linuxfromscratch.org/blfs/view/stable/introduction/beyond.html">page in the Beyond Linux from Scratch manual</a> describes environment variables that should be set when installing software in a non-traditional location (e.g. your home directory).</p>
<p>I've written a sh/bash include that can be included from .bashrc to set these variables, as well as PYTHON_PATH for separately installed Python libraries:</p>
<p>
<div class="codeblock"><code>#!/bin/bash&lt;br /&gt;&lt;br /&gt;PREFIX=$HOME/usr&lt;br /&gt;&lt;br /&gt;export PATH=&amp;quot;$PREFIX/bin:$PATH&amp;quot;&lt;br /&gt;export PYTHONPATH=&amp;quot;$PREFIX/lib/python2.4/site-packages:$PYTHON_PATH&amp;quot;&lt;br /&gt;export MANPATH=&amp;quot;$PREFIX/man:$MANPATH&amp;quot;&lt;br /&gt;export INFOPATH=&amp;quot;$PREFIX/info:$INFOPATH&amp;quot;&lt;br /&gt;export LD_LIBRARY_PATH=&amp;quot;$PREFIX/lib:$LD_LIBRARY_PATH&amp;quot;&lt;br /&gt;export PKG_CONFIG_PATH=&amp;quot;$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH&amp;quot;&lt;br /&gt;export CPPFLAGS=&amp;quot;-I$PREFIX/includes $CPPFLAGS&amp;quot;&lt;br /&gt;export LDFLAGS=&amp;quot;-L$PREFIX/lib $LDFLAGS&amp;quot;</code></div>
</p>
    ]]></summary>
  </entry>
  <entry>
    <title>A take on Drupal&#039;s taxonomy system from the Plone/Python camp</title>
    <link rel="alternate" type="text/html" href="http://samat.org/weblog/20060602-a-take-on-drupals-taxonomy-system-from-the-plone-python-camp.html" />
    <id>http://samat.org/weblog/20060602-a-take-on-drupals-taxonomy-system-from-the-plone-python-camp.html</id>
    <published>2006-06-02T04:23:13-06:00</published>
    <updated>2006-06-02T04:28:46-06:00</updated>
    <author>
      <name>Samat Jain</name>
    </author>
    <category term="Drupal" />
    <category term="Python" />
    <category term="Web link" />
    <summary type="html"><![CDATA[<p>Over at the Plone Blog is the article <a href="http://theploneblog.org/blog/archive/2006/05/31/death-and-taxonomies">Death  and Taxonomies</a>; it reviews <a href="http://drupal.org/">Drupal's</a> taxonomy (aka category) system.</p>

<p>The author basically comes to the conclusion I have, a conclusion that is shared by many in the Drupal community but not so much outside of it: <strong>Drupal's taxonomy system is <em>amazing</em></strong>.</p>

<p>For most people and their uses, it is completely overengineered and complicated to use. This fits into Drupal's marketing stance that it is a content management framework rather than just a <acronym title="content management system">CMS</acronym>. It is very generic, and with some custom programming can be adapted to anything--the possibilities are limitless. With many web development projects (that I don't want to write in PHP) I think about, I wish I had the facility of Drupal's taxonomy system.</p>

<p>Of course, there are problems, which the review goes into: there are too many hierarchal relationships in Drupal, all competing with each other. There is the menu system, the book module, and hierarchal taxonomies. The key to being a Drupal master is know when to use which and how to use them, something I've definitely not mastered. And that is part of the problem--why should you need to?</p>
    ]]></summary>
  </entry>
  <entry>
    <title>Calculating bandwidth from a combined-format web server log</title>
    <link rel="alternate" type="text/html" href="http://samat.org/weblog/20060525-calculating-bandwidth-from-a-combined-format-web-server-log.html" />
    <id>http://samat.org/weblog/20060525-calculating-bandwidth-from-a-combined-format-web-server-log.html</id>
    <published>2006-05-25T03:03:21-06:00</published>
    <updated>2008-10-04T09:05:30-06:00</updated>
    <author>
      <name>Samat Jain</name>
    </author>
    <category term="Apache" />
    <category term="Article" />
    <category term="Python" />
    <summary type="html"><![CDATA[<p>Given a combined web server access log, such as the ones generated by Apache, it can be useful to know the total amount of data transfer of all requests in that log. This task is simple: extract the field listing the number of bytes sent for a request, and add them all up. For something so simple, there is an odd lack of examples or pre-made scripts that do this. Or, at least, I couldn’t find any.</p>

<p>I wrote my solution, calculate-data-transfer.py, in Python:</p>
    ]]></summary>
  </entry>
  <entry>
    <title>A better way to separate Apache log files by virtual host domains</title>
    <link rel="alternate" type="text/html" href="http://samat.org/weblog/20060523-a-better-way-to-separate-apache-log-files-by-virtual-host-domains.html" />
    <id>http://samat.org/weblog/20060523-a-better-way-to-separate-apache-log-files-by-virtual-host-domains.html</id>
    <published>2006-05-23T02:02:00-06:00</published>
    <updated>2006-05-23T23:20:57-06:00</updated>
    <author>
      <name>Samat Jain</name>
    </author>
    <category term="Apache" />
    <category term="Article" />
    <category term="Python" />
    <summary type="html"><![CDATA[<p>Apache's "combined" log format is one the most common log formats used in <a href="http://httpd.apache.org/docs/2.0/logs.html#accesslog">access logging</a>, containing useful fields such as referrer and user agent. Unfortunately, it does not contain a field listing the the virtual host for whom a request was formed. With Apache, this is easily rectified by defining a custom logging format and post-processing logs to maintain compatibility.</p>
    ]]></summary>
  </entry>
</feed>
