This commit is contained in:
2024-11-29 18:15:30 +00:00
parent 40aade2d8e
commit bc9415586e
5298 changed files with 1938676 additions and 80 deletions

View File

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@ -0,0 +1,612 @@
Metadata-Version: 2.1
Name: dominate
Version: 2.9.1
Summary: Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API.
Author: Jake Wharton
Author-email: Tom Flanagan <tom@zkpq.ca>
License: LGPL-3.0-or-newer
Project-URL: Homepage, https://github.com/Knio/dominate
Project-URL: Source, https://github.com/Knio/dominate
Keywords: framework,templating,template,html,xhtml,python,html5
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Markup :: HTML
Requires-Python: >=3.4
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Dominate
========
`Dominate` is a Python library for creating and manipulating HTML documents using an elegant DOM API.
It allows you to write HTML pages in pure Python very concisely, which eliminates the need to learn another template language, and lets you take advantage of the more powerful features of Python.
![Python version](https://img.shields.io/pypi/pyversions/dominate.svg?style=flat)
[![Build status](https://github.com/Knio/dominate/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Knio/dominate/actions/workflows/ci.yml?query=branch%3Amaster+)
[![Coverage status](https://img.shields.io/coveralls/github/Knio/dominate/master.svg?style=flat)](https://coveralls.io/r/Knio/dominate?branch=master)
Python:
```python
import dominate
from dominate.tags import *
doc = dominate.document(title='Dominate your HTML')
with doc.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
with doc:
with div(id='header').add(ol()):
for i in ['home', 'about', 'contact']:
li(a(i.title(), href='/%s.html' % i))
with div():
attr(cls='body')
p('Lorem ipsum..')
print(doc)
```
Output:
```html
<!DOCTYPE html>
<html>
<head>
<title>Dominate your HTML</title>
<link href="style.css" rel="stylesheet">
<script src="script.js" type="text/javascript"></script>
</head>
<body>
<div id="header">
<ol>
<li>
<a href="/home.html">Home</a>
</li>
<li>
<a href="/about.html">About</a>
</li>
<li>
<a href="/contact.html">Contact</a>
</li>
</ol>
</div>
<div class="body">
<p>Lorem ipsum..</p>
</div>
</body>
</html>
```
Installation
------------
The recommended way to install `dominate` is with
[`pip`](http://pypi.python.org/pypi/pip/):
pip install dominate
[![PyPI version](https://img.shields.io/pypi/v/dominate.svg?style=flat)](https://pypi.org/project/dominate/)
[![PyPI downloads](https://img.shields.io/pypi/dm/dominate.svg?style=flat)](https://pypi.org/project/dominate/)
Developed By
------------
* Tom Flanagan - <tom@zkpq.ca>
* Jake Wharton - <jakewharton@gmail.com>
* [Brad Janke](//github.com/bradj)
Git repository located at
[github.com/Knio/dominate](//github.com/Knio/dominate)
Examples
========
All examples assume you have imported the appropriate tags or entire tag set:
```python
from dominate.tags import *
```
Hello, World!
-------------
The most basic feature of `dominate` exposes a class for each HTML element, where the constructor
accepts child elements, text, or keyword attributes. `dominate` nodes return their HTML representation
from the `__str__`, `__unicode__`, and `render()` methods.
```python
print(html(body(h1('Hello, World!'))))
```
```html
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
```
Attributes
----------
`Dominate` can also use keyword arguments to append attributes onto your tags. Most of the attributes are a direct copy from the HTML spec with a few variations.
For attributes `class` and `for` which conflict with Python's [reserved keywords](http://docs.python.org/2/reference/lexical_analysis.html#keywords "Reserved Keywords"), you can use the following aliases:
| class | for |
|-------|-----|
|_class | _for |
|cls | fr |
|className|htmlFor|
|class_name|html_for|
```python
test = label(cls='classname anothername', fr='someinput')
print(test)
```
```html
<label class="classname anothername" for="someinput"></label>
```
Use `data_*` for [custom HTML5 data attributes](http://www.w3.org/html/wg/drafts/html/master/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes "HTML5 Data Attributes").
```python
test = div(data_employee='101011')
print(test)
```
```html
<div data-employee="101011"></div>
```
You can also modify the attributes of tags through a dictionary-like interface:
```python
header = div()
header['id'] = 'header'
print(header)
```
```html
<div id="header"></div>
```
Complex Structures
------------------
Through the use of the `+=` operator and the `.add()` method you can easily create more advanced structures.
Create a simple list:
```python
list = ul()
for item in range(4):
list += li('Item #', item)
print(list)
```
```html
<ul>
<li>Item #0</li>
<li>Item #1</li>
<li>Item #2</li>
<li>Item #3</li>
</ul>
```
`dominate` supports iterables to help streamline your code:
```python
print(ul(li(a(name, href=link), __pretty=False) for name, link in menu_items))
```
```html
<ul>
<li><a href="/home/">Home</a></li>
<li><a href="/about/">About</a></li>
<li><a href="/downloads/">Downloads</a></li>
<li><a href="/links/">Links</a></li>
</ul>
```
A simple document tree:
```python
_html = html()
_body = _html.add(body())
header = _body.add(div(id='header'))
content = _body.add(div(id='content'))
footer = _body.add(div(id='footer'))
print(_html)
```
```html
<html>
<body>
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
</body>
</html>
```
For clean code, the `.add()` method returns children in tuples. The above example can be cleaned up and expanded like this:
```python
_html = html()
_head, _body = _html.add(head(title('Simple Document Tree')), body())
names = ['header', 'content', 'footer']
header, content, footer = _body.add([div(id=name) for name in names])
print(_html)
```
```html
<html>
<head>
<title>Simple Document Tree</title>
</head>
<body>
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
</body>
</html>
```
You can modify the attributes of tags through a dictionary-like interface:
```python
header = div()
header['id'] = 'header'
print(header)
```
```html
<div id="header"></div>
```
Or the children of a tag though an array-line interface:
```python
header = div('Test')
header[0] = 'Hello World'
print(header)
```
```html
<div>Hello World</div>
```
Comments can be created using objects too!
```python
print(comment('BEGIN HEADER'))
```
```html
<!--BEGIN HEADER-->
```
```python
print(comment(p('Upgrade to newer IE!'), condition='lt IE9'))
```
```html
<!--[if lt IE9]>
<p>Upgrade to newer IE!</p>
<![endif]-->
```
Rendering
---------
By default, `render()` tries to make all output human readable, with one HTML
element per line and two spaces of indentation.
This behavior can be controlled by the `__pretty` (default: `True` except for
certain element types like `pre`) attribute when creating an element, and by
the `pretty` (default: `True`), `indent` (default: ` `) and `xhtml` (default: `False`)
arguments to `render()`. Rendering options propagate to all descendant nodes.
```python
a = div(span('Hello World'))
print(a.render())
```
```html
<div>
<span>Hello World</span>
</div>
```
```python
print(a.render(pretty=False))
```
```html
<div><span>Hello World</span></div>
```
```python
print(a.render(indent='\t'))
```
```html
<div>
<span>Hello World</span>
</div>
```
```python
a = div(span('Hello World'), __pretty=False)
print(a.render())
```
```html
<div><span>Hello World</span></div>
```
```python
d = div()
with d:
hr()
p("Test")
br()
print(d.render())
print(d.render(xhtml=True))
```
```html
<div>
<hr>
<p>Test</p><br>
</div>
<div>
<hr />
<p>Test</p><br />
</div>
```
Context Managers
----------------
You can also add child elements using Python's `with` statement:
```python
h = ul()
with h:
li('One')
li('Two')
li('Three')
print(h)
```
```html
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
```
You can use this along with the other mechanisms of adding children elements, including nesting `with` statements, and it works as expected:
```python
h = html()
with h.add(body()).add(div(id='content')):
h1('Hello World!')
p('Lorem ipsum ...')
with table().add(tbody()):
l = tr()
l += td('One')
l.add(td('Two'))
with l:
td('Three')
print(h)
```
```html
<html>
<body>
<div id="content">
<h1>Hello World!</h1>
<p>Lorem ipsum ...</p>
<table>
<tbody>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
```
When the context is closed, any nodes that were not already added to something get added to the current context.
Attributes can be added to the current context with the `attr` function:
```python
d = div()
with d:
attr(id='header')
print(d)
```
```html
<div id="header"></div>
```
And text nodes can be added with the `dominate.util.text` function:
```python
from dominate.util import text
para = p(__pretty=False)
with para:
text('Have a look at our ')
a('other products', href='/products')
print(para)
```
```html
<p>Have a look at our <a href="/products">other products</a></p>
```
Decorators
----------
`Dominate` is great for creating reusable widgets for parts of your page. Consider this example:
```python
def greeting(name):
with div() as d:
p('Hello, %s' % name)
return d
print(greeting('Bob'))
```
```html
<div>
<p>Hello, Bob</p>
</div>
```
You can see the following pattern being repeated here:
```python
def widget(parameters):
with tag() as t:
...
return t
```
This boilerplate can be avoided by using tags (objects and instances) as decorators
```python
@div
def greeting(name):
p('Hello %s' % name)
print(greeting('Bob'))
```
```html
<div>
<p>Hello Bob</p>
</div>
```
The decorated function will return a new instance of the tag used to decorate it, and execute in a `with` context which will collect all the nodes created inside it.
You can also use instances of tags as decorators, if you need to add attributes or other data to the root node of the widget.
Each call to the decorated function will return a copy of the node used to decorate it.
```python
@div(h2('Welcome'), cls='greeting')
def greeting(name):
p('Hello %s' % name)
print(greeting('Bob'))
```
```html
<div class="greeting">
<h2>Welcome</h2>
<p>Hello Bob</p>
</div>
```
Creating Documents
------------------
Since creating the common structure of an HTML document everytime would be excessively tedious dominate provides a class to create and manage them for you: `document`.
When you create a new document, the basic HTML tag structure is created for you.
```python
d = document()
print(d)
```
```html
<!DOCTYPE html>
<html>
<head>
<title>Dominate</title>
</head>
<body></body>
</html>
```
The `document` class accepts `title`, `doctype`, and `request` keyword arguments.
The default values for these arguments are `Dominate`, `<!DOCTYPE html>`, and `None` respectively.
The `document` class also provides helpers to allow you to access the `title`, `head`, and `body` nodes directly.
```python
d = document()
```
```python
>>> d.head
<dominate.tags.head: 0 attributes, 1 children>
>>> d.body
<dominate.tags.body: 0 attributes, 0 children>
>>> d.title
u'Dominate'
```
The `document` class also provides helpers to allow you to directly add nodes to the `body` tag.
```python
d = document()
d += h1('Hello, World!')
d += p('This is a paragraph.')
print(d)
```
```html
<!DOCTYPE html>
<html>
<head>
<title>Dominate</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a paragraph.</p>
</body>
</html>
```
Embedding HTML
--------------
If you need to embed a node of pre-formed HTML coming from a library such as markdown or the like, you can avoid escaped HTML by using the raw method from the dominate.util package:
```
from dominate.util import raw
...
td(raw('<a href="example.html">Example</a>'))
```
Without the raw call, this code would render escaped HTML with lt, etc.
SVG
---
The `dominate.svg` module contains SVG tags similar to how `dominate.tags` contains HTML tags. SVG elements will automatically convert `_` to `-` for dashed elements. For example:
```python
from dominate.svg import *
print(circle(stroke_width=5))
```
```html
<circle stroke-width="5"></circle>
```

View File

@ -0,0 +1,22 @@
dominate-2.9.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
dominate-2.9.1.dist-info/LICENSE.txt,sha256=nM8mz-hF4OuLtYBT5HNm56traXrgEPdlCXjUtxt9H8E,7637
dominate-2.9.1.dist-info/METADATA,sha256=N-7LJV5L2WLqvpKPGA6EPYnf6ed2B04flZCLbJwsZWM,13673
dominate-2.9.1.dist-info/RECORD,,
dominate-2.9.1.dist-info/WHEEL,sha256=bb2Ot9scclHKMOLDEHY6B2sicWOgugjFKaJsT7vwMQo,110
dominate-2.9.1.dist-info/top_level.txt,sha256=lkq2NuHoGLvvjfSl6OLHyLNBidBuRCf1CbUpKhH-lYY,9
dominate/__init__.py,sha256=qZ6CLTkIM6XUGeCvrWxODTC0KwHqdGHhuPK_IOq9FN8,88
dominate/__pycache__/__init__.cpython-312.pyc,,
dominate/__pycache__/_version.cpython-312.pyc,,
dominate/__pycache__/document.cpython-312.pyc,,
dominate/__pycache__/dom1core.cpython-312.pyc,,
dominate/__pycache__/dom_tag.cpython-312.pyc,,
dominate/__pycache__/svg.cpython-312.pyc,,
dominate/__pycache__/tags.cpython-312.pyc,,
dominate/__pycache__/util.cpython-312.pyc,,
dominate/_version.py,sha256=GbsReBQFPhB6a_q8Z29ZlN6su5QplX7xbYNCMunZnmI,22
dominate/document.py,sha256=Y8rRKqoFdnJInVT6XmlB_wqbaXkhmNzRp0jtqY7kpgg,2243
dominate/dom1core.py,sha256=GwXNJ3P-Ab7eo5nBwohe0lJLNXD9d6hizcqy6AjAMTA,1734
dominate/dom_tag.py,sha256=Pzwvgequ201IjULjoYmXvGb0AIVVb_T_HYaepeJ1d9I,14131
dominate/svg.py,sha256=r6GUaBZ-1lhlQVtKeX4s3svap8ePSpDbaFonIsIRGXs,9121
dominate/tags.py,sha256=OcKwrFHxjKlsS1VUhAcajxM55lGGsFEkuAUxwXllqvk,28643
dominate/util.py,sha256=0vMJrJKzTLqpDdstnbC3LTXNv8TxDXvWKSRV6kv_Ung,4311

View File

@ -0,0 +1,6 @@
Wheel-Version: 1.0
Generator: bdist_wheel (0.38.4)
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any

View File

@ -0,0 +1 @@
dominate