engineyard-serverside 1.5.23.ruby19.16 → 1.5.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. data/lib/engineyard-serverside.rb +19 -17
  2. data/lib/engineyard-serverside/cli.rb +38 -30
  3. data/lib/engineyard-serverside/configuration.rb +4 -28
  4. data/lib/engineyard-serverside/deploy.rb +10 -7
  5. data/lib/engineyard-serverside/lockfile_parser.rb +2 -2
  6. data/lib/engineyard-serverside/logged_output.rb +2 -0
  7. data/lib/engineyard-serverside/server.rb +2 -27
  8. data/lib/engineyard-serverside/task.rb +14 -10
  9. data/lib/engineyard-serverside/version.rb +1 -1
  10. data/lib/vendor/dataflow/HISTORY +52 -0
  11. data/lib/vendor/dataflow/LICENSE +19 -0
  12. data/lib/vendor/dataflow/README.textile +290 -0
  13. data/lib/vendor/dataflow/Rakefile +36 -0
  14. data/lib/vendor/dataflow/examples/barrier.rb +9 -0
  15. data/lib/vendor/dataflow/examples/data_driven.rb +17 -0
  16. data/lib/vendor/dataflow/examples/dataflow_http_gets.rb +13 -0
  17. data/lib/vendor/dataflow/examples/flow.rb +20 -0
  18. data/lib/vendor/dataflow/examples/future_http_gets.rb +12 -0
  19. data/lib/vendor/dataflow/examples/future_queue.rb +11 -0
  20. data/lib/vendor/dataflow/examples/instance_variables.rb +15 -0
  21. data/lib/vendor/dataflow/examples/laziness.rb +9 -0
  22. data/lib/vendor/dataflow/examples/local_variables.rb +11 -0
  23. data/lib/vendor/dataflow/examples/messages.rb +26 -0
  24. data/lib/vendor/dataflow/examples/port_http_gets.rb +13 -0
  25. data/lib/vendor/dataflow/examples/port_send.rb +10 -0
  26. data/lib/vendor/dataflow/examples/ring.rb +21 -0
  27. data/lib/vendor/dataflow/spec/actor_spec.rb +28 -0
  28. data/lib/vendor/dataflow/spec/anonymous_variables_spec.rb +21 -0
  29. data/lib/vendor/dataflow/spec/barrier_spec.rb +25 -0
  30. data/lib/vendor/dataflow/spec/by_need_spec.rb +55 -0
  31. data/lib/vendor/dataflow/spec/dataflow_spec.rb +151 -0
  32. data/lib/vendor/dataflow/spec/equality_spec.rb +40 -0
  33. data/lib/vendor/dataflow/spec/flow_spec.rb +25 -0
  34. data/lib/vendor/dataflow/spec/forker_spec.rb +28 -0
  35. data/lib/vendor/dataflow/spec/future_queue_spec.rb +31 -0
  36. data/lib/vendor/dataflow/spec/inspect_spec.rb +19 -0
  37. data/lib/vendor/dataflow/spec/need_later_spec.rb +12 -0
  38. data/lib/vendor/dataflow/spec/port_spec.rb +26 -0
  39. data/lib/vendor/dataflow/spec/spec.opts +1 -0
  40. data/lib/vendor/dataflow/spec/spec_helper.rb +10 -0
  41. data/lib/vendor/escape/Readme +21 -0
  42. data/lib/vendor/escape/doc_include/template/qualitysmith.rb +631 -0
  43. data/lib/vendor/json_pure/CHANGES +166 -0
  44. data/lib/vendor/json_pure/COPYING +58 -0
  45. data/lib/vendor/json_pure/GPL +340 -0
  46. data/lib/vendor/json_pure/README +358 -0
  47. data/lib/vendor/json_pure/Rakefile +292 -0
  48. data/lib/vendor/json_pure/TODO +1 -0
  49. data/lib/vendor/json_pure/VERSION +1 -0
  50. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +52 -0
  51. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +1000 -0
  52. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +1001 -0
  53. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +900 -0
  54. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +901 -0
  55. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +1000 -0
  56. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +1001 -0
  57. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +261 -0
  58. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +1000 -0
  59. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +1001 -0
  60. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +1000 -0
  61. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +1001 -0
  62. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +1000 -0
  63. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +1001 -0
  64. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +262 -0
  65. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +1000 -0
  66. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +1001 -0
  67. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +82 -0
  68. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +34 -0
  69. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +900 -0
  70. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +901 -0
  71. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +81 -0
  72. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +1000 -0
  73. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +1001 -0
  74. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +82 -0
  75. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +1000 -0
  76. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +1001 -0
  77. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +82 -0
  78. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +1000 -0
  79. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +1001 -0
  80. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +82 -0
  81. data/lib/vendor/json_pure/benchmarks/generator2_benchmark.rb +222 -0
  82. data/lib/vendor/json_pure/benchmarks/generator_benchmark.rb +224 -0
  83. data/lib/vendor/json_pure/benchmarks/ohai.json +1216 -0
  84. data/lib/vendor/json_pure/benchmarks/ohai.ruby +1 -0
  85. data/lib/vendor/json_pure/benchmarks/parser2_benchmark.rb +251 -0
  86. data/lib/vendor/json_pure/benchmarks/parser_benchmark.rb +259 -0
  87. data/lib/vendor/json_pure/bin/edit_json.rb +9 -0
  88. data/lib/vendor/json_pure/bin/prettify_json.rb +75 -0
  89. data/lib/vendor/json_pure/data/example.json +1 -0
  90. data/lib/vendor/json_pure/data/index.html +38 -0
  91. data/lib/vendor/json_pure/data/prototype.js +4184 -0
  92. data/lib/vendor/json_pure/ext/json/ext/generator/extconf.rb +16 -0
  93. data/lib/vendor/json_pure/ext/json/ext/generator/generator.c +1323 -0
  94. data/lib/vendor/json_pure/ext/json/ext/generator/generator.h +170 -0
  95. data/lib/vendor/json_pure/ext/json/ext/parser/extconf.rb +15 -0
  96. data/lib/vendor/json_pure/ext/json/ext/parser/parser.c +1935 -0
  97. data/lib/vendor/json_pure/ext/json/ext/parser/parser.h +71 -0
  98. data/lib/vendor/json_pure/ext/json/ext/parser/parser.rl +792 -0
  99. data/lib/vendor/json_pure/install.rb +26 -0
  100. data/lib/vendor/json_pure/tests/fixtures/fail1.json +1 -0
  101. data/lib/vendor/json_pure/tests/fixtures/fail10.json +1 -0
  102. data/lib/vendor/json_pure/tests/fixtures/fail11.json +1 -0
  103. data/lib/vendor/json_pure/tests/fixtures/fail12.json +1 -0
  104. data/lib/vendor/json_pure/tests/fixtures/fail13.json +1 -0
  105. data/lib/vendor/json_pure/tests/fixtures/fail14.json +1 -0
  106. data/lib/vendor/json_pure/tests/fixtures/fail18.json +1 -0
  107. data/lib/vendor/json_pure/tests/fixtures/fail19.json +1 -0
  108. data/lib/vendor/json_pure/tests/fixtures/fail2.json +1 -0
  109. data/lib/vendor/json_pure/tests/fixtures/fail20.json +1 -0
  110. data/lib/vendor/json_pure/tests/fixtures/fail21.json +1 -0
  111. data/lib/vendor/json_pure/tests/fixtures/fail22.json +1 -0
  112. data/lib/vendor/json_pure/tests/fixtures/fail23.json +1 -0
  113. data/lib/vendor/json_pure/tests/fixtures/fail24.json +1 -0
  114. data/lib/vendor/json_pure/tests/fixtures/fail25.json +1 -0
  115. data/lib/vendor/json_pure/tests/fixtures/fail27.json +2 -0
  116. data/lib/vendor/json_pure/tests/fixtures/fail28.json +2 -0
  117. data/lib/vendor/json_pure/tests/fixtures/fail3.json +1 -0
  118. data/lib/vendor/json_pure/tests/fixtures/fail4.json +1 -0
  119. data/lib/vendor/json_pure/tests/fixtures/fail5.json +1 -0
  120. data/lib/vendor/json_pure/tests/fixtures/fail6.json +1 -0
  121. data/lib/vendor/json_pure/tests/fixtures/fail7.json +1 -0
  122. data/lib/vendor/json_pure/tests/fixtures/fail8.json +1 -0
  123. data/lib/vendor/json_pure/tests/fixtures/fail9.json +1 -0
  124. data/lib/vendor/json_pure/tests/fixtures/pass1.json +56 -0
  125. data/lib/vendor/json_pure/tests/fixtures/pass15.json +1 -0
  126. data/lib/vendor/json_pure/tests/fixtures/pass16.json +1 -0
  127. data/lib/vendor/json_pure/tests/fixtures/pass17.json +1 -0
  128. data/lib/vendor/json_pure/tests/fixtures/pass2.json +1 -0
  129. data/lib/vendor/json_pure/tests/fixtures/pass26.json +1 -0
  130. data/lib/vendor/json_pure/tests/fixtures/pass3.json +6 -0
  131. data/lib/vendor/json_pure/tests/test_json.rb +361 -0
  132. data/lib/vendor/json_pure/tests/test_json_addition.rb +162 -0
  133. data/lib/vendor/json_pure/tests/test_json_encoding.rb +68 -0
  134. data/lib/vendor/json_pure/tests/test_json_fixtures.rb +34 -0
  135. data/lib/vendor/json_pure/tests/test_json_generate.rb +122 -0
  136. data/lib/vendor/json_pure/tests/test_json_rails.rb +144 -0
  137. data/lib/vendor/json_pure/tests/test_json_unicode.rb +76 -0
  138. data/lib/vendor/json_pure/tools/fuzz.rb +139 -0
  139. data/lib/vendor/json_pure/tools/server.rb +61 -0
  140. data/lib/vendor/open4/lib/open4.rb +51 -80
  141. data/lib/vendor/thor/CHANGELOG.rdoc +89 -0
  142. data/lib/vendor/thor/LICENSE +20 -0
  143. data/lib/vendor/thor/README.rdoc +297 -0
  144. data/lib/vendor/thor/Thorfile +69 -0
  145. data/lib/vendor/thor/bin/rake2thor +86 -0
  146. data/lib/vendor/thor/bin/thor +6 -0
  147. data/lib/vendor/thor/thor.gemspec +120 -0
  148. data/spec/basic_deploy_spec.rb +1 -1
  149. data/spec/bundler_deploy_spec.rb +1 -1
  150. data/spec/nodejs_deploy_spec.rb +5 -2
  151. data/spec/rails31_deploy_spec.rb +3 -3
  152. data/spec/services_deploy_spec.rb +1 -1
  153. data/spec/support/integration.rb +1 -2
  154. metadata +165 -44
  155. data/lib/engineyard-serverside/future.rb +0 -29
  156. data/lib/engineyard-serverside/futures/celluloid.rb +0 -25
  157. data/lib/engineyard-serverside/futures/dataflow.rb +0 -31
  158. data/lib/vendor/celluloid/lib/celluloid.rb +0 -261
  159. data/lib/vendor/celluloid/lib/celluloid/actor.rb +0 -242
  160. data/lib/vendor/celluloid/lib/celluloid/actor_pool.rb +0 -54
  161. data/lib/vendor/celluloid/lib/celluloid/actor_proxy.rb +0 -75
  162. data/lib/vendor/celluloid/lib/celluloid/application.rb +0 -78
  163. data/lib/vendor/celluloid/lib/celluloid/calls.rb +0 -94
  164. data/lib/vendor/celluloid/lib/celluloid/core_ext.rb +0 -14
  165. data/lib/vendor/celluloid/lib/celluloid/events.rb +0 -14
  166. data/lib/vendor/celluloid/lib/celluloid/fiber.rb +0 -33
  167. data/lib/vendor/celluloid/lib/celluloid/fsm.rb +0 -141
  168. data/lib/vendor/celluloid/lib/celluloid/future.rb +0 -60
  169. data/lib/vendor/celluloid/lib/celluloid/links.rb +0 -61
  170. data/lib/vendor/celluloid/lib/celluloid/logger.rb +0 -32
  171. data/lib/vendor/celluloid/lib/celluloid/mailbox.rb +0 -124
  172. data/lib/vendor/celluloid/lib/celluloid/receivers.rb +0 -66
  173. data/lib/vendor/celluloid/lib/celluloid/registry.rb +0 -33
  174. data/lib/vendor/celluloid/lib/celluloid/responses.rb +0 -26
  175. data/lib/vendor/celluloid/lib/celluloid/rspec.rb +0 -2
  176. data/lib/vendor/celluloid/lib/celluloid/signals.rb +0 -50
  177. data/lib/vendor/celluloid/lib/celluloid/supervisor.rb +0 -57
  178. data/lib/vendor/celluloid/lib/celluloid/task.rb +0 -73
  179. data/lib/vendor/celluloid/lib/celluloid/tcp_server.rb +0 -33
  180. data/lib/vendor/celluloid/lib/celluloid/timers.rb +0 -109
  181. data/lib/vendor/celluloid/lib/celluloid/version.rb +0 -4
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'test/unit'
5
+ case ENV['JSON']
6
+ when 'pure' then require 'json/pure'
7
+ when 'ext' then require 'json/ext'
8
+ else require 'json'
9
+ end
10
+
11
+ class TC_JSONUnicode < Test::Unit::TestCase
12
+ include JSON
13
+
14
+ def test_unicode
15
+ assert_equal '""', ''.to_json
16
+ assert_equal '"\\b"', "\b".to_json
17
+ assert_equal '"\u0001"', 0x1.chr.to_json
18
+ assert_equal '"\u001f"', 0x1f.chr.to_json
19
+ assert_equal '" "', ' '.to_json
20
+ assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json
21
+ utf8 = [ "© ≠ €! \01" ]
22
+ json = '["© ≠ €! \u0001"]'
23
+ assert_equal json, utf8.to_json(:ascii_only => false)
24
+ assert_equal utf8, parse(json)
25
+ json = '["\u00a9 \u2260 \u20ac! \u0001"]'
26
+ assert_equal json, utf8.to_json(:ascii_only => true)
27
+ assert_equal utf8, parse(json)
28
+ utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
29
+ json = "[\"\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212\"]"
30
+ assert_equal utf8, parse(json)
31
+ assert_equal json, utf8.to_json(:ascii_only => false)
32
+ utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
33
+ assert_equal utf8, parse(json)
34
+ json = "[\"\\u3042\\u3044\\u3046\\u3048\\u304a\"]"
35
+ assert_equal json, utf8.to_json(:ascii_only => true)
36
+ assert_equal utf8, parse(json)
37
+ utf8 = ['საქართველო']
38
+ json = '["საქართველო"]'
39
+ assert_equal json, utf8.to_json(:ascii_only => false)
40
+ json = "[\"\\u10e1\\u10d0\\u10e5\\u10d0\\u10e0\\u10d7\\u10d5\\u10d4\\u10da\\u10dd\"]"
41
+ assert_equal json, utf8.to_json(:ascii_only => true)
42
+ assert_equal utf8, parse(json)
43
+ assert_equal '["Ã"]', JSON.generate(["Ã"], :ascii_only => false)
44
+ assert_equal '["\\u00c3"]', JSON.generate(["Ã"], :ascii_only => true)
45
+ assert_equal ["€"], JSON.parse('["\u20ac"]')
46
+ utf8 = ["\xf0\xa0\x80\x81"]
47
+ json = "[\"\xf0\xa0\x80\x81\"]"
48
+ assert_equal json, JSON.generate(utf8, :ascii_only => false)
49
+ assert_equal utf8, JSON.parse(json)
50
+ json = '["\ud840\udc01"]'
51
+ assert_equal json, JSON.generate(utf8, :ascii_only => true)
52
+ assert_equal utf8, JSON.parse(json)
53
+ end
54
+
55
+ def test_chars
56
+ (0..0x7f).each do |i|
57
+ json = '["\u%04x"]' % i
58
+ if RUBY_VERSION >= "1.9."
59
+ i = i.chr
60
+ end
61
+ assert_equal i, JSON.parse(json).first[0]
62
+ if i == ?\b
63
+ generated = JSON.generate(["" << i])
64
+ assert '["\b"]' == generated || '["\10"]' == generated
65
+ elsif [?\n, ?\r, ?\t, ?\f].include?(i)
66
+ assert_equal '[' << ('' << i).dump << ']', JSON.generate(["" << i])
67
+ elsif i.chr < 0x20.chr
68
+ assert_equal json, JSON.generate(["" << i])
69
+ end
70
+ end
71
+ assert_raise(JSON::GeneratorError) do
72
+ JSON.generate(["\x80"], :ascii_only => true)
73
+ end
74
+ assert_equal "\302\200", JSON.parse('["\u0080"]').first
75
+ end
76
+ end
@@ -0,0 +1,139 @@
1
+ require 'json'
2
+
3
+ require 'iconv'
4
+ ISO_8859_1_TO_UTF8 = Iconv.new('utf-8', 'iso-8859-15')
5
+ class ::String
6
+ def to_utf8
7
+ ISO_8859_1_TO_UTF8.iconv self
8
+ end
9
+ end
10
+
11
+ class Fuzzer
12
+ def initialize(n, freqs = {})
13
+ sum = freqs.inject(0.0) { |s, x| s + x.last }
14
+ freqs.each_key { |x| freqs[x] /= sum }
15
+ s = 0.0
16
+ freqs.each_key do |x|
17
+ freqs[x] = s .. (s + t = freqs[x])
18
+ s += t
19
+ end
20
+ @freqs = freqs
21
+ @n = n
22
+ @alpha = (0..0xff).to_a
23
+ end
24
+
25
+ def random_string
26
+ s = ''
27
+ 30.times { s << @alpha[rand(@alpha.size)] }
28
+ s.to_utf8
29
+ end
30
+
31
+ def pick
32
+ r = rand
33
+ found = @freqs.find { |k, f| f.include? rand }
34
+ found && found.first
35
+ end
36
+
37
+ def make_pick
38
+ k = pick
39
+ case
40
+ when k == Hash, k == Array
41
+ k.new
42
+ when k == true, k == false, k == nil
43
+ k
44
+ when k == String
45
+ random_string
46
+ when k == Fixnum
47
+ rand(2 ** 30) - 2 ** 29
48
+ when k == Bignum
49
+ rand(2 ** 70) - 2 ** 69
50
+ end
51
+ end
52
+
53
+ def fuzz(current = nil)
54
+ if @n > 0
55
+ case current
56
+ when nil
57
+ @n -= 1
58
+ current = fuzz [ Hash, Array ][rand(2)].new
59
+ when Array
60
+ while @n > 0
61
+ @n -= 1
62
+ current << case p = make_pick
63
+ when Array, Hash
64
+ fuzz(p)
65
+ else
66
+ p
67
+ end
68
+ end
69
+ when Hash
70
+ while @n > 0
71
+ @n -= 1
72
+ current[random_string] = case p = make_pick
73
+ when Array, Hash
74
+ fuzz(p)
75
+ else
76
+ p
77
+ end
78
+ end
79
+ end
80
+ end
81
+ current
82
+ end
83
+ end
84
+
85
+ class MyState < JSON.state
86
+ WS = " \r\t\n"
87
+
88
+ def initialize
89
+ super(
90
+ :indent => make_spaces,
91
+ :space => make_spaces,
92
+ :space_before => make_spaces,
93
+ :object_nl => make_spaces,
94
+ :array_nl => make_spaces,
95
+ :max_nesting => false
96
+ )
97
+ end
98
+
99
+ def make_spaces
100
+ s = ''
101
+ rand(1).times { s << WS[rand(WS.size)] }
102
+ s
103
+ end
104
+ end
105
+
106
+ n = (ARGV.shift || 500).to_i
107
+ loop do
108
+ fuzzer = Fuzzer.new(n,
109
+ Hash => 25,
110
+ Array => 25,
111
+ String => 10,
112
+ Fixnum => 10,
113
+ Bignum => 10,
114
+ nil => 5,
115
+ true => 5,
116
+ false => 5
117
+ )
118
+ o1 = fuzzer.fuzz
119
+ json = JSON.generate o1, MyState.new
120
+ if $DEBUG
121
+ puts "-" * 80
122
+ puts json, json.size
123
+ else
124
+ puts json.size
125
+ end
126
+ begin
127
+ o2 = JSON.parse(json, :max_nesting => false)
128
+ rescue JSON::ParserError => e
129
+ puts "Caught #{e.class}: #{e.message}\n#{e.backtrace * "\n"}"
130
+ puts "o1 = #{o1.inspect}", "json = #{json}", "json_str = #{json.inspect}"
131
+ puts "locals = #{local_variables.inspect}"
132
+ exit
133
+ end
134
+ if o1 != o2
135
+ puts "mismatch", "o1 = #{o1.inspect}", "o2 = #{o2.inspect}",
136
+ "json = #{json}", "json_str = #{json.inspect}"
137
+ puts "locals = #{local_variables.inspect}"
138
+ end
139
+ end
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'webrick'
4
+ include WEBrick
5
+ $:.unshift 'ext'
6
+ $:.unshift 'lib'
7
+ require 'json'
8
+
9
+ class JSONServlet < HTTPServlet::AbstractServlet
10
+ @@count = 1
11
+
12
+ def do_GET(req, res)
13
+ obj = {
14
+ "TIME" => Time.now.strftime("%FT%T"),
15
+ "foo" => "Bär",
16
+ "bar" => "© ≠ €!",
17
+ 'a' => 2,
18
+ 'b' => 3.141,
19
+ 'COUNT' => @@count += 1,
20
+ 'c' => 'c',
21
+ 'd' => [ 1, "b", 3.14 ],
22
+ 'e' => { 'foo' => 'bar' },
23
+ 'g' => "松本行弘",
24
+ 'h' => 1000.0,
25
+ 'i' => 0.001,
26
+ 'j' => "\xf0\xa0\x80\x81",
27
+ }
28
+ res.body = JSON.generate obj
29
+ res['Content-Type'] = "application/json"
30
+ end
31
+ end
32
+
33
+ def create_server(err, dir, port)
34
+ dir = File.expand_path(dir)
35
+ err.puts "Surf to:", "http://#{Socket.gethostname}:#{port}"
36
+
37
+ s = HTTPServer.new(
38
+ :Port => port,
39
+ :DocumentRoot => dir,
40
+ :Logger => WEBrick::Log.new(err),
41
+ :AccessLog => [
42
+ [ err, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
43
+ [ err, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
44
+ [ err, WEBrick::AccessLog::AGENT_LOG_FORMAT ]
45
+ ]
46
+ )
47
+ s.mount("/json", JSONServlet)
48
+ s
49
+ end
50
+
51
+ default_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'data'))
52
+ dir = ARGV.shift || default_dir
53
+ port = (ARGV.shift || 6666).to_i
54
+ s = create_server(STDERR, dir, 6666)
55
+ t = Thread.new { s.start }
56
+ trap(:INT) do
57
+ s.shutdown
58
+ t.join
59
+ exit
60
+ end
61
+ sleep
@@ -4,65 +4,23 @@ require 'timeout'
4
4
  require 'thread'
