diff --git a/gen/plone25/mixins/__init__.py b/gen/plone25/mixins/__init__.py index 2e6e6a0..f2a66b5 100644 --- a/gen/plone25/mixins/__init__.py +++ b/gen/plone25/mixins/__init__.py @@ -1210,15 +1210,20 @@ class BaseMixin: if field: # Maybe we do not have the field itself, but only its name if isinstance(field, basestring): - field = self.getAppyType(field, className=className) - # Include field-specific mapping if any. - fieldMapping = field.mapping[label] - if fieldMapping: - if callable(fieldMapping): - fieldMapping = field.callMethod(self, fieldMapping) - mapping.update(fieldMapping) - # Get the label - label = getattr(field, label+'Id') + appyField = self.getAppyType(field, className=className) + else: + appyField = field + if appyField: + fieldMapping = appyField.mapping[label] + if fieldMapping: + if callable(fieldMapping): + fieldMapping=appyField.callMethod(self,fieldMapping) + mapping.update(fieldMapping) + # Get the label + label = getattr(appyField, label+'Id') + else: + # It must be a group. + label = '%s_group_%s_%s' % (self.meta_type, field, label) # We will get the translation from a Translation object. # In what language must we get the translation? if not language: language = self.getUserLanguage() diff --git a/pod/renderer.py b/pod/renderer.py index a0e1137..d0a6191 100644 --- a/pod/renderer.py +++ b/pod/renderer.py @@ -239,11 +239,11 @@ class Renderer: return Xhtml2OdtConverter(xhtmlContent, encoding, self.stylesManager, stylesMapping, ns).run() - def renderText(self, text, encoding='utf-8'): + def renderText(self, text, encoding='utf-8', stylesMapping={}): '''Method that can be used (under the name 'text') into a pod template for inserting a text containing carriage returns.''' text = text.replace('\r\n', '
').replace('\n', '
') - return self.renderXhtml(text, encoding) + return self.renderXhtml(text, encoding, stylesMapping) def evalIfExpression(self, condition, ifTrue, ifFalse): '''This method implements the method 'test' which is proposed in the diff --git a/shared/dav.py b/shared/dav.py index 5cc77f5..d71568e 100644 --- a/shared/dav.py +++ b/shared/dav.py @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------ -import os, re, httplib, sys, stat, urlparse, time, socket +import os, re, httplib, sys, stat, urlparse, time, socket, xml.sax from urllib import quote from StringIO import StringIO from mimetypes import guess_type @@ -87,7 +87,14 @@ class HttpResponse: if self.duration: duration = ', got in %.4f seconds' % self.duration return '' % (self.code, self.text, duration) - xmlHeaders = ('text/xml', 'application/xml') + def extractContentType(self, contentType): + '''Extract the content type from the HTTP header, potentially removing + encoding-related data.''' + i = contentType.find(';') + if i != -1: return contentType[:i] + return contentType + + xmlHeaders = ('text/xml', 'application/xml', 'application/soap+xml') def extractData(self): '''This method extracts, from the various parts of the HTTP response, some useful information. For example, it will find the URI where to @@ -96,12 +103,15 @@ class HttpResponse: if self.code == 302: return urlparse.urlparse(self.headers['location'])[2] elif self.headers.has_key('content-type'): - contentType = self.headers['content-type'] + contentType = self.extractContentType(self.headers['content-type']) for xmlHeader in self.xmlHeaders: if contentType.startswith(xmlHeader): # Return an unmarshalled version of the XML content, for # easy use in Python. - return XmlUnmarshaller().parse(self.body) + try: + return XmlUnmarshaller().parse(self.body) + except xml.sax.SAXParseException, se: + raise ResourceError('Invalid XML response (%s)'%str(se)) # ------------------------------------------------------------------------------ urlRex = re.compile(r'http://([^:/]+)(:[0-9]+)?(/.+)?', re.I)