3
OXPp  ã               @   sH   d Z ddlmZmZ ddlmZmZ G dd„ deƒZG dd„ deƒZ	d	S )
a  
    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.
é    )Úunicode_literalsÚdivisioné   )ÚCSS21ParserÚ
ParseErrorc               @   s   e Zd ZdZdd„ ZdS )Ú
MarginRulea  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.

    c             C   s   || _ || _|| _|| _d S )N)Ú
at_keywordÚdeclarationsÚlineÚcolumn)Úselfr   r	   r
   r   © r   úM/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/tinycss/page3.pyÚ__init__9   s    zMarginRule.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   $r   c                   sT   e Zd ZdZdddddddd	d
dddddddgZddgZ‡ fdd„Zdd„ Z‡  ZS )ÚCSSPage3Parsera>  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') |
    +--------------------------+------------------------+

    z@top-left-cornerz	@top-leftz@top-centerz
@top-rightz@top-right-cornerz@bottom-left-cornerz@bottom-leftz@bottom-centerz@bottom-rightz@bottom-right-cornerz	@left-topz@left-middlez@left-bottomz
@right-topz@right-middlez@right-bottomZ
stylesheetz@mediac                s”   |j | jkr~|dkr(t|d|j |f ƒ‚|jrPt|jd d|jd j|j f ƒ‚| j|jƒ\}}|j|ƒ t|j ||j	|j
ƒS tt| ƒj||||ƒS )Nz@pagez%s rule not allowed in %sr   z%unexpected %s token in %s rule header)r   ÚPAGE_MARGIN_AT_KEYWORDSr   ÚheadÚtypeZparse_declaration_listÚbodyÚextendr   r
   r   Úsuperr   Úparse_at_rule)r   ZruleZprevious_rulesÚerrorsÚcontextr	   Zbody_errors)Ú	__class__r   r   r   p   s    


zCSSPage3Parser.parse_at_rulec             C   sÎ   |sdS |d j dkrZ|jdƒj}x |rB|d j dkrB|jdƒ q$W |sT|dfdfS d}nd}d}t|ƒdkr¼|d j dkr¼|d j dkr¼|d j}dddddœj|ƒ}|r¼||f|| fS t|d d	ƒ‚dS )aU  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

        Nr   ZIDENTÚSr   é   ú:)ÚfirstZblankÚleftÚrightzinvalid @page selector©NN©r   r   r   )r%   r&   )r   r   r   )r   )r   )r   r   )r   r   )r   r   )r   r   )r   ÚpopÚvalueÚlenÚgetr   )r   r   ÚnameZname_specificityZpseudo_classZspecificityr   r   r   Úparse_page_selector€   s(    

z"CSSPage3Parser.parse_page_selector)	r   r   r   r   r   Zat_page_allowed_contextsr   r,   Ú__classcell__r   r   )r   r   r   @   s(   r   N)
r   Ú
__future__r   r   Zcss21r   r   Úobjectr   r   r   r   r   r   Ú<module>   s   -