From 1fc46a0e13eff5603ba0c26d98407e3012d9de42 Mon Sep 17 00:00:00 2001 From: Lokesh S Date: Thu, 21 Jul 2016 15:41:58 +0000 Subject: [PATCH] py3: Fixes encoding and type error Fixes encoding bytes to base64. Fixes unorderedtype int() and str() for python3. Fixes encoding issues. Change-Id: I6e7aaf21e080078d4b36562e41129804d71df2fc --- swift/account/backend.py | 10 ++++++---- swift/common/middleware/acl.py | 2 +- test/unit/account/test_backend.py | 19 ++++++++++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/swift/account/backend.py b/swift/account/backend.py index 4726a0bd1f..31f6470b99 100644 --- a/swift/account/backend.py +++ b/swift/account/backend.py @@ -254,7 +254,7 @@ class AccountBroker(DatabaseBroker): :param bytes_used: number of bytes used by the container :param storage_policy_index: the storage policy for this container """ - if delete_timestamp > put_timestamp and \ + if Timestamp(delete_timestamp) > Timestamp(put_timestamp) and \ object_count in (None, '', 0, '0'): deleted = 1 else: @@ -501,12 +501,14 @@ class AccountBroker(DatabaseBroker): for i in range(5): if record[i] is None and row[i] is not None: record[i] = row[i] - if row[1] > record[1]: # Keep newest put_timestamp + if Timestamp(row[1]) > \ + Timestamp(record[1]): # Keep newest put_timestamp record[1] = row[1] - if row[2] > record[2]: # Keep newest delete_timestamp + if Timestamp(row[2]) > \ + Timestamp(record[2]): # Keep newest delete_timestamp record[2] = row[2] # If deleted, mark as such - if record[2] > record[1] and \ + if Timestamp(record[2]) > Timestamp(record[1]) and \ record[3] in (None, '', 0, '0'): record[5] = 1 else: diff --git a/swift/common/middleware/acl.py b/swift/common/middleware/acl.py index c3f70729d3..c23e89284c 100644 --- a/swift/common/middleware/acl.py +++ b/swift/common/middleware/acl.py @@ -142,7 +142,7 @@ def format_acl_v1(groups=None, referrers=None, header_name=None): def format_acl_v2(acl_dict): - """ + r""" Returns a version-2 Swift ACL JSON string. HTTP headers for Version 2 ACLs have the following form: diff --git a/test/unit/account/test_backend.py b/test/unit/account/test_backend.py index 28d649987c..e9a5c51752 100644 --- a/test/unit/account/test_backend.py +++ b/test/unit/account/test_backend.py @@ -30,6 +30,7 @@ import itertools from contextlib import contextmanager import random import mock +import base64 from swift.account.backend import AccountBroker from swift.common.utils import Timestamp @@ -801,13 +802,13 @@ class TestAccountBroker(unittest.TestCase): broker = AccountBroker(broker_path, account='real') broker.initialize(Timestamp(1).internal) with open(broker.pending_file, 'a+b') as pending: - pending.write(':') - pending.write(pickle.dumps( + pending.write(b':') + pending.write(base64.b64encode(pickle.dumps( # name, put_timestamp, delete_timestamp, object_count, # bytes_used, deleted ('oldcon', Timestamp(200).internal, Timestamp(0).internal, - 896, 9216695, 0)).encode('base64')) + 896, 9216695, 0)))) broker._commit_puts() with broker.get() as conn: @@ -830,13 +831,13 @@ class TestAccountBroker(unittest.TestCase): stale_reads_ok=True) broker.initialize(Timestamp(1).internal) with open(broker.pending_file, 'a+b') as pending: - pending.write(':') - pending.write(pickle.dumps( + pending.write(b':') + pending.write(base64.b64encode(pickle.dumps( # name, put_timestamp, delete_timestamp, object_count, # bytes_used, deleted ('oldcon', Timestamp(200).internal, Timestamp(0).internal, - 896, 9216695, 0)).encode('base64')) + 896, 9216695, 0)))) broker._commit_puts = mock_commit_puts broker.get_info() @@ -852,13 +853,13 @@ class TestAccountBroker(unittest.TestCase): stale_reads_ok=False) broker.initialize(Timestamp(1).internal) with open(broker.pending_file, 'a+b') as pending: - pending.write(':') - pending.write(pickle.dumps( + pending.write(b':') + pending.write(base64.b64encode(pickle.dumps( # name, put_timestamp, delete_timestamp, object_count, # bytes_used, deleted ('oldcon', Timestamp(200).internal, Timestamp(0).internal, - 896, 9216695, 0)).encode('base64')) + 896, 9216695, 0)))) broker._commit_puts = mock_commit_puts