diff --git a/swift/common/db.py b/swift/common/db.py index 69466a1a15..3245ffcbf2 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -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: