diff --git a/qubesmgmt/__init__.py b/qubesmgmt/__init__.py index 9eb601c1..4b834bc0 100644 --- a/qubesmgmt/__init__.py +++ b/qubesmgmt/__init__.py @@ -73,6 +73,7 @@ def _parse_qubesd_response(response_data): # drop last field because of terminating '\x00' args = [arg.decode() for arg in args.split(b'\x00')[:-1]] format_string = format_string.decode('utf-8') + exc_type = exc_type.decode('ascii') exc_class = getattr(qubesmgmt.exc, exc_type, 'QubesException') # TODO: handle traceback if given raise exc_class(format_string, *args) @@ -87,7 +88,7 @@ def property_list(self): self._method_prefix + 'List', None, None) - self._properties = properties_str.splitlines() + self._properties = properties_str.decode('ascii').splitlines() # TODO: make it somehow immutable return self._properties @@ -114,9 +115,10 @@ def __getattr__(self, item): self._method_prefix + 'Get', item, None) - (_default, value) = property_str.split(' ', 1) + (_default, value) = property_str.split(b' ', 1) + value = value.decode() if value[0] == '\'': - return ast.literal_eval('b' + value) + return ast.literal_eval('u' + value) else: return ast.literal_eval(value) @@ -137,7 +139,7 @@ def __setattr__(self, key, value): self._method_dest, self._method_prefix + 'Set', key, - bytes(value)) + str(value).encode('utf-8')) def __delattr__(self, name): if name.startswith('_') or name in dir(self): diff --git a/qubesmgmt/app.py b/qubesmgmt/app.py index 47cbea4d..b56d07fa 100644 --- a/qubesmgmt/app.py +++ b/qubesmgmt/app.py @@ -44,10 +44,10 @@ def refresh_cache(self, force=False): new_vm_list = {} # FIXME: this will probably change for vm_data in vm_list_data.splitlines(): - vm_name, props = vm_data.split(b' ', 1) - props = props.split(b' ') + vm_name, props = vm_data.decode('ascii').split(' ', 1) + props = props.split(' ') new_vm_list[vm_name] = dict( - [vm_prop.split(b'=', 1) for vm_prop in props]) + [vm_prop.split('=', 1) for vm_prop in props]) self._vm_list = new_vm_list diff --git a/qubesmgmt/tests/app.py b/qubesmgmt/tests/app.py index 7f19e7b6..2e062584 100644 --- a/qubesmgmt/tests/app.py +++ b/qubesmgmt/tests/app.py @@ -26,7 +26,7 @@ def test_000_list(self): self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \ b'0\x00test-vm class=AppVM state=running\n' self.assertEqual( - self.app.domains.keys(), + list(self.app.domains.keys()), ['test-vm']) self.assertAllCalled()