From 85488f43c3b2b0c8881ebccbccce17541f9e705d Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Wed, 22 May 2013 02:13:37 +0100 Subject: Fixed __mul__ on Python 3 --- markupsafe/__init__.py | 7 ++++--- markupsafe/_compat.py | 4 ++-- markupsafe/tests.py | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'markupsafe') diff --git a/markupsafe/__init__.py b/markupsafe/__init__.py index a6e744a..25f00d3 100644 --- a/markupsafe/__init__.py +++ b/markupsafe/__init__.py @@ -9,7 +9,8 @@ :license: BSD, see LICENSE for more details. """ import re -from markupsafe._compat import text_type, string_types, imap, unichr, PY2 +from markupsafe._compat import text_type, string_types, int_types, \ + unichr, PY2 __all__ = ['Markup', 'soft_unicode', 'escape', 'escape_silent'] @@ -85,7 +86,7 @@ class Markup(text_type): return NotImplemented def __mul__(self, num): - if isinstance(num, (int, long)): + if isinstance(num, int_types): return self.__class__(text_type.__mul__(self, num)) return NotImplemented __rmul__ = __mul__ @@ -104,7 +105,7 @@ class Markup(text_type): ) def join(self, seq): - return self.__class__(text_type.join(self, imap(self.escape, seq))) + return self.__class__(text_type.join(self, map(self.escape, seq))) join.__doc__ = text_type.join.__doc__ def split(self, *args, **kwargs): diff --git a/markupsafe/_compat.py b/markupsafe/_compat.py index 10627a6..29e4a3d 100644 --- a/markupsafe/_compat.py +++ b/markupsafe/_compat.py @@ -15,10 +15,10 @@ PY2 = sys.version_info[0] == 2 if not PY2: text_type = str string_types = (str,) - imap = map unichr = chr + int_types = (int,) else: text_type = unicode string_types = (str, unicode) - from itertools import imap unichr = unichr + int_types = (int, long) diff --git a/markupsafe/tests.py b/markupsafe/tests.py index 703cfa6..b34cc6e 100644 --- a/markupsafe/tests.py +++ b/markupsafe/tests.py @@ -89,6 +89,9 @@ class MarkupTestCase(unittest.TestCase): Markup('b') ]) + def test_mul(self): + self.assertEqual(Markup('a') * 3, Markup('aaa')) + class MarkupLeakTestCase(unittest.TestCase): -- cgit v1.2.1