appy.pod: added param 'stylesMapping' for the 'text' function (which calls 'xhtml' internally); appy.gen: bufgix in the translation system (translation of group-related labels); appy.shared.dav: bugfix while getting the 'content-type' HTTP header key; appy.shared.dav: smart error handling when parsing wrong XML content.

This commit is contained in:
Gaetan Delannay 2011-04-15 11:26:20 +02:00
parent 36237c3ee5
commit 4e848ce0a8
3 changed files with 30 additions and 15 deletions

View file

@ -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()

View file

@ -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', '<br/>').replace('\n', '<br/>')
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

View file

@ -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 '<HttpResponse %s (%s)%s>' % (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)