Exemplo n.º 1
0
    def _check(self, name, keys):
        """
        Check each value in values if for property name p.name==exp.
        """
        notvalid = self._allvalues()

        for value in self._valuesofkeys(keys):
            if name == debug:
                print('+True?', Property(name, value).valid, value)
            self.assertEqual(True, Property(name, value).valid)
            if value in notvalid:
                notvalid.remove(value)
        for value in notvalid:
            if name == debug:
                print('-False?', Property(name, value).valid, value)
            self.assertEqual(False, Property(name, value).valid)
Exemplo n.º 2
0
    def test_validate(self):
        "Property.validate() and Property.valid"
        tests = {
            # (default L2, no default, no profile, L2, Color L3)
            'red': (True, True, True, True, True),
            'rgba(1,2,3,1)': (False, True, True, False, True),
            '1': (False, False, False, False, False)
        }
        for v, rs in tests.items():
            p = Property('color', v)
            cssutils.profile.defaultProfiles = \
                cssutils.profile.CSS_LEVEL_2
            self.assertEqual(rs[0], p.valid)
            cssutils.profile.defaultProfiles = None
            self.assertEqual(rs[1], p.valid)

            self.assertEqual(rs[2], p.validate())
Exemplo n.º 3
0
    def test_validate(self):
        "Property.validate() and Property.valid"
        tests = {
            # (default L2, no default, no profile, L2, Color L3)
            'red': (True, True, True, True, True),
            'rgba(1,2,3,1)': (False, True, True, False, True),
            '1': (False, False, False, False, False)
        }
        for v, rs in tests.items():
            p = Property('color', v)
            cssutils.profile.defaultProfiles = \
                cssutils.profile.CSS_LEVEL_2
            self.assertEqual(rs[0], p.valid)
            cssutils.profile.defaultProfiles = None
            self.assertEqual(rs[1], p.valid)

            self.assertEqual(rs[2], p.validate())
Exemplo n.º 4
0
 def _convert_impl(self, cssss, resource):
   # CSS Rule List
   cssrl = cssss.cssRules
   # 遍历各个Rule
   for rule in cssss.cssRules:
     if rule.type != 1:
       continue
     # rule的类型是CSSStyleRule
     style = rule.style                  # CSSStyleDeclaration
     properties = style.getProperties()  # list<cssutils.css.Property>
     new_props = []
     for p in properties:
       key = p.name
       value = p.cssValue
       new_prop = None
       if key.endswith('background') or \
          key.endswith('background-image'):
         if value.cssValueType == value.CSS_VALUE_LIST:
           for k in value:
             if k.primitiveType == k.CSS_URI:
               # logging.warning(k.getStringValue())
               uri_path = k.getStringValue()
               # 如果图片时png,且该png不是png8格式(通过命名区分),则进行转换并加上ie6的css hack
               if uri_path.endswith('.png') and not uri_path.endswith('-fs8.png'):
                 # create property _background or _background-image
                 new_uri = self._convert_image(resource, uri_path)
                 if new_uri:
                   new_prop = Property()
                   new_prop.cssText = p.cssText.replace('background', '_background').replace(uri_path, new_uri)
         elif value.cssValueType == value.CSS_PRIMITIVE_VALUE and \
              value.primitiveType == value.CSS_URI:
           uri_path = value.getStringValue()
           # 如果图片时png,且该png不是png8格式(通过命名区分),则进行转换并加上ie6的css hack
           if uri_path.endswith('.png') and not uri_path.endswith('-fs8.png'):
             # create property _background or _background-image
             new_uri = self._convert_image(resource, uri_path)
             if new_uri:
               new_prop = Property('_' + key, cssutils.helper.uri(new_uri))
       if new_prop:
         new_props.append(new_prop)
     # 往rule.style里面添加hack的property
     for x in new_props:
       style.setProperty(x)
   return cssss.cssText