xmlparser 0.6.81 → 0.7.2.1

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,49 +6,61 @@
6
6
  ##
7
7
 
8
8
  require 'xml/dom/core'
9
- require 'md5'
10
- require 'uconv'
9
+ require 'digest/md5'
11
10
 
12
11
  module XML
13
12
  module DOM
14
-
15
13
  def self.tou16(str)
16
- Uconv.u16swap(Uconv.u8tou16(str))
14
+ if defined?(::Encoding)
15
+ str.encode(::Encoding::UTF_16BE).force_encoding(::Encoding::ASCII_8BIT)
16
+ else
17
+ str.unpack("U*").map {|v|
18
+ if v >= 0x10000 && v <= 0x10ffff
19
+ ## surrogate pair
20
+ hi = ((v - 0x10000) >> 10) | 0xd800
21
+ low = (v & 1023) | 0xdc00
22
+ [hi, low].pack("n*")
23
+ else
24
+ [v].pack("n*")
25
+ end
26
+ }.join
27
+ end
17
28
  end
18
29
 
19
30
  class Node
20
- def getDigest(force = false)
31
+ def getDigest(algorithm = Digest::MD5, force = false)
21
32
  nil
22
33
  end
23
34
  end
24
35
 
25
36
  class Text
26
- def getDigest(force = false)
37
+ def getDigest(algorithm = Digest::MD5, force = false)
27
38
  (!force && @digest) ||
28
- @digest = MD5.new([TEXT_NODE].pack("N") + DOM.tou16(nodeValue)).digest
39
+ @digest = algorithm.digest([TEXT_NODE].pack("N") + DOM.tou16(nodeValue))
40
+ @digest
29
41
  end
30
42
  end
31
43
 
32
44
  ## class Comment
33
- ## def getDigest(force = false)
45
+ ## def getDigest(algorithm = Digest::MD5, force = false)
34
46
  ## (!force && @digest) ||
35
- ## @digest = MD5.new([COMMENT_NODE].pack("N") + DOM.tou16(data)).digest
47
+ ## @digest = algorithm.digest([COMMENT_NODE].pack("N") + DOM.tou16(data)).digest
36
48
  ## end
37
49
  ## end
38
50
 
39
51
  class ProcessingInstruction
40
- def getDigest(force = false)
52
+ def getDigest(algorithm = Digest::MD5, force = false)
41
53
  (!force && @digest) ||
42
- @digest = MD5.new([PROCESSING_INSTRUCTION_NODE].pack("N") +
43
- DOM.tou16(target) + "\0\0" + DOM.tou16(data)).digest
54
+ @digest = algorithm.digest([PROCESSING_INSTRUCTION_NODE].pack("N") +
55
+ DOM.tou16(target) + "\0\0" + DOM.tou16(data))
44
56
  end
45
57
  end
46
58
 
47
59
  class Attr
48
- def getDigest(force = false)
60
+ def getDigest(algorithm = Digest::MD5, force = false)
49
61
  (!force && @digest) ||
50
- @digest = MD5.new([ATTRIBUTE_NODE].pack("N") +
51
- DOM.tou16(nodeName) + "\0\0" + DOM.tou16(nodeValue)).digest
62
+ @digest = algorithm.digest([ATTRIBUTE_NODE].pack("N") +
63
+ DOM.tou16(nodeName) + "\0\0" + DOM.tou16(nodeValue))
52
64
  end
53
65
  end
54
66
 
@@ -61,7 +73,7 @@ module XML
61
73
  end
62
74
 
63
75
  class Element
64
- def getDigest(force = false)
76
+ def getDigest(algorithm = Digest::MD5, force = false)
65
77
  return @digest if (!force && @digest)
66
78
  attr = attributes
67
79
  children = childNodes
@@ -71,22 +83,22 @@ module XML
71
83
  attr_array = attr.sort {|a, b|
72
84
  DOM.tou16(a.nodeName) <=> DOM.tou16(b.nodeName)}
73
85
  attr_array.each {|a|
74
- attr_digests << a.getDigest(force)
86
+ attr_digests << a.getDigest(algorithm, force)
75
87
  }
76
88
  end
77
89
  children_num = 0
78
90
  children.each {|c|
79
91
  next if c.nodeType == COMMENT_NODE
80
92
  children_num += 1
81
- children_digests << c.getDigest(force)
93
+ children_digests << c.getDigest(algorithm, force)
82
94
  }
