Python 3 Patterns & Idioms / html / Decorator.html

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Decorator: Dynamic Type Selection &mdash; Python 3 Patterns, Recipes and Idioms</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '',
          VERSION:     '1.0',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="shortcut icon" href="_static/favicon.ico"/>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="Python 3 Patterns, Recipes and Idioms" href="index.html" />
    <link rel="next" title="Iterators: Decoupling Algorithms from Containers" href="Iterators.html" />
    <link rel="prev" title="StateMachine" href="StateMachine.html" />
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="Iterators.html" title="Iterators: Decoupling Algorithms from Containers"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="StateMachine.html" title="StateMachine"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Python 3 Patterns, Recipes and Idioms</a> &raquo;</li>
      </ul>
    </div>
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section" id="decorator-dynamic-type-selection">
<h1>Decorator: Dynamic Type Selection<a class="headerlink" href="#decorator-dynamic-type-selection" title="Permalink to this headline"></a></h1>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">I think we can rewrite this chapter to use Python decorators as
implementation (thus the decorators chapter should precede this one).</p>
</div>
<p>The use of layered objects to dynamically and transparently add responsibilities
to individual objects is referred to as the <em>decorator</em> pattern.</p>
<p>Used when subclassing creates too many (&amp; inflexible) classes</p>
<p>All decorators that wrap around the original object must have the same basic
interface</p>
<p>Dynamic proxy/surrogate?</p>
<p>This accounts for the odd inheritance structure</p>
<p>Tradeoff: coding is more complicated when using decorators</p>
<div class="section" id="basic-decorator-structure">
<h2>Basic Decorator Structure<a class="headerlink" href="#basic-decorator-structure" title="Permalink to this headline"></a></h2>
<img alt="_images/decorator.gif" src="_images/decorator.gif" />
</div>
<div class="section" id="a-coffee-example">
<h2>A Coffee Example<a class="headerlink" href="#a-coffee-example" title="Permalink to this headline"></a></h2>
<p>Consider going down to the local coffee shop, <em>BeanMeUp</em>, for a coffee.  There
are typically many different drinks on offer &#8211; espressos, lattes, teas, iced
coffees, hot chocolate to name a few, as well as a number of extras (which cost
extra too) such as whipped cream or an extra shot of espresso. You can also make
certain changes to your drink at no extra cost, such as asking for decaf coffee
instead of regular coffee.</p>
<p>Quite clearly if we are going to model all these drinks and combinations, there
will be sizeable class diagrams. So for clarity we will only consider a subset
of the coffees: Espresso, Espresso Con Panna, Café Late, Cappuccino and Café
Mocha. We&#8217;ll include 2 extras - whipped cream (&#8220;whipped&#8221;) and an extra shot of
espresso; and three changes - decaf, steamed milk (&#8220;wet&#8221;) and foamed milk
(&#8220;dry&#8221;).</p>
</div>
<div class="section" id="class-for-each-combination">
<h2>Class for Each Combination<a class="headerlink" href="#class-for-each-combination" title="Permalink to this headline"></a></h2>
<p>One solution is to create an individual class for every combination. Each class
describes the drink and is responsible for the cost etc. The resulting menu is
huge, and a part of the class diagram would look something like this:</p>
<img alt="_images/coffeeExplosion.gif" src="_images/coffeeExplosion.gif" />
<p>The key to using this method is to find the particular combination you want.
So, once you&#8217;ve found the drink you would like, here is how you would use it, as
shown in the <strong>CoffeeShop</strong> class in the following code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># Decorator/nodecorators/CoffeeShop.py</span>
<span class="c"># Coffee example with no decorators</span>

<span class="k">class</span> <span class="nc">Espresso</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">DoubleEspresso</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">EspressoConPanna</span><span class="p">:</span> <span class="k">pass</span>

<span class="k">class</span> <span class="nc">Cappuccino</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cost</span> <span class="o">=</span> <span class="mf">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="s">&quot;Cappucino&quot;</span>
    <span class="k">def</span> <span class="nf">getCost</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cost</span>
    <span class="k">def</span> <span class="nf">getDescription</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">description</span>

<span class="k">class</span> <span class="nc">CappuccinoDecaf</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CappuccinoDecafWhipped</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CappuccinoDry</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CappuccinoDryWhipped</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CappuccinoExtraEspresso</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CappuccinoExtraEspressoWhipped</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CappuccinoWhipped</span><span class="p">:</span> <span class="k">pass</span>

<span class="k">class</span> <span class="nc">CafeMocha</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeMochaDecaf</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeMochaDecafWhipped</span><span class="p">:</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cost</span> <span class="o">=</span> <span class="mf">1.25</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> \
          <span class="s">&quot;Cafe Mocha decaf whipped cream&quot;</span>
    <span class="k">def</span> <span class="nf">getCost</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cost</span>
    <span class="k">def</span> <span class="nf">getDescription</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">description</span>

<span class="k">class</span> <span class="nc">CafeMochaExtraEspresso</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeMochaExtraEspressoWhipped</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeMochaWet</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeMochaWetWhipped</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeMochaWhipped</span><span class="p">:</span> <span class="k">pass</span>

<span class="k">class</span> <span class="nc">CafeLatte</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeLatteDecaf</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeLatteDecafWhipped</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeLatteExtraEspresso</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeLatteExtraEspressoWhipped</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeLatteWet</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeLatteWetWhipped</span><span class="p">:</span> <span class="k">pass</span>
<span class="k">class</span> <span class="nc">CafeLatteWhipped</span><span class="p">:</span> <span class="k">pass</span>

<span class="n">cappuccino</span> <span class="o">=</span> <span class="n">Cappuccino</span><span class="p">()</span>
<span class="k">print</span><span class="p">((</span><span class="n">cappuccino</span><span class="o">.</span><span class="n">getDescription</span><span class="p">()</span> <span class="o">+</span> <span class="s">&quot;: $&quot;</span> <span class="o">+</span>
  <span class="sb">`cappuccino.getCost()`</span><span class="p">))</span>

<span class="n">cafeMocha</span> <span class="o">=</span> <span class="n">CafeMochaDecafWhipped</span><span class="p">()</span>
<span class="k">print</span><span class="p">((</span><span class="n">cafeMocha</span><span class="o">.</span><span class="n">getDescription</span><span class="p">()</span>
  <span class="o">+</span> <span class="s">&quot;: $&quot;</span> <span class="o">+</span> <span class="sb">`cafeMocha.getCost()`</span><span class="p">))</span>
</pre></div>
</div>
<p>And here is the corresponding output:</p>
<div class="highlight-python"><pre>Cappucino: $1.0
Cafe Mocha decaf whipped cream: $1.25</pre>
</div>
<p>You can see that creating the particular combination you want is easy, since you
are just creating an instance of a class. However, there are a number of
problems with this approach. Firstly, the combinations are fixed statically so
that any combination a customer may wish to order needs to be created up front.
Secondly, the resulting menu is so huge that finding your particular combination
is difficult and time consuming.</p>
</div>
<div class="section" id="the-decorator-approach">
<h2>The Decorator Approach<a class="headerlink" href="#the-decorator-approach" title="Permalink to this headline"></a></h2>
<p>Another approach would be to break the drinks down into the various components
such as espresso and foamed milk, and then let the customer combine the
components to describe a particular coffee.</p>
<p>In order to do this programmatically, we use the Decorator pattern.  A Decorator
adds responsibility to a component by wrapping it, but the Decorator conforms to
the interface of the component it encloses, so the wrapping is transparent.
Decorators can also be nested without the loss of this transparency.</p>
<img alt="_images/decoratedCoffee.gif" src="_images/decoratedCoffee.gif" />
<p>Methods invoked on the Decorator can in turn invoke methods in the component,
and can of course perform processing before or after the invocation.</p>
<p>So if we added <strong>getTotalCost()</strong> and <strong>getDescription()</strong> methods to the
<strong>DrinkComponent</strong> interface, an Espresso looks like this:</p>
<div class="highlight-python"><pre># Decorator/alldecorators/EspressoDecorator.py

class Espresso(Decorator):
    cost = 0.75f
    description = " espresso"
    def __init__(DrinkComponent):
        Decorator.__init__(self, component)

    def getTotalCost(self):
        return self.component.getTotalCost() + cost

    def getDescription(self):
        return self.component.getDescription() +
            description</pre>
</div>
<p>You combine the components to create a drink as follows, as shown in the code
below:</p>
<div class="highlight-python"><pre># Decorator/alldecorators/CoffeeShop.py
# Coffee example using decorators

class DrinkComponent:
    def getDescription(self):
        return self.__class__.__name__
    def getTotalCost(self):
        return self.__class__.cost

class Mug(DrinkComponent):
    cost = 0.0

class Decorator(DrinkComponent):
    def __init__(self, drinkComponent):
        self.component = drinkComponent
    def getTotalCost(self):
        return self.component.getTotalCost() + \
          DrinkComponent.getTotalCost(self)
    def getDescription(self):
        return self.component.getDescription() + \
          ' ' + DrinkComponent.getDescription(self)

class Espresso(Decorator):
    cost = 0.75
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

class Decaf(Decorator):
    cost = 0.0
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

class FoamedMilk(Decorator):
    cost = 0.25
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

class SteamedMilk(Decorator):
    cost = 0.25
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

class Whipped(Decorator):
    cost = 0.25
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

class Chocolate(Decorator):
    cost = 0.25
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

cappuccino = Espresso(FoamedMilk(Mug()))
print(cappuccino.getDescription().strip() + \)
  ": $" + `cappuccino.getTotalCost()`

cafeMocha = Espresso(SteamedMilk(Chocolate(
  Whipped(Decaf(Mug())))))

print(cafeMocha.getDescription().strip() + \)
  ": $" + `cafeMocha.getTotalCost()`</pre>
</div>
<p>This approach would certainly provide the most flexibility and the smallest
menu. You have a small number of components to choose from, but assembling the
description of the coffee then becomes rather arduous.</p>
<p>If you want to describe a plain cappuccino, you create it with:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plainCap</span> <span class="o">=</span> <span class="n">Espresso</span><span class="p">(</span><span class="n">FoamedMilk</span><span class="p">(</span><span class="n">Mug</span><span class="p">()))</span>
</pre></div>
</div>
<p>Creating a decaf Cafe Mocha with whipped cream requires an even longer
description.</p>
</div>
<div class="section" id="compromise">
<h2>Compromise<a class="headerlink" href="#compromise" title="Permalink to this headline"></a></h2>
<p>The previous approach takes too long to describe a coffee. There will also be
certain combinations that you will describe regularly, and it would be
convenient to have a quick way of describing them.</p>
<p>The 3rd approach is a mixture of the first 2 approaches, and combines
flexibility with ease of use. This compromise is achieved by creating a
reasonably sized menu of basic selections, which would often work exactly as
they are, but if you wanted to decorate them (whipped cream, decaf etc.) then
you would use decorators to make the modifications. This is the type of menu you
are presented with in most coffee shops.</p>
<img alt="_images/compromiseDecoration.gif" src="_images/compromiseDecoration.gif" />
<p>Here is how to create a basic selection, as well as a decorated selection:</p>
<div class="highlight-python"><pre># Decorator/compromise/CoffeeShop.py
# Coffee example with a compromise of basic
# combinations and decorators

class DrinkComponent:
    def getDescription(self):
        return self.__class__.__name__
    def getTotalCost(self):
        return self.__class__.cost

class Espresso(DrinkComponent):
    cost = 0.75

class EspressoConPanna(DrinkComponent):
    cost = 1.0

class Cappuccino(DrinkComponent):
    cost = 1.0

class CafeLatte(DrinkComponent):
    cost = 1.0

class CafeMocha(DrinkComponent):
    cost = 1.25

class Decorator(DrinkComponent):
    def __init__(self, drinkComponent):
        self.component = drinkComponent
    def getTotalCost(self):
        return self.component.getTotalCost() + \
          DrinkComponent.getTotalCost(self)
    def getDescription(self):
        return self.component.getDescription() + \
          ' ' + DrinkComponent.getDescription(self)

class ExtraEspresso(Decorator):
    cost = 0.75
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

class Whipped(Decorator):
    cost = 0.50
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

class Decaf(Decorator):
    cost = 0.0
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

class Dry(Decorator):
    cost = 0.0
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

class Wet(Decorator):
    cost = 0.0
    def __init__(self, drinkComponent):
        Decorator.__init__(self, drinkComponent)

cappuccino = Cappuccino()
print(cappuccino.getDescription() + ": $" + \)
  `cappuccino.getTotalCost()`

cafeMocha = Whipped(Decaf(CafeMocha()))
print(cafeMocha.getDescription() + ": $" + \)
  `cafeMocha.getTotalCost()`</pre>
</div>
<p>You can see that creating a basic selection is quick and easy, which makes sense
since they will be described regularly.  Describing a decorated drink is more
work than when using a class per combination, but clearly less work than when
only using decorators.</p>
<p>The final result is not too many classes, but not too many decorators either.
Most of the time it&#8217;s possible to get away without using any decorators at all,
so we have the benefits of both approaches.</p>
</div>
<div class="section" id="other-considerations">
<h2>Other Considerations<a class="headerlink" href="#other-considerations" title="Permalink to this headline"></a></h2>
<p>What happens if we decide to change the menu at a later stage, such as by adding
a new type of drink? If we had used the class per combination approach, the
effect of adding an extra such as syrup would be an exponential growth in the
number of classes. However, the implications to the all decorator or compromise
approaches are the same - one extra class is created.</p>
<p>How about the effect of changing the cost of steamed milk and foamed milk, when
the price of milk goes up? Having a class for each combination means that you
need to change a method in each class, and thus maintain many classes. By using
decorators, maintenance is reduced by defining the logic in one place.</p>
</div>
<div class="section" id="further-reading">
<h2>Further Reading<a class="headerlink" href="#further-reading" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="exercises">
<h2>Exercises<a class="headerlink" href="#exercises" title="Permalink to this headline"></a></h2>
<ol class="arabic simple">
<li>Add a Syrup class to the decorator approach described above. Then create a
Café Latte (you&#8217;ll need to use steamed milk with an espresso) with syrup.</li>
<li>Repeat Exercise 1 for the compromise approach.</li>
<li>Implement the decorator pattern to create a Pizza restaurant, which has a
set menu of choices as well as the option to design your own pizza.  Follow
the compromise approach to create a menu consisting of a Margherita,
Hawaiian, Regina, and Vegetarian pizzas, with toppings (decorators) of
Garlic, Olives, Spinach, Avocado, Feta and Pepperdews. Create a Hawaiian
pizza, as well as a Margherita decorated with Spinach, Feta, Pepperdews and
Olives.</li>
</ol>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/cover.png" alt="Logo"/>
            </a></p>
    <font color="Red">This book is in early development; you will find parts that are incorrect &amp; incomplete.</font>
    
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">Decorator: Dynamic Type Selection</a><ul>
<li><a class="reference external" href="#basic-decorator-structure">Basic Decorator Structure</a></li>
<li><a class="reference external" href="#a-coffee-example">A Coffee Example</a></li>
<li><a class="reference external" href="#class-for-each-combination">Class for Each Combination</a></li>
<li><a class="reference external" href="#the-decorator-approach">The Decorator Approach</a></li>
<li><a class="reference external" href="#compromise">Compromise</a></li>
<li><a class="reference external" href="#other-considerations">Other Considerations</a></li>
<li><a class="reference external" href="#further-reading">Further Reading</a></li>
<li><a class="reference external" href="#exercises">Exercises</a></li>
</ul>
</li>
</ul>


            <h4>Previous topic</h4>
            <p class="topless"><a href="StateMachine.html" title="previous chapter">StateMachine</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="Iterators.html" title="next chapter">Iterators: Decoupling Algorithms from Containers</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/Decorator.txt">Show Source</a></li>
            </ul>
    
          <h3>Quick search</h3>
            <form class="search" action="search.html" method="get">
              <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
              <input type="hidden" name="check_keywords" value="yes" />
              <input type="hidden" name="area" value="default" />
            </form>
    <h4><a href="http://www.mindviewinc.com/Books/Python3Patterns/Index.php">Project Homepage</a></h4>
    <h4><a href="http://www.bitbucket.org/BruceEckel/python-3-patterns-idioms/issues/">Corrections/Suggestions</a></h4>
    <h4><a href="http://www.mindviewinc.com/Consulting/Index.php">Consulting &amp; Training</a></h4><br><br>

        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="Iterators.html" title="Iterators: Decoupling Algorithms from Containers"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="StateMachine.html" title="StateMachine"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Python 3 Patterns, Recipes and Idioms</a> &raquo;</li>
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2008, Creative Commons Attribution-Share Alike 3.0.
      Last updated on Feb 13, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.5.
    </div>
  </body>
</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.