From d398d5bcfc01c358c6401b387a434d2ed207ac14 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 5 Feb 2010 15:39:52 +0100 Subject: [PATCH] Performance improvement in XML marshaller by mimicking StringIO in unicode-friendly buffer UnicodeBuffer and added a class appy.gen.No allowing to explain why some workflow condition cannot be triggered. --- gen/__init__.py | 11 +++++++++++ gen/plone25/mixins/PodTemplateMixin.py | 4 ++-- shared/__init__.py | 10 ++++++---- shared/xml_parser.py | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/gen/__init__.py b/gen/__init__.py index 3871aa3..0025f26 100755 --- a/gen/__init__.py +++ b/gen/__init__.py @@ -581,6 +581,17 @@ class Permission: class ReadPermission(Permission): pass class WritePermission(Permission): pass +class No: + '''When you write a workflow condition method and you want to return False + but you want to give to the user some explanations about why a transition + can't be triggered, do not return False, return an instance of No + instead. When creating such an instance, you can specify an error + message.''' + def __init__(self, msg): + self.msg = msg + def __nonzero__(self): + return False + # ------------------------------------------------------------------------------ class Selection: '''Instances of this class may be given as validator of a String, in order diff --git a/gen/plone25/mixins/PodTemplateMixin.py b/gen/plone25/mixins/PodTemplateMixin.py index 2a13ab3..0e09ebf 100644 --- a/gen/plone25/mixins/PodTemplateMixin.py +++ b/gen/plone25/mixins/PodTemplateMixin.py @@ -3,6 +3,8 @@ import os, os.path, time, unicodedata from appy.shared import mimeTypes from appy.gen.plone25.mixins import AbstractMixin from StringIO import StringIO +import appy.pod +from appy.pod.renderer import Renderer # ------------------------------------------------------------------------------ class PodError(Exception): pass @@ -81,8 +83,6 @@ class PodTemplateMixin(AbstractMixin): if appySelf.tool.openOfficePort: rendererParams['ooPort'] = appySelf.tool.openOfficePort # Launch the renderer - import appy.pod - from appy.pod.renderer import Renderer try: renderer = Renderer(**rendererParams) renderer.run() diff --git a/shared/__init__.py b/shared/__init__.py index 64ee52d..9824416 100755 --- a/shared/__init__.py +++ b/shared/__init__.py @@ -41,15 +41,17 @@ class UnicodeBuffer: '''With StringIO class, I have tons of encoding problems. So I define a similar class here, that uses an internal unicode buffer.''' def __init__(self): - self.buffer = u'' + self.buffer = [] def write(self, s): if s == None: return if isinstance(s, unicode): - self.buffer += s + self.buffer.append(s) elif isinstance(s, str): - self.buffer += s.decode('utf-8') + self.buffer.append(s.decode('utf-8')) else: - self.buffer += unicode(s) + self.buffer.append(unicode(s)) + def getValue(self): + return u''.join(self.buffer) # ------------------------------------------------------------------------------ class Dummy: pass diff --git a/shared/xml_parser.py b/shared/xml_parser.py index 8590106..33e33a4 100755 --- a/shared/xml_parser.py +++ b/shared/xml_parser.py @@ -503,7 +503,7 @@ class XmlMarshaller: self.marshallSpecificElements(instance, res) # Return the result res.write('') - res = res.buffer + res = res.getValue() if not self.dumpUnicode: res = res.encode('utf-8') return res