htmy 0.7.3__py3-none-any.whl → 0.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of htmy might be problematic. Click here for more details.

htmy/etree.py CHANGED
@@ -1,23 +1,37 @@
1
1
  from __future__ import annotations
2
2
 
3
- import xml.etree.ElementTree as ET
4
- from collections.abc import Callable, Generator
5
3
  from typing import TYPE_CHECKING, ClassVar
6
4
  from xml.sax.saxutils import unescape
7
5
 
8
- if TYPE_CHECKING:
9
- from collections.abc import Mapping
10
- from xml.etree.ElementTree import Element
11
-
12
- from htmy.typing import ComponentType, Properties
13
-
6
+ try:
7
+ from lxml.etree import _Element as Element
8
+ from lxml.etree import tostring as etree_to_string
9
+ from lxml.html import fragment_fromstring as etree_from_string
10
+ except ImportError:
11
+ from xml.etree.ElementTree import Element # type: ignore[assignment]
12
+ from xml.etree.ElementTree import fromstring as etree_from_string # type: ignore[assignment]
13
+ from xml.etree.ElementTree import tostring as etree_to_string # type: ignore[no-redef]
14
14
 
15
+ from htmy import ComponentType, Properties
15
16
  from htmy.core import Fragment, SafeStr, WildcardTag
16
17
 
18
+ if TYPE_CHECKING:
19
+ from collections.abc import Callable, Generator, Mapping
20
+
17
21
 
18
22
  class ETreeConverter:
19
23
  """
20
24
  Utility for converting XML strings to custom components.
25
+
26
+ By default the converter uses the standard library's `xml.etree.ElementTree`
27
+ module for string to element tree, and element tree to string conversion,
28
+ but if `lxml` is installed, it will be used instead.
29
+
30
+ Installing `lxml` is recommended for better performance and additional features,
31
+ like performance and support for broken HTML fragments. **Important:** `lxml` is
32
+ far more lenient and flexible than the standard library, so having it installed is
33
+ not only a performance boost, but it may also slightly change the element conversion
34
+ behavior in certain edge-cases!
21
35
  """
22
36
 
23
37
  __slots__ = ("_rules",)
@@ -43,15 +57,15 @@ class ETreeConverter:
43
57
  return SafeStr(element)
44
58
 
45
59
  element = f"<{self._htmy_fragment}>{element}</{self._htmy_fragment}>"
46
- return self.convert_element(ET.fromstring(element)) # noqa: S314 # Only use from XML strings from a trusted source.
60
+ return self.convert_element(etree_from_string(element)) # noqa: S314 # Only use XML strings from a trusted source.
47
61
 
48
62
  def convert_element(self, element: Element) -> ComponentType:
49
63
  """Converts the given `Element` to a component."""
50
64
  rules = self._rules
51
65
  if len(rules) == 0:
52
- return SafeStr(ET.tostring(element))
66
+ return SafeStr(etree_to_string(element, encoding="unicode"))
53
67
 
54
- tag: str = element.tag
68
+ tag: str = element.tag # type: ignore[assignment]
55
69
  component = Fragment if tag == self._htmy_fragment else rules.get(tag)
56
70
  children = self._convert_children(element)
57
71
  properties = self._convert_properties(element)
htmy/html.py CHANGED
@@ -285,7 +285,7 @@ class hr(TagWithProps):
285
285
  __slots__ = ()
286
286
 
287
287
 
