changeset 2496:d9e112066a9e

Merge 1.7.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 22 Jul 2007 04:17:59 +0200
parents b9e0a8a1f14c (current diff) 01f2921e5fa4 (diff)
children 09afb8020b20
files
diffstat 8 files changed, 194 insertions(+), 209 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Sun Jul 22 04:17:31 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Sun Jul 22 04:17:59 2007 +0200
@@ -2,12 +2,13 @@
 """
     MoinMoin - MoinMoin.wikiutil Tests
 
-    @copyright: 2003-2004 by Juergen Hermann <jh@web.de>
+    @copyright: 2003-2004 by Juergen Hermann <jh@web.de>,
+                2007 by MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
 import py
-import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
+
 from MoinMoin import wikiutil
 
 
@@ -111,7 +112,7 @@
     def testSystemPagesGroupNotEmpty(self):
         assert self.request.dicts.members('SystemPagesGroup')
 
-class TestSystemPage(unittest.TestCase):
+class TestSystemPage:
     systemPages = (
         # First level, on SystemPagesGroup
         'SystemPagesInEnglishGroup',
@@ -126,14 +127,12 @@
     def testSystemPage(self):
         """wikiutil: good system page names accepted, bad rejected"""
         for name in self.systemPages:
-            self.assert_(wikiutil.isSystemPage(self.request, name),
-                '"%(name)s" is a system page' % locals())
+            assert wikiutil.isSystemPage(self.request, name)
         for name in self.notSystemPages:
-            self.failIf(wikiutil.isSystemPage(self.request, name),
-                '"%(name)s" is NOT a system page' % locals())
+            assert not  wikiutil.isSystemPage(self.request, name)
 
 
-class TestTemplatePage(unittest.TestCase):
+class TestTemplatePage:
     good = (
         'aTemplate',
         'MyTemplate',
@@ -146,55 +145,93 @@
         'XTemplateInFront',
     )
 
-    # require default page_template_regex config
-    def setUp(self):
-        self.config = self.TestConfig(defaults=['page_template_regex'])
-    def tearDown(self):
-        self.config.restore()
-
     def testTemplatePage(self):
         """wikiutil: good template names accepted, bad rejected"""
         for name in self.good:
-            self.assert_(wikiutil.isTemplatePage(self.request, name),
-                '"%(name)s" is a valid template name' % locals())
+            assert  wikiutil.isTemplatePage(self.request, name)
         for name in self.bad:
-            self.failIf(wikiutil.isTemplatePage(self.request, name),
-                '"%(name)s" is NOT a valid template name' % locals())
+            assert not wikiutil.isTemplatePage(self.request, name)
 
 
-class TestParmeterParser(unittest.TestCase):
-
-    def testNoWantedArguments(self):
-        args = ''
-        argParser = wikiutil.ParameterParser('')
-        self.arg_list, self.arg_dict = argParser.parse_parameters(args)
-        result = len(self.arg_dict)
-        expected = 0
-        self.assert_(result == expected,
-                     'Expected "%(expected)s" but got "%(result)s"' % locals())
+class TestParmeterParser:
 
-    def testWantedArguments(self):
-        test_args = ('',
-                     'width=100',
-                     'width=100, height=200', )
+    def testParameterParser(self):
+        tests = [
+            # trivial
+            ('', '', 0, {}),
 
-        argParser = wikiutil.ParameterParser("%(width)s%(height)s")
-        for args in test_args:
-            self.arg_list, self.arg_dict = argParser.parse_parameters(args)
-            result = len(self.arg_dict)
-            expected = 2
-            self.assert_(result == expected,
-                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+            # fixed
+            ('%s%i%f%b', '"test",42,23.0,True', 4, {0: 'test', 1: 42, 2: 23.0, 3: True}),
+
+            # fixed and named
+            ('%s%(x)i%(y)i', '"test"', 1, {0: 'test', 'x': None, 'y': None}),
+            ('%s%(x)i%(y)i', '"test",1', 1, {0: 'test', 'x': 1, 'y': None}),
+            ('%s%(x)i%(y)i', '"test",1,2', 1, {0: 'test', 'x': 1, 'y': 2}),
+            ('%s%(x)i%(y)i', '"test",x=1', 1, {0: 'test', 'x': 1, 'y': None}),
+            ('%s%(x)i%(y)i', '"test",x=1,y=2', 1, {0: 'test', 'x': 1, 'y': 2}),
+            ('%s%(x)i%(y)i', '"test",y=2', 1, {0: 'test', 'x': None, 'y': 2}),
+
+            # test mixed acceptance
+            ("%ifs", '100', 1, {0: 100}),
+            ("%ifs", '100.0', 1, {0: 100.0}),
+            ("%ifs", '"100"', 1, {0: "100"}),
+
+            # boolean
+            ("%(t)b%(f)b", '', 0, {'t': None, 'f': None}),
+            ("%(t)b%(f)b", 't=1', 0, {'t': True, 'f': None}),
+            ("%(t)b%(f)b", 'f=False', 0, {'t': None, 'f': False}),
+            ("%(t)b%(f)b", 't=True, f=0', 0, {'t': True, 'f': False}),
+
+            # integer
+            ("%(width)i%(height)i", '', 0, {'width': None, 'height': None}),
+            ("%(width)i%(height)i", 'width=100', 0, {'width': 100, 'height': None}),
+            ("%(width)i%(height)i", 'height=200', 0, {'width': None, 'height': 200}),
+            ("%(width)i%(height)i", 'width=100, height=200', 0, {'width': 100, 'height': 200}),
+
+            # float
+            ("%(width)f%(height)f", '', 0, {'width': None, 'height': None}),
+            ("%(width)f%(height)f", 'width=100.0', 0, {'width': 100.0, 'height': None}),
+            ("%(width)f%(height)f", 'height=2.0E2', 0, {'width': None, 'height': 200.0}),
+            ("%(width)f%(height)f", 'width=1000.0E-1, height=200.0', 0, {'width': 100.0, 'height': 200.0}),
+
+            # string
+            ("%(width)s%(height)s", '', 0, {'width': None, 'height': None}),
+            ("%(width)s%(height)s", 'width="really wide"', 0, {'width': 'really wide', 'height': None}),
+            ("%(width)s%(height)s", 'height="not too high"', 0, {'width': None, 'height': 'not too high'}),
+            ("%(width)s%(height)s", 'width="really wide", height="not too high"', 0, {'width': 'really wide', 'height': 'not too high'}),
+            # conversion from given type to expected type
+            ("%(width)s%(height)s", 'width=100', 0, {'width': '100', 'height': None}),
+            ("%(width)s%(height)s", 'width=100, height=200', 0, {'width': '100', 'height': '200'}),
+
+            # complex test
+            ("%i%sf%s%ifs%(a)s|%(b)s", ' 4,"DI\'NG", b=retry, a="DING"', 2, {0: 4, 1: "DI'NG", 'a': 'DING', 'b': 'retry'}),
+
+            ]
+        for format, args, expected_fixed_count, expected_dict in tests:
+            argParser = wikiutil.ParameterParser(format)
+            fixed_count, arg_dict = argParser.parse_parameters(args)
+            assert (fixed_count, arg_dict) == (expected_fixed_count, expected_dict)
 
     def testTooMuchWantedArguments(self):
-        py.test.skip("fails because of unfinished wikiutil.ParameterParser code crashing")
         args = 'width=100, height=200, alt=Example'
         argParser = wikiutil.ParameterParser("%(width)s%(height)s")
-        self.arg_list, self.arg_dict = argParser.parse_parameters(args)
-        result = len(self.arg_dict)
-        expected = 2
-        self.assert_(result == expected,
-                     'Expected "%(expected)s" but got "%(result)s"' % locals())
+        py.test.raises(ValueError, argParser.parse_parameters, args)
+
+    def testMalformedArguments(self):
+        args = '='
+        argParser = wikiutil.ParameterParser("%(width)s%(height)s")
+        py.test.raises(ValueError, argParser.parse_parameters, args)
+
+    def testWrongTypeFixedPosArgument(self):
+        args = '0.0'
+        argParser = wikiutil.ParameterParser("%b")
+        py.test.raises(ValueError, argParser.parse_parameters, args)
+
+    def testWrongTypeNamedArgument(self):
+        args = 'flag=0.0'
+        argParser = wikiutil.ParameterParser("%(flag)b")
+        py.test.raises(ValueError, argParser.parse_parameters, args)
+
 
 coverage_modules = ['MoinMoin.wikiutil']
 
--- a/MoinMoin/macro/Hits.py	Sun Jul 22 04:17:31 2007 +0200
+++ b/MoinMoin/macro/Hits.py	Sun Jul 22 04:17:59 2007 +0200
@@ -10,10 +10,11 @@
         all: if set to 1 then cummulative hits over all wiki pages is returned. Default is 0
         filter: if set to SAVEPAGE then the saved pages are counted. Default is VIEWPAGE.
 
-   @copyright: 2004-2007 MoinMoin:ReimarBauer
+   @copyright: 2004-2007 MoinMoin:ReimarBauer,
                2005 BenjaminVrolijk
    @license: GNU GPL, see COPYING for details.
 """
+
 Dependencies = ['time'] # do not cache
 
 from MoinMoin import wikiutil
@@ -21,39 +22,38 @@
 
 class Hits:
     def __init__(self, macro, args):
-        self.macro = macro
         self.request = macro.request
         self.formatter = macro.formatter
+        self.this_page = macro.formatter.page.page_name
         argParser = wikiutil.ParameterParser("%(all)s%(filter)s")
         try:
-            self.arg_list, self.arg_dict = argParser.parse_parameters(args)
-        except ValueError:
-            # TODO Set defaults until raise in ParameterParser.parse_parameters is changed
-            self.arg_dict = {}
-            self.arg_dict["filter"] = None
-            self.arg_dict["all"] = 0
-
-        self.count = 0
+            self.fixed_count, self.arg_dict = argParser.parse_parameters(args)
+            self.error = None
+        except ValueError, err:
+            self.error = str(err)
 
     def renderInText(self):
-        return self.formatter.text("%s" % (self.getHits()))
+        if self.error:
+            text = "Hits macro: %s" % self.error
+        else:
+            text = "%d" % self.getHits()
+        return self.formatter.text(text)
 
     def getHits(self):
-        formatter = self.macro.formatter
-        kw = self.arg_dict
-        if not kw["filter"]: kw["filter"] = "VIEWPAGE"
+        event_filter = self.arg_dict["filter"]
+        if not event_filter:
+            event_filter = "VIEWPAGE"
+        count_all_pages = self.arg_dict["all"]
 
         event_log = eventlog.EventLog(self.request)
