Python port

I don't have a Ruby environment on the logstash server so I ported the code to Python.  I've tried to respect the Ruby implementation as closely as possible.