mechanize 0.7.7 → 0.7.8

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/History.txt CHANGED
@@ -1,5 +1,13 @@
1
1
  = Mechanize CHANGELOG
2
2
 
3
+ === 0.7.8
4
+
5
+ * Bug Fixes:
6
+ * Fixed bug when receiving a 304 response (HTTPNotModified) on a page not
7
+ cached in history.
8
+ * #21428 Default to HTML parser for 'application/xhtml+xml' content-type.
9
+ * Fixed an issue where redirects were resending posted data
10
+
3
11
  === 0.7.7
4
12
 
5
13
  * New Features:
data/Manifest.txt CHANGED
@@ -43,6 +43,7 @@ lib/www/mechanize/pluggable_parsers.rb
43
43
  lib/www/mechanize/redirect_limit_reached_error.rb
44
44
  lib/www/mechanize/response_code_error.rb
45
45
  lib/www/mechanize/unsupported_scheme_error.rb
46
+ mechanize.gemspec
46
47
  test/data/htpasswd
47
48
  test/data/server.crt
48
49
  test/data/server.csr
@@ -94,6 +95,7 @@ test/test_authenticate.rb
94
95
  test/test_bad_links.rb
95
96
  test/test_blank_form.rb
96
97
  test/test_checkboxes.rb
98
+ test/test_content_type.rb
97
99
  test/test_cookie_class.rb
98
100
  test/test_cookie_jar.rb
99
101
  test/test_cookies.rb
data/Rakefile CHANGED
@@ -4,24 +4,7 @@ require 'hoe'
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "lib")
5
5
  require 'mechanize'
6
6
 
7
- class MechHoe < Hoe
8
- def define_tasks
9
- super
10
- desc "Update SSL Certificate"
11
- Rake::Task.define_task('ssl_cert') do |p|
12
- sh "openssl genrsa -des3 -out server.key 1024"
13
- sh "openssl req -new -key server.key -out server.csr"
14
- sh "cp server.key server.key.org"
15
- sh "openssl rsa -in server.key.org -out server.key"
16
- sh "openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt"
17
- sh "cp server.key server.pem"
18
- sh "mv server.key server.csr server.crt server.pem test/data/"
19
- sh "rm server.key.org"
20
- end
21
- end
22
- end
23
-
24
- MechHoe.new('mechanize', WWW::Mechanize::VERSION) do |p|
7
+ HOE = Hoe.new('mechanize', WWW::Mechanize::VERSION) do |p|
25
8
  p.rubyforge_name = 'mechanize'
26
9
  p.author = 'Aaron Patterson'
27
10
  p.email = 'aaronp@rubyforge.org'
@@ -29,3 +12,24 @@ MechHoe.new('mechanize', WWW::Mechanize::VERSION) do |p|
29
12
  p.extra_deps = [['hpricot', '>= 0.5.0']]
30
13
  end
31
14
 
15
+ desc "Update SSL Certificate"
16
+ task('ssl_cert') do |p|
17
+ sh "openssl genrsa -des3 -out server.key 1024"
18
+ sh "openssl req -new -key server.key -out server.csr"
19
+ sh "cp server.key server.key.org"
20
+ sh "openssl rsa -in server.key.org -out server.key"
21
+ sh "openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt"
22
+ sh "cp server.key server.pem"
23
+ sh "mv server.key server.csr server.crt server.pem test/data/"
24
+ sh "rm server.key.org"
25
+ end
26
+
27
+ namespace :gem do
28
+ desc 'Generate a gem spec'
29
+ task :spec do
30
+ File.open("#{HOE.name}.gemspec", 'w') do |f|
31
+ HOE.spec.version = "#{HOE.version}.#{Time.now.strftime("%Y%m%d%H%M%S")}"
32
+ f.write(HOE.spec.to_ruby)
33
+ end
34
+ end
35
+ end
data/lib/www/mechanize.rb CHANGED
@@ -43,7 +43,7 @@ module WWW
43
43
  class Mechanize
44
44
  ##
45
45
  # The version of Mechanize you are using.
46
- VERSION = '0.7.7'
46
+ VERSION = '0.7.8'
47
47
 
48
48
  ##
49
49
  # User Agent aliases
@@ -716,14 +716,14 @@ module WWW
716
716
 
717
717
  if res_klass == Net::HTTPNotModified
718
718
  log.debug("Got cached page") if log
719
- return visited_page(uri)
719
+ return visited_page(uri) || page
720
720
  elsif res_klass <= Net::HTTPRedirection
721
721
  return page unless follow_redirect?
722
722
  log.info("follow redirect to: #{ response['Location'] }") if log
723
723
  from_uri = page.uri
724
724
  abs_uri = to_absolute_uri(response['Location'].to_s, page)
725
725
  raise RedirectLimitReachedError.new(page, redirects) if redirects + 1 > redirection_limit
726
- page = fetch_page(abs_uri, fetch_request(abs_uri), page, request_data, redirects + 1)
726
+ page = fetch_page(abs_uri, fetch_request(abs_uri), page, [], redirects + 1)
727
727
  @history.push(page, from_uri)
728
728
  return page
729
729
  elsif res_klass <= Net::HTTPUnauthorized
@@ -27,7 +27,7 @@ module WWW
27
27
  @mech ||= mech
28
28
 
29
29
  raise Mechanize::ContentTypeError.new(response['content-type']) unless
30
- content_type() =~ /^text\/html/
30
+ content_type() =~ /^(text\/html)|(application\/xhtml\+xml)/
31
31
 
32
32
  @parser = @links = @forms = @meta = @bases = @frames = @iframes = nil
33
33
  end
@@ -45,6 +45,7 @@ module WWW
45
45
  class PluggableParser
46
46
  CONTENT_TYPES = {
47
47
  :html => 'text/html',
48
+ :xhtml => 'application/xhtml+xml',
48
49
  :pdf => 'application/pdf',
49
50
  :csv => 'text/csv',
50
51
  :xml => 'text/xml',
@@ -53,7 +54,8 @@ module WWW
53
54
  attr_accessor :default
54
55
 
55
56
  def initialize
56
- @parsers = { CONTENT_TYPES[:html] => Page }
57
+ @parsers = { CONTENT_TYPES[:html] => Page,
58
+ CONTENT_TYPES[:xhtml] => Page }
57
59
  @default = File
58
60
  end
59
61
 
@@ -67,6 +69,11 @@ module WWW
67
69
 
68
70
  def html=(klass)
69
71
  register_parser(CONTENT_TYPES[:html], klass)
72
+ register_parser(CONTENT_TYPES[:xhtml], klass)
73
+ end
74
+
75
+ def xhtml=(klass)
76
+ register_parser(CONTENT_TYPES[:xhtml], klass)
70
77
  end
71
78
 
72
79
  def pdf=(klass)
data/mechanize.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{mechanize}
3
+ s.version = "0.7.7.20080826145538"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Aaron Patterson"]
7
+ s.date = %q{2008-08-26}
8
+ s.description = %q{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.}
9
+ s.email = %q{aaronp@rubyforge.org}
10
+ s.extra_rdoc_files = ["EXAMPLES.txt", "FAQ.txt", "GUIDE.txt", "History.txt", "LICENSE.txt", "Manifest.txt", "NOTES.txt", "README.txt"]
11
+ s.files = ["EXAMPLES.txt", "FAQ.txt", "GUIDE.txt", "History.txt", "LICENSE.txt", "Manifest.txt", "NOTES.txt", "README.txt", "Rakefile", "eg/flickr_upload.rb", "eg/mech-dump.rb", "eg/proxy_req.rb", "eg/rubyforge.rb", "eg/spider.rb", "lib/mechanize.rb", "lib/www/mechanize.rb", "lib/www/mechanize/content_type_error.rb", "lib/www/mechanize/cookie.rb", "lib/www/mechanize/cookie_jar.rb", "lib/www/mechanize/file.rb", "lib/www/mechanize/file_saver.rb", "lib/www/mechanize/form.rb", "lib/www/mechanize/form/button.rb", "lib/www/mechanize/form/check_box.rb", "lib/www/mechanize/form/field.rb", "lib/www/mechanize/form/file_upload.rb", "lib/www/mechanize/form/image_button.rb", "lib/www/mechanize/form/multi_select_list.rb", "lib/www/mechanize/form/option.rb", "lib/www/mechanize/form/radio_button.rb", "lib/www/mechanize/form/select_list.rb", "lib/www/mechanize/headers.rb", "lib/www/mechanize/history.rb", "lib/www/mechanize/inspect.rb", "lib/www/mechanize/list.rb", "lib/www/mechanize/monkey_patch.rb", "lib/www/mechanize/page.rb", "lib/www/mechanize/page/base.rb", "lib/www/mechanize/page/frame.rb", "lib/www/mechanize/page/link.rb", "lib/www/mechanize/page/meta.rb", "lib/www/mechanize/pluggable_parsers.rb", "lib/www/mechanize/redirect_limit_reached_error.rb", "lib/www/mechanize/response_code_error.rb", "lib/www/mechanize/unsupported_scheme_error.rb", "mechanize.gemspec", "test/data/htpasswd", "test/data/server.crt", "test/data/server.csr", "test/data/server.key", "test/data/server.pem", "test/helper.rb", "test/htdocs/alt_text.html", "test/htdocs/bad_form_test.html", "test/htdocs/button.jpg", "test/htdocs/empty_form.html", "test/htdocs/file_upload.html", "test/htdocs/find_link.html", "test/htdocs/form_multi_select.html", "test/htdocs/form_multival.html", "test/htdocs/form_no_action.html", "test/htdocs/form_no_input_name.html", "test/htdocs/form_select.html", "test/htdocs/form_select_all.html", "test/htdocs/form_select_none.html", "test/htdocs/form_select_noopts.html", "test/htdocs/form_set_fields.html", "test/htdocs/form_test.html", "test/htdocs/frame_test.html", "test/htdocs/google.html", "test/htdocs/iframe_test.html", "test/htdocs/index.html", "test/htdocs/link with space.html", "test/htdocs/meta_cookie.html", "test/htdocs/no_title_test.html", "test/htdocs/relative/tc_relative_links.html", "test/htdocs/tc_bad_links.html", "test/htdocs/tc_base_link.html", "test/htdocs/tc_blank_form.html", "test/htdocs/tc_checkboxes.html", "test/htdocs/tc_encoded_links.html", "test/htdocs/tc_follow_meta.html", "test/htdocs/tc_form_action.html", "test/htdocs/tc_links.html", "test/htdocs/tc_no_attributes.html", "test/htdocs/tc_pretty_print.html", "test/htdocs/tc_radiobuttons.html", "test/htdocs/tc_referer.html", "test/htdocs/tc_relative_links.html", "test/htdocs/tc_textarea.html", "test/htdocs/unusual______.html", "test/servlets.rb", "test/ssl_server.rb", "test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb"]
12
+ s.has_rdoc = true
13
+ s.homepage = %q{ http://mechanize.rubyforge.org/}
14
+ s.rdoc_options = ["--main", "README.txt"]
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = %q{mechanize}
17
+ s.rubygems_version = %q{1.2.0}
18
+ s.summary = %q{Mechanize provides automated web-browsing}
19
+ s.test_files = ["test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb"]
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 2
24
+
25
+ if current_version >= 3 then
26
+ s.add_runtime_dependency(%q<hpricot>, [">= 0.5.0"])
27
+ s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
28
+ else
29
+ s.add_dependency(%q<hpricot>, [">= 0.5.0"])
30
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<hpricot>, [">= 0.5.0"])
34
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class TestContentType < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ end
7
+
8
+ def test_application_xhtml_xml
9
+ url = 'http://localhost/content_type_test?ct=application/xhtml%2Bxml'
10
+ page = @agent.get url
11
+ assert_equal WWW::Mechanize::Page, page.class, "xhtml docs should return a Page"
12
+ end
13
+ end
@@ -22,11 +22,18 @@ class TestGetHeaders < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  def test_if_modified_since_header
25
- value = Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")
25
+ value = (Time.now - 600).strftime("%a, %d %b %Y %H:%M:%S %z")
26
26
  page = @agent.get(:url => 'http://localhost/http_headers', :headers => { :if_modified_since => value})
27
27
  assert_header(page, 'if-modified-since' => value)
28
28
  end
29
29
 
30
+ def test_if_modified_since_response
31
+ value = (Time.now - 600).strftime("%a, %d %b %Y %H:%M:%S %z")
32
+ page = @agent.get(:url => 'http://localhost/if_modified_since', :headers => { :if_modified_since => value})
33
+ assert_equal "304", page.code
34
+ assert_equal "0", page.header['content-length']
35
+ end
36
+
30
37
  def test_string_header
31
38
  page = @agent.get(:url => 'http://localhost/http_headers', :headers => { "X-BS-French-Header" => 'Ou est la bibliotheque?'})
32
39
  assert_header(page, 'x-bs-french-header' => 'Ou est la bibliotheque?')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mechanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-25 00:00:00 -07:00
12
+ date: 2008-08-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -93,6 +93,7 @@ files:
93
93
  - lib/www/mechanize/redirect_limit_reached_error.rb
94
94
  - lib/www/mechanize/response_code_error.rb
95
95
  - lib/www/mechanize/unsupported_scheme_error.rb
96
+ - mechanize.gemspec
96
97
  - test/data/htpasswd
97
98
  - test/data/server.crt
98
99
  - test/data/server.csr
@@ -144,6 +145,7 @@ files:
144
145
  - test/test_bad_links.rb
145
146
  - test/test_blank_form.rb
146
147
  - test/test_checkboxes.rb
148
+ - test/test_content_type.rb
147
149
  - test/test_cookie_class.rb
148
150
  - test/test_cookie_jar.rb
149
151
  - test/test_cookies.rb
@@ -221,6 +223,7 @@ test_files:
221
223
  - test/test_bad_links.rb
222
224
  - test/test_blank_form.rb
223
225
  - test/test_checkboxes.rb
226
+ - test/test_content_type.rb
224
227
  - test/test_cookie_class.rb
225
228
  - test/test_cookie_jar.rb
226
229
  - test/test_cookies.rb