Package yum :: Module config :: Class BytesOption
[hide private]
[frames] | no frames]

Class BytesOption

source code


An option representing a value in bytes.

The value may be given in bytes, kilobytes, megabytes, or gigabytes.

Instance Methods [hide private]
 
parse(self, s)
Parse a friendly bandwidth option to bytes
source code

Inherited from Option: __get__, __init__, __set__, clone, setup, tostring

Inherited from Option (private): _setattrname

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  MULTS = {'g': 1073741824, 'k': 1024, 'm': 1048576}

Inherited from Option: __slotnames__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

parse(self, s)

source code 

Parse a friendly bandwidth option to bytes

The input should be a string containing a (possibly floating point) number followed by an optional single character unit. Valid units are 'k', 'M', 'G'. Case is ignored.

Valid inputs: 100, 123M, 45.6k, 12.4G, 100K, 786.3, 0 Invalid inputs: -10, -0.1, 45.6L, 123Mb

Return value will always be an integer

1k = 1024 bytes.

ValueError will be raised if the option couldn't be parsed.

Parameters:
  • s - Raw string value to parse.
Returns:
Validated native value.

Will raise ValueError if there was a problem parsing the string. Subclasses should override this.

Overrides: Option.parse