Commit 192e490e authored by Ken Manheimer's avatar Ken Manheimer

Replace faulty references that had the (previously unnoticed!)

multiply rendered example sections.
parent 8d0ee8fc
......@@ -38,36 +38,6 @@
</PRE>
<p> The <a href="ExtensionClass.html">ExtensionClass</a>. release includes mix-in
extension base classes that can be used to add acquisition as a
feature to extension subclasses. These mix-in classes use the
context-wrapping feature of ExtensionClasses to implement
acquisition. Consider the following example::</p>
<p> import ExtensionClass, Acquisition</p>
<p> class C(ExtensionClass.Base):
color='red'</p>
<p> class A(Acquisition.Implicit):</p>
<p> def report(self):
print self.color</p>
<p> a=A()
c=C()
c.a=A()</p>
<p> c.a.report() # prints <code>red</code></p>
<p> d=C()
d.color='green'
d.a=a</p>
<p> d.a.report() # prints <code>green</code></p>
<p> a.report() # raises an attribute error</p>
<p> The class <code>A</code> inherits acquisition behavior from
<code>Acquisition.Implicit</code>. The object, <code>a</code>, "has" the color of
objects <code>c</code> and <code>d</code> when it is accessed through them, but it
......@@ -92,32 +62,18 @@
</PRE>
<p> Aquisition wrappers provide access to the wrapped objects
through the attributes <code>aq_parent</code>, <code>aq_self</code>, <code>aq_base</code>.
In the example above, the expressions::</p>
<p> <code>c.a.aq_parent is c</code></p>
<p> and:</p>
<PRE>
'c.a.aq_self is a'
</PRE>
<p> and::</p>
<p> <code>c.a.aq_self is a</code></p>
<p> both evaluate to true, but the expression:</p>
<PRE>
'c.a is a'
</PRE>
<p> both evaluate to true, but the expression::</p>
<p> <code>c.a is a</code></p>
<p> evaluates to false, because the expression <code>c.a</code> evaluates
to an acquisition wrapper around <code>c</code> and <code>a</code>, not <code>a</code> itself.</p>
......@@ -152,12 +108,6 @@
</PRE>
<p> When explicit acquisition is used, attributes are not
automatically obtained from the environment. Instead, the
method <code>aq_aquire</code> must be used, as in::</p>
<p> print c.a.aq_acquire(<code>color</code>)</p>
<p> To support explicit acquisition, an object should inherit
from the mix-in class <code>Acquisition.Explicit</code>.</p>
......@@ -183,14 +133,6 @@
</PRE>
<p> For example, in::</p>
<p> class C(Acquisition.Explicit):
id=1
secret=2
color=Acquisition.Acquired
__roles__=Acquisition.Acquired</p>
<p> The <em>only</em> attributes that are automatically acquired from
containing objects are <code>color</code>, and <code>__roles__</code>. Note also
that the <code>__roles__</code> attribute is acquired even though it's
......@@ -261,35 +203,6 @@
</PRE>
<p> For example, in::</p>
<p> from Acquisition import Explicit</p>
<p> class HandyForTesting:
def __init__(self, name): self.name=name
def __str__(self):
return "%s(%s)" % (self.name, self.__class__.__name__)
__repr__=__str__</p>
<p> class E(Explicit, HandyForTesting): pass</p>
<p> class Nice(HandyForTesting):
isNice=1
def __str__(self):
return HandyForTesting.__str__(self)+' and I am nice!'
__repr__=__str__</p>
<p> a=E(<code>a</code>)
a.b=E(<code>b</code>)
a.b.c=E(<code>c</code>)
a.p=Nice(<code>spam</code>)
a.b.p=E(<code>p</code>)</p>
<p> def find_nice(self, ancestor, name, object, extra):
return hasattr(object,'isNice') and object.isNice</p>
<p> print a.b.c.aq_acquire(<code>p</code>, find_nice)</p>
<p> The filtered acquisition in the last line skips over the first
attribute it finds with the name <code>p</code>, because the attribute
doesn't satisfy the condition given in the filter. The output of
......@@ -299,13 +212,6 @@
</PRE>
<p> The filtered acquisition in the last line skips over the first
attribute it finds with the name <code>p</code>, because the attribute
doesn't satisfy the condition given in the filter. The output of
the last line is::</p>
<p> spam(Nice) and I am nice!</p>
<h2>Acquisition and methods</h2>
......@@ -346,26 +252,6 @@
</PRE>
<p> Consider the following example::</p>
<p> from Acquisition import Implicit</p>
<p> class C(Implicit):
def __init__(self, name): self.name=name
def __str__(self):
return "%s(%s)" % (self.name, self.__class__.__name__)
__repr__=__str__</p>
<p> a=C("a")
a.b=C("b")
a.b.pref="spam"
a.b.c=C("c")
a.b.c.color="red"
a.b.c.pref="eggs"
a.x=C("x")</p>
<p> o=a.b.c.x</p>
<p> The expression <code>o.color</code> might be expected to return <code>"red"</code>. In
earlier versions of ExtensionClass, however, this expression
failed. Acquired acquiring objects did not acquire from the
......
......@@ -330,16 +330,6 @@
</PRE>
<p> Attribute lookup is performed by calling the base extension class
<code>getattr</code> operation for the base extension class that includes C
data, or for the first base extension class, if none of the base
extension classes include C data. <code>ExtensionClass.h</code> defines a
macro <code>Py_FindAttrString</code> that can be used to find an object's
attributes that are stored in the object's instance dictionary or
in the object's class or base classes::</p>
<p> v = Py_FindAttrString(self,name);</p>
<p> where <code>name</code> is a C string containing the attribute name.</p>
<p> In addition, a macro is provided that replaces <code>Py_FindMethod</code>
......@@ -405,22 +395,6 @@
</PRE>
<p> A problem occurs when trying to overide methods inherited from
Python base classes. Consider the following example::</p>
<p> from ExtensionClass import Base</p>
<p> class Spam:</p>
<p> def __init__(self, name):
self.name=name</p>
<p> class ECSpam(Base, Spam):</p>
<p> def __init__(self, name, favorite_color):
Spam.__init__(self,name)
self.favorite_color=favorite_color</p>
<p> This implementation will fail when an <code>ECSpam</code> object is
instantiated. The problem is that <code>ECSpam.__init__</code> calls
<code>Spam.__init__</code>, and <code>Spam.__init__</code> can only be called with a
......@@ -449,25 +423,6 @@
</PRE>
<p> To overcome this problem, extension classes provide a class method
<code>inheritedAttribute</code> that can be used to obtain an inherited
attribute that is suitable for calling with an extension class
instance. Using the <code>inheritedAttribute</code> method, the above
example can be rewritten as::</p>
<p> from ExtensionClass import Base</p>
<p> class Spam:</p>
<p> def __init__(self, name):
self.name=name</p>
<p> class ECSpam(Base, Spam):</p>
<p> def __init__(self, name, favorite_color):
ECSpam.inheritedAttribute(<code>__init__</code>)(self,name)
self.favorite_color=favorite_color</p>
<p> This isn't as pretty but does provide the desired result.</p>
......@@ -529,29 +484,6 @@
</PRE>
<p> Consider the following example::</p>
<p> import ExtensionClass</p>
<p> class CustomMethod(ExtensionClass.Base):</p>
<p> def __call__(self,ob):
print <code>a %s was called</code> % ob.__class__.__name__</p>
<p> class wrapper:</p>
<p> def __init__(self,m,o): self.meth, self.ob=m,o</p>
<p> def __call__(self): self.meth(self.ob)</p>
<p> def __of__(self,o): return self.wrapper(self,o)</p>
<p> class bar(ExtensionClass.Base):
hi=CustomMethod()</p>
<p> x=bar()
hi=x.hi()</p>
<p> Note that <code>ExtensionClass.Base</code> is a base extension class that
provides very basic ExtensionClass behavior. </p>
......@@ -651,23 +583,6 @@
</PRE>
<p> For example::</p>
<p> class C(ExtensionClass.Base):</p>
<p> def get_secret(self):
"Get a secret"
....</p>
<p> c=C()</p>
<p> c.f.__roles__=['Trusted People']</p>
<p> print c.f.__roles__ # outputs ['Trusted People']
print c.f__roles__ # outputs ['Trusted People']</p>
<p> print C.f.__roles__ # fails, unbound method</p>
<p> A bound method attribute is set by setting an attribute in it's
instance with a name consisting of the concatination of the
method's <code>__name__</code> attribute and the attribute name.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment