Changeset 3241:b87e8fa740da in livinglogic.python.xist

Show
Ignore:
Timestamp:
03/22/08 22:03:01 (12 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Remove CSSWeight class, methods and tests. Use csstils specificity instead.

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xist/css.py

    r3240 r3241  
    165165            if not style.isfancy(): 
    166166                yield ( 
     167                    (1, 0, 0, 0), 
    167168                    xfind.IsSelector(node), 
    168169                    cssutils.parseString(u"*{%s}" % style).cssRules[0].style # parse the style out of the style attribute 
     
    172173    for (i, rule) in enumerate(iterrules(node, base=base, media=media)): 
    173174        for sel in rule.selectorList: 
    174             rules.append((selector(sel), rule.style)) 
    175     rules.sort(key=lambda(sel, rule): sel.cssweight()) 
     175            rules.append((sel.specificity, selector(sel), rule.style)) 
     176    rules.sort(key=lambda(spec, sel, rule): spec) 
    176177    count = 0 
    177178    for path in node.walk(xsc.Element): 
     
    179180        if path[-1].Attrs.isallowed("style"): 
    180181            styles = {} 
    181             for (sel, style) in iterstyles(path[-1], rules): 
     182            for (spec, sel, style) in iterstyles(path[-1], rules): 
    182183                if sel.matchpath(path): 
    183184                    for prop in style.seq: 
     
    266267    Base class for all CSS pseudo-class selectors. 
    267268    """ 
    268     def cssweight(self): 
    269         return xfind.CSSWeight(0, 1, 0) 
    270269 
    271270 
     
    532531        v.append(")") 
    533532        return "".join(v) 
    534  
    535     def cssweight(self): 
    536         result = xfind.CSSWeight(0, 0, 0, int(self.type is not None)) 
    537         for selector in self.selectors: 
    538             result += selector.cssweight() 
    539         return result 
    540533 
    541534 
  • src/ll/xist/xfind.py

    r3180 r3241  
    2828 
    2929 
    30 class CSSWeight(tuple): 
    31     """ 
    32     The specificity of a CSS selector as a 3-item tuple as specified by CSS3__. 
    33      
    34     __ http://www.w3.org/TR/css3-selectors/#specificity 
    35     """ 
    36  
    37     def __new__(cls, a=0, b=0, c=0, d=0): 
    38         return tuple.__new__(cls, (a, b, c, d)) 
    39  
    40     def __add__(self, other): 
    41         return CSSWeight(self[0]+other[0], self[1]+other[1], self[2]+other[2], self[3]+other[3]) 
    42  
    43     def __repr__(self): 
    44         return "CSSWeight(%r, %r, %r, %r)" % (self[0], self[1], self[2], self[3]) 
    45  
    46  
    4730class Selector(xsc.WalkFilter): 
    4831    """ 
     
    10588        """ 
    10689        return NotCombinator(self) 
    107  
    108     def cssweight(self): 
    109         """ 
    110         Return the CSS specificity of :var:`self` as a :class:`CSSWeight` object. 
    111         """ 
    112         return CSSWeight() 
    11390 
    11491 
     
    666643        return "%s(%r)" % (self.__class__.__name__, self.id) 
    667644 
    668     def cssweight(self): 
    669         return CSSWeight(0, 1, 0, 0) 
    670  
    671645 
    672646class hasclass(Selector): 
     
    701675    def __str__(self): 
    702676        return "%s(%r)" % (self.__class__.__name__, self.classname) 
    703  
    704     def cssweight(self): 
    705         return CSSWeight(0, 0, 1, 0) 
    706677 
    707678 
     
    756727            right = "(%s)" % right 
    757728        return "%s%s%s" % (left, self.symbol, right) 
    758  
    759     def cssweight(self): 
    760         return self.left.cssweight()+self.right.cssweight() 
    761729 
    762730 
     
    925893            v.append(s) 
    926894        return self.symbol.join(v) 
    927  
    928     def cssweight(self): 
    929         raise TypeError("no weight info for chained combinator") 
    930895 
    931896 
  • test/test_xist_css.py

    r3239 r3241  
    8282 
    8383 
    84 def test_cssweight(): 
    85     # from http://www.w3.org/TR/css3-selectors/#specificity 
    86     assert css.selector("*").cssweight() == (0, 0, 0, 0) 
    87     assert css.selector("LI").cssweight() == (0, 0, 0, 1) 
    88     assert css.selector("UL LI").cssweight() == (0, 0, 0, 2) 
    89     assert css.selector("UL OL+LI").cssweight() == (0, 0, 0, 3) 
    90     assert css.selector("UL OL LI.red").cssweight() == (0, 0, 1, 3) 
    91     assert css.selector("LI.red.level").cssweight() == (0, 0, 2, 1) 
    92     assert css.selector("#x34y").cssweight() == (0, 1, 0, 0) 
    93     # The following is not supported 
    94     # assert css.selector("#s12:not(FOO)").cssweight() == (0, 1, 0, 1) 
    95  
    96  
    9784def test_applystylesheets1(): 
    9885    with html.html() as e: