epitools 0.5.124 → 0.5.125

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: 6ccc18312dec46b4af2100239be52ac5db3ce4aaf7c3cbdb8a325ec656fff6f9
4
- data.tar.gz: 2e68f10fc0006ef3dec61493d8950103a24e05f1ed24afc967bcfdb38e758282
3
+ metadata.gz: 2fcf4b7e59aa4de44dc3a90da3cefb218d720f22cc6c9f2177c5a4f470eac016
4
+ data.tar.gz: 4bba5168cfdb15666abdaed22cbe26a8e762942cbaa5d575c9d732f7db8897c7
5
5
  SHA512:
6
- metadata.gz: d65bbb00c1359e587f18399dbd952386f6beceae05c04201c8d0e97aec735c70b573cc337f56657ac372334202081b4c2c568a7753bc79f1e52f347fea1786e0
7
- data.tar.gz: 07c4623c4bd5217ebdce11fcb373ad27406e0d5d6eb8c0bd8f6c0e087c39c281a1146b757b9606da37026d01c791d8462bf62966ace409535f7f21e7d1d4b2a5
6
+ metadata.gz: 4780af5b44481720d1bc6164d1fee44c6e2fdcd439df99a69ac874f45b748400dcdb8e4f6878a7f2e05031478855a262448e53e8955cd7ffc7be6195b4e47458
7
+ data.tar.gz: d03c86090738137ce74dc6cff4cb398a93080eb643893c4b89212e2bc874bd78cfdbe82964a7e878aa6500d09b209a9ff3451af35d9a2ac4cf01e41cd01c2111
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.124
1
+ 0.5.125
@@ -1,7 +1,6 @@
1
1
  ## Standard library
2
2
 
3
3
  autoload :Set, 'set'
4
- autoload :URI, 'uri'
5
4
  autoload :Zlib, 'zlib'
6
5
  autoload :FileUtils, 'fileutils'
7
6
  autoload :Tempfile, 'tempfile'
@@ -23,6 +22,10 @@ autoload :CSV, 'csv'
23
22
  autoload :SDBM, 'sdbm'
24
23
  autoload :StringScanner, 'strscan'
25
24
 
25
+ autoreq :URI do
26
+ require 'epitools/core_ext/uri'
27
+ end
28
+
26
29
  module Digest
27
30
  autoload :SHA1, 'digest/sha1'
28
31
  autoload :SHA2, 'digest/sha2'
@@ -80,8 +83,13 @@ autoload :SemanticVersion, 'epitools/semantic_version'
80
83
  autoload :Matrix, 'epitools/core_ext/matrix'
81
84
  autoreq(:Vector) { Matrix }
82
85
 
83
- module Epi; autoload :Slop, 'epitools/slop'; end
84
- autoreq(:Slop) { Slop = Epi::Slop }
86
+ ## Bundled slop
87
+ module Epi
88
+ autoload :Slop, 'epitools/slop'
89
+ end
90
+ autoreq(:Slop) do
91
+ Slop = Epi::Slop
92
+ end
85
93
 
86
94
  ## Gems (common)
87
95
 
@@ -5,16 +5,23 @@ require 'epitools'
5
5
  require 'epitools/core_ext/object'
6
6
  require 'epitools/core_ext/class'
7
7
  require 'epitools/core_ext/module'
8
+
8
9
  require 'epitools/core_ext/string'
10
+
9
11
  require 'epitools/core_ext/array'
10
- require 'epitools/core_ext/file'
11
- require 'epitools/core_ext/io'
12
12
  require 'epitools/core_ext/enumerable'
13
13
  require 'epitools/core_ext/hash'
14
+
14
15
  require 'epitools/core_ext/numbers'
15
16
  require 'epitools/core_ext/truthiness'
16
17
  require 'epitools/core_ext/range'
17
18
  require 'epitools/core_ext/time'
19
+
20
+ require 'epitools/core_ext/argv'
21
+ require 'epitools/core_ext/file'
22
+ require 'epitools/core_ext/io'
23
+ require 'epitools/core_ext/uri'
24
+
18
25
  require 'epitools/core_ext/misc'
19
26
 
20
27
  ##############################################################################
