rubyment 0.6.25581116 → 0.6.25622871
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/lib/rubyment.rb +1450 -673
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1af01ed82dd69412c3b2bb67c4d4563a12c8866f
|
4
|
+
data.tar.gz: f2b77d810d636178b2e474d8e20d2df83801d80b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45908cb4f83297a21fb499e2f87bba89c87f42a1a54ec7617f75c7754b791a1736cd2e840cf0fd0ac2c2808df86f8706a0f82f259d5c67e2a66dcfed5721a1d7
|
7
|
+
data.tar.gz: 6b202da96a5f35e602441ed1f285896c774e3257607245fb3d8dd059cf49711443b0501a5a06b8bc7dba5fcc691a25808eb5ff99a7a43b6a2707cee2a5d7aa11
|
data/lib/rubyment.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
TrueClass will be changed just by including
|
7
7
|
this file or requiring rubyment, which is not the
|
8
8
|
best approach, but kept to respect the open/closed
|
9
|
-
principle, but new functions should be added here.
|
9
|
+
principle, but new functions should NOT be added here.
|
10
10
|
# end_documentation
|
11
11
|
=end
|
12
12
|
class TrueClass
|
@@ -23,7 +23,7 @@ end
|
|
23
23
|
Object will be changed just by including
|
24
24
|
this file or requiring rubyment, which is not the
|
25
25
|
best approach, but kept to respect the open/closed
|
26
|
-
principle, but new functions should be added here.
|
26
|
+
principle, but new functions should NOT be added here.
|
27
27
|
|
28
28
|
only a bunch of methods, is, however, added:
|
29
29
|
. negate_me
|
@@ -90,6 +90,82 @@ class Object
|
|
90
90
|
self
|
91
91
|
)
|
92
92
|
end
|
93
|
+
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
=begin
|
99
|
+
# begin_documentation
|
100
|
+
This module offers function to interface with certain
|
101
|
+
internal structures. Ie, these functions are supposed
|
102
|
+
to be useless unless running Rubyment.
|
103
|
+
|
104
|
+
# end_documentation
|
105
|
+
=end
|
106
|
+
module InternalRubymentModule
|
107
|
+
|
108
|
+
|
109
|
+
=begin
|
110
|
+
gets the current @memory
|
111
|
+
=end
|
112
|
+
def rubyment_memory__
|
113
|
+
@memory
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
=begin
|
118
|
+
updates the current @memory with a new hash m
|
119
|
+
=end
|
120
|
+
def rubyment_memory__shallow_update m
|
121
|
+
@memory.update m
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
=begin
|
126
|
+
updates the current @memory with a new hash m
|
127
|
+
=end
|
128
|
+
def rubyment_memory__set m
|
129
|
+
@memory = m
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
=begin
|
137
|
+
# begin_documentation
|
138
|
+
Object will be changed just by including
|
139
|
+
this file or requiring rubyment, which is not the
|
140
|
+
best approach, but kept to respect the open/closed
|
141
|
+
principle, the Object class is kept adding some
|
142
|
+
methods.
|
143
|
+
|
144
|
+
However, the best approach is to add new functions
|
145
|
+
to this module, which will only be used to modify
|
146
|
+
the Object class if the RubymentModule is included.
|
147
|
+
|
148
|
+
|
149
|
+
# end_documentation
|
150
|
+
=end
|
151
|
+
module ModifierForClassObjectModule
|
152
|
+
|
153
|
+
|
154
|
+
def __is object
|
155
|
+
object
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
def array__is *args
|
160
|
+
args
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def __note arg
|
165
|
+
self
|
166
|
+
end
|
167
|
+
|
168
|
+
|
93
169
|
end
|
94
170
|
|
95
171
|
|
@@ -334,29 +410,11 @@ module RubymentExperimentModule
|
|
334
410
|
debug && (stderr.puts "{#{__method__} starting")
|
335
411
|
debug && (stderr.puts "caller=#{caller_label.inspect}")
|
336
412
|
debug && (stderr.puts "args=#{args.inspect}")
|
337
|
-
|
338
|
-
|
339
|
-
|
413
|
+
rv = tester_with_bled [
|
414
|
+
test_cases,
|
415
|
+
debug,
|
416
|
+
:use_first_of_bled_return.__is(true),
|
340
417
|
]
|
341
|
-
expectation = {}
|
342
|
-
actual = {}
|
343
|
-
debug && (stderr.puts "test_cases.size=#{test_cases.size}")
|
344
|
-
test_cases.each_with_index{ |test_case|
|
345
|
-
debug && (stderr.puts "test_case=[test_case_id, test_expectation, actual_params]=#{test_case.inspect}")
|
346
|
-
test_case_id, test_expectation, actual_params = test_case
|
347
|
-
actual_params_method_name,
|
348
|
-
*actual_params_method_args = actual_params
|
349
|
-
debug && (stderr.puts "will send: #{actual_params_method_name.to_s}(*#{actual_params_method_args.inspect})")
|
350
|
-
result = send actual_params_method_name, *actual_params_method_args
|
351
|
-
expectation[test_case_id] = test_expectation
|
352
|
-
actual[test_case_id] = result
|
353
|
-
debug && (stderr.puts "[test_expectation.hash, result.hash]=#{[test_expectation.hash, result.hash].inspect}")
|
354
|
-
}
|
355
|
-
judgement = actual.keys.map {|test_case|
|
356
|
-
[expectation[test_case], actual[test_case] , test_case]
|
357
|
-
}.map(&method("expect_equal")).all?
|
358
|
-
|
359
|
-
rv = judgement
|
360
418
|
debug && (stderr.puts "will return #{rv.inspect}")
|
361
419
|
debug && (stderr.puts "#{__method__} returning}")
|
362
420
|
rv
|
@@ -437,6 +495,24 @@ enum = (s.scan /http_[^(]*/).uniq.map
|
|
437
495
|
# send_enumerator [ enum, :gsub, ["http_", ""] ]
|
438
496
|
# => ["delete", "get", "head", "post", "put"]
|
439
497
|
|
498
|
+
send_enumerator [ ["tinga_http_tinga", "http_catepa"], :gsub, ["http_", ""] ]
|
499
|
+
# => ["tinga_tinga", "catepa"]
|
500
|
+
|
501
|
+
send_enumerator [ [ [1, 2, 3] ], :map, [], Proc.new {|x| x + 1 } ]
|
502
|
+
# => [[2, 3, 4]]
|
503
|
+
|
504
|
+
send_enumerator [ [ {}, {} ], :containerize, [], nil, 0]
|
505
|
+
# => [[{}], [{}]]
|
506
|
+
|
507
|
+
|
508
|
+
#bug:
|
509
|
+
send_enumerator [ [ {}, {} ], :method.to_nil, :args.to_nil, Proc.new {} ]
|
510
|
+
# ArgumentError: no method name given
|
511
|
+
|
512
|
+
# no bug, just not intuitive usage:
|
513
|
+
|
514
|
+
send_enumerator [ [ {}, {} ], Proc.new {|x| x.size }, [].to_nil, :whatever, 0]
|
515
|
+
# => [0, 0]
|
440
516
|
|
441
517
|
=end
|
442
518
|
def send_enumerator args=[]
|
@@ -445,9 +521,21 @@ enum = (s.scan /http_[^(]*/).uniq.map
|
|
445
521
|
args_to_method,
|
446
522
|
block_to_method,
|
447
523
|
replace_at_index,
|
524
|
+
debug,
|
525
|
+
no_output_exceptions,
|
526
|
+
rescuing_exceptions,
|
527
|
+
return_not_only_first,
|
448
528
|
reserved = args
|
449
529
|
|
530
|
+
stderr = @memory[:stderr]
|
531
|
+
debug = debug.nne
|
532
|
+
debug && (stderr.puts "{#{__method__} starting")
|
533
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
534
|
+
debug && (stderr.puts "args=#{args.inspect}")
|
450
535
|
args_to_method = args_to_method.nne []
|
536
|
+
no_output_exceptions = no_output_exceptions.nne
|
537
|
+
rescuing_exceptions = rescuing_exceptions.nne
|
538
|
+
return_not_only_first = return_not_only_first.nne
|
451
539
|
|
452
540
|
calling_tuples = enum.map {|e|
|
453
541
|
method_name = (!method.respond_to? :call) && method || nil
|
@@ -458,13 +546,28 @@ enum = (s.scan /http_[^(]*/).uniq.map
|
|
458
546
|
replace_at_index && (c_t[replace_at_index] = e)
|
459
547
|
method_name && (c_t.unshift method_name)
|
460
548
|
c_t.unshift method_to_call
|
549
|
+
debug && (stderr.puts "[e, method_to_call, method_name, replace_at_index]=#{[e, method_name, method_to_call, replace_at_index]}")
|
550
|
+
|
461
551
|
c_t
|
462
552
|
}
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
553
|
+
debug && (stderr.puts "calling_tuples=#{calling_tuples}")
|
554
|
+
|
555
|
+
rv = calling_tuples.map {|c_t|
|
556
|
+
block = bled [
|
557
|
+
:nil,
|
558
|
+
rescuing_exceptions,
|
559
|
+
no_output_exceptions,
|
560
|
+
] {
|
561
|
+
method_to_call, *args_to_call = c_t
|
562
|
+
method_to_call.call *args_to_call, &block_to_method
|
563
|
+
}
|
564
|
+
return_not_only_first.negate_me && (lrv = block.first.call.first)
|
565
|
+
return_not_only_first && (lrv = block.first.call)
|
566
|
+
lrv
|
467
567
|
}
|
568
|
+
debug && (stderr.puts "will return #{rv.inspect}")
|
569
|
+
debug && (stderr.puts "#{__method__} returning}")
|
570
|
+
rv
|
468
571
|
end
|
469
572
|
|
470
573
|
|
@@ -730,23 +833,193 @@ enum = (s.scan /http_[^(]*/).uniq.map
|
|
730
833
|
end
|
731
834
|
|
732
835
|
|
733
|
-
|
836
|
+
=begin
|
837
|
+
trying to get the interface compatible with
|
838
|
+
# rest_request_or_open_uri_open
|
839
|
+
# ideally, i would need an equivalent for
|
840
|
+
# rest_response__request_base
|
841
|
+
|
842
|
+
=end
|
843
|
+
def http_request_response__curl args=[]
|
844
|
+
stderr = @memory[:stderr]
|
845
|
+
url,
|
846
|
+
payload,
|
847
|
+
verify_ssl,
|
848
|
+
unimplemented__headers,
|
849
|
+
method,
|
850
|
+
auth_user,
|
851
|
+
password,
|
852
|
+
unimplemented__timeout,
|
853
|
+
unused__skip_open_uri,
|
854
|
+
debug,
|
855
|
+
no_rescuing,
|
856
|
+
output_exception,
|
857
|
+
reserved = args
|
858
|
+
|
859
|
+
debug = debug.nne
|
860
|
+
debug && (stderr.puts "{#{__method__} starting")
|
861
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
862
|
+
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
863
|
+
no_rescuing = no_rescuing.nne
|
864
|
+
output_exception = output_exception.nne
|
865
|
+
method = method.nne "get"
|
866
|
+
verify_ssl = verify_ssl.nne
|
867
|
+
curl_method = "http_#{method.downcase}"
|
868
|
+
curl_post_data = payload.nne
|
869
|
+
curl_args = [url, curl_post_data].compact
|
870
|
+
block = bled [
|
871
|
+
:no_answer.to_nil,
|
872
|
+
no_rescuing,
|
873
|
+
output_exception,
|
874
|
+
] {
|
875
|
+
require 'curb'
|
876
|
+
c = Curl::Easy.send(curl_method, *curl_args){|c|
|
877
|
+
c.http_auth_types = :basic
|
878
|
+
c.username = auth_user
|
879
|
+
c.password = password
|
880
|
+
c.ssl_verify_host = verify_ssl
|
881
|
+
c.ssl_verify_peer = verify_ssl
|
882
|
+
c.follow_location = true
|
883
|
+
debug && (stderr.puts "c.ssl_verify_peer=#{c.ssl_verify_peer?}")
|
884
|
+
debug && (stderr.puts "c.ssl_verify_host=#{c.ssl_verify_host?}")
|
885
|
+
}
|
886
|
+
c.perform
|
887
|
+
[ c.body_str, nil, c.http_connect_code]
|
888
|
+
}
|
889
|
+
rv = block.first.call
|
890
|
+
|
891
|
+
debug && (stderr.puts "#{__method__} will return #{rv.inspect}")
|
892
|
+
debug && (stderr.puts "#{__method__} returning}")
|
893
|
+
rv
|
894
|
+
end
|
734
895
|
|
735
896
|
|
736
897
|
=begin
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
898
|
+
tests #experiment__web_http_https_server, creating two
|
899
|
+
servers, one ssl and another plain, redirecting to
|
900
|
+
the ssl one. then, opens a client thread with a client
|
901
|
+
connecting to the root document of the plain server
|
902
|
+
(and in the end being served by the root document of
|
903
|
+
the ssl server).
|
904
|
+
note that this function, with default values will run
|
905
|
+
forever. client_loop_times must be set (to at least 1)
|
741
906
|
=end
|
742
|
-
|
907
|
+
def test__experiment__web_http_https_server args = ARGV
|
908
|
+
stderr = @memory[:stderr]
|
909
|
+
tcp_ssl_server_method,
|
910
|
+
http_processing_method,
|
911
|
+
http_processing_method_args,
|
912
|
+
http_server_port,
|
913
|
+
http_ip_addr,
|
914
|
+
priv_pemfile,
|
915
|
+
cert_pem_file,
|
916
|
+
extra_cert_pem_files,
|
917
|
+
ssl_cert_pkey_chain_method,
|
918
|
+
debug_tcp_ssl_server_method,
|
919
|
+
happy_with_request,
|
920
|
+
io_method,
|
921
|
+
io_method_debug,
|
922
|
+
domain,
|
923
|
+
admit_non_ssl,
|
924
|
+
plain_http_processing_method,
|
925
|
+
plain_http_processing_method_args,
|
926
|
+
plain_http_server_port,
|
927
|
+
plain_http_ip_addr,
|
928
|
+
no_debug_client,
|
929
|
+
client_loop_times,
|
930
|
+
reserved = args
|
931
|
+
tcp_ssl_server_method = tcp_ssl_server_method.nne :experiment__web_http_https_server
|
932
|
+
domain = domain.nne "localhost"
|
933
|
+
http_server_port = http_server_port.nne 8003
|
934
|
+
plain_http_server_port = plain_http_server_port.nne 8004
|
935
|
+
no_debug_client = no_debug_client.nne
|
936
|
+
client_loop_times = client_loop_times.nne Float::INFINITY
|
937
|
+
servers = send tcp_ssl_server_method,
|
938
|
+
[
|
939
|
+
http_processing_method,
|
940
|
+
http_processing_method_args,
|
941
|
+
http_server_port,
|
942
|
+
http_ip_addr,
|
943
|
+
priv_pemfile,
|
944
|
+
cert_pem_file,
|
945
|
+
extra_cert_pem_files,
|
946
|
+
ssl_cert_pkey_chain_method,
|
947
|
+
debug_tcp_ssl_server_method,
|
948
|
+
happy_with_request,
|
949
|
+
io_method,
|
950
|
+
io_method_debug,
|
951
|
+
admit_non_ssl,
|
952
|
+
plain_http_processing_method,
|
953
|
+
plain_http_processing_method_args,
|
954
|
+
plain_http_server_port,
|
955
|
+
plain_http_ip_addr,
|
956
|
+
]
|
957
|
+
|
958
|
+
thread_client = Thread.new {
|
959
|
+
(1..client_loop_times).map { |i|
|
960
|
+
response = test__file_read__uri_root [
|
961
|
+
domain,
|
962
|
+
plain_http_server_port,
|
963
|
+
admit_non_ssl,
|
964
|
+
no_debug_client.negate_me,
|
965
|
+
]
|
966
|
+
sleep 2
|
967
|
+
}
|
968
|
+
}
|
969
|
+
thread_client.join
|
970
|
+
|
971
|
+
true
|
972
|
+
end
|
973
|
+
|
974
|
+
|
975
|
+
=begin
|
976
|
+
calls a function with the processing arg
|
977
|
+
@param [Array] +args+, an +Array+ whose elements are expected to be:
|
978
|
+
+processing_arg+:: [Object]
|
979
|
+
+method+:: [Method, String]
|
980
|
+
+method_args+:: [Array] args to be given to the +transform_method_name+
|
981
|
+
+on_object+:: [String, Boolean]
|
982
|
+
+debug+:: [Boolean]
|
983
|
+
+output_exceptions+:: [Boolean]
|
984
|
+
|
985
|
+
@return [String] +processing_arg+
|
986
|
+
=end
|
987
|
+
def transform_call args = ARGV
|
988
|
+
processing_arg,
|
989
|
+
method,
|
990
|
+
method_args,
|
991
|
+
on_object,
|
992
|
+
debug,
|
993
|
+
output_exceptions,
|
994
|
+
reserved = args
|
995
|
+
stderr = @memory[:stderr]
|
996
|
+
debug = debug.nne
|
997
|
+
debug && (stderr.puts "{#{__method__} starting")
|
998
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
999
|
+
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
1000
|
+
object_arg = on_object.nne && processing_arg || nil
|
1001
|
+
to_method_block = bled [
|
1002
|
+
nil,
|
1003
|
+
:no_rescue.negate_me,
|
1004
|
+
output_exceptions,
|
1005
|
+
] {
|
1006
|
+
to_method(
|
1007
|
+
[method, object_arg]).call(
|
1008
|
+
[processing_arg] + method_args
|
1009
|
+
)
|
1010
|
+
}
|
1011
|
+
rv = to_method_block.first.call
|
1012
|
+
debug && (stderr.puts "will return first of: #{rv.inspect}")
|
1013
|
+
debug && (stderr.puts "#{__method__} returning}")
|
1014
|
+
rv.first
|
1015
|
+
end
|
743
1016
|
|
744
1017
|
|
745
1018
|
=begin
|
746
1019
|
# documentation_begin
|
747
|
-
# short_desc = "
|
1020
|
+
# short_desc = "natural improvement of experiment__tester: but protect each case from exception throwing",
|
748
1021
|
@memory[:documentation].push = {
|
749
|
-
:function => :
|
1022
|
+
:function => :tester_with_bled,
|
750
1023
|
:short_desc => short_desc,
|
751
1024
|
:description => "",
|
752
1025
|
:params => [
|
@@ -757,22 +1030,790 @@ module RubymentMaintainedModule
|
|
757
1030
|
:default_behavior => [],
|
758
1031
|
:params => [
|
759
1032
|
{
|
760
|
-
:name => :
|
761
|
-
:duck_type =>
|
762
|
-
:default_behavior =>
|
763
|
-
:description => "
|
1033
|
+
:name => :test_cases,
|
1034
|
+
:duck_type => Array,
|
1035
|
+
:default_behavior => :[],
|
1036
|
+
:description => "Array having the fields: __test_id__, __test_expected_value__ and __actual_params__. __actual_params__ is an __Array__ having as first member __method_name__ to be called, and all its remaining args __method_args__ (a __splat__) will be given to __method_name__",
|
764
1037
|
},
|
765
1038
|
{
|
766
|
-
:name => :
|
767
|
-
:duck_type =>
|
768
|
-
:default_behavior =>
|
769
|
-
:description => "
|
1039
|
+
:name => :debug,
|
1040
|
+
:duck_type => Object,
|
1041
|
+
:default_behavior => :nil,
|
1042
|
+
:description => "prints debug information to the __IO__ specified by __@memory[:stderr]__ (STDERR by default)",
|
770
1043
|
},
|
771
1044
|
{
|
772
|
-
:name => :
|
1045
|
+
:name => :use_first_of_bled_return,
|
773
1046
|
:duck_type => Object,
|
774
|
-
:default_behavior => nil,
|
775
|
-
:description => "
|
1047
|
+
:default_behavior => :nil,
|
1048
|
+
:description => "will ignore the exception report information returned by bled, and use only the first value.",
|
1049
|
+
},
|
1050
|
+
{
|
1051
|
+
:name => :output_exceptions,
|
1052
|
+
:duck_type => :boolean,
|
1053
|
+
:default_behavior => :nil,
|
1054
|
+
:description => "exceptions are normally properly handled by inner functions, but setting this to true can be helpful to debug some cases",
|
1055
|
+
:forwarded => [
|
1056
|
+
{ :to => :bled, :as => :output_exceptions }
|
1057
|
+
],
|
1058
|
+
},
|
1059
|
+
{
|
1060
|
+
:name => :no_rescue,
|
1061
|
+
:duck_type => :boolean,
|
1062
|
+
:default_behavior => :nil,
|
1063
|
+
:description => "don't protect against exceptions happening",
|
1064
|
+
:forwarded => [
|
1065
|
+
{ :to => :bled, :as => :dont_rescue }
|
1066
|
+
],
|
1067
|
+
},
|
1068
|
+
{
|
1069
|
+
:name => :reserved,
|
1070
|
+
:duck_type => Object,
|
1071
|
+
:default_behavior => :nil,
|
1072
|
+
:description => "for future use",
|
1073
|
+
},
|
1074
|
+
],
|
1075
|
+
},
|
1076
|
+
],
|
1077
|
+
:return_value => [
|
1078
|
+
{
|
1079
|
+
:name => :args,
|
1080
|
+
:description => "__true__ if tests were successful, __false__ otherwise",
|
1081
|
+
:duck_type => :boolean,
|
1082
|
+
},
|
1083
|
+
],
|
1084
|
+
}
|
1085
|
+
# documentation_end
|
1086
|
+
=end
|
1087
|
+
def tester_with_bled args=[]
|
1088
|
+
stderr = @memory[:stderr]
|
1089
|
+
test_cases,
|
1090
|
+
debug,
|
1091
|
+
use_first_of_bled_return,
|
1092
|
+
output_exceptions,
|
1093
|
+
no_rescue,
|
1094
|
+
reserved = args
|
1095
|
+
|
1096
|
+
debug = debug.nne
|
1097
|
+
debug && (stderr.puts "{#{__method__} starting")
|
1098
|
+
debug && (stderr.puts "caller=#{caller_label.inspect}")
|
1099
|
+
debug && (stderr.puts "args=#{args.inspect}")
|
1100
|
+
use_first_of_bled_return = use_first_of_bled_return.nne
|
1101
|
+
test_cases = test_cases.nne [
|
1102
|
+
# [ :id, :expectation, :actual_params ],
|
1103
|
+
# :actual_params: array with :method_name + :method_args
|
1104
|
+
]
|
1105
|
+
expectation = {}
|
1106
|
+
actual = {}
|
1107
|
+
debug && (stderr.puts "test_cases.size=#{test_cases.size}")
|
1108
|
+
test_cases.each_with_index{ |test_case|
|
1109
|
+
debug && (stderr.puts "test_case=[test_case_id, test_expectation, actual_params]=#{test_case.inspect}")
|
1110
|
+
test_case_id, test_expectation, actual_params = test_case
|
1111
|
+
actual_params_method_name,
|
1112
|
+
*actual_params_method_args = actual_params
|
1113
|
+
debug && (stderr.puts "will send: #{actual_params_method_name.to_s}(*#{actual_params_method_args.inspect})")
|
1114
|
+
|
1115
|
+
block = bled [
|
1116
|
+
nil,
|
1117
|
+
no_rescue,
|
1118
|
+
output_exceptions,
|
1119
|
+
] {
|
1120
|
+
send actual_params_method_name, *actual_params_method_args
|
1121
|
+
}
|
1122
|
+
result = block.first.call
|
1123
|
+
|
1124
|
+
expectation[test_case_id] = test_expectation
|
1125
|
+
use_first_of_bled_return && (actual[test_case_id] = result.first)
|
1126
|
+
use_first_of_bled_return.negate_me && (actual[test_case_id] = result)
|
1127
|
+
debug && (stderr.puts "[test_expectation.hash, result.hash]=#{[test_expectation.hash, result.hash].inspect}")
|
1128
|
+
}
|
1129
|
+
judgement = actual.keys.map {|test_case|
|
1130
|
+
[expectation[test_case], actual[test_case] , test_case]
|
1131
|
+
}.map(&method("expect_equal")).all?
|
1132
|
+
|
1133
|
+
rv = judgement
|
1134
|
+
debug && (stderr.puts "will return #{rv.inspect}")
|
1135
|
+
debug && (stderr.puts "#{__method__} returning}")
|
1136
|
+
rv
|
1137
|
+
end
|
1138
|
+
|
1139
|
+
|
1140
|
+
=begin
|
1141
|
+
returns a timestamp in the format "%Y.%m.%d_%H:%M:%S"
|
1142
|
+
=end
|
1143
|
+
def time__now_strftime_default
|
1144
|
+
Time.now.strftime("%Y.%m.%d_%H:%M:%S")
|
1145
|
+
end
|
1146
|
+
|
1147
|
+
|
1148
|
+
=begin
|
1149
|
+
# documentation_begin
|
1150
|
+
# short_desc = "this improves experiment__tester by encapsulating the bled block building, calls experiment__tester too "
|
1151
|
+
@memory[:documentation].push = {
|
1152
|
+
:function => :experiment__tester_with_bled,
|
1153
|
+
:short_desc => short_desc,
|
1154
|
+
:description => "",
|
1155
|
+
:params => [
|
1156
|
+
{
|
1157
|
+
:name => :args,
|
1158
|
+
:description => "list of parameters",
|
1159
|
+
:duck_type => Array,
|
1160
|
+
:default_behavior => [],
|
1161
|
+
:params => [
|
1162
|
+
{
|
1163
|
+
:name => :test_cases_method_args,
|
1164
|
+
:duck_type => Object,
|
1165
|
+
:default_behavior => :nil,
|
1166
|
+
:description => "for future use",
|
1167
|
+
},
|
1168
|
+
{
|
1169
|
+
:name => :test_cases_array,
|
1170
|
+
:duck_type => Object,
|
1171
|
+
:default_behavior => :nil,
|
1172
|
+
:description => "for future use",
|
1173
|
+
},
|
1174
|
+
{
|
1175
|
+
:name => :debug,
|
1176
|
+
:duck_type => :boolean,
|
1177
|
+
:default_behavior => :nil,
|
1178
|
+
:description => "prints debug information to the __IO__ specified by __@memory[:stderr]__ (STDERR by default)",
|
1179
|
+
},
|
1180
|
+
{
|
1181
|
+
:name => :debug_experiment__tester,
|
1182
|
+
:duck_type => :boolean,
|
1183
|
+
:default_behavior => :nil,
|
1184
|
+
:forwarded => [
|
1185
|
+
{ :to => :experiment__tester, :as => :debug }
|
1186
|
+
],
|
1187
|
+
},
|
1188
|
+
{
|
1189
|
+
:name => :output_exceptions,
|
1190
|
+
:duck_type => :boolean,
|
1191
|
+
:default_behavior => :nil,
|
1192
|
+
:description => "exceptions are normally properly handled by inner functions, but setting this to true can be helpful to debug some cases",
|
1193
|
+
},
|
1194
|
+
{
|
1195
|
+
:name => :to_method_debug,
|
1196
|
+
:duck_type => :boolean,
|
1197
|
+
:default_behavior => :nil,
|
1198
|
+
:forwarded => [
|
1199
|
+
{ :to => :to_method , :as => :to_method_debug }
|
1200
|
+
],
|
1201
|
+
},
|
1202
|
+
{
|
1203
|
+
:name => :to_object_method_debug,
|
1204
|
+
:duck_type => :boolean,
|
1205
|
+
:default_behavior => :nil,
|
1206
|
+
:forwarded => [
|
1207
|
+
{ :to => :to_method , :as => :to_object_method_debug }
|
1208
|
+
],
|
1209
|
+
},
|
1210
|
+
{
|
1211
|
+
:name => :reserved,
|
1212
|
+
:duck_type => Object,
|
1213
|
+
:default_behavior => :nil,
|
1214
|
+
:description => "for future use",
|
1215
|
+
},
|
1216
|
+
],
|
1217
|
+
},
|
1218
|
+
],
|
1219
|
+
:return_value => [
|
1220
|
+
{
|
1221
|
+
:name => :args,
|
1222
|
+
:description => "list of parameters",
|
1223
|
+
:duck_type => Array,
|
1224
|
+
:default_behavior => [],
|
1225
|
+
:params => [
|
1226
|
+
{
|
1227
|
+
:name => :reserved,
|
1228
|
+
:duck_type => Object,
|
1229
|
+
:default_behavior => :nil,
|
1230
|
+
:description => "for future use",
|
1231
|
+
},
|
1232
|
+
],
|
1233
|
+
},
|
1234
|
+
],
|
1235
|
+
}
|
1236
|
+
# documentation_end
|
1237
|
+
=end
|
1238
|
+
def experiment__tester_with_bled args=[]
|
1239
|
+
stderr = @memory[:stderr]
|
1240
|
+
test_cases_method,
|
1241
|
+
test_cases_method_args,
|
1242
|
+
test_cases_array,
|
1243
|
+
debug,
|
1244
|
+
debug_experiment__tester,
|
1245
|
+
output_exceptions,
|
1246
|
+
to_method_debug,
|
1247
|
+
to_object_method_debug,
|
1248
|
+
no_rescue,
|
1249
|
+
reserved = args
|
1250
|
+
debug = debug.nne
|
1251
|
+
debug && (stderr.puts "{#{__method__} starting")
|
1252
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
1253
|
+
debug && (stderr.puts "args=#{args.inspect}")
|
1254
|
+
test_cases_array = test_cases_array.nne []
|
1255
|
+
test_cases_method_args = test_cases_method_args.nne []
|
1256
|
+
test_cases_from_method = (to_method [
|
1257
|
+
test_cases_method,
|
1258
|
+
to_method_debug,
|
1259
|
+
to_object_method_debug,
|
1260
|
+
no_rescue,
|
1261
|
+
]).call *test_cases_method_args
|
1262
|
+
debug && (stderr.puts "test_cases_array.size=#{test_cases_array.size}")
|
1263
|
+
debug && (stderr.puts "test_cases_from_method.size=#{test_cases_from_method.size}")
|
1264
|
+
test_cases = test_cases_from_method.to_a + test_cases_array.to_a
|
1265
|
+
debug && (stderr.puts "test_cases.size=#{test_cases.size}")
|
1266
|
+
experiment__tester_block = bled [
|
1267
|
+
nil,
|
1268
|
+
no_rescue,
|
1269
|
+
output_exceptions,
|
1270
|
+
] {
|
1271
|
+
experiment__tester [
|
1272
|
+
test_cases,
|
1273
|
+
debug_experiment__tester,
|
1274
|
+
]
|
1275
|
+
}
|
1276
|
+
debug && (stderr.puts "experiment__tester_block=#{experiment__tester_block.inspect}")
|
1277
|
+
rv = experiment__tester_block.first.call
|
1278
|
+
debug && (stderr.puts "will return first of #{rv.inspect}")
|
1279
|
+
!rv.first && (stderr.puts "{#{__method__}: failed with arguments=#{args.inspect}}")
|
1280
|
+
rv[1] && (stderr.puts "{#{__method__} exception caught:")
|
1281
|
+
rv[1] && (stderr.puts :exception_output.__is(rv[1][1]))
|
1282
|
+
rv[1] && (stderr.puts "#{__method__} exception caught}")
|
1283
|
+
debug && (stderr.puts "#{__method__} returning}")
|
1284
|
+
rv.first
|
1285
|
+
end
|
1286
|
+
|
1287
|
+
|
1288
|
+
=begin
|
1289
|
+
give as first element in args to experiment__tester_with_bled
|
1290
|
+
=end
|
1291
|
+
def test_cases__send_enumerator args=[]
|
1292
|
+
testing_method = :send_enumerator
|
1293
|
+
test_cases ||= [
|
1294
|
+
[
|
1295
|
+
:test_case_id.__is("array_base"),
|
1296
|
+
:expectation.array__is("post", "get"),
|
1297
|
+
:get_actual_results_with.array__is(
|
1298
|
+
testing_method,
|
1299
|
+
:testing_method_args.array__is(
|
1300
|
+
:enum.array__is("http_post", "http_get"),
|
1301
|
+
:method_to_each_in_enum.__is(:gsub),
|
1302
|
+
:args_to_method.array__is("http_", ""),
|
1303
|
+
:block_to_method.__is(:whatever),
|
1304
|
+
:insert_iterating_element_at.__is(:ensure.__is(nil)),
|
1305
|
+
:debug.__is(false),
|
1306
|
+
:no_output_exceptions.__is(nil),
|
1307
|
+
:rescuing_exceptions.__is(nil),
|
1308
|
+
:return_not_only_first.__is(nil),
|
1309
|
+
),
|
1310
|
+
),
|
1311
|
+
].__note("end of array_base"),
|
1312
|
+
|
1313
|
+
[
|
1314
|
+
:test_case_id.__is("two_hashes_base"),
|
1315
|
+
:expectation.array__is(
|
1316
|
+
[{}], [{}],
|
1317
|
+
),
|
1318
|
+
:get_actual_results_with.array__is(
|
1319
|
+
testing_method,
|
1320
|
+
:testing_method_args.array__is(
|
1321
|
+
[ {}, {} ],
|
1322
|
+
:containerize,
|
1323
|
+
[],
|
1324
|
+
:block_to_method.__is(:whatever),
|
1325
|
+
:insert_iterating_element_at.__is(0),
|
1326
|
+
:debug.__is(nil),
|
1327
|
+
:no_output_exceptions.__is(nil),
|
1328
|
+
:rescuing_exceptions.__is(nil),
|
1329
|
+
:return_not_only_first.__is(nil),
|
1330
|
+
),
|
1331
|
+
),
|
1332
|
+
].__note("end of two_hashes_base"),
|
1333
|
+
|
1334
|
+
[
|
1335
|
+
:test_case_id.__is("two_hashes_size"),
|
1336
|
+
:expectation.array__is(0, 0),
|
1337
|
+
:get_actual_results_with.array__is(
|
1338
|
+
testing_method,
|
1339
|
+
:testing_method_args.array__is(
|
1340
|
+
[ {}, {} ],
|
1341
|
+
Proc.new {|x| x.size },
|
1342
|
+
[].to_nil,
|
1343
|
+
:block_to_method.__is(:whatever),
|
1344
|
+
:insert_iterating_element_at.__is(0),
|
1345
|
+
:debug.__is(nil),
|
1346
|
+
:no_output_exceptions.__is(nil),
|
1347
|
+
:rescuing_exceptions.__is(nil),
|
1348
|
+
:return_not_only_first.__is(nil),
|
1349
|
+
),
|
1350
|
+
),
|
1351
|
+
].__note("end of two_hashes_size"),
|
1352
|
+
|
1353
|
+
[
|
1354
|
+
:test_case_id.__is("distribute_methods_over_object_v1"),
|
1355
|
+
:expectation.array__is(
|
1356
|
+
"Test", "TEST",
|
1357
|
+
),
|
1358
|
+
:get_actual_results_with.array__is(
|
1359
|
+
testing_method,
|
1360
|
+
:testing_method_args.array__is(
|
1361
|
+
["capitalize", "upcase" ],
|
1362
|
+
Proc.new {|method| "test".send method },
|
1363
|
+
nil,
|
1364
|
+
:block_to_method.__is(:whatever),
|
1365
|
+
:insert_iterating_element_at.__is(0),
|
1366
|
+
:debug.__is(nil),
|
1367
|
+
:no_output_exceptions.__is(nil),
|
1368
|
+
:rescuing_exceptions.__is(nil),
|
1369
|
+
:return_not_only_first.__is(nil),
|
1370
|
+
),
|
1371
|
+
),
|
1372
|
+
].__note("end of distribute_methods_over_object_v1"),
|
1373
|
+
|
1374
|
+
[
|
1375
|
+
:test_case_id.__is("distribute_methods_over_object_v2"),
|
1376
|
+
:expectation.array__is(
|
1377
|
+
"Test", "TEST",
|
1378
|
+
),
|
1379
|
+
:get_actual_results_with.array__is(
|
1380
|
+
testing_method,
|
1381
|
+
:testing_method_args.array__is(
|
1382
|
+
["capitalize", "upcase" ],
|
1383
|
+
"test".method(:send),
|
1384
|
+
:args_to_method.__is(nil),
|
1385
|
+
:block_to_method.__is(:whatever),
|
1386
|
+
:insert_iterating_element_at.__is(0),
|
1387
|
+
:debug.__is(nil),
|
1388
|
+
:no_output_exceptions.__is(nil),
|
1389
|
+
:rescuing_exceptions.__is(nil),
|
1390
|
+
:return_not_only_first.__is(nil),
|
1391
|
+
),
|
1392
|
+
),
|
1393
|
+
].__note("end of distribute_methods_over_object_v2"),
|
1394
|
+
|
1395
|
+
[
|
1396
|
+
:test_case_id.__is("array_map"),
|
1397
|
+
:expectation.array__is(
|
1398
|
+
[2, 3, 4],
|
1399
|
+
),
|
1400
|
+
:get_actual_results_with.array__is(
|
1401
|
+
testing_method,
|
1402
|
+
:testing_method_args.array__is(
|
1403
|
+
:enum.array__is([1, 2, 3]),
|
1404
|
+
:method_to_each_in_enum.__is(:map),
|
1405
|
+
:args_to_method.__is(nil),
|
1406
|
+
:block_to_method.__is(Proc.new {|x| x + 1 }),
|
1407
|
+
:insert_iterating_element_at.__is(:ensure.__is(nil)),
|
1408
|
+
:debug.__is(nil),
|
1409
|
+
:no_output_exceptions.__is(nil),
|
1410
|
+
:rescuing_exceptions.__is(nil),
|
1411
|
+
:return_not_only_first.__is(nil),
|
1412
|
+
),
|
1413
|
+
),
|
1414
|
+
].__note("end of array_map"),
|
1415
|
+
|
1416
|
+
]
|
1417
|
+
|
1418
|
+
end
|
1419
|
+
|
1420
|
+
|
1421
|
+
=begin
|
1422
|
+
Just alias to
|
1423
|
+
experiment__tester_with_bled containerize test_cases__send_enumerator
|
1424
|
+
=end
|
1425
|
+
def test__send_enumerator args=[]
|
1426
|
+
debug,
|
1427
|
+
reserved = args
|
1428
|
+
stderr = @memory[:stderr]
|
1429
|
+
debug = debug.nne
|
1430
|
+
debug && (stderr.puts "{#{__method__} starting")
|
1431
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
1432
|
+
debug && (stderr.puts "args=#{args.inspect}")
|
1433
|
+
rv = experiment__tester_with_bled [:test_cases__send_enumerator]
|
1434
|
+
debug && (stderr.puts "will return #{rv.inspect}")
|
1435
|
+
debug && (stderr.puts "#{__method__} returning}")
|
1436
|
+
rv
|
1437
|
+
end
|
1438
|
+
|
1439
|
+
|
1440
|
+
=begin
|
1441
|
+
# documentation_begin
|
1442
|
+
# short_desc = "parses an http request"
|
1443
|
+
@memory[:documentation].push = {
|
1444
|
+
:function => :experiment__http_request_parse,
|
1445
|
+
:short_desc => short_desc,
|
1446
|
+
:description => "",
|
1447
|
+
:params => [
|
1448
|
+
{
|
1449
|
+
:name => :args,
|
1450
|
+
:description => "list of parameters",
|
1451
|
+
:duck_type => Array,
|
1452
|
+
:default_behavior => [],
|
1453
|
+
:params => [
|
1454
|
+
{
|
1455
|
+
:name => :request,
|
1456
|
+
:duck_type => [String, :array_of_strings],
|
1457
|
+
:default_behavior => :nil,
|
1458
|
+
:description => "for future use",
|
1459
|
+
},
|
1460
|
+
:name => :debug,
|
1461
|
+
:duck_type => :boolean,
|
1462
|
+
:default_behavior => :nil,
|
1463
|
+
:description => "prints debug information to the __IO__ specified by __@memory[:stderr]__ (STDERR by default)",
|
1464
|
+
},
|
1465
|
+
{
|
1466
|
+
:name => :methods_to_call,
|
1467
|
+
:duck_type => Array,
|
1468
|
+
:default_behavior => [
|
1469
|
+
:path_info,
|
1470
|
+
:request_uri,
|
1471
|
+
:body,
|
1472
|
+
:request_method,
|
1473
|
+
:ssl?,
|
1474
|
+
]
|
1475
|
+
:description => "methods/properties to extract from a WEBrick::HTTPRequest object -- it must be a valid method callable without parameters.",
|
1476
|
+
},
|
1477
|
+
{
|
1478
|
+
:name => :output_exceptions,
|
1479
|
+
:duck_type => :boolean,
|
1480
|
+
:default_behavior => :nil,
|
1481
|
+
:description => "exceptions are normally properly handled by inner functions, but setting this to true can be helpful to debug some cases",
|
1482
|
+
},
|
1483
|
+
{
|
1484
|
+
:name => :reserved,
|
1485
|
+
:duck_type => Object,
|
1486
|
+
:default_behavior => :nil,
|
1487
|
+
:description => "for future use",
|
1488
|
+
},
|
1489
|
+
],
|
1490
|
+
},
|
1491
|
+
],
|
1492
|
+
:return_value => [
|
1493
|
+
{
|
1494
|
+
:name => :args,
|
1495
|
+
:description => "list of parameters",
|
1496
|
+
:duck_type => Array,
|
1497
|
+
:default_behavior => [],
|
1498
|
+
:params => [
|
1499
|
+
{
|
1500
|
+
:name => :reserved,
|
1501
|
+
:duck_type => Object,
|
1502
|
+
:default_behavior => :nil,
|
1503
|
+
:description => "for future use",
|
1504
|
+
},
|
1505
|
+
],
|
1506
|
+
},
|
1507
|
+
],
|
1508
|
+
}
|
1509
|
+
# documentation_end
|
1510
|
+
=end
|
1511
|
+
def experiment__http_request_parse args=[]
|
1512
|
+
request,
|
1513
|
+
debug,
|
1514
|
+
methods_to_call,
|
1515
|
+
output_exceptions,
|
1516
|
+
reserved = args
|
1517
|
+
stderr = @memory[:stderr]
|
1518
|
+
debug = debug.nne
|
1519
|
+
debug && (stderr.puts "{#{__method__} starting")
|
1520
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
1521
|
+
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
1522
|
+
# debug && (stderr.puts "backtrace=#{backtrace}")
|
1523
|
+
output_exceptions = output_exceptions.nne
|
1524
|
+
methods_to_call = methods_to_call.nne [
|
1525
|
+
:path_info,
|
1526
|
+
:request_uri,
|
1527
|
+
:body,
|
1528
|
+
:request_method,
|
1529
|
+
:ssl?,
|
1530
|
+
]
|
1531
|
+
request = (containerize request.nne "").join
|
1532
|
+
debug && (stderr.puts "=#{}")
|
1533
|
+
require 'webrick'
|
1534
|
+
require 'stringio'
|
1535
|
+
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
|
1536
|
+
block = bled [
|
1537
|
+
:no_answer.to_nil,
|
1538
|
+
:no_rescue.negate_me,
|
1539
|
+
output_exceptions,
|
1540
|
+
] {
|
1541
|
+
req.parse(StringIO.new(request))
|
1542
|
+
req
|
1543
|
+
}
|
1544
|
+
parse_return = block.first.call
|
1545
|
+
methods_result_return = send_enumerator [
|
1546
|
+
methods_to_call,
|
1547
|
+
req.method(:send),
|
1548
|
+
:args_to_method.array__is(nil),
|
1549
|
+
:block_to_method.__is(:whatever),
|
1550
|
+
:insert_iterating_element_at.__is(0),
|
1551
|
+
:debug.__is(nil),
|
1552
|
+
:no_output_exceptions.__is(output_exceptions.negate_me),
|
1553
|
+
:rescuing_exceptions.__is(nil),
|
1554
|
+
:return_not_only_first.__is(true),
|
1555
|
+
]
|
1556
|
+
methods_result = methods_result_return.transpose[0]
|
1557
|
+
rv = [
|
1558
|
+
req,
|
1559
|
+
methods_to_call,
|
1560
|
+
methods_result,
|
1561
|
+
parse_return,
|
1562
|
+
methods_result_return,
|
1563
|
+
]
|
1564
|
+
debug && (stderr.puts "#{__method__} will return #{rv.inspect}")
|
1565
|
+
debug && (stderr.puts "#{__method__} returning}")
|
1566
|
+
rv
|
1567
|
+
end
|
1568
|
+
|
1569
|
+
|
1570
|
+
=begin
|
1571
|
+
returns an array having all the valid values for elements
|
1572
|
+
of methods_to_call parameter of #experiment__http_request_parse
|
1573
|
+
=end
|
1574
|
+
def callable_methods__http_request_parse args=[]
|
1575
|
+
methods_to_call = methods_to_call.nne [
|
1576
|
+
:path_info,
|
1577
|
+
:request_uri,
|
1578
|
+
:content_length,
|
1579
|
+
:body,
|
1580
|
+
:request_method,
|
1581
|
+
:ssl?,
|
1582
|
+
:path,
|
1583
|
+
:host,
|
1584
|
+
:attributes,
|
1585
|
+
:accept,
|
1586
|
+
:port,
|
1587
|
+
:query,
|
1588
|
+
:user,
|
1589
|
+
:addr,
|
1590
|
+
:header,
|
1591
|
+
:body,
|
1592
|
+
:request_method,
|
1593
|
+
:content_type,
|
1594
|
+
:keep_alive,
|
1595
|
+
:cookies,
|
1596
|
+
:http_version,
|
1597
|
+
:accept_charset,
|
1598
|
+
:query_string,
|
1599
|
+
:script_name,
|
1600
|
+
:server_name,
|
1601
|
+
:accept_encoding,
|
1602
|
+
:accept_language,
|
1603
|
+
:peeraddr,
|
1604
|
+
:raw_header,
|
1605
|
+
:continue,
|
1606
|
+
:remote_ip,
|
1607
|
+
:keep_alive?,
|
1608
|
+
:fixup,
|
1609
|
+
]
|
1610
|
+
end
|
1611
|
+
|
1612
|
+
|
1613
|
+
=begin
|
1614
|
+
# short_desc = "creates an http response, after executing the GET "
|
1615
|
+
|
1616
|
+
@memory[:documentation].push = {
|
1617
|
+
:function => :experiment__http_response_invoke,
|
1618
|
+
:short_desc => short_desc,
|
1619
|
+
:description => "",
|
1620
|
+
:params => [
|
1621
|
+
{
|
1622
|
+
:name => :args,
|
1623
|
+
:description => "list of parameters",
|
1624
|
+
:duck_type => Array,
|
1625
|
+
:default_behavior => "interpreted as empty array",
|
1626
|
+
:params => [
|
1627
|
+
{
|
1628
|
+
:name => :request,
|
1629
|
+
:duck_type => String,
|
1630
|
+
:default_behavior => :nil
|
1631
|
+
:description => "ignored, will redirect whatever request is made. nil is used.",
|
1632
|
+
},
|
1633
|
+
{
|
1634
|
+
:name => :location,
|
1635
|
+
:duck_type => String,
|
1636
|
+
:default_behavior => "",
|
1637
|
+
:description => "Location: field value (the url to redirect to)",
|
1638
|
+
},
|
1639
|
+
{
|
1640
|
+
:name => :code,
|
1641
|
+
:duck_type => String,
|
1642
|
+
:default_behavior => "200 OK",
|
1643
|
+
:description => "Request code",
|
1644
|
+
},
|
1645
|
+
{
|
1646
|
+
:name => :version,
|
1647
|
+
:duck_type => String,
|
1648
|
+
:default_behavior => "1.1",
|
1649
|
+
:description => "HTTP protocol version",
|
1650
|
+
},
|
1651
|
+
{
|
1652
|
+
:name => :debug,
|
1653
|
+
:duck_type => Object,
|
1654
|
+
:default_behavior => :nil,
|
1655
|
+
:description => "prints debug information to the __IO__ specified by __@memory[:stderr]__ (STDERR by default)",
|
1656
|
+
},
|
1657
|
+
{
|
1658
|
+
:name => :eol,
|
1659
|
+
:duck_type => Object,
|
1660
|
+
:default_behavior => "\r\n",
|
1661
|
+
:description => "separator to join each line of the response",
|
1662
|
+
},
|
1663
|
+
{
|
1664
|
+
:name => :debug_request_parse,
|
1665
|
+
:duck_type => :boolean,
|
1666
|
+
:default_behavior => :nil,
|
1667
|
+
:forwarded => [
|
1668
|
+
{ :to => experiment__http_request_parse , :as => :debug }
|
1669
|
+
],
|
1670
|
+
},
|
1671
|
+
{
|
1672
|
+
:name => :output_exceptions,
|
1673
|
+
:duck_type => :boolean,
|
1674
|
+
:default_behavior => :nil,
|
1675
|
+
:description => "exceptions are normally properly handled by inner functions, but setting this to true can be helpful to debug some cases",
|
1676
|
+
},
|
1677
|
+
{
|
1678
|
+
:name => :reserved,
|
1679
|
+
:duck_type => Object,
|
1680
|
+
:default_behavior => "interpreted as nil",
|
1681
|
+
:description => "for future use",
|
1682
|
+
},
|
1683
|
+
],
|
1684
|
+
},
|
1685
|
+
],
|
1686
|
+
}
|
1687
|
+
|
1688
|
+
=end
|
1689
|
+
def experiment__http_response_invoke args = []
|
1690
|
+
request,
|
1691
|
+
location,
|
1692
|
+
code,
|
1693
|
+
version,
|
1694
|
+
debug,
|
1695
|
+
eol,
|
1696
|
+
debug_request_parse,
|
1697
|
+
output_exceptions,
|
1698
|
+
reserved = args
|
1699
|
+
stderr = @memory[:stderr]
|
1700
|
+
stdout = @memory[:stdout]
|
1701
|
+
debug = debug.nne
|
1702
|
+
debug && (stderr.puts "{#{__method__} starting")
|
1703
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
1704
|
+
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
1705
|
+
request_parse = experiment__http_request_parse [
|
1706
|
+
request,
|
1707
|
+
debug_request_parse,
|
1708
|
+
:methods_to_call.to_nil,
|
1709
|
+
output_exceptions,
|
1710
|
+
]
|
1711
|
+
debug && (stderr.puts "request_parse[2]=#{request_parse[2]}")
|
1712
|
+
require "shellwords"
|
1713
|
+
# request_parse[2][0] is the the request_uri
|
1714
|
+
# remove any starting slashes before sending to invoke:
|
1715
|
+
args_for_rubyment = Shellwords.split(request_parse[2][0].to_s.gsub /\/*/, "")
|
1716
|
+
debug && (stderr.puts "args_for_rubyment=#{args_for_rubyment}")
|
1717
|
+
request_stdout = StringIO.new
|
1718
|
+
request_stderr = StringIO.new
|
1719
|
+
# not thread-safe:
|
1720
|
+
@memory[:stdout] = request_stdout
|
1721
|
+
@memory[:stderr] = request_stderr
|
1722
|
+
block = bled [
|
1723
|
+
:no_answer.to_nil,
|
1724
|
+
:no_rescue.negate_me,
|
1725
|
+
:output.negate_me,
|
1726
|
+
] {
|
1727
|
+
invoke args_for_rubyment
|
1728
|
+
}
|
1729
|
+
invoke_result = block.first.call
|
1730
|
+
@memory[:stdout] = stdout
|
1731
|
+
@memory[:stderr] = stderr
|
1732
|
+
require 'json'
|
1733
|
+
payload = ({
|
1734
|
+
"invoke_result" => invoke_result,
|
1735
|
+
"request_stdout" => request_stdout.string,
|
1736
|
+
"request_stderr" => request_stderr.string,
|
1737
|
+
}).to_json
|
1738
|
+
debug && (stderr.puts "payload=#{payload}")
|
1739
|
+
location = location.nne ""
|
1740
|
+
version = version.nne "1.1"
|
1741
|
+
code = code.nne "200 OK"
|
1742
|
+
eol = eol.nne "\r\n"
|
1743
|
+
rv = http_response_base [
|
1744
|
+
payload,
|
1745
|
+
:content_type.to_nil,
|
1746
|
+
code,
|
1747
|
+
version,
|
1748
|
+
:keep_alive.to_nil,
|
1749
|
+
debug,
|
1750
|
+
eol,
|
1751
|
+
location,
|
1752
|
+
]
|
1753
|
+
debug && (stderr.puts "#{__method__} will return #{rv.inspect}")
|
1754
|
+
debug && (stderr.puts "#{__method__} returning}")
|
1755
|
+
rv
|
1756
|
+
end
|
1757
|
+
|
1758
|
+
|
1759
|
+
=begin
|
1760
|
+
returns an array having all the paths which are ancestors of
|
1761
|
+
path, and path at the end of that array
|
1762
|
+
=end
|
1763
|
+
def parent_dirs__from path
|
1764
|
+
path_parent = File.dirname(path)
|
1765
|
+
base_case = (path == path_parent)
|
1766
|
+
rv = []
|
1767
|
+
base_case.negate_me && (
|
1768
|
+
rv = parent_dirs__from path_parent
|
1769
|
+
)
|
1770
|
+
rv.push path
|
1771
|
+
end
|
1772
|
+
|
1773
|
+
|
1774
|
+
end
|
1775
|
+
|
1776
|
+
|
1777
|
+
=begin
|
1778
|
+
# begin_documentation
|
1779
|
+
This module receives only functions that are maintained.
|
1780
|
+
Ie, the non-deprecated or not under deprecation functions.
|
1781
|
+
# end_documentation
|
1782
|
+
=end
|
1783
|
+
module RubymentMaintainedModule
|
1784
|
+
|
1785
|
+
|
1786
|
+
=begin
|
1787
|
+
# documentation_begin
|
1788
|
+
# short_desc = "extracts information about a block and return them structurally in an array."
|
1789
|
+
@memory[:documentation].push = {
|
1790
|
+
:function => :block_info_base,
|
1791
|
+
:short_desc => short_desc,
|
1792
|
+
:description => "",
|
1793
|
+
:params => [
|
1794
|
+
{
|
1795
|
+
:name => :args,
|
1796
|
+
:description => "list of parameters",
|
1797
|
+
:duck_type => Array,
|
1798
|
+
:default_behavior => [],
|
1799
|
+
:params => [
|
1800
|
+
{
|
1801
|
+
:name => :block,
|
1802
|
+
:duck_type => Exception,
|
1803
|
+
:default_behavior => nil,
|
1804
|
+
:description => "block to extract info from",
|
1805
|
+
},
|
1806
|
+
{
|
1807
|
+
:name => :max_str_index,
|
1808
|
+
:duck_type => FixNum,
|
1809
|
+
:default_behavior => -1,
|
1810
|
+
:description => "limit the full string output to this last index",
|
1811
|
+
},
|
1812
|
+
{
|
1813
|
+
:name => :reserved,
|
1814
|
+
:duck_type => Object,
|
1815
|
+
:default_behavior => nil,
|
1816
|
+
:description => "reserved for future use",
|
776
1817
|
},
|
777
1818
|
],
|
778
1819
|
},
|
@@ -1085,7 +2126,7 @@ module RubymentMaintainedModule
|
|
1085
2126
|
stderr = @memory[:stderr]
|
1086
2127
|
default_on_exception,
|
1087
2128
|
dont_rescue,
|
1088
|
-
output_backtrace,
|
2129
|
+
output_backtrace,
|
1089
2130
|
backtrace_max_str_len,
|
1090
2131
|
debug,
|
1091
2132
|
reserved = args
|
@@ -1289,11 +2330,109 @@ module RubymentDeprecatedModule
|
|
1289
2330
|
backtrace.to_a
|
1290
2331
|
).join "\n"
|
1291
2332
|
|
1292
|
-
full = string_truncate [
|
1293
|
-
full,
|
1294
|
-
max_str_index,
|
2333
|
+
full = string_truncate [
|
2334
|
+
full,
|
2335
|
+
max_str_index,
|
2336
|
+
]
|
2337
|
+
[short, full, inspection, backtrace]
|
2338
|
+
end
|
2339
|
+
|
2340
|
+
|
2341
|
+
# calls a function with the processing arg
|
2342
|
+
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
2343
|
+
# +processing_arg+:: [Object]
|
2344
|
+
# +method+:: [Method, String]
|
2345
|
+
# +method_args+:: [Array] args to be given to the +transform_method_name+
|
2346
|
+
# +on_object+:: [String, Boolean]
|
2347
|
+
#
|
2348
|
+
# @return [String] +processing_arg+
|
2349
|
+
def test__transform_call args = ARGV
|
2350
|
+
processing_arg, method, method_args, on_object = args
|
2351
|
+
object_arg = on_object.nne && processing_arg || nil
|
2352
|
+
p args
|
2353
|
+
to_method(
|
2354
|
+
[method, object_arg]).call(
|
2355
|
+
[processing_arg] + method_args
|
2356
|
+
)
|
2357
|
+
end
|
2358
|
+
|
2359
|
+
|
2360
|
+
# use #tcp_ssl_server
|
2361
|
+
# opens one or more TCP and/or SSL server accepting connections.
|
2362
|
+
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
2363
|
+
# +listening_port+:: [String, Integer] port to listen
|
2364
|
+
# +ip_addr+:: [String, nil] ip (no hostname) to bind the server. 0, nil, false, empty string will bind to all addresses possible. 0.0.0.0 => binds to all ipv4 . ::0 to all ipv4 and ipv6
|
2365
|
+
# +admit_plain+:: [Boolean] if +true+, tries to create a normal +TCPServer+, if not possible to create +SSLServer+ (default: +false+, for preventing unadvertnt non-SSL server creation)
|
2366
|
+
# +debug+:: [Object] for future use
|
2367
|
+
# +callback_method+:: [String, Method] method to call when a client connects. The method must accept a socket as parameter.
|
2368
|
+
# +callback_method_args+:: [Array] args to be given to the call_back_method. Note that the type differs from #tcp_server_plain (which takes splat)
|
2369
|
+
#
|
2370
|
+
# @return [Array] returns a , an +Array+ whose elements are:
|
2371
|
+
# +threads+:: [Array of Thread] returns an Array of Thread object looping for accepting incoming connections (call join on those object for waiting for its completion).
|
2372
|
+
def tcp_ssl_servers args = ARGV
|
2373
|
+
stderr = @memory[:stderr]
|
2374
|
+
listening_port,
|
2375
|
+
ip_addr,
|
2376
|
+
debug,
|
2377
|
+
admit_plain,
|
2378
|
+
callback_method,
|
2379
|
+
callback_method_args,
|
2380
|
+
priv_pemfile,
|
2381
|
+
cert_pem_file,
|
2382
|
+
extra_cert_pem_files,
|
2383
|
+
output_exception,
|
2384
|
+
reserved = args
|
2385
|
+
|
2386
|
+
server = (ssl_make_servers [
|
2387
|
+
listening_port,
|
2388
|
+
ip_addr,
|
2389
|
+
debug,
|
2390
|
+
admit_plain,
|
2391
|
+
priv_pemfile,
|
2392
|
+
cert_pem_file,
|
2393
|
+
extra_cert_pem_files,
|
2394
|
+
output_exception,
|
2395
|
+
]).first.first
|
2396
|
+
debug.nne && (stderr.puts server)
|
2397
|
+
Thread.start {
|
2398
|
+
loop {
|
2399
|
+
client = runea ["yes, rescue",
|
2400
|
+
"yes, output exception",
|
2401
|
+
"nil on exception"
|
2402
|
+
] {
|
2403
|
+
server.accept
|
2404
|
+
}
|
2405
|
+
Thread.start(client) { |client|
|
2406
|
+
debug.nne && (stderr.puts Thread.current)
|
2407
|
+
debug.nne && (stderr.puts client)
|
2408
|
+
runoe {
|
2409
|
+
to_method([callback_method])
|
2410
|
+
.call([client] + callback_method_args)
|
2411
|
+
}
|
2412
|
+
}
|
2413
|
+
}
|
2414
|
+
}
|
2415
|
+
end
|
2416
|
+
|
2417
|
+
|
2418
|
+
def test_cases_template args=[]
|
2419
|
+
# testing_method = :send_enumerator
|
2420
|
+
test_cases ||= [
|
2421
|
+
# [ :id, :expectation, :actual_params ],
|
2422
|
+
# actual_params can be an array with method_name + args to that method.
|
1295
2423
|
]
|
1296
|
-
|
2424
|
+
end
|
2425
|
+
|
2426
|
+
|
2427
|
+
def test__file_read___http_request_response__curl args=[]
|
2428
|
+
# these tests depend on internet connection, so it may be difficult
|
2429
|
+
# to automate them.
|
2430
|
+
url_1 = "https://www.google.com/"
|
2431
|
+
url_1 = "http://www.google.com/"
|
2432
|
+
url_1 = "https://localhost:8003/"
|
2433
|
+
url_1 = "https://localhost:8003/"
|
2434
|
+
url_1 = "http://localhost:8004/tinga"
|
2435
|
+
p file_read [url_1, nil, nil, nil, nil, :skip_open_uri, :payload.to_nil, false, nil, nil, nil, nil, :http_request_response__curl]
|
1297
2436
|
end
|
1298
2437
|
|
1299
2438
|
|
@@ -1522,6 +2661,29 @@ module RubymentUnderDeprecationModule
|
|
1522
2661
|
include RubymentUnderDeprecationRuneFunctionsModule
|
1523
2662
|
|
1524
2663
|
|
2664
|
+
# experimental stuff coming. usage example:
|
2665
|
+
# ./rubyment.rb invoke_double p test__shell_send_array__main "tinga" "" sub in EN
|
2666
|
+
# ["tENga"]
|
2667
|
+
# will be deprecated by send_array_base
|
2668
|
+
# ./rubyment.rb invoke_double p experiment__send_array_base 300 "bytes"
|
2669
|
+
# [[51, 48, 48], nil, nil]
|
2670
|
+
# only works with strings by now
|
2671
|
+
def test__shell_send_array__main args=[]
|
2672
|
+
p args
|
2673
|
+
object_to_send,
|
2674
|
+
reserved,
|
2675
|
+
method_to_send,
|
2676
|
+
*args_to_send = args
|
2677
|
+
object_to_send = object_to_send.nne
|
2678
|
+
method_to_send = method_to_send.nne :main
|
2679
|
+
object_to_send && (
|
2680
|
+
object_to_send.send method_to_send, *args_to_send
|
2681
|
+
) || (!object_to_send) && (
|
2682
|
+
send method_to_send, args_to_send
|
2683
|
+
)
|
2684
|
+
end
|
2685
|
+
|
2686
|
+
|
1525
2687
|
end
|
1526
2688
|
|
1527
2689
|
|
@@ -1538,14 +2700,6 @@ end
|
|
1538
2700
|
module RubymentTestModule
|
1539
2701
|
|
1540
2702
|
|
1541
|
-
def test_cases_template args=[]
|
1542
|
-
test_cases ||= [
|
1543
|
-
# [ :id, :expectation, :actual_params ],
|
1544
|
-
# actual_params can be an array with method_name + args to that method.
|
1545
|
-
]
|
1546
|
-
end
|
1547
|
-
|
1548
|
-
|
1549
2703
|
=begin
|
1550
2704
|
test for #bled
|
1551
2705
|
=end
|
@@ -1689,228 +2843,20 @@ module RubymentTestModule
|
|
1689
2843
|
end
|
1690
2844
|
|
1691
2845
|
|
1692
|
-
=
|
1693
|
-
|
1694
|
-
|
1695
|
-
method_to_test,
|
1696
|
-
reserved = args
|
1697
|
-
method_to_test = method_to_test.nne :experiment__send_array_base
|
2846
|
+
def test_cases__template args=[]
|
2847
|
+
# current best example: test_cases__send_enumerator
|
2848
|
+
# testing_method = :send_enumerator
|
1698
2849
|
test_cases ||= [
|
1699
|
-
#
|
1700
|
-
[
|
1701
|
-
# id:
|
1702
|
-
"test #{method_to_test} base :array_first_remainder",
|
1703
|
-
# expectation:
|
1704
|
-
[ [ :arg_to_send_1, [:arg_to_send_2, :arg_to_send_3]], nil, nil],
|
1705
|
-
# method_name + args:
|
1706
|
-
[
|
1707
|
-
# method_name:
|
1708
|
-
method_to_test,
|
1709
|
-
# args to method_to_test:
|
1710
|
-
[
|
1711
|
-
# array_first_remainder is a method of...
|
1712
|
-
self,
|
1713
|
-
# method to call
|
1714
|
-
:array_first_remainder,
|
1715
|
-
# args to array_first_remainder
|
1716
|
-
[ :arg_to_send_1, :arg_to_send_2, :arg_to_send_3 ],
|
1717
|
-
# block to array_first_remainder
|
1718
|
-
nil,
|
1719
|
-
# args_to_bled:
|
1720
|
-
[nil, :dont_rescue.negate_me, :debug_block.negate_me],
|
1721
|
-
# nil method takes Array (and not splat)
|
1722
|
-
:is_array_method,
|
1723
|
-
# destination:
|
1724
|
-
nil,
|
1725
|
-
# debug:
|
1726
|
-
0,
|
1727
|
-
],
|
1728
|
-
],
|
1729
|
-
],
|
1730
|
-
# test_case:
|
1731
|
-
[
|
1732
|
-
# id:
|
1733
|
-
"test #{method_to_test} base nil method ",
|
1734
|
-
# expectation:
|
1735
|
-
[[ :arg_to_send_1, :arg_to_send_2, :arg_to_send_3 ], nil, nil],
|
1736
|
-
# method_name + args:
|
1737
|
-
[
|
1738
|
-
# method_name:
|
1739
|
-
method_to_test,
|
1740
|
-
# args to method_to_test:
|
1741
|
-
[
|
1742
|
-
# object responding to method to call:
|
1743
|
-
self,
|
1744
|
-
# method to call: nil method (no method):
|
1745
|
-
:method_to_call.to_nil,
|
1746
|
-
# args to nil method:
|
1747
|
-
[ :arg_to_send_1, :arg_to_send_2, :arg_to_send_3 ],
|
1748
|
-
# block to nil method:
|
1749
|
-
nil,
|
1750
|
-
# args_to_bled:
|
1751
|
-
[nil, :no_rescue.negate_me, :debug_block.to_nil],
|
1752
|
-
# nil method takes splat (and not Array)
|
1753
|
-
:is_array_method.to_nil,
|
1754
|
-
# destination:
|
1755
|
-
nil,
|
1756
|
-
# debug:
|
1757
|
-
0,
|
1758
|
-
],
|
1759
|
-
],
|
1760
|
-
],
|
1761
|
-
# test_case:
|
1762
|
-
[
|
1763
|
-
# id:
|
1764
|
-
"test #{method_to_test} nil.inspect ",
|
1765
|
-
# expectation:
|
1766
|
-
["nil", nil, nil],
|
1767
|
-
# method_name + args:
|
1768
|
-
[
|
1769
|
-
# method_name:
|
1770
|
-
method_to_test,
|
1771
|
-
# args to method_to_test:
|
1772
|
-
[
|
1773
|
-
# object responding to method to call:
|
1774
|
-
nil,
|
1775
|
-
# method to call on nil
|
1776
|
-
:inspect,
|
1777
|
-
# args to inspect:
|
1778
|
-
nil,
|
1779
|
-
# block to inspect:
|
1780
|
-
nil,
|
1781
|
-
# args_to_bled:
|
1782
|
-
[nil, :no_rescue.negate_me, :debug_block.to_nil ],
|
1783
|
-
# inspect takes splat (and not Array)
|
1784
|
-
:is_array_method.to_nil,
|
1785
|
-
# destination:
|
1786
|
-
nil,
|
1787
|
-
# debug:
|
1788
|
-
0,
|
1789
|
-
],
|
1790
|
-
],
|
1791
|
-
],
|
1792
|
-
# test_case:
|
1793
|
-
[
|
1794
|
-
# id:
|
1795
|
-
"test #{method_to_test} array.map(&:to_s) ",
|
1796
|
-
# expectation:
|
1797
|
-
[["1", "2", "3"], nil, nil],
|
1798
|
-
# method_name + args:
|
1799
|
-
[
|
1800
|
-
# method_name:
|
1801
|
-
method_to_test,
|
1802
|
-
# args to method_to_test:
|
1803
|
-
[
|
1804
|
-
# object responding to method to call:
|
1805
|
-
[1, 2, 3],
|
1806
|
-
# method to call on [1, 2, 3]:
|
1807
|
-
:map,
|
1808
|
-
# args to :map
|
1809
|
-
[],
|
1810
|
-
# block to map:
|
1811
|
-
lambda {|x| x.to_s },
|
1812
|
-
# args_to_bled:
|
1813
|
-
[nil, :no_rescue.negate_me, :debug_block.to_nil ],
|
1814
|
-
# map takes splat (and not Array)
|
1815
|
-
:is_array_method.to_nil,
|
1816
|
-
# destination:
|
1817
|
-
nil,
|
1818
|
-
# debug:
|
1819
|
-
0,
|
1820
|
-
],
|
1821
|
-
],
|
1822
|
-
],
|
1823
|
-
# test_case:
|
1824
|
-
[
|
1825
|
-
# id:
|
1826
|
-
"test #{method_to_test} array_unflatten_base",
|
1827
|
-
# expectation:
|
1828
|
-
[[ :a, [ :b ], :c], nil, nil],
|
1829
|
-
# method_name + args:
|
1830
|
-
[
|
1831
|
-
# method_name:
|
1832
|
-
method_to_test,
|
1833
|
-
# args to method_to_test:
|
1834
|
-
[
|
1835
|
-
# object responding to method call:
|
1836
|
-
self,
|
1837
|
-
# method to call on self
|
1838
|
-
:array_unflatten_base, [
|
1839
|
-
[:a, "[", :b, "]", :c],
|
1840
|
-
:shallow,
|
1841
|
-
:debug.negate_me,
|
1842
|
-
:reserved_tokens.to_nil,
|
1843
|
-
:inverse.negate_me,
|
1844
|
-
],
|
1845
|
-
# block to array_unflatten_base
|
1846
|
-
nil,
|
1847
|
-
# args_to_bled:
|
1848
|
-
[nil, :dont_rescue.negate_me, :debug_block.to_nil],
|
1849
|
-
# array_unflatten_base takes array (and not splat)
|
1850
|
-
:is_array_method,
|
1851
|
-
# destination:
|
1852
|
-
nil,
|
1853
|
-
# debug:
|
1854
|
-
0,
|
1855
|
-
],
|
1856
|
-
],
|
1857
|
-
],
|
1858
|
-
# test_case end
|
1859
|
-
|
1860
|
-
]
|
1861
|
-
end
|
1862
|
-
|
1863
|
-
|
1864
|
-
=begin
|
1865
|
-
test for #experiment__send_array_base
|
1866
|
-
=end
|
1867
|
-
def test__experiment__send_array_base args=[]
|
1868
|
-
=begin
|
1869
|
-
method_to_test,
|
1870
|
-
reserved = args
|
1871
|
-
method_to_test = method_to_test.nne :experiment__send_array_base
|
1872
|
-
e1 = [ [ :arg_to_send_1, [:arg_to_send_2, :arg_to_send_3]], nil, nil]
|
1873
|
-
a1 = send method_to_test, [
|
1874
|
-
[
|
1875
|
-
:array_first_remainder,
|
1876
|
-
[ :arg_to_send_1, :arg_to_send_2, :arg_to_send_3 ],
|
1877
|
-
],
|
1878
|
-
self,
|
2850
|
+
# [ :id, :expectation, :actual_params ],
|
2851
|
+
# actual_params can be an array with method_name + [args] to that method.
|
1879
2852
|
]
|
1880
|
-
|
1881
|
-
judgement =
|
1882
|
-
[
|
1883
|
-
[e1, a1, "test #{method_to_test} base :array_first_remainder"],
|
1884
|
-
].map(&method("expect_equal")).all?
|
1885
|
-
=end
|
1886
|
-
stderr = @memory[:stderr]
|
1887
|
-
debug = debug.nne
|
1888
|
-
debug && (stderr.puts "{#{__method__} starting")
|
1889
|
-
debug && (stderr.puts "caller=#{caller_label}")
|
1890
|
-
debug && (stderr.puts "args=#{args.inspect}")
|
1891
|
-
test_cases = (test_cases__experiment__send_array_base args)
|
1892
|
-
debug && (stderr.puts "test_cases.size=#{test_cases.size}")
|
1893
|
-
experiment__tester_block = bled [
|
1894
|
-
nil,
|
1895
|
-
:no_rescue.negate_me,
|
1896
|
-
:output.negate_me,
|
1897
|
-
] {
|
1898
|
-
experiment__tester [
|
1899
|
-
(test_cases), 0
|
1900
|
-
]
|
1901
|
-
}
|
1902
|
-
debug && (stderr.puts "experiment__tester_block=#{experiment__tester_block.inspect}")
|
1903
|
-
rv = experiment__tester_block.first.call
|
1904
|
-
debug && (stderr.puts "will return #{rv.inspect}")
|
1905
|
-
debug && (stderr.puts "#{__method__} returning}")
|
1906
|
-
rv
|
1907
2853
|
end
|
1908
2854
|
|
1909
2855
|
|
1910
2856
|
end
|
1911
2857
|
|
1912
2858
|
|
1913
|
-
=begin
|
2859
|
+
=begin
|
1914
2860
|
# begin_documentation
|
1915
2861
|
This module receives functions that change other
|
1916
2862
|
Ruby classes, by adding or changing their classes.
|
@@ -1941,6 +2887,7 @@ end
|
|
1941
2887
|
- HTTP/HTTPS server ready-to-go
|
1942
2888
|
- gem package generation and submission.
|
1943
2889
|
- tree parsing.
|
2890
|
+
- graph visitor.
|
1944
2891
|
|
1945
2892
|
|
1946
2893
|
Rubyment functions must respect the open/closed principle
|
@@ -1969,7 +2916,8 @@ end
|
|
1969
2916
|
=end
|
1970
2917
|
module RubymentModule
|
1971
2918
|
|
1972
|
-
include
|
2919
|
+
Object.class_eval { include ModifierForClassObjectModule }
|
2920
|
+
include InternalRubymentModule
|
1973
2921
|
include RubymentExperimentModule
|
1974
2922
|
include RubymentMaintainedModule
|
1975
2923
|
include RubymentDeprecatedModule
|
@@ -2125,7 +3073,9 @@ module RubymentModule
|
|
2125
3073
|
# +headers+:: [Hash] +"Authorization"+ key will be added to it if +auth_user+ is given. Defaults to +{}+
|
2126
3074
|
# +method+:: [HTTP method] one of +:get+, +:method+, +:post+ or +:delete+. defaults to +:get+
|
2127
3075
|
# +timeout+:: [Fixnum, nil] defaults to +nil+
|
3076
|
+
# +debug+:: [Object] if calling the object +nne+ method returns a +false+ value, won't print debug information
|
2128
3077
|
# +request_method+:: [Method name] if given, won't call open-uri's or 'rest-client' , and will use this method instead. It has to have the same signature as #rest_request_or_open_uri_open. By default is +false+ to respect open-closed principle, but it is advised to be set to http_request_response__curl (which depends on 'curb') -- since, for some kind of responses, as redirects, a full featured http client is needed.
|
3078
|
+
# +output_exceptions+:: [bool] output exceptions, for the methods supporting it.
|
2129
3079
|
#
|
2130
3080
|
# @return [String, Object] read data (or +return_on_rescue+)
|
2131
3081
|
def file_read args=ARGV
|
@@ -2143,8 +3093,10 @@ module RubymentModule
|
|
2143
3093
|
timeout,
|
2144
3094
|
debug,
|
2145
3095
|
request_method,
|
3096
|
+
output_exceptions,
|
2146
3097
|
reserved = args
|
2147
|
-
debug = debug.nne
|
3098
|
+
debug = debug.nne
|
3099
|
+
output_request_method_exceptions = output_request_method_exceptions.nne
|
2148
3100
|
debug && (stderr.puts "{#{__method__} starting")
|
2149
3101
|
debug && (stderr.puts "args=#{args.inspect}")
|
2150
3102
|
request_method = request_method.nne :rest_request_or_open_uri_open
|
@@ -2166,6 +3118,7 @@ module RubymentModule
|
|
2166
3118
|
skip_open_uri,
|
2167
3119
|
:debug_request_method.to_nil,
|
2168
3120
|
:no_rescue_i_catch_exceptions,
|
3121
|
+
output_exceptions,
|
2169
3122
|
]).first
|
2170
3123
|
debug && (stderr.puts "url_response=#{url_response.inspect}")
|
2171
3124
|
url_response
|
@@ -2335,16 +3288,28 @@ module RubymentModule
|
|
2335
3288
|
# method_object (Method)
|
2336
3289
|
def to_object_method args=ARGV
|
2337
3290
|
stderr = @memory[:stderr]
|
2338
|
-
name,
|
2339
|
-
|
3291
|
+
name,
|
3292
|
+
object,
|
3293
|
+
debug,
|
3294
|
+
reserved = containerize args
|
3295
|
+
|
3296
|
+
debug = debug.nne
|
3297
|
+
debug && (stderr.puts "{#{__method__} starting")
|
3298
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
3299
|
+
debug && (stderr.puts "args=#{args.inspect}")
|
3300
|
+
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
3301
|
+
rv = begin
|
2340
3302
|
object.method("method").call(name.to_s)
|
2341
3303
|
rescue NameError => nameError
|
2342
3304
|
# every object (even nil) has :method,
|
2343
3305
|
# and every Method has :call: exception
|
2344
3306
|
# is thrown in call
|
2345
|
-
stderr.puts nameError
|
3307
|
+
debug && (stderr.puts nameError)
|
2346
3308
|
nil
|
2347
3309
|
end
|
3310
|
+
debug && (stderr.puts "will return #{rv.inspect}")
|
3311
|
+
debug && (stderr.puts "#{__method__} returning}")
|
3312
|
+
rv
|
2348
3313
|
end
|
2349
3314
|
|
2350
3315
|
# calls object.method call_args
|
@@ -2744,11 +3709,9 @@ module RubymentModule
|
|
2744
3709
|
reserved = args
|
2745
3710
|
|
2746
3711
|
debug = debug.nne
|
2747
|
-
debug = 1
|
2748
3712
|
debug && (stderr.puts "{#{__method__} starting")
|
2749
3713
|
debug && (stderr.puts "args=#{args.inspect}")
|
2750
3714
|
skip_open_uri = skip_open_uri.nne
|
2751
|
-
debug && (stderr.puts "skip_open_uri=#{skip_open_uri.inspect}")
|
2752
3715
|
|
2753
3716
|
response = runea ["yes, rescue".negate_me,
|
2754
3717
|
"already not rescuing, forget about output".to_nil,
|
@@ -3947,8 +4910,6 @@ require '#{gem_name}'
|
|
3947
4910
|
command="gem uninstall #{all} -x #{user_install} #{gem_spec}"
|
3948
4911
|
debug && (stderr.puts "command=#{command}")
|
3949
4912
|
`#{command}`
|
3950
|
-
#stdin, stdout, stderr, wait_thr = Open3.popen3(":;" + command)
|
3951
|
-
#stdout
|
3952
4913
|
end
|
3953
4914
|
|
3954
4915
|
# gem_list
|
@@ -4315,16 +5276,44 @@ require '#{gem_name}'
|
|
4315
5276
|
# in a polymorphic style.
|
4316
5277
|
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
4317
5278
|
# +method_name_or_method+:: [String, Method] method name or method object
|
5279
|
+
# +debug+::
|
5280
|
+
# +to_object_method_debug+:: debug to_object_method call
|
5281
|
+
# +output_exceptions+::
|
5282
|
+
# +no_rescue+::
|
5283
|
+
# +default_method+:: in the case no method can be derived from the args, this one is returned. Suggested Proc.new {|*args| } (not done for API respect)
|
4318
5284
|
#
|
4319
5285
|
# @return [Method] a method
|
4320
5286
|
def to_method args = ARGV
|
4321
|
-
method_name_or_method,
|
4322
|
-
|
4323
|
-
|
4324
|
-
|
4325
|
-
|
4326
|
-
|
4327
|
-
|
5287
|
+
method_name_or_method,
|
5288
|
+
object,
|
5289
|
+
debug,
|
5290
|
+
to_object_method_debug,
|
5291
|
+
output_exceptions,
|
5292
|
+
no_rescue,
|
5293
|
+
default_method,
|
5294
|
+
reserved = args
|
5295
|
+
|
5296
|
+
stderr = @memory[:stderr]
|
5297
|
+
debug && (stderr.puts "{#{__method__} starting")
|
5298
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
5299
|
+
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
5300
|
+
default_method = default_method.nne # ideally Proc.new {|*args| }, but we can't change the API
|
5301
|
+
to_method_block = bled [
|
5302
|
+
nil,
|
5303
|
+
no_rescue,
|
5304
|
+
output_exceptions,
|
5305
|
+
] {
|
5306
|
+
(
|
5307
|
+
to_object_method [object, method_name_or_method, to_object_method_debug ]
|
5308
|
+
) || (
|
5309
|
+
method_name_or_method.respond_to?(:call) && method_name_or_method
|
5310
|
+
) ||
|
5311
|
+
method(method_name_or_method) || default_method
|
5312
|
+
}
|
5313
|
+
rv = to_method_block.first.call
|
5314
|
+
debug && (stderr.puts "will return first of: #{rv.inspect}")
|
5315
|
+
debug && (stderr.puts "#{__method__} returning}")
|
5316
|
+
rv.first
|
4328
5317
|
end
|
4329
5318
|
|
4330
5319
|
|
@@ -4338,25 +5327,6 @@ require '#{gem_name}'
|
|
4338
5327
|
end
|
4339
5328
|
|
4340
5329
|
|
4341
|
-
# calls a function with the processing arg
|
4342
|
-
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
4343
|
-
# +processing_arg+:: [Object]
|
4344
|
-
# +method+:: [Method, String]
|
4345
|
-
# +method_args+:: [Array] args to be given to the +transform_method_name+
|
4346
|
-
# +on_object+:: [String, Boolean]
|
4347
|
-
#
|
4348
|
-
# @return [String] +processing_arg+
|
4349
|
-
def test__transform_call args = ARGV
|
4350
|
-
processing_arg, method, method_args, on_object = args
|
4351
|
-
object_arg = on_object.nne && processing_arg || nil
|
4352
|
-
p args
|
4353
|
-
to_method(
|
4354
|
-
[method, object_arg]).call(
|
4355
|
-
[processing_arg] + method_args
|
4356
|
-
)
|
4357
|
-
end
|
4358
|
-
|
4359
|
-
|
4360
5330
|
# returns an HTTP response
|
4361
5331
|
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
4362
5332
|
# +response+:: [String, nil] response payload
|
@@ -4547,7 +5517,7 @@ require '#{gem_name}'
|
|
4547
5517
|
lazy.map {|i|
|
4548
5518
|
r = lines.push(io.gets).last
|
4549
5519
|
debug.nne && (stderr.puts r)
|
4550
|
-
|
5520
|
+
r.index(happy_with_request.to_s).to_i.nne && r
|
4551
5521
|
}.find {|x| !x }
|
4552
5522
|
debug.nne && (stderr.puts lines.inspect)
|
4553
5523
|
debug.nne && (stderr.puts "#{__method__} returning")
|
@@ -4564,6 +5534,11 @@ require '#{gem_name}'
|
|
4564
5534
|
# +transform_method_name+:: [String]
|
4565
5535
|
# +transform_method_args+:: [Array] args to be given to the ++transform_method_name+
|
4566
5536
|
# +happy_with_request+:: [String, nil] if nil, +eol+ is used.
|
5537
|
+
# +io_forward_debug+:: [boolean] will forward this argument to io_forward
|
5538
|
+
# +transform_call_debug+:: [boolean] will forward this argument to transform_call
|
5539
|
+
# +to_method_debug+:: [boolean] will forward this argument to to_method
|
5540
|
+
# +to_object_method_debug+:: [boolean] will forward this argument to to_object_method
|
5541
|
+
# +output_exceptions+:: [boolean]
|
4567
5542
|
#
|
4568
5543
|
# @return [nil]
|
4569
5544
|
def io_transform args = ARGV
|
@@ -4572,19 +5547,30 @@ require '#{gem_name}'
|
|
4572
5547
|
happy_with_request,
|
4573
5548
|
transform_method_name,
|
4574
5549
|
transform_method_args,
|
5550
|
+
io_forward_debug,
|
5551
|
+
transform_call_debug,
|
5552
|
+
to_method_debug,
|
5553
|
+
to_object_method_debug,
|
5554
|
+
output_exceptions,
|
4575
5555
|
reserved = args
|
4576
5556
|
stderr = @memory[:stderr]
|
4577
|
-
debug.nne && (stderr.puts "#{__method__} starting")
|
5557
|
+
debug.nne && (stderr.puts "#{__method__} starting{")
|
5558
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
5559
|
+
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
4578
5560
|
debug.nne && (stderr.puts "transform_method_name: #{transform_method_name}")
|
4579
5561
|
debug.nne && (stderr.puts "transform_method_args: #{transform_method_args.inspect}")
|
4580
|
-
io_forward [[io], io,
|
4581
|
-
:
|
5562
|
+
io_forward [[io], io, io_forward_debug, happy_with_request, reserved,
|
5563
|
+
:transform_call, [
|
4582
5564
|
transform_method_name,
|
4583
|
-
|
4584
|
-
|
4585
|
-
|
5565
|
+
transform_method_args,
|
5566
|
+
"on_object:true",
|
5567
|
+
transform_call_debug,
|
5568
|
+
output_exceptions,
|
5569
|
+
],
|
5570
|
+
to_method_debug,
|
5571
|
+
to_object_method_debug,
|
4586
5572
|
]
|
4587
|
-
debug.nne && (stderr.puts "#{__method__} returning")
|
5573
|
+
debug.nne && (stderr.puts "#{__method__} returning}")
|
4588
5574
|
nil
|
4589
5575
|
end
|
4590
5576
|
|
@@ -4595,6 +5581,9 @@ require '#{gem_name}'
|
|
4595
5581
|
# +io_in+:: [IO] any +IO+, like a +Socket+, returned by #TCPServer::accept, where data will be read from.
|
4596
5582
|
# +debug+:: [Object] if evals to false (or empty string), won't print debug information
|
4597
5583
|
# +happy_with_request+:: [String, nil] if nil, +eol+ is used.
|
5584
|
+
# +to_method_debug+:: [boolean] will forward this argument to to_method
|
5585
|
+
# +to_object_method_debug+:: [boolean] will forward this argument to to_object_method
|
5586
|
+
# +output_exceptions+:: [boolean]
|
4598
5587
|
#
|
4599
5588
|
# @return [nil]
|
4600
5589
|
def io_forward args = ARGV
|
@@ -4605,25 +5594,40 @@ require '#{gem_name}'
|
|
4605
5594
|
happy_with_request,
|
4606
5595
|
reserved,
|
4607
5596
|
processing_method,
|
4608
|
-
processing_method_args
|
4609
|
-
|
5597
|
+
processing_method_args,
|
5598
|
+
to_method_debug,
|
5599
|
+
to_object_method_debug,
|
5600
|
+
output_exceptions,
|
5601
|
+
reserved = args
|
4610
5602
|
stderr = @memory[:stderr]
|
4611
|
-
debug.nne && (stderr.puts "#{__method__} starting")
|
5603
|
+
debug.nne && (stderr.puts "{#{__method__} starting")
|
5604
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
4612
5605
|
debug.nne && (stderr.puts args.inspect)
|
5606
|
+
io_gets_args = [io_in, debug, happy_with_request]
|
4613
5607
|
input = io_gets io_gets_args
|
4614
5608
|
debug.nne && (stderr.puts input.inspect)
|
4615
5609
|
debug.nne && (stderr.puts ios_out.class.inspect)
|
4616
5610
|
processing_method ||= :echo
|
5611
|
+
debug && (stderr.puts "processing_method=#{processing_method}")
|
4617
5612
|
processing_method_args ||= []
|
4618
5613
|
processed_input = to_method(
|
4619
|
-
[
|
5614
|
+
[
|
5615
|
+
processing_method,
|
5616
|
+
:object.to_nil,
|
5617
|
+
to_method_debug,
|
5618
|
+
to_object_method_debug,
|
5619
|
+
]
|
5620
|
+
).call(
|
4620
5621
|
[input] + processing_method_args
|
4621
5622
|
)
|
4622
|
-
ios_out.map{ |shared_io_out|
|
5623
|
+
threads = ios_out.map{ |shared_io_out|
|
4623
5624
|
runoe_threaded(shared_io_out) {|io_out|
|
4624
|
-
|
5625
|
+
io_out = shared_io_out
|
4625
5626
|
io_out.print processed_input
|
4626
|
-
debug
|
5627
|
+
debug && (
|
5628
|
+
stderr.puts "#{io_out}: processed_input.class=#{processed_input.class}"
|
5629
|
+
)
|
5630
|
+
debug && processed_input && (
|
4627
5631
|
stderr.puts "#{io_out}: #{processed_input.size} bytes: response writen."
|
4628
5632
|
)
|
4629
5633
|
io_out.close
|
@@ -4633,7 +5637,12 @@ require '#{gem_name}'
|
|
4633
5637
|
|
4634
5638
|
}
|
4635
5639
|
}
|
4636
|
-
|
5640
|
+
threads.map { |thread|
|
5641
|
+
runoe_threaded() {
|
5642
|
+
thread.join
|
5643
|
+
}
|
5644
|
+
}
|
5645
|
+
debug.nne && (stderr.puts "#{__method__} returning}")
|
4637
5646
|
nil
|
4638
5647
|
end
|
4639
5648
|
|
@@ -4760,16 +5769,17 @@ require '#{gem_name}'
|
|
4760
5769
|
output_exception = (
|
4761
5770
|
output_exception.nne || admit_plain.negate_me
|
4762
5771
|
)
|
4763
|
-
debug && (stderr.puts "#{__method__} starting")
|
5772
|
+
debug && (stderr.puts "#{__method__} starting{")
|
5773
|
+
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
4764
5774
|
# openssl functions want contents, not filenames:
|
4765
5775
|
extra_cert_pem_files = extra_cert_pem_files
|
4766
5776
|
.map! { |extra_cert_pem_file|
|
4767
5777
|
file_read [
|
4768
|
-
|
4769
|
-
|
4770
|
-
|
4771
|
-
|
4772
|
-
|
5778
|
+
extra_cert_pem_file,
|
5779
|
+
nil,
|
5780
|
+
nil,
|
5781
|
+
extra_cert_pem_file
|
5782
|
+
]
|
4773
5783
|
}
|
4774
5784
|
cert_pem_file = file_read [cert_pem_file, nil, nil, cert_pem_file]
|
4775
5785
|
priv_pemfile = file_read [priv_pemfile, nil, nil, priv_pemfile]
|
@@ -4780,8 +5790,8 @@ require '#{gem_name}'
|
|
4780
5790
|
servers = plain_servers.map { |plain_server|
|
4781
5791
|
ssl_server = runea [
|
4782
5792
|
admit_plain,
|
4783
|
-
|
4784
|
-
|
5793
|
+
output_exception,
|
5794
|
+
"nil on exception"] {
|
4785
5795
|
require 'openssl'
|
4786
5796
|
ssl_context = OpenSSL::SSL::SSLContext.new
|
4787
5797
|
ssl_context.extra_chain_cert =
|
@@ -4798,7 +5808,7 @@ require '#{gem_name}'
|
|
4798
5808
|
server = ssl_server || admit_plain && plain_server
|
4799
5809
|
}
|
4800
5810
|
debug && (stderr.puts "will return #{[servers]}")
|
4801
|
-
debug && (stderr.puts "#{__method__} returning")
|
5811
|
+
debug && (stderr.puts "#{__method__} returning}")
|
4802
5812
|
[servers]
|
4803
5813
|
end
|
4804
5814
|
|
@@ -4833,77 +5843,20 @@ require '#{gem_name}'
|
|
4833
5843
|
reserved = args
|
4834
5844
|
debug = debug.nne
|
4835
5845
|
debug && (stderr.puts "#{__method__} starting")
|
4836
|
-
rv = (ssl_make_servers [
|
4837
|
-
listening_port,
|
4838
|
-
ip_addr,
|
4839
|
-
debug,
|
4840
|
-
admit_plain,
|
4841
|
-
priv_pemfile,
|
4842
|
-
cert_pem_file,
|
4843
|
-
extra_cert_pem_files,
|
4844
|
-
output_exception,
|
4845
|
-
plain_server,
|
4846
|
-
]).first.first
|
4847
|
-
debug && (stderr.puts "will return #{rv}")
|
4848
|
-
debug && (stderr.puts "#{__method__} returning")
|
4849
|
-
rv
|
4850
|
-
end
|
4851
|
-
|
4852
|
-
|
4853
|
-
# opens one or more TCP and/or SSL server accepting connections.
|
4854
|
-
# @param [Array] +args+, an +Array+ whose elements are expected to be:
|
4855
|
-
# +listening_port+:: [String, Integer] port to listen
|
4856
|
-
# +ip_addr+:: [String, nil] ip (no hostname) to bind the server. 0, nil, false, empty string will bind to all addresses possible. 0.0.0.0 => binds to all ipv4 . ::0 to all ipv4 and ipv6
|
4857
|
-
# +admit_plain+:: [Boolean] if +true+, tries to create a normal +TCPServer+, if not possible to create +SSLServer+ (default: +false+, for preventing unadvertnt non-SSL server creation)
|
4858
|
-
# +debug+:: [Object] for future use
|
4859
|
-
# +callback_method+:: [String, Method] method to call when a client connects. The method must accept a socket as parameter.
|
4860
|
-
# +callback_method_args+:: [Array] args to be given to the call_back_method. Note that the type differs from #tcp_server_plain (which takes splat)
|
4861
|
-
#
|
4862
|
-
# @return [Array] returns a , an +Array+ whose elements are:
|
4863
|
-
# +threads+:: [Array of Thread] returns an Array of Thread object looping for accepting incoming connections (call join on those object for waiting for its completion).
|
4864
|
-
def tcp_ssl_servers args = ARGV
|
4865
|
-
stderr = @memory[:stderr]
|
4866
|
-
listening_port,
|
4867
|
-
ip_addr,
|
4868
|
-
debug,
|
4869
|
-
admit_plain,
|
4870
|
-
callback_method,
|
4871
|
-
callback_method_args,
|
4872
|
-
priv_pemfile,
|
4873
|
-
cert_pem_file,
|
4874
|
-
extra_cert_pem_files,
|
4875
|
-
output_exception,
|
4876
|
-
reserved = args
|
4877
|
-
|
4878
|
-
server = (ssl_make_servers [
|
4879
|
-
listening_port,
|
4880
|
-
ip_addr,
|
4881
|
-
debug,
|
4882
|
-
admit_plain,
|
4883
|
-
priv_pemfile,
|
4884
|
-
cert_pem_file,
|
4885
|
-
extra_cert_pem_files,
|
4886
|
-
output_exception,
|
4887
|
-
]).first.first
|
4888
|
-
debug.nne && (stderr.puts server)
|
4889
|
-
Thread.start {
|
4890
|
-
loop {
|
4891
|
-
client = runea ["yes, rescue",
|
4892
|
-
"yes, output exception",
|
4893
|
-
"nil on exception"
|
4894
|
-
] {
|
4895
|
-
server.accept
|
4896
|
-
}
|
4897
|
-
Thread.start(client) { |client|
|
4898
|
-
debug.nne && (stderr.puts Thread.current)
|
4899
|
-
debug.nne && (stderr.puts client)
|
4900
|
-
runoe {
|
4901
|
-
to_method([callback_method])
|
4902
|
-
.call([client] + callback_method_args)
|
4903
|
-
}
|
4904
|
-
}
|
4905
|
-
}
|
4906
|
-
}
|
5846
|
+
rv = (ssl_make_servers [
|
5847
|
+
listening_port,
|
5848
|
+
ip_addr,
|
5849
|
+
debug,
|
5850
|
+
admit_plain,
|
5851
|
+
priv_pemfile,
|
5852
|
+
cert_pem_file,
|
5853
|
+
extra_cert_pem_files,
|
5854
|
+
output_exception,
|
5855
|
+
plain_server,
|
5856
|
+
]).first.first
|
5857
|
+
debug && (stderr.puts "will return #{rv}")
|
5858
|
+
debug && (stderr.puts "#{__method__} returning")
|
5859
|
+
rv
|
4907
5860
|
end
|
4908
5861
|
|
4909
5862
|
|
@@ -4931,8 +5884,13 @@ require '#{gem_name}'
|
|
4931
5884
|
cert_pem_file,
|
4932
5885
|
extra_cert_pem_files,
|
4933
5886
|
output_exception,
|
5887
|
+
debug_client,
|
4934
5888
|
reserved = args
|
4935
5889
|
|
5890
|
+
debug = debug.nne
|
5891
|
+
debug && (stderr.puts "{#{__method__} starting")
|
5892
|
+
debug && (stderr.puts "caller=#{caller_label}")
|
5893
|
+
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
4936
5894
|
server = (ssl_make_servers [
|
4937
5895
|
listening_port,
|
4938
5896
|
ip_addr,
|
@@ -4943,25 +5901,38 @@ require '#{gem_name}'
|
|
4943
5901
|
extra_cert_pem_files,
|
4944
5902
|
output_exception,
|
4945
5903
|
]).first.first
|
4946
|
-
|
4947
|
-
|
5904
|
+
debug_client = debug_client.nne || debug
|
5905
|
+
debug && (stderr.puts "server=#{server}")
|
5906
|
+
rv = Thread.start {
|
4948
5907
|
loop {
|
4949
|
-
client = runea [
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
5908
|
+
client = runea [
|
5909
|
+
"yes, rescue",
|
5910
|
+
"yes, output exception",
|
5911
|
+
"nil on exception"
|
5912
|
+
] {
|
5913
|
+
server.accept
|
5914
|
+
}
|
4955
5915
|
Thread.start(client) { |client|
|
4956
|
-
|
4957
|
-
|
4958
|
-
|
5916
|
+
debug_client && (stderr.puts "{client #{client} starting")
|
5917
|
+
debug_client && (stderr.puts Thread.current)
|
5918
|
+
block = bled [
|
5919
|
+
nil,
|
5920
|
+
:no_rescue.negate_me,
|
5921
|
+
output_exception,
|
5922
|
+
] {
|
4959
5923
|
to_method([callback_method])
|
4960
5924
|
.call([client] + callback_method_args)
|
4961
5925
|
}
|
5926
|
+
rv = block.first.call
|
5927
|
+
debug_client && (stderr.puts "client will return #{rv}")
|
5928
|
+
debug_client && (stderr.puts "client #{client} finishing}")
|
5929
|
+
rv
|
4962
5930
|
}
|
4963
5931
|
}
|
4964
5932
|
}
|
5933
|
+
debug && (stderr.puts "will return #{rv.inspect}")
|
5934
|
+
debug && (stderr.puts "#{__method__} returning}")
|
5935
|
+
rv
|
4965
5936
|
end
|
4966
5937
|
|
4967
5938
|
|
@@ -5362,7 +6333,8 @@ n8mFEtUKobsK
|
|
5362
6333
|
:name => :http_processing_method_args,
|
5363
6334
|
:duck_type => Array,
|
5364
6335
|
:default_behavior => [],
|
5365
|
-
:description => "arguments for the method that returns an http request string (used by the first server)
|
6336
|
+
:description => "arguments for the method that returns an http request string (used by the first server). http_processing_method is fully controlled throught these arguments -- internally, io_forward will only prepend an argument having the request this list.
|
6337
|
+
",
|
5366
6338
|
},
|
5367
6339
|
{
|
5368
6340
|
:name => :http_server_port,
|
@@ -5455,6 +6427,42 @@ n8mFEtUKobsK
|
|
5455
6427
|
:default_behavior => "0",
|
5456
6428
|
:description => "ip address (used by the redirect server)",
|
5457
6429
|
},
|
6430
|
+
{
|
6431
|
+
:name => :output_exceptions,
|
6432
|
+
:duck_type => :boolean,
|
6433
|
+
:default_behavior => :nil,
|
6434
|
+
:description => "exceptions are normally properly handled by inner functions, but setting this to true can be helpful to debug some cases",
|
6435
|
+
},
|
6436
|
+
{
|
6437
|
+
:name => :io_forward_debug,
|
6438
|
+
:duck_type => :boolean,
|
6439
|
+
:default_behavior => :nil,
|
6440
|
+
:description => "will be forwarded as debug argument to io_forward, somehow",
|
6441
|
+
},
|
6442
|
+
{
|
6443
|
+
:name => :transform_call_debug,
|
6444
|
+
:duck_type => :boolean,
|
6445
|
+
:default_behavior => :nil,
|
6446
|
+
:description => "will be forwarded as debug argument to transform_call, somehow",
|
6447
|
+
},
|
6448
|
+
{
|
6449
|
+
:name => :to_method_debug,
|
6450
|
+
:duck_type => :boolean,
|
6451
|
+
:default_behavior => :nil,
|
6452
|
+
:description => "will be forwarded as debug argument to to_method, somehow",
|
6453
|
+
},
|
6454
|
+
{
|
6455
|
+
:name => :to_object_method_debug,
|
6456
|
+
:duck_type => :boolean,
|
6457
|
+
:default_behavior => :nil,
|
6458
|
+
:description => "will be forwarded as debug argument to to_method_method, somehow",
|
6459
|
+
},
|
6460
|
+
{
|
6461
|
+
:name => :debug_accept,
|
6462
|
+
:duck_type => :boolean,
|
6463
|
+
:default_behavior => :nil,
|
6464
|
+
:description => "will be forwarded as __debug_client__ argument to tcp_ssl_server, somehow",
|
6465
|
+
},
|
5458
6466
|
{
|
5459
6467
|
:name => :reserved,
|
5460
6468
|
:duck_type => Object,
|
@@ -5486,11 +6494,20 @@ n8mFEtUKobsK
|
|
5486
6494
|
plain_http_processing_method_args,
|
5487
6495
|
plain_http_server_port,
|
5488
6496
|
plain_http_ip_addr,
|
6497
|
+
output_exceptions,
|
6498
|
+
io_forward_debug,
|
6499
|
+
transform_call_debug,
|
6500
|
+
to_method_debug,
|
6501
|
+
to_object_method_debug,
|
6502
|
+
debug_accept,
|
5489
6503
|
reserved = args
|
5490
6504
|
|
5491
6505
|
debug = debug.nne
|
6506
|
+
output_exceptions = output_exceptions.nne
|
5492
6507
|
debug.nne && (stderr.puts "{#{__method__} starting")
|
5493
6508
|
debug && (stderr.puts "args=#{args.inspect}")
|
6509
|
+
# http_OK_response is completely controlled by here -- io_forward
|
6510
|
+
# will only prepend an argument having the request to it.
|
5494
6511
|
http_processing_method = http_processing_method.nne :http_OK_response
|
5495
6512
|
http_processing_method_args = http_processing_method_args.nne []
|
5496
6513
|
http_server_port = http_server_port.nne 8003
|
@@ -5502,9 +6519,8 @@ n8mFEtUKobsK
|
|
5502
6519
|
priv_pemfile = priv_pemfile.nne ssl_cert_pkey_chain[1]
|
5503
6520
|
cert_pem_file = cert_pem_file.nne ssl_cert_pkey_chain[0]
|
5504
6521
|
extra_cert_pemiles = extra_cert_pem_files.nne ssl_cert_pkey_chain[2]
|
5505
|
-
debug = debug.nne "yes, debug"
|
5506
6522
|
io_method = io_method.nne "io_transform"
|
5507
|
-
io_method_debug =
|
6523
|
+
io_method_debug = io_method_debug.nne
|
5508
6524
|
happy_with_request = happy_with_request.nne
|
5509
6525
|
admit_non_ssl = admit_non_ssl.nne
|
5510
6526
|
plain_http_processing_method = plain_http_processing_method.nne :test__http_response__redirect
|
@@ -5524,12 +6540,18 @@ n8mFEtUKobsK
|
|
5524
6540
|
io_method_debug,
|
5525
6541
|
happy_with_request,
|
5526
6542
|
http_processing_method,
|
5527
|
-
http_processing_method_args
|
6543
|
+
http_processing_method_args,
|
6544
|
+
io_forward_debug,
|
6545
|
+
transform_call_debug,
|
6546
|
+
to_method_debug,
|
6547
|
+
to_object_method_debug,
|
6548
|
+
output_exceptions,
|
5528
6549
|
],
|
5529
6550
|
priv_pemfile,
|
5530
6551
|
cert_pem_file,
|
5531
6552
|
extra_cert_pem_files,
|
5532
|
-
|
6553
|
+
output_exceptions,
|
6554
|
+
debug_accept,
|
5533
6555
|
]
|
5534
6556
|
tcp_ssl_server_thread = send :tcp_ssl_server, tcp_ssl_server_args
|
5535
6557
|
tcp_plain_server_args = [
|
@@ -5543,11 +6565,15 @@ n8mFEtUKobsK
|
|
5543
6565
|
happy_with_request,
|
5544
6566
|
plain_http_processing_method,
|
5545
6567
|
plain_http_processing_method_args,
|
6568
|
+
io_forward_debug,
|
6569
|
+
transform_call_debug,
|
6570
|
+
to_method_debug,
|
6571
|
+
to_object_method_debug,
|
5546
6572
|
],
|
5547
6573
|
:priv_pemfile.to_nil,
|
5548
6574
|
:cert_pem_file.to_nil,
|
5549
6575
|
:extra_cert_pem_files.to_nil,
|
5550
|
-
|
6576
|
+
output_exceptions,
|
5551
6577
|
]
|
5552
6578
|
tcp_plain_server_thread = send :tcp_ssl_server, tcp_plain_server_args
|
5553
6579
|
|
@@ -5674,73 +6700,6 @@ n8mFEtUKobsK
|
|
5674
6700
|
end
|
5675
6701
|
|
5676
6702
|
|
5677
|
-
=begin
|
5678
|
-
tests #experiment__web_http_https_server, creating two
|
5679
|
-
servers, one ssl and another plain, redirecting to
|
5680
|
-
the ssl one. then, opens a client thread with a client
|
5681
|
-
connecting to the root document of the plain server
|
5682
|
-
(and in the end being served by the root document of
|
5683
|
-
the ssl server).
|
5684
|
-
=end
|
5685
|
-
def test__experiment__web_http_https_server args = ARGV
|
5686
|
-
stderr = @memory[:stderr]
|
5687
|
-
tcp_ssl_server_method,
|
5688
|
-
http_processing_method,
|
5689
|
-
http_processing_method_args,
|
5690
|
-
http_server_port,
|
5691
|
-
http_ip_addr,
|
5692
|
-
priv_pemfile,
|
5693
|
-
cert_pem_file,
|
5694
|
-
extra_cert_pem_files,
|
5695
|
-
ssl_cert_pkey_chain_method,
|
5696
|
-
debug_tcp_ssl_server_method,
|
5697
|
-
happy_with_request,
|
5698
|
-
io_method,
|
5699
|
-
io_method_debug,
|
5700
|
-
domain,
|
5701
|
-
admit_non_ssl,
|
5702
|
-
no_debug_client,
|
5703
|
-
reserved = args
|
5704
|
-
tcp_ssl_server_method = tcp_ssl_server_method.nne :experiment__web_http_https_server
|
5705
|
-
domain = domain.nne "localhost"
|
5706
|
-
http_server_port = http_server_port.nne 8003
|
5707
|
-
no_debug_client = no_debug_client.nne
|
5708
|
-
servers = send tcp_ssl_server_method,
|
5709
|
-
[
|
5710
|
-
http_processing_method,
|
5711
|
-
http_processing_method_args,
|
5712
|
-
http_server_port,
|
5713
|
-
http_ip_addr,
|
5714
|
-
priv_pemfile,
|
5715
|
-
cert_pem_file,
|
5716
|
-
extra_cert_pem_files,
|
5717
|
-
ssl_cert_pkey_chain_method,
|
5718
|
-
debug_tcp_ssl_server_method,
|
5719
|
-
happy_with_request,
|
5720
|
-
io_method,
|
5721
|
-
io_method_debug,
|
5722
|
-
admit_non_ssl,
|
5723
|
-
]
|
5724
|
-
|
5725
|
-
# TODO: not hardcoded this way
|
5726
|
-
plain_http_server_port = 8004
|
5727
|
-
thread_client = Thread.new {
|
5728
|
-
loop {
|
5729
|
-
response = test__file_read__uri_root [
|
5730
|
-
domain,
|
5731
|
-
plain_http_server_port,
|
5732
|
-
admit_non_ssl,
|
5733
|
-
:no_debug_client,
|
5734
|
-
]
|
5735
|
-
sleep 2
|
5736
|
-
}
|
5737
|
-
}
|
5738
|
-
servers.first.join
|
5739
|
-
|
5740
|
-
true
|
5741
|
-
end
|
5742
|
-
|
5743
|
-
|
5744
6703
|
# tests test__tcp_ssl_server__io_method and opens
|
5745
6704
|
# another thread for the client
|
5746
6705
|
def test__tcp_ssl_server__get_root args = ARGV
|
@@ -5800,29 +6759,6 @@ n8mFEtUKobsK
|
|
5800
6759
|
end
|
5801
6760
|
|
5802
6761
|
|
5803
|
-
# experimental stuff coming. usage example:
|
5804
|
-
# ./rubyment.rb invoke_double p test__shell_send_array__main "tinga" "" sub in EN
|
5805
|
-
# ["tENga"]
|
5806
|
-
# will be deprecated by send_array_base
|
5807
|
-
# ./rubyment.rb invoke_double p experiment__send_array_base 300 "bytes"
|
5808
|
-
# [[51, 48, 48], nil, nil]
|
5809
|
-
# only works with strings by now
|
5810
|
-
def test__shell_send_array__main args=[]
|
5811
|
-
p args
|
5812
|
-
object_to_send,
|
5813
|
-
reserved,
|
5814
|
-
method_to_send,
|
5815
|
-
*args_to_send = args
|
5816
|
-
object_to_send = object_to_send.nne
|
5817
|
-
method_to_send = method_to_send.nne :main
|
5818
|
-
object_to_send && (
|
5819
|
-
object_to_send.send method_to_send, *args_to_send
|
5820
|
-
) || (!object_to_send) && (
|
5821
|
-
send method_to_send, args_to_send
|
5822
|
-
)
|
5823
|
-
end
|
5824
|
-
|
5825
|
-
|
5826
6762
|
# test for Object::nne
|
5827
6763
|
def test__object_nne args = ARGV
|
5828
6764
|
string_neutral = ""
|
@@ -6278,9 +7214,9 @@ n8mFEtUKobsK
|
|
6278
7214
|
],
|
6279
7215
|
],
|
6280
7216
|
|
6281
|
-
# test__array_unflatten_base_shallow
|
6282
7217
|
|
6283
7218
|
]
|
7219
|
+
# test__array_unflatten_base_shallow is finishing:
|
6284
7220
|
experiment__tester [ test_cases ]
|
6285
7221
|
end
|
6286
7222
|
|
@@ -6460,9 +7396,9 @@ n8mFEtUKobsK
|
|
6460
7396
|
]
|
6461
7397
|
],
|
6462
7398
|
],
|
6463
|
-
# test__array_unflatten_base
|
6464
7399
|
|
6465
7400
|
]
|
7401
|
+
# test__array_unflatten_base is finishing
|
6466
7402
|
experiment__tester [ test_cases ]
|
6467
7403
|
end
|
6468
7404
|
|
@@ -6598,166 +7534,7 @@ n8mFEtUKobsK
|
|
6598
7534
|
end
|
6599
7535
|
|
6600
7536
|
|
6601
|
-
module RubymentDevelopmentModule
|
6602
|
-
|
6603
|
-
|
6604
|
-
=begin
|
6605
|
-
trying to get the interface compatible with
|
6606
|
-
# rest_request_or_open_uri_open
|
6607
|
-
# ideally, i would need an equivalent for
|
6608
|
-
# rest_response__request_base
|
6609
|
-
|
6610
|
-
=end
|
6611
|
-
def http_request_response__curl args=[]
|
6612
|
-
stderr = @memory[:stderr]
|
6613
|
-
url,
|
6614
|
-
payload,
|
6615
|
-
verify_ssl,
|
6616
|
-
unimplemented__headers,
|
6617
|
-
method,
|
6618
|
-
auth_user,
|
6619
|
-
password,
|
6620
|
-
unimplemented__timeout,
|
6621
|
-
unused__skip_open_uri,
|
6622
|
-
debug,
|
6623
|
-
no_rescuing,
|
6624
|
-
reserved = args
|
6625
|
-
|
6626
|
-
debug = debug.nne
|
6627
|
-
debug && (stderr.puts "{#{__method__} starting")
|
6628
|
-
debug && (stderr.puts "caller=#{caller_label}")
|
6629
|
-
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
6630
|
-
no_rescuing = no_rescuing.nne
|
6631
|
-
method = method.nne "get"
|
6632
|
-
verify_ssl = verify_ssl.nne
|
6633
|
-
curl_method = "http_#{method.downcase}"
|
6634
|
-
curl_post_data = payload.nne
|
6635
|
-
curl_args = [url, curl_post_data].compact
|
6636
|
-
block = bled [
|
6637
|
-
:no_answer.to_nil,
|
6638
|
-
no_rescuing,
|
6639
|
-
no_rescuing,
|
6640
|
-
] {
|
6641
|
-
require 'curb'
|
6642
|
-
c = Curl::Easy.send curl_method, *curl_args
|
6643
|
-
c.http_auth_types = :basic
|
6644
|
-
c.username = auth_user
|
6645
|
-
c.password = password
|
6646
|
-
# follow_location?
|
6647
|
-
c.ssl_verify_host = verify_ssl
|
6648
|
-
c.ssl_verify_peer = verify_ssl
|
6649
|
-
c.perform
|
6650
|
-
[ c.body_str, nil, c.http_connect_code]
|
6651
|
-
}
|
6652
|
-
rv = block.first.call
|
6653
|
-
# rv = block_rv.first
|
6654
|
-
|
6655
|
-
debug && (stderr.puts "#{__method__} will return #{rv.inspect}")
|
6656
|
-
debug && (stderr.puts "#{__method__} returning}")
|
6657
|
-
rv
|
6658
|
-
end
|
6659
|
-
|
6660
|
-
|
6661
|
-
def runtime_tmp_dir # for initialize
|
6662
|
-
end
|
6663
|
-
|
6664
|
-
|
6665
|
-
=begin
|
6666
|
-
returns args
|
6667
|
-
=end
|
6668
|
-
def experiment__resolve args=[]
|
6669
|
-
reference_or_value,
|
6670
|
-
resolver,
|
6671
|
-
debug,
|
6672
|
-
dont_resolve,
|
6673
|
-
reserved = args
|
6674
|
-
rv
|
6675
|
-
end
|
6676
|
-
|
6677
|
-
|
6678
|
-
|
6679
|
-
=begin
|
6680
|
-
# note: some functions may misbehave if they have different
|
6681
|
-
# behaviours depending if they get a block or not
|
6682
|
-
# to be tested.
|
6683
|
-
=end
|
6684
|
-
def experiment__send_array_base args=[]
|
6685
|
-
object_to_send,
|
6686
|
-
method_to_send,
|
6687
|
-
args_to_send,
|
6688
|
-
block_to_send,
|
6689
|
-
args_to_bled,
|
6690
|
-
is_array_method,
|
6691
|
-
reference,
|
6692
|
-
derref_args,
|
6693
|
-
debug,
|
6694
|
-
shallow,
|
6695
|
-
send_to_self,
|
6696
|
-
reserved = args
|
6697
|
-
|
6698
|
-
stderr = @memory[:stderr]
|
6699
|
-
debug = debug.nne
|
6700
|
-
debug && (stderr.puts "{#{__method__} starting")
|
6701
|
-
debug && (stderr.puts "args.each_with_index=#{args.each_with_index.entries.inspect}")
|
6702
|
-
|
6703
|
-
reference = reference.nne
|
6704
|
-
args_to_send = args_to_send.nne []
|
6705
|
-
is_array_method = is_array_method.nne
|
6706
|
-
args_to_send = is_array_method && [args_to_send] || args_to_send
|
6707
|
-
block_to_send = block_to_send.nne
|
6708
|
-
|
6709
|
-
args_to_bled = args_to_bled.nne []
|
6710
|
-
default_on_exception,
|
6711
|
-
dont_rescue,
|
6712
|
-
output_backtrace,
|
6713
|
-
unsed = args_to_bled
|
6714
|
-
|
6715
|
-
default_on_exception = default_on_exception.nne
|
6716
|
-
dont_rescue = dont_rescue.nne
|
6717
|
-
output_backtrace = output_backtrace.nne
|
6718
|
-
|
6719
|
-
debug && (stderr.puts "general case{: #{object_to_send.inspect}.#{method_to_send.inspect}(#{args_to_send.inspect})&#{block_to_send} }")
|
6720
|
-
|
6721
|
-
send_block = bled(args_to_bled) {
|
6722
|
-
(debug || output_backtrace) && (stderr.puts "{#{__method__} block starting")
|
6723
|
-
(debug || output_backtrace) && (stderr.puts "#{__method__} block: args.each_with_index=#{args.each_with_index.entries.inspect}")
|
6724
|
-
|
6725
|
-
brv = object_to_send.send method_to_send, *args_to_send, &block_to_send
|
6726
|
-
|
6727
|
-
(debug || output_backtrace) && (stderr.puts "#{__method__} block will return #{brv.inspect}")
|
6728
|
-
(debug || output_backtrace) && (stderr.puts "#{__method__} block returning}")
|
6729
|
-
brv
|
6730
|
-
}.first
|
6731
|
-
|
6732
|
-
default_block = bled(args_to_bled) {
|
6733
|
-
(debug || output_backtrace) && (stderr.puts "#{__method__} block: nil method makes return #{args_to_send.inspect}")
|
6734
|
-
args_to_send
|
6735
|
-
}.first
|
6736
|
-
|
6737
|
-
block_return, e_info, exception = experiment__whether [
|
6738
|
-
method_to_send,
|
6739
|
-
send_block,
|
6740
|
-
default_block,
|
6741
|
-
]
|
6742
|
-
|
6743
|
-
rv = [block_return, e_info, exception]
|
6744
|
-
|
6745
|
-
debug && (stderr.puts "will return #{rv.inspect}")
|
6746
|
-
debug && (stderr.puts "#{__method__} returning}")
|
6747
|
-
rv
|
6748
|
-
end
|
6749
|
-
|
6750
|
-
|
6751
|
-
end
|
6752
|
-
|
6753
|
-
|
6754
|
-
=begin
|
6755
|
-
the purpose of this class is just to be able
|
6756
|
-
to have all the functions of RubymentModule
|
6757
|
-
available in a single object.
|
6758
|
-
=end
|
6759
7537
|
class Rubyment
|
6760
|
-
include RubymentDevelopmentModule # must NOT be in master TODO
|
6761
7538
|
include RubymentModule
|
6762
7539
|
end
|
6763
7540
|
|