Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
d45bf98e
Commit
d45bf98e
authored
Apr 10, 2005
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a test for proper __of__ handling.
parent
c2e64d2d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
1 deletion
+52
-1
lib/python/ZClasses/_pmc.txt
lib/python/ZClasses/_pmc.txt
+52
-1
No files found.
lib/python/ZClasses/_pmc.txt
View file @
d45bf98e
...
...
@@ -279,5 +279,56 @@ share the same class:
True
__of__
======
Extension Classes define a special method __of__. Extension classes
that define __of__ attributes are treated as read descriptors and the
__of__ method is also used as a __get__ methods.
Let's look at an example.
>>> from ExtensionClass import Base
>>> class Named(Base):
... def __init__(self, name):
... self.name = name
... def __repr__(self):
... return self.name
>>> class WithOf(Named):
... def __of__(self, parent):
... print '__of__', self, parent
... return self
>>> n = Named('n')
>>> n.w = WithOf('w')
>>> w = n.w
__of__ w n
We see that __of__ was called when we did the getattr. Now let's try a
persistent version:
>>> C = connection.root()['C']
>>> class PersistentWithOf(C, WithOf):
... pass
>>> n.w = PersistentWithOf('pw')
>>> w = n.w
__of__ pw n
(We reloaded C from the connection we were going to use.)
Now we'll save our class in the database and reload it:
>>> connection.root()['PW'] = PersistentWithOf
>>> tm.commit()
>>> connection2.sync()
>>> PW = connection2.root()['PW']
And the class loaded from the database will have the same behavior:
>>> n.w = PW('pw2')
>>> w = n.w
__of__ pw2 n
XXX test abort of import
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment