コード例 #1
0
ファイル: csspagerule.py プロジェクト: andymckay/zamboni-lib
    def _setCssText(self, cssText):
        """
        :exceptions:    
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
        """
        super(CSSPageRule, self)._setCssText(cssText)
        
        tokenizer = self._tokenize2(cssText)
        if self._type(self._nexttoken(tokenizer)) != self._prods.PAGE_SYM:
            self._log.error(u'CSSPageRule: No CSSPageRule found: %s' %
                            self._valuestr(cssText), 
                            error=xml.dom.InvalidModificationErr)
        else:
            newStyle = CSSStyleDeclaration(parentRule=self)
            ok = True
            
            selectortokens, startbrace = self._tokensupto2(tokenizer, 
                                                           blockstartonly=True,
                                                           separateEnd=True)
            styletokens, braceorEOFtoken = self._tokensupto2(tokenizer, 
                                                        blockendonly=True,
                                                        separateEnd=True)
            nonetoken = self._nexttoken(tokenizer)
            if self._tokenvalue(startbrace) != u'{':
                ok = False
                self._log.error(
                    u'CSSPageRule: No start { of style declaration found: %r' %
                    self._valuestr(cssText), startbrace)
            elif nonetoken:
                ok = False
                self._log.error(
                    u'CSSPageRule: Trailing content found.', token=nonetoken)
                
            selok, newselectorseq = self.__parseSelectorText(selectortokens)
            ok = ok and selok

            val, type_ = self._tokenvalue(braceorEOFtoken),\
                       self._type(braceorEOFtoken)
            if val != u'}' and type_ != 'EOF':
                ok = False
                self._log.error(
                    u'CSSPageRule: No "}" after style declaration found: %r' %
                    self._valuestr(cssText))
            else:
                if 'EOF' == type_:
                    # add again as style needs it
                    styletokens.append(braceorEOFtoken)
                # SET, may raise:
                newStyle.cssText = styletokens

            if ok:
                self._selectorText = newselectorseq
                self.style = newStyle 
コード例 #2
0
ファイル: cssstylerule.py プロジェクト: andymckay/zamboni-lib
    def _setCssText(self, cssText):
        """
        :param cssText:
            a parseable string or a tuple of (cssText, dict-of-namespaces)
        :exceptions:
            - :exc:`~xml.dom.NamespaceErr`:
              Raised if the specified selector uses an unknown namespace
              prefix.
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
        """
        super(CSSStyleRule, self)._setCssText(cssText)
        
        # might be (cssText, namespaces)
        cssText, namespaces = self._splitNamespacesOff(cssText)
        try:
            # use parent style sheet ones if available
            namespaces = self.parentStyleSheet.namespaces
        except AttributeError:
            pass

        tokenizer = self._tokenize2(cssText)
        selectortokens = self._tokensupto2(tokenizer, blockstartonly=True)
        styletokens = self._tokensupto2(tokenizer, blockendonly=True)
        trail = self._nexttoken(tokenizer)
        if trail:
            self._log.error(u'CSSStyleRule: Trailing content: %s' % 
                            self._valuestr(cssText), token=trail)
        elif not selectortokens:
            self._log.error(u'CSSStyleRule: No selector found: %r' % 
                            self._valuestr(cssText))
        elif self._tokenvalue(selectortokens[0]).startswith(u'@'):
            self._log.error(u'CSSStyleRule: No style rule: %r' %
                            self._valuestr(cssText),
                            error=xml.dom.InvalidModificationErr)
        else:            
            newSelectorList = SelectorList(parentRule=self)
            newStyle = CSSStyleDeclaration(parentRule=self)
            ok = True
            
            bracetoken = selectortokens.pop()
            if self._tokenvalue(bracetoken) != u'{':
                ok = False
                self._log.error(
                    u'CSSStyleRule: No start { of style declaration found: %r' %
                    self._valuestr(cssText), bracetoken)
            elif not selectortokens:
                ok = False
                self._log.error(u'CSSStyleRule: No selector found: %r.' %
                            self._valuestr(cssText), bracetoken)
            # SET
            newSelectorList.selectorText = (selectortokens, 
                                              namespaces)

            if not styletokens:
                ok = False
                self._log.error(
                    u'CSSStyleRule: No style declaration or "}" found: %r' %
                    self._valuestr(cssText))
            else:
                braceorEOFtoken = styletokens.pop()
                val, typ = self._tokenvalue(braceorEOFtoken),\
                           self._type(braceorEOFtoken)
                if val != u'}' and typ != 'EOF':
                    ok = False
                    self._log.error(u'CSSStyleRule: No "}" after style '
                                    u'declaration found: %r'
                                    % self._valuestr(cssText))
                else:
                    if 'EOF' == typ:
                        # add again as style needs it
                        styletokens.append(braceorEOFtoken)                    
                    # SET, may raise:
                    newStyle.cssText = styletokens

            if ok:
                self.selectorList = newSelectorList
                self.style = newStyle
コード例 #3
0
    def _setCssText(self, cssText):
        """
        :exceptions:    
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
        """
        super(CSSPageRule, self)._setCssText(cssText)
        
        tokenizer = self._tokenize2(cssText)
        if self._type(self._nexttoken(tokenizer)) != self._prods.PAGE_SYM:
            self._log.error(u'CSSPageRule: No CSSPageRule found: %s' %
                            self._valuestr(cssText), 
                            error=xml.dom.InvalidModificationErr)
        else:
            wellformed = True
            selectortokens, startbrace = self._tokensupto2(tokenizer, 
                                                           blockstartonly=True,
                                                           separateEnd=True)
            styletokens, braceorEOFtoken = self._tokensupto2(tokenizer, 
                                                        blockendonly=True,
                                                        separateEnd=True)
            nonetoken = self._nexttoken(tokenizer)
            if self._tokenvalue(startbrace) != u'{':
                wellformed = False
                self._log.error(
                    u'CSSPageRule: No start { of style declaration found: %r' %
                    self._valuestr(cssText), startbrace)
            elif nonetoken:
                wellformed = False
                self._log.error(
                    u'CSSPageRule: Trailing content found.', token=nonetoken)
                
                
            wellformed, newselectorseq = self.__parseSelectorText(selectortokens)

            teststyle = CSSStyleDeclaration(parentRule=self)
            val, typ = self._tokenvalue(braceorEOFtoken), self._type(braceorEOFtoken)
            if val != u'}' and typ != 'EOF':
                wellformed = False
                self._log.error(
                    u'CSSPageRule: No "}" after style declaration found: %r' %
                    self._valuestr(cssText))
            else:
                if 'EOF' == typ:
                    # add again as style needs it
                    styletokens.append(braceorEOFtoken)
                teststyle.cssText = styletokens

            if wellformed:
                # known as correct from before
                cssutils.log.enabled = False
                self._selectorText = newselectorseq # TODO: TEST and REFS
                self.style.cssText = styletokens
                cssutils.log.enabled = True
コード例 #4
0
    def _setCssText(self, cssText):
        """
        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
        """
        super(CSSFontFaceRule, self)._setCssText(cssText)
        
        tokenizer = self._tokenize2(cssText)
        attoken = self._nexttoken(tokenizer, None)
        if self._type(attoken) != self._prods.FONT_FACE_SYM:
            self._log.error(u'CSSFontFaceRule: No CSSFontFaceRule found: %s' %
                self._valuestr(cssText),
                error=xml.dom.InvalidModificationErr)
        else:
            newStyle = CSSStyleDeclaration(parentRule=self)
            ok = True
            
            beforetokens, brace = self._tokensupto2(tokenizer, 
                                                    blockstartonly=True,
                                                    separateEnd=True)            
            if self._tokenvalue(brace) != u'{':
                ok = False
                self._log.error(u'CSSFontFaceRule: No start { of style '
                                u'declaration found: %r' 
                                % self._valuestr(cssText), brace)
            
            # parse stuff before { which should be comments and S only
            new = {'wellformed': True}
            newseq = self._tempSeq()
            
            beforewellformed, expected = self._parse(expected=':',
                seq=newseq, tokenizer=self._tokenize2(beforetokens),
                productions={})
            ok = ok and beforewellformed and new['wellformed']
    
            styletokens, braceorEOFtoken = self._tokensupto2(tokenizer, 
                                                             blockendonly=True,
                                                             separateEnd=True)

            val, type_ = self._tokenvalue(braceorEOFtoken),\
                         self._type(braceorEOFtoken)
            if val != u'}' and type_ != 'EOF':
                ok = False
                self._log.error(u'CSSFontFaceRule: No "}" after style '
                                u'declaration found: %r'
                                % self._valuestr(cssText))
                
            nonetoken = self._nexttoken(tokenizer)
            if nonetoken:
                ok = False
                self._log.error(u'CSSFontFaceRule: Trailing content found.',
                                token=nonetoken)

            if 'EOF' == type_:
                # add again as style needs it
                styletokens.append(braceorEOFtoken)

            # SET, may raise:
            newStyle.cssText = styletokens

            if ok:
                # contains probably comments only (upto ``{``)
                self._setSeq(newseq)
                self.style = newStyle                 
コード例 #5
0
    def _setCssText(self, cssText):
        """
        :param cssText:
            a parseable string or a tuple of (cssText, dict-of-namespaces)
        :exceptions:
            - :exc:`~xml.dom.NamespaceErr`:
              Raised if the specified selector uses an unknown namespace
              prefix.
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
        """
        super(CSSStyleRule, self)._setCssText(cssText)

        # might be (cssText, namespaces)
        cssText, namespaces = self._splitNamespacesOff(cssText)
        try:
            # use parent style sheet ones if available
            namespaces = self.parentStyleSheet.namespaces
        except AttributeError:
            pass

        tokenizer = self._tokenize2(cssText)
        selectortokens = self._tokensupto2(tokenizer, blockstartonly=True)
        styletokens = self._tokensupto2(tokenizer, blockendonly=True)
        trail = self._nexttoken(tokenizer)
        if trail:
            self._log.error(u'CSSStyleRule: Trailing content: %s' %
                            self._valuestr(cssText),
                            token=trail)
        elif not selectortokens:
            self._log.error(u'CSSStyleRule: No selector found: %r' %
                            self._valuestr(cssText))
        elif self._tokenvalue(selectortokens[0]).startswith(u'@'):
            self._log.error(u'CSSStyleRule: No style rule: %r' %
                            self._valuestr(cssText),
                            error=xml.dom.InvalidModificationErr)
        else:
            newSelectorList = SelectorList(parentRule=self)
            newStyle = CSSStyleDeclaration(parentRule=self)
            ok = True

            bracetoken = selectortokens.pop()
            if self._tokenvalue(bracetoken) != u'{':
                ok = False
                self._log.error(
                    u'CSSStyleRule: No start { of style declaration found: %r'
                    % self._valuestr(cssText), bracetoken)
            elif not selectortokens:
                ok = False
                self._log.error(
                    u'CSSStyleRule: No selector found: %r.' %
                    self._valuestr(cssText), bracetoken)
            # SET
            newSelectorList.selectorText = (selectortokens, namespaces)

            if not styletokens:
                ok = False
                self._log.error(
                    u'CSSStyleRule: No style declaration or "}" found: %r' %
                    self._valuestr(cssText))
            else:
                braceorEOFtoken = styletokens.pop()
                val, typ = self._tokenvalue(braceorEOFtoken),\
                           self._type(braceorEOFtoken)
                if val != u'}' and typ != 'EOF':
                    ok = False
                    self._log.error(u'CSSStyleRule: No "}" after style '
                                    u'declaration found: %r' %
                                    self._valuestr(cssText))
                else:
                    if 'EOF' == typ:
                        # add again as style needs it
                        styletokens.append(braceorEOFtoken)
                    # SET, may raise:
                    newStyle.cssText = styletokens

            if ok:
                self.selectorList = newSelectorList
                self.style = newStyle
コード例 #6
0
    def _setCssText(self, cssText):
        """
        DOMException on setting

        - SYNTAX_ERR: (self, StyleDeclaration)
          Raised if the specified CSS string value has a syntax error and
          is unparsable.
        - INVALID_MODIFICATION_ERR: (self)
          Raised if the specified CSS string value represents a different
          type of rule than the current one.
        - HIERARCHY_REQUEST_ERR: (CSSStylesheet)
          Raised if the rule cannot be inserted at this point in the
          style sheet.
        - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
          Raised if the rule is readonly.
        """
        super(CSSFontFaceRule, self)._setCssText(cssText)
        
        tokenizer = self._tokenize2(cssText)
        attoken = self._nexttoken(tokenizer, None)
        if not attoken or u'@font-face' != self._tokenvalue(
                                                attoken, normalize=True):
            self._log.error(u'CSSFontFaceRule: No CSSFontFaceRule found: %s' %
                self._valuestr(cssText),
                error=xml.dom.InvalidModificationErr)
        else:
            valid = True
            beforetokens = self._tokensupto2(tokenizer, blockstartonly=True)            
            try:
                bracetoken = beforetokens.pop()
            except IndexError:
                bracetoken = None
            if self._tokenvalue(bracetoken) != u'{':
                valid = False
                self._log.error(
                    u'CSSFontFaceRule: No start { of style declaration found: %r' %
                    self._valuestr(cssText), bracetoken)
            
            # parse stuff before { which should be comments and S only
            new = {'valid': True}
            newseq = []
            beforevalid, expected = self._parse(expected=':',
                seq=newseq, tokenizer=self._tokenize2(beforetokens),
                productions={})
            valid = valid and beforevalid and new['valid']
    
            styletokens = self._tokensupto2(tokenizer, blockendonly=True)
            newstyle = CSSStyleDeclaration()
            if not styletokens:
                valid = False
                self._log.error(
                    u'CSSFontFaceRule: No style declaration or "}" found: %r' %
                    self._valuestr(cssText))            

            braceorEOFtoken = styletokens.pop()
            val, typ = self._tokenvalue(braceorEOFtoken), self._type(braceorEOFtoken)
            if val != u'}' and typ != 'EOF':
                valid = False
                self._log.error(
                    u'CSSFontFaceRule: No "}" after style declaration found: %r' %
                    self._valuestr(cssText))
            else:
                if 'EOF' == typ:
                    # add again as style needs it
                    styletokens.append(braceorEOFtoken)
                newstyle.cssText = styletokens

            if valid:
                self.valid = True
                self.style = newstyle
                self.seq = newseq # contains upto { only
コード例 #7
0
ファイル: csspagerule.py プロジェクト: pib/PyBrowser
    def _setCssText(self, cssText):
        """
        DOMException on setting

        - SYNTAX_ERR: (self, StyleDeclaration)
          Raised if the specified CSS string value has a syntax error and
          is unparsable.
        - INVALID_MODIFICATION_ERR: (self)
          Raised if the specified CSS string value represents a different
          type of rule than the current one.
        - HIERARCHY_REQUEST_ERR: (CSSStylesheet)
          Raised if the rule cannot be inserted at this point in the
          style sheet.
        - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
          Raised if the rule is readonly.
        """
        super(CSSPageRule, self)._setCssText(cssText)

        tokenizer = self._tokenize2(cssText)
        attoken = self._nexttoken(tokenizer, None)
        if not attoken or u"@page" != self._tokenvalue(attoken, normalize=True):
            self._log.error(
                u"CSSPageRule: No CSSPageRule found: %s" % self._valuestr(cssText), error=xml.dom.InvalidModificationErr
            )
        else:
            valid = True
            selectortokens = self._tokensupto2(tokenizer, blockstartonly=True)
            styletokens = self._tokensupto2(tokenizer, blockendonly=True)

            try:
                bracetoken = selectortokens.pop()
            except IndexError:
                bracetoken = None
            if self._tokenvalue(bracetoken) != u"{":
                valid = False
                self._log.error(
                    u"CSSPageRule: No start { of style declaration found: %r" % self._valuestr(cssText), bracetoken
                )

            newselector, newselectorseq = self.__parseSelectorText(selectortokens)

            newstyle = CSSStyleDeclaration()
            if not styletokens:
                valid = False
                self._log.error(u'CSSPageRule: No style declaration or "}" found: %r' % self._valuestr(cssText))

            braceorEOFtoken = styletokens.pop()
            val, typ = self._tokenvalue(braceorEOFtoken), self._type(braceorEOFtoken)
            if val != u"}" and typ != "EOF":
                valid = False
                self._log.error(u'CSSPageRule: No "}" after style declaration found: %r' % self._valuestr(cssText))
            else:
                if "EOF" == typ:
                    # add again as style needs it
                    styletokens.append(braceorEOFtoken)
                newstyle.cssText = styletokens

            if valid:
                self.valid = True
                self._selectorText = newselector  # already parsed
                self.style = newstyle
                self.seq = newselectorseq  # contains upto style only
コード例 #8
0
ファイル: csspagerule.py プロジェクト: rolandf/cssutils
    def _setCssText(self, cssText):
        """
        :exceptions:    
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
        """
        super(CSSPageRule, self)._setCssText(cssText)
        
        tokenizer = self._tokenize2(cssText)
        if self._type(self._nexttoken(tokenizer)) != self._prods.PAGE_SYM:
            self._log.error(u'CSSPageRule: No CSSPageRule found: %s' %
                            self._valuestr(cssText), 
                            error=xml.dom.InvalidModificationErr)
        else:
            newStyle = CSSStyleDeclaration(parentRule=self)
            ok = True
            
            selectortokens, startbrace = self._tokensupto2(tokenizer, 
                                                           blockstartonly=True,
                                                           separateEnd=True)
            styletokens, braceorEOFtoken = self._tokensupto2(tokenizer, 
                                                             blockendonly=True,
                                                             separateEnd=True)
            nonetoken = self._nexttoken(tokenizer)
            if self._tokenvalue(startbrace) != u'{':
                ok = False
                self._log.error(u'CSSPageRule: No start { of style declaration ' 
                                u'found: %r' % 
                                self._valuestr(cssText), startbrace)
            elif nonetoken:
                ok = False
                self._log.error(u'CSSPageRule: Trailing content found.', 
                                token=nonetoken)
                
            selok, newselseq, specificity = self.__parseSelectorText(selectortokens)
            ok = ok and selok

            val, type_ = self._tokenvalue(braceorEOFtoken),\
                         self._type(braceorEOFtoken)
                         
            if val != u'}' and type_ != 'EOF':
                ok = False
                self._log.error(
                    u'CSSPageRule: No "}" after style declaration found: %r' %
                    self._valuestr(cssText))
            else:
                if 'EOF' == type_:
                    # add again as style needs it
                    styletokens.append(braceorEOFtoken)
                    
                # filter pagemargin rules out first
                cssRules, styletokens = self.__parseMarginAndStyle(styletokens)
                    
                # SET, may raise:
                newStyle.cssText = styletokens

            if ok:
                self._selectorText = newselseq
                self._specificity = specificity
                self.style = newStyle 
                self.cssRules = cssutils.css.CSSRuleList()
                for r in cssRules:
                    self.cssRules.append(r)
