├── .gitignore
├── __pycache__
├── application.cpython-312.pyc
└── template_engine.cpython-312.pyc
├── README.md
├── templates
└── home.html
├── example.py
├── docs
├── README.md
├── getting-started.md
├── routing.md
├── request-handling.md
├── template-engine.md
└── response-handling.md
├── template_engine.py
├── application.py
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__/
2 |
--------------------------------------------------------------------------------
/__pycache__/application.cpython-312.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phantom-kali/SimWeb/HEAD/__pycache__/application.cpython-312.pyc
--------------------------------------------------------------------------------
/__pycache__/template_engine.cpython-312.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phantom-kali/SimWeb/HEAD/__pycache__/template_engine.cpython-312.pyc
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SimWeb
2 |
3 | - Is a simple web-framework I'm developing using python default libraries. It's in prototyping stage and I aim for simplicity for beginner's sake. Pros can use this to lecture the concept of web development
4 |
5 | Run it using `python example.py`
6 |
7 |
8 |
--------------------------------------------------------------------------------
/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | SimWeb
8 |
9 |
10 |
11 | Welcome to SimWeb
12 | Lorem ipsum dolor sit amet consectetur adipisicing elit. Assumenda, ut, tempore, nulla repellat atque ad
13 | consequuntur aliquid ratione incidunt laboriosam minus perferendis? Corporis at et, illum deserunt in molestiae
14 | quibusdam!
15 |
16 |
17 |
--------------------------------------------------------------------------------
/example.py:
--------------------------------------------------------------------------------
1 | from application import Application, Response
2 | import os
3 |
4 | # Ensure the templates directory exists
5 | if not os.path.exists('templates'):
6 | os.makedirs('templates')
7 |
8 | app = Application()
9 |
10 | @app.route('/')
11 | def home(request):
12 | skills = {"python": "98%"}
13 | return Response(app.render_template('home.html', skills))
14 |
15 | @app.route('/api/data', methods=['GET', 'POST'])
16 | def api_data(request):
17 | if request.method == 'GET':
18 | return Response.json({'message': 'This is GET data', 'query_params': request.query_params})
19 | elif request.method == 'POST':
20 | json_data = request.get_json()
21 | return Response.json({'message': 'This is POST data', 'received_data': json_data})
22 |
23 | @app.route('/hello')
24 | def hello(request):
25 | name = request.query_params.get('name', ['World'])[0]
26 | return Response.html(f'Hello, {name}!
')
27 |
28 | if __name__ == '__main__':
29 | app.run()
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # SimWeb Documentation
2 |
3 | SimWeb is a lightweight web framework built using Python's standard libraries. It's designed with simplicity in mind, making it an excellent tool for learning web development concepts and building simple web applications.
4 |
5 | ## Table of Contents
6 |
7 | 1. [Getting Started](getting-started.md)
8 | 2. [Routing](routing.md)
9 | 3. [Request Handling](request-handling.md)
10 | 4. [Response Handling](response-handling.md)
11 | 5. [Template Engine](template-engine.md)
12 |
13 | ## Key Features
14 |
15 | - Simple and lightweight web framework
16 | - Built using only Python standard libraries
17 | - Easy-to-understand routing system
18 | - Basic template engine with variable substitution
19 | - Support for JSON responses
20 | - Query parameter handling
21 | - HTTP method handling (GET, POST)
22 |
23 | ## Purpose
24 |
25 | SimWeb is primarily designed for:
26 | - Learning web development concepts
27 | - Teaching web framework fundamentals
28 | - Building simple web applications
29 | - Understanding how web frameworks work under the hood
30 |
31 | ## Requirements
32 |
33 | - Python 3.x (No additional dependencies required)
34 |
35 | ## License
36 |
37 | This project is licensed under the Apache License 2.0 - see the [LICENSE](../LICENSE) file for details.
38 |
--------------------------------------------------------------------------------
/template_engine.py:
--------------------------------------------------------------------------------
1 | import os
2 | import re
3 |
4 | class TemplateEngine:
5 | def __init__(self, template_dir):
6 | self.template_dir = template_dir
7 |
8 | def render(self, template_name, context=None):
9 | if context is None:
10 | context = {}
11 |
12 | template_path = os.path.join(self.template_dir, template_name)
13 |
14 | if not os.path.exists(template_path):
15 | raise FileNotFoundError(f"Template not found: {template_name}")
16 |
17 | with open(template_path, 'r') as file:
18 | template_content = file.read()
19 |
20 | # Replace variables
21 | template_content = re.sub(r'\{\{\s*(\w+)\s*\}\}', lambda m: str(context.get(m.group(1), '')), template_content)
22 |
23 | # Handle simple for loops
24 | def replace_for_loop(match):
25 | loop_var = match.group(1)
26 | inner_content = match.group(2)
27 | iterable = context.get(loop_var.split()[-1], [])
28 | result = []
29 | for item in iterable:
30 | item_context = context.copy()
31 | item_context['item'] = item
32 | result.append(re.sub(r'\{\{\s*item\s*\}\}', str(item), inner_content))
33 | return ''.join(result)
34 |
35 | template_content = re.sub(r'\{% for (\w+ in \w+) %\}(.*?)\{% endfor %\}', replace_for_loop, template_content, flags=re.DOTALL)
36 |
37 | return template_content
--------------------------------------------------------------------------------
/docs/getting-started.md:
--------------------------------------------------------------------------------
1 | # Getting Started with SimWeb
2 |
3 | ## Installation
4 |
5 | Since SimWeb uses only Python standard libraries, there's no installation required beyond having Python installed. Simply clone or download the framework files to your project directory.
6 |
7 | ## Quick Start
8 |
9 | 1. Create a new Python file (e.g., `app.py`):
10 |
11 | ```python
12 | from application import Application, Response
13 |
14 | app = Application()
15 |
16 | @app.route('/')
17 | def home(request):
18 | return Response.html('Hello, SimWeb!
')
19 |
20 | if __name__ == '__main__':
21 | app.run()
22 | ```
23 |
24 | 2. Run your application:
25 | ```bash
26 | python app.py
27 | ```
28 |
29 | 3. Visit `http://localhost:8000` in your browser to see your application running.
30 |
31 | ## Basic Example with Templates
32 |
33 | 1. Create a template file `templates/hello.html`:
34 | ```html
35 |
36 |
37 |
38 | {{ title }}
39 |
40 |
41 | Hello, {{ name }}!
42 |
43 |
44 | ```
45 |
46 | 2. Create your application:
47 | ```python
48 | from application import Application, Response
49 |
50 | app = Application()
51 |
52 | @app.route('/')
53 | def home(request):
54 | context = {
55 | 'title': 'Welcome',
56 | 'name': 'World'
57 | }
58 | return Response(app.render_template('hello.html', context))
59 |
60 | if __name__ == '__main__':
61 | app.run()
62 | ```
63 |
64 | ## Configuration
65 |
66 | The Application class accepts the following parameters:
67 | - `templates_dir`: Directory containing template files (default: "templates")
68 |
69 | The `run()` method accepts:
70 | - `host`: Host to run the server on (default: "localhost")
71 | - `port`: Port to run the server on (default: 8000)
72 |
73 | ## Next Steps
74 |
75 | - Learn about [Routing](routing.md)
76 | - Understand [Request Handling](request-handling.md)
77 | - Explore [Response Handling](response-handling.md)
78 | - Master the [Template Engine](template-engine.md)
79 |
--------------------------------------------------------------------------------
/docs/routing.md:
--------------------------------------------------------------------------------
1 | # Routing in SimWeb
2 |
3 | SimWeb provides a simple and intuitive routing system that allows you to map URLs to handler functions using decorators.
4 |
5 | ## Basic Routing
6 |
7 | ### Route Decorator
8 |
9 | The basic syntax for creating a route is:
10 |
11 | ```python
12 | @app.route('/path')
13 | def handler(request):
14 | return Response.html('Content')
15 | ```
16 |
17 | ### HTTP Methods
18 |
19 | You can specify which HTTP methods a route supports:
20 |
21 | ```python
22 | @app.route('/api/data', methods=['GET', 'POST'])
23 | def api_handler(request):
24 | if request.method == 'GET':
25 | return Response.json({'message': 'GET request'})
26 | elif request.method == 'POST':
27 | return Response.json({'message': 'POST request'})
28 | ```
29 |
30 | ## Route Parameters
31 |
32 | ### Query Parameters
33 |
34 | Access query parameters through the request object:
35 |
36 | ```python
37 | @app.route('/hello')
38 | def hello(request):
39 | name = request.query_params.get('name', ['World'])[0]
40 | return Response.html(f'Hello, {name}!')
41 | ```
42 |
43 | This route can be accessed as `/hello?name=John`
44 |
45 | ## Examples
46 |
47 | ### Basic HTML Response
48 | ```python
49 | @app.route('/')
50 | def home(request):
51 | return Response.html('Welcome
')
52 | ```
53 |
54 | ### JSON API Endpoint
55 | ```python
56 | @app.route('/api/user')
57 | def user_api(request):
58 | return Response.json({
59 | 'username': 'john_doe',
60 | 'email': 'john@example.com'
61 | })
62 | ```
63 |
64 | ### Template Response
65 | ```python
66 | @app.route('/profile')
67 | def profile(request):
68 | context = {'username': 'John'}
69 | return Response(app.render_template('profile.html', context))
70 | ```
71 |
72 | ## Error Handling
73 |
74 | SimWeb provides basic error handling for:
75 | - 404 Not Found (when a route doesn't exist)
76 | - 405 Method Not Allowed (when a method isn't supported for a route)
77 |
78 | You can customize these by extending the Application class and overriding:
79 | - `not_found()`
80 | - `method_not_allowed()`
81 |
82 | ## Next Steps
83 |
84 | - Understand [Request Handling](request-handling.md)
85 | - Explore [Response Handling](response-handling.md)
86 | - Master the [Template Engine](template-engine.md)
--------------------------------------------------------------------------------
/docs/request-handling.md:
--------------------------------------------------------------------------------
1 | # Request Handling in SimWeb
2 |
3 | SimWeb provides a `Request` class that encapsulates all the information about incoming HTTP requests.
4 |
5 | ## Request Object Properties
6 |
7 | ### Basic Properties
8 |
9 | - `path`: The URL path of the request
10 | - `method`: The HTTP method (GET, POST, etc.)
11 | - `headers`: Dictionary of request headers
12 | - `query_params`: Dictionary of query parameters
13 | - `body`: Raw request body data
14 |
15 | ## Working with Requests
16 |
17 | ### Accessing Query Parameters
18 |
19 | Query parameters are automatically parsed and available in the `query_params` dictionary:
20 |
21 | ```python
22 | @app.route('/search')
23 | def search(request):
24 | # URL: /search?q=python&page=1
25 | query = request.query_params.get('q', [''])[0]
26 | page = request.query_params.get('page', ['1'])[0]
27 | return Response.html(f'Searching for: {query} on page {page}')
28 | ```
29 |
30 | ### Handling JSON Data
31 |
32 | For requests with JSON data, use the `get_json()` method:
33 |
34 | ```python
35 | @app.route('/api/data', methods=['POST'])
36 | def handle_json(request):
37 | data = request.get_json()
38 | if data is None:
39 | return Response.json({'error': 'Invalid JSON'}, status=400)
40 | return Response.json({'received': data})
41 | ```
42 |
43 | ### Request Headers
44 |
45 | Access request headers through the `headers` dictionary:
46 |
47 | ```python
48 | @app.route('/headers')
49 | def show_headers(request):
50 | content_type = request.headers.get('Content-Type')
51 | user_agent = request.headers.get('User-Agent')
52 | return Response.json({
53 | 'content_type': content_type,
54 | 'user_agent': user_agent
55 | })
56 | ```
57 |
58 | ## Example Usage
59 |
60 | ### Complete Request Handler
61 |
62 | ```python
63 | @app.route('/api/users', methods=['GET', 'POST'])
64 | def users(request):
65 | if request.method == 'GET':
66 | # Handle GET request
67 | page = request.query_params.get('page', ['1'])[0]
68 | return Response.json({
69 | 'page': page,
70 | 'users': ['user1', 'user2']
71 | })
72 |
73 | elif request.method == 'POST':
74 | # Handle POST request
75 | data = request.get_json()
76 | if not data:
77 | return Response.json(
78 | {'error': 'Invalid JSON'},
79 | status=400
80 | )
81 | return Response.json({
82 | 'message': 'User created',
83 | 'data': data
84 | })
85 | ```
86 |
87 | ## Best Practices
88 |
89 | 1. Always validate input data
90 | 2. Check for required parameters
91 | 3. Handle potential errors gracefully
92 | 4. Use appropriate HTTP status codes
93 | 5. Consider security implications when handling user data
94 |
95 |
96 | ## Next Steps
97 |
98 | - Explore [Response Handling](response-handling.md)
99 | - Master the [Template Engine](template-engine.md)
--------------------------------------------------------------------------------
/docs/template-engine.md:
--------------------------------------------------------------------------------
1 | # Template Engine in SimWeb
2 |
3 | SimWeb includes a simple yet effective template engine that supports basic variable substitution and loops.
4 |
5 | ## Basic Usage
6 |
7 | ### Template Variables
8 |
9 | Use double curly braces to insert variables:
10 |
11 | ```html
12 | Hello, {{ name }}!
13 | ```
14 |
15 | ### For Loops
16 |
17 | Use {% for %} syntax for loops:
18 |
19 | ```html
20 |
21 | {% for item in items %}
22 | - {{ item }}
23 | {% endfor %}
24 |
25 | ```
26 |
27 | ## Template Directory
28 |
29 | Templates are stored in the `templates` directory by default. You can specify a different directory when initializing the application:
30 |
31 | ```python
32 | app = Application(templates_dir='my_templates')
33 | ```
34 |
35 | ## Rendering Templates
36 |
37 | ### Basic Template Rendering
38 |
39 | ```python
40 | @app.route('/')
41 | def home(request):
42 | context = {'name': 'World'}
43 | return Response(
44 | app.render_template('home.html', context)
45 | )
46 | ```
47 |
48 | ### Context Data
49 |
50 | The context is a dictionary that contains the variables available in the template:
51 |
52 | ```python
53 | context = {
54 | 'title': 'My Page',
55 | 'user': {
56 | 'name': 'John',
57 | 'email': 'john@example.com'
58 | },
59 | 'items': ['apple', 'banana', 'orange']
60 | }
61 | ```
62 |
63 | ## Example Templates
64 |
65 | ### Simple Page Template
66 | ```html
67 |
68 |
69 |
70 | {{ title }}
71 |
72 |
73 | Welcome, {{ user.name }}!
74 | Your email is: {{ user.email }}
75 |
76 |
77 | ```
78 |
79 | ### Template with Loop
80 | ```html
81 |
82 |
83 |
84 | Shopping List
85 |
86 |
87 | Shopping List
88 |
89 | {% for item in items %}
90 | - {{ item }}
91 | {% endfor %}
92 |
93 |
94 |
95 | ```
96 |
97 | ## Features
98 |
99 | The template engine supports:
100 | 1. Variable substitution using {{ variable }}
101 | 2. Simple for loops using {% for item in items %}
102 | 3. Nested context variables (e.g., user.name)
103 | 4. Automatic HTML escaping
104 |
105 | ## Best Practices
106 |
107 | 1. Keep templates simple and focused
108 | 2. Use meaningful variable names
109 | 3. Organize templates in a clear directory structure
110 | 4. Separate logic from presentation
111 | 5. Reuse common templates when possible
112 |
113 | ## Limitations
114 |
115 | The current template engine implementation has some limitations:
116 |
117 | 1. Basic variable substitution only
118 | 2. Simple for loops without complex logic
119 | 3. No if/else conditionals
120 | 4. No template inheritance
121 | 5. No filters or custom functions
122 |
123 | These limitations make it ideal for learning and simple applications, while keeping the codebase clean and understandable.
124 |
125 | ## Next Steps
126 |
127 | Write your first website using SimWeb
--------------------------------------------------------------------------------
/docs/response-handling.md:
--------------------------------------------------------------------------------
1 | # Response Handling in SimWeb
2 |
3 | SimWeb provides a flexible `Response` class for handling different types of HTTP responses.
4 |
5 | ## Response Class
6 |
7 | The Response class is used to create HTTP responses with:
8 | - Response body
9 | - Status code
10 | - Content type
11 | - Custom headers
12 |
13 | ## Basic Usage
14 |
15 | ### Creating Simple Responses
16 |
17 | ```python
18 | # Basic HTML response
19 | response = Response('Hello World
')
20 |
21 | # Response with custom status code
22 | response = Response('Not Found', status=404)
23 |
24 | # Response with custom content type
25 | response = Response(
26 | 'Plain text content',
27 | content_type='text/plain'
28 | )
29 | ```
30 |
31 | ## Response Helper Methods
32 |
33 | ### HTML Responses
34 |
35 | Use the `html` class method for HTML responses:
36 |
37 | ```python
38 | @app.route('/')
39 | def home(request):
40 | return Response.html('Welcome
')
41 | ```
42 |
43 | ### JSON Responses
44 |
45 | Use the `json` class method for JSON responses:
46 |
47 | ```python
48 | @app.route('/api/data')
49 | def api_data(request):
50 | return Response.json({
51 | 'message': 'Success',
52 | 'data': [1, 2, 3]
53 | })
54 | ```
55 |
56 | ## Template Responses
57 |
58 | When using templates:
59 |
60 | ```python
61 | @app.route('/profile')
62 | def profile(request):
63 | context = {
64 | 'username': 'John',
65 | 'email': 'john@example.com'
66 | }
67 | return Response(
68 | app.render_template('profile.html', context)
69 | )
70 | ```
71 |
72 | ## Common HTTP Status Codes
73 |
74 | SimWeb supports all standard HTTP status codes. Common ones include:
75 |
76 | - 200: OK (default)
77 | - 201: Created
78 | - 400: Bad Request
79 | - 401: Unauthorized
80 | - 403: Forbidden
81 | - 404: Not Found
82 | - 405: Method Not Allowed
83 | - 500: Internal Server Error
84 |
85 | Example using status codes:
86 |
87 | ```python
88 | @app.route('/api/resource', methods=['POST'])
89 | def create_resource(request):
90 | data = request.get_json()
91 | if not data:
92 | return Response.json(
93 | {'error': 'Invalid data'},
94 | status=400
95 | )
96 | # Create resource...
97 | return Response.json(
98 | {'message': 'Created'},
99 | status=201
100 | )
101 | ```
102 |
103 | ## Best Practices
104 |
105 | 1. Always set appropriate status codes
106 | 2. Use correct content types
107 | 3. Structure JSON responses consistently
108 | 4. Handle errors gracefully with proper error responses
109 | 5. Consider security headers when necessary
110 |
111 | ## Example: Complete Response Handling
112 |
113 | ```python
114 | @app.route('/api/users/:id')
115 | def get_user(request):
116 | user_id = request.query_params.get('id', [''])[0]
117 |
118 | if not user_id:
119 | return Response.json({
120 | 'error': 'User ID required'
121 | }, status=400)
122 |
123 | try:
124 | # Simulate user lookup
125 | if user_id == '1':
126 | return Response.json({
127 | 'id': '1',
128 | 'name': 'John Doe'
129 | })
130 | else:
131 | return Response.json({
132 | 'error': 'User not found'
133 | }, status=404)
134 | except Exception as e:
135 | return Response.json({
136 | 'error': 'Server error'
137 | }, status=500)
138 | ```
139 |
140 | ## Next Steps
141 |
142 | - Master the [Template Engine](template-engine.md)
--------------------------------------------------------------------------------
/application.py:
--------------------------------------------------------------------------------
1 | from http.server import HTTPServer, BaseHTTPRequestHandler
2 | from urllib.parse import parse_qs
3 | import json
4 | from template_engine import TemplateEngine
5 |
6 |
7 | class Application:
8 | def __init__(self, templates_dir="templates"):
9 | self.routes = {}
10 | self.template_engine = TemplateEngine(templates_dir)
11 |
12 | def route(self, path, methods=None):
13 | if methods is None:
14 | methods = ["GET"]
15 |
16 | def decorator(handler):
17 | self.routes[path] = {"handler": handler, "methods": methods}
18 | return handler
19 |
20 | return decorator
21 |
22 | def handle_request(self, request):
23 | path = request.path.split("?")[0] # Remove query string for routing
24 | method = request.method
25 |
26 | if path in self.routes:
27 | route = self.routes[path]
28 | if method in route["methods"]:
29 | return route["handler"](request)
30 | else:
31 | return self.method_not_allowed()
32 | else:
33 | return self.not_found()
34 |
35 | def not_found(self):
36 | return Response("Not Found", status=404)
37 |
38 | def method_not_allowed(self):
39 | return Response("Method Not Allowed", status=405)
40 |
41 | def render_template(self, template_name, context=None):
42 | return self.template_engine.render(template_name, context)
43 |
44 | def run(self, host="localhost", port=8000):
45 | class RequestHandler(BaseHTTPRequestHandler):
46 | def do_GET(self):
47 | self.handle_request()
48 |
49 | def do_POST(self):
50 | self.handle_request()
51 |
52 | def handle_request(self):
53 | request = Request(self)
54 | response = self.server.app.handle_request(request)
55 | self.send_response(response.status)
56 | for header, value in response.headers.items():
57 | self.send_header(header, value)
58 | self.end_headers()
59 | self.wfile.write(response.body.encode())
60 |
61 | server = HTTPServer((host, port), RequestHandler)
62 | server.app = self
63 | print(f"Running on http://{host}:{port}")
64 | server.serve_forever()
65 |
66 |
67 | class Request:
68 | def __init__(self, handler):
69 | self.path = handler.path
70 | self.method = handler.command # Changed from 'cmd' to 'command'
71 | self.headers = handler.headers
72 | self.query_params = (
73 | parse_qs(handler.path.split("?")[1]) if "?" in handler.path else {}
74 | )
75 | self.body = self._get_body(handler)
76 |
77 | def _get_body(self, handler):
78 | content_length = int(handler.headers.get("Content-Length", 0))
79 | return handler.rfile.read(content_length) if content_length > 0 else b""
80 |
81 | def get_json(self):
82 | if self.headers.get("Content-Type") == "application/json":
83 | return json.loads(self.body)
84 | return None
85 |
86 |
87 | class Response:
88 | def __init__(self, body, status=200, content_type="text/html"):
89 | self.body = body
90 | self.status = status
91 | self.headers = {"Content-Type": content_type}
92 |
93 | @classmethod
94 | def html(cls, content):
95 | return cls(content)
96 |
97 | @classmethod
98 | def json(cls, content):
99 | return cls(json.dumps(content), content_type="application/json")
100 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------