home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __all__ = [
- 'CSSCharsetRule']
- __docformat__ = 'restructuredtext'
- __version__ = '$Id: csscharsetrule.py 1605 2009-01-03 18:27:32Z cthedot $'
- import codecs
- import cssrule
- import cssutils
- import xml.dom as xml
-
- class CSSCharsetRule(cssrule.CSSRule):
-
- def __init__(self, encoding = None, parentRule = None, parentStyleSheet = None, readonly = False):
- super(CSSCharsetRule, self).__init__(parentRule = parentRule, parentStyleSheet = parentStyleSheet)
- self._atkeyword = '@charset'
- self._encoding = None
- if encoding:
- self.encoding = encoding
-
- self._readonly = readonly
-
-
- def __repr__(self):
- return 'cssutils.css.%s(encoding=%r)' % (self.__class__.__name__, self.encoding)
-
-
- def __str__(self):
- return '<cssutils.css.%s object encoding=%r at 0x%x>' % (self.__class__.__name__, self.encoding, id(self))
-
-
- def _getCssText(self):
- return cssutils.ser.do_CSSCharsetRule(self)
-
-
- def _setCssText(self, cssText):
- super(CSSCharsetRule, self)._setCssText(cssText)
- wellformed = True
- tokenizer = self._tokenize2(cssText)
- if self._type(self._nexttoken(tokenizer)) != self._prods.CHARSET_SYM:
- wellformed = False
- self._log.error(u'CSSCharsetRule must start with "@charset "', error = xml.dom.InvalidModificationErr)
-
- encodingtoken = self._nexttoken(tokenizer)
- encodingtype = self._type(encodingtoken)
- encoding = self._stringtokenvalue(encodingtoken)
- if self._prods.STRING != encodingtype or not encoding:
- wellformed = False
- self._log.error(u'CSSCharsetRule: no encoding found; %r.' % self._valuestr(cssText))
-
- semicolon = self._tokenvalue(self._nexttoken(tokenizer))
- EOFtype = self._type(self._nexttoken(tokenizer))
- if u';' != semicolon or EOFtype not in ('EOF', None):
- wellformed = False
- self._log.error(u'CSSCharsetRule: Syntax Error: %r.' % self._valuestr(cssText))
-
- if wellformed:
- self.encoding = encoding
-
-
- cssText = property(fget = _getCssText, fset = _setCssText, doc = '(DOM) The parsable textual representation.')
-
- def _setEncoding(self, encoding):
- self._checkReadonly()
- tokenizer = self._tokenize2(encoding)
- encodingtoken = self._nexttoken(tokenizer)
- unexpected = self._nexttoken(tokenizer)
- valid = True
- if not encodingtoken and unexpected or self._prods.IDENT != self._type(encodingtoken):
- valid = False
- self._log.error('CSSCharsetRule: Syntax Error in encoding value %r.' % encoding)
- else:
-
- try:
- codecs.lookup(encoding)
- except LookupError:
- valid = False
- self._log.error('CSSCharsetRule: Unknown (Python) encoding %r.' % encoding)
-
- self._encoding = encoding.lower()
-
- encoding = property((lambda self: self._encoding), _setEncoding, doc = '(DOM)The encoding information used in this @charset rule.')
- type = property((lambda self: self.CHARSET_RULE), doc = 'The type of this rule, as defined by a CSSRule type constant.')
- wellformed = property((lambda self: bool(self.encoding)))
-
-