BUG: Fix str/unicode warnings from SQLAlchemy on python 2.

When running with `reset_db=True` on python 2, several SQLAlchemy operations
were performed with bytes where unicode was expected, resulting in
warnings like the following.

```
/home/ssanderson/.virtualenvs/jupyterhub/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py:573:
SAWarning: Unicode type received non-unicodebind param value.
  param.append(processors[key](compiled_params[key]))
```

Fixes a few stray non-unicode literals and adds a unicode safe wrapper
for `getpass.getuser`.
This commit is contained in:
Scott Sanderson
2014-10-25 17:46:25 -04:00
parent fa7250ecc3
commit a34d514d66
3 changed files with 20 additions and 10 deletions

View File

@@ -4,9 +4,12 @@
# Distributed under the terms of the Modified BSD License.
import binascii
import getpass
import errno
import os
import socket
from six import text_type
from tornado import web, gen, ioloop
from tornado.httpclient import AsyncHTTPClient, HTTPError
from tornado.log import app_log
@@ -21,6 +24,14 @@ except NameError:
class TimeoutError(Exception):
pass
def getuser_unicode():
"""
Call getpass.getuser, ensuring that the output is returned as unicode.
"""
return text_type(getpass.getuser())
def random_port():
"""get a single random port"""
sock = socket.socket()