paperclip-storage-ftp 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +20 -0
  3. data/Gemfile +6 -0
  4. data/README.md +6 -1
  5. data/Rakefile +1 -1
  6. data/gemfiles/Gemfile.paperclip-2.x +11 -0
  7. data/gemfiles/Gemfile.paperclip-3.x +11 -0
  8. data/lib/paperclip/storage/ftp.rb +6 -1
  9. data/lib/paperclip/storage/ftp/server.rb +16 -3
  10. data/paperclip-storage-ftp.gemspec +1 -1
  11. data/spec/integration_spec.rb +32 -0
  12. data/spec/paperclip/storage/ftp/server_spec.rb +23 -7
  13. data/spec/paperclip/storage/ftp_spec.rb +13 -1
  14. data/spec/support/integration/avatar.jpg +0 -0
  15. data/spec/support/integration/ftp_server.rb +27 -0
  16. data/spec/support/integration/user.rb +31 -0
  17. data/vendor/apache-ftpserver/LICENSE +202 -0
  18. data/vendor/apache-ftpserver/LICENSE.slf4j.txt +28 -0
  19. data/vendor/apache-ftpserver/LICENSE.springframework.txt +177 -0
  20. data/vendor/apache-ftpserver/NOTICE +54 -0
  21. data/vendor/apache-ftpserver/README.txt +73 -0
  22. data/vendor/apache-ftpserver/bin/appendcp.bat +22 -0
  23. data/vendor/apache-ftpserver/bin/ftpd.bat +63 -0
  24. data/vendor/apache-ftpserver/bin/ftpd.exe +0 -0
  25. data/vendor/apache-ftpserver/bin/ftpd.sh +140 -0
  26. data/vendor/apache-ftpserver/bin/ftpdw.exe +0 -0
  27. data/vendor/apache-ftpserver/bin/service.bat +152 -0
  28. data/vendor/apache-ftpserver/common/classes/log4j.properties +25 -0
  29. data/vendor/apache-ftpserver/common/lib/README.txt +4 -0
  30. data/vendor/apache-ftpserver/common/lib/aopalliance-1.0.jar +0 -0
  31. data/vendor/apache-ftpserver/common/lib/ftplet-api-1.0.6.jar +0 -0
  32. data/vendor/apache-ftpserver/common/lib/ftpserver-core-1.0.6.jar +0 -0
  33. data/vendor/apache-ftpserver/common/lib/jcl-over-slf4j-1.5.2.jar +0 -0
  34. data/vendor/apache-ftpserver/common/lib/log4j-1.2.14.jar +0 -0
  35. data/vendor/apache-ftpserver/common/lib/mina-core-2.0.4.jar +0 -0
  36. data/vendor/apache-ftpserver/common/lib/slf4j-api-1.5.2.jar +0 -0
  37. data/vendor/apache-ftpserver/common/lib/slf4j-log4j12-1.5.2.jar +0 -0
  38. data/vendor/apache-ftpserver/common/lib/spring-beans-2.5.5.jar +0 -0
  39. data/vendor/apache-ftpserver/common/lib/spring-context-2.5.5.jar +0 -0
  40. data/vendor/apache-ftpserver/common/lib/spring-core-2.5.5.jar +0 -0
  41. data/vendor/apache-ftpserver/res/conf/README.txt +3 -0
  42. data/vendor/apache-ftpserver/res/conf/ftpd-full.xml +103 -0
  43. data/vendor/apache-ftpserver/res/conf/ftpd-typical.xml +30 -0
  44. data/vendor/apache-ftpserver/res/conf/users.properties +37 -0
  45. data/vendor/apache-ftpserver/res/ftp-db.sql +29 -0
  46. data/vendor/apache-ftpserver/res/ftpserver.jks +0 -0
  47. metadata +44 -3
data/.gitignore CHANGED
@@ -17,3 +17,6 @@ test/version_tmp
17
17
  tmp
18
18
  .rspec
19
19
  .rvmrc
20
+ vendor/apache-ftpserver/res/ftpd.pid*
21
+ vendor/apache-ftpserver/res/home/*
22
+ vendor/apache-ftpserver/res/log/*
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ gemfile:
11
+ - gemfiles/Gemfile.paperclip-2.x
12
+ - gemfiles/Gemfile.paperclip-3.x
13
+ matrix:
14
+ exclude:
15
+ - rvm: 1.8.7
16
+ gemfile: gemfiles/Gemfile.paperclip-3.x
17
+ - rvm: jruby-18mode
18
+ gemfile: gemfiles/Gemfile.paperclip-3.x
19
+ - rvm: rbx-18mode
20
+ gemfile: gemfiles/Gemfile.paperclip-3.x
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in paperclip-multistorage.gemspec
4
4
  gemspec
5
+
6
+ group :integration_test do
7
+ gem "daemon_controller", :platforms => :ruby
8
+ gem "activerecord", :platforms => :ruby
9
+ gem "sqlite3", :platforms => :ruby
10
+ end
data/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  Allow [Paperclip](https://github.com/thoughtbot/paperclip) attachments
4
4
  to be stored on FTP servers.
5
5
 
6
+ ## Build status
7
+
8
+ [![Build Status](https://secure.travis-ci.org/xing/paperclip-storage-ftp.png)](http://travis-ci.org/xing/paperclip-storage-ftp)
9
+
6
10
  ## Installation
7
11
 
8
12
  Add this line to your application's Gemfile:
@@ -44,7 +48,8 @@ In your model:
44
48
  {
45
49
  :host => "ftp1.example.com",
46
50
  :user => "foo",
47
- :password => "bar"
51
+ :password => "bar",
52
+ :port => 21 # optional
48
53
  },
49
54
  # Add more servers if needed
50
55
  {
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
- #!/usr/bin/env rake
2
1
  require "bundler/gem_tasks"
3
2
  require "rspec/core/rake_task"
4
3
 
5
4
  RSpec::Core::RakeTask.new do |t|
6
5
  t.rspec_opts = "--color"
6
+ t.rspec_opts += " --tag ~integration" if RUBY_PLATFORM == "java"
7
7
  end
8
8
 
9
9
  task :default => :spec
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :path => '..'
4
+
5
+ gem "paperclip", "~>2.0"
6
+
7
+ group :integration_test do
8
+ gem "daemon_controller", :platforms => :ruby
9
+ gem "activerecord", :platforms => :ruby
10
+ gem "sqlite3", :platforms => :ruby
11
+ end
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :path => '..'
4
+
5
+ gem "paperclip", "~>3.0"
6
+
7
+ group :integration_test do
8
+ gem "daemon_controller", :platforms => :ruby
9
+ gem "activerecord", :platforms => :ruby
10
+ gem "sqlite3", :platforms => :ruby
11
+ end
@@ -55,6 +55,10 @@ module Paperclip
55
55
  @queued_for_delete = []
56
56
  end
57
57
 
58
+ def copy_to_local_file(style, destination_path)
59
+ primary_ftp_server.get_file(path(style), destination_path)
60
+ end
61
+
58
62
  def ftp_servers
59
63
  @ftp_servers ||= begin
60
64
  ftp_servers = []
@@ -62,7 +66,8 @@ module Paperclip
62
66
  server = Server.new(
63
67
  :host => config[:host],
64
68
  :user => config[:user],
65
- :password => config[:password]
69
+ :password => config[:password],
70
+ :port => config[:port]
66
71
  )
67
72
  ftp_servers << server
68
73
  end
@@ -5,10 +5,18 @@ module Paperclip
5
5
  module Storage
6
6
  module Ftp
7
7
  class Server
8
- attr_accessor :host, :user, :password
8
+
9
+ attr_accessor :host, :user, :password, :port
9
10
  attr_writer :connection
10
11
 
12
+ def self.default_options
13
+ {
14
+ :port => Net::FTP::FTP_PORT
15
+ }
16
+ end
17
+
11
18
  def initialize(options = {})
19
+ options = self.class.default_options.merge(options)
12
20
  options.each do |k,v|
13
21
  send("#{k}=", v)
14
22
  end
@@ -16,7 +24,7 @@ module Paperclip
16
24
 
17
25
  def file_exists?(path)
18
26
  pathname = Pathname.new(path)
19
- connection.nlst(pathname.dirname.to_s).include?(pathname.basename.to_s)
27
+ connection.nlst(pathname.dirname.to_s).map { |f| File.basename f }.include?(pathname.basename.to_s)
20
28
  end
21
29
 
22
30
  def get_file(remote_file_path, local_file_path)
@@ -34,7 +42,12 @@ module Paperclip
34
42
  end
35
43
 
36
44
  def connection
37
- @connection ||= Net::FTP.open(host, user, password)
45
+ @connection ||= begin
46
+ connection = Net::FTP.new
47
+ connection.connect(host, port)
48
+ connection.login(user, password)
49
+ connection
50
+ end
38
51
  end
39
52
 
40
53
  def mkdir_p(dirname)
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
12
  gem.name = "paperclip-storage-ftp"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = "1.0.0.rc1"
14
+ gem.version = "1.0.0.rc2"
15
15
 
16
16
  gem.add_dependency("paperclip")
17
17
 
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe "Integration", :integration => true do
4
+ before do
5
+ require "support/integration/ftp_server"
6
+ require "support/integration/user"
7
+ FtpServer.clear
8
+ FtpServer.start
9
+ end
10
+
11
+ let(:file) { File.new(File.expand_path("../support/integration/avatar.jpg", __FILE__), "rb") }
12
+
13
+ it "stores the attachment on the ftp servers" do
14
+ user = User.new
15
+ user.avatar = file
16
+ user.save!
17
+ file.close
18
+
19
+ File.exists?(FtpServer::HOME_PATH + "/#{user.id}/original/avatar.jpg").should be_true
20
+ end
21
+
22
+ it "deletes an attachment from the ftp servers" do
23
+ user = User.new
24
+ user.avatar = file
25
+ user.save!
26
+ file.close
27
+
28
+ user.destroy
29
+
30
+ File.exists?(FtpServer::HOME_PATH + "/#{user.id}/original/avatar.jpg").should be_false
31
+ end
32
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path("../../../../spec_helper", __FILE__)
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::Storage::Ftp::Server do
4
4
  let(:server) { Paperclip::Storage::Ftp::Server.new }
@@ -8,12 +8,19 @@ describe Paperclip::Storage::Ftp::Server do
8
8
  options = {
9
9
  :host => "ftp.example.com",
10
10
  :user => "user",
11
- :password => "password"
11
+ :password => "password",
12
+ :port => 2121
12
13
  }
13
14
  server = Paperclip::Storage::Ftp::Server.new(options)
14
- server.host.should == "ftp.example.com"
15
- server.user.should == "user"
16
- server.password.should == "password"
15
+ server.host.should == options[:host]
16
+ server.user.should == options[:user]
17
+ server.password.should == options[:password]
18
+ server.port.should == options[:port]
19
+ end
20
+
21
+ it "sets a default port" do
22
+ server = Paperclip::Storage::Ftp::Server.new
23
+ server.port.should == Net::FTP::FTP_PORT
17
24
  end
18
25
  end
19
26
 
@@ -24,6 +31,12 @@ describe Paperclip::Storage::Ftp::Server do
24
31
  server.file_exists?("/files/original/foo.jpg").should be_true
25
32
  end
26
33
 
34
+ it "recognizes complete file paths correctly" do
35
+ server.connection = double("connection")
36
+ server.connection.should_receive(:nlst).with("/files/original").and_return(["/files/original/foo.jpg"])
37
+ server.file_exists?("/files/original/foo.jpg").should be_true
38
+ end
39
+
27
40
  it "returns false if the file does not exist on the server" do
28
41
  server.connection = double("connection")
29
42
  server.connection.should_receive(:nlst).with("/files/original").and_return([])
@@ -62,9 +75,12 @@ describe Paperclip::Storage::Ftp::Server do
62
75
  server.user = "user"
63
76
  server.password = "password"
64
77
 
65
- Net::FTP.should_receive(:open).with(server.host, server.user, server.password).once.and_return(:foo)
78
+ connection = double("connection")
79
+ Net::FTP.should_receive(:new).once.and_return(connection)
80
+ connection.should_receive(:connect).once.with(server.host, server.port)
81
+ connection.should_receive(:login).once.with(server.user, server.password)
66
82
 
67
- 2.times { server.connection.should == :foo }
83
+ 2.times { server.connection.should == connection }
68
84
  end
69
85
  end
70
86
 
@@ -1,4 +1,4 @@
1
- require File.expand_path("../../../spec_helper", __FILE__)
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::Storage::Ftp do
4
4
  let(:attachment) do
@@ -109,6 +109,18 @@ describe Paperclip::Storage::Ftp do
109
109
  end
110
110
  end
111
111
 
112
+ context "#copy_to_local_file" do
113
+ it "returns the file from the primary server and stores it in the path specified" do
114
+ attachment.primary_ftp_server.should_receive(:get_file).with("/files/original/foo.jpg", "/local/foo").and_return(:foo)
115
+ attachment.copy_to_local_file(:original, "/local/foo")
116
+ end
117
+
118
+ it "accepts the style parameter to build the correct path" do
119
+ attachment.primary_ftp_server.should_receive(:get_file).with("/files/thumb/foo.jpg", "/local/thumb/foo").and_return(:foo)
120
+ attachment.copy_to_local_file(:thumb, "/local/thumb/foo")
121
+ end
122
+ end
123
+
112
124
  context "#ftp_servers" do
113
125
  it "returns the configured ftp servers" do
114
126
  attachment.ftp_servers.first.host.should == "ftp1.example.com"
Binary file
@@ -0,0 +1,27 @@
1
+ require "daemon_controller"
2
+
3
+ class FtpServer
4
+
5
+ INSTALL_PATH = File.expand_path("../../../../vendor/apache-ftpserver", __FILE__)
6
+ HOME_PATH = INSTALL_PATH + "/res/home"
7
+
8
+ def self.start
9
+ daemon_controller.start unless daemon_controller.running?
10
+ end
11
+
12
+ def self.clear
13
+ FileUtils.rm_r(Dir.glob(HOME_PATH + "/*"))
14
+ end
15
+
16
+ private
17
+
18
+ def self.daemon_controller
19
+ @daemon_controller ||= DaemonController.new(
20
+ :identifier => "Apache FtpServer",
21
+ :start_command => "cd #{INSTALL_PATH}; ./bin/ftpd.sh res/conf/ftpd-typical.xml",
22
+ :ping_command => [:tcp, '127.0.0.1', 2121],
23
+ :pid_file => INSTALL_PATH + "/res/ftpd.pid",
24
+ :log_file => INSTALL_PATH + "/res/log/ftpd.log"
25
+ )
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ require "active_record"
2
+
3
+ ActiveRecord::Base.establish_connection(
4
+ :adapter => "sqlite3",
5
+ :database => ":memory:"
6
+ )
7
+
8
+ ActiveRecord::Migration.verbose = false
9
+ ActiveRecord::Schema.define do
10
+ create_table :users
11
+ add_column :users, :avatar_file_name, :string
12
+ add_column :users, :avatar_content_type, :string
13
+ add_column :users, :avatar_file_size, :integer
14
+ add_column :users, :avatar_updated_at, :datetime
15
+ end
16
+
17
+ class User < ActiveRecord::Base
18
+ include Paperclip::Glue
19
+
20
+ has_attached_file :avatar,
21
+ :storage => :ftp,
22
+ :path => "/:id/:style/:filename",
23
+ :ftp_servers => [
24
+ {
25
+ :host => "127.0.0.1",
26
+ :user => "admin",
27
+ :password => "admin",
28
+ :port => 2121
29
+ }
30
+ ]
31
+ end
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.