CedarBackup2.config.ByteQuantity

Package CedarBackup2 :: Module config :: Class ByteQuantity |
[hide private]
[frames] | no frames]

# Class ByteQuantity

source code

    object --+
             |
            ByteQuantity

Class representing a byte quantity.

A byte quantity has both a quantity and a byte-related unit. Units are maintained using the constants from util.py. If no units are provided, `UNIT_BYTES` is assumed.

The quantity 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 quantity of bytes in this context.

Instance Methods | [hide private]
__init__(self, quantity=None, units=None) Constructor for the `ByteQuantity` 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 interpretable as a float if it is not None | source code
_getQuantity(self) Property target used to get the quantity. | source code
_setUnits(self, value) Property target used to set the units value. | source code
_getUnits(self) Property target used to get the units value. | source code
_getBytes(self) Property target used to return the byte quantity as a floating point number. | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__subclasshook__`

Properties | [hide private]
| quantity Byte quantity, as a string
| units Units for byte quantity, for instance UNIT_BYTES
| bytes Byte quantity, as a floating point number.
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, quantity=None, units=None) (Constructor) | source code
Constructor for the `ByteQuantity` class. Parameters: `quantity` - Quantity of bytes, something interpretable as a float `units` - Unit of bytes, one of VALID_BYTE_UNITS Raises: `ValueError` - If one of the values is invalid. 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 interpretable as a float 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

### _setUnits(self, value) | source code
Property target used to set the units value. If not `None`, the units value must be one of the values in VALID_BYTE_UNITS. Raises: `ValueError` - If the value is not valid.

### _getBytes(self) | source code
Property target used to return the byte 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 Byte quantity, 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 interpretable as a float if it is not None

### units Units for byte quantity, for instance UNIT_BYTES Get Method: _getUnits(self) - Property target used to get the units value. Set Method: _setUnits(self, value) - Property target used to set the units value.

### bytes Byte quantity, as a floating point number. Get Method: _getBytes(self) - Property target used to return the byte quantity as a floating point number.