aws-s3 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 = Base64.encode64(OpenSSL::HMAC.digest(digest, secret_access_key, canonical_string)).strip
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
 
@@ -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 *retry_exceptions
78
- attempts == 3 ? raise : (attempts += 1; retry)
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): attributes[method.to_s]
230
- when attributes.has_key?(method): attributes[method]
231
- else super
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
@@ -7,7 +7,7 @@ module AWS
7
7
  end
8
8
 
9
9
  def prepare_path(path)
10
- path = path.remove_extended unless path.utf8?
10
+ path = path.remove_extended unless path.valid_utf8?
11
11
  URI.escape(path)
12
12
  end
13
13
  end
@@ -26,9 +26,16 @@ class Hash
26
26
  end
27
27
 
28
28
  class String
29
- def previous!
30
- self[-1] -= 1
31
- self
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
- def utf8?
52
- scan(/[^\x00-\xa0]/u) { |s| s.unpack('U') }
53
- true
54
- rescue ArgumentError
55
- false
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#utf8?
60
- def remove_extended!
61
- gsub!(/[\x80-\xFF]/) { "%02X" % $&[0] }
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': true
79
- when 'false': false
102
+ when 'true'; true
103
+ when 'false'; false
80
104
  # Don't coerce numbers that start with zero
81
- when /^[1-9]+\d*$/: Integer(self)
82
- when datetime_format: Time.parse(self)
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 #if RUBY_VERSION < '1.8.7'
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
- storage = "@#{storage || __method__(1)}"
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
@@ -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
- def lines
101
- log.value.map {|line| Line.new(line)}
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
- month = datetime[/[a-z]+/i]
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
@@ -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.utf8?
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
@@ -2,8 +2,8 @@ module AWS
2
2
  module S3
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = '0'
5
- MINOR = '5'
6
- TINY = '1'
5
+ MINOR = '6'
6
+ TINY = '0'
7
7
  BETA = nil # Time.now.to_i.to_s
8
8
  end
9
9
 
@@ -65,14 +65,14 @@ class StringExtensionsTest < Test::Unit::TestCase
65
65
  end
66
66
  end
67
67
 
68
- def test_utf8?
69
- assert !"318597/620065/GTL_75\24300_A600_A610.zip".utf8?
70
- assert "318597/620065/GTL_75£00_A600_A610.zip".utf8?
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.utf8?
75
- assert "318597/620065/GTL_75£00_A600_A610.zip".remove_extended.utf8?
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 !@instance.instance_variables.include?('@foo')
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.instance_variables.include?('@foo')
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 !@instance.instance_variables.include?('@bar')
181
- assert !@instance.instance_variables.include?('@baz')
180
+ assert !instance_variables_of(@instance).include?('@bar')
181
+ assert !instance_variables_of(@instance).include?('@baz')
182
182
  cached_result = @instance.bar
183
- assert !@instance.instance_variables.include?('@bar')
184
- assert @instance.instance_variables.include?('@baz')
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 !@instance.instance_variables.include?('@quux')
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.instance_variables.include?('@quux')
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
@@ -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('11/14/2006 06:36:48 +0000'),
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'),
@@ -2,7 +2,10 @@ require 'test/unit'
2
2
  require 'uri'
3
3
  $:.unshift File.dirname(__FILE__) + '/../../lib'
4
4
  require 'aws/s3'
5
- require_library_or_gem 'breakpoint'
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'
@@ -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
- require_library_or_gem 'ruby-debug'
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.5.1
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: 2008-07-03 00:00:00 -05:00
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.0
113
+ rubygems_version: 1.3.2
112
114
  signing_key:
113
- specification_version: 2
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