home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1526 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  10.2 KB  |  270 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 1878 2009-11-17 20:16:26Z 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.             oldvalue = self.seqs[1].cssText
  142.             
  143.             try:
  144.                 self.seqs[1].cssText = cssText
  145.             except:
  146.                 self.seqs[1].cssText = oldvalue
  147.                 raise 
  148.  
  149.             if self.wellformed:
  150.                 pass
  151.             self.wellformed = self.seqs[1].wellformed
  152.  
  153.     cssValue = property(_getCSSValue, _setCSSValue, doc = '(cssutils) CSSValue object of this property')
  154.     
  155.     def _getValue(self):
  156.         if self.cssValue:
  157.             return self.cssValue.cssText
  158.         return u''
  159.  
  160.     
  161.     def _setValue(self, value):
  162.         self._setCSSValue(value)
  163.  
  164.     value = property(_getValue, _setValue, doc = 'The textual value of this Properties cssValue.')
  165.     
  166.     def _setPriority(self, priority):
  167.         if self._mediaQuery:
  168.             self._priority = u''
  169.             self._literalpriority = u''
  170.             if priority:
  171.                 self._log.error(u'Property: No priority in a MediaQuery - ignored.')
  172.             
  173.             return None
  174.         if isinstance(priority, basestring) and u'important' == self._normalize(priority):
  175.             priority = u'!%s' % priority
  176.         
  177.         new = {
  178.             'literalpriority': u'',
  179.             'wellformed': True }
  180.         
  181.         def _char(expected, seq, token, tokenizer = (None, None)):
  182.             val = self._tokenvalue(token)
  183.             if expected == expected:
  184.                 pass
  185.             elif expected == val:
  186.                 seq.append(val)
  187.                 return 'important'
  188.             new['wellformed'] = False
  189.             self._log.error(u'Property: Unexpected char.', token)
  190.             return expected
  191.  
  192.         
  193.         def _ident(expected, seq, token, tokenizer = (None, None)):
  194.             val = self._tokenvalue(token)
  195.             if 'important' == expected:
  196.                 new['literalpriority'] = val
  197.                 seq.append(val)
  198.                 return 'EOF'
  199.             new['wellformed'] = False
  200.             self._log.error(u'Property: Unexpected ident.', token)
  201.             return expected
  202.  
  203.         newseq = []
  204.         (wellformed, expected) = self._parse(expected = '!', seq = newseq, tokenizer = self._tokenize2(priority), productions = {
  205.             'CHAR': _char,
  206.             'IDENT': _ident })
  207.         if wellformed:
  208.             pass
  209.         wellformed = new['wellformed']
  210.         if priority and not new['literalpriority']:
  211.             wellformed = False
  212.             self._log.info(u'Property: Invalid priority: %r.' % self._valuestr(priority))
  213.         
  214.         if wellformed:
  215.             if self.wellformed:
  216.                 pass
  217.             self.wellformed = wellformed
  218.             self._literalpriority = new['literalpriority']
  219.             self._priority = self._normalize(self.literalpriority)
  220.             self.seqs[2] = newseq
  221.             if self._priority not in (u'', u'important'):
  222.                 self._log.error(u'Property: No CSS priority value: %r.' % self._priority)
  223.             
  224.         
  225.  
  226.     priority = property((lambda self: self._priority), _setPriority, doc = 'Priority of this property.')
  227.     literalpriority = property((lambda self: self._literalpriority), doc = 'Readonly literal (not normalized) priority of this property')
  228.     
  229.     def _setParent(self, parent):
  230.         self._parent = parent
  231.  
  232.     parent = property((lambda self: self._parent), _setParent, doc = 'The Parent Node (normally a CSSStyledeclaration) of this Property')
  233.     
  234.     def validate(self):
  235.         valid = False
  236.         profiles = None
  237.         
  238.         try:
  239.             rule = self.parent.parentRule
  240.             if rule.type == rule.FONT_FACE_RULE:
  241.                 profiles = [
  242.                     cssutils.profile.CSS3_FONT_FACE]
  243.         except AttributeError:
  244.             pass
  245.  
  246.         if self.name and self.value:
  247.             if self.name in cssutils.profile.knownNames:
  248.                 (valid, matching, validprofiles) = cssutils.profile.validateWithProfile(self.name, self.value, profiles)
  249.                 if not valid:
  250.                     self._log.error(u'Property: Invalid value for "%s" property: %s' % (u'/'.join(validprofiles), self.value), token = self._Property__nametoken, neverraise = True)
  251.                 elif valid and not matching:
  252.                     if not profiles:
  253.                         notvalidprofiles = u'/'.join(cssutils.profile.defaultProfiles)
  254.                     else:
  255.                         notvalidprofiles = profiles
  256.                     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)
  257.                     valid = False
  258.                 elif valid:
  259.                     self._log.debug(u'Property: Found valid "%s" value: %s' % (u'/'.join(validprofiles), self.value), token = self._Property__nametoken, neverraise = True)
  260.                 
  261.             
  262.         
  263.         if self._priority not in (u'', u'important'):
  264.             valid = False
  265.         
  266.         return valid
  267.  
  268.     valid = property(validate, doc = 'Check if value of this property is valid in the properties context.')
  269.  
  270.