aws-s3 0.1.1 → 0.1.2

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.
@@ -6,7 +6,6 @@ require 'digest/sha1'
6
6
  require 'net/https'
7
7
  require 'time'
8
8
  require 'date'
9
- require 'generator'
10
9
 
11
10
  $:.unshift(File.dirname(__FILE__))
12
11
  require 's3/extensions'
@@ -42,6 +41,7 @@ AWS::S3::S3Object.class_eval do
42
41
  include AWS::S3::BitTorrent
43
42
  end
44
43
 
44
+ require_library_or_gem 'xmlsimple' unless defined? XmlSimple
45
45
  # XmlSimple is a very convenient way of dealing with the xml needs of this library, but unfortunately
46
46
  # it is powered by REXML which is both very slow (even for me who does not privilege performance)
47
47
  # and consumes way too much memory (beach balls a MacBookPro with 2GB of memory for 2 minutes while parsing 60KB of xml).
@@ -49,16 +49,15 @@ end
49
49
  # So, if libxml is installed, we use the FasterXmlSimple library, that provides most of the functionality of XmlSimple
50
50
  # except it uses the xml/libxml library for xml parsing. If libxml isn't installed, we just fall back on
51
51
  # XmlSimple.
52
- AWS::S3::Parsing.parser =
52
+ AWS::S3::Parsing.parser =
53
53
  begin
54
- # N.B. Push, don't shift
55
- $:.push(File.join(File.dirname(__FILE__), '..', '..', 'support', 'faster-xml-simple', 'lib'))
56
- require_library_or_gem 'faster_xml_simple'
54
+ require_library_or_gem 'xml/libxml'
57
55
  # Older version of libxml aren't stable (bus error when requesting attributes that don't exist) so we
58
56
  # have to use a version greater than '0.3.8.2'.
59
57
  raise LoadError unless XML::Parser::VERSION > '0.3.8.2'
58
+ $:.push(File.join(File.dirname(__FILE__), '..', '..', 'support', 'faster-xml-simple', 'lib'))
59
+ require_library_or_gem 'faster_xml_simple'
60
60
  FasterXmlSimple
61
61
  rescue LoadError
62
- require_library_or_gem 'xmlsimple' unless defined? XmlSimple
63
62
  XmlSimple
64
63
  end
@@ -33,7 +33,7 @@ module AWS
33
33
  keys = hash.keys.map {|key| key.underscore}
34
34
  values = hash.values.map {|value| typecast(value)}
35
35
  keys.inject({}) do |new_hash, key|
36
- new_hash[key] = values.shift
36
+ new_hash[key] = values.slice!(0)
37
37
  new_hash
38
38
  end
39
39
  end
@@ -49,35 +49,23 @@ module AWS
49
49
  end
50
50
 
51
51
  def coerce
52
- attempt = nil
53
- break unless (attempt = coercions.next).nil? while coercions.next?
54
- attempt.nil? ? self : attempt
52
+ case self
53
+ when 'true': true
54
+ when 'false': false
55
+ when /^\d+$/: Integer(self)
56
+ when datetime_format: Time.parse(self)
57
+ else
58
+ self
59
+ end
55
60
  end
56
61
 
57
62
  private
58
-
59
- def coercions
60
- Generator.new do |self.generator|
61
- try { self == 'true' }
62
- try { [self == 'false', false] }
63
- try { Integer(self) }
64
- try { Time.parse(self) } if appears_to_be_date?
65
- end
66
- end
67
- memoized :coercions
68
-
69
- def try
70
- attempt, desired = yield
71
- generator.yield(desired.nil? ? attempt : desired) if attempt
72
- rescue ArgumentError
73
- generator.yield nil
74
- end
75
63
 
76
64
  # Lame hack since Date._parse is so accepting. S3 dates are of the form: '2006-10-29T23:14:47.000Z'
77
65
  # so unless the string looks like that, don't even try, otherwise it might convert an object's
78
66
  # key from something like '03 1-2-3-Apple-Tree.mp3' to Sat Feb 03 00:00:00 CST 2001.
79
- def appears_to_be_date?
80
- self =~ /^\d{4}-\d{2}-\d{2}\w\d{2}:\d{2}:\d{2}/
67
+ def datetime_format
68
+ /^\d{4}-\d{2}-\d{2}\w\d{2}:\d{2}:\d{2}/
81
69
  end
82
70
  end
83
71
 
@@ -3,10 +3,10 @@ module AWS
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = '0'
5
5
  MINOR = '1'
6
- TINY = '1'
7
- REVISION = '$Revision: 84 $'[/\d+/]
6
+ TINY = '2'
7
+ BETA = nil # Time.now.to_i.to_s
8
8
  end
9
9
 
10
- Version = [VERSION::MAJOR, VERSION::MINOR, VERSION::TINY || VERSION::REVISION] * '.'
10
+ Version = [VERSION::MAJOR, VERSION::MINOR, VERSION::TINY, VERSION::BETA].compact * '.'
11
11
  end
12
12
  end
@@ -56,7 +56,9 @@ class FasterXmlSimple
56
56
  hash
57
57
  end
58
58
  end
