How to use the msrest.serialization.Deserializer function in msrest

To help you get started, we’ve selected a few msrest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / msrest-for-python / tests / test_xml_serialization.py View on Github external
_attribute_map = {
                'good_apples': {'key': 'GoodApples', 'type': '[Apple]', 'xml': {'name': 'GoodApples', 'wrapped': True, 'itemsName': 'Apple'}},
            }
            _xml_map = {
                'name': 'AppleBarrel'
            }

        class Apple(Model):
            _attribute_map = {
                'name': {'key': 'name', 'type': 'str', 'xml':{'name': 'name', 'attr': True}},
            }
            _xml_map = {
                'name': 'Pomme' # Should be ignored, since "itemsName" is defined
            }

        s = Deserializer({"AppleBarrel": AppleBarrel, "Apple": Apple})
        result = s('AppleBarrel', basic_xml, "application/xml")

        assert [apple.name for apple in result.good_apples] == ["granny", "fuji"]
github Azure / msrest-for-python / tests / test_xml_serialization.py View on Github external
def test_basic_empty(self):
        """Test an basic XML with an empty node."""
        basic_xml = """
            <data>
                
            </data>"""

        class XmlModel(Model):
            _attribute_map = {
                'age': {'key': 'age', 'type': 'str', 'xml':{'name': 'Age'}},
            }
            _xml_map = {
                'name': 'Data'
            }

        s = Deserializer({"XmlModel": XmlModel})
        result = s(XmlModel, basic_xml, "application/xml")

        assert result.age == ""