5
5
 
6
6
  module Open4
7
- VERSION = '1.3.0'
7
+ #--{{{
8
+ VERSION = '1.1.0'
8
9
  def self.version() VERSION end
9
10
 
10
11
  class Error < ::StandardError; end
11
12
 
12
- def pfork4(fun, &b)
13
- Open4.do_popen(b, :block) do |ps_read, _|
14
- ps_read.close
15
- begin
16
- fun.call
17
- rescue SystemExit => e
18
- # Make it seem to the caller that calling Kernel#exit in +fun+ kills
19
- # the child process normally. Kernel#exit! bypasses this rescue
20
- # block.
21
- exit! e.status
22
- else
23
- exit! 0
24
- end
25
- end
26
- end
27
- module_function :pfork4
28
-
29
13
  def popen4(*cmd, &b)
30
- Open4.do_popen(b, :init) do |ps_read, ps_write|
31
- ps_read.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
32
- ps_write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
33
- exec(*cmd)
34
- raise 'forty-two' # Is this really needed?
35
- end
36
- end
37
- alias open4 popen4
38
- module_function :popen4
39
- module_function :open4
40
-
41
- def popen4ext(closefds=false, *cmd, &b)
42
- Open4.do_popen(b, :init, closefds) do |ps_read, ps_write|
43
- ps_read.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
44
- ps_write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
45
- exec(*cmd)
46
- raise 'forty-two' # Is this really needed?
47
- end
48
- end
49
- module_function :popen4ext
50
-
51
- def self.do_popen(b = nil, exception_propagation_at = nil, closefds=false, &cmd)
14
+ #--{{{
52
15
  pw, pr, pe, ps = IO.pipe, IO.pipe, IO.pipe, IO.pipe
53
16
 
54
17
  verbose = $VERBOSE
55
18
  begin
56
19
  $VERBOSE = nil
20
+ ps.first.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
21
+ ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
57
22
 
58
23
  cid = fork {
59
- if closefds
60
- exlist = [0, 1, 2] | [pw,pr,pe,ps].map{|p| [p.first.fileno, p.last.fileno] }.flatten
61
- ObjectSpace.each_object(IO){|io|
62
- io.close if (not io.closed?) and (not exlist.include? io.fileno)
63
- }
64
- end
65
-
66
24
  pw.last.close
67
25
  STDIN.reopen pw.first
68
26
  pw.first.close
@@ -78,59 +36,52 @@ module Open4
78
36
  STDOUT.sync = STDERR.sync = true
79
37
 
80
38
  begin
81
- cmd.call(ps)
39
+ exec(*cmd)
40
+ raise 'forty-two'
82
41
  rescue Exception => e
83
42
  Marshal.dump(e, ps.last)
84
43
  ps.last.flush
85
- ensure
86
- ps.last.close unless ps.last.closed?
87
44
  end
88
-
45
+ ps.last.close unless (ps.last.closed?)
89
46
  exit!
90
47
  }
91
48
  ensure
92
49
  $VERBOSE = verbose
93
50
  end
