From 1f1c4c0e61bbd91dd9e735b4fb8e84578bc0ac7d Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 24 Mar 2011 20:04:20 +0000 Subject: [PATCH] better update related to the last commit --- lib/core/common.py | 11 +++++++++++ lib/core/dump.py | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index b2b645b54..d1ad4c2c6 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -22,6 +22,7 @@ import ntpath import posixpath import httplib import struct +import unicodedata from ConfigParser import DEFAULTSECT from ConfigParser import RawConfigParser @@ -2431,3 +2432,13 @@ def removeReflectiveValues(content, payload): logger.debug(debugMsg) return retVal + +def normalizeUnicode(value): + """ + Does an ASCII normalization of unicode strings + Reference: http://www.peterbe.com/plog/unicode-to-ascii + """ + retVal = value + if isinstance(value, unicode): + retVal = unicodedata.normalize('NFKD', value).encode('ascii','ignore') + return retVal diff --git a/lib/core/dump.py b/lib/core/dump.py index d53e206a1..51388d853 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -15,6 +15,7 @@ from lib.core.common import Backend from lib.core.common import dataToDumpFile from lib.core.common import dataToStdout from lib.core.common import getUnicode +from lib.core.common import normalizeUnicode from lib.core.common import openFile from lib.core.common import restoreDumpMarkedChars from lib.core.data import conf @@ -159,7 +160,7 @@ class Dump: if isinstance(table, (list, tuple, set)): table = table[0] - maxlength = max(maxlength, len(getUnicode(table))) + maxlength = max(maxlength, len(normalizeUnicode(table))) lines = "-" * (int(maxlength) + 2) @@ -179,7 +180,7 @@ class Dump: if isinstance(table, (list, tuple, set)): table = table[0] - blank = " " * (maxlength - len(getUnicode(table))) + blank = " " * (maxlength - len(normalizeUnicode(table))) self.__write("| %s%s |" % (table, blank)) self.__write("+%s+\n" % lines)