Commit b56d8b5e authored by Tres Seaver's avatar Tres Seaver

ReST twiddling.

parent baab4718
============================
Environmental Acquisiton Environmental Acquisiton
============================ ========================
This package implements "environmental acquisiton" for Python, as This package implements "environmental acquisiton" for Python, as
proposed in `1996 OOPSLA paper by Joseph Gil and David H. Lorenz proposed in the OOPSLA96_ paper by Joseph Gil and David H. Lorenz:
http://www.cs.virginia.edu/~lorenz/papers/oopsla96/>`_:
We propose a new programming paradigm, environmental acquisition in We propose a new programming paradigm, environmental acquisition in
the context of object aggregation, in which objects acquire the context of object aggregation, in which objects acquire
...@@ -18,10 +16,12 @@ http://www.cs.virginia.edu/~lorenz/papers/oopsla96/>`_: ...@@ -18,10 +16,12 @@ http://www.cs.virginia.edu/~lorenz/papers/oopsla96/>`_:
composite. These relationships are the basis for language constructs composite. These relationships are the basis for language constructs
that supports acquisition. that supports acquisition.
.. _OOPSLA96: http://www.cs.virginia.edu/~lorenz/papers/oopsla96/>`_:
.. contents:: .. contents::
Introductory Example Introductory Example
==================== --------------------
Zope implements acquisition with "Extension Class" mix-in classes. To Zope implements acquisition with "Extension Class" mix-in classes. To
use acquisition your classes must inherit from an acquisition base use acquisition your classes must inherit from an acquisition base
...@@ -30,7 +30,7 @@ class. For example:: ...@@ -30,7 +30,7 @@ class. For example::
>>> import ExtensionClass, Acquisition >>> import ExtensionClass, Acquisition
>>> class C(ExtensionClass.Base): >>> class C(ExtensionClass.Base):
... color='red' ... color = 'red'
>>> class A(Acquisition.Implicit): >>> class A(Acquisition.Implicit):
... def report(self): ... def report(self):
...@@ -63,7 +63,7 @@ environment, where its environment is defined by the access path used ...@@ -63,7 +63,7 @@ environment, where its environment is defined by the access path used
to reach ``a``. to reach ``a``.
Acquisition Wrappers Acquisition Wrappers
==================== --------------------
When an object that supports acquisition is accessed through an When an object that supports acquisition is accessed through an
extension class instance, a special object, called an acquisition extension class instance, a special object, called an acquisition
...@@ -82,7 +82,7 @@ example from above:: ...@@ -82,7 +82,7 @@ example from above::
True True
Explicit and Implicit Acquisition Explicit and Implicit Acquisition
================================= ---------------------------------
Two styles of acquisition are supported: implicit and explicit Two styles of acquisition are supported: implicit and explicit
acquisition. acquisition.
...@@ -123,10 +123,10 @@ all attributes that should be acquired to the special value ...@@ -123,10 +123,10 @@ all attributes that should be acquired to the special value
inherited attributes to be overridden with acquired ones. For example:: inherited attributes to be overridden with acquired ones. For example::
>>> class C(Acquisition.Explicit): >>> class C(Acquisition.Explicit):
... id=1 ... id = 1
... secret=2 ... secret = 2
... color=Acquisition.Acquired ... color = Acquisition.Acquired
... __roles__=Acquisition.Acquired ... __roles__ = Acquisition.Acquired
The only attributes that are automatically acquired from containing The only attributes that are automatically acquired from containing
objects are color, and ``__roles__``. Note that the ``__roles__`` objects are color, and ``__roles__``. Note that the ``__roles__``
...@@ -141,7 +141,7 @@ aq_explicit attribute. This attribute provides the object with an ...@@ -141,7 +141,7 @@ aq_explicit attribute. This attribute provides the object with an
explicit wrapper that replaces the original implicit wrapper. explicit wrapper that replaces the original implicit wrapper.
Filtered Acquisition Filtered Acquisition
==================== --------------------
The acquisition method, ``aq_acquire``, accepts two optional The acquisition method, ``aq_acquire``, accepts two optional
arguments. The first of the additional arguments is a "filtering" arguments. The first of the additional arguments is a "filtering"
...@@ -178,10 +178,10 @@ Here's an example:: ...@@ -178,10 +178,10 @@ Here's an example::
>>> class E(Explicit, HandyForTesting): pass >>> class E(Explicit, HandyForTesting): pass
... ...
>>> class Nice(HandyForTesting): >>> class Nice(HandyForTesting):
... isNice= 1 ... isNice = 1
... def __str__(self): ... def __str__(self):
... return HandyForTesting.__str__(self)+' and I am nice!' ... return HandyForTesting.__str__(self)+' and I am nice!'
... __repr__=__str__ ... __repr__ = __str__
... ...
>>> a = E('a') >>> a = E('a')
>>> a.b = E('b') >>> a.b = E('b')
...@@ -202,7 +202,7 @@ satisfy the condition given in the filter. ...@@ -202,7 +202,7 @@ satisfy the condition given in the filter.
Filtered acquisition is rarely used in Zope. Filtered acquisition is rarely used in Zope.
Acquiring from Context Acquiring from Context
====================== ----------------------
Normally acquisition allows objects to acquire data from their Normally acquisition allows objects to acquire data from their
containers. However an object can acquire from objects that aren't its containers. However an object can acquire from objects that aren't its
...@@ -252,7 +252,7 @@ Here acquisition context is defined by the objects used to access ...@@ -252,7 +252,7 @@ Here acquisition context is defined by the objects used to access
another object. another object.
Containment Before Context Containment Before Context
========================== --------------------------
If in the example above suppose both a and b have an color attribute:: If in the example above suppose both a and b have an color attribute::
...@@ -294,7 +294,7 @@ found in ``g`` or any of its containers, then the search moves to ...@@ -294,7 +294,7 @@ found in ``g`` or any of its containers, then the search moves to
``f`` and all its containers, and so on. ``f`` and all its containers, and so on.
Additional Attributes and Methods Additional Attributes and Methods
================================= ---------------------------------
You can use the special method ``aq_inner`` to access an object You can use the special method ``aq_inner`` to access an object
wrapped only by containment. So in the example above, wrapped only by containment. So in the example above,
...@@ -322,7 +322,7 @@ object using the ``aq_inContextOf`` method. For example: ...@@ -322,7 +322,7 @@ object using the ``aq_inContextOf`` method. For example:
just need to get to it). just need to get to it).
Acquisition Module Functions Acquisition Module Functions
============================ ----------------------------
In addition to using acquisition attributes and methods directly on In addition to using acquisition attributes and methods directly on
objects you can use similar functions defined in the ``Acquisition`` objects you can use similar functions defined in the ``Acquisition``
...@@ -409,7 +409,7 @@ In most cases it is more convenient to use these module functions ...@@ -409,7 +409,7 @@ In most cases it is more convenient to use these module functions
instead of the acquisition attributes and methods directly. instead of the acquisition attributes and methods directly.
Acquisition and Methods Acquisition and Methods
======================= -----------------------
Python methods of objects that support acquisition can use acquired Python methods of objects that support acquisition can use acquired
attributes. When a Python method is called on an object that is attributes. When a Python method is called on an object that is
...@@ -424,7 +424,7 @@ structures expected by these methods. In practice, you will seldom ...@@ -424,7 +424,7 @@ structures expected by these methods. In practice, you will seldom
find this a problem. find this a problem.
Conclusion Conclusion
========== ----------
Acquisition provides a powerful way to dynamically share information Acquisition provides a powerful way to dynamically share information
between objects. Zope 2 uses acquisition for a number of its key between objects. Zope 2 uses acquisition for a number of its key
......
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