Author: bree Date: Mon Apr 17 16:00:37 2006 New Revision: 2859 Modified: azax/branches/plugin/commands.py azax/branches/plugin/parsers.py Log: refactor html named entit replacement, now it is done as standard part of the parsing.
Modified: azax/branches/plugin/commands.py ============================================================================== --- azax/branches/plugin/commands.py (original) +++ azax/branches/plugin/commands.py Mon Apr 17 16:00:37 2006 @@ -30,7 +30,6 @@ from interfaces import IAzaxCommands, IAzaxCommand, IAzaxParam from plugins import Command from unicode_quirks import force_unicode -import re, htmlentitydefs class AzaxCommands(list): implements(IAzaxCommands) @@ -86,25 +85,14 @@ The render method does actual marshalling of the commands to be sent to the client. ''' - - _entity_regexp = re.compile(r"&([a-zA-Z]+);") def __init__(self, context, request): self.context = context self.request = request # XML output gets rendered via a page template - _render = ViewPageTemplateFile('browser/kukitresponse.pt', content_type='text/xml;charset=utf-8') + render = ViewPageTemplateFile('browser/kukitresponse.pt', content_type='text/xml;charset=utf-8') - # replace named entities to fix a bug in IE - def render(self): - name2codepoint = htmlentitydefs.name2codepoint - def entity_replacer(m): - value = name2codepoint.get(m.group(1)) - if value is None: - return m.group(0) - return "&#%i;" % value - - result = self._render() - result = self._entity_regexp.sub(entity_replacer, result) - return result +# def render(self): +# result = self._render() +# return result Modified: azax/branches/plugin/parsers.py ============================================================================== --- azax/branches/plugin/parsers.py (original) +++ azax/branches/plugin/parsers.py Mon Apr 17 16:00:37 2006 @@ -29,6 +29,25 @@ ''' from unicode_quirks import force_unicode +import re, htmlentitydefs + +class replace_html_named_entities(object): + + _entity_regexp = re.compile(r'&([A-Za-z]+);') + + def _entity_replacer(m): + value = htmlentitydefs.name2codepoint.get(m.group(1)) + if value is None: + return m.group(0) + return "&#%i;" % value + _entity_replacer = staticmethod(_entity_replacer) + + def _replace(cls, value): + return cls._entity_regexp.sub(cls._entity_replacer, value) + _replace = classmethod(_replace) + + def __new__(cls, value): + return cls._replace(value) class XmlParser(object): '''Custom XML parser @@ -64,4 +83,10 @@ # tag['xmlns'] = "http://www.w3.org/1999/xhtml" def __call__(self): - return unicode(self.soup) + value = unicode(self.soup) + # Replace named HTML entitied in each case. + # This is necessary for two reasons: + # 1. Fixes an IE bug. + # 2. Needed for the alternate transport mechanism to work. + value = replace_html_named_entities(value) + return value -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins