home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __all__ = [
- 'Property']
- __docformat__ = 'restructuredtext'
- __version__ = '$Id: property.py 1878 2009-11-17 20:16:26Z cthedot $'
- from cssutils.helper import Deprecated
- from cssvalue import CSSValue
- import cssutils
- import xml.dom as xml
-
- class Property(cssutils.util.Base):
-
- def __init__(self, name = None, value = None, priority = u'', _mediaQuery = False, parent = None):
- super(Property, self).__init__()
- self.seqs = [
- [],
- None,
- []]
- self.wellformed = False
- self._mediaQuery = _mediaQuery
- self.parent = parent
- self._Property__nametoken = None
- self._name = u''
- self._literalname = u''
- self.seqs[1] = CSSValue(parent = self)
- if name:
- self.name = name
- self.cssValue = value
-
- self._priority = u''
- self._literalpriority = u''
- if priority:
- self.priority = priority
-
-
-
- def __repr__(self):
- return 'cssutils.css.%s(name=%r, value=%r, priority=%r)' % (self.__class__.__name__, self.literalname, self.cssValue.cssText, self.priority)
-
-
- def __str__(self):
- return '<%s.%s object name=%r value=%r priority=%r valid=%r at 0x%x>' % (self.__class__.__module__, self.__class__.__name__, self.name, self.cssValue.cssText, self.priority, self.valid, id(self))
-
-
- def _getCssText(self):
- return cssutils.ser.do_Property(self)
-
-
- def _setCssText(self, cssText):
- tokenizer = self._tokenize2(cssText)
- nametokens = self._tokensupto2(tokenizer, propertynameendonly = True)
- if nametokens:
- wellformed = True
- valuetokens = self._tokensupto2(tokenizer, propertyvalueendonly = True)
- prioritytokens = self._tokensupto2(tokenizer, propertypriorityendonly = True)
- if self._mediaQuery and not valuetokens:
- self.name = nametokens
- self.cssValue = None
- self.priority = None
- return None
- colontoken = nametokens.pop()
- if self._tokenvalue(colontoken) != u':':
- wellformed = False
- self._log.error(u'Property: No ":" after name found: %r' % self._valuestr(cssText), colontoken)
- elif not nametokens:
- wellformed = False
- self._log.error(u'Property: No property name found: %r.' % self._valuestr(cssText), colontoken)
-
- if valuetokens:
- if self._tokenvalue(valuetokens[-1]) == u'!':
- prioritytokens.insert(0, valuetokens.pop(-1))
-
- else:
- wellformed = False
- self._log.error(u'Property: No property value found: %r.' % self._valuestr(cssText), colontoken)
- if wellformed:
- self.wellformed = True
- self.name = nametokens
- self.cssValue = valuetokens
- self.priority = prioritytokens
- self.validate()
-
- else:
- self._log.error(u'Property: No property name found: %r.' % self._valuestr(cssText))
-
- cssText = property(fget = _getCssText, fset = _setCssText, doc = 'A parsable textual representation.')
-
- def _setName(self, name):
- new = {
- 'literalname': None,
- 'wellformed': True }
-
- def _ident(expected, seq, token, tokenizer = (None, None)):
- if 'name' == expected:
- new['literalname'] = self._tokenvalue(token).lower()
- seq.append(new['literalname'])
- return 'EOF'
- new['wellformed'] = False
- self._log.error(u'Property: Unexpected ident.', token)
- return expected
-
- newseq = []
- (wellformed, expected) = self._parse(expected = 'name', seq = newseq, tokenizer = self._tokenize2(name), productions = {
- 'IDENT': _ident })
- if wellformed:
- pass
- wellformed = new['wellformed']
- if isinstance(name, list):
- token = name[0]
- self._Property__nametoken = token
- else:
- token = None
- if not new['literalname']:
- wellformed = False
- self._log.error(u'Property: No name found: %r' % self._valuestr(name), token = token)
-
- if wellformed:
- self.wellformed = True
- self._literalname = new['literalname']
- self._name = self._normalize(self._literalname)
- self.seqs[0] = newseq
- if self._name not in cssutils.profile.knownNames:
- self._log.warn(u'Property: Unknown Property name.', token = token, neverraise = True)
-
- else:
- self.wellformed = False
-
- name = property((lambda self: self._name), _setName, doc = 'Name of this property.')
- literalname = property((lambda self: self._literalname), doc = 'Readonly literal (not normalized) name of this property')
-
- def _getCSSValue(self):
- return self.seqs[1]
-
-
- def _setCSSValue(self, cssText):
- if self._mediaQuery and not cssText:
- self.seqs[1] = CSSValue(parent = self)
- else:
- oldvalue = self.seqs[1].cssText
-
- try:
- self.seqs[1].cssText = cssText
- except:
- self.seqs[1].cssText = oldvalue
- raise
-
- if self.wellformed:
- pass
- self.wellformed = self.seqs[1].wellformed
-
- cssValue = property(_getCSSValue, _setCSSValue, doc = '(cssutils) CSSValue object of this property')
-
- def _getValue(self):
- if self.cssValue:
- return self.cssValue.cssText
- return u''
-
-
- def _setValue(self, value):
- self._setCSSValue(value)
-
- value = property(_getValue, _setValue, doc = 'The textual value of this Properties cssValue.')
-
- def _setPriority(self, priority):
- if self._mediaQuery:
- self._priority = u''
- self._literalpriority = u''
- if priority:
- self._log.error(u'Property: No priority in a MediaQuery - ignored.')
-
- return None
- if isinstance(priority, basestring) and u'important' == self._normalize(priority):
- priority = u'!%s' % priority
-
- new = {
- 'literalpriority': u'',
- 'wellformed': True }
-
- def _char(expected, seq, token, tokenizer = (None, None)):
- val = self._tokenvalue(token)
- if expected == expected:
- pass
- elif expected == val:
- seq.append(val)
- return 'important'
- new['wellformed'] = False
- self._log.error(u'Property: Unexpected char.', token)
- return expected
-
-
- def _ident(expected, seq, token, tokenizer = (None, None)):
- val = self._tokenvalue(token)
- if 'important' == expected:
- new['literalpriority'] = val
- seq.append(val)
- return 'EOF'
- new['wellformed'] = False
- self._log.error(u'Property: Unexpected ident.', token)
- return expected
-
- newseq = []
- (wellformed, expected) = self._parse(expected = '!', seq = newseq, tokenizer = self._tokenize2(priority), productions = {
- 'CHAR': _char,
- 'IDENT': _ident })
- if wellformed:
- pass
- wellformed = new['wellformed']
- if priority and not new['literalpriority']:
- wellformed = False
- self._log.info(u'Property: Invalid priority: %r.' % self._valuestr(priority))
-
- if wellformed:
- if self.wellformed:
- pass
- self.wellformed = wellformed
- self._literalpriority = new['literalpriority']
- self._priority = self._normalize(self.literalpriority)
- self.seqs[2] = newseq
- if self._priority not in (u'', u'important'):
- self._log.error(u'Property: No CSS priority value: %r.' % self._priority)
-
-
-
- priority = property((lambda self: self._priority), _setPriority, doc = 'Priority of this property.')
- literalpriority = property((lambda self: self._literalpriority), doc = 'Readonly literal (not normalized) priority of this property')
-
- def _setParent(self, parent):
- self._parent = parent
-
- parent = property((lambda self: self._parent), _setParent, doc = 'The Parent Node (normally a CSSStyledeclaration) of this Property')
-
- def validate(self):
- valid = False
- profiles = None
-
- try:
- rule = self.parent.parentRule
- if rule.type == rule.FONT_FACE_RULE:
- profiles = [
- cssutils.profile.CSS3_FONT_FACE]
- except AttributeError:
- pass
-
- if self.name and self.value:
- if self.name in cssutils.profile.knownNames:
- (valid, matching, validprofiles) = cssutils.profile.validateWithProfile(self.name, self.value, profiles)
- if not valid:
- self._log.error(u'Property: Invalid value for "%s" property: %s' % (u'/'.join(validprofiles), self.value), token = self._Property__nametoken, neverraise = True)
- elif valid and not matching:
- if not profiles:
- notvalidprofiles = u'/'.join(cssutils.profile.defaultProfiles)
- else:
- notvalidprofiles = profiles
- self._log.warn(u'Property: Not valid for profile "%s" but valid "%s" value: %s ' % (notvalidprofiles, u'/'.join(validprofiles), self.value), token = self._Property__nametoken, neverraise = True)
- valid = False
- elif valid:
- self._log.debug(u'Property: Found valid "%s" value: %s' % (u'/'.join(validprofiles), self.value), token = self._Property__nametoken, neverraise = True)
-
-
-
- if self._priority not in (u'', u'important'):
- valid = False
-
- return valid
-
- valid = property(validate, doc = 'Check if value of this property is valid in the properties context.')
-
-