From 9430f4c9f5e79026f7275f8ec32ef4a180c5e8fc Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Wed, 2 Mar 2016 10:28:51 +0000 Subject: [PATCH] Move HeaderKeyDict to avoid an inline import There was a function in swift.common.utils that was importing swob.HeaderKeyDict at call time. It couldn't import it at compilation time since utils can't import from swob or else it blows up with a circular import error. This commit just moves HeaderKeyDict into swift.common.header_key_dict so that we can remove the inline import. Change-Id: I656fde8cc2e125327c26c589cf1045cb81ffc7e5 --- swift/common/direct_client.py | 2 +- swift/common/header_key_dict.py | 63 +++++++++++++++++ swift/common/middleware/tempurl.py | 5 +- swift/common/swob.py | 48 +------------ swift/common/utils.py | 2 +- swift/container/server.py | 3 +- swift/obj/reconstructor.py | 2 +- swift/obj/server.py | 5 +- swift/proxy/controllers/base.py | 3 +- swift/proxy/controllers/obj.py | 3 +- test/unit/__init__.py | 7 +- test/unit/account/test_utils.py | 2 +- test/unit/common/middleware/helpers.py | 7 +- test/unit/common/middleware/test_bulk.py | 3 +- test/unit/common/middleware/test_dlo.py | 51 +++++++------- test/unit/common/middleware/test_slo.py | 59 ++++++++-------- test/unit/common/middleware/test_tempurl.py | 3 +- test/unit/common/test_direct_client.py | 3 +- test/unit/common/test_header_key_dict.py | 75 +++++++++++++++++++++ test/unit/common/test_internal_client.py | 3 +- test/unit/common/test_swob.py | 58 ---------------- test/unit/common/test_utils.py | 3 +- test/unit/container/test_reconciler.py | 3 +- test/unit/container/test_server.py | 4 +- test/unit/obj/test_reconstructor.py | 2 +- test/unit/obj/test_server.py | 3 +- test/unit/obj/test_updater.py | 8 +-- test/unit/proxy/controllers/test_base.py | 4 +- test/unit/proxy/controllers/test_obj.py | 3 +- test/unit/proxy/test_server.py | 3 +- 30 files changed, 246 insertions(+), 194 deletions(-) create mode 100644 swift/common/header_key_dict.py create mode 100644 test/unit/common/test_header_key_dict.py diff --git a/swift/common/direct_client.py b/swift/common/direct_client.py index 96f2579de0..0dea8acefc 100644 --- a/swift/common/direct_client.py +++ b/swift/common/direct_client.py @@ -33,7 +33,7 @@ from swift.common.exceptions import ClientException from swift.common.utils import Timestamp, FileLikeIter from swift.common.http import HTTP_NO_CONTENT, HTTP_INSUFFICIENT_STORAGE, \ is_success, is_server_error -from swift.common.swob import HeaderKeyDict +from swift.common.header_key_dict import HeaderKeyDict from swift.common.utils import quote diff --git a/swift/common/header_key_dict.py b/swift/common/header_key_dict.py new file mode 100644 index 0000000000..fc67bb0f29 --- /dev/null +++ b/swift/common/header_key_dict.py @@ -0,0 +1,63 @@ +# Copyright (c) 2010-2012 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import six + + +class HeaderKeyDict(dict): + """ + A dict that title-cases all keys on the way in, so as to be + case-insensitive. + """ + def __init__(self, base_headers=None, **kwargs): + if base_headers: + self.update(base_headers) + self.update(kwargs) + + def update(self, other): + if hasattr(other, 'keys'): + for key in other.keys(): + self[key.title()] = other[key] + else: + for key, value in other: + self[key.title()] = value + + def __getitem__(self, key): + return dict.get(self, key.title()) + + def __setitem__(self, key, value): + if value is None: + self.pop(key.title(), None) + elif isinstance(value, six.text_type): + return dict.__setitem__(self, key.title(), value.encode('utf-8')) + else: + return dict.__setitem__(self, key.title(), str(value)) + + def __contains__(self, key): + return dict.__contains__(self, key.title()) + + def __delitem__(self, key): + return dict.__delitem__(self, key.title()) + + def get(self, key, default=None): + return dict.get(self, key.title(), default) + + def setdefault(self, key, value=None): + if key not in self: + self[key] = value + return self[key] + + def pop(self, key, default=None): + return dict.pop(self, key.title(), default) diff --git a/swift/common/middleware/tempurl.py b/swift/common/middleware/tempurl.py index b71df51c35..7fece15b34 100644 --- a/swift/common/middleware/tempurl.py +++ b/swift/common/middleware/tempurl.py @@ -169,8 +169,9 @@ from six.moves.urllib.parse import parse_qs from six.moves.urllib.parse import urlencode from swift.proxy.controllers.base import get_account_info, get_container_info -from swift.common.swob import HeaderKeyDict, header_to_environ_key, \ - HTTPUnauthorized, HTTPBadRequest +from swift.common.header_key_dict import HeaderKeyDict +from swift.common.swob import header_to_environ_key, HTTPUnauthorized, \ + HTTPBadRequest from swift.common.utils import split_path, get_valid_utf8_str, \ register_swift_info, get_hmac, streq_const_time, quote diff --git a/swift/common/swob.py b/swift/common/swob.py index c7c9afe358..98ee37278e 100644 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -50,6 +50,7 @@ from six import BytesIO from six import StringIO from six.moves import urllib +from swift.common.header_key_dict import HeaderKeyDict from swift.common.utils import reiterate, split_path, Timestamp, pairs, \ close_if_possible from swift.common.exceptions import InvalidTimestamp @@ -271,53 +272,6 @@ class HeaderEnvironProxy(MutableMapping): return keys -class HeaderKeyDict(dict): - """ - A dict that title-cases all keys on the way in, so as to be - case-insensitive. - """ - def __init__(self, base_headers=None, **kwargs): - if base_headers: - self.update(base_headers) - self.update(kwargs) - - def update(self, other): - if hasattr(other, 'keys'): - for key in other.keys(): - self[key.title()] = other[key] - else: - for key, value in other: - self[key.title()] = value - - def __getitem__(self, key): - return dict.get(self, key.title()) - - def __setitem__(self, key, value): - if value is None: - self.pop(key.title(), None) - elif isinstance(value, six.text_type): - return dict.__setitem__(self, key.title(), value.encode('utf-8')) - else: - return dict.__setitem__(self, key.title(), str(value)) - - def __contains__(self, key): - return dict.__contains__(self, key.title()) - - def __delitem__(self, key): - return dict.__delitem__(self, key.title()) - - def get(self, key, default=None): - return dict.get(self, key.title(), default) - - def setdefault(self, key, value=None): - if key not in self: - self[key] = value - return self[key] - - def pop(self, key, default=None): - return dict.pop(self, key.title(), default) - - def _resp_status_property(): """ Set and retrieve the value of Response.status diff --git a/swift/common/utils.py b/swift/common/utils.py index 66f6ad777b..9547bf8f6a 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -68,6 +68,7 @@ from swift import gettext_ as _ import swift.common.exceptions from swift.common.http import is_success, is_redirection, HTTP_NOT_FOUND, \ HTTP_PRECONDITION_FAILED, HTTP_REQUESTED_RANGE_NOT_SATISFIABLE +from swift.common.header_key_dict import HeaderKeyDict if six.PY3: stdlib_queue = eventlet.patcher.original('queue') @@ -3648,7 +3649,6 @@ def parse_mime_headers(doc_file): :param doc_file: binary file-like object containing a MIME document :returns: a swift.common.swob.HeaderKeyDict containing the headers """ - from swift.common.swob import HeaderKeyDict # avoid circular import headers = [] while True: line = doc_file.readline() diff --git a/swift/container/server.py b/swift/container/server.py index 7e24bd4e50..92bb595e8f 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -41,10 +41,11 @@ from swift.common.exceptions import ConnectionTimeout from swift.common.http import HTTP_NOT_FOUND, is_success from swift.common.storage_policy import POLICIES from swift.common.base_storage_server import BaseStorageServer +from swift.common.header_key_dict import HeaderKeyDict from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPConflict, \ HTTPCreated, HTTPInternalServerError, HTTPNoContent, HTTPNotFound, \ HTTPPreconditionFailed, HTTPMethodNotAllowed, Request, Response, \ - HTTPInsufficientStorage, HTTPException, HeaderKeyDict + HTTPInsufficientStorage, HTTPException def gen_resp_headers(info, is_deleted=False): diff --git a/swift/obj/reconstructor.py b/swift/obj/reconstructor.py index 151c00c1e7..e2ad368344 100644 --- a/swift/obj/reconstructor.py +++ b/swift/obj/reconstructor.py @@ -32,7 +32,7 @@ from swift.common.utils import ( whataremyips, unlink_older_than, compute_eta, get_logger, dump_recon_cache, mkdirs, config_true_value, list_from_csv, get_hub, tpool_reraise, GreenAsyncPile, Timestamp, remove_file) -from swift.common.swob import HeaderKeyDict +from swift.common.header_key_dict import HeaderKeyDict from swift.common.bufferedhttp import http_connect from swift.common.daemon import Daemon from swift.common.ring.utils import is_local_device diff --git a/swift/obj/server.py b/swift/obj/server.py index ac3c7f39e5..5fdcd56a5f 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -44,14 +44,15 @@ from swift.common.exceptions import ConnectionTimeout, DiskFileQuarantined, \ from swift.obj import ssync_receiver from swift.common.http import is_success from swift.common.base_storage_server import BaseStorageServer +from swift.common.header_key_dict import HeaderKeyDict from swift.common.request_helpers import get_name_and_placement, \ is_user_meta, is_sys_or_user_meta from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPCreated, \ HTTPInternalServerError, HTTPNoContent, HTTPNotFound, \ HTTPPreconditionFailed, HTTPRequestTimeout, HTTPUnprocessableEntity, \ HTTPClientDisconnect, HTTPMethodNotAllowed, Request, Response, \ - HTTPInsufficientStorage, HTTPForbidden, HTTPException, HeaderKeyDict, \ - HTTPConflict, HTTPServerError + HTTPInsufficientStorage, HTTPForbidden, HTTPException, HTTPConflict, \ + HTTPServerError from swift.obj.diskfile import DATAFILE_SYSTEM_META, DiskFileRouter diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index fc36d9dfae..e25620c58e 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -47,11 +47,12 @@ from swift.common.utils import Timestamp, config_true_value, \ from swift.common.bufferedhttp import http_connect from swift.common.exceptions import ChunkReadTimeout, ChunkWriteTimeout, \ ConnectionTimeout, RangeAlreadyComplete +from swift.common.header_key_dict import HeaderKeyDict from swift.common.http import is_informational, is_success, is_redirection, \ is_server_error, HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_MULTIPLE_CHOICES, \ HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVICE_UNAVAILABLE, \ HTTP_INSUFFICIENT_STORAGE, HTTP_UNAUTHORIZED, HTTP_CONTINUE -from swift.common.swob import Request, Response, HeaderKeyDict, Range, \ +from swift.common.swob import Request, Response, Range, \ HTTPException, HTTPRequestedRangeNotSatisfiable, HTTPServiceUnavailable, \ status_map from swift.common.request_helpers import strip_sys_meta_prefix, \ diff --git a/swift/proxy/controllers/obj.py b/swift/proxy/controllers/obj.py index f3c13d589f..dea29eab3a 100644 --- a/swift/proxy/controllers/obj.py +++ b/swift/proxy/controllers/obj.py @@ -57,6 +57,7 @@ from swift.common.exceptions import ChunkReadTimeout, \ ChunkWriteTimeout, ConnectionTimeout, ResponseTimeout, \ InsufficientStorage, FooterNotSupported, MultiphasePUTNotSupported, \ PutterConnectError, ChunkReadError +from swift.common.header_key_dict import HeaderKeyDict from swift.common.http import ( is_informational, is_success, is_client_error, is_server_error, HTTP_CONTINUE, HTTP_CREATED, HTTP_MULTIPLE_CHOICES, @@ -69,7 +70,7 @@ from swift.proxy.controllers.base import Controller, delay_denial, \ cors_validation, ResumingGetter from swift.common.swob import HTTPAccepted, HTTPBadRequest, HTTPNotFound, \ HTTPPreconditionFailed, HTTPRequestEntityTooLarge, HTTPRequestTimeout, \ - HTTPServerError, HTTPServiceUnavailable, Request, HeaderKeyDict, \ + HTTPServerError, HTTPServiceUnavailable, Request, \ HTTPClientDisconnect, HTTPUnprocessableEntity, Response, HTTPException, \ HTTPRequestedRangeNotSatisfiable, Range, HTTPInternalServerError from swift.common.request_helpers import is_sys_or_user_meta, is_sys_meta, \ diff --git a/test/unit/__init__.py b/test/unit/__init__.py index 9068d84307..377ee2ecc2 100644 --- a/test/unit/__init__.py +++ b/test/unit/__init__.py @@ -34,7 +34,8 @@ from tempfile import mkdtemp from shutil import rmtree from swift.common.utils import Timestamp, NOTICE from test import get_config -from swift.common import swob, utils +from swift.common import utils +from swift.common.header_key_dict import HeaderKeyDict from swift.common.ring import Ring, RingData from hashlib import md5 import logging.handlers @@ -901,7 +902,7 @@ def fake_http_connect(*code_iter, **kwargs): else: etag = '"68b329da9893e34099c7d8ad5cb9c940"' - headers = swob.HeaderKeyDict({ + headers = HeaderKeyDict({ 'content-length': len(self.body), 'content-type': 'x-application/test', 'x-timestamp': self.timestamp, @@ -960,7 +961,7 @@ def fake_http_connect(*code_iter, **kwargs): eventlet.sleep(value) def getheader(self, name, default=None): - return swob.HeaderKeyDict(self.getheaders()).get(name, default) + return HeaderKeyDict(self.getheaders()).get(name, default) def close(self): pass diff --git a/test/unit/account/test_utils.py b/test/unit/account/test_utils.py index 35467d0dab..f931ad58bd 100644 --- a/test/unit/account/test_utils.py +++ b/test/unit/account/test_utils.py @@ -20,7 +20,7 @@ import mock from swift.account import utils, backend from swift.common.storage_policy import POLICIES from swift.common.utils import Timestamp -from swift.common.swob import HeaderKeyDict +from swift.common.header_key_dict import HeaderKeyDict from test.unit import patch_policies diff --git a/test/unit/common/middleware/helpers.py b/test/unit/common/middleware/helpers.py index 1387a773b4..0847a1cbcf 100644 --- a/test/unit/common/middleware/helpers.py +++ b/test/unit/common/middleware/helpers.py @@ -19,6 +19,7 @@ from collections import defaultdict from copy import deepcopy from hashlib import md5 from swift.common import swob +from swift.common.header_key_dict import HeaderKeyDict from swift.common.utils import split_path from test.unit import FakeLogger, FakeRing @@ -85,18 +86,18 @@ class FakeSwift(object): try: resp_class, raw_headers, body = self._find_response(method, path) - headers = swob.HeaderKeyDict(raw_headers) + headers = HeaderKeyDict(raw_headers) except KeyError: if (env.get('QUERY_STRING') and (method, env['PATH_INFO']) in self._responses): resp_class, raw_headers, body = self._find_response( method, env['PATH_INFO']) - headers = swob.HeaderKeyDict(raw_headers) + headers = HeaderKeyDict(raw_headers) elif method == 'HEAD' and ('GET', path) in self._responses: resp_class, raw_headers, body = self._find_response( 'GET', path) body = None - headers = swob.HeaderKeyDict(raw_headers) + headers = HeaderKeyDict(raw_headers) elif method == 'GET' and obj and path in self.uploaded: resp_class = swob.HTTPOk headers, body = self.uploaded[path] diff --git a/test/unit/common/middleware/test_bulk.py b/test/unit/common/middleware/test_bulk.py index a024a94ff6..1888261629 100644 --- a/test/unit/common/middleware/test_bulk.py +++ b/test/unit/common/middleware/test_bulk.py @@ -29,9 +29,10 @@ from eventlet import sleep from mock import patch, call from test.unit.common.middleware.helpers import FakeSwift from swift.common import utils, constraints +from swift.common.header_key_dict import HeaderKeyDict from swift.common.middleware import bulk from swift.common.swob import Request, Response, HTTPException, \ - HTTPNoContent, HTTPCreated, HeaderKeyDict + HTTPNoContent, HTTPCreated from swift.common.http import HTTP_NOT_FOUND, HTTP_UNAUTHORIZED diff --git a/test/unit/common/middleware/test_dlo.py b/test/unit/common/middleware/test_dlo.py index 00d107ad33..1374b403df 100644 --- a/test/unit/common/middleware/test_dlo.py +++ b/test/unit/common/middleware/test_dlo.py @@ -24,6 +24,7 @@ import time import unittest from swift.common import exceptions, swob +from swift.common.header_key_dict import HeaderKeyDict from swift.common.middleware import dlo from swift.common.utils import closing_if_possible from test.unit.common.middleware.helpers import FakeSwift @@ -248,7 +249,7 @@ class TestDloHeadManifest(DloTestCase): req = swob.Request.blank('/v1/AUTH_test/mancon/manifest', environ={'REQUEST_METHOD': 'HEAD'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(headers["Etag"], expected_etag) self.assertEqual(headers["Content-Length"], "25") @@ -257,7 +258,7 @@ class TestDloHeadManifest(DloTestCase): environ={'REQUEST_METHOD': 'HEAD'}) with mock.patch(LIMIT, 3): status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) # etag is manifest's etag self.assertEqual(headers["Etag"], "etag-manyseg") @@ -267,7 +268,7 @@ class TestDloHeadManifest(DloTestCase): req = swob.Request.blank('/v1/AUTH_test/mancon/manifest-no-segments', environ={'REQUEST_METHOD': 'HEAD'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(headers["Etag"], '"%s"' % md5hex("")) self.assertEqual(headers["Content-Length"], "0") @@ -291,7 +292,7 @@ class TestDloGetManifest(DloTestCase): req = swob.Request.blank('/v1/AUTH_test/mancon/manifest', environ={'REQUEST_METHOD': 'GET'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(headers["Etag"], expected_etag) self.assertEqual(headers["Content-Length"], "25") self.assertEqual(body, 'aaaaabbbbbcccccdddddeeeee') @@ -336,7 +337,7 @@ class TestDloGetManifest(DloTestCase): environ={'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'multipart-manifest=get'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(headers["Etag"], "manifest-etag") self.assertEqual(body, "manifest-contents") @@ -354,7 +355,7 @@ class TestDloGetManifest(DloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=8-17'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "206 Partial Content") self.assertEqual(headers["Content-Length"], "10") self.assertEqual(body, "bbcccccddd") @@ -368,7 +369,7 @@ class TestDloGetManifest(DloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=10-19'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "206 Partial Content") self.assertEqual(headers["Content-Length"], "10") self.assertEqual(body, "cccccddddd") @@ -378,7 +379,7 @@ class TestDloGetManifest(DloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=0-0'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "206 Partial Content") self.assertEqual(headers["Content-Length"], "1") self.assertEqual(body, "a") @@ -388,7 +389,7 @@ class TestDloGetManifest(DloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=24-24'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "206 Partial Content") self.assertEqual(headers["Content-Length"], "1") self.assertEqual(body, "e") @@ -398,7 +399,7 @@ class TestDloGetManifest(DloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=18-30'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "206 Partial Content") self.assertEqual(headers["Content-Length"], "7") self.assertEqual(headers["Content-Range"], "bytes 18-24/25") @@ -417,7 +418,7 @@ class TestDloGetManifest(DloTestCase): headers={'Range': 'bytes=3-12'}) with mock.patch(LIMIT, 3): status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "206 Partial Content") self.assertEqual(headers["Content-Length"], "10") # The /15 here indicates that this is a 15-byte object. DLO can't tell @@ -448,7 +449,7 @@ class TestDloGetManifest(DloTestCase): headers={'Range': 'bytes=10-22'}) with mock.patch(LIMIT, 3): status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "200 OK") # this requires multiple pages of container listing, so we can't send # a Content-Length header @@ -460,7 +461,7 @@ class TestDloGetManifest(DloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=-40'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "206 Partial Content") self.assertEqual(headers["Content-Length"], "25") self.assertEqual(body, "aaaaabbbbbcccccdddddeeeee") @@ -471,7 +472,7 @@ class TestDloGetManifest(DloTestCase): headers={'Range': 'bytes=-5'}) with mock.patch(LIMIT, 3): status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "200 OK") self.assertEqual(headers.get("Content-Length"), None) self.assertEqual(headers.get("Content-Range"), None) @@ -485,7 +486,7 @@ class TestDloGetManifest(DloTestCase): headers={'Range': 'bytes=5-9,15-19'}) with mock.patch(LIMIT, 3): status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, "200 OK") self.assertEqual(headers.get("Content-Length"), None) self.assertEqual(headers.get("Content-Range"), None) @@ -500,7 +501,7 @@ class TestDloGetManifest(DloTestCase): headers={'If-Match': manifest_etag}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers['Content-Length'], '25') @@ -512,7 +513,7 @@ class TestDloGetManifest(DloTestCase): headers={'If-Match': 'not it'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '412 Precondition Failed') self.assertEqual(headers['Content-Length'], '0') @@ -527,7 +528,7 @@ class TestDloGetManifest(DloTestCase): headers={'If-None-Match': manifest_etag}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '304 Not Modified') self.assertEqual(headers['Content-Length'], '0') @@ -539,7 +540,7 @@ class TestDloGetManifest(DloTestCase): headers={'If-None-Match': 'not it'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers['Content-Length'], '25') @@ -582,7 +583,7 @@ class TestDloGetManifest(DloTestCase): req = swob.Request.blank('/v1/AUTH_test/mancon/manifest', environ={'REQUEST_METHOD': 'GET'}) status, headers, body, exc = self.call_dlo(req, expect_exception=True) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertTrue(isinstance(exc, exceptions.SegmentError)) self.assertEqual(status, "200 OK") @@ -628,7 +629,7 @@ class TestDloGetManifest(DloTestCase): req = swob.Request.blank('/v1/AUTH_test/mancon/manifest', environ={'REQUEST_METHOD': 'GET'}) status, headers, body, exc = self.call_dlo(req, expect_exception=True) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertTrue(isinstance(exc, exceptions.SegmentError)) self.assertEqual(status, "200 OK") @@ -653,7 +654,7 @@ class TestDloGetManifest(DloTestCase): req = swob.Request.blank('/v1/AUTH_test/mani/festo', environ={'REQUEST_METHOD': 'HEAD'}) status, headers, body = self.call_dlo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(headers["Etag"], '"' + hashlib.md5("abcdef").hexdigest() + '"') @@ -729,7 +730,7 @@ class TestDloGetManifest(DloTestCase): '/v1/AUTH_test/mancon/manifest', environ={'REQUEST_METHOD': 'GET'}) status, headers, body, exc = self.call_dlo(req, expect_exception=True) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') # sanity check self.assertEqual(headers.get('Content-Length'), '25') # sanity check @@ -762,7 +763,7 @@ class TestDloGetManifest(DloTestCase): '/v1/AUTH_test/mancon/manifest', environ={'REQUEST_METHOD': 'GET'}) status, headers, body, exc = self.call_dlo(req, expect_exception=True) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') # sanity check self.assertEqual(headers.get('Content-Length'), '25') # sanity check @@ -781,7 +782,7 @@ class TestDloGetManifest(DloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=0-14'}) status, headers, body, exc = self.call_dlo(req, expect_exception=True) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') # sanity check self.assertEqual(headers.get('Content-Length'), '15') # sanity check diff --git a/test/unit/common/middleware/test_slo.py b/test/unit/common/middleware/test_slo.py index c33860cb74..34024f1e47 100644 --- a/test/unit/common/middleware/test_slo.py +++ b/test/unit/common/middleware/test_slo.py @@ -24,6 +24,7 @@ from mock import patch from hashlib import md5 from swift.common import swob, utils from swift.common.exceptions import ListingIterError, SegmentError +from swift.common.header_key_dict import HeaderKeyDict from swift.common.middleware import slo from swift.common.swob import Request, Response, HTTPException from swift.common.utils import quote, closing_if_possible, close_if_possible @@ -1054,7 +1055,7 @@ class TestSloHeadManifest(SloTestCase): '/v1/AUTH_test/headtest/man', environ={'REQUEST_METHOD': 'HEAD'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers.get('Etag', '').strip("'\""), @@ -1331,7 +1332,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/gettest/manifest-bc', environ={'REQUEST_METHOD': 'GET'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) manifest_etag = md5hex(md5hex("b" * 10) + md5hex("c" * 15)) self.assertEqual(status, '200 OK') @@ -1382,7 +1383,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/gettest/manifest-aabbccdd', environ={'REQUEST_METHOD': 'GET'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(body, ( @@ -1469,7 +1470,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'If-None-Match': self.manifest_abcd_etag}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '304 Not Modified') self.assertEqual(headers['Content-Length'], '0') @@ -1481,7 +1482,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'If-None-Match': "not-%s" % self.manifest_abcd_etag}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual( @@ -1493,7 +1494,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'If-Match': self.manifest_abcd_etag}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual( @@ -1505,7 +1506,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'If-Match': "not-%s" % self.manifest_abcd_etag}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '412 Precondition Failed') self.assertEqual(headers['Content-Length'], '0') @@ -1518,7 +1519,7 @@ class TestSloGetManifest(SloTestCase): headers={'If-Match': self.manifest_abcd_etag, 'Range': 'bytes=3-6'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual(headers['Content-Length'], '4') @@ -1529,7 +1530,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/gettest/manifest-abcd', environ={'REQUEST_METHOD': 'GET'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers['Content-Length'], '50') @@ -1543,7 +1544,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=3-17'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual(headers['Content-Length'], '15') @@ -1582,7 +1583,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=0-999999999'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual( @@ -1619,7 +1620,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=100000-199999'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') count_e = sum(1 if x == 'e' else 0 for x in body) @@ -1656,7 +1657,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=0-999999999'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual( @@ -1678,7 +1679,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=5-29'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual(headers['Content-Length'], '25') @@ -1706,7 +1707,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=0-0'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual(headers['Content-Length'], '1') @@ -1726,7 +1727,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=25-30'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual(headers['Content-Length'], '6') self.assertEqual(body, 'cccccd') @@ -1747,7 +1748,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=45-55'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual(headers['Content-Length'], '5') @@ -1769,7 +1770,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=0-0,2-2'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers['Content-Length'], '50') @@ -1799,7 +1800,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/ünicode/manifest', environ={'REQUEST_METHOD': 'GET'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(body, segment_body) @@ -1808,7 +1809,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/gettest/manifest-abcd-ranges', environ={'REQUEST_METHOD': 'GET'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers['Content-Length'], '32') @@ -1850,7 +1851,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/gettest/manifest-abcd-subranges', environ={'REQUEST_METHOD': 'GET'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers['Content-Length'], '17') @@ -1899,7 +1900,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=7-26'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual(headers['Content-Length'], '20') @@ -1937,7 +1938,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=4-12'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual(headers['Content-Length'], '9') @@ -1988,7 +1989,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=0-999999999'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '206 Partial Content') self.assertEqual(headers['Content-Length'], '32') @@ -2025,7 +2026,7 @@ class TestSloGetManifest(SloTestCase): environ={'REQUEST_METHOD': 'GET'}, headers={'Range': 'bytes=0-0,2-2'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers['Content-Type'], 'application/json') @@ -2039,7 +2040,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/gettest/manifest-badjson', environ={'REQUEST_METHOD': 'GET'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers['Content-Length'], '0') @@ -2113,7 +2114,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/gettest/manifest-abcd', environ={'REQUEST_METHOD': 'HEAD'}) status, headers, body = self.call_slo(req) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertEqual(status, '200 OK') self.assertEqual(headers['Content-Length'], '50') @@ -2171,7 +2172,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/gettest/man1', environ={'REQUEST_METHOD': 'GET'}) status, headers, body, exc = self.call_slo(req, expect_exception=True) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertIsInstance(exc, ListingIterError) # we don't know at header-sending time that things are going to go @@ -2319,7 +2320,7 @@ class TestSloGetManifest(SloTestCase): '/v1/AUTH_test/gettest/manifest-abcd', environ={'REQUEST_METHOD': 'GET'}) status, headers, body, exc = self.call_slo(req, expect_exception=True) - headers = swob.HeaderKeyDict(headers) + headers = HeaderKeyDict(headers) self.assertIsInstance(exc, SegmentError) self.assertEqual(status, '200 OK') diff --git a/test/unit/common/middleware/test_tempurl.py b/test/unit/common/middleware/test_tempurl.py index ff06eb8510..d407ba58b1 100644 --- a/test/unit/common/middleware/test_tempurl.py +++ b/test/unit/common/middleware/test_tempurl.py @@ -35,7 +35,8 @@ from hashlib import sha1 from time import time from swift.common.middleware import tempauth, tempurl -from swift.common.swob import Request, Response, HeaderKeyDict +from swift.common.header_key_dict import HeaderKeyDict +from swift.common.swob import Request, Response from swift.common import utils diff --git a/test/unit/common/test_direct_client.py b/test/unit/common/test_direct_client.py index c7fd0a9588..664a6227b1 100644 --- a/test/unit/common/test_direct_client.py +++ b/test/unit/common/test_direct_client.py @@ -26,8 +26,9 @@ from six.moves import urllib from swift.common import direct_client from swift.common.exceptions import ClientException +from swift.common.header_key_dict import HeaderKeyDict from swift.common.utils import Timestamp -from swift.common.swob import HeaderKeyDict, RESPONSE_REASONS +from swift.common.swob import RESPONSE_REASONS from swift.common.storage_policy import POLICIES from six.moves.http_client import HTTPException diff --git a/test/unit/common/test_header_key_dict.py b/test/unit/common/test_header_key_dict.py new file mode 100644 index 0000000000..5f3f669704 --- /dev/null +++ b/test/unit/common/test_header_key_dict.py @@ -0,0 +1,75 @@ +# Copyright (c) 2012 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from swift.common.header_key_dict import HeaderKeyDict + + +class TestHeaderKeyDict(unittest.TestCase): + def test_case_insensitive(self): + headers = HeaderKeyDict() + headers['Content-Length'] = 0 + headers['CONTENT-LENGTH'] = 10 + headers['content-length'] = 20 + self.assertEqual(headers['Content-Length'], '20') + self.assertEqual(headers['content-length'], '20') + self.assertEqual(headers['CONTENT-LENGTH'], '20') + + def test_setdefault(self): + headers = HeaderKeyDict() + + # it gets set + headers.setdefault('x-rubber-ducky', 'the one') + self.assertEqual(headers['X-Rubber-Ducky'], 'the one') + + # it has the right return value + ret = headers.setdefault('x-boat', 'dinghy') + self.assertEqual(ret, 'dinghy') + + ret = headers.setdefault('x-boat', 'yacht') + self.assertEqual(ret, 'dinghy') + + # shouldn't crash + headers.setdefault('x-sir-not-appearing-in-this-request', None) + + def test_del_contains(self): + headers = HeaderKeyDict() + headers['Content-Length'] = 0 + self.assertTrue('Content-Length' in headers) + del headers['Content-Length'] + self.assertTrue('Content-Length' not in headers) + + def test_update(self): + headers = HeaderKeyDict() + headers.update({'Content-Length': '0'}) + headers.update([('Content-Type', 'text/plain')]) + self.assertEqual(headers['Content-Length'], '0') + self.assertEqual(headers['Content-Type'], 'text/plain') + + def test_get(self): + headers = HeaderKeyDict() + headers['content-length'] = 20 + self.assertEqual(headers.get('CONTENT-LENGTH'), '20') + self.assertEqual(headers.get('something-else'), None) + self.assertEqual(headers.get('something-else', True), True) + + def test_keys(self): + headers = HeaderKeyDict() + headers['content-length'] = 20 + headers['cOnTent-tYpe'] = 'text/plain' + headers['SomeThing-eLse'] = 'somevalue' + self.assertEqual( + set(headers.keys()), + set(('Content-Length', 'Content-Type', 'Something-Else'))) diff --git a/test/unit/common/test_internal_client.py b/test/unit/common/test_internal_client.py index 0900da42e3..834206e55b 100644 --- a/test/unit/common/test_internal_client.py +++ b/test/unit/common/test_internal_client.py @@ -27,6 +27,7 @@ from six.moves.urllib.parse import quote from test.unit import FakeLogger from eventlet.green import urllib2 from swift.common import exceptions, internal_client, swob +from swift.common.header_key_dict import HeaderKeyDict from swift.common.storage_policy import StoragePolicy from test.unit import with_tempdir, write_fake_ring, patch_policies @@ -1027,7 +1028,7 @@ class TestInternalClient(unittest.TestCase): 'user-agent': 'test', # from InternalClient.make_request }) self.assertEqual(app.calls_with_headers, [( - 'GET', path_info, swob.HeaderKeyDict(req_headers))]) + 'GET', path_info, HeaderKeyDict(req_headers))]) def test_iter_object_lines(self): class InternalClient(internal_client.InternalClient): diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index c1900ec5e4..fede30785d 100644 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -98,64 +98,6 @@ class TestHeaderEnvironProxy(unittest.TestCase): set(('Content-Length', 'Content-Type', 'Something-Else'))) -class TestHeaderKeyDict(unittest.TestCase): - def test_case_insensitive(self): - headers = swift.common.swob.HeaderKeyDict() - headers['Content-Length'] = 0 - headers['CONTENT-LENGTH'] = 10 - headers['content-length'] = 20 - self.assertEqual(headers['Content-Length'], '20') - self.assertEqual(headers['content-length'], '20') - self.assertEqual(headers['CONTENT-LENGTH'], '20') - - def test_setdefault(self): - headers = swift.common.swob.HeaderKeyDict() - - # it gets set - headers.setdefault('x-rubber-ducky', 'the one') - self.assertEqual(headers['X-Rubber-Ducky'], 'the one') - - # it has the right return value - ret = headers.setdefault('x-boat', 'dinghy') - self.assertEqual(ret, 'dinghy') - - ret = headers.setdefault('x-boat', 'yacht') - self.assertEqual(ret, 'dinghy') - - # shouldn't crash - headers.setdefault('x-sir-not-appearing-in-this-request', None) - - def test_del_contains(self): - headers = swift.common.swob.HeaderKeyDict() - headers['Content-Length'] = 0 - self.assertTrue('Content-Length' in headers) - del headers['Content-Length'] - self.assertTrue('Content-Length' not in headers) - - def test_update(self): - headers = swift.common.swob.HeaderKeyDict() - headers.update({'Content-Length': '0'}) - headers.update([('Content-Type', 'text/plain')]) - self.assertEqual(headers['Content-Length'], '0') - self.assertEqual(headers['Content-Type'], 'text/plain') - - def test_get(self): - headers = swift.common.swob.HeaderKeyDict() - headers['content-length'] = 20 - self.assertEqual(headers.get('CONTENT-LENGTH'), '20') - self.assertEqual(headers.get('something-else'), None) - self.assertEqual(headers.get('something-else', True), True) - - def test_keys(self): - headers = swift.common.swob.HeaderKeyDict() - headers['content-length'] = 20 - headers['cOnTent-tYpe'] = 'text/plain' - headers['SomeThing-eLse'] = 'somevalue' - self.assertEqual( - set(headers.keys()), - set(('Content-Length', 'Content-Type', 'Something-Else'))) - - class TestRange(unittest.TestCase): def test_range(self): swob_range = swift.common.swob.Range('bytes=1-7') diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 63c746de51..3ebc8f6dc4 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -60,7 +60,8 @@ from swift.common.exceptions import Timeout, MessageTimeout, \ MimeInvalid, ThreadPoolDead from swift.common import utils from swift.common.container_sync_realms import ContainerSyncRealms -from swift.common.swob import Request, Response, HeaderKeyDict +from swift.common.header_key_dict import HeaderKeyDict +from swift.common.swob import Request, Response from test.unit import FakeLogger threading = eventlet.patcher.original('threading') diff --git a/test/unit/container/test_reconciler.py b/test/unit/container/test_reconciler.py index 4a00e72f2e..0e1346273d 100644 --- a/test/unit/container/test_reconciler.py +++ b/test/unit/container/test_reconciler.py @@ -31,6 +31,7 @@ from swift.container import reconciler from swift.container.server import gen_resp_headers from swift.common.direct_client import ClientException from swift.common import swob +from swift.common.header_key_dict import HeaderKeyDict from swift.common.utils import split_path, Timestamp, encode_timestamps from test.unit import debug_logger, FakeRing, fake_http_connect @@ -43,7 +44,7 @@ def timestamp_to_last_modified(timestamp): def container_resp_headers(**kwargs): - return swob.HeaderKeyDict(gen_resp_headers(kwargs)) + return HeaderKeyDict(gen_resp_headers(kwargs)) class FakeStoragePolicySwift(object): diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index 0205bca3bf..fd0e5a5633 100644 --- a/test/unit/container/test_server.py +++ b/test/unit/container/test_server.py @@ -34,8 +34,8 @@ from six import BytesIO from six import StringIO from swift import __version__ as swift_version -from swift.common.swob import (Request, HeaderKeyDict, - WsgiBytesIO, HTTPNoContent) +from swift.common.header_key_dict import HeaderKeyDict +from swift.common.swob import (Request, WsgiBytesIO, HTTPNoContent) import swift.container from swift.container import server as container_server from swift.common import constraints diff --git a/test/unit/obj/test_reconstructor.py b/test/unit/obj/test_reconstructor.py index a093a80213..19fc1f8bba 100755 --- a/test/unit/obj/test_reconstructor.py +++ b/test/unit/obj/test_reconstructor.py @@ -30,8 +30,8 @@ from contextlib import closing, contextmanager from gzip import GzipFile from shutil import rmtree from swift.common import utils -from swift.common.swob import HeaderKeyDict from swift.common.exceptions import DiskFileError +from swift.common.header_key_dict import HeaderKeyDict from swift.obj import diskfile, reconstructor as object_reconstructor from swift.common import ring from swift.common.storage_policy import (StoragePolicy, ECStoragePolicy, diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index 40c37ee39c..a4de8d7a35 100755 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -50,11 +50,12 @@ from test.unit import connect_tcp, readuntil2crlfs, patch_policies from swift.obj import server as object_server from swift.obj import diskfile from swift.common import utils, bufferedhttp +from swift.common.header_key_dict import HeaderKeyDict from swift.common.utils import hash_path, mkdirs, normalize_timestamp, \ NullLogger, storage_directory, public, replication, encode_timestamps, \ Timestamp from swift.common import constraints -from swift.common.swob import Request, HeaderKeyDict, WsgiBytesIO +from swift.common.swob import Request, WsgiBytesIO from swift.common.splice import splice from swift.common.storage_policy import (StoragePolicy, ECStoragePolicy, POLICIES, EC_POLICY) diff --git a/test/unit/obj/test_updater.py b/test/unit/obj/test_updater.py index 79cfd7a695..1990e4a6b3 100644 --- a/test/unit/obj/test_updater.py +++ b/test/unit/obj/test_updater.py @@ -35,9 +35,9 @@ from swift.obj.diskfile import (ASYNCDIR_BASE, get_async_dir, DiskFileManager, get_tmp_dir) from swift.common.ring import RingData from swift.common import utils +from swift.common.header_key_dict import HeaderKeyDict from swift.common.utils import hash_path, normalize_timestamp, mkdirs, \ write_pickle -from swift.common import swob from test.unit import debug_logger, patch_policies, mocked_http_conn from swift.common.storage_policy import StoragePolicy, POLICIES @@ -316,7 +316,7 @@ class TestObjectUpdater(unittest.TestCase): out.flush() self.assertEqual(inc.readline(), 'PUT /sda1/0/a/c/o HTTP/1.1\r\n') - headers = swob.HeaderKeyDict() + headers = HeaderKeyDict() line = inc.readline() while line and line != '\r\n': headers[line.split(':')[0]] = \ @@ -404,7 +404,7 @@ class TestObjectUpdater(unittest.TestCase): daemon = object_updater.ObjectUpdater(conf, logger=self.logger) dfmanager = DiskFileManager(conf, daemon.logger) # don't include storage-policy-index in headers_out pickle - headers_out = swob.HeaderKeyDict({ + headers_out = HeaderKeyDict({ 'x-size': 0, 'x-content-type': 'text/plain', 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e', @@ -452,7 +452,7 @@ class TestObjectUpdater(unittest.TestCase): dfmanager = DiskFileManager(conf, daemon.logger) account, container, obj = 'a', 'c', 'o' op = 'PUT' - headers_out = swob.HeaderKeyDict({ + headers_out = HeaderKeyDict({ 'x-size': 0, 'x-content-type': 'text/plain', 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e', diff --git a/test/unit/proxy/controllers/test_base.py b/test/unit/proxy/controllers/test_base.py index 295be11cee..4bc8991d04 100644 --- a/test/unit/proxy/controllers/test_base.py +++ b/test/unit/proxy/controllers/test_base.py @@ -23,10 +23,10 @@ from swift.proxy.controllers.base import headers_to_container_info, \ get_object_env_key, get_info, get_object_info, \ Controller, GetOrHeadHandler, _set_info_cache, _set_object_info_cache, \ bytes_to_skip -from swift.common.swob import Request, HTTPException, HeaderKeyDict, \ - RESPONSE_REASONS +from swift.common.swob import Request, HTTPException, RESPONSE_REASONS from swift.common import exceptions from swift.common.utils import split_path +from swift.common.header_key_dict import HeaderKeyDict from swift.common.http import is_success from swift.common.storage_policy import StoragePolicy from test.unit import fake_http_connect, FakeRing, FakeMemcache diff --git a/test/unit/proxy/controllers/test_obj.py b/test/unit/proxy/controllers/test_obj.py index d0fcf96fd3..08a0be9e98 100755 --- a/test/unit/proxy/controllers/test_obj.py +++ b/test/unit/proxy/controllers/test_obj.py @@ -31,6 +31,7 @@ from six.moves import range import swift from swift.common import utils, swob, exceptions +from swift.common.header_key_dict import HeaderKeyDict from swift.proxy import server as proxy_server from swift.proxy.controllers import obj from swift.proxy.controllers.base import get_info as _real_get_info @@ -1074,7 +1075,7 @@ class StubResponse(object): self.status = status self.body = body self.readable = BytesIO(body) - self.headers = swob.HeaderKeyDict(headers) + self.headers = HeaderKeyDict(headers) fake_reason = ('Fake', 'This response is a lie.') self.reason = swob.RESPONSE_REASONS.get(status, fake_reason)[0] diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 5f9d03094d..8aba81ffb1 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -74,8 +74,9 @@ from swift.proxy.controllers.base import get_container_memcache_key, \ get_account_memcache_key, cors_validation, _get_info_cache import swift.proxy.controllers import swift.proxy.controllers.obj +from swift.common.header_key_dict import HeaderKeyDict from swift.common.swob import Request, Response, HTTPUnauthorized, \ - HTTPException, HeaderKeyDict, HTTPBadRequest + HTTPException, HTTPBadRequest from swift.common import storage_policy from swift.common.storage_policy import StoragePolicy, ECStoragePolicy, \ StoragePolicyCollection, POLICIES