@@ -0,0 +1,59 @@
1
+ class << ARGV
2
+
3
+ def parse!
4
+ unless @opts or @args
5
+ @opts, @args = partition { |arg| arg[/^--?\w{1,2}/].nil? }
6
+ @opts = @opts.map { |opt| key, val = opt.strip(/^-+/).split("=") }.to_ostruct
7
+ if @opts.help
8
+ @help_handler.call
9
+ exit
10
+ end
11
+ end
12
+
13
+ [@opts, @args]
14
+ end
15
+
16
+ def parse
17
+ parse!
18
+ [@opts, @args]
19
+ end
20
+
21
+ def help?
22
+ !!@opts["help"]
23
+ end
24
+
25
+ def opts
26
+ parse! unless @opts
27
+ @opts
28
+ end
29
+
30
+ def args
31
+ @args ? @args : opts && @args
32
+ end
33
+
34
+ def paths
35
+ map(&:to_Path)
36
+ end
37
+
38
+ def paths_R
39
+ recursive_proc = proc do |paths|
40
+ paths.map { |path| path.dir? ? the_expander.(path.ls_R) : path }
41
+ end
42
+
43
+ recursive_proc.(paths)
44
+ end
45
+ alias_method :recursive_paths, :paths_R
46
+
47
+ def on_help(&block)
48
+ @help_handler = block
49
+ end
50
+
51
+ def regexes(escaped: true, case_sensitive: false)
52
+ if case_sensitive
53
+ map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/ } # NO 'i'
54
+ else
55
+ map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/i }
56
+ end
57
+ end
58
+
59
+ end
@@ -128,79 +128,6 @@ end
128
128
 
129
129
 
130
130
 
131
- module URI
132
-
133
- #
134
- # Return a Hash of the variables in the query string
135
- #
136
- def params
137
- query ? query.to_params : {}
138
- end
139
-
140
- #
141
- # URIs are strings, dammit!
142
- #
143
- def to_str
144
- to_s
145
- end
146
-
147
- #
148
- # Default user agent for the 'get' method
149
- #
150
- # USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
151
-
152
- #
153
- # Get this URI using Net::HTTP
154
- #
155
- def get(headers={}, redirect_limit=10)
156
- raise "Sorry, URI can't get from #{scheme.inspect} URIs yet" unless scheme =~ /^https?$/
157
- raise 'Too many HTTP redirections' if redirect_limit == 0
158
-
159
- # headers['User-Agent'] ||= USER_AGENT
160
-
161
- # response = Net::HTTP.start(host, port) do |http|
162
- # # the_path = path.empty? ? "/" : path
163
- # req = Net::HTTP::Get.new(self, headers)
164
- # http.request(req)
165
- # end
166
-
167
- response = Net::HTTP.get_response(self)
168
-
169
- case response
170
- when Net::HTTPSuccess
171
- response
172
- when Net::HTTPRedirection
173
- # puts "redirect: #{response['location']}"
174
- URI(response['location']).get(headers, redirect_limit-1)
175
- else
176
- response.error!
177
- end
178
- end
179
-
180
- end
181
-
182
- #
183
- # Stupid workaround for URI blowing up when it receives a [ or ] character
184
- #
185
- module Better_URI_RFC3986_Parser # ::RFC3986_relative_ref
186
- ESCAPE_ME_PLZ = "[]{}!"
187
-
188
- def split(uri)
189
- subsitutions = ESCAPE_ME_PLZ.chars.map { |c| [c, CGI.escape(c)] }
190
- subsitutions << [" ", "%20"]
191
-
192
- subsitutions.each do |find, replace|
193
- uri = uri.gsub(find, replace)
194
- end
195
-
196
- super(uri)
197
- end
198
-
199
- end
200
-
201
- URI::RFC3986_Parser.prepend(Better_URI_RFC3986_Parser)
202
-
203
-
204
131
 
205
132
  #
206
133
  # Give ObjectSpace Enumerable powers (select, map, etc.)