94
51
 
95
- [ pw.first, pr.last, pe.last, ps.last ].each { |fd| fd.close }
52
+ [pw.first, pr.last, pe.last, ps.last].each{|fd| fd.close}
96
53
 
97
- Open4.propagate_exception cid, ps.first if exception_propagation_at == :init
54
+ begin
55
+ e = Marshal.load ps.first
56
+ raise(Exception === e ? e : "unknown failure!")
57
+ rescue EOFError # If we get an EOF error, then the exec was successful
58
+ 42
59
+ ensure
60
+ ps.first.close
61
+ end
98
62
 
99
63
  pw.last.sync = true
100
64
 
101
- pi = [ pw.last, pr.first, pe.first ]
102
-
103
- begin
104
- return [cid, *pi] unless b
65
+ pi = [pw.last, pr.first, pe.first]
105
66
 
67
+ if b
106
68
  begin
107
- b.call(cid, *pi)
69
+ b[cid, *pi]
70
+ Process.waitpid2(cid).last
108
71
  ensure
109
- pi.each { |fd| fd.close unless fd.closed? }
72
+ pi.each{|fd| fd.close unless fd.closed?}
110
73
  end
111
-
112
- Open4.propagate_exception cid, ps.first if exception_propagation_at == :block
113
-
114
- Process.waitpid2(cid).last
115
- ensure
116
- ps.first.close unless ps.first.closed?
74
+ else
75
+ [cid, pw.last, pr.first, pe.first]
117
76
  end
