BasicObject
borrowed from feedvalidator, original copyright license is
Copyright (c) 2002-2006, Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# File lib/feed_tools/vendor/html5/lib/html5/filters/validator.rb, line 20 def _(str); str; end
# File lib/feed_tools/vendor/html5/tests/test_lxp.rb, line 20 def assert_xhtml_equal(input, expected=nil, parser=HTML5::XHTMLParser) assert_xml_equal(input, expected, parser) end
# File lib/feed_tools/vendor/html5/tests/test_lxp.rb, line 7 def assert_xml_equal(input, expected=nil, parser=HTML5::XMLParser) sortattrs = proc {"<#{$1+$2.split.sort.join(' ')+$3}>"} document = parser.parse(input.chomp, :lowercase_attr_name => false, :lowercase_element_name => false).root if not expected expected = input.chomp.gsub(XMLELEM,&sortattrs) expected = expected.gsub(/&#(\d+);/) {[$1.to_i].pack('U')} output = document.to_s.gsub(/'/,'"').gsub(XMLELEM,&sortattrs) assert_equal(expected, output) else assert_equal(expected, document.to_s.gsub(/'/,'"')) end end
# File lib/feed_tools/vendor/html5/tests/preamble.rb, line 17 def html5_test_files(subdirectory) Dir[File.join(TESTDATA_DIR, subdirectory, '*.*')] end
# File lib/feed_tools/vendor/html5/lib/html5/filters/rfc3987.rb, line 87 def is_valid_fully_qualified_uri(value) is_valid_uri(value, rfc2396_full) end
# File lib/feed_tools/vendor/html5/lib/html5/filters/rfc3987.rb, line 77 def is_valid_iri(value) begin if value.length > 0 value = value.encode('idna') end rescue end is_valid_uri(value) end
# File lib/feed_tools/vendor/html5/lib/html5/filters/iso639codes.rb, line 745 def is_valid_lang_code(value) if value.include? '-' lang, sublang = value.split('-', 2) else lang = value end !!ISO_LANG[lang.downcase] end
mime_re = Regexp.new('[^s()<>,;:\"/?=]+/[^s()<>,;:\"/[]?=]+(s*;s*[^s()<>,;:\"/[]?=]+=("(\"|[^"])*"|[^s()<>,;:\"/[]?=]+))*$')
# File lib/feed_tools/vendor/html5/lib/html5/filters/rfc2046.rb, line 26 def is_valid_mime_type(value) # !!mime_re.match(value) true end
# File lib/feed_tools/vendor/html5/lib/html5/filters/rfc3987.rb, line 39 def is_valid_uri(value, uri_pattern = RFC2396) scheme = value.split(':').first scheme.downcase! if scheme if scheme == 'tag' if !TAG.match(value) return false, "invalid-tag-uri" end elsif scheme == "urn" if !URN.match(value) return false, "invalid-urn" end elsif uri_pattern.match(value).to_a.reject{|i| i == ''}.compact.length == 0 || uri_pattern.match(value)[0] != value urichars = Regexp.new("^[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%,#]$", Regexp::MULTILINE) if value.length > 0 value.each_byte do |b| if b < 128 and !urichars.match([b].pack('c*')) return false, "invalid-uri-char" end end else begin if uri_pattern.match(value.encode('idna')) return false, "uri-not-iri" end rescue end return false, "invalid-uri" end elsif ['http','ftp'].include?(scheme) if !value.match(%{^\w+://[^/].*}) return false, "invalid-http-or-ftp-uri" end elsif value.index(':') && scheme.match(/^[a-z]+$/) && !ALLOWED_SCHEMES.include?(scheme) return false, "invalid-scheme" end return true, "" end
# File lib/feed_tools/vendor/html5/bin/html5, line 6 def parse(opts, args) encoding = nil f = args[-1] if f begin if f[0..6] == 'http://' require 'open-uri' f = URI.parse(f).open encoding = f.charset elsif f == '-' f = $stdin else f = open(f) end rescue end else $stderr.write("No filename provided. Use -h for help\n") exit(1) end require 'html5/treebuilders' treebuilder = HTML5::TreeBuilders[opts.treebuilder] if opts.output == :xml require 'html5/liberalxmlparser' p = HTML5::XMLParser.new(:tree=>treebuilder) else require 'html5/html5parser' p = HTML5::HTMLParser.new(:tree=>treebuilder) end if opts.parsemethod == :parse args = [f, encoding] else args = [f, (opts.container || 'div'), encoding] end if opts.profile require 'profiler' Profiler__::start_profile p.send(opts.parsemethod, *args) Profiler__::stop_profile Profiler__::print_profile($stderr) elsif opts.time require 'time' # TODO: switch to benchmark t0 = Time.new document = p.send(opts.parsemethod, *args) t1 = Time.new print_output(p, document, opts) t2 = Time.new puts "\n\nRun took: %fs (plus %fs to print the output)"%[t1-t0, t2-t1] else document = p.send(opts.parsemethod, *args) print_output(p, document, opts) end end
# File lib/feed_tools/vendor/html5/bin/html5, line 65 def print_output(parser, document, opts) puts "Encoding: #{parser.tokenizer.stream.char_encoding}" if opts.encoding case opts.output when :xml print document when :html require 'html5/treewalkers' tokens = HTML5::TreeWalkers[opts.treebuilder].new(document) require 'html5/serializer' puts HTML5::HTMLSerializer.serialize(tokens, opts.serializer) when :hilite print document.hilite when :tree document = [document] unless document.respond_to?(:each) document.each {|fragment| puts parser.tree.testSerializer(fragment)} end if opts.error errList=[] for pos, errorcode, datavars in parser.errors errList << "Line #{pos[0]} Col #{pos[1]} " + (HTML5::E[errorcode] || "Unknown error \"#{errorcode}\"") % datavars end $stdout.write("\nParse errors:\n" + errList.join("\n")+"\n") end end
Generated with the Darkfish Rdoc Generator 2.