mime-types 2.99.3 → 3.3.1
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 +5 -5
- data/{Code-of-Conduct.rdoc → Code-of-Conduct.md} +19 -20
- data/Contributing.md +143 -0
- data/History.md +240 -0
- data/{Licence.rdoc → Licence.md} +4 -18
- data/Manifest.txt +8 -25
- data/README.rdoc +62 -73
- data/Rakefile +175 -58
- data/lib/mime-types.rb +1 -1
- data/lib/mime/type.rb +213 -424
- data/lib/mime/type/columnar.rb +29 -62
- data/lib/mime/types.rb +46 -141
- data/lib/mime/types/_columnar.rb +136 -0
- data/lib/mime/types/cache.rb +51 -73
- data/lib/mime/types/columnar.rb +2 -147
- data/lib/mime/types/container.rb +96 -0
- data/lib/mime/types/deprecations.rb +4 -25
- data/lib/mime/types/full.rb +19 -0
- data/lib/mime/types/loader.rb +12 -141
- data/lib/mime/types/logger.rb +5 -1
- data/lib/mime/types/registry.rb +90 -0
- data/test/minitest_helper.rb +5 -13
- data/test/test_mime_type.rb +470 -456
- data/test/test_mime_types.rb +135 -87
- data/test/test_mime_types_cache.rb +82 -54
- data/test/test_mime_types_class.rb +118 -98
- data/test/test_mime_types_lazy.rb +26 -24
- data/test/test_mime_types_loader.rb +6 -33
- metadata +107 -64
- data/Contributing.rdoc +0 -170
- data/History-Types.rdoc +0 -454
- data/History.rdoc +0 -590
- data/data/mime-types.json +0 -1
- data/data/mime.content_type.column +0 -1980
- data/data/mime.docs.column +0 -1980
- data/data/mime.encoding.column +0 -1980
- data/data/mime.friendly.column +0 -1980
- data/data/mime.obsolete.column +0 -1980
- data/data/mime.registered.column +0 -1980
- data/data/mime.signature.column +0 -1980
- data/data/mime.use_instead.column +0 -1980
- data/data/mime.xrefs.column +0 -1980
- data/docs/COPYING.txt +0 -339
- data/docs/artistic.txt +0 -127
- data/lib/mime/types/loader_path.rb +0 -15
- data/support/apache_mime_types.rb +0 -108
- data/support/benchmarks/load.rb +0 -64
- data/support/benchmarks/load_allocations.rb +0 -83
- data/support/benchmarks/object_counts.rb +0 -41
- data/support/convert.rb +0 -158
- data/support/convert/columnar.rb +0 -88
- data/support/iana_registry.rb +0 -172
data/support/convert/columnar.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'convert'
|
2
|
-
|
3
|
-
class Convert::Columnar < Convert
|
4
|
-
class << self
|
5
|
-
# Converts from YAML to Columnar format. This *always* converts to multiple
|
6
|
-
# files.
|
7
|
-
def from_yaml_to_columnar(args)
|
8
|
-
from_yaml(yaml_path(args.source)).
|
9
|
-
to_columnar(destination: columnar_path(args.destination))
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def columnar_path(path)
|
15
|
-
path_or_default(path, 'data')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Convert the data to multiple text files.
|
20
|
-
def to_columnar(options = {})
|
21
|
-
root = options[:destination] or require_destination!
|
22
|
-
@root = must_be_directory!(root)
|
23
|
-
@data = @loader.container.sort.map(&:to_h)
|
24
|
-
|
25
|
-
column_file('content_type') do |type|
|
26
|
-
[ type['content-type'], Array(type['extensions']).join(' ') ].
|
27
|
-
flatten.join(' ').strip
|
28
|
-
end
|
29
|
-
|
30
|
-
required_file('encoding')
|
31
|
-
optional_file('docs')
|
32
|
-
bool_file('obsolete')
|
33
|
-
bool_file('registered')
|
34
|
-
bool_file('signature')
|
35
|
-
dict_file('xrefs')
|
36
|
-
dict_file('friendly')
|
37
|
-
optional_file('use_instead', 'use-instead')
|
38
|
-
end
|
39
|
-
|
40
|
-
def column_file(name, &block)
|
41
|
-
File.open(File.join(@root, "mime.#{name}.column"), 'wb') do |f|
|
42
|
-
f.puts @data.map(&block)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def bool_file(name, *fields)
|
47
|
-
fields = [ name ] if fields.empty?
|
48
|
-
column_file(name) do |type|
|
49
|
-
fields.map { |field|
|
50
|
-
type[field] ? 1 : 0
|
51
|
-
}.join(' ')
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def required_file(name, field = name)
|
56
|
-
column_file(name) { |type| type[field] }
|
57
|
-
end
|
58
|
-
|
59
|
-
def optional_file(name, field = name)
|
60
|
-
column_file(name) { |type| opt(type[field]) }
|
61
|
-
end
|
62
|
-
|
63
|
-
def array_file(name, field = name)
|
64
|
-
column_file(name) { |type| arr(type[field]) }
|
65
|
-
end
|
66
|
-
|
67
|
-
def dict_file(name, field = name)
|
68
|
-
column_file(name) { |type| dict(type[field]) }
|
69
|
-
end
|
70
|
-
|
71
|
-
def opt(value)
|
72
|
-
value || '-'
|
73
|
-
end
|
74
|
-
|
75
|
-
def arr(value)
|
76
|
-
Array(opt(value)).join('|')
|
77
|
-
end
|
78
|
-
|
79
|
-
def dict(value)
|
80
|
-
if value
|
81
|
-
value.sort.map { |k, v|
|
82
|
-
[ k, Array(v).compact.join('^') ].join('^')
|
83
|
-
}.join('|')
|
84
|
-
else
|
85
|
-
'-'
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
data/support/iana_registry.rb
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
# -*- ruby encoding: utf-8 -*-
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
-
|
5
|
-
require 'open-uri'
|
6
|
-
require 'nokogiri'
|
7
|
-
require 'cgi'
|
8
|
-
require 'pathname'
|
9
|
-
require 'yaml'
|
10
|
-
|
11
|
-
ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'yes'
|
12
|
-
require 'mime/types'
|
13
|
-
|
14
|
-
class MIME::Types
|
15
|
-
def self.deprecated(*_args, &_block)
|
16
|
-
# We are an internal tool. Silence deprecation warnings.
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class MIME::Type
|
21
|
-
public_constant :MEDIA_TYPE_RE if respond_to? :public_constant
|
22
|
-
end
|
23
|
-
|
24
|
-
class IANARegistry
|
25
|
-
DEFAULTS = {
|
26
|
-
url: %q(https://www.iana.org/assignments/media-types/media-types.xml),
|
27
|
-
to: Pathname(__FILE__).join('../../type-lists')
|
28
|
-
}.freeze.each_value(&:freeze)
|
29
|
-
|
30
|
-
def self.download(options = {})
|
31
|
-
dest = Pathname(options[:to] || DEFAULTS[:to]).expand_path
|
32
|
-
url = options.fetch(:url, DEFAULTS[:url])
|
33
|
-
|
34
|
-
puts 'Downloading IANA MIME type assignments.'
|
35
|
-
puts "\t#{url}"
|
36
|
-
xml = Nokogiri::XML(open(url) { |f| f.read })
|
37
|
-
|
38
|
-
xml.css('registry registry').each do |registry|
|
39
|
-
next if registry.at_css('title').text == 'example'
|
40
|
-
new(registry: registry, to: dest) do |parser|
|
41
|
-
puts "Extracting #{parser.type}/*."
|
42
|
-
parser.parse
|
43
|
-
parser.save
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
attr_reader :type
|
49
|
-
|
50
|
-
def initialize(options = {})
|
51
|
-
@registry = options.fetch(:registry)
|
52
|
-
@to = Pathname(options.fetch(:to)).expand_path
|
53
|
-
@type = @registry.at_css('title').text
|
54
|
-
@name = "#{@type}.yaml"
|
55
|
-
@file = @to.join(@name)
|
56
|
-
@types = mime_types_for(@file)
|
57
|
-
|
58
|
-
yield self if block_given?
|
59
|
-
end
|
60
|
-
|
61
|
-
ASSIGNMENT_FILE_REF = '{%s=http://www.iana.org/assignments/media-types/%s}'
|
62
|
-
|
63
|
-
def parse
|
64
|
-
@registry.css('record').each do |record|
|
65
|
-
subtype = record.at_css('name').text
|
66
|
-
obsolete = record.at_css('obsolete').text rescue nil
|
67
|
-
use_instead = record.at_css('deprecated').text rescue nil
|
68
|
-
|
69
|
-
if subtype =~ /OBSOLETE|DEPRECATE/i
|
70
|
-
use_instead ||= $1 if subtype =~ /in favou?r of (#{MIME::Type::MEDIA_TYPE_RE})/
|
71
|
-
obsolete = true
|
72
|
-
end
|
73
|
-
|
74
|
-
subtype, notes = subtype.split(/ /, 2)
|
75
|
-
|
76
|
-
refs, xrefs = parse_refs_and_files(
|
77
|
-
record.css('xref'),
|
78
|
-
record.css('file'),
|
79
|
-
subtype
|
80
|
-
)
|
81
|
-
|
82
|
-
xrefs['notes'] << notes if notes
|
83
|
-
|
84
|
-
content_type = [ @type, subtype ].join('/')
|
85
|
-
|
86
|
-
types = @types.select { |t|
|
87
|
-
(t.content_type.downcase == content_type.downcase)
|
88
|
-
}
|
89
|
-
|
90
|
-
if types.empty?
|
91
|
-
MIME::Type.new(content_type) do |mt|
|
92
|
-
mt.xrefs = xrefs
|
93
|
-
mt.registered = true
|
94
|
-
mt.obsolete = obsolete if obsolete
|
95
|
-
mt.use_instead = use_instead if use_instead
|
96
|
-
@types << mt
|
97
|
-
end
|
98
|
-
else
|
99
|
-
types.each { |mt|
|
100
|
-
mt.registered = true
|
101
|
-
mt.xrefs = xrefs
|
102
|
-
mt.obsolete = obsolete if obsolete
|
103
|
-
mt.use_instead = use_instead if use_instead
|
104
|
-
}
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def save
|
110
|
-
@to.mkpath
|
111
|
-
File.open(@file, 'wb') { |f| f.puts @types.map.to_a.sort.uniq.to_yaml }
|
112
|
-
end
|
113
|
-
|
114
|
-
private
|
115
|
-
|
116
|
-
def mime_types_for(file)
|
117
|
-
if file.exist?
|
118
|
-
MIME::Types::Loader.load_from_yaml(file)
|
119
|
-
else
|
120
|
-
MIME::Types.new
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def parse_refs_and_files(refs, files, subtype)
|
125
|
-
xr = MIME::Types::Container.new
|
126
|
-
r = []
|
127
|
-
|
128
|
-
refs.each do |xref|
|
129
|
-
type = xref['type']
|
130
|
-
data = xref['data']
|
131
|
-
|
132
|
-
next if data.nil? || data.empty?
|
133
|
-
|
134
|
-
r << ref_from_type(type, data)
|
135
|
-
|
136
|
-
xr[type] << data
|
137
|
-
end
|
138
|
-
|
139
|
-
files.each do |file|
|
140
|
-
file_name = if file.text == subtype
|
141
|
-
[ @type, subtype ].join('/')
|
142
|
-
else
|
143
|
-
file.text
|
144
|
-
end
|
145
|
-
|
146
|
-
if file['type'] == 'template'
|
147
|
-
r << (ASSIGNMENT_FILE_REF % [ file_name, file_name ])
|
148
|
-
end
|
149
|
-
|
150
|
-
xr[file['type']] << file_name
|
151
|
-
end
|
152
|
-
|
153
|
-
[ r, xr ]
|
154
|
-
end
|
155
|
-
|
156
|
-
def ref_from_type(type, data)
|
157
|
-
case type
|
158
|
-
when 'person'
|
159
|
-
"[#{data}]"
|
160
|
-
when 'rfc'
|
161
|
-
data.upcase
|
162
|
-
when 'draft'
|
163
|
-
"DRAFT:#{data.sub(/^RFC-/, 'draft-')}"
|
164
|
-
when 'rfc-errata'
|
165
|
-
"{RFC Errata #{data}=http://www.rfc-editor.org/errata_search.php?eid=#{data}}"
|
166
|
-
when 'uri'
|
167
|
-
"{#{data}}"
|
168
|
-
else # 'text' or something else
|
169
|
-
data
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|