├── pytest.ini ├── upload-demo.gif ├── .gitignore ├── .github └── workflows │ ├── test.yml │ └── publish.yml ├── setup.py ├── README.md ├── datasette_upload_dbs ├── __init__.py └── templates │ └── upload_dbs.html ├── tests └── test_upload_dbs.py └── LICENSE /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | asyncio_mode = strict 3 | -------------------------------------------------------------------------------- /upload-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonw/datasette-upload-dbs/HEAD/upload-demo.gif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .venv 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | venv 6 | .eggs 7 | .pytest_cache 8 | *.egg-info 9 | .DS_Store 10 | .vscode 11 | dist 12 | build 13 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: [push, pull_request] 4 | 5 | permissions: 6 | contents: read 7 | 8 | jobs: 9 | test: 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up Python ${{ matrix.python-version }} 17 | uses: actions/setup-python@v6 18 | with: 19 | python-version: ${{ matrix.python-version }} 20 | cache: pip 21 | cache-dependency-path: setup.py 22 | - name: Install dependencies 23 | run: | 24 | pip install '.[test]' 25 | - name: Run tests 26 | run: | 27 | python -m pytest 28 | 29 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish Python Package 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | test: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: Set up Python ${{ matrix.python-version }} 19 | uses: actions/setup-python@v6 20 | with: 21 | python-version: ${{ matrix.python-version }} 22 | cache: pip 23 | cache-dependency-path: setup.py 24 | - name: Install dependencies 25 | run: | 26 | pip install '.[test]' 27 | - name: Run tests 28 | run: | 29 | python -m pytest 30 | deploy: 31 | runs-on: ubuntu-latest 32 | needs: [test] 33 | environment: release 34 | permissions: 35 | id-token: write 36 | steps: 37 | - uses: actions/checkout@v4 38 | - name: Set up Python 39 | uses: actions/setup-python@v6 40 | with: 41 | python-version: "3.12" 42 | cache: pip 43 | cache-dependency-path: setup.py 44 | - name: Install dependencies 45 | run: | 46 | pip install setuptools wheel build 47 | - name: Build 48 | run: | 49 | python -m build 50 | - name: Publish 51 | uses: pypa/gh-action-pypi-publish@release/v1 52 | 53 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | import os 3 | 4 | VERSION = "0.4a0" 5 | 6 | 7 | def get_long_description(): 8 | with open( 9 | os.path.join(os.path.dirname(os.path.abspath(__file__)), "README.md"), 10 | encoding="utf8", 11 | ) as fp: 12 | return fp.read() 13 | 14 | 15 | setup( 16 | name="datasette-upload-dbs", 17 | description="Upload SQLite database files to Datasette", 18 | long_description=get_long_description(), 19 | long_description_content_type="text/markdown", 20 | author="Simon Willison", 21 | url="https://github.com/simonw/datasette-upload-dbs", 22 | project_urls={ 23 | "Issues": "https://github.com/simonw/datasette-upload-dbs/issues", 24 | "CI": "https://github.com/simonw/datasette-upload-dbs/actions", 25 | "Changelog": "https://github.com/simonw/datasette-upload-dbs/releases", 26 | }, 27 | license="Apache License, Version 2.0", 28 | classifiers=[ 29 | "Framework :: Datasette", 30 | "License :: OSI Approved :: Apache Software License", 31 | ], 32 | version=VERSION, 33 | packages=["datasette_upload_dbs"], 34 | entry_points={"datasette": ["upload_dbs = datasette_upload_dbs"]}, 35 | install_requires=["datasette>=1.0a21", "starlette"], 36 | extras_require={"test": ["pytest", "pytest-asyncio"]}, 37 | package_data={"datasette_upload_dbs": ["templates/*"]}, 38 | python_requires=">=3.10", 39 | ) 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # datasette-upload-dbs 2 | 3 | [](https://pypi.org/project/datasette-upload-dbs/) 4 | [](https://github.com/simonw/datasette-upload-dbs/releases) 5 | [](https://github.com/simonw/datasette-upload-dbs/actions?query=workflow%3ATest) 6 | [](https://github.com/simonw/datasette-upload-dbs/blob/main/LICENSE) 7 | 8 | Upload SQLite database files to Datasette 9 | 10 | ## Installation 11 | 12 | Install this plugin in the same environment as Datasette. 13 | 14 | datasette install datasette-upload-dbs 15 | 16 | ## Configuration 17 | 18 | This plugin requires you to configure a directory in which uploaded files will be stored. 19 | 20 | On startup, Datasette will automatically load any SQLite files that it finds in that directory. This means it is safe to restart your server in between file uploads. 21 | 22 | To configure the directory as `/home/datasette/uploads`, add this to a `metadata.yml` configuration file: 23 | 24 | ```yaml 25 | plugins: 26 | datasette-upload-dbs: 27 | directory: /home/datasette/uploads 28 | ``` 29 | 30 | Or if you are using `metadata.json`: 31 | 32 | ```json 33 | { 34 | "plugins": { 35 | "datasette-upload-dbs": { 36 | "directory": "/home/datasette/uploads" 37 | } 38 | } 39 | } 40 | ``` 41 | You can use `"."` for the current folder when the server starts, or `"uploads"` for a folder relative to that folder. The folder will be created on startup if it does not already exist. 42 | 43 | Then start Datasette like this: 44 | 45 | datasette -m metadata.yml 46 | 47 | The plugin defaults to loading all databases in the configured directory. 48 | 49 | You can disable this by adding the following setting: 50 | ``` 51 | "skip_startup_scan": true 52 | ``` 53 | ## Usage 54 | 55 | Only users with the `upload-dbs` permission will be able to upload files. The `root` user has this permission by default - other users can be granted access using permission plugins, see the [Permissions](https://docs.datasette.io/en/stable/authentication.html#permissions) documentation for details. 56 | 57 | To start Datasette as the root user, run this: 58 | 59 | datasette -m metadata.yml --root 60 | 61 | And follow the link that is displayed on the console. 62 | 63 | If a user has that permission they will see an "Upload database" link in the navigation menu. 64 | 65 | This will take them to `/-/upload-dbs` where they will be able to upload database files, by selecting them or by dragging them onto the drop area. 66 | 67 |  68 | 69 | ## Development 70 | 71 | To set up this plugin locally, first checkout the code. Then create a new virtual environment: 72 | 73 | cd datasette-upload-dbs 74 | python3 -m venv venv 75 | source venv/bin/activate 76 | 77 | Now install the dependencies and test dependencies: 78 | 79 | pip install -e '.[test]' 80 | 81 | To run the tests: 82 | 83 | pytest 84 | -------------------------------------------------------------------------------- /datasette_upload_dbs/__init__.py: -------------------------------------------------------------------------------- 1 | from datasette import hookimpl 2 | from datasette.permissions import Action 3 | from datasette.database import Database 4 | from datasette.utils.asgi import Response, Forbidden 5 | from datasette.utils import to_css_class 6 | from datasette.utils.sqlite import sqlite3 7 | from starlette.requests import Request 8 | from shutil import copyfileobj 9 | import pathlib 10 | 11 | 12 | @hookimpl 13 | def register_actions(datasette): 14 | return [ 15 | Action( 16 | name="upload-dbs", 17 | description="Upload SQLite database files", 18 | ) 19 | ] 20 | 21 | 22 | @hookimpl 23 | def register_routes(): 24 | return [ 25 | (r"^/-/upload-dbs$", upload_dbs), 26 | (r"^/-/upload-db$", lambda: Response.redirect("/-/upload-dbs")), 27 | ] 28 | 29 | 30 | @hookimpl 31 | def menu_links(datasette, actor): 32 | async def inner(): 33 | if await datasette.allowed( 34 | actor=actor, 35 | action="upload-dbs", 36 | ) and _configured(datasette): 37 | return [ 38 | { 39 | "href": datasette.urls.path("/-/upload-dbs"), 40 | "label": "Upload database", 41 | }, 42 | ] 43 | 44 | return inner 45 | 46 | 47 | @hookimpl 48 | def startup(datasette): 49 | # Load any databases located in the directory folder 50 | config = datasette.plugin_config("datasette-upload-dbs") or {} 51 | if config.get("skip_startup_scan"): 52 | return 53 | directory = config.get("directory") 54 | if not directory: 55 | return 56 | path = pathlib.Path(directory) 57 | database_files = path.glob("*.db") 58 | for file_path in database_files: 59 | # Needs to set is_mutable=True here because the default was False 60 | # in Datasette versions up to and including 0.62 61 | datasette.add_database( 62 | Database(datasette, path=str(file_path), is_mutable=True), 63 | ) 64 | 65 | 66 | def _configured(datasette): 67 | return (datasette.plugin_config("datasette-upload-dbs") or {}).get("directory") 68 | 69 | 70 | async def upload_dbs(scope, receive, datasette, request): 71 | if not await datasette.allowed( 72 | actor=request.actor, 73 | action="upload-dbs", 74 | ): 75 | raise Forbidden("Permission denied for upload-dbs") 76 | 77 | directory = _configured(datasette) 78 | 79 | if not directory: 80 | raise Forbidden("datasette-upload-dbs plugin has not been correctly configured") 81 | 82 | path = pathlib.Path(directory) 83 | 84 | if request.method != "POST": 85 | return Response.html( 86 | await datasette.render_template("upload_dbs.html", request=request) 87 | ) 88 | 89 | # We use the Starlette request object to handle file uploads 90 | starlette_request = Request(scope, receive) 91 | 92 | async def error(msg): 93 | if is_xhr: 94 | return Response.json({"ok": False, "error": msg}) 95 | 96 | return Response.html( 97 | await datasette.render_template( 98 | "upload_dbs.html", 99 | { 100 | "error": msg, 101 | }, 102 | request=request, 103 | ) 104 | ) 105 | 106 | formdata = await starlette_request.form() 107 | db_file = formdata["db"] 108 | is_xhr = formdata.get("xhr") 109 | db_name = (formdata.get("db_name") or "").strip() 110 | 111 | if not db_name: 112 | db_name = db_file.filename.split(".")[0] 113 | 114 | db_name = to_css_class(db_name) or "db" 115 | 116 | first_16 = db_file.file.read(16) 117 | if first_16 != b"SQLite format 3\x00": 118 | return await error("File is not a valid SQLite database (invalid header)") 119 | 120 | path.mkdir(parents=True, exist_ok=True) 121 | 122 | # Copy it to its final destination 123 | filepath = path / (db_name + ".db") 124 | with open(filepath, "wb+") as target_file: 125 | db_file.file.seek(0) 126 | copyfileobj(db_file.file, target_file) 127 | 128 | # Now really verify it 129 | conn = sqlite3.connect(str(filepath)) 130 | try: 131 | conn.execute("select * from sqlite_master") 132 | except sqlite3.Error as e: 133 | # Delete file, it is invalid 134 | filepath.unlink() 135 | return await error(f"File is not a valid SQLite database ({e})") 136 | 137 | # File is valid - add it to this Datasette instance 138 | db = Database(datasette, path=str(filepath), is_mutable=True) 139 | datasette.add_database(db) 140 | 141 | redirect_url = datasette.urls.database(db.name) 142 | if is_xhr: 143 | return Response.json({"ok": True, "redirect": redirect_url}) 144 | else: 145 | return Response.redirect(redirect_url) 146 | -------------------------------------------------------------------------------- /datasette_upload_dbs/templates/upload_dbs.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block title %}Upload a SQLite database{% endblock %} 4 | 5 | {% block extra_head %} 6 | 46 | {% endblock %} 47 | 48 | {% block content %} 49 |
SQLite database files can by created using a range of different tools, including the sqlite-utils Python library and command-line utility.
68 | 69 | 70 | 179 | {% endblock %} 180 | -------------------------------------------------------------------------------- /tests/test_upload_dbs.py: -------------------------------------------------------------------------------- 1 | from datasette.app import Datasette 2 | import sqlite3 3 | import pytest 4 | from io import BytesIO 5 | 6 | 7 | @pytest.mark.asyncio 8 | @pytest.mark.parametrize("auth", [True, False]) 9 | async def test_menu(auth): 10 | ds = Datasette( 11 | memory=True, 12 | config={"plugins": {"datasette-upload-dbs": {"directory": "."}}}, 13 | ) 14 | ds.root_enabled = True 15 | cookies = {} 16 | if auth: 17 | cookies = {"ds_actor": ds.sign({"a": {"id": "root"}}, "actor")} 18 | response = await ds.client.get("/", cookies=cookies) 19 | assert response.status_code == 200 20 | if auth: 21 | assert "/-/upload-dbs" in response.text 22 | else: 23 | assert "/-/upload-dbs" not in response.text 24 | 25 | 26 | @pytest.mark.asyncio 27 | async def test_redirect(): 28 | ds = Datasette(memory=True) 29 | response = await ds.client.get("/-/upload-db") 30 | assert response.status_code == 302 31 | assert response.headers["location"] == "/-/upload-dbs" 32 | 33 | 34 | @pytest.mark.asyncio 35 | @pytest.mark.parametrize("skip_startup_scan", (False, True)) 36 | async def test_databases_loaded_on_startup(tmp_path_factory, skip_startup_scan): 37 | uploads_directory = tmp_path_factory.mktemp("uploads") 38 | for name in ("test1.db", "test2.db"): 39 | db_path = uploads_directory / name 40 | sqlite3.connect(str(db_path)).execute("create table t (id integer primary key)") 41 | config = {"directory": str(uploads_directory)} 42 | if skip_startup_scan: 43 | config["skip_startup_scan"] = True 44 | 45 | ds = Datasette( 46 | memory=True, 47 | config={"plugins": {"datasette-upload-dbs": config}}, 48 | ) 49 | await ds.invoke_startup() 50 | db_names = {"test1", "test2"} 51 | if skip_startup_scan: 52 | # Startup scan skipped, so none of the uploaded DBs should be loaded 53 | assert db_names.isdisjoint(ds.databases.keys()) 54 | else: 55 | assert set(ds.databases.keys()).issuperset(db_names) 56 | for name in db_names: 57 | assert ds.databases[name].is_mutable 58 | 59 | 60 | @pytest.mark.asyncio 61 | @pytest.mark.parametrize( 62 | "authed,configured,expected_error", 63 | ( 64 | (False, False, "Permission denied for upload-dbs"), 65 | (False, True, "Permission denied for upload-dbs"), 66 | (True, False, "datasette-upload-dbs plugin has not been correctly configured"), 67 | ), 68 | ) 69 | async def test_errors(authed, configured, expected_error): 70 | ds = Datasette( 71 | memory=True, 72 | config={ 73 | "plugins": ( 74 | {"datasette-upload-dbs": {"directory": "."}} if configured else {} 75 | ) 76 | }, 77 | ) 78 | ds.root_enabled = True 79 | cookies = {} 80 | if authed: 81 | cookies = {"ds_actor": ds.sign({"a": {"id": "root"}}, "actor")} 82 | response = await ds.client.get("/-/upload-dbs", cookies=cookies) 83 | assert response.status_code == 403 84 | assert expected_error in response.text 85 | 86 | 87 | @pytest.mark.asyncio 88 | @pytest.mark.parametrize( 89 | "bytes,expected_error", 90 | ( 91 | (b"bad_bytes", "File is not a valid SQLite database (invalid header)"), 92 | ( 93 | b"SQLite format 3\x00invalid", 94 | "File is not a valid SQLite database (file is not a database)", 95 | ), 96 | ), 97 | ) 98 | @pytest.mark.parametrize("xhr", (True, False)) 99 | async def test_invalid_files(tmp_path_factory, bytes, expected_error, xhr): 100 | uploads_directory = tmp_path_factory.mktemp("uploads") 101 | ds = Datasette( 102 | memory=True, 103 | config={ 104 | "plugins": {"datasette-upload-dbs": {"directory": str(uploads_directory)}} 105 | }, 106 | ) 107 | ds.root_enabled = True 108 | csrftoken = await _get_csrftoken(ds) 109 | # write to database 110 | response = await ds.client.post( 111 | "/-/upload-dbs", 112 | cookies={ 113 | "ds_actor": ds.sign({"a": {"id": "root"}}, "actor"), 114 | "ds_csrftoken": csrftoken, 115 | }, 116 | data={"csrftoken": csrftoken, "xhr": "1" if xhr else ""}, 117 | files={"db": BytesIO(bytes)}, 118 | ) 119 | if xhr: 120 | assert response.json() == {"ok": False, "error": expected_error} 121 | else: 122 | assert f'' in response.text 123 | 124 | 125 | @pytest.mark.asyncio 126 | @pytest.mark.parametrize("xhr", (True, False)) 127 | @pytest.mark.parametrize( 128 | "db_file_name,db_name,expected_path", 129 | ( 130 | ("temp.db", None, "/temp"), 131 | (".db", None, "/d41d8c"), 132 | ("temp.db", "custom", "/custom"), 133 | ("temp.db", "a + b + c ~ d", "/a--b--c--d-26e27e"), 134 | ), 135 | ) 136 | async def test_upload(tmp_path_factory, xhr, db_file_name, db_name, expected_path): 137 | uploads_directory = tmp_path_factory.mktemp("uploads") 138 | tmp_directory = tmp_path_factory.mktemp("tmp") 139 | ds = Datasette( 140 | memory=True, 141 | config={ 142 | "plugins": {"datasette-upload-dbs": {"directory": str(uploads_directory)}} 143 | }, 144 | ) 145 | ds.root_enabled = True 146 | csrftoken = await _get_csrftoken(ds) 147 | 148 | temp = str(tmp_directory / db_file_name) 149 | sqlite3.connect(temp).execute("create table t (id integer primary key)") 150 | 151 | upload_data = {"csrftoken": csrftoken, "xhr": "1" if xhr else ""} 152 | if db_name: 153 | upload_data["db_name"] = db_name 154 | 155 | response = await ds.client.post( 156 | "/-/upload-dbs", 157 | cookies={ 158 | "ds_actor": ds.sign({"a": {"id": "root"}}, "actor"), 159 | "ds_csrftoken": csrftoken, 160 | }, 161 | data=upload_data, 162 | files={"db": open(temp, "rb")}, 163 | ) 164 | if xhr: 165 | assert response.json() == {"ok": True, "redirect": expected_path} 166 | else: 167 | assert response.status_code == 302 168 | assert response.headers["location"] == expected_path 169 | 170 | # Datasette should serve that file 171 | table_response = await ds.client.get(f"{expected_path}/t.json?_shape=array") 172 | assert table_response.status_code == 200 173 | assert table_response.json() == [] 174 | 175 | # Uploaded file should exist 176 | conn = sqlite3.connect(temp) 177 | assert conn.execute("select sql from sqlite_master").fetchall() == [ 178 | ("CREATE TABLE t (id integer primary key)",) 179 | ] 180 | # And it should be mutable 181 | new_db = [db for db in ds.databases.values() if not db.name.startswith("_")][0] 182 | assert new_db.is_mutable 183 | 184 | 185 | async def _get_csrftoken(ds): 186 | return ( 187 | await ds.client.get( 188 | "/-/upload-dbs", 189 | cookies={"ds_actor": ds.sign({"a": {"id": "root"}}, "actor")}, 190 | ) 191 | ).cookies["ds_csrftoken"] 192 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------