Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/MarkupSafe-0.23-py2.7.egg-info/PKG-INFO @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
| author | bcclaywell |
|---|---|
| date | Mon, 12 Oct 2015 17:43:33 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d67268158946 |
|---|---|
| 1 Metadata-Version: 1.1 | |
| 2 Name: MarkupSafe | |
| 3 Version: 0.23 | |
| 4 Summary: Implements a XML/HTML/XHTML Markup safe string for Python | |
| 5 Home-page: http://github.com/mitsuhiko/markupsafe | |
| 6 Author: Armin Ronacher | |
| 7 Author-email: armin.ronacher@active-4.com | |
| 8 License: BSD | |
| 9 Description: MarkupSafe | |
| 10 ========== | |
| 11 | |
| 12 Implements a unicode subclass that supports HTML strings: | |
| 13 | |
| 14 >>> from markupsafe import Markup, escape | |
| 15 >>> escape("<script>alert(document.cookie);</script>") | |
| 16 Markup(u'<script>alert(document.cookie);</script>') | |
| 17 >>> tmpl = Markup("<em>%s</em>") | |
| 18 >>> tmpl % "Peter > Lustig" | |
| 19 Markup(u'<em>Peter > Lustig</em>') | |
| 20 | |
| 21 If you want to make an object unicode that is not yet unicode | |
| 22 but don't want to lose the taint information, you can use the | |
| 23 `soft_unicode` function. (On Python 3 you can also use `soft_str` which | |
| 24 is a different name for the same function). | |
| 25 | |
| 26 >>> from markupsafe import soft_unicode | |
| 27 >>> soft_unicode(42) | |
| 28 u'42' | |
| 29 >>> soft_unicode(Markup('foo')) | |
| 30 Markup(u'foo') | |
| 31 | |
| 32 HTML Representations | |
| 33 -------------------- | |
| 34 | |
| 35 Objects can customize their HTML markup equivalent by overriding | |
| 36 the `__html__` function: | |
| 37 | |
| 38 >>> class Foo(object): | |
| 39 ... def __html__(self): | |
| 40 ... return '<strong>Nice</strong>' | |
| 41 ... | |
| 42 >>> escape(Foo()) | |
| 43 Markup(u'<strong>Nice</strong>') | |
| 44 >>> Markup(Foo()) | |
| 45 Markup(u'<strong>Nice</strong>') | |
| 46 | |
| 47 Silent Escapes | |
| 48 -------------- | |
| 49 | |
| 50 Since MarkupSafe 0.10 there is now also a separate escape function | |
| 51 called `escape_silent` that returns an empty string for `None` for | |
| 52 consistency with other systems that return empty strings for `None` | |
| 53 when escaping (for instance Pylons' webhelpers). | |
| 54 | |
| 55 If you also want to use this for the escape method of the Markup | |
| 56 object, you can create your own subclass that does that:: | |
| 57 | |
| 58 from markupsafe import Markup, escape_silent as escape | |
| 59 | |
| 60 class SilentMarkup(Markup): | |
| 61 __slots__ = () | |
| 62 | |
| 63 @classmethod | |
| 64 def escape(cls, s): | |
| 65 return cls(escape(s)) | |
| 66 | |
| 67 New-Style String Formatting | |
| 68 --------------------------- | |
| 69 | |
| 70 Starting with MarkupSafe 0.21 new style string formats from Python 2.6 and | |
| 71 3.x are now fully supported. Previously the escape behavior of those | |
| 72 functions was spotty at best. The new implementations operates under the | |
| 73 following algorithm: | |
| 74 | |
| 75 1. if an object has an ``__html_format__`` method it is called as | |
| 76 replacement for ``__format__`` with the format specifier. It either | |
| 77 has to return a string or markup object. | |
| 78 2. if an object has an ``__html__`` method it is called. | |
| 79 3. otherwise the default format system of Python kicks in and the result | |
| 80 is HTML escaped. | |
| 81 | |
| 82 Here is how you can implement your own formatting:: | |
| 83 | |
| 84 class User(object): | |
| 85 | |
| 86 def __init__(self, id, username): | |
| 87 self.id = id | |
| 88 self.username = username | |
| 89 | |
| 90 def __html_format__(self, format_spec): | |
| 91 if format_spec == 'link': | |
| 92 return Markup('<a href="/user/{0}">{1}</a>').format( | |
| 93 self.id, | |
| 94 self.__html__(), | |
| 95 ) | |
| 96 elif format_spec: | |
| 97 raise ValueError('Invalid format spec') | |
| 98 return self.__html__() | |
| 99 | |
| 100 def __html__(self): | |
| 101 return Markup('<span class=user>{0}</span>').format(self.username) | |
| 102 | |
| 103 And to format that user: | |
| 104 | |
| 105 >>> user = User(1, 'foo') | |
| 106 >>> Markup('<p>User: {0:link}').format(user) | |
| 107 Markup(u'<p>User: <a href="/user/1"><span class=user>foo</span></a>') | |
| 108 | |
| 109 Platform: UNKNOWN | |
| 110 Classifier: Development Status :: 5 - Production/Stable | |
| 111 Classifier: Environment :: Web Environment | |
| 112 Classifier: Intended Audience :: Developers | |
| 113 Classifier: License :: OSI Approved :: BSD License | |
| 114 Classifier: Operating System :: OS Independent | |
| 115 Classifier: Programming Language :: Python | |
| 116 Classifier: Programming Language :: Python :: 3 | |
| 117 Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content | |
| 118 Classifier: Topic :: Software Development :: Libraries :: Python Modules | |
| 119 Classifier: Topic :: Text Processing :: Markup :: HTML |
