home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) __all__ = [ 'SelectorList'] __docformat__ = 'restructuredtext' __version__ = '$Id: selectorlist.py 1868 2009-10-17 19:36:54Z cthedot $' from selector import Selector import cssutils import xml.dom as xml class SelectorList(cssutils.util.Base, cssutils.util.ListSeq): def __init__(self, selectorText = None, parentRule = None, readonly = False): super(SelectorList, self).__init__() self._parentRule = parentRule if selectorText: self.selectorText = selectorText self._readonly = readonly def __repr__(self): if self._namespaces: st = (self.selectorText, self._namespaces) else: st = self.selectorText return 'cssutils.css.%s(selectorText=%r)' % (self.__class__.__name__, st) def __str__(self): return '<cssutils.css.%s object selectorText=%r _namespaces=%r at 0x%x>' % (self.__class__.__name__, self.selectorText, self._namespaces, id(self)) def __setitem__(self, index, newSelector): newSelector = self._SelectorList__prepareset(newSelector) if newSelector: self.seq[index] = newSelector def __prepareset(self, newSelector, namespaces = None): if not namespaces: namespaces = { } self._checkReadonly() if not isinstance(newSelector, Selector): newSelector = Selector((newSelector, namespaces), parent = self) if newSelector.wellformed: newSelector._parent = self return newSelector def __getNamespaces(self): try: return self.parentRule.parentStyleSheet.namespaces except AttributeError: namespaces = { } for selector in self.seq: namespaces.update(selector._namespaces) return namespaces def _absorb(self, other): self._parentRule = other._parentRule self.seq[:] = other.seq[:] self._readonly = other._readonly def _getUsedUris(self): uris = set() for s in self: uris.update(s._getUsedUris()) return uris _namespaces = property(__getNamespaces, doc = 'If this SelectorList is\n attached to a CSSStyleSheet the namespaces of that sheet are mirrored\n here. While the SelectorList (or parentRule(s) are\n not attached the namespaces of all children Selectors are used.') def append(self, newSelector): self.appendSelector(newSelector) def appendSelector(self, newSelector): self._checkReadonly() (newSelector, namespaces) = self._splitNamespacesOff(newSelector) try: namespaces = self.parentRule.parentStyleSheet.namespaces except AttributeError: _namespaces = self._namespaces _namespaces.update(namespaces) namespaces = _namespaces newSelector = self._SelectorList__prepareset(newSelector, namespaces) if newSelector: seq = self.seq[:] del self.seq[:] for s in seq: if s.selectorText != newSelector.selectorText: self.seq.append(s) continue self.seq.append(newSelector) return newSelector def _getSelectorText(self): return cssutils.ser.do_css_SelectorList(self) def _setSelectorText(self, selectorText): self._checkReadonly() (selectorText, namespaces) = self._splitNamespacesOff(selectorText) try: namespaces = self.parentRule.parentStyleSheet.namespaces except AttributeError: pass wellformed = True tokenizer = self._tokenize2(selectorText) newseq = [] expected = True while True: selectortokens = self._tokensupto2(tokenizer, listseponly = True) if selectortokens: if self._tokenvalue(selectortokens[-1]) == ',': expected = selectortokens.pop() else: expected = None selector = Selector((selectortokens, namespaces), parent = self) if selector.wellformed: newseq.append(selector) else: wellformed = False self._log.error(u'SelectorList: Invalid Selector: %s' % self._valuestr(selectortokens)) selector.wellformed break if u',' == expected: wellformed = False self._log.error(u'SelectorList: Cannot end with ",": %r' % self._valuestr(selectorText)) elif expected: wellformed = False self._log.error(u'SelectorList: Unknown Syntax: %r' % self._valuestr(selectorText)) if wellformed: self.seq = newseq selectorText = property(_getSelectorText, _setSelectorText, doc = '(cssutils) The textual representation of the selector for\n a rule set.') length = property((lambda self: len(self)), doc = 'The number of :class:`~cssutils.css.Selector` objects in the list.') parentRule = property((lambda self: self._parentRule), doc = '(DOM) The CSS rule that contains this SelectorList or ``None`` if this SelectorList is not attached to a CSSRule.') wellformed = property((lambda self: bool(len(self.seq))))