home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1656 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  10.2 KB  |  271 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = [
  5.     'Property']
  6. __docformat__ = 'restructuredtext'
  7. __version__ = '$Id: property.py 1917 2010-03-14 18:29:08Z cthedot $'
  8. from cssutils.helper import Deprecated
  9. from cssvalue import CSSValue
  10. import cssutils
  11. import xml.dom as xml
  12.  
  13. class Property(cssutils.util.Base):
  14.     
  15.     def __init__(self, name = None, value = None, priority = u'', _mediaQuery = False, parent = None):
  16.         super(Property, self).__init__()
  17.         self.seqs = [
  18.             [],
  19.             None,
  20.             []]
  21.         self.wellformed = False
  22.         self._mediaQuery = _mediaQuery
  23.         self.parent = parent
  24.         self._Property__nametoken = None
  25.         self._name = u''
  26.         self._literalname = u''
  27.         self.seqs[1] = CSSValue(parent = self)
  28.         if name:
  29.             self.name = name
  30.             self.cssValue = value
  31.         
  32.         self._priority = u''
  33.         self._literalpriority = u''
  34.         if priority:
  35.             self.priority = priority
  36.         
  37.  
  38.     
  39.     def __repr__(self):
  40.         return 'cssutils.css.%s(name=%r, value=%r, priority=%r)' % (self.__class__.__name__, self.literalname, self.cssValue.cssText, self.priority)
  41.  
  42.     
  43.     def __str__(self):
  44.         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))
  45.  
  46.     
  47.     def _getCssText(self):
  48.         return cssutils.ser.do_Property(self)
  49.  
  50.     
  51.     def _setCssText(self, cssText):
  52.         tokenizer = self._tokenize2(cssText)
  53.         nametokens = self._tokensupto2(tokenizer, propertynameendonly = True)
  54.         if nametokens:
  55.             wellformed = True
  56.             valuetokens = self._tokensupto2(tokenizer, propertyvalueendonly = True)
  57.             prioritytokens = self._tokensupto2(tokenizer, propertypriorityendonly = True)
  58.             if self._mediaQuery and not valuetokens:
  59.                 self.name = nametokens
  60.                 self.cssValue = None
  61.                 self.priority = None
  62.                 return None
  63.             colontoken = nametokens.pop()
  64.             if self._tokenvalue(colontoken) != u':':
  65.                 wellformed = False
  66.                 self._log.error(u'Property: No ":" after name found: %r' % self._valuestr(cssText), colontoken)
  67.             elif not nametokens:
  68.                 wellformed = False
  69.                 self._log.error(u'Property: No property name found: %r.' % self._valuestr(cssText), colontoken)
  70.             
  71.             if valuetokens:
  72.                 if self._tokenvalue(valuetokens[-1]) == u'!':
  73.                     prioritytokens.insert(0, valuetokens.pop(-1))
  74.                 
  75.             else:
  76.                 wellformed = False
  77.                 self._log.error(u'Property: No property value found: %r.' % self._valuestr(cssText), colontoken)
  78.             if wellformed:
  79.                 self.wellformed = True
  80.                 self.name = nametokens
  81.                 self.cssValue = valuetokens
  82.                 self.priority = prioritytokens
  83.                 self.validate()
  84.             
  85.         else:
  86.             self._log.error(u'Property: No property name found: %r.' % self._valuestr(cssText))
  87.  
  88.     cssText = property(fget = _getCssText, fset = _setCssText, doc = 'A parsable textual representation.')
  89.     
  90.     def _setName(self, name):
  91.         new = {
  92.             'literalname': None,
  93.             'wellformed': True }
  94.         
  95.         def _ident(expected, seq, token, tokenizer = (None, None)):
  96.             if 'name' == expected:
  97.                 new['literalname'] = self._tokenvalue(token).lower()
  98.                 seq.append(new['literalname'])
  99.                 return 'EOF'
  100.             new['wellformed'] = False
  101.             self._log.error(u'Property: Unexpected ident.', token)
  102.             return expected
  103.  
  104.         newseq = []
  105.         (wellformed, expected) = self._parse(expected = 'name', seq = newseq, tokenizer = self._tokenize2(name), productions = {
  106.             'IDENT': _ident })
  107.         if wellformed:
  108.             pass
  109.         wellformed = new['wellformed']
  110.         if isinstance(name, list):
  111.             token = name[0]
  112.             self._Property__nametoken = token
  113.         else:
  114.             token = None
  115.         if not new['literalname']:
  116.             wellformed = False
  117.             self._log.error(u'Property: No name found: %r' % self._valuestr(name), token = token)
  118.         
  119.         if wellformed:
  120.             self.wellformed = True
  121.             self._literalname = new['literalname']
  122.             self._name = self._normalize(self._literalname)
  123.             self.seqs[0] = newseq
  124.             if self._name not in cssutils.profile.knownNames:
  125.                 self._log.warn(u'Property: Unknown Property name.', token = token, neverraise = True)
  126.             
  127.         else:
  128.             self.wellformed = False
  129.  
  130.     name = property((lambda self: self._name), _setName, doc = 'Name of this property.')
  131.     literalname = property((lambda self: self._literalname), doc = 'Readonly literal (not normalized) name of this property')
  132.     
  133.     def _getCSSValue(self):
  134.         return self.seqs[1]
  135.  
  136.     
  137.     def _setCSSValue(self, cssText):
  138.         if self._mediaQuery and not cssText:
  139.             self.seqs[1] = CSSValue(parent = self)
  140.         else:
  141.             
  142.             try:
  143.                 self.seqs[1].cssText = cssText
  144.             except xml.dom.SyntaxErr:
  145.                 e = None
  146.                 v = CSSValue(parent = self)
  147.                 v.cssText = cssText
  148.                 self.seqs[1] = v
  149.  
  150.             if self.wellformed:
  151.                 pass
  152.             self.wellformed = self.seqs[1].wellformed
  153.  
  154.     cssValue = property(_getCSSValue, _setCSSValue, doc = '(cssutils) CSSValue object of this property')
  155.     
  156.     def _getValue(self):
  157.         if self.cssValue:
  158.             return self.cssValue.cssText
  159.         return u''
  160.  
  161.     
  162.     def _setValue(self, value):
  163.         self._setCSSValue(value)
  164.  
  165.     value = property(_getValue, _setValue, doc = 'The textual value of this Properties cssValue.')
  166.     
  167.     def _setPriority(self, priority):
  168.         if self._mediaQuery:
  169.             self._priority = u''
  170.             self._literalpriority = u''
  171.             if priority:
  172.                 self._log.error(u'Property: No priority in a MediaQuery - ignored.')
  173.             
  174.             return None
  175.         if isinstance(priority, basestring) and u'important' == self._normalize(priority):
  176.             priority = u'!%s' % priority
  177.         
  178.         new = {
  179.             'literalpriority': u'',
  180.             'wellformed': True }
  181.         
  182.         def _char(expected, seq, token, tokenizer = (None, None)):
  183.             val = self._tokenvalue(token)
  184.             if expected == expected:
  185.                 pass
  186.             elif expected == val:
  187.                 seq.append(val)
  188.                 return 'important'
  189.             new['wellformed'] = False
  190.             self._log.error(u'Property: Unexpected char.', token)
  191.             return expected
  192.  
  193.         
  194.         def _ident(expected, seq, token, tokenizer = (None, None)):
  195.             val = self._tokenvalue(token)
  196.             if 'important' == expected:
  197.                 new['literalpriority'] = val
  198.                 seq.append(val)
  199.                 return 'EOF'
  200.             new['wellformed'] = False
  201.             self._log.error(u'Property: Unexpected ident.', token)
  202.             return expected
  203.  
  204.         newseq = []
  205.         (wellformed, expected) = self._parse(expected = '!', seq = newseq, tokenizer = self._tokenize2(priority), productions = {
  206.             'CHAR': _char,
  207.             'IDENT': _ident })
  208.         if wellformed:
  209.             pass
  210.         wellformed = new['wellformed']
  211.         if priority and not new['literalpriority']:
  212.             wellformed = False
  213.             self._log.info(u'Property: Invalid priority: %r.' % self._valuestr(priority))
  214.         
  215.         if wellformed:
  216.             if self.wellformed:
  217.                 pass
  218.             self.wellformed = wellformed
  219.             self._literalpriority = new['literalpriority']
  220.             self._priority = self._normalize(self.literalpriority)
  221.             self.seqs[2] = newseq
  222.             if self._priority not in (u'', u'important'):
  223.                 self._log.error(u'Property: No CSS priority value: %r.' % self._priority)
  224.             
  225.         
  226.  
  227.     priority = property((lambda self: self._priority), _setPriority, doc = 'Priority of this property.')
  228.     literalpriority = property((lambda self: self._literalpriority), doc = 'Readonly literal (not normalized) priority of this property')
  229.     
  230.     def _setParent(self, parent):
  231.         self._parent = parent
  232.  
  233.     parent = property((lambda self: self._parent), _setParent, doc = 'The Parent Node (normally a CSSStyledeclaration) of this Property')
  234.     
  235.     def validate(self):
  236.         valid = False
  237.         profiles = None
  238.         
  239.         try:
  240.             rule = self.parent.parentRule
  241.             if rule.type == rule.FONT_FACE_RULE:
  242.                 profiles = [
  243.                     cssutils.profile.CSS3_FONT_FACE]
  244.         except AttributeError:
  245.             pass
  246.  
  247.         if self.name and self.value:
  248.             if self.name in cssutils.profile.knownNames:
  249.                 (valid, matching, validprofiles) = cssutils.profile.validateWithProfile(self.name, self.value, profiles)
  250.                 if not valid:
  251.                     self._log.error(u'Property: Invalid value for "%s" property: %s' % (u'/'.join(validprofiles), self.value), token = self._Property__nametoken, neverraise = True)
  252.                 elif valid and not matching:
  253.                     if not profiles:
  254.                         notvalidprofiles = u'/'.join(cssutils.profile.defaultProfiles)
  255.                     else:
  256.                         notvalidprofiles = profiles
  257.                     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)
  258.                     valid = False
  259.                 elif valid:
  260.                     self._log.debug(u'Property: Found valid "%s" value: %s' % (u'/'.join(validprofiles), self.value), token = self._Property__nametoken, neverraise = True)
  261.                 
  262.             
  263.         
  264.         if self._priority not in (u'', u'important'):
  265.             valid = False
  266.         
  267.         return valid
  268.  
  269.     valid = property(validate, doc = 'Check if value of this property is valid in the properties context.')
  270.  
  271.