Ticket #1604: 0002-Truncate-ad-hoc-network-name-to-not-exceed-the-SSID.patch

File 0002-Truncate-ad-hoc-network-name-to-not-exceed-the-SSID.patch, 1.8 KB (added by dsd, 14 years ago)
  • extensions/deviceicon/network.py

    From f1fcf461752f164b6f697dcf86c86c7ddde644bf Mon Sep 17 00:00:00 2001
    From: Daniel Drake <dsd@laptop.org>
    Date: Fri, 4 Dec 2009 17:07:55 +0000
    Subject: [PATCH 2/2] Truncate ad-hoc network name to not exceed the SSID limit (#1604)
    
    Fixes breakage where you could not create an ad-hoc network if your
    sugar name is long.
    ---
     extensions/deviceicon/network.py |   19 +++++++++++++++++--
     1 files changed, 17 insertions(+), 2 deletions(-)
    
    diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
    index 75bc467..fd5c9b1 100644
    a b import logging 
    2121import hashlib
    2222import socket
    2323import struct
     24import re
    2425
    2526import gtk
    2627import gobject
    class WirelessDeviceView(ToolButton): 
    398399
    399400    def __create_connection_cb(self, palette, data=None):
    400401        client = gconf.client_get_default()
    401         nick = client.get_string('/desktop/sugar/user/nick')
    402         connection_name = _('%s\'s network') % nick
     402        nick = client.get_string('/desktop/sugar/user/nick').decode('utf-8')
     403
     404        # there is a 32 character SSID limit, and we use some of that with
     405        # our "'s network"  label. truncate the name accordingly, being careful
     406        # not to truncate in the middle of multi-byte characters
     407
     408        fmt = _('%s\'s network').encode('utf-8')
     409        extra_len = len(fmt) - len('%s')
     410        name_limit = 32 - extra_len
     411
     412        # truncate the nick and use a regex to drop any partial characters
     413        # at the end
     414        nick = nick.encode('utf-8')[:name_limit]
     415        nick = re.sub("([\xf6-\xf7][\x80-\xbf]{0,2}|[\xe0-\xef][\x80-\xbf]{0,1}|[\xc0-\xdf])$", '', nick)
     416
     417        connection_name = fmt % nick
    403418
    404419        connection = network.find_connection(connection_name)
    405420        if connection is None: