Skip to content

Commit

Permalink
Merge in changes in Zope-2_8-branch from revision 37686 till "now" (a…
Browse files Browse the repository at this point in the history
…s recorded in Zope/branches/lra-userid_username_separation-branchpoints/Zope-2_8-20050809-1700).

If additional merges from Zope-2_8-branch are needed, take the difference from lra-userid_username_separation-branchpoints/Zope-2_8-20050809-1700
  • Loading branch information
leorochael committed Aug 9, 2005
2 parents 3ac7e92 + c1b1adb commit bb59ccd
Show file tree
Hide file tree
Showing 13 changed files with 739 additions and 82 deletions.
19 changes: 19 additions & 0 deletions doc/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,27 @@ Zope Changes

after Zope 2.8.1 b1

Features added

- Interface: Added Z3 -> Z2 bridge utilities.
This allows to migrate interfaces to Zope 3 style interfaces and
bridge them back to oldstyle interfaces for backwards compatibility.

Bugs Fixed

- Enhance userid/username separation on ZMI screens:
manage_owner now displays the username instead of the userid and
local roles management functions (manage_{add,set,del}LocalRoles)
now lookup the userid if they get a username.

- Zope2.Startup.zopectl: fork before execv when running unit tests
(don't exit the shell, if run from there).

- TAL: MassageIDs are now handled the same way as in zope.tal.

- DocumentTemplate: ustr no longer mangles MassageIDs.
Custom string types are now returned unchanged.

- As developed in a long thread starting at
http://mail.zope.org/pipermail/zope/2005-July/160433.html
there appears to be a race bug in the Microsoft Windows socket
Expand Down
37 changes: 25 additions & 12 deletions lib/python/DocumentTemplate/tests/testustr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
# 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
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Document Template Tests
"""
"""ustr unit tests.
__rcs_id__='$Id$'
__version__='$Revision: 1.3 $'[11:-2]
$Id$
"""

import sys, os
import unittest

from DocumentTemplate.ustr import ustr
from ExtensionClass import Base


class force_str:
# A class whose string representation is not always a plain string:
Expand All @@ -29,7 +27,18 @@ def __init__(self,s):
def __str__(self):
return self.s

class UnicodeTests (unittest.TestCase):

class Foo(str):

pass


class Bar(unicode):

pass


class UnicodeTests(unittest.TestCase):

def testPlain(self):
a = ustr('hello')
Expand Down Expand Up @@ -59,13 +68,17 @@ def testExceptions(self):
a = ustr(ValueError(unichr(200)))
assert a==unichr(200), `a`

def testCustomStrings(self):
a = ustr(Foo('foo'))
self.failUnlessEqual(type(a), Foo)
a = ustr(Bar('bar'))
self.failUnlessEqual(type(a), Bar)


def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( UnicodeTests ) )
return suite

def main():
unittest.TextTestRunner().run(test_suite())

if __name__ == '__main__':
main()
unittest.main(defaultTest='test_suite')
12 changes: 6 additions & 6 deletions lib/python/DocumentTemplate/ustr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
# 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
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""ustr function.
from types import StringType, UnicodeType, InstanceType
$Id$
"""

nasty_exception_str = Exception.__str__.im_func

Expand All @@ -20,8 +22,7 @@ def ustr(v):
minimising the chance of raising a UnicodeError. This
even works with uncooperative objects like Exceptions
"""
string_types = (StringType,UnicodeType)
if type(v) in string_types:
if isinstance(v, basestring):
return v
else:
fn = getattr(v,'__str__',None)
Expand All @@ -41,7 +42,7 @@ def ustr(v):
else:
# Trust the object to do this right
v = fn()
if type(v) in string_types:
if isinstance(v, basestring):
return v
else:
raise ValueError('__str__ returned wrong type')
Expand All @@ -59,4 +60,3 @@ def _exception_str(exc):
else:
return str(exc.args)
return str(exc)

99 changes: 99 additions & 0 deletions lib/python/Interface/bridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
##############################################################################
#
# Copyright (c) 2005 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.
#
##############################################################################
""" Z3 -> Z2 bridge utilities.
$Id$
"""
from Interface._InterfaceClass import Interface as Z2_InterfaceClass
from Interface import Interface as Z2_Interface
from Interface import Attribute as Z2_Attribute
from Interface.Method import Method as Z2_Method

from zope.interface.interface import InterfaceClass as Z3_InterfaceClass
from zope.interface.interface import Interface as Z3_Interface
from zope.interface.interface import Attribute as Z3_Attribute
from zope.interface.interface import Method as Z3_Method

_bridges = {Z3_Interface: Z2_Interface}

def fromZ3Interface(z3i):
""" Return a Zope 2 interface corresponding to 'z3i'.
o 'z3i' must be a Zope 3 interface.
"""
if not isinstance(z3i, Z3_InterfaceClass):
raise ValueError, 'Not a Zope 3 interface!'

if z3i in _bridges:
return _bridges[z3i]

name = z3i.getName()
bases = [ fromZ3Interface(x) for x in z3i.getBases() ]
attrs = {}

for k, v in z3i.namesAndDescriptions():
if isinstance(v, Z3_Method):
v = fromZ3Method(v)

elif isinstance(v, Z3_Attribute):
v = fromZ3Attribute(v)

attrs[k] = v

# XXX: Note that we pass the original interface's __module__;
# we may live to regret that.
z2i = Z2_InterfaceClass(name=name,
bases=tuple(bases),
attrs=attrs,
__doc__=z3i.getDoc(),
__module__=z3i.__module__)
_bridges[z3i] = z2i
return z2i

def fromZ3Attribute(z3a):
""" Return a Zope 2 interface attribute corresponding to 'z3a'.
o 'z3a' must be a Zope 3 interface attribute.
"""
if not isinstance(z3a, Z3_Attribute):
raise ValueError, 'Not a Zope 3 interface attribute!'

return Z2_Attribute(z3a.getName(), z3a.getDoc())

def fromZ3Method(z3m):
""" Return a Zope 2 interface method corresponding to 'z3m'.
o 'z3m' must be a Zope 3 interface method.
"""
if not isinstance(z3m, Z3_Method):
raise ValueError, 'Not a Zope 3 interface method!'

z2m = Z2_Method(z3m.getName(), z3m.getDoc())
sig = z3m.getSignatureInfo()
z2m.positional = sig['positional']
z2m.required = sig['required']
z2m.optional = sig['optional']
z2m.varargs = sig['varargs']
z2m.kwargs = sig['kwargs']
return z2m

def createZope3Bridge(zope3, package, name):
# Map a Zope 3 interface into a Zope2 interface, seated within 'package'
# as 'name'.
z2i = fromZ3Interface(zope3)

if name is not None:
z2i.__dict__['__name__'] = name

z2i.__dict__['__module__'] = package.__name__
setattr(package, z2i.getName(), z2i)
Loading

0 comments on commit bb59ccd

Please sign in to comment.