Popular recipes by Rodney Drenth http://code.activestate.com/recipes/users/4050661/2012-02-14T23:43:53-08:00ActiveState Code RecipesObserver pattern implemented with Descriptor class (Python) 2012-02-14T23:43:53-08:00Rodney Drenthhttp://code.activestate.com/recipes/users/4050661/http://code.activestate.com/recipes/578038-observer-pattern-implemented-with-descriptor-class/ <p style="color: grey"> Python recipe 578038 by <a href="/recipes/users/4050661/">Rodney Drenth</a> (<a href="/recipes/tags/descriptor/">descriptor</a>, <a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/publish/">publish</a>, <a href="/recipes/tags/reactive/">reactive</a>, <a href="/recipes/tags/subscribe/">subscribe</a>). </p> <p>The observer pattern is implemented using an observable descriptor. One creates instances of observable in a class, which allows observers to subscribe to changes in the observable. Assigning a value to the observable causes the suscribers to be notified. An observable can subscribe to another observable, in which case changes to the second propagate to subscribers of the first. The subscribe method returns a Subscription object. When this object is deleted or becomes unreferenced, the subscription is cancelled.</p> <p>This version compatible with Python 3.0 Example uses unittest to help in understanding the functionality.</p> Synchronization Decorator for Class Methods (Python) 2010-03-13T10:11:07-08:00Rodney Drenthhttp://code.activestate.com/recipes/users/4050661/http://code.activestate.com/recipes/577105-synchronization-decorator-for-class-methods/ <p style="color: grey"> Python recipe 577105 by <a href="/recipes/users/4050661/">Rodney Drenth</a> (<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/synchronize/">synchronize</a>, <a href="/recipes/tags/threads/">threads</a>). </p> <p>Synchronizes access to methods of a class with either an instance or class specific lock.</p> Threadsafe observer pattern implemented as descriptor (Python) 2010-03-13T12:17:11-08:00Rodney Drenthhttp://code.activestate.com/recipes/users/4050661/http://code.activestate.com/recipes/577106-threadsafe-observer-pattern-implemented-as-descrip/ <p style="color: grey"> Python recipe 577106 by <a href="/recipes/users/4050661/">Rodney Drenth</a> (<a href="/recipes/tags/descriptor/">descriptor</a>, <a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/publish/">publish</a>, <a href="/recipes/tags/subscribe/">subscribe</a>, <a href="/recipes/tags/threads/">threads</a>). </p> <p>This is a threadsafe version of <a href="http://code.activestate.com/recipes/576979/">recipe 576979</a>. A publish-subscribe (observer) pattern is implemented as a descriptor. Assigning a value notifies the observers. Uses <a href="http://code.activestate.com/recipes/577105/">recipe 577105</a> as synchlock.py and <a href="http://code.activestate.com/recipes/576979/">recipe 576979</a> as Observer.py</p> Observer pattern implemented with Descriptor class (Python) 2010-03-13T11:53:18-08:00Rodney Drenthhttp://code.activestate.com/recipes/users/4050661/http://code.activestate.com/recipes/576979-observer-pattern-implemented-with-descriptor-class/ <p style="color: grey"> Python recipe 576979 by <a href="/recipes/users/4050661/">Rodney Drenth</a> (<a href="/recipes/tags/descriptor/">descriptor</a>, <a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/publish/">publish</a>, <a href="/recipes/tags/subscribe/">subscribe</a>). Revision 5. </p> <p>The observer pattern is implemented using an observable descriptor. One creates instances of observable in a class, which allows observers to subscribe to changes in the observable. Assigning a value to the observable causes the suscribers to be notified. An observable can subscribe to another observable, in which case changes to the second propagate to subscribers of the first. The subscribe method returns a Subscription object. When this object is deleted or becomes unreferenced, the subscription is cancelled.</p> Easy State Pattern - support for implementing state machines (Python) 2009-06-15T11:25:17-07:00Rodney Drenthhttp://code.activestate.com/recipes/users/4050661/http://code.activestate.com/recipes/576613-easy-state-pattern-support-for-implementing-state-/ <p style="color: grey"> Python recipe 576613 by <a href="/recipes/users/4050661/">Rodney Drenth</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/metaclasses/">metaclasses</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/state_machine/">state_machine</a>, <a href="/recipes/tags/state_pattern/">state_pattern</a>). Revision 3. </p> <p>Provides is a module that gives support for implementing state machines. States are implemented as subclasses, derived from the state machine class. Methods that are state dependant or which cause transitions are declared using decorators. Because states can be subclasses of other states, common behaviour among several states is easily supported. The implementation allows for implementing multiple states or substates within a class.</p> <p>This module best support statem achines implemeting controllers for embedded systems, implementing user interfaces, or in discrete event model simulation. Parsers, which generally have many states and where you would need to define a Transaction method for each different character encountered would be more easily implemented by other means.</p>