<s> from shpkpr import exceptions <EOL> def filter_items ( value , startswith = None , strip_prefix = False ) : <EOL> """<STR_LIT>""" <EOL> if startswith is not None : <EOL> value = [ x for x in value . items ( ) if x [ <NUM_LIT:0> ] . startswith ( startswith ) ] <EOL> else : <EOL> value = value . items ( ) <EOL> if startswith is not None and strip_prefix : <EOL> value = [ ( x [ <NUM_LIT:0> ] . replace ( startswith , "<STR_LIT>" , <NUM_LIT:1> ) , x [ <NUM_LIT:1> ] ) for x in value ] <EOL> return value <EOL> class IntegerRequired ( exceptions . ShpkprException ) : <EOL> exit_code = <NUM_LIT:2> <EOL> class IntegerTooSmall ( exceptions . ShpkprException ) : <EOL> exit_code = <NUM_LIT:2> <EOL> class IntegerTooLarge ( exceptions . ShpkprException ) : <EOL> exit_code = <NUM_LIT:2> <EOL> @ exceptions . rewrap ( ValueError , IntegerRequired ) <EOL> def require_int ( value , min = None , max = None ) : <EOL> """<STR_LIT>""" <EOL> value = int ( value ) <EOL> if min is not None and value < min : <EOL> raise IntegerTooSmall ( "<STR_LIT>" % ( value , min ) ) <EOL> if max is not None and value > max : <EOL> raise IntegerTooLarge ( "<STR_LIT>" % ( value , max ) ) <EOL> return value <EOL> class FloatRequired ( exceptions . ShpkprException ) : <EOL> exit_code = <NUM_LIT:2> <EOL> class FloatTooSmall ( exceptions . ShpkprException ) : <EOL> exit_code = <NUM_LIT:2> <EOL> class FloatTooLarge ( exceptions . ShpkprException ) : <EOL> exit_code = <NUM_LIT:2> <EOL> @ exceptions . rewrap ( ValueError , FloatRequired ) <EOL> def require_float ( value , min = None , max = None ) : <EOL> """<STR_LIT>""" <EOL> value = float ( value ) <EOL> if min is not None and value < min : <EOL> raise FloatTooSmall ( "<STR_LIT>" % ( value , min ) ) <EOL> if max is not None and value > max : <EOL> raise FloatTooLarge ( "<STR_LIT>" % ( value , max ) ) <EOL> return value </s>
