[Mailman-Developers] Problem with % formatting.

Sean Reifschneider jafo@tummy.com
Wed, 13 Oct 1999 02:56:15 -0600


Boy, this percent formatting is really turning out to be a problem.  For
about the last week, a list I manage has been having severe problems,
but I didn't realize fully HOW severe (the only report was that digests
had duplicate messages in them).

It turns out that the code which creates the headers and footers from the
template was missing an 's' on this list, so it had "%(real_name):".
This meant that the message was being written for archiving with every
delivery, but every REAL attempt to deliver was failing.

I've made a patch for the specific instance of this problem (switching to
a SafeDict at the same time).  However, I think the real answer may be
something like the following in Util.py:

def Formatter(fmt, data):
	if type(data) == types.DictType:
		data = SafeDict(data)
	try: s = fmt % data
	except ValueError: s = fmt
	return(s)

and use this function in place of % formatting, *PARTICULARLY* where
the LHS is user-provided.

Sean
======================
*** MailList.py.old     Wed Oct 13 02:28:31 1999
--- MailList.py Wed Oct 13 02:36:26 1999
***************
*** 1346,1356 ****
                  pass
          self.LogMsg("post", "post to %s from %s size=%d",
                      self._internal_name, msg.GetSender(), len(msg.body))
!         d = self.__dict__.copy()
          d['cgiext'] = mm_cfg.CGIEXT
        self.DeliverToList(msg, recipients, 
!                          header = self.msg_header % d,
!                          footer = self.msg_footer % d)
        if ack_post:
            self.SendPostAck(msg, sender)
        self.last_post_time = time.time()
--- 1346,1362 ----
                  pass
          self.LogMsg("post", "post to %s from %s size=%d",
                      self._internal_name, msg.GetSender(), len(msg.body))
!         d = Utils.SafeDict(self.__dict__.copy())
          d['cgiext'] = mm_cfg.CGIEXT
+ 
+         #  Make sure invalid formatting doesn't frob us up
+         try: header = self.msg_header % d
+         except ValueError: header = self.msg_header
+         try: footer = self.msg_footer % d
+         except ValueError: footer = self.msg_footer
        self.DeliverToList(msg, recipients, 
!                          header = header,
!                          footer = footer)
        if ack_post:
            self.SendPostAck(msg, sender)
        self.last_post_time = time.time()

-- 
 [...] Premature optimization is the root of all evil.
                 -- Donald Knuth
Sean Reifschneider, Inimitably Superfluous <jafo@tummy.com>
URL: <http://www.tummy.com/xvscan> HP-UX/Linux/FreeBSD/BSDOS scanning software.