Skip to main content

3 posts tagged with "python"

View All Tags

· 2 min read

According to the Apache URL rewriting guide, the way to handle Canonical Hostnames is like this:

RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*)$1 [L,R]

Well, those rules are not always sufficient. Specifically, what if you also owned the domain, and wished to redirect it also to the primary domain? The solution is simple - we just need to add a single $ character to the end of the match-pattern of the first RewriteCond like this:

RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*)$1 [L,R]

Now that will work nicely as long as the hosts use standard ports (ie 80 for HTTP, and 443 for HTTPS). However, some Python versions unnecessarily append the standard HTTPS port number to the Host HTTP header. Also I discovered today (after some Apache debug logging) that Adobe AIR applications have the exact same misbehavior for HTTPS, but only when running under Mac OS X.

· 2 min read

I've been using the excellent PyODConverter (aka Python OpenDocument Converter) for quite some time now. It's a very small Python script that uses OpenOffice's Python-UNO bridge to convert documents between formats. For example, to convert test.doc to a PDF file, you could execute:

python test.doc test.pdf

For the Python-UNO bridge (and thus PyODConverter) to work, you do need to use the python binary that installs with OpenOffice, so you will most likely need to full-qualify the python command like:

/opt/openoffice.org3/program/python test.doc test.pdf

Anyway, PyODConverter always tries to talk to OpenOffice via (the somewhat arbitrary) port 8100. But today I found myself needing to able to tell PyODConverter which port to use via the command line. So, I went about modifying the PyODConverter code - which was very easy, thanks to it being already very well written.

· One min read

I had a really frustrating time yesterday, trying to sort out some bugs in IBM's ibm_db DB2 driver for Python. Unfortunately I don't know Python well enough to know whether the bugs are in the ibm_db driver, Python, or my misuse if either or both :( But what I can tell you, is that the following Python / ibm_db code results in a definite memory leak.

sql = "SELECT filename, data FROM files WHERE id = ... ";
stmt = ibm_db.exec_immediate(conn,sql);
row = ibm_db.fetch_assoc(stmt);
row.clear(); # Just to be sure.

I've started a discussion on the memory leak issue over at the ibm_db group (on Google Groups), so it will be interesting to see what transpires :) But all I can say at this stage is this: IBM's ibm_db DB2 driver for Python seems only half baked, currently. To be fair though, it is still officially in Beta.