home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) __all__ = [ 'CSSVariablesDeclaration'] __docformat__ = 'restructuredtext' __version__ = '$Id: cssstyledeclaration.py 1819 2009-08-01 20:52:43Z cthedot $' from cssutils.prodparser import * from cssvalue import CSSValue import cssutils import itertools import xml.dom as xml class CSSVariablesDeclaration(cssutils.util._NewBase): def __init__(self, cssText = u'', parentRule = None, readonly = False): super(CSSVariablesDeclaration, self).__init__() self._parentRule = parentRule self._vars = { } if cssText: self.cssText = cssText self._readonly = readonly def __repr__(self): return 'cssutils.css.%s(cssText=%r)' % (self.__class__.__name__, self.cssText) def __str__(self): return '<cssutils.css.%s object length=%r at 0x%x>' % (self.__class__.__name__, self.length, id(self)) def __contains__(self, variableName): return variableName.lower() in self.keys() def __getitem__(self, variableName): return self.getVariableValue(variableName.lower()) def __setitem__(self, variableName, value): self.setVariable(variableName.lower(), value) def __delitem__(self, variableName): return self.removeVariable(variableName.lower()) def __iter__(self): for name in self.keys(): yield name def _absorb(self, other): self._parentRule = other._parentRule self.seq.absorb(other.seq) self._readonly = other._readonly def keys(self): return self._vars.keys() def _getCssText(self): return cssutils.ser.do_css_CSSVariablesDeclaration(self) def _setCssText(self, cssText): self._checkReadonly() vardeclaration = Sequence(PreDef.ident(), PreDef.char(u':', u':', toSeq = False), Prod(name = u'term', match = (lambda t, v: True), toSeq = (lambda t, tokens: (u'value', CSSValue(itertools.chain([ t], tokens))))), PreDef.char(u';', u';', toSeq = False, optional = True)) prods = Sequence(vardeclaration, minmax = (lambda : (0, None))) (wellformed, seq, store, notused) = ProdParser().parse(cssText, u'CSSVariableDeclaration', prods) if wellformed: newseq = self._tempSeq() lastname = None for item in seq: if u'IDENT' == item.type: lastname = item self._vars[lastname.value.lower()] = None continue if u'value' == item.type: self._vars[lastname.value.lower()] = item.value newseq.append((lastname.value, item.value), 'var', lastname.line, lastname.col) continue newseq.appendItem(item) self._setSeq(newseq) self.wellformed = True cssText = property(_getCssText, _setCssText, doc = '(DOM) A parsable textual representation of the declaration block excluding the surrounding curly braces.') def _setParentRule(self, parentRule): self._parentRule = parentRule parentRule = property((lambda self: self._parentRule), _setParentRule, doc = '(DOM) The CSS rule that contains this declaration block or None if this block is not attached to a CSSRule.') def getVariableValue(self, variableName): try: return self._vars[variableName.lower()].cssText except KeyError: e = None return u'' def removeVariable(self, variableName): try: r = self._vars[variableName.lower()] except KeyError: e = None return u'' self.seq._readonly = False if variableName in self._vars: for i, x in enumerate(self.seq): if x.value[0] == variableName: del self.seq[i] continue self.seq._readonly = True del self._vars[variableName.lower()] return r.cssText def setVariable(self, variableName, value): self._checkReadonly() (wellformed, seq, store, unused) = ProdParser().parse(variableName.lower(), u'variableName', Sequence(PreDef.ident())) if not wellformed: self._log.error(u'Invalid variableName: %r: %r' % (variableName, value)) elif isinstance(value, CSSValue): v = value else: v = CSSValue(cssText = value) if not v.wellformed: self._log.error(u'Invalid variable value: %r: %r' % (variableName, value)) else: self.seq._readonly = False if variableName in self._vars: for i, x in enumerate(self.seq): if x.value[0] == variableName: x.replace(i, [ variableName, v], x.type, x.line, x.col) break continue else: self.seq.append([ variableName, v], 'var') self.seq._readonly = True self._vars[variableName] = v def item(self, index): try: return self.keys()[index] except IndexError: return u'' length = property((lambda self: len(self._vars)), doc = 'The number of variables that have been explicitly set in this variable declaration block. The range of valid indices is 0 to length-1 inclusive.')