# HG changeset patch # User borax # Date 1250204539 -7200 # Node ID 89da289790ea4ce5e66e3019b3532f0baeb84a6c # Parent e8b56275875336359b017a26b28dfe0a23de20d8 New \"spaces\" parameter in function \"unicode.translateString\" allows to specify a replacement string for spaces still present in converted result diff -r e8b562758753 -r 89da289790ea ztfy/utils/doctests/README.txt --- a/ztfy/utils/doctests/README.txt Thu Aug 13 19:59:05 2009 +0200 +++ b/ztfy/utils/doctests/README.txt Fri Aug 14 01:02:19 2009 +0200 @@ -45,6 +45,21 @@ >>> unicode.translateString(sample, escapeSlashes=True) u'test.txt' +To remove remaining spaces or convert them to another character, you can use the "spaces" parameter +which can contain any string to be used instead of initial spaces: + + >>> sample = 'C:\\Program Files\\My Application\\test.txt' + >>> unicode.translateString(sample, spaces=' ') + u'cprogram filesmy applicationtest.txt' + >>> unicode.translateString(sample, spaces='-') + u'cprogram-filesmy-applicationtest.txt' + +Spaces replacement is made in the last step, so using it with "escapeSlashes" parameter only affects +the final result: + + >>> unicode.translateString(sample, escapeSlashes=True, spaces='-') + u'test.txt' + Dates functions --------------- diff -r e8b562758753 -r 89da289790ea ztfy/utils/unicode.py --- a/ztfy/utils/unicode.py Thu Aug 13 19:59:05 2009 +0200 +++ b/ztfy/utils/unicode.py Fri Aug 14 01:02:19 2009 +0200 @@ -82,7 +82,7 @@ _fillUnicodeTransTable() -def translateString(s, escapeSlashes=False, forceLower=True) : +def translateString(s, escapeSlashes=False, forceLower=True, spaces=' ') : """Remove extended characters from string and replace them with 'basic' ones @param s: text to be cleaned. @@ -103,6 +103,8 @@ s = ''.join([a for a in s.translate(_unicodeTransTable) if a.replace(' ','-') in (string.ascii_letters + string.digits + '_-.')]) if forceLower: s = s.lower() + if spaces != ' ': + s = s.replace(' ', spaces) return s