tinycss-0.4/0000755000175000017500000000000012771254226013011 5ustar lizelize00000000000000tinycss-0.4/docs/0000755000175000017500000000000012771254226013741 5ustar lizelize00000000000000tinycss-0.4/docs/_static/0000755000175000017500000000000012771254226015367 5ustar lizelize00000000000000tinycss-0.4/docs/_static/custom.css0000644000175000017500000000064512766005714017420 0ustar lizelize00000000000000div.body { text-align: left; } div.document p, div.document ul { margin-top: 0; margin-bottom: 1em; } div.document ul ul { margin-top: 0; margin-bottom: .5em; } .field-name { padding-right: .5em; } table.field-list p, table.field-list ul { margin-bottom: .5em; } table { border-collapse: collapse; margin-bottom: 1em; } table.docutils td, table.docutils th { padding: .2em .5em; } tinycss-0.4/docs/_templates/0000755000175000017500000000000012771254226016076 5ustar lizelize00000000000000tinycss-0.4/docs/_templates/layout.html0000644000175000017500000000021612766005714020300 0ustar lizelize00000000000000{% extends "!layout.html" %} {% block extrahead %} {% endblock %} tinycss-0.4/docs/changelog.rst0000644000175000017500000000003012766005714016413 0ustar lizelize00000000000000.. include:: ../CHANGES tinycss-0.4/docs/conf.py0000644000175000017500000002000112771251261015225 0ustar lizelize00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # tinycss documentation build configuration file, created by # sphinx-quickstart on Tue Mar 27 14:20:34 2012. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys, os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.viewcode', 'sphinx.ext.doctest'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = 'tinycss' copyright = '2012, Simon Sapin' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The full version, including alpha/beta/rc tags. #release = '0.1dev' import re with open(os.path.join(os.path.dirname(__file__), '..', 'tinycss', 'version.py')) as init_py: release = re.search("VERSION = '([^']+)'", init_py.read()).group(1) # The short X.Y version. version = release.rstrip('dev') # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. #html_theme = 'agogo' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'tinycssdoc' # -- Options for LaTeX output -------------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'tinycss.tex', 'tinycss Documentation', 'Simon Sapin', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'tinycss', 'tinycss Documentation', ['Simon Sapin'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'tinycss', 'tinycss Documentation', 'Simon Sapin', 'tinycss', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'http://docs.python.org/': None} tinycss-0.4/docs/css3.rst0000644000175000017500000000620712771244625015355 0ustar lizelize00000000000000CSS 3 Modules ============= .. _selectors3: Selectors 3 ----------- .. currentmodule:: tinycss.css21 On :attr:`RuleSet.selector`, the :meth:`~.token_data.TokenList.as_css` method can be used to serialize a selector back to an Unicode string. >>> import tinycss >>> stylesheet = tinycss.make_parser().parse_stylesheet( ... 'div.error, #root > section:first-letter { color: red }') >>> selector_string = stylesheet.rules[0].selector.as_css() >>> selector_string 'div.error, #root > section:first-letter' This string can be parsed by cssselect_. The parsed objects have information about pseudo-elements and selector specificity. .. _cssselect: http://packages.python.org/cssselect/ >>> import cssselect >>> selectors = cssselect.parse(selector_string) >>> [s.specificity() for s in selectors] [(0, 1, 1), (1, 0, 2)] >>> [s.pseudo_element for s in selectors] [None, 'first-letter'] These objects can in turn be translated to XPath expressions. Note that the translation ignores pseudo-elements, you have to account for them somehow or reject selectors with pseudo-elements. >>> xpath = cssselect.HTMLTranslator().selector_to_xpath(selectors[1]) >>> xpath "descendant-or-self::*[@id = 'root']/section" Finally, the XPath expressions can be used with lxml_ to find the matching elements. >>> from lxml import etree >>> compiled_selector = etree.XPath(xpath) >>> document = etree.fromstring('''
... ...
... Lorem
ipsum
...
...
''') >>> [el.get('id') for el in compiled_selector(document)] ['head', 'content'] .. _lxml: http://lxml.de/xpathxslt.html#xpath Find more details in the `cssselect documentation`_. .. _cssselect documentation: http://packages.python.org/cssselect/ .. module:: tinycss.color3 Color 3 ------- This module implements parsing for the ** values, as defined in `CSS 3 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. For example:: if token.type == 'IDENT' and token.value == 'ButtonText': return ... 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 parse tokens as found in :attr:`.css21.Declaration.value`, for example. .. autofunction:: parse_color .. autofunction:: parse_color_string .. autoclass:: RGBA .. module:: tinycss.page3 Paged Media 3 ------------- .. autoclass:: CSSPage3Parser .. autoclass:: MarginRule .. module:: tinycss.fonts3 Fonts 3 ------- .. autoclass:: CSSFonts3Parser .. autoclass:: FontFaceRule .. autoclass:: FontFeatureValuesRule .. autoclass:: FontFeatureRule Other CSS modules ----------------- To add support for new CSS syntax, see :ref:`extending`. tinycss-0.4/docs/extending.rst0000644000175000017500000000660512766005714016467 0ustar lizelize00000000000000.. _extending: Extending the parser ==================== 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. tinycss is designed to enable you to have parser subclasses outside of tinycss, without monkey-patching. If however the syntax you added is for a W3C specification, consider including your subclass in a new tinycss module and send a pull request: see :ref:`hacking`. .. currentmodule:: tinycss.css21 Example: star hack ------------------ .. _star hack: https://en.wikipedia.org/wiki/CSS_filter#Star_hack The `star hack`_ uses invalid declarations that are only parsed by some versions of Internet Explorer. By default, tinycss ignores invalid declarations and logs an error. >>> from tinycss.css21 import CSS21Parser >>> css = '#elem { width: [W3C Model Width]; *width: [BorderBox Model]; }' >>> stylesheet = CSS21Parser().parse_stylesheet(css) >>> stylesheet.errors [ParseError('Parse error at 1:35, expected a property name, got DELIM',)] >>> [decl.name for decl in stylesheet.rules[0].declarations] ['width'] If for example a minifier based on tinycss wants to support the star hack, it can by extending the parser:: >>> class CSSStarHackParser(CSS21Parser): ... def parse_declaration(self, tokens): ... has_star_hack = (tokens[0].type == 'DELIM' and tokens[0].value == '*') ... if has_star_hack: ... tokens = tokens[1:] ... declaration = super(CSSStarHackParser, self).parse_declaration(tokens) ... declaration.has_star_hack = has_star_hack ... return declaration ... >>> stylesheet = CSSStarHackParser().parse_stylesheet(css) >>> stylesheet.errors [] >>> [(d.name, d.has_star_hack) for d in stylesheet.rules[0].declarations] [('width', False), ('width', True)] This class extends the :meth:`~CSS21Parser.parse_declaration` method. It removes any ``*`` delimeter :class:`~.token_data.Token` at the start of a declaration, and adds a ``has_star_hack`` boolean attribute on parsed :class:`Declaration` objects: ``True`` if a ``*`` was removed, ``False`` for “normal” declarations. Parser methods -------------- In addition to methods of the user API (see :ref:`parsing`), here are the methods of the CSS 2.1 parser that can be overriden or extended: .. automethod:: CSS21Parser.parse_rules .. automethod:: CSS21Parser.read_at_rule .. automethod:: CSS21Parser.parse_at_rule .. automethod:: CSS21Parser.parse_media .. automethod:: CSS21Parser.parse_page_selector .. automethod:: CSS21Parser.parse_declarations_and_at_rules .. automethod:: CSS21Parser.parse_ruleset .. automethod:: CSS21Parser.parse_declaration_list .. automethod:: CSS21Parser.parse_declaration .. automethod:: CSS21Parser.parse_value_priority Unparsed at-rules ----------------- .. autoclass:: AtRule .. module:: tinycss.parsing Parsing helper functions ------------------------ The :mod:`tinycss.parsing` module contains helper functions for parsing tokens into a more structured form: .. autofunction:: strip_whitespace .. autofunction:: split_on_comma .. autofunction:: validate_value .. autofunction:: validate_block .. autofunction:: validate_any tinycss-0.4/docs/hacking.rst0000644000175000017500000000557012766005714016106 0ustar lizelize00000000000000.. _hacking: Hacking tinycss =============== .. highlight:: sh Bugs and feature requests ------------------------- Bug reports, feature requests and other issues should got to the `tinycss issue tracker`_ on Github. Any suggestion or feedback is welcome. Please include in full any error message, trackback or other detail that could be helpful. .. _tinycss issue tracker: https://github.com/SimonSapin/tinycss/issues Installing the development version ---------------------------------- First, get the latest git version:: git clone https://github.com/SimonSapin/tinycss.git cd tinycss You will need Cython_ and pytest_. Installing in a virtualenv_ is recommended:: virtualenv env . env/bin/activate pip install Cython pytest .. _Cython: http://cython.org/ .. _pytest: http://pytest.org/ .. _virtualenv: http://www.virtualenv.org/ Then, install tinycss in-place with pip’s *editable mode*. This will also build the accelerators:: pip install -e . Running the test suite ---------------------- Once you have everything installed (see above), just run pytest from the *tinycss* directory:: py.test If the accelerators are not available for some reason, use the ``TINYCSS_SKIP_SPEEDUPS_TESTS`` environment variable:: 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 `report it <#bugs-and-feature-requests>`_. Test in multiple Python versions with tox ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tox_ automatically creates virtualenvs for various Python versions and runs the test suite there:: pip install tox Change to the project’s root directory and just run:: tox .. _tox: http://tox.testrun.org/ 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 If you use ``--`` in the arguments passed to tox, further arguments are passed to the underlying ``py.test`` command:: tox -- -x --pdb Building the documentation -------------------------- This documentation is made with Sphinx_:: pip install Sphinx .. _Sphinx: http://sphinx.pocoo.org/ To build the HTML version of the documentation, change to the project’s root directory and run:: python setup.py build_sphinx The built HTML files are in ``docs/_build/html``. Making a patch and a pull request --------------------------------- If you would like to see something included in tinycss, please fork `the repository `_ on Github and make a pull request. Make sure to include tests for your change. Mailing-list ------------ tinycss does not have a mailing-list of its own for now, but the `WeasyPrint mailing-list `_ is appropriate to discuss it. tinycss-0.4/docs/index.rst0000644000175000017500000000203112771251512015571 0ustar lizelize00000000000000.. include:: ../README.rst Requirements ------------ `tinycss is tested `_ on CPython 2.7, 3.3, 3.4 and 3.5 as well as PyPy 5.3 and PyPy3 2.4; it should work on any implementation of **Python 2.7 or later version (including 3.x)** of the language. Cython_ is used for optional accelerators but is only required for development versions on tinycss. .. _Cython: http://cython.org/ Installation ------------ Installing with `pip `_ should Just Work: .. code-block:: sh pip install tinycss The release tarballs contain pre-*cythoned* C files for the accelerators: you will not need Cython to install like this. If the accelerators fail to build for some reason, tinycss will print a warning and fall back to a pure-Python installation. Documentation ------------- .. Have this page in the sidebar, but do not show a link to itself here: .. toctree:: :hidden: self .. toctree:: :maxdepth: 2 parsing css3 extending hacking changelog tinycss-0.4/docs/parsing.rst0000644000175000017500000000470312766005714016142 0ustar lizelize00000000000000Parsing with tinycss ==================== .. highlight:: python Quickstart ---------- Import *tinycss*, make a parser object with the features you want, and parse a stylesheet: .. doctest:: >>> import tinycss >>> parser = tinycss.make_parser('page3') >>> stylesheet = parser.parse_stylesheet_bytes(b'''@import "foo.css"; ... p.error { color: red } @lorem-ipsum; ... @page tables { size: landscape }''') >>> stylesheet.rules [, , ] >>> stylesheet.errors [ParseError('Parse error at 2:29, unknown at-rule in stylesheet context: @lorem-ipsum',)] You’ll get a :class:`~tinycss.css21.Stylesheet` object which contains all the parsed content as well as a list of encountered errors. Parsers ------- Parsers are subclasses of :class:`tinycss.css21.CSS21Parser`. Various subclasses add support for more syntax. You can choose which features to enable by making a new parser class with multiple inheritance, but there is also a convenience function to do that: .. module:: tinycss .. autofunction:: make_parser .. module:: tinycss.css21 .. _parsing: Parsing a stylesheet ~~~~~~~~~~~~~~~~~~~~ Parser classes have three different methods to parse CSS stylesheet, depending on whether you have a file, a byte string, or an Unicode string. .. autoclass:: CSS21Parser :members: parse_stylesheet_file, parse_stylesheet_bytes, parse_stylesheet Parsing a ``style`` attribute ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. automethod:: CSS21Parser.parse_style_attr Parsed objects -------------- These data structures make up the results of the various parsing methods. .. autoclass:: tinycss.parsing.ParseError() .. autoclass:: Stylesheet() .. note:: All subsequent objects have :obj:`line` and :obj:`column` attributes (not repeated every time fore brevity) that indicate where in the CSS source this object was read. .. autoclass:: RuleSet() .. autoclass:: ImportRule() .. autoclass:: MediaRule() .. autoclass:: PageRule() .. autoclass:: Declaration() Tokens ------ Some parts of a stylesheet (such as selectors in CSS 2.1 or property values) are not parsed by tinycss. They appear as tokens instead. .. module:: tinycss.token_data .. autoclass:: TokenList() :member-order: bysource :members: .. autoclass:: Token() :members: .. autoclass:: tinycss.speedups.CToken() .. autoclass:: ContainerToken() :members: .. autoclass:: FunctionToken() tinycss-0.4/tinycss/0000755000175000017500000000000012771254226014505 5ustar lizelize00000000000000tinycss-0.4/tinycss/tests/0000755000175000017500000000000012771254226015647 5ustar lizelize00000000000000tinycss-0.4/tinycss/tests/__init__.py0000644000175000017500000000117312766272664017774 0ustar lizelize00000000000000# coding: utf-8 """ Test suite for tinycss ---------------------- :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals import sys # Awful workaround to fix isort's "sys.setdefaultencoding('utf-8')". if sys.version_info[0] == 2: reload(sys) # noqa sys.setdefaultencoding('ascii') def assert_errors(errors, expected_errors): """Test not complete error messages but only substrings.""" assert len(errors) == len(expected_errors) for error, expected in zip(errors, expected_errors): assert expected in str(error) tinycss-0.4/tinycss/tests/speed.py0000644000175000017500000000670612766235720017334 0ustar lizelize00000000000000# coding: utf-8 """ Speed tests ----------- Note: this file is not named test_*.py as it is not part of the test suite ran by pytest. :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import division, unicode_literals import contextlib import functools import os.path import sys import timeit from cssutils import parseString from .. import tokenizer from ..css21 import CSS21Parser from ..parsing import remove_whitespace CSS_REPEAT = 4 TIMEIT_REPEAT = 3 TIMEIT_NUMBER = 20 def load_css(): filename = os.path.join(os.path.dirname(__file__), '..', '..', 'docs', '_static', 'custom.css') with open(filename, 'rb') as fd: return b'\n'.join([fd.read()] * CSS_REPEAT) # Pre-load so that I/O is not measured CSS = load_css() @contextlib.contextmanager def install_tokenizer(name): original = tokenizer.tokenize_flat try: tokenizer.tokenize_flat = getattr(tokenizer, name) yield finally: tokenizer.tokenize_flat = original def parse(tokenizer_name): with install_tokenizer(tokenizer_name): stylesheet = CSS21Parser().parse_stylesheet_bytes(CSS) result = [] for rule in stylesheet.rules: selector = rule.selector.as_css() declarations = [ (declaration.name, len(list(remove_whitespace(declaration.value)))) for declaration in rule.declarations] result.append((selector, declarations)) return result parse_cython = functools.partial(parse, 'cython_tokenize_flat') parse_python = functools.partial(parse, 'python_tokenize_flat') def parse_cssutils(): stylesheet = parseString(CSS) result = [] for rule in stylesheet.cssRules: selector = rule.selectorText declarations = [ (declaration.name, len(list(declaration.propertyValue))) for declaration in rule.style.getProperties(all=True)] result.append((selector, declarations)) return result def check_consistency(): result = parse_python() assert len(result) > 0 if tokenizer.cython_tokenize_flat: assert parse_cython() == result assert parse_cssutils() == result version = '.'.join(map(str, sys.version_info[:3])) print('Python {}, consistency OK.'.format(version)) def warm_up(): is_pypy = hasattr(sys, 'pypy_translation_info') if is_pypy: print('Warming up for PyPy...') for i in range(80): for i in range(10): parse_python() parse_cssutils() sys.stdout.write('.') sys.stdout.flush() sys.stdout.write('\n') def time(function): seconds = timeit.Timer(function).repeat(TIMEIT_REPEAT, TIMEIT_NUMBER) miliseconds = int(min(seconds) * 1000) return miliseconds def run(): if tokenizer.cython_tokenize_flat: data_set = [ ('tinycss + speedups ', parse_cython), ] else: print('Speedups are NOT available.') data_set = [] data_set += [ ('tinycss WITHOUT speedups', parse_python), ('cssutils ', parse_cssutils), ] label, function = data_set.pop(0) ref = time(function) print('{} {} ms'.format(label, ref)) for label, function in data_set: result = time(function) print('{} {} ms {:.2f}x'.format(label, result, result / ref)) if __name__ == '__main__': check_consistency() warm_up() run() tinycss-0.4/tinycss/tests/test_api.py0000644000175000017500000000247412766235733020046 0ustar lizelize00000000000000# coding: utf-8 """ Tests for the public API ------------------------ :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals from pytest import raises from tinycss import make_parser from tinycss.page3 import CSSPage3Parser def test_make_parser(): class MyParser(object): def __init__(self, some_config): self.some_config = some_config parsers = [ make_parser(), make_parser('page3'), make_parser(CSSPage3Parser), make_parser(MyParser, some_config=42), make_parser(CSSPage3Parser, MyParser, some_config=42), make_parser(MyParser, 'page3', some_config=42), ] for parser, exp in zip(parsers, [False, True, True, False, True, True]): assert isinstance(parser, CSSPage3Parser) == exp for parser, exp in zip(parsers, [False, False, False, True, True, True]): assert isinstance(parser, MyParser) == exp for parser in parsers[3:]: assert parser.some_config == 42 # Extra or missing named parameters raises(TypeError, make_parser, some_config=4) raises(TypeError, make_parser, 'page3', some_config=4) raises(TypeError, make_parser, MyParser) raises(TypeError, make_parser, MyParser, some_config=4, other_config=7) tinycss-0.4/tinycss/tests/test_color3.py0000644000175000017500000001635312766236133020472 0ustar lizelize00000000000000# coding: utf-8 """ Tests for the CSS 3 color parser -------------------------------- :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals import pytest from tinycss.color3 import hsl_to_rgb, parse_color_string @pytest.mark.parametrize(('css_source', 'expected_result'), [ ('', None), (' /* hey */\n', None), ('4', None), ('top', None), ('/**/transparent', (0, 0, 0, 0)), ('transparent', (0, 0, 0, 0)), (' transparent\n', (0, 0, 0, 0)), ('TransParent', (0, 0, 0, 0)), ('currentColor', 'currentColor'), ('CURRENTcolor', 'currentColor'), ('current_Color', None), ('black', (0, 0, 0, 1)), ('white', (1, 1, 1, 1)), ('fuchsia', (1, 0, 1, 1)), ('cyan', (0, 1, 1, 1)), ('CyAn', (0, 1, 1, 1)), ('darkkhaki', (189 / 255., 183 / 255., 107 / 255., 1)), ('#', None), ('#f', None), ('#ff', None), ('#fff', (1, 1, 1, 1)), ('#ffg', None), ('#ffff', None), ('#fffff', None), ('#ffffff', (1, 1, 1, 1)), ('#fffffg', None), ('#fffffff', None), ('#ffffffff', None), ('#fffffffff', None), ('#cba987', (203 / 255., 169 / 255., 135 / 255., 1)), ('#CbA987', (203 / 255., 169 / 255., 135 / 255., 1)), ('#1122aA', (17 / 255., 34 / 255., 170 / 255., 1)), ('#12a', (17 / 255., 34 / 255., 170 / 255., 1)), ('rgb(203, 169, 135)', (203 / 255., 169 / 255., 135 / 255., 1)), ('RGB(255, 255, 255)', (1, 1, 1, 1)), ('rgB(0, 0, 0)', (0, 0, 0, 1)), ('rgB(0, 51, 255)', (0, .2, 1, 1)), ('rgb(0,51,255)', (0, .2, 1, 1)), ('rgb(0\t, 51 ,255)', (0, .2, 1, 1)), ('rgb(/* R */0, /* G */51, /* B */255)', (0, .2, 1, 1)), ('rgb(-51, 306, 0)', (-.2, 1.2, 0, 1)), # out of 0..1 is allowed ('rgb(42%, 3%, 50%)', (.42, .03, .5, 1)), ('RGB(100%, 100%, 100%)', (1, 1, 1, 1)), ('rgB(0%, 0%, 0%)', (0, 0, 0, 1)), ('rgB(10%, 20%, 30%)', (.1, .2, .3, 1)), ('rgb(10%,20%,30%)', (.1, .2, .3, 1)), ('rgb(10%\t, 20% ,30%)', (.1, .2, .3, 1)), ('rgb(/* R */10%, /* G */20%, /* B */30%)', (.1, .2, .3, 1)), ('rgb(-12%, 110%, 1400%)', (-.12, 1.1, 14, 1)), # out of 0..1 is allowed ('rgb(10%, 50%, 0)', None), ('rgb(255, 50%, 0%)', None), ('rgb(0, 0 0)', None), ('rgb(0, 0, 0deg)', None), ('rgb(0, 0, light)', None), ('rgb()', None), ('rgb(0)', None), ('rgb(0, 0)', None), ('rgb(0, 0, 0, 0)', None), ('rgb(0%)', None), ('rgb(0%, 0%)', None), ('rgb(0%, 0%, 0%, 0%)', None), ('rgb(0%, 0%, 0%, 0)', None), ('rgba(0, 0, 0, 0)', (0, 0, 0, 0)), ('rgba(203, 169, 135, 0.3)', (203 / 255., 169 / 255., 135 / 255., 0.3)), ('RGBA(255, 255, 255, 0)', (1, 1, 1, 0)), ('rgBA(0, 51, 255, 1)', (0, 0.2, 1, 1)), ('rgba(0, 51, 255, 1.1)', (0, 0.2, 1, 1)), ('rgba(0, 51, 255, 37)', (0, 0.2, 1, 1)), ('rgba(0, 51, 255, 0.42)', (0, 0.2, 1, 0.42)), ('rgba(0, 51, 255, 0)', (0, 0.2, 1, 0)), ('rgba(0, 51, 255, -0.1)', (0, 0.2, 1, 0)), ('rgba(0, 51, 255, -139)', (0, 0.2, 1, 0)), ('rgba(42%, 3%, 50%, 0.3)', (.42, .03, .5, 0.3)), ('RGBA(100%, 100%, 100%, 0)', (1, 1, 1, 0)), ('rgBA(0%, 20%, 100%, 1)', (0, 0.2, 1, 1)), ('rgba(0%, 20%, 100%, 1.1)', (0, 0.2, 1, 1)), ('rgba(0%, 20%, 100%, 37)', (0, 0.2, 1, 1)), ('rgba(0%, 20%, 100%, 0.42)', (0, 0.2, 1, 0.42)), ('rgba(0%, 20%, 100%, 0)', (0, 0.2, 1, 0)), ('rgba(0%, 20%, 100%, -0.1)', (0, 0.2, 1, 0)), ('rgba(0%, 20%, 100%, -139)', (0, 0.2, 1, 0)), ('rgba(255, 255, 255, 0%)', None), ('rgba(10%, 50%, 0, 1)', None), ('rgba(255, 50%, 0%, 1)', None), ('rgba(0, 0, 0 0)', None), ('rgba(0, 0, 0, 0deg)', None), ('rgba(0, 0, 0, light)', None), ('rgba()', None), ('rgba(0)', None), ('rgba(0, 0, 0)', None), ('rgba(0, 0, 0, 0, 0)', None), ('rgba(0%)', None), ('rgba(0%, 0%)', None), ('rgba(0%, 0%, 0%)', None), ('rgba(0%, 0%, 0%, 0%)', None), ('rgba(0%, 0%, 0%, 0%, 0%)', None), ('HSL(0, 0%, 0%)', (0, 0, 0, 1)), ('hsL(0, 100%, 50%)', (1, 0, 0, 1)), ('hsl(60, 100%, 37.5%)', (0.75, 0.75, 0, 1)), ('hsl(780, 100%, 37.5%)', (0.75, 0.75, 0, 1)), ('hsl(-300, 100%, 37.5%)', (0.75, 0.75, 0, 1)), ('hsl(300, 50%, 50%)', (0.75, 0.25, 0.75, 1)), ('hsl(10, 50%, 0)', None), ('hsl(50%, 50%, 0%)', None), ('hsl(0, 0% 0%)', None), ('hsl(30deg, 100%, 100%)', None), ('hsl(0, 0%, light)', None), ('hsl()', None), ('hsl(0)', None), ('hsl(0, 0%)', None), ('hsl(0, 0%, 0%, 0%)', None), ('HSLA(-300, 100%, 37.5%, 1)', (0.75, 0.75, 0, 1)), ('hsLA(-300, 100%, 37.5%, 12)', (0.75, 0.75, 0, 1)), ('hsla(-300, 100%, 37.5%, 0.2)', (0.75, 0.75, 0, .2)), ('hsla(-300, 100%, 37.5%, 0)', (0.75, 0.75, 0, 0)), ('hsla(-300, 100%, 37.5%, -3)', (0.75, 0.75, 0, 0)), ('hsla(10, 50%, 0, 1)', None), ('hsla(50%, 50%, 0%, 1)', None), ('hsla(0, 0% 0%, 1)', None), ('hsla(30deg, 100%, 100%, 1)', None), ('hsla(0, 0%, light, 1)', None), ('hsla()', None), ('hsla(0)', None), ('hsla(0, 0%)', None), ('hsla(0, 0%, 0%, 50%)', None), ('hsla(0, 0%, 0%, 1, 0%)', None), ('cmyk(0, 0, 0, 0)', None), ]) def test_color(css_source, expected_result): result = parse_color_string(css_source) if isinstance(result, tuple): for got, expected in zip(result, expected_result): # Compensate for floating point errors: assert abs(got - expected) < 1e-10 for i, attr in enumerate(['red', 'green', 'blue', 'alpha']): assert getattr(result, attr) == result[i] else: assert result == expected_result @pytest.mark.parametrize(('hsl', 'expected_rgb'), [ # http://en.wikipedia.org/wiki/HSL_and_HSV#Examples ((0, 0, 100 ), (1, 1, 1 )), # noqa ((127, 0, 100 ), (1, 1, 1 )), # noqa ((0, 0, 50 ), (0.5, 0.5, 0.5 )), # noqa ((127, 0, 50 ), (0.5, 0.5, 0.5 )), # noqa ((0, 0, 0 ), (0, 0, 0 )), # noqa ((127, 0, 0 ), (0, 0, 0 )), # noqa ((0, 100, 50 ), (1, 0, 0 )), # noqa ((60, 100, 37.5), (0.75, 0.75, 0 )), # noqa ((780, 100, 37.5), (0.75, 0.75, 0 )), # noqa ((-300, 100, 37.5), (0.75, 0.75, 0 )), # noqa ((120, 100, 25 ), (0, 0.5, 0 )), # noqa ((180, 100, 75 ), (0.5, 1, 1 )), # noqa ((240, 100, 75 ), (0.5, 0.5, 1 )), # noqa ((300, 50, 50 ), (0.75, 0.25, 0.75 )), # noqa ((61.8, 63.8, 39.3), (0.628, 0.643, 0.142)), # noqa ((251.1, 83.2, 51.1), (0.255, 0.104, 0.918)), # noqa ((134.9, 70.7, 39.6), (0.116, 0.675, 0.255)), # noqa ((49.5, 89.3, 49.7), (0.941, 0.785, 0.053)), # noqa ((283.7, 77.5, 54.2), (0.704, 0.187, 0.897)), # noqa ((14.3, 81.7, 62.4), (0.931, 0.463, 0.316)), # noqa ((56.9, 99.1, 76.5), (0.998, 0.974, 0.532)), # noqa ((162.4, 77.9, 44.7), (0.099, 0.795, 0.591)), # noqa ((248.3, 60.1, 37.3), (0.211, 0.149, 0.597)), # noqa ((240.5, 29, 60.7), (0.495, 0.493, 0.721)), # noqa ]) def test_hsl(hsl, expected_rgb): for got, expected in zip(hsl_to_rgb(*hsl), expected_rgb): # Compensate for floating point errors and Wikipedia’s rounding: assert abs(got - expected) < 0.001 tinycss-0.4/tinycss/tests/test_css21.py0000644000175000017500000003116712766236206020225 0ustar lizelize00000000000000# coding: utf-8 """ Tests for the CSS 2.1 parser ---------------------------- :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals import io import os import tempfile import pytest from tinycss.css21 import CSS21Parser from . import assert_errors from .test_tokenizer import jsonify def parse_bytes(css_bytes, kwargs): return CSS21Parser().parse_stylesheet_bytes(css_bytes, **kwargs) def parse_bytesio_file(css_bytes, kwargs): css_file = io.BytesIO(css_bytes) return CSS21Parser().parse_stylesheet_file(css_file, **kwargs) def parse_filename(css_bytes, kwargs): css_file = tempfile.NamedTemporaryFile(delete=False) try: css_file.write(css_bytes) # Windows can not open the filename a second time while # it is still open for writing. css_file.close() return CSS21Parser().parse_stylesheet_file(css_file.name, **kwargs) finally: os.remove(css_file.name) @pytest.mark.parametrize(('css_bytes', 'kwargs', 'expected_result', 'parse'), [ params + (parse,) for parse in [parse_bytes, parse_bytesio_file, parse_filename] for params in [ ('@import "é";'.encode('utf8'), {}, 'é'), ('@import "é";'.encode('utf16'), {}, 'é'), # with a BOM ('@import "é";'.encode('latin1'), {}, 'é'), ('@import "£";'.encode('Shift-JIS'), {}, '\x81\x92'), # lat1 mojibake ('@charset "Shift-JIS";@import "£";'.encode('Shift-JIS'), {}, '£'), (' @charset "Shift-JIS";@import "£";'.encode('Shift-JIS'), {}, '\x81\x92'), ('@import "£";'.encode('Shift-JIS'), {'document_encoding': 'Shift-JIS'}, '£'), ('@import "£";'.encode('Shift-JIS'), {'document_encoding': 'utf8'}, '\x81\x92'), ('@charset "utf8"; @import "£";'.encode('utf8'), {'document_encoding': 'latin1'}, '£'), # Mojibake yay! (' @charset "utf8"; @import "é";'.encode('utf8'), {'document_encoding': 'latin1'}, 'é'), ('@import "é";'.encode('utf8'), {'document_encoding': 'latin1'}, 'é'), ] ]) def test_bytes(css_bytes, kwargs, expected_result, parse): stylesheet = parse(css_bytes, kwargs) assert stylesheet.rules[0].at_keyword == '@import' assert stylesheet.rules[0].uri == expected_result @pytest.mark.parametrize(('css_source', 'expected_rules', 'expected_errors'), [ (' /* hey */\n', 0, []), ('foo {}', 1, []), ('foo{} @lipsum{} bar{}', 2, ['unknown at-rule in stylesheet context: @lipsum']), ('@charset "ascii"; foo {}', 1, []), (' @charset "ascii"; foo {}', 1, [ 'mis-placed or malformed @charset rule']), ('@charset ascii; foo {}', 1, ['mis-placed or malformed @charset rule']), ('foo {} @charset "ascii";', 1, ['mis-placed or malformed @charset rule']), ]) def test_at_rules(css_source, expected_rules, expected_errors): # Pass 'encoding' to allow @charset stylesheet = CSS21Parser().parse_stylesheet(css_source, encoding='utf8') assert_errors(stylesheet.errors, expected_errors) result = len(stylesheet.rules) assert result == expected_rules @pytest.mark.parametrize(('css_source', 'expected_rules', 'expected_errors'), [ (' /* hey */\n', [], []), ('foo{} /* hey */\n@bar;@baz{}', [('foo', []), ('@bar', [], None), ('@baz', [], [])], []), ('@import "foo.css"/**/;', [ ('@import', [('STRING', 'foo.css')], None)], []), ('@import "foo.css"/**/', [ ('@import', [('STRING', 'foo.css')], None)], []), ('@import "foo.css', [ ('@import', [('STRING', 'foo.css')], None)], []), ('{}', [], ['empty selector']), ('a{b:4}', [('a', [('b', [('INTEGER', 4)])])], []), ('@page {\t b: 4; @margin}', [('@page', [], [ ('S', '\t '), ('IDENT', 'b'), (':', ':'), ('S', ' '), ('INTEGER', 4), (';', ';'), ('S', ' '), ('ATKEYWORD', '@margin'), ])], []), ('foo', [], ['no declaration block found']), ('foo @page {} bar {}', [('bar', [])], ['unexpected ATKEYWORD token in selector']), ('foo { content: "unclosed string;\n color:red; ; margin/**/\n: 2cm; }', [('foo', [('margin', [('DIMENSION', 2)])])], ['unexpected BAD_STRING token in property value']), ('foo { 4px; bar: 12% }', [('foo', [('bar', [('PERCENTAGE', 12)])])], ['expected a property name, got DIMENSION']), ('foo { bar! 3cm auto ; baz: 7px }', [('foo', [('baz', [('DIMENSION', 7)])])], ["expected ':', got DELIM"]), ('foo { bar ; baz: {("}"/* comment */) {0@fizz}} }', [('foo', [('baz', [('{', [ ('(', [('STRING', '}')]), ('S', ' '), ('{', [('INTEGER', 0), ('ATKEYWORD', '@fizz')]) ])])])], ["expected ':'"]), ('foo { bar: ; baz: not(z) }', [('foo', [('baz', [('FUNCTION', 'not', [('IDENT', 'z')])])])], ['expected a property value']), ('foo { bar: (]) ; baz: U+20 }', [('foo', [('baz', [('UNICODE-RANGE', 'U+20')])])], ['unmatched ] token in (']), ]) def test_core_parser(css_source, expected_rules, expected_errors): class CoreParser(CSS21Parser): """A parser that always accepts unparsed at-rules.""" def parse_at_rule(self, rule, stylesheet_rules, errors, context): return rule stylesheet = CoreParser().parse_stylesheet(css_source) assert_errors(stylesheet.errors, expected_errors) result = [ (rule.at_keyword, list(jsonify(rule.head)), list(jsonify(rule.body)) if rule.body is not None else None) if rule.at_keyword else (rule.selector.as_css(), [ (decl.name, list(jsonify(decl.value))) for decl in rule.declarations]) for rule in stylesheet.rules ] assert result == expected_rules @pytest.mark.parametrize(('css_source', 'expected_declarations', 'expected_errors'), [ (' /* hey */\n', [], []), ('b:4', [('b', [('INTEGER', 4)])], []), ('{b:4}', [], ['expected a property name, got {']), ('b:4} c:3', [], ['unmatched } token in property value']), (' 4px; bar: 12% ', [('bar', [('PERCENTAGE', 12)])], ['expected a property name, got DIMENSION']), ('bar! 3cm auto ; baz: 7px', [('baz', [('DIMENSION', 7)])], ["expected ':', got DELIM"]), ('foo; bar ; baz: {("}"/* comment */) {0@fizz}}', [('baz', [('{', [ ('(', [('STRING', '}')]), ('S', ' '), ('{', [('INTEGER', 0), ('ATKEYWORD', '@fizz')]) ])])], ["expected ':'", "expected ':'"]), ('bar: ; baz: not(z)', [('baz', [('FUNCTION', 'not', [('IDENT', 'z')])])], ['expected a property value']), ('bar: (]) ; baz: U+20', [('baz', [('UNICODE-RANGE', 'U+20')])], ['unmatched ] token in (']), ]) def test_parse_style_attr(css_source, expected_declarations, expected_errors): declarations, errors = CSS21Parser().parse_style_attr(css_source) assert_errors(errors, expected_errors) result = [(decl.name, list(jsonify(decl.value))) for decl in declarations] assert result == expected_declarations @pytest.mark.parametrize(('css_source', 'expected_declarations', 'expected_errors'), [ (' /* hey */\n', [], []), ('a:1; b:2', [('a', [('INTEGER', 1)], None), ('b', [('INTEGER', 2)], None)], []), ('a:1 important; b: important', [('a', [('INTEGER', 1), ('S', ' '), ('IDENT', 'important')], None), ('b', [('IDENT', 'important')], None)], []), ('a:1 !important; b:2', [('a', [('INTEGER', 1)], 'important'), ('b', [('INTEGER', 2)], None)], []), ('a:1!\t Im\\50 O\\RTant; b:2', [('a', [('INTEGER', 1)], 'important'), ('b', [('INTEGER', 2)], None)], []), ('a: !important; b:2', [('b', [('INTEGER', 2)], None)], ['expected a value before !important']), ]) def test_important(css_source, expected_declarations, expected_errors): declarations, errors = CSS21Parser().parse_style_attr(css_source) assert_errors(errors, expected_errors) result = [(decl.name, list(jsonify(decl.value)), decl.priority) for decl in declarations] assert result == expected_declarations @pytest.mark.parametrize(('css_source', 'expected_rules', 'expected_errors'), [ (' /* hey */\n', [], []), ('@import "foo.css";', [('foo.css', ['all'])], []), ('@import url(foo.css);', [('foo.css', ['all'])], []), ('@import "foo.css" screen, print;', [('foo.css', ['screen', 'print'])], []), ('@charset "ascii"; @import "foo.css"; @import "bar.css";', [('foo.css', ['all']), ('bar.css', ['all'])], []), ('foo {} @import "foo.css";', [], ['@import rule not allowed after a ruleset']), ('@page {} @import "foo.css";', [], ['@import rule not allowed after an @page rule']), ('@import ;', [], ['expected URI or STRING for @import rule']), ('@import foo.css;', [], ['expected URI or STRING for @import rule, got IDENT']), ('@import "foo.css" {}', [], ["expected ';', got a block"]), ]) def test_at_import(css_source, expected_rules, expected_errors): # Pass 'encoding' to allow @charset stylesheet = CSS21Parser().parse_stylesheet(css_source, encoding='utf8') assert_errors(stylesheet.errors, expected_errors) result = [ (rule.uri, rule.media) for rule in stylesheet.rules if rule.at_keyword == '@import' ] assert result == expected_rules @pytest.mark.parametrize(('css', 'expected_result', 'expected_errors'), [ ('@page {}', (None, (0, 0), []), []), ('@page:first {}', ('first', (1, 0), []), []), ('@page :left{}', ('left', (0, 1), []), []), ('@page\t\n:right {}', ('right', (0, 1), []), []), ('@page :last {}', None, ['invalid @page selector']), ('@page : right {}', None, ['invalid @page selector']), ('@page table:left {}', None, ['invalid @page selector']), ('@page;', None, ['invalid @page rule: missing block']), ('@page { a:1; ; b: 2 }', (None, (0, 0), [('a', [('INTEGER', 1)]), ('b', [('INTEGER', 2)])]), []), ('@page { a:1; c: ; b: 2 }', (None, (0, 0), [('a', [('INTEGER', 1)]), ('b', [('INTEGER', 2)])]), ['expected a property value']), ('@page { a:1; @top-left {} b: 2 }', (None, (0, 0), [('a', [('INTEGER', 1)]), ('b', [('INTEGER', 2)])]), ['unknown at-rule in @page context: @top-left']), ('@page { a:1; @top-left {}; b: 2 }', (None, (0, 0), [('a', [('INTEGER', 1)]), ('b', [('INTEGER', 2)])]), ['unknown at-rule in @page context: @top-left']), ]) def test_at_page(css, expected_result, expected_errors): stylesheet = CSS21Parser().parse_stylesheet(css) assert_errors(stylesheet.errors, expected_errors) if expected_result is None: assert not stylesheet.rules else: assert len(stylesheet.rules) == 1 rule = stylesheet.rules[0] assert rule.at_keyword == '@page' assert rule.at_rules == [] # in CSS 2.1 result = ( rule.selector, rule.specificity, [(decl.name, list(jsonify(decl.value))) for decl in rule.declarations], ) assert result == expected_result @pytest.mark.parametrize(('css_source', 'expected_rules', 'expected_errors'), [ (' /* hey */\n', [], []), ('@media all {}', [(['all'], [])], []), ('@media screen, print {}', [(['screen', 'print'], [])], []), ('@media all;', [], ['invalid @media rule: missing block']), ('@media {}', [], ['expected media types for @media']), ('@media 4 {}', [], ['expected a media type, got INTEGER']), ('@media , screen {}', [], ['expected a media type']), ('@media screen, {}', [], ['expected a media type']), ('@media screen print {}', [], ['expected a media type, got IDENT, IDENT']), ('@media all { @page { a: 1 } @media; @import; foo { a: 1 } }', [(['all'], [('foo', [('a', [('INTEGER', 1)])])])], ['@page rule not allowed in @media', '@media rule not allowed in @media', '@import rule not allowed in @media']), ]) def test_at_media(css_source, expected_rules, expected_errors): stylesheet = CSS21Parser().parse_stylesheet(css_source) assert_errors(stylesheet.errors, expected_errors) for rule in stylesheet.rules: assert rule.at_keyword == '@media' result = [ (rule.media, [ (sub_rule.selector.as_css(), [ (decl.name, list(jsonify(decl.value))) for decl in sub_rule.declarations]) for sub_rule in rule.rules ]) for rule in stylesheet.rules ] assert result == expected_rules tinycss-0.4/tinycss/tests/test_decoding.py0000644000175000017500000000642112766236227021044 0ustar lizelize00000000000000# coding: utf-8 """ Tests for decoding bytes to Unicode ----------------------------------- :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals import pytest from tinycss.decoding import decode def params(css, encoding, use_bom=False, expect_error=False, **kwargs): """Nicer syntax to make a tuple.""" return css, encoding, use_bom, expect_error, kwargs @pytest.mark.parametrize(('css', 'encoding', 'use_bom', 'expect_error', 'kwargs'), [ params('', 'utf8'), # default to utf8 params('𐂃', 'utf8'), params('é', 'latin1'), # utf8 fails, fall back on ShiftJIS params('£', 'ShiftJIS', expect_error=True), params('£', 'ShiftJIS', protocol_encoding='Shift-JIS'), params('£', 'ShiftJIS', linking_encoding='Shift-JIS'), params('£', 'ShiftJIS', document_encoding='Shift-JIS'), params('£', 'ShiftJIS', protocol_encoding='utf8', document_encoding='ShiftJIS'), params('@charset "utf8"; £', 'ShiftJIS', expect_error=True), params('@charset "utf£8"; £', 'ShiftJIS', expect_error=True), params('@charset "unknown-encoding"; £', 'ShiftJIS', expect_error=True), params('@charset "utf8"; £', 'ShiftJIS', document_encoding='ShiftJIS'), params('£', 'ShiftJIS', linking_encoding='utf8', document_encoding='ShiftJIS'), params('@charset "utf-32"; 𐂃', 'utf-32-be'), params('@charset "Shift-JIS"; £', 'ShiftJIS'), params('@charset "ISO-8859-8"; £', 'ShiftJIS', expect_error=True), params('𐂃', 'utf-16-le', expect_error=True), # no BOM params('𐂃', 'utf-16-le', use_bom=True), params('𐂃', 'utf-32-be', expect_error=True), params('𐂃', 'utf-32-be', use_bom=True), params('𐂃', 'utf-32-be', document_encoding='utf-32-be'), params('𐂃', 'utf-32-be', linking_encoding='utf-32-be'), params('@charset "utf-32-le"; 𐂃', 'utf-32-be', use_bom=True, expect_error=True), # protocol_encoding takes precedence over @charset params('@charset "ISO-8859-8"; £', 'ShiftJIS', protocol_encoding='Shift-JIS'), params('@charset "unknown-encoding"; £', 'ShiftJIS', protocol_encoding='Shift-JIS'), params('@charset "Shift-JIS"; £', 'ShiftJIS', protocol_encoding='utf8'), # @charset takes precedence over document_encoding params('@charset "Shift-JIS"; £', 'ShiftJIS', document_encoding='ISO-8859-8'), # @charset takes precedence over linking_encoding params('@charset "Shift-JIS"; £', 'ShiftJIS', linking_encoding='ISO-8859-8'), # linking_encoding takes precedence over document_encoding params('£', 'ShiftJIS', linking_encoding='Shift-JIS', document_encoding='ISO-8859-8'), ]) def test_decode(css, encoding, use_bom, expect_error, kwargs): # Workaround PyPy and CPython 3.0 bug: https://bugs.pypy.org/issue1094 css = css.encode('utf16').decode('utf16') if use_bom: source = '\ufeff' + css else: source = css css_bytes = source.encode(encoding) result, result_encoding = decode(css_bytes, **kwargs) if expect_error: assert result != css, 'Unexpected unicode success' else: assert result == css, 'Unexpected unicode error' tinycss-0.4/tinycss/tests/test_fonts3.py0000644000175000017500000001347512771240422020477 0ustar lizelize00000000000000# coding: utf-8 """ Tests for the Fonts 3 parser ---------------------------- :copyright: (c) 2016 by Kozea. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals import pytest from tinycss.fonts3 import CSSFonts3Parser from . import assert_errors from .test_tokenizer import jsonify @pytest.mark.parametrize(('css', 'expected_family_names', 'expected_errors'), [ ('@font-feature-values foo {}', ('foo',), []), ('@font-feature-values Foo Test {}', ('Foo Test',), []), ('@font-feature-values \'Foo Test\' {}', ('Foo Test',), []), ('@font-feature-values Foo Test, Foo Lol, "Foo tooo"', ( 'Foo Test', 'Foo Lol', 'Foo tooo'), []), ('@font-feature-values Foo , Foo lol {}', ('Foo', 'Foo lol'), []), ('@font-feature-values Foo , "Foobar" , Lol {}', ( 'Foo', 'Foobar', 'Lol'), []), ('@font-feature-values Foo, {}', None, [ 'invalid @font-feature-values selector']), ('@font-feature-values ,Foo {}', None, [ 'invalid @font-feature-values selector']), ('@font-feature-values Test,"Foo", {}', None, [ 'invalid @font-feature-values selector']), ('@font-feature-values Test "Foo" {}', None, [ 'invalid @font-feature-values selector']), ('@font-feature-values Test Foo, Test "bar", "foo" {}', None, [ 'invalid @font-feature-values selector']), ('@font-feature-values Test/Foo {}', None, [ 'invalid @font-feature-values selector']), ('@font-feature-values /Foo {}', None, [ 'invalid @font-feature-values selector']), ('@font-feature-values #Foo {}', None, [ 'invalid @font-feature-values selector']), # TODO: this currently works but should not work # ('@font-feature-values test@foo {}', None, [ # 'invalid @font-feature-values selector']), ('@font-feature-values Hawaii 5-0 {}', None, [ 'invalid @font-feature-values selector']), ]) def test_font_feature_values_selectors(css, expected_family_names, expected_errors): stylesheet = CSSFonts3Parser().parse_stylesheet(css) assert_errors(stylesheet.errors, expected_errors) if stylesheet.rules: assert len(stylesheet.rules) == 1 rule = stylesheet.rules[0] assert rule.at_keyword == '@font-feature-values' assert rule.family_names == expected_family_names @pytest.mark.parametrize(('css', 'expected_declarations', 'expected_errors'), [ ('@font-face {}', [], []), ('@font-face test { src: "lol"; font-family: "bar" }', None, [ 'unexpected IDENT token in @font-face rule header']), ('@font-face { src: "lol"; font-family: "bar" }', [ ('src', [('STRING', 'lol')]), ('font-family', [('STRING', 'bar')])], []), ('@font-face { src: "lol"; font-family: "bar"; src: "baz" }', [ ('src', [('STRING', 'lol')]), ('font-family', [('STRING', 'bar')]), ('src', [('STRING', 'baz')])], []), ]) def test_font_face_content(css, expected_declarations, expected_errors): stylesheet = CSSFonts3Parser().parse_stylesheet(css) assert_errors(stylesheet.errors, expected_errors) def declarations(rule): return [(decl.name, list(jsonify(decl.value))) for decl in rule.declarations] if expected_declarations is None: assert stylesheet.rules == [] assert expected_errors else: assert len(stylesheet.rules) == 1 rule = stylesheet.rules[0] assert rule.at_keyword == '@font-face' assert declarations(rule) == expected_declarations @pytest.mark.parametrize( ('css', 'expected_rules', 'expected_errors'), [ ('''@annotation{}''', None, [ '@annotation rule not allowed in stylesheet']), ('''@font-feature-values foo {}''', None, []), ('''@font-feature-values foo { @swash { ornate: 1; } @styleset { double-W: 14; sharp-terminals: 16 1; } }''', [ ('@swash', [('ornate', [('INTEGER', 1)])]), ('@styleset', [ ('double-w', [('INTEGER', 14)]), ('sharp-terminals', [ ('INTEGER', 16), ('S', ' '), ('INTEGER', 1)])])], []), ('''@font-feature-values foo { @swash { ornate: 14; } @unknown { test: 1; } }''', [('@swash', [('ornate', [('INTEGER', 14)])])], [ 'unknown at-rule in @font-feature-values context: @unknown']), ('''@font-feature-values foo { @annotation{boxed:1} bad: 2; @brokenstylesetbecauseofbadabove { sharp: 1} @styleset { sharp-terminals: 16 1; @bad {}} @styleset { @bad {} top-ignored: 3; top: 9000} really-bad }''', [ ('@annotation', [('boxed', [('INTEGER', 1)])]), ('@styleset', [ ('sharp-terminals', [ ('INTEGER', 16), ('S', ' '), ('INTEGER', 1)])]), ('@styleset', [('top', [('INTEGER', 9000)])])], [ 'unexpected ; token in selector', 'expected a property name, got ATKEYWORD', 'expected a property name, got ATKEYWORD', 'no declaration block found for ruleset']), ]) def test_font_feature_values_content(css, expected_rules, expected_errors): stylesheet = CSSFonts3Parser().parse_stylesheet(css) assert_errors(stylesheet.errors, expected_errors) if expected_rules is not None: assert len(stylesheet.rules) == 1 rule = stylesheet.rules[0] assert rule.at_keyword == '@font-feature-values' rules = [ (at_rule.at_keyword, [ (decl.name, list(jsonify(decl.value))) for decl in at_rule.declarations]) for at_rule in rule.at_rules] if rule.at_rules else None assert rules == expected_rules tinycss-0.4/tinycss/tests/test_page3.py0000644000175000017500000000725312766236332020270 0ustar lizelize00000000000000# coding: utf-8 """ Tests for the Paged Media 3 parser ---------------------------------- :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals import pytest from tinycss.page3 import CSSPage3Parser from . import assert_errors from .test_tokenizer import jsonify @pytest.mark.parametrize(('css', 'expected_selector', 'expected_specificity', 'expected_errors'), [ ('@page {}', (None, None), (0, 0, 0), []), ('@page :first {}', (None, 'first'), (0, 1, 0), []), ('@page:left{}', (None, 'left'), (0, 0, 1), []), ('@page :right {}', (None, 'right'), (0, 0, 1), []), ('@page :blank{}', (None, 'blank'), (0, 1, 0), []), ('@page :last {}', None, None, ['invalid @page selector']), ('@page : first {}', None, None, ['invalid @page selector']), ('@page foo:first {}', ('foo', 'first'), (1, 1, 0), []), ('@page bar :left {}', ('bar', 'left'), (1, 0, 1), []), (r'@page \26:right {}', ('&', 'right'), (1, 0, 1), []), ('@page foo {}', ('foo', None), (1, 0, 0), []), (r'@page \26 {}', ('&', None), (1, 0, 0), []), ('@page foo fist {}', None, None, ['invalid @page selector']), ('@page foo, bar {}', None, None, ['invalid @page selector']), ('@page foo&first {}', None, None, ['invalid @page selector']), ]) def test_selectors(css, expected_selector, expected_specificity, expected_errors): stylesheet = CSSPage3Parser().parse_stylesheet(css) assert_errors(stylesheet.errors, expected_errors) if stylesheet.rules: assert len(stylesheet.rules) == 1 rule = stylesheet.rules[0] assert rule.at_keyword == '@page' selector = rule.selector assert rule.specificity == expected_specificity else: selector = None assert selector == expected_selector @pytest.mark.parametrize(('css', 'expected_declarations', 'expected_rules', 'expected_errors'), [ ('@page {}', [], [], []), ('@page { foo: 4; bar: z }', [('foo', [('INTEGER', 4)]), ('bar', [('IDENT', 'z')])], [], []), ('''@page { foo: 4; @top-center { content: "Awesome Title" } @bottom-left { content: counter(page) } bar: z }''', [('foo', [('INTEGER', 4)]), ('bar', [('IDENT', 'z')])], [('@top-center', [('content', [('STRING', 'Awesome Title')])]), ('@bottom-left', [('content', [ ('FUNCTION', 'counter', [('IDENT', 'page')])])])], []), ('''@page { foo: 4; @bottom-top { content: counter(page) } bar: z }''', [('foo', [('INTEGER', 4)]), ('bar', [('IDENT', 'z')])], [], ['unknown at-rule in @page context: @bottom-top']), ('@page{} @top-right{}', [], [], [ '@top-right rule not allowed in stylesheet']), ('@page{ @top-right 4 {} }', [], [], [ 'unexpected INTEGER token in @top-right rule header']), # Not much error recovery tests here. This should be covered in test_css21 ]) def test_content(css, expected_declarations, expected_rules, expected_errors): stylesheet = CSSPage3Parser().parse_stylesheet(css) assert_errors(stylesheet.errors, expected_errors) def declarations(rule): return [(decl.name, list(jsonify(decl.value))) for decl in rule.declarations] assert len(stylesheet.rules) == 1 rule = stylesheet.rules[0] assert rule.at_keyword == '@page' assert declarations(rule) == expected_declarations rules = [(margin_rule.at_keyword, declarations(margin_rule)) for margin_rule in rule.at_rules] assert rules == expected_rules tinycss-0.4/tinycss/tests/test_tokenizer.py0000644000175000017500000002464612766241474021313 0ustar lizelize00000000000000# coding: utf-8 """ Tests for the tokenizer ----------------------- :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals import os import sys import pytest from tinycss.tokenizer import ( cython_tokenize_flat, python_tokenize_flat, regroup) def test_speedups(): is_pypy = hasattr(sys, 'pypy_translation_info') env_skip_tests = os.environ.get('TINYCSS_SKIP_SPEEDUPS_TESTS') # pragma: no cover if is_pypy or env_skip_tests: return assert cython_tokenize_flat is not None, ( 'Cython speedups are not installed, related tests will ' 'be skipped. Set the TINYCSS_SKIP_SPEEDUPS_TESTS environment ' 'variable if this is expected.') @pytest.mark.parametrize(('tokenize', 'css_source', 'expected_tokens'), [ (tokenize,) + test_data for tokenize in (python_tokenize_flat, cython_tokenize_flat) for test_data in [ ('', []), ('red -->', [('IDENT', 'red'), ('S', ' '), ('CDC', '-->')]), # Longest match rule: no CDC ('red-->', [('IDENT', 'red--'), ('DELIM', '>')]), (r'p[example="foo(int x) { this.x = x;}"]', [ ('IDENT', 'p'), ('[', '['), ('IDENT', 'example'), ('DELIM', '='), ('STRING', 'foo(int x) { this.x = x;}'), (']', ']')]), # Numbers are parsed ('42 .5 -4pX 1.25em 30%', [ ('INTEGER', 42), ('S', ' '), ('NUMBER', .5), ('S', ' '), # units are normalized to lower-case: ('DIMENSION', -4, 'px'), ('S', ' '), ('DIMENSION', 1.25, 'em'), ('S', ' '), ('PERCENTAGE', 30, '%')]), # URLs are extracted ('url(foo.png)', [('URI', 'foo.png')]), ('url("foo.png")', [('URI', 'foo.png')]), # Escaping (r'/* Comment with a \ backslash */', [ ('COMMENT', '/* Comment with a \ backslash */')]), # Unchanged # backslash followed by a newline in a string: ignored ('"Lorem\\\nIpsum"', [('STRING', 'LoremIpsum')]), # backslash followed by a newline outside a string: stands for itself ('Lorem\\\nIpsum', [ ('IDENT', 'Lorem'), ('DELIM', '\\'), ('S', '\n'), ('IDENT', 'Ipsum')]), # Cancel the meaning of special characters (r'"Lore\m Ipsum"', [('STRING', 'Lorem Ipsum')]), # or not specal (r'"Lorem \49psum"', [('STRING', 'Lorem Ipsum')]), (r'"Lorem \49 psum"', [('STRING', 'Lorem Ipsum')]), (r'"Lorem\"Ipsum"', [('STRING', 'Lorem"Ipsum')]), (r'"Lorem\\Ipsum"', [('STRING', r'Lorem\Ipsum')]), (r'"Lorem\5c Ipsum"', [('STRING', r'Lorem\Ipsum')]), (r'Lorem\+Ipsum', [('IDENT', 'Lorem+Ipsum')]), (r'Lorem+Ipsum', [ ('IDENT', 'Lorem'), ('DELIM', '+'), ('IDENT', 'Ipsum')]), (r'url(foo\).png)', [('URI', 'foo).png')]), # Unicode and backslash escaping ('\\26 B', [('IDENT', '&B')]), ('\\&B', [('IDENT', '&B')]), ('@\\26\tB', [('ATKEYWORD', '@&B')]), ('@\\&B', [('ATKEYWORD', '@&B')]), ('#\\26\nB', [('HASH', '#&B')]), ('#\\&B', [('HASH', '#&B')]), ('\\26\r\nB(', [('FUNCTION', '&B(')]), ('\\&B(', [('FUNCTION', '&B(')]), (r'12.5\000026B', [('DIMENSION', 12.5, '&b')]), (r'12.5\0000263B', [('DIMENSION', 12.5, '&3b')]), # max 6 digits (r'12.5\&B', [('DIMENSION', 12.5, '&b')]), (r'"\26 B"', [('STRING', '&B')]), (r"'\000026B'", [('STRING', '&B')]), (r'"\&B"', [('STRING', '&B')]), (r'url("\26 B")', [('URI', '&B')]), (r'url(\26 B)', [('URI', '&B')]), (r'url("\&B")', [('URI', '&B')]), (r'url(\&B)', [('URI', '&B')]), (r'Lorem\110000Ipsum', [('IDENT', 'Lorem\uFFFDIpsum')]), # Bad strings # String ends at EOF without closing: no error, parsed ('"Lorem\\26Ipsum', [('STRING', 'Lorem&Ipsum')]), # Unescaped newline: ends the string, error, unparsed ('"Lorem\\26Ipsum\n', [ ('BAD_STRING', r'"Lorem\26Ipsum'), ('S', '\n')]), # Tokenization restarts after the newline, so the second " starts # a new string (which ends at EOF without errors, as above.) ('"Lorem\\26Ipsum\ndolor" sit', [ ('BAD_STRING', r'"Lorem\26Ipsum'), ('S', '\n'), ('IDENT', 'dolor'), ('STRING', ' sit')]), ]]) def test_tokens(tokenize, css_source, expected_tokens): if tokenize is None: # pragma: no cover pytest.skip('Speedups not available') sources = [css_source] if sys.version_info[0] < 3: # On Python 2.x, ASCII-only bytestrings can be used # where Unicode is expected. sources.append(css_source.encode('ascii')) for css_source in sources: tokens = tokenize(css_source, ignore_comments=False) result = [ (token.type, token.value) + ( () if token.unit is None else (token.unit,)) for token in tokens ] assert result == expected_tokens @pytest.mark.parametrize('tokenize', [ python_tokenize_flat, cython_tokenize_flat]) def test_positions(tokenize): """Test the reported line/column position of each token.""" if tokenize is None: # pragma: no cover pytest.skip('Speedups not available') css = '/* Lorem\nipsum */\fa {\n color: red;\tcontent: "dolor\\\fsit" }' tokens = tokenize(css, ignore_comments=False) result = [(token.type, token.line, token.column) for token in tokens] assert result == [ ('COMMENT', 1, 1), ('S', 2, 9), ('IDENT', 3, 1), ('S', 3, 2), ('{', 3, 3), ('S', 3, 4), ('IDENT', 4, 5), (':', 4, 10), ('S', 4, 11), ('IDENT', 4, 12), (';', 4, 15), ('S', 4, 16), ('IDENT', 4, 17), (':', 4, 24), ('S', 4, 25), ('STRING', 4, 26), ('S', 5, 5), ('}', 5, 6)] @pytest.mark.parametrize(('tokenize', 'css_source', 'expected_tokens'), [ (tokenize,) + test_data for tokenize in (python_tokenize_flat, cython_tokenize_flat) for test_data in [ ('', []), (r'Lorem\26 "i\psum"4px', [ ('IDENT', 'Lorem&'), ('STRING', 'ipsum'), ('DIMENSION', 4)]), ('not([[lorem]]{ipsum (42)})', [ ('FUNCTION', 'not', [ ('[', [ ('[', [ ('IDENT', 'lorem'), ]), ]), ('{', [ ('IDENT', 'ipsum'), ('S', ' '), ('(', [ ('INTEGER', 42), ]) ]) ])]), # Close everything at EOF, no error ('a[b{"d', [ ('IDENT', 'a'), ('[', [ ('IDENT', 'b'), ('{', [ ('STRING', 'd'), ]), ]), ]), # Any remaining ), ] or } token is a nesting error ('a[b{d]e}', [ ('IDENT', 'a'), ('[', [ ('IDENT', 'b'), ('{', [ ('IDENT', 'd'), (']', ']'), # The error is visible here ('IDENT', 'e'), ]), ]), ]), # ref: ('a[b{d}e]', [ ('IDENT', 'a'), ('[', [ ('IDENT', 'b'), ('{', [ ('IDENT', 'd'), ]), ('IDENT', 'e'), ]), ]), ]]) def test_token_grouping(tokenize, css_source, expected_tokens): if tokenize is None: # pragma: no cover pytest.skip('Speedups not available') tokens = regroup(tokenize(css_source, ignore_comments=False)) result = list(jsonify(tokens)) assert result == expected_tokens def jsonify(tokens): """Turn tokens into "JSON-compatible" data structures.""" for token in tokens: if token.type == 'FUNCTION': yield (token.type, token.function_name, list(jsonify(token.content))) elif token.is_container: yield token.type, list(jsonify(token.content)) else: yield token.type, token.value @pytest.mark.parametrize(('tokenize', 'ignore_comments', 'expected_tokens'), [ (tokenize,) + test_data for tokenize in (python_tokenize_flat, cython_tokenize_flat) for test_data in [ (False, [ ('COMMENT', '/* lorem */'), ('S', ' '), ('IDENT', 'ipsum'), ('[', [ ('IDENT', 'dolor'), ('COMMENT', '/* sit */'), ]), ('BAD_COMMENT', '/* amet') ]), (True, [ ('S', ' '), ('IDENT', 'ipsum'), ('[', [ ('IDENT', 'dolor'), ]), ]), ]]) def test_comments(tokenize, ignore_comments, expected_tokens): if tokenize is None: # pragma: no cover pytest.skip('Speedups not available') css_source = '/* lorem */ ipsum[dolor/* sit */]/* amet' tokens = regroup(tokenize(css_source, ignore_comments)) result = list(jsonify(tokens)) assert result == expected_tokens @pytest.mark.parametrize(('tokenize', 'css_source'), [ (tokenize, test_data) for tokenize in (python_tokenize_flat, cython_tokenize_flat) for test_data in [ r'p[example="foo(int x) { this.x = x;}"]', '"Lorem\\26Ipsum\ndolor" sit', '/* Lorem\nipsum */\fa {\n color: red;\tcontent: "dolor\\\fsit" }', 'not([[lorem]]{ipsum (42)})', 'a[b{d]e}', 'a[b{"d', ]]) def test_token_serialize_css(tokenize, css_source): if tokenize is None: # pragma: no cover pytest.skip('Speedups not available') for _regroup in [regroup, lambda x: x]: tokens = _regroup(tokenize(css_source, ignore_comments=False)) result = ''.join(token.as_css() for token in tokens) assert result == css_source @pytest.mark.parametrize(('tokenize', 'css_source'), [ (tokenize, test_data) for tokenize in (python_tokenize_flat, cython_tokenize_flat) for test_data in [ '(8, foo, [z])', '[8, foo, (z)]', '{8, foo, [z]}', 'func(8, foo, [z])' ] ]) def test_token_api(tokenize, css_source): if tokenize is None: # pragma: no cover pytest.skip('Speedups not available') tokens = list(regroup(tokenize(css_source))) assert len(tokens) == 1 token = tokens[0] expected_len = 7 # 2 spaces, 2 commas, 3 others. assert len(token.content) == expected_len tinycss-0.4/tinycss/__init__.py0000644000175000017500000000227612766234113016622 0ustar lizelize00000000000000# coding: utf-8 """ tinycss ------- A CSS parser, and nothing else. :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from .version import VERSION from .css21 import CSS21Parser from .page3 import CSSPage3Parser from .fonts3 import CSSFonts3Parser __version__ = VERSION PARSER_MODULES = { 'page3': CSSPage3Parser, 'fonts3': CSSFonts3Parser, } def make_parser(*features, **kwargs): """Make a parser object with the chosen features. :param features: Positional arguments are base classes the new parser class will extend. The string ``'page3'`` is accepted as short for :class:`~page3.CSSPage3Parser`. The string ``'fonts3'`` is accepted as short for :class:`~fonts3.CSSFonts3Parser`. :param kwargs: Keyword arguments are passed to the parser’s constructor. :returns: An instance of a new subclass of :class:`CSS21Parser` """ if features: bases = tuple(PARSER_MODULES.get(f, f) for f in features) parser_class = type('CustomCSSParser', bases + (CSS21Parser,), {}) else: parser_class = CSS21Parser return parser_class(**kwargs) tinycss-0.4/tinycss/color3.py0000644000175000017500000003000212766233446016260 0ustar lizelize00000000000000# coding: utf-8 """ tinycss.colors3 --------------- Parser for CSS 3 color values http://www.w3.org/TR/css3-color/ This module does not provide anything that integrates in a parser class, only functions that parse single tokens from (eg.) a property value. :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import division, unicode_literals import collections import itertools import re from .tokenizer import tokenize_grouped class RGBA(collections.namedtuple('RGBA', ['red', 'green', 'blue', 'alpha'])): """An RGBA color. A tuple of four floats in the 0..1 range: ``(r, g, b, a)``. Also has ``red``, ``green``, ``blue`` and ``alpha`` attributes to access the same values. """ def parse_color_string(css_string): """Parse a CSS string as a color value. This is a convenience wrapper around :func:`parse_color` in case you have a string that is not from a CSS stylesheet. :param css_string: An unicode string in CSS syntax. :returns: Same as :func:`parse_color`. """ tokens = list(tokenize_grouped(css_string.strip())) if len(tokens) == 1: return parse_color(tokens[0]) def parse_color(token): """Parse single token as a color value. :param token: A single :class:`~.token_data.Token` or :class:`~.token_data.ContainerToken`, as found eg. in a property value. :returns: * ``None``, if the token is not a valid CSS 3 color value. (No exception is raised.) * For the *currentColor* keyword: the string ``'currentColor'`` * Every other values (including keywords, HSL and HSLA) is converted to RGBA and returned as an :class:`RGBA` object (a 4-tuple with attribute access). The alpha channel is clipped to [0, 1], but R, G, or B can be out of range (eg. ``rgb(-51, 306, 0)`` is represented as ``(-.2, 1.2, 0, 1)``.) """ if token.type == 'IDENT': return COLOR_KEYWORDS.get(token.value.lower()) elif token.type == 'HASH': for multiplier, regexp in HASH_REGEXPS: match = regexp(token.value) if match: r, g, b = [int(group * multiplier, 16) / 255 for group in match.groups()] return RGBA(r, g, b, 1.) elif token.type == 'FUNCTION': args = parse_comma_separated(token.content) if args: name = token.function_name.lower() if name == 'rgb': return parse_rgb(args, alpha=1.) elif name == 'rgba': alpha = parse_alpha(args[3:]) if alpha is not None: return parse_rgb(args[:3], alpha) elif name == 'hsl': return parse_hsl(args, alpha=1.) elif name == 'hsla': alpha = parse_alpha(args[3:]) if alpha is not None: return parse_hsl(args[:3], alpha) def parse_alpha(args): """ If args is a list of a single INTEGER or NUMBER token, retur its value clipped to the 0..1 range Otherwise, return None. """ if len(args) == 1 and args[0].type in ('NUMBER', 'INTEGER'): return min(1, max(0, args[0].value)) def parse_rgb(args, alpha): """ If args is a list of 3 INTEGER tokens or 3 PERCENTAGE tokens, return RGB values as a tuple of 3 floats in 0..1. Otherwise, return None. """ types = [arg.type for arg in args] if types == ['INTEGER', 'INTEGER', 'INTEGER']: r, g, b = [arg.value / 255 for arg in args[:3]] return RGBA(r, g, b, alpha) elif types == ['PERCENTAGE', 'PERCENTAGE', 'PERCENTAGE']: r, g, b = [arg.value / 100 for arg in args[:3]] return RGBA(r, g, b, alpha) def parse_hsl(args, alpha): """ If args is a list of 1 INTEGER token and 2 PERCENTAGE tokens, return RGB values as a tuple of 3 floats in 0..1. Otherwise, return None. """ types = [arg.type for arg in args] if types == ['INTEGER', 'PERCENTAGE', 'PERCENTAGE']: hsl = [arg.value for arg in args[:3]] r, g, b = hsl_to_rgb(*hsl) return RGBA(r, g, b, alpha) def hsl_to_rgb(hue, saturation, lightness): """ :param hue: degrees :param saturation: percentage :param lightness: percentage :returns: (r, g, b) as floats in the 0..1 range """ hue = (hue / 360) % 1 saturation = min(1, max(0, saturation / 100)) lightness = min(1, max(0, lightness / 100)) # Translated from ABC: http://www.w3.org/TR/css3-color/#hsl-color def hue_to_rgb(m1, m2, h): if h < 0: h += 1 if h > 1: h -= 1 if h * 6 < 1: return m1 + (m2 - m1) * h * 6 if h * 2 < 1: return m2 if h * 3 < 2: return m1 + (m2 - m1) * (2 / 3 - h) * 6 return m1 if lightness <= 0.5: m2 = lightness * (saturation + 1) else: m2 = lightness + saturation - lightness * saturation m1 = lightness * 2 - m2 return ( hue_to_rgb(m1, m2, hue + 1 / 3), hue_to_rgb(m1, m2, hue), hue_to_rgb(m1, m2, hue - 1 / 3), ) def parse_comma_separated(tokens): """Parse a list of tokens (typically the content of a function token) as arguments made of a single token each, separated by mandatory commas, with optional white space around each argument. return the argument list without commas or white space; or None if the function token content do not match the description above. """ tokens = [token for token in tokens if token.type != 'S'] if not tokens: return [] if len(tokens) % 2 == 1 and all( token.type == 'DELIM' and token.value == ',' for token in tokens[1::2]): return tokens[::2] HASH_REGEXPS = ( (2, re.compile('^#([\da-f])([\da-f])([\da-f])$', re.I).match), (1, re.compile('^#([\da-f]{2})([\da-f]{2})([\da-f]{2})$', re.I).match), ) # (r, g, b) in 0..255 BASIC_COLOR_KEYWORDS = [ ('black', (0, 0, 0)), ('silver', (192, 192, 192)), ('gray', (128, 128, 128)), ('white', (255, 255, 255)), ('maroon', (128, 0, 0)), ('red', (255, 0, 0)), ('purple', (128, 0, 128)), ('fuchsia', (255, 0, 255)), ('green', (0, 128, 0)), ('lime', (0, 255, 0)), ('olive', (128, 128, 0)), ('yellow', (255, 255, 0)), ('navy', (0, 0, 128)), ('blue', (0, 0, 255)), ('teal', (0, 128, 128)), ('aqua', (0, 255, 255)), ] # (r, g, b) in 0..255 EXTENDED_COLOR_KEYWORDS = [ ('aliceblue', (240, 248, 255)), ('antiquewhite', (250, 235, 215)), ('aqua', (0, 255, 255)), ('aquamarine', (127, 255, 212)), ('azure', (240, 255, 255)), ('beige', (245, 245, 220)), ('bisque', (255, 228, 196)), ('black', (0, 0, 0)), ('blanchedalmond', (255, 235, 205)), ('blue', (0, 0, 255)), ('blueviolet', (138, 43, 226)), ('brown', (165, 42, 42)), ('burlywood', (222, 184, 135)), ('cadetblue', (95, 158, 160)), ('chartreuse', (127, 255, 0)), ('chocolate', (210, 105, 30)), ('coral', (255, 127, 80)), ('cornflowerblue', (100, 149, 237)), ('cornsilk', (255, 248, 220)), ('crimson', (220, 20, 60)), ('cyan', (0, 255, 255)), ('darkblue', (0, 0, 139)), ('darkcyan', (0, 139, 139)), ('darkgoldenrod', (184, 134, 11)), ('darkgray', (169, 169, 169)), ('darkgreen', (0, 100, 0)), ('darkgrey', (169, 169, 169)), ('darkkhaki', (189, 183, 107)), ('darkmagenta', (139, 0, 139)), ('darkolivegreen', (85, 107, 47)), ('darkorange', (255, 140, 0)), ('darkorchid', (153, 50, 204)), ('darkred', (139, 0, 0)), ('darksalmon', (233, 150, 122)), ('darkseagreen', (143, 188, 143)), ('darkslateblue', (72, 61, 139)), ('darkslategray', (47, 79, 79)), ('darkslategrey', (47, 79, 79)), ('darkturquoise', (0, 206, 209)), ('darkviolet', (148, 0, 211)), ('deeppink', (255, 20, 147)), ('deepskyblue', (0, 191, 255)), ('dimgray', (105, 105, 105)), ('dimgrey', (105, 105, 105)), ('dodgerblue', (30, 144, 255)), ('firebrick', (178, 34, 34)), ('floralwhite', (255, 250, 240)), ('forestgreen', (34, 139, 34)), ('fuchsia', (255, 0, 255)), ('gainsboro', (220, 220, 220)), ('ghostwhite', (248, 248, 255)), ('gold', (255, 215, 0)), ('goldenrod', (218, 165, 32)), ('gray', (128, 128, 128)), ('green', (0, 128, 0)), ('greenyellow', (173, 255, 47)), ('grey', (128, 128, 128)), ('honeydew', (240, 255, 240)), ('hotpink', (255, 105, 180)), ('indianred', (205, 92, 92)), ('indigo', (75, 0, 130)), ('ivory', (255, 255, 240)), ('khaki', (240, 230, 140)), ('lavender', (230, 230, 250)), ('lavenderblush', (255, 240, 245)), ('lawngreen', (124, 252, 0)), ('lemonchiffon', (255, 250, 205)), ('lightblue', (173, 216, 230)), ('lightcoral', (240, 128, 128)), ('lightcyan', (224, 255, 255)), ('lightgoldenrodyellow', (250, 250, 210)), ('lightgray', (211, 211, 211)), ('lightgreen', (144, 238, 144)), ('lightgrey', (211, 211, 211)), ('lightpink', (255, 182, 193)), ('lightsalmon', (255, 160, 122)), ('lightseagreen', (32, 178, 170)), ('lightskyblue', (135, 206, 250)), ('lightslategray', (119, 136, 153)), ('lightslategrey', (119, 136, 153)), ('lightsteelblue', (176, 196, 222)), ('lightyellow', (255, 255, 224)), ('lime', (0, 255, 0)), ('limegreen', (50, 205, 50)), ('linen', (250, 240, 230)), ('magenta', (255, 0, 255)), ('maroon', (128, 0, 0)), ('mediumaquamarine', (102, 205, 170)), ('mediumblue', (0, 0, 205)), ('mediumorchid', (186, 85, 211)), ('mediumpurple', (147, 112, 219)), ('mediumseagreen', (60, 179, 113)), ('mediumslateblue', (123, 104, 238)), ('mediumspringgreen', (0, 250, 154)), ('mediumturquoise', (72, 209, 204)), ('mediumvioletred', (199, 21, 133)), ('midnightblue', (25, 25, 112)), ('mintcream', (245, 255, 250)), ('mistyrose', (255, 228, 225)), ('moccasin', (255, 228, 181)), ('navajowhite', (255, 222, 173)), ('navy', (0, 0, 128)), ('oldlace', (253, 245, 230)), ('olive', (128, 128, 0)), ('olivedrab', (107, 142, 35)), ('orange', (255, 165, 0)), ('orangered', (255, 69, 0)), ('orchid', (218, 112, 214)), ('palegoldenrod', (238, 232, 170)), ('palegreen', (152, 251, 152)), ('paleturquoise', (175, 238, 238)), ('palevioletred', (219, 112, 147)), ('papayawhip', (255, 239, 213)), ('peachpuff', (255, 218, 185)), ('peru', (205, 133, 63)), ('pink', (255, 192, 203)), ('plum', (221, 160, 221)), ('powderblue', (176, 224, 230)), ('purple', (128, 0, 128)), ('red', (255, 0, 0)), ('rosybrown', (188, 143, 143)), ('royalblue', (65, 105, 225)), ('saddlebrown', (139, 69, 19)), ('salmon', (250, 128, 114)), ('sandybrown', (244, 164, 96)), ('seagreen', (46, 139, 87)), ('seashell', (255, 245, 238)), ('sienna', (160, 82, 45)), ('silver', (192, 192, 192)), ('skyblue', (135, 206, 235)), ('slateblue', (106, 90, 205)), ('slategray', (112, 128, 144)), ('slategrey', (112, 128, 144)), ('snow', (255, 250, 250)), ('springgreen', (0, 255, 127)), ('steelblue', (70, 130, 180)), ('tan', (210, 180, 140)), ('teal', (0, 128, 128)), ('thistle', (216, 191, 216)), ('tomato', (255, 99, 71)), ('turquoise', (64, 224, 208)), ('violet', (238, 130, 238)), ('wheat', (245, 222, 179)), ('white', (255, 255, 255)), ('whitesmoke', (245, 245, 245)), ('yellow', (255, 255, 0)), ('yellowgreen', (154, 205, 50)), ] # (r, g, b, a) in 0..1 or a string marker SPECIAL_COLOR_KEYWORDS = { 'currentcolor': 'currentColor', 'transparent': RGBA(0., 0., 0., 0.), } # RGBA namedtuples of (r, g, b, a) in 0..1 or a string marker COLOR_KEYWORDS = SPECIAL_COLOR_KEYWORDS.copy() COLOR_KEYWORDS.update( # 255 maps to 1, 0 to 0, the rest is linear. (keyword, RGBA(r / 255., g / 255., b / 255., 1.)) for keyword, (r, g, b) in itertools.chain( BASIC_COLOR_KEYWORDS, EXTENDED_COLOR_KEYWORDS)) tinycss-0.4/tinycss/css21.py0000644000175000017500000007062612766234625016032 0ustar lizelize00000000000000# coding: utf-8 """ tinycss.css21 ------------- Parser for CSS 2.1 http://www.w3.org/TR/CSS21/syndata.html :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals from itertools import chain, islice from .decoding import decode from .parsing import ( ParseError, remove_whitespace, split_on_comma, strip_whitespace, validate_any, validate_value) from .token_data import TokenList from .tokenizer import tokenize_grouped # stylesheet : [ CDO | CDC | S | statement ]*; # statement : ruleset | at-rule; # at-rule : ATKEYWORD S* any* [ block | ';' S* ]; # block : '{' S* [ any | block | ATKEYWORD S* | ';' S* ]* '}' S*; # ruleset : selector? '{' S* declaration? [ ';' S* declaration? ]* '}' S*; # selector : any+; # declaration : property S* ':' S* value; # property : IDENT; # value : [ any | block | ATKEYWORD S* ]+; # any : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING # | DELIM | URI | HASH | UNICODE-RANGE | INCLUDES # | DASHMATCH | ':' | FUNCTION S* [any|unused]* ')' # | '(' S* [any|unused]* ')' | '[' S* [any|unused]* ']' # ] S*; # unused : block | ATKEYWORD S* | ';' S* | CDO S* | CDC S*; class Stylesheet(object): """ A parsed CSS stylesheet. .. attribute:: rules A mixed list, in source order, of :class:`RuleSet` and various at-rules such as :class:`ImportRule`, :class:`MediaRule` and :class:`PageRule`. Use their :obj:`at_keyword` attribute to distinguish them. .. attribute:: errors A list of :class:`~.parsing.ParseError`. Invalid rules and declarations are ignored, with the details logged in this list. .. attribute:: encoding The character encoding that was used to decode the stylesheet from bytes, or ``None`` for Unicode stylesheets. """ def __init__(self, rules, errors, encoding): self.rules = rules self.errors = errors self.encoding = encoding def __repr__(self): return '<{0.__class__.__name__} {1} rules {2} errors>'.format( self, len(self.rules), len(self.errors)) class AtRule(object): """ An unparsed at-rule. .. attribute:: at_keyword The normalized (lower-case) at-keyword as a string. Eg: ``'@page'`` .. attribute:: head The part of the at-rule between the at-keyword and the ``{`` marking the body, or the ``;`` marking the end of an at-rule without a body. A :class:`~.token_data.TokenList`. .. attribute:: body The content of the body between ``{`` and ``}`` as a :class:`~.token_data.TokenList`, or ``None`` if there is no body (ie. if the rule ends with ``;``). The head was validated against the core grammar but **not** the body, as the body might contain declarations. In case of an error in a declaration, parsing should continue from the next declaration. The whole rule should not be ignored as it would be for an error in the head. These at-rules are expected to be parsed further before reaching the user API. """ def __init__(self, at_keyword, head, body, line, column): self.at_keyword = at_keyword self.head = TokenList(head) self.body = TokenList(body) if body is not None else body self.line = line self.column = column def __repr__(self): return ('<{0.__class__.__name__} {0.line}:{0.column} {0.at_keyword}>' .format(self)) class RuleSet(object): """A ruleset. .. attribute:: at_keyword Always ``None``. Helps to tell rulesets apart from at-rules. .. attribute:: selector The selector as a :class:`~.token_data.TokenList`. In CSS 3, this is actually called a selector group. ``rule.selector.as_css()`` gives the selector as a string. This string can be used with *cssselect*, see :ref:`selectors3`. .. attribute:: declarations The list of :class:`Declaration`, in source order. """ at_keyword = None def __init__(self, selector, declarations, line, column): self.selector = TokenList(selector) self.declarations = declarations self.line = line self.column = column def __repr__(self): return ('<{0.__class__.__name__} at {0.line}:{0.column} {1}>' .format(self, self.selector.as_css())) class Declaration(object): """A property declaration. .. attribute:: name The property name as a normalized (lower-case) string. .. attribute:: value The property value as a :class:`~.token_data.TokenList`. The value is not parsed. UAs using tinycss may only support some properties or some values and tinycss does not know which. They need to parse values themselves and ignore declarations with unknown or unsupported properties or values, and fall back on any previous declaration. :mod:`tinycss.color3` parses color values, but other values will need specific parsing/validation code. .. attribute:: priority Either the string ``'important'`` or ``None``. """ def __init__(self, name, value, priority, line, column): self.name = name self.value = TokenList(value) self.priority = priority self.line = line self.column = column def __repr__(self): priority = ' !' + self.priority if self.priority else '' return ('<{0.__class__.__name__} {0.line}:{0.column}' ' {0.name}: {1}{2}>'.format( self, self.value.as_css(), priority)) class PageRule(object): """A parsed CSS 2.1 @page rule. .. attribute:: at_keyword Always ``'@page'`` .. attribute:: selector The page selector. In CSS 2.1 this is either ``None`` (no selector), or the string ``'first'``, ``'left'`` or ``'right'`` for the pseudo class of the same name. .. attribute:: specificity Specificity of the page selector. This is a tuple of four integers, but these tuples are mostly meant to be compared to each other. .. attribute:: declarations A list of :class:`Declaration`, in source order. .. attribute:: at_rules The list of parsed at-rules inside the @page block, in source order. Always empty for CSS 2.1. """ at_keyword = '@page' def __init__(self, selector, specificity, declarations, at_rules, line, column): self.selector = selector self.specificity = specificity self.declarations = declarations self.at_rules = at_rules self.line = line self.column = column def __repr__(self): return ('<{0.__class__.__name__} {0.line}:{0.column}' ' {0.selector}>'.format(self)) class MediaRule(object): """A parsed @media rule. .. attribute:: at_keyword Always ``'@media'`` .. attribute:: media For CSS 2.1 without media queries: the media types as a list of strings. .. attribute:: rules The list :class:`RuleSet` and various at-rules inside the @media block, in source order. """ at_keyword = '@media' def __init__(self, media, rules, line, column): self.media = media self.rules = rules self.line = line self.column = column def __repr__(self): return ('<{0.__class__.__name__} {0.line}:{0.column}' ' {0.media}>'.format(self)) class ImportRule(object): """A parsed @import rule. .. attribute:: at_keyword Always ``'@import'`` .. attribute:: uri The URI to be imported, as read from the stylesheet. (URIs are not made absolute.) .. attribute:: media For CSS 2.1 without media queries: the media types as a list of strings. This attribute is explicitly ``['all']`` if the media was omitted in the source. """ at_keyword = '@import' def __init__(self, uri, media, line, column): self.uri = uri self.media = media self.line = line self.column = column def __repr__(self): return ('<{0.__class__.__name__} {0.line}:{0.column}' ' {0.uri}>'.format(self)) def _remove_at_charset(tokens): """Remove any valid @charset at the beggining of a token stream. :param tokens: An iterable of tokens :returns: A possibly truncated iterable of tokens """ tokens = iter(tokens) header = list(islice(tokens, 4)) if [t.type for t in header] == ['ATKEYWORD', 'S', 'STRING', ';']: atkw, space, string, semicolon = header if ((atkw.value, space.value) == ('@charset', ' ') and string.as_css()[0] == '"'): # Found a valid @charset rule, only keep what’s after it. return tokens return chain(header, tokens) class CSS21Parser(object): """Parser for CSS 2.1 This parser supports the core CSS syntax as well as @import, @media, @page and !important. Note that property values are still not parsed, as UAs using this parser may only support some properties or some values. Currently the parser holds no state. It being a class only allows subclassing and overriding its methods. """ # User API: def parse_stylesheet_file(self, css_file, protocol_encoding=None, linking_encoding=None, document_encoding=None): """Parse a stylesheet from a file or filename. Character encoding-related parameters and behavior are the same as in :meth:`parse_stylesheet_bytes`. :param css_file: Either a file (any object with a :meth:`~file.read` method) or a filename. :return: A :class:`Stylesheet`. """ if hasattr(css_file, 'read'): css_bytes = css_file.read() else: with open(css_file, 'rb') as fd: css_bytes = fd.read() return self.parse_stylesheet_bytes(css_bytes, protocol_encoding, linking_encoding, document_encoding) def parse_stylesheet_bytes(self, css_bytes, protocol_encoding=None, linking_encoding=None, document_encoding=None): """Parse a stylesheet from a byte string. The character encoding is determined from the passed metadata and the ``@charset`` rule in the stylesheet (if any). If no encoding information is available or decoding fails, decoding defaults to UTF-8 and then fall back on ISO-8859-1. :param css_bytes: A CSS stylesheet as a byte string. :param protocol_encoding: The "charset" parameter of a "Content-Type" HTTP header (if any), or similar metadata for other protocols. :param linking_encoding: ```` or other metadata from the linking mechanism (if any) :param document_encoding: Encoding of the referring style sheet or document (if any) :return: A :class:`Stylesheet`. """ css_unicode, encoding = decode(css_bytes, protocol_encoding, linking_encoding, document_encoding) return self.parse_stylesheet(css_unicode, encoding=encoding) def parse_stylesheet(self, css_unicode, encoding=None): """Parse a stylesheet from an Unicode string. :param css_unicode: A CSS stylesheet as an unicode string. :param encoding: The character encoding used to decode the stylesheet from bytes, if any. :return: A :class:`Stylesheet`. """ tokens = tokenize_grouped(css_unicode) if encoding: tokens = _remove_at_charset(tokens) rules, errors = self.parse_rules(tokens, context='stylesheet') return Stylesheet(rules, errors, encoding) def parse_style_attr(self, css_source): """Parse a "style" attribute (eg. of an HTML element). This method only accepts Unicode as the source (HTML) document is supposed to handle the character encoding. :param css_source: The attribute value, as an unicode string. :return: A tuple of the list of valid :class:`Declaration` and a list of :class:`~.parsing.ParseError`. """ return self.parse_declaration_list(tokenize_grouped(css_source)) # API for subclasses: def parse_rules(self, tokens, context): """Parse a sequence of rules (rulesets and at-rules). :param tokens: An iterable of tokens. :param context: Either ``'stylesheet'`` or an at-keyword such as ``'@media'``. (Most at-rules are only allowed in some contexts.) :return: A tuple of a list of parsed rules and a list of :class:`~.parsing.ParseError`. """ rules = [] errors = [] tokens = iter(tokens) for token in tokens: if token.type not in ('S', 'CDO', 'CDC'): try: if token.type == 'ATKEYWORD': rule = self.read_at_rule(token, tokens) result = self.parse_at_rule( rule, rules, errors, context) rules.append(result) else: rule, rule_errors = self.parse_ruleset(token, tokens) rules.append(rule) errors.extend(rule_errors) except ParseError as exc: errors.append(exc) # Skip the entire rule return rules, errors def read_at_rule(self, at_keyword_token, tokens): """Read an at-rule from a token stream. :param at_keyword_token: The ATKEYWORD token that starts this at-rule You may have read it already to distinguish the rule from a ruleset. :param tokens: An iterator of subsequent tokens. Will be consumed just enough for one at-rule. :return: An unparsed :class:`AtRule`. :raises: :class:`~.parsing.ParseError` if the head is invalid for the core grammar. The body is **not** validated. See :class:`AtRule`. """ # CSS syntax is case-insensitive at_keyword = at_keyword_token.value.lower() head = [] # For the ParseError in case `tokens` is empty: token = at_keyword_token for token in tokens: if token.type in '{;': break # Ignore white space just after the at-keyword. else: head.append(token) # On unexpected end of stylesheet, pretend that a ';' was there head = strip_whitespace(head) for head_token in head: validate_any(head_token, 'at-rule head') body = token.content if token.type == '{' else None return AtRule(at_keyword, head, body, at_keyword_token.line, at_keyword_token.column) def parse_at_rule(self, rule, previous_rules, errors, context): """Parse an at-rule. Subclasses that override this method must use ``super()`` and pass its return value for at-rules they do not know. In CSS 2.1, this method handles @charset, @import, @media and @page rules. :param rule: An unparsed :class:`AtRule`. :param previous_rules: The list of at-rules and rulesets that have been parsed so far in this context. This list can be used to decide if the current rule is valid. (For example, @import rules are only allowed before anything but a @charset rule.) :param context: Either ``'stylesheet'`` or an at-keyword such as ``'@media'``. (Most at-rules are only allowed in some contexts.) :raises: :class:`~.parsing.ParseError` if the rule is invalid. :return: A parsed at-rule """ if rule.at_keyword == '@page': if context != 'stylesheet': raise ParseError(rule, '@page rule not allowed in ' + context) selector, specificity = self.parse_page_selector(rule.head) if rule.body is None: raise ParseError( rule, 'invalid {0} rule: missing block'.format( rule.at_keyword)) declarations, at_rules, rule_errors = \ self.parse_declarations_and_at_rules(rule.body, '@page') errors.extend(rule_errors) return PageRule(selector, specificity, declarations, at_rules, rule.line, rule.column) elif rule.at_keyword == '@media': if context != 'stylesheet': raise ParseError(rule, '@media rule not allowed in ' + context) if not rule.head: raise ParseError(rule, 'expected media types for @media') media = self.parse_media(rule.head) if rule.body is None: raise ParseError( rule, 'invalid {0} rule: missing block'.format( rule.at_keyword)) rules, rule_errors = self.parse_rules(rule.body, '@media') errors.extend(rule_errors) return MediaRule(media, rules, rule.line, rule.column) elif rule.at_keyword == '@import': if context != 'stylesheet': raise ParseError( rule, '@import rule not allowed in ' + context) for previous_rule in previous_rules: if previous_rule.at_keyword not in ('@charset', '@import'): if previous_rule.at_keyword: type_ = 'an {0} rule'.format(previous_rule.at_keyword) else: type_ = 'a ruleset' raise ParseError( previous_rule, '@import rule not allowed after ' + type_) head = rule.head if not head: raise ParseError( rule, 'expected URI or STRING for @import rule') if head[0].type not in ('URI', 'STRING'): raise ParseError( rule, 'expected URI or STRING for @import rule, got ' + head[0].type) uri = head[0].value media = self.parse_media(strip_whitespace(head[1:])) if rule.body is not None: # The position of the ';' token would be best, but we don’t # have it anymore here. raise ParseError(head[-1], "expected ';', got a block") return ImportRule(uri, media, rule.line, rule.column) elif rule.at_keyword == '@charset': raise ParseError(rule, 'mis-placed or malformed @charset rule') else: raise ParseError( rule, 'unknown at-rule in {0} context: {1}'.format( context, rule.at_keyword)) def parse_media(self, tokens): """For CSS 2.1, parse a list of media types. Media Queries are expected to override this. :param tokens: A list of tokens :raises: :class:`~.parsing.ParseError` on invalid media types/queries :returns: For CSS 2.1, a list of media types as strings """ if not tokens: return ['all'] media_types = [] for part in split_on_comma(remove_whitespace(tokens)): types = [token.type for token in part] if types == ['IDENT']: media_types.append(part[0].value) else: raise ParseError( tokens[0], 'expected a media type' + ((', got ' + ', '.join(types)) if types else '')) return media_types def parse_page_selector(self, tokens): """Parse an @page selector. :param tokens: An iterable of token, typically from the ``head`` attribute of an unparsed :class:`AtRule`. :returns: A page selector. For CSS 2.1, this is ``'first'``, ``'left'``, ``'right'`` or ``None``. :raises: :class:`~.parsing.ParseError` on invalid selectors """ if not tokens: return None, (0, 0) if (len(tokens) == 2 and tokens[0].type == ':' and tokens[1].type == 'IDENT'): pseudo_class = tokens[1].value specificity = { 'first': (1, 0), 'left': (0, 1), 'right': (0, 1), }.get(pseudo_class) if specificity: return pseudo_class, specificity raise ParseError(tokens[0], 'invalid @page selector') def parse_declarations_and_at_rules(self, tokens, context): """Parse a mixed list of declarations and at rules, as found eg. in the body of an @page rule. Note that to add supported at-rules inside @page, :class:`~.page3.CSSPage3Parser` extends :meth:`parse_at_rule`, not this method. :param tokens: An iterable of token, typically from the ``body`` attribute of an unparsed :class:`AtRule`. :param context: An at-keyword such as ``'@page'``. (Most at-rules are only allowed in some contexts.) :returns: A tuple of: * A list of :class:`Declaration` * A list of parsed at-rules (empty for CSS 2.1) * A list of :class:`~.parsing.ParseError` """ at_rules = [] declarations = [] errors = [] tokens = iter(tokens) for token in tokens: if token.type == 'ATKEYWORD': try: rule = self.read_at_rule(token, tokens) result = self.parse_at_rule( rule, at_rules, errors, context) at_rules.append(result) except ParseError as err: errors.append(err) elif token.type != 'S': declaration_tokens = [] while token and token.type != ';': declaration_tokens.append(token) token = next(tokens, None) if declaration_tokens: try: declarations.append( self.parse_declaration(declaration_tokens)) except ParseError as err: errors.append(err) return declarations, at_rules, errors def parse_ruleset(self, first_token, tokens): """Parse a ruleset: a selector followed by declaration block. :param first_token: The first token of the ruleset (probably of the selector). You may have read it already to distinguish the rule from an at-rule. :param tokens: an iterator of subsequent tokens. Will be consumed just enough for one ruleset. :return: a tuple of a :class:`RuleSet` and an error list. The errors are recovered :class:`~.parsing.ParseError` in declarations. (Parsing continues from the next declaration on such errors.) :raises: :class:`~.parsing.ParseError` if the selector is invalid for the core grammar. Note a that a selector can be valid for the core grammar but not for CSS 2.1 or another level. """ selector = [] for token in chain([first_token], tokens): if token.type == '{': # Parse/validate once we’ve read the whole rule selector = strip_whitespace(selector) if not selector: raise ParseError(first_token, 'empty selector') for selector_token in selector: validate_any(selector_token, 'selector') declarations, errors = self.parse_declaration_list( token.content) ruleset = RuleSet(selector, declarations, first_token.line, first_token.column) return ruleset, errors else: selector.append(token) raise ParseError(token, 'no declaration block found for ruleset') def parse_declaration_list(self, tokens): """Parse a ``;`` separated declaration list. You may want to use :meth:`parse_declarations_and_at_rules` (or some other method that uses :func:`parse_declaration` directly) instead if you have not just declarations in the same context. :param tokens: an iterable of tokens. Should stop at (before) the end of the block, as marked by ``}``. :return: a tuple of the list of valid :class:`Declaration` and a list of :class:`~.parsing.ParseError` """ # split at ';' parts = [] this_part = [] for token in tokens: if token.type == ';': parts.append(this_part) this_part = [] else: this_part.append(token) parts.append(this_part) declarations = [] errors = [] for tokens in parts: tokens = strip_whitespace(tokens) if tokens: try: declarations.append(self.parse_declaration(tokens)) except ParseError as exc: errors.append(exc) # Skip the entire declaration return declarations, errors def parse_declaration(self, tokens): """Parse a single declaration. :param tokens: an iterable of at least one token. Should stop at (before) the end of the declaration, as marked by a ``;`` or ``}``. Empty declarations (ie. consecutive ``;`` with only white space in-between) should be skipped earlier and not passed to this method. :returns: a :class:`Declaration` :raises: :class:`~.parsing.ParseError` if the tokens do not match the 'declaration' production of the core grammar. """ tokens = iter(tokens) name_token = next(tokens) # assume there is at least one if name_token.type == 'IDENT': # CSS syntax is case-insensitive property_name = name_token.value.lower() else: raise ParseError( name_token, 'expected a property name, got {0}'.format( name_token.type)) token = name_token # In case ``tokens`` is now empty for token in tokens: if token.type == ':': break elif token.type != 'S': raise ParseError( token, "expected ':', got {0}".format(token.type)) else: raise ParseError(token, "expected ':'") value = strip_whitespace(list(tokens)) if not value: raise ParseError(token, 'expected a property value') validate_value(value) value, priority = self.parse_value_priority(value) return Declaration( property_name, value, priority, name_token.line, name_token.column) def parse_value_priority(self, tokens): """Separate any ``!important`` marker at the end of a property value. :param tokens: A list of tokens for the property value. :returns: A tuple of the actual property value (a list of tokens) and the :attr:`~Declaration.priority`. """ value = list(tokens) # Walk the token list from the end token = value.pop() if token.type == 'IDENT' and token.value.lower() == 'important': while value: token = value.pop() if token.type == 'DELIM' and token.value == '!': # Skip any white space before the '!' while value and value[-1].type == 'S': value.pop() if not value: raise ParseError( token, 'expected a value before !important') return value, 'important' # Skip white space between '!' and 'important' elif token.type != 'S': break return tokens, None tinycss-0.4/tinycss/decoding.py0000644000175000017500000002172612766235104016641 0ustar lizelize00000000000000# coding: utf-8 """ tinycss.decoding ---------------- Decoding stylesheets from bytes to Unicode. http://www.w3.org/TR/CSS21/syndata.html#charset :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals import operator import re from binascii import unhexlify __all__ = ['decode'] # Everything else is implementation detail def decode(css_bytes, protocol_encoding=None, linking_encoding=None, document_encoding=None): """ Determine the character encoding from the passed metadata and the ``@charset`` rule in the stylesheet (if any); and decode accordingly. If no encoding information is available or decoding fails, decoding defaults to UTF-8 and then fall back on ISO-8859-1. :param css_bytes: a CSS stylesheet as a byte string :param protocol_encoding: The "charset" parameter of a "Content-Type" HTTP header (if any), or similar metadata for other protocols. :param linking_encoding: ```` or other metadata from the linking mechanism (if any) :param document_encoding: Encoding of the referring style sheet or document (if any) :return: A tuple of an Unicode string, with any BOM removed, and the encoding that was used. """ if protocol_encoding: css_unicode = try_encoding(css_bytes, protocol_encoding) if css_unicode is not None: return css_unicode, protocol_encoding for encoding, pattern in ENCODING_MAGIC_NUMBERS: match = pattern(css_bytes) if match: has_at_charset = isinstance(encoding, tuple) if has_at_charset: extract, endianness = encoding encoding = extract(match.group(1)) # Get an ASCII-only unicode value. # This is the only thing that works on both Python 2 and 3 # for bytes.decode() # Non-ASCII encoding names are invalid anyway, # but make sure they stay invalid. encoding = encoding.decode('ascii', 'replace') encoding = encoding.replace('\ufffd', '?') if encoding.replace('-', '').replace('_', '').lower() in [ 'utf16', 'utf32']: encoding += endianness encoding = encoding.encode('ascii', 'replace').decode('ascii') css_unicode = try_encoding(css_bytes, encoding) if css_unicode and not (has_at_charset and not css_unicode.startswith('@charset "')): return css_unicode, encoding break for encoding in [linking_encoding, document_encoding]: if encoding: css_unicode = try_encoding(css_bytes, encoding) if css_unicode is not None: return css_unicode, encoding css_unicode = try_encoding(css_bytes, 'UTF-8') if css_unicode is not None: return css_unicode, 'UTF-8' return try_encoding(css_bytes, 'ISO-8859-1', fallback=False), 'ISO-8859-1' def try_encoding(css_bytes, encoding, fallback=True): if fallback: try: css_unicode = css_bytes.decode(encoding) # LookupError means unknown encoding except (UnicodeDecodeError, LookupError): return None else: css_unicode = css_bytes.decode(encoding) if css_unicode and css_unicode[0] == '\ufeff': # Remove any Byte Order Mark css_unicode = css_unicode[1:] return css_unicode def hex2re(hex_data): return re.escape(unhexlify(hex_data.replace(' ', '').encode('ascii'))) class Slicer(object): """Slice()[start:stop:end] == slice(start, stop, end)""" def __getitem__(self, slice_): return operator.itemgetter(slice_) Slice = Slicer() # List of (bom_size, encoding, pattern) # bom_size is in bytes and can be zero # encoding is a string or (slice_, endianness) for "as specified" # slice_ is a slice object.How to extract the specified ENCODING_MAGIC_NUMBERS = [ ((Slice[:], ''), re.compile( hex2re('EF BB BF 40 63 68 61 72 73 65 74 20 22') + b'([^\x22]*?)' + hex2re('22 3B')).match), ('UTF-8', re.compile( hex2re('EF BB BF')).match), ((Slice[:], ''), re.compile( hex2re('40 63 68 61 72 73 65 74 20 22') + b'([^\x22]*?)' + hex2re('22 3B')).match), ((Slice[1::2], '-BE'), re.compile( hex2re('FE FF 00 40 00 63 00 68 00 61 00 72 00 73 00 65 00' '74 00 20 00 22') + b'((\x00[^\x22])*?)' + hex2re('00 22 00 3B')).match), ((Slice[1::2], '-BE'), re.compile( hex2re('00 40 00 63 00 68 00 61 00 72 00 73 00 65 00 74 00' '20 00 22') + b'((\x00[^\x22])*?)' + hex2re('00 22 00 3B')).match), ((Slice[::2], '-LE'), re.compile( hex2re('FF FE 40 00 63 00 68 00 61 00 72 00 73 00 65 00 74' '00 20 00 22 00') + b'(([^\x22]\x00)*?)' + hex2re('22 00 3B 00')).match), ((Slice[::2], '-LE'), re.compile( hex2re('40 00 63 00 68 00 61 00 72 00 73 00 65 00 74 00 20' '00 22 00') + b'(([^\x22]\x00)*?)' + hex2re('22 00 3B 00')).match), ((Slice[3::4], '-BE'), re.compile( hex2re('00 00 FE FF 00 00 00 40 00 00 00 63 00 00 00 68 00' '00 00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00' '00 74 00 00 00 20 00 00 00 22') + b'((\x00\x00\x00[^\x22])*?)' + hex2re('00 00 00 22 00 00 00 3B')).match), ((Slice[3::4], '-BE'), re.compile( hex2re('00 00 00 40 00 00 00 63 00 00 00 68 00 00 00 61 00' '00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00' '00 20 00 00 00 22') + b'((\x00\x00\x00[^\x22])*?)' + hex2re('00 00 00 22 00 00 00 3B')).match), # Python does not support 2143 or 3412 endianness, AFAIK. # I guess we could fix it up ourselves but meh. Patches welcome. # ((Slice[2::4], '-2143'), re.compile( # hex2re('00 00 FF FE 00 00 40 00 00 00 63 00 00 00 68 00 00' # '00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00' # '74 00 00 00 20 00 00 00 22 00') + # b'((\x00\x00[^\x22]\x00)*?)' + # hex2re('00 00 22 00 00 00 3B 00')).match), # ((Slice[2::4], '-2143'), re.compile( # hex2re('00 00 40 00 00 00 63 00 00 00 68 00 00 00 61 00 00' # '00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00' # '20 00 00 00 22 00') + # b'((\x00\x00[^\x22]\x00)*?)' + # hex2re('00 00 22 00 00 00 3B 00')).match), # ((Slice[1::4], '-3412'), re.compile( # hex2re('FE FF 00 00 00 40 00 00 00 63 00 00 00 68 00 00 00' # '61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74' # '00 00 00 20 00 00 00 22 00 00') + # b'((\x00[^\x22]\x00\x00)*?)' + # hex2re('00 22 00 00 00 3B 00 00')).match), # ((Slice[1::4], '-3412'), re.compile( # hex2re('00 40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00' # '72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20' # '00 00 00 22 00 00') + # b'((\x00[^\x22]\x00\x00)*?)' + # hex2re('00 22 00 00 00 3B 00 00')).match), ((Slice[::4], '-LE'), re.compile( hex2re('FF FE 00 00 40 00 00 00 63 00 00 00 68 00 00 00 61' '00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00' '00 00 20 00 00 00 22 00 00 00') + b'(([^\x22]\x00\x00\x00)*?)' + hex2re('22 00 00 00 3B 00 00 00')).match), ((Slice[::4], '-LE'), re.compile( hex2re('40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00 72' '00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20 00' '00 00 22 00 00 00') + b'(([^\x22]\x00\x00\x00)*?)' + hex2re('22 00 00 00 3B 00 00 00')).match), ('UTF-32-BE', re.compile( hex2re('00 00 FE FF')).match), ('UTF-32-LE', re.compile( hex2re('FF FE 00 00')).match), # ('UTF-32-2143', re.compile( # hex2re('00 00 FF FE')).match), # ('UTF-32-3412', re.compile( # hex2re('FE FF 00 00')).match), ('UTF-16-BE', re.compile( hex2re('FE FF')).match), ('UTF-16-LE', re.compile( hex2re('FF FE')).match), # Some of there are supported by Python, but I didn’t bother. # You know the story with patches ... # # as specified, transcoded from EBCDIC to ASCII # ('as_specified-EBCDIC', re.compile( # hex2re('7C 83 88 81 99 A2 85 A3 40 7F') # + b'([^\x7F]*?)' # + hex2re('7F 5E')).match), # # as specified, transcoded from IBM1026 to ASCII # ('as_specified-IBM1026', re.compile( # hex2re('AE 83 88 81 99 A2 85 A3 40 FC') # + b'([^\xFC]*?)' # + hex2re('FC 5E')).match), # # as specified, transcoded from GSM 03.38 to ASCII # ('as_specified-GSM_03.38', re.compile( # hex2re('00 63 68 61 72 73 65 74 20 22') # + b'([^\x22]*?)' # + hex2re('22 3B')).match), ] tinycss-0.4/tinycss/fonts3.py0000644000175000017500000001320712771240243016270 0ustar lizelize00000000000000# coding: utf-8 """ tinycss.colors3 --------------- Parser for CSS 3 Fonts syntax: https://www.w3.org/TR/css-fonts-3/ Adds support for font-face and font-feature-values rules. :copyright: (c) 2016 by Kozea. :license: BSD, see LICENSE for more details. """ from __future__ import division, unicode_literals from .css21 import CSS21Parser, ParseError class FontFaceRule(object): """A parsed at-rule for font faces. .. attribute:: at_keyword Always ``'@font-face'``. .. attribute:: declarations A list of :class:`~.css21.Declaration` objects. .. attribute:: line Source line where this was read. .. attribute:: column Source column where this was read. """ def __init__(self, at_keyword, declarations, line, column): assert at_keyword == '@font-face' self.at_keyword = at_keyword self.declarations = declarations self.line = line self.column = column class FontFeatureValuesRule(object): """A parsed at-rule for font feature values. .. attribute:: at_keyword Always ``'@font-feature-values'``. .. attribute:: line Source line where this was read. .. attribute:: column Source column where this was read. .. attribute:: at_rules The list of parsed at-rules inside the @font-feature-values block, in source order. .. attribute:: family_names A list of strings representing font families. """ def __init__(self, at_keyword, at_rules, family_names, line, column): assert at_keyword == '@font-feature-values' self.at_keyword = at_keyword self.family_names = family_names self.at_rules = at_rules self.line = line self.column = column class FontFeatureRule(object): """A parsed at-rule for font features. .. attribute:: at_keyword One of the 16 following strings: * ``@stylistic`` * ``@styleset`` * ``@character-variant`` * ``@swash`` * ``@ornaments`` * ``@annotation`` .. attribute:: declarations A list of :class:`~.css21.Declaration` objects. .. attribute:: line Source line where this was read. .. attribute:: column Source column where this was read. """ def __init__(self, at_keyword, declarations, line, column): self.at_keyword = at_keyword self.declarations = declarations self.line = line self.column = column class CSSFonts3Parser(CSS21Parser): """Extend :class:`~.css21.CSS21Parser` for `CSS 3 Fonts`_ syntax. .. _CSS 3 Fonts: https://www.w3.org/TR/css-fonts-3/ """ FONT_FEATURE_VALUES_AT_KEYWORDS = [ '@stylistic', '@styleset', '@character-variant', '@swash', '@ornaments', '@annotation', ] def parse_at_rule(self, rule, previous_rules, errors, context): if rule.at_keyword == '@font-face': if rule.head: raise ParseError( rule.head[0], 'unexpected {0} token in {1} rule header'.format( rule.head[0].type, rule.at_keyword)) declarations, body_errors = self.parse_declaration_list(rule.body) errors.extend(body_errors) return FontFaceRule( rule.at_keyword, declarations, rule.line, rule.column) elif rule.at_keyword == '@font-feature-values': family_names = tuple( self.parse_font_feature_values_family_names(rule.head)) at_rules, body_errors = ( self.parse_rules(rule.body or [], '@font-feature-values')) errors.extend(body_errors) return FontFeatureValuesRule( rule.at_keyword, at_rules, family_names, rule.line, rule.column) elif rule.at_keyword in self.FONT_FEATURE_VALUES_AT_KEYWORDS: if context != '@font-feature-values': raise ParseError( rule, '{0} rule not allowed in {1}'.format( rule.at_keyword, context)) declarations, body_errors = self.parse_declaration_list(rule.body) errors.extend(body_errors) return FontFeatureRule( rule.at_keyword, declarations, rule.line, rule.column) return super(CSSFonts3Parser, self).parse_at_rule( rule, previous_rules, errors, context) def parse_font_feature_values_family_names(self, tokens): """Parse an @font-feature-values selector. :param tokens: An iterable of token, typically from the ``head`` attribute of an unparsed :class:`AtRule`. :returns: A generator of strings representing font families. :raises: :class:`~.parsing.ParseError` on invalid selectors """ family = '' current_string = False for token in tokens: if token.type == 'DELIM' and token.value == ',' and family: yield family family = '' current_string = False elif token.type == 'STRING' and not family and ( current_string is False): family = token.value current_string = True elif token.type == 'IDENT' and not current_string: if family: family += ' ' family += token.value elif token.type != 'S': family = '' break if family: yield family else: raise ParseError(token, 'invalid @font-feature-values selector') tinycss-0.4/tinycss/page3.py0000644000175000017500000001177612766235570016077 0ustar lizelize00000000000000# coding: utf-8 """ tinycss.page3 ------------------ Support for CSS 3 Paged Media syntax: http://dev.w3.org/csswg/css3-page/ Adds support for named page selectors and margin rules. :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import division, unicode_literals from .css21 import CSS21Parser, ParseError class MarginRule(object): """A parsed at-rule for margin box. .. attribute:: at_keyword One of the 16 following strings: * ``@top-left-corner`` * ``@top-left`` * ``@top-center`` * ``@top-right`` * ``@top-right-corner`` * ``@bottom-left-corner`` * ``@bottom-left`` * ``@bottom-center`` * ``@bottom-right`` * ``@bottom-right-corner`` * ``@left-top`` * ``@left-middle`` * ``@left-bottom`` * ``@right-top`` * ``@right-middle`` * ``@right-bottom`` .. attribute:: declarations A list of :class:`~.css21.Declaration` objects. .. attribute:: line Source line where this was read. .. attribute:: column Source column where this was read. """ def __init__(self, at_keyword, declarations, line, column): self.at_keyword = at_keyword self.declarations = declarations self.line = line self.column = column class CSSPage3Parser(CSS21Parser): """Extend :class:`~.css21.CSS21Parser` for `CSS 3 Paged Media`_ syntax. .. _CSS 3 Paged Media: http://dev.w3.org/csswg/css3-page/ Compared to CSS 2.1, the ``at_rules`` and ``selector`` attributes of :class:`~.css21.PageRule` objects are modified: * ``at_rules`` is not always empty, it is a list of :class:`MarginRule` objects. * ``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 selectors | +==========================+========================+ | .. code-block:: css | .. code-block:: python | | | | | @page {} | (None, None) | | @page :first {} | (None, 'first') | | @page chapter {} | ('chapter', None) | | @page table:right {} | ('table', 'right') | +--------------------------+------------------------+ """ PAGE_MARGIN_AT_KEYWORDS = [ '@top-left-corner', '@top-left', '@top-center', '@top-right', '@top-right-corner', '@bottom-left-corner', '@bottom-left', '@bottom-center', '@bottom-right', '@bottom-right-corner', '@left-top', '@left-middle', '@left-bottom', '@right-top', '@right-middle', '@right-bottom', ] def parse_at_rule(self, rule, previous_rules, errors, context): if rule.at_keyword in self.PAGE_MARGIN_AT_KEYWORDS: if context != '@page': raise ParseError( rule, '{0} rule not allowed in {1}'.format( rule.at_keyword, context)) if rule.head: raise ParseError( rule.head[0], 'unexpected {0} token in {1} rule header'.format( rule.head[0].type, rule.at_keyword)) declarations, body_errors = self.parse_declaration_list(rule.body) errors.extend(body_errors) return MarginRule( rule.at_keyword, declarations, rule.line, rule.column) return super(CSSPage3Parser, self).parse_at_rule( rule, previous_rules, errors, context) def parse_page_selector(self, head): """Parse an @page selector. :param head: The ``head`` attribute of an unparsed :class:`AtRule`. :returns: A page selector. For CSS 2.1, this is 'first', 'left', 'right' or None. 'blank' is added by GCPM. :raises: :class`~parsing.ParseError` on invalid selectors """ if not head: return (None, None), (0, 0, 0) if head[0].type == 'IDENT': name = head.pop(0).value while head and head[0].type == 'S': head.pop(0) if not head: return (name, None), (1, 0, 0) name_specificity = (1,) else: name = None name_specificity = (0,) if (len(head) == 2 and head[0].type == ':' and head[1].type == 'IDENT'): pseudo_class = head[1].value specificity = { 'first': (1, 0), 'blank': (1, 0), 'left': (0, 1), 'right': (0, 1), }.get(pseudo_class) if specificity: return (name, pseudo_class), (name_specificity + specificity) raise ParseError(head[0], 'invalid @page selector') tinycss-0.4/tinycss/parsing.py0000644000175000017500000001062612766235437016536 0ustar lizelize00000000000000# coding: utf-8 """ tinycss.parsing --------------- Utilities for parsing lists of tokens. :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals # TODO: unit tests def split_on_comma(tokens): """Split a list of tokens on commas, ie ``,`` DELIM tokens. Only "top-level" comma tokens are splitting points, not commas inside a function or other :class:`ContainerToken`. :param tokens: An iterable of :class:`~.token_data.Token` or :class:`~.token_data.ContainerToken`. :returns: A list of lists of tokens """ parts = [] this_part = [] for token in tokens: if token.type == 'DELIM' and token.value == ',': parts.append(this_part) this_part = [] else: this_part.append(token) parts.append(this_part) return parts def strip_whitespace(tokens): """Remove whitespace at the beggining and end of a token list. Whitespace tokens in-between other tokens in the list are preserved. :param tokens: A list of :class:`~.token_data.Token` or :class:`~.token_data.ContainerToken`. :return: A new sub-sequence of the list. """ for i, token in enumerate(tokens): if token.type != 'S': break else: return [] # only whitespace tokens = tokens[i:] while tokens and tokens[-1].type == 'S': tokens.pop() return tokens def remove_whitespace(tokens): """Remove any top-level whitespace in a token list. Whitespace tokens inside recursive :class:`~.token_data.ContainerToken` are preserved. :param tokens: A list of :class:`~.token_data.Token` or :class:`~.token_data.ContainerToken`. :return: A new sub-sequence of the list. """ return [token for token in tokens if token.type != 'S'] def validate_value(tokens): """Validate a property value. :param tokens: an iterable of tokens :raises: :class:`ParseError` if there is any invalid token for the 'value' production of the core grammar. """ for token in tokens: type_ = token.type if type_ == '{': validate_block(token.content, 'property value') else: validate_any(token, 'property value') def validate_block(tokens, context): """ :raises: :class:`ParseError` if there is any invalid token for the 'block' production of the core grammar. :param tokens: an iterable of tokens :param context: a string for the 'unexpected in ...' message """ for token in tokens: type_ = token.type if type_ == '{': validate_block(token.content, context) elif type_ not in (';', 'ATKEYWORD'): validate_any(token, context) def validate_any(token, context): """ :raises: :class:`ParseError` if this is an invalid token for the 'any' production of the core grammar. :param token: a single token :param context: a string for the 'unexpected in ...' message """ type_ = token.type if type_ in ('FUNCTION', '(', '['): for token in token.content: validate_any(token, type_) elif type_ not in ('S', 'IDENT', 'DIMENSION', 'PERCENTAGE', 'NUMBER', 'INTEGER', 'URI', 'DELIM', 'STRING', 'HASH', ':', 'UNICODE-RANGE'): if type_ in ('}', ')', ']'): adjective = 'unmatched' else: adjective = 'unexpected' raise ParseError( token, '{0} {1} token in {2}'.format(adjective, type_, context)) class ParseError(ValueError): """Details about a CSS syntax error. Usually indicates that something (a rule or a declaration) was ignored and will not appear as a parsed object. This exception is typically logged in a list rather than being propagated to the user API. .. attribute:: line Source line where the error occured. .. attribute:: column Column in the source line where the error occured. .. attribute:: reason What happend (a string). """ def __init__(self, subject, reason): self.line = subject.line self.column = subject.column self.reason = reason super(ParseError, self).__init__( 'Parse error at {0.line}:{0.column}, {0.reason}'.format(self)) tinycss-0.4/tinycss/speedups.c0000644000175000017500000113224112766024776016516 0ustar lizelize00000000000000/* Generated by Cython 0.24.1 */ #define PY_SSIZE_T_CLEAN #include "Python.h" #ifndef Py_PYTHON_H #error Python headers needed to compile C extensions, please install development version of Python. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000) #error Cython requires Python 2.6+ or Python 3.2+. #else #define CYTHON_ABI "0_24_1" #include #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) #endif #if !defined(WIN32) && !defined(MS_WINDOWS) #ifndef __stdcall #define __stdcall #endif #ifndef __cdecl #define __cdecl #endif #ifndef __fastcall #define __fastcall #endif #endif #ifndef DL_IMPORT #define DL_IMPORT(t) t #endif #ifndef DL_EXPORT #define DL_EXPORT(t) t #endif #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif #ifndef Py_HUGE_VAL #define Py_HUGE_VAL HUGE_VAL #endif #ifdef PYPY_VERSION #define CYTHON_COMPILING_IN_PYPY 1 #define CYTHON_COMPILING_IN_CPYTHON 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #endif #if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000 #define CYTHON_USE_PYLONG_INTERNALS 1 #endif #if CYTHON_USE_PYLONG_INTERNALS #include "longintrepr.h" #undef SHIFT #undef BASE #undef MASK #endif #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) #define Py_OptimizeFlag 0 #endif #define __PYX_BUILD_PY_SSIZE_T "n" #define CYTHON_FORMAT_SSIZE_T "z" #if PY_MAJOR_VERSION < 3 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyType_Type #endif #ifndef Py_TPFLAGS_CHECKTYPES #define Py_TPFLAGS_CHECKTYPES 0 #endif #ifndef Py_TPFLAGS_HAVE_INDEX #define Py_TPFLAGS_HAVE_INDEX 0 #endif #ifndef Py_TPFLAGS_HAVE_NEWBUFFER #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #endif #ifndef Py_TPFLAGS_HAVE_FINALIZE #define Py_TPFLAGS_HAVE_FINALIZE 0 #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ 0 : _PyUnicode_Ready((PyObject *)(op))) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) #else #define CYTHON_PEP393_ENABLED 0 #define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) #endif #if CYTHON_COMPILING_IN_PYPY #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) #else #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) #endif #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) #define PyObject_Malloc(s) PyMem_Malloc(s) #define PyObject_Free(p) PyMem_Free(p) #define PyObject_Realloc(p) PyMem_Realloc(p) #endif #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) #else #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) #endif #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) #define PyObject_ASCII(o) PyObject_Repr(o) #endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type #define PyStringObject PyUnicodeObject #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) #else #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject #define PyInt_Type PyLong_Type #define PyInt_Check(op) PyLong_Check(op) #define PyInt_CheckExact(op) PyLong_CheckExact(op) #define PyInt_FromString PyLong_FromString #define PyInt_FromUnicode PyLong_FromUnicode #define PyInt_FromLong PyLong_FromLong #define PyInt_FromSize_t PyLong_FromSize_t #define PyInt_FromSsize_t PyLong_FromSsize_t #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_AsSsize_t PyLong_AsSsize_t #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask #define PyNumber_Int PyNumber_Long #endif #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY #ifndef PyUnicode_InternFromString #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) #endif #endif #if PY_VERSION_HEX < 0x030200A4 typedef long Py_hash_t; #define __Pyx_PyInt_FromHash_t PyInt_FromLong #define __Pyx_PyInt_AsHash_t PyInt_AsLong #else #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) #else #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #endif #if PY_VERSION_HEX >= 0x030500B1 #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) #elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 typedef struct { unaryfunc am_await; unaryfunc am_aiter; unaryfunc am_anext; } __Pyx_PyAsyncMethodsStruct; #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) #else #define __Pyx_PyType_AsAsync(obj) NULL #endif #ifndef CYTHON_RESTRICT #if defined(__GNUC__) #define CYTHON_RESTRICT __restrict__ #elif defined(_MSC_VER) && _MSC_VER >= 1400 #define CYTHON_RESTRICT __restrict #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_RESTRICT restrict #else #define CYTHON_RESTRICT #endif #endif #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) #ifndef CYTHON_INLINE #if defined(__GNUC__) #define CYTHON_INLINE __inline__ #elif defined(_MSC_VER) #define CYTHON_INLINE __inline #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define CYTHON_INLINE inline #else #define CYTHON_INLINE #endif #endif #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES #endif #include #ifdef NAN #define __PYX_NAN() ((float) NAN) #else static CYTHON_INLINE float __PYX_NAN() { float value; memset(&value, 0xFF, sizeof(value)); return value; } #endif #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) #define __Pyx_truncl trunc #else #define __Pyx_truncl truncl #endif #define __PYX_ERR(f_index, lineno, Ln_error) \ { \ __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \ } #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) #else #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) #endif #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" #else #define __PYX_EXTERN_C extern #endif #endif #define __PYX_HAVE__tinycss__speedups #define __PYX_HAVE_API__tinycss__speedups #ifdef _OPENMP #include #endif /* _OPENMP */ #ifdef PYREX_WITHOUT_ASSERTIONS #define CYTHON_WITHOUT_ASSERTIONS #endif #ifndef CYTHON_UNUSED # if defined(__GNUC__) # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) # define CYTHON_UNUSED __attribute__ ((__unused__)) # else # define CYTHON_UNUSED # endif #endif #ifndef CYTHON_NCP_UNUSED # if CYTHON_COMPILING_IN_CPYTHON # define CYTHON_NCP_UNUSED # else # define CYTHON_NCP_UNUSED CYTHON_UNUSED # endif #endif typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #define __Pyx_uchar_cast(c) ((unsigned char)c) #define __Pyx_long_cast(x) ((long)x) #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ (sizeof(type) < sizeof(Py_ssize_t)) ||\ (sizeof(type) > sizeof(Py_ssize_t) &&\ likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX) &&\ (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ v == (type)PY_SSIZE_T_MIN))) ||\ (sizeof(type) == sizeof(Py_ssize_t) &&\ (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX))) ) #if defined (__cplusplus) && __cplusplus >= 201103L #include #define __Pyx_sst_abs(value) std::abs(value) #elif SIZEOF_INT >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) abs(value) #elif SIZEOF_LONG >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) labs(value) #elif defined (_MSC_VER) && defined (_M_X64) #define __Pyx_sst_abs(value) _abs64(value) #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define __Pyx_sst_abs(value) llabs(value) #elif defined (__GNUC__) #define __Pyx_sst_abs(value) __builtin_llabs(value) #else #define __Pyx_sst_abs(value) ((value<0) ? -value : value) #endif static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*); static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); #if PY_MAJOR_VERSION < 3 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize #else #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #endif #define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) #if PY_MAJOR_VERSION < 3 static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { const Py_UNICODE *u_end = u; while (*u_end++) ; return (size_t)(u_end - u - 1); } #else #define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen #endif #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) #define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False)) static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); #if CYTHON_COMPILING_IN_CPYTHON #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #else #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) #endif #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) #else #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) #endif #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; PyObject* ascii_chars_u = NULL; PyObject* ascii_chars_b = NULL; const char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; if (strcmp(default_encoding_c, "ascii") == 0) { __Pyx_sys_getdefaultencoding_not_ascii = 0; } else { char ascii_chars[128]; int c; for (c = 0; c < 128; c++) { ascii_chars[c] = c; } __Pyx_sys_getdefaultencoding_not_ascii = 1; ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); if (!ascii_chars_u) goto bad; ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { PyErr_Format( PyExc_ValueError, "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", default_encoding_c); goto bad; } Py_DECREF(ascii_chars_u); Py_DECREF(ascii_chars_b); } Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); Py_XDECREF(ascii_chars_u); Py_XDECREF(ascii_chars_b); return -1; } #endif #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) #else #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT static char* __PYX_DEFAULT_STRING_ENCODING; static int __Pyx_init_sys_getdefaultencoding_params(void) { PyObject* sys; PyObject* default_encoding = NULL; char* default_encoding_c; sys = PyImport_ImportModule("sys"); if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); Py_DECREF(sys); if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c)); if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); Py_DECREF(default_encoding); return 0; bad: Py_XDECREF(default_encoding); return -1; } #endif #endif /* Test for GCC > 2.95 */ #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else /* !__GNUC__ or GCC < 2.95 */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ static PyObject *__pyx_m; static PyObject *__pyx_d; static PyObject *__pyx_b; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; static PyObject *__pyx_empty_unicode; static int __pyx_lineno; static int __pyx_clineno = 0; static const char * __pyx_cfilenm= __FILE__; static const char *__pyx_filename; static const char *__pyx_f[] = { "tinycss/speedups.pyx", }; /*--- Type declarations ---*/ struct __pyx_obj_7tinycss_8speedups_CToken; struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr; /* "tinycss/speedups.pyx":25 * * * cdef class CToken: # <<<<<<<<<<<<<< * """A token built by the Cython speedups. Identical to * :class:`~.token_data.Token`. */ struct __pyx_obj_7tinycss_8speedups_CToken { PyObject_HEAD PyObject *type; PyObject *_as_css; PyObject *value; PyObject *unit; Py_ssize_t line; Py_ssize_t column; }; /* "tinycss/speedups.pyx":22 * * COMPILED_TOKEN_INDEXES = dict( * (name, i) for i, (name, regexp) in enumerate(COMPILED_TOKEN_REGEXPS)) # <<<<<<<<<<<<<< * * */ struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr { PyObject_HEAD PyObject *__pyx_v_i; PyObject *__pyx_v_name; PyObject *__pyx_v_regexp; }; /* --- Runtime support code (head) --- */ /* Refnanny.proto */ #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif #if CYTHON_REFNANNY typedef struct { void (*INCREF)(void*, PyObject*, int); void (*DECREF)(void*, PyObject*, int); void (*GOTREF)(void*, PyObject*, int); void (*GIVEREF)(void*, PyObject*, int); void* (*SetupContext)(const char*, int, const char*); void (*FinishContext)(void**); } __Pyx_RefNannyAPIStruct; static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; #ifdef WITH_THREAD #define __Pyx_RefNannySetupContext(name, acquire_gil)\ if (acquire_gil) {\ PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ PyGILState_Release(__pyx_gilstate_save);\ } else {\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ } #else #define __Pyx_RefNannySetupContext(name, acquire_gil)\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) #endif #define __Pyx_RefNannyFinishContext()\ __Pyx_RefNanny->FinishContext(&__pyx_refnanny) #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) #else #define __Pyx_RefNannyDeclarations #define __Pyx_RefNannySetupContext(name, acquire_gil) #define __Pyx_RefNannyFinishContext() #define __Pyx_INCREF(r) Py_INCREF(r) #define __Pyx_DECREF(r) Py_DECREF(r) #define __Pyx_GOTREF(r) #define __Pyx_GIVEREF(r) #define __Pyx_XINCREF(r) Py_XINCREF(r) #define __Pyx_XDECREF(r) Py_XDECREF(r) #define __Pyx_XGOTREF(r) #define __Pyx_XGIVEREF(r) #endif #define __Pyx_XDECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_XDECREF(tmp);\ } while (0) #define __Pyx_DECREF_SET(r, v) do {\ PyObject *tmp = (PyObject *) r;\ r = v; __Pyx_DECREF(tmp);\ } while (0) #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) /* PyObjectGetAttrStr.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { PyTypeObject* tp = Py_TYPE(obj); if (likely(tp->tp_getattro)) return tp->tp_getattro(obj, attr_name); #if PY_MAJOR_VERSION < 3 if (likely(tp->tp_getattr)) return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); #endif return PyObject_GetAttr(obj, attr_name); } #else #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) #endif /* GetBuiltinName.proto */ static PyObject *__Pyx_GetBuiltinName(PyObject *name); /* GetModuleGlobalName.proto */ static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); /* RaiseTooManyValuesToUnpack.proto */ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); /* RaiseNeedMoreValuesToUnpack.proto */ static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); /* IterFinish.proto */ static CYTHON_INLINE int __Pyx_IterFinish(void); /* UnpackItemEndCheck.proto */ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /* PyIntBinop.proto */ #if CYTHON_COMPILING_IN_CPYTHON static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace); #else #define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\ (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) #endif /* RaiseArgTupleInvalid.proto */ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /* RaiseDoubleKeywords.proto */ static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /* ParseKeywords.proto */ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ const char* function_name); /* PyObjectCall.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); #else #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) #endif /* GetItemInt.proto */ #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ __Pyx_GetItemInt_Generic(o, to_py_func(i)))) #define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); #define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int wraparound, int boundscheck); static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, int wraparound, int boundscheck); /* PyUnicodeContains.proto */ static CYTHON_INLINE int __Pyx_PyUnicode_ContainsTF(PyObject* substring, PyObject* text, int eq) { int result = PyUnicode_Contains(text, substring); return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); } /* UnicodeAsUCS4.proto */ static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*); /* object_ord.proto */ #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyObject_Ord(c)\ (likely(PyUnicode_Check(c)) ? (long)__Pyx_PyUnicode_AsPy_UCS4(c) : __Pyx__PyObject_Ord(c)) #else #define __Pyx_PyObject_Ord(c) __Pyx__PyObject_Ord(c) #endif static long __Pyx__PyObject_Ord(PyObject* c); /* PyObjectCallMethO.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); #endif /* PyObjectCallOneArg.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /* PyObjectCallNoArg.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); #else #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL) #endif /* None.proto */ static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); /* PySequenceContains.proto */ static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { int result = PySequence_Contains(seq, item); return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); } /* SliceObject.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, PyObject** py_start, PyObject** py_stop, PyObject** py_slice, int has_cstart, int has_cstop, int wraparound); /* ListAppend.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { PyListObject* L = (PyListObject*) list; Py_ssize_t len = Py_SIZE(list); if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) { Py_INCREF(x); PyList_SET_ITEM(list, len, x); Py_SIZE(list) = len+1; return 0; } return PyList_Append(list, x); } #else #define __Pyx_PyList_Append(L,x) PyList_Append(L,x) #endif /* IncludeStringH.proto */ #include /* Import.proto */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /* ImportFrom.proto */ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); /* CodeObjectCache.proto */ typedef struct { PyCodeObject* code_object; int code_line; } __Pyx_CodeObjectCacheEntry; struct __Pyx_CodeObjectCache { int count; int max_count; __Pyx_CodeObjectCacheEntry* entries; }; static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); static PyCodeObject *__pyx_find_code_object(int code_line); static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); /* AddTraceback.proto */ static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); /* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); /* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); /* CIntFromPy.proto */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); /* FetchCommonType.proto */ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); /* PyThreadStateGet.proto */ #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; #define __Pyx_PyThreadState_assign __pyx_tstate = PyThreadState_GET(); #else #define __Pyx_PyThreadState_declare #define __Pyx_PyThreadState_assign #endif /* PyErrFetchRestore.proto */ #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); #else #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) #endif /* RaiseException.proto */ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /* SwapException.proto */ #if CYTHON_COMPILING_IN_CPYTHON #define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); #else static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); #endif /* PyObjectCallMethod1.proto */ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); /* CoroutineBase.proto */ typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyObject *); typedef struct { PyObject_HEAD __pyx_coroutine_body_t body; PyObject *closure; PyObject *exc_type; PyObject *exc_value; PyObject *exc_traceback; PyObject *gi_weakreflist; PyObject *classobj; PyObject *yieldfrom; PyObject *gi_name; PyObject *gi_qualname; PyObject *gi_modulename; int resume_label; char is_running; } __pyx_CoroutineObject; static __pyx_CoroutineObject *__Pyx__Coroutine_New( PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *closure, PyObject *name, PyObject *qualname, PyObject *module_name); static int __Pyx_Coroutine_clear(PyObject *self); #if 1 || PY_VERSION_HEX < 0x030300B0 static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue); #else #define __Pyx_PyGen_FetchStopIterationValue(pvalue) PyGen_FetchStopIterationValue(pvalue) #endif /* PatchModuleWithCoroutine.proto */ static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code); /* PatchGeneratorABC.proto */ static int __Pyx_patch_abc(void); /* Generator.proto */ #define __Pyx_Generator_USED static PyTypeObject *__pyx_GeneratorType = 0; #define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType) #define __Pyx_Generator_New(body, closure, name, qualname, module_name)\ __Pyx__Coroutine_New(__pyx_GeneratorType, body, closure, name, qualname, module_name) static PyObject *__Pyx_Generator_Next(PyObject *self); static int __pyx_Generator_init(void); /* CheckBinaryVersion.proto */ static int __Pyx_check_binary_version(void); /* InitStrings.proto */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /* Module declarations from 'tinycss.speedups' */ static PyTypeObject *__pyx_ptype_7tinycss_8speedups_CToken = 0; static PyTypeObject *__pyx_ptype_7tinycss_8speedups___pyx_scope_struct__genexpr = 0; #define __Pyx_MODULE_NAME "tinycss.speedups" int __pyx_module_is_main_tinycss__speedups = 0; /* Implementation of 'tinycss.speedups' */ static PyObject *__pyx_builtin_enumerate; static const char __pyx_k_[] = ""; static const char __pyx_k__2[] = ":;{}()[]"; static const char __pyx_k__4[] = "."; static const char __pyx_k__7[] = "%"; static const char __pyx_k__9[] = "\"'"; static const char __pyx_k_URI[] = "URI"; static const char __pyx_k_end[] = "end"; static const char __pyx_k_pos[] = "pos"; static const char __pyx_k_HASH[] = "HASH"; static const char __pyx_k_args[] = "args"; static const char __pyx_k_char[] = "char"; static const char __pyx_k_line[] = "line"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_send[] = "send"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_type[] = "type_"; static const char __pyx_k_unit[] = "unit"; static const char __pyx_k_DELIM[] = "DELIM"; static const char __pyx_k_IDENT[] = "IDENT"; static const char __pyx_k_close[] = "close"; static const char __pyx_k_group[] = "group"; static const char __pyx_k_lower[] = "lower"; static const char __pyx_k_match[] = "match"; static const char __pyx_k_throw[] = "throw"; static const char __pyx_k_token[] = "token"; static const char __pyx_k_value[] = "value"; static const char __pyx_k_NUMBER[] = "NUMBER"; static const char __pyx_k_STRING[] = "STRING"; static const char __pyx_k_column[] = "column"; static const char __pyx_k_format[] = "format"; static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_length[] = "length"; static const char __pyx_k_regexp[] = "regexp"; static const char __pyx_k_tokens[] = "tokens"; static const char __pyx_k_COMMENT[] = "COMMENT"; static const char __pyx_k_INTEGER[] = "INTEGER"; static const char __pyx_k_genexpr[] = "genexpr"; static const char __pyx_k_FUNCTION[] = "FUNCTION"; static const char __pyx_k_n_tokens[] = "n_tokens"; static const char __pyx_k_newlines[] = "newlines"; static const char __pyx_k_next_pos[] = "next_pos"; static const char __pyx_k_ATKEYWORD[] = "ATKEYWORD"; static const char __pyx_k_DIMENSION[] = "DIMENSION"; static const char __pyx_k_codepoint[] = "codepoint"; static const char __pyx_k_css_value[] = "css_value"; static const char __pyx_k_enumerate[] = "enumerate"; static const char __pyx_k_type_name[] = "type_name"; static const char __pyx_k_BAD_STRING[] = "BAD_STRING"; static const char __pyx_k_PERCENTAGE[] = "PERCENTAGE"; static const char __pyx_k_css_source[] = "css_source"; static const char __pyx_k_source_len[] = "source_len"; static const char __pyx_k_token_data[] = "token_data"; static const char __pyx_k_BAD_COMMENT[] = "BAD_COMMENT"; static const char __pyx_k_is_container[] = "is_container"; static const char __pyx_k_FIND_NEWLINES[] = "FIND_NEWLINES"; static const char __pyx_k_find_newlines[] = "find_newlines"; static const char __pyx_k_tokenize_flat[] = "tokenize_flat"; static const char __pyx_k_TOKEN_DISPATCH[] = "TOKEN_DISPATCH"; static const char __pyx_k_SIMPLE_UNESCAPE[] = "SIMPLE_UNESCAPE"; static const char __pyx_k_compiled_tokens[] = "compiled_tokens"; static const char __pyx_k_ignore_comments[] = "ignore_comments"; static const char __pyx_k_simple_unescape[] = "simple_unescape"; static const char __pyx_k_tokens_dispatch[] = "tokens_dispatch"; static const char __pyx_k_NEWLINE_UNESCAPE[] = "NEWLINE_UNESCAPE"; static const char __pyx_k_UNICODE_UNESCAPE[] = "UNICODE_UNESCAPE"; static const char __pyx_k_newline_unescape[] = "newline_unescape"; static const char __pyx_k_tinycss_speedups[] = "tinycss.speedups"; static const char __pyx_k_unicode_unescape[] = "unicode_unescape"; static const char __pyx_k_COMPILED_TOKEN_INDEXES[] = "COMPILED_TOKEN_INDEXES"; static const char __pyx_k_COMPILED_TOKEN_REGEXPS[] = "COMPILED_TOKEN_REGEXPS"; static const char __pyx_k_compiled_token_indexes[] = "compiled_token_indexes"; static const char __pyx_k_home_lize_Informatique_tinycss[] = "/home/lize/Informatique/tinycss/tinycss/speedups.pyx"; static const char __pyx_k_tinycss_speedups_Cython_module[] = "\n tinycss.speedups\n ----------------\n\n Cython module for speeding up inner loops.\n\n Right now only :func:`tokenize_flat` has a second implementation.\n\n :copyright: (c) 2010 by Simon Sapin.\n :license: BSD, see LICENSE for more details.\n"; static const char __pyx_k_Token_0_type_at_0_line_0_column[] = ""; static PyObject *__pyx_kp_u_; static PyObject *__pyx_n_s_ATKEYWORD; static PyObject *__pyx_n_u_ATKEYWORD; static PyObject *__pyx_n_s_BAD_COMMENT; static PyObject *__pyx_n_u_BAD_COMMENT; static PyObject *__pyx_n_s_BAD_STRING; static PyObject *__pyx_n_u_BAD_STRING; static PyObject *__pyx_n_s_COMMENT; static PyObject *__pyx_n_u_COMMENT; static PyObject *__pyx_n_s_COMPILED_TOKEN_INDEXES; static PyObject *__pyx_n_s_COMPILED_TOKEN_REGEXPS; static PyObject *__pyx_n_s_DELIM; static PyObject *__pyx_n_u_DELIM; static PyObject *__pyx_n_s_DIMENSION; static PyObject *__pyx_n_u_DIMENSION; static PyObject *__pyx_n_s_FIND_NEWLINES; static PyObject *__pyx_n_s_FUNCTION; static PyObject *__pyx_n_u_FUNCTION; static PyObject *__pyx_n_s_HASH; static PyObject *__pyx_n_u_HASH; static PyObject *__pyx_n_s_IDENT; static PyObject *__pyx_n_u_IDENT; static PyObject *__pyx_n_u_INTEGER; static PyObject *__pyx_n_s_NEWLINE_UNESCAPE; static PyObject *__pyx_n_s_NUMBER; static PyObject *__pyx_n_u_NUMBER; static PyObject *__pyx_n_s_PERCENTAGE; static PyObject *__pyx_n_u_PERCENTAGE; static PyObject *__pyx_n_s_SIMPLE_UNESCAPE; static PyObject *__pyx_n_s_STRING; static PyObject *__pyx_n_u_STRING; static PyObject *__pyx_n_s_TOKEN_DISPATCH; static PyObject *__pyx_kp_u_Token_0_type_at_0_line_0_column; static PyObject *__pyx_n_s_UNICODE_UNESCAPE; static PyObject *__pyx_n_s_URI; static PyObject *__pyx_n_u_URI; static PyObject *__pyx_kp_u__2; static PyObject *__pyx_kp_u__4; static PyObject *__pyx_kp_u__7; static PyObject *__pyx_kp_u__9; static PyObject *__pyx_n_s_args; static PyObject *__pyx_n_s_char; static PyObject *__pyx_n_s_close; static PyObject *__pyx_n_s_codepoint; static PyObject *__pyx_n_s_column; static PyObject *__pyx_n_s_compiled_token_indexes; static PyObject *__pyx_n_s_compiled_tokens; static PyObject *__pyx_n_s_css_source; static PyObject *__pyx_n_s_css_value; static PyObject *__pyx_n_s_end; static PyObject *__pyx_n_s_enumerate; static PyObject *__pyx_n_s_find_newlines; static PyObject *__pyx_n_s_format; static PyObject *__pyx_n_s_genexpr; static PyObject *__pyx_n_s_group; static PyObject *__pyx_kp_s_home_lize_Informatique_tinycss; static PyObject *__pyx_n_s_ignore_comments; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_is_container; static PyObject *__pyx_n_s_length; static PyObject *__pyx_n_s_line; static PyObject *__pyx_n_s_lower; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_match; static PyObject *__pyx_n_s_n_tokens; static PyObject *__pyx_n_s_newline_unescape; static PyObject *__pyx_n_s_newlines; static PyObject *__pyx_n_s_next_pos; static PyObject *__pyx_n_s_pos; static PyObject *__pyx_n_s_regexp; static PyObject *__pyx_n_s_send; static PyObject *__pyx_n_s_simple_unescape; static PyObject *__pyx_n_s_source_len; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_throw; static PyObject *__pyx_n_s_tinycss_speedups; static PyObject *__pyx_n_s_token; static PyObject *__pyx_n_s_token_data; static PyObject *__pyx_n_s_tokenize_flat; static PyObject *__pyx_n_s_tokens; static PyObject *__pyx_n_s_tokens_dispatch; static PyObject *__pyx_n_s_type; static PyObject *__pyx_n_s_type_name; static PyObject *__pyx_n_s_unicode_unescape; static PyObject *__pyx_n_s_unit; static PyObject *__pyx_n_s_value; static PyObject *__pyx_pf_7tinycss_8speedups_2genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken___init__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_type_, PyObject *__pyx_v_css_value, PyObject *__pyx_v_value, PyObject *__pyx_v_unit, PyObject *__pyx_v_line, PyObject *__pyx_v_column); /* proto */ static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_2as_css(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_4__repr__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_4type___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_4type_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_4type_4__del__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_7_as_css___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_7_as_css_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_7_as_css_4__del__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_5value___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_5value_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_5value_4__del__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_4unit___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_4unit_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_4unit_4__del__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_4line___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_4line_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_6column___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self); /* proto */ static int __pyx_pf_7tinycss_8speedups_6CToken_6column_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static PyObject *__pyx_pf_7tinycss_8speedups_tokenize_flat(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_css_source, int __pyx_v_ignore_comments); /* proto */ static PyObject *__pyx_tp_new_7tinycss_8speedups_CToken(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_7tinycss_8speedups___pyx_scope_struct__genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_2; static PyObject *__pyx_int_neg_1; static PyObject *__pyx_slice__6; static PyObject *__pyx_tuple__3; static PyObject *__pyx_tuple__5; static PyObject *__pyx_tuple__8; static PyObject *__pyx_slice__10; static PyObject *__pyx_slice__11; static PyObject *__pyx_slice__12; static PyObject *__pyx_tuple__13; static PyObject *__pyx_codeobj__14; static PyObject *__pyx_gb_7tinycss_8speedups_4generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* "tinycss/speedups.pyx":22 * * COMPILED_TOKEN_INDEXES = dict( * (name, i) for i, (name, regexp) in enumerate(COMPILED_TOKEN_REGEXPS)) # <<<<<<<<<<<<<< * * */ static PyObject *__pyx_pf_7tinycss_8speedups_2genexpr(CYTHON_UNUSED PyObject *__pyx_self) { struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("genexpr", 0); __pyx_cur_scope = (struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *)__pyx_tp_new_7tinycss_8speedups___pyx_scope_struct__genexpr(__pyx_ptype_7tinycss_8speedups___pyx_scope_struct__genexpr, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; } __Pyx_GOTREF(__pyx_cur_scope); { __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_7tinycss_8speedups_4generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_genexpr, __pyx_n_s_tinycss_speedups); if (unlikely(!gen)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; } /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("tinycss.speedups.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_gb_7tinycss_8speedups_4generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *__pyx_cur_scope = ((struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *)__pyx_generator->closure); PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; Py_ssize_t __pyx_t_4; PyObject *(*__pyx_t_5)(PyObject *); PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; PyObject *(*__pyx_t_9)(PyObject *); __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; default: /* CPython raises the right error here */ __Pyx_RefNannyFinishContext(); return NULL; } __pyx_L3_first_run:; if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 22, __pyx_L1_error) __pyx_r = PyDict_New(); if (unlikely(!__pyx_r)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_r); __Pyx_INCREF(__pyx_int_0); __pyx_t_1 = __pyx_int_0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_COMPILED_TOKEN_REGEXPS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 22, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (likely(!__pyx_t_5)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 22, __pyx_L1_error) #else __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 22, __pyx_L1_error) #else __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } } else { __pyx_t_2 = __pyx_t_5(__pyx_t_3); if (unlikely(!__pyx_t_2)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(0, 22, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_2); } if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 22, __pyx_L1_error) } #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_6 = PyList_GET_ITEM(sequence, 0); __pyx_t_7 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(__pyx_t_7); #else __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_7); if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 22, __pyx_L1_error) __pyx_t_9 = NULL; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L7_unpacking_done; __pyx_L6_unpacking_failed:; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_9 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 22, __pyx_L1_error) __pyx_L7_unpacking_done:; } __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name); __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_name, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_regexp); __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_regexp, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_INCREF(__pyx_t_1); __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_i, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = __pyx_t_2; __pyx_t_2 = 0; if (unlikely(PyDict_SetItem(__pyx_r, (PyObject*)__pyx_cur_scope->__pyx_v_name, (PyObject*)__pyx_cur_scope->__pyx_v_i))) __PYX_ERR(0, 22, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_r); __pyx_r = 0; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __pyx_generator->resume_label = -1; __Pyx_Coroutine_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "tinycss/speedups.pyx":35 * cdef public Py_ssize_t line, column * * def __init__(self, type_, css_value, value, unit, line, column): # <<<<<<<<<<<<<< * self.type = type_ * self._as_css = css_value */ /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_type_ = 0; PyObject *__pyx_v_css_value = 0; PyObject *__pyx_v_value = 0; PyObject *__pyx_v_unit = 0; PyObject *__pyx_v_line = 0; PyObject *__pyx_v_column = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_type,&__pyx_n_s_css_value,&__pyx_n_s_value,&__pyx_n_s_unit,&__pyx_n_s_line,&__pyx_n_s_column,0}; PyObject* values[6] = {0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_type)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_css_value)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 6, 6, 1); __PYX_ERR(0, 35, __pyx_L3_error) } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 6, 6, 2); __PYX_ERR(0, 35, __pyx_L3_error) } case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_unit)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 6, 6, 3); __PYX_ERR(0, 35, __pyx_L3_error) } case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_line)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 6, 6, 4); __PYX_ERR(0, 35, __pyx_L3_error) } case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_column)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 6, 6, 5); __PYX_ERR(0, 35, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 35, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); } __pyx_v_type_ = values[0]; __pyx_v_css_value = values[1]; __pyx_v_value = values[2]; __pyx_v_unit = values[3]; __pyx_v_line = values[4]; __pyx_v_column = values[5]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 35, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("tinycss.speedups.CToken.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken___init__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self), __pyx_v_type_, __pyx_v_css_value, __pyx_v_value, __pyx_v_unit, __pyx_v_line, __pyx_v_column); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken___init__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_type_, PyObject *__pyx_v_css_value, PyObject *__pyx_v_value, PyObject *__pyx_v_unit, PyObject *__pyx_v_line, PyObject *__pyx_v_column) { int __pyx_r; __Pyx_RefNannyDeclarations Py_ssize_t __pyx_t_1; __Pyx_RefNannySetupContext("__init__", 0); /* "tinycss/speedups.pyx":36 * * def __init__(self, type_, css_value, value, unit, line, column): * self.type = type_ # <<<<<<<<<<<<<< * self._as_css = css_value * self.value = value */ __Pyx_INCREF(__pyx_v_type_); __Pyx_GIVEREF(__pyx_v_type_); __Pyx_GOTREF(__pyx_v_self->type); __Pyx_DECREF(__pyx_v_self->type); __pyx_v_self->type = __pyx_v_type_; /* "tinycss/speedups.pyx":37 * def __init__(self, type_, css_value, value, unit, line, column): * self.type = type_ * self._as_css = css_value # <<<<<<<<<<<<<< * self.value = value * self.unit = unit */ __Pyx_INCREF(__pyx_v_css_value); __Pyx_GIVEREF(__pyx_v_css_value); __Pyx_GOTREF(__pyx_v_self->_as_css); __Pyx_DECREF(__pyx_v_self->_as_css); __pyx_v_self->_as_css = __pyx_v_css_value; /* "tinycss/speedups.pyx":38 * self.type = type_ * self._as_css = css_value * self.value = value # <<<<<<<<<<<<<< * self.unit = unit * self.line = line */ __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); __Pyx_GOTREF(__pyx_v_self->value); __Pyx_DECREF(__pyx_v_self->value); __pyx_v_self->value = __pyx_v_value; /* "tinycss/speedups.pyx":39 * self._as_css = css_value * self.value = value * self.unit = unit # <<<<<<<<<<<<<< * self.line = line * self.column = column */ __Pyx_INCREF(__pyx_v_unit); __Pyx_GIVEREF(__pyx_v_unit); __Pyx_GOTREF(__pyx_v_self->unit); __Pyx_DECREF(__pyx_v_self->unit); __pyx_v_self->unit = __pyx_v_unit; /* "tinycss/speedups.pyx":40 * self.value = value * self.unit = unit * self.line = line # <<<<<<<<<<<<<< * self.column = column * */ __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_line); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 40, __pyx_L1_error) __pyx_v_self->line = __pyx_t_1; /* "tinycss/speedups.pyx":41 * self.unit = unit * self.line = line * self.column = column # <<<<<<<<<<<<<< * * def as_css(self): */ __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_column); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 41, __pyx_L1_error) __pyx_v_self->column = __pyx_t_1; /* "tinycss/speedups.pyx":35 * cdef public Py_ssize_t line, column * * def __init__(self, type_, css_value, value, unit, line, column): # <<<<<<<<<<<<<< * self.type = type_ * self._as_css = css_value */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("tinycss.speedups.CToken.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "tinycss/speedups.pyx":43 * self.column = column * * def as_css(self): # <<<<<<<<<<<<<< * """ * Return as an Unicode string the CSS representation of the token, */ /* Python wrapper */ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_3as_css(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static char __pyx_doc_7tinycss_8speedups_6CToken_2as_css[] = "\n Return as an Unicode string the CSS representation of the token,\n as parsed in the source.\n "; static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_3as_css(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("as_css (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_2as_css(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_2as_css(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("as_css", 0); /* "tinycss/speedups.pyx":48 * as parsed in the source. * """ * return self._as_css # <<<<<<<<<<<<<< * * def __repr__(self): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_as_css); __pyx_r = __pyx_v_self->_as_css; goto __pyx_L0; /* "tinycss/speedups.pyx":43 * self.column = column * * def as_css(self): # <<<<<<<<<<<<<< * """ * Return as an Unicode string the CSS representation of the token, */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "tinycss/speedups.pyx":50 * return self._as_css * * def __repr__(self): # <<<<<<<<<<<<<< * return ('' * .format(self, self.unit or '')) */ /* Python wrapper */ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_5__repr__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_5__repr__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_4__repr__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_4__repr__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; int __pyx_t_4; PyObject *__pyx_t_5 = NULL; Py_ssize_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("__repr__", 0); /* "tinycss/speedups.pyx":51 * * def __repr__(self): * return ('' # <<<<<<<<<<<<<< * .format(self, self.unit or '')) * */ __Pyx_XDECREF(__pyx_r); /* "tinycss/speedups.pyx":52 * def __repr__(self): * return ('' * .format(self, self.unit or '')) # <<<<<<<<<<<<<< * * */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_Token_0_type_at_0_line_0_column, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_self->unit); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 52, __pyx_L1_error) if (!__pyx_t_4) { } else { __Pyx_INCREF(__pyx_v_self->unit); __pyx_t_3 = __pyx_v_self->unit; goto __pyx_L3_bool_binop_done; } __Pyx_INCREF(__pyx_kp_u_); __pyx_t_3 = __pyx_kp_u_; __pyx_L3_bool_binop_done:; __pyx_t_5 = NULL; __pyx_t_6 = 0; if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); __pyx_t_6 = 1; } } __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (__pyx_t_5) { __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; } __Pyx_INCREF(((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* "tinycss/speedups.pyx":50 * return self._as_css * * def __repr__(self): # <<<<<<<<<<<<<< * return ('' * .format(self, self.unit or '')) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("tinycss.speedups.CToken.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "tinycss/speedups.pyx":32 * is_container = False * * cdef public object type, _as_css, value, unit # <<<<<<<<<<<<<< * cdef public Py_ssize_t line, column * */ /* Python wrapper */ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_4type_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_4type_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_4type___get__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_4type___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->type); __pyx_r = __pyx_v_self->type; goto __pyx_L0; /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_4type_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_4type_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_4type_2__set__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_4type_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); __Pyx_GOTREF(__pyx_v_self->type); __Pyx_DECREF(__pyx_v_self->type); __pyx_v_self->type = __pyx_v_value; /* function exit code */ __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_4type_5__del__(PyObject *__pyx_v_self); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_4type_5__del__(PyObject *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_4type_4__del__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_4type_4__del__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->type); __Pyx_DECREF(__pyx_v_self->type); __pyx_v_self->type = Py_None; /* function exit code */ __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_7_as_css_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_7_as_css_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_7_as_css___get__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_7_as_css___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_as_css); __pyx_r = __pyx_v_self->_as_css; goto __pyx_L0; /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_7_as_css_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_7_as_css_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_7_as_css_2__set__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_7_as_css_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); __Pyx_GOTREF(__pyx_v_self->_as_css); __Pyx_DECREF(__pyx_v_self->_as_css); __pyx_v_self->_as_css = __pyx_v_value; /* function exit code */ __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_7_as_css_5__del__(PyObject *__pyx_v_self); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_7_as_css_5__del__(PyObject *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_7_as_css_4__del__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_7_as_css_4__del__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->_as_css); __Pyx_DECREF(__pyx_v_self->_as_css); __pyx_v_self->_as_css = Py_None; /* function exit code */ __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_5value_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_5value_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_5value___get__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_5value___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->value); __pyx_r = __pyx_v_self->value; goto __pyx_L0; /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_5value_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_5value_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_5value_2__set__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_5value_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); __Pyx_GOTREF(__pyx_v_self->value); __Pyx_DECREF(__pyx_v_self->value); __pyx_v_self->value = __pyx_v_value; /* function exit code */ __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_5value_5__del__(PyObject *__pyx_v_self); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_5value_5__del__(PyObject *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_5value_4__del__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_5value_4__del__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->value); __Pyx_DECREF(__pyx_v_self->value); __pyx_v_self->value = Py_None; /* function exit code */ __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_4unit_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_4unit_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_4unit___get__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_4unit___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->unit); __pyx_r = __pyx_v_self->unit; goto __pyx_L0; /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_4unit_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_4unit_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_4unit_2__set__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_4unit_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__", 0); __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); __Pyx_GOTREF(__pyx_v_self->unit); __Pyx_DECREF(__pyx_v_self->unit); __pyx_v_self->unit = __pyx_v_value; /* function exit code */ __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_4unit_5__del__(PyObject *__pyx_v_self); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_4unit_5__del__(PyObject *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_4unit_4__del__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_4unit_4__del__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__del__", 0); __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->unit); __Pyx_DECREF(__pyx_v_self->unit); __pyx_v_self->unit = Py_None; /* function exit code */ __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "tinycss/speedups.pyx":33 * * cdef public object type, _as_css, value, unit * cdef public Py_ssize_t line, column # <<<<<<<<<<<<<< * * def __init__(self, type_, css_value, value, unit, line, column): */ /* Python wrapper */ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_4line_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_4line_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_4line___get__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_4line___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("tinycss.speedups.CToken.line.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_4line_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_4line_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_4line_2__set__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_4line_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations Py_ssize_t __pyx_t_1; __Pyx_RefNannySetupContext("__set__", 0); __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_value); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 33, __pyx_L1_error) __pyx_v_self->line = __pyx_t_1; /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("tinycss.speedups.CToken.line.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_6column_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_7tinycss_8speedups_6CToken_6column_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_6column___get__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7tinycss_8speedups_6CToken_6column___get__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->column); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("tinycss.speedups.CToken.column.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static int __pyx_pw_7tinycss_8speedups_6CToken_6column_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ static int __pyx_pw_7tinycss_8speedups_6CToken_6column_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); __pyx_r = __pyx_pf_7tinycss_8speedups_6CToken_6column_2__set__(((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_v_self), ((PyObject *)__pyx_v_value)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_7tinycss_8speedups_6CToken_6column_2__set__(struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations Py_ssize_t __pyx_t_1; __Pyx_RefNannySetupContext("__set__", 0); __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_value); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 33, __pyx_L1_error) __pyx_v_self->column = __pyx_t_1; /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("tinycss.speedups.CToken.column.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "tinycss/speedups.pyx":55 * * * def tokenize_flat(css_source, int ignore_comments=1): # <<<<<<<<<<<<<< * """ * :param css_source: */ /* Python wrapper */ static PyObject *__pyx_pw_7tinycss_8speedups_1tokenize_flat(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_7tinycss_8speedups_tokenize_flat[] = "\n :param css_source:\n CSS as an unicode string\n :param ignore_comments:\n if true (the default) comments will not be included in the\n return value\n :return:\n An iterator of :class:`Token`\n\n "; static PyMethodDef __pyx_mdef_7tinycss_8speedups_1tokenize_flat = {"tokenize_flat", (PyCFunction)__pyx_pw_7tinycss_8speedups_1tokenize_flat, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7tinycss_8speedups_tokenize_flat}; static PyObject *__pyx_pw_7tinycss_8speedups_1tokenize_flat(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_css_source = 0; int __pyx_v_ignore_comments; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("tokenize_flat (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_css_source,&__pyx_n_s_ignore_comments,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_css_source)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ignore_comments); if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "tokenize_flat") < 0)) __PYX_ERR(0, 55, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_css_source = values[0]; if (values[1]) { __pyx_v_ignore_comments = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_ignore_comments == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 55, __pyx_L3_error) } else { __pyx_v_ignore_comments = ((int)1); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("tokenize_flat", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 55, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("tinycss.speedups.tokenize_flat", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_7tinycss_8speedups_tokenize_flat(__pyx_self, __pyx_v_css_source, __pyx_v_ignore_comments); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_7tinycss_8speedups_tokenize_flat(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_css_source, int __pyx_v_ignore_comments) { PyObject *__pyx_v_tokens_dispatch = NULL; PyObject *__pyx_v_compiled_token_indexes = NULL; PyObject *__pyx_v_compiled_tokens = NULL; PyObject *__pyx_v_unicode_unescape = NULL; PyObject *__pyx_v_newline_unescape = NULL; PyObject *__pyx_v_simple_unescape = NULL; PyObject *__pyx_v_find_newlines = NULL; Py_ssize_t __pyx_v_BAD_COMMENT; Py_ssize_t __pyx_v_BAD_STRING; Py_ssize_t __pyx_v_PERCENTAGE; Py_ssize_t __pyx_v_DIMENSION; Py_ssize_t __pyx_v_ATKEYWORD; Py_ssize_t __pyx_v_FUNCTION; Py_ssize_t __pyx_v_COMMENT; Py_ssize_t __pyx_v_NUMBER; Py_ssize_t __pyx_v_STRING; Py_ssize_t __pyx_v_IDENT; Py_ssize_t __pyx_v_HASH; Py_ssize_t __pyx_v_URI; Py_ssize_t __pyx_v_DELIM; Py_ssize_t __pyx_v_pos; Py_ssize_t __pyx_v_line; Py_ssize_t __pyx_v_column; Py_ssize_t __pyx_v_source_len; CYTHON_UNUSED Py_ssize_t __pyx_v_n_tokens; Py_ssize_t __pyx_v_length; Py_ssize_t __pyx_v_next_pos; Py_ssize_t __pyx_v_type_; struct __pyx_obj_7tinycss_8speedups_CToken *__pyx_v_token = 0; PyObject *__pyx_v_tokens = NULL; PyObject *__pyx_v_char = NULL; PyObject *__pyx_v_type_name = NULL; PyObject *__pyx_v_css_value = NULL; long __pyx_v_codepoint; PyObject *__pyx_v_regexp = NULL; PyObject *__pyx_v_match = NULL; PyObject *__pyx_v_unit = NULL; PyObject *__pyx_v_value = NULL; PyObject *__pyx_v_newlines = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; Py_ssize_t __pyx_t_2; int __pyx_t_3; int __pyx_t_4; long __pyx_t_5; long __pyx_t_6; long __pyx_t_7; PyObject *__pyx_t_8 = NULL; PyObject *(*__pyx_t_9)(PyObject *); PyObject *__pyx_t_10 = NULL; PyObject *__pyx_t_11 = NULL; PyObject *__pyx_t_12 = NULL; PyObject *__pyx_t_13 = NULL; PyObject *(*__pyx_t_14)(PyObject *); Py_ssize_t __pyx_t_15; int __pyx_t_16; int __pyx_t_17; __Pyx_RefNannySetupContext("tokenize_flat", 0); /* "tinycss/speedups.pyx":67 * """ * # Make these local variable to avoid global lookups in the loop * tokens_dispatch = TOKEN_DISPATCH # <<<<<<<<<<<<<< * compiled_token_indexes = COMPILED_TOKEN_INDEXES * compiled_tokens = COMPILED_TOKEN_REGEXPS */ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_TOKEN_DISPATCH); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_tokens_dispatch = __pyx_t_1; __pyx_t_1 = 0; /* "tinycss/speedups.pyx":68 * # Make these local variable to avoid global lookups in the loop * tokens_dispatch = TOKEN_DISPATCH * compiled_token_indexes = COMPILED_TOKEN_INDEXES # <<<<<<<<<<<<<< * compiled_tokens = COMPILED_TOKEN_REGEXPS * unicode_unescape = UNICODE_UNESCAPE */ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_COMPILED_TOKEN_INDEXES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 68, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_compiled_token_indexes = __pyx_t_1; __pyx_t_1 = 0; /* "tinycss/speedups.pyx":69 * tokens_dispatch = TOKEN_DISPATCH * compiled_token_indexes = COMPILED_TOKEN_INDEXES * compiled_tokens = COMPILED_TOKEN_REGEXPS # <<<<<<<<<<<<<< * unicode_unescape = UNICODE_UNESCAPE * newline_unescape = NEWLINE_UNESCAPE */ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_COMPILED_TOKEN_REGEXPS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_compiled_tokens = __pyx_t_1; __pyx_t_1 = 0; /* "tinycss/speedups.pyx":70 * compiled_token_indexes = COMPILED_TOKEN_INDEXES * compiled_tokens = COMPILED_TOKEN_REGEXPS * unicode_unescape = UNICODE_UNESCAPE # <<<<<<<<<<<<<< * newline_unescape = NEWLINE_UNESCAPE * simple_unescape = SIMPLE_UNESCAPE */ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_UNICODE_UNESCAPE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_unicode_unescape = __pyx_t_1; __pyx_t_1 = 0; /* "tinycss/speedups.pyx":71 * compiled_tokens = COMPILED_TOKEN_REGEXPS * unicode_unescape = UNICODE_UNESCAPE * newline_unescape = NEWLINE_UNESCAPE # <<<<<<<<<<<<<< * simple_unescape = SIMPLE_UNESCAPE * find_newlines = FIND_NEWLINES */ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_NEWLINE_UNESCAPE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_newline_unescape = __pyx_t_1; __pyx_t_1 = 0; /* "tinycss/speedups.pyx":72 * unicode_unescape = UNICODE_UNESCAPE * newline_unescape = NEWLINE_UNESCAPE * simple_unescape = SIMPLE_UNESCAPE # <<<<<<<<<<<<<< * find_newlines = FIND_NEWLINES * */ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_SIMPLE_UNESCAPE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_simple_unescape = __pyx_t_1; __pyx_t_1 = 0; /* "tinycss/speedups.pyx":73 * newline_unescape = NEWLINE_UNESCAPE * simple_unescape = SIMPLE_UNESCAPE * find_newlines = FIND_NEWLINES # <<<<<<<<<<<<<< * * # Use the integer indexes instead of string markers */ __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_FIND_NEWLINES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_find_newlines = __pyx_t_1; __pyx_t_1 = 0; /* "tinycss/speedups.pyx":76 * * # Use the integer indexes instead of string markers * cdef Py_ssize_t BAD_COMMENT = compiled_token_indexes['BAD_COMMENT'] # <<<<<<<<<<<<<< * cdef Py_ssize_t BAD_STRING = compiled_token_indexes['BAD_STRING'] * cdef Py_ssize_t PERCENTAGE = compiled_token_indexes['PERCENTAGE'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_BAD_COMMENT); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_BAD_COMMENT = __pyx_t_2; /* "tinycss/speedups.pyx":77 * # Use the integer indexes instead of string markers * cdef Py_ssize_t BAD_COMMENT = compiled_token_indexes['BAD_COMMENT'] * cdef Py_ssize_t BAD_STRING = compiled_token_indexes['BAD_STRING'] # <<<<<<<<<<<<<< * cdef Py_ssize_t PERCENTAGE = compiled_token_indexes['PERCENTAGE'] * cdef Py_ssize_t DIMENSION = compiled_token_indexes['DIMENSION'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_BAD_STRING); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_BAD_STRING = __pyx_t_2; /* "tinycss/speedups.pyx":78 * cdef Py_ssize_t BAD_COMMENT = compiled_token_indexes['BAD_COMMENT'] * cdef Py_ssize_t BAD_STRING = compiled_token_indexes['BAD_STRING'] * cdef Py_ssize_t PERCENTAGE = compiled_token_indexes['PERCENTAGE'] # <<<<<<<<<<<<<< * cdef Py_ssize_t DIMENSION = compiled_token_indexes['DIMENSION'] * cdef Py_ssize_t ATKEYWORD = compiled_token_indexes['ATKEYWORD'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_PERCENTAGE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_PERCENTAGE = __pyx_t_2; /* "tinycss/speedups.pyx":79 * cdef Py_ssize_t BAD_STRING = compiled_token_indexes['BAD_STRING'] * cdef Py_ssize_t PERCENTAGE = compiled_token_indexes['PERCENTAGE'] * cdef Py_ssize_t DIMENSION = compiled_token_indexes['DIMENSION'] # <<<<<<<<<<<<<< * cdef Py_ssize_t ATKEYWORD = compiled_token_indexes['ATKEYWORD'] * cdef Py_ssize_t FUNCTION = compiled_token_indexes['FUNCTION'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_DIMENSION); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_DIMENSION = __pyx_t_2; /* "tinycss/speedups.pyx":80 * cdef Py_ssize_t PERCENTAGE = compiled_token_indexes['PERCENTAGE'] * cdef Py_ssize_t DIMENSION = compiled_token_indexes['DIMENSION'] * cdef Py_ssize_t ATKEYWORD = compiled_token_indexes['ATKEYWORD'] # <<<<<<<<<<<<<< * cdef Py_ssize_t FUNCTION = compiled_token_indexes['FUNCTION'] * cdef Py_ssize_t COMMENT = compiled_token_indexes['COMMENT'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_ATKEYWORD); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_ATKEYWORD = __pyx_t_2; /* "tinycss/speedups.pyx":81 * cdef Py_ssize_t DIMENSION = compiled_token_indexes['DIMENSION'] * cdef Py_ssize_t ATKEYWORD = compiled_token_indexes['ATKEYWORD'] * cdef Py_ssize_t FUNCTION = compiled_token_indexes['FUNCTION'] # <<<<<<<<<<<<<< * cdef Py_ssize_t COMMENT = compiled_token_indexes['COMMENT'] * cdef Py_ssize_t NUMBER = compiled_token_indexes['NUMBER'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_FUNCTION); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 81, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 81, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_FUNCTION = __pyx_t_2; /* "tinycss/speedups.pyx":82 * cdef Py_ssize_t ATKEYWORD = compiled_token_indexes['ATKEYWORD'] * cdef Py_ssize_t FUNCTION = compiled_token_indexes['FUNCTION'] * cdef Py_ssize_t COMMENT = compiled_token_indexes['COMMENT'] # <<<<<<<<<<<<<< * cdef Py_ssize_t NUMBER = compiled_token_indexes['NUMBER'] * cdef Py_ssize_t STRING = compiled_token_indexes['STRING'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_COMMENT); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_COMMENT = __pyx_t_2; /* "tinycss/speedups.pyx":83 * cdef Py_ssize_t FUNCTION = compiled_token_indexes['FUNCTION'] * cdef Py_ssize_t COMMENT = compiled_token_indexes['COMMENT'] * cdef Py_ssize_t NUMBER = compiled_token_indexes['NUMBER'] # <<<<<<<<<<<<<< * cdef Py_ssize_t STRING = compiled_token_indexes['STRING'] * cdef Py_ssize_t IDENT = compiled_token_indexes['IDENT'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_NUMBER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 83, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 83, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_NUMBER = __pyx_t_2; /* "tinycss/speedups.pyx":84 * cdef Py_ssize_t COMMENT = compiled_token_indexes['COMMENT'] * cdef Py_ssize_t NUMBER = compiled_token_indexes['NUMBER'] * cdef Py_ssize_t STRING = compiled_token_indexes['STRING'] # <<<<<<<<<<<<<< * cdef Py_ssize_t IDENT = compiled_token_indexes['IDENT'] * cdef Py_ssize_t HASH = compiled_token_indexes['HASH'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_STRING); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 84, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 84, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_STRING = __pyx_t_2; /* "tinycss/speedups.pyx":85 * cdef Py_ssize_t NUMBER = compiled_token_indexes['NUMBER'] * cdef Py_ssize_t STRING = compiled_token_indexes['STRING'] * cdef Py_ssize_t IDENT = compiled_token_indexes['IDENT'] # <<<<<<<<<<<<<< * cdef Py_ssize_t HASH = compiled_token_indexes['HASH'] * cdef Py_ssize_t URI = compiled_token_indexes['URI'] */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_IDENT); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 85, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_IDENT = __pyx_t_2; /* "tinycss/speedups.pyx":86 * cdef Py_ssize_t STRING = compiled_token_indexes['STRING'] * cdef Py_ssize_t IDENT = compiled_token_indexes['IDENT'] * cdef Py_ssize_t HASH = compiled_token_indexes['HASH'] # <<<<<<<<<<<<<< * cdef Py_ssize_t URI = compiled_token_indexes['URI'] * cdef Py_ssize_t DELIM = -1 */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_HASH); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_HASH = __pyx_t_2; /* "tinycss/speedups.pyx":87 * cdef Py_ssize_t IDENT = compiled_token_indexes['IDENT'] * cdef Py_ssize_t HASH = compiled_token_indexes['HASH'] * cdef Py_ssize_t URI = compiled_token_indexes['URI'] # <<<<<<<<<<<<<< * cdef Py_ssize_t DELIM = -1 * */ __pyx_t_1 = PyObject_GetItem(__pyx_v_compiled_token_indexes, __pyx_n_u_URI); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 87, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_URI = __pyx_t_2; /* "tinycss/speedups.pyx":88 * cdef Py_ssize_t HASH = compiled_token_indexes['HASH'] * cdef Py_ssize_t URI = compiled_token_indexes['URI'] * cdef Py_ssize_t DELIM = -1 # <<<<<<<<<<<<<< * * cdef Py_ssize_t pos = 0 */ __pyx_v_DELIM = -1L; /* "tinycss/speedups.pyx":90 * cdef Py_ssize_t DELIM = -1 * * cdef Py_ssize_t pos = 0 # <<<<<<<<<<<<<< * cdef Py_ssize_t line = 1 * cdef Py_ssize_t column = 1 */ __pyx_v_pos = 0; /* "tinycss/speedups.pyx":91 * * cdef Py_ssize_t pos = 0 * cdef Py_ssize_t line = 1 # <<<<<<<<<<<<<< * cdef Py_ssize_t column = 1 * cdef Py_ssize_t source_len = len(css_source) */ __pyx_v_line = 1; /* "tinycss/speedups.pyx":92 * cdef Py_ssize_t pos = 0 * cdef Py_ssize_t line = 1 * cdef Py_ssize_t column = 1 # <<<<<<<<<<<<<< * cdef Py_ssize_t source_len = len(css_source) * cdef Py_ssize_t n_tokens = len(compiled_tokens) */ __pyx_v_column = 1; /* "tinycss/speedups.pyx":93 * cdef Py_ssize_t line = 1 * cdef Py_ssize_t column = 1 * cdef Py_ssize_t source_len = len(css_source) # <<<<<<<<<<<<<< * cdef Py_ssize_t n_tokens = len(compiled_tokens) * cdef Py_ssize_t length, next_pos, type_ */ __pyx_t_2 = PyObject_Length(__pyx_v_css_source); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 93, __pyx_L1_error) __pyx_v_source_len = __pyx_t_2; /* "tinycss/speedups.pyx":94 * cdef Py_ssize_t column = 1 * cdef Py_ssize_t source_len = len(css_source) * cdef Py_ssize_t n_tokens = len(compiled_tokens) # <<<<<<<<<<<<<< * cdef Py_ssize_t length, next_pos, type_ * cdef CToken token */ __pyx_t_2 = PyObject_Length(__pyx_v_compiled_tokens); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 94, __pyx_L1_error) __pyx_v_n_tokens = __pyx_t_2; /* "tinycss/speedups.pyx":98 * cdef CToken token * * tokens = [] # <<<<<<<<<<<<<< * while pos < source_len: * char = css_source[pos] */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 98, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_tokens = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":99 * * tokens = [] * while pos < source_len: # <<<<<<<<<<<<<< * char = css_source[pos] * if char in ':;{}()[]': */ while (1) { __pyx_t_3 = ((__pyx_v_pos < __pyx_v_source_len) != 0); if (!__pyx_t_3) break; /* "tinycss/speedups.pyx":100 * tokens = [] * while pos < source_len: * char = css_source[pos] # <<<<<<<<<<<<<< * if char in ':;{}()[]': * type_ = -1 # not parsed further anyway */ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_css_source, __pyx_v_pos, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 100, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_char, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":101 * while pos < source_len: * char = css_source[pos] * if char in ':;{}()[]': # <<<<<<<<<<<<<< * type_ = -1 # not parsed further anyway * type_name = char */ __pyx_t_3 = (__Pyx_PyUnicode_ContainsTF(__pyx_v_char, __pyx_kp_u__2, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 101, __pyx_L1_error) __pyx_t_4 = (__pyx_t_3 != 0); if (__pyx_t_4) { /* "tinycss/speedups.pyx":102 * char = css_source[pos] * if char in ':;{}()[]': * type_ = -1 # not parsed further anyway # <<<<<<<<<<<<<< * type_name = char * css_value = char */ __pyx_v_type_ = -1L; /* "tinycss/speedups.pyx":103 * if char in ':;{}()[]': * type_ = -1 # not parsed further anyway * type_name = char # <<<<<<<<<<<<<< * css_value = char * else: */ __Pyx_INCREF(__pyx_v_char); __Pyx_XDECREF_SET(__pyx_v_type_name, __pyx_v_char); /* "tinycss/speedups.pyx":104 * type_ = -1 # not parsed further anyway * type_name = char * css_value = char # <<<<<<<<<<<<<< * else: * codepoint = min(ord(char), 160) */ __Pyx_INCREF(__pyx_v_char); __Pyx_XDECREF_SET(__pyx_v_css_value, __pyx_v_char); /* "tinycss/speedups.pyx":101 * while pos < source_len: * char = css_source[pos] * if char in ':;{}()[]': # <<<<<<<<<<<<<< * type_ = -1 # not parsed further anyway * type_name = char */ goto __pyx_L5; } /* "tinycss/speedups.pyx":106 * css_value = char * else: * codepoint = min(ord(char), 160) # <<<<<<<<<<<<<< * for type_, type_name, regexp in tokens_dispatch[codepoint]: * match = regexp(css_source, pos) */ /*else*/ { __pyx_t_5 = 0xA0; __pyx_t_6 = __Pyx_PyObject_Ord(__pyx_v_char); if (unlikely(__pyx_t_6 == (long)(Py_UCS4)-1)) __PYX_ERR(0, 106, __pyx_L1_error) if (((__pyx_t_5 < __pyx_t_6) != 0)) { __pyx_t_7 = __pyx_t_5; } else { __pyx_t_7 = __pyx_t_6; } __pyx_v_codepoint = __pyx_t_7; /* "tinycss/speedups.pyx":107 * else: * codepoint = min(ord(char), 160) * for type_, type_name, regexp in tokens_dispatch[codepoint]: # <<<<<<<<<<<<<< * match = regexp(css_source, pos) * if match: */ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_tokens_dispatch, __pyx_v_codepoint, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) { __pyx_t_8 = __pyx_t_1; __Pyx_INCREF(__pyx_t_8); __pyx_t_2 = 0; __pyx_t_9 = NULL; } else { __pyx_t_2 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 107, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (;;) { if (likely(!__pyx_t_9)) { if (likely(PyList_CheckExact(__pyx_t_8))) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_8)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 107, __pyx_L1_error) #else __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif } else { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_8)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 107, __pyx_L1_error) #else __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif } } else { __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(0, 107, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_1); } if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { PyObject* sequence = __pyx_t_1; #if CYTHON_COMPILING_IN_CPYTHON Py_ssize_t size = Py_SIZE(sequence); #else Py_ssize_t size = PySequence_Size(sequence); #endif if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 107, __pyx_L1_error) } #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_12 = PyTuple_GET_ITEM(sequence, 2); } else { __pyx_t_10 = PyList_GET_ITEM(sequence, 0); __pyx_t_11 = PyList_GET_ITEM(sequence, 1); __pyx_t_12 = PyList_GET_ITEM(sequence, 2); } __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(__pyx_t_12); #else __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_12 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { Py_ssize_t index = -1; __pyx_t_13 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext; index = 0; __pyx_t_10 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_10)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); index = 1; __pyx_t_11 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_11)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_11); index = 2; __pyx_t_12 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_12)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_12); if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 3) < 0) __PYX_ERR(0, 107, __pyx_L1_error) __pyx_t_14 = NULL; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; goto __pyx_L9_unpacking_done; __pyx_L8_unpacking_failed:; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_14 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 107, __pyx_L1_error) __pyx_L9_unpacking_done:; } __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_t_10); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 107, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_v_type_ = __pyx_t_15; __Pyx_XDECREF_SET(__pyx_v_type_name, __pyx_t_11); __pyx_t_11 = 0; __Pyx_XDECREF_SET(__pyx_v_regexp, __pyx_t_12); __pyx_t_12 = 0; /* "tinycss/speedups.pyx":108 * codepoint = min(ord(char), 160) * for type_, type_name, regexp in tokens_dispatch[codepoint]: * match = regexp(css_source, pos) # <<<<<<<<<<<<<< * if match: * # First match is the longest. See comments on TOKENS above. */ __pyx_t_12 = PyInt_FromSsize_t(__pyx_v_pos); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_INCREF(__pyx_v_regexp); __pyx_t_11 = __pyx_v_regexp; __pyx_t_10 = NULL; __pyx_t_15 = 0; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_11))) { __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11); if (likely(__pyx_t_10)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_11, function); __pyx_t_15 = 1; } } __pyx_t_13 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); if (__pyx_t_10) { __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_10); __pyx_t_10 = NULL; } __Pyx_INCREF(__pyx_v_css_source); __Pyx_GIVEREF(__pyx_v_css_source); PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_15, __pyx_v_css_source); __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_15, __pyx_t_12); __pyx_t_12 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_XDECREF_SET(__pyx_v_match, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":109 * for type_, type_name, regexp in tokens_dispatch[codepoint]: * match = regexp(css_source, pos) * if match: # <<<<<<<<<<<<<< * # First match is the longest. See comments on TOKENS above. * css_value = match.group() */ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_match); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 109, __pyx_L1_error) if (__pyx_t_4) { /* "tinycss/speedups.pyx":111 * if match: * # First match is the longest. See comments on TOKENS above. * css_value = match.group() # <<<<<<<<<<<<<< * break * else: */ __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_group); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 111, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_13 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_11))) { __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_11); if (likely(__pyx_t_13)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); __Pyx_INCREF(__pyx_t_13); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_11, function); } } if (__pyx_t_13) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 111, __pyx_L1_error) __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 111, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_XDECREF_SET(__pyx_v_css_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":112 * # First match is the longest. See comments on TOKENS above. * css_value = match.group() * break # <<<<<<<<<<<<<< * else: * # No match. */ goto __pyx_L7_break; /* "tinycss/speedups.pyx":109 * for type_, type_name, regexp in tokens_dispatch[codepoint]: * match = regexp(css_source, pos) * if match: # <<<<<<<<<<<<<< * # First match is the longest. See comments on TOKENS above. * css_value = match.group() */ } /* "tinycss/speedups.pyx":107 * else: * codepoint = min(ord(char), 160) * for type_, type_name, regexp in tokens_dispatch[codepoint]: # <<<<<<<<<<<<<< * match = regexp(css_source, pos) * if match: */ } /*else*/ { /* "tinycss/speedups.pyx":119 * # ... but quotes at the start of a token are always matched * # by STRING or BAD_STRING. So DELIM is any single character. * type_ = DELIM # <<<<<<<<<<<<<< * type_name = 'DELIM' * css_value = char */ __pyx_v_type_ = __pyx_v_DELIM; /* "tinycss/speedups.pyx":120 * # by STRING or BAD_STRING. So DELIM is any single character. * type_ = DELIM * type_name = 'DELIM' # <<<<<<<<<<<<<< * css_value = char * length = len(css_value) */ __Pyx_INCREF(__pyx_n_u_DELIM); __Pyx_XDECREF_SET(__pyx_v_type_name, __pyx_n_u_DELIM); /* "tinycss/speedups.pyx":121 * type_ = DELIM * type_name = 'DELIM' * css_value = char # <<<<<<<<<<<<<< * length = len(css_value) * next_pos = pos + length */ __Pyx_INCREF(__pyx_v_char); __Pyx_XDECREF_SET(__pyx_v_css_value, __pyx_v_char); } /* "tinycss/speedups.pyx":107 * else: * codepoint = min(ord(char), 160) * for type_, type_name, regexp in tokens_dispatch[codepoint]: # <<<<<<<<<<<<<< * match = regexp(css_source, pos) * if match: */ __pyx_L7_break:; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __pyx_L5:; /* "tinycss/speedups.pyx":122 * type_name = 'DELIM' * css_value = char * length = len(css_value) # <<<<<<<<<<<<<< * next_pos = pos + length * */ __pyx_t_2 = PyObject_Length(__pyx_v_css_value); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 122, __pyx_L1_error) __pyx_v_length = __pyx_t_2; /* "tinycss/speedups.pyx":123 * css_value = char * length = len(css_value) * next_pos = pos + length # <<<<<<<<<<<<<< * * # A BAD_COMMENT is a comment at EOF. Ignore it too. */ __pyx_v_next_pos = (__pyx_v_pos + __pyx_v_length); /* "tinycss/speedups.pyx":126 * * # A BAD_COMMENT is a comment at EOF. Ignore it too. * if not (ignore_comments and type_ in (COMMENT, BAD_COMMENT)): # <<<<<<<<<<<<<< * # Parse numbers, extract strings and URIs, unescape * unit = None */ __pyx_t_3 = (__pyx_v_ignore_comments != 0); if (__pyx_t_3) { } else { __pyx_t_4 = __pyx_t_3; goto __pyx_L13_bool_binop_done; } __pyx_t_2 = __pyx_v_type_; __pyx_t_16 = ((__pyx_t_2 == __pyx_v_COMMENT) != 0); if (!__pyx_t_16) { } else { __pyx_t_3 = __pyx_t_16; goto __pyx_L15_bool_binop_done; } __pyx_t_16 = ((__pyx_t_2 == __pyx_v_BAD_COMMENT) != 0); __pyx_t_3 = __pyx_t_16; __pyx_L15_bool_binop_done:; __pyx_t_16 = (__pyx_t_3 != 0); __pyx_t_4 = __pyx_t_16; __pyx_L13_bool_binop_done:; __pyx_t_16 = ((!__pyx_t_4) != 0); if (__pyx_t_16) { /* "tinycss/speedups.pyx":128 * if not (ignore_comments and type_ in (COMMENT, BAD_COMMENT)): * # Parse numbers, extract strings and URIs, unescape * unit = None # <<<<<<<<<<<<<< * if type_ == DIMENSION: * value = match.group(1) */ __Pyx_INCREF(Py_None); __Pyx_XDECREF_SET(__pyx_v_unit, Py_None); /* "tinycss/speedups.pyx":129 * # Parse numbers, extract strings and URIs, unescape * unit = None * if type_ == DIMENSION: # <<<<<<<<<<<<<< * value = match.group(1) * value = float(value) if '.' in value else int(value) */ __pyx_t_16 = ((__pyx_v_type_ == __pyx_v_DIMENSION) != 0); if (__pyx_t_16) { /* "tinycss/speedups.pyx":130 * unit = None * if type_ == DIMENSION: * value = match.group(1) # <<<<<<<<<<<<<< * value = float(value) if '.' in value else int(value) * unit = match.group(2) */ if (unlikely(!__pyx_v_match)) { __Pyx_RaiseUnboundLocalError("match"); __PYX_ERR(0, 130, __pyx_L1_error) } __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_group); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 130, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":131 * if type_ == DIMENSION: * value = match.group(1) * value = float(value) if '.' in value else int(value) # <<<<<<<<<<<<<< * unit = match.group(2) * unit = simple_unescape(unit) */ __pyx_t_16 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__4, __pyx_v_value, Py_EQ)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 131, __pyx_L1_error) if ((__pyx_t_16 != 0)) { __pyx_t_8 = __Pyx_PyNumber_Float(__pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = __pyx_t_8; __pyx_t_8 = 0; } else { __pyx_t_8 = __Pyx_PyNumber_Int(__pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = __pyx_t_8; __pyx_t_8 = 0; } __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":132 * value = match.group(1) * value = float(value) if '.' in value else int(value) * unit = match.group(2) # <<<<<<<<<<<<<< * unit = simple_unescape(unit) * unit = unicode_unescape(unit) */ if (unlikely(!__pyx_v_match)) { __Pyx_RaiseUnboundLocalError("match"); __PYX_ERR(0, 132, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_group); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_unit, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":133 * value = float(value) if '.' in value else int(value) * unit = match.group(2) * unit = simple_unescape(unit) # <<<<<<<<<<<<<< * unit = unicode_unescape(unit) * unit = unit.lower() # normalize */ __Pyx_INCREF(__pyx_v_simple_unescape); __pyx_t_1 = __pyx_v_simple_unescape; __pyx_t_11 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); } } if (!__pyx_t_11) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_unit); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } else { __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL; __Pyx_INCREF(__pyx_v_unit); __Pyx_GIVEREF(__pyx_v_unit); PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_unit); __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_unit, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":134 * unit = match.group(2) * unit = simple_unescape(unit) * unit = unicode_unescape(unit) # <<<<<<<<<<<<<< * unit = unit.lower() # normalize * elif type_ == PERCENTAGE: */ __Pyx_INCREF(__pyx_v_unicode_unescape); __pyx_t_1 = __pyx_v_unicode_unescape; __pyx_t_13 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_13)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_13); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); } } if (!__pyx_t_13) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_unit); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } else { __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL; __Pyx_INCREF(__pyx_v_unit); __Pyx_GIVEREF(__pyx_v_unit); PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_unit); __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_unit, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":135 * unit = simple_unescape(unit) * unit = unicode_unescape(unit) * unit = unit.lower() # normalize # <<<<<<<<<<<<<< * elif type_ == PERCENTAGE: * value = css_value[:-1] */ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_unit, __pyx_n_s_lower); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_11 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); } } if (__pyx_t_11) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } else { __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 135, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_unit, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":129 * # Parse numbers, extract strings and URIs, unescape * unit = None * if type_ == DIMENSION: # <<<<<<<<<<<<<< * value = match.group(1) * value = float(value) if '.' in value else int(value) */ goto __pyx_L17; } /* "tinycss/speedups.pyx":136 * unit = unicode_unescape(unit) * unit = unit.lower() # normalize * elif type_ == PERCENTAGE: # <<<<<<<<<<<<<< * value = css_value[:-1] * value = float(value) if '.' in value else int(value) */ __pyx_t_16 = ((__pyx_v_type_ == __pyx_v_PERCENTAGE) != 0); if (__pyx_t_16) { /* "tinycss/speedups.pyx":137 * unit = unit.lower() # normalize * elif type_ == PERCENTAGE: * value = css_value[:-1] # <<<<<<<<<<<<<< * value = float(value) if '.' in value else int(value) * unit = '%' */ __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_v_css_value, 0, -1L, NULL, NULL, &__pyx_slice__6, 0, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":138 * elif type_ == PERCENTAGE: * value = css_value[:-1] * value = float(value) if '.' in value else int(value) # <<<<<<<<<<<<<< * unit = '%' * elif type_ == NUMBER: */ __pyx_t_16 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__4, __pyx_v_value, Py_EQ)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 138, __pyx_L1_error) if ((__pyx_t_16 != 0)) { __pyx_t_1 = __Pyx_PyNumber_Float(__pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __pyx_t_1; __pyx_t_1 = 0; } else { __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __pyx_t_1; __pyx_t_1 = 0; } __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":139 * value = css_value[:-1] * value = float(value) if '.' in value else int(value) * unit = '%' # <<<<<<<<<<<<<< * elif type_ == NUMBER: * value = css_value */ __Pyx_INCREF(__pyx_kp_u__7); __Pyx_DECREF_SET(__pyx_v_unit, __pyx_kp_u__7); /* "tinycss/speedups.pyx":136 * unit = unicode_unescape(unit) * unit = unit.lower() # normalize * elif type_ == PERCENTAGE: # <<<<<<<<<<<<<< * value = css_value[:-1] * value = float(value) if '.' in value else int(value) */ goto __pyx_L17; } /* "tinycss/speedups.pyx":140 * value = float(value) if '.' in value else int(value) * unit = '%' * elif type_ == NUMBER: # <<<<<<<<<<<<<< * value = css_value * if '.' in value: */ __pyx_t_16 = ((__pyx_v_type_ == __pyx_v_NUMBER) != 0); if (__pyx_t_16) { /* "tinycss/speedups.pyx":141 * unit = '%' * elif type_ == NUMBER: * value = css_value # <<<<<<<<<<<<<< * if '.' in value: * value = float(value) */ __Pyx_INCREF(__pyx_v_css_value); __Pyx_XDECREF_SET(__pyx_v_value, __pyx_v_css_value); /* "tinycss/speedups.pyx":142 * elif type_ == NUMBER: * value = css_value * if '.' in value: # <<<<<<<<<<<<<< * value = float(value) * else: */ __pyx_t_16 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__4, __pyx_v_value, Py_EQ)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 142, __pyx_L1_error) __pyx_t_4 = (__pyx_t_16 != 0); if (__pyx_t_4) { /* "tinycss/speedups.pyx":143 * value = css_value * if '.' in value: * value = float(value) # <<<<<<<<<<<<<< * else: * value = int(value) */ __pyx_t_8 = __Pyx_PyNumber_Float(__pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":142 * elif type_ == NUMBER: * value = css_value * if '.' in value: # <<<<<<<<<<<<<< * value = float(value) * else: */ goto __pyx_L18; } /* "tinycss/speedups.pyx":145 * value = float(value) * else: * value = int(value) # <<<<<<<<<<<<<< * type_name = 'INTEGER' * elif type_ in (IDENT, ATKEYWORD, HASH, FUNCTION): */ /*else*/ { __pyx_t_8 = __Pyx_PyNumber_Int(__pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 145, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":146 * else: * value = int(value) * type_name = 'INTEGER' # <<<<<<<<<<<<<< * elif type_ in (IDENT, ATKEYWORD, HASH, FUNCTION): * value = simple_unescape(css_value) */ __Pyx_INCREF(__pyx_n_u_INTEGER); __Pyx_DECREF_SET(__pyx_v_type_name, __pyx_n_u_INTEGER); } __pyx_L18:; /* "tinycss/speedups.pyx":140 * value = float(value) if '.' in value else int(value) * unit = '%' * elif type_ == NUMBER: # <<<<<<<<<<<<<< * value = css_value * if '.' in value: */ goto __pyx_L17; } /* "tinycss/speedups.pyx":147 * value = int(value) * type_name = 'INTEGER' * elif type_ in (IDENT, ATKEYWORD, HASH, FUNCTION): # <<<<<<<<<<<<<< * value = simple_unescape(css_value) * value = unicode_unescape(value) */ __pyx_t_2 = __pyx_v_type_; __pyx_t_16 = ((__pyx_t_2 == __pyx_v_IDENT) != 0); if (!__pyx_t_16) { } else { __pyx_t_4 = __pyx_t_16; goto __pyx_L19_bool_binop_done; } __pyx_t_16 = ((__pyx_t_2 == __pyx_v_ATKEYWORD) != 0); if (!__pyx_t_16) { } else { __pyx_t_4 = __pyx_t_16; goto __pyx_L19_bool_binop_done; } __pyx_t_16 = ((__pyx_t_2 == __pyx_v_HASH) != 0); if (!__pyx_t_16) { } else { __pyx_t_4 = __pyx_t_16; goto __pyx_L19_bool_binop_done; } __pyx_t_16 = ((__pyx_t_2 == __pyx_v_FUNCTION) != 0); __pyx_t_4 = __pyx_t_16; __pyx_L19_bool_binop_done:; __pyx_t_16 = (__pyx_t_4 != 0); if (__pyx_t_16) { /* "tinycss/speedups.pyx":148 * type_name = 'INTEGER' * elif type_ in (IDENT, ATKEYWORD, HASH, FUNCTION): * value = simple_unescape(css_value) # <<<<<<<<<<<<<< * value = unicode_unescape(value) * elif type_ == URI: */ __Pyx_INCREF(__pyx_v_simple_unescape); __pyx_t_1 = __pyx_v_simple_unescape; __pyx_t_11 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); } } if (!__pyx_t_11) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_css_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } else { __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL; __Pyx_INCREF(__pyx_v_css_value); __Pyx_GIVEREF(__pyx_v_css_value); PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_css_value); __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":149 * elif type_ in (IDENT, ATKEYWORD, HASH, FUNCTION): * value = simple_unescape(css_value) * value = unicode_unescape(value) # <<<<<<<<<<<<<< * elif type_ == URI: * value = match.group(1) */ __Pyx_INCREF(__pyx_v_unicode_unescape); __pyx_t_1 = __pyx_v_unicode_unescape; __pyx_t_13 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_13)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_13); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); } } if (!__pyx_t_13) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } else { __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_value); __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_8); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":147 * value = int(value) * type_name = 'INTEGER' * elif type_ in (IDENT, ATKEYWORD, HASH, FUNCTION): # <<<<<<<<<<<<<< * value = simple_unescape(css_value) * value = unicode_unescape(value) */ goto __pyx_L17; } /* "tinycss/speedups.pyx":150 * value = simple_unescape(css_value) * value = unicode_unescape(value) * elif type_ == URI: # <<<<<<<<<<<<<< * value = match.group(1) * if value and value[0] in '"\'': */ __pyx_t_16 = ((__pyx_v_type_ == __pyx_v_URI) != 0); if (__pyx_t_16) { /* "tinycss/speedups.pyx":151 * value = unicode_unescape(value) * elif type_ == URI: * value = match.group(1) # <<<<<<<<<<<<<< * if value and value[0] in '"\'': * value = value[1:-1] # Remove quotes */ if (unlikely(!__pyx_v_match)) { __Pyx_RaiseUnboundLocalError("match"); __PYX_ERR(0, 151, __pyx_L1_error) } __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_group); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 151, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":152 * elif type_ == URI: * value = match.group(1) * if value and value[0] in '"\'': # <<<<<<<<<<<<<< * value = value[1:-1] # Remove quotes * value = newline_unescape(value) */ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_value); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 152, __pyx_L1_error) if (__pyx_t_4) { } else { __pyx_t_16 = __pyx_t_4; goto __pyx_L24_bool_binop_done; } __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_value, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = (__Pyx_PyUnicode_ContainsTF(__pyx_t_1, __pyx_kp_u__9, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (__pyx_t_4 != 0); __pyx_t_16 = __pyx_t_3; __pyx_L24_bool_binop_done:; if (__pyx_t_16) { /* "tinycss/speedups.pyx":153 * value = match.group(1) * if value and value[0] in '"\'': * value = value[1:-1] # Remove quotes # <<<<<<<<<<<<<< * value = newline_unescape(value) * value = simple_unescape(value) */ __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_value, 1, -1L, NULL, NULL, &__pyx_slice__10, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":154 * if value and value[0] in '"\'': * value = value[1:-1] # Remove quotes * value = newline_unescape(value) # <<<<<<<<<<<<<< * value = simple_unescape(value) * value = unicode_unescape(value) */ __Pyx_INCREF(__pyx_v_newline_unescape); __pyx_t_8 = __pyx_v_newline_unescape; __pyx_t_11 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } if (!__pyx_t_11) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_value); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":152 * elif type_ == URI: * value = match.group(1) * if value and value[0] in '"\'': # <<<<<<<<<<<<<< * value = value[1:-1] # Remove quotes * value = newline_unescape(value) */ } /* "tinycss/speedups.pyx":155 * value = value[1:-1] # Remove quotes * value = newline_unescape(value) * value = simple_unescape(value) # <<<<<<<<<<<<<< * value = unicode_unescape(value) * elif type_ == STRING: */ __Pyx_INCREF(__pyx_v_simple_unescape); __pyx_t_8 = __pyx_v_simple_unescape; __pyx_t_13 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_13)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_13); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } if (!__pyx_t_13) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_value); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":156 * value = newline_unescape(value) * value = simple_unescape(value) * value = unicode_unescape(value) # <<<<<<<<<<<<<< * elif type_ == STRING: * value = css_value[1:-1] # Remove quotes */ __Pyx_INCREF(__pyx_v_unicode_unescape); __pyx_t_8 = __pyx_v_unicode_unescape; __pyx_t_11 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } if (!__pyx_t_11) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_value); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":150 * value = simple_unescape(css_value) * value = unicode_unescape(value) * elif type_ == URI: # <<<<<<<<<<<<<< * value = match.group(1) * if value and value[0] in '"\'': */ goto __pyx_L17; } /* "tinycss/speedups.pyx":157 * value = simple_unescape(value) * value = unicode_unescape(value) * elif type_ == STRING: # <<<<<<<<<<<<<< * value = css_value[1:-1] # Remove quotes * value = newline_unescape(value) */ __pyx_t_16 = ((__pyx_v_type_ == __pyx_v_STRING) != 0); if (__pyx_t_16) { /* "tinycss/speedups.pyx":158 * value = unicode_unescape(value) * elif type_ == STRING: * value = css_value[1:-1] # Remove quotes # <<<<<<<<<<<<<< * value = newline_unescape(value) * value = simple_unescape(value) */ __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_css_value, 1, -1L, NULL, NULL, &__pyx_slice__11, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":159 * elif type_ == STRING: * value = css_value[1:-1] # Remove quotes * value = newline_unescape(value) # <<<<<<<<<<<<<< * value = simple_unescape(value) * value = unicode_unescape(value) */ __Pyx_INCREF(__pyx_v_newline_unescape); __pyx_t_8 = __pyx_v_newline_unescape; __pyx_t_13 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_13)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_13); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } if (!__pyx_t_13) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 159, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_value); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":160 * value = css_value[1:-1] # Remove quotes * value = newline_unescape(value) * value = simple_unescape(value) # <<<<<<<<<<<<<< * value = unicode_unescape(value) * # BAD_STRING can only be one of: */ __Pyx_INCREF(__pyx_v_simple_unescape); __pyx_t_8 = __pyx_v_simple_unescape; __pyx_t_11 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } if (!__pyx_t_11) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_value); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":161 * value = newline_unescape(value) * value = simple_unescape(value) * value = unicode_unescape(value) # <<<<<<<<<<<<<< * # BAD_STRING can only be one of: * # * Unclosed string at the end of the stylesheet: */ __Pyx_INCREF(__pyx_v_unicode_unescape); __pyx_t_8 = __pyx_v_unicode_unescape; __pyx_t_13 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_13)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_13); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } if (!__pyx_t_13) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_value); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":157 * value = simple_unescape(value) * value = unicode_unescape(value) * elif type_ == STRING: # <<<<<<<<<<<<<< * value = css_value[1:-1] # Remove quotes * value = newline_unescape(value) */ goto __pyx_L17; } /* "tinycss/speedups.pyx":170 * # Leave it as a BAD_STRING, dont bother parsing it. * # See http://www.w3.org/TR/CSS21/syndata.html#parsing-errors * elif type_ == BAD_STRING and next_pos == source_len: # <<<<<<<<<<<<<< * type_name = 'STRING' * value = css_value[1:] # Remove quote */ __pyx_t_3 = ((__pyx_v_type_ == __pyx_v_BAD_STRING) != 0); if (__pyx_t_3) { } else { __pyx_t_16 = __pyx_t_3; goto __pyx_L26_bool_binop_done; } __pyx_t_3 = ((__pyx_v_next_pos == __pyx_v_source_len) != 0); __pyx_t_16 = __pyx_t_3; __pyx_L26_bool_binop_done:; if (__pyx_t_16) { /* "tinycss/speedups.pyx":171 * # See http://www.w3.org/TR/CSS21/syndata.html#parsing-errors * elif type_ == BAD_STRING and next_pos == source_len: * type_name = 'STRING' # <<<<<<<<<<<<<< * value = css_value[1:] # Remove quote * value = newline_unescape(value) */ __Pyx_INCREF(__pyx_n_u_STRING); __Pyx_DECREF_SET(__pyx_v_type_name, __pyx_n_u_STRING); /* "tinycss/speedups.pyx":172 * elif type_ == BAD_STRING and next_pos == source_len: * type_name = 'STRING' * value = css_value[1:] # Remove quote # <<<<<<<<<<<<<< * value = newline_unescape(value) * value = simple_unescape(value) */ __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_css_value, 1, 0, NULL, NULL, &__pyx_slice__12, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":173 * type_name = 'STRING' * value = css_value[1:] # Remove quote * value = newline_unescape(value) # <<<<<<<<<<<<<< * value = simple_unescape(value) * value = unicode_unescape(value) */ __Pyx_INCREF(__pyx_v_newline_unescape); __pyx_t_8 = __pyx_v_newline_unescape; __pyx_t_11 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } if (!__pyx_t_11) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_value); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":174 * value = css_value[1:] # Remove quote * value = newline_unescape(value) * value = simple_unescape(value) # <<<<<<<<<<<<<< * value = unicode_unescape(value) * else: */ __Pyx_INCREF(__pyx_v_simple_unescape); __pyx_t_8 = __pyx_v_simple_unescape; __pyx_t_13 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_13)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_13); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } if (!__pyx_t_13) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_value); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":175 * value = newline_unescape(value) * value = simple_unescape(value) * value = unicode_unescape(value) # <<<<<<<<<<<<<< * else: * value = css_value */ __Pyx_INCREF(__pyx_v_unicode_unescape); __pyx_t_8 = __pyx_v_unicode_unescape; __pyx_t_11 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_8, function); } } if (!__pyx_t_11) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 175, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 175, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL; __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_value); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 175, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":170 * # Leave it as a BAD_STRING, dont bother parsing it. * # See http://www.w3.org/TR/CSS21/syndata.html#parsing-errors * elif type_ == BAD_STRING and next_pos == source_len: # <<<<<<<<<<<<<< * type_name = 'STRING' * value = css_value[1:] # Remove quote */ goto __pyx_L17; } /* "tinycss/speedups.pyx":177 * value = unicode_unescape(value) * else: * value = css_value # <<<<<<<<<<<<<< * token = CToken(type_name, css_value, value, unit, line, column) * tokens.append(token) */ /*else*/ { __Pyx_INCREF(__pyx_v_css_value); __Pyx_XDECREF_SET(__pyx_v_value, __pyx_v_css_value); } __pyx_L17:; /* "tinycss/speedups.pyx":178 * else: * value = css_value * token = CToken(type_name, css_value, value, unit, line, column) # <<<<<<<<<<<<<< * tokens.append(token) * */ __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 178, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = PyInt_FromSsize_t(__pyx_v_column); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 178, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_13 = PyTuple_New(6); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 178, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_INCREF(__pyx_v_type_name); __Pyx_GIVEREF(__pyx_v_type_name); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_type_name); __Pyx_INCREF(__pyx_v_css_value); __Pyx_GIVEREF(__pyx_v_css_value); PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_v_css_value); __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_v_value); __Pyx_INCREF(__pyx_v_unit); __Pyx_GIVEREF(__pyx_v_unit); PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_v_unit); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_t_8); __pyx_t_1 = 0; __pyx_t_8 = 0; __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7tinycss_8speedups_CToken), __pyx_t_13, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 178, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_XDECREF_SET(__pyx_v_token, ((struct __pyx_obj_7tinycss_8speedups_CToken *)__pyx_t_8)); __pyx_t_8 = 0; /* "tinycss/speedups.pyx":179 * value = css_value * token = CToken(type_name, css_value, value, unit, line, column) * tokens.append(token) # <<<<<<<<<<<<<< * * pos = next_pos */ __pyx_t_17 = __Pyx_PyList_Append(__pyx_v_tokens, ((PyObject *)__pyx_v_token)); if (unlikely(__pyx_t_17 == -1)) __PYX_ERR(0, 179, __pyx_L1_error) /* "tinycss/speedups.pyx":126 * * # A BAD_COMMENT is a comment at EOF. Ignore it too. * if not (ignore_comments and type_ in (COMMENT, BAD_COMMENT)): # <<<<<<<<<<<<<< * # Parse numbers, extract strings and URIs, unescape * unit = None */ } /* "tinycss/speedups.pyx":181 * tokens.append(token) * * pos = next_pos # <<<<<<<<<<<<<< * newlines = list(find_newlines(css_value)) * if newlines: */ __pyx_v_pos = __pyx_v_next_pos; /* "tinycss/speedups.pyx":182 * * pos = next_pos * newlines = list(find_newlines(css_value)) # <<<<<<<<<<<<<< * if newlines: * line += len(newlines) */ __Pyx_INCREF(__pyx_v_find_newlines); __pyx_t_13 = __pyx_v_find_newlines; __pyx_t_1 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_13))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_13); if (likely(__pyx_t_1)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_13, function); } } if (!__pyx_t_1) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_v_css_value); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } else { __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_1); __pyx_t_1 = NULL; __Pyx_INCREF(__pyx_v_css_value); __Pyx_GIVEREF(__pyx_v_css_value); PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_css_value); __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_13 = PySequence_List(__pyx_t_8); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 182, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF_SET(__pyx_v_newlines, ((PyObject*)__pyx_t_13)); __pyx_t_13 = 0; /* "tinycss/speedups.pyx":183 * pos = next_pos * newlines = list(find_newlines(css_value)) * if newlines: # <<<<<<<<<<<<<< * line += len(newlines) * # Add 1 to have lines start at column 1, not 0 */ __pyx_t_16 = (__pyx_v_newlines != Py_None) && (PyList_GET_SIZE(__pyx_v_newlines) != 0); if (__pyx_t_16) { /* "tinycss/speedups.pyx":184 * newlines = list(find_newlines(css_value)) * if newlines: * line += len(newlines) # <<<<<<<<<<<<<< * # Add 1 to have lines start at column 1, not 0 * column = length - newlines[-1].end() + 1 */ __pyx_t_2 = PyList_GET_SIZE(__pyx_v_newlines); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 184, __pyx_L1_error) __pyx_v_line = (__pyx_v_line + __pyx_t_2); /* "tinycss/speedups.pyx":186 * line += len(newlines) * # Add 1 to have lines start at column 1, not 0 * column = length - newlines[-1].end() + 1 # <<<<<<<<<<<<<< * else: * column += length */ __pyx_t_13 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __pyx_t_11 = __Pyx_GetItemInt_List(__pyx_v_newlines, -1L, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_end); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_11 = NULL; if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); } } if (__pyx_t_11) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } else { __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 186, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Subtract(__pyx_t_13, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_8); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_v_column = __pyx_t_2; /* "tinycss/speedups.pyx":183 * pos = next_pos * newlines = list(find_newlines(css_value)) * if newlines: # <<<<<<<<<<<<<< * line += len(newlines) * # Add 1 to have lines start at column 1, not 0 */ goto __pyx_L28; } /* "tinycss/speedups.pyx":188 * column = length - newlines[-1].end() + 1 * else: * column += length # <<<<<<<<<<<<<< * return tokens */ /*else*/ { __pyx_v_column = (__pyx_v_column + __pyx_v_length); } __pyx_L28:; } /* "tinycss/speedups.pyx":189 * else: * column += length * return tokens # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_tokens); __pyx_r = __pyx_v_tokens; goto __pyx_L0; /* "tinycss/speedups.pyx":55 * * * def tokenize_flat(css_source, int ignore_comments=1): # <<<<<<<<<<<<<< * """ * :param css_source: */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_11); __Pyx_XDECREF(__pyx_t_12); __Pyx_XDECREF(__pyx_t_13); __Pyx_AddTraceback("tinycss.speedups.tokenize_flat", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_tokens_dispatch); __Pyx_XDECREF(__pyx_v_compiled_token_indexes); __Pyx_XDECREF(__pyx_v_compiled_tokens); __Pyx_XDECREF(__pyx_v_unicode_unescape); __Pyx_XDECREF(__pyx_v_newline_unescape); __Pyx_XDECREF(__pyx_v_simple_unescape); __Pyx_XDECREF(__pyx_v_find_newlines); __Pyx_XDECREF((PyObject *)__pyx_v_token); __Pyx_XDECREF(__pyx_v_tokens); __Pyx_XDECREF(__pyx_v_char); __Pyx_XDECREF(__pyx_v_type_name); __Pyx_XDECREF(__pyx_v_css_value); __Pyx_XDECREF(__pyx_v_regexp); __Pyx_XDECREF(__pyx_v_match); __Pyx_XDECREF(__pyx_v_unit); __Pyx_XDECREF(__pyx_v_value); __Pyx_XDECREF(__pyx_v_newlines); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_tp_new_7tinycss_8speedups_CToken(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_7tinycss_8speedups_CToken *p; PyObject *o; if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { o = (*t->tp_alloc)(t, 0); } else { o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); } if (unlikely(!o)) return 0; p = ((struct __pyx_obj_7tinycss_8speedups_CToken *)o); p->type = Py_None; Py_INCREF(Py_None); p->_as_css = Py_None; Py_INCREF(Py_None); p->value = Py_None; Py_INCREF(Py_None); p->unit = Py_None; Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_7tinycss_8speedups_CToken(PyObject *o) { struct __pyx_obj_7tinycss_8speedups_CToken *p = (struct __pyx_obj_7tinycss_8speedups_CToken *)o; #if PY_VERSION_HEX >= 0x030400a1 if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif PyObject_GC_UnTrack(o); Py_CLEAR(p->type); Py_CLEAR(p->_as_css); Py_CLEAR(p->value); Py_CLEAR(p->unit); (*Py_TYPE(o)->tp_free)(o); } static int __pyx_tp_traverse_7tinycss_8speedups_CToken(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_7tinycss_8speedups_CToken *p = (struct __pyx_obj_7tinycss_8speedups_CToken *)o; if (p->type) { e = (*v)(p->type, a); if (e) return e; } if (p->_as_css) { e = (*v)(p->_as_css, a); if (e) return e; } if (p->value) { e = (*v)(p->value, a); if (e) return e; } if (p->unit) { e = (*v)(p->unit, a); if (e) return e; } return 0; } static int __pyx_tp_clear_7tinycss_8speedups_CToken(PyObject *o) { PyObject* tmp; struct __pyx_obj_7tinycss_8speedups_CToken *p = (struct __pyx_obj_7tinycss_8speedups_CToken *)o; tmp = ((PyObject*)p->type); p->type = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->_as_css); p->_as_css = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->value); p->value = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->unit); p->unit = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyObject *__pyx_getprop_7tinycss_8speedups_6CToken_type(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_7tinycss_8speedups_6CToken_4type_1__get__(o); } static int __pyx_setprop_7tinycss_8speedups_6CToken_type(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_7tinycss_8speedups_6CToken_4type_3__set__(o, v); } else { return __pyx_pw_7tinycss_8speedups_6CToken_4type_5__del__(o); } } static PyObject *__pyx_getprop_7tinycss_8speedups_6CToken__as_css(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_7tinycss_8speedups_6CToken_7_as_css_1__get__(o); } static int __pyx_setprop_7tinycss_8speedups_6CToken__as_css(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_7tinycss_8speedups_6CToken_7_as_css_3__set__(o, v); } else { return __pyx_pw_7tinycss_8speedups_6CToken_7_as_css_5__del__(o); } } static PyObject *__pyx_getprop_7tinycss_8speedups_6CToken_value(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_7tinycss_8speedups_6CToken_5value_1__get__(o); } static int __pyx_setprop_7tinycss_8speedups_6CToken_value(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_7tinycss_8speedups_6CToken_5value_3__set__(o, v); } else { return __pyx_pw_7tinycss_8speedups_6CToken_5value_5__del__(o); } } static PyObject *__pyx_getprop_7tinycss_8speedups_6CToken_unit(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_7tinycss_8speedups_6CToken_4unit_1__get__(o); } static int __pyx_setprop_7tinycss_8speedups_6CToken_unit(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_7tinycss_8speedups_6CToken_4unit_3__set__(o, v); } else { return __pyx_pw_7tinycss_8speedups_6CToken_4unit_5__del__(o); } } static PyObject *__pyx_getprop_7tinycss_8speedups_6CToken_line(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_7tinycss_8speedups_6CToken_4line_1__get__(o); } static int __pyx_setprop_7tinycss_8speedups_6CToken_line(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_7tinycss_8speedups_6CToken_4line_3__set__(o, v); } else { PyErr_SetString(PyExc_NotImplementedError, "__del__"); return -1; } } static PyObject *__pyx_getprop_7tinycss_8speedups_6CToken_column(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_7tinycss_8speedups_6CToken_6column_1__get__(o); } static int __pyx_setprop_7tinycss_8speedups_6CToken_column(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_7tinycss_8speedups_6CToken_6column_3__set__(o, v); } else { PyErr_SetString(PyExc_NotImplementedError, "__del__"); return -1; } } static PyMethodDef __pyx_methods_7tinycss_8speedups_CToken[] = { {"as_css", (PyCFunction)__pyx_pw_7tinycss_8speedups_6CToken_3as_css, METH_NOARGS, __pyx_doc_7tinycss_8speedups_6CToken_2as_css}, {0, 0, 0, 0} }; static struct PyGetSetDef __pyx_getsets_7tinycss_8speedups_CToken[] = { {(char *)"type", __pyx_getprop_7tinycss_8speedups_6CToken_type, __pyx_setprop_7tinycss_8speedups_6CToken_type, (char *)0, 0}, {(char *)"_as_css", __pyx_getprop_7tinycss_8speedups_6CToken__as_css, __pyx_setprop_7tinycss_8speedups_6CToken__as_css, (char *)0, 0}, {(char *)"value", __pyx_getprop_7tinycss_8speedups_6CToken_value, __pyx_setprop_7tinycss_8speedups_6CToken_value, (char *)0, 0}, {(char *)"unit", __pyx_getprop_7tinycss_8speedups_6CToken_unit, __pyx_setprop_7tinycss_8speedups_6CToken_unit, (char *)0, 0}, {(char *)"line", __pyx_getprop_7tinycss_8speedups_6CToken_line, __pyx_setprop_7tinycss_8speedups_6CToken_line, (char *)0, 0}, {(char *)"column", __pyx_getprop_7tinycss_8speedups_6CToken_column, __pyx_setprop_7tinycss_8speedups_6CToken_column, (char *)0, 0}, {0, 0, 0, 0, 0} }; static PyTypeObject __pyx_type_7tinycss_8speedups_CToken = { PyVarObject_HEAD_INIT(0, 0) "tinycss.speedups.CToken", /*tp_name*/ sizeof(struct __pyx_obj_7tinycss_8speedups_CToken), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_7tinycss_8speedups_CToken, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #endif #if PY_MAJOR_VERSION >= 3 0, /*tp_as_async*/ #endif __pyx_pw_7tinycss_8speedups_6CToken_5__repr__, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ "A token built by the Cython speedups. Identical to\n :class:`~.token_data.Token`.\n\n ", /*tp_doc*/ __pyx_tp_traverse_7tinycss_8speedups_CToken, /*tp_traverse*/ __pyx_tp_clear_7tinycss_8speedups_CToken, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_7tinycss_8speedups_CToken, /*tp_methods*/ 0, /*tp_members*/ __pyx_getsets_7tinycss_8speedups_CToken, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ __pyx_pw_7tinycss_8speedups_6CToken_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_7tinycss_8speedups_CToken, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif }; static struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *__pyx_freelist_7tinycss_8speedups___pyx_scope_struct__genexpr[8]; static int __pyx_freecount_7tinycss_8speedups___pyx_scope_struct__genexpr = 0; static PyObject *__pyx_tp_new_7tinycss_8speedups___pyx_scope_struct__genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o; if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_7tinycss_8speedups___pyx_scope_struct__genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr)))) { o = (PyObject*)__pyx_freelist_7tinycss_8speedups___pyx_scope_struct__genexpr[--__pyx_freecount_7tinycss_8speedups___pyx_scope_struct__genexpr]; memset(o, 0, sizeof(struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr)); (void) PyObject_INIT(o, t); PyObject_GC_Track(o); } else { o = (*t->tp_alloc)(t, 0); if (unlikely(!o)) return 0; } return o; } static void __pyx_tp_dealloc_7tinycss_8speedups___pyx_scope_struct__genexpr(PyObject *o) { struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *p = (struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *)o; PyObject_GC_UnTrack(o); Py_CLEAR(p->__pyx_v_i); Py_CLEAR(p->__pyx_v_name); Py_CLEAR(p->__pyx_v_regexp); if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_7tinycss_8speedups___pyx_scope_struct__genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr)))) { __pyx_freelist_7tinycss_8speedups___pyx_scope_struct__genexpr[__pyx_freecount_7tinycss_8speedups___pyx_scope_struct__genexpr++] = ((struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *)o); } else { (*Py_TYPE(o)->tp_free)(o); } } static int __pyx_tp_traverse_7tinycss_8speedups___pyx_scope_struct__genexpr(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *p = (struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *)o; if (p->__pyx_v_i) { e = (*v)(p->__pyx_v_i, a); if (e) return e; } if (p->__pyx_v_name) { e = (*v)(p->__pyx_v_name, a); if (e) return e; } if (p->__pyx_v_regexp) { e = (*v)(p->__pyx_v_regexp, a); if (e) return e; } return 0; } static int __pyx_tp_clear_7tinycss_8speedups___pyx_scope_struct__genexpr(PyObject *o) { PyObject* tmp; struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *p = (struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr *)o; tmp = ((PyObject*)p->__pyx_v_i); p->__pyx_v_i = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_name); p->__pyx_v_name = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_regexp); p->__pyx_v_regexp = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } static PyTypeObject __pyx_type_7tinycss_8speedups___pyx_scope_struct__genexpr = { PyVarObject_HEAD_INIT(0, 0) "tinycss.speedups.__pyx_scope_struct__genexpr", /*tp_name*/ sizeof(struct __pyx_obj_7tinycss_8speedups___pyx_scope_struct__genexpr), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_7tinycss_8speedups___pyx_scope_struct__genexpr, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #endif #if PY_MAJOR_VERSION >= 3 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ __pyx_tp_traverse_7tinycss_8speedups___pyx_scope_struct__genexpr, /*tp_traverse*/ __pyx_tp_clear_7tinycss_8speedups___pyx_scope_struct__genexpr, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ 0, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_7tinycss_8speedups___pyx_scope_struct__genexpr, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif }; static PyMethodDef __pyx_methods[] = { {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef __pyx_moduledef = { #if PY_VERSION_HEX < 0x03020000 { PyObject_HEAD_INIT(NULL) NULL, 0, NULL }, #else PyModuleDef_HEAD_INIT, #endif "speedups", __pyx_k_tinycss_speedups_Cython_module, /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0}, {&__pyx_n_s_ATKEYWORD, __pyx_k_ATKEYWORD, sizeof(__pyx_k_ATKEYWORD), 0, 0, 1, 1}, {&__pyx_n_u_ATKEYWORD, __pyx_k_ATKEYWORD, sizeof(__pyx_k_ATKEYWORD), 0, 1, 0, 1}, {&__pyx_n_s_BAD_COMMENT, __pyx_k_BAD_COMMENT, sizeof(__pyx_k_BAD_COMMENT), 0, 0, 1, 1}, {&__pyx_n_u_BAD_COMMENT, __pyx_k_BAD_COMMENT, sizeof(__pyx_k_BAD_COMMENT), 0, 1, 0, 1}, {&__pyx_n_s_BAD_STRING, __pyx_k_BAD_STRING, sizeof(__pyx_k_BAD_STRING), 0, 0, 1, 1}, {&__pyx_n_u_BAD_STRING, __pyx_k_BAD_STRING, sizeof(__pyx_k_BAD_STRING), 0, 1, 0, 1}, {&__pyx_n_s_COMMENT, __pyx_k_COMMENT, sizeof(__pyx_k_COMMENT), 0, 0, 1, 1}, {&__pyx_n_u_COMMENT, __pyx_k_COMMENT, sizeof(__pyx_k_COMMENT), 0, 1, 0, 1}, {&__pyx_n_s_COMPILED_TOKEN_INDEXES, __pyx_k_COMPILED_TOKEN_INDEXES, sizeof(__pyx_k_COMPILED_TOKEN_INDEXES), 0, 0, 1, 1}, {&__pyx_n_s_COMPILED_TOKEN_REGEXPS, __pyx_k_COMPILED_TOKEN_REGEXPS, sizeof(__pyx_k_COMPILED_TOKEN_REGEXPS), 0, 0, 1, 1}, {&__pyx_n_s_DELIM, __pyx_k_DELIM, sizeof(__pyx_k_DELIM), 0, 0, 1, 1}, {&__pyx_n_u_DELIM, __pyx_k_DELIM, sizeof(__pyx_k_DELIM), 0, 1, 0, 1}, {&__pyx_n_s_DIMENSION, __pyx_k_DIMENSION, sizeof(__pyx_k_DIMENSION), 0, 0, 1, 1}, {&__pyx_n_u_DIMENSION, __pyx_k_DIMENSION, sizeof(__pyx_k_DIMENSION), 0, 1, 0, 1}, {&__pyx_n_s_FIND_NEWLINES, __pyx_k_FIND_NEWLINES, sizeof(__pyx_k_FIND_NEWLINES), 0, 0, 1, 1}, {&__pyx_n_s_FUNCTION, __pyx_k_FUNCTION, sizeof(__pyx_k_FUNCTION), 0, 0, 1, 1}, {&__pyx_n_u_FUNCTION, __pyx_k_FUNCTION, sizeof(__pyx_k_FUNCTION), 0, 1, 0, 1}, {&__pyx_n_s_HASH, __pyx_k_HASH, sizeof(__pyx_k_HASH), 0, 0, 1, 1}, {&__pyx_n_u_HASH, __pyx_k_HASH, sizeof(__pyx_k_HASH), 0, 1, 0, 1}, {&__pyx_n_s_IDENT, __pyx_k_IDENT, sizeof(__pyx_k_IDENT), 0, 0, 1, 1}, {&__pyx_n_u_IDENT, __pyx_k_IDENT, sizeof(__pyx_k_IDENT), 0, 1, 0, 1}, {&__pyx_n_u_INTEGER, __pyx_k_INTEGER, sizeof(__pyx_k_INTEGER), 0, 1, 0, 1}, {&__pyx_n_s_NEWLINE_UNESCAPE, __pyx_k_NEWLINE_UNESCAPE, sizeof(__pyx_k_NEWLINE_UNESCAPE), 0, 0, 1, 1}, {&__pyx_n_s_NUMBER, __pyx_k_NUMBER, sizeof(__pyx_k_NUMBER), 0, 0, 1, 1}, {&__pyx_n_u_NUMBER, __pyx_k_NUMBER, sizeof(__pyx_k_NUMBER), 0, 1, 0, 1}, {&__pyx_n_s_PERCENTAGE, __pyx_k_PERCENTAGE, sizeof(__pyx_k_PERCENTAGE), 0, 0, 1, 1}, {&__pyx_n_u_PERCENTAGE, __pyx_k_PERCENTAGE, sizeof(__pyx_k_PERCENTAGE), 0, 1, 0, 1}, {&__pyx_n_s_SIMPLE_UNESCAPE, __pyx_k_SIMPLE_UNESCAPE, sizeof(__pyx_k_SIMPLE_UNESCAPE), 0, 0, 1, 1}, {&__pyx_n_s_STRING, __pyx_k_STRING, sizeof(__pyx_k_STRING), 0, 0, 1, 1}, {&__pyx_n_u_STRING, __pyx_k_STRING, sizeof(__pyx_k_STRING), 0, 1, 0, 1}, {&__pyx_n_s_TOKEN_DISPATCH, __pyx_k_TOKEN_DISPATCH, sizeof(__pyx_k_TOKEN_DISPATCH), 0, 0, 1, 1}, {&__pyx_kp_u_Token_0_type_at_0_line_0_column, __pyx_k_Token_0_type_at_0_line_0_column, sizeof(__pyx_k_Token_0_type_at_0_line_0_column), 0, 1, 0, 0}, {&__pyx_n_s_UNICODE_UNESCAPE, __pyx_k_UNICODE_UNESCAPE, sizeof(__pyx_k_UNICODE_UNESCAPE), 0, 0, 1, 1}, {&__pyx_n_s_URI, __pyx_k_URI, sizeof(__pyx_k_URI), 0, 0, 1, 1}, {&__pyx_n_u_URI, __pyx_k_URI, sizeof(__pyx_k_URI), 0, 1, 0, 1}, {&__pyx_kp_u__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 1, 0, 0}, {&__pyx_kp_u__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 1, 0, 0}, {&__pyx_kp_u__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 1, 0, 0}, {&__pyx_kp_u__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 1, 0, 0}, {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, {&__pyx_n_s_char, __pyx_k_char, sizeof(__pyx_k_char), 0, 0, 1, 1}, {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, {&__pyx_n_s_codepoint, __pyx_k_codepoint, sizeof(__pyx_k_codepoint), 0, 0, 1, 1}, {&__pyx_n_s_column, __pyx_k_column, sizeof(__pyx_k_column), 0, 0, 1, 1}, {&__pyx_n_s_compiled_token_indexes, __pyx_k_compiled_token_indexes, sizeof(__pyx_k_compiled_token_indexes), 0, 0, 1, 1}, {&__pyx_n_s_compiled_tokens, __pyx_k_compiled_tokens, sizeof(__pyx_k_compiled_tokens), 0, 0, 1, 1}, {&__pyx_n_s_css_source, __pyx_k_css_source, sizeof(__pyx_k_css_source), 0, 0, 1, 1}, {&__pyx_n_s_css_value, __pyx_k_css_value, sizeof(__pyx_k_css_value), 0, 0, 1, 1}, {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, {&__pyx_n_s_find_newlines, __pyx_k_find_newlines, sizeof(__pyx_k_find_newlines), 0, 0, 1, 1}, {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1}, {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1}, {&__pyx_n_s_group, __pyx_k_group, sizeof(__pyx_k_group), 0, 0, 1, 1}, {&__pyx_kp_s_home_lize_Informatique_tinycss, __pyx_k_home_lize_Informatique_tinycss, sizeof(__pyx_k_home_lize_Informatique_tinycss), 0, 0, 1, 0}, {&__pyx_n_s_ignore_comments, __pyx_k_ignore_comments, sizeof(__pyx_k_ignore_comments), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_is_container, __pyx_k_is_container, sizeof(__pyx_k_is_container), 0, 0, 1, 1}, {&__pyx_n_s_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 0, 1, 1}, {&__pyx_n_s_line, __pyx_k_line, sizeof(__pyx_k_line), 0, 0, 1, 1}, {&__pyx_n_s_lower, __pyx_k_lower, sizeof(__pyx_k_lower), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_match, __pyx_k_match, sizeof(__pyx_k_match), 0, 0, 1, 1}, {&__pyx_n_s_n_tokens, __pyx_k_n_tokens, sizeof(__pyx_k_n_tokens), 0, 0, 1, 1}, {&__pyx_n_s_newline_unescape, __pyx_k_newline_unescape, sizeof(__pyx_k_newline_unescape), 0, 0, 1, 1}, {&__pyx_n_s_newlines, __pyx_k_newlines, sizeof(__pyx_k_newlines), 0, 0, 1, 1}, {&__pyx_n_s_next_pos, __pyx_k_next_pos, sizeof(__pyx_k_next_pos), 0, 0, 1, 1}, {&__pyx_n_s_pos, __pyx_k_pos, sizeof(__pyx_k_pos), 0, 0, 1, 1}, {&__pyx_n_s_regexp, __pyx_k_regexp, sizeof(__pyx_k_regexp), 0, 0, 1, 1}, {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1}, {&__pyx_n_s_simple_unescape, __pyx_k_simple_unescape, sizeof(__pyx_k_simple_unescape), 0, 0, 1, 1}, {&__pyx_n_s_source_len, __pyx_k_source_len, sizeof(__pyx_k_source_len), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1}, {&__pyx_n_s_tinycss_speedups, __pyx_k_tinycss_speedups, sizeof(__pyx_k_tinycss_speedups), 0, 0, 1, 1}, {&__pyx_n_s_token, __pyx_k_token, sizeof(__pyx_k_token), 0, 0, 1, 1}, {&__pyx_n_s_token_data, __pyx_k_token_data, sizeof(__pyx_k_token_data), 0, 0, 1, 1}, {&__pyx_n_s_tokenize_flat, __pyx_k_tokenize_flat, sizeof(__pyx_k_tokenize_flat), 0, 0, 1, 1}, {&__pyx_n_s_tokens, __pyx_k_tokens, sizeof(__pyx_k_tokens), 0, 0, 1, 1}, {&__pyx_n_s_tokens_dispatch, __pyx_k_tokens_dispatch, sizeof(__pyx_k_tokens_dispatch), 0, 0, 1, 1}, {&__pyx_n_s_type, __pyx_k_type, sizeof(__pyx_k_type), 0, 0, 1, 1}, {&__pyx_n_s_type_name, __pyx_k_type_name, sizeof(__pyx_k_type_name), 0, 0, 1, 1}, {&__pyx_n_s_unicode_unescape, __pyx_k_unicode_unescape, sizeof(__pyx_k_unicode_unescape), 0, 0, 1, 1}, {&__pyx_n_s_unit, __pyx_k_unit, sizeof(__pyx_k_unit), 0, 0, 1, 1}, {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 22, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); /* "tinycss/speedups.pyx":130 * unit = None * if type_ == DIMENSION: * value = match.group(1) # <<<<<<<<<<<<<< * value = float(value) if '.' in value else int(value) * unit = match.group(2) */ __pyx_tuple__3 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 130, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3); /* "tinycss/speedups.pyx":132 * value = match.group(1) * value = float(value) if '.' in value else int(value) * unit = match.group(2) # <<<<<<<<<<<<<< * unit = simple_unescape(unit) * unit = unicode_unescape(unit) */ __pyx_tuple__5 = PyTuple_Pack(1, __pyx_int_2); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 132, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__5); /* "tinycss/speedups.pyx":137 * unit = unit.lower() # normalize * elif type_ == PERCENTAGE: * value = css_value[:-1] # <<<<<<<<<<<<<< * value = float(value) if '.' in value else int(value) * unit = '%' */ __pyx_slice__6 = PySlice_New(Py_None, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__6)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_slice__6); __Pyx_GIVEREF(__pyx_slice__6); /* "tinycss/speedups.pyx":151 * value = unicode_unescape(value) * elif type_ == URI: * value = match.group(1) # <<<<<<<<<<<<<< * if value and value[0] in '"\'': * value = value[1:-1] # Remove quotes */ __pyx_tuple__8 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 151, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__8); __Pyx_GIVEREF(__pyx_tuple__8); /* "tinycss/speedups.pyx":153 * value = match.group(1) * if value and value[0] in '"\'': * value = value[1:-1] # Remove quotes # <<<<<<<<<<<<<< * value = newline_unescape(value) * value = simple_unescape(value) */ __pyx_slice__10 = PySlice_New(__pyx_int_1, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__10)) __PYX_ERR(0, 153, __pyx_L1_error) __Pyx_GOTREF(__pyx_slice__10); __Pyx_GIVEREF(__pyx_slice__10); /* "tinycss/speedups.pyx":158 * value = unicode_unescape(value) * elif type_ == STRING: * value = css_value[1:-1] # Remove quotes # <<<<<<<<<<<<<< * value = newline_unescape(value) * value = simple_unescape(value) */ __pyx_slice__11 = PySlice_New(__pyx_int_1, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__11)) __PYX_ERR(0, 158, __pyx_L1_error) __Pyx_GOTREF(__pyx_slice__11); __Pyx_GIVEREF(__pyx_slice__11); /* "tinycss/speedups.pyx":172 * elif type_ == BAD_STRING and next_pos == source_len: * type_name = 'STRING' * value = css_value[1:] # Remove quote # <<<<<<<<<<<<<< * value = newline_unescape(value) * value = simple_unescape(value) */ __pyx_slice__12 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__12)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_slice__12); __Pyx_GIVEREF(__pyx_slice__12); /* "tinycss/speedups.pyx":55 * * * def tokenize_flat(css_source, int ignore_comments=1): # <<<<<<<<<<<<<< * """ * :param css_source: */ __pyx_tuple__13 = PyTuple_Pack(41, __pyx_n_s_css_source, __pyx_n_s_ignore_comments, __pyx_n_s_tokens_dispatch, __pyx_n_s_compiled_token_indexes, __pyx_n_s_compiled_tokens, __pyx_n_s_unicode_unescape, __pyx_n_s_newline_unescape, __pyx_n_s_simple_unescape, __pyx_n_s_find_newlines, __pyx_n_s_BAD_COMMENT, __pyx_n_s_BAD_STRING, __pyx_n_s_PERCENTAGE, __pyx_n_s_DIMENSION, __pyx_n_s_ATKEYWORD, __pyx_n_s_FUNCTION, __pyx_n_s_COMMENT, __pyx_n_s_NUMBER, __pyx_n_s_STRING, __pyx_n_s_IDENT, __pyx_n_s_HASH, __pyx_n_s_URI, __pyx_n_s_DELIM, __pyx_n_s_pos, __pyx_n_s_line, __pyx_n_s_column, __pyx_n_s_source_len, __pyx_n_s_n_tokens, __pyx_n_s_length, __pyx_n_s_next_pos, __pyx_n_s_type, __pyx_n_s_token, __pyx_n_s_tokens, __pyx_n_s_char, __pyx_n_s_type_name, __pyx_n_s_css_value, __pyx_n_s_codepoint, __pyx_n_s_regexp, __pyx_n_s_match, __pyx_n_s_unit, __pyx_n_s_value, __pyx_n_s_newlines); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 55, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__13); __Pyx_GIVEREF(__pyx_tuple__13); __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(2, 0, 41, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_lize_Informatique_tinycss, __pyx_n_s_tokenize_flat, 55, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 55, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; __Pyx_RefNannyFinishContext(); return -1; } static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } #if PY_MAJOR_VERSION < 3 PyMODINIT_FUNC initspeedups(void); /*proto*/ PyMODINIT_FUNC initspeedups(void) #else PyMODINIT_FUNC PyInit_speedups(void); /*proto*/ PyMODINIT_FUNC PyInit_speedups(void) #endif { PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; __Pyx_RefNannyDeclarations #if CYTHON_REFNANNY __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); if (!__Pyx_RefNanny) { PyErr_Clear(); __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); if (!__Pyx_RefNanny) Py_FatalError("failed to import 'refnanny' module"); } #endif __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_speedups(void)", 0); if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pyx_CyFunction_USED if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Coroutine_USED if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_StopAsyncIteration_USED if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS #ifdef WITH_THREAD /* Python build with threading support? */ PyEval_InitThreads(); #endif #endif /*--- Module creation code ---*/ #if PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4("speedups", __pyx_methods, __pyx_k_tinycss_speedups_Cython_module, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_d); __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) #if CYTHON_COMPILING_IN_PYPY Py_INCREF(__pyx_b); #endif if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif if (__pyx_module_is_main_tinycss__speedups) { if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) } #if PY_MAJOR_VERSION >= 3 { PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) if (!PyDict_GetItemString(modules, "tinycss.speedups")) { if (unlikely(PyDict_SetItemString(modules, "tinycss.speedups", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) } } #endif /*--- Builtin init code ---*/ if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Constants init code ---*/ if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Global init code ---*/ /*--- Variable export code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ if (PyType_Ready(&__pyx_type_7tinycss_8speedups_CToken) < 0) __PYX_ERR(0, 25, __pyx_L1_error) __pyx_type_7tinycss_8speedups_CToken.tp_print = 0; if (PyObject_SetAttrString(__pyx_m, "CToken", (PyObject *)&__pyx_type_7tinycss_8speedups_CToken) < 0) __PYX_ERR(0, 25, __pyx_L1_error) __pyx_ptype_7tinycss_8speedups_CToken = &__pyx_type_7tinycss_8speedups_CToken; if (PyType_Ready(&__pyx_type_7tinycss_8speedups___pyx_scope_struct__genexpr) < 0) __PYX_ERR(0, 22, __pyx_L1_error) __pyx_type_7tinycss_8speedups___pyx_scope_struct__genexpr.tp_print = 0; __pyx_ptype_7tinycss_8speedups___pyx_scope_struct__genexpr = &__pyx_type_7tinycss_8speedups___pyx_scope_struct__genexpr; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /* "tinycss/speedups.pyx":17 * * from .token_data import ( * COMPILED_TOKEN_REGEXPS, UNICODE_UNESCAPE, NEWLINE_UNESCAPE, # <<<<<<<<<<<<<< * SIMPLE_UNESCAPE, FIND_NEWLINES, TOKEN_DISPATCH) * */ __pyx_t_1 = PyList_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_COMPILED_TOKEN_REGEXPS); __Pyx_GIVEREF(__pyx_n_s_COMPILED_TOKEN_REGEXPS); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_COMPILED_TOKEN_REGEXPS); __Pyx_INCREF(__pyx_n_s_UNICODE_UNESCAPE); __Pyx_GIVEREF(__pyx_n_s_UNICODE_UNESCAPE); PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_UNICODE_UNESCAPE); __Pyx_INCREF(__pyx_n_s_NEWLINE_UNESCAPE); __Pyx_GIVEREF(__pyx_n_s_NEWLINE_UNESCAPE); PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_NEWLINE_UNESCAPE); __Pyx_INCREF(__pyx_n_s_SIMPLE_UNESCAPE); __Pyx_GIVEREF(__pyx_n_s_SIMPLE_UNESCAPE); PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_SIMPLE_UNESCAPE); __Pyx_INCREF(__pyx_n_s_FIND_NEWLINES); __Pyx_GIVEREF(__pyx_n_s_FIND_NEWLINES); PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_FIND_NEWLINES); __Pyx_INCREF(__pyx_n_s_TOKEN_DISPATCH); __Pyx_GIVEREF(__pyx_n_s_TOKEN_DISPATCH); PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_s_TOKEN_DISPATCH); /* "tinycss/speedups.pyx":16 * from __future__ import unicode_literals * * from .token_data import ( # <<<<<<<<<<<<<< * COMPILED_TOKEN_REGEXPS, UNICODE_UNESCAPE, NEWLINE_UNESCAPE, * SIMPLE_UNESCAPE, FIND_NEWLINES, TOKEN_DISPATCH) */ __pyx_t_2 = __Pyx_Import(__pyx_n_s_token_data, __pyx_t_1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_COMPILED_TOKEN_REGEXPS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_COMPILED_TOKEN_REGEXPS, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_UNICODE_UNESCAPE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_UNICODE_UNESCAPE, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_NEWLINE_UNESCAPE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_NEWLINE_UNESCAPE, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_SIMPLE_UNESCAPE); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_SIMPLE_UNESCAPE, __pyx_t_1) < 0) __PYX_ERR(0, 18, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_FIND_NEWLINES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_FIND_NEWLINES, __pyx_t_1) < 0) __PYX_ERR(0, 18, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_TOKEN_DISPATCH); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_TOKEN_DISPATCH, __pyx_t_1) < 0) __PYX_ERR(0, 18, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "tinycss/speedups.pyx":22 * * COMPILED_TOKEN_INDEXES = dict( * (name, i) for i, (name, regexp) in enumerate(COMPILED_TOKEN_REGEXPS)) # <<<<<<<<<<<<<< * * */ __pyx_t_2 = __pyx_pf_7tinycss_8speedups_2genexpr(NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* "tinycss/speedups.pyx":21 * * * COMPILED_TOKEN_INDEXES = dict( # <<<<<<<<<<<<<< * (name, i) for i, (name, regexp) in enumerate(COMPILED_TOKEN_REGEXPS)) * */ __pyx_t_1 = __Pyx_Generator_Next(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyDict_SetItem(__pyx_d, __pyx_n_s_COMPILED_TOKEN_INDEXES, __pyx_t_1) < 0) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":30 * * """ * is_container = False # <<<<<<<<<<<<<< * * cdef public object type, _as_css, value, unit */ if (PyDict_SetItem((PyObject *)__pyx_ptype_7tinycss_8speedups_CToken->tp_dict, __pyx_n_s_is_container, Py_False) < 0) __PYX_ERR(0, 30, __pyx_L1_error) PyType_Modified(__pyx_ptype_7tinycss_8speedups_CToken); /* "tinycss/speedups.pyx":55 * * * def tokenize_flat(css_source, int ignore_comments=1): # <<<<<<<<<<<<<< * """ * :param css_source: */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7tinycss_8speedups_1tokenize_flat, NULL, __pyx_n_s_tinycss_speedups); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_tokenize_flat, __pyx_t_1) < 0) __PYX_ERR(0, 55, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "tinycss/speedups.pyx":1 * # coding: utf-8 # <<<<<<<<<<<<<< * """ * tinycss.speedups */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /*--- Wrapped vars code ---*/ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init tinycss.speedups", __pyx_clineno, __pyx_lineno, __pyx_filename); } Py_DECREF(__pyx_m); __pyx_m = 0; } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init tinycss.speedups"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); #if PY_MAJOR_VERSION < 3 return; #else return __pyx_m; #endif } /* --- Runtime support code --- */ /* Refnanny */ #if CYTHON_REFNANNY static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; m = PyImport_ImportModule((char *)modname); if (!m) goto end; p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: Py_XDECREF(p); Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; } #endif /* GetBuiltinName */ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); if (unlikely(!result)) { PyErr_Format(PyExc_NameError, #if PY_MAJOR_VERSION >= 3 "name '%U' is not defined", name); #else "name '%.200s' is not defined", PyString_AS_STRING(name)); #endif } return result; } /* GetModuleGlobalName */ static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { PyObject *result; #if CYTHON_COMPILING_IN_CPYTHON result = PyDict_GetItem(__pyx_d, name); if (likely(result)) { Py_INCREF(result); } else { #else result = PyObject_GetItem(__pyx_d, name); if (!result) { PyErr_Clear(); #endif result = __Pyx_GetBuiltinName(name); } return result; } /* RaiseTooManyValuesToUnpack */ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { PyErr_Format(PyExc_ValueError, "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); } /* RaiseNeedMoreValuesToUnpack */ static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack", index, (index == 1) ? "" : "s"); } /* IterFinish */ static CYTHON_INLINE int __Pyx_IterFinish(void) { #if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); PyObject* exc_type = tstate->curexc_type; if (unlikely(exc_type)) { if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) { PyObject *exc_value, *exc_tb; exc_value = tstate->curexc_value; exc_tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; Py_DECREF(exc_type); Py_XDECREF(exc_value); Py_XDECREF(exc_tb); return 0; } else { return -1; } } return 0; #else if (unlikely(PyErr_Occurred())) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { PyErr_Clear(); return 0; } else { return -1; } } return 0; #endif } /* UnpackItemEndCheck */ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { if (unlikely(retval)) { Py_DECREF(retval); __Pyx_RaiseTooManyValuesError(expected); return -1; } else { return __Pyx_IterFinish(); } return 0; } /* PyIntBinop */ #if CYTHON_COMPILING_IN_CPYTHON static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) { #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(op1))) { const long b = intval; long x; long a = PyInt_AS_LONG(op1); x = (long)((unsigned long)a + b); if (likely((x^a) >= 0 || (x^b) >= 0)) return PyInt_FromLong(x); return PyLong_Type.tp_as_number->nb_add(op1, op2); } #endif #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3 if (likely(PyLong_CheckExact(op1))) { const long b = intval; long a, x; const PY_LONG_LONG llb = intval; PY_LONG_LONG lla, llx; const digit* digits = ((PyLongObject*)op1)->ob_digit; const Py_ssize_t size = Py_SIZE(op1); if (likely(__Pyx_sst_abs(size) <= 1)) { a = likely(size) ? digits[0] : 0; if (size == -1) a = -a; } else { switch (size) { case -2: if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); goto long_long; } case 2: if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); goto long_long; } case -3: if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); goto long_long; } case 3: if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); goto long_long; } case -4: if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); goto long_long; } case 4: if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); break; } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); goto long_long; } default: return PyLong_Type.tp_as_number->nb_add(op1, op2); } } x = a + b; return PyLong_FromLong(x); long_long: llx = lla + llb; return PyLong_FromLongLong(llx); } #endif if (PyFloat_CheckExact(op1)) { const long b = intval; double a = PyFloat_AS_DOUBLE(op1); double result; PyFPE_START_PROTECT("add", return NULL) result = ((double)a) + (double)b; PyFPE_END_PROTECT(result) return PyFloat_FromDouble(result); } return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); } #endif /* RaiseArgTupleInvalid */ static void __Pyx_RaiseArgtupleInvalid( const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found) { Py_ssize_t num_expected; const char *more_or_less; if (num_found < num_min) { num_expected = num_min; more_or_less = "at least"; } else { num_expected = num_max; more_or_less = "at most"; } if (exact) { more_or_less = "exactly"; } PyErr_Format(PyExc_TypeError, "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", func_name, more_or_less, num_expected, (num_expected == 1) ? "" : "s", num_found); } /* RaiseDoubleKeywords */ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) { PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION >= 3 "%s() got multiple values for keyword argument '%U'", func_name, kw_name); #else "%s() got multiple values for keyword argument '%s'", func_name, PyString_AsString(kw_name)); #endif } /* ParseKeywords */ static int __Pyx_ParseOptionalKeywords( PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name) { PyObject *key = 0, *value = 0; Py_ssize_t pos = 0; PyObject*** name; PyObject*** first_kw_arg = argnames + num_pos_args; while (PyDict_Next(kwds, &pos, &key, &value)) { name = first_kw_arg; while (*name && (**name != key)) name++; if (*name) { values[name-argnames] = value; continue; } name = first_kw_arg; #if PY_MAJOR_VERSION < 3 if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { while (*name) { if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) && _PyString_Eq(**name, key)) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { if ((**argname == key) || ( (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) && _PyString_Eq(**argname, key))) { goto arg_passed_twice; } argname++; } } } else #endif if (likely(PyUnicode_Check(key))) { while (*name) { int cmp = (**name == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : #endif PyUnicode_Compare(**name, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) { values[name-argnames] = value; break; } name++; } if (*name) continue; else { PyObject*** argname = argnames; while (argname != first_kw_arg) { int cmp = (**argname == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : #endif PyUnicode_Compare(**argname, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; if (cmp == 0) goto arg_passed_twice; argname++; } } } else goto invalid_keyword_type; if (kwds2) { if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; } else { goto invalid_keyword; } } return 0; arg_passed_twice: __Pyx_RaiseDoubleKeywordsError(function_name, key); goto bad; invalid_keyword_type: PyErr_Format(PyExc_TypeError, "%.200s() keywords must be strings", function_name); goto bad; invalid_keyword: PyErr_Format(PyExc_TypeError, #if PY_MAJOR_VERSION < 3 "%.200s() got an unexpected keyword argument '%.200s'", function_name, PyString_AsString(key)); #else "%s() got an unexpected keyword argument '%U'", function_name, key); #endif bad: return -1; } /* PyObjectCall */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { PyObject *result; ternaryfunc call = func->ob_type->tp_call; if (unlikely(!call)) return PyObject_Call(func, arg, kw); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = (*call)(func, arg, kw); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif /* GetItemInt */ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); Py_DECREF(j); return r; } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_COMPILING_IN_CPYTHON if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o); if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { PyObject *r = PyList_GET_ITEM(o, i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_COMPILING_IN_CPYTHON if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o); if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, i); Py_INCREF(r); return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); #else return PySequence_GetItem(o, i); #endif } static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) { #if CYTHON_COMPILING_IN_CPYTHON if (is_list || PyList_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { PyObject *r = PyList_GET_ITEM(o, n); Py_INCREF(r); return r; } } else if (PyTuple_CheckExact(o)) { Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, n); Py_INCREF(r); return r; } } else { PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; if (likely(m && m->sq_item)) { if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { Py_ssize_t l = m->sq_length(o); if (likely(l >= 0)) { i += l; } else { if (!PyErr_ExceptionMatches(PyExc_OverflowError)) return NULL; PyErr_Clear(); } } return m->sq_item(o, i); } } #else if (is_list || PySequence_Check(o)) { return PySequence_GetItem(o, i); } #endif return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } /* UnicodeAsUCS4 */ static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) { Py_ssize_t length; #if CYTHON_PEP393_ENABLED length = PyUnicode_GET_LENGTH(x); if (likely(length == 1)) { return PyUnicode_READ_CHAR(x, 0); } #else length = PyUnicode_GET_SIZE(x); if (likely(length == 1)) { return PyUnicode_AS_UNICODE(x)[0]; } #if Py_UNICODE_SIZE == 2 else if (PyUnicode_GET_SIZE(x) == 2) { Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0]; if (high_val >= 0xD800 && high_val <= 0xDBFF) { Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1]; if (low_val >= 0xDC00 && low_val <= 0xDFFF) { return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1))); } } } #endif #endif PyErr_Format(PyExc_ValueError, "only single character unicode strings can be converted to Py_UCS4, " "got length %" CYTHON_FORMAT_SSIZE_T "d", length); return (Py_UCS4)-1; } /* object_ord */ static long __Pyx__PyObject_Ord(PyObject* c) { Py_ssize_t size; if (PyBytes_Check(c)) { size = PyBytes_GET_SIZE(c); if (likely(size == 1)) { return (unsigned char) PyBytes_AS_STRING(c)[0]; } #if PY_MAJOR_VERSION < 3 } else if (PyUnicode_Check(c)) { return (long)__Pyx_PyUnicode_AsPy_UCS4(c); #endif #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) } else if (PyByteArray_Check(c)) { size = PyByteArray_GET_SIZE(c); if (likely(size == 1)) { return (unsigned char) PyByteArray_AS_STRING(c)[0]; } #endif } else { PyErr_Format(PyExc_TypeError, "ord() expected string of length 1, but %.200s found", c->ob_type->tp_name); return (long)(Py_UCS4)-1; } PyErr_Format(PyExc_TypeError, "ord() expected a character, but string of length %zd found", size); return (long)(Py_UCS4)-1; } /* PyObjectCallMethO */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { PyObject *self, *result; PyCFunction cfunc; cfunc = PyCFunction_GET_FUNCTION(func); self = PyCFunction_GET_SELF(func); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) return NULL; result = cfunc(self, arg); Py_LeaveRecursiveCall(); if (unlikely(!result) && unlikely(!PyErr_Occurred())) { PyErr_SetString( PyExc_SystemError, "NULL result without error in PyObject_Call"); } return result; } #endif /* PyObjectCallOneArg */ #if CYTHON_COMPILING_IN_CPYTHON static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject *result; PyObject *args = PyTuple_New(1); if (unlikely(!args)) return NULL; Py_INCREF(arg); PyTuple_SET_ITEM(args, 0, arg); result = __Pyx_PyObject_Call(func, args, NULL); Py_DECREF(args); return result; } static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { #ifdef __Pyx_CyFunction_USED if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) { #else if (likely(PyCFunction_Check(func))) { #endif if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { return __Pyx_PyObject_CallMethO(func, arg); } } return __Pyx__PyObject_CallOneArg(func, arg); } #else static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { PyObject *result; PyObject *args = PyTuple_Pack(1, arg); if (unlikely(!args)) return NULL; result = __Pyx_PyObject_Call(func, args, NULL); Py_DECREF(args); return result; } #endif /* PyObjectCallNoArg */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { #ifdef __Pyx_CyFunction_USED if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) { #else if (likely(PyCFunction_Check(func))) { #endif if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) { return __Pyx_PyObject_CallMethO(func, NULL); } } return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL); } #endif /* None */ static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); } /* SliceObject */ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice, int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) { #if CYTHON_COMPILING_IN_CPYTHON PyMappingMethods* mp; #if PY_MAJOR_VERSION < 3 PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence; if (likely(ms && ms->sq_slice)) { if (!has_cstart) { if (_py_start && (*_py_start != Py_None)) { cstart = __Pyx_PyIndex_AsSsize_t(*_py_start); if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; } else cstart = 0; } if (!has_cstop) { if (_py_stop && (*_py_stop != Py_None)) { cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop); if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; } else cstop = PY_SSIZE_T_MAX; } if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) { Py_ssize_t l = ms->sq_length(obj); if (likely(l >= 0)) { if (cstop < 0) { cstop += l; if (cstop < 0) cstop = 0; } if (cstart < 0) { cstart += l; if (cstart < 0) cstart = 0; } } else { if (!PyErr_ExceptionMatches(PyExc_OverflowError)) goto bad; PyErr_Clear(); } } return ms->sq_slice(obj, cstart, cstop); } #endif mp = Py_TYPE(obj)->tp_as_mapping; if (likely(mp && mp->mp_subscript)) #endif { PyObject* result; PyObject *py_slice, *py_start, *py_stop; if (_py_slice) { py_slice = *_py_slice; } else { PyObject* owned_start = NULL; PyObject* owned_stop = NULL; if (_py_start) { py_start = *_py_start; } else { if (has_cstart) { owned_start = py_start = PyInt_FromSsize_t(cstart); if (unlikely(!py_start)) goto bad; } else py_start = Py_None; } if (_py_stop) { py_stop = *_py_stop; } else { if (has_cstop) { owned_stop = py_stop = PyInt_FromSsize_t(cstop); if (unlikely(!py_stop)) { Py_XDECREF(owned_start); goto bad; } } else py_stop = Py_None; } py_slice = PySlice_New(py_start, py_stop, Py_None); Py_XDECREF(owned_start); Py_XDECREF(owned_stop); if (unlikely(!py_slice)) goto bad; } #if CYTHON_COMPILING_IN_CPYTHON result = mp->mp_subscript(obj, py_slice); #else result = PyObject_GetItem(obj, py_slice); #endif if (!_py_slice) { Py_DECREF(py_slice); } return result; } PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name); bad: return NULL; } /* Import */ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; PyObject *empty_dict = 0; PyObject *list; #if PY_VERSION_HEX < 0x03030000 PyObject *py_import; py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); if (!py_import) goto bad; #endif if (from_list) list = from_list; else { empty_list = PyList_New(0); if (!empty_list) goto bad; list = empty_list; } global_dict = PyModule_GetDict(__pyx_m); if (!global_dict) goto bad; empty_dict = PyDict_New(); if (!empty_dict) goto bad; { #if PY_MAJOR_VERSION >= 3 if (level == -1) { if (strchr(__Pyx_MODULE_NAME, '.')) { #if PY_VERSION_HEX < 0x03030000 PyObject *py_level = PyInt_FromLong(1); if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, py_level, NULL); Py_DECREF(py_level); #else module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, 1); #endif if (!module) { if (!PyErr_ExceptionMatches(PyExc_ImportError)) goto bad; PyErr_Clear(); } } level = 0; } #endif if (!module) { #if PY_VERSION_HEX < 0x03030000 PyObject *py_level = PyInt_FromLong(level); if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, name, global_dict, empty_dict, list, py_level, NULL); Py_DECREF(py_level); #else module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, level); #endif } } bad: #if PY_VERSION_HEX < 0x03030000 Py_XDECREF(py_import); #endif Py_XDECREF(empty_list); Py_XDECREF(empty_dict); return module; } /* ImportFrom */ static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Format(PyExc_ImportError, #if PY_MAJOR_VERSION < 3 "cannot import name %.230s", PyString_AS_STRING(name)); #else "cannot import name %S", name); #endif } return value; } /* CodeObjectCache */ static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { return count; } while (start < end) { mid = start + (end - start) / 2; if (code_line < entries[mid].code_line) { end = mid; } else if (code_line > entries[mid].code_line) { start = mid + 1; } else { return mid; } } if (code_line <= entries[mid].code_line) { return mid; } else { return mid + 1; } } static PyCodeObject *__pyx_find_code_object(int code_line) { PyCodeObject* code_object; int pos; if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { return NULL; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { return NULL; } code_object = __pyx_code_cache.entries[pos].code_object; Py_INCREF(code_object); return code_object; } static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { int pos, i; __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; if (unlikely(!code_line)) { return; } if (unlikely(!entries)) { entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); if (likely(entries)) { __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = 64; __pyx_code_cache.count = 1; entries[0].code_line = code_line; entries[0].code_object = code_object; Py_INCREF(code_object); } return; } pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { PyCodeObject* tmp = entries[pos].code_object; entries[pos].code_object = code_object; Py_DECREF(tmp); return; } if (__pyx_code_cache.count == __pyx_code_cache.max_count) { int new_max = __pyx_code_cache.max_count + 64; entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); if (unlikely(!entries)) { return; } __pyx_code_cache.entries = entries; __pyx_code_cache.max_count = new_max; } for (i=__pyx_code_cache.count; i>pos; i--) { entries[i] = entries[i-1]; } entries[pos].code_line = code_line; entries[pos].code_object = code_object; __pyx_code_cache.count++; Py_INCREF(code_object); } /* AddTraceback */ #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyObject *py_srcfile = 0; PyObject *py_funcname = 0; #if PY_MAJOR_VERSION < 3 py_srcfile = PyString_FromString(filename); #else py_srcfile = PyUnicode_FromString(filename); #endif if (!py_srcfile) goto bad; if (c_line) { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #else py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); #endif } else { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromString(funcname); #else py_funcname = PyUnicode_FromString(funcname); #endif } if (!py_funcname) goto bad; py_code = __Pyx_PyCode_New( 0, 0, 0, 0, 0, __pyx_empty_bytes, /*PyObject *code,*/ __pyx_empty_tuple, /*PyObject *consts,*/ __pyx_empty_tuple, /*PyObject *names,*/ __pyx_empty_tuple, /*PyObject *varnames,*/ __pyx_empty_tuple, /*PyObject *freevars,*/ __pyx_empty_tuple, /*PyObject *cellvars,*/ py_srcfile, /*PyObject *filename,*/ py_funcname, /*PyObject *name,*/ py_line, __pyx_empty_bytes /*PyObject *lnotab*/ ); Py_DECREF(py_srcfile); Py_DECREF(py_funcname); return py_code; bad: Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); return NULL; } static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; py_code = __pyx_find_code_object(c_line ? c_line : py_line); if (!py_code) { py_code = __Pyx_CreateCodeObjectForTraceback( funcname, c_line, py_line, filename); if (!py_code) goto bad; __pyx_insert_code_object(c_line ? c_line : py_line, py_code); } py_frame = PyFrame_New( PyThreadState_GET(), /*PyThreadState *tstate,*/ py_code, /*PyCodeObject *code,*/ __pyx_d, /*PyObject *globals,*/ 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; py_frame->f_lineno = py_line; PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } /* CIntFromPyVerify */ #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ {\ func_type value = func_value;\ if (sizeof(target_type) < sizeof(func_type)) {\ if (unlikely(value != (func_type) (target_type) value)) {\ func_type zero = 0;\ if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ return (target_type) -1;\ if (is_unsigned && unlikely(value < zero))\ goto raise_neg_overflow;\ else\ goto raise_overflow;\ }\ }\ return (target_type) value;\ } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); } } else { if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(long), little, !is_unsigned); } } /* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(int) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(int) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); } } else { if (sizeof(int) <= sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); } } { int one = 1; int little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&value; return _PyLong_FromByteArray(bytes, sizeof(int), little, !is_unsigned); } } /* CIntFromPy */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(int) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (int) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (int) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(int) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) case -2: if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 2: if (8 * sizeof(int) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -3: if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 3: if (8 * sizeof(int) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case -4: if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; case 4: if (8 * sizeof(int) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); } } break; } #endif if (sizeof(int) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else int val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (int) -1; } } else { int val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (int) -1; val = __Pyx_PyInt_As_int(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to int"); return (int) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to int"); return (int) -1; } /* CIntFromPy */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(long) < sizeof(long)) { __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { goto raise_neg_overflow; } return (long) val; } } else #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); } } break; } #endif #if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { goto raise_neg_overflow; } #else { int result = PyObject_RichCompareBool(x, Py_False, Py_LT); if (unlikely(result < 0)) return (long) -1; if (unlikely(result == 1)) goto raise_neg_overflow; } #endif if (sizeof(long) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) case -2: if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 2: if (8 * sizeof(long) > 1 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -3: if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 3: if (8 * sizeof(long) > 2 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case -4: if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; case 4: if (8 * sizeof(long) > 3 * PyLong_SHIFT) { if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); } } break; } #endif if (sizeof(long) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) } } { #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else long val; PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; v = PyNumber_Long(tmp); Py_DECREF(tmp); } #endif if (likely(v)) { int one = 1; int is_little = (int)*(unsigned char *)&one; unsigned char *bytes = (unsigned char *)&val; int ret = _PyLong_AsByteArray((PyLongObject *)v, bytes, sizeof(val), is_little, !is_unsigned); Py_DECREF(v); if (likely(!ret)) return val; } #endif return (long) -1; } } else { long val; PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (long) -1; val = __Pyx_PyInt_As_long(tmp); Py_DECREF(tmp); return val; } raise_overflow: PyErr_SetString(PyExc_OverflowError, "value too large to convert to long"); return (long) -1; raise_neg_overflow: PyErr_SetString(PyExc_OverflowError, "can't convert negative value to long"); return (long) -1; } /* FetchCommonType */ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { PyObject* fake_module; PyTypeObject* cached_type = NULL; fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI); if (!fake_module) return NULL; Py_INCREF(fake_module); cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name); if (cached_type) { if (!PyType_Check((PyObject*)cached_type)) { PyErr_Format(PyExc_TypeError, "Shared Cython type %.200s is not a type object", type->tp_name); goto bad; } if (cached_type->tp_basicsize != type->tp_basicsize) { PyErr_Format(PyExc_TypeError, "Shared Cython type %.200s has the wrong size, try recompiling", type->tp_name); goto bad; } } else { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; PyErr_Clear(); if (PyType_Ready(type) < 0) goto bad; if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0) goto bad; Py_INCREF(type); cached_type = type; } done: Py_DECREF(fake_module); return cached_type; bad: Py_XDECREF(cached_type); cached_type = NULL; goto done; } /* PyErrFetchRestore */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; tmp_type = tstate->curexc_type; tmp_value = tstate->curexc_value; tmp_tb = tstate->curexc_traceback; tstate->curexc_type = type; tstate->curexc_value = value; tstate->curexc_traceback = tb; Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); } static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; } #endif /* RaiseException */ #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, CYTHON_UNUSED PyObject *cause) { __Pyx_PyThreadState_declare Py_XINCREF(type); if (!value || value == Py_None) value = NULL; else Py_INCREF(value); if (!tb || tb == Py_None) tb = NULL; else { Py_INCREF(tb); if (!PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto raise_error; } } if (PyType_Check(type)) { #if CYTHON_COMPILING_IN_PYPY if (!value) { Py_INCREF(Py_None); value = Py_None; } #endif PyErr_NormalizeException(&type, &value, &tb); } else { if (value) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto raise_error; } value = type; type = (PyObject*) Py_TYPE(type); Py_INCREF(type); if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto raise_error; } } __Pyx_PyThreadState_assign __Pyx_ErrRestore(type, value, tb); return; raise_error: Py_XDECREF(value); Py_XDECREF(type); Py_XDECREF(tb); return; } #else static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { PyObject* owned_instance = NULL; if (tb == Py_None) { tb = 0; } else if (tb && !PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "raise: arg 3 must be a traceback or None"); goto bad; } if (value == Py_None) value = 0; if (PyExceptionInstance_Check(type)) { if (value) { PyErr_SetString(PyExc_TypeError, "instance exception may not have a separate value"); goto bad; } value = type; type = (PyObject*) Py_TYPE(value); } else if (PyExceptionClass_Check(type)) { PyObject *instance_class = NULL; if (value && PyExceptionInstance_Check(value)) { instance_class = (PyObject*) Py_TYPE(value); if (instance_class != type) { int is_subclass = PyObject_IsSubclass(instance_class, type); if (!is_subclass) { instance_class = NULL; } else if (unlikely(is_subclass == -1)) { goto bad; } else { type = instance_class; } } } if (!instance_class) { PyObject *args; if (!value) args = PyTuple_New(0); else if (PyTuple_Check(value)) { Py_INCREF(value); args = value; } else args = PyTuple_Pack(1, value); if (!args) goto bad; owned_instance = PyObject_Call(type, args, NULL); Py_DECREF(args); if (!owned_instance) goto bad; value = owned_instance; if (!PyExceptionInstance_Check(value)) { PyErr_Format(PyExc_TypeError, "calling %R should have returned an instance of " "BaseException, not %R", type, Py_TYPE(value)); goto bad; } } } else { PyErr_SetString(PyExc_TypeError, "raise: exception class must be a subclass of BaseException"); goto bad; } #if PY_VERSION_HEX >= 0x03030000 if (cause) { #else if (cause && cause != Py_None) { #endif PyObject *fixed_cause; if (cause == Py_None) { fixed_cause = NULL; } else if (PyExceptionClass_Check(cause)) { fixed_cause = PyObject_CallObject(cause, NULL); if (fixed_cause == NULL) goto bad; } else if (PyExceptionInstance_Check(cause)) { fixed_cause = cause; Py_INCREF(fixed_cause); } else { PyErr_SetString(PyExc_TypeError, "exception causes must derive from " "BaseException"); goto bad; } PyException_SetCause(value, fixed_cause); } PyErr_SetObject(type, value); if (tb) { #if CYTHON_COMPILING_IN_PYPY PyObject *tmp_type, *tmp_value, *tmp_tb; PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); Py_INCREF(tb); PyErr_Restore(tmp_type, tmp_value, tb); Py_XDECREF(tmp_tb); #else PyThreadState *tstate = PyThreadState_GET(); PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { Py_INCREF(tb); tstate->curexc_traceback = tb; Py_XDECREF(tmp_tb); } #endif } bad: Py_XDECREF(owned_instance); return; } #endif /* SwapException */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; tmp_type = tstate->exc_type; tmp_value = tstate->exc_value; tmp_tb = tstate->exc_traceback; tstate->exc_type = *type; tstate->exc_value = *value; tstate->exc_traceback = *tb; *type = tmp_type; *value = tmp_value; *tb = tmp_tb; } #else static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); PyErr_SetExcInfo(*type, *value, *tb); *type = tmp_type; *value = tmp_value; *tb = tmp_tb; } #endif /* PyObjectCallMethod1 */ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { PyObject *method, *result = NULL; method = __Pyx_PyObject_GetAttrStr(obj, method_name); if (unlikely(!method)) goto bad; #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyMethod_Check(method))) { PyObject *self = PyMethod_GET_SELF(method); if (likely(self)) { PyObject *args; PyObject *function = PyMethod_GET_FUNCTION(method); args = PyTuple_New(2); if (unlikely(!args)) goto bad; Py_INCREF(self); PyTuple_SET_ITEM(args, 0, self); Py_INCREF(arg); PyTuple_SET_ITEM(args, 1, arg); Py_INCREF(function); Py_DECREF(method); method = NULL; result = __Pyx_PyObject_Call(function, args, NULL); Py_DECREF(args); Py_DECREF(function); return result; } } #endif result = __Pyx_PyObject_CallOneArg(method, arg); bad: Py_XDECREF(method); return result; } /* CoroutineBase */ #include #include static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value); static PyObject *__Pyx_Coroutine_Close(PyObject *self); static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args); #define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom) #if 1 || PY_VERSION_HEX < 0x030300B0 static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) { PyObject *et, *ev, *tb; PyObject *value = NULL; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&et, &ev, &tb); if (!et) { Py_XDECREF(tb); Py_XDECREF(ev); Py_INCREF(Py_None); *pvalue = Py_None; return 0; } if (likely(et == PyExc_StopIteration)) { #if PY_VERSION_HEX >= 0x030300A0 if (ev && Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) { value = ((PyStopIterationObject *)ev)->value; Py_INCREF(value); Py_DECREF(ev); Py_XDECREF(tb); Py_DECREF(et); *pvalue = value; return 0; } #endif if (!ev || !PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) { if (!ev) { Py_INCREF(Py_None); ev = Py_None; } else if (PyTuple_Check(ev)) { if (PyTuple_GET_SIZE(ev) >= 1) { PyObject *value; #if CYTHON_COMPILING_IN_CPYTHON value = PySequence_ITEM(ev, 0); #else value = PyTuple_GET_ITEM(ev, 0); Py_INCREF(value); #endif Py_DECREF(ev); ev = value; } else { Py_INCREF(Py_None); Py_DECREF(ev); ev = Py_None; } } Py_XDECREF(tb); Py_DECREF(et); *pvalue = ev; return 0; } } else if (!PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) { __Pyx_ErrRestore(et, ev, tb); return -1; } PyErr_NormalizeException(&et, &ev, &tb); if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) { __Pyx_ErrRestore(et, ev, tb); return -1; } Py_XDECREF(tb); Py_DECREF(et); #if PY_VERSION_HEX >= 0x030300A0 value = ((PyStopIterationObject *)ev)->value; Py_INCREF(value); Py_DECREF(ev); #else { PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args); Py_DECREF(ev); if (likely(args)) { value = PySequence_GetItem(args, 0); Py_DECREF(args); } if (unlikely(!value)) { __Pyx_ErrRestore(NULL, NULL, NULL); Py_INCREF(Py_None); value = Py_None; } } #endif *pvalue = value; return 0; } #endif static CYTHON_INLINE void __Pyx_Coroutine_ExceptionClear(__pyx_CoroutineObject *self) { PyObject *exc_type = self->exc_type; PyObject *exc_value = self->exc_value; PyObject *exc_traceback = self->exc_traceback; self->exc_type = NULL; self->exc_value = NULL; self->exc_traceback = NULL; Py_XDECREF(exc_type); Py_XDECREF(exc_value); Py_XDECREF(exc_traceback); } static CYTHON_INLINE int __Pyx_Coroutine_CheckRunning(__pyx_CoroutineObject *gen) { if (unlikely(gen->is_running)) { PyErr_SetString(PyExc_ValueError, "generator already executing"); return 1; } return 0; } static CYTHON_INLINE PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) { PyObject *retval; __Pyx_PyThreadState_declare assert(!self->is_running); if (unlikely(self->resume_label == 0)) { if (unlikely(value && value != Py_None)) { PyErr_SetString(PyExc_TypeError, "can't send non-None value to a " "just-started generator"); return NULL; } } if (unlikely(self->resume_label == -1)) { PyErr_SetNone(PyExc_StopIteration); return NULL; } __Pyx_PyThreadState_assign if (value) { #if CYTHON_COMPILING_IN_PYPY #else if (self->exc_traceback) { PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; PyFrameObject *f = tb->tb_frame; Py_XINCREF(__pyx_tstate->frame); assert(f->f_back == NULL); f->f_back = __pyx_tstate->frame; } #endif __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback); } else { __Pyx_Coroutine_ExceptionClear(self); } self->is_running = 1; retval = self->body((PyObject *) self, value); self->is_running = 0; if (retval) { __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback); #if CYTHON_COMPILING_IN_PYPY #else if (self->exc_traceback) { PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; PyFrameObject *f = tb->tb_frame; Py_CLEAR(f->f_back); } #endif } else { __Pyx_Coroutine_ExceptionClear(self); } return retval; } static CYTHON_INLINE PyObject *__Pyx_Coroutine_MethodReturn(PyObject *retval) { if (unlikely(!retval && !PyErr_Occurred())) { PyErr_SetNone(PyExc_StopIteration); } return retval; } static CYTHON_INLINE PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) { PyObject *ret; PyObject *val = NULL; __Pyx_Coroutine_Undelegate(gen); __Pyx_PyGen_FetchStopIterationValue(&val); ret = __Pyx_Coroutine_SendEx(gen, val); Py_XDECREF(val); return ret; } static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) { PyObject *retval; __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; PyObject *yf = gen->yieldfrom; if (unlikely(__Pyx_Coroutine_CheckRunning(gen))) return NULL; if (yf) { PyObject *ret; gen->is_running = 1; #ifdef __Pyx_Generator_USED if (__Pyx_Generator_CheckExact(yf)) { ret = __Pyx_Coroutine_Send(yf, value); } else #endif #ifdef __Pyx_Coroutine_USED if (__Pyx_Coroutine_CheckExact(yf)) { ret = __Pyx_Coroutine_Send(yf, value); } else #endif { if (value == Py_None) ret = Py_TYPE(yf)->tp_iternext(yf); else ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value); } gen->is_running = 0; if (likely(ret)) { return ret; } retval = __Pyx_Coroutine_FinishDelegation(gen); } else { retval = __Pyx_Coroutine_SendEx(gen, value); } return __Pyx_Coroutine_MethodReturn(retval); } static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) { PyObject *retval = NULL; int err = 0; #ifdef __Pyx_Generator_USED if (__Pyx_Generator_CheckExact(yf)) { retval = __Pyx_Coroutine_Close(yf); if (!retval) return -1; } else #endif #ifdef __Pyx_Coroutine_USED if (__Pyx_Coroutine_CheckExact(yf)) { retval = __Pyx_Coroutine_Close(yf); if (!retval) return -1; } else #endif { PyObject *meth; gen->is_running = 1; meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_close); if (unlikely(!meth)) { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_WriteUnraisable(yf); } PyErr_Clear(); } else { retval = PyObject_CallFunction(meth, NULL); Py_DECREF(meth); if (!retval) err = -1; } gen->is_running = 0; } Py_XDECREF(retval); return err; } static PyObject *__Pyx_Generator_Next(PyObject *self) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; PyObject *yf = gen->yieldfrom; if (unlikely(__Pyx_Coroutine_CheckRunning(gen))) return NULL; if (yf) { PyObject *ret; gen->is_running = 1; ret = Py_TYPE(yf)->tp_iternext(yf); gen->is_running = 0; if (likely(ret)) { return ret; } return __Pyx_Coroutine_FinishDelegation(gen); } return __Pyx_Coroutine_SendEx(gen, Py_None); } static PyObject *__Pyx_Coroutine_Close(PyObject *self) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; PyObject *retval, *raised_exception; PyObject *yf = gen->yieldfrom; int err = 0; if (unlikely(__Pyx_Coroutine_CheckRunning(gen))) return NULL; if (yf) { Py_INCREF(yf); err = __Pyx_Coroutine_CloseIter(gen, yf); __Pyx_Coroutine_Undelegate(gen); Py_DECREF(yf); } if (err == 0) PyErr_SetNone(PyExc_GeneratorExit); retval = __Pyx_Coroutine_SendEx(gen, NULL); if (retval) { Py_DECREF(retval); PyErr_SetString(PyExc_RuntimeError, "generator ignored GeneratorExit"); return NULL; } raised_exception = PyErr_Occurred(); if (!raised_exception || raised_exception == PyExc_StopIteration || raised_exception == PyExc_GeneratorExit || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit) || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration)) { if (raised_exception) PyErr_Clear(); Py_INCREF(Py_None); return Py_None; } return NULL; } static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; PyObject *typ; PyObject *tb = NULL; PyObject *val = NULL; PyObject *yf = gen->yieldfrom; if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb)) return NULL; if (unlikely(__Pyx_Coroutine_CheckRunning(gen))) return NULL; if (yf) { PyObject *ret; Py_INCREF(yf); if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) { int err = __Pyx_Coroutine_CloseIter(gen, yf); Py_DECREF(yf); __Pyx_Coroutine_Undelegate(gen); if (err < 0) return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL)); goto throw_here; } gen->is_running = 1; #ifdef __Pyx_Generator_USED if (__Pyx_Generator_CheckExact(yf)) { ret = __Pyx_Coroutine_Throw(yf, args); } else #endif #ifdef __Pyx_Coroutine_USED if (__Pyx_Coroutine_CheckExact(yf)) { ret = __Pyx_Coroutine_Throw(yf, args); } else #endif { PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_throw); if (unlikely(!meth)) { Py_DECREF(yf); if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { gen->is_running = 0; return NULL; } PyErr_Clear(); __Pyx_Coroutine_Undelegate(gen); gen->is_running = 0; goto throw_here; } ret = PyObject_CallObject(meth, args); Py_DECREF(meth); } gen->is_running = 0; Py_DECREF(yf); if (!ret) { ret = __Pyx_Coroutine_FinishDelegation(gen); } return __Pyx_Coroutine_MethodReturn(ret); } throw_here: __Pyx_Raise(typ, val, tb, NULL); return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL)); } static int __Pyx_Coroutine_traverse(PyObject *self, visitproc visit, void *arg) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; Py_VISIT(gen->closure); Py_VISIT(gen->classobj); Py_VISIT(gen->yieldfrom); Py_VISIT(gen->exc_type); Py_VISIT(gen->exc_value); Py_VISIT(gen->exc_traceback); return 0; } static int __Pyx_Coroutine_clear(PyObject *self) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; Py_CLEAR(gen->closure); Py_CLEAR(gen->classobj); Py_CLEAR(gen->yieldfrom); Py_CLEAR(gen->exc_type); Py_CLEAR(gen->exc_value); Py_CLEAR(gen->exc_traceback); Py_CLEAR(gen->gi_name); Py_CLEAR(gen->gi_qualname); return 0; } static void __Pyx_Coroutine_dealloc(PyObject *self) { __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; PyObject_GC_UnTrack(gen); if (gen->gi_weakreflist != NULL) PyObject_ClearWeakRefs(self); if (gen->resume_label > 0) { PyObject_GC_Track(self); #if PY_VERSION_HEX >= 0x030400a1 if (PyObject_CallFinalizerFromDealloc(self)) #else Py_TYPE(gen)->tp_del(self); if (self->ob_refcnt > 0) #endif { return; } PyObject_GC_UnTrack(self); } __Pyx_Coroutine_clear(self); PyObject_GC_Del(gen); } static void __Pyx_Coroutine_del(PyObject *self) { PyObject *res; PyObject *error_type, *error_value, *error_traceback; __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; __Pyx_PyThreadState_declare if (gen->resume_label <= 0) return ; #if PY_VERSION_HEX < 0x030400a1 assert(self->ob_refcnt == 0); self->ob_refcnt = 1; #endif __Pyx_PyThreadState_assign __Pyx_ErrFetch(&error_type, &error_value, &error_traceback); res = __Pyx_Coroutine_Close(self); if (res == NULL) PyErr_WriteUnraisable(self); else Py_DECREF(res); __Pyx_ErrRestore(error_type, error_value, error_traceback); #if PY_VERSION_HEX < 0x030400a1 assert(self->ob_refcnt > 0); if (--self->ob_refcnt == 0) { return; } { Py_ssize_t refcnt = self->ob_refcnt; _Py_NewReference(self); self->ob_refcnt = refcnt; } #if CYTHON_COMPILING_IN_CPYTHON assert(PyType_IS_GC(self->ob_type) && _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); _Py_DEC_REFTOTAL; #endif #ifdef COUNT_ALLOCS --Py_TYPE(self)->tp_frees; --Py_TYPE(self)->tp_allocs; #endif #endif } static PyObject * __Pyx_Coroutine_get_name(__pyx_CoroutineObject *self) { Py_INCREF(self->gi_name); return self->gi_name; } static int __Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value) { PyObject *tmp; #if PY_MAJOR_VERSION >= 3 if (unlikely(value == NULL || !PyUnicode_Check(value))) { #else if (unlikely(value == NULL || !PyString_Check(value))) { #endif PyErr_SetString(PyExc_TypeError, "__name__ must be set to a string object"); return -1; } tmp = self->gi_name; Py_INCREF(value); self->gi_name = value; Py_XDECREF(tmp); return 0; } static PyObject * __Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self) { Py_INCREF(self->gi_qualname); return self->gi_qualname; } static int __Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value) { PyObject *tmp; #if PY_MAJOR_VERSION >= 3 if (unlikely(value == NULL || !PyUnicode_Check(value))) { #else if (unlikely(value == NULL || !PyString_Check(value))) { #endif PyErr_SetString(PyExc_TypeError, "__qualname__ must be set to a string object"); return -1; } tmp = self->gi_qualname; Py_INCREF(value); self->gi_qualname = value; Py_XDECREF(tmp); return 0; } static __pyx_CoroutineObject *__Pyx__Coroutine_New( PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *closure, PyObject *name, PyObject *qualname, PyObject *module_name) { __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type); if (gen == NULL) return NULL; gen->body = body; gen->closure = closure; Py_XINCREF(closure); gen->is_running = 0; gen->resume_label = 0; gen->classobj = NULL; gen->yieldfrom = NULL; gen->exc_type = NULL; gen->exc_value = NULL; gen->exc_traceback = NULL; gen->gi_weakreflist = NULL; Py_XINCREF(qualname); gen->gi_qualname = qualname; Py_XINCREF(name); gen->gi_name = name; Py_XINCREF(module_name); gen->gi_modulename = module_name; PyObject_GC_Track(gen); return gen; } /* PatchModuleWithCoroutine */ static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) { #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) int result; PyObject *globals, *result_obj; globals = PyDict_New(); if (unlikely(!globals)) goto ignore; result = PyDict_SetItemString(globals, "_cython_coroutine_type", #ifdef __Pyx_Coroutine_USED (PyObject*)__pyx_CoroutineType); #else Py_None); #endif if (unlikely(result < 0)) goto ignore; result = PyDict_SetItemString(globals, "_cython_generator_type", #ifdef __Pyx_Generator_USED (PyObject*)__pyx_GeneratorType); #else Py_None); #endif if (unlikely(result < 0)) goto ignore; if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore; if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore; result_obj = PyRun_String(py_code, Py_file_input, globals, globals); if (unlikely(!result_obj)) goto ignore; Py_DECREF(result_obj); Py_DECREF(globals); return module; ignore: Py_XDECREF(globals); PyErr_WriteUnraisable(module); if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) { Py_DECREF(module); module = NULL; } #else py_code++; #endif return module; } /* PatchGeneratorABC */ #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) static PyObject* __Pyx_patch_abc_module(PyObject *module); static PyObject* __Pyx_patch_abc_module(PyObject *module) { module = __Pyx_Coroutine_patch_module( module, "" "if _cython_generator_type is not None:\n" " try: Generator = _module.Generator\n" " except AttributeError: pass\n" " else: Generator.register(_cython_generator_type)\n" "if _cython_coroutine_type is not None:\n" " try: Coroutine = _module.Coroutine\n" " except AttributeError: pass\n" " else: Coroutine.register(_cython_coroutine_type)\n" ); return module; } #endif static int __Pyx_patch_abc(void) { #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) static int abc_patched = 0; if (!abc_patched) { PyObject *module; module = PyImport_ImportModule((PY_VERSION_HEX >= 0x03030000) ? "collections.abc" : "collections"); if (!module) { PyErr_WriteUnraisable(NULL); if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, ((PY_VERSION_HEX >= 0x03030000) ? "Cython module failed to register with collections.abc module" : "Cython module failed to register with collections module"), 1) < 0)) { return -1; } } else { module = __Pyx_patch_abc_module(module); abc_patched = 1; if (unlikely(!module)) return -1; Py_DECREF(module); } module = PyImport_ImportModule("backports_abc"); if (module) { module = __Pyx_patch_abc_module(module); Py_XDECREF(module); } if (!module) { PyErr_Clear(); } } #else if (0) __Pyx_Coroutine_patch_module(NULL, NULL); #endif return 0; } /* Generator */ static PyMethodDef __pyx_Generator_methods[] = { {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O, (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")}, {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS, (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")}, {"close", (PyCFunction) __Pyx_Coroutine_Close, METH_NOARGS, (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")}, {0, 0, 0, 0} }; static PyMemberDef __pyx_Generator_memberlist[] = { {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL}, {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY, (char*) PyDoc_STR("object being iterated by 'yield from', or None")}, {0, 0, 0, 0, 0} }; static PyGetSetDef __pyx_Generator_getsets[] = { {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name, (char*) PyDoc_STR("name of the generator"), 0}, {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname, (char*) PyDoc_STR("qualified name of the generator"), 0}, {0, 0, 0, 0, 0} }; static PyTypeObject __pyx_GeneratorType_type = { PyVarObject_HEAD_INIT(0, 0) "generator", sizeof(__pyx_CoroutineObject), 0, (destructor) __Pyx_Coroutine_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, 0, (traverseproc) __Pyx_Coroutine_traverse, 0, 0, offsetof(__pyx_CoroutineObject, gi_weakreflist), 0, (iternextfunc) __Pyx_Generator_Next, __pyx_Generator_methods, __pyx_Generator_memberlist, __pyx_Generator_getsets, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #if PY_VERSION_HEX >= 0x030400a1 0, #else __Pyx_Coroutine_del, #endif 0, #if PY_VERSION_HEX >= 0x030400a1 __Pyx_Coroutine_del, #endif }; static int __pyx_Generator_init(void) { __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr; __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter; __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type); if (unlikely(!__pyx_GeneratorType)) { return -1; } return 0; } /* CheckBinaryVersion */ static int __Pyx_check_binary_version(void) { char ctversion[4], rtversion[4]; PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { char message[200]; PyOS_snprintf(message, sizeof(message), "compiletime version %s of module '%.100s' " "does not match runtime version %s", ctversion, __Pyx_MODULE_NAME, rtversion); return PyErr_WarnEx(NULL, message, 1); } return 0; } /* InitStrings */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); } else if (t->intern) { *t->p = PyString_InternFromString(t->s); } else { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } #else if (t->is_unicode | t->is_str) { if (t->intern) { *t->p = PyUnicode_InternFromString(t->s); } else if (t->encoding) { *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); } else { *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); } } else { *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); } #endif if (!*t->p) return -1; ++t; } return 0; } static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); } static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) { Py_ssize_t ignore; return __Pyx_PyObject_AsStringAndSize(o, &ignore); } static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { #if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if ( #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII __Pyx_sys_getdefaultencoding_not_ascii && #endif PyUnicode_Check(o)) { #if PY_VERSION_HEX < 0x03030000 char* defenc_c; PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); if (!defenc) return NULL; defenc_c = PyBytes_AS_STRING(defenc); #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII { char* end = defenc_c + PyBytes_GET_SIZE(defenc); char* c; for (c = defenc_c; c < end; c++) { if ((unsigned char) (*c) >= 128) { PyUnicode_AsASCIIString(o); return NULL; } } } #endif *length = PyBytes_GET_SIZE(defenc); return defenc_c; #else if (__Pyx_PyUnicode_READY(o) == -1) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII if (PyUnicode_IS_ASCII(o)) { *length = PyUnicode_GET_LENGTH(o); return PyUnicode_AsUTF8(o); } else { PyUnicode_AsASCIIString(o); return NULL; } #else return PyUnicode_AsUTF8AndSize(o, length); #endif #endif } else #endif #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) if (PyByteArray_Check(o)) { *length = PyByteArray_GET_SIZE(o); return PyByteArray_AS_STRING(o); } else #endif { char* result; int r = PyBytes_AsStringAndSize(o, &result, length); if (unlikely(r < 0)) { return NULL; } else { return result; } } } static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { int is_true = x == Py_True; if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); } static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { PyNumberMethods *m; const char *name = NULL; PyObject *res = NULL; #if PY_MAJOR_VERSION < 3 if (PyInt_Check(x) || PyLong_Check(x)) #else if (PyLong_Check(x)) #endif return __Pyx_NewRef(x); m = Py_TYPE(x)->tp_as_number; #if PY_MAJOR_VERSION < 3 if (m && m->nb_int) { name = "int"; res = PyNumber_Int(x); } else if (m && m->nb_long) { name = "long"; res = PyNumber_Long(x); } #else if (m && m->nb_int) { name = "int"; res = PyNumber_Long(x); } #endif if (res) { #if PY_MAJOR_VERSION < 3 if (!PyInt_Check(res) && !PyLong_Check(res)) { #else if (!PyLong_Check(res)) { #endif PyErr_Format(PyExc_TypeError, "__%.4s__ returned non-%.4s (type %.200s)", name, name, Py_TYPE(res)->tp_name); Py_DECREF(res); return NULL; } } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "an integer is required"); } return res; } static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; PyObject *x; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_CheckExact(b))) { if (sizeof(Py_ssize_t) >= sizeof(long)) return PyInt_AS_LONG(b); else return PyInt_AsSsize_t(x); } #endif if (likely(PyLong_CheckExact(b))) { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)b)->ob_digit; const Py_ssize_t size = Py_SIZE(b); if (likely(__Pyx_sst_abs(size) <= 1)) { ival = likely(size) ? digits[0] : 0; if (size == -1) ival = -ival; return ival; } else { switch (size) { case 2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -2: if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -3: if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case 4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; case -4: if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); } break; } } #endif return PyLong_AsSsize_t(b); } x = PyNumber_Index(b); if (!x) return -1; ival = PyInt_AsSsize_t(x); Py_DECREF(x); return ival; } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { return PyInt_FromSize_t(ival); } #endif /* Py_PYTHON_H */ tinycss-0.4/tinycss/speedups.pyx0000644000175000017500000001572012766005714017104 0ustar lizelize00000000000000# coding: utf-8 """ tinycss.speedups ---------------- Cython module for speeding up inner loops. Right now only :func:`tokenize_flat` has a second implementation. :copyright: (c) 2010 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals from .token_data import ( COMPILED_TOKEN_REGEXPS, UNICODE_UNESCAPE, NEWLINE_UNESCAPE, SIMPLE_UNESCAPE, FIND_NEWLINES, TOKEN_DISPATCH) COMPILED_TOKEN_INDEXES = dict( (name, i) for i, (name, regexp) in enumerate(COMPILED_TOKEN_REGEXPS)) cdef class CToken: """A token built by the Cython speedups. Identical to :class:`~.token_data.Token`. """ is_container = False cdef public object type, _as_css, value, unit cdef public Py_ssize_t line, column def __init__(self, type_, css_value, value, unit, line, column): self.type = type_ self._as_css = css_value self.value = value self.unit = unit self.line = line self.column = column def as_css(self): """ Return as an Unicode string the CSS representation of the token, as parsed in the source. """ return self._as_css def __repr__(self): return ('' .format(self, self.unit or '')) def tokenize_flat(css_source, int ignore_comments=1): """ :param css_source: CSS as an unicode string :param ignore_comments: if true (the default) comments will not be included in the return value :return: An iterator of :class:`Token` """ # Make these local variable to avoid global lookups in the loop tokens_dispatch = TOKEN_DISPATCH compiled_token_indexes = COMPILED_TOKEN_INDEXES compiled_tokens = COMPILED_TOKEN_REGEXPS unicode_unescape = UNICODE_UNESCAPE newline_unescape = NEWLINE_UNESCAPE simple_unescape = SIMPLE_UNESCAPE find_newlines = FIND_NEWLINES # Use the integer indexes instead of string markers cdef Py_ssize_t BAD_COMMENT = compiled_token_indexes['BAD_COMMENT'] cdef Py_ssize_t BAD_STRING = compiled_token_indexes['BAD_STRING'] cdef Py_ssize_t PERCENTAGE = compiled_token_indexes['PERCENTAGE'] cdef Py_ssize_t DIMENSION = compiled_token_indexes['DIMENSION'] cdef Py_ssize_t ATKEYWORD = compiled_token_indexes['ATKEYWORD'] cdef Py_ssize_t FUNCTION = compiled_token_indexes['FUNCTION'] cdef Py_ssize_t COMMENT = compiled_token_indexes['COMMENT'] cdef Py_ssize_t NUMBER = compiled_token_indexes['NUMBER'] cdef Py_ssize_t STRING = compiled_token_indexes['STRING'] cdef Py_ssize_t IDENT = compiled_token_indexes['IDENT'] cdef Py_ssize_t HASH = compiled_token_indexes['HASH'] cdef Py_ssize_t URI = compiled_token_indexes['URI'] cdef Py_ssize_t DELIM = -1 cdef Py_ssize_t pos = 0 cdef Py_ssize_t line = 1 cdef Py_ssize_t column = 1 cdef Py_ssize_t source_len = len(css_source) cdef Py_ssize_t n_tokens = len(compiled_tokens) cdef Py_ssize_t length, next_pos, type_ cdef CToken token tokens = [] while pos < source_len: char = css_source[pos] if char in ':;{}()[]': type_ = -1 # not parsed further anyway type_name = char css_value = char else: codepoint = min(ord(char), 160) for type_, type_name, regexp in tokens_dispatch[codepoint]: match = regexp(css_source, pos) if match: # First match is the longest. See comments on TOKENS above. css_value = match.group() break else: # No match. # "Any other character not matched by the above rules, # and neither a single nor a double quote." # ... but quotes at the start of a token are always matched # by STRING or BAD_STRING. So DELIM is any single character. type_ = DELIM type_name = 'DELIM' css_value = char length = len(css_value) next_pos = pos + length # A BAD_COMMENT is a comment at EOF. Ignore it too. if not (ignore_comments and type_ in (COMMENT, BAD_COMMENT)): # Parse numbers, extract strings and URIs, unescape unit = None if type_ == DIMENSION: value = match.group(1) value = float(value) if '.' in value else int(value) unit = match.group(2) unit = simple_unescape(unit) unit = unicode_unescape(unit) unit = unit.lower() # normalize elif type_ == PERCENTAGE: value = css_value[:-1] value = float(value) if '.' in value else int(value) unit = '%' elif type_ == NUMBER: value = css_value if '.' in value: value = float(value) else: value = int(value) type_name = 'INTEGER' elif type_ in (IDENT, ATKEYWORD, HASH, FUNCTION): value = simple_unescape(css_value) value = unicode_unescape(value) elif type_ == URI: value = match.group(1) if value and value[0] in '"\'': value = value[1:-1] # Remove quotes value = newline_unescape(value) value = simple_unescape(value) value = unicode_unescape(value) elif type_ == STRING: value = css_value[1:-1] # Remove quotes value = newline_unescape(value) value = simple_unescape(value) value = unicode_unescape(value) # BAD_STRING can only be one of: # * Unclosed string at the end of the stylesheet: # Close the string, but this is not an error. # Make it a "good" STRING token. # * Unclosed string at the (unescaped) end of the line: # Close the string, but this is an error. # Leave it as a BAD_STRING, don’t bother parsing it. # See http://www.w3.org/TR/CSS21/syndata.html#parsing-errors elif type_ == BAD_STRING and next_pos == source_len: type_name = 'STRING' value = css_value[1:] # Remove quote value = newline_unescape(value) value = simple_unescape(value) value = unicode_unescape(value) else: value = css_value token = CToken(type_name, css_value, value, unit, line, column) tokens.append(token) pos = next_pos newlines = list(find_newlines(css_value)) if newlines: line += len(newlines) # Add 1 to have lines start at column 1, not 0 column = length - newlines[-1].end() + 1 else: column += length return tokens tinycss-0.4/tinycss/token_data.py0000644000175000017500000003220012766235546017175 0ustar lizelize00000000000000# coding: utf-8 """ tinycss.token_data ------------------ Shared data for both implementations (Cython and Python) of the tokenizer. :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals import functools import operator import re import string import sys # * Raw strings with the r'' notation are used so that \ do not need # to be escaped. # * Names and regexps are separated by a tabulation. # * Macros are re-ordered so that only previous definitions are needed. # * {} are used for macro substitution with ``string.Formatter``, # so other uses of { or } have been doubled. # * The syntax is otherwise compatible with re.compile. # * Some parentheses were added to add capturing groups. # (in unicode, DIMENSION and URI) # *** Willful violation: *** # Numbers can take a + or - sign, but the sign is a separate DELIM token. # Since comments are allowed anywhere between tokens, this makes # the following this is valid. It means 10 negative pixels: # margin-top: -/**/10px # This makes parsing numbers a pain, so instead we’ll do the same is Firefox # and make the sign part as of the 'num' macro. The above CSS will be invalid. # See discussion: # http://lists.w3.org/Archives/Public/www-style/2011Oct/0028.html MACROS = r''' nl \n|\r\n|\r|\f w [ \t\r\n\f]* nonascii [^\0-\237] unicode \\([0-9a-f]{{1,6}})(\r\n|[ \n\r\t\f])? simple_escape [^\n\r\f0-9a-f] escape {unicode}|\\{simple_escape} nmstart [_a-z]|{nonascii}|{escape} nmchar [_a-z0-9-]|{nonascii}|{escape} name {nmchar}+ ident [-]?{nmstart}{nmchar}* num [-+]?(?:[0-9]*\.[0-9]+|[0-9]+) string1 \"([^\n\r\f\\"]|\\{nl}|{escape})*\" string2 \'([^\n\r\f\\']|\\{nl}|{escape})*\' string {string1}|{string2} badstring1 \"([^\n\r\f\\"]|\\{nl}|{escape})*\\? badstring2 \'([^\n\r\f\\']|\\{nl}|{escape})*\\? badstring {badstring1}|{badstring2} badcomment1 \/\*[^*]*\*+([^/*][^*]*\*+)* badcomment2 \/\*[^*]*(\*+[^/*][^*]*)* badcomment {badcomment1}|{badcomment2} baduri1 url\({w}([!#$%&*-~]|{nonascii}|{escape})*{w} baduri2 url\({w}{string}{w} baduri3 url\({w}{badstring} baduri {baduri1}|{baduri2}|{baduri3} '''.replace(r'\0', '\0').replace(r'\237', '\237') # Removed these tokens. Instead, they’re tokenized as two DELIM each. # INCLUDES ~= # DASHMATCH |= # They are only used in selectors but selectors3 also have ^=, *= and $=. # We don’t actually parse selectors anyway # Re-ordered so that the longest match is always the first. # For example, "url('foo')" matches URI, BAD_URI, FUNCTION and IDENT, # but URI would always be a longer match than the others. TOKENS = r''' S [ \t\r\n\f]+ URI url\({w}({string}|([!#$%&*-\[\]-~]|{nonascii}|{escape})*){w}\) BAD_URI {baduri} FUNCTION {ident}\( UNICODE-RANGE u\+[0-9a-f?]{{1,6}}(-[0-9a-f]{{1,6}})? IDENT {ident} ATKEYWORD @{ident} HASH #{name} DIMENSION ({num})({ident}) PERCENTAGE {num}% NUMBER {num} STRING {string} BAD_STRING {badstring} COMMENT \/\*[^*]*\*+([^/*][^*]*\*+)*\/ BAD_COMMENT {badcomment} : : ; ; { \{{ } \}} ( \( ) \) [ \[ ] \] CDO ''' # Strings with {macro} expanded COMPILED_MACROS = {} COMPILED_TOKEN_REGEXPS = [] # [(name, regexp.match)] ordered COMPILED_TOKEN_INDEXES = {} # {name: i} helper for the C speedups # Indexed by codepoint value of the first character of a token. # Codepoints >= 160 (aka nonascii) all use the index 160. # values are (i, name, regexp.match) TOKEN_DISPATCH = [] try: unichr except NameError: # Python 3 unichr = chr unicode = str def _init(): """Import-time initialization.""" COMPILED_MACROS.clear() for line in MACROS.splitlines(): if line.strip(): name, value = line.split('\t') COMPILED_MACROS[name.strip()] = '(?:%s)' \ % value.format(**COMPILED_MACROS) COMPILED_TOKEN_REGEXPS[:] = ( ( name.strip(), re.compile( value.format(**COMPILED_MACROS), # Case-insensitive when matching eg. uRL(foo) # but preserve the case in extracted groups re.I ).match ) for line in TOKENS.splitlines() if line.strip() for name, value in [line.split('\t')] ) COMPILED_TOKEN_INDEXES.clear() for i, (name, regexp) in enumerate(COMPILED_TOKEN_REGEXPS): COMPILED_TOKEN_INDEXES[name] = i dispatch = [[] for i in range(161)] for chars, names in [ (' \t\r\n\f', ['S']), ('uU', ['URI', 'BAD_URI', 'UNICODE-RANGE']), # \ is an escape outside of another token (string.ascii_letters + '\\_-' + unichr(160), ['FUNCTION', 'IDENT']), (string.digits + '.+-', ['DIMENSION', 'PERCENTAGE', 'NUMBER']), ('@', ['ATKEYWORD']), ('#', ['HASH']), ('\'"', ['STRING', 'BAD_STRING']), ('/', ['COMMENT', 'BAD_COMMENT']), ('<', ['CDO']), ('-', ['CDC']), ]: for char in chars: dispatch[ord(char)].extend(names) for char in ':;{}()[]': dispatch[ord(char)] = [char] TOKEN_DISPATCH[:] = ( [ (index,) + COMPILED_TOKEN_REGEXPS[index] for name in names for index in [COMPILED_TOKEN_INDEXES[name]] ] for names in dispatch ) _init() def _unicode_replace(match, int=int, unichr=unichr, maxunicode=sys.maxunicode): codepoint = int(match.group(1), 16) if codepoint <= maxunicode: return unichr(codepoint) else: return '\N{REPLACEMENT CHARACTER}' # U+FFFD UNICODE_UNESCAPE = functools.partial( re.compile(COMPILED_MACROS['unicode'], re.I).sub, _unicode_replace) NEWLINE_UNESCAPE = functools.partial( re.compile(r'()\\' + COMPILED_MACROS['nl']).sub, '') SIMPLE_UNESCAPE = functools.partial( re.compile(r'\\(%s)' % COMPILED_MACROS['simple_escape'], re.I).sub, # Same as r'\1', but faster on CPython operator.methodcaller('group', 1)) FIND_NEWLINES = re.compile(COMPILED_MACROS['nl']).finditer class Token(object): """A single atomic token. .. attribute:: is_container Always ``False``. Helps to tell :class:`Token` apart from :class:`ContainerToken`. .. attribute:: type The type of token as a string: ``S`` A sequence of white space ``IDENT`` An identifier: a name that does not start with a digit. A name is a sequence of letters, digits, ``_``, ``-``, escaped characters and non-ASCII characters. Eg: ``margin-left`` ``HASH`` ``#`` followed immediately by a name. Eg: ``#ff8800`` ``ATKEYWORD`` ``@`` followed immediately by an identifier. Eg: ``@page`` ``URI`` Eg: ``url(foo)`` The content may or may not be quoted. ``UNICODE-RANGE`` ``U+`` followed by one or two hexadecimal Unicode codepoints. Eg: ``U+20-00FF`` ``INTEGER`` An integer with an optional ``+`` or ``-`` sign ``NUMBER`` A non-integer number with an optional ``+`` or ``-`` sign ``DIMENSION`` An integer or number followed immediately by an identifier (the unit). Eg: ``12px`` ``PERCENTAGE`` An integer or number followed immediately by ``%`` ``STRING`` A string, quoted with ``"`` or ``'`` ``:`` or ``;`` That character. ``DELIM`` A single character not matched in another token. Eg: ``,`` See the source of the :mod:`.token_data` module for the precise regular expressions that match various tokens. Note that other token types exist in the early tokenization steps, but these are ignored, are syntax errors, or are later transformed into :class:`ContainerToken` or :class:`FunctionToken`. .. attribute:: value The parsed value: * INTEGER, NUMBER, PERCENTAGE or DIMENSION tokens: the numeric value as an int or float. * STRING tokens: the unescaped string without quotes * URI tokens: the unescaped URI without quotes or ``url(`` and ``)`` markers. * IDENT, ATKEYWORD or HASH tokens: the unescaped token, with ``@`` or ``#`` markers left as-is * Other tokens: same as :attr:`as_css` *Unescaped* refers to the various escaping methods based on the backslash ``\`` character in CSS syntax. .. attribute:: unit * DIMENSION tokens: the normalized (unescaped, lower-case) unit name as a string. eg. ``'px'`` * PERCENTAGE tokens: the string ``'%'`` * Other tokens: ``None`` .. attribute:: line The line number in the CSS source of the start of this token. .. attribute:: column The column number (inside a source line) of the start of this token. """ is_container = False __slots__ = 'type', '_as_css', 'value', 'unit', 'line', 'column' def __init__(self, type_, css_value, value, unit, line, column): self.type = type_ self._as_css = css_value self.value = value self.unit = unit self.line = line self.column = column def as_css(self): """ Return as an Unicode string the CSS representation of the token, as parsed in the source. """ return self._as_css def __repr__(self): return ('' .format(self, self.unit or '')) def __eq__(self, other): if type(self) != type(other): raise TypeError( 'Cannot compare {0} and {1}'.format(type(self), type(other))) else: return all( self.type_ == other.type_, self._as_css == other._as_css, self.value == other.value, self.unit == other.unit, ) class ContainerToken(object): """A token that contains other (nested) tokens. .. attribute:: is_container Always ``True``. Helps to tell :class:`ContainerToken` apart from :class:`Token`. .. attribute:: type The type of token as a string. One of ``{``, ``(``, ``[`` or ``FUNCTION``. For ``FUNCTION``, the object is actually a :class:`FunctionToken`. .. attribute:: unit Always ``None``. Included to make :class:`ContainerToken` behave more like :class:`Token`. .. attribute:: content A list of :class:`Token` or nested :class:`ContainerToken`, not including the opening or closing token. .. attribute:: line The line number in the CSS source of the start of this token. .. attribute:: column The column number (inside a source line) of the start of this token. """ is_container = True unit = None __slots__ = 'type', '_css_start', '_css_end', 'content', 'line', 'column' def __init__(self, type_, css_start, css_end, content, line, column): self.type = type_ self._css_start = css_start self._css_end = css_end self.content = content self.line = line self.column = column def as_css(self): """ Return as an Unicode string the CSS representation of the token, as parsed in the source. """ parts = [self._css_start] parts.extend(token.as_css() for token in self.content) parts.append(self._css_end) return ''.join(parts) format_string = '' def __repr__(self): return (self.format_string + ' {0.content}').format(self) class FunctionToken(ContainerToken): """A specialized :class:`ContainerToken` for a ``FUNCTION`` group. Has an additional attribute: .. attribute:: function_name The unescaped name of the function, with the ``(`` marker removed. """ __slots__ = 'function_name', def __init__(self, type_, css_start, css_end, function_name, content, line, column): super(FunctionToken, self).__init__( type_, css_start, css_end, content, line, column) # Remove the ( marker: self.function_name = function_name[:-1] format_string = ('') class TokenList(list): """ A mixed list of :class:`~.token_data.Token` and :class:`~.token_data.ContainerToken` objects. This is a subclass of the builtin :class:`~builtins.list` type. It can be iterated, indexed and sliced as usual, but also has some additional API: """ @property def line(self): """The line number in the CSS source of the first token.""" return self[0].line @property def column(self): """The column number (inside a source line) of the first token.""" return self[0].column def as_css(self): """ Return as an Unicode string the CSS representation of the tokens, as parsed in the source. """ return ''.join(token.as_css() for token in self) tinycss-0.4/tinycss/tokenizer.py0000644000175000017500000001717112766235660017105 0ustar lizelize00000000000000# coding: utf-8 """ tinycss.tokenizer ----------------- Tokenizer for the CSS core syntax: http://www.w3.org/TR/CSS21/syndata.html#tokenization This is the pure-python implementation. See also speedups.pyx :copyright: (c) 2012 by Simon Sapin. :license: BSD, see LICENSE for more details. """ from __future__ import unicode_literals from . import token_data def tokenize_flat( css_source, ignore_comments=True, # Make these local variable to avoid global lookups in the loop tokens_dispatch=token_data.TOKEN_DISPATCH, unicode_unescape=token_data.UNICODE_UNESCAPE, newline_unescape=token_data.NEWLINE_UNESCAPE, simple_unescape=token_data.SIMPLE_UNESCAPE, find_newlines=token_data.FIND_NEWLINES, Token=token_data.Token, len=len, int=int, float=float, list=list, _None=None): """ :param css_source: CSS as an unicode string :param ignore_comments: if true (the default) comments will not be included in the return value :return: An iterator of :class:`Token` """ pos = 0 line = 1 column = 1 source_len = len(css_source) tokens = [] while pos < source_len: char = css_source[pos] if char in ':;{}()[]': type_ = char css_value = char else: codepoint = min(ord(char), 160) for _index, type_, regexp in tokens_dispatch[codepoint]: match = regexp(css_source, pos) if match: # First match is the longest. See comments on TOKENS above. css_value = match.group() break else: # No match. # "Any other character not matched by the above rules, # and neither a single nor a double quote." # ... but quotes at the start of a token are always matched # by STRING or BAD_STRING. So DELIM is any single character. type_ = 'DELIM' css_value = char length = len(css_value) next_pos = pos + length # A BAD_COMMENT is a comment at EOF. Ignore it too. if not (ignore_comments and type_ in ('COMMENT', 'BAD_COMMENT')): # Parse numbers, extract strings and URIs, unescape unit = _None if type_ == 'DIMENSION': value = match.group(1) value = float(value) if '.' in value else int(value) unit = match.group(2) unit = simple_unescape(unit) unit = unicode_unescape(unit) unit = unit.lower() # normalize elif type_ == 'PERCENTAGE': value = css_value[:-1] value = float(value) if '.' in value else int(value) unit = '%' elif type_ == 'NUMBER': value = css_value if '.' in value: value = float(value) else: value = int(value) type_ = 'INTEGER' elif type_ in ('IDENT', 'ATKEYWORD', 'HASH', 'FUNCTION'): value = simple_unescape(css_value) value = unicode_unescape(value) elif type_ == 'URI': value = match.group(1) if value and value[0] in '"\'': value = value[1:-1] # Remove quotes value = newline_unescape(value) value = simple_unescape(value) value = unicode_unescape(value) elif type_ == 'STRING': value = css_value[1:-1] # Remove quotes value = newline_unescape(value) value = simple_unescape(value) value = unicode_unescape(value) # BAD_STRING can only be one of: # * Unclosed string at the end of the stylesheet: # Close the string, but this is not an error. # Make it a "good" STRING token. # * Unclosed string at the (unescaped) end of the line: # Close the string, but this is an error. # Leave it as a BAD_STRING, don’t bother parsing it. # See http://www.w3.org/TR/CSS21/syndata.html#parsing-errors elif type_ == 'BAD_STRING' and next_pos == source_len: type_ = 'STRING' value = css_value[1:] # Remove quote value = newline_unescape(value) value = simple_unescape(value) value = unicode_unescape(value) else: value = css_value tokens.append(Token(type_, css_value, value, unit, line, column)) pos = next_pos newlines = list(find_newlines(css_value)) if newlines: line += len(newlines) # Add 1 to have lines start at column 1, not 0 column = length - newlines[-1].end() + 1 else: column += length return tokens def regroup(tokens): """ Match pairs of tokens: () [] {} function() (Strings in "" or '' are taken care of by the tokenizer.) Opening tokens are replaced by a :class:`ContainerToken`. Closing tokens are removed. Unmatched closing tokens are invalid but left as-is. All nested structures that are still open at the end of the stylesheet are implicitly closed. :param tokens: a *flat* iterable of tokens, as returned by :func:`tokenize_flat`. :return: A tree of tokens. """ # "global" objects for the inner recursion pairs = {'FUNCTION': ')', '(': ')', '[': ']', '{': '}'} tokens = iter(tokens) eof = [False] def _regroup_inner(stop_at=None, tokens=tokens, pairs=pairs, eof=eof, ContainerToken=token_data.ContainerToken, FunctionToken=token_data.FunctionToken): for token in tokens: type_ = token.type if type_ == stop_at: return end = pairs.get(type_) if end is None: yield token # Not a grouping token else: assert not isinstance(token, ContainerToken), ( 'Token looks already grouped: {0}'.format(token)) content = list(_regroup_inner(end)) if eof[0]: end = '' # Implicit end of structure at EOF. if type_ == 'FUNCTION': yield FunctionToken(token.type, token.as_css(), end, token.value, content, token.line, token.column) else: yield ContainerToken(token.type, token.as_css(), end, content, token.line, token.column) else: eof[0] = True # end of file/stylesheet return _regroup_inner() def tokenize_grouped(css_source, ignore_comments=True): """ :param css_source: CSS as an unicode string :param ignore_comments: if true (the default) comments will not be included in the return value :return: An iterator of :class:`Token` """ return regroup(tokenize_flat(css_source, ignore_comments)) # Optional Cython version of tokenize_flat # Make both versions available with explicit names for tests. python_tokenize_flat = tokenize_flat try: from . import speedups except ImportError: cython_tokenize_flat = None else: cython_tokenize_flat = speedups.tokenize_flat # Default to the Cython version if available tokenize_flat = cython_tokenize_flat tinycss-0.4/tinycss/version.py0000644000175000017500000000002012771253541016533 0ustar lizelize00000000000000VERSION = '0.4' tinycss-0.4/tinycss.egg-info/0000755000175000017500000000000012771254226016177 5ustar lizelize00000000000000tinycss-0.4/tinycss.egg-info/PKG-INFO0000644000175000017500000000352012771254226017274 0ustar lizelize00000000000000Metadata-Version: 1.1 Name: tinycss Version: 0.4 Summary: tinycss is a complete yet simple CSS parser for Python. Home-page: http://tinycss.readthedocs.io/ Author: Simon Sapin Author-email: simon.sapin@exyr.org License: BSD Description: 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: * CSS Color 3 * CSS Fonts 3 * CSS Paged Media 3 It is designed to be easy to extend for new CSS modules and syntax, and integrates well with cssselect_ for Selectors 3 support. Quick facts: * Free software: BSD licensed * Compatible with Python 2.7 and 3.x * Latest documentation `on python.org`_ * Source, issues and pull requests `on Github`_ * Releases `on PyPI`_ * Install with ``pip install tinycss`` .. _cssselect: http://packages.python.org/cssselect/ .. _on python.org: http://packages.python.org/tinycss/ .. _on Github: https://github.com/SimonSapin/tinycss/ .. _on PyPI: http://pypi.python.org/pypi/tinycss Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy tinycss-0.4/tinycss.egg-info/SOURCES.txt0000644000175000017500000000157712771254226020075 0ustar lizelize00000000000000.coveragerc .gitignore .travis.yml CHANGES LICENSE MANIFEST.in README.rst setup.cfg setup.py docs/changelog.rst docs/conf.py docs/css3.rst docs/extending.rst docs/hacking.rst docs/index.rst docs/parsing.rst docs/_static/custom.css docs/_templates/layout.html tinycss/__init__.py tinycss/color3.py tinycss/css21.py tinycss/decoding.py tinycss/fonts3.py tinycss/page3.py tinycss/parsing.py tinycss/speedups.c tinycss/speedups.pyx tinycss/token_data.py tinycss/tokenizer.py tinycss/version.py tinycss.egg-info/PKG-INFO tinycss.egg-info/SOURCES.txt tinycss.egg-info/dependency_links.txt tinycss.egg-info/requires.txt tinycss.egg-info/top_level.txt tinycss/tests/__init__.py tinycss/tests/speed.py tinycss/tests/test_api.py tinycss/tests/test_color3.py tinycss/tests/test_css21.py tinycss/tests/test_decoding.py tinycss/tests/test_fonts3.py tinycss/tests/test_page3.py tinycss/tests/test_tokenizer.pytinycss-0.4/tinycss.egg-info/dependency_links.txt0000644000175000017500000000000112771254226022245 0ustar lizelize00000000000000 tinycss-0.4/tinycss.egg-info/requires.txt0000644000175000017500000000007412771254226020600 0ustar lizelize00000000000000 [test] pytest-runner pytest-cov pytest-flake8 pytest-isort tinycss-0.4/tinycss.egg-info/top_level.txt0000644000175000017500000000001012771254226020720 0ustar lizelize00000000000000tinycss tinycss-0.4/.coveragerc0000644000175000017500000000021512766005714015130 0ustar lizelize00000000000000[run] branch = True [report] exclude_lines = pragma: no cover def __repr__ except ImportError omit = tinycss/tests/speed.py tinycss-0.4/.gitignore0000644000175000017500000000013512766005714015000 0ustar lizelize00000000000000*.pyc *.c *.so *.egg-info /.coverage /htmlcov /build /dist /.tox /MANIFEST /docs/_build /env tinycss-0.4/.travis.yml0000644000175000017500000000030112766231031015105 0ustar lizelize00000000000000language: python python: - "2.7" - "3.3" - "3.4" - "3.5" - "pypy" - "pypy3" install: - pip install Cython - pip install --upgrade -e .[test] script: - python setup.py test tinycss-0.4/CHANGES0000644000175000017500000000150212771252001013767 0ustar lizelize00000000000000tinycss changelog ================= Version 0.4 ----------- Released on 2016-09-23. * Add an __eq__ operator to Token object. * Support Fonts 3. Version 0.3 ----------- Released on 2012-09-18. * Fix a bug when parsing \5c (an escaped antislash.) Version 0.2 ----------- Released on 2012-04-27. **Breaking changes:** * Remove the ``selectors3`` module. The functionality has moved to the `cssselect `_ project. * Simplify the API for :func:`~tinycss.make_parser`. Version 0.1.1 ------------- Released on 2012-04-06. Bug fixes: * Error handling on exepected end of stylesheet in an at-rule head * Fix the installation on ASCII-only locales Version 0.1 ----------- Released on 2012-04-05. First release. Parser support for CSS 2.1, Seloctors 3, Color 3 and Paged Media 3. tinycss-0.4/LICENSE0000644000175000017500000000276112766005714014024 0ustar lizelize00000000000000Copyright (c) 2012 by Simon Sapin. Some rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. tinycss-0.4/MANIFEST.in0000644000175000017500000000016512766005714014551 0ustar lizelize00000000000000include README.rst CHANGES LICENSE tox.ini .coveragerc tinycss/speedups.c recursive-include docs * prune docs/_build tinycss-0.4/README.rst0000644000175000017500000000150112771246011014466 0ustar lizelize00000000000000tinycss: 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: * CSS Color 3 * CSS Fonts 3 * CSS Paged Media 3 It is designed to be easy to extend for new CSS modules and syntax, and integrates well with cssselect_ for Selectors 3 support. Quick facts: * Free software: BSD licensed * Compatible with Python 2.7 and 3.x * Latest documentation `on python.org`_ * Source, issues and pull requests `on Github`_ * Releases `on PyPI`_ * Install with ``pip install tinycss`` .. _cssselect: http://packages.python.org/cssselect/ .. _on python.org: http://packages.python.org/tinycss/ .. _on Github: https://github.com/SimonSapin/tinycss/ .. _on PyPI: http://pypi.python.org/pypi/tinycss tinycss-0.4/setup.cfg0000644000175000017500000000064712771254226014641 0ustar lizelize00000000000000[build_sphinx] source-dir = docs build-dir = docs/_build [upload_sphinx] upload-dir = docs/_build/html [aliases] test = pytest [tool:pytest] addopts = --flake8 --isort --cov --ignore=test/cairosvg_reference norecursedirs = dist .cache .git build *.egg-info .eggs venv cairosvg_reference flake8-ignore = docs/conf.py ALL isort_ignore = docs/conf.py setup.py [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 tinycss-0.4/setup.py0000644000175000017500000001005112771253325014517 0ustar lizelize00000000000000import os.path import re import sys from distutils.errors import ( CCompilerError, DistutilsExecError, DistutilsPlatformError) from setuptools import Extension, setup try: from Cython.Distutils import build_ext import Cython.Compiler.Version CYTHON_INSTALLED = True except ImportError: from distutils.command.build_ext import build_ext CYTHON_INSTALLED = False ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) if sys.platform == 'win32' and sys.version_info > (2, 6): # 2.6's distutils.msvc9compiler can raise an IOError when failing to # find the compiler ext_errors += (IOError,) class BuildFailed(Exception): pass class ve_build_ext(build_ext): # This class allows C extension building to fail. def run(self): try: build_ext.run(self) except DistutilsPlatformError: raise BuildFailed def build_extension(self, ext): try: build_ext.build_extension(self, ext) except ext_errors: raise BuildFailed ROOT = os.path.dirname(__file__) with open(os.path.join(ROOT, 'tinycss', 'version.py')) as fd: VERSION = re.search("VERSION = '([^']+)'", fd.read()).group(1) with open(os.path.join(ROOT, 'README.rst'), 'rb') as fd: README = fd.read().decode('utf8') needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv) pytest_runner = ['pytest-runner'] if needs_pytest else [] def run_setup(with_extension): if with_extension: extension_path = os.path.join('tinycss', 'speedups') if CYTHON_INSTALLED: extension_path += '.pyx' print('Building with Cython %s.' % Cython.Compiler.Version.version) else: extension_path += '.c' if not os.path.exists(extension_path): print("WARNING: Trying to build without Cython, but " "pre-generated '%s' does not seem to be available." % extension_path) else: print('Building without Cython.') kwargs = dict( cmdclass=dict(build_ext=ve_build_ext), ext_modules=[Extension('tinycss.speedups', sources=[extension_path])], ) else: kwargs = dict() setup( name='tinycss', version=VERSION, url='http://tinycss.readthedocs.io/', license='BSD', author='Simon Sapin', author_email='simon.sapin@exyr.org', description='tinycss is a complete yet simple CSS parser for Python.', long_description=README, classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', ], setup_requires=pytest_runner, tests_require=[ 'pytest-cov', 'pytest-flake8', 'pytest-isort', 'pytest-runner'], extras_require={'test': ( 'pytest-runner', 'pytest-cov', 'pytest-flake8', 'pytest-isort')}, packages=['tinycss', 'tinycss.tests'], **kwargs ) IS_PYPY = hasattr(sys, 'pypy_translation_info') try: run_setup(not IS_PYPY) except BuildFailed: BUILD_EXT_WARNING = ('WARNING: The extension could not be compiled, ' 'speedups are not enabled.') print('*' * 75) print(BUILD_EXT_WARNING) print('Failure information, if any, is above.') print('Retrying the build without the Cython extension now.') print('*' * 75) run_setup(False) print('*' * 75) print(BUILD_EXT_WARNING) print('Plain-Python installation succeeded.') print('*' * 75) tinycss-0.4/PKG-INFO0000644000175000017500000000352012771254226014106 0ustar lizelize00000000000000Metadata-Version: 1.1 Name: tinycss Version: 0.4 Summary: tinycss is a complete yet simple CSS parser for Python. Home-page: http://tinycss.readthedocs.io/ Author: Simon Sapin Author-email: simon.sapin@exyr.org License: BSD Description: 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: * CSS Color 3 * CSS Fonts 3 * CSS Paged Media 3 It is designed to be easy to extend for new CSS modules and syntax, and integrates well with cssselect_ for Selectors 3 support. Quick facts: * Free software: BSD licensed * Compatible with Python 2.7 and 3.x * Latest documentation `on python.org`_ * Source, issues and pull requests `on Github`_ * Releases `on PyPI`_ * Install with ``pip install tinycss`` .. _cssselect: http://packages.python.org/cssselect/ .. _on python.org: http://packages.python.org/tinycss/ .. _on Github: https://github.com/SimonSapin/tinycss/ .. _on PyPI: http://pypi.python.org/pypi/tinycss Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy