44# (C)2011-2016 Dennis Kaarsemaker
55# License: zlib
66
7+ import copy
78import dbus
89import os
910import socket
@@ -88,9 +89,9 @@ def unwrap(self, val):
8889 def wrap (self , val ):
8990 if isinstance (val , NMDbusInterface ):
9091 return val .object_path
91- if hasattr (val , 'mro' ):
92- for klass in val .mro ():
93- if klass .__module__ == ' _dbus_bindings' :
92+ if hasattr (val . __class__ , 'mro' ):
93+ for klass in val .__class__ . mro ():
94+ if klass .__module__ in ( 'dbus' , ' _dbus_bindings') :
9495 return val
9596 if hasattr (val , '__iter__' ) and not isinstance (val , basestring ):
9697 if hasattr (val , 'items' ):
@@ -138,8 +139,8 @@ class NetworkManager(NMDbusInterface):
138139 object_path = '/org/freedesktop/NetworkManager'
139140
140141 def preprocess (self , name , args , kwargs ):
141- if name in ('AddConnection' , 'Update' , 'AddAndActivateConnection' ):
142- settings = args [0 ]
142+ if name in ('AddConnection' , 'Update' , 'UpdateUnsaved' , ' AddAndActivateConnection' ):
143+ settings = copy . deepcopy ( args [0 ])
143144 for key in settings :
144145 if 'mac-address' in settings [key ]:
145146 settings [key ]['mac-address' ] = fixups .mac_to_dbus (settings [key ]['mac-address' ])
@@ -163,6 +164,18 @@ def preprocess(self, name, args, kwargs):
163164 settings ['ipv6' ]['routes' ] = [fixups .route_to_dbus (route ,socket .AF_INET6 ) for route in settings ['ipv6' ]['routes' ]]
164165 if 'dns' in settings ['ipv6' ]:
165166 settings ['ipv6' ]['dns' ] = [fixups .addr_to_dbus (addr ,socket .AF_INET6 ) for addr in settings ['ipv6' ]['dns' ]]
167+ # Get rid of empty arrays/dicts. dbus barfs on them (can't guess
168+ # signatures), and if they were to get through, NetworkManager
169+ # ignores them anyway.
170+ for key in list (settings .keys ()):
171+ if isinstance (settings [key ], dict ):
172+ for key2 in list (settings [key ].keys ()):
173+ if settings [key ][key2 ] in ({}, []):
174+ del settings [key ][key2 ]
175+ if settings [key ] in ({}, []):
176+ del settings [key ]
177+ return (settings ,) + args [1 :], kwargs
178+
166179 return args , kwargs
167180NetworkManager = NetworkManager ()
168181
@@ -335,7 +348,7 @@ def preprocess(self, name, args, kwargs):
335348 conf ['addresses' ] = [fixups .addrconf_to_python (addr ,socket .AF_INET ) for addr in conf ['addresses' ]]
336349 conf ['routes' ] = [fixups .route_to_python (route ,socket .AF_INET ) for route in conf ['routes' ]]
337350 conf ['dns' ] = [fixups .addr_to_python (addr ,socket .AF_INET ) for addr in conf ['dns' ]]
338- return args , kwargs
351+ return ( conf ,) + args [ 1 :] , kwargs
339352
340353class VPNPlugin (NMDbusInterface ):
341354 interface_name = 'org.freedesktop.NetworkManager.VPN.Plugin'
0 commit comments