How to use the pypsrp._utils.to_string function in pypsrp

To help you get started, we’ve selected a few pypsrp 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 jborean93 / pypsrp / tests / test_serializer.py View on Github external
def test_serialize_list_as_ie(self):
        serializer = Serializer()
        data = []
        data.append("0")
        data.append("1")
        data.append("2")
        expected = \
            'System.Object[]' \
            'System.ArraySystem.Object' \
            '<s>0</s><s>1</s><s>2</s>'

        actual = serializer.serialize(data, ListMeta("IE"))
        actual_xml = to_string(ET.tostring(actual))
        assert actual_xml == expected
github jborean93 / pypsrp / tests / test_serializer.py View on Github external
'' \
            'System.Management.Automation.PSCustomObject' \
            'System.Objectto string value' \
            '1<s>2</s>' \
            '<s>adapted</s>'

        obj = GenericComplexObject()
        obj.types = ["System.Management.Automation.PSCustomObject",
                     "System.Object"]
        obj.extended_properties['extended_key'] = 'extended'
        obj.adapted_properties['adapted_key'] = 'adapted'
        obj.property_sets = [1, "2"]
        obj.to_string = "to string value"

        actual = serializer.serialize(obj)
        actual_xml = to_string(ET.tostring(actual))
        assert actual_xml == expected
github jborean93 / pypsrp / tests / runner.py View on Github external
override_element.attrib[attr_key] = attr_value
        else:
            xml_obj = ET.fromstring(to_bytes(xml))

        # convert the string to an XML object, for Python 2.6 (lxml) we need
        # to change the namespace handling to mimic the ElementTree way of
        # working so the string compare works
        if sys.version_info[0] == 2 and sys.version_info[1] &lt; 7:
            namespaces = {}
            new_xml_obj = self._simplify_namespaces(namespaces, xml_obj)
            for key, value in namespaces.items():
                new_xml_obj.attrib["xmlns:%s" % key] = value

            xml_obj = new_xml_obj

        return to_string(ETNew.tostring(xml_obj, encoding='utf-8'))
github jborean93 / pypsrp / tests / test_utils.py View on Github external
def test_to_str():
    if PY3:
        assert str(to_string).startswith("
github jborean93 / pypsrp / tests / test_utils.py View on Github external
def test_to_str():
    if PY3:
        assert str(to_string).startswith("
github jborean93 / pypsrp / pypsrp / complex_objects.py View on Github external
def __str__(self):
        return to_string(self._to_string)
github jborean93 / pypsrp / pypsrp / serializer.py View on Github external
            'BA': lambda m, d: to_string(base64.b64encode(d)),
            'G': lambda m, d: str(d),
github jborean93 / pypsrp / pypsrp / serializer.py View on Github external
def deserialize(self, element, metadata=None, clear=True):
        if clear:
            self._clear()

        if isinstance(element, string_types):
            element_string = element
            element = ET.fromstring(element)
        else:
            xml_string = ET.tostring(element, encoding='utf-8', method='xml')
            element_string = to_string(xml_string)

        metadata = metadata or ObjectMeta()
        if metadata.tag == "*":
            metadata.tag = element.tag

        # get the object types so we store the TN Ref ids for later use
        obj_types = self._get_types_from_obj(element)

        # check if it is a primitive object
        unpack_function = {
            # Primitive types
            'S': lambda d: self._deserialize_string(d.text),
            'ToString': lambda d: self._deserialize_string(d.text),
            'C': lambda d: chr(d.text),
            'B': lambda d: d.text.lower() == "true",
            'DT': lambda d: None,
github jborean93 / pypsrp / pypsrp / wsman.py View on Github external
def _send_request(self, request, hostname):
        response = self.session.send(request, timeout=(
            self.connection_timeout, self.read_timeout
        ))

        content_type = response.headers.get('content-type', "")
        if content_type.startswith("multipart/encrypted;") or \
                content_type.startswith("multipart/x-multi-encrypted;"):
            response_content = self.encryption.unwrap_message(response.content,
                                                              hostname)
            response_text = to_string(response_content)
        else:
            response_content = response.content
            response_text = response.text if response_content else ''

        log.debug("Received message: %s" % response_text)
        # for testing, keep commented out
        # self._test_messages[-1]['response'] = response_text
        try:
            response.raise_for_status()
        except requests.HTTPError as err:
            response = err.response
            if response.status_code == 401:
                raise AuthenticationError("Failed to authenticate the user %s "
                                          "with %s"
                                          % (self.username, self.auth))
            else:
github jborean93 / pypsrp / pypsrp / messages.py View on Github external
def unpack(data, serializer):
        destination = struct.unpack("