[Zope-Checkins] CVS: Zope/lib/python/DocumentTemplate - DT_Var.py:1.55
Chris McDonough
chrism@zope.com
Wed, 14 Aug 2002 11:47:28 -0400
Update of /cvs-repository/Zope/lib/python/DocumentTemplate
In directory cvs.zope.org:/tmp/cvs-serv25172/DocumentTemplate
Modified Files:
DT_Var.py
Log Message:
Added 'url_unquote' and 'url_unquote_plus' modifiers to DTML as
well as made these functions available in PythonScripts via
the 'standard' module.
=== Zope/lib/python/DocumentTemplate/DT_Var.py 1.54 => 1.55 ===
--- Zope/lib/python/DocumentTemplate/DT_Var.py:1.54 Thu Aug 1 12:00:39 2002
+++ Zope/lib/python/DocumentTemplate/DT_Var.py Wed Aug 14 11:46:57 2002
@@ -114,6 +114,12 @@
space characters with '+'. This is needed for building
query strings in some cases.
+ 'url_unquote' -- convert HTML character entities in strings
+ back to their real values.
+
+ 'url_unquote_plus' -- like url_unquote, but also
+ replace '+' characters with spaces.
+
'sql_quote' -- Convert single quotes to pairs of single
quotes. This is needed to safely include values in
Standard Query Language (SQL) strings.
@@ -150,7 +156,7 @@
from DT_Util import parse_params, name_param, str, ustr
import os, string, re, sys
-from urllib import quote, quote_plus
+from urllib import quote, quote_plus, unquote, unquote_plus
from cgi import escape
from html_quote import html_quote # for import by other modules, dont remove!
from types import StringType
@@ -167,7 +173,8 @@
capitalize=1, spacify=1, null='', fmt='s',
size=0, etc='...', thousands_commas=1,
html_quote=1, url_quote=1, sql_quote=1,
- url_quote_plus=1, missing='',
+ url_quote_plus=1, url_unquote=1,
+ url_unquote_plus=1,missing='',
newline_to_br=1, url=1)
self.args=args
@@ -333,6 +340,11 @@
def url_quote_plus(v, name='(Unknown name)', md={}):
return quote_plus(str(v))
+def url_unquote(v, name='(Unknown name)', md={}):
+ return unquote(str(v))
+
+def url_unquote_plus(v, name='(Unknown name)', md={}):
+ return unquote_plus(str(v))
def newline_to_br(v, name='(Unknown name)', md={}):
# Unsafe data is explicitly quoted here; we don't expect this to be HTML
@@ -422,6 +434,8 @@
'html-quote': html_quote,
'url-quote': url_quote,
'url-quote-plus': url_quote_plus,
+ 'url-unquote': url_unquote,
+ 'url-unquote-plus': url_unquote_plus,
'multi-line': newline_to_br,
'comma-numeric': thousands_commas,
'dollars-with-commas': whole_dollars_with_commas,
@@ -434,7 +448,7 @@
modifiers=(html_quote, url_quote, url_quote_plus, newline_to_br,
string.lower, string.upper, string.capitalize, spacify,
- thousands_commas, sql_quote)
+ thousands_commas, sql_quote, url_unquote, url_unquote_plus)
modifiers=map(lambda f: (f.__name__, f), modifiers)
class Comment: