diff MoinMoin/macro/__init__.py @ 2536:72a31f09d5a1

allow types as defaults for macro args to force conversion to that type
author Johannes Berg <johannes AT sipsolutions DOT net>
date Mon, 23 Jul 2007 13:11:10 +0200
parents cc125871c8a0
children 070294763d3e
line wrap: on
line diff
--- a/MoinMoin/macro/__init__.py	Mon Jul 23 12:57:53 2007 +0200
+++ b/MoinMoin/macro/__init__.py	Mon Jul 23 13:11:10 2007 +0200
@@ -108,6 +108,12 @@
             return wikiutil.get_float(self.request, value, name, default)
         elif isinstance(default, unicode):
             return wikiutil.get_unicode(self.request, value, name, default)
+        elif default is bool:
+            return wikiutil.get_bool(self.request, value, name)
+        elif default is int or default is long:
+            return wikiutil.get_int(self.request, value, name)
+        elif default is float:
+            return wikiutil.get_float(self.request, value, name)
         return value
 
     def _wrap(self, macro_name, fn, args):
@@ -121,6 +127,7 @@
         it to the macro function. That way, macros need not call the
         wikiutil.get_* functions for any arguments that have a default.
         """
+        _ = self.request.getText
         if args:
             positional, keyword, trailing = \
                 wikiutil.parse_quoted_separated(args)
@@ -183,6 +190,8 @@
                 # iterate through all arguments, but if no more positional
                 # arguments are given then skip converting them
                 if idx >= len(positional):
+                    if isinstance(default, type):
+                        raise ValueError(_("Not enough arguments"))
                     continue
 
                 # use the default right away if it's not given,
@@ -461,7 +470,7 @@
         anchor = wikiutil.get_unicode(self.request, anchor, 'anchor', u'anchor')
         return self.formatter.anchordef(anchor)
 
-    def macro_MailTo(self, email, text=u''):
+    def macro_MailTo(self, email=unicode, text=u''):
         if not email:
             raise ValueError("You need to give an (obfuscated) email address")