Random Password Generator

I’ve been seeing a lot of this lately on ActiveState Code Recipes; Random Password Generators written in Python. Well I thought I’d get in on this and share one I’ve been using for many years, but mostly because I’m finding “Blogging” to be quite fun! This recipe is also a part of my very old pymills repository of useful modules and routines I’ve either written or collected. You might find bits and pieces of my library useful. [Read More]

Unpacking and Conditional Expressions

Unpacking tuples and conditional expressions in Python.

The other day whilst working on a web crawler at work called spyda I came across an interesting behavior in Python. Here it goes: >>> xs = [(1, 2), (3, 4)] >>> a, b = xs[0] if xs else None, None >>> a (1, 2) >>> b Notice that a becomes the first tuple in the list and b becomes None? This kinda got me stumped at first until I realized what was happening with the Python parser. [Read More]

Introducing the circuits team

Lately circuits has seen some presence in the wild and this is a good thing for the project. Just the other day Crunch.io posted a job advert on the Python Job Board in need of a RESTful Web Developer to designer and build their public API(s). Naturally I sent them an email asking if they’d like to hire the lead developer of circuits (that’s me!) :) I thought it was about time I setup a circuits team repository on bitbucket to make things a little more prominent. [Read More]

Python Websockets Server with Circuits

Today marks the release of circuits-1.5 which brings to the circuits application framework a new circuits.web dispatcher. The WebSockets dispatcher This dispatcher allows you to build a web application that is capable of accepting WebSockets client connections on the same process/thread. Using circuits-1.5 here is a very simple Web Application that has WebSockets support and echos back every message it recieves: index.html: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. [Read More]

Worker Pools with Circuits

For some time now I’ve been wanting to greatly improve the concurrency support in circuits and implement worker pools (using threads and/or processes). A few weeks ago I finally did that. I thought it would be hard at first until it hit me; circuits has all the tools necessary It turns out implementing “worker pools” in circuits is quite simple. All you need to do is construct a component that will start a number of other components as workers (either in thread mode or process mode). [Read More]

Testing With Mox

Last week I discovered the mocking library mox. I had previously known about the concept of mocking but had no experience in writing tests that mocked anything out… We use mocks quite a bit where I work and it was while implementing new functionality into our software that I learned also to write tests that used mocks (using the mox library/framework). The most challenging concept with mocking in general was deciding what to mock and what not to mock and how you should structure your test. [Read More]