Provides the set of core attributes for each tinycss AST Node
Project description
tinycss2_core_attributes
This is a companion to the tinycss2 project that provides
a list of "core attribute" names for every tinycss Node class.
This allows you to traverse the parse tree or print out information
(for example, for debugging), all without special-casing every node type.
For example:
>>> import tinycss2
>>> from tinycss2_core_attributes import get_core_attrs
>>> decl = tinycss2.parse_one_declaration('width: 100%;')
>>> decl
<Declaration width: …>
>>> get_core_attrs(decl)
['name', 'value', 'important']
>>> for attr_name in get_core_attrs(decl):
... print(f'{attr_name}: {getattr(decl, attr_name)}')
...
name: width
value: [<WhitespaceToken>, <PercentageToken 100%>, <LiteralToken ;>]
important: False
The "core attributes" are ones that contain information about the individual node. This excludes:
- attributes common to all nodes, like
typeandsource_line - attributes that can be trivially computed from other core attributes,
like
lower_at_keyword(which you can compute fromat_keyword - the undocumented
representationof string and URL tokens (which can't always be computed fromvalue)
The purpose of this project is to show that this concept of "core attributes"
is useful. Perhaps it could be added to tinycss2 itself.
API
The project provides a single function:
get_core_attrs
get_core_attrs(node)
Takes a tinycss2.ast.Node instance or subclass, and returns a list of
names of its "core attributes".
CLI interface
There's a demo!
Run python -m tinycss2_core_attributes FILE.css to parse FILE.css and
display a colorized dump of the AST.
Use --help to see all options.
Versioning
This project is tightly tied to tinycss2, and uses the tinycss2 version
it is compatible with plus a change counter at the end.
Thus, tinycss2_core_attributes 1.5.1.0 requires tinycss2 1.5.1.
Licence
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this work to the public domain worldwide. This work is distributed without any warranty.
See the CC0 Public Domain Dedication: http://creativecommons.org/publicdomain/zero/1.0/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tinycss2_core_attributes-1.5.1.0.tar.gz.
File metadata
- Download URL: tinycss2_core_attributes-1.5.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa16d847c6934262d2ac6c06f38a66b13d7bfcb669a68274f1dbf11f5acbac69
|
|
| MD5 |
a0109f0d1ab79266dd442c341b2045ab
|
|
| BLAKE2b-256 |
ad66bd7c8893788a2e47ce8b192d0b52122c77f6b0cec759937d5c546e24ff51
|
File details
Details for the file tinycss2_core_attributes-1.5.1.0-py3-none-any.whl.
File metadata
- Download URL: tinycss2_core_attributes-1.5.1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f8c74f1317df548955529994a3bd5ca3b909cfa8fcdcaf268064b6205a17e22
|
|
| MD5 |
a4202d4bcf225ae06174ca06a410ba72
|
|
| BLAKE2b-256 |
0ebee632589719656d73a8b52801683f3f1a852b0fd4f109d70bb0e59e300a17
|