Rework, simplify and document Livestatus.query()

This patch is a rewrite of Livestatus.query() was badly tested and had many undocumented hacks.

This patch includes:
* A new class LivestatusQuery that helps with constructing livestatus queries in a safe manner
* A new method Livestatus.write() for writing directly to a livestatus socket
* A new method Livestatus.raw_query() which makes it easy to query livestatus and get raw response back
* A complete rewrite of Livestatus.query() which uses all the new items mentioned above.

Please review and give feedback.