Skip to content

Commit

Permalink
Finish 3.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Aug 6, 2020
2 parents 7e547c3 + df74f33 commit 6325096
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.1.4
3.1.5
4 changes: 2 additions & 2 deletions bin/rdf
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
$:.unshift(File.expand_path("../../lib", __FILE__))
require 'rubygems'
require 'rdf/cli'
require 'rdf'

options = RDF::CLI.options(ARGV)

Expand Down
3 changes: 3 additions & 0 deletions lib/rdf.rb
Expand Up @@ -76,6 +76,9 @@ module RDF
# Utilities
autoload :Util, 'rdf/util'

# CLI
autoload :CLI, 'rdf/cli'

##
# Alias for `RDF::Resource.new`.
#
Expand Down
14 changes: 11 additions & 3 deletions lib/rdf/cli.rb
Expand Up @@ -8,7 +8,7 @@
require 'linkeddata'
rescue LoadError
# Silently load without linkeddata, but try some others
%w(reasoner rdfa rdfxml turtle vocab json/ld ld/patch).each do |ser|
%w(microdata n3 rdfa rdfxml reasoner tabular trig trix turtle vocab xsd json/ld ld/patch).each do |ser|
begin
require ser.include?('/') ? ser : "rdf/#{ser}"
rescue LoadError
Expand Down Expand Up @@ -296,6 +296,12 @@ def to_hash
control: :none,
on: ["-o", "--output FILE"],
description: "File to write output, defaults to STDOUT") {|arg| File.open(arg, "w")},
RDF::CLI::Option.new(
symbol: :ordered,
control: :checkbox,
datatype: TrueClass,
on: ["--ordered"],
description: "Use order preserving repository"),
RDF::CLI::Option.new(
symbol: :format,
control: :select,
Expand Down Expand Up @@ -495,14 +501,16 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
options[:format] = options[:format].to_sym if options[:format]
options[:output_format] = options[:output_format].to_sym if options[:output_format]

@repository = RDF::Repository.new
@repository = options[:ordered] ?
[].extend(RDF::Enumerable, RDF::Queryable) :
RDF::Repository.new

# Parse input files if any command requires it
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
start = Time.new
count = 0
self.parse(args, **options) do |reader|
@repository << reader
reader.each_statement {|st| @repository << st}
end
secs = Time.new - start
options[:logger].info "Parsed #{repository.count} statements with #{@readers.join(', ')} in #{secs} seconds @ #{count/secs} statements/second."
Expand Down
6 changes: 3 additions & 3 deletions lib/rdf/model/uri.rb
Expand Up @@ -902,7 +902,7 @@ def user=(value)
# Normalized version of user
# @return [String]
def normalized_user
URI.encode(CGI.unescape(user), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/) if user
URI.encode(CGI.unescape(user), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).force_encoding(Encoding::UTF_8) if user
end

##
Expand All @@ -928,7 +928,7 @@ def password=(value)
# Normalized version of password
# @return [String]
def normalized_password
URI.encode(CGI.unescape(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/) if password
URI.encode(CGI.unescape(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).force_encoding(Encoding::UTF_8) if password
end

HOST_FROM_AUTHORITY_RE = /(?:[^@]+@)?([^:]+)(?::.*)?$/.freeze
Expand Down Expand Up @@ -1295,7 +1295,7 @@ def normalize_segment(value, expr, downcase = false)
value = value.dup.force_encoding(Encoding::UTF_8)
decoded = CGI.unescape(value)
decoded.downcase! if downcase
URI.encode(decoded, /[^(?:#{expr})]/)
URI.encode(decoded, /[^(?:#{expr})]/).force_encoding(Encoding::UTF_8)
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/rdf/util/file.rb
Expand Up @@ -14,7 +14,7 @@ module RDF; module Util
# allowing the use of `Rack::Cache` to avoid network access.
#
# To use other HTTP clients, consumers can subclass
# {RDF::Util::File::HttpAdapter} and set the {RDF::Util::File.http_adapter}.
# {RDF::Util::File::HttpAdapter} and set the {RDF::Util::File.}.
#
# Also supports the file: scheme for access to local files.
#
Expand Down Expand Up @@ -121,8 +121,8 @@ def self.open_url(base_uri, proxy: nil, headers: {}, verify_none: false, **optio

redirect_count = 0
max_redirects = 5
parsed_url = ::URI.parse(base_uri)
parsed_proxy = ::URI.parse(proxy.to_s)
parsed_url = RDF::URI.parse(base_uri)
parsed_proxy = RDF::URI.parse(proxy.to_s)
base_uri = parsed_url.to_s
remote_document = nil

Expand Down
9 changes: 8 additions & 1 deletion spec/cli_spec.rb
Expand Up @@ -76,9 +76,16 @@
end
end

describe "--ordered" do
it "sets :ordered" do
options = RDF::CLI.options(%w(help --ordered) << triple)
expect(options.options[:ordered]).to be_truthy
end
end

describe "--evaluate" do
it "sets :evaluate" do
options = RDF::CLI.options(%w(helpcount --format ntriples --evaluate) << triple)
options = RDF::CLI.options(%w(help count --format ntriples --evaluate) << triple)
expect(options.options[:evaluate]).to eql triple
end
end
Expand Down
11 changes: 5 additions & 6 deletions spec/model_uri_spec.rb
Expand Up @@ -470,14 +470,18 @@
"urn" => [
"urn:ex:s001",
"urn:ex:s001"
],
"utf-8" => [
"Dürst",
"Dürst"
]
}.each do |name, (input, output)|
it "#canonicalize #{name}" do
u1 = RDF::URI(input)
u2 = RDF::URI(output)
expect(u1.canonicalize.hash).to eq u2.hash
expect(u1.canonicalize.to_s).to eq u2.to_s
expect(u1).to eq u1
expect(u1.canonicalize).to eq u1.canonicalize
end
end
it "#canonicalize! alters resource" do
Expand All @@ -486,11 +490,6 @@
expect(u1.canonicalize!.to_s).to eq u2.to_s
expect(u1).to eq u2
end
it "#canonicalize does not fail with Encoding::CompatibilityError on weird IRIs" do
u1 = RDF::URI "htЫtp://user:passoЫd@exaЫmple.com:8080/path ПУТЬ?queЫry=valЫue#fragmeЫnt"
u2 = RDF::URI "ht%D0%ABtp://user:passoЫd@exaЫmple.com:8080/path%20ПУТЬ?queЫry=valЫue#fragmeЫnt"
expect {u1.canonicalize.to_s.dup.force_encoding(u2.to_s.encoding)}.not_to raise_error
end
end

describe "#/" do
Expand Down
12 changes: 6 additions & 6 deletions spec/util_logger_spec.rb
Expand Up @@ -100,38 +100,38 @@ def initialize(logger = nil)
describe "#log_info" do
it "Logs messages, and yield return" do
subject.log_info("a", "b") {"c"}
expect(subject.logger.to_s).to eql "INFO a: b: c\n"
expect(subject.logger.to_s).to eql " INFO a: b: c\n"
end

it "adds lineno" do
subject.log_info("a", lineno: 10)
expect(subject.logger.to_s).to eql "INFO [line 10] a\n"
expect(subject.logger.to_s).to eql " INFO [line 10] a\n"
end

it "adds depth with option" do
subject.log_info("a", depth: 2)
expect(subject.logger.to_s).to eql "INFO a\n"
expect(subject.logger.to_s).to eql " INFO a\n"
end

it "adds depth with option" do
subject.log_info("a", depth: 2)
expect(subject.logger.to_s).to eql "INFO a\n"
expect(subject.logger.to_s).to eql " INFO a\n"
end

it "uses logger from @options" do
logger = LogTester.new
logger.options[:logger] = RDF::Spec.logger
logger.log_info("a")
expect(logger.instance_variable_get(:@logger).to_s).to be_empty
expect(logger.options[:logger].to_s).to eql "INFO a\n"
expect(logger.options[:logger].to_s).to eql " INFO a\n"
end

it "uses logger from options" do
logger = LogTester.new
l = RDF::Spec.logger
logger.log_info("a", logger: l)
expect(logger.instance_variable_get(:@logger).to_s).to be_empty
expect(l.to_s).to eql "INFO a\n"
expect(l.to_s).to eql " INFO a\n"
end

it "increments log_statistics" do
Expand Down

0 comments on commit 6325096

Please sign in to comment.