How to use the soco.xml.XML function in soco

To help you get started, we’ve selected a few soco 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 tdamdouni / Pythonista / automation / SoCoSono / unittest / test_new_datastructures.py View on Github external
def test_didl_object_to_element(self):
        didl_object = data_structures.DidlObject(title='a_title',
            parent_id='pid', item_id='iid', creator='a_creator')
        # we seem to have to go through this to get ElementTree to deal
        # with namespaces properly!
        elt = XML.fromstring(XML.tostring(didl_object.to_element(True)))
        elt2 = XML.fromstring('' +
                    '' +
                    'a_title' +
                    'a_creator' +
                    'object')[0]
        assert_xml_equal(elt2, elt)
github SoCo / SoCo / tests / test_soap.py View on Github external
endpoint='http://endpoint.example.com',
        method='getData',
        parameters=[('one', '1')],
        http_headers={'user-agent': 'sonos'},
        soap_action='ACTION',
        soap_header="data",
        namespace="http://namespace.com",
        other_arg=4)

    response = mock.MagicMock()
    response.headers = {}
    response.status_code = 200
    response.content = DUMMY_VALID_RESPONSE
    with mock.patch('requests.post', return_value=response) as fake_post:
        result = s.call()
        assert XML.tostring(result)
        fake_post.assert_called_once_with(
            'http://endpoint.example.com',
            headers={'SOAPACTION': '"ACTION"',
                     'Content-Type': 'text/xml; charset="utf-8"', 'user-agent':
                         'sonos'},
            data=mock.ANY, other_arg=4)
github SoCo / SoCo / soco / core.py View on Github external
timeout: How long to wait for the server to send
                data before giving up, as a float, or a
                `(connect timeout, read timeout)` tuple
                e.g. (3, 5). Default is no timeout.

        Returns:
            dict: Information about the Sonos speaker, such as the UID,
            MAC Address, and Zone Name.
        """
        if self.speaker_info and refresh is False:
            return self.speaker_info
        else:
            response = requests.get('http://' + self.ip_address +
                                    ':1400/xml/device_description.xml',
                                    timeout=timeout)
            dom = XML.fromstring(response.content)

        device = dom.find('{urn:schemas-upnp-org:device-1-0}device')
        if device is not None:
            self.speaker_info['zone_name'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}roomName')

            # no zone icon in device_description.xml -> player icon
            self.speaker_info['player_icon'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}iconList/'
                '{urn:schemas-upnp-org:device-1-0}icon/'
                '{urn:schemas-upnp-org:device-1-0}url'
            )

            self.speaker_info['uid'] = self.uid
            self.speaker_info['serial_number'] = device.findtext(
                '{urn:schemas-upnp-org:device-1-0}serialNum')
github SoCo / SoCo / soco / alarms.py View on Github external
zone (`SoCo`, optional): a SoCo instance to query. If None, a random
            instance is used. Defaults to `None`.

    Returns:
        set: A set of `Alarm` instances

    Note:
        Any existing `Alarm` instance will have its attributes updated to those
        currently stored on the Sonos system.
    """
    # Get a soco instance to query. It doesn't matter which.
    if zone is None:
        zone = discovery.any_soco()
    response = zone.alarmClock.ListAlarms()
    alarm_list = response['CurrentAlarmList']
    tree = XML.fromstring(alarm_list.encode('utf-8'))

    # An alarm list looks like this:
    # 
    #     
    #     
    # 
github SoCo / SoCo / soco / data_structures.py View on Github external
``'...'``.
    """
    didl = XML.Element(
        'DIDL-Lite',
        {
            'xmlns': "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/",
            'xmlns:dc': "http://purl.org/dc/elements/1.1/",
            'xmlns:upnp': "urn:schemas-upnp-org:metadata-1-0/upnp/",
            'xmlns:r': "urn:schemas-rinconnetworks-com:metadata-1-0/"
        })
    for arg in args:
        didl.append(arg.to_element())
    if sys.version_info[0] == 2:
        return XML.tostring(didl)
    else:
        return XML.tostring(didl, encoding='unicode')
github SoCo / SoCo / soco / didl_lite.py View on Github external
def parse_xml(data):
    """ Parses XML in a unicode string into an ElementTree.

    @param data: raw XML data as unicode
    @type data: string

    @rtype: ElementTree
    """
    return ElementTree.fromstring(data.encode('utf-8'))
github SoCo / SoCo / soco / ms_data_structures.py View on Github external
item_attrib = {
            'parentID': '',
            'restricted': 'true',
            'id': self.extended_id
        }
        # Only add the parent_id if we have it
        if self.parent_id:
            item_attrib['parentID'] = self.parent_id
        item = XML.SubElement(
            xml,
            '{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}item',
            item_attrib,
        )

        # Add title and class
        XML.SubElement(
            item, '{http://purl.org/dc/elements/1.1/}title',
        ).text = self.title
        XML.SubElement(
            item, '{urn:schemas-upnp-org:metadata-1-0/upnp/}class',
        ).text = self.item_class
        # Add the desc element
        desc_attrib = {
            'id': 'cdudn',
            'nameSpace': 'urn:schemas-rinconnetworks-com:metadata-1-0/'
        }
        desc = XML.SubElement(
            item,
            '{urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/}desc',
            desc_attrib,
        )
        desc.text = self.content['description']
github SoCo / SoCo / soco / music_services / music_service.py View on Github external
def _get_music_services_data(cls):
        """Parse raw account data xml into a useful python datastructure.

        Returns:
            dict: Each key is a service_type, and each value is a
            `dict` containing relevant data.
        """
        # Return from cache if we have it.
        if cls._music_services_data is not None:
            return cls._music_services_data

        result = {}
        root = XML.fromstring(
            cls._get_music_services_data_xml().encode('utf-8')
        )
        # 
        #     
        #         
        #         
        #             
        #