77
+ #--}}}
118
78
  end
119
-
120
- def self.propagate_exception(cid, ps_read)
121
- e = Marshal.load ps_read
122
- raise Exception === e ? e : "unknown failure!"
123
- rescue EOFError
124
- # Child process did not raise exception.
125
- rescue
126
- # Child process raised exception; wait it in order to avoid a zombie.
127
- Process.waitpid2 cid
128
- raise
129
- ensure
130
- ps_read.close
131
- end
79
+ alias open4 popen4
80
+ module_function :popen4
81
+ module_function :open4
132
82
 
133
83
  class SpawnError < Error
84
+ #--{{{
134
85
  attr 'cmd'
135
86
  attr 'status'
136
87
  attr 'signals'
@@ -147,9 +98,11 @@ module Open4
147
98
  sigs = @signals.map{|k,v| "#{ k }:#{ v.inspect }"}.join(' ')
148
99
  super "cmd <#{ cmd }> failed with status <#{ exitstatus.inspect }> signals <#{ sigs }>"
149
100
  end
101
+ #--}}}
150
102
  end
151
103
 
152
104
  class ThreadEnsemble
105
+ #--{{{
153
106
  attr 'threads'
154
107
 
155
108
  def initialize cid
@@ -201,14 +154,18 @@ module Open4
201
154
  def all_done
