xmlclass/xmlclass.py
changeset 90 2245e8776086
parent 88 bac6435df86f
child 92 76d5001393df
equal deleted inserted replaced
89:a6ff2b3fcc25 90:2245e8776086
    40 """
    40 """
    41 time_model = re.compile('([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)')
    41 time_model = re.compile('([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)')
    42 date_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})')
    42 date_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})')
    43 datetime_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})[ T]([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)')
    43 datetime_model = re.compile('([0-9]{4})-([0-9]{2})-([0-9]{2})[ T]([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)')
    44 
    44 
       
    45 XSD_INTEGER_TYPES = ["integer","nonPositiveInteger","negativeInteger","long",
       
    46     "int","short","byte","nonNegativeInteger","unsignedLong","unsignedInt",
       
    47     "unsignedShort","unsignedByte","positiveInteger"]
       
    48 
       
    49 XSD_STRING_TYPES = ["string","normalizedString","token","anyURI","NMTOKEN","language"]
       
    50 
    45 """
    51 """
    46 This function calculates the number of whitespace for indentation
    52 This function calculates the number of whitespace for indentation
    47 """
    53 """
    48 def getIndent(indent, balise):
    54 def getIndent(indent, balise):
    49     first = indent * 2
    55     first = indent * 2
    86              return True
    92              return True
    87          elif value == "false":
    93          elif value == "false":
    88              return False
    94              return False
    89          else:
    95          else:
    90             raise ValueError, "\"%s\" is not a valid boolean!"%value
    96             raise ValueError, "\"%s\" is not a valid boolean!"%value
    91     elif type_compute in ["unsignedLong","long","integer"]:
    97     elif type_compute in XSD_INTEGER_TYPES:
    92         return int(value)
    98         return int(value)
    93     elif type_compute == "decimal":
    99     elif type_compute in ["decimal", "float", "double"]:
    94         computed_value = float(value)
   100         computed_value = float(value)
    95         if computed_value % 1 == 0:
   101         if computed_value % 1 == 0:
    96             return int(computed_value)
   102             return int(computed_value)
    97         return computed_value
   103         return computed_value
    98     elif type_compute in ["string","anyURI","NMTOKEN","language"]:
   104     elif type_compute in XSD_STRING_TYPES:
    99         return value
   105         return value
   100     elif type_compute == "time":
   106     elif type_compute == "time":
   101         result = time_model.match(value)
   107         result = time_model.match(value)
   102         if result:
   108         if result:
   103             values = result.groups()
   109             values = result.groups()