Skip to content

Commit

Permalink
Merge pull request #1575 from geopython/MetaSearch-0.3.1
Browse files Browse the repository at this point in the history
Meta search 0.3.1
  • Loading branch information
tomkralidis committed Sep 5, 2014
2 parents 0a7ddfa + 3eb6e7c commit 86987b5
Show file tree
Hide file tree
Showing 664 changed files with 3,543 additions and 2,634 deletions.
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: MarkupSafe
Version: 0.18
Version: 0.23
Summary: Implements a XML/HTML/XHTML Markup safe string for Python
Home-page: http://github.com/mitsuhiko/markupsafe
Author: Armin Ronacher
Expand Down Expand Up @@ -29,6 +29,9 @@ Description: MarkupSafe
>>> soft_unicode(Markup('foo'))
Markup(u'foo')

HTML Representations
--------------------

Objects can customize their HTML markup equivalent by overriding
the `__html__` function:

Expand All @@ -41,6 +44,9 @@ Description: MarkupSafe
>>> 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`
Expand All @@ -58,6 +64,48 @@ Description: MarkupSafe
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
Expand Down
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: OWSLib
Version: 0.8.6
Version: 0.8.8
Summary: OGC Web Service utility library
Home-page: https://geopython.github.io/OWSLib
Author: Tom Kralidis
Expand Down Expand Up @@ -97,6 +97,18 @@ Description: OWSLib
Service for the Web (CSW), Web Processing Service (WPS), and Web
Map Tile Service (WMTS). Some of those are beta quality.


Logging
-------
OWSLib logs messages to the 'owslib' named python logger. You may
configure your application to use the log messages like so:

>>> import logging
>>> owslib_log = logging.getLogger('owslib')
>>> # Add formatting and handlers as needed
>>> owslib_log.setLevel(logging.DEBUG)


Support
-------

Expand Down
Expand Up @@ -8,6 +8,7 @@ LICENSE.txt
MANIFEST.in
README.txt
VERSION.txt
requirements-2.6.txt
requirements-dev.txt
requirements.txt
setup.cfg
Expand Down Expand Up @@ -56,6 +57,4 @@ owslib/swe/sensor/sml.py
owslib/waterml/__init__.py
owslib/waterml/wml.py
owslib/waterml/wml10.py
owslib/waterml/wml11.py
tests/__init__.py
tests/utils.py
owslib/waterml/wml11.py
@@ -1,5 +1,3 @@
../tests/utils.py
../tests/__init__.py
../owslib/sos.py
../owslib/etree.py
../owslib/wms.py
Expand Down Expand Up @@ -40,8 +38,6 @@
../owslib/swe/observation/sos200.py
../owslib/swe/observation/sos100.py
../owslib/swe/observation/__init__.py
../tests/utils.pyc
../tests/__init__.pyc
../owslib/sos.pyc
../owslib/etree.pyc
../owslib/wms.pyc
Expand Down
@@ -1,2 +1 @@
tests
owslib
82 changes: 73 additions & 9 deletions python/ext-libs/markupsafe/__init__.py
Expand Up @@ -9,8 +9,10 @@
:license: BSD, see LICENSE for more details.
"""
import re
import string
from collections import Mapping
from markupsafe._compat import text_type, string_types, int_types, \
unichr, PY2
unichr, iteritems, PY2


__all__ = ['Markup', 'soft_unicode', 'escape', 'escape_silent']
Expand Down Expand Up @@ -41,7 +43,7 @@ class Markup(text_type):
>>> class Foo(object):
... def __html__(self):
... return '<a href="#">foo</a>'
...
...
>>> Markup(Foo())
Markup(u'<a href="#">foo</a>')
Expand Down Expand Up @@ -117,7 +119,8 @@ def rsplit(self, *args, **kwargs):
rsplit.__doc__ = text_type.rsplit.__doc__

def splitlines(self, *args, **kwargs):
return list(map(self.__class__, text_type.splitlines(self, *args, **kwargs)))
return list(map(self.__class__, text_type.splitlines(
self, *args, **kwargs)))
splitlines.__doc__ = text_type.splitlines.__doc__

def unescape(self):
Expand Down Expand Up @@ -164,11 +167,11 @@ def escape(cls, s):
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__
Expand All @@ -178,7 +181,7 @@ def func(self, *args, **kwargs):
'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'):
Expand All @@ -191,13 +194,74 @@ def rpartition(self, sep):

# 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)
kwargs = _MagicFormatMapping(args, kwargs)
return self.__class__(formatter.vformat(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


class _MagicFormatMapping(Mapping):
"""This class implements a dummy wrapper to fix a bug in the Python
standard library for string formatting.
See http://bugs.python.org/issue13598 for information about why
this is necessary.
"""

def __init__(self, args, kwargs):
self._args = args
self._kwargs = kwargs
self._last_index = 0

def __getitem__(self, key):
if key == '':
idx = self._last_index
self._last_index += 1
try:
return self._args[idx]
except LookupError:
pass
key = str(idx)
return self._kwargs[key]

def __iter__(self):
return iter(self._kwargs)

def __len__(self):
return len(self._kwargs)


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):
Expand Down
2 changes: 2 additions & 0 deletions python/ext-libs/markupsafe/_compat.py
Expand Up @@ -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()
Binary file added python/ext-libs/markupsafe/_speedups.so
Binary file not shown.
57 changes: 56 additions & 1 deletion python/ext-libs/markupsafe/tests.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import gc
import sys
import unittest
from markupsafe import Markup, escape, escape_silent
from markupsafe._compat import text_type
Expand Down Expand Up @@ -42,7 +43,7 @@ def __unicode__(self):
__str__ = __unicode__
assert Markup(Foo()) == '<em>awesome</em>'
assert Markup('<strong>%s</strong>') % Foo() == \
'<strong><em>awesome</em></strong>'
'<strong><em>awesome</em></strong>'

def test_tuple_interpol(self):
self.assertEqual(Markup('<em>%s:%s</em>') % (
Expand All @@ -65,6 +66,60 @@ def test_escaping(self):
assert Markup("<em>Foo &amp; Bar</em>").striptags() == "Foo & Bar"
assert Markup("&lt;test&gt;").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, '>'), '&lt; 123 &gt;'),
(Markup('<em>{awesome}</em>').format(awesome='<awesome>'),
'<em>&lt;awesome&gt;</em>'),
(Markup('{0[1][bar]}').format([0, {'bar': '<bar/>'}]),
'&lt;bar/&gt;'),
(Markup('{0[1][bar]}').format([0, {'bar': Markup('<bar/>')}]),
'<bar/>')):
assert actual == expected, "%r should be %r!" % (actual, expected)

# This is new in 2.7
if sys.version_info >= (2, 7):
def test_formatting_empty(self):
formatted = Markup('{}').format(0)
assert formatted == Markup('0')

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__:
Expand Down
2 changes: 1 addition & 1 deletion python/ext-libs/owslib/__init__.py
@@ -1 +1 @@
__version__ = '0.8.6'
__version__ = '0.8.8'

0 comments on commit 86987b5

Please sign in to comment.