hermeneutics 1.23 → 1.24

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81d01a3292ca2c19c8a0a7f285262c44584bb7d91d658dc5650774f9828bcd92
4
- data.tar.gz: 92bf5d6e7c81f27da58666bba8e5df0716bafcefef2daec6b0dca1f716f2b20d
3
+ metadata.gz: df19436c205dec9d79e7ea6329b0039f73c0df18785684b3497a5beacba86de0
4
+ data.tar.gz: 71249e9f95d7d3b7a5cc4c69de6dcdf8d50312db07d6b4e06e75df798e24a7f6
5
5
  SHA512:
6
- metadata.gz: b97a17139583cd4955b413e09affd7349544d36ff0228d9c4238879567e9ed83c922f5f0d2a5cb41009afc7ebe94330ff7187d8d75c0452dc7e17b5e3bb23757
7
- data.tar.gz: 198822fd194ff176303b2d05ab599d662458e6e9100ee0d1c711ce819ddb7da324c6b86377a148fce0ff0a1e16492e8947eed8e894d88512a73fef9d2cf120b4
6
+ metadata.gz: 53de39c130f7134771b2ae8a03047ddd58ddf8daed8bf1b62e32f3627fe0125324e89a33aec4072cd38e4c5194261322e32d6069533fed8845c352982ca714fc
7
+ data.tar.gz: f3b02d37c1397fa5ddc2bf76247d85b1eef0d99a74d0c3afda583e97d1938ab1a7542c3ea557eec95c0deef199ddd1dfa5e73f3618598af009b8848f7def97d9
@@ -6,7 +6,7 @@
6
6
 
7
7
  =begin rdoc
8
8
 
9
- :section: Classes definied here
9
+ :section: Classes defined here
10
10
 
11
11
  Hermeneutics::Addr is a single address
12
12
  Hermeneutics::AddrList is a list of addresses in mail header fields.
@@ -306,22 +306,6 @@ module Hermeneutics
306
306
  end
307
307
  end
308
308
 
309
- def lexer_decode str, &block
310
- if block_given? then
311
- HeaderExt.lexer str do |k,s|
312
- case k
313
- when :decoded then yield Token[ :char, s, true]
314
- when :plain then lexer s, &block
315
- when :space then yield Token[ :space]
316
- end
317
- end
318
- else
319
- r = []
320
- lexer_decode str do |t| r.push t end
321
- r
322
- end
323
- end
324
-
325
309
  private
326
310
 
327
311
  def escaped h, c
@@ -432,7 +416,7 @@ module Hermeneutics
432
416
  # # "Möller, Fritz" <fmoeller@example.com>
433
417
  #
434
418
  def parse_decode str, &block
435
- l = Token.lexer_decode str
419
+ l = Token.lexer str
436
420
  compile l, &block
437
421
  end
438
422
 
@@ -577,7 +561,8 @@ module Hermeneutics
577
561
 
578
562
  class <<self
579
563
  def parse cont
580
- new.add_encoded cont
564
+ str = HeaderExt.decode cont
565
+ new.add_quoted str
581
566
  end
582
567
  end
583
568
 
@@ -596,7 +581,7 @@ module Hermeneutics
596
581
  def push addrs
597
582
  case addrs
598
583
  when nil then
599
- when String then add_encoded addrs
584
+ when String then add_quoted addrs
600
585
  when Addr then @list.push addrs
601
586
  else addrs.each { |a| push a }
602
587
  end
@@ -681,13 +666,6 @@ module Hermeneutics
681
666
  self
682
667
  end
683
668
 
684
- def add_encoded cont
685
- Addr.parse_decode cont.to_s do |a,|
686
- @list.push a
687
- end
688
- self
689
- end
690
-
691
669
  end
692
670
 
693
671
  end
@@ -129,7 +129,7 @@ module Hermeneutics
129
129
 
130
130
  def parameters nl: false, sym: false, strip: false
131
131
  if block_given? then
132
- data.parse do |k,v,**kw|
132
+ parameter_data.parse do |k,v,**kw|
133
133
  k = k.to_sym if sym
134
134
  if v then
135
135
  v.strip! if strip
@@ -146,33 +146,28 @@ module Hermeneutics
146
146
  end
147
147
  end
148
148
 
149
- def data
149
+ def parameter_data
150
150
  case request_method
151
151
  when "GET", "HEAD" then
152
- Data::UrlEnc.new query_string
152
+ dc, d = Data::UrlEnc, query_string
153
153
  when "POST" then
154
- data = $stdin.binmode.read
155
- data.bytesize == content_length.to_i or
156
- warn "Content length #{content_length} is wrong (#{data.bytesize})."
154
+ d = $stdin.binmode.read
155
+ d.bytesize == content_length.to_i or
156
+ warn "Content length #{content_length} is wrong (#{d.bytesize})."
157
157
  ct = ContentType.parse content_type
158
- data.force_encoding ct[ :charset]||Encoding::ASCII_8BIT
159
- case ct.fulltype
160
- when "application/x-www-form-urlencoded" then
161
- Data::UrlEnc.new data
162
- when "multipart/form-data" then
163
- Data::Multiparted.new data, ct.hash
164
- when "text/plain" then
165
- Data::Plain.new data
166
- when "application/json" then
167
- Data::Json.new data
168
- when "application/x-yaml", "application/yaml" then
169
- Data::Yaml.new data
170
- else
171
- Data::UrlEnc.new data
158
+ d.force_encoding ct[ :charset]||Encoding::ASCII_8BIT
159
+ dc = case ct.fulltype
160
+ when "application/x-www-form-urlencoded" then Data::UrlEnc
161
+ when "multipart/form-data" then a = [ ct.hash] ; Data::Multiparted
162
+ when "text/plain" then Data::Plain
163
+ when "application/json" then Data::Json
164
+ when "application/x-yaml", "application/yaml" then Data::Yaml
165
+ else Data::UrlEnc
172
166
  end
173
167
  else
174
- Data::Lines.new read_interactive
168
+ dc, d = Data::Lines, read_interactive
175
169
  end
170
+ dc.new d, *a
176
171
  end
177
172
 
178
173
 
@@ -208,8 +203,9 @@ module Hermeneutics
208
203
  class Lines < Plain
209
204
  def initialize lines
210
205
  @lines = lines
206
+ super nil
211
207
  end
212
- def data ; @lines.join "\n" ; end
208
+ def data ; @data ||= @lines.join "\n" ; end
213
209
  def parse
214
210
  @lines.each { |s|
215
211
  k, v = s.split %r/=/
@@ -4,7 +4,7 @@
4
4
 
5
5
  =begin rdoc
6
6
 
7
- :section: Classes definied here
7
+ :section: Classes defined here
8
8
 
9
9
  Hermeneutics::Color handles 24-bit colors.
10
10
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  =begin rdoc
6
6
 
7
- :section: Classes definied here
7
+ :section: Classes defined here
8
8
 
9
9
  Hermeneutics::Contents is a content field parser.
10
10
 
@@ -44,9 +44,9 @@ module Hermeneutics
44
44
  # ds[ "a"] #=> "0123456"
45
45
  #
46
46
  def parse line
47
- rest = line.strip
48
- hash = parse_hash rest
49
- new hash
47
+ rest = HeaderExt.decode line
48
+ rest.strip!
49
+ new *(build_args rest)
50
50
  end
51
51
 
52
52
  def urltext
@@ -55,7 +55,7 @@ module Hermeneutics
55
55
 
56
56
  private
57
57
 
58
- def parse_hash rest
58
+ def build_args rest
59
59
  hash = Hash.new { |h,k| h[ k] = [] }
60
60
  asts = {}
61
61
  while rest.notempty? do
@@ -66,6 +66,7 @@ module Hermeneutics
66
66
  else
67
67
  [ rest.dup, ""]
68
68
  end
69
+ rest.lstrip!
69
70
  key.downcase!
70
71
  key = key.to_sym
71
72
  asts[ key] = ast
@@ -91,7 +92,7 @@ module Hermeneutics
91
92
  end
92
93
  r[ k] = v
93
94
  }
94
- r
95
+ [ r]
95
96
  end
96
97
 
97
98
  end
@@ -236,11 +237,9 @@ module Hermeneutics
236
237
  # c.caption #=> "text/html"
237
238
  # c[ :boundary] #=> "0123456"
238
239
  #
239
- def parse line
240
- rest = line.strip
240
+ def build_args rest
241
241
  caption, rest = rest.split Dictionary::RES, 2
242
- hash = parse_hash rest
243
- new caption, hash
242
+ [ caption, *(super rest)]
244
243
  end
245
244
 
246
245
  end
@@ -9,7 +9,7 @@ require "supplement"
9
9
 
10
10
  =begin rdoc
11
11
 
12
- :section: Classes definied here
12
+ :section: Classes defined here
13
13
 
14
14
  Hermeneutics::Entities encodes to and decodes from HTML-Entities
15
15
  (+&amp;+ etc.)