59
- return nil if result.empty?
59
+ if result.empty?
60
+ return empty_element
61
+ end
60
62
  # Compact them to ensure it complies with the user's requests
61
63
  inline_single_element_arrays(result)
62
64
  suppress_empty(result) if suppress_empty?
@@ -64,12 +66,22 @@ class FasterXmlSimple
64
66
  result
65
67
  end
66
68
 
69
+ def empty_element
70
+ if options['suppressempty'] == true
71
+ raise 'unimplemented'
72
+ elsif !options.has_key? 'suppressempty'
73
+ {}
74
+ else
75
+ options['suppressempty']
76
+ end
77
+ end
78
+
67
79
  def content_key
68
80
  options['contentkey']
69
81
  end
70
82
 
71
83
  def force_array?(key_name)
72
- options['forcearray'].include?(key_name)
84
+ Array(options['forcearray']).include?(key_name)
73
85
  end
74
86
 
75
87
  def inline_single_element_arrays(result)
@@ -112,4 +124,10 @@ class FasterXmlSimple
112
124
  def parse(string)
113
125
  XML::Parser.string(string).parse
114
126
  end
127
+ end
128
+
129
+ class XmlSimple
130
+ def self.xml_in(*args)
131
+ FasterXmlSimple.xml_in *args
132
+ end
115
133
  end
@@ -1,10 +1,9 @@
1
1
  require 'faster_xml_simple'
2
2
  require 'test/unit'
3
- require 'pp'
4
3
 
5
4
  class RegressionTest < Test::Unit::TestCase
6
5
  def test_content_nil_regressions
7
- expected = {"asdf"=>{"jklsemicolon"=>nil}}
6
+ expected = {"asdf"=>{"jklsemicolon"=>{}}}
8
7
  assert_equal expected, FasterXmlSimple.xml_in("<asdf><jklsemicolon /></asdf>")
9
8
  assert_equal expected, FasterXmlSimple.xml_in("<asdf><jklsemicolon /></asdf>", 'forcearray'=>['asdf'])
10
9
  end
@@ -13,4 +12,19 @@ class RegressionTest < Test::Unit::TestCase
13
12
  str = File.read("test/fixtures/test-7.xml")
14
13
  assert_nil FasterXmlSimple.xml_in(str)["AccessControlPolicy"]["AccessControlList"]["__content__"]
15
14
  end
15
+
16
+ def test_xml_simple_transparency
17
+ assert_equal XmlSimple.xml_in("<asdf />"), FasterXmlSimple.xml_in("<asdf />")
18
+ end
19
+
20
+ def test_suppress_empty_variations
21
+ str = "<asdf><fdsa /></asdf>"
22
+
23
+ assert_equal Hash.new, FasterXmlSimple.xml_in(str)["asdf"]["fdsa"]
24
+ assert_nil FasterXmlSimple.xml_in(str, 'suppressempty'=>nil)["asdf"]["fdsa"]
25
+ assert_equal '', FasterXmlSimple.xml_in(str, 'suppressempty'=>'')["asdf"]["fdsa"]
26
+ # assert !FasterXmlSimple.xml_in(str, 'suppressempty'=>true)["asdf"].has_key?("fdsa")
27
+ end
28
+
29
+
16
30
  end
@@ -10,13 +10,38 @@ class XmlSimpleComparisonTest < Test::Unit::TestCase
10
10
  xml_file_name = file_name
11
11
  method_name = File.basename(file_name, ".xml").gsub('-', '_')
12
12
  yml_file_name = file_name.gsub('xml', 'yml')
13
+ rails_yml_file_name = file_name.gsub('xml', 'rails.yml')
13
14
  class_eval <<-EOV, __FILE__, __LINE__
14
15
  def #{method_name}
15
16
  assert_equal YAML.load(File.read('#{yml_file_name}')),
16
- FasterXmlSimple.xml_in(File.read('#{xml_file_name}'), 'forcearray'=>['something-else', 'Grant'])
17
+ FasterXmlSimple.xml_in(File.read('#{xml_file_name}'), default_options )
18
+ end
19
+
20
+ def #{method_name}_rails
21
+ assert_equal YAML.load(File.read('#{rails_yml_file_name}')),
22
+ FasterXmlSimple.xml_in(File.read('#{xml_file_name}'), rails_options)
17
23
  end
18
24
  EOV
19
25
  end
20
26
 
27
+ def default_options
28
+ {
29
+ 'keeproot' => true,
30
+ 'contentkey' => '__content__',
31
+ 'forcecontent' => true,
32
+ 'suppressempty' => nil,
33
+ 'forcearray' => ['something-else']
34
+ }
35
+ end
36
+
37
+ def rails_options
38
+ {
39
+ 'forcearray' => false,
40
+ 'forcecontent' => true,
41
+ 'keeproot' => true,
42
+ 'contentkey' => '__content__'
43
+ }
44
+ end
45
+
21
46
 
22
47
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: aws-s3
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2006-11-28 00:00:00 -06:00
6
+ version: 0.1.2
7
+ date: 2006-11-30 00:00:00 -06:00
8
8
  summary: Client library for Amazon's Simple Storage Service's REST API
9
9
  require_paths:
10
10
  - lib