Revision: 3664
Author: pekka.klarck
Date: Sat May 29 14:09:53 2010
Log: Cleanup. Also notized that importing unicodedata on Jython takes ages
(7s on my machine). Wonder could we run normalize only on Python?
http://code.google.com/p/robotframework/source/detail?r=3664
Modified:
/trunk/src/robot/utils/unic.py
=======================================
--- /trunk/src/robot/utils/unic.py Fri May 28 04:23:30 2010
+++ /trunk/src/robot/utils/unic.py Sat May 29 14:09:53 2010
@@ -13,17 +13,17 @@
# limitations under the License.
import sys
-import unicodedata
+
+try:
+ from unicodedata import normalize
+except ImportError: # Jython on Java 1.5 lacks this method
+ normalize = lambda form, unistr: unistr
def unic(item, *args):
# Based on a recipe from http://code.activestate.com/recipes/466341
try:
- # in jython with java 1.5 unicodedata does not have the
normalize-method
- if hasattr(unicodedata, 'normalize'):
- return unicodedata.normalize('NFC', unicode(item, *args))
- else:
- return unicode(item, *args)
+ return normalize('NFC', unicode(item, *args))
except UnicodeError:
try:
ascii_text = str(item).encode('string_escape')