skates 0.5.8 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/skates/xmpp_parser.rb +34 -31
  2. metadata +54 -87
@@ -3,9 +3,9 @@ module Skates
3
3
  ##
4
4
  # This is the XML SAX Parser that accepts "pushed" content
5
5
  class XmppParser < Nokogiri::XML::SAX::Document
6
-
6
+
7
7
  attr_accessor :elem, :doc, :parser
8
-
8
+
9
9
  ##
10
10
  # Initialize the parser and adds the callback that will be called upon stanza completion
11
11
  def initialize(callback)
@@ -14,27 +14,27 @@ module Skates
14
14
  super()
15
15
  reset
16
16
  end
17
-
18
- ##
17
+
18
+ ##
19
19
  # Resets the Pushed SAX Parser.
20
20
  def reset
21
21
  @parser = Nokogiri::XML::SAX::PushParser.new(self, "UTF-8")
22
22
  @elem = @doc = nil
23
23
  end
24
-
24
+
25
25
  ##
26
26
  # Pushes the received data to the parser. The parser will then callback the document's methods (start_tag, end_tag... etc)
27
27
  def push(data)
28
28
  @parser << data
29
29
  end
30
-
30
+
31
31
  ##
32
32
  # Adds characters to the current element (being parsed)
33
33
  def characters(string)
34
34
  @buffer ||= ""
35
- @buffer << string
35
+ @buffer << string
36
36
  end
37
-
37
+
38
38
  ##
39
39
  # Instantiate a new current Element, adds the corresponding attributes and namespaces.
40
40
  # The new element is eventually added to a parent element (if present).
@@ -44,33 +44,36 @@ module Skates
44
44
  @doc ||= Nokogiri::XML::Document.new
45
45
  @elem ||= @doc # If we have no current element, then, we take the doc
46
46
  @parent = @elem
47
-
47
+
48
48
  # First thing first : identify namespaces, and attributes
49
49
  namespaces, attributes = identify_namespaces_and_attributes(attributes)
50
-
50
+ @parent.namespaces.each do |p, u|
51
+ namespaces[p.split(":")[1]] ||= u
52
+ end
53
+
51
54
  # Now, we may need to add a namespace!
52
55
  namespace, qname = qname.split(":") if qname.match(/.*:.*/)
53
-
56
+
54
57
  @elem = Nokogiri::XML::Element.new(qname, @doc)
55
58
  # Let's now add all namespaces
56
59
  namespaces.each do |prefix, uri|
57
60
  set_namespace(prefix, uri)
58
61
  end
59
-
62
+
60
63
  # And all attributes
61
64
  attributes.each do |name, value|
62
65
  set_attribute(name, value)
63
66
  end
64
-
67
+
65
68
  # And now addback the namespace if applicable
