Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config with pure python template #15

Merged
merged 4 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ jobs:
config:
# [Python version, tox env]
- ["3.9", "lint"]
- ["2.7", "py27"]
- ["3.5", "py35"]
- ["3.6", "py36"]
- ["3.7", "py37"]
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
- ["3.11", "py311"]
- ["pypy-2.7", "pypy"]
- ["pypy-3.7", "pypy3"]
- ["pypy-3.9", "pypy3"]
- ["3.9", "docs"]
- ["3.9", "coverage"]

Expand Down Expand Up @@ -60,7 +56,7 @@ jobs:
- name: Coverage
if: matrix.config[1] == 'coverage'
run: |
pip install coveralls coverage-python-version
pip install coveralls
coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 1 addition & 2 deletions .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
[meta]
template = "pure-python"
commit-id = "200573eb414d2228d463da3de7d71a6d6335a704"
commit-id = "487d9939"

[python]
with-windows = false
with-pypy = true
with-future-python = false
with-legacy-python = true
with-docs = true
with-sphinx-doctests = false
with-macos = false
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
Changes
=========

4.4 (unreleased)
5.0 (unreleased)
================

- Drop support for Python 2.7, 3.5, 3.6.

- Add support for Python 3.11.


Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
[bdist_wheel]
universal = 1
universal = 0

[flake8]
doctests = 1
Expand All @@ -16,7 +16,7 @@ ignore =
force_single_line = True
combine_as_imports = True
sections = FUTURE,STDLIB,THIRDPARTY,ZOPE,FIRSTPARTY,LOCALFOLDER
known_third_party = six, docutils, pkg_resources
known_third_party = six, docutils, pkg_resources, pytz
known_zope =
known_first_party =
default_section = ZOPE
Expand Down
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def read(*rnames):
]

setup(name='zope.viewlet',
version='4.4.dev0',
version='5.0.dev0',
author='Zope Foundation and Contributors',
author_email='[email protected]',
description='Zope Viewlets',
Expand All @@ -52,11 +52,7 @@ def read(*rnames):
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
Expand All @@ -74,6 +70,7 @@ def read(*rnames):
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope'],
python_requires='>=3.7',
extras_require={
'test': TESTS_REQUIRE,
'docs': [
Expand Down
20 changes: 10 additions & 10 deletions src/zope/viewlet/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ So initially nothing gets rendered:

>>> leftColumn.update()
>>> leftColumn.render()
u''
''

But now we register some :class:`viewlets
<zope.viewlet.interfaces.IViewlet>` for the manager:
Expand All @@ -93,7 +93,7 @@ But now we register some :class:`viewlets
... pass
...
... def render(self):
... return u'<div class="box">It is sunny today!</div>'
... return '<div class="box">It is sunny today!</div>'
...
... def __repr__(self):
... return '<WeatherBox object at %x>' % id(self)
Expand Down Expand Up @@ -121,7 +121,7 @@ But now we register some :class:`viewlets
... pass
...
... def render(self):
... return u'<div class="box">Patriots (23) : Steelers (7)</div>'
... return '<div class="box">Patriots (23) : Steelers (7)</div>'

>>> defineChecker(SportBox, viewletChecker)

Expand Down Expand Up @@ -188,7 +188,7 @@ If a viewlet provides :class:`zope.location.interfaces.ILocation` the
the viewlet is registered.

>>> [getattr(viewlet, '__name__', None) for viewlet in leftColumn.viewlets]
[u'sport', None]
['sport', None]


You can also lookup the viewlets directly for management purposes:
Expand Down Expand Up @@ -323,26 +323,26 @@ Let's create some viewlets:
... weight = 1
...
... def render(self):
... return u'<div>first</div>'
... return '<div>first</div>'

>>> class SecondViewlet(viewlet.ViewletBase):
...
... weight = 2
...
... def render(self):
... return u'<div>second</div>'
... return '<div>second</div>'

>>> class ThirdViewlet(viewlet.ViewletBase):
...
... weight = 3
...
... def render(self):
... return u'<div>third</div>'
... return '<div>third</div>'

>>> class UnWeightedViewlet(viewlet.ViewletBase):
...
... def render(self):
... return u'<div>unweighted</div>'
... return '<div>unweighted</div>'

>>> defineChecker(FirstViewlet, viewletChecker)
>>> defineChecker(SecondViewlet, viewletChecker)
Expand Down Expand Up @@ -431,7 +431,7 @@ weight and or no available attribute:
... available = True
...
... def render(self):
... return u'<div>available</div>'
... return '<div>available</div>'

>>> class UnAvailableViewlet(viewlet.ViewletBase):
...
Expand All @@ -440,7 +440,7 @@ weight and or no available attribute:
... available = False
...
... def render(self):
... return u'<div>not available</div>'
... return '<div>not available</div>'

>>> defineChecker(AvailableViewlet, viewletChecker)
>>> defineChecker(UnAvailableViewlet, viewletChecker)
Expand Down
20 changes: 10 additions & 10 deletions src/zope/viewlet/directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Now let's lookup the manager. This particular registration is pretty boring:
True
>>> manager.update()
>>> manager.render()
u''
''

However, this registration is not very useful, since we did specify a specific
viewlet manager interface, a specific content interface, specific view or
Expand Down Expand Up @@ -95,7 +95,7 @@ Now we can register register a manager providing this interface:
True
>>> manager.update()
>>> manager.render()
u''
''

Next let's see what happens, if we specify a template for the viewlet manager:

Expand Down Expand Up @@ -224,9 +224,9 @@ If we look into the adapter registry, we will find the viewlet:
... (content, request, view, manager), interfaces.IViewlet,
... name='weather')
>>> viewlet.render().strip()
u'<div>sunny</div>'
'<div>sunny</div>'
>>> viewlet.extra_string_attributes
u'can be specified'
'can be specified'

The manager now also gives us the output of the one and only viewlet:

Expand Down Expand Up @@ -260,15 +260,15 @@ Let's now ensure that we can also specify a viewlet class:
... (content, request, view, manager), interfaces.IViewlet,
... name='weather2')
>>> viewlet().strip()
u'<div>sunny</div>'
'<div>sunny</div>'

Okay, so the template-driven cases work. But just specifying a class should
also work:

>>> class Sport(object):
... weight = 0
... def __call__(self):
... return u'Red Sox vs. White Sox'
... return 'Red Sox vs. White Sox'

>>> context = xmlconfig.string('''
... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope">
Expand All @@ -285,15 +285,15 @@ also work:
>>> viewlet = zope.component.getMultiAdapter(
... (content, request, view, manager), interfaces.IViewlet, name='sport')
>>> viewlet()
u'Red Sox vs. White Sox'
'Red Sox vs. White Sox'

It should also be possible to specify an alternative attribute of the class to
be rendered upon calling the viewlet:

>>> class Stock(object):
... weight = 0
... def getStockTicker(self):
... return u'SRC $5.19'
... return 'SRC $5.19'

>>> context = xmlconfig.string('''
... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope">
Expand All @@ -312,7 +312,7 @@ be rendered upon calling the viewlet:
... (content, request, view, manager), interfaces.IViewlet,
... name='stock')
>>> viewlet.render()
u'SRC $5.19'
'SRC $5.19'

If the class mentions that it implements any interfaces using the
old-fashioned style, the resulting viewlet will
Expand Down Expand Up @@ -358,7 +358,7 @@ specification of any number of keyword arguments:
... (content, request, view, manager), interfaces.IViewlet,
... name='stock2')
>>> viewlet.weight
u'8'
'8'


Error Scenarios
Expand Down
6 changes: 3 additions & 3 deletions src/zope/viewlet/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


@zope.interface.implementer(interfaces.IViewletManager)
class ViewletManagerBase(object):
class ViewletManagerBase:
"""The Viewlet Manager Base

A generic manager class which can be instantiated.
Expand Down Expand Up @@ -177,7 +177,7 @@ def render(self):
# Now render the view
if self.template:
return self.template(viewlets=self.viewlets)
return u'\n'.join([viewlet.render() for viewlet in self.viewlets])
return '\n'.join([viewlet.render() for viewlet in self.viewlets])


def ViewletManager(name, interface, template=None, bases=()):
Expand Down Expand Up @@ -234,7 +234,7 @@ def render(self):
"""
# do not render a manager template if no viewlets are avaiable
if not self.viewlets:
return u''
return ''
return ViewletManagerBase.render(self)


Expand Down
10 changes: 5 additions & 5 deletions src/zope/viewlet/metadirectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class IContentProvider(Interface):
required=True)

for_ = zope.configuration.fields.GlobalObject(
title=u"The interface or class this view is for.",
title="The interface or class this view is for.",
required=False
)

permission = Permission(
title=u"Permission",
description=u"The permission needed to use the view.",
title="Permission",
description="The permission needed to use the view.",
required=True
)

Expand Down Expand Up @@ -151,8 +151,8 @@ class IViewletDirective(ITemplatedContentProvider):

manager = zope.configuration.fields.GlobalObject(
title=_("view"),
description=u"The interface of the view this viewlet is for. "
u"(default IBrowserView)",
description="The interface of the view this viewlet is for. "
"(default IBrowserView)",
required=False,
default=interfaces.IViewletManager)

Expand Down
Loading