diff options
author | Jenkins <jenkins@review.openstack.org> | 2017-01-24 00:39:54 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-01-24 00:39:54 +0000 |
commit | 5ffd496f1f5c7cbbb4bd65803cecd37a6bfb7080 (patch) | |
tree | f7eabab26d0f410a415f273108bd3798cc737404 /swiftclient/utils.py | |
parent | 816565d575489e745e4f8f021791eda2b7774af3 (diff) | |
parent | a1e2bcde4a54a33054c7dcb31c3c3b0e6d72d021 (diff) | |
download | python-swiftclient-5ffd496f1f5c7cbbb4bd65803cecd37a6bfb7080.tar.gz |
Merge "Accept more types of input for headers/meta"
Diffstat (limited to 'swiftclient/utils.py')
-rw-r--r-- | swiftclient/utils.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/swiftclient/utils.py b/swiftclient/utils.py index 5ba6d5b..9f8af1f 100644 --- a/swiftclient/utils.py +++ b/swiftclient/utils.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Miscellaneous utility functions for use with Swift.""" +import collections import gzip import hashlib import hmac @@ -158,15 +159,24 @@ def parse_api_response(headers, body): def split_request_headers(options, prefix=''): headers = {} + if isinstance(options, collections.Mapping): + options = options.items() for item in options: - split_item = item.split(':', 1) - if len(split_item) == 2: - headers[(prefix + split_item[0]).title()] = split_item[1].strip() - else: + if isinstance(item, six.string_types): + if ':' not in item: + raise ValueError( + "Metadata parameter %s must contain a ':'.\n" + "Example: 'Color:Blue' or 'Size:Large'" + % item + ) + item = item.split(':', 1) + if len(item) != 2: raise ValueError( - "Metadata parameter %s must contain a ':'.\n%s" - % (item, "Example: 'Color:Blue' or 'Size:Large'") + "Metadata parameter %r must have exactly two items.\n" + "Example: ('Color', 'Blue') or ['Size', 'Large']" + % (item, ) ) + headers[(prefix + item[0]).title()] = item[1].strip() return headers |