Skip to content

Commit 9d50efe

Browse files
Copilotjaraco
andauthored
Initial plan for cssText to return text instead of bytes
Agent-Logs-Url: https://github.com/jaraco/cssutils/sessions/3fa81fde-23b2-4404-af80-0fc6925ccf1b Co-authored-by: jaraco <308610+jaraco@users.noreply.github.com>
1 parent 100429b commit 9d50efe

52 files changed

Lines changed: 857 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LICENSE

Lines changed: 304 additions & 0 deletions
Large diffs are not rendered by default.
2.97 KB
Binary file not shown.

cssutils.egg-info/PKG-INFO

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
Metadata-Version: 2.4
2+
Name: cssutils
3+
Version: 2.15.1.dev1+g100429bce
4+
Summary: A CSS Cascading Style Sheets library for Python
5+
Author-email: Christof Hoeke <c@cthedot.de>
6+
Maintainer-email: "Jason R. Coombs" <jaraco@jaraco.com>
7+
License-Expression: LGPL-3.0-or-later
8+
Project-URL: Source, https://github.com/jaraco/cssutils
9+
Keywords: CSS,Cascading Style Sheets,CSSParser,DOM Level 2 Stylesheets,DOM Level 2 CSS
10+
Classifier: Development Status :: 5 - Production/Stable
11+
Classifier: Intended Audience :: Developers
12+
Classifier: Programming Language :: Python :: 3
13+
Classifier: Programming Language :: Python :: 3 :: Only
14+
Classifier: Topic :: Internet
15+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
16+
Classifier: Topic :: Text Processing :: Markup :: HTML
17+
Requires-Python: >=3.10
18+
Description-Content-Type: text/x-rst
19+
License-File: LICENSE
20+
Requires-Dist: more_itertools
21+
Requires-Dist: encutils
22+
Provides-Extra: test
23+
Requires-Dist: pytest!=8.1.*,>=6; extra == "test"
24+
Requires-Dist: lxml; python_version < "3.11" and extra == "test"
25+
Requires-Dist: cssselect; extra == "test"
26+
Requires-Dist: importlib_resources; python_version < "3.9" and extra == "test"
27+
Requires-Dist: jaraco.test>=5.1; extra == "test"
28+
Provides-Extra: doc
29+
Requires-Dist: sphinx>=3.5; extra == "doc"
30+
Requires-Dist: jaraco.packaging>=9.3; extra == "doc"
31+
Requires-Dist: rst.linker>=1.9; extra == "doc"
32+
Requires-Dist: furo; extra == "doc"
33+
Requires-Dist: sphinx-lint; extra == "doc"
34+
Requires-Dist: jaraco.tidelift>=1.4; extra == "doc"
35+
Provides-Extra: check
36+
Requires-Dist: pytest-checkdocs>=2.14; extra == "check"
37+
Requires-Dist: pytest-ruff>=0.2.1; sys_platform != "cygwin" and extra == "check"
38+
Provides-Extra: cover
39+
Requires-Dist: pytest-cov; extra == "cover"
40+
Provides-Extra: enabler
41+
Requires-Dist: pytest-enabler>=3.4; extra == "enabler"
42+
Provides-Extra: type
43+
Requires-Dist: pytest-mypy>=1.0.1; platform_python_implementation != "PyPy" and extra == "type"
44+
Dynamic: license-file
45+
46+
.. image:: https://img.shields.io/pypi/v/cssutils.svg
47+
:target: https://pypi.org/project/cssutils
48+
49+
.. image:: https://img.shields.io/pypi/pyversions/cssutils.svg
50+
51+
.. image:: https://github.com/jaraco/cssutils/actions/workflows/main.yml/badge.svg
52+
:target: https://github.com/jaraco/cssutils/actions?query=workflow%3A%22tests%22
53+
:alt: tests
54+
55+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
56+
:target: https://github.com/astral-sh/ruff
57+
:alt: Ruff
58+
59+
.. image:: https://readthedocs.org/projects/cssutils/badge/?version=latest
60+
:target: https://cssutils.readthedocs.io/en/latest/?badge=latest
61+
62+
.. image:: https://img.shields.io/badge/skeleton-2026-informational
63+
:target: https://blog.jaraco.com/skeleton
64+
65+
.. image:: https://tidelift.com/badges/package/pypi/cssutils
66+
:target: https://tidelift.com/subscription/pkg/pypi-cssutils?utm_source=pypi-cssutils&utm_medium=readme
67+
68+
69+
Overview
70+
========
71+
A Python package to parse and build CSS Cascading Style Sheets. DOM only, not any rendering facilities!
72+
73+
You can find more documentation at `cssutils.readthedocs.io <https://cssutils.readthedocs.io>`_.
74+
75+
Based upon and partly implementing the following specifications :
76+
77+
`CSS 2.1rev1 <http://www.w3.org/TR/CSS2/>`__
78+
General CSS rules and properties are defined here
79+
`CSS3 Module: Syntax <http://www.w3.org/TR/css3-syntax/>`__
80+
Used in parts since cssutils 0.9.4. cssutils tries to use the features from CSS 2.1 and CSS 3 with preference to CSS3 but as this is not final yet some parts are from CSS 2.1
81+
`CSS Fonts Module Level 3 <http://www.w3.org/TR/css3-fonts/>`__
82+
Added changes and additional stuff (since cssutils v0.9.6)
83+
`MediaQueries <http://www.w3.org/TR/css3-mediaqueries/>`__
84+
MediaQueries are part of ``stylesheets.MediaList`` since v0.9.4, used in @import and @media rules.
85+
`Namespaces <http://dev.w3.org/csswg/css3-namespace/>`__
86+
Added in v0.9.1, updated to definition in CSSOM in v0.9.4, updated in 0.9.5 for dev version
87+
`CSS3 Module: Pages Media <http://www.w3.org/TR/css3-page/>`__
88+
Most properties of this spec are implemented including MarginRules
89+
`Selectors <http://www.w3.org/TR/css3-selectors/>`__
90+
The selector syntax defined here (and not in CSS 2.1) should be parsable with cssutils (*should* mind though ;) )
91+
`CSS Backgrounds and Borders Module Level 3 <http://www.w3.org/TR/css3-background/>`__, `CSS3 Basic User Interface Module <http://www.w3.org/TR/css3-ui/#resize>`__, `CSS Text Level 3 <http://www.w3.org/TR/css3-text/>`__
92+
Some validation for properties included, mainly `cursor`, `outline`, `resize`, `box-shadow`, `text-shadow`
93+
`Variables <http://disruptive-innovations.com/zoo/cssvariables/>`__ / `CSS Custom Properties <http://dev.w3.org/csswg/css-variables/>`__
94+
Experimental specification of CSS Variables which cssutils implements partly. The vars defined in the newer CSS Custom Properties spec should in main parts be at least parsable with cssutils.
95+
96+
`DOM Level 2 Style CSS <http://www.w3.org/TR/DOM-Level-2-Style/css.html>`__
97+
DOM for package css. 0.9.8 removes support for CSSValue and related API, see PropertyValue and Value API for now
98+
`DOM Level 2 Style Stylesheets <http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html>`__
99+
DOM for package stylesheets
100+
`CSSOM <http://dev.w3.org/csswg/cssom/>`__
101+
A few details (mainly the NamespaceRule DOM) are taken from here. Plan is to move implementation to the stuff defined here which is newer but still no REC so might change anytime...
102+
103+
The cssutils tokenizer is a customized implementation of `CSS3 Module: Syntax (W3C Working Draft 13 August 2003) <http://www.w3.org/TR/css3-syntax/>`_ which itself is based on the CSS 2.1 tokenizer. It tries to be as compliant as possible but uses some (helpful) parts of the CSS 2.1 tokenizer.
104+
105+
I guess cssutils is neither CSS 2.1 nor CSS 3 compliant but tries to at least be able to parse both grammars including some more real world cases (some CSS hacks are actually parsed and serialized). Both official grammars are not final nor bugfree but still feasible. cssutils aim is not to be fully compliant to any CSS specification (the specifications seem to be in a constant flow anyway) but cssutils *should* be able to read and write as many as possible CSS stylesheets "in the wild" while at the same time implement the official APIs which are well documented. Some minor extensions are provided as well.
106+
107+
108+
Compatibility
109+
=============
110+
111+
cssutils is developed on modern Python versions. Check the package metadata
112+
for compatibilty.
113+
114+
Beware, cssutils is known to be thread unsafe.
115+
116+
117+
Example
118+
=======
119+
::
120+
121+
import cssutils
122+
123+
css = '''/* a comment with umlaut &auml; */
124+
@namespace html "http://www.w3.org/1999/xhtml";
125+
@variables { BG: #fff }
126+
html|a { color:red; background: var(BG) }'''
127+
sheet = cssutils.parseString(css)
128+
129+
for rule in sheet:
130+
if rule.type == rule.STYLE_RULE:
131+
# find property
132+
for property in rule.style:
133+
if property.name == 'color':
134+
property.value = 'green'
135+
property.priority = 'IMPORTANT'
136+
break
137+
# or simply:
138+
rule.style['margin'] = '01.0eM' # or: ('1em', 'important')
139+
140+
sheet.encoding = 'ascii'
141+
sheet.namespaces['xhtml'] = 'http://www.w3.org/1999/xhtml'
142+
sheet.namespaces['atom'] = 'http://www.w3.org/2005/Atom'
143+
sheet.add('atom|title {color: #000000 !important}')
144+
sheet.add('@import "sheets/import.css";')
145+
146+
# cssutils.ser.prefs.resolveVariables == True since 0.9.7b2
147+
print sheet.cssText
148+
149+
results in::
150+
151+
@charset "ascii";
152+
@import "sheets/import.css";
153+
/* a comment with umlaut \E4 */
154+
@namespace xhtml "http://www.w3.org/1999/xhtml";
155+
@namespace atom "http://www.w3.org/2005/Atom";
156+
xhtml|a {
157+
color: green !important;
158+
background: #fff;
159+
margin: 1em
160+
}
161+
atom|title {
162+
color: #000 !important
163+
}
164+
165+
166+
Kind Request
167+
============
168+
169+
cssutils is far from being perfect or even complete. If you find any bugs (especially specification violations) or have problems or suggestions please put them in the `Issue Tracker <https://github.com/jaraco/cssutils/issues>`_.
170+
171+
172+
Thanks
173+
======
174+
175+
Special thanks to Christof Höke for seminal creation of the library.
176+
177+
Thanks to Simon Sapin, Jason R. Coombs, and Walter Doerwald for patches, help and discussion. Thanks to Kevin D. Smith for the value validating module. Thanks also to Cory Dodt, Tim Gerla, James Dobson and Amit Moscovich for helpful suggestions and code patches. Thanks to Fredrik Hedman for help on port of encutils to Python 3.
178+
179+
180+
For Enterprise
181+
==============
182+
183+
Available as part of the Tidelift Subscription.
184+
185+
This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.
186+
187+
`Learn more <https://tidelift.com/subscription/pkg/pypi-cssutils?utm_source=pypi-cssutils&utm_medium=referral&utm_campaign=github>`_.

0 commit comments

Comments
 (0)