How to use the soco.xml.XML.tostring 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_create_didl_resource_to_from_element(self):
        res = data_structures.DidlResource('a%20uri', 'a:protocol:info:xx',
            bitrate=3)
        elt = res.to_element()
        assert XML.tostring(elt) == (
            b'a%20uri')
        assert data_structures.DidlResource.from_element(elt).__dict__ == \
            res.__dict__
github tdamdouni / Pythonista / automation / SoCoSono / unittest / test_core.py View on Github external
moco.add_item_to_sonos_playlist(track, playlist)
        moco.contentDirectory.Browse.assert_called_once_with([
            ('ObjectID', playlist.item_id),
            ('BrowseFlag', 'BrowseDirectChildren'), 
            ('Filter', '*'),
            ('StartingIndex', 0),
            ('RequestedCount', 1),
            ('SortCriteria', '')
        ])
        moco.avTransport.AddURIToSavedQueue.assert_called_once_with(
            [('InstanceID', 0),
             ('UpdateID', update_id),
             ('ObjectID', playlist.item_id),
             ('EnqueuedURI', track.uri),
             ('EnqueuedURIMetaData', XML.tostring(track.didl_metadata)),
             ('AddAtIndex', 4294967295)]
        )
github SoCo / SoCo / tests / 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 / soco / plugins / wimp.py View on Github external
start
             max_items
           
         
        """
        xml = self._base_body()

        # Add the Body part
        XML.SubElement(xml, ns_tag('s', 'Body'))
        search = XML.SubElement(xml[1], ns_tag('', 'search'))
        XML.SubElement(search, 'id').text = search_type
        XML.SubElement(search, 'term').text = search_term
        XML.SubElement(search, 'index').text = str(start)
        XML.SubElement(search, 'count').text = str(max_items)

        return XML.tostring(xml)
github SoCo / SoCo / soco / music_services / music_service.py View on Github external
household_id.text = self._device.household_id
            credentials_header.append(login_token)

        # otherwise, perhaps use DeviceLink or UserId auth
        elif music_service.auth_type in ['DeviceLink', 'UserId']:
            # We need a session ID from Sonos
            session_id = self._device.musicServices.GetSessionId([
                ('ServiceId', music_service.service_id),
                ('Username', music_service.account.username)
            ])['SessionId']
            session_elt = XML.Element('sessionId')
            session_elt.text = session_id
            credentials_header.append(session_elt)

        # Anonymous auth. No need for anything further.
        self._cached_soap_header = XML.tostring(
            credentials_header,
            encoding='utf-8').decode(encoding='utf-8')
        return self._cached_soap_header
github SoCo / SoCo / soco / utils.py View on Github external
def show_xml(xml):
    """Pretty print an :class:`~xml.etree.ElementTree.ElementTree` XML object.

    Args:
        xml (:class:`~xml.etree.ElementTree.ElementTree`): The
            :class:`~xml.etree.ElementTree.ElementTree` to pretty print

    Note:
        This is used a convenience function used during development. It
        is not used anywhere in the main code base.
    """
    string = XML.tostring(xml)
    print(prettify(string))
github SoCo / SoCo / soco / didl_lite.py View on Github external
def to_string(self):
        """ String representation of this object.
        """
        return ElementTree.tostring(self.to_didl_element())