[Patches] [ python-Patches-1056967 ] No ValueError for safe_substitute()

SourceForge.net noreply at sourceforge.net
Sun Oct 31 02:13:05 CEST 2004


Patches item #1056967, was opened at 2004-10-30 04:47
Message generated for change (Comment added) made by ncoghlan
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1056967&group_id=5470

Category: Library (Lib)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Barry A. Warsaw (bwarsaw)
Assigned to: Raymond Hettinger (rhettinger)
Summary: No ValueError for safe_substitute()

Initial Comment:
I think it's a mistake for Template.safe_substitute()
to raise a ValueError when the invalid group is
matched.  I just ran across such a situation in Real
Code that is using Template.  In my code, I'm using a
subclass to override idpattern and then calling
safe_substitute().  The source of the template is a
flattened mail message where what I'm substituting is
going into some of the header fields.

The body of the message contains a big blurb of XML,
including the string "...$1...".  Well, that $1
triggers the ValueError.

This patch changes the semantics of safe_substitute()
so that when the 'invalid' group matches, the original
delimiter is returned, which I think is the right thing
to do.  Included is an updated test (I will update the
docs too if you agree that this patch should be applied).


----------------------------------------------------------------------

Comment By: Nick Coghlan (ncoghlan)
Date: 2004-10-31 10:13

Message:
Logged In: YES 
user_id=1038590

I'd agree with those semantics - if an unrecognised
identifier doesn't trigger a Key Error, I see no reason for
a non-identifier to trigger a Value Error.

For people who want stricter checking - well, that's what
substitute() is for.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1056967&group_id=5470


More information about the Patches mailing list