CedarBackup3.extend.capacity.PercentageQuantity

Package CedarBackup3 :: 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 originally wanted 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) Original Python 2 comparison operator. | source code
__eq__(self, other) Equals operator, iplemented in terms of original Python 2 compare operator. | source code
__lt__(self, other) Less-than operator, iplemented in terms of original Python 2 compare operator. | source code
__gt__(self, other) Greater-than operator, iplemented in terms of original Python 2 compare operator. | 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
__ge__(x, y) x>=y |
__le__(x, y) x<=y |
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__subclasshook__`

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
Original Python 2 comparison operator. 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.