<s> """<STR_LIT>""" <EOL> import re <EOL> import click <EOL> MEMORY_RE = re . compile ( r"<STR_LIT>" ) <EOL> class MemoryType ( click . ParamType ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> def convert ( self , value , param , ctx ) : <EOL> """<STR_LIT>""" <EOL> matches = MEMORY_RE . match ( value . lower ( ) ) <EOL> if matches is None : <EOL> self . fail ( '<STR_LIT>' <EOL> % value , param , ctx ) <EOL> amount_str , unit = matches . groups ( ) <EOL> amount = int ( amount_str ) <EOL> if unit in [ None , '<STR_LIT:m>' , '<STR_LIT>' ] : <EOL> if amount < <NUM_LIT> : <EOL> return amount * <NUM_LIT> <EOL> else : <EOL> if amount % <NUM_LIT> != <NUM_LIT:0> : <EOL> self . fail ( '<STR_LIT>' <EOL> % value , param , ctx ) <EOL> return amount <EOL> elif unit in [ '<STR_LIT:g>' , '<STR_LIT>' ] : <EOL> return amount * <NUM_LIT> <EOL> MEM_TYPE = MemoryType ( ) </s>
