SafePortalTransforms
====================

Builds on transmogrifier.portaltransform. Adds
- protection against exceptions caused by transform failures
- logging
- subobjects from transforms such as images from word and pdf transforms

The following test will transform the html by adding two images.

>>> from collective.transmogrifier.tests import registerConfig
>>> from collective.transmogrifier.transmogrifier import Transmogrifier
>>> transmogrifier = Transmogrifier(plone)
>>> config = """
... [transmogrifier]
... pipeline =
...     webcrawler
...     convert
...     treeserializer
...     printer
...
...
... [webcrawler]
... blueprint = transmogrify.webcrawler.test.htmlsource
... one=<a href="two">2</a>
...
... [convert]
... blueprint = transmogrify.webcrawler.safeportaltransforms
... mimetype_field = _mimetype
... target = text/blah
... keys = text
...
... [treeserializer]
... blueprint = transmogrify.webcrawler.treeserializer
...
... [printer]
... blueprint = collective.transmogrifier.sections.tests.pprinter
...
... """
>>> registerConfig(u'test1', config)
>>> transmogrifier(u'test1')
{'_default_page': 'one',
 '_path': 'one',
 '_site_url': 'http://test.com/',
 '_type': 'Folder'}
{'_backlinks': [('http://test.com/one/one', '')],
 '_path': 'one/image01.jpg',
 '_site_url': 'http://test.com/',
 '_type': 'Image',
 'image': '<a href="two">2</a>',
 'image.filename': 'image01.jpg'}
{'_backlinks': [('http://test.com/one/one', '')],
 '_path': 'one/image02.jpg',
 '_site_url': 'http://test.com/',
 '_type': 'Image',
 'image': '<a href="two">2</a>',
 'image.filename': 'image02.jpg'}
{'_mimetype': 'text/blah',
 '_path': 'one/one',
 '_site_url': 'http://test.com/',
 'text': 'Transformed 19 from text/html to text/blah<img src="image01.jpg"><img src="image02.jpg">'}

Test it works when we move content, convert it and then turn into attachments and relink
it.
>>> config = """
... [transmogrifier]
... pipeline =
...     source
...     moves
...     convert
...     relinker
...     makeattachments
...     relinker
...     treeserializer
...     printer
...
... [source]
... blueprint = transmogrify.webcrawler.test.htmlbacklinksource
... f oo/content1=blah
...
... [moves]
... blueprint = transmogrify.webcrawler.pathmover
... moves =
...    f%20oo a
...
... [convert]
... blueprint = transmogrify.webcrawler.safeportaltransforms
... mimetype_field = _mimetype
... target = text/xhtml
... keys = text
...
... [makeattachments]
... blueprint = transmogrify.webcrawler.makeattachments
... fields = python:[('attach%i'%i,subitem['image'])]
...
... [relinker]
... blueprint = transmogrify.webcrawler.relinker
...
... [treeserializer]
... blueprint = transmogrify.webcrawler.treeserializer
...
... [printer]
... blueprint = collective.transmogrifier.sections.tests.pprinter
... """
>>> registerConfig(u'test2', config)
>>> transmogrifier(u'test2')
{'_type': 'Folder', '_site_url': 'http://test.com/', '_path': 'a'}
{'_default_page': 'content1',
 '_path': 'a/content1',
 '_site_url': 'http://test.com/',
 '_type': 'Folder'}
{'_site_url': 'http://test.com/', '_path': 'a/content1/content1/attach0'}
{'_site_url': 'http://test.com/', '_path': 'a/content1/content1/attach1'}
{'_mimetype': 'text/xhtml',
 '_path': 'a/content1/content1',
 '_site_url': 'http://test.com/',
 'attach0': 'blah',
 'attach1': 'blah',
 'text': '<html>Transformed 4 from text/html to text/xhtml<img src="attach1"/><img src="attach0"/></html>\n\n'}
