Ensure parameters sent to db are utf8 strs

Change-Id: I45952adfcfbc813477ee9966f05dcdeef23c683b
This commit is contained in:
gholt 2012-08-02 14:49:02 +00:00
parent d2b51dd2b6
commit ef3f8bb335

View File

@ -47,6 +47,10 @@ PICKLE_PROTOCOL = 2
PENDING_CAP = 131072
def utf8encode(*args):
return [(s.encode('utf8') if isinstance(s, unicode) else s) for s in args]
class DatabaseConnectionError(sqlite3.DatabaseError):
"""More friendly error messages for DB Errors."""
@ -1062,6 +1066,8 @@ class ContainerBroker(DatabaseBroker):
:returns: list of tuples of (name, created_at, size, content_type,
etag)
"""
(marker, end_marker, prefix, delimiter, path) = utf8encode(
marker, end_marker, prefix, delimiter, path)
try:
self._commit_puts()
except LockTimeout:
@ -1102,8 +1108,6 @@ class ContainerBroker(DatabaseBroker):
if prefix is None:
return [r for r in curs]
if not delimiter:
if isinstance(prefix, unicode):
prefix = prefix.encode("utf-8")
return [r for r in curs if r[0].startswith(prefix)]
rowcount = 0
for row in curs:
@ -1557,6 +1561,8 @@ class AccountBroker(DatabaseBroker):
:returns: list of tuples of (name, object_count, bytes_used, 0)
"""
(marker, end_marker, prefix, delimiter) = utf8encode(
marker, end_marker, prefix, delimiter)
try:
self._commit_puts()
except LockTimeout: