home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1566 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.4 KB  |  87 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = [
  5.     'CSSCharsetRule']
  6. __docformat__ = 'restructuredtext'
  7. __version__ = '$Id: csscharsetrule.py 1605 2009-01-03 18:27:32Z cthedot $'
  8. import codecs
  9. import cssrule
  10. import cssutils
  11. import xml.dom as xml
  12.  
  13. class CSSCharsetRule(cssrule.CSSRule):
  14.     
  15.     def __init__(self, encoding = None, parentRule = None, parentStyleSheet = None, readonly = False):
  16.         super(CSSCharsetRule, self).__init__(parentRule = parentRule, parentStyleSheet = parentStyleSheet)
  17.         self._atkeyword = '@charset'
  18.         self._encoding = None
  19.         if encoding:
  20.             self.encoding = encoding
  21.         
  22.         self._readonly = readonly
  23.  
  24.     
  25.     def __repr__(self):
  26.         return 'cssutils.css.%s(encoding=%r)' % (self.__class__.__name__, self.encoding)
  27.  
  28.     
  29.     def __str__(self):
  30.         return '<cssutils.css.%s object encoding=%r at 0x%x>' % (self.__class__.__name__, self.encoding, id(self))
  31.  
  32.     
  33.     def _getCssText(self):
  34.         return cssutils.ser.do_CSSCharsetRule(self)
  35.  
  36.     
  37.     def _setCssText(self, cssText):
  38.         super(CSSCharsetRule, self)._setCssText(cssText)
  39.         wellformed = True
  40.         tokenizer = self._tokenize2(cssText)
  41.         if self._type(self._nexttoken(tokenizer)) != self._prods.CHARSET_SYM:
  42.             wellformed = False
  43.             self._log.error(u'CSSCharsetRule must start with "@charset "', error = xml.dom.InvalidModificationErr)
  44.         
  45.         encodingtoken = self._nexttoken(tokenizer)
  46.         encodingtype = self._type(encodingtoken)
  47.         encoding = self._stringtokenvalue(encodingtoken)
  48.         if self._prods.STRING != encodingtype or not encoding:
  49.             wellformed = False
  50.             self._log.error(u'CSSCharsetRule: no encoding found; %r.' % self._valuestr(cssText))
  51.         
  52.         semicolon = self._tokenvalue(self._nexttoken(tokenizer))
  53.         EOFtype = self._type(self._nexttoken(tokenizer))
  54.         if u';' != semicolon or EOFtype not in ('EOF', None):
  55.             wellformed = False
  56.             self._log.error(u'CSSCharsetRule: Syntax Error: %r.' % self._valuestr(cssText))
  57.         
  58.         if wellformed:
  59.             self.encoding = encoding
  60.         
  61.  
  62.     cssText = property(fget = _getCssText, fset = _setCssText, doc = '(DOM) The parsable textual representation.')
  63.     
  64.     def _setEncoding(self, encoding):
  65.         self._checkReadonly()
  66.         tokenizer = self._tokenize2(encoding)
  67.         encodingtoken = self._nexttoken(tokenizer)
  68.         unexpected = self._nexttoken(tokenizer)
  69.         valid = True
  70.         if not encodingtoken and unexpected or self._prods.IDENT != self._type(encodingtoken):
  71.             valid = False
  72.             self._log.error('CSSCharsetRule: Syntax Error in encoding value %r.' % encoding)
  73.         else:
  74.             
  75.             try:
  76.                 codecs.lookup(encoding)
  77.             except LookupError:
  78.                 valid = False
  79.                 self._log.error('CSSCharsetRule: Unknown (Python) encoding %r.' % encoding)
  80.  
  81.             self._encoding = encoding.lower()
  82.  
  83.     encoding = property((lambda self: self._encoding), _setEncoding, doc = '(DOM)The encoding information used in this @charset rule.')
  84.     type = property((lambda self: self.CHARSET_RULE), doc = 'The type of this rule, as defined by a CSSRule type constant.')
  85.     wellformed = property((lambda self: bool(self.encoding)))
  86.  
  87.