Logo Search packages:      
Sourcecode: calibre version File versions

def cssutils::css::property::Property::validate (   self  ) 

Validate value against `profiles` which are checked dynamically.
properties in e.g. @font-face rules are checked against 
``cssutils.profile.CSS3_FONT_FACE`` only. 

For each of the following cases a message is reported:

- INVALID (so the property is known but not valid)
    ``ERROR    Property: Invalid value for "{PROFILE-1[/PROFILE-2...]"
    property: ...``

- VALID but not in given profiles or defaultProfiles
    ``WARNING    Property: Not valid for profile "{PROFILE-X}" but valid
    "{PROFILE-Y}" property: ...``

- VALID in current profile
    ``DEBUG    Found valid "{PROFILE-1[/PROFILE-2...]" property...``

- UNKNOWN property
    ``WARNING    Unknown Property name...`` is issued            
    
so for example::

    cssutils.log.setLevel(logging.DEBUG)
    parser = cssutils.CSSParser()
    s = parser.parseString('''body { 
unknown-property: x;
color: 4;
color: rgba(1,2,3,4);
color: red 
    }''')

    # Log output:
    
    WARNING Property: Unknown Property name. [2:9: unknown-property]
    ERROR   Property: Invalid value for "CSS Color Module Level 3/CSS Level 2.1" property: 4 [3:9: color]
    DEBUG   Property: Found valid "CSS Color Module Level 3" value: rgba(1, 2, 3, 4) [4:9: color]
    DEBUG   Property: Found valid "CSS Level 2.1" value: red [5:9: color]


and when setting an explicit default profile::

    cssutils.profile.defaultProfiles = cssutils.profile.CSS_LEVEL_2
    s = parser.parseString('''body { 
unknown-property: x;
color: 4;
color: rgba(1,2,3,4);
color: red 
    }''')

    # Log output:
    
    WARNING Property: Unknown Property name. [2:9: unknown-property]
    ERROR   Property: Invalid value for "CSS Color Module Level 3/CSS Level 2.1" property: 4 [3:9: color]
    WARNING Property: Not valid for profile "CSS Level 2.1" but valid "CSS Color Module Level 3" value: rgba(1, 2, 3, 4)  [4:9: color]
    DEBUG   Property: Found valid "CSS Level 2.1" value: red [5:9: color]            

Definition at line 374 of file property.py.

00374                       :
        """Validate value against `profiles` which are checked dynamically.
        properties in e.g. @font-face rules are checked against 
        ``cssutils.profile.CSS3_FONT_FACE`` only. 
        
        For each of the following cases a message is reported:
        
        - INVALID (so the property is known but not valid)
            ``ERROR    Property: Invalid value for "{PROFILE-1[/PROFILE-2...]"
            property: ...``

        - VALID but not in given profiles or defaultProfiles
            ``WARNING    Property: Not valid for profile "{PROFILE-X}" but valid
            "{PROFILE-Y}" property: ...``

        - VALID in current profile
            ``DEBUG    Found valid "{PROFILE-1[/PROFILE-2...]" property...``

        - UNKNOWN property
            ``WARNING    Unknown Property name...`` is issued            
            
        so for example::
        
            cssutils.log.setLevel(logging.DEBUG)
            parser = cssutils.CSSParser()
            s = parser.parseString('''body { 
                unknown-property: x;
                color: 4;
                color: rgba(1,2,3,4);
                color: red 
            }''')

            # Log output:
            
            WARNING Property: Unknown Property name. [2:9: unknown-property]
            ERROR   Property: Invalid value for "CSS Color Module Level 3/CSS Level 2.1" property: 4 [3:9: color]
            DEBUG   Property: Found valid "CSS Color Module Level 3" value: rgba(1, 2, 3, 4) [4:9: color]
            DEBUG   Property: Found valid "CSS Level 2.1" value: red [5:9: color]
        

        and when setting an explicit default profile::

            cssutils.profile.defaultProfiles = cssutils.profile.CSS_LEVEL_2
            s = parser.parseString('''body { 
                unknown-property: x;
                color: 4;
                color: rgba(1,2,3,4);
                color: red 
            }''')

            # Log output:
            
            WARNING Property: Unknown Property name. [2:9: unknown-property]
            ERROR   Property: Invalid value for "CSS Color Module Level 3/CSS Level 2.1" property: 4 [3:9: color]
            WARNING Property: Not valid for profile "CSS Level 2.1" but valid "CSS Color Module Level 3" value: rgba(1, 2, 3, 4)  [4:9: color]
            DEBUG   Property: Found valid "CSS Level 2.1" value: red [5:9: color]            
        """
        valid = False
        
        profiles = None
        try:
            # if @font-face use that profile
            rule = self.parent.parentRule
            if rule.type == rule.FONT_FACE_RULE:
                profiles = [cssutils.profile.CSS3_FONT_FACE]
            #TODO: same for @page
        except AttributeError:
            pass
        
        if self.name and self.value:

            if self.name in cssutils.profile.knownNames:
                # add valid, matching, validprofiles...
                valid, matching, validprofiles = \
                    cssutils.profile.validateWithProfile(self.name,
                                                         self.value,
                                                         profiles)
                
                if not valid:
                    self._log.error(u'Property: Invalid value for '
                                    u'"%s" property: %s'
                                    % (u'/'.join(validprofiles), self.value),
                                    token=self.__nametoken,
                                    neverraise=True)
                    
                # TODO: remove logic to profiles!
                elif valid and not matching:#(profiles and profiles not in validprofiles):
                    if not profiles:
                        notvalidprofiles = u'/'.join(cssutils.profile.defaultProfiles)
                    else:
                        notvalidprofiles = profiles
                    self._log.warn(u'Property: Not valid for profile "%s" '
                                   u'but valid "%s" value: %s '
                                   % (notvalidprofiles, u'/'.join(validprofiles),
                                      self.value),
                                   token = self.__nametoken,
                                   neverraise=True)
                    valid = False
                                
                elif valid:
                    self._log.debug(u'Property: Found valid "%s" value: %s'
                                   % (u'/'.join(validprofiles), self.value),
                                   token = self.__nametoken,
                                   neverraise=True)
                    
        if self._priority not in (u'', u'important'):
            valid = False

        return valid

    valid = property(validate, doc="Check if value of this property is valid "


Generated by  Doxygen 1.6.0   Back to index