<s> import re <EOL> _RE_FIND_FIRST_CAP = re . compile ( '<STR_LIT>' ) <EOL> _RE_SPAN_OF_CAPS = re . compile ( '<STR_LIT>' ) <EOL> def camelcase_to_underscore ( name ) : <EOL> return _RE_SPAN_OF_CAPS . sub ( r'<STR_LIT>' , <EOL> _RE_FIND_FIRST_CAP . sub ( r'<STR_LIT>' , name ) <EOL> ) . lower ( ) <EOL> class binary : <EOL> """<STR_LIT>""" <EOL> value = None <EOL> def __init__ ( self , value = None , unit = None ) : <EOL> self . do ( value = value , unit = unit ) <EOL> @ staticmethod <EOL> def convert ( value = None , oldUnit = None , newUnit = None ) : <EOL> convertor = binary ( value = value , unit = oldUnit ) <EOL> return convertor . get ( unit = newUnit ) <EOL> def set ( self , value , unit = None ) : <EOL> return self . do ( value = value , unit = unit ) <EOL> def get ( self , unit = None ) : <EOL> return self . do ( unit = unit ) <EOL> def do ( self , value = None , unit = None ) : <EOL> if not unit : <EOL> return self . bit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT:b>' ] : <EOL> return self . bit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . kilobit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . megabit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . gigabit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . terabit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . petabit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . exabit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . zettabit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . yottabit ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT:B>' ] : <EOL> return self . byte ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . kilobyte ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . megabyte ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . gigabyte ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . terabyte ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . petabyte ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . exabyte ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . zettabyte ( value = value ) <EOL> if unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . yottabyte ( value = value ) <EOL> raise NotImplementedError ( "<STR_LIT>" % unit ) <EOL> def bit ( self , value = None ) : <EOL> if value is None : <EOL> return self . value <EOL> else : <EOL> self . value = float ( value ) <EOL> def convertb ( self , value , source , offset = <NUM_LIT:1> ) : <EOL> if value is None : <EOL> return source ( ) / pow ( <NUM_LIT> , offset ) <EOL> else : <EOL> source ( value * pow ( <NUM_LIT> , offset ) ) <EOL> def kilobit ( self , value = None ) : <EOL> return self . convertb ( value , self . bit ) <EOL> def megabit ( self , value = None ) : <EOL> return self . convertb ( value , self . bit , <NUM_LIT:2> ) <EOL> def gigabit ( self , value = None ) : <EOL> return self . convertb ( value , self . bit , <NUM_LIT:3> ) <EOL> def terabit ( self , value = None ) : <EOL> return self . convertb ( value , self . bit , <NUM_LIT:4> ) <EOL> def petabit ( self , value = None ) : <EOL> return self . convertb ( value , self . bit , <NUM_LIT:5> ) <EOL> def exabit ( self , value = None ) : <EOL> return self . convertb ( value , self . bit , <NUM_LIT:6> ) <EOL> def zettabit ( self , value = None ) : <EOL> return self . convertb ( value , self . bit , <NUM_LIT:7> ) <EOL> def yottabit ( self , value = None ) : <EOL> return self . convertb ( value , self . bit , <NUM_LIT:8> ) <EOL> def byte ( self , value = None ) : <EOL> if value is None : <EOL> return self . value / <NUM_LIT:8> <EOL> else : <EOL> self . value = float ( value ) * <NUM_LIT:8> <EOL> def kilobyte ( self , value = None ) : <EOL> return self . convertb ( value , self . byte ) <EOL> def megabyte ( self , value = None ) : <EOL> return self . convertb ( value , self . byte , <NUM_LIT:2> ) <EOL> def gigabyte ( self , value = None ) : <EOL> return self . convertb ( value , self . byte , <NUM_LIT:3> ) <EOL> def terabyte ( self , value = None ) : <EOL> return self . convertb ( value , self . byte , <NUM_LIT:4> ) <EOL> def petabyte ( self , value = None ) : <EOL> return self . convertb ( value , self . byte , <NUM_LIT:5> ) <EOL> def exabyte ( self , value = None ) : <EOL> return self . convertb ( value , self . byte , <NUM_LIT:6> ) <EOL> def zettabyte ( self , value = None ) : <EOL> return self . convertb ( value , self . byte , <NUM_LIT:7> ) <EOL> def yottabyte ( self , value = None ) : <EOL> return self . convertb ( value , self . byte , <NUM_LIT:8> ) <EOL> class time : <EOL> """<STR_LIT>""" <EOL> value = None <EOL> def __init__ ( self , value = None , unit = None ) : <EOL> self . do ( value = value , unit = unit ) <EOL> @ staticmethod <EOL> def convert ( value = None , oldUnit = None , newUnit = None ) : <EOL> convertor = time ( value = value , unit = oldUnit ) <EOL> return convertor . get ( unit = newUnit ) <EOL> def set ( self , value , unit = None ) : <EOL> return self . do ( value = value , unit = unit ) <EOL> def get ( self , unit = None ) : <EOL> return self . do ( unit = unit ) <EOL> def do ( self , value = None , unit = None ) : <EOL> if not unit : <EOL> v = self . millisecond ( value = value ) <EOL> elif unit . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> v = self . millisecond ( value = value ) <EOL> elif unit . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:s>' ] : <EOL> v = self . second ( value = value ) <EOL> elif unit . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:m>' ] : <EOL> v = self . minute ( value = value ) <EOL> elif unit . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:h>' ] : <EOL> v = self . hour ( value = value ) <EOL> elif unit . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:d>' ] : <EOL> v = self . day ( value = value ) <EOL> elif unit . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:y>' ] : <EOL> v = self . year ( value = value ) <EOL> elif unit . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> v = self . microsecond ( value = value ) <EOL> elif unit . lower ( ) in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> v = self . nanosecond ( value = value ) <EOL> else : <EOL> raise NotImplementedError ( "<STR_LIT>" % unit ) <EOL> return v <EOL> def millisecond ( self , value = None ) : <EOL> if value is None : <EOL> return self . value <EOL> else : <EOL> self . value = float ( value ) <EOL> def second ( self , value = None ) : <EOL> if value is None : <EOL> return self . millisecond ( ) / <NUM_LIT:1000> <EOL> else : <EOL> self . millisecond ( value * <NUM_LIT:1000> ) <EOL> def minute ( self , value = None ) : <EOL> if value is None : <EOL> return self . second ( ) / <NUM_LIT> <EOL> else : <EOL> self . millisecond ( self . second ( value * <NUM_LIT> ) ) <EOL> def hour ( self , value = None ) : <EOL> if value is None : <EOL> return self . minute ( ) / <NUM_LIT> <EOL> else : <EOL> self . millisecond ( self . minute ( value * <NUM_LIT> ) ) <EOL> def day ( self , value = None ) : <EOL> if value is None : <EOL> return self . hour ( ) / <NUM_LIT> <EOL> else : <EOL> self . millisecond ( self . hour ( value * <NUM_LIT> ) ) <EOL> def year ( self , value = None ) : <EOL> """<STR_LIT>""" <EOL> if value is None : <EOL> return self . day ( ) / <NUM_LIT> <EOL> else : <EOL> self . millisecond ( self . day ( value * <NUM_LIT> ) ) <EOL> def microsecond ( self , value = None ) : <EOL> if value is None : <EOL> return self . millisecond ( ) * <NUM_LIT:1000> <EOL> else : <EOL> self . millisecond ( value / <NUM_LIT:1000> ) <EOL> def nanosecond ( self , value = None ) : <EOL> if value is None : <EOL> return self . microsecond ( ) * <NUM_LIT:1000> <EOL> else : <EOL> self . millisecond ( self . microsecond ( value / <NUM_LIT:1000> ) ) </s>
