How to use the pypsrp._utils.to_unicode 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_complex_objects.py View on Github external
def normalise_xml(xml_string):
    xml = "".join([l.lstrip() for l in to_unicode(xml_string).splitlines()])
    xml = ETInbuilt.fromstring(xml)
    return to_unicode(ETInbuilt.tostring(xml))
github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def normalise_xml(xml_string):
    xml = "".join([l.lstrip() for l in to_unicode(xml_string).splitlines()])
    xml = ETInbuilt.fromstring(xml)
    return to_unicode(ETInbuilt.tostring(xml))
github jborean93 / pypsrp / tests / test_serializer.py View on Github external
def test_serialize_primitives(self, data, expected):
        serializer = Serializer()

        actual = serializer.serialize(data)
        actual_xml = to_unicode(ET.tostring(actual))
        expected_xml = to_unicode(expected)
        assert actual_xml == expected_xml

        deserial_actual = serializer.deserialize(actual)
        assert deserial_actual == data
github jborean93 / pypsrp / tests / test_utils.py View on Github external
def test_byte_to_unicode():
    expected = u"abc"
    actual = to_unicode(b"\x61\x62\x63")
    assert actual == expected
github jborean93 / pypsrp / pypsrp / serializer.py View on Github external
translation = {}
        for char_range in char_ranges:
            for i in range(char_range[0], char_range[1]):
                utf_bytes = to_bytes(unichr_func(i), encoding='utf-16-be')
                hex_string = binascii.hexlify(utf_bytes)
                translation[i] = '_x%s_' % to_string(hex_string)

        string_value = str(value)

        # before running the translation we need to make sure _ before x is
        # encoded, normally _ isn't encoded except when preceding x
        string_value = string_value.replace("_x", "_x005f_x")

        # now translate our string with the map provided
        string_value = to_unicode(string_value).translate(translation)

        return to_string(string_value)
github jborean93 / pypsrp / pypsrp / wsman.py View on Github external
def _create_endpoint(ssl, server, port, path):
        scheme = "https" if ssl else "http"

        # Check if the server is an IPv6 Address, enclose in [] if it is
        try:
            address = ipaddress.IPv6Address(to_unicode(server))
        except ipaddress.AddressValueError:
            pass
        else:
            server = "[%s]" % address.compressed

        endpoint = "%s://%s:%s/%s" % (scheme, server, port, path)
        return endpoint
github jborean93 / pypsrp / pypsrp / client.py View on Github external
def read_buffer(b_path, total_size, buffer_size):
            offset = 0
            sha1 = hashlib.sha1()

            with open(b_path, 'rb') as src_file:
                for data in iter((lambda: src_file.read(buffer_size)), b""):
                    log.debug("Reading data of file at offset=%d with size=%d"
                              % (offset, buffer_size))
                    offset += len(data)
                    sha1.update(data)
                    b64_data = base64.b64encode(data)

                    result = [to_unicode(b64_data)]
                    if offset == total_size:
                        result.append(to_unicode(base64.b64encode(to_bytes(sha1.hexdigest()))))

                    yield result

                # the file was empty, return empty buffer
                if offset == 0:
                    yield [u"", to_unicode(base64.b64encode(to_bytes(sha1.hexdigest())))]