Skip to content

Commit

Permalink
fix: fixed deferred parsing for Properties
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Horton <paul.horton@owasp.org>
  • Loading branch information
madpah committed Aug 23, 2022
1 parent 54607f1 commit 833e29b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions serializable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import json
import logging
import re
import typing # type: ignore
import warnings
from copy import copy
from io import StringIO, TextIOWrapper
Expand Down Expand Up @@ -363,7 +364,8 @@ def _from_xml(cls: Type[_T], data: Union[TextIOWrapper, ElementTree.Element],

prop_info = klass_properties.get(decoded_k, None)
if not prop_info:
raise ValueError(f'{decoded_k} is not a known Property for {cls.__module__}.{cls.__qualname__}')
raise ValueError(f'Non-primitive types not supported from XML Attributes - see {decoded_k} for '
f'{cls.__module__}.{cls.__qualname__} which has Prop Metadata: {prop_info}')

if prop_info.custom_type and prop_info.is_helper_type():
_data[decoded_k] = prop_info.custom_type.deserialize(v)
Expand Down Expand Up @@ -394,10 +396,16 @@ def _from_xml(cls: Type[_T], data: Union[TextIOWrapper, ElementTree.Element],
if pi.xml_array_config:
array_type, nested_name = pi.xml_array_config
if nested_name == decoded_k:
decoded_k = p
if array_type == XmlArraySerializationType.FLAT:
decoded_k = p
else:
decoded_k = '____SKIP_ME____'
elif pi.custom_names.get(SerializationType.XML, None) == decoded_k:
decoded_k = p

if decoded_k == '____SKIP_ME____':
continue

prop_info = klass_properties.get(decoded_k, None)
if not prop_info:
raise ValueError(f'{decoded_k} is not a known Property for {cls.__module__}.{cls.__qualname__}')
Expand Down Expand Up @@ -521,6 +529,7 @@ def __init__(self, *, prop_name: str, prop_type: Any, custom_names: Dict[Seriali
self._is_xml_attribute = is_xml_attribute
self._xml_array_config = xml_array_config

self._deferred_type_parsing = False
self._parse_type(type_=prop_type)

@property
Expand Down Expand Up @@ -643,7 +652,7 @@ def _parse_type(self, type_: Any) -> None:
self._is_enum = True

# Ensure marked as not deferred
if self._defered_type_parsing:
if self._deferred_type_parsing:
self._deferred_type_parsing = False

def __repr__(self) -> str:
Expand Down

0 comments on commit 833e29b

Please sign in to comment.