202
155
  @threads.size.times{ @done.pop }
203
156
  end
157
+ #--}}}
204
158
  end
205
159
 
206
160
  def to timeout = nil
161
+ #--{{{
207
162
  Timeout.timeout(timeout){ yield }
163
+ #--}}}
208
164
  end
209
165
  module_function :to
210
166
 
211
167
  def new_thread *a, &b
168
+ #--{{{
212
169
  cur = Thread.current
213
170
  Thread.new(*a) do |*a|
214
171
  begin
@@ -217,25 +174,29 @@ module Open4
217
174
  cur.raise e
218
175
  end
219
176
  end
177
+ #--}}}
220
178
  end
221
179
  module_function :new_thread
222
180
 
223
181
  def getopts opts = {}
182
+ #--{{{
224
183
  lambda do |*args|
225
184
  keys, default, ignored = args
226
- catch(:opt) do
185
+ catch('opt') do
227
186
  [keys].flatten.each do |key|
228
187
  [key, key.to_s, key.to_s.intern].each do |key|
229
- throw :opt, opts[key] if opts.has_key?(key)
188
+ throw 'opt', opts[key] if opts.has_key?(key)
230
189
  end
231
190
  end
232
191
  default
233
192
  end
234
193
  end
194
+ #--}}}
235
195
  end
