From 24d2a1eb4d673bb3209efe04c3fc4f274dc9e59a Mon Sep 17 00:00:00 2001 From: David Grant Date: Sat, 19 Jul 2014 20:54:19 -0700 Subject: [PATCH] trying to fix syntax errors in python 3.2 --- markupsafe/__init__.py | 23 ++++++++++++----------- markupsafe/tests.py | 13 +++++++------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/markupsafe/__init__.py b/markupsafe/__init__.py index 27554015..48c70116 100644 --- a/markupsafe/__init__.py +++ b/markupsafe/__init__.py @@ -8,6 +8,7 @@ :copyright: (c) 2010 by Armin Ronacher. :license: BSD, see LICENSE for more details. """ +from __future__ import unicode_literals import re import string from collections import Mapping @@ -39,35 +40,35 @@ class Markup(text_type): converted into a unicode string and then assumed to be safe: >>> Markup("Hello World!") - Markup(u'Hello World!') + Markup('Hello World!') >>> class Foo(object): ... def __html__(self): ... return 'foo' ... >>> Markup(Foo()) - Markup(u'foo') + Markup('foo') If you want object passed being always treated as unsafe you can use the :meth:`escape` classmethod to create a :class:`Markup` object: >>> Markup.escape("Hello World!") - Markup(u'Hello <em>World</em>!') + Markup('Hello <em>World</em>!') Operations on a markup string are markup aware which means that all arguments are passed through the :func:`escape` function: >>> em = Markup("%s") >>> em % "foo & bar" - Markup(u'foo & bar') + Markup('foo & bar') >>> strong = Markup("%(text)s") >>> strong % {'text': 'hacker here'} - Markup(u'<blink>hacker here</blink>') + Markup('<blink>hacker here</blink>') >>> Markup("Hello ") + "" - Markup(u'Hello <foo>') + Markup('Hello <foo>') """ __slots__ = () - def __new__(cls, base=u'', encoding=None, errors='strict'): + def __new__(cls, base='', encoding=None, errors='strict'): if hasattr(base, '__html__'): base = base.__html__() if encoding is None: @@ -128,7 +129,7 @@ def unescape(self): known HTML4 and XHTML entities: >>> Markup("Main » About").unescape() - u'Main \xbb About' + 'Main \xbb About' """ from markupsafe._constants import HTML_ENTITIES def handle_match(m): @@ -142,7 +143,7 @@ def handle_match(m): return unichr(int(name[1:])) except ValueError: pass - return u'' + return '' return _entity_re.sub(handle_match, text_type(self)) def striptags(self): @@ -151,9 +152,9 @@ def striptags(self): normalized to one: >>> Markup("Main » About").striptags() - u'Main \xbb About' + 'Main \xbb About' """ - stripped = u' '.join(_striptags_re.sub('', self).split()) + stripped = ' '.join(_striptags_re.sub('', self).split()) return Markup(stripped).unescape() @classmethod diff --git a/markupsafe/tests.py b/markupsafe/tests.py index 63699362..946d1abc 100644 --- a/markupsafe/tests.py +++ b/markupsafe/tests.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import gc import sys import unittest @@ -49,16 +50,16 @@ def test_tuple_interpol(self): self.assertEqual(Markup('%s:%s') % ( '', '', - ), Markup(u'<foo>:<bar>')) + ), Markup('<foo>:<bar>')) def test_dict_interpol(self): self.assertEqual(Markup('%(foo)s') % { 'foo': '', - }, Markup(u'<foo>')) + }, Markup('<foo>')) self.assertEqual(Markup('%(foo)s:%(bar)s') % { 'foo': '', 'bar': '', - }, Markup(u'<foo>:<bar>')) + }, Markup('<foo>:<bar>')) def test_escaping(self): # escaping and unescaping @@ -128,7 +129,7 @@ def test_all_set(self): def test_escape_silent(self): assert escape_silent(None) == Markup() assert escape(None) == Markup(None) - assert escape_silent('') == Markup(u'<foo>') + assert escape_silent('') == Markup('<foo>') def test_splitting(self): self.assertEqual(Markup('a b').split(), [ @@ -156,8 +157,8 @@ def test_markup_leaks(self): for item in range(1000): escape("foo") escape("") - escape(u"foo") - escape(u"") + escape("foo") + escape("") counts.add(len(gc.get_objects())) assert len(counts) == 1, 'ouch, c extension seems to leak objects'