コード例 #9
0
    def _setCssText(self, cssText):
        """
        DOMException on setting

        - SYNTAX_ERR: (self, StyleDeclaration)
          Raised if the specified CSS string value has a syntax error and
          is unparsable.
        - INVALID_MODIFICATION_ERR: (self)
          Raised if the specified CSS string value represents a different
          type of rule than the current one.
        - HIERARCHY_REQUEST_ERR: (CSSStylesheet)
          Raised if the rule cannot be inserted at this point in the
          style sheet.
        - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
          Raised if the rule is readonly.
        """
        super(CSSFontFaceRule, self)._setCssText(cssText)

        tokenizer = self._tokenize2(cssText)
        attoken = self._nexttoken(tokenizer, None)
        if not attoken or u'@font-face' != self._tokenvalue(attoken,
                                                            normalize=True):
            self._log.error(u'CSSFontFaceRule: No CSSFontFaceRule found: %s' %
                            self._valuestr(cssText),
                            error=xml.dom.InvalidModificationErr)
        else:
            valid = True
            beforetokens = self._tokensupto2(tokenizer, blockstartonly=True)
            try:
                bracetoken = beforetokens.pop()
            except IndexError:
                bracetoken = None
            if self._tokenvalue(bracetoken) != u'{':
                valid = False
                self._log.error(
                    u'CSSFontFaceRule: No start { of style declaration found: %r'
                    % self._valuestr(cssText), bracetoken)

            # parse stuff before { which should be comments and S only
            new = {'valid': True}
            newseq = []
            beforevalid, expected = self._parse(
                expected=':',
                seq=newseq,
                tokenizer=self._tokenize2(beforetokens),
                productions={})
            valid = valid and beforevalid and new['valid']

            styletokens = self._tokensupto2(tokenizer, blockendonly=True)
            newstyle = CSSStyleDeclaration()
            if not styletokens:
                valid = False
                self._log.error(
                    u'CSSFontFaceRule: No style declaration or "}" found: %r' %
                    self._valuestr(cssText))

            braceorEOFtoken = styletokens.pop()
            val, typ = self._tokenvalue(braceorEOFtoken), self._type(
                braceorEOFtoken)
            if val != u'}' and typ != 'EOF':
                valid = False
                self._log.error(
                    u'CSSFontFaceRule: No "}" after style declaration found: %r'
                    % self._valuestr(cssText))
            else:
                if 'EOF' == typ:
                    # add again as style needs it
                    styletokens.append(braceorEOFtoken)
                newstyle.cssText = styletokens

            if valid:
                self.valid = True
                self.style = newstyle
                self.seq = newseq  # contains upto { only
