Tres Seaver
2013-04-26 1d7c1956bf6a25448a58e6fdc531fde0703cbbf6
Parse INI-file configuration using SafeConfigParser.

Allows escaping the ``'%'`` so that e.g. a query template using for a DB-API
connection using ``pyformat`` preserves the template.
5 files modified
27 ■■■■ changed files
CHANGES.rst 4 ●●●● patch | view | raw | blame | history
docs/configuration.rst 10 ●●●● patch | view | raw | blame | history
repoze/who/_compat.py 4 ●●●● patch | view | raw | blame | history
repoze/who/config.py 4 ●●●● patch | view | raw | blame | history
repoze/who/tests/test_config.py 5 ●●●●● patch | view | raw | blame | history
CHANGES.rst
@@ -4,6 +4,10 @@
2.2 (unreleased)
----------------
- Parse INI-file configuration using ``SafeConfigParser``:  allows
  escaping the ``'%'`` so that e.g. a query template using for a DB-API
  connection using ``pyformat`` preserves the template.
- Added support for Python 3.3, PyPy.
docs/configuration.rst
@@ -230,14 +230,20 @@
    [plugin:sqlusers]
    # authentication
    use = repoze.who.plugins.sql:make_authenticator_plugin
    query = "SELECT userid, password FROM users where login = %(login)s;"
    # Note the double %%:  we have to escape it from the config parser in
    # order to preserve it as a template for the psycopg2, whose 'paramstyle'
    # is 'pyformat'.
    query = SELECT userid, password FROM users where login = %%(login)s
    conn_factory = repoze.who.plugins.sql:make_psycopg_conn_factory
    compare_fn = repoze.who.plugins.sql:default_password_compare
    [plugin:sqlproperties]
    name = properties
    use = repoze.who.plugins.sql:make_metadata_plugin
    query = "SELECT firstname, lastname FROM users where userid = %(__userid)s;"
    # Note the double %%:  we have to escape it from the config parser in
    # order to preserve it as a template for the psycopg2, whose 'paramstyle'
    # is 'pyformat'.
    query = SELECT firstname, lastname FROM users where userid = %%(__userid)s
    filter = my.package:filter_propmd
    conn_factory = repoze.who.plugins.sql:make_psycopg_conn_factory
repoze/who/_compat.py
@@ -34,9 +34,9 @@
    from urllib.parse import parse_qsl
try:
    from ConfigParser import ConfigParser
    from ConfigParser import SafeConfigParser
except ImportError: #pragma NO COVER Python >= 3.0
    from configparser import ConfigParser
    from configparser import SafeConfigParser
    from configparser import ParsingError
else: #pragma NO COVER Python < 3.0
    from ConfigParser import ParsingError
repoze/who/config.py
@@ -15,7 +15,7 @@
from repoze.who.interfaces import IRequestClassifier
from repoze.who.middleware import PluggableAuthenticationMiddleware
from repoze.who._compat import StringIO
from repoze.who._compat import ConfigParser
from repoze.who._compat import SafeConfigParser
from repoze.who._compat import ParsingError
def _resolve(name):
@@ -71,7 +71,7 @@
    def parse(self, text):
        if getattr(text, 'readline', None) is None:
            text = StringIO(text)
        cp = ConfigParser(defaults={'here': self.here})
        cp = SafeConfigParser(defaults={'here': self.here})
        try:
            cp.read_file(text)
        except AttributeError: #pragma NO COVER Python < 3.0
repoze/who/tests/test_config.py
@@ -230,6 +230,9 @@
        self.failUnless(isinstance(foo, DummyPlugin))
        self.assertEqual(foo.iface, 'iface')
        self.assertEqual(foo.name, 'name')
        self.assertEqual(foo.template, '%(template)s')
        self.assertEqual(foo.template_with_eq,
                         'template_with_eq = %(template_with_eq)s')
class DummyPlugin:
    def __init__(self, **kw):
@@ -348,6 +351,8 @@
use = repoze.who.tests.test_config:DummyPlugin
name = name
iface = iface
template = %%(template)s
template_with_eq = template_with_eq = %%(template_with_eq)s
"""
class TestConfigMiddleware(_Base):