mechanize 0.6.6 → 0.6.7
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.
- data/CHANGELOG.txt +5 -0
- data/lib/mechanize.rb +22 -19
- data/lib/mechanize/cookie.rb +2 -1
- data/test/tc_cookie_class.rb +2 -2
- data/test/tc_cookies.rb +3 -3
- data/test/test_includes.rb +2 -1
- metadata +148 -149
data/CHANGELOG.txt
CHANGED
data/lib/mechanize.rb
CHANGED
@@ -62,7 +62,7 @@ class Mechanize
|
|
62
62
|
##
|
63
63
|
# The version of Mechanize you are using.
|
64
64
|
|
65
|
-
VERSION = '0.6.
|
65
|
+
VERSION = '0.6.7'
|
66
66
|
|
67
67
|
##
|
68
68
|
# User Agent aliases
|
@@ -391,6 +391,8 @@ class Mechanize
|
|
391
391
|
end
|
392
392
|
end
|
393
393
|
|
394
|
+
http_obj.start unless http_obj.started?
|
395
|
+
|
394
396
|
request = set_headers(uri, request, cur_page)
|
395
397
|
|
396
398
|
# Log specified headers for the request
|
@@ -405,7 +407,7 @@ class Mechanize
|
|
405
407
|
http_obj.read_timeout = @read_timeout if @read_timeout
|
406
408
|
|
407
409
|
# Send the request
|
408
|
-
http_obj.request(request, *request_data) {|response|
|
410
|
+
response = http_obj.request(request, *request_data) {|response|
|
409
411
|
if log
|
410
412
|
response.each_header {|k,v|
|
411
413
|
log.debug("response-header: #{ k } => #{ v }")
|
@@ -460,27 +462,28 @@ class Mechanize
|
|
460
462
|
end
|
461
463
|
}
|
462
464
|
|
463
|
-
|
465
|
+
}
|
464
466
|
|
465
|
-
|
467
|
+
log.info("status: #{ page.code }") if log
|
466
468
|
|
467
|
-
|
469
|
+
res_klass = Net::HTTPResponse::CODE_TO_OBJ[page.code.to_s]
|
468
470
|
|
469
|
-
|
470
|
-
log.debug("Got cached page") if log
|
471
|
-
return visited_page(uri)
|
472
|
-
elsif res_klass <= Net::HTTPRedirection
|
473
|
-
return page unless follow_redirect?
|
474
|
-
log.info("follow redirect to: #{ response['Location'] }") if log
|
475
|
-
from_uri = page.uri
|
476
|
-
abs_uri = to_absolute_uri(response['Location'].to_s, page)
|
477
|
-
page = fetch_page(abs_uri, fetch_request(abs_uri), page)
|
478
|
-
@history.push(page, from_uri)
|
479
|
-
return page
|
480
|
-
end
|
471
|
+
return page if res_klass <= Net::HTTPSuccess
|
481
472
|
|
482
|
-
|
483
|
-
|
473
|
+
if res_klass == Net::HTTPNotModified
|
474
|
+
log.debug("Got cached page") if log
|
475
|
+
return visited_page(uri)
|
476
|
+
elsif res_klass <= Net::HTTPRedirection
|
477
|
+
return page unless follow_redirect?
|
478
|
+
log.info("follow redirect to: #{ response['Location'] }") if log
|
479
|
+
from_uri = page.uri
|
480
|
+
abs_uri = to_absolute_uri(response['Location'].to_s, page)
|
481
|
+
page = fetch_page(abs_uri, fetch_request(abs_uri), page)
|
482
|
+
@history.push(page, from_uri)
|
483
|
+
return page
|
484
|
+
end
|
485
|
+
|
486
|
+
raise ResponseCodeError.new(page), "Unhandled response", caller
|
484
487
|
end
|
485
488
|
|
486
489
|
def self.build_query_string(parameters)
|
data/lib/mechanize/cookie.rb
CHANGED
data/test/tc_cookie_class.rb
CHANGED
@@ -171,7 +171,7 @@ class CookieClassTest < Test::Unit::TestCase
|
|
171
171
|
|
172
172
|
# If no path was given, use the one from the URL
|
173
173
|
def test_cookie_using_url_path
|
174
|
-
url = URI.parse('http://rubyforge.org/login')
|
174
|
+
url = URI.parse('http://rubyforge.org/login.php')
|
175
175
|
cookie_params = {}
|
176
176
|
cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
|
177
177
|
cookie_params['path'] = 'path=/'
|
@@ -196,7 +196,7 @@ class CookieClassTest < Test::Unit::TestCase
|
|
196
196
|
assert_not_nil(cookie)
|
197
197
|
assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
|
198
198
|
assert_equal('rubyforge.org', cookie.domain)
|
199
|
-
assert_equal('/
|
199
|
+
assert_equal('/', cookie.path)
|
200
200
|
|
201
201
|
# if expires was set, make sure we parsed it
|
202
202
|
if c.find { |k| k == 'expires' }
|
data/test/tc_cookies.rb
CHANGED
@@ -15,7 +15,7 @@ class CookiesMechTest < Test::Unit::TestCase
|
|
15
15
|
def test_send_cookies
|
16
16
|
page = @agent.get("http://localhost:#{PORT}/many_cookies")
|
17
17
|
page = @agent.get("http://localhost:#{PORT}/send_cookies")
|
18
|
-
assert_equal(
|
18
|
+
assert_equal(3, page.links.length)
|
19
19
|
assert_not_nil(page.links.find { |l| l.text == "name:Aaron" })
|
20
20
|
assert_not_nil(page.links.find { |l| l.text == "no_expires:nope" })
|
21
21
|
end
|
@@ -57,7 +57,7 @@ class CookiesMechTest < Test::Unit::TestCase
|
|
57
57
|
no_path_cookie = @agent.cookies.find { |k| k.name == "no_path" }
|
58
58
|
assert_not_nil(no_path_cookie, "No path cookie is nil")
|
59
59
|
assert_equal("no_path", no_path_cookie.value)
|
60
|
-
assert_equal("/
|
60
|
+
assert_equal("/", no_path_cookie.path)
|
61
61
|
assert_equal(true, Time.now < no_path_cookie.expires)
|
62
62
|
end
|
63
63
|
|
@@ -88,7 +88,7 @@ class CookiesMechTest < Test::Unit::TestCase
|
|
88
88
|
no_path_cookie = @agent.cookies.find { |k| k.name == "no_path" }
|
89
89
|
assert_not_nil(no_path_cookie, "No path cookie is nil")
|
90
90
|
assert_equal("no_path", no_path_cookie.value)
|
91
|
-
assert_equal("/
|
91
|
+
assert_equal("/", no_path_cookie.path)
|
92
92
|
assert_equal(true, Time.now < no_path_cookie.expires)
|
93
93
|
end
|
94
94
|
|
data/test/test_includes.rb
CHANGED
metadata
CHANGED
@@ -1,178 +1,177 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.2
|
3
3
|
specification_version: 1
|
4
4
|
name: mechanize
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.6.
|
7
|
-
date: 2007-03-
|
6
|
+
version: 0.6.7
|
7
|
+
date: 2007-03-27 00:00:00 -07:00
|
8
8
|
summary: Mechanize provides automated web-browsing
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: aaronp@rubyforge.org
|
12
12
|
homepage: http://mechanize.rubyforge.org/
|
13
13
|
rubyforge_project: mechanize
|
14
|
-
description:
|
15
|
-
Mechanize automatically stores and sends cookies, follows redirects, can follow
|
16
|
-
links, and submit forms. Form fields can be populated and submitted. Mechanize
|
17
|
-
also keeps track of the sites that you have visited as a history."
|
14
|
+
description: The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follows redirects, can follow links, and submit forms. Form fields can be populated and submitted. Mechanize also keeps track of the sites that you have visited as a history.
|
18
15
|
autorequire:
|
19
16
|
default_executable:
|
20
17
|
bindir: bin
|
21
18
|
has_rdoc: true
|
22
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
23
20
|
requirements:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
28
24
|
version:
|
29
25
|
platform: ruby
|
30
26
|
signing_key:
|
31
27
|
cert_chain:
|
32
28
|
post_install_message:
|
33
29
|
authors:
|
34
|
-
|
30
|
+
- Aaron Patterson
|
35
31
|
files:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
32
|
+
- CHANGELOG.txt
|
33
|
+
- EXAMPLES.txt
|
34
|
+
- GUIDE.txt
|
35
|
+
- LICENSE.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- NOTES.txt
|
38
|
+
- README.txt
|
39
|
+
- Rakefile
|
40
|
+
- eg/flickr_upload.rb
|
41
|
+
- eg/mech-dump.rb
|
42
|
+
- eg/proxy_req.rb
|
43
|
+
- eg/rubyforge.rb
|
44
|
+
- eg/spider.rb
|
45
|
+
- lib/mechanize.rb
|
46
|
+
- lib/mechanize/cookie.rb
|
47
|
+
- lib/mechanize/errors.rb
|
48
|
+
- lib/mechanize/form.rb
|
49
|
+
- lib/mechanize/form_elements.rb
|
50
|
+
- lib/mechanize/history.rb
|
51
|
+
- lib/mechanize/inspect.rb
|
52
|
+
- lib/mechanize/list.rb
|
53
|
+
- lib/mechanize/net-overrides/net/http.rb
|
54
|
+
- lib/mechanize/net-overrides/net/https.rb
|
55
|
+
- lib/mechanize/net-overrides/net/protocol.rb
|
56
|
+
- lib/mechanize/page.rb
|
57
|
+
- lib/mechanize/page_elements.rb
|
58
|
+
- lib/mechanize/parsers/rexml_page.rb
|
59
|
+
- lib/mechanize/pluggable_parsers.rb
|
60
|
+
- lib/mechanize/rexml.rb
|
61
|
+
- setup.rb
|
62
|
+
- test/data/htpasswd
|
63
|
+
- test/data/server.crt
|
64
|
+
- test/data/server.csr
|
65
|
+
- test/data/server.key
|
66
|
+
- test/data/server.pem
|
67
|
+
- test/htdocs/alt_text.html
|
68
|
+
- test/htdocs/bad_form_test.html
|
69
|
+
- test/htdocs/button.jpg
|
70
|
+
- test/htdocs/empty_form.html
|
71
|
+
- test/htdocs/file_upload.html
|
72
|
+
- test/htdocs/find_link.html
|
73
|
+
- test/htdocs/form_multi_select.html
|
74
|
+
- test/htdocs/form_multival.html
|
75
|
+
- test/htdocs/form_no_action.html
|
76
|
+
- test/htdocs/form_no_input_name.html
|
77
|
+
- test/htdocs/form_select.html
|
78
|
+
- test/htdocs/form_select_all.html
|
79
|
+
- test/htdocs/form_select_none.html
|
80
|
+
- test/htdocs/form_select_noopts.html
|
81
|
+
- test/htdocs/form_set_fields.html
|
82
|
+
- test/htdocs/form_test.html
|
83
|
+
- test/htdocs/frame_test.html
|
84
|
+
- test/htdocs/google.html
|
85
|
+
- test/htdocs/iframe_test.html
|
86
|
+
- test/htdocs/index.html
|
87
|
+
- test/htdocs/link with space.html
|
88
|
+
- test/htdocs/no_title_test.html
|
89
|
+
- test/htdocs/relative/tc_relative_links.html
|
90
|
+
- test/htdocs/tc_bad_links.html
|
91
|
+
- test/htdocs/tc_checkboxes.html
|
92
|
+
- test/htdocs/tc_encoded_links.html
|
93
|
+
- test/htdocs/tc_form_action.html
|
94
|
+
- test/htdocs/tc_links.html
|
95
|
+
- test/htdocs/tc_no_attributes.html
|
96
|
+
- test/htdocs/tc_pretty_print.html
|
97
|
+
- test/htdocs/tc_radiobuttons.html
|
98
|
+
- test/htdocs/tc_referer.html
|
99
|
+
- test/htdocs/tc_relative_links.html
|
100
|
+
- test/htdocs/tc_textarea.html
|
101
|
+
- test/ssl_server.rb
|
102
|
+
- test/tc_authenticate.rb
|
103
|
+
- test/tc_bad_links.rb
|
104
|
+
- test/tc_checkboxes.rb
|
105
|
+
- test/tc_cookie_class.rb
|
106
|
+
- test/tc_cookie_jar.rb
|
107
|
+
- test/tc_cookies.rb
|
108
|
+
- test/tc_encoded_links.rb
|
109
|
+
- test/tc_errors.rb
|
110
|
+
- test/tc_form_action.rb
|
111
|
+
- test/tc_form_as_hash.rb
|
112
|
+
- test/tc_form_button.rb
|
113
|
+
- test/tc_form_no_inputname.rb
|
114
|
+
- test/tc_forms.rb
|
115
|
+
- test/tc_frames.rb
|
116
|
+
- test/tc_gzipping.rb
|
117
|
+
- test/tc_history.rb
|
118
|
+
- test/tc_html_unscape_forms.rb
|
119
|
+
- test/tc_if_modified_since.rb
|
120
|
+
- test/tc_links.rb
|
121
|
+
- test/tc_mech.rb
|
122
|
+
- test/tc_multi_select.rb
|
123
|
+
- test/tc_no_attributes.rb
|
124
|
+
- test/tc_page.rb
|
125
|
+
- test/tc_pluggable_parser.rb
|
126
|
+
- test/tc_post_form.rb
|
127
|
+
- test/tc_pretty_print.rb
|
128
|
+
- test/tc_proxy.rb
|
129
|
+
- test/tc_radiobutton.rb
|
130
|
+
- test/tc_referer.rb
|
131
|
+
- test/tc_relative_links.rb
|
132
|
+
- test/tc_response_code.rb
|
133
|
+
- test/tc_save_file.rb
|
134
|
+
- test/tc_select.rb
|
135
|
+
- test/tc_select_all.rb
|
136
|
+
- test/tc_select_none.rb
|
137
|
+
- test/tc_select_noopts.rb
|
138
|
+
- test/tc_set_fields.rb
|
139
|
+
- test/tc_ssl_server.rb
|
140
|
+
- test/tc_subclass.rb
|
141
|
+
- test/tc_textarea.rb
|
142
|
+
- test/tc_upload.rb
|
143
|
+
- test/tc_watches.rb
|
144
|
+
- test/test_all.rb
|
145
|
+
- test/test_includes.rb
|
146
|
+
- test/test_servlets.rb
|
151
147
|
test_files:
|
152
|
-
|
148
|
+
- test/test_all.rb
|
153
149
|
rdoc_options: []
|
150
|
+
|
154
151
|
extra_rdoc_files: []
|
152
|
+
|
155
153
|
executables: []
|
154
|
+
|
156
155
|
extensions: []
|
156
|
+
|
157
157
|
requirements: []
|
158
|
+
|
158
159
|
dependencies:
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
version: 1.2.0
|
178
|
-
version:
|
160
|
+
- !ruby/object:Gem::Dependency
|
161
|
+
name: hpricot
|
162
|
+
version_requirement:
|
163
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: 0.0.0
|
168
|
+
version:
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: hoe
|
171
|
+
version_requirement:
|
172
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: 1.2.0
|
177
|
+
version:
|