sugarlabs / sugar

Sugar GTK shell
GNU General Public License v3.0
252 stars 240 forks source link

unicode error due to python3 port in network.py #899

Closed bhulsken closed 4 years ago

bhulsken commented 4 years ago

ssid is bytes and not string, giving errors in network.py

  File "/usr/lib/python3.7/site-packages/jarabe/desktop/meshbox.py", line 495, in _ap_props_changed_cb
    network.is_sugar_adhoc_network(ap.ssid) and \
  File "/usr/lib/python3.7/site-packages/jarabe/model/network.py", line 367, in is_sugar_adhoc_network
    return ssid.startswith('Ad-hoc Network')
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

according to the standard the SSID should be a UTF-8 coded sting. So prefixing b to the string literal should work in both python2 and 3, and be according to the standard (see https://en.wikipedia.org/wiki/Service_set_(802.11_network))

same problem in adhoc.py

the below patch fixes the issue for me,

best regards, Bas Hulsken

--- sugar/src/jarabe/model/adhoc.py     2019-10-14 13:28:28.326142372 +0200
+++ sugar-fix/src/jarabe/model/adhoc.py 2020-01-10 11:19:24.400883809 +0100
@@ -251,13 +251,13 @@ class AdHocManager(GObject.GObject):
         access_point -- Access Point

         """
-        if access_point.ssid.endswith(' 1'):
+        if access_point.ssid.endswith(b" 1"):
             self._networks[self._CHANNEL_1] = access_point
             self.emit('members-changed', self._CHANNEL_1, True)
-        elif access_point.ssid.endswith(' 6'):
+        elif access_point.ssid.endswith(b" 6"):
             self._networks[self._CHANNEL_6] = access_point
             self.emit('members-changed', self._CHANNEL_6, True)
-        elif access_point.ssid.endswith('11'):
+        elif access_point.ssid.endswith(b"11"):
             self._networks[self._CHANNEL_11] = access_point
             self.emit('members-changed', self._CHANNEL_11, True)
--- sugar/src/jarabe/model/network.py   2019-09-07 16:44:09.062479965 +0200
+++ sugar-fix/src/jarabe/model/network.py       2020-01-10 10:43:44.497237307 +0100
@@ -364,7 +364,7 @@ def is_sugar_adhoc_network(ssid):
     Return: Boolean

     """
-    return ssid.startswith('Ad-hoc Network')
+    return ssid.startswith(b"Ad-hoc Network")

 class WirelessSecurity(object):
quozl commented 4 years ago

Thanks for testing. I expect to get to this next week or the week after.

It looks like this was a Port to Python 3 regression as our porters did not test on actual hardware. Since their work was merged, I've tested with infrastructure networks, but not yet with IBSS or pluggable ethernet.

Also, feel free to make a pull request in future, as that will save copy and paste errors.

namannimmo10 commented 4 years ago

Hey @quozl, should I raise a PR? I've never contributed to sugarlabs before.

bhulsken commented 4 years ago

Sure, just created a pull request for this one as well: #901

quozl commented 4 years ago

https://github.com/sugarlabs/sugar/commit/e9b033eae09adbca5ef3b159dbe6249f68fcfcd5

quozl commented 4 years ago

@namannimmo10, thanks for asking. You could have tested the change if you had a computer you could run Sugar on. But if you've never contributed before, you would have found it difficult.

namannimmo10 commented 4 years ago

I have sugar installed on my computer. I have contributed to open source projects before so It wouldn't have been that much difficult. @quozl Is there any other task I could help you with? Apart from porting code to python 3 or gtk+3. Because it seems like almost everyone is working on those tasks.

quozl commented 4 years ago

Many of them have just stopped working on them in the past day, because Google Code-in has finished. I've no specific task in mind for you. http://lists.sugarlabs.org/archive/sugar-devel/2020-January/057643.html near the end of the message is my general recommendation for choosing what to work on.

namannimmo10 commented 4 years ago

Thank you, I will look into it.