#7554 NORM 8.2.0 (: sugar.hardware.nmclient.Device() instances' get_colors() method should never raise()
Zarro Boogs per Child
bugtracker at laptop.org
Thu Jul 17 20:20:19 EDT 2008
#7554: sugar.hardware.nmclient.Device() instances' get_colors() method should
never raise()
------------------------+---------------------------------------------------
Reporter: mtd | Owner: mtd
Type: defect | Status: new
Priority: normal | Milestone: 8.2.0 (was Update.2)
Component: sugar | Version: Git as of bug date
Keywords: 8.2.0:+ r? | Next_action: review
Verified: 0 | Blockedby:
Blocking: |
------------------------+---------------------------------------------------
If I interrogate a sugar.hardware.nmclient.Device() instances'
get_colors() method, I should never get an exception. But sometimes I do:
{{{
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
/usr/share/sugar/shell/view/devices/network/wireless.py in
_ip_address_changed_cb(self=<DeviceView object at 0x94bd43c (SugarTrayIcon
at 0x9566b50)>, model=<Device object at 0x94bd02c
(model+devices+network+wireless+Device at 0x946e540)>, pspec=<GParamString
'ip-address'>)
91
92 def _ip_address_changed_cb(self, model, pspec):
---> 93 self._update_state()
self._update_state = <bound method DeviceView._update_state of
<DeviceView object at 0x94bd43c (SugarTrayIcon at 0x9566b50)>>
94 self.palette.set_ip_address(self._model.props.ip_address)
95
/usr/share/sugar/shell/view/devices/network/wireless.py in
_update_state(self=<DeviceView object at 0x94bd43c (SugarTrayIcon at
0x9566b50)>)
114 self._logger.debug("_update_state(): %s --> %s %s"
115 % (self._state, new_state,
--> 116
self._model.get_active_network_colors()))
self._model.get_active_network_colors = <bound method
Device.get_active_network_colors of <Device object at 0x94bd02c
(model+devices+network+wireless+Device at 0x946e540)>>
117 if new_state != self._state:
118 old_color = self._state_to_color[new_state]
/usr/share/sugar/shell/model/devices/network/wireless.py in
get_active_network_colors(self=<Device object at 0x94bd02c
(model+devices+network+wireless+Device at 0x946e540)>)
103 if not net:
104 return (None, None)
--> 105 return net.get_colors()
net.get_colors = <bound method Network.get_colors of <Network
object at 0x94b0e3c (hardware+nmclient+Network at 0x946d8a0)>>
106
107
/usr/share/sugar/shell/hardware/nmclient.py in get_colors(self=<Network
object at 0x94b0e3c (hardware+nmclient+Network at 0x946d8a0)>)
152 import sha
153 sh = sha.new()
--> 154 data = self._ssid + hex(self._caps) + hex(self._mode)
data = undefined
self._ssid = None
global hex = undefined
self._caps = 0
self._mode = None
155 sh.update(data)
156 h = hash(sh.digest())
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
}}}
The below patch fixes this:
{{{
bash-3.2$ git-diff src/hardware/nmclient.py
diff --git a/src/hardware/nmclient.py b/src/hardware/nmclient.py
index 3873a83..af4824a 100644
--- a/src/hardware/nmclient.py
+++ b/src/hardware/nmclient.py
@@ -149,14 +149,17 @@ class Network(gobject.GObject):
self.emit('initialized', self._valid)
def get_colors(self):
- import sha
- sh = sha.new()
- data = self._ssid + hex(self._caps) + hex(self._mode)
- sh.update(data)
- h = hash(sh.digest())
- idx = h % len(xocolor.colors)
- # stroke, fill
- return (xocolor.colors[idx][0], xocolor.colors[idx][1])
+ if self._caps is None or self._mode is None:
+ return xocolor.XoColor()
+ else:
+ import sha
+ sh = sha.new()
+ data = self._ssid + hex(self._caps) + hex(self._mode)
+ sh.update(data)
+ h = hash(sh.digest())
+ idx = h % len(xocolor.colors)
+ # stroke, fill
+ return (xocolor.colors[idx][0], xocolor.colors[idx][1])
def get_ssid(self):
return self._ssid
}}}
--
Ticket URL: <http://dev.laptop.org/ticket/7554>
One Laptop Per Child <http://laptop.org/>
OLPC bug tracking system
More information about the Bugs
mailing list