[Zope3-checkins]
SVN: Zope3/branches/testbrowser-integration/src/zope/testbrowser/ClientForm.py
rework the way entities are unescaped making the code cleaner
and much faster
Benji York
benji at zope.com
Wed Aug 24 14:11:42 EDT 2005
Log message for revision 38074:
rework the way entities are unescaped making the code cleaner and much faster
Changed:
U Zope3/branches/testbrowser-integration/src/zope/testbrowser/ClientForm.py
-=-
Modified: Zope3/branches/testbrowser-integration/src/zope/testbrowser/ClientForm.py
===================================================================
--- Zope3/branches/testbrowser-integration/src/zope/testbrowser/ClientForm.py 2005-08-24 18:00:05 UTC (rev 38073)
+++ Zope3/branches/testbrowser-integration/src/zope/testbrowser/ClientForm.py 2005-08-24 18:11:42 UTC (rev 38074)
@@ -184,30 +184,17 @@
l.append(k + '=' + urllib.quote_plus(str(elt)))
return string.join(l, '&')
-# Grabbed from 2.4 xml.sax.saxutils, and modified
-def __dict_replace(s, d):
- """Replace substrings of a string using a dictionary."""
- for key, value in d.items():
- s = string.replace(s, key, value)
- return s
def unescape(data, entities):
- if data is None:
- return None
- do_amp = False
- if entities:
- # must do ampersand last
- ents = entities.copy()
- try:
- del ents["&"]
- except KeyError:
- pass
- else:
- do_amp = True
- data = __dict_replace(data, ents)
- if do_amp:
- data = string.replace(data, "&", "&")
- return data
+ if data is None or '&' not in data:
+ return data
+ def replace_entities(match):
+ ent = match.group()
+ repl = entities.get(ent, ent)
+ return repl
+
+ return re.sub(r'&\S+;', replace_entities, data)
+
def startswith(string, initial):
if len(initial) > len(string): return False
return string[:len(initial)] == initial
More information about the Zope3-Checkins
mailing list