| 1 |
# coding: utf8 |
| 2 |
""" |
| 3 |
tinycss |
| 4 |
------- |
| 5 |
|
| 6 |
A CSS parser, and nothing else. |
| 7 |
|
| 8 |
:copyright: (c) 2012 by Simon Sapin. |
| 9 |
:license: BSD, see LICENSE for more details. |
| 10 |
""" |
| 11 |
|
| 12 |
from .version import VERSION |
| 13 |
|
| 14 |
__version__ = VERSION |
| 15 |
|
| 16 |
from tinycss.css21 import CSS21Parser |
| 17 |
from tinycss.fonts3 import CSSFonts3Parser |
| 18 |
from tinycss.media3 import CSSMedia3Parser |
| 19 |
from tinycss.page3 import CSSPage3Parser |
| 20 |
|
| 21 |
PARSER_MODULES = { |
| 22 |
'page3': CSSPage3Parser, |
| 23 |
'fonts3': CSSFonts3Parser, |
| 24 |
'media3': CSSMedia3Parser, |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
def make_parser(*features, **kwargs): |
| 29 |
"""Make a parser object with the chosen features. |
| 30 |
|
| 31 |
:param features: |
| 32 |
Positional arguments are base classes the new parser class will extend. |
| 33 |
The string ``'page3'`` is accepted as short for |
| 34 |
:class:`~page3.CSSPage3Parser`. |
| 35 |
:param kwargs: |
| 36 |
Keyword arguments are passed to the parser’s constructor. |
| 37 |
:returns: |
| 38 |
An instance of a new subclass of :class:`CSS21Parser` |
| 39 |
|
| 40 |
""" |
| 41 |
if features: |
| 42 |
bases = tuple(PARSER_MODULES.get(f, f) for f in features) |
| 43 |
parser_class = type('CustomCSSParser', bases + (CSS21Parser,), {}) |
| 44 |
else: |
| 45 |
parser_class = CSS21Parser |
| 46 |
return parser_class(**kwargs) |
| 47 |
|
| 48 |
|
| 49 |
def make_full_parser(**kwargs): |
| 50 |
''' A parser that parses all supported CSS 3 modules in addition to CSS 2.1 ''' |
| 51 |
features = tuple(PARSER_MODULES) |
| 52 |
return make_parser(*features, **kwargs) |