How to use the pypsrp.complex_objects.GenericComplexObject 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_host.py View on Github external
assert raw_ui.cursor_position.x == 11
        assert raw_ui.cursor_position.y == 12

        actual_window_position = raw_ui.GetWindowPosition(None, None)
        assert actual_window_position == window_position
        raw_ui.SetWindowPosition(None, None, coordinates)
        assert isinstance(raw_ui.window_position, Coordinates)
        assert raw_ui.window_position.x == 11
        assert raw_ui.window_position.y == 12

        actual_cursor_size = raw_ui.GetCursorSize(None, None)
        assert actual_cursor_size == cursor_size
        raw_ui.SetCursorSize(None, None, 25)
        assert raw_ui.cursor_size == 25

        size = GenericComplexObject()
        size.extended_properties['height'] = 160
        size.extended_properties['width'] = 160

        actual_buffer_size = raw_ui.GetBufferSize(None, None)
        assert actual_buffer_size == buffer_size
        raw_ui.SetBufferSize(None, None, size)
        assert isinstance(raw_ui.buffer_size, Size)
        assert raw_ui.buffer_size.height == 160
        assert raw_ui.buffer_size.width == 160

        actual_window_size = raw_ui.GetWindowSize(None, None)
        assert actual_window_size == window_size
        raw_ui.SetWindowSize(None, None, size)
        assert isinstance(raw_ui.window_size, Size)
        assert raw_ui.window_size.height == 160
        assert raw_ui.window_size.width == 160
github jborean93 / pypsrp / tests / test_serializer.py View on Github external
def test_serialize_dynamic_complex(self):
        serializer = Serializer()
        expected = \
            '' \
            '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 / test_serializer.py View on Github external
def test_deserialize_unknown_tag(self):
        serializer = Serializer()
        xml = '''
    
'''
        actual = serializer.deserialize(xml, ObjectMeta(
            "fake", object=GenericComplexObject
        ))
        assert actual == xml
github jborean93 / pypsrp / tests / test_host.py View on Github external
None)
        assert actual_physical_window_size == max_physical_window_size

        raw_ui.key_available = True
        actual_key_available = raw_ui.GetKeyAvailable(None, None)
        assert actual_key_available is True

        raw_ui.FlushInputBuffer(None, None)

        rectangle = GenericComplexObject()
        rectangle.extended_properties['left'] = 1
        rectangle.extended_properties['top'] = 2
        rectangle.extended_properties['right'] = 3
        rectangle.extended_properties['bottom'] = 4

        fill = GenericComplexObject()
        fill.extended_properties['character'] = "A"
        fill.extended_properties['foregroundColor'] = 12
        fill.extended_properties['backgroundColor'] = 10
        fill.extended_properties['bufferCellType'] = 0

        contents = GenericComplexObject()
        contents.extended_properties['mal'] = [2, 2]
        contents.extended_properties['mae'] = [[fill, fill], [fill, fill]]

        raw_ui.SetBufferContents1(None, None, rectangle, fill)
        raw_ui.SetBufferContents2(None, None, coordinates, contents)
        raw_ui.ScrollBufferContents(None, None, rectangle, coordinates,
                                    rectangle, fill)
github jborean93 / pypsrp / tests / test_host.py View on Github external
raw_ui.FlushInputBuffer(None, None)

        rectangle = GenericComplexObject()
        rectangle.extended_properties['left'] = 1
        rectangle.extended_properties['top'] = 2
        rectangle.extended_properties['right'] = 3
        rectangle.extended_properties['bottom'] = 4

        fill = GenericComplexObject()
        fill.extended_properties['character'] = "A"
        fill.extended_properties['foregroundColor'] = 12
        fill.extended_properties['backgroundColor'] = 10
        fill.extended_properties['bufferCellType'] = 0

        contents = GenericComplexObject()
        contents.extended_properties['mal'] = [2, 2]
        contents.extended_properties['mae'] = [[fill, fill], [fill, fill]]

        raw_ui.SetBufferContents1(None, None, rectangle, fill)
        raw_ui.SetBufferContents2(None, None, coordinates, contents)
        raw_ui.ScrollBufferContents(None, None, rectangle, coordinates,
                                    rectangle, fill)
github jborean93 / pypsrp / tests / test_powershell.py View on Github external
assert pool.state == RunspacePoolState.CLOSED
        # verify we can still call close on a closed pool
        pool.close()

        assert len(output) == 7
        assert output[0] == u"Hello World"
        assert output[1] == u"abc"
        assert output[2] == string_value
        assert output[3] == u"hi\""
        # this result differs on whether this is mocked or not
        if type(wsman_conn.transport).__name__ == "TransportFake":
            assert output[4] == "win-nnmu24vvkj0\\vagrant"
        else:
            assert wsman_conn.transport.username.lower() in output[4].lower()
        assert output[5] == 123
        assert isinstance(output[6], GenericComplexObject)
        assert str(output[6]) == "winrm"
        assert output[6].adapted_properties['DisplayName'] == \
            'Windows Remote Management (WS-Management)'
        assert output[6].adapted_properties['ServiceName'] == 'winrm'
        assert output[6].extended_properties['Name'] == 'winrm'
github jborean93 / pypsrp / tests / test_serializer.py View on Github external
def test_serialize_dynamic_obj(self):
        serializer = Serializer()
        expected = ''
        obj = GenericComplexObject()
        obj.extended_properties['key'] = "value"
        actual = serializer.serialize(obj)
        actual_xml = to_string(ET.tostring(actual))
        assert actual_xml == expected
github jborean93 / pypsrp / pypsrp / complex_objects.py View on Github external
def __init__(self):
        super(GenericComplexObject, self).__init__()
        self.property_sets = []
        self.extended_properties = {}
        self.adapted_properties = {}
        self.to_string = None
        self.types = []
github jborean93 / pypsrp / pypsrp / complex_objects.py View on Github external
def __init__(self, size):
            super(_HostDefaultData._Size, self).__init__()
            self._extended_properties = (
                ('type', ObjectMeta("S", name="T")),
                ('value', ObjectMeta("ObjDynamic", name="V",
                                     object=GenericComplexObject)),
            )
            self.type = "System.Management.Automation.Host.Size"
            self.value = GenericComplexObject()
            self.value.extended_properties['width'] = size.width
            self.value.extended_properties['height'] = size.height
github jborean93 / pypsrp / pypsrp / serializer.py View on Github external
elif value_type == float:
            return "Sg"
        elif value_type == str:
            return "S"
        elif value_type == bytes:
            # This will only occur in Python 3 as a byte string in Python 2 is
            # a str. If users on that platform want a BA then they need to
            # explicitly set the metadata themselves
            return "BA"
        elif value_type == uuid:
            return "G"
        elif value_type == list:
            return "LST"
        elif value_type == dict:
            return "DCT"
        elif isinstance(value, GenericComplexObject):
            return "ObjDynamic"
        elif isinstance(value, ComplexObject):
            return "Obj"
        else:
            # catch all, this probably isn't right but will not throw an
            # error
            return "S"