Victory

After several iterations of arguing the denials of my request for lxml to be installed as a Python egg, my web host finally acquiesced.

I think I’m going to print this out and get it framed:

Hello,

I apologize for the delay. We were able to install this for you:

xxxxxxx@xxxxxxxx.net [~/lxml-3.3.5]# CFLAGS=”-O0″ easy_install –install-dir=/xxxxx/xxxxxxx/xxxxx/xxxxxxx/python2.6/site-packages lxml
Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Best match: lxml 3.3.5
Downloading https://pypi.python.org/packages/source/l/lxml/lxml-3.3.5.tar.gz#md5=88c75f4c73fc8f59c9ebb17495044f2f
Processing lxml-3.3.5.tar.gz
Running lxml-3.3.5/setup.py -q bdist_egg –dist-dir /tmp/easy_install-qdMwRH/lxml-3.3.5/egg-dist-tmp-bZ_ZZT
Building lxml version 3.3.5.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib64
/usr/lib64/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: ‘bugtrack_url’
warnings.warn(msg)
Adding lxml 3.3.5 to easy-install.pth file

Installed /xxxxx/xxxxxxx/xxxxx/xxxxxxx/python2.6/site-packages/lxml-3.3.5-py2.6-linux-x86_64.egg
Processing dependencies for lxml
Finished processing dependencies for lxml
———————————————-

Lambda lambda lambda

It can help ya help ya help ya.

It’s Python’s lambda function1! Pesky urllib2 not allowing you to construct a DELETE request? Environment Overlords not letting you install a sane http module like Requests2? Don’t like what a module you have no control over is doing for you?

Lambda the damn thing!

For example urllib2 has a method called .get_method(). It returns the type of HTML request being made. In their infinite wisdom, the writers of urllib2 thought there were only two useful types of request anyone would ever want to make using their module, GET and PUT. The method looks at the URL and if it sees post data it returns “POST”. Otherwise it returns “GET”.

But it’s a modern Web we live in and we want to do modern things like make calls against a RESTful api provided by a vendor. Sometimes that vendor uses the kind of request being sent to determine the kind of action to take. Makes sense, no? But urllib2 spits on us and makes us write bad checks. What shall we do?

In this case we just hack the bejesus out of the .get_method() method and force it to return “DELETE” every time.


import urllib2
req = urllib2.Request( "http://www.example.com" )
req.get_method = lambda: "DELETE"

Now we can run DELETE requests against the RESTful API all damn day long. And then, later, when we want to do a “GET” all we have to do is lambda the damn thing again and make it return “GET”. Yay for us!

Yay for lambdas!

This is my rose for the day.

1http://www.secnetix.de/olli/Python/lambda_functions.hawk
2http://docs.python-requests.org/en/latest/

Ubuntu Oddity

I’ve been using Ubuntu server edition for my end-of-lifecycle PC turned headless web/file server for the past year and change. For the most part I like it. What you lose in hardware-specific tuning in Gentoo you generally more than make up for in easy of install and use. I rather like Gentoo’s portage and have since come to appreciate the utility of apt-get. What I don’t like, however, is Unbuntu / Debian’s insistence on renaming popular modules in what I would assume is some misguided attempt at making the whole OS human readable.

For example, I spent an unreasonable amount of time yesterday hunting for PyXML, a bog-standard and widely used 3rd party Python module. It wasn’t until I finally decided to step outside the apt-get process and install myself from source that I found a reference indicating that PyXML is actually referred to as python-xml in Ubuntu.

In the grand scheme of things, it rates a meh. Still, there is always a small window of opportunity for programming projects on the weekend and the more time I have to spend configging my environment, the less time and energy I have for doing what it is I want. If you’re going to fudge with the package names, please include a thesaurus.

That is all.