@@ -401,11 +401,12 @@ module Hermeneutics
401
401
  #
402
402
  def mkurl path, hash = nil, anchor = nil
403
403
  unless Hash === hash then
404
- hash, anchor = anchor, hash
404
+ hash, anchor = anchor, nil
405
405
  end
406
- r = "#{path}"
407
- r << "?#{encode_hash hash}" if hash
408
- r << "##{anchor}" if anchor
406
+ r = ""
407
+ r << path.to_s
408
+ r << "?" << (encode_hash hash) if hash
409
+ r << "#" << anchor.to_s if anchor
409
410
  r
410
411
  end
411
412
 
@@ -726,28 +727,18 @@ module Hermeneutics
726
727
  #
727
728
  def decode str
728
729
  r, e = [], []
729
- v, l = nil, nil
730
- lexer str do |type,piece|
731
- case type
732
- when :decoded then
733
- e.push piece.encoding
734
- if l == :space and (v == :decoded or not v) then
735
- r.pop
736
- elsif l == :plain then
737
- r.push SPACE
738
- end
739
- when :space then
740
- nil
741
- when :plain then
742
- if l == :decoded then
743
- r.push SPACE
744
- end
730
+ loop do
731
+ if str =~ /=\?([a-z0-9_-]+?)\?([QB])\?([!-~]+?)\?=/i then
732
+ p = $`
733
+ d = unmask $1, $2, $3
734
+ str = $'
735
+ else
736
+ p = str
745
737
  end
746
- r.push piece
747
- v, l = l, type
748
- end
749
- if l == :space and v == :decoded then
750
- r.pop
738
+ r.push p if p =~ /\S/
739
+ d or break
740
+ r.push d
741
+ e.push d.encoding
751
742
  end
752
743
  e.uniq!
753
744
  begin
@@ -760,23 +751,6 @@ module Hermeneutics
760
751
  end
761
752
  end
762
753
 
763
- def lexer str
764
- while str do
765
- str =~ /(\s+)|\B=\?(\S*?)\?([QB])\?(\S*?)\?=\B/i
766
- if $1 then
767
- yield :plain, $` unless $`.empty?
768
- yield :space, $&
769
- elsif $2 then
770
- yield :plain, $` unless $`.empty?
771
- d = unmask $2, $3, $4
772
- yield :decoded, d
773
- else
774
- yield :plain, str
775
- end
776
- str = $'.notempty?
777
- end
778
- end
779
-
780
754
  private
781
755
 
782
756
  def unmask cs, tp, txt
@@ -146,11 +146,7 @@ module Hermeneutics
146
146
 
147
147
  def contents type = nil
148
148
  if type then
149
- if @contents then
150
- if not @contents.is_a? type then
151
- @contents = type.parse @data
152
- end
153
- else
149
+ unless @contents and (@contents.is_a? type) then
154
150
  @contents = type.parse @data
155
151
  end
156
152
  else
@@ -4,7 +4,7 @@
4
4
 
5
5
  =begin rdoc
6
6
 
7
- :section: Classes definied here
7
+ :section: Classes defined here
8
8
 
9
9
  Hermeneutics::Parser Parses HTML source and builds a tree
10
10
 
@@ -42,6 +42,12 @@ module Hermeneutics
42
42
  end
43
43
 
44
44
  class Timestamp
45
+ class <<self
46
+ def parse str
47
+ t = DateTime.parse str
48
+ new t
49
+ end
50
+ end
45
51
  attr_reader :value
46
52
  def initialize value = nil
47
53
  self.value = value
@@ -13,7 +13,7 @@
13
13
  module Hermeneutics
14
14
 
15
15
  NAME = "hermeneutics"
16
- VERSION = "1.23".freeze
16
+ VERSION = "1.24".freeze
17
17
  SUMMARY = "CGI and mail handling"
18
18
 
19
19
  DESCRIPTION = <<~EOT
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermeneutics
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.23'
4
+ version: '1.24'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: supplement
@@ -78,7 +77,6 @@ homepage: http://www.bertram-scharpf.de
78
77
  licenses:
79
78
  - BSD-2-Clause
80
79
  metadata: {}
81
- post_install_message:
82
80
  rdoc_options:
83
81
  - "--charset"
84
82
  - utf-8
@@ -98,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
96
  version: '0'
99
97
  requirements:
100
98
  - Ruby, at least 3.0
101
- rubygems_version: 3.5.21
102
- signing_key:
99
+ rubygems_version: 3.7.1
103
100
  specification_version: 4
104
101
  summary: CGI and mail handling
105
102
  test_files: []