Unquote s3 key names. Closes #13.
This commit is contained in:
parent
8fe0c91853
commit
98d7a50790
@ -2,6 +2,7 @@ import datetime
|
||||
import md5
|
||||
|
||||
from moto.core import BaseBackend
|
||||
from .utils import clean_key_name
|
||||
|
||||
|
||||
class FakeKey(object):
|
||||
@ -72,6 +73,8 @@ class S3Backend(BaseBackend):
|
||||
return None
|
||||
|
||||
def set_key(self, bucket_name, key_name, value):
|
||||
key_name = clean_key_name(key_name)
|
||||
|
||||
bucket = self.buckets[bucket_name]
|
||||
new_key = FakeKey(name=key_name, value=value)
|
||||
bucket.keys[key_name] = new_key
|
||||
@ -79,6 +82,7 @@ class S3Backend(BaseBackend):
|
||||
return new_key
|
||||
|
||||
def get_key(self, bucket_name, key_name):
|
||||
key_name = clean_key_name(key_name)
|
||||
bucket = self.get_bucket(bucket_name)
|
||||
if bucket:
|
||||
return bucket.keys.get(key_name)
|
||||
@ -107,10 +111,13 @@ class S3Backend(BaseBackend):
|
||||
return key_results, folder_results
|
||||
|
||||
def delete_key(self, bucket_name, key_name):
|
||||
key_name = clean_key_name(key_name)
|
||||
bucket = self.buckets[bucket_name]
|
||||
return bucket.keys.pop(key_name)
|
||||
|
||||
def copy_key(self, src_bucket_name, src_key_name, dest_bucket_name, dest_key_name):
|
||||
src_key_name = clean_key_name(src_key_name)
|
||||
dest_key_name = clean_key_name(dest_key_name)
|
||||
src_bucket = self.buckets[src_bucket_name]
|
||||
dest_bucket = self.buckets[dest_bucket_name]
|
||||
dest_bucket.keys[dest_key_name] = src_bucket.keys[src_key_name]
|
||||
|
@ -1,4 +1,5 @@
|
||||
import re
|
||||
import urllib2
|
||||
import urlparse
|
||||
|
||||
bucket_name_regex = re.compile("(.+).s3.amazonaws.com")
|
||||
@ -21,3 +22,7 @@ def bucket_name_from_hostname(hostname):
|
||||
else:
|
||||
# No subdomain found.
|
||||
return None
|
||||
|
||||
|
||||
def clean_key_name(key_name):
|
||||
return urllib2.unquote(key_name)
|
||||
|
@ -205,3 +205,16 @@ def test_bucket_name_with_dot():
|
||||
|
||||
k = Key(bucket, 'somekey')
|
||||
k.set_contents_from_string('somedata')
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_key_with_special_characters():
|
||||
conn = boto.connect_s3()
|
||||
bucket = conn.create_bucket('test_bucket_name')
|
||||
|
||||
key = Key(bucket, 'test_list_keys_2/x?y')
|
||||
key.set_contents_from_string('value1')
|
||||
|
||||
key_list = bucket.list('test_list_keys_2/', '/')
|
||||
keys = [x for x in key_list]
|
||||
keys[0].name.should.equal("test_list_keys_2/x?y")
|
||||
|
Loading…
Reference in New Issue
Block a user