Commit ebb8b02e authored by Sigmund Augdal's avatar Sigmund Augdal

Fix parsing of Collection typed properties

parent dd96aabc
......@@ -14,6 +14,7 @@ except ImportError:
from ConfigParser import SafeConfigParser # pylint: disable=F0401
import uuid
from dateutil.parser import parse as tsparse
import re
namespaces = {
'b': "http://www.w3.org/2007/app",
......@@ -57,6 +58,22 @@ def type_encode_argvalue(value):
return value
def convert_property_value(property_type, property_value):
inttypes = set(("Edm.Int32", "Edm.Int64", "Edm.Byte", "Edm.Int16"))
if not property_type:
return property_value
if property_type == "Edm.Boolean":
if property_value == "true":
return True
return False
if property_type in inttypes:
return int(property_value)
if property_type == "Edm.Guid":
return uuid.UUID(property_value)
if property_type == "Edm.DateTime":
return tsparse(property_value)
class ODataException(Exception):
def __init__(self, error_type, error_message, full_error):
self.error_type = error_type
......@@ -218,25 +235,21 @@ class Entry(object):
return resources
def parse_property(self, prop):
inttypes = set(("Edm.Int32", "Edm.Int64", "Edm.Byte", "Edm.Int16"))
collectiontypes = set(("VMM.ErrorInfo", "VMM.UserAndRole", "VMM.VPNVMNetworkGateway"))
collectiontypes = set(("VMM.ErrorInfo", "VMM.UserAndRole",
"VMM.VPNVMNetworkGateway"))
if prop.get(ns("m", "null")) == "true":
return None
property_type = prop.get(ns("m", "type"))
if not property_type:
return prop.text
if property_type == "Edm.Boolean":
if prop.text == "true":
return True
return False
if property_type in inttypes:
return int(prop.text)
if property_type == "Edm.Guid":
return uuid.UUID(prop.text)
if property_type == "Edm.DateTime":
return tsparse(prop.text)
if property_type in collectiontypes or property_type.startswith("Collection("):
property_value = prop.text
if property_type:
if property_type in collectiontypes:
return self.parse_properties(prop, "*")
if property_type.startswith("Collection("):
subtype = re.search('\((.*)\)', property_type).group(1)
return [convert_property_value(subtype, el.text) for el in
prop.xpath('ds:element', namespaces=namespaces)]
return convert_property_value(property_type, property_value)
def parse_properties(self, prop, xpath="atom:content/m:properties/*"):
element = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment