From 1551b070b25acf02ec34f50242b5642a37ffa112 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Tue, 6 Jan 2015 12:29:06 +0100 Subject: [PATCH] Fix and test for class names containing utf-8 characters - Python 2.7 and 3.x --- demos/subst/wscript | 2 +- waflib/Task.py | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/demos/subst/wscript b/demos/subst/wscript index e0173027..ce7b8e5f 100644 --- a/demos/subst/wscript +++ b/demos/subst/wscript @@ -53,7 +53,7 @@ def build(bld): bld(features='subst', fun=hlink, source='wscript', target='wscript3') # this one is just a reminder that simple files can be created (and a test too) - #bld(rule='echo "การไฟ่" > ${TGT}', target='foo.txt') + bld(rule='echo "การไฟ่" > ${TGT}', target='foo.txt') # and this is an alternate syntax #@bld.rule(source='wscript', target='wscript2') diff --git a/waflib/Task.py b/waflib/Task.py index 423094ef..66d084c8 100644 --- a/waflib/Task.py +++ b/waflib/Task.py @@ -94,6 +94,9 @@ class store_task_type(type): # getattr(cls, 'hcode') would look in the upper classes cls.hcode = Utils.h_fun(cls.run) + if sys.hexversion > 0x3000000: + cls.hcode = cls.hcode.encode('iso8859-1', 'xmlcharrefreplace') + # be creative getattr(cls, 'register', classes)[name] = cls @@ -546,7 +549,7 @@ class Task(TaskBase): except AttributeError: pass self.m = Utils.md5() - self.m.update(self.hcode.encode()) + self.m.update(self.hcode) # explicit deps self.sig_explicit_deps() @@ -833,15 +836,9 @@ if sys.hexversion > 0x3000000: except AttributeError: m = Utils.md5() up = m.update - def encode_and_update(path): - try: - up(path.encode('iso8859-1')) - except UnicodeEncodeError as e: - Logs.error("Can't encode in iso8859-1: %s" % path) - raise e - encode_and_update(self.__class__.__name__) + up(self.__class__.__name__.encode('iso8859-1', 'xmlcharrefreplace')) for x in self.inputs + self.outputs: - encode_and_update(x.abspath()) + up(x.abspath().encode('iso8859-1', 'xmlcharrefreplace')) self.uid_ = m.digest() return self.uid_ uid.__doc__ = Task.uid.__doc__