wiot_parser 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/lib/wiot_parser.rb +17 -16
- data/lib/wiot_parser/version.rb +1 -1
- metadata +1 -6
- data/lib/wiot_parser/constrainer.rb +0 -26
- data/lib/wiot_parser/errors.rb +0 -27
- data/lib/wiot_parser/yaml/yaml_line.rb +0 -62
- data/lib/wiot_parser/yaml/yaml_parser.rb +0 -17
- data/lib/wiot_parser/yaml/yaml_security.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca52af60df83899ca249168563c4fefb26099586
|
4
|
+
data.tar.gz: fcae0ab109604a277e3e10d6dd945a46751e83da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ceb0f2223e31bc422cc6e050e0fa09ecd9f2d975c9174508c8507fa83ce93165b9a975d2a841d3aa75a2df0fc86a5d9cf6032218357254de448d79954939ec2
|
7
|
+
data.tar.gz: eb673eead8ee3d1c3c38909a0901f8b78c1560b0042607ab364f4afb59798c6f16cc6e65940da1ce09cd77504df79413416561c2080318ec5906a6d5cac3f58f
|
data/lib/wiot_parser.rb
CHANGED
@@ -1,23 +1,24 @@
|
|
1
|
-
require 'wiot_parser/errors'
|
2
|
-
require 'wiot_parser/yaml/yaml_line'
|
3
|
-
require 'wiot_parser/yaml/yaml_security'
|
4
|
-
require 'wiot_parser/yaml/yaml_parser'
|
1
|
+
#require 'wiot_parser/errors'
|
2
|
+
#require 'wiot_parser/yaml/yaml_line'
|
3
|
+
#require 'wiot_parser/yaml/yaml_security'
|
4
|
+
#require 'wiot_parser/yaml/yaml_parser'
|
5
5
|
|
6
6
|
module WiotParser
|
7
7
|
def self.parse(yaml, constrainers)
|
8
8
|
|
9
9
|
# try to put more difficult the possible yml exploit with basic validations
|
10
|
-
errors = YamlSecurity.valid(yaml)
|
11
|
-
return errors unless errors.empty?
|
10
|
+
#errors = YamlSecurity.valid(yaml)
|
11
|
+
#return errors unless errors.empty?
|
12
12
|
|
13
|
-
begin
|
14
|
-
|
15
|
-
|
16
|
-
rescue => e
|
17
|
-
|
18
|
-
end
|
13
|
+
#begin
|
14
|
+
# obj = YamlParser.parser yaml
|
15
|
+
# errors = parser_obj obj, constrainers
|
16
|
+
#rescue => e
|
17
|
+
# return ParserError.yaml_exception e.message
|
18
|
+
#end
|
19
19
|
|
20
|
-
errors
|
20
|
+
#errors
|
21
|
+
errors = {}
|
21
22
|
end
|
22
23
|
|
23
24
|
def self.token
|
@@ -27,8 +28,8 @@ module WiotParser
|
|
27
28
|
private
|
28
29
|
|
29
30
|
def self.parser_obj(obj, constrainers)
|
30
|
-
errors = {}
|
31
|
-
errors['error-' + errors.size.to_s] = ParserError.new(1, 1, 'bafd token')
|
32
|
-
errors
|
31
|
+
#errors = {}
|
32
|
+
#errors['error-' + errors.size.to_s] = ParserError.new(1, 1, 'bafd token')
|
33
|
+
#errors
|
33
34
|
end
|
34
35
|
end
|
data/lib/wiot_parser/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiot_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gorums
|
@@ -67,12 +67,7 @@ files:
|
|
67
67
|
- bin/console
|
68
68
|
- bin/setup
|
69
69
|
- lib/wiot_parser.rb
|
70
|
-
- lib/wiot_parser/constrainer.rb
|
71
|
-
- lib/wiot_parser/errors.rb
|
72
70
|
- lib/wiot_parser/version.rb
|
73
|
-
- lib/wiot_parser/yaml/yaml_line.rb
|
74
|
-
- lib/wiot_parser/yaml/yaml_parser.rb
|
75
|
-
- lib/wiot_parser/yaml/yaml_security.rb
|
76
71
|
- wiot_parser.gemspec
|
77
72
|
homepage: http://www.watchiot.org
|
78
73
|
licenses:
|
@@ -1,26 +0,0 @@
|
|
1
|
-
##
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module WiotParser
|
5
|
-
class Constrainer
|
6
|
-
|
7
|
-
def initialize(values)
|
8
|
-
@params_max = values[:params_max]
|
9
|
-
@valid_emails = values[:valid_emails]
|
10
|
-
@repeat_email_min = values[:repeat_email_min]
|
11
|
-
end
|
12
|
-
|
13
|
-
def params_max
|
14
|
-
@params_max
|
15
|
-
end
|
16
|
-
|
17
|
-
def valid_emails
|
18
|
-
@valid_emails
|
19
|
-
end
|
20
|
-
|
21
|
-
def repeat_email_min
|
22
|
-
@repeat_email_min
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
data/lib/wiot_parser/errors.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
##
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module WiotParser
|
5
|
-
class ParserError
|
6
|
-
def initialize(row, column, text)
|
7
|
-
@row=row
|
8
|
-
@column=column
|
9
|
-
@text=text
|
10
|
-
@type='error'
|
11
|
-
end
|
12
|
-
|
13
|
-
def row
|
14
|
-
@row
|
15
|
-
end
|
16
|
-
|
17
|
-
def row=(row)
|
18
|
-
@row = row
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.yaml_exception(msg)
|
22
|
-
errors = {}
|
23
|
-
errors['error-' + errors.size.to_s] = ParserError.new(1, 1, msg)
|
24
|
-
errors
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'psych'
|
2
|
-
|
3
|
-
##
|
4
|
-
#
|
5
|
-
#
|
6
|
-
module WiotParser
|
7
|
-
|
8
|
-
# Psych's first step is to parse the Yaml into an AST of Node objects
|
9
|
-
# so we open the Node class and add a way to track the line.
|
10
|
-
class Psych::Nodes::Node
|
11
|
-
attr_accessor :line
|
12
|
-
end
|
13
|
-
|
14
|
-
# We need to provide a handler that will add the line to the node
|
15
|
-
# as it is parsed. TreeBuilder is the "usual" handler, that
|
16
|
-
# creates the AST.
|
17
|
-
class LineNumberHandler < Psych::TreeBuilder
|
18
|
-
|
19
|
-
# The handler needs access to the parser in order to call mark
|
20
|
-
attr_accessor :parser
|
21
|
-
|
22
|
-
# We are only interested in scalars, so here we override
|
23
|
-
# the method so that it calls mark and adds the line info
|
24
|
-
# to the node.
|
25
|
-
def scalar value, anchor, tag, plain, quoted, style
|
26
|
-
mark = parser.mark
|
27
|
-
s = super
|
28
|
-
s.line = mark.line
|
29
|
-
s
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# The next step is to convert the AST to a Ruby object.
|
34
|
-
# Psych does this using the visitor pattern with the ToRuby
|
35
|
-
# visitor. Here we patch ToRuby rather than inherit from it
|
36
|
-
# as it makes the last step a little easier.
|
37
|
-
class Psych::Visitors::ToRuby
|
38
|
-
|
39
|
-
# This is the method for creating hashes. There may be problems
|
40
|
-
# with Yaml mappings that have tags.
|
41
|
-
def revive_hash hash, o
|
42
|
-
o.children.each_slice(2) { |k,v|
|
43
|
-
key = accept(k)
|
44
|
-
val = accept(v)
|
45
|
-
|
46
|
-
# This is the important bit. If the value is a scalar,
|
47
|
-
# we replace it with the desired hash.
|
48
|
-
if v.is_a? ::Psych::Nodes::Scalar
|
49
|
-
val = { "value" => val, "line" => v.line}
|
50
|
-
end
|
51
|
-
|
52
|
-
# Code dealing with << (for merging hashes) omitted.
|
53
|
-
# If you need this you will probably need to copy it
|
54
|
-
# in here. See the method:
|
55
|
-
# https://github.com/tenderlove/psych/blob/v2.0.13/lib/psych/visitors/to_ruby.rb#L333-L365
|
56
|
-
|
57
|
-
hash[key] = val
|
58
|
-
}
|
59
|
-
hash
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
##
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module WiotParser
|
5
|
-
class YamlParser
|
6
|
-
def self.parser(yaml)
|
7
|
-
# Put it all together
|
8
|
-
handler = LineNumberHandler.new
|
9
|
-
parser = Psych::Parser.new(handler)
|
10
|
-
# Provide the handler with a reference to the parser
|
11
|
-
handler.parser = parser
|
12
|
-
|
13
|
-
parser.parse yaml
|
14
|
-
handler.root.to_ruby[0]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|