66
- if prefix = ["xmlns", namespace].join(":") and uri = @parent.namespaces[prefix]
67
- @elem.namespace = @parent.namespace_definitions.select() {|ns|
68
- ns.href == uri
69
+ if namespace
70
+ @elem.namespace = @elem.namespace_definitions.select() {|ns|
71
+ ns.prefix == namespace
69
72
  }.first
70
73
  end
71
-
74
+
72
75
  @parent.add_child(@elem) # Finally, add the element
73
-
76
+
74
77
  if @elem.name == "stream"
75
78
  # We activate the callback since this element will never end.
76
79
  @callback.call(@elem)
@@ -78,7 +81,7 @@ module Skates
78
81
  # And then, we start a new Sax Push Parser
79
82
  end
80
83
  end
81
-
84
+
82
85
  ##
83
86
  # Clears the characters buffer
84
87
  def clear_characters_buffer
@@ -96,17 +99,17 @@ module Skates
96
99
  if @elem
97
100
  if @elem.parent == @doc
98
101
  # If we're actually finishing the stanza (a stanza is always a document's root)
99
- @callback.call(@elem)
102
+ @callback.call(@elem)
100
103
  # We delete the current element and the doc (1 doc per stanza policy)
101
- @elem = @doc = nil
104
+ @elem = @doc = nil
102
105
  else
103
- @elem = @elem.parent
104
- end
105
- else
106
+ @elem = @elem.parent
107
+ end
108
+ else
106
109
  # Not sure what to do since it seems we're not processing any element at this time, so how can one end?
107
- end
108
- end
109
-
110
+ end
111
+ end
112
+
110
113
  ##
111
114
  # Idenitifies namespaces and attributes
112
115
  # Nokogiri passes them as a array of [[ns_name, ns_url], [ns_name, ns_url]..., key, value, key, value]...
@@ -127,13 +130,13 @@ module Skates
127
130
  end
128
131
  [namespaces, attributes]
129
132
  end
130
-
133
+
131
134
  def set_attribute(key, value)
132
135
  @elem.set_attribute(key, Skates.decode_xml(value))
133
136
  end
134
-
137
+
135
138
  def set_namespace(key, value)
136
139
  @elem.add_namespace(key, value)
137
140
  end
138
- end
139
- end
141
+ end
142
+ end
metadata CHANGED
@@ -1,93 +1,69 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: skates
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.9
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 8
10
- version: 0.5.8
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - julien Genestoux
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-14 00:00:00 -05:00
19
- default_executable: skates
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-07-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: eventmachine
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2166149040 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 59
30
- segments:
31
- - 0
32
- - 12
33
- - 10
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 0.12.10
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: log4r
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2166149040
25
+ - !ruby/object:Gem::Dependency
26
+ name: log4r
27
+ requirement: &2166148480 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
49
33
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: nokogiri
53
34
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2166148480
36
+ - !ruby/object:Gem::Dependency
37
+ name: nokogiri
38
+ requirement: &2166147960 !ruby/object:Gem::Requirement
55
39
  none: false
56
- requirements:
57
- - - "="
58
- - !ruby/object:Gem::Version
59
- hash: 15
60
- segments:
61
- - 1
62
- - 4
63
- - 4
40
+ requirements:
41
+ - - =
42
+ - !ruby/object:Gem::Version
64
43
  version: 1.4.4
65
44
  type: :runtime
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: utf8cleaner
69
45
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2166147960
47
+ - !ruby/object:Gem::Dependency
48
+ name: utf8cleaner
49
+ requirement: &2166147400 !ruby/object:Gem::Requirement
71
50
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
79
55
  type: :runtime
80
- version_requirements: *id004
56
+ prerelease: false
57
+ version_requirements: *2166147400
81
58
  description:
82
59
  email: julien.genestoux@gmail.com
83
- executables:
60
+ executables:
84
61
  - skates
85
62
  extensions: []
86
-
87
- extra_rdoc_files:
63
+ extra_rdoc_files:
88
64
  - LICENSE
89
65
  - README.rdoc
90
- files:
66
+ files:
91
67
  - LICENSE
92
68
  - README.rdoc
93
69
  - Rakefile
@@ -118,34 +94,25 @@ files:
118
94
  - templates/skates/log/test.log
119
95
  - templates/skates/script/component
120
96
  - templates/skates/tmp/pids/README
121
- has_rdoc: true
122
97
  homepage: http://github.com/julien51/skates
123
98
  licenses: []
124
-
125
99
  post_install_message:
126
100
  rdoc_options: []
127
-
128
- require_paths:
101
+ require_paths:
129
102
  - lib
130
- required_ruby_version: !ruby/object:Gem::Requirement
103
+ required_ruby_version: !ruby/object:Gem::Requirement
131
104
  none: false
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- hash: 3
136
- segments:
137
- - 0
138
- version: "0"
139
- required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
110
  none: false
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- hash: 3
145
- segments:
146
- - 0
147
- version: "0"
148
- requirements:
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements:
149
116
  - bundler
150
117
  - eventmachine
151
118
  - yaml
@@ -158,9 +125,9 @@ requirements:
158
125
  - resolv
159
126
  - utf8cleaner
160
127
  rubyforge_project: skates
161
- rubygems_version: 1.4.2
128
+ rubygems_version: 1.8.17
162
129
  signing_key:
163
130
  specification_version: 3
164
- summary: Skates is a framework to create EventMachine based XMPP External Components in Ruby.
131
+ summary: Skates is a framework to create EventMachine based XMPP External Components
132
+ in Ruby.
165
133
  test_files: []
166
-