288
- class iframe(TagWithProps):
288
+ class iframe(Tag):
289
289
  """
290
290
  `<iframe>` element.
291
291
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: htmy
3
- Version: 0.7.3
3
+ Version: 0.8.0
4
4
  Summary: Async, pure-Python server-side rendering engine.
5
5
  License: MIT
6
6
  Author: Peter Volf
@@ -12,9 +12,11 @@ Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
+ Provides-Extra: lxml
15
16
  Requires-Dist: anyio (>=4.6.2.post1,<5.0.0)
16
17
  Requires-Dist: async-lru (>=2.0.4,<3.0.0)
17
- Requires-Dist: markdown (>=3.7,<4.0)
18
+ Requires-Dist: lxml (>=6.0.0) ; extra == "lxml"
19
+ Requires-Dist: markdown (>=3.8,<4.0)
18
20
  Description-Content-Type: text/markdown
19
21
 
20
22
  ![Tests](https://github.com/volfpeter/htmy/actions/workflows/tests.yml/badge.svg)
@@ -47,6 +49,20 @@ Unleash your creativity with the full power and Python, without the hassle of le
47
49
  - Automatic and customizable **property-name conversion** from snake case to kebab case.
48
50
  - **Fully-typed**.
49
51
 
52
+ ## Testimonials
53
+
54
+ "Thank you for your work on `fasthx`, as well as `htmy`! I've never had an easier time developing with another stack." ([ref](https://github.com/volfpeter/fasthx/discussions/77))
55
+
56
+ "One of the main parts of the `FastAPI` -> `fasthx` -> `htmy` integration I'm falling in love with is its explicitness, and not too much magic happening." ([ref](https://github.com/volfpeter/fasthx/issues/54))
57
+
58
+ "Thank you for your work on `htmy` and `fasthx`, both have been very pleasant to use, and the APIs are both intuitive and simple. Great work." ([ref](https://github.com/volfpeter/fasthx/issues/54))
59
+
60
+ "I love that the language-embedded HTML generation library approach is becoming more popular." ([ref](https://www.reddit.com/r/programming/comments/1h1a0dx/comment/lzd3phw))
61
+
62
+ "Neat approach and it naturally solves the partial templates problem 👍" ([ref](https://www.reddit.com/r/Python/comments/1gp3mww/comment/lwqj4fc))
63
+
64
+ "Great API design!" ([ref](https://www.reddit.com/r/Python/comments/1gp3mww/comment/lwpdyq9))
65
+
50
66
  ## Support
51
67
 
52
68
  Consider supporting the development and maintenance of the project through [sponsoring](https://buymeacoffee.com/volfpeter), or reach out for [consulting](https://www.volfp.com/contact?subject=Consulting%20-%20HTMY) so you can get the most out of the library.
@@ -59,6 +75,10 @@ The package is available on PyPI and can be installed with:
59
75
  $ pip install htmy
60
76
  ```
61
77
 
78
+ The package has the following optional dependencies:
79
+
80
+ - `lxml` *(recommended)*: When installed, it is prioritized over `xml.etree.ElementTree` and provides more secure, faster, and more flexible HTML and XML processing. It is used, for example, for Markdown processing. Install with: `pip install "htmy[lxml]"`.
81
+
62
82
  ## Concepts
63
83
 
64
84
  The entire library -- from the rendering engine itself to the built-in components -- is built around a few simple protocols and a handful of simple utility classes. This means that you can easily customize, extend, or replace basically everything in the library. Yes, even the rendering engine. The remaining parts will keep working as expected.
@@ -1,8 +1,8 @@
1
1
  htmy/__init__.py,sha256=Us5P9Y6ZSp38poIz88bsAh2Hxuze5jE3V_uMtMyuH-E,1880
2
2
  htmy/core.py,sha256=mvNbxTRS8HNnjMSwe4NEJdL1KF19pJImF4Ciip6837I,15484
3
- htmy/etree.py,sha256=yKxom__AdsJY-Q1kbU0sdTMr0ZF5dMSVBKxayntNFyQ,3062
3
+ htmy/etree.py,sha256=3znZCYQ5xbNqyXYSYFkUh6M22QLWMYWhTNjUcgpjCLc,4051
4
4
  htmy/function_component.py,sha256=iSp5cGrErmIsc-VfNq053_J2m-Nuu_k2xK9UxvEnlw8,12431
5
- htmy/html.py,sha256=7UohfPRtl-3IoSbOiDxazsSHQpCZ0tyRdNayQISPM8A,21086
5
+ htmy/html.py,sha256=dXYLYmyW1VR4mesib2iBLLdqMBAP3y4JmeGFZs6RLgI,21077
6
6
  htmy/i18n.py,sha256=Kobvm9mFoNcJas52KQbheiRIzJF1Ad1azOhtfm_k0BE,5123
7
7
  htmy/io.py,sha256=oEXXVnpdbjs2NzAGi36Pept-pyvXshEGHrbBFzcHYio,344
8
8
  htmy/md/__init__.py,sha256=lxBJnYplkDuxYuiese6My9KYp1DeGdzo70iUdYTvMnE,334
@@ -15,7 +15,7 @@ htmy/renderer/default.py,sha256=G6K5YptvH9QvEvMQZdLPtgUblO_zTv4Eo6TETHZDlX8,1086
15
15
  htmy/snippet.py,sha256=9-ltfs4rugv6kFNzAY0PYNP3YI3xvJG8lkxEnYcCYWw,10538
16
16
  htmy/typing.py,sha256=0spTpz_JWql2yy_lSlRx0uqgXar7fxwyBqWeIzltvKU,3111
17
17
  htmy/utils.py,sha256=Kp0j9G8CBeRiyFGmz-CoDiLtXHfpvHzlTVsWeDhIebM,1935
18
- htmy-0.7.3.dist-info/LICENSE,sha256=rFtoGU_3c_rlacXgOZapTHfMErN-JFPT5Bq_col4bqI,1067
19
- htmy-0.7.3.dist-info/METADATA,sha256=T3hOzzQL_Al4cNT_Fruj-IM1pbMMkvKFCX9KBUdJlcY,18714
20
- htmy-0.7.3.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
21
- htmy-0.7.3.dist-info/RECORD,,
18
+ htmy-0.8.0.dist-info/LICENSE,sha256=rFtoGU_3c_rlacXgOZapTHfMErN-JFPT5Bq_col4bqI,1067
19
+ htmy-0.8.0.dist-info/METADATA,sha256=bJLl5E0h85GOmvrmukpKHtxfiwQjwPQum2l1e0fCrWw,20123
20
+ htmy-0.8.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
21
+ htmy-0.8.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.1
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
File without changes