chupa-text 1.0.9 → 1.1.0
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/doc/text/news.md +15 -0
- data/lib/chupa-text/data.rb +5 -1
- data/lib/chupa-text/external-command.rb +22 -8
- data/lib/chupa-text/input-data.rb +3 -3
- data/lib/chupa-text/text-data.rb +2 -2
- data/lib/chupa-text/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07fabf59599faf7e5360e69c08e7d79614294099
|
4
|
+
data.tar.gz: e92e9800b47c7dc056b6232e371513832d18ded6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5d45be9f36b34dcc0987860b17f4e37808a7541acf74bc074e5c9c088b49d394ec5b4e0984d2c67686b6695450d4132effe7273c42c8786291de0c4e3619651
|
7
|
+
data.tar.gz: bf1e91f18a9e5206ef85f85afc522b86764a4ac4d09e1e3e3be38a35a26c05c5ecd051d41094b33acbd667e1ca0ab3e9b01e83f7400e9167a1ec3154bc243ff4
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
+
## 1.1.0: 2017-07-12
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* Supported external command limitation by the following environment
|
8
|
+
variables:
|
9
|
+
|
10
|
+
* `CHUPA_TEXT_EXTERNAL_COMMAND_LIMIT_CPU`
|
11
|
+
|
12
|
+
* `CHUPA_TEXT_EXTERNAL_COMMAND_LIMIT_AS`
|
13
|
+
|
14
|
+
* Handled more download errors.
|
15
|
+
|
16
|
+
* Improved extension detection.
|
17
|
+
|
3
18
|
## 1.0.9: 2017-07-11
|
4
19
|
|
5
20
|
### Improvements
|
data/lib/chupa-text/data.rb
CHANGED
@@ -166,7 +166,11 @@ module ChupaText
|
|
166
166
|
# lower case like `pdf` not `PDF`.
|
167
167
|
def extension
|
168
168
|
return nil if @uri.nil?
|
169
|
-
|
169
|
+
if @uri.is_a?(URI::HTTP) and @uri.path.end_with?("/")
|
170
|
+
"html"
|
171
|
+
else
|
172
|
+
File.extname(@uri.path).downcase.gsub(/\A\./, "")
|
173
|
+
end
|
170
174
|
end
|
171
175
|
|
172
176
|
# @return [Bool] true if MIME type is "text/XXX", false
|
@@ -56,6 +56,8 @@ module ChupaText
|
|
56
56
|
end
|
57
57
|
|
58
58
|
class SpawnLimitOptions
|
59
|
+
include Loggable
|
60
|
+
|
59
61
|
attr_reader :options
|
60
62
|
def initialize
|
61
63
|
@options = {}
|
@@ -65,13 +67,16 @@ module ChupaText
|
|
65
67
|
private
|
66
68
|
def set_default_options
|
67
69
|
set_option(:cpu, :int)
|
68
|
-
set_option(:rss, :size)
|
69
70
|
set_option(:as, :size)
|
70
71
|
end
|
71
72
|
|
72
73
|
def set_option(key, type)
|
73
|
-
value =
|
74
|
+
value =
|
75
|
+
ENV["CHUPA_TEXT_EXTERNAL_COMMAND_LIMIT_#{key.to_s.upcase}"] ||
|
76
|
+
# For backward compatibility
|
77
|
+
ENV["CHUPA_EXTERNAL_COMMAND_LIMIT_#{key.to_s.upcase}"]
|
74
78
|
return if value.nil?
|
79
|
+
return if value.empty?
|
75
80
|
value = send("parse_#{type}", key, value)
|
76
81
|
return if value.nil?
|
77
82
|
rlimit_number = Process.const_get("RLIMIT_#{key.to_s.upcase}")
|
@@ -81,8 +86,17 @@ module ChupaText
|
|
81
86
|
return nil
|
82
87
|
end
|
83
88
|
limit_info = "soft-limit:#{soft_limit}, hard-limit:#{hard_limit}"
|
84
|
-
|
85
|
-
|
89
|
+
info("#{log_tag}[#{key}][set] <#{value}>(#{limit_info})")
|
90
|
+
|
91
|
+
# TODO: Workaround for Ruby 2.3.3p222
|
92
|
+
case key
|
93
|
+
when :cpu
|
94
|
+
@options[:rlimit_cpu] = value
|
95
|
+
when :as
|
96
|
+
@options[:rlimit_as] = value
|
97
|
+
else
|
98
|
+
@options[:"rlimit_#{key}"] = value
|
99
|
+
end
|
86
100
|
end
|
87
101
|
|
88
102
|
def parse_int(key, value)
|
@@ -122,15 +136,15 @@ module ChupaText
|
|
122
136
|
end
|
123
137
|
|
124
138
|
def log_hard_limit_over_value(key, value, hard_limit)
|
125
|
-
|
139
|
+
warn("#{log_tag}[#{key}][large] <#{value}>(hard-limit:#{hard_limit})")
|
126
140
|
end
|
127
141
|
|
128
142
|
def log_invalid_value(key, value, type)
|
129
|
-
|
143
|
+
warn("#{log_tag}[#{key}][invalid] <#{value}>(#{type})")
|
130
144
|
end
|
131
145
|
|
132
|
-
def
|
133
|
-
|
146
|
+
def log_tag
|
147
|
+
"[external-command][limit]"
|
134
148
|
end
|
135
149
|
end
|
136
150
|
end
|
@@ -45,15 +45,15 @@ module ChupaText
|
|
45
45
|
|
46
46
|
private
|
47
47
|
def download
|
48
|
-
path = @uri.path
|
49
|
-
path += "index.html" if path.end_with?("/")
|
50
48
|
begin
|
51
49
|
@uri.open("rb") do |input|
|
52
50
|
self.mime_type = input.content_type.split(/;/).first
|
53
|
-
VirtualContent.new(input, path)
|
51
|
+
VirtualContent.new(input, @uri.path)
|
54
52
|
end
|
55
53
|
rescue OpenURI::HTTPError => error
|
56
54
|
raise DownloadError.new(@uri, error.message.strip)
|
55
|
+
rescue => error
|
56
|
+
raise DownloadError.new(@uri, "#{error.class}: #{error.message}")
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/lib/chupa-text/text-data.rb
CHANGED
@@ -18,8 +18,8 @@ module ChupaText
|
|
18
18
|
class TextData < Data
|
19
19
|
def initialize(text, options={})
|
20
20
|
super(options)
|
21
|
-
self.uri = uri.to_s.gsub(/\.[
|
22
|
-
self.path = path.to_s.gsub(/\.[
|
21
|
+
self.uri = uri.to_s.gsub(/\.[a-z\d]+\z/i, ".txt")
|
22
|
+
self.path = path.to_s.gsub(/\.[a-z\d]+\z/i, ".txt")
|
23
23
|
self.mime_type = "text/plain"
|
24
24
|
self.body = text
|
25
25
|
self.size = text.bytesize
|
data/lib/chupa-text/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chupa-text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: archive-zip
|