コード例 #10
0
ファイル: cssstylerule.py プロジェクト: galexcode/PyBrowser
    def _setCssText(self, cssText):
        """
        DOMException on setting

        - SYNTAX_ERR: (self, StyleDeclaration, etc)
          Raised if the specified CSS string value has a syntax error and
          is unparsable.
        - INVALID_MODIFICATION_ERR: (self)
          Raised if the specified CSS string value represents a different
          type of rule than the current one.
        - HIERARCHY_REQUEST_ERR: (CSSStylesheet)
          Raised if the rule cannot be inserted at this point in the
          style sheet.
        - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
          Raised if the rule is readonly.
        """
        super(CSSStyleRule, self)._setCssText(cssText)
        
        tokenizer = self._tokenize2(cssText)
        selectortokens = self._tokensupto2(tokenizer, blockstartonly=True)
        styletokens = self._tokensupto2(tokenizer, blockendonly=True)
        
        if not selectortokens or self._tokenvalue(
                                        selectortokens[0]).startswith(u'@'):
            self._log.error(u'CSSStyleRule: No content or no style rule.',
                    error=xml.dom.InvalidModificationErr)

        else:
            valid = True
            
            bracetoken = selectortokens.pop()
            if self._tokenvalue(bracetoken) != u'{':
                valid = False
                self._log.error(
                    u'CSSStyleRule: No start { of style declaration found: %r' %
                    self._valuestr(cssText), bracetoken)
            elif not selectortokens:
                valid = False
                self._log.error(u'CSSStyleRule: No selector found: %r.' %
                            self._valuestr(cssText), bracetoken)
                
            newselectorlist = SelectorList(selectorText=selectortokens)

            newstyle = CSSStyleDeclaration()
            if not styletokens:
                valid = False
                self._log.error(
                    u'CSSStyleRule: No style declaration or "}" found: %r' %
                    self._valuestr(cssText))
            else:
                braceorEOFtoken = styletokens.pop()
                val, typ = self._tokenvalue(braceorEOFtoken), self._type(braceorEOFtoken)
                if val != u'}' and typ != 'EOF':
                    valid = False
                    self._log.error(
                        u'CSSStyleRule: No "}" after style declaration found: %r' %
                        self._valuestr(cssText))
                else:
                    if 'EOF' == typ:
                        # add again as style needs it
                        styletokens.append(braceorEOFtoken)
                    newstyle.cssText = styletokens

            if valid:
                self.valid = True
                self.selectorList = newselectorlist
                self.style = newstyle
コード例 #11
0
    def _setCssText(self, cssText):
        """
        DOMException on setting

        - SYNTAX_ERR: (self, StyleDeclaration, etc)
          Raised if the specified CSS string value has a syntax error and
          is unparsable.
        - INVALID_MODIFICATION_ERR: (self)
          Raised if the specified CSS string value represents a different
          type of rule than the current one.
        - HIERARCHY_REQUEST_ERR: (CSSStylesheet)
          Raised if the rule cannot be inserted at this point in the
          style sheet.
        - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
          Raised if the rule is readonly.
        """
        super(CSSStyleRule, self)._setCssText(cssText)

        tokenizer = self._tokenize2(cssText)
        selectortokens = self._tokensupto2(tokenizer, blockstartonly=True)
        styletokens = self._tokensupto2(tokenizer, blockendonly=True)

        if not selectortokens or self._tokenvalue(
                selectortokens[0]).startswith(u'@'):
            self._log.error(u'CSSStyleRule: No content or no style rule.',
                            error=xml.dom.InvalidModificationErr)

        else:
            valid = True

            bracetoken = selectortokens.pop()
            if self._tokenvalue(bracetoken) != u'{':
                valid = False
                self._log.error(
                    u'CSSStyleRule: No start { of style declaration found: %r'
                    % self._valuestr(cssText), bracetoken)
            elif not selectortokens:
                valid = False
                self._log.error(
                    u'CSSStyleRule: No selector found: %r.' %
                    self._valuestr(cssText), bracetoken)

            newselectorlist = SelectorList(selectorText=selectortokens)

            newstyle = CSSStyleDeclaration()
            if not styletokens:
                valid = False
                self._log.error(
                    u'CSSStyleRule: No style declaration or "}" found: %r' %
                    self._valuestr(cssText))
            else:
                braceorEOFtoken = styletokens.pop()
                val, typ = self._tokenvalue(braceorEOFtoken), self._type(
                    braceorEOFtoken)
                if val != u'}' and typ != 'EOF':
                    valid = False
                    self._log.error(
                        u'CSSStyleRule: No "}" after style declaration found: %r'
                        % self._valuestr(cssText))
                else:
                    if 'EOF' == typ:
                        # add again as style needs it
                        styletokens.append(braceorEOFtoken)
                    newstyle.cssText = styletokens

            if valid:
                self.valid = True
                self.selectorList = newselectorlist
                self.style = newstyle