Commit ebb8b02e authored by Sigmund Augdal's avatar Sigmund Augdal
Browse files

Fix parsing of Collection typed properties

parent dd96aabc
...@@ -14,6 +14,7 @@ except ImportError: ...@@ -14,6 +14,7 @@ except ImportError:
from ConfigParser import SafeConfigParser # pylint: disable=F0401 from ConfigParser import SafeConfigParser # pylint: disable=F0401
import uuid import uuid
from dateutil.parser import parse as tsparse from dateutil.parser import parse as tsparse
import re
namespaces = { namespaces = {
'b': "", 'b': "",
...@@ -57,6 +58,22 @@ def type_encode_argvalue(value): ...@@ -57,6 +58,22 @@ def type_encode_argvalue(value):
return 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): class ODataException(Exception):
def __init__(self, error_type, error_message, full_error): def __init__(self, error_type, error_message, full_error):
self.error_type = error_type self.error_type = error_type
...@@ -218,25 +235,21 @@ class Entry(object): ...@@ -218,25 +235,21 @@ class Entry(object):
return resources return resources
def parse_property(self, prop): def parse_property(self, prop):
inttypes = set(("Edm.Int32", "Edm.Int64", "Edm.Byte", "Edm.Int16")) collectiontypes = set(("VMM.ErrorInfo", "VMM.UserAndRole",
collectiontypes = set(("VMM.ErrorInfo", "VMM.UserAndRole", "VMM.VPNVMNetworkGateway")) "VMM.VPNVMNetworkGateway"))
if prop.get(ns("m", "null")) == "true": if prop.get(ns("m", "null")) == "true":
return None return None
property_type = prop.get(ns("m", "type")) property_type = prop.get(ns("m", "type"))
if not property_type: property_value = prop.text
return prop.text
if property_type == "Edm.Boolean": if property_type:
if prop.text == "true": if property_type in collectiontypes:
return True return self.parse_properties(prop, "*")
return False if property_type.startswith("Collection("):
if property_type in inttypes: subtype ='\((.*)\)', property_type).group(1)
return int(prop.text) return [convert_property_value(subtype, el.text) for el in
if property_type == "Edm.Guid": prop.xpath('ds:element', namespaces=namespaces)]
return uuid.UUID(prop.text) return convert_property_value(property_type, property_value)
if property_type == "Edm.DateTime":
return tsparse(prop.text)
if property_type in collectiontypes or property_type.startswith("Collection("):
return self.parse_properties(prop, "*")
def parse_properties(self, prop, xpath="atom:content/m:properties/*"): def parse_properties(self, prop, xpath="atom:content/m:properties/*"):
element = {} 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