├── har2warc ├── __init__.py └── har2warc.py ├── .coveragerc ├── .travis.yml ├── appveyor.yml ├── README.rst ├── .gitignore ├── setup.py ├── test └── test_har2warc.py └── LICENSE /har2warc/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '1.0.4' 2 | 3 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | source = codecov 3 | branch = True 4 | omit = 5 | */test/* 6 | 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - "2.7" 5 | - "3.4" 6 | - "3.5" 7 | - "3.6" 8 | 9 | matrix: 10 | include: 11 | - python: "3.7" 12 | dist: xenial 13 | sudo: required 14 | 15 | os: 16 | - linux 17 | 18 | sudo: false 19 | 20 | install: 21 | # add brotli for tests 22 | - pip install brotlipy 23 | - python setup.py install 24 | - pip install coverage pytest-cov codecov 25 | 26 | script: 27 | - python setup.py test 28 | 29 | after_success: 30 | - codecov 31 | 32 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | global: 3 | CMD_IN_ENV: "cmd /E:ON /V:ON /C obvci_appveyor_python_build_env.cmd" 4 | 5 | matrix: 6 | - PYTHON: "C:\\Python27" 7 | - PYTHON: "C:\\Python27-x64" 8 | - PYTHON: "C:\\Python34" 9 | - PYTHON: "C:\\Python34-x64" 10 | DISTUTILS_USE_SDK: "1" 11 | - PYTHON: "C:\\Python35" 12 | - PYTHON: "C:\\Python35-x64" 13 | - PYTHON: "C:\\Python36" 14 | - PYTHON: "C:\\Python36-x64" 15 | - PYTHON: "C:\\Python37" 16 | - PYTHON: "C:\\Python37-x64" 17 | 18 | 19 | install: 20 | - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" 21 | - "pip install -U setuptools" 22 | - "pip install coverage pytest-cov codecov" 23 | - "pip install brotlipy" 24 | 25 | build_script: 26 | - "python setup.py install" 27 | 28 | test_script: 29 | - "python setup.py test" 30 | 31 | 32 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | har2warc 2 | ======== 3 | 4 | Convert HTTP Archive (HAR) -> Web Archive (WARC) format 5 | 6 | ``pip install har2warc`` 7 | 8 | 9 | Command-Line Usage 10 | ~~~~~~~~~~~~~~~~~~ 11 | 12 | ``har2warc `` 13 | 14 | 15 | Libary Usage 16 | ~~~~~~~~~~~~ 17 | 18 | har2warc can be used as a python library. 19 | 20 | Simple usage similar to CLI interface: 21 | 22 | .. code:: python 23 | 24 | from har2warc.har2warc import har2warc 25 | 26 | har2warc('input.har', 'output.warc.gz') 27 | 28 | 29 | Also supports reading and writing from buffers: 30 | 31 | .. code:: python 32 | 33 | from har2warc.har2warc import har2warc 34 | 35 | har = json.loads(...) 36 | 37 | with open('output.warc.gz', 'w+b') as warc: 38 | har2warc(har, warc) 39 | 40 | # READ WARC 41 | warc.seek(0) 42 | warc.read() 43 | 44 | 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # vim: set sw=4 et: 3 | 4 | from setuptools import setup, find_packages 5 | from setuptools.command.test import test as TestCommand 6 | import glob 7 | 8 | from har2warc import __version__ 9 | 10 | class PyTest(TestCommand): 11 | def finalize_options(self): 12 | TestCommand.finalize_options(self) 13 | 14 | def run_tests(self): 15 | import pytest 16 | import sys 17 | import os 18 | errcode = pytest.main(['--doctest-module', './har2warc', '--cov', 'har2warc', '-v', 'test/']) 19 | sys.exit(errcode) 20 | 21 | 22 | setup( 23 | name='har2warc', 24 | version=__version__, 25 | author='Ilya Kreymer', 26 | author_email='ikreymer@gmail.com', 27 | license='Apache 2.0', 28 | packages=find_packages(), 29 | url='https://github.com/webrecorder/har2warc', 30 | description='Convert HTTP Archive (HAR) -> Web Archive (WARC) format', 31 | long_description=open('README.rst').read(), 32 | provides=[ 33 | 'har2warc' 34 | ], 35 | install_requires=[ 36 | 'warcio', 37 | 'six', 38 | 'http_status', 39 | ], 40 | zip_safe=True, 41 | data_files=[ 42 | ('test/data', glob.glob('test/data/*')), 43 | ], 44 | entry_points=""" 45 | [console_scripts] 46 | har2warc = har2warc.har2warc:main 47 | """, 48 | cmdclass={'test': PyTest}, 49 | test_suite='', 50 | tests_require=[ 51 | 'pytest', 52 | 'pytest-cov', 53 | ], 54 | classifiers=[ 55 | 'Development Status :: 4 - Beta', 56 | 'Environment :: Web Environment', 57 | 'License :: OSI Approved :: Apache Software License', 58 | 'Programming Language :: Python :: 2', 59 | 'Programming Language :: Python :: 2.7', 60 | 'Programming Language :: Python :: 3', 61 | 'Programming Language :: Python :: 3.3', 62 | 'Programming Language :: Python :: 3.4', 63 | 'Programming Language :: Python :: 3.5', 64 | 'Programming Language :: Python :: 3.6', 65 | 'Topic :: Software Development :: Libraries :: Python Modules', 66 | 'Topic :: Utilities', 67 | ] 68 | ) 69 | -------------------------------------------------------------------------------- /test/test_har2warc.py: -------------------------------------------------------------------------------- 1 | from har2warc.har2warc import har2warc, main 2 | from warcio.cli import main as indexer 3 | from warcio import ArchiveIterator 4 | import tempfile 5 | import os 6 | import sys 7 | 8 | from contextlib import contextmanager 9 | from io import BytesIO 10 | 11 | 12 | class TestHar2WARC(object): 13 | @classmethod 14 | def get_test_file(cls, filename): 15 | return os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', filename) 16 | 17 | def load_har(self, filename): 18 | filename = self.get_test_file(filename) 19 | 20 | temp_filename = os.path.join(tempfile.gettempdir(), tempfile.gettempprefix() + '-' + os.path.basename(filename)) 21 | 22 | try: 23 | main([filename, temp_filename]) 24 | 25 | with patch_stdout() as buff: 26 | indexer(['index', temp_filename, '-f', 'warc-target-uri']) 27 | 28 | return buff.getvalue().decode('utf-8') 29 | finally: 30 | os.remove(temp_filename) 31 | 32 | def test_example_har(self): 33 | assert self.load_har('example.har') == EXAMPLE_INDEX 34 | 35 | def test_http2_har(self): 36 | assert self.load_har('http2.github.io.har').startswith(HTTP2_INDEX) 37 | 38 | def test_load_http2_warc_convert_protocol(self): 39 | filename = self.get_test_file('http2.github.io.har') 40 | 41 | temp_filename = os.path.join(tempfile.gettempdir(), tempfile.gettempprefix() + '-http2.warc') 42 | 43 | try: 44 | # write then read same file 45 | with open(temp_filename, 'w+b') as fh: 46 | har2warc(filename, fh) 47 | 48 | fh.seek(0) 49 | 50 | ai = ArchiveIterator(fh, verify_http=True) 51 | 52 | record = next(ai) 53 | assert record.rec_type == 'warcinfo' 54 | 55 | record = next(ai) 56 | assert record.rec_type == 'response' 57 | 58 | # ensure protocol vonerted to HTTP/1.1 59 | assert record.http_headers.protocol == 'HTTP/1.1' 60 | 61 | finally: 62 | os.remove(temp_filename) 63 | 64 | 65 | 66 | EXAMPLE_INDEX = """\ 67 | {} 68 | {"warc-target-uri": "http://example.com/"} 69 | {"warc-target-uri": "http://example.com/"} 70 | {"warc-target-uri": "https://www.iana.org/domains/reserved"} 71 | {"warc-target-uri": "https://www.iana.org/domains/reserved"} 72 | {"warc-target-uri": "http://www.iana.org/domains/example"} 73 | {"warc-target-uri": "http://www.iana.org/domains/example"} 74 | {"warc-target-uri": "https://www.iana.org/domains/example"} 75 | {"warc-target-uri": "https://www.iana.org/domains/example"} 76 | {"warc-target-uri": "https://www.iana.org/_css/2015.1/screen.css"} 77 | {"warc-target-uri": "https://www.iana.org/_css/2015.1/screen.css"} 78 | {"warc-target-uri": "https://www.iana.org/_js/2013.1/jquery.js"} 79 | {"warc-target-uri": "https://www.iana.org/_js/2013.1/jquery.js"} 80 | {"warc-target-uri": "https://www.iana.org/_js/2013.1/iana.js"} 81 | {"warc-target-uri": "https://www.iana.org/_js/2013.1/iana.js"} 82 | {"warc-target-uri": "https://www.iana.org/_img/2013.1/iana-logo-header.svg"} 83 | {"warc-target-uri": "https://www.iana.org/_img/2013.1/iana-logo-header.svg"} 84 | {"warc-target-uri": "https://www.iana.org/_css/2015.1/print.css"} 85 | {"warc-target-uri": "https://www.iana.org/_css/2015.1/print.css"} 86 | {"warc-target-uri": "https://www.iana.org/_img/2015.1/fonts/NotoSans-Bold.woff"} 87 | {"warc-target-uri": "https://www.iana.org/_img/2015.1/fonts/NotoSans-Bold.woff"} 88 | {"warc-target-uri": "https://www.iana.org/_img/2015.1/fonts/NotoSans-Regular.woff"} 89 | {"warc-target-uri": "https://www.iana.org/_img/2015.1/fonts/NotoSans-Regular.woff"} 90 | {"warc-target-uri": "https://www.iana.org/_img/2015.1/fonts/SourceCodePro-Regular.woff"} 91 | {"warc-target-uri": "https://www.iana.org/_img/2015.1/fonts/SourceCodePro-Regular.woff"} 92 | {"warc-target-uri": "https://www.iana.org/_img/bookmark_icon.ico"} 93 | {"warc-target-uri": "https://www.iana.org/_img/bookmark_icon.ico"} 94 | """ 95 | 96 | HTTP2_INDEX = """\ 97 | {} 98 | {"warc-target-uri": "https://http2.github.io/"} 99 | {"warc-target-uri": "https://http2.github.io/"} 100 | {"warc-target-uri": "https://http2.github.io/components/bootstrap/dist/css/bootstrap.min.css"} 101 | {"warc-target-uri": "https://http2.github.io/components/bootstrap/dist/css/bootstrap.min.css"} 102 | {"warc-target-uri": "https://http2.github.io/asset/site.css"} 103 | {"warc-target-uri": "https://http2.github.io/asset/site.css"} 104 | """ 105 | 106 | 107 | @contextmanager 108 | def patch_stdout(): 109 | buff = BytesIO() 110 | if hasattr(sys.stdout, 'buffer'): 111 | orig = sys.stdout.buffer 112 | sys.stdout.buffer = buff 113 | yield buff 114 | sys.stdout.buffer = orig 115 | else: 116 | orig = sys.stdout 117 | sys.stdout = buff 118 | yield buff 119 | sys.stdout = orig 120 | 121 | 122 | -------------------------------------------------------------------------------- /har2warc/har2warc.py: -------------------------------------------------------------------------------- 1 | import json 2 | import sys 3 | import base64 4 | import logging 5 | import codecs 6 | 7 | from warcio.warcwriter import BufferWARCWriter, WARCWriter, BaseWARCWriter 8 | from warcio.statusandheaders import StatusAndHeaders 9 | from warcio.timeutils import iso_date_to_timestamp 10 | 11 | from six.moves.urllib.parse import urlsplit, urlencode 12 | from io import BytesIO 13 | 14 | from collections import OrderedDict 15 | 16 | from argparse import ArgumentParser, RawTextHelpFormatter 17 | 18 | from http_status import name as http_status_names 19 | 20 | from . import __version__ 21 | 22 | 23 | # ============================================================================ 24 | class HarParser(object): 25 | logger = logging.getLogger(__name__) 26 | 27 | def __init__(self, reader, writer, gzip=True): 28 | if isinstance(reader, str): 29 | with codecs.open(reader, encoding='utf-8') as fh: 30 | self.har = json.loads(fh.read()) 31 | elif hasattr(reader, 'read'): 32 | self.har = json.loads(reader.read()) 33 | elif isinstance(reader, dict): 34 | self.har = reader 35 | else: 36 | raise Exception('reader is in an unknown format') 37 | 38 | self.fh = None 39 | if isinstance(writer, BaseWARCWriter): 40 | self.writer = writer 41 | elif isinstance(writer, str): 42 | self.fh = open(writer, 'wb') 43 | self.writer = WARCWriter(self.fh, gzip=gzip) 44 | elif hasattr(writer, 'write'): 45 | self.writer = WARCWriter(writer, gzip=gzip) 46 | else: 47 | raise Exception('writer is in an unknown format') 48 | 49 | def parse(self, out_filename=None, rec_title=None): 50 | out_filename = out_filename or 'har.warc.gz' 51 | rec_title = rec_title or 'HAR Recording' 52 | metadata = self.create_wr_metadata(self.har['log'], rec_title) 53 | self.write_warc_info(self.har['log'], out_filename, metadata) 54 | 55 | for entry in self.har['log']['entries']: 56 | self.parse_entry(entry) 57 | 58 | if self.fh: 59 | self.fh.close() 60 | 61 | def parse_entry(self, entry): 62 | url = entry['request']['url'] 63 | 64 | response = self.parse_response(url, 65 | entry['response'], 66 | entry.get('serverIPAddress')) 67 | 68 | #TODO: support WARC/1.1 arbitrary precision dates! 69 | warc_date = entry['startedDateTime'][:19] + 'Z' 70 | 71 | response.rec_headers.replace_header('WARC-Date', warc_date) 72 | 73 | request = self.parse_request(entry['request']) 74 | 75 | self.writer.write_request_response_pair(request, response) 76 | 77 | 78 | def create_wr_metadata(self, log, rec_title): 79 | pagelist = [] 80 | 81 | for page in log['pages']: 82 | if not page['title'].startswith(('http:', 'https:')): 83 | continue 84 | 85 | pagelist.append(dict(title=page['title'], 86 | url=page['title'], 87 | timestamp=iso_date_to_timestamp(page['startedDateTime']))) 88 | 89 | metadata = {"title": rec_title, 90 | "type": "recording", 91 | } 92 | 93 | if pagelist: 94 | metadata["pages"] = pagelist 95 | 96 | return metadata 97 | 98 | def write_warc_info(self, log, filename, metadata): 99 | creator = '{0} {1}'.format(log['creator']['name'], 100 | log['creator']['version']) 101 | 102 | source = 'HAR Format {0}'.format(log['version']) 103 | 104 | software = 'har2warc ' + str(__version__) 105 | 106 | params = OrderedDict([('software', software), 107 | ('creator', creator), 108 | ('source', source), 109 | ('format', 'WARC File Format 1.0'), 110 | ('json-metadata', json.dumps(metadata))]) 111 | 112 | record = self.writer.create_warcinfo_record(filename, params) 113 | self.writer.write_record(record) 114 | 115 | def _get_http_version(self, entry): 116 | http_version = entry.get('httpVersion') 117 | if not http_version or http_version.upper() not in ('HTTP/1.1', 'HTTP/1.0'): 118 | http_version = 'HTTP/1.1' 119 | 120 | return http_version 121 | 122 | def parse_response(self, url, response, ip=None): 123 | headers = [] 124 | payload = BytesIO() 125 | content = response['content'].get('text', '') 126 | 127 | if not content and not response.get('headers'): 128 | self.logger.info('No headers or payload for: {0}'.format(url)) 129 | headers.append(('Content-Length', '0')) 130 | if response['content'].get('encoding') == 'base64': 131 | payload.write(base64.b64decode(content)) 132 | else: 133 | payload.write(content.encode('utf-8')) 134 | 135 | length = payload.tell() 136 | payload.seek(0) 137 | 138 | SKIP_HEADERS = ('content-encoding', 'transfer-encoding') 139 | 140 | http2 = False 141 | 142 | for header in response['headers']: 143 | if header['name'].lower() not in SKIP_HEADERS: 144 | headers.append((header['name'], header['value'])) 145 | 146 | #TODO: http2 detection -- write as same warc header? 147 | if (not http2 and 148 | header['name'] in (':method', ':scheme', ':path')): 149 | http2 = True 150 | 151 | status = response.get('status') or 204 152 | 153 | reason = response.get('statusText') 154 | if not reason: 155 | reason = http_status_names.get(status, 'No Reason') 156 | 157 | status_line = str(status) + ' ' + reason 158 | 159 | proto = self._get_http_version(response) 160 | 161 | http_headers = StatusAndHeaders(status_line, headers, protocol=proto) 162 | 163 | if not content: 164 | content_length = http_headers.get_header('Content-Length', '0') 165 | if content_length != '0': 166 | self.logger.info('No Content for length {0} {1}'.format(content_length, url)) 167 | http_headers.replace_header('Content-Length', '0') 168 | else: 169 | http_headers.replace_header('Content-Length', str(length)) 170 | 171 | warc_headers_dict = {} 172 | if ip: 173 | warc_headers_dict['WARC-IP-Address'] = ip 174 | 175 | record = self.writer.create_warc_record(url, 'response', 176 | http_headers=http_headers, 177 | payload=payload, 178 | length=length, 179 | warc_headers_dict=warc_headers_dict) 180 | 181 | return record 182 | 183 | def parse_request(self, request): 184 | parts = urlsplit(request['url']) 185 | 186 | path = parts.path 187 | query = request.get('queryString') 188 | if query: 189 | path += '?' + urlencode(dict((p['name'], p['value']) 190 | for p in query)) 191 | 192 | headers = [] 193 | http2 = False 194 | 195 | for header in request['headers']: 196 | headers.append((header['name'], header['value'])) 197 | 198 | #TODO: http2 detection -- write as same warc header? 199 | if (not http2 and 200 | header['name'] in (':method', ':scheme', ':path')): 201 | http2 = True 202 | 203 | if http2: 204 | headers.append(('Host', parts.netloc)) 205 | 206 | http_version = self._get_http_version(request) 207 | 208 | status_line = request['method'] + ' ' + path + ' ' + http_version 209 | http_headers = StatusAndHeaders(status_line, headers) 210 | 211 | payload = None 212 | length = 0 213 | 214 | if request['bodySize'] > 0: 215 | payload = BytesIO() 216 | payload.write(request['postData']['text'].encode('utf-8')) 217 | length = payload.tell() 218 | payload.seek(0) 219 | 220 | record = self.writer.create_warc_record(request['url'], 'request', 221 | http_headers=http_headers, 222 | payload=payload, 223 | length=length) 224 | 225 | return record 226 | 227 | 228 | # ============================================================================ 229 | def har2warc(har, writer, gzip=True, filename=None, rec_title=None): 230 | HarParser(har, writer, gzip=gzip).parse(filename, rec_title) 231 | 232 | 233 | # ============================================================================ 234 | def main(args=None): 235 | parser = ArgumentParser(description='HAR to WARC Converter', 236 | formatter_class=RawTextHelpFormatter) 237 | 238 | parser.add_argument('input') 239 | parser.add_argument('output') 240 | 241 | parser.add_argument('--title') 242 | parser.add_argument('--no-z', action='store_true') 243 | parser.add_argument('-v', '--verbose', action='store_true') 244 | 245 | r = parser.parse_args(args=args) 246 | 247 | rec_title = r.title or r.input.rsplit('/', 1)[-1] 248 | 249 | logging.basicConfig(format='[%(levelname)s]: %(message)s') 250 | HarParser.logger.setLevel(logging.ERROR if not r.verbose else logging.INFO) 251 | 252 | har2warc(r.input, r.output, gzip=not r.no_z, 253 | filename=r.output, 254 | rec_title=rec_title) 255 | 256 | 257 | if __name__ == "__main__": #pragma: no cover 258 | main() 259 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------