Permalink
Browse files

Remove selector3 support. Functionality has moved to cssselect.

  • Loading branch information...
1 parent 163c89d commit 08969816f5b83b5a5b865c1fed782ce32ae76339 @SimonSapin SimonSapin committed Apr 25, 2012
Showing with 56 additions and 429 deletions.
  1. +13 −2 CHANGES
  2. +3 −4 README.rst
  3. +11 −12 docs/css3.rst
  4. +2 −2 docs/extending.rst
  5. +8 −16 docs/hacking.rst
  6. +0 −4 docs/index.rst
  7. +1 −1 docs/parsing.rst
  8. +1 −7 tinycss/__init__.py
  9. +3 −0 tinycss/css21.py
  10. +11 −9 tinycss/page3.py
  11. +0 −240 tinycss/selectors3.py
  12. +0 −4 tinycss/tests/test_api.py
  13. +0 −121 tinycss/tests/test_selectors3.py
  14. +1 −1 tinycss/version.py
  15. +2 −6 tox.ini
View
@@ -2,10 +2,21 @@ tinycss changelog
=================
+Version 0.2
+-----------
+
+Not released yet.
+
+**Breaking changes:**
+
+* Remove the ``selectors3`` module. The functionality has moved to the
+ `cssselect <http://packages.python.org/cssselect/>`_ project.
+
+
Version 0.1.1
-------------
-Released on April 6th 2012.
+Released on 2012-04-06.
Bug fixes:
@@ -16,7 +27,7 @@ Bug fixes:
Version 0.1
-----------
-Released on April 5th 2012.
+Released on 2012-04-05.
First release. Parser support for CSS 2.1, Seloctors 3, Color 3 and
Paged Media 3.
View
@@ -4,13 +4,12 @@ tinycss: CSS parser for Python
*tinycss* is a complete yet simple CSS parser for Python. It supports the full
syntax and error handling for CSS 2.1 as well as some CSS 3 modules:
-* Selectors 3 (can also find matching elements in a `lxml <http://lxml.de/>`_
- document)
* CSS Color 3
* CSS Paged Media 3
-It is designed to be easy to extend for new CSS modules and syntax.
-
+It is designed to be easy to extend for new CSS modules and syntax,
+and integrates well with `cssselect <http://packages.python.org/cssselect/>`_
+for Selectors 3 support.
Quick facts:
View
@@ -1,44 +1,43 @@
CSS 3 Modules
=============
-.. module:: tinycss.selectors3
+.. _selectors3:
Selectors 3
-----------
-This module is based on `lxml.cssselect <http://lxml.de/cssselect.html>`_.
-Importing :mod:`tinycss.selectors3` without lxml installed will raise an
-:exc:`~exceptions.ImportError`.
+See cssselect_ can be used to parse selectors.
-.. autoclass:: CSSSelectors3Parser
-.. autoclass:: Selector
- :members: match
+**TODO:** give an example of how to use it with tinycss.
+
+.. _cssselect: http://packages.python.org/cssselect/
.. module:: tinycss.color3
Color 3
-------
-This module implements parsing for the *<color>* values defined in
+This module implements parsing for the *<color>* values, as defined in
`CSS 3 Color <http://www.w3.org/TR/css3-color/>`_.
The (deprecated) CSS2 system colors are not supported, but you can
-easily test for them if you want as they are simple ``IDENT`` tokens::
+easily test for them if you want as they are simple ``IDENT`` tokens.
+For example::
if token.type == 'IDENT' and token.value == 'ButtonText':
return ...
-Other values types are supported:
+All other values types *are* supported:
* Basic, extended (X11) and transparent color keywords;
* 3-digit and 6-digit hexadecimal notations;
* ``rgb()``, ``rgba()``, ``hsl()`` and ``hsla()`` functional notations.
* ``currentColor``
This module does not integrate with a parser class. Instead, it provides
-a function that can help parse property values, as
-:attr:`.css21.Declaration.value` is provided as a list of unparsed tokens.
+a function that can parse tokens as found in :attr:`.css21.Declaration.value`,
+for example.
.. autofunction:: parse_color
.. autofunction:: parse_color_string
View
@@ -3,8 +3,8 @@
Extending the parser
====================
-Various modules such as :mod:`.selectors3` and :mod:`.page3` extend the
-CSS 2.1 parser to add support for some CSS 3 syntax.
+Modules such as :mod:`.page3` extend the CSS 2.1 parser to add support for
+CSS 3 syntax.
They do so by sub-classing :class:`.css21.CSS21Parser` and overriding/extending
some of its methods. If fact, the parser is made of methods in a class
(rather than a set of functions) solely to enable this kind of sub-classing.
View
@@ -24,22 +24,16 @@ First, get the latest git version::
git clone https://github.com/SimonSapin/tinycss.git
cd tinycss
-Cython_ is required. lxml_ is used by the :mod:`~tinycss.selectors3`, but
-is otherwise optional. pytest_ is used to run the test suite. Installing in
-a virtualenv_ is recommended::
+You will need Cython_ and pytest_. Installing in a virtualenv_ is recommended::
virtualenv env
. env/bin/activate
- pip install Cython lxml pytest
+ pip install Cython pytest
.. _Cython: http://cython.org/
-.. _lxml: http://lxml.de/
.. _pytest: http://pytest.org/
.. _virtualenv: http://www.virtualenv.org/
-You can omit lxml in the command above if you don’t intend to work on
-selectors.
-
Then, install tinycss in-place with pip’s *editable mode*. This will also
build the accelerators::
@@ -54,13 +48,10 @@ Once you have everything installed (see above), just run pytest from the
py.test
-If you chose not to install lxml, use the ``TINYCSS_SKIP_LXML_TESTS``
-environment variable::
-
- TINYCSS_SKIP_LXML_TESTS=1 py.test
+If the accelerators are not available for some reason, use the
+``TINYCSS_SKIP_SPEEDUPS_TESTS`` environment variable::
-Similarly, there is a ``TINYCSS_SKIP_SPEEDUPS_TESTS`` environment variable
-if the accelerators are not available for some reason.
+ TINYCSS_SKIP_SPEEDUPS_TESTS=1 py.test
If you get test failures on a fresh git clone, something may have gone wrong
during the installation. Otherwise, you probably found a bug. Please
@@ -81,8 +72,9 @@ Change to the project’s root directory and just run::
.. _tox: http://tox.testrun.org/
-tinycss pre-configures tox to test in CPython 2.6, 2.7, 3.1 and 3.2 as well as
-PyPy, but you can change that with the ``-e`` parameter. Eg::
+tinycss comes with a pre-configured ``tox.ini`` file to test in CPython
+2.6, 2.7, 3.1 and 3.2 as well as PyPy. You can change that with the ``-e``
+parameter::
tox -e py27,py32
View
@@ -8,14 +8,10 @@ tinycss is tested on CPython 2.6, 2.7, 3.1 and 3.2 as well as PyPy 1.8;
it should work on any implementation of **Python 2.6 or later version
(including 3.x)** of the language.
-lxml_ is required for the :mod:`~tinycss.selectors3` module, but not for
-the base parser or other modules.
-
Cython_ is used for optional accelerators but is only required for
development versions on tinycss.
.. _Cython: http://cython.org/
-.. _lxml: http://lxml.de/
Installation
View
@@ -19,7 +19,7 @@ Import *tinycss*, make a parser object, and parse a stylesheet:
<ImportRule 1:1 foo.css>
<RuleSet at 2:5 p.error>
-You’ll get a :class:`~tinycss.core.Stylesheet` object which contains
+You’ll get a :class:`~tinycss.css21.Stylesheet` object which contains
all the parsed content.
View
@@ -21,13 +21,8 @@ def make_parser(*base_classes, **kwargs):
:param base_classes:
Positional arguments are base classes the new parser
class will extend.
- :param with_selectors3:
- Add :class:`CSSSelectors3Parser` to :obj:`base_classes`: enable
- parsing and matching of level 3 selectors.
- This requires lxml.cssselect, and will raise
- :class:`ImportError` if it is not installed.
:param with_page3:
- Add :class:`CSSPage3Parser` to :obj:`base_classes`: enable
+ Add :class:`~page3.CSSPage3Parser` to :obj:`base_classes`: enable
CSS 3 Paged Media syntax.
:param kwargs:
Other arguments are passed to the parser’s constructor.
@@ -56,6 +51,5 @@ class will extend.
PARSER_MODULES = [
- ('selectors3', 'CSSSelectors3Parser'),
('page3', 'CSSPage3Parser'),
]
View
@@ -123,6 +123,9 @@ class RuleSet(object):
The selector as a :class:`~.token_data.TokenList`.
In CSS 3, this is actually called a selector group.
+ ``selector.as_css()`` can be used with `cssselect
+ <http://packages.python.org/cssselect/>`_, see :ref:`selectors3`.
+
.. attribute:: declarations
The list of :class:`Declaration`, in source order.
View
@@ -42,7 +42,7 @@ class MarginRule(object):
.. attribute:: declarations
- A list of :class:`~.css21.Declaration`
+ A list of :class:`~.css21.Declaration` objects.
.. attribute:: line
@@ -75,14 +75,16 @@ class CSSPage3Parser(CSS21Parser):
* ``selector``, instead of a single string, is a tuple of the page name
and the pseudo class. Each of these may be a ``None`` or a string.
- ======================== ======================
- CSS Parsed selector
- ======================== ======================
- ``@page {}`` ``(None, None)``
- ``@page :first {}`` ``(None, 'first')``
- ``@page chapter {}`` ``('chapter', None)``
- ``@page table:right {}`` ``('table', 'right')``
- ======================== ======================
+ +--------------------------+------------------------+
+ | CSS | Parsed selectors |
+ +==========================+========================+
+ | .. code-block:: css | .. code-block:: python |
+ | | |
+ | @page {} | (None, None) |
+ | @page :first {} | (None, 'first') |
+ | @page chapter {} | ('chapter', None) |
+ | @page table:right {} | ('table', 'right') |
+ +--------------------------+------------------------+
"""
Oops, something went wrong.

0 comments on commit 0896981

Please sign in to comment.