<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <h1 class="pudge-member-page-heading"> <tt>boundattributes</tt> </h1> <h4 class="pudge-member-page-subheading"> Bound attributes are attributes that are bound to a specific class and a specific name. In SQLObject a typical example is a column object, which knows its name and class. </h4> <p class="pudge-member-parent-link"> <small> The boundattributes module is accessible via the <a href="module-sqlobject.html"> <tt>sqlobject</tt> </a> module. </small> </p> <div id="pudge-section-nav"> <ul> <li> <a href="#attributes" class="pudge-section-link"> Attributes (1) </a> </li><li> <span class="pudge-missing-section-link"> Functions </span> </li><li> <a href="#classes" class="pudge-section-link"> Classes (2) </a> </li><li> <span class="pudge-missing-section-link"> Modules </span> </li> <li> <a href="module-sqlobject.boundattributes-index.html" class="pudge-section-link"> Index </a> </li> <li> <a href="sqlobject/boundattributes.py.html" class="pudge-section-link"> Source </a> </li> </ul> </div> <div style="clear: left"></div> <div class="rst pudge-module-doc"> <p>A bound attribute should define a method <tt class="docutils literal">__addtoclass__(added_class, name)</tt> (attributes without this method will simply be treated as normal). The return value is ignored; if the attribute wishes to change the value in the class, it must call <tt class="docutils literal">setattr(added_class, name, new_value)</tt>.</p> <p>BoundAttribute is a class that facilitates lazy attribute creation.</p> <p><tt class="docutils literal">bind_attributes(cls, new_attrs)</tt> is a function that looks for attributes with this special method. <tt class="docutils literal">new_attrs</tt> is a dictionary, as typically passed into <tt class="docutils literal">__classinit__</tt> with declarative (calling <tt class="docutils literal">bind_attributes</tt> in <tt class="docutils literal">__classinit__</tt> would be typical).</p> <p>Note if you do this that attributes defined in a superclass will not be rebound in subclasses. If you want to rebind attributes in subclasses, use <tt class="docutils literal">bind_attributes_local</tt>, which adds a <tt class="docutils literal">__bound_attributes__</tt> variable to your class to track these active attributes.</p> </div> <hr> <a name="attributes"></a> <h2>Attributes</h2> <div class="pudge-member name"> <a name="__package__"></a> <h4 class="pudge-member-name"><span class="prefix">a</span> <tt><a href="module-sqlobject.boundattributes.html#__package__" class="pudge-obj-link">__package__</a></tt></h4> <div class="pudge-section rst"> <pre>'sqlobject'</pre> </div> </div> <a name="classes"></a> <h2>Classes</h2> <div class="pudge-member class "> <h4 class="pudge-member-name"><span class="prefix">C</span> <tt> <a href="class-sqlobject.boundattributes.BoundAttribute.html" class="pudge-obj-link">BoundAttribute</a>(...)</tt> <a href="sqlobject/boundattributes.py.html?f=32&l=116#32" class="pudge-member-view-source" title="View Source">...</a> </h4> <div class="pudge-section rst"> <p class="pudge-member-blurb"> This is a declarative class that passes all the values given to it to another object. So you can pass it arguments (via __init__/__call__) or give it the equivalent of keyword arguments through subclassing. Then a bound object will be added in its place. </p> <p>To hook this other object in, override <tt class="docutils literal">make_object(added_class, name, **attrs)</tt> and maybe <tt class="docutils literal">set_object(added_class, name, **attrs)</tt> (the default implementation of <tt class="docutils literal">set_object</tt> just resets the attribute to whatever <tt class="docutils literal">make_object</tt> returned).</p> <p>Also see <tt class="docutils literal">BoundFactory</tt>.</p> <p class="note"> This class contains <a href="class-sqlobject.boundattributes.BoundAttribute.html#members"> 16 members</a>. </p> </div> </div><div class="pudge-member class "> <h4 class="pudge-member-name"><span class="prefix">C</span> <tt> <a href="class-sqlobject.boundattributes.BoundFactory.html" class="pudge-obj-link">BoundFactory</a>(...)</tt> <a href="sqlobject/boundattributes.py.html?f=117&l=134#117" class="pudge-member-view-source" title="View Source">...</a> </h4> <div class="pudge-section rst"> <p class="pudge-member-blurb"> This will bind the attribute to whatever is given by <tt class="docutils literal">factory_class</tt>. This factory should be a callable with the signature <tt class="docutils literal">factory_class(added_class, attr_name, *args, **kw)</tt>. </p> <p>The factory will be reinvoked (and the attribute rebound) for every subclassing.</p> <p class="note"> This class contains <a href="class-sqlobject.boundattributes.BoundFactory.html#members"> 17 members</a>. </p> </div> </div> <p> <small> See <a href="sqlobject/boundattributes.py.html" title="sqlobject/boundattributes.py:0">the source</a> for more information. </small> </p>