-        event_log.set_filter([kw["filter"]])
+        event_log.set_filter([event_filter])
+        count = 0
         for event in event_log.reverse():
-            pagename = event[2].get('pagename', None)
-            if not kw["all"]:
-                if pagename == formatter.page.page_name:
-                    self.count += 1
-            else:
-                self.count += 1
+            pagename = event[2].get('pagename')
+            if count_all_pages or pagename == self.this_page:
+                count += 1
 
-        return self.count
+        return count
 
 def execute(macro, args):
     """ Temporary glue code to use with moin current macro system """
--- a/MoinMoin/macro/_tests/test_macro.py	Sun Jul 22 04:17:31 2007 +0200
+++ b/MoinMoin/macro/_tests/test_macro.py	Sun Jul 22 04:17:59 2007 +0200
@@ -7,21 +7,18 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
-
 from MoinMoin import macro
 from MoinMoin.parser.text import Parser
 from MoinMoin.formatter.text_html import Formatter
 
 
-class TestMacro(unittest.TestCase):
+class TestMacro:
     def testTrivialMacro(self):
         """macro: trivial macro works"""
         m = self._make_macro()
         expected = m.formatter.linebreak(0)
         result = m.execute("BR", "")
-        self.assertEqual(result, expected,
-            'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert result == expected
 
     def _make_macro(self):
         """Test helper"""
--- a/MoinMoin/mail/_tests/test_sendmail.py	Sun Jul 22 04:17:31 2007 +0200
+++ b/MoinMoin/mail/_tests/test_sendmail.py	Sun Jul 22 04:17:59 2007 +0200
@@ -6,14 +6,13 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from email.Charset import Charset, QP
 from email.Header import Header
 from MoinMoin.mail import sendmail
 from MoinMoin import config
 
 
-class TestdecodeSpamSafeEmail(unittest.TestCase):
+class TestdecodeSpamSafeEmail:
     """mail.sendmail: testing mail"""
 
     _tests = (
@@ -39,13 +38,10 @@
     def testDecodeSpamSafeMail(self):
         """mail.sendmail: decoding spam safe mail"""
         for coded, expected in self._tests:
-            result = sendmail.decodeSpamSafeEmail(coded)
-            self.assertEqual(result, expected,
-                             'Expected "%(expected)s" but got "%(result)s"' %
-                             locals())
+            assert sendmail.decodeSpamSafeEmail(coded) == expected
 
 
-class TestEncodeAddress(unittest.TestCase):
+class TestEncodeAddress:
     """ Address encoding tests
 
     See http://www.faqs.org/rfcs/rfc2822.html section 3.4.
@@ -63,31 +59,27 @@
         """ mail.sendmail: encode simple address: local@domain """
         address = u'local@domain'
         expected = address.encode(config.charset)
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testComposite(self):
         """ mail.sendmail: encode address: 'Phrase <local@domain>' """
         address = u'Phrase <local@domain>'
         phrase = str(Header(u'Phrase '.encode('utf-8'), self.charset))
         expected = phrase + '<local@domain>'
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testCompositeUnicode(self):
         """ mail.sendmail: encode Uncode address: 'ויקי <local@domain>' """
         address = u'ויקי <local@domain>'
         phrase = str(Header(u'ויקי '.encode('utf-8'), self.charset))
         expected = phrase + '<local@domain>'
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testEmptyPhrase(self):
         """ mail.sendmail: encode address with empty phrase: '<local@domain>' """
         address = u'<local@domain>'
         expected = address.encode(config.charset)
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testEmptyAddress(self):
         """ mail.sendmail: encode address with empty address: 'Phrase <>'
@@ -98,8 +90,7 @@
         address = u'Phrase <>'
         phrase = str(Header(u'Phrase '.encode('utf-8'), self.charset))
         expected = phrase + '<>'
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
     def testInvalidAddress(self):
         """ mail.sendmail: encode invalid address 'Phrase <blah'
@@ -110,8 +101,7 @@
         """
         address = u'Phrase <blah'
         expected = address.encode(config.charset)
-        self.failUnlessEqual(sendmail.encodeAddress(address, self.charset),
-                             expected)
+        assert sendmail.encodeAddress(address, self.charset) == expected
 
 
 coverage_modules = ['MoinMoin.mail.sendmail']
--- a/MoinMoin/search/_tests/test_search.py	Sun Jul 22 04:17:31 2007 +0200
+++ b/MoinMoin/search/_tests/test_search.py	Sun Jul 22 04:17:59 2007 +0200
@@ -6,11 +6,10 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin import search
 
 
-class TestQuotingBug(unittest.TestCase):
+class TestQuotingBug:
     """search: quoting bug tests
 
     http://moinmoin.wikiwikiweb.de/MoinMoinBugs/SearchOneCharString
@@ -19,20 +18,18 @@
     testing parsed queries is much more work.
     """
 
-    def setUp(self):
-        self.parser = search.QueryParser()
-
     def testIsQuoted(self):
         """ search: quoting bug - quoted terms """
+        parser = search.QueryParser()
         for case in ('"yes"', "'yes'"):
-            self.assertEqual(self.parser.isQuoted(case), True)
+            assert parser.isQuoted(case)
 
     def testIsNot(self):
         """ search: quoting bug - unquoted terms """
-        tests = ('', "'", '"', '""', "''", "'\"", '"no', 'no"', "'no",
-                 "no'", '"no\'')
+        tests = ('', "'", '"', '""', "''", "'\"", '"no', 'no"', "'no", "no'", '"no\'')
+        parser = search.QueryParser()
         for case in tests:
-            self.assertEqual(self.parser.isQuoted(case), False)
+            assert not parser.isQuoted(case)
 
 
 coverage_modules = ['MoinMoin.search']
--- a/MoinMoin/util/_tests/test_web.py	Sun Jul 22 04:17:31 2007 +0200
+++ b/MoinMoin/util/_tests/test_web.py	Sun Jul 22 04:17:59 2007 +0200
@@ -6,13 +6,12 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
 from MoinMoin import wikiutil
 from MoinMoin.util import web
 from MoinMoin.widget import html
 
 
-class TestMakeQueryString(unittest.TestCase):
+class TestMakeQueryString:
     """util.web: making query string"""
 
     def testMakeQueryStringFromArgument(self):
@@ -26,17 +25,11 @@
             )
 
         for description, arg, expected in tests:
-            result = wikiutil.makeQueryString(arg)
-            self.assertEqual(result, expected,
-                             ('%(description)s: expected "%(expected)s" '
-                              'but got "%(result)s"') % locals())
+            assert wikiutil.makeQueryString(arg) == expected
 
     def testMakeQueryStringFromKeywords(self):
         """ util.web: make query sting from keywords """
-        expected = 'a=1&b=string'
-        result = wikiutil.makeQueryString(a=1, b='string')
-        self.assertEqual(result, expected,
-                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert wikiutil.makeQueryString(a=1, b='string') == 'a=1&b=string'
 
     def testMakeQueryStringFromArgumentAndKeywords(self):
         """ util.web: make query sting from argument and keywords """
@@ -50,48 +43,41 @@
 
         for description, arg, expected in tests:
             # Call makeQueryString with both arg and keyword
-            result = wikiutil.makeQueryString(arg, b='kw')
-            self.assertEqual(result, expected,
-                             ('%(description)s: expected "%(expected)s" '
-                              'but got "%(result)s"') % locals())
+            assert wikiutil.makeQueryString(arg, b='kw') == expected
 
 
-class TestMakeSelection(unittest.TestCase):
+class TestMakeSelection:
     """util.web: creating html select"""
 
     values = ('one', 'two', 'simple', ('complex', 'A tuple & <escaped text>'))
 
-    def setUp(self):
-        html._SORT_ATTRS = 1
-        self.expected = (
+    html._SORT_ATTRS = 1
+    expected = (
         u'<select name="test" size="1">'
         u'<option value="one">one</option>'
         u'<option value="two">two</option>'
         u'<option value="simple">simple</option>'
         u'<option value="complex">A tuple &amp; &lt;escaped text&gt;</option>'
         u'</select>'
-        )
+    )
 
     def testMakeSelectNoSelection(self):
         """util.web: creating html select with no selection"""
         expected = self.expected
         result = unicode(web.makeSelection('test', self.values, size=1))
-        self.assertEqual(result, expected,
-                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert result == expected
 
     def testMakeSelectNoSelection2(self):
         """util.web: creating html select with non existing selection"""
         expected = self.expected
         result = unicode(web.makeSelection('test', self.values, 'three', size=1))
-        self.assertEqual(result, expected,
-                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert result == expected
 
     def testMakeSelectWithSelectedItem(self):
         """util.web: creating html select with selected item"""
         expected = self.expected.replace('value="two"', 'selected value="two"')
         result = unicode(web.makeSelection('test', self.values, 'two', size=1))
-        self.assertEqual(result, expected,
-                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+        assert result == expected
 
 
 coverage_modules = ['MoinMoin.util.web']
--- a/MoinMoin/widget/_tests/test_html.py	Sun Jul 22 04:17:31 2007 +0200
+++ b/MoinMoin/widget/_tests/test_html.py	Sun Jul 22 04:17:59 2007 +0200
@@ -6,10 +6,11 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import unittest # LEGACY UNITTEST, PLEASE DO NOT IMPORT unittest IN NEW TESTS, PLEASE CONSULT THE py.test DOCS
+import py
+
 from MoinMoin.widget import html
 
-class TestHTMLWidgets(unittest.TestCase):
+class TestHTMLWidgets:
     """widget.html: testing html widgets"""
 
     def testCreate(self):
@@ -28,16 +29,14 @@
 
         for description, obj, expected in tests:
             result = unicode(obj)
-            self.assertEqual(result, expected,
-                             ('%(description)s: expected "%(expected)s" '
-                              'but got "%(result)s"') % locals())
+            assert result == expected
 
     def testInvalidAttributes(self):
-        """widegt.html: invalid attributes raises exception
+        """widget.html: invalid attributes raises exception
 
         TO DO: add tests for all elements by HTML 4 spec.
         """
-        self.assertRaises(AttributeError, html.BR, name='foo')
+        py.test.raises(AttributeError, html.BR, name='foo')
 
 
     def testCompositeElements(self):
@@ -61,8 +60,7 @@
         for action, data, expected in actions:
             action(data)
             result = unicode(element)
-            self.assertEqual(result, expected,
-                             'Expected "%(expected)s" but got "%(result)s"' % locals())
+            assert result == expected
 
 coverage_modules = ['MoinMoin.widget.html']
 
--- a/MoinMoin/wikiutil.py	Sun Jul 22 04:17:31 2007 +0200
+++ b/MoinMoin/wikiutil.py	Sun Jul 22 04:17:59 2007 +0200
@@ -3,6 +3,8 @@
     MoinMoin - Wiki Utility Functions
 
     @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
+                2004 by Florian Festi,
+                2006 by Mikko Virkkil,
                 2005-2007 MoinMoin:ThomasWaldmann,
                 2007 MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
@@ -1303,14 +1305,10 @@
             ("John Smith", male=True)
         this will result in the following dict:
             {"name": "John Smith", "age": None, "male": True}
-
-        @copyright: 2004 by Florian Festi,
-                    2006 by Mikko Virkkil
-        @license: GNU GPL, see COPYING for details.
     """
 
     def __init__(self, pattern):
-        #parameter_re = "([^\"',]*(\"[^\"]*\"|'[^']*')?[^\"',]*)[,)]"
+        # parameter_re = "([^\"',]*(\"[^\"]*\"|'[^']*')?[^\"',]*)[,)]"
         name = "(?P<%s>[a-zA-Z_][a-zA-Z0-9_]*)"
         int_re = r"(?P<int>-?\d+)"
         bool_re = r"(?P<bool>(([10])|([Tt]rue)|([Ff]alse)))"
@@ -1343,7 +1341,7 @@
                 named = True
                 self.param_dict[match.group('name')[1:-1]] = i
             elif named:
-                raise ValueError, "Named parameter expected"
+                raise ValueError("Named parameter expected")
             i += 1
 
     def __str__(self):
@@ -1351,65 +1349,60 @@
                                         self.optional)
 
     def parse_parameters(self, params):
-        """
-        (4, 2)
-        """
-        #Default list to "None"s
+        # Default list/dict entries to None
         parameter_list = [None] * len(self.param_list)
-        parameter_dict = {}
+        parameter_dict = dict([(key, None) for key in self.param_dict])
         check_list = [0] * len(self.param_list)
 
         i = 0
         start = 0
+        fixed_count = 0
         named = False
 
-        if not params:
-            params = '""'
-
         while start < len(params):
             match = re.match(self.param_re, params[start:])
             if not match:
-                raise ValueError, "Misformatted value"
+                raise ValueError("malformed parameters")
             start += match.end()
-            value = None
             if match.group("int"):
-                value = int(match.group("int"))
-                type = 'i'
+                pvalue = int(match.group("int"))
+                ptype = 'i'
             elif match.group("bool"):
-                value = (match.group("bool") == "1") or (match.group("bool") == "True") or (match.group("bool") == "true")
-                type = 'b'
+                pvalue = (match.group("bool") == "1") or (match.group("bool") == "True") or (match.group("bool") == "true")
+                ptype = 'b'
             elif match.group("float"):
-                value = float(match.group("float"))
-                type = 'f'
+                pvalue = float(match.group("float"))
+                ptype = 'f'
             elif match.group("string"):
-                value = match.group("string")[1:-1]
-                type = 's'
+                pvalue = match.group("string")[1:-1]
+                ptype = 's'
             elif match.group("name_param"):
-                value = match.group("name_param")
-                type = 'n'
+                pvalue = match.group("name_param")
+                ptype = 'n'
             else:
-                value = None
+                raise ValueError("Parameter parser code does not fit param_re regex")
 
-            parameter_list.append(value)
-            if match.group("name"):
-                if match.group("name") not in self.param_dict:
+            name = match.group("name")
+            if name:
+                if name not in self.param_dict:
                     # TODO we should think on inheritance of parameters
-                    raise ValueError, "Unknown parameter name '%s'" % match.group("name")
-                nr = self.param_dict[match.group("name")]
+                    raise ValueError("unknown parameter name '%s'" % name)
+                nr = self.param_dict[name]
                 if check_list[nr]:
-                    #raise ValueError, "Parameter specified twice"
-                    #TODO: Something saner that raising an exception. This is pretty good, since it ignores it.
-                    pass
+                    raise ValueError("parameter '%s' specified twice" % name)
                 else:
                     check_list[nr] = 1
-                parameter_dict[match.group("name")] = value
-                parameter_list[nr] = value
+                pvalue = self._check_type(pvalue, ptype, self.param_list[nr])
+                parameter_dict[name] = pvalue
+                parameter_list[nr] = pvalue
                 named = True
             elif named:
-                raise ValueError, "Only named parameters allowed"
+                raise ValueError("only named parameters allowed after first named parameter")
             else:
                 nr = i
-                parameter_list[nr] = value
+                if nr not in self.param_dict.values():
+                    fixed_count = nr + 1
+                parameter_list[nr] = self._check_type(pvalue, ptype, self.param_list[nr])
 
             # Let's populate and map our dictionary to what's been found
             for name in self.param_dict:
@@ -1418,50 +1411,37 @@
 
             i += 1
 
-        return parameter_list, parameter_dict
-
-""" never used:
-    def _check_type(value, type, format):
-        if type == 'n' and 's' in format: # n as s
-            return value
-
-        if type in format:
-            return value # x -> x
+        for i in range(fixed_count):
+            parameter_dict[i] = parameter_list[i]
 
-        if type == 'i':
+        return fixed_count, parameter_dict
+
+    def _check_type(self, pvalue, ptype, format):
+        if ptype == 'n' and 's' in format: # n as s
+            return pvalue
+
+        if ptype in format:
+            return pvalue # x -> x
+
+        if ptype == 'i':
             if 'f' in format:
-                return float(value) # i -> f
+                return float(pvalue) # i -> f
             elif 'b' in format:
-                return value # i -> b
-        elif type == 'f':
+                return pvalue != 0 # i -> b
+        elif ptype == 's':
             if 'b' in format:
-                return value  # f -> b
-        elif type == 's':
-            if 'b' in format:
-                return value.lower() != 'false' # s-> b
+                if pvalue.lower() == 'false':
+                    return False # s-> b
+                elif pvalue.lower() == 'true':
+                    return True # s-> b
+                else:
+                    raise ValueError('%r does not match format %r' % (pvalue, format))
 
         if 's' in format: # * -> s
-            return str(value)
-        else:
-            pass # XXX error
-
-def main():
-    pattern = "%i%sf%s%ifs%(a)s|%(b)s"
-    param = ' 4,"DI\'NG", b=retry, a="DING"'
-
-    #p_list, p_dict = parse_parameters(param)
+            return str(pvalue)
 
-    print 'Pattern :', pattern
-    print 'Param :', param
+        raise ValueError('%r does not match format %r' % (pvalue, format))
 
-    P = ParameterParser(pattern)
-    print P
-    print P.parse_parameters(param)
-
-
-if __name__=="__main__":
-    main()
-"""
 
 #############################################################################
 ### Misc