83
- @digest = MD5.new([ELEMENT_NODE].pack("N") +
84
- DOM.tou16(nodeName) +
85
- "\0\0" +
86
- [attr.length].pack("N") +
87
- attr_digests +
88
- [children_num].pack("N") +
89
- children_digests).digest
95
+ @digest = algorithm.digest([ELEMENT_NODE].pack("N") +
96
+ DOM.tou16(nodeName) +
97
+ "\0\0" +
98
+ [attr.length].pack("N") +
99
+ attr_digests +
100
+ [children_num].pack("N") +
101
+ children_digests)
90
102
  end
91
103
  end
92
104
 
@@ -5,30 +5,19 @@
5
5
 
6
6
  require 'xml/dom2/domentityresolver'
7
7
  require 'xml/dom2/dominputsource'
8
+ require 'open-uri'
8
9
 
9
10
  module XML
10
11
  module DOM
11
12
  class DOMEntityResolverImpl
12
13
  include DOMEntityResolver
13
14
 
14
- ## replace 'open' by WGET::open
15
- begin
16
- require 'wget'
17
- ## include WGET
18
- rescue
19
- ## ignore
20
- end
21
-
22
15
  ## DOMInputSource resolveEntity(publicId, systemId)
23
16
  def resolveEntity(publicId, systemId)
24
17
  ret = DOMInputSource.new
25
18
  ret.publicId = publicId
26
19
  ret.systemId = systemId
27
- if systemId =~ /file:/
28
- ret.byteStream = open(systemId.sub('^file://', ''))
29
- else
30
- ret.byteStream = WGET::open(systemId)
31
- end
20
+ ret.byteStream = open(systemId, 'rb')
32
21
  ret
33
22
  end
34
23
  end
metadata CHANGED
@@ -1,111 +1,97 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.3
3
- specification_version: 1
1
+ --- !ruby/object:Gem::Specification
4
2
  name: xmlparser
5
- version: !ruby/object:Gem::Version
6
- version: 0.6.81
7
- date: 2007-05-21 00:00:00 -04:00
8
- summary: Ruby bindings to the Expat XML parsing library
9
- require_paths:
10
- - lib
11
- email:
12
- homepage:
13
- rubyforge_project: xmlparser
14
- description: Ruby bindings to the Expat XML parsing library
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yoshida Mataso
15
9
  autorequire:
16
- default_executable:
17
10
  bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
25
- platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
- authors:
30
- - Yoshida Mataso with Jeff Hodges
31
- files:
32
- - lib/xmldigest.rb
33
- - lib/saxdriver.rb
34
- - lib/xmltree.rb
35
- - lib/xml
36
- - lib/xmltreebuilder.rb
37
- - lib/wget.rb
11
+ cert_chain: []
12
+ date: 2012-03-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Ruby bindings to the Expat XML parsing library
15
+ email:
16
+ executables: []
17
+ extensions:
18
+ - ext/extconf.rb
19
+ extra_rdoc_files:
20
+ - README
21
+ - README.ja
22
+ - MANIFEST
23
+ files:
38
24
  - lib/sax.rb
25
+ - lib/saxdriver.rb
26
+ - lib/xmldigest.rb
39
27
  - lib/xmltreevisitor.rb
40
- - lib/xml/dom
41
- - lib/xml/saxdriver.rb
42
- - lib/xml/dom2
43
- - lib/xml/xpath.rb
44
- - lib/xml/parser.rb
45
- - lib/xml/parserns.rb
46
- - lib/xml/sax.rb
47
- - lib/xml/xpath.ry
48
- - lib/xml/encoding-ja.rb
49
- - lib/xml/dom/digest.rb
50
- - lib/xml/dom/core.rb
51
- - lib/xml/dom/visitor.rb
52
- - lib/xml/dom/builder-ja.rb
53
- - lib/xml/dom/builder.rb
54
- - lib/xml/dom2/notation.rb
55
- - lib/xml/dom2/domimplementation.rb
56
- - lib/xml/dom2/dombuilderfilter.rb
57
- - lib/xml/dom2/node.rb
58
- - lib/xml/dom2/domentityresolverimpl.rb
59
- - lib/xml/dom2/entity.rb
28
+ - lib/xmltree.rb
60
29
  - lib/xml/dom2/documenttype.rb
30
+ - lib/xml/dom2/xpath.rb
31
+ - lib/xml/dom2/notation.rb
61
32
  - lib/xml/dom2/documentfragment.rb
62
- - lib/xml/dom2/comment.rb
63
- - lib/xml/dom2/dombuilder.rb
64
- - lib/xml/dom2/entityreference.rb
65
- - lib/xml/dom2/processinginstruction.rb
66
33
  - lib/xml/dom2/core.rb
67
- - lib/xml/dom2/namednodemap.rb
68
- - lib/xml/dom2/document.rb
34
+ - lib/xml/dom2/dominputsource.rb
69
35
  - lib/xml/dom2/attr.rb
70
- - lib/xml/dom2/nodelist.rb
71
- - lib/xml/dom2/domentityresolver.rb
72
- - lib/xml/dom2/text.rb
36
+ - lib/xml/dom2/domexception.rb
37
+ - lib/xml/dom2/entity.rb
73
38
  - lib/xml/dom2/cdatasection.rb
74
- - lib/xml/dom2/xpath.rb
75
- - lib/xml/dom2/dominputsource.rb
39
+ - lib/xml/dom2/node.rb
40
+ - lib/xml/dom2/dombuilder.rb
41
+ - lib/xml/dom2/nodelist.rb
42
+ - lib/xml/dom2/domentityresolverimpl.rb
43
+ - lib/xml/dom2/domimplementation.rb
76
44
  - lib/xml/dom2/element.rb
77
- - lib/xml/dom2/domexception.rb
45
+ - lib/xml/dom2/dombuilderfilter.rb
78
46
  - lib/xml/dom2/characterdata.rb
47
+ - lib/xml/dom2/text.rb
48
+ - lib/xml/dom2/document.rb
49
+ - lib/xml/dom2/namednodemap.rb
50
+ - lib/xml/dom2/domentityresolver.rb
51
+ - lib/xml/dom2/comment.rb
52
+ - lib/xml/dom2/processinginstruction.rb
53
+ - lib/xml/dom2/entityreference.rb
54
+ - lib/xml/xpath.rb
55
+ - lib/xml/sax.rb
56
+ - lib/xml/parserns.rb
57
+ - lib/xml/saxdriver.rb
58
+ - lib/xml/dom/builder.rb
59
+ - lib/xml/dom/digest.rb
60
+ - lib/xml/dom/core.rb
61
+ - lib/xml/dom/visitor.rb
62
+ - lib/xml/parser.rb
63
+ - lib/xmltreebuilder.rb
64
+ - lib/wget.rb
65
+ - lib/xml/xpath.ry
79
66
  - ext/encoding.h
80
- - ext/xmlparser
81
- - ext/xmlparser/xmlparser.c
82
- - ext/xmlparser/mkrf_conf.rb
67
+ - ext/extconf.rb
68
+ - ext/xmlparser.c
83
69
  - README
84
70
  - README.ja
85
71
  - MANIFEST
86
- - samples
87
- test_files: []
88
-
72
+ homepage: http://www.yoshidam.net/Ruby.html
73
+ licenses: []
74
+ post_install_message:
89
75
  rdoc_options: []
90
-
91
- extra_rdoc_files:
92
- - README
93
- - README.ja
94
- - MANIFEST
95
- - samples
96
- executables: []
97
-
98
- extensions:
99
- - Rakefile
76
+ require_paths:
77
+ - lib
78
+ - ext
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
100
91
  requirements: []
101
-
102
- dependencies:
103
- - !ruby/object:Gem::Dependency
104
- name: mkrf
105
- version_requirement:
106
- version_requirements: !ruby/object:Gem::Version::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: 0.2.1
111
- version:
92
+ rubyforge_project: xmlparser
93
+ rubygems_version: 1.8.15
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Ruby bindings to the Expat XML parsing library
97
+ test_files: []
data/Rakefile DELETED
@@ -1,34 +0,0 @@
1
- #!/usr/bin/ruby
2
- require 'rubygems'
3
- require 'rake'
4
- require 'rake/testtask'
5
- require 'rake/clean'
6
- require 'rake/gempackagetask'
7
- require 'rake/rdoctask'
8
- require 'mkrf/rakehelper'
9
- require 'fileutils'
10
- include FileUtils
11
-
12
- setup_clean ["pkg", "lib/*.bundle", "*.gem", ".config", "ext/**/Rakefile"]
13
-
14
- setup_extension('xmlparser','xmlparser')
15
-
16
- desc "Does a full compile"
17
- task :default => [:xmlparser]
18
-
19
- task 'extension' => :default
20
- version = "0.6.81"
21
- name = "xmlparser"
22
-
23
- setup_gem(name, version) do |spec|
24
- spec.summary = "Ruby bindings to the Expat XML parsing library"
25
- spec.description = spec.summary
26
- spec.author = "Yoshida Mataso with Jeff Hodges"
27
- spec.add_dependency("mkrf", ">=0.2.1")
28
- spec.extensions << "Rakefile"
29
- spec.files = FileList["lib/**/*","ext/**/*"].exclude("rdoc").to_a
30
- spec.has_rdoc = false
31
- spec.extra_rdoc_files=['README', 'README.ja', 'MANIFEST', 'samples']
32
- spec.rubyforge_project = 'xmlparser'
33
- end
34
-
@@ -1,28 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require 'rubygems'
4
- require 'mkrf'
5
-
6
- def crash(str)
7
- printf(" extconf failure: %s\n", str)
8
- exit 1
9
- end
10
-
11
- Mkrf::Generator.new('xmlparser') do |g|
12
- if g.include_header('expat.h', '/opt/include','/usr/local/include','/usr/include')
13
- g.include_library('expat',function='XML_ParserCreate', '/opt/lib', '/usr/local/lib', '/usr/lib')
14
- elsif g.include_header('libxmltok', '/opt/include','/usr/local/include','/usr/include')
15
- g.include_library('xmltok', function='XML_ParserCreate', '/opt/lib', '/usr/local/lib', '/usr/lib')
16
- end
17
- if g.has_function?("XML_SetNotStandaloneHandler")
18
- #g.cflags << ' -DNEW_EXPAT'
19
- g.add_define('NEW_EXPAT')
20
- end
21
- if g.has_function?("XML_SetParamEntityParsing")
22
- #g.cflags << ' -DXML_DTD'
23
- g.add_define('XML_DTD')
24
- end
25
-
26
- #g.include_library("socket", function="ntohl")
27
- g.include_library("wsock32") if RUBY_PLATFORM =~ /mswin32|mingw/
28
- end
@@ -1,58 +0,0 @@
1
- ## -*- Ruby -*-
2
- ## Tree builder class for Japanese encoding
3
- ## 1998 by yoshidam
4
-
5
- require 'xml/dom/builder'
6
-
7
- module XML
8
- module DOM
9
- class JapaneseBuilder<Builder
10
- require 'kconv'
11
- include Kconv
12
- require 'uconv'
13
- include Uconv
14
-
15
- def nameConverter(str)
16
- u8toeuc(str)
17
- end
18
- def cdataConverter(str)
19
- u8toeuc(str)
20
- end
21
-
22
- def parseStream(stream, trim = false)
23
- ## empty file
24
- if ((xml = stream.gets).nil?); exit 1; end
25
- ## rewrite encoding in XML decl.
26
- if xml =~ /^<\?xml\sversion=.+\sencoding=.EUC-JP./i
27
- xml.sub!(/EUC-JP/i, "UTF-8")
28
- encoding = 'EUC-JP'
29
- elsif xml =~ /^<\?xml\sversion=.+\sencoding=.Shift_JIS./i
30
- xml.sub!(/Shift_JIS/i, "UTF-8")
31
- encoding = "Shift_JIS"
32
- elsif xml =~ /^<\?xml\sversion=.+\sencoding=.ISO-2022-JP./i
33
- xml.sub!(/ISO-2022-JP/i, "UTF-8")
34
- encoding = "ISO-2022-JP"
35
- end
36
-
37
- ## read body
38
- xml += String(stream.read)
39
-
40
- ## convert body encoding
41
- if encoding == "EUC-JP"
42
- xml = euctou8(xml)
43
- elsif encoding == "Shift_JIS"
44
- xml = euctou8(kconv(xml, EUC, SJIS))
45
- elsif encoding == "ISO-2022-JP"
46
- xml = euctou8(kconv(xml, EUC, JIS))
47
- end
48
-
49
- return parse(xml, trim)
50
- end
51
-
52
-
53
- def Uconv.unknown_unicode_handler(u)
54
- return '®'
55
- end
56
- end
57
- end
58
- end