Commit ecefb5c1 authored by Antony Chazapis's avatar Antony Chazapis
Browse files

Make sure unicode strings work for container and object names, as well as...

Make sure unicode strings work for container and object names, as well as metadata (keys and values).
parent d2de2e5c
......@@ -28,6 +28,9 @@ class ResizeNotAllowed(Fault):
class ItemNotFound(Fault):
code = 404
class Conflict(Fault):
code = 409
class LengthRequired(Fault):
code = 411
......
......@@ -12,7 +12,7 @@ try:
except:
from pithos.api.util import parse_http_date_safe
from pithos.api.faults import Fault, NotModified, BadRequest, Unauthorized, ItemNotFound, LengthRequired, PreconditionFailed, RangeNotSatisfiable, UnprocessableEntity
from pithos.api.faults import Fault, NotModified, BadRequest, Unauthorized, ItemNotFound, Conflict, LengthRequired, PreconditionFailed, RangeNotSatisfiable, UnprocessableEntity
from pithos.api.util import get_meta, get_range, api_method
from settings import PROJECT_PATH
......@@ -23,7 +23,7 @@ from pithos.backends.dummy import BackEnd
import logging
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)
@api_method('GET')
def authenticate(request):
......@@ -101,7 +101,7 @@ def account_meta(request, v_account):
response['X-Account-Container-Count'] = info['count']
response['X-Account-Bytes-Used'] = info['bytes']
for k in [x for x in info.keys() if x.startswith('X-Account-Meta-')]:
response[k] = info[k]
response[k.encode('utf-8')] = info[k].encode('utf-8')
return response
......@@ -178,7 +178,7 @@ def container_meta(request, v_account, v_container):
response['X-Container-Object-Count'] = info['count']
response['X-Container-Bytes-Used'] = info['bytes']
for k in [x for x in info.keys() if x.startswith('X-Container-Meta-')]:
response[k] = info[k]
response[k.encode('utf-8')] = info[k].encode('utf-8')
return response
......@@ -226,6 +226,7 @@ def container_update(request, v_account, v_container):
def container_delete(request, v_account, v_container):
# Normal Response Codes: 204
# Error Response Codes: serviceUnavailable (503),
# conflict (409),
# itemNotFound (404),
# unauthorized (401),
# badRequest (400)
......@@ -237,7 +238,7 @@ def container_delete(request, v_account, v_container):
raise ItemNotFound()
if info['count'] > 0:
return HttpResponse(status = 409)
raise Conflict()
# TODO: Handle both exceptions.
try:
......@@ -319,8 +320,9 @@ def object_meta(request, v_account, v_container, v_object):
response['Content-Length'] = info['bytes']
response['Content-Type'] = info['content_type']
response['Last-Modified'] = http_date(info['last_modified'])
# TODO: How should these be encoded for non-ascii?
for k in [x for x in info.keys() if x.startswith('X-Object-Meta-')]:
response[k] = info[k]
response[k.encode('utf-8')] = info[k].encode('utf-8')
return response
......@@ -520,6 +522,14 @@ def object_update(request, v_account, v_container, v_object):
# unauthorized (401),
# badRequest (400)
meta = get_meta(request, 'X-Object-Meta-')
be = BackEnd(STORAGE_PATH)
try:
be.update_object_meta(request.user, v_container, v_object, meta)
except NameError:
raise ItemNotFound()
return HttpResponse(status = 202)
@api_method('DELETE')
......
# coding=utf-8
import cloudfiles
conn = cloudfiles.get_connection('jsmith', '1234567890', authurl = 'http://127.0.0.1:8000/v1')
print 'Authenticated. Token: %s' % conn.token
print 'Container count: %d Total bytes: %d' % conn.get_info()
container = 'asdf'
container = 'asdf κοντέινερ'
conn.create_container(container)
containers = conn.get_all_containers()
print 'Found: %d containers' % len(containers)
for container in containers:
print container.name
print container.name.encode('utf-8')
containers = conn.list_containers_info()
for container in containers:
print container
container = 'asdf'
container = 'asdf κοντέινερ'
conn.create_container(container)
cont = conn.get_container(container)
......@@ -29,10 +31,11 @@ for object in objects:
print object
cont.delete_object(object)
object = 'test_file'
object = 'δοκιμαστικό object'
obj = cont.create_object(object)
obj.content_type = 'text/plain'
obj.metadata['blah'] = 'aldsjflkajdsflk'
obj.metadata['blah'] = 'αθδσηκφ'
obj.metadata['δοκ'] = 'αθδσηκφ'
obj.write('asdfasdfasdf')
obj.metadata
print ''
......@@ -43,6 +46,9 @@ print 'Size: %s' % obj.size
print 'Last Modified: %s' % obj.last_modified
print 'Container: %s' % obj.container
print 'Metadata: %s' % obj.metadata
print 'Metadata: %s' % obj.metadata.get('blah')
from urllib import unquote
obj = cont.get_object(object)
data = obj.read()
......@@ -54,6 +60,8 @@ print 'Size: %s' % obj.size
print 'Last Modified: %s' % obj.last_modified
print 'Container: %s' % obj.container
print 'Metadata: %s' % obj.metadata
print 'Metadata: %s' % unquote(obj.metadata.get('blah'))
print 'Metadata: %s' % unquote(obj.metadata.keys()[1])
print 'Data: %s' % data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment