zope.app.renderer-3.5.1/ 0000755 0000764 0000764 00000000000 11232115613 015314 5 ustar srichter srichter zope.app.renderer-3.5.1/setup.cfg 0000644 0000764 0000764 00000000073 11232115613 017135 0 ustar srichter srichter [egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
zope.app.renderer-3.5.1/src/ 0000755 0000764 0000764 00000000000 11232115613 016103 5 ustar srichter srichter zope.app.renderer-3.5.1/src/zope.app.renderer.egg-info/ 0000755 0000764 0000764 00000000000 11232115613 023136 5 ustar srichter srichter zope.app.renderer-3.5.1/src/zope.app.renderer.egg-info/SOURCES.txt 0000644 0000764 0000764 00000001471 11232115613 025025 0 ustar srichter srichter CHANGES.txt
README.txt
bootstrap.py
buildout.cfg
setup.py
src/zope/__init__.py
src/zope.app.renderer.egg-info/PKG-INFO
src/zope.app.renderer.egg-info/SOURCES.txt
src/zope.app.renderer.egg-info/dependency_links.txt
src/zope.app.renderer.egg-info/namespace_packages.txt
src/zope.app.renderer.egg-info/not-zip-safe
src/zope.app.renderer.egg-info/requires.txt
src/zope.app.renderer.egg-info/top_level.txt
src/zope/app/__init__.py
src/zope/app/renderer/__init__.py
src/zope/app/renderer/configure.zcml
src/zope/app/renderer/i18n.py
src/zope/app/renderer/interfaces.py
src/zope/app/renderer/plaintext.py
src/zope/app/renderer/rest.py
src/zope/app/renderer/stx.py
src/zope/app/renderer/vocabulary.py
src/zope/app/renderer/tests/__init__.py
src/zope/app/renderer/tests/test_renderers.py
src/zope/app/renderer/tests/test_vocabulary.py zope.app.renderer-3.5.1/src/zope.app.renderer.egg-info/namespace_packages.txt 0000644 0000764 0000764 00000000016 11232115613 027466 0 ustar srichter srichter zope
zope.app
zope.app.renderer-3.5.1/src/zope.app.renderer.egg-info/PKG-INFO 0000644 0000764 0000764 00000003530 11232115613 024234 0 ustar srichter srichter Metadata-Version: 1.0
Name: zope.app.renderer
Version: 3.5.1
Summary: Text Renderer Framework
Home-page: http://pypi.python.org/pypi/zope.app.renderer
Author: Zope Corporation and Contributors
Author-email: zope-dev@zope.org
License: ZPL 2.1
Description: This package provides a framework to convert a string from one format, such as
Structured or Restructured Text, to another, such as HTML. Converters are
looked up by adapter and uses other packages to implement the converters.
=======
CHANGES
=======
3.5.1 (2009-07-21)
------------------
- Require the new `roman` package, since docutils does not install it
correctly.
3.5.0 (2009-01-17)
------------------
- Adapted to docutils 0.5 for ReST rendering: get rid of the
ZopeTranslator class, because docutils changed the way it
uses translator so previous implementation doesn't work anymore.
Instead, use publish_parts and join needed parts in the ``render``
method of the renderer itself.
- Removed deprecated meta.zcml stuff and zpkg stuff.
- Replaced __used_for__ with zope.component.adapts calls.
3.4.0 (2007-10-27)
------------------
- Initial release independent of the main Zope tree.
Keywords: zope3 renderer text rest rst stx
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Zope Public License
Classifier: Programming Language :: Python
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Framework :: Zope3
zope.app.renderer-3.5.1/src/zope.app.renderer.egg-info/requires.txt 0000644 0000764 0000764 00000000252 11232115613 025535 0 ustar srichter srichter setuptools
docutils>=0.5
roman
zope.component
zope.configuration
zope.i18nmessageid
zope.interface
zope.publisher
zope.schema
zope.structuredtext
[test]
zope.app.testing zope.app.renderer-3.5.1/src/zope.app.renderer.egg-info/top_level.txt 0000644 0000764 0000764 00000000005 11232115613 025663 0 ustar srichter srichter zope
zope.app.renderer-3.5.1/src/zope.app.renderer.egg-info/dependency_links.txt 0000644 0000764 0000764 00000000001 11232115613 027204 0 ustar srichter srichter
zope.app.renderer-3.5.1/src/zope.app.renderer.egg-info/not-zip-safe 0000644 0000764 0000764 00000000001 11221077621 025370 0 ustar srichter srichter
zope.app.renderer-3.5.1/src/zope/ 0000755 0000764 0000764 00000000000 11232115613 017060 5 ustar srichter srichter zope.app.renderer-3.5.1/src/zope/app/ 0000755 0000764 0000764 00000000000 11232115613 017640 5 ustar srichter srichter zope.app.renderer-3.5.1/src/zope/app/renderer/ 0000755 0000764 0000764 00000000000 11232115613 021446 5 ustar srichter srichter zope.app.renderer-3.5.1/src/zope/app/renderer/rest.py 0000644 0000764 0000764 00000007155 11232115227 023006 0 ustar srichter srichter ##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""ReStructured Text Renderer Classes
$Id: rest.py 94785 2009-01-17 12:54:26Z nadako $
"""
__docformat__ = 'restructuredtext'
import docutils.core
from zope.component import adapts
from zope.interface import implements
from zope.publisher.browser import BrowserView
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app.renderer.i18n import ZopeMessageFactory as _
from zope.app.renderer.interfaces import ISource, IHTMLRenderer
from zope.app.renderer import SourceFactory
class IReStructuredTextSource(ISource):
"""Marker interface for a restructured text source. Note that an
implementation of this interface should always derive from unicode or
behave like a unicode class."""
ReStructuredTextSourceFactory = SourceFactory(
IReStructuredTextSource, _("ReStructured Text (ReST)"),
_("ReStructured Text (ReST) Source"))
class ReStructuredTextToHTMLRenderer(BrowserView):
r"""An Adapter to convert from Restructured Text to HTML.
Examples::
>>> from zope.publisher.browser import TestRequest
>>> source = ReStructuredTextSourceFactory(u'''
... This is source.
...
... Header 3
... --------
... This is more source.
... ''')
>>> renderer = ReStructuredTextToHTMLRenderer(source, TestRequest())
>>> print renderer.render().strip()
This is source.
"""
implements(IHTMLRenderer)
adapts(IReStructuredTextSource, IBrowserRequest)
def render(self, settings_overrides={}):
"""See zope.app.interfaces.renderer.IHTMLRenderer
Let's make sure that inputted unicode stays as unicode:
>>> renderer = ReStructuredTextToHTMLRenderer(u'b\xc3h', None)
>>> repr(renderer.render())
"u'b\\\\xc3h
\\\\n'"
>>> text = u'''
... =========
... Heading 1
... =========
...
... hello world
...
... Heading 2
... ========='''
>>> overrides = {'initial_header_level': 2,
... 'doctitle_xform': 0 }
>>> renderer = ReStructuredTextToHTMLRenderer(text, None)
>>> print renderer.render(overrides)
Heading 1
hello world
Heading 2
"""
# default settings for the renderer
overrides = {
'halt_level': 6,
'input_encoding': 'unicode',
'output_encoding': 'unicode',
'initial_header_level': 3,
}
overrides.update(settings_overrides)
parts = docutils.core.publish_parts(
self.context,
writer_name='html',
settings_overrides=overrides,
)
return u''.join((parts['body_pre_docinfo'], parts['docinfo'], parts['body']))
zope.app.renderer-3.5.1/src/zope/app/renderer/tests/ 0000755 0000764 0000764 00000000000 11232115613 022610 5 ustar srichter srichter zope.app.renderer-3.5.1/src/zope/app/renderer/tests/test_vocabulary.py 0000644 0000764 0000764 00000005775 11221077621 026412 0 ustar srichter srichter ##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for Renderer Vocabulary.
$Id: test_vocabulary.py 73674 2007-03-27 07:52:12Z dobe $
"""
import unittest
from zope.app.testing import ztapi
from zope.app.renderer import SourceFactory
from zope.app.renderer.interfaces import ISource
from zope.app.renderer.vocabulary import SourceTypeVocabulary
from zope.component.interfaces import IFactory
from zope.app.testing.placelesssetup import PlacelessSetup
from zope.schema.interfaces import IVocabulary, IVocabularyTokenized
class IFoo(ISource):
"""Source marker interface"""
FooFactory = SourceFactory(IFoo, 'Foo', 'Foo Source')
class IFoo2(ISource):
"""Source marker interface"""
Foo2Factory = SourceFactory(IFoo2, 'Foo2', 'Foo2 Source')
# The vocabulary uses SimpleVocabulary now, so these tests are a bit
# redundant. Leaving them in as confirmation that the replacement function
# works identically to the old custom vocabulary.
class SourceTypeVocabularyTest(PlacelessSetup, unittest.TestCase):
def setUp(self):
super(SourceTypeVocabularyTest, self).setUp()
ztapi.provideUtility(IFactory, FooFactory, 'zope.source.Foo')
ztapi.provideUtility(IFactory, Foo2Factory, 'zope.source.Foo2')
self.vocab = SourceTypeVocabulary(None)
def test_Interface(self):
self.failUnless(IVocabulary.providedBy(self.vocab))
self.failUnless(IVocabularyTokenized.providedBy(self.vocab))
def test_contains(self):
self.failUnless('zope.source.Foo' in self.vocab)
self.failIf('zope.source.Foo3' in self.vocab)
def test_iter(self):
self.failUnless(
'zope.source.Foo' in [term.value for term in self.vocab])
self.failIf(
'zope.source.Foo3' in [term.value for term in iter(self.vocab)])
def test_len(self):
self.assertEqual(len(self.vocab), 2)
def test_getTerm(self):
self.assertEqual(self.vocab.getTerm('zope.source.Foo').title, 'Foo')
self.assertRaises(
LookupError, self.vocab.getTerm, ('zope.source.Foo3',))
def test_getTermByToken(self):
vocab = self.vocab
self.assertEqual(vocab.getTermByToken('zope.source.Foo').title, 'Foo')
self.assertRaises(
LookupError, vocab.getTermByToken, ('zope.source.Foo3',))
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(SourceTypeVocabularyTest),
))
if __name__ == '__main__':
unittest.main()
zope.app.renderer-3.5.1/src/zope/app/renderer/tests/test_renderers.py 0000644 0000764 0000764 00000002050 11221077621 026213 0 ustar srichter srichter ##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Renderer Tests
$Id: test_renderers.py 25177 2004-06-02 13:17:31Z jim $
"""
import unittest
from zope.testing.doctestunit import DocTestSuite
def test_suite():
return unittest.TestSuite((
DocTestSuite('zope.app.renderer.plaintext'),
DocTestSuite('zope.app.renderer.rest'),
DocTestSuite('zope.app.renderer.stx'),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
zope.app.renderer-3.5.1/src/zope/app/renderer/tests/__init__.py 0000644 0000764 0000764 00000000040 11221077621 024717 0 ustar srichter srichter # make this directory a package
zope.app.renderer-3.5.1/src/zope/app/renderer/plaintext.py 0000644 0000764 0000764 00000003764 11232115177 024047 0 ustar srichter srichter ##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Plain Text Renderer Classes
$Id: plaintext.py 94785 2009-01-17 12:54:26Z nadako $
"""
__docformat__ = 'restructuredtext'
import cgi
from zope.component import adapts
from zope.interface import implements
from zope.publisher.browser import BrowserView
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app.renderer.i18n import ZopeMessageFactory as _
from zope.app.renderer.interfaces import ISource, IHTMLRenderer
from zope.app.renderer import SourceFactory
class IPlainTextSource(ISource):
"""Marker interface for a plain text source. Note that an implementation
of this interface should always derive from unicode or behave like a
unicode class."""
PlainTextSourceFactory = SourceFactory(
IPlainTextSource, _("Plain Text"), _("Plain Text Source"))
class PlainTextToHTMLRenderer(BrowserView):
r"""A view to convert from Plain Text to HTML.
Example::
>>> from zope.publisher.browser import TestRequest
>>> source = PlainTextSourceFactory(u'I hear that 1 > 2.\n')
>>> renderer = PlainTextToHTMLRenderer(source, TestRequest())
>>> renderer.render()
u'I hear that 1 > 2.
\n'
"""
implements(IHTMLRenderer)
adapts(IPlainTextSource, IBrowserRequest)
def render(self):
"See zope.app.interfaces.renderer.IHTMLRenderer"
return cgi.escape(self.context).replace('\n', '
\n')
zope.app.renderer-3.5.1/src/zope/app/renderer/vocabulary.py 0000644 0000764 0000764 00000002267 11221077621 024202 0 ustar srichter srichter ##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Vocabulary for the Source Type Registry
$Id: vocabulary.py 67630 2006-04-27 00:54:03Z jim $
"""
import zope.component
from zope.interface import alsoProvides
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
from zope.schema.interfaces import IVocabularyFactory
from zope.app.renderer.interfaces import ISource
def SourceTypeVocabulary(context):
return SimpleVocabulary(
[SimpleTerm(name, title=factory.title) for name, factory in
zope.component.getFactoriesFor(ISource)])
alsoProvides(SourceTypeVocabulary, IVocabularyFactory)
zope.app.renderer-3.5.1/src/zope/app/renderer/interfaces.py 0000644 0000764 0000764 00000002712 11221077621 024151 0 ustar srichter srichter ##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Renderer Interface Declarations
The source renderer takes a special type of string, an ISource, and is able to
produce
$Id: interfaces.py 25177 2004-06-02 13:17:31Z jim $
"""
from zope.interface import Interface
class ISource(Interface):
"""Simple base interface for all possible Wiki Page Source types."""
class ISourceRenderer(Interface):
"""Object implementing this interface are responsible for rendering an
ISource objects to an output format.
This is the base class for all possible output types."""
def __init__(self, source):
"""Initialize the renderer.
The source argument is the source code that needs to be converted.
"""
def render():
"""Renders the source into another format."""
class IHTMLRenderer(ISourceRenderer):
"""Renders an ISource object to HTML."""
zope.app.renderer-3.5.1/src/zope/app/renderer/i18n.py 0000644 0000764 0000764 00000001653 11221077621 022610 0 ustar srichter srichter ##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Customization of zope.i18n for the Zope application server
$Id: i18n.py 73674 2007-03-27 07:52:12Z dobe $
"""
__docformat__ = 'restructuredtext'
# import this as _ to create i18n messages in the zope domain
from zope.i18nmessageid import MessageFactory
ZopeMessageFactory = MessageFactory('zope')
zope.app.renderer-3.5.1/src/zope/app/renderer/configure.zcml 0000644 0000764 0000764 00000002260 11221077621 024322 0 ustar srichter srichter
zope.app.renderer-3.5.1/src/zope/app/renderer/__init__.py 0000644 0000764 0000764 00000002557 11221077621 023574 0 ustar srichter srichter ##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Plain Text Renderer Classes
$Id: __init__.py 73674 2007-03-27 07:52:12Z dobe $
"""
from zope.component.interfaces import IFactory
from zope.interface import implements, directlyProvides, Declaration
from interfaces import ISource, IHTMLRenderer
class Source(unicode):
__provides__ = None
class SourceFactory(object):
"""Creates an ISource object."""
implements(IFactory)
def __init__(self, iface, title='', description=''):
self._iface = iface
self.title = title
self.description = description
def getInterfaces(self):
return Declaration(self._iface).flattened()
def __call__(self, ustr):
source = Source(ustr)
directlyProvides(source, self._iface)
return source
zope.app.renderer-3.5.1/src/zope/app/renderer/stx.py 0000644 0000764 0000764 00000005154 11232115177 022650 0 ustar srichter srichter ##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Structured Text Renderer Classes
$Id: stx.py 94785 2009-01-17 12:54:26Z nadako $
"""
__docformat__ = 'restructuredtext'
import re
from zope.component import adapts
from zope.interface import implements
from zope.structuredtext.document import Document
from zope.structuredtext.html import HTML
from zope.publisher.browser import BrowserView
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app.renderer.i18n import ZopeMessageFactory as _
from zope.app.renderer.interfaces import ISource, IHTMLRenderer
from zope.app.renderer import SourceFactory
class IStructuredTextSource(ISource):
"""Marker interface for a structured text source. Note that an
implementation of this interface should always derive from unicode or
behave like a unicode class."""
StructuredTextSourceFactory = SourceFactory(
IStructuredTextSource, _("Structured Text (STX)"),
_("Structured Text (STX) Source"))
class StructuredTextToHTMLRenderer(BrowserView):
r"""A view to convert from Plain Text to HTML.
Example::
>>> from zope.publisher.browser import TestRequest
>>> source = StructuredTextSourceFactory(u'This is source.')
>>> renderer = StructuredTextToHTMLRenderer(source, TestRequest())
>>> renderer.render()
u'This is source.
\n'
Make sure that unicode works as well::
>>> source = StructuredTextSourceFactory(u'This is \xc3\x9c.')
>>> renderer = StructuredTextToHTMLRenderer(source, TestRequest())
>>> renderer.render()
u'This is \xc3\x9c.
\n'
"""
implements(IHTMLRenderer)
adapts(IStructuredTextSource, IBrowserRequest)
def render(self):
"See zope.app.interfaces.renderer.IHTMLRenderer"
encoded = self.context.encode('UTF-8')
doc = Document()(encoded)
html = HTML()(doc)
# strip html & body added by some zope versions
html = re.sub(
r'(?sm)^\n(.*)