Filed under

Python

Persuading Paste HTTP server to use correct REMOTE_ADDR

Configuring reverse proxy headers was on bottom of my TODO list because I never felt it was important for my applications. Today I tried to fuddle with nginx to pass those headers but it gave me a headache. For sake of reference and because I'm sure many others tripped on this one, here is what I figured out from mailing lists and source code (please inform me of a better, straight forward way if there is one):

Read article

Joining strings in Python

There is already a lot of good material to read about performance. Therefore, it is best to use the following method: >>> print ' '.join(['The', 'fox', 'jumped', 'over', 'the', 'dog.']) The fox jumped over the dog. Perfect. We have very fast string contatenation that even allows us to choose separator. Now, here is the problem: >>> print ', '.join(['apples', 'oranges', '', 'cocos']) apples, oranges, , cocos So, if we dynamically generate string and we have a separator for a reason, we do not want this to happen. This is basically the idea:

Read article

Mocking logging module for unittests

Today I was writing tests for upcoming application I'm writing (more information will come later) and I needed some way to redirect logging to some kind of storage that could be easily asserted to values in tests. First I tried with monkey patching it, but that wasn't the solution since all logging setup is done before pylons tests come to play, so somebody in IRC pointed me toward writing a handler. I thought to do so in the first place, but were too stubborn;)

Read article