nokogiri-streaming-reader 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/nokogiri/streaming/reader.rb +28 -2
- data/lib/nokogiri/streaming/version.rb +2 -2
- data/nokogiri-streaming-reader.gemspec +1 -1
- data/spec/reader_spec.rb +3 -3
- metadata +19 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1eb4862727aea104efe91c018f0a9e2a0028cb14
|
4
|
+
data.tar.gz: fd0873746033091ef29e77e69010ef6fe79c96be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c339ad735fc8f065a6f73ed3eba1e9e5aadf32cf2fe07bc348c308d8945d98cfa72abd48bef9f7f5ba574446b98fc4032dbe19acd35cc30e93f9b0b126888b6c
|
7
|
+
data.tar.gz: e9ab7271bfaf71a817d4fff7da753b793c197332ea74fe1a9d43405c872c5f7f1f3aa7f9518d08b7ccb1eb4665787abce484cb2669bb06d15618f6799aafbe83
|
@@ -3,12 +3,35 @@ require 'nokogiri'
|
|
3
3
|
module Nokogiri
|
4
4
|
module Streaming
|
5
5
|
|
6
|
+
# IO wrapper which traps stream exceptions. This works around bug in Nokogiri's
|
7
|
+
# SAX code, which seems to ignore exceptions entirely.
|
8
|
+
class IOWrapper
|
9
|
+
def initialize(source)
|
10
|
+
@source = source
|
11
|
+
end
|
12
|
+
|
13
|
+
def read(length = nil)
|
14
|
+
begin
|
15
|
+
return @source.read(length)
|
16
|
+
rescue => e
|
17
|
+
@exception = e
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def close
|
23
|
+
@stream.close
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :exception
|
27
|
+
end
|
28
|
+
|
6
29
|
class ParseError < StandardError; end
|
7
30
|
|
8
31
|
class Reader < XML::SAX::Document
|
9
32
|
|
10
33
|
def initialize(source)
|
11
|
-
@source = source
|
34
|
+
@source = IOWrapper.new(source)
|
12
35
|
@parser = Nokogiri::XML::SAX::Parser.new(self)
|
13
36
|
@stack = []
|
14
37
|
@triggers = {}
|
@@ -35,6 +58,9 @@ module Nokogiri
|
|
35
58
|
#
|
36
59
|
|
37
60
|
def error(message)
|
61
|
+
if @source.exception
|
62
|
+
raise @source.exception
|
63
|
+
end
|
38
64
|
raise ParseError.new(message)
|
39
65
|
end
|
40
66
|
|
@@ -94,4 +120,4 @@ module Nokogiri
|
|
94
120
|
end
|
95
121
|
|
96
122
|
end
|
97
|
-
end
|
123
|
+
end
|
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "nokogiri", ">= 1.4"
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.5"
|
25
25
|
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rspec", '>= 3.0'
|
27
27
|
end
|
data/spec/reader_spec.rb
CHANGED
@@ -45,7 +45,7 @@ describe Nokogiri::Streaming::Reader do
|
|
45
45
|
reader = subject.new(doc)
|
46
46
|
reader.on('/root') do |e|
|
47
47
|
expect(e.children.length).to eq 1
|
48
|
-
expect(e.children.first.cdata?).to
|
48
|
+
expect(e.children.first.cdata?).to be true
|
49
49
|
end
|
50
50
|
reader.run
|
51
51
|
end
|
@@ -58,8 +58,8 @@ describe Nokogiri::Streaming::Reader do
|
|
58
58
|
reader = subject.new(doc)
|
59
59
|
reader.on('/root') do |e|
|
60
60
|
expect(e.children.length).to eq 1
|
61
|
-
expect(e.children.first.text?).to
|
62
|
-
expect(e.children.first.cdata?).to
|
61
|
+
expect(e.children.first.text?).to be true
|
62
|
+
expect(e.children.first.cdata?).to be false
|
63
63
|
end
|
64
64
|
reader.run
|
65
65
|
end
|
metadata
CHANGED
@@ -1,80 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokogiri-streaming-reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alexander Staubo
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: nokogiri
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.4'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.4'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '1.5'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '1.5'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
61
|
+
version: '3.0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
68
|
+
version: '3.0'
|
78
69
|
description: Simple streaming reader for Nokogiri.
|
79
70
|
email:
|
80
71
|
- alex@bengler.no
|
@@ -82,7 +73,7 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
86
77
|
- Gemfile
|
87
78
|
- LICENSE.txt
|
88
79
|
- README.md
|
@@ -95,28 +86,28 @@ files:
|
|
95
86
|
homepage: ''
|
96
87
|
licenses:
|
97
88
|
- MIT
|
89
|
+
metadata: {}
|
98
90
|
post_install_message:
|
99
91
|
rdoc_options: []
|
100
92
|
require_paths:
|
101
93
|
- lib
|
102
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
-
none: false
|
104
95
|
requirements:
|
105
|
-
- -
|
96
|
+
- - ">="
|
106
97
|
- !ruby/object:Gem::Version
|
107
98
|
version: '0'
|
108
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
100
|
requirements:
|
111
|
-
- -
|
101
|
+
- - ">="
|
112
102
|
- !ruby/object:Gem::Version
|
113
103
|
version: '0'
|
114
104
|
requirements: []
|
115
105
|
rubyforge_project:
|
116
|
-
rubygems_version:
|
106
|
+
rubygems_version: 2.2.5
|
117
107
|
signing_key:
|
118
|
-
specification_version:
|
108
|
+
specification_version: 4
|
119
109
|
summary: Simple streaming reader for Nokogiri.
|
120
110
|
test_files:
|
121
111
|
- spec/reader_spec.rb
|
122
112
|
- spec/spec_helper.rb
|
113
|
+
has_rdoc:
|