46 def convert(self, value, param, ctx):
47
48 if type(value) == str:
49 if value.startswith('0x'):
50 base = 16
51 elif value.startswith('0o'):
52 bae = 8
53 elif value.startswith('0b'):
54 base = 2
55 else:
56 base = 10
57 rv = int(value, base)
58 else:
59 rv = int(value)
60 if self.clamp:
61 if self.min is not None and rv < self.min:
62 return self.min
63 if self.max is not None and rv > self.max:
64 return self.max
65 if self.min is not None and rv < self.min or \
66 self.max is not None and rv > self.max:
67 if self.min is None:
68 self.fail('%s is bigger than the maximum valid value '
69 '%s.' % (rv, self.max), param, ctx)
70 elif self.max is None:
71 self.fail('%s is smaller than the minimum valid value '
72 '%s.' % (rv, self.min), param, ctx)
73 else:
74 self.fail('%s is not in the valid range of %s to %s.'
75 % (rv, self.min, self.max), param, ctx)
76 return rv
77