236
196
  module_function :getopts
237
197
 
238
198
  def relay src, dst = nil, t = nil
199
+ #--{{{
239
200
  send_dst =
240
201
  if dst.respond_to?(:call)
241
202
  lambda{|buf| dst.call(buf)}
@@ -283,10 +244,12 @@ module Open4
283
244
  send_dst[buf]
284
245
  end
285
246
  end
247
+ #--}}}
286
248
  end
287
249
  module_function :relay
288
250
 
289
251
  def spawn arg, *argv
252
+ #--{{{
290
253
  argv.unshift(arg)
291
254
  opts = ((argv.size > 1 and Hash === argv.last) ? argv.pop : {})
292
255
  argv.flatten!
@@ -362,6 +325,7 @@ module Open4
362
325
  (ignore_exit_failure or (status.nil? and ignore_exec_failure) or exitstatus.include?(status.exitstatus))
363
326
 
364
327
  status
328
+ #--}}}
365
329
  end
366
330
  module_function :spawn
367
331
 
@@ -372,6 +336,7 @@ module Open4
372
336
  module_function :chdir
373
337
 
374
338
  def background arg, *argv
339
+ #--{{{
375
340
  require 'thread'
376
341
  q = Queue.new
377
342
  opts = { 'pid' => q, :pid => q }
