Fix AttributeError in irclogsearch on Python 2.7

Fixes https://github.com/mgedmin/irclog2html/issues/1

Also fix UnicodeError I saw while testing with

  LC_ALL=C IRCLOG_LOCATION=testcases QUERY_STRING=q=ą bin/irclogsearch

The code to deal with all this mess is rather ugly, but better ugly and
working than beautiful and broken.