Hello community, here is the log from the commit of package python-MarkupSafe for openSUSE:Factory checked in at 2014-05-10 08:32:23 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-MarkupSafe (Old) and /work/SRC/openSUSE:Factory/.python-MarkupSafe.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python-MarkupSafe" Changes: -------- --- /work/SRC/openSUSE:Factory/python-MarkupSafe/python-MarkupSafe.changes 2014-03-15 17:35:55.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.python-MarkupSafe.new/python-MarkupSafe.changes 2014-05-10 08:32:41.000000000 +0200 @@ -1,0 +2,6 @@ +Thu May 8 13:51:56 UTC 2014 - toddrme2178@gmail.com + +- Update to 0.21 + + No upstream changelog + + ------------------------------------------------------------------- Old: ---- MarkupSafe-0.19.tar.gz New: ---- MarkupSafe-0.21.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-MarkupSafe.spec ++++++ --- /var/tmp/diff_new_pack.GKIHW7/_old 2014-05-10 08:32:42.000000000 +0200 +++ /var/tmp/diff_new_pack.GKIHW7/_new 2014-05-10 08:32:42.000000000 +0200 @@ -17,7 +17,7 @@ Name: python-MarkupSafe -Version: 0.19 +Version: 0.21 Release: 0 Url: http://dev.pocoo.org/ Summary: Implements a XML/HTML/XHTML Markup safe string for Python @@ -54,6 +54,6 @@ %defattr(-,root,root,-) %doc AUTHORS LICENSE README.rst %{python_sitearch}/markupsafe/ -%{python_sitearch}/MarkupSafe-%{version}-py%{py_ver}.egg-info +%{python_sitearch}/MarkupSafe-%{version}-py*.egg-info %changelog ++++++ MarkupSafe-0.19.tar.gz -> MarkupSafe-0.21.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/MarkupSafe-0.19/MarkupSafe.egg-info/PKG-INFO new/MarkupSafe-0.21/MarkupSafe.egg-info/PKG-INFO --- old/MarkupSafe-0.19/MarkupSafe.egg-info/PKG-INFO 2014-03-06 17:52:29.000000000 +0100 +++ new/MarkupSafe-0.21/MarkupSafe.egg-info/PKG-INFO 2014-04-17 11:50:53.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: MarkupSafe -Version: 0.19 +Version: 0.21 Summary: Implements a XML/HTML/XHTML Markup safe string for Python Home-page: http://github.com/mitsuhiko/markupsafe Author: Armin Ronacher @@ -29,6 +29,9 @@ >>> soft_unicode(Markup('foo')) Markup(u'foo') + HTML Representations + -------------------- + Objects can customize their HTML markup equivalent by overriding the `__html__` function: @@ -41,6 +44,9 @@ >>> Markup(Foo()) Markup(u'<strong>Nice</strong>') + Silent Escapes + -------------- + Since MarkupSafe 0.10 there is now also a separate escape function called `escape_silent` that returns an empty string for `None` for consistency with other systems that return empty strings for `None` @@ -58,6 +64,48 @@ def escape(cls, s): return cls(escape(s)) + New-Style String Formatting + --------------------------- + + Starting with MarkupSafe 0.21 new style string formats from Python 2.6 and + 3.x are now fully supported. Previously the escape behavior of those + functions was spotty at best. The new implementations operates under the + following algorithm: + + 1. if an object has an ``__html_format__`` method it is called as + replacement for ``__format__`` with the format specifier. It either + has to return a string or markup object. + 2. if an object has an ``__html__`` method it is called. + 3. otherwise the default format system of Python kicks in and the result + is HTML escaped. + + Here is how you can implement your own formatting: + + class User(object): + + def __init__(self, id, username): + self.id = id + self.username = username + + def __html_format__(self, format_spec): + if format_spec == 'link': + return Markup('<a href="/user/{0}">{1}</a>').format( + self.id, + self.__html__(), + ) + elif format_spec: + raise ValueError('Invalid format spec') + return self.__html__() + + def __html__(self): + return Markup('<span class=user>{0}</span>').format(self.username) + + And to format that user: + + >>> user = User(1, 'foo') + >>> Markup('<p>User: {0:link}').format(user) + Markup(u'<p>User: <a href="/user/1"><span class=user>foo</span></a>') + Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Web Environment diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/MarkupSafe-0.19/PKG-INFO new/MarkupSafe-0.21/PKG-INFO --- old/MarkupSafe-0.19/PKG-INFO 2014-03-06 17:52:29.000000000 +0100 +++ new/MarkupSafe-0.21/PKG-INFO 2014-04-17 11:50:53.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: MarkupSafe -Version: 0.19 +Version: 0.21 Summary: Implements a XML/HTML/XHTML Markup safe string for Python Home-page: http://github.com/mitsuhiko/markupsafe Author: Armin Ronacher @@ -29,6 +29,9 @@ >>> soft_unicode(Markup('foo')) Markup(u'foo') + HTML Representations + -------------------- + Objects can customize their HTML markup equivalent by overriding the `__html__` function: @@ -41,6 +44,9 @@ >>> Markup(Foo()) Markup(u'<strong>Nice</strong>') + Silent Escapes + -------------- + Since MarkupSafe 0.10 there is now also a separate escape function called `escape_silent` that returns an empty string for `None` for consistency with other systems that return empty strings for `None` @@ -58,6 +64,48 @@ def escape(cls, s): return cls(escape(s)) + New-Style String Formatting + --------------------------- + + Starting with MarkupSafe 0.21 new style string formats from Python 2.6 and + 3.x are now fully supported. Previously the escape behavior of those + functions was spotty at best. The new implementations operates under the + following algorithm: + + 1. if an object has an ``__html_format__`` method it is called as + replacement for ``__format__`` with the format specifier. It either + has to return a string or markup object. + 2. if an object has an ``__html__`` method it is called. + 3. otherwise the default format system of Python kicks in and the result + is HTML escaped. + + Here is how you can implement your own formatting: + + class User(object): + + def __init__(self, id, username): + self.id = id + self.username = username + + def __html_format__(self, format_spec): + if format_spec == 'link': + return Markup('<a href="/user/{0}">{1}</a>').format( + self.id, + self.__html__(), + ) + elif format_spec: + raise ValueError('Invalid format spec') + return self.__html__() + + def __html__(self): + return Markup('<span class=user>{0}</span>').format(self.username) + + And to format that user: + + >>> user = User(1, 'foo') + >>> Markup('<p>User: {0:link}').format(user) + Markup(u'<p>User: <a href="/user/1"><span class=user>foo</span></a>') + Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Web Environment diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/MarkupSafe-0.19/README.rst new/MarkupSafe-0.21/README.rst --- old/MarkupSafe-0.19/README.rst 2013-05-20 20:25:19.000000000 +0200 +++ new/MarkupSafe-0.21/README.rst 2014-04-17 11:49:09.000000000 +0200 @@ -21,6 +21,9 @@
soft_unicode(Markup('foo')) Markup(u'foo')
+HTML Representations +-------------------- + Objects can customize their HTML markup equivalent by overriding the `__html__` function: @@ -33,6 +36,9 @@
Markup(Foo()) Markup(u'<strong>Nice</strong>')
+Silent Escapes +-------------- + Since MarkupSafe 0.10 there is now also a separate escape function called `escape_silent` that returns an empty string for `None` for consistency with other systems that return empty strings for `None` @@ -49,3 +55,45 @@ @classmethod def escape(cls, s): return cls(escape(s)) + +New-Style String Formatting +--------------------------- + +Starting with MarkupSafe 0.21 new style string formats from Python 2.6 and +3.x are now fully supported. Previously the escape behavior of those +functions was spotty at best. The new implementations operates under the +following algorithm: + +1. if an object has an ``__html_format__`` method it is called as + replacement for ``__format__`` with the format specifier. It either + has to return a string or markup object. +2. if an object has an ``__html__`` method it is called. +3. otherwise the default format system of Python kicks in and the result + is HTML escaped. + +Here is how you can implement your own formatting: + + class User(object): + + def __init__(self, id, username): + self.id = id + self.username = username + + def __html_format__(self, format_spec): + if format_spec == 'link': + return Markup('<a href="/user/{0}">{1}</a>').format( + self.id, + self.__html__(), + ) + elif format_spec: + raise ValueError('Invalid format spec') + return self.__html__() + + def __html__(self): + return Markup('<span class=user>{0}</span>').format(self.username) + +And to format that user: + +>>> user = User(1, 'foo') +>>> Markup('<p>User: {0:link}').format(user) +Markup(u'<p>User: <a href="/user/1"><span class=user>foo</span></a>') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/MarkupSafe-0.19/markupsafe/__init__.py new/MarkupSafe-0.21/markupsafe/__init__.py --- old/MarkupSafe-0.19/markupsafe/__init__.py 2013-05-22 03:13:09.000000000 +0200 +++ new/MarkupSafe-0.21/markupsafe/__init__.py 2014-04-17 11:43:10.000000000 +0200 @@ -9,8 +9,9 @@ :license: BSD, see LICENSE for more details. """ import re +import string from markupsafe._compat import text_type, string_types, int_types, \ - unichr, PY2 + unichr, iteritems, PY2 __all__ = ['Markup', 'soft_unicode', 'escape', 'escape_silent'] @@ -164,11 +165,11 @@ return cls(rv) return rv - def make_wrapper(name): + def make_simple_escaping_wrapper(name): orig = getattr(text_type, name) def func(self, *args, **kwargs): args = _escape_argspec(list(args), enumerate(args), self.escape) - #_escape_argspec(kwargs, kwargs.iteritems(), None) + _escape_argspec(kwargs, iteritems(kwargs), self.escape) return self.__class__(orig(self, *args, **kwargs)) func.__name__ = orig.__name__ func.__doc__ = orig.__doc__ @@ -178,7 +179,7 @@ 'title', 'lower', 'upper', 'replace', 'ljust', \ 'rjust', 'lstrip', 'rstrip', 'center', 'strip', \ 'translate', 'expandtabs', 'swapcase', 'zfill': - locals()[method] = make_wrapper(method) + locals()[method] = make_simple_escaping_wrapper(method) # new in python 2.5 if hasattr(text_type, 'partition'): @@ -191,13 +192,42 @@ # new in python 2.6 if hasattr(text_type, 'format'): - format = make_wrapper('format') + def format(*args, **kwargs): + self, args = args[0], args[1:] + formatter = EscapeFormatter(self.escape) + return self.__class__(formatter.format(self, *args, **kwargs)) + + def __html_format__(self, format_spec): + if format_spec: + raise ValueError('Unsupported format specification ' + 'for Markup.') + return self # not in python 3 if hasattr(text_type, '__getslice__'): - __getslice__ = make_wrapper('__getslice__') + __getslice__ = make_simple_escaping_wrapper('__getslice__') - del method, make_wrapper + del method, make_simple_escaping_wrapper + + +if hasattr(text_type, 'format'): + class EscapeFormatter(string.Formatter): + + def __init__(self, escape): + self.escape = escape + + def format_field(self, value, format_spec): + if hasattr(value, '__html_format__'): + rv = value.__html_format__(format_spec) + elif hasattr(value, '__html__'): + if format_spec: + raise ValueError('No format specification allowed ' + 'when formatting an object with ' + 'its __html__ method.') + rv = value.__html__() + else: + rv = string.Formatter.format_field(self, value, format_spec) + return text_type(self.escape(rv)) def _escape_argspec(obj, iterable, escape): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/MarkupSafe-0.19/markupsafe/_compat.py new/MarkupSafe-0.21/markupsafe/_compat.py --- old/MarkupSafe-0.19/markupsafe/_compat.py 2013-05-22 03:13:09.000000000 +0200 +++ new/MarkupSafe-0.21/markupsafe/_compat.py 2014-04-17 11:01:00.000000000 +0200 @@ -17,8 +17,10 @@ string_types = (str,) unichr = chr int_types = (int,) + iteritems = lambda x: iter(x.items()) else: text_type = unicode string_types = (str, unicode) unichr = unichr int_types = (int, long) + iteritems = lambda x: x.iteritems() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/MarkupSafe-0.19/markupsafe/tests.py new/MarkupSafe-0.21/markupsafe/tests.py --- old/MarkupSafe-0.19/markupsafe/tests.py 2013-05-22 03:13:29.000000000 +0200 +++ new/MarkupSafe-0.21/markupsafe/tests.py 2014-04-17 11:48:41.000000000 +0200 @@ -65,6 +65,54 @@ assert Markup("<em>Foo & Bar</em>").striptags() == "Foo & Bar" assert Markup("<test>").unescape() == "<test>" + def test_formatting(self): + for actual, expected in ( + (Markup('%i') % 3.14, '3'), + (Markup('%.2f') % 3.14159, '3.14'), + (Markup('%s %s %s') % ('<', 123, '>'), '< 123 >'), + (Markup('<em>{awesome}</em>').format(awesome='<awesome>'), + '<em><awesome></em>'), + (Markup('{0[1][bar]}').format([0, {'bar': '<bar/>'}]), + '<bar/>'), + (Markup('{0[1][bar]}').format([0, {'bar': Markup('<bar/>')}]), + '<bar/>')): + assert actual == expected, "%r should be %r!" % (actual, expected) + + def test_custom_formatting(self): + class HasHTMLOnly(object): + def __html__(self): + return Markup('<foo>') + + class HasHTMLAndFormat(object): + def __html__(self): + return Markup('<foo>') + def __html_format__(self, spec): + return Markup('<FORMAT>') + + assert Markup('{0}').format(HasHTMLOnly()) == Markup('<foo>') + assert Markup('{0}').format(HasHTMLAndFormat()) == Markup('<FORMAT>') + + def test_complex_custom_formatting(self): + class User(object): + def __init__(self, id, username): + self.id = id + self.username = username + def __html_format__(self, format_spec): + if format_spec == 'link': + return Markup('<a href="/user/{0}">{1}</a>').format( + self.id, + self.__html__(), + ) + elif format_spec: + raise ValueError('Invalid format spec') + return self.__html__() + def __html__(self): + return Markup('<span class=user>{0}</span>').format(self.username) + + user = User(1, 'foo') + assert Markup('<p>User: {0:link}').format(user) == \ + Markup('<p>User: <a href="/user/1"><span class=user>foo</span></a>') + def test_all_set(self): import markupsafe as markup for item in markup.__all__: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/MarkupSafe-0.19/setup.py new/MarkupSafe-0.21/setup.py --- old/MarkupSafe-0.19/setup.py 2014-03-06 17:51:40.000000000 +0100 +++ new/MarkupSafe-0.21/setup.py 2014-04-17 11:50:25.000000000 +0200 @@ -3,7 +3,7 @@ from setuptools import setup, Extension from distutils.command.build_ext import build_ext from distutils.errors import CCompilerError, DistutilsExecError, \ - DistutilsPlatformError + DistutilsPlatformError # fail safe compilation shamelessly stolen from the simplejson @@ -24,9 +24,9 @@ ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) if sys.platform == 'win32' and sys.version_info > (2, 6): - # 2.6's distutils.msvc9compiler can raise an IOError when failing to - # find the compiler - ext_errors += (IOError,) + # 2.6's distutils.msvc9compiler can raise an IOError when failing to + # find the compiler + ext_errors += (IOError,) class BuildFailed(Exception): @@ -66,7 +66,7 @@ ext_modules = [ext] if with_binary else [] setup( name='MarkupSafe', - version='0.19', + version='0.21', url='http://github.com/mitsuhiko/markupsafe', license='BSD', author='Armin Ronacher', -- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org