more Python3 fixes

This commit is contained in:
Helmut Merz 2024-09-27 08:40:20 +02:00
parent 992b5c012d
commit 010106406d
4 changed files with 17 additions and 40 deletions

View file

@ -52,9 +52,9 @@ some options.
>>> opt.useVersioning >>> opt.useVersioning
True True
>>> print opt >>> print(opt)
organize(tracking=['changes', 'access'])
useVersioning=True useVersioning=True
organize(tracking=['changes', 'access'])
If we query an option that is not defined on the site level we get a If we query an option that is not defined on the site level we get a
dummy element that corresponds to False. dummy element that corresponds to False.

View file

@ -2,8 +2,6 @@
loops - Linked Objects for Organization and Processing Services loops - Linked Objects for Organization and Processing Services
=============================================================== ===============================================================
($Id$)
Let's do some basic set up Let's do some basic set up
>>> from zope.app.testing.setup import placefulSetUp, placefulTearDown >>> from zope.app.testing.setup import placefulSetUp, placefulTearDown
@ -33,7 +31,7 @@ ZCML setup):
For testing and demonstration purposes let's create a topic. For testing and demonstration purposes let's create a topic.
>>> topic = concepts['topic'] >>> topic = concepts['topic']
>>> topic01 = concepts['topic01'] = Concept(u'loops for Zope 3') >>> topic01 = concepts['topic01'] = Concept('loops for Zope 3')
>>> topic01.conceptType = topic >>> topic01.conceptType = topic
@ -43,7 +41,7 @@ Content Internationalization
Let's look at a certain concept that should contain i18n-alized data. Let's look at a certain concept that should contain i18n-alized data.
>>> topic01.title >>> topic01.title
u'loops for Zope 3' 'loops for Zope 3'
We can query the available languages, the current language setting and We can query the available languages, the current language setting and
the default language using a LanguageInfo object that is similar to a view. the default language using a LanguageInfo object that is similar to a view.
@ -115,7 +113,7 @@ Now we are ready to enter a language-specific title.
>>> form.update() >>> form.update()
>>> topic01.title >>> topic01.title
I18NValue({'en': u'loops for Zope 3', 'it': u'loops per Zope 3'}) I18NValue({'it': 'loops per Zope 3', 'en': 'loops for Zope 3'})
If we access an i18n attribute via a view that is i18n-aware we get the If we access an i18n attribute via a view that is i18n-aware we get the
value corresponding to the language preferences that appear in the request. value corresponding to the language preferences that appear in the request.
@ -123,7 +121,7 @@ value corresponding to the language preferences that appear in the request.
>>> input = {'loops.language': 'it'} >>> input = {'loops.language': 'it'}
>>> view = ConceptView(topic01, TestRequest(form=input)) >>> view = ConceptView(topic01, TestRequest(form=input))
>>> view.title >>> view.title
u'loops per Zope 3' 'loops per Zope 3'
If there is no entry for the language given we get back the entry for If there is no entry for the language given we get back the entry for
the default language. the default language.
@ -131,24 +129,24 @@ the default language.
>>> input = {'loops.language': 'de'} >>> input = {'loops.language': 'de'}
>>> view = ConceptView(topic01, TestRequest(form=input)) >>> view = ConceptView(topic01, TestRequest(form=input))
>>> view.title >>> view.title
u'loops for Zope 3' 'loops for Zope 3'
There are also fallbacks - mainly for being able to access the title There are also fallbacks - mainly for being able to access the title
attribute in not i18n-aware contexts - that retrieve the value corresponding attribute in not i18n-aware contexts - that retrieve the value corresponding
to the default language at the time of the attribute creation. to the default language at the time of the attribute creation.
>>> topic01.title.getDefault() >>> topic01.title.getDefault()
u'loops for Zope 3' 'loops for Zope 3'
>>> str(topic01.title) >>> str(topic01.title)
'loops for Zope 3' 'loops for Zope 3'
>>> topic01.title.lower() >>> topic01.title.lower()
u'loops for zope 3' 'loops for zope 3'
Viewing translations Viewing translations
-------------------- --------------------
>>> view.adapted.translations() >>> view.adapted.translations()
{'en': u'loops for Zope 3', 'it': u'loops per Zope 3'} {'it': 'loops per Zope 3', 'en': 'loops for Zope 3'}
Fin de partie Fin de partie

View file

@ -2,8 +2,6 @@
loops.xmlrpc loops.xmlrpc
=============================================================== ===============================================================
($Id$)
Let's do some basic set up Let's do some basic set up
>>> from zope.app.testing.setup import placefulSetUp, placefulTearDown >>> from zope.app.testing.setup import placefulSetUp, placefulTearDown
@ -35,8 +33,8 @@ ZCML setup):
Let's look what setup has provided us with: Let's look what setup has provided us with:
>>> sorted(concepts) >>> sorted(concepts)
[u'domain', u'file', u'hasType', u'note', u'predicate', ['domain', 'file', 'hasType', 'note', 'predicate',
u'standard', u'textdocument', u'type'] 'standard', 'textdocument', 'type']
loops Traversal loops Traversal
@ -62,7 +60,7 @@ domain type concept (or the top-level type concept, if there is no domain type):
>>> obj >>> obj
<loops.rest.common.ConceptView object at ...> <loops.rest.common.ConceptView object at ...>
>>> obj.context.title >>> obj.context.title
u'Domain' 'Domain'
The traversal adapter returns a view that when called renders the The traversal adapter returns a view that when called renders the
representation of its context object: representation of its context object:

View file

@ -1,28 +1,9 @@
# # loops.rest.common
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Common stuff for REST (REpresentational State Transfer) views.
Common stuff for REST (REpresentational State Transfer) views.
$Id$
""" """
from zope.interface import implements from zope.interface import implementer
from zope.component import adapts from zope.component import adapts
from zope.publisher.interfaces.browser import IBrowserRequest, IBrowserPublisher from zope.publisher.interfaces.browser import IBrowserRequest, IBrowserPublisher
@ -39,11 +20,11 @@ class IRESTView(IBrowserPublisher):
""" """
@implementer(IRESTView)
class ConceptView(object): class ConceptView(object):
""" A REST view for a concept. """ A REST view for a concept.
""" """
implements(IRESTView)
adapts(IConcept, IBrowserRequest) adapts(IConcept, IBrowserRequest)
def __init__(self, context, request): def __init__(self, context, request):