23 def convert(self, value, param, ctx):
24
25 if type(value) == str:
26 if value.startswith('0x'):
27 base = 16
28 elif value.startswith('0o'):
29 bae = 8
30 elif value.startswith('0b'):
31 base = 2
32 else:
33 base = 10
34 rv = int(value, base)
35 else:
36 rv = int(value)
37 if self.clamp:
38 if self.min is not None and rv < self.min:
39 return self.min
40 if self.max is not None and rv > self.max:
41 return self.max
42 if self.min is not None and rv < self.min or \
43 self.max is not None and rv > self.max:
44 if self.min is None:
45 self.fail('%s is bigger than the maximum valid value '
46 '%s.' % (rv, self.max), param, ctx)
47 elif self.max is None:
48 self.fail('%s is smaller than the minimum valid value '
49 '%s.' % (rv, self.min), param, ctx)
50 else:
51 self.fail('%s is not in the valid range of %s to %s.'
52 % (rv, self.min, self.max), param, ctx)
53 return rv
54