mechanize 0.6.11 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mechanize might be problematic. Click here for more details.

Files changed (91) hide show
  1. data/CHANGELOG.txt +8 -0
  2. data/Manifest.txt +31 -22
  3. data/lib/mechanize.rb +2 -652
  4. data/lib/www/mechanize.rb +635 -0
  5. data/lib/www/mechanize/content_type_error.rb +16 -0
  6. data/lib/www/mechanize/cookie.rb +64 -0
  7. data/lib/{mechanize/cookie.rb → www/mechanize/cookie_jar.rb} +0 -60
  8. data/lib/www/mechanize/file.rb +73 -0
  9. data/lib/www/mechanize/file_saver.rb +39 -0
  10. data/lib/{mechanize → www/mechanize}/form.rb +119 -137
  11. data/lib/www/mechanize/form/button.rb +8 -0
  12. data/lib/www/mechanize/form/check_box.rb +13 -0
  13. data/lib/www/mechanize/form/field.rb +28 -0
  14. data/lib/www/mechanize/form/file_upload.rb +24 -0
  15. data/lib/www/mechanize/form/image_button.rb +23 -0
  16. data/lib/www/mechanize/form/multi_select_list.rb +69 -0
  17. data/lib/www/mechanize/form/option.rb +51 -0
  18. data/lib/www/mechanize/form/radio_button.rb +38 -0
  19. data/lib/www/mechanize/form/select_list.rb +41 -0
  20. data/lib/www/mechanize/headers.rb +12 -0
  21. data/lib/{mechanize → www/mechanize}/history.rb +0 -0
  22. data/lib/{mechanize → www/mechanize}/inspect.rb +21 -28
  23. data/lib/{mechanize → www/mechanize}/list.rb +0 -0
  24. data/lib/{mechanize → www/mechanize}/monkey_patch.rb +19 -0
  25. data/lib/www/mechanize/page.rb +121 -0
  26. data/lib/www/mechanize/page/base.rb +10 -0
  27. data/lib/www/mechanize/page/frame.rb +22 -0
  28. data/lib/www/mechanize/page/link.rb +50 -0
  29. data/lib/www/mechanize/page/meta.rb +10 -0
  30. data/lib/www/mechanize/pluggable_parsers.rb +93 -0
  31. data/lib/{mechanize/errors.rb → www/mechanize/response_code_error.rb} +1 -13
  32. data/test/{test_includes.rb → helper.rb} +4 -18
  33. data/test/{test_servlets.rb → servlets.rb} +0 -0
  34. data/test/tc_authenticate.rb +1 -8
  35. data/test/tc_bad_links.rb +3 -10
  36. data/test/tc_blank_form.rb +1 -8
  37. data/test/tc_checkboxes.rb +1 -8
  38. data/test/tc_cookie_class.rb +1 -6
  39. data/test/tc_cookie_jar.rb +1 -7
  40. data/test/tc_cookies.rb +10 -17
  41. data/test/tc_encoded_links.rb +5 -12
  42. data/test/tc_errors.rb +4 -11
  43. data/test/tc_follow_meta.rb +1 -8
  44. data/test/tc_form_action.rb +6 -14
  45. data/test/tc_form_as_hash.rb +1 -9
  46. data/test/tc_form_button.rb +5 -8
  47. data/test/tc_form_no_inputname.rb +1 -8
  48. data/test/tc_forms.rb +16 -24
  49. data/test/tc_frames.rb +3 -10
  50. data/test/tc_gzipping.rb +2 -9
  51. data/test/tc_history.rb +5 -12
  52. data/test/tc_html_unscape_forms.rb +8 -15
  53. data/test/tc_if_modified_since.rb +1 -6
  54. data/test/tc_keep_alive.rb +1 -8
  55. data/test/tc_links.rb +12 -19
  56. data/test/tc_mech.rb +26 -34
  57. data/test/{test_mechanize_file.rb → tc_mechanize_file.rb} +1 -6
  58. data/test/tc_multi_select.rb +10 -17
  59. data/test/tc_no_attributes.rb +1 -8
  60. data/test/tc_page.rb +3 -10
  61. data/test/tc_pluggable_parser.rb +8 -15
  62. data/test/tc_post_form.rb +3 -10
  63. data/test/tc_pretty_print.rb +3 -10
  64. data/test/tc_radiobutton.rb +2 -9
  65. data/test/tc_referer.rb +13 -20
  66. data/test/tc_relative_links.rb +1 -8
  67. data/test/tc_response_code.rb +14 -21
  68. data/test/tc_save_file.rb +1 -9
  69. data/test/tc_select.rb +3 -10
  70. data/test/tc_select_all.rb +2 -10
  71. data/test/tc_select_none.rb +2 -10
  72. data/test/tc_select_noopts.rb +2 -9
  73. data/test/tc_set_fields.rb +2 -9
  74. data/test/tc_ssl_server.rb +5 -12
  75. data/test/tc_subclass.rb +2 -9
  76. data/test/tc_textarea.rb +2 -9
  77. data/test/tc_upload.rb +2 -9
  78. data/test/test_all.rb +4 -43
  79. metadata +96 -80
  80. data/lib/mechanize/form_elements.rb +0 -254
  81. data/lib/mechanize/net-overrides/net/http.rb +0 -2107
  82. data/lib/mechanize/net-overrides/net/https.rb +0 -172
  83. data/lib/mechanize/net-overrides/net/protocol.rb +0 -380
  84. data/lib/mechanize/page.rb +0 -138
  85. data/lib/mechanize/page_elements.rb +0 -77
  86. data/lib/mechanize/parsers/rexml_page.rb +0 -35
  87. data/lib/mechanize/pluggable_parsers.rb +0 -204
  88. data/lib/mechanize/rexml.rb +0 -236
  89. data/setup.rb +0 -1585
  90. data/test/tc_proxy.rb +0 -25
  91. data/test/tc_watches.rb +0 -32
@@ -1,172 +0,0 @@
1
- # :enddoc:
2
- =begin
3
-
4
- = $RCSfile: https.rb,v $ -- SSL/TLS enhancement for Net::HTTP.
5
-
6
- == Info
7
- 'OpenSSL for Ruby 2' project
8
- Copyright (C) 2001 GOTOU Yuuzou <gotoyuzo@notwork.org>
9
- All rights reserved.
10
-
11
- == Licence
12
- This program is licenced under the same licence as Ruby.
13
- (See the file 'LICENCE'.)
14
-
15
- == Requirements
16
- This program requires Net 1.2.0 or higher version.
17
- You can get it from RAA or Ruby's CVS repository.
18
-
19
- == Version
20
- $Id: https.rb,v 1.3 2004/12/20 05:46:45 gotoyuzo Exp $
21
-
22
- 2001-11-06: Contiributed to Ruby/OpenSSL project.
23
- 2004-03-06: Some code is merged in to net/http.
24
-
25
- == Example
26
-
27
- Here is a simple HTTP client:
28
-
29
- require 'net/http'
30
- require 'uri'
31
-
32
- uri = URI.parse(ARGV[0] || 'http://localhost/')
33
- http = Net::HTTP.new(uri.host, uri.port)
34
- http.start {
35
- http.request_get(uri.path) {|res|
36
- print res.body
37
- }
38
- }
39
-
40
- It can be replaced by the following code:
41
-
42
- require 'net/https'
43
- require 'uri'
44
-
45
- uri = URI.parse(ARGV[0] || 'https://localhost/')
46
- http = Net::HTTP.new(uri.host, uri.port)
47
- http.use_ssl = true if uri.scheme == "https" # enable SSL/TLS
48
- http.start {
49
- http.request_get(uri.path) {|res|
50
- print res.body
51
- }
52
- }
53
-
54
- == class Net::HTTP
55
-
56
- === Instance Methods
57
-
58
- : use_ssl?
59
- returns true if use SSL/TLS with HTTP.
60
-
61
- : use_ssl=((|true_or_false|))
62
- sets use_ssl.
63
-
64
- : peer_cert
65
- return the X.509 certificates the server presented.
66
-
67
- : key, key=((|key|))
68
- Sets an OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
69
- (This method is appeared in Michal Rokos's OpenSSL extention.)
70
-
71
- : cert, cert=((|cert|))
72
- Sets an OpenSSL::X509::Certificate object as client certificate
73
- (This method is appeared in Michal Rokos's OpenSSL extention).
74
-
75
- : ca_file, ca_file=((|path|))
76
- Sets path of a CA certification file in PEM format.
77
- The file can contrain several CA certificats.
78
-
79
- : ca_path, ca_path=((|path|))
80
- Sets path of a CA certification directory containing certifications
81
- in PEM format.
82
-
83
- : verify_mode, verify_mode=((|mode|))
84
- Sets the flags for server the certification verification at
85
- begining of SSL/TLS session.
86
- OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER is acceptable.
87
-
88
- : verify_callback, verify_callback=((|proc|))
89
- Sets the verify callback for the server certification verification.
90
-
91
- : verify_depth, verify_depth=((|num|))
92
- Sets the maximum depth for the certificate chain verification.
93
-
94
- : cert_store, cert_store=((|store|))
95
- Sets the X509::Store to verify peer certificate.
96
-
97
- : ssl_timeout, ssl_timeout=((|sec|))
98
- Sets the SSL timeout seconds.
99
-
100
- =end
101
-
102
- require 'net/http'
103
- require 'openssl'
104
-
105
- module Net
106
-
107
- class HTTP
108
- remove_method :use_ssl?
109
- def use_ssl?
110
- @use_ssl
111
- end
112
-
113
- alias use_ssl use_ssl? # for backward compatibility
114
-
115
- # Turn on/off SSL.
116
- # This flag must be set before starting session.
117
- # If you change use_ssl value after session started,
118
- # a Net::HTTP object raises IOError.
119
- def use_ssl=(flag)
120
- flag = (flag ? true : false)
121
- raise IOError, "use_ssl value changed, but session already started" \
122
- if started? and @use_ssl != flag
123
- if flag and not @ssl_context
124
- @ssl_context = OpenSSL::SSL::SSLContext.new
125
- end
126
- @use_ssl = flag
127
- end
128
-
129
- def self.ssl_context_accessor(name)
130
- module_eval(<<-End, __FILE__, __LINE__ + 1)
131
- def #{name}
132
- return nil unless @ssl_context
133
- @ssl_context.#{name}
134
- end
135
-
136
- def #{name}=(val)
137
- @ssl_context ||= OpenSSL::SSL::SSLContext.new
138
- @ssl_context.#{name} = val
139
- end
140
- End
141
- end
142
-
143
- ssl_context_accessor :key
144
- ssl_context_accessor :cert
145
- ssl_context_accessor :ca_file
146
- ssl_context_accessor :ca_path
147
- ssl_context_accessor :verify_mode
148
- ssl_context_accessor :verify_callback
149
- ssl_context_accessor :verify_depth
150
- ssl_context_accessor :cert_store
151
-
152
- def ssl_timeout
153
- return nil unless @ssl_context
154
- @ssl_context.timeout
155
- end
156
-
157
- def ssl_timeout=(sec)
158
- raise ArgumentError, 'Net::HTTP#ssl_timeout= called but use_ssl=false' \
159
- unless use_ssl?
160
- @ssl_context ||= OpenSSL::SSL::SSLContext.new
161
- @ssl_context.timeout = sec
162
- end
163
-
164
- alias timeout= ssl_timeout= # for backward compatibility
165
-
166
- def peer_cert
167
- return nil if not use_ssl? or not @socket
168
- @socket.io.peer_cert
169
- end
170
- end
171
-
172
- end
@@ -1,380 +0,0 @@
1
- # :enddoc:
2
- # = net/protocol.rb
3
- #
4
- #--
5
- # Copyright (c) 1999-2004 Yukihiro Matsumoto
6
- # Copyright (c) 1999-2004 Minero Aoki
7
- #
8
- # written and maintained by Minero Aoki <aamine@loveruby.net>
9
- #
10
- # This program is free software. You can re-distribute and/or
11
- # modify this program under the same terms as Ruby itself,
12
- # Ruby Distribute License or GNU General Public License.
13
- #
14
- # $Id: protocol.rb,v 1.78 2004/08/18 14:44:41 aamine Exp $
15
- #++
16
- #
17
- # WARNING: This file is going to remove.
18
- # Do not rely on the implementation written in this file.
19
- #
20
-
21
- require 'socket'
22
- require 'timeout'
23
-
24
- module Net # :nodoc:
25
-
26
- class Protocol #:nodoc: internal use only
27
- private
28
- def Protocol.protocol_param(name, val)
29
- module_eval(<<-End, __FILE__, __LINE__ + 1)
30
- def #{name}
31
- #{val}
32
- end
33
- End
34
- end
35
- end
36
-
37
-
38
- class ProtocolError < StandardError; end
39
- class ProtoSyntaxError < ProtocolError; end
40
- class ProtoFatalError < ProtocolError; end
41
- class ProtoUnknownError < ProtocolError; end
42
- class ProtoServerError < ProtocolError; end
43
- class ProtoAuthError < ProtocolError; end
44
- class ProtoCommandError < ProtocolError; end
45
- class ProtoRetriableError < ProtocolError; end
46
- ProtocRetryError = ProtoRetriableError
47
-
48
-
49
- class BufferedIO #:nodoc: internal use only
50
- def initialize(io)
51
- @io = io
52
- @read_timeout = 60
53
- @debug_output = nil
54
- @rbuf = ''
55
- end
56
-
57
- attr_reader :io
58
- attr_accessor :read_timeout
59
- attr_accessor :debug_output
60
-
61
- def inspect
62
- "#<#{self.class} io=#{@io}>"
63
- end
64
-
65
- def closed?
66
- @io.closed?
67
- end
68
-
69
- def close
70
- @io.close
71
- end
72
-
73
- #
74
- # Read
75
- #
76
-
77
- public
78
-
79
- def read(len, dest = '', ignore_eof = false)
80
- LOG "reading #{len} bytes..."
81
- read_bytes = 0
82
- begin
83
- while read_bytes + @rbuf.size < len
84
- dest << (s = rbuf_consume(@rbuf.size))
85
- read_bytes += s.size
86
- rbuf_fill
87
- end
88
- dest << (s = rbuf_consume(len - read_bytes))
89
- read_bytes += s.size
90
- rescue EOFError
91
- raise unless ignore_eof
92
- end
93
- LOG "read #{read_bytes} bytes"
94
- dest
95
- end
96
-
97
- def read_all(dest = '')
98
- LOG 'reading all...'
99
- read_bytes = 0
100
- begin
101
- while true
102
- dest << (s = rbuf_consume(@rbuf.size))
103
- read_bytes += s.size
104
- rbuf_fill
105
- end
106
- rescue EOFError
107
- ;
108
- end
109
- LOG "read #{read_bytes} bytes"
110
- dest
111
- end
112
-
113
- def readuntil(terminator, ignore_eof = false)
114
- begin
115
- until idx = @rbuf.index(terminator)
116
- rbuf_fill
117
- end
118
- return rbuf_consume(idx + terminator.size)
119
- rescue EOFError
120
- raise unless ignore_eof
121
- return rbuf_consume(@rbuf.size)
122
- end
123
- end
124
-
125
- def readline
126
- readuntil("\n").chop
127
- end
128
-
129
- private
130
-
131
- def rbuf_fill
132
- timeout(@read_timeout) {
133
- @rbuf << @io.sysread(1024)
134
- }
135
- end
136
-
137
- def rbuf_consume(len)
138
- s = @rbuf.slice!(0, len)
139
- @debug_output << %Q[-> #{s.dump}\n] if @debug_output
140
- s
141
- end
142
-
143
- #
144
- # Write
145
- #
146
-
147
- public
148
-
149
- def write(str)
150
- writing {
151
- write0 str
152
- }
153
- end
154
-
155
- def writeline(str)
156
- writing {
157
- write0 str + "\r\n"
158
- }
159
- end
160
-
161
- private
162
-
163
- def writing
164
- @written_bytes = 0
165
- @debug_output << '<- ' if @debug_output
166
- yield
167
- @debug_output << "\n" if @debug_output
168
- bytes = @written_bytes
169
- @written_bytes = nil
170
- bytes
171
- end
172
-
173
- def write0(str)
174
- @debug_output << str.dump if @debug_output
175
- len = @io.write(str)
176
- @written_bytes += len
177
- len
178
- end
179
-
180
- #
181
- # Logging
182
- #
183
-
184
- private
185
-
186
- def LOG_off
187
- @save_debug_out = @debug_output
188
- @debug_output = nil
189
- end
190
-
191
- def LOG_on
192
- @debug_output = @save_debug_out
193
- end
194
-
195
- def LOG(msg)
196
- return unless @debug_output
197
- @debug_output << msg + "\n"
198
- end
199
- end
200
-
201
-
202
- class InternetMessageIO < BufferedIO #:nodoc: internal use only
203
- def initialize(io)
204
- super
205
- @wbuf = nil
206
- end
207
-
208
- #
209
- # Read
210
- #
211
-
212
- def each_message_chunk
213
- LOG 'reading message...'
214
- LOG_off()
215
- read_bytes = 0
216
- while (line = readuntil("\r\n")) != ".\r\n"
217
- read_bytes += line.size
218
- yield line.sub(/\A\./, '')
219
- end
220
- LOG_on()
221
- LOG "read message (#{read_bytes} bytes)"
222
- end
223
-
224
- # *library private* (cannot handle 'break')
225
- def each_list_item
226
- while (str = readuntil("\r\n")) != ".\r\n"
227
- yield str.chop
228
- end
229
- end
230
-
231
- def write_message_0(src)
232
- prev = @written_bytes
233
- each_crlf_line(src) do |line|
234
- write0 line.sub(/\A\./, '..')
235
- end
236
- @written_bytes - prev
237
- end
238
-
239
- #
240
- # Write
241
- #
242
-
243
- def write_message(src)
244
- LOG "writing message from #{src.class}"
245
- LOG_off()
246
- len = writing {
247
- using_each_crlf_line {
248
- write_message_0 src
249
- }
250
- }
251
- LOG_on()
252
- LOG "wrote #{len} bytes"
253
- len
254
- end
255
-
256
- def write_message_by_block(&block)
257
- LOG 'writing message from block'
258
- LOG_off()
259
- len = writing {
260
- using_each_crlf_line {
261
- begin
262
- block.call(WriteAdapter.new(self, :write_message_0))
263
- rescue LocalJumpError
264
- # allow `break' from writer block
265
- end
266
- }
267
- }
268
- LOG_on()
269
- LOG "wrote #{len} bytes"
270
- len
271
- end
272
-
273
- private
274
-
275
- def using_each_crlf_line
276
- @wbuf = ''
277
- yield
278
- if not @wbuf.empty? # unterminated last line
279
- write0 @wbuf.chomp + "\r\n"
280
- elsif @written_bytes == 0 # empty src
281
- write0 "\r\n"
282
- end
283
- write0 ".\r\n"
284
- @wbuf = nil
285
- end
286
-
287
- def each_crlf_line(src)
288
- buffer_filling(@wbuf, src) do
289
- while line = @wbuf.slice!(/\A.*(?:\n|\r\n|\r(?!\z))/n)
290
- yield line.chomp("\n") + "\r\n"
291
- end
292
- end
293
- end
294
-
295
- def buffer_filling(buf, src)
296
- case src
297
- when String # for speeding up.
298
- 0.step(src.size - 1, 1024) do |i|
299
- buf << src[i, 1024]
300
- yield
301
- end
302
- when File # for speeding up.
303
- while s = src.read(1024)
304
- buf << s
305
- yield
306
- end
307
- else # generic reader
308
- src.each do |s|
309
- buf << s
310
- yield if buf.size > 1024
311
- end
312
- yield unless buf.empty?
313
- end
314
- end
315
- end
316
-
317
-
318
- #
319
- # The writer adapter class
320
- #
321
- class WriteAdapter
322
- def initialize(socket, method)
323
- @socket = socket
324
- @method_id = method
325
- end
326
-
327
- def inspect
328
- "#<#{self.class} socket=#{@socket.inspect}>"
329
- end
330
-
331
- def write(str)
332
- @socket.__send__(@method_id, str)
333
- end
334
-
335
- alias print write
336
-
337
- def <<(str)
338
- write str
339
- self
340
- end
341
-
342
- def puts(str = '')
343
- write str.chomp("\n") + "\n"
344
- end
345
-
346
- def printf(*args)
347
- write sprintf(*args)
348
- end
349
- end
350
-
351
-
352
- class ReadAdapter #:nodoc: internal use only
353
- def initialize(block)
354
- @block = block
355
- end
356
-
357
- def inspect
358
- "#<#{self.class}>"
359
- end
360
-
361
- def <<(str)
362
- call_block(str, &@block) if @block
363
- end
364
-
365
- private
366
-
367
- # This method is needed because @block must be called by yield,
368
- # not Proc#call. You can see difference when using `break' in
369
- # the block.
370
- def call_block(str)
371
- yield str
372
- end
373
- end
374
-
375
-
376
- module NetPrivate #:nodoc: obsolete
377
- Socket = ::Net::InternetMessageIO
378
- end
379
-
380
- end # module Net