ruby_ex 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/AUTHORS +51 -0
  2. data/ChangeLog +1763 -0
  3. data/NEWS +3 -0
  4. data/README +1 -0
  5. data/Rakefile +8 -0
  6. data/SPEC.dyn.yml +10 -0
  7. data/SPEC.gem.yml +269 -0
  8. data/SPEC.yml +36 -0
  9. data/src/abstract.rb +253 -0
  10. data/src/abstract_node.rb +85 -0
  11. data/src/algorithms.rb +12 -0
  12. data/src/algorithms/simulated_annealing.rb +142 -0
  13. data/src/ask.rb +100 -0
  14. data/src/attributed_class.rb +303 -0
  15. data/src/cache.rb +350 -0
  16. data/src/checkout.rb +12 -0
  17. data/src/choose.rb +271 -0
  18. data/src/commands.rb +20 -0
  19. data/src/commands/command.rb +492 -0
  20. data/src/commands/datas.rb +16 -0
  21. data/src/commands/datas/composite.rb +31 -0
  22. data/src/commands/datas/data.rb +65 -0
  23. data/src/commands/datas/factory.rb +69 -0
  24. data/src/commands/datas/temp.rb +26 -0
  25. data/src/commands/factory.rb +67 -0
  26. data/src/commands/helpers.rb +81 -0
  27. data/src/commands/pipe.rb +66 -0
  28. data/src/commands/runners.rb +16 -0
  29. data/src/commands/runners/exec.rb +50 -0
  30. data/src/commands/runners/fork.rb +130 -0
  31. data/src/commands/runners/runner.rb +140 -0
  32. data/src/commands/runners/system.rb +57 -0
  33. data/src/commands/seq.rb +32 -0
  34. data/src/config_file.rb +95 -0
  35. data/src/const_regexp.rb +57 -0
  36. data/src/daemon.rb +135 -0
  37. data/src/diff.rb +665 -0
  38. data/src/dlogger.rb +62 -0
  39. data/src/drb/drb_observable.rb +95 -0
  40. data/src/drb/drb_observable_pool.rb +27 -0
  41. data/src/drb/drb_service.rb +44 -0
  42. data/src/drb/drb_undumped_attributes.rb +56 -0
  43. data/src/drb/drb_undumped_indexed_object.rb +55 -0
  44. data/src/drb/insecure_protected_methods.rb +101 -0
  45. data/src/drb_ex.rb +12 -0
  46. data/src/dumpable_proc.rb +57 -0
  47. data/src/filetype.rb +229 -0
  48. data/src/generate_id.rb +44 -0
  49. data/src/histogram.rb +222 -0
  50. data/src/hookable.rb +283 -0
  51. data/src/hooker.rb +54 -0
  52. data/src/indexed_node.rb +65 -0
  53. data/src/io_marshal.rb +99 -0
  54. data/src/ioo.rb +193 -0
  55. data/src/labeled_node.rb +62 -0
  56. data/src/logger_observer.rb +24 -0
  57. data/src/md5sum.rb +70 -0
  58. data/src/module/autoload_tree.rb +65 -0
  59. data/src/module/hierarchy.rb +334 -0
  60. data/src/module/instance_method_visibility.rb +71 -0
  61. data/src/node.rb +81 -0
  62. data/src/object_monitor.rb +143 -0
  63. data/src/object_monitor_activity.rb +34 -0
  64. data/src/observable.rb +138 -0
  65. data/src/observable_pool.rb +291 -0
  66. data/src/orderedhash.rb +252 -0
  67. data/src/pp_hierarchy.rb +30 -0
  68. data/src/random_generators.rb +29 -0
  69. data/src/random_generators/random_generator.rb +33 -0
  70. data/src/random_generators/ruby.rb +25 -0
  71. data/src/ruby_ex.rb +124 -0
  72. data/src/safe_eval.rb +346 -0
  73. data/src/sendmail.rb +214 -0
  74. data/src/service_manager.rb +122 -0
  75. data/src/shuffle.rb +30 -0
  76. data/src/spring.rb +134 -0
  77. data/src/spring_set.rb +134 -0
  78. data/src/symtbl.rb +108 -0
  79. data/src/synflow.rb +474 -0
  80. data/src/thread_mutex.rb +11 -0
  81. data/src/timeout_ex.rb +79 -0
  82. data/src/trace.rb +26 -0
  83. data/src/uri/druby.rb +78 -0
  84. data/src/uri/file.rb +63 -0
  85. data/src/uri/ftp_ex.rb +36 -0
  86. data/src/uri/http_ex.rb +41 -0
  87. data/src/uri/pgsql.rb +136 -0
  88. data/src/uri/ssh.rb +87 -0
  89. data/src/uri/svn.rb +113 -0
  90. data/src/uri_ex.rb +71 -0
  91. data/src/verbose_object.rb +70 -0
  92. data/src/yaml/basenode_ext.rb +63 -0
  93. data/src/yaml/chop_header.rb +24 -0
  94. data/src/yaml/transform.rb +450 -0
  95. data/src/yaml/yregexpath.rb +76 -0
  96. data/test/algorithms/simulated_annealing_test.rb +102 -0
  97. data/test/check-pkg-ruby_ex.yml +15 -0
  98. data/test/check-ruby_ex.yml +12 -0
  99. data/test/resources/autoload_tree/A.rb +11 -0
  100. data/test/resources/autoload_tree/B.rb +10 -0
  101. data/test/resources/autoload_tree/foo/C.rb +18 -0
  102. data/test/resources/foo.txt +6 -0
  103. data/test/sanity-suite.yml +12 -0
  104. data/test/sanity/multiple-requires.yml +20 -0
  105. data/test/sanity/single-requires.yml +24 -0
  106. data/test/test-unit-setup.rb +6 -0
  107. data/test/unit-suite.yml +14 -0
  108. metadata +269 -0
