Back to index

obnam  1.1
Public Member Functions | Public Attributes | Static Public Attributes
obnamlib.sizeparse.ByteSizeParser Class Reference

List of all members.

Public Member Functions

def __init__
def set_default_unit
def parse

Public Attributes

 default_unit

Static Public Attributes

tuple pat
dictionary units

Detailed Description

Parse sizes of data in bytes, kilobytes, kibibytes, etc.

Definition at line 40 of file sizeparse.py.


Constructor & Destructor Documentation

Definition at line 60 of file sizeparse.py.

00060 
00061     def __init__(self):
00062         self.set_default_unit('B')
        

Here is the call graph for this function:


Member Function Documentation

def obnamlib.sizeparse.ByteSizeParser.parse (   self,
  string 
)

Definition at line 68 of file sizeparse.py.

00068 
00069     def parse(self, string):
00070         m = self.pat.match(string)
00071         if not m:
00072             raise SizeSyntaxError(string)
00073         size = float(m.group('size'))
00074         unit = m.group('unit')
00075         if not unit:
00076             unit = self.default_unit
00077         elif unit.lower() not in self.units:
00078             raise UnitNameError(unit)
00079         factor = self.units[unit.lower()]
00080         return int(size * factor)
00081 

Definition at line 63 of file sizeparse.py.

00063 
00064     def set_default_unit(self, unit):
00065         if unit.lower() not in self.units:
00066             raise UnitNameError(unit)
00067         self.default_unit = unit
        

Here is the caller graph for this function:


Member Data Documentation

Definition at line 66 of file sizeparse.py.

Initial value:
re.compile(r'^(?P<size>\d+(\.\d+)?)\s*'
                     r'(?P<unit>[kmg]?i?b?)?$', re.I)

Definition at line 44 of file sizeparse.py.

Initial value:
{
        'b': 1,
        'k': 1000,
        'kb': 1000,
        'kib': 1024,
        'm': 1000**2,
        'mb': 1000**2,
        'mib': 1024**2,
        'g': 1000**3,
        'gb': 1000**3,
        'gib': 1024**3,
    }

Definition at line 47 of file sizeparse.py.


The documentation for this class was generated from the following file: