[wwwsearch-commits] r16892 - wwwsearch/pullparser/trunk
jjlee at codespeak.net
jjlee at codespeak.net
Sat Aug 27 22:12:08 CEST 2005
Author: jjlee
Date: Sat Aug 27 22:12:07 2005
New Revision: 16892
Modified:
wwwsearch/pullparser/trunk/pullparser.py
Log:
Optimisation (Benji York, Zope Corp)
Modified: wwwsearch/pullparser/trunk/pullparser.py
==============================================================================
--- wwwsearch/pullparser/trunk/pullparser.py (original)
+++ wwwsearch/pullparser/trunk/pullparser.py Sat Aug 27 22:12:07 2005
@@ -100,29 +100,14 @@
import sys
return sys.exc_traceback.tb_frame.f_back.f_back.f_code.co_name
-# Grabbed from 2.4 xml.sax.saxutils, and modified (via ClientForm)
-def __dict_replace(s, d):
- """Replace substrings of a string using a dictionary."""
- for key, value in d.items():
- s = s.replace(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 = data.replace("&", "&")
- 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 get_entitydefs():
entitydefs = {}
More information about the wwwsearch-commits
mailing list