github Azure / msrest-for-python / tests / test_xml_serialization.py View on Github external
'key_name': {'key': 'KeyName', 'type': 'str', 'xml': {'ns': 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'}},
            }
            _xml_map = {
                'ns': 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'
            }

        class MessageCountDetails(Model):
            _attribute_map = {
                'active_message_count': {'key': 'ActiveMessageCount', 'type': 'int', 'xml': {'prefix': 'd2p1', 'ns': 'http://schemas.microsoft.com/netservices/2011/06/servicebus'}},
            }
            _xml_map = {
                'name': 'CountDetails', 'ns': 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'
            }


        s = Deserializer({
            "XmlRoot": XmlRoot,
            "QueueDescriptionResponseAuthor": QueueDescriptionResponseAuthor,
            "AuthorizationRule": AuthorizationRule,
            "MessageCountDetails": MessageCountDetails,
        })
        result = s(XmlRoot, basic_xml, "application/xml")

        assert result.author.name == "lmazuel"
        assert result.authorization_rules[0].key_name == "testpolicy"
        assert result.authorization_rules[0].type == "SharedAccessAuthorizationRule"
        assert result.message_count_details.active_message_count == 12
github Azure / azure-sdk-for-java / ClientRuntimes / Python / msrestazure / msrestazure / azure_exceptions.py View on Github external
"""
        try:
            value = eval(value)
        except (SyntaxError, TypeError):
            pass
        try:
            value = value.get('value', value)
            msg_data = value.split('\n')
            self._message = msg_data[0]
        except AttributeError:
            self._message = value
            return
        try:
            self.request_id = msg_data[1].partition(':')[2]
            time_str = msg_data[2].partition(':')
            self.error_time = Deserializer.deserialize_iso(
                "".join(time_str[2:]))
        except (IndexError, DeserializationError):
            pass
github Azure / azure-sdk-for-java / ClientRuntimes / Python / msrestazure / msrestazure / azure_exceptions.py View on Github external
"""
        try:
            value = eval(value)
        except (SyntaxError, TypeError):
            pass
        try:
            value = value.get('value', value)
            msg_data = value.split('\n')
            self._message = msg_data[0]
        except AttributeError:
            self._message = value
            return
        try:
            self.request_id = msg_data[1].partition(':')[2]
            time_str = msg_data[2].partition(':')
            self.error_time = Deserializer.deserialize_iso(
                "".join(time_str[2:]))
        except (IndexError, DeserializationError):
            pass
github Azure / msrest-for-python / msrest / serialization.py View on Github external
def __init__(self, classes=None):
        self.deserialize_type = {
            'iso-8601': Deserializer.deserialize_iso,
            'rfc-1123': Deserializer.deserialize_rfc,
            'unix-time': Deserializer.deserialize_unix,
            'duration': Deserializer.deserialize_duration,
            'date': Deserializer.deserialize_date,
            'time': Deserializer.deserialize_time,
            'decimal': Deserializer.deserialize_decimal,
            'long': Deserializer.deserialize_long,
            'bytearray': Deserializer.deserialize_bytearray,
            'base64': Deserializer.deserialize_base64,
            'object': self.deserialize_object,
            '[]': self.deserialize_iter,
            '{}': self.deserialize_dict
            }
        self.deserialize_expected_types = {
            'duration': (isodate.Duration, datetime.timedelta),
            'iso-8601': (datetime.datetime)
        }
        self.dependencies = dict(classes) if classes else {}
        self.key_extractors = [
            rest_key_extractor,
            xml_key_extractor
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / batchai / custom.py View on Github external
def _get_deserializer():
    client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
    return Deserializer(client_models)
github Azure / msrest-for-python / msrest / serialization.py View on Github external
def __init__(self, classes=None):
        self.deserialize_type = {
            'iso-8601': Deserializer.deserialize_iso,
            'rfc-1123': Deserializer.deserialize_rfc,
            'unix-time': Deserializer.deserialize_unix,
            'duration': Deserializer.deserialize_duration,
            'date': Deserializer.deserialize_date,
            'time': Deserializer.deserialize_time,
            'decimal': Deserializer.deserialize_decimal,
            'long': Deserializer.deserialize_long,
            'bytearray': Deserializer.deserialize_bytearray,
            'base64': Deserializer.deserialize_base64,
            'object': self.deserialize_object,
            '[]': self.deserialize_iter,
            '{}': self.deserialize_dict
            }
        self.deserialize_expected_types = {
            'duration': (isodate.Duration, datetime.timedelta),
            'iso-8601': (datetime.datetime)
        }
        self.dependencies = dict(classes) if classes else {}
        self.key_extractors = [
            rest_key_extractor,
            xml_key_extractor
        ]
        # Additional properties only works if the "rest_key_extractor" is used to
github Azure / msrest-for-python / msrest / serialization.py View on Github external
def __init__(self, classes=None):
        self.deserialize_type = {
            'iso-8601': Deserializer.deserialize_iso,
            'rfc-1123': Deserializer.deserialize_rfc,
            'unix-time': Deserializer.deserialize_unix,
            'duration': Deserializer.deserialize_duration,
            'date': Deserializer.deserialize_date,
            'time': Deserializer.deserialize_time,
            'decimal': Deserializer.deserialize_decimal,
            'long': Deserializer.deserialize_long,
            'bytearray': Deserializer.deserialize_bytearray,
            'base64': Deserializer.deserialize_base64,
            'object': self.deserialize_object,
            '[]': self.deserialize_iter,
            '{}': self.deserialize_dict
            }
        self.deserialize_expected_types = {
            'duration': (isodate.Duration, datetime.timedelta),
            'iso-8601': (datetime.datetime)
        }
        self.dependencies = dict(classes) if classes else {}
        self.key_extractors = [
            rest_key_extractor,
github Azure / msrest-for-python / msrest / paging.py View on Github external
def __init__(self, command, classes, raw_headers=None, **kwargs):
        # type: (Callable[[str], ClientResponse], Dict[str, Model], Dict[str, str], Any) -> None
        super(Paged, self).__init__(**kwargs)  # type: ignore
        # Sets next_link, current_page, and _current_page_iter_index.
        self.next_link = ""
        self._current_page_iter_index = 0
        self.reset()
        self._derserializer = Deserializer(classes)
        self._get_next = command
        self._response = None  # type: Optional[ClientResponse]
        self._raw_headers = raw_headers