Package CedarBackup2 :: Package extend :: Module capacity :: Class PercentageQuantity
[hide private]
[frames] | no frames]

Class PercentageQuantity

source code

object --+
         |
        PercentageQuantity

Class representing a percentage quantity.

The percentage is maintained internally as a string so that issues of precision can be avoided. It really isn't possible to store a floating point number here while being able to losslessly translate back and forth between XML and object representations. (Perhaps the Python 2.4 Decimal class would have been an option, but I want to stay compatible with Python 2.3.)

Even though the quantity is maintained as a string, the string must be in a valid floating point positive number. Technically, any floating point string format supported by Python is allowble. However, it does not make sense to have a negative percentage in this context.

Instance Methods [hide private]
 
__init__(self, quantity=None)
Constructor for the PercentageQuantity class.
source code
 
__repr__(self)
Official string representation for class instance.
source code
 
__str__(self)
Informal string representation for class instance.
source code
 
__cmp__(self, other)
Definition of equals operator for this class.
source code
 
_setQuantity(self, value)
Property target used to set the quantity The value must be a non-empty string if it is not None.
source code
 
_getQuantity(self)
Property target used to get the quantity.
source code
 
_getPercentage(self)
Property target used to get the quantity as a floating point number.
source code

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

Properties [hide private]
  quantity
Percentage value, as a string
  percentage
Percentage value, as a floating point number.

Inherited from object: __class__

Method Details [hide private]

__init__(self, quantity=None)
(Constructor)

source code 

Constructor for the PercentageQuantity class.

Parameters:
  • quantity - Percentage quantity, as a string (i.e. "99.9" or "12")
Raises:
  • ValueError - If the quantity value is invaid.
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

Official string representation for class instance.

Overrides: object.__repr__

__str__(self)
(Informal representation operator)

source code 

Informal string representation for class instance.

Overrides: object.__str__

__cmp__(self, other)
(Comparison operator)

source code 

Definition of equals operator for this class. Lists within this class are "unordered" for equality comparisons.

Parameters:
  • other - Other object to compare to.
Returns:
-1/0/1 depending on whether self is <, = or > other.

_setQuantity(self, value)

source code 

Property target used to set the quantity The value must be a non-empty string if it is not None.

Raises:
  • ValueError - If the value is an empty string.
  • ValueError - If the value is not a valid floating point number
  • ValueError - If the value is less than zero

_getPercentage(self)

source code 

Property target used to get the quantity as a floating point number. If there is no quantity set, then a value of 0.0 is returned.


Property Details [hide private]

quantity

Percentage value, as a string

Get Method:
_getQuantity(self) - Property target used to get the quantity.
Set Method:
_setQuantity(self, value) - Property target used to set the quantity The value must be a non-empty string if it is not None.

percentage

Percentage value, as a floating point number.

Get Method:
_getPercentage(self) - Property target used to get the quantity as a floating point number.