Revision e7b51248 pithos/api/util.py
b/pithos/api/util.py | ||
---|---|---|
41 | 41 |
from django.http import HttpResponse |
42 | 42 |
from django.utils import simplejson as json |
43 | 43 |
from django.utils.http import http_date, parse_etags |
44 |
from django.utils.encoding import smart_str |
|
44 | 45 |
|
45 | 46 |
from pithos.api.compat import parse_http_date_safe, parse_http_date |
46 | 47 |
from pithos.api.faults import (Fault, NotModified, BadRequest, Unauthorized, ItemNotFound, |
... | ... | |
77 | 78 |
|
78 | 79 |
def format_header_key(k): |
79 | 80 |
"""Convert underscores to dashes and capitalize intra-dash strings.""" |
80 |
|
|
81 | 81 |
return '-'.join([x.capitalize() for x in k.replace('_', '-').split('-')]) |
82 | 82 |
|
83 | 83 |
def get_header_prefix(request, prefix): |
... | ... | |
106 | 106 |
response['X-Account-Bytes-Used'] = meta['bytes'] |
107 | 107 |
response['Last-Modified'] = http_date(int(meta['modified'])) |
108 | 108 |
for k in [x for x in meta.keys() if x.startswith('X-Account-Meta-')]: |
109 |
response[k.encode('utf-8')] = meta[k].encode('utf-8')
|
|
109 |
response[smart_str(k, strings_only=True)] = smart_str(meta[k], strings_only=True)
|
|
110 | 110 |
if 'until_timestamp' in meta: |
111 | 111 |
response['X-Account-Until-Timestamp'] = http_date(int(meta['until_timestamp'])) |
112 | 112 |
for k, v in groups.iteritems(): |
113 |
response[format_header_key('X-Account-Group-' + k).encode('utf-8')] = (','.join(v)).encode('utf-8') |
|
114 |
|
|
113 |
k = smart_str(k, strings_only=True) |
|
114 |
k = format_header_key('X-Account-Group-' + k) |
|
115 |
v = smart_str(','.join(v), strings_only=True) |
|
116 |
response[k] = v |
|
117 |
|
|
115 | 118 |
def get_container_headers(request): |
116 | 119 |
meta = get_header_prefix(request, 'X-Container-Meta-') |
117 | 120 |
policy = dict([(k[19:].lower(), v.replace(' ', '')) for k, v in get_header_prefix(request, 'X-Container-Policy-').iteritems()]) |
... | ... | |
124 | 127 |
response['X-Container-Bytes-Used'] = meta['bytes'] |
125 | 128 |
response['Last-Modified'] = http_date(int(meta['modified'])) |
126 | 129 |
for k in [x for x in meta.keys() if x.startswith('X-Container-Meta-')]: |
127 |
response[k.encode('utf-8')] = meta[k].encode('utf-8') |
|
128 |
response['X-Container-Object-Meta'] = ','.join([x[14:] for x in meta['object_meta'] if x.startswith('X-Object-Meta-')]) |
|
130 |
response[smart_str(k, strings_only=True)] = smart_str(meta[k], strings_only=True) |
|
131 |
l = [smart_str(x, strings_only=True) for x in meta['object_meta'] if x.startswith('X-Object-Meta-')] |
|
132 |
response['X-Container-Object-Meta'] = ','.join([x[14:] for x in l]) |
|
129 | 133 |
response['X-Container-Block-Size'] = backend.block_size |
130 | 134 |
response['X-Container-Block-Hash'] = backend.hash_algorithm |
131 | 135 |
if 'until_timestamp' in meta: |
132 | 136 |
response['X-Container-Until-Timestamp'] = http_date(int(meta['until_timestamp'])) |
133 | 137 |
for k, v in policy.iteritems(): |
134 |
response[format_header_key('X-Container-Policy-' + k).encode('utf-8')] = v.encode('utf-8')
|
|
138 |
response[smart_str(format_header_key('X-Container-Policy-' + k), strings_only=True)] = smart_str(v, strings_only=True)
|
|
135 | 139 |
|
136 | 140 |
def get_object_headers(request): |
137 | 141 |
meta = get_header_prefix(request, 'X-Object-Meta-') |
... | ... | |
155 | 159 |
response['X-Object-Version'] = meta['version'] |
156 | 160 |
response['X-Object-Version-Timestamp'] = http_date(int(meta['version_timestamp'])) |
157 | 161 |
for k in [x for x in meta.keys() if x.startswith('X-Object-Meta-')]: |
158 |
response[k.encode('utf-8')] = meta[k].encode('utf-8')
|
|
162 |
response[smart_str(k, strings_only=True)] = smart_str(meta[k], strings_only=True)
|
|
159 | 163 |
for k in ('Content-Encoding', 'Content-Disposition', 'X-Object-Manifest', 'X-Object-Sharing', 'X-Object-Shared-By', 'X-Object-Public'): |
160 | 164 |
if k in meta: |
161 |
response[k] = meta[k]
|
|
165 |
response[k] = smart_str(meta[k], strings_only=True)
|
|
162 | 166 |
else: |
163 | 167 |
for k in ('Content-Encoding', 'Content-Disposition'): |
164 | 168 |
if k in meta: |
Also available in: Unified diff