@@ -389,12 +354,14 @@ module Open4
389
354
  define_method(:exitstatus){ @exitstatus ||= spawn_status.exitstatus }
390
355
  }
391
356
  thread
357
+ #--}}}
392
358
  end
393
359
  alias bg background
394
360
  module_function :background
395
361
  module_function :bg
396
362
 
397
363
  def maim pid, opts = {}
364
+ #--{{{
398
365
  getopt = getopts opts
399
366
  sigs = getopt[ 'signals', %w(SIGTERM SIGQUIT SIGKILL) ]
400
367
  suspend = getopt[ 'suspend', 4 ]
@@ -412,10 +379,12 @@ module Open4
412
379
  return true unless alive? pid
413
380
  end
414
381
  return(not alive?(pid))
382
+ #--}}}
415
383
  end
416
384
  module_function :maim
417
385
 
418
386
  def alive pid
387
+ #--{{{
419
388
  pid = Integer pid
420
389
  begin
421
390
  Process.kill 0, pid
@@ -423,10 +392,12 @@ module Open4
423
392
  rescue Errno::ESRCH
424
393
  false
425
394
  end
395
+ #--}}}
426
396
  end
427
397
  alias alive? alive
428
398
  module_function :alive
429
399
  module_function :'alive?'
400
+ #--}}}
430
401
  end
431
402
 
432
403
  def open4(*cmd, &b) cmd.size == 0 ? Open4 : Open4::popen4(*cmd, &b) end