data/src/dlogger.rb ADDED
@@ -0,0 +1,62 @@
1
+ # Copyright: Copyright (c) 2004 Nicolas Pouillard. All rights reserved.
2
+ # Author: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License: Gnu General Public License.
4
+
5
+ # $LastChangedBy: ertai $
6
+ # $Id: dlogger.rb 266 2005-06-01 14:27:18Z ertai $
7
+
8
+ require 'ruby_ex'
9
+ require 'logger'
10
+
11
+ # This Logger subclass permit to use more debug levels
12
+ #
13
+ # log = DLogger.new(STDERR)
14
+ # log.level = -1
15
+ # log.debug1 "You see me"
16
+ # log.debug2 "You see me"
17
+ # log.debug3 "You don't see me"
18
+ #
19
+ class DLogger < Logger
20
+
21
+ def format_severity ( severity )
22
+ return super if severity >= 0
23
+ return "DEBUG#{severity.abs + 1}"
24
+ end
25
+ private :format_severity
26
+
27
+ def method_missing ( meth, progname=nil, *args, &block )
28
+ return super unless meth.to_s =~ /^debug(\d+)$/ or !args.empty
29
+ add(-$1.to_i + 1, nil, progname, &block)
30
+ end
31
+
32
+ Format = "%s, [%s#%d] %6s -- %s: %s\n"
33
+ def format_message(severity, timestamp, msg, progname)
34
+ Format % [severity[0..0], timestamp, $$, severity, progname, msg]
35
+ end
36
+ private :format_message
37
+
38
+ end # class DLogger
39
+
40
+
41
+ test_section __FILE__ do
42
+
43
+ require 'stringio'
44
+
45
+ class DLoggerTest < Test::Unit::TestCase
46
+
47
+ def test1
48
+ cout = StringIO.new
49
+ log = DLogger.new(cout)
50
+ log.level = -1
51
+ log.debug1 'You see me'
52
+ log.debug3 'You don\'t see me'
53
+ log.debug2 'You see me'
54
+ cout.rewind
55
+ ref = /D, \[\d+-\d+-\d+.\d+:\d+:\d+\.\d+ #\d+\] DEBUG -- : You see me
56
+ D, \[\d+-\d+-\d+.\d+:\d+:\d+\.\d+ #\d+\] DEBUG2 -- : You see me/
57
+ assert_match(ref, cout.readlines.join)
58
+ end
59
+
60
+ end # class DLoggerTest
61
+
62
+ end
@@ -0,0 +1,95 @@
1
+ # Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
2
+ # Author: Nicolas Despres <polrop@lrde.epita.fr>.
3
+ # License: Gnu General Public License.
4
+
5
+ # $LastChangedBy: ertai $
6
+ # $Id: drb_observable.rb 266 2005-06-01 14:27:18Z ertai $
7
+
8
+
9
+ require 'ruby_ex'
10
+ require 'drb/observer'
11
+
12
+ require 'observable'
13
+
14
+
15
+ module DRb
16
+
17
+ module DRbObservable
18
+ include Observable
19
+
20
+ undef notify_observers
21
+ def notify_observers(*args, &block)
22
+ if defined? @observer_state and @observer_state
23
+ if defined? @observer_peers
24
+ for i in @observer_peers.dup
25
+ begin
26
+ i.update(*args, &block)
27
+ rescue
28
+ delete_observer(i)
29
+ end
30
+ end
31
+ end
32
+ @observer_state = false
33
+ end
34
+ end
35
+
36
+ def notify_observer(observer, *arg, &block)
37
+ if defined? @observer_state and @observer_state
38
+ if defined? @observer_peers
39
+ if @observer_peers.include?(observer)
40
+ begin
41
+ observer.update(*arg, &block)
42
+ rescue
43
+ delete_observer(observer)
44
+ end
45
+ end
46
+ end
47
+ @observer_state = false
48
+ end
49
+ end
50
+
51
+ end # module DRbObservable
52
+
53
+ end # module DRb
54
+
55
+
56
+ test_section __FILE__ do
57
+
58
+
59
+ module DRb
60
+
61
+ class ObservablePoolTest < ::Test::Unit::TestCase
62
+
63
+ class Obsv
64
+ include DRbObservable
65
+
66
+ end
67
+
68
+ class Foo
69
+
70
+ def update(*args, &block)
71
+ raise 'toto'
72
+ end
73
+
74
+ end
75
+
76
+ def test_simple
77
+ o = Obsv.new
78
+ assert_respond_to(o, :list_observers)
79
+ o.add_observer(Foo.new)
80
+ assert_equal(1, o.count_observers)
81
+ o.changed
82
+ o.notify_observers('msg')
83
+ assert_equal(0, o.count_observers)
84
+ end
85
+
86
+
87
+ end # class ObservablePoolTest
88
+
89
+ end # module DRb
90
+
91
+
92
+ end
93
+
94
+
95
+
@@ -0,0 +1,27 @@
1
+ # Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
2
+ # Author: Nicolas Despres <polrop@lrde.epita.fr>.
3
+ # License: Gnu General Public License.
4
+
5
+ # $LastChangedBy: polrop $
6
+ # $Id: drb_observable_pool.rb 97 2005-01-13 18:20:49Z polrop $
7
+
8
+
9
+ require 'observable_pool'
10
+
11
+ require 'drb/drb_observable'
12
+
13
+
14
+ module DRb
15
+
16
+ class DRbObservablePool
17
+
18
+ class SyncObserver
19
+ include DRbObservable
20
+
21
+ end # class SyncObserver
22
+
23
+ end # class DRbObservable
24
+
25
+ end # module DRb
26
+
27
+
@@ -0,0 +1,44 @@
1
+ # Author:: Nicolas Despres <nicolas.despres@epita.fr>.
2
+ # Copyright:: Copyright (c) 2004 TTK Team. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ # $LastChangedBy: ertai $
6
+ # $Id: drb_service.rb 266 2005-06-01 14:27:18Z ertai $
7
+
8
+
9
+ require 'ruby_ex'
10
+ require 'drb/drb'
11
+
12
+
13
+ module DRb
14
+
15
+ class DRbService
16
+ include DRbUndumped
17
+
18
+ def initialize(config={})
19
+ @config = config
20
+ @server = nil
21
+ @uri = nil
22
+ @front = nil
23
+ end
24
+
25
+ attr_reader :server, :uri, :front
26
+
27
+ def start_service(uri)
28
+ @server = DRb.start_service(uri.nil? ? uri : uri.to_s, @front, @config)
29
+ @uri = URI.parse(@server.uri)
30
+ end
31
+
32
+ def stop_service
33
+ @server.stop_service if @server
34
+ end
35
+
36
+ def thread
37
+ @server.thread if @server
38
+ end
39
+
40
+ end # class DRbService
41
+
42
+ end # module DRb
43
+
44
+
@@ -0,0 +1,56 @@
1
+ # Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
2
+ # Author: Nicolas Despres <polrop@lrde.epita.fr>.
3
+ # License: Gnu General Public License.
4
+
5
+ # $LastChangedBy: ertai $
6
+ # $Id: drb_undumped_attributes.rb 266 2005-06-01 14:27:18Z ertai $
7
+
8
+
9
+ require 'ruby_ex'
10
+ require 'drb/drb'
11
+
12
+
13
+ module DRb
14
+
15
+ module DRbUndumpedAttributes
16
+
17
+ def DRbUndumpedAttributes.append_features(cl)
18
+ super
19
+ cl.module_eval do
20
+
21
+ def _dump(depth)
22
+ if self.class.include?(DRb::DRbUndumped)
23
+ raise(TypeError, 'can\'t dump')
24
+ end
25
+ attribs = {}
26
+ instance_variables.each do |attr|
27
+ obj = instance_variable_get(attr)
28
+ begin
29
+ attribs[attr] = Marshal.dump(obj)
30
+ rescue TypeError
31
+ if (defined? LOG) and (not obj.class.include? DRb::DRbUndumped)
32
+ LOG.warn("#{self.class}._dump") do
33
+ "can't dump a #{attr}:#{obj.class}"
34
+ end
35
+ end
36
+ attribs[attr] = Marshal.dump(DRbObject.new(obj))
37
+ end
38
+ end
39
+ Marshal.dump([self.class, attribs])
40
+ end
41
+
42
+ def self._load(data)
43
+ klass, attribs = Marshal.load(data)
44
+ obj = klass.new
45
+ attribs.each do |attr, value|
46
+ obj.instance_variable_set(attr, Marshal.load(value))
47
+ end
48
+ obj
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end # module DRbUndumpedAttributes
55
+
56
+ end # module DRb
@@ -0,0 +1,55 @@
1
+ # Author:: Nicolas Despres <nicolas.despres@epita.fr>.
2
+ # Copyright:: Copyright (c) 2004 TTK Team. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ # $LastChangedBy: ertai $
6
+ # $Id: drb_undumped_indexed_object.rb 266 2005-06-01 14:27:18Z ertai $
7
+
8
+
9
+ require 'ruby_ex'
10
+ require 'drb'
11
+
12
+
13
+ module DRb
14
+
15
+ module DRbUndumpedIndexedObject
16
+
17
+ def DRbUndumpedIndexedObject.append_features(cl)
18
+ super
19
+ cl.module_eval do
20
+
21
+ def _dump(depth)
22
+ if self.class.include?(DRb::DRbUndumped)
23
+ raise(TypeError, 'can\'t dump')
24
+ end
25
+ attribs = {}
26
+ each_pair do |k, v|
27
+ begin
28
+ attribs[k] = Marshal.dump(v)
29
+ rescue TypeError
30
+ if (defined? LOG) and (not v.class.include? DRb::DRbUndumped)
31
+ LOG.warn("#{self.class}._dump") do
32
+ "can't dump a #{k}:#{v.class}"
33
+ end
34
+ end
35
+ attribs[k] = Marshal.dump(DRbObject.new(v))
36
+ end
37
+ end
38
+ Marshal.dump([self.class, attribs])
39
+ end
40
+
41
+ def self._load(data)
42
+ klass, attribs = Marshal.load(data)
43
+ obj = klass.new
44
+ attribs.each do |key, value|
45
+ obj[key] = Marshal.load(value)
46
+ end
47
+ obj
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end # module DRbUndumpedIndexedObject
54
+
55
+ end # module DRb
@@ -0,0 +1,101 @@
1
+ # Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved.
2
+ # Author: Nicolas Despres <polrop@lrde.epita.fr>.
3
+ # License: Gnu General Public License.
4
+
5
+ # $LastChangedBy: ertai $
6
+ # $Id: insecure_protected_methods.rb 268 2005-06-02 12:39:07Z ertai $
7
+
8
+
9
+ require 'ruby_ex'
10
+ require 'drb/drb'
11
+
12
+
13
+ module DRb
14
+
15
+ class DRbServer
16
+
17
+ alias_method :ori_check_insecure_method, :check_insecure_method
18
+ def check_insecure_method(obj, msg_id)
19
+ ori_check_insecure_method(obj, msg_id)
20
+ if obj.protected_methods.include?(msg_id.to_s)
21
+ desc = any_to_s(obj)
22
+ if desc.nil? || desc[0] == '#'
23
+ desc << ":#{obj.class}"
24
+ end
25
+ raise NameError, "protected method `#{msg_id}' called for #{desc}"
26
+ end
27
+ true
28
+ end
29
+
30
+ end # class DRbServer
31
+
32
+ end # module DRb
33
+
34
+
35
+ #
36
+ # Unit test suite
37
+ #
38
+ test_section __FILE__ do
39
+
40
+
41
+ module DRb
42
+
43
+ class InsecureProtectedMethodsTest < Test::Unit::TestCase
44
+
45
+ class SrvFoo
46
+
47
+ def public_request
48
+ end
49
+
50
+ protected
51
+ def protected_request
52
+ end
53
+
54
+ end # class Foo
55
+
56
+ def setup
57
+ rd, wr = IO.pipe
58
+ unless @srv_pid = fork # son
59
+ rd.close
60
+ DRb.start_service("druby://localhost:42000", SrvFoo.new)
61
+ wr.puts('ready')
62
+ wr.close
63
+ DRb.thread.join
64
+ else # father
65
+ wr.close
66
+ rd.gets
67
+ @drb_srv = DRb.start_service
68
+ @drb_obj = DRbObject.new(nil, "druby://localhost:42000")
69
+ rd.close
70
+ end
71
+ end
72
+
73
+ def teardown
74
+ @drb_srv.stop_service unless @drb_srv.nil?
75
+ Process.kill('TERM', @srv_pid)
76
+ Process.waitpid(@srv_pid)
77
+ end
78
+
79
+ #
80
+ # Test
81
+ #
82
+ def test_simple
83
+ assert_raises(NameError) { @drb_obj.send(:protected_resquest) }
84
+ assert_nothing_raised { @drb_obj.public_request }
85
+ end
86
+
87
+ #
88
+ # Tools
89
+ #
90
+ def server_request(req)
91
+ end
92
+
93
+ end # class InsecureProtectedMethodsTest
94
+
95
+
96
+ end # module DRb
97
+
98
+
99
+ end
100
+
101
+