Skip to main content

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 type and source_line
  • attributes that can be trivially computed from other core attributes, like lower_at_keyword (which you can compute from at_keyword
  • the undocumented representation of string and URL tokens (which can't always be computed from value)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinycss2_core_attributes-1.4.0.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinycss2_core_attributes-1.4.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file tinycss2_core_attributes-1.4.0.0.tar.gz.

File metadata

  • Download URL: tinycss2_core_attributes-1.4.0.0.tar.gz
  • Upload date:
  • Size: 8.1 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

Hashes for tinycss2_core_attributes-1.4.0.0.tar.gz
Algorithm Hash digest
SHA256 ea157ab863be6112874fffe79d943b8c20bff5eb60d0f98345c5ceeff7b1da3b
MD5 b0b4bd305cdeed1e21f8b80c047199bc
BLAKE2b-256 562478201826a0433bfb60f7a9c3301f19a3cf5f7faebed01b3525d8c7cb32db

See more details on using hashes here.

File details

Details for the file tinycss2_core_attributes-1.4.0.0-py3-none-any.whl.

File metadata

  • Download URL: tinycss2_core_attributes-1.4.0.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

Hashes for tinycss2_core_attributes-1.4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f42281dcd10b578aea41da3cf7c423dd9ac09d4f6fc99ca3c60e71aed1f0c3ab
MD5 3d3b072f777b3dd3959506a789dee382
BLAKE2b-256 4ffe03961f8155ab4b45b72c5bec61b211b47751fbab584184087da4df09b6e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page