Most important method in this module is cssutils.profiles.Profiles.addProfile() to add new properties to cssutils and the setting of defaultprofile.
Example of how to add a new profile:
>>> import cssutils
>>> sheet = cssutils.parseString('x { -test-x: 1 }')
>>> print sheet.cssRules[0].style.getProperties()[0].valid
False
>>> P1 = {
... '-test-x': '{num}',
... '-test-y': '{ident}|{percentage}',
... # custom validation function
... '-test-z': lambda(v): int(v) > 0}
>>> cssutils.profiles.profiles.addProfile('test', P1)
>>> sheet = cssutils.parseString('x { -test-x: 1 }')
>>> print sheet.cssRules[0].style.getProperties()[0].valid
True
This may change again, please beware!
A per CSSStyleSheet setting of a profile may be added soon.
Current status in release 0.9.6a1.
A global cssutils.profiles.Profile object which is used by all CSS properties for validation. Add or remove new profile definitions here.
All profiles used for validation. cssutils.profiles.profiles is a preset object of this class and used by all properties for validation.
Predefined profiles are (use propertiesByProfile() to get a list of defined properties):
Add a new profile with name profile (e.g. ‘CSS level 2’) and the given properties.
Parameters: |
|
---|
Generator: Yield property names, if no profiles is given all profile’s properties are used.
Parameters: |
|
---|
Remove profile or remove all profiles.
Parameters: |
|
---|---|
Exceptions: |
|
Check if value is valid for given property name using any profile.
Parameters: |
|
---|---|
Returns: | if the value is valid for the given property name in any profile |
Check if value is valid for given property name returning (valid, profile).
Parameters: |
|
---|---|
Returns: | valid, profiles where valid is if the value is valid for the given property name in any profile of given profiles and profiles the profile names for which the value is valid (or [] if not valid at all) |
Example: You might expect a valid Profiles.CSS_LEVEL_2 value but e.g. validateWithProfile('color', 'rgba(1,1,1,1)') returns (True, Profiles.CSS_COLOR_LEVEL_3)