xmlclass/xmlclass.py
changeset 1780 c52d1460cea8
parent 1777 c46ec818bdd7
child 1782 5b6ad7a7fd9d
equal deleted inserted replaced
1779:6cf16e5bfbf9 1780:c52d1460cea8
   189         value = attr
   189         value = attr
   190     if len(value) % 2 != 0:
   190     if len(value) % 2 != 0:
   191         raise ValueError("\"%s\" isn't a valid hexadecimal integer!" % value)
   191         raise ValueError("\"%s\" isn't a valid hexadecimal integer!" % value)
   192     try:
   192     try:
   193         return int(value, 16)
   193         return int(value, 16)
   194     except:
   194     except Exception:
   195         raise ValueError("\"%s\" isn't a valid hexadecimal integer!" % value)
   195         raise ValueError("\"%s\" isn't a valid hexadecimal integer!" % value)
   196 
   196 
   197 
   197 
   198 def GenerateIntegerExtraction(minInclusive=None, maxInclusive=None,
   198 def GenerateIntegerExtraction(minInclusive=None, maxInclusive=None,
   199                               minExclusive=None, maxExclusive=None):
   199                               minExclusive=None, maxExclusive=None):
   219         else:
   219         else:
   220             value = attr
   220             value = attr
   221         try:
   221         try:
   222             # TODO: permit to write value like 1E2
   222             # TODO: permit to write value like 1E2
   223             value = int(value)
   223             value = int(value)
   224         except:
   224         except Exception:
   225             raise ValueError("\"%s\" isn't a valid integer!" % value)
   225             raise ValueError("\"%s\" isn't a valid integer!" % value)
   226         if minInclusive is not None and value < minInclusive:
   226         if minInclusive is not None and value < minInclusive:
   227             raise ValueError("\"%d\" isn't greater or equal to %d!" %
   227             raise ValueError("\"%d\" isn't greater or equal to %d!" %
   228                              (value, minInclusive))
   228                              (value, minInclusive))
   229         if maxInclusive is not None and value > maxInclusive:
   229         if maxInclusive is not None and value > maxInclusive:
   258             value = attr
   258             value = attr
   259         if value in extra_values:
   259         if value in extra_values:
   260             return value
   260             return value
   261         try:
   261         try:
   262             return float(value)
   262             return float(value)
   263         except:
   263         except Exception:
   264             raise ValueError("\"%s\" isn't a valid %s!" % (value, type))
   264             raise ValueError("\"%s\" isn't a valid %s!" % (value, type))
   265     return GetFloat
   265     return GetFloat
   266 
   266 
   267 
   267 
   268 def GetBoolean(attr, extract=True):
   268 def GetBoolean(attr, extract=True):
   408                 return value
   408                 return value
   409             else:
   409             else:
   410                 raise ValueError("Member limit can't be defined to \"unbounded\"!")
   410                 raise ValueError("Member limit can't be defined to \"unbounded\"!")
   411         try:
   411         try:
   412             limit = int(value)
   412             limit = int(value)
   413         except:
   413         except Exception:
   414             raise ValueError("\"%s\" isn't a valid value for this member limit!" % value)
   414             raise ValueError("\"%s\" isn't a valid value for this member limit!" % value)
   415         if limit < 0:
   415         if limit < 0:
   416             raise ValueError("Member limit can't be negative!")
   416             raise ValueError("Member limit can't be negative!")
   417         elif min is not None and limit < min:
   417         elif min is not None and limit < min:
   418             raise ValueError("Member limit can't be lower than \"%d\"!" % min)
   418             raise ValueError("Member limit can't be lower than \"%d\"!" % min)