#32 Workaround incorrect byte encoding in Active Directory

closed-out-of-date
nobody
Interface (11)
5
2012-10-01
2008-11-07
Arno Peters
No

Retrieving information from an Active Directory causes problems.

Luma 2.3 (problem also persists in version 2.4) complains:
File "/usr/lib/luma/base/utils/gui/BrowserWidget.py", line 149, in itemClicked
self.emit(PYSIGNAL("ldap_result"), (deepcopy(result),))
File "/usr/lib/luma/base/utils/gui/AdvancedObjectWidget.py", line 136, in initView
self.displayValues()
File "/usr/lib/luma/base/utils/gui/AdvancedObjectWidget.py", line 177, in displayValues
tmpList.append(self.createAttributeString())
File "/usr/lib/luma/base/utils/gui/AdvancedObjectWidget.py", line 291, in createAttributeString
valueList = self.ldapDataObject.getAttributeValueList(x)
File "/usr/lib/luma/base/backend/SmartDataObject.py", line 183, in getAttributeValueList
tmpList.append(x.decode('utf-8'))
File "/usr/lib/python2.5/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
Reason: <type 'exceptions.UnicodeDecodeError'> 'utf8' codec can't decode byte 0x80 in position 3: unexpected code byte

To correct, apply the following patch:

diff -ru luma-2.4/lib/luma/base/backend/SmartDataObject.py luma/lib/luma/base/backend/SmartDataObject.py
--- luma-2.4/lib/luma/base/backend/SmartDataObject.py 2008-02-27 20:37:56.000000000 +0100
+++ luma/lib/luma/base/backend/SmartDataObject.py 2008-11-08 00:26:18.000000000 +0100
@@ -1,4 +1,4 @@
-# -*- coding: <utf-8> -*-
+# -*- coding: utf-8 -*-

###########################################################################
# Copyright (C) 2004, 2005 by Wido Depping
@@ -181,7 +181,10 @@
if None == x:
tmpList.append(None)
else:
- tmpList.append(x.decode('utf-8'))
+ try:
+ tmpList.append(x.decode('utf-8'))
+ except UnicodeDecodeError:
+ tmpList.append(x.decode('iso-8859-1'))
return tmpList
else:
return None

Discussion

  • Arno Peters
    Arno Peters
    2008-11-07

    The patch again

     
    Attachments
  • I just discovered ape's fix as I was about to report my proposed change. I think mine is a bit cleaner.

    diff -u -r1.1 -r1.2
    --- SmartDataObject.py 2008/12/14 21:54:53 1.1
    +++ SmartDataObject.py 2008/12/14 21:59:06 1.2
    @@ -181,7 +181,7 @@
    if None == x:
    tmpList.append(None)
    else:
    - tmpList.append(x.decode('utf-8'))
    + tmpList.append(x.decode('utf-8',"replace"))
    return tmpList
    else:
    return None

     
  • phobie
    phobie
    2012-10-01

    • status: open --> closed-out-of-date