From e38b78d10ce98e7b29681f5b0ffd9c0f36b90f38 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 28 Jun 2011 09:12:20 +0200 Subject: [PATCH] appy.bin: job.py: allow to specify several commands to execute (to separate with semicolons); appy.gen: translate: added the possibility to escape XML special chars in translations; appy.pod: bugfix in buffers.write: if content is already utf-8-encoded it does not crash anymore. --- bin/job.py | 25 +++++++++++++++++-------- gen/plone25/mixins/__init__.py | 7 ++++--- gen/plone25/wrappers/__init__.py | 6 ++++-- pod/buffers.py | 5 ++++- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/bin/job.py b/bin/job.py index ed4cdad..e740428 100644 --- a/bin/job.py +++ b/bin/job.py @@ -18,7 +18,12 @@ Zope object if previous param starts with "path=". (optional) are the arguments to give to this method (only strings - are supported). Several arguments must be separated by '*'.''' + are supported). Several arguments must be separated by '*'. + + Note that you can also specify several commands, separated with + semicolons (";"). This scripts performes a single commit after all commands + have been executed. +''' # ------------------------------------------------------------------------------ import sys, transaction @@ -28,12 +33,16 @@ if len(sys.argv) != 2: print 'job.py was called with wrong args.' print __doc__ else: - command = sys.argv[1] - parts = command.split(':') - if len(parts) not in (4,5): - print 'job.py was called with wrong args.' - print __doc__ - else: + commands = sys.argv[1].split(';') + # Check that every command has the right number of sub-elelements. + for command in commands: + parts = command.split(':') + if len(parts) not in (4,5): + print 'job.py was called with wrong args.' + print __doc__ + + for command in commands: + parts = command.split(':') # Unwrap parameters if len(parts) == 4: zopeUser, plonePath, appName, toolMethod = parts @@ -66,5 +75,5 @@ else: # Execute the method on the target object if args: args = args.split('*') exec 'targetObject.%s(*args)' % toolMethod - transaction.commit() + transaction.commit() # ------------------------------------------------------------------------------ diff --git a/gen/plone25/mixins/__init__.py b/gen/plone25/mixins/__init__.py index e2328ab..8be34b1 100644 --- a/gen/plone25/mixins/__init__.py +++ b/gen/plone25/mixins/__init__.py @@ -3,7 +3,7 @@ - mixins/ToolMixin is mixed in with the generated application Tool class.''' # ------------------------------------------------------------------------------ -import os, os.path, sys, types, mimetypes, urllib +import os, os.path, sys, types, mimetypes, urllib, cgi import appy.gen from appy.gen import Type, String, Selection, Role, No from appy.gen.utils import * @@ -1173,8 +1173,9 @@ class BaseMixin: def formatText(self, text, format='html'): '''Produces a representation of p_text into the desired p_format, which - is 'html' by default.''' - if format in ('html', 'xhtml'): + is "html" by default.''' + if 'html' in format: + if format == 'html_from_text': text = cgi.escape(text) res = text.replace('\r\n', '
').replace('\n', '
') elif format == 'js': res = text.replace('\r\n', '').replace('\n', '') diff --git a/gen/plone25/wrappers/__init__.py b/gen/plone25/wrappers/__init__.py index 523a01d..12e44aa 100644 --- a/gen/plone25/wrappers/__init__.py +++ b/gen/plone25/wrappers/__init__.py @@ -250,9 +250,11 @@ class AbstractWrapper: '''Deletes myself.''' self.o.delete() - def translate(self, label, mapping={}, domain=None, language=None): + def translate(self, label, mapping={}, domain=None, language=None, + format='html'): '''Check documentation of self.o.translate.''' - return self.o.translate(label, mapping, domain, language=language) + return self.o.translate(label, mapping, domain, language=language, + format=format) def do(self, transition, comment='', doAction=False, doNotify=False, doHistory=True): diff --git a/pod/buffers.py b/pod/buffers.py index fada406..c17b212 100644 --- a/pod/buffers.py +++ b/pod/buffers.py @@ -177,7 +177,10 @@ class FileBuffer(Buffer): def getLength(self): return 0 def write(self, something): - self.content.write(something.encode('utf-8')) + try: + self.content.write(something.encode('utf-8')) + except UnicodeDecodeError: + self.content.write(something) def addExpression(self, expression): try: