65 def convert(self, value, param, ctx):
66
67 if type(value) == str:
68 if value.startswith('0x'):
69 base = 16
70 elif value.startswith('0o'):
71 bae = 8
72 elif value.startswith('0b'):
73 base = 2
74 else:
75 base = 10
76 rv = int(value, base)
77 else:
78 rv = int(value)
79 if self.clamp:
80 if self.min is not None and rv < self.min:
81 return self.min
82 if self.max is not None and rv > self.max:
83 return self.max
84 if self.min is not None and rv < self.min or \
85 self.max is not None and rv > self.max:
86 if self.min is None:
87 self.fail('%s is bigger than the maximum valid value '
88 '%s.' % (rv, self.max), param, ctx)
89 elif self.max is None:
90 self.fail('%s is smaller than the minimum valid value '
91 '%s.' % (rv, self.min), param, ctx)
92 else:
93 self.fail('%s is not in the valid range of %s to %s.'
94 % (rv, self.min, self.max), param, ctx)
95 return rv
96