Beispiel #1
0
    def addBinary(self,
                  field,
                  data,
                  mimetype,
                  encoding=None,
                  language=None,
                  logError=False,
                  raiseException=False):

        try:
            converter = getUtility(IConverter, mimetype)
        except ComponentLookupError:
            LOG.warn('No converter registered for %s' % mimetype)
            return

        text, encoding = converter.convert(data, encoding, mimetype, logError,
                                           raiseException)

        # The result should be string/unicode. If not, convert the returned
        # content to unicode using the returned encoding. The converter is
        # in charge to handle encoding issues correctly.

        assert isinstance(text, basestring)
        if isinstance(text, str):
            text = unicode(text, encoding, 'ignore')

        infos = self._d.get(field, ())
        self._d[field] = infos + ({'content': text, 'language': language}, )
    def addBinary(self, field, data, mimetype, encoding=None, language=None,
                  logError=False, raiseException=False):
        
        try:
            converter = getUtility(IConverter, mimetype)
        except ComponentLookupError:
            LOG.warn('No converter registered for %s' % mimetype)
            return

        

        text, encoding = converter.convert(data, encoding, mimetype,
                                           logError, raiseException)

        # The result should be string/unicode. If not, convert the returned
        # content to unicode using the returned encoding. The converter is
        # in charge to handle encoding issues correctly.

        assert isinstance(text, basestring)
        if isinstance(text, str):
            text = unicode(text, encoding, 'ignore')

        infos = self._d.get(field, ())
        self._d[field] = infos + ({'content': text, 'language': language},)