Use binascii.b2a_hex instead of hand-tweaked string concatenation

This is a major performance win for parsing.
Optimze _read_until_keywords a little

- use an unconditional function call in the inner loop rather than
checking whether content is set all the time.  This saves a few percent.

- use a compiled regex to determine whether we have found the target
keywords.  This is a fairly big win fwict.  Perhaps this regex can be tuned
further?
Using a constant for line regex we match against

Just a minor tweak so the regex we use is with the others for descriptor
content.
Improve parsing speed for consensus documents

Improvements from Nick so we can parse consensus documents faster (and to a
lesser extent other document types). This reduces the parse type by around 30%
according to cProfile.

  https://trac.torproject.org/12859
Fixing E713 (test for membership should be 'not in')

Correcting several instances where we do...

  if not X in Y:

... rather than...

  if X not in Y:
Fixing E265 (block comment should start with '# ')

Couple instances where we don't have whitespace after '#'.
Fixing E126 (continuation line over-indented for hanging indent)

Evidently PEP8 doesn't like our multi-line imports. That's fine, the
parenthetical imports are just as readable.
Fixing E128 (continuation line under-indented for visual indent)

Mostly complaints about alignment with the parenthese for multi-line
conditionals.
Ignoring E131 (continuation line unaligned for hanging indent)

This check is based on four space indentations so skipping it.
Fixing pyflakes issues

Couple finds from the new version of pyflakes...

  * /home/atagar/Desktop/stem/stem/descriptor/server_descriptor.py
    line 543  - list comprehension redefines 'value' from line 374

  * /home/atagar/Desktop/stem/stem/util/test_tools.py
    line 175  - local variable 'prev_indent' is assigned to but never used
Stylistic issues from pep8 1.5.7

New version of pep8 and pyflakes reports some new issues. Addressing them.
Correcting doctest failure for python3

Our 2to3 python conversion understandably doesn't convert examples on our
comments. As a result doctest choked when processing a python 2.x print
statement...

**********************************************************************
File "/home/atagar/Desktop/stem/test/data/python3/stem/version.py", line 12, in version.py
Failed example:
    print my_version
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.2/doctest.py", line 1288, in __run
        compileflags, 1), test.globs)
      File "<doctest version.py[2]>", line 1
        print my_version
                       ^
    SyntaxError: invalid syntax
**********************************************************************
1 items had failures:
   1 of   4 in version.py
***Test Failed*** 1 failures.
**********************************************************************
Unit tests for connection.connect failed under python 3.x

Weird oddity with how StringIO works with python 3.x. This is a new regression
after reinstalling my system so probably specific to the version of python 3.x
I'm using.
Correcting python 3.x regression for descriptor parsing

Our recent b2ahex broke python 3.x because we expect fingerprints to be a str
or unicode, not bytes...

======================================================================
ERROR: test_ns_event
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/atagar/Desktop/stem/test/data/python3/test/unit/response/events.py", line 796, in test_ns_event
    's': 'Fast HSDir Named Stable V2Dir Valid',
  File "/home/atagar/Desktop/stem/test/data/python3/test/mocking.py", line 479, in get_router_status_entry_v3
    return stem.descriptor.router_status_entry.RouterStatusEntryV3(desc_content, validate = True)
  File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 344, in __init__
    super(RouterStatusEntryV3, self).__init__(content, validate, document)
  File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 161, in __init__
    self._parse(entries, validate)
  File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 351, in _parse
    _parse_r_line(self, value, validate, True)
  File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 514, in _parse_r_line
    desc.fingerprint = _base64_to_hex(r_comp[1], validate)
  File "/home/atagar/Desktop/stem/test/data/python3/stem/descriptor/router_status_entry.py", line 733, in _base64_to_hex
    raise ValueError("Decoded '%s' to be '%s', which isn't a valid fingerprint" % (identity, fingerprint))
ValueError: Decoded 'dbBxYcJriTTrcxsuy4PUZcMRwCA===' to be 'b'75B07161C26B8934EB731B2ECB83D465C311C020'', which isn't a valid fingerprint

----------------------------------------------------------------------
Fixing unit tests for python 3.x

Unit test runs for python 3.x (run_tests.py --unit --python3) were bused for a
few reasons. Some seem to be interpreter version related, but another was a
recent regression.
Correcting StatusEvent's docs and adding an 'arguments' attribute

Our StatusEvent class misdocumented its 'action' argument as being called
'message'. Also, it wasn't clear that it commonly had keyword arguments
available. Technically they were available since the parent class supplied
these in its keyword_args attribute, but adding an alias for that to the
StatusEvent to make it clear that they're usually provided.

Issues caught by sysrqb on...

  https://trac.torproject.org/12925
Don't fail validation if consensus method 1 isn't present

Change from proposal 215. Tor no longer requires that consensus method 1 is
around as a fallback. Pointed out thanks to Sebastian.
Example for getting number of relays a bw auth has a measurement for

Including a script I just whipped up for Sebastian to see if there was an issue
with the bandwidth authorities. This gives a fine spot to describe a bit more
about how the Tor network works.
Adding crop() method to our str_tools

Method from arm's ui_tools with a little cleanup. This is a pretty delicate
method and I'm a tad worried about some changes so we might see some regression
from what arm had. That said, regressions can easily be added to our unit tests
(it'll be soooo nice to finally have those for this helper....).
connection_time() method for the BaseController

Adding a connection_time() to our ControlSocket and BaseController to provide
when we either connected or disconnected from the socket.