'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'

def parse_page_selector(self, head):

    if (not head):
        return ((None, None), (0, 0, 0))
    if (head[0].type == u'IDENT'):
        name = head.pop(0).value
        while (head and (head[0].type == u'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 == u':') and (head[1].type == u'IDENT')):
        pseudo_class = head[1].value
        specificity = {u'first': (1, 0), u'blank': (1, 0), u'left': (0, 1), u'right': (0, 1)}.get(pseudo_class)
        if specificity:
            return ((name, pseudo_class), (name_specificity + specificity))
    raise ParseError(head[0], u'invalid    @page    selector')