@@ -0,0 +1,88 @@
1
+ require 'uri'
2
+
3
+ module URI
4
+
5
+ #
6
+ # Return a Hash of the variables in the query string
7
+ #
8
+ def params
9
+ (@query ? @query.to_params : {})
10
+ end
11
+
12
+ #
13
+ # Mutate the query
14
+ # NB: This is super slow. To make it faster, store params directly in a locally cached dict, and only call `to_query` when query is accesed, or to_s/inspect are called
15
+ #
16
+ def params=(key, value)
17
+ current = params
18
+ current[key] = value
19
+ self.query = current.to_query
20
+ end
21
+
22
+ def query
23
+ params.to_query
24
+ end
25
+
26
+ #
27
+ # URIs are strings, dammit!
28
+ #
29
+ def to_str
30
+ to_s
31
+ end
32
+
33
+ #
34
+ # Default user agent for the 'get' method
35
+ #
36
+ # USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
37
+
38
+ #
39
+ # Get this URI using Net::HTTP
40
+ #
41
+ def get(headers={}, redirect_limit=10)
42
+ raise "Sorry, URI can't get from #{scheme.inspect} URIs yet" unless scheme =~ /^https?$/
43
+ raise 'Too many HTTP redirections' if redirect_limit == 0
44
+
45
+ # headers['User-Agent'] ||= USER_AGENT
46
+
47
+ # response = Net::HTTP.start(host, port) do |http|
48
+ # # the_path = path.empty? ? "/" : path
49
+ # req = Net::HTTP::Get.new(self, headers)
50
+ # http.request(req)
51
+ # end
52
+
53
+ response = Net::HTTP.get_response(self)
54
+
55
+ case response
56
+ when Net::HTTPSuccess
57
+ response
58
+ when Net::HTTPRedirection
59
+ # puts "redirect: #{response['location']}"
60
+ URI(response['location']).get(headers, redirect_limit-1)
61
+ else
62
+ response.error!
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ #
69
+ # Stupid workaround for URI blowing up when it receives a [ or ] character
70
+ #
71
+ module Better_URI_RFC3986_Parser # ::RFC3986_relative_ref
72
+ ESCAPE_ME_PLZ = "[]{}!"
73
+
74
+ def split(uri)
75
+ subsitutions = ESCAPE_ME_PLZ.chars.map { |c| [c, CGI.escape(c)] }
76
+ subsitutions << [" ", "%20"]
77
+
78
+ subsitutions.each do |find, replace|
79
+ uri = uri.gsub(find, replace)
80
+ end
81
+
82
+ super(uri)
83
+ end
84
+
85
+ end
86
+
87
+ URI::RFC3986_Parser.prepend(Better_URI_RFC3986_Parser)
88
+
@@ -1,8 +1,10 @@
1
+ ####################################################################################
1
2
  #
2
3
  # If you require 'epitools/minimal' instead of 'epitools',
3
4
  # this is what you get: core_ext monkeypatches and all the
4
5
  # autoloads; the barest essentials for survival.
5
6
  #
7
+ ####################################################################################
6
8
 
7
9
  if RUBY_VERSION[/^1.8/]
8
10
  require 'enumerator'
@@ -14,6 +16,7 @@ RbConfig = Config unless defined? RbConfig
14
16
  Infinity = Float::INFINITY
15
17
  Inf = Float::INFINITY
16
18
 
19
+ ####################################################################################
17
20
  class Object
18
21
 
19
22
  unless defined?(__DIR__)
@@ -179,6 +182,7 @@ class Object
179
182
  end
180
183
 
181
184
 
185
+ ####################################################################################
182
186
  #
183
187
  # Patch 'Module#const_missing' to support 'autoreq' (which can autoload gems)
184
188
  #
@@ -213,6 +217,8 @@ class Module
213
217
  end
214
218
 
215
219
 
220
+
221
+ ####################################################################################
216
222
  module Kernel
217
223
 
218
224
  #
@@ -254,10 +260,8 @@ module Kernel
254
260
  end
255
261
 
256
262
  end
257
- ####################################################################################
258
-
259
-
260
263
 
264
+ ####################################################################################
261
265
  class String
262
266
 
263
267
  #
@@ -270,6 +274,7 @@ class String
270
274
 
271
275
  end
272
276
 
277
+ ####################################################################################
273
278
  #
274
279
  # Path("/some/path") is an alias for Path["/some/path"]
275
280
  #
@@ -277,43 +282,7 @@ def Path(arg)
277
282
  Path[arg]
278
283
  end
279
284
 
280
- ####################################################################
281
-
282
- # class << ARGV
283
-
284
- # def opts
285
- # @opts, @args ||= partition { |arg| arg[/^--?\w{1,2}/].nil? }
286
- # end
287
-
288
- # def args
289
- # @args ? @args : opts && @args
290
- # end
291
-
292
- # def paths
293
- # map(&:to_Path)
294
- # end
295
-
296
- # def paths_R
297
- # recursive_proc = proc do |paths|
298
- # paths.map { |path| path.dir? ? the_expander.(path.ls_R) : path }
299
- # end
300
-
301
- # recursive_proc.(paths)
302
- # end
303
- # alias_method :recursive_paths, :paths_R
304
-
305
- # def regexes(escaped: true, case_sensitive: false)
306
- # if case_sensitive
307
- # map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/ } # NO 'i'
308
- # else
309
- # map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/i }
310
- # end
311
- # end
312
-
313
- # end
314
285
 
315
286
  ####################################################################
316
-
317
287
  require 'epitools/autoloads'
318
-
319
288
  ####################################################################
@@ -61,7 +61,7 @@ module WM
61
61
 
62
62
  def self.all
63
63
  # FIXME: Windows owned by linux-namespaced processes (firejail) report their namspaced pid to X11. `window.process` ends up pointing at either nil, or the wrong process.
64
- `wmctrl -lpG`.lines.map(&:strip).map { |line| Window.from_line(line) }
64
+ `wmctrl -lpG`.lines.map(&:strip).map { |line| Window.from_line(line) unless line.blank? }.compact
65
65
  end
66
66
 
67
67
  def self.from_line(line)
@@ -106,23 +106,6 @@ module WM
106
106
  system "wmctrl", "-i", "-a", window_id
107
107
  end
108
108
 
109
- def maximized?
110
- end
111
-
112
- def maximize!
113
- system "wmctrl", "-i", "-a", window_id
114
- end
115
-
116
-
117
- def unmazimize!
118
- end
119
-
120
- def minimized?
121
- end
122
-
123
- def minimize!
124
- end
125
-
126
109
  #
127
110
  # string is made up of regular text, plus <>'d keypresses
128
111
  # eg: "Hello<Ctrl-T><Ctrl-L><Ctrl-Shift-K><Return>!!!"
@@ -1242,6 +1242,16 @@ describe File do
1242
1242
 
1243
1243
  end
1244
1244
 
1245
+ describe ARGV do
1246
+
1247
+ # it "parses args" do
1248
+ # ARGV.clear
1249
+ # ARGV << "-d"
1250
+ # ARGV.parse!
1251
+ # p ARGV.opts
1252
+ # end
1253
+
1254
+ end
1245
1255
 
1246
1256
  describe "Anything" do
1247
1257
 
@@ -1275,5 +1285,13 @@ describe URI do
1275
1285
  (response.size > 0).should == true
1276
1286
  end
1277
1287
 
1288
+ it "params=" do
1289
+ u = "http://butt.com/?q=1".to_uri
1290
+ u.query.should == "q=1"
1291
+ u.params["q"] = 2
1292
+ u.params["q"].should == 2
1293
+ u.query.should == "q=2"
1294
+ end
1295
+
1278
1296
  end
1279
1297
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.124
4
+ version: 0.5.125
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-05 00:00:00.000000000 Z
11
+ date: 2019-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -51,6 +51,7 @@ files:
51
51
  - lib/epitools/clitools.rb
52
52
  - lib/epitools/colored.rb
53
53
  - lib/epitools/core_ext.rb
54
+ - lib/epitools/core_ext/argv.rb
54
55
  - lib/epitools/core_ext/array.rb
55
56
  - lib/epitools/core_ext/class.rb
56
57
  - lib/epitools/core_ext/enumerable.rb
@@ -66,6 +67,7 @@ files:
66
67
  - lib/epitools/core_ext/string.rb
67
68
  - lib/epitools/core_ext/time.rb
68
69
  - lib/epitools/core_ext/truthiness.rb
70
+ - lib/epitools/core_ext/uri.rb
69
71
  - lib/epitools/daemonize.rb
70
72
  - lib/epitools/hexdump.rb
71
73
  - lib/epitools/iter.rb
@@ -139,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  - !ruby/object:Gem::Version
140
142
  version: '0'
141
143
  requirements: []
142
- rubygems_version: 3.0.4
144
+ rubygems_version: 3.1.2
143
145
  signing_key:
144
146
  specification_version: 3
145
147
  summary: Not utils... METILS!