Package cssutils :: Package css :: Module cssvalue :: Class CSSPrimitiveValue
[hide private]
[frames] | no frames]

Class CSSPrimitiveValue

source code

object --+        
         |        
 util.Base --+    
             |    
      CSSValue --+
                 |
                CSSPrimitiveValue

represents a single CSS Value. May be used to determine the value of a specific style property currently set in a block or to set a specific style property explicitly within the block. Might be obtained from the getPropertyCSSValue method of CSSStyleDeclaration.

Conversions are allowed between absolute values (from millimeters to centimeters, from degrees to radians, and so on) but not between relative values. (For example, a pixel value cannot be converted to a centimeter value.) Percentage values can't be converted since they are relative to the parent value (or another property value). There is one exception for color percentage values: since a color percentage value is relative to the range 0-255, a color percentage value can be converted to a number; (see also the RGBColor interface).



Nested Classes [hide private]

Inherited from util.Base (private): _prods

Instance Methods [hide private]
 
__init__(self, cssText=None, readonly=False, _propertyName=None)
see CSSPrimitiveValue.__init__()
source code
 
_init(self) source code
 
__set_primitiveType(self)
primitiveType is readonly but is set lazy if accessed no value is given as self._value is used
source code
 
_getPrimitiveType(self) source code
 
_getPrimitiveTypeString(self) source code
 
_getCSSPrimitiveTypeString(self, type)
get TypeString by given type which may be unknown, used by setters
source code
 
__getValDim(self)
splits self._value in numerical and dimension part
source code
 
getFloatValue(self, unitType)
(DOM method) This method is used to get a float value in a specified unit.
source code
 
setFloatValue(self, unitType, floatValue)
(DOM method) A method to set the float value with a specified unit.
source code
 
getStringValue(self)
(DOM method) This method is used to get the string value.
source code
 
setStringValue(self, stringType, stringValue)
(DOM method) A method to set the string value with the specified unit.
source code
 
getCounterValue(self)
(DOM method) This method is used to get the Counter value.
source code
 
getRGBColorValue(self)
(DOM method) This method is used to get the RGB color.
source code
 
getRectValue(self)
(DOM method) This method is used to get the Rect value.
source code
 
__str__(self) source code

Inherited from CSSValue: __repr__

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Static Methods [hide private]

Inherited from util.Base (private): _normalize

Class Variables [hide private]
  cssValueType = 1
A (readonly) code defining the type of the value as defined above.
  CSS_UNKNOWN = 0
  CSS_NUMBER = 1
A (readonly) code defining the type of the value as defined above.
  CSS_PERCENTAGE = 2
A (readonly) code defining the type of the value as defined above.
  CSS_EMS = 3
  CSS_EXS = 4
  CSS_PX = 5
  CSS_CM = 6
  CSS_MM = 7
  CSS_IN = 8
  CSS_PT = 9
  CSS_PC = 10
  CSS_DEG = 11
  CSS_RAD = 12
  CSS_GRAD = 13
  CSS_MS = 14
  CSS_S = 15
  CSS_HZ = 16
  CSS_KHZ = 17
  CSS_DIMENSION = 18
  CSS_STRING = 19
  CSS_URI = 20
  CSS_IDENT = 21
  CSS_ATTR = 22
  CSS_COUNTER = 23
  CSS_RECT = 24
  CSS_RGBCOLOR = 25
  CSS_RGBACOLOR = 26
  _floattypes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...
  _stringtypes = [22, 21, 19, 20]
  _countertypes = [23]
  _recttypes = [24]
  _rbgtypes = [25, 26]
  _reNumDim = re.compile(r'(?iux)^(.*?)([a-z]+|%)$')
  _converter = {(6, 7): <function <lambda> at 0x01DB5730>, (6, 8...

Inherited from CSSValue: CSS_CUSTOM, CSS_INHERIT, CSS_PRIMITIVE_VALUE, CSS_VALUE_LIST

Inherited from CSSValue (private): _typestrings

Inherited from util.Base (private): _SHORTHANDPROPERTIES, _log

Properties [hide private]
  primitiveType
READONLY: The type of the value as defined by the constants specified above.
  primitiveTypeString
Name of primitive type of this value.

Inherited from CSSValue: cssText, cssValueTypeString

Inherited from CSSValue (private): _propertyName, _value

Inherited from object: __class__

Method Details [hide private]

__init__(self, cssText=None, readonly=False, _propertyName=None)
(Constructor)

source code 
see CSSPrimitiveValue.__init__()
Overrides: CSSValue.__init__

getFloatValue(self, unitType)

source code 

(DOM method) This method is used to get a float value in a specified unit. If this CSS value doesn't contain a float value or can't be converted into the specified unit, a DOMException is raised.

unitType
to get the float value. The unit code can only be a float unit type (i.e. CSS_NUMBER, CSS_PERCENTAGE, CSS_EMS, CSS_EXS, CSS_PX, CSS_CM, CSS_MM, CSS_IN, CSS_PT, CSS_PC, CSS_DEG, CSS_RAD, CSS_GRAD, CSS_MS, CSS_S, CSS_HZ, CSS_KHZ, CSS_DIMENSION).

returns not necessarily a float but some cases just an int e.g. if the value is 1px it return 1 and not 1.0

conversions might return strange values like 1.000000000001

setFloatValue(self, unitType, floatValue)

source code 

(DOM method) A method to set the float value with a specified unit. If the property attached with this value can not accept the specified unit or the float value, the value will be unchanged and a DOMException will be raised.

unitType
a unit code as defined above. The unit code can only be a float unit type
floatValue

the new float value which does not have to be a float value but may simple be an int e.g. if setting:

setFloatValue(CSS_PX, 1)
raises DOMException
  • INVALID_ACCESS_ERR: Raised if the attached property doesn't

    support the float value or the unit type.

  • NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly.

getStringValue(self)

source code 

(DOM method) This method is used to get the string value. If the CSS value doesn't contain a string value, a DOMException is raised.

Some properties (like 'font-family' or 'voice-family') convert a whitespace separated list of idents to a string.

Only the actual value is returned so e.g. all the following return the actual value a: url(a), attr(a), "a", 'a'

setStringValue(self, stringType, stringValue)

source code 

(DOM method) A method to set the string value with the specified unit. If the property attached to this value can't accept the specified unit or the string value, the value will be unchanged and a DOMException will be raised.

stringType
a string code as defined above. The string code can only be a string unit type (i.e. CSS_STRING, CSS_URI, CSS_IDENT, and CSS_ATTR).
stringValue
the new string value Only the actual value is expected so for (CSS_URI, "a") the new value will be url(a). For (CSS_STRING, "'a'") the new value will be "\'a\'" as the surrounding ' are not part of the string value
raises

DOMException

  • INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a string value or if the string value can't be converted into the specified unit.
  • NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly.

getCounterValue(self)

source code 
(DOM method) This method is used to get the Counter value. If this CSS value doesn't contain a counter value, a DOMException is raised. Modification to the corresponding style property can be achieved using the Counter interface.

getRGBColorValue(self)

source code 
(DOM method) This method is used to get the RGB color. If this CSS value doesn't contain a RGB color value, a DOMException is raised. Modification to the corresponding style property can be achieved using the RGBColor interface.

getRectValue(self)

source code 
(DOM method) This method is used to get the Rect value. If this CSS value doesn't contain a rect value, a DOMException is raised. Modification to the corresponding style property can be achieved using the Rect interface.

__str__(self)
(Informal representation operator)

source code 
Overrides: CSSValue.__str__

Class Variable Details [hide private]

_floattypes

Value:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]

_converter

Value:
{(CSS_CM, CSS_MM): lambda x: x* 10, (CSS_MM, CSS_CM): lambda x: x/ 10,\
 (CSS_PT, CSS_PC): lambda x: x* 12, (CSS_PC, CSS_PT): lambda x: x/ 12,\
 (CSS_CM, CSS_IN): lambda x: x/ 2.54, (CSS_IN, CSS_CM): lambda x: x* 2\
.54, (CSS_MM, CSS_IN): lambda x: x/ 25.4, (CSS_IN, CSS_MM): lambda x: \
x* 25.4, (CSS_IN, CSS_PT): lambda x: x/ 72, (CSS_PT, CSS_IN): lambda x\
: x* 72, (CSS_CM, CSS_PT): lambda x: x/ 2.54/ 72, (CSS_PT, CSS_CM): la\
mbda x: x* 72* 2.54, (CSS_MM, CSS_PT): lambda x: x/ 25.4/ 72, (CSS_PT,\
 CSS_MM): lambda x: x* 72* 25.4, (CSS_IN, CSS_PC): lambda x: x/ 72/ 12\
...

Property Details [hide private]

primitiveType

READONLY: The type of the value as defined by the constants specified above.
Get Method:
cssutils.css.cssvalue.CSSPrimitiveValue._getPrimitiveType(self)
Set Method:
None
Delete Method:
None

primitiveTypeString

Name of primitive type of this value.
Get Method:
cssutils.css.cssvalue.CSSPrimitiveValue._getPrimitiveTypeString(self)
Set Method:
None
Delete Method:
None