aws-s3 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/aws/s3.rb +2 -3
- data/lib/aws/s3/authentication.rb +1 -1
- data/lib/aws/s3/base.rb +13 -9
- data/lib/aws/s3/connection.rb +1 -1
- data/lib/aws/s3/extensions.rb +50 -18
- data/lib/aws/s3/logging.rb +9 -6
- data/lib/aws/s3/object.rb +1 -1
- data/lib/aws/s3/version.rb +2 -2
- data/test/extensions_test.rb +23 -14
- data/test/logging_test.rb +1 -1
- data/test/remote/test_helper.rb +4 -1
- data/test/test_helper.rb +4 -1
- metadata +6 -7
data/lib/aws/s3.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'base64'
|
2
1
|
require 'cgi'
|
3
2
|
require 'uri'
|
4
3
|
require 'openssl'
|
@@ -11,7 +10,7 @@ require 'open-uri'
|
|
11
10
|
$:.unshift(File.dirname(__FILE__))
|
12
11
|
require 's3/extensions'
|
13
12
|
require_library_or_gem 'builder' unless defined? Builder
|
14
|
-
require_library_or_gem 'mime/types' unless defined? MIME::Types
|
13
|
+
require_library_or_gem 'mime/types', 'mime-types' unless defined? MIME::Types
|
15
14
|
|
16
15
|
require 's3/base'
|
17
16
|
require 's3/version'
|
@@ -43,7 +42,7 @@ AWS::S3::S3Object.class_eval do
|
|
43
42
|
include AWS::S3::BitTorrent
|
44
43
|
end
|
45
44
|
|
46
|
-
require_library_or_gem 'xmlsimple' unless defined? XmlSimple
|
45
|
+
require_library_or_gem 'xmlsimple', 'xml-simple' unless defined? XmlSimple
|
47
46
|
# If libxml is installed, we use the FasterXmlSimple library, that provides most of the functionality of XmlSimple
|
48
47
|
# except it uses the xml/libxml library for xml parsing (rather than REXML). If libxml isn't installed, we just fall back on
|
49
48
|
# XmlSimple.
|
@@ -69,7 +69,7 @@ module AWS
|
|
69
69
|
|
70
70
|
def encoded_canonical
|
71
71
|
digest = OpenSSL::Digest::Digest.new('sha1')
|
72
|
-
b64_hmac =
|
72
|
+
b64_hmac = [OpenSSL::HMAC.digest(digest, secret_access_key, canonical_string)].pack("m").strip
|
73
73
|
url_encode? ? CGI.escape(b64_hmac) : b64_hmac
|
74
74
|
end
|
75
75
|
|
data/lib/aws/s3/base.rb
CHANGED
@@ -74,8 +74,13 @@ module AWS #:nodoc:
|
|
74
74
|
# Once in a while, a request to S3 returns an internal error. A glitch in the matrix I presume. Since these
|
75
75
|
# errors are few and far between the request method will rescue InternalErrors the first three times they encouter them
|
76
76
|
# and will retry the request again. Most of the time the second attempt will work.
|
77
|
-
rescue
|
78
|
-
attempts == 3
|
77
|
+
rescue InternalError, RequestTimeout
|
78
|
+
if attempts == 3
|
79
|
+
raise
|
80
|
+
else
|
81
|
+
attempts += 1
|
82
|
+
retry
|
83
|
+
end
|
79
84
|
end
|
80
85
|
|
81
86
|
[:get, :post, :put, :delete, :head].each do |verb|
|
@@ -173,10 +178,6 @@ module AWS #:nodoc:
|
|
173
178
|
def bucket_name(name)
|
174
179
|
name || current_bucket
|
175
180
|
end
|
176
|
-
|
177
|
-
def retry_exceptions
|
178
|
-
[InternalError, RequestTimeout]
|
179
|
-
end
|
180
181
|
|
181
182
|
class RequestOptions < Hash #:nodoc:
|
182
183
|
attr_reader :options, :verb
|
@@ -226,9 +227,12 @@ module AWS #:nodoc:
|
|
226
227
|
|
227
228
|
def method_missing(method, *args, &block)
|
228
229
|
case
|
229
|
-
when attributes.has_key?(method.to_s)
|
230
|
-
|
231
|
-
|
230
|
+
when attributes.has_key?(method.to_s)
|
231
|
+
attributes[method.to_s]
|
232
|
+
when attributes.has_key?(method)
|
233
|
+
attributes[method]
|
234
|
+
else
|
235
|
+
super
|
232
236
|
end
|
233
237
|
end
|
234
238
|
end
|
data/lib/aws/s3/connection.rb
CHANGED
data/lib/aws/s3/extensions.rb
CHANGED
@@ -26,9 +26,16 @@ class Hash
|
|
26
26
|
end
|
27
27
|
|
28
28
|
class String
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
if RUBY_VERSION <= '1.9'
|
30
|
+
def previous!
|
31
|
+
self[-1] -= 1
|
32
|
+
self
|
33
|
+
end
|
34
|
+
else
|
35
|
+
def previous!
|
36
|
+
self[-1] = (self[-1].ord - 1).chr
|
37
|
+
self
|
38
|
+
end
|
32
39
|
end
|
33
40
|
|
34
41
|
def previous
|
@@ -48,17 +55,34 @@ class String
|
|
48
55
|
tr("-", "_").downcase
|
49
56
|
end unless public_method_defined? :underscore
|
50
57
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
58
|
+
if RUBY_VERSION >= '1.9'
|
59
|
+
def valid_utf8?
|
60
|
+
dup.force_encoding('UTF-8').valid_encoding?
|
61
|
+
end
|
62
|
+
else
|
63
|
+
def valid_utf8?
|
64
|
+
scan(Regexp.new('[^\x00-\xa0]', nil, 'u')) { |s| s.unpack('U') }
|
65
|
+
true
|
66
|
+
rescue ArgumentError
|
67
|
+
false
|
68
|
+
end
|
56
69
|
end
|
57
70
|
|
58
71
|
# All paths in in S3 have to be valid unicode so this takes care of
|
59
|
-
# cleaning up any strings that aren't valid utf-8 according to String#
|
60
|
-
|
61
|
-
|
72
|
+
# cleaning up any strings that aren't valid utf-8 according to String#valid_utf8?
|
73
|
+
if RUBY_VERSION >= '1.9'
|
74
|
+
def remove_extended!
|
75
|
+
sanitized_string = ''
|
76
|
+
each_byte do |byte|
|
77
|
+
character = byte.chr
|
78
|
+
sanitized_string << character if character.ascii_only?
|
79
|
+
end
|
80
|
+
sanitized_string
|
81
|
+
end
|
82
|
+
else
|
83
|
+
def remove_extended!
|
84
|
+
gsub!(/[\x80-\xFF]/) { "%02X" % $&[0] }
|
85
|
+
end
|
62
86
|
end
|
63
87
|
|
64
88
|
def remove_extended
|
@@ -75,11 +99,11 @@ class CoercibleString < String
|
|
75
99
|
|
76
100
|
def coerce
|
77
101
|
case self
|
78
|
-
when 'true'
|
79
|
-
when 'false'
|
102
|
+
when 'true'; true
|
103
|
+
when 'false'; false
|
80
104
|
# Don't coerce numbers that start with zero
|
81
|
-
when /^[1-9]+\d
|
82
|
-
when datetime_format
|
105
|
+
when /^[1-9]+\d*$/; Integer(self)
|
106
|
+
when datetime_format; Time.parse(self)
|
83
107
|
else
|
84
108
|
self
|
85
109
|
end
|
@@ -103,10 +127,15 @@ end
|
|
103
127
|
module Kernel
|
104
128
|
def __method__(depth = 0)
|
105
129
|
caller[depth][/`([^']+)'/, 1]
|
106
|
-
end
|
130
|
+
end if RUBY_VERSION < '1.8.7'
|
131
|
+
|
132
|
+
def __called_from__
|
133
|
+
caller[1][/`([^']+)'/, 1]
|
134
|
+
end if RUBY_VERSION > '1.8.7'
|
107
135
|
|
108
136
|
def memoize(reload = false, storage = nil)
|
109
|
-
|
137
|
+
current_method = RUBY_VERSION >= '1.8.7' ? __called_from__ : __method__(1)
|
138
|
+
storage = "@#{storage || current_method}"
|
110
139
|
if reload
|
111
140
|
instance_variable_set(storage, nil)
|
112
141
|
else
|
@@ -117,7 +146,10 @@ module Kernel
|
|
117
146
|
instance_variable_set(storage, yield)
|
118
147
|
end
|
119
148
|
|
120
|
-
def require_library_or_gem(library)
|
149
|
+
def require_library_or_gem(library, gem_name = nil)
|
150
|
+
if RUBY_VERSION >= '1.9'
|
151
|
+
gem(gem_name || library, '>=0')
|
152
|
+
end
|
121
153
|
require library
|
122
154
|
rescue LoadError => library_not_installed
|
123
155
|
begin
|
data/lib/aws/s3/logging.rb
CHANGED
@@ -97,8 +97,14 @@ module AWS
|
|
97
97
|
end
|
98
98
|
|
99
99
|
# Returns the lines for the log. Each line is wrapped in a Log::Line.
|
100
|
-
|
101
|
-
|
100
|
+
if RUBY_VERSION >= '1.8.7'
|
101
|
+
def lines
|
102
|
+
log.value.lines.map {|line| Line.new(line)}
|
103
|
+
end
|
104
|
+
else
|
105
|
+
def lines
|
106
|
+
log.value.map {|line| Line.new(line)}
|
107
|
+
end
|
102
108
|
end
|
103
109
|
memoized :lines
|
104
110
|
|
@@ -158,10 +164,7 @@ module AWS
|
|
158
164
|
|
159
165
|
# Time.parse doesn't like %d/%B/%Y:%H:%M:%S %z so we have to transform it unfortunately
|
160
166
|
def typecast_time(datetime) #:nodoc:
|
161
|
-
|
162
|
-
month_names = [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
163
|
-
datetime.sub!(%r|^(\w{2})/(\w{3})|, '\2/\1')
|
164
|
-
datetime.sub!(month, month_names.index(month).to_s)
|
167
|
+
datetime.sub!(%r|^(\w{2})/(\w{3})/(\w{4})|, '\2 \1 \3')
|
165
168
|
datetime.sub!(':', ' ')
|
166
169
|
Time.parse(datetime)
|
167
170
|
end
|
data/lib/aws/s3/object.rb
CHANGED
@@ -168,7 +168,7 @@ module AWS
|
|
168
168
|
|
169
169
|
# We need to ensure the key doesn't have extended characters but not uri escape it before doing the lookup and comparing since if the object exists,
|
170
170
|
# the key on S3 will have been normalized
|
171
|
-
key = key.remove_extended unless key.
|
171
|
+
key = key.remove_extended unless key.valid_utf8?
|
172
172
|
bucket = Bucket.find(bucket_name(bucket), :marker => key.previous, :max_keys => 1)
|
173
173
|
# If our heuristic failed, trigger a NoSuchKey exception
|
174
174
|
if (object = bucket.objects.first) && object.key == key
|
data/lib/aws/s3/version.rb
CHANGED
data/test/extensions_test.rb
CHANGED
@@ -65,14 +65,14 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
69
|
-
assert !"318597/620065/GTL_75\24300_A600_A610.zip".
|
70
|
-
assert "318597/620065/GTL_75£00_A600_A610.zip".
|
68
|
+
def test_valid_utf8?
|
69
|
+
assert !"318597/620065/GTL_75\24300_A600_A610.zip".valid_utf8?
|
70
|
+
assert "318597/620065/GTL_75£00_A600_A610.zip".valid_utf8?
|
71
71
|
end
|
72
72
|
|
73
73
|
def test_remove_extended
|
74
|
-
assert "318597/620065/GTL_75\24300_A600_A610.zip".remove_extended.
|
75
|
-
assert "318597/620065/GTL_75£00_A600_A610.zip".remove_extended.
|
74
|
+
assert "318597/620065/GTL_75\24300_A600_A610.zip".remove_extended.valid_utf8?
|
75
|
+
assert "318597/620065/GTL_75£00_A600_A610.zip".remove_extended.valid_utf8?
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -139,7 +139,7 @@ class KerneltExtensionsTest < Test::Unit::TestCase
|
|
139
139
|
assert_equal 'foo', b.foo
|
140
140
|
assert_equal 'bar', b.bar
|
141
141
|
end
|
142
|
-
end
|
142
|
+
end if RUBY_VERSION < '1.8.7'
|
143
143
|
|
144
144
|
class ModuleExtensionsTest < Test::Unit::TestCase
|
145
145
|
class Foo
|
@@ -166,10 +166,10 @@ class ModuleExtensionsTest < Test::Unit::TestCase
|
|
166
166
|
end
|
167
167
|
|
168
168
|
def test_memoize
|
169
|
-
assert
|
169
|
+
assert !instance_variables_of(@instance).include?('@foo')
|
170
170
|
cached_result = @instance.foo
|
171
171
|
assert_equal cached_result, @instance.foo
|
172
|
-
assert @instance.
|
172
|
+
assert instance_variables_of(@instance).include?('@foo')
|
173
173
|
assert_equal cached_result, @instance.send(:instance_variable_get, :@foo)
|
174
174
|
assert_not_equal cached_result, new_cache = @instance.foo(:reload)
|
175
175
|
assert_equal new_cache, @instance.foo
|
@@ -177,21 +177,21 @@ class ModuleExtensionsTest < Test::Unit::TestCase
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def test_customizing_memoize_storage
|
180
|
-
assert
|
181
|
-
assert
|
180
|
+
assert !instance_variables_of(@instance).include?('@bar')
|
181
|
+
assert !instance_variables_of(@instance).include?('@baz')
|
182
182
|
cached_result = @instance.bar
|
183
|
-
assert
|
184
|
-
assert @instance.
|
183
|
+
assert !instance_variables_of(@instance).include?('@bar')
|
184
|
+
assert instance_variables_of(@instance).include?('@baz')
|
185
185
|
assert_equal cached_result, @instance.bar
|
186
186
|
assert_equal cached_result, @instance.send(:instance_variable_get, :@baz)
|
187
187
|
assert_nil @instance.send(:instance_variable_get, :@bar)
|
188
188
|
end
|
189
189
|
|
190
190
|
def test_memoized
|
191
|
-
assert
|
191
|
+
assert !instance_variables_of(@instance).include?('@quux')
|
192
192
|
cached_result = @instance.quux
|
193
193
|
assert_equal cached_result, @instance.quux
|
194
|
-
assert @instance.
|
194
|
+
assert instance_variables_of(@instance).include?('@quux')
|
195
195
|
assert_equal cached_result, @instance.send(:instance_variable_get, :@quux)
|
196
196
|
assert_not_equal cached_result, new_cache = @instance.quux(:reload)
|
197
197
|
assert_equal new_cache, @instance.quux
|
@@ -220,6 +220,15 @@ class ModuleExtensionsTest < Test::Unit::TestCase
|
|
220
220
|
assert_equal 'bar', some_module::FOO
|
221
221
|
assert_equal 'bar', some_module.foo
|
222
222
|
end
|
223
|
+
|
224
|
+
private
|
225
|
+
# For 1.9 compatibility
|
226
|
+
def instance_variables_of(object)
|
227
|
+
object.instance_variables.map do |instance_variable|
|
228
|
+
instance_variable.to_s
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
223
232
|
end
|
224
233
|
|
225
234
|
class AttributeProxyTest < Test::Unit::TestCase
|
data/test/logging_test.rb
CHANGED
@@ -58,7 +58,7 @@ class LogLineTest < Test::Unit::TestCase
|
|
58
58
|
expected_results = {
|
59
59
|
:owner => Owner.new('id' => 'bb2041a25975c3d4ce9775fe9e93e5b77a6a9fad97dc7e00686191f3790b13f1'),
|
60
60
|
:bucket => 'marcel',
|
61
|
-
:time => Time.parse('
|
61
|
+
:time => Time.parse('Nov 14 2006 06:36:48 +0000'),
|
62
62
|
:remote_ip => '67.165.183.125',
|
63
63
|
:request_id => '8B5297D428A05432',
|
64
64
|
:requestor => Owner.new('id' => 'bb2041a25975c3d4ce9775fe9e93e5b77a6a9fad97dc7e00686191f3790b13f1'),
|
data/test/remote/test_helper.rb
CHANGED
@@ -2,7 +2,10 @@ require 'test/unit'
|
|
2
2
|
require 'uri'
|
3
3
|
$:.unshift File.dirname(__FILE__) + '/../../lib'
|
4
4
|
require 'aws/s3'
|
5
|
-
|
5
|
+
begin
|
6
|
+
require_library_or_gem 'breakpoint'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
6
9
|
|
7
10
|
TEST_BUCKET = 'aws-s3-tests'
|
8
11
|
TEST_FILE = File.dirname(__FILE__) + '/test_file.data'
|
data/test/test_helper.rb
CHANGED
@@ -3,7 +3,10 @@ $:.unshift File.dirname(__FILE__) + '/../lib'
|
|
3
3
|
require 'aws/s3'
|
4
4
|
require File.dirname(__FILE__) + '/mocks/fake_response'
|
5
5
|
require File.dirname(__FILE__) + '/fixtures'
|
6
|
-
|
6
|
+
begin
|
7
|
+
require_library_or_gem 'ruby-debug'
|
8
|
+
rescue LoadError
|
9
|
+
end
|
7
10
|
require_library_or_gem 'flexmock'
|
8
11
|
require_library_or_gem 'flexmock/test_unit'
|
9
12
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcel Molina Jr.
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-04-19 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -83,6 +83,8 @@ files:
|
|
83
83
|
- INSTALL
|
84
84
|
has_rdoc: true
|
85
85
|
homepage: http://amazon.rubyforge.org
|
86
|
+
licenses: []
|
87
|
+
|
86
88
|
post_install_message:
|
87
89
|
rdoc_options:
|
88
90
|
- --title
|
@@ -108,9 +110,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
110
|
requirements: []
|
109
111
|
|
110
112
|
rubyforge_project: amazon
|
111
|
-
rubygems_version: 1.2
|
113
|
+
rubygems_version: 1.3.2
|
112
114
|
signing_key:
|
113
|
-
specification_version:
|
115
|
+
specification_version: 3
|
114
116
|
summary: Client library for Amazon's Simple Storage Service's REST API
|
115
117
|
test_files:
|
116
118
|
- test/acl_test.rb
|
@@ -120,7 +122,6 @@ test_files:
|
|
120
122
|
- test/connection_test.rb
|
121
123
|
- test/error_test.rb
|
122
124
|
- test/extensions_test.rb
|
123
|
-
- test/fixtures
|
124
125
|
- test/fixtures/buckets.yml
|
125
126
|
- test/fixtures/errors.yml
|
126
127
|
- test/fixtures/headers.yml
|
@@ -130,11 +131,9 @@ test_files:
|
|
130
131
|
- test/fixtures/policies.yml
|
131
132
|
- test/fixtures.rb
|
132
133
|
- test/logging_test.rb
|
133
|
-
- test/mocks
|
134
134
|
- test/mocks/fake_response.rb
|
135
135
|
- test/object_test.rb
|
136
136
|
- test/parsing_test.rb
|
137
|
-
- test/remote
|
138
137
|
- test/remote/acl_test.rb
|
139
138
|
- test/remote/bittorrent_test.rb
|
140
139
|
- test/remote/bucket_test.rb
|