summaryrefslogtreecommitdiff
path: root/pypers
diff options
context:
space:
mode:
authormichele.simionato <devnull@localhost>2007-12-02 12:04:58 +0000
committermichele.simionato <devnull@localhost>2007-12-02 12:04:58 +0000
commit07279fd0cb5e642a4068ffa808f381d01674eccf (patch)
tree8eabfe26ce04342d1136e6ce7f67cdc4cb3f2a11 /pypers
parent8903a90556fc62d418c200c8eacd8de641c25c1d (diff)
downloadmicheles-07279fd0cb5e642a4068ffa808f381d01674eccf.tar.gz
Removed generated html files
Diffstat (limited to 'pypers')
-rw-r--r--pypers/adwi/talk.html408
-rwxr-xr-xpypers/all.html11002
-rwxr-xr-xpypers/bolzano/db/mysql/ui/table.html23
-rwxr-xr-xpypers/bolzano/db/mysql/ui/x.html104
-rwxr-xr-xpypers/bolzano/db/mysql/x.html2
-rwxr-xr-xpypers/bolzano/links.html58
-rwxr-xr-xpypers/bolzano/web/cgi-bin/ex_form.html10
-rwxr-xr-xpypers/bolzano/web/prova.html1
-rwxr-xr-xpypers/classcreation.html236
-rw-r--r--pypers/classinitializer/classinitializer.html530
-rwxr-xr-xpypers/descr.html1085
-rwxr-xr-xpypers/doctest_talk/P01.html115
-rwxr-xr-xpypers/doctest_talk/P02.html110
-rwxr-xr-xpypers/doctest_talk/P03.html105
-rwxr-xr-xpypers/doctest_talk/P04.html111
-rwxr-xr-xpypers/doctest_talk/P05.html110
-rwxr-xr-xpypers/doctest_talk/P06.html111
-rwxr-xr-xpypers/doctest_talk/P07.html110
-rwxr-xr-xpypers/doctest_talk/P08.html105
-rwxr-xr-xpypers/doctest_talk/P09.html117
-rwxr-xr-xpypers/doctest_talk/P10.html104
-rwxr-xr-xpypers/doctest_talk/P11.html118
-rwxr-xr-xpypers/doctest_talk/P12.html122
-rwxr-xr-xpypers/doctest_talk/P13.html114
-rwxr-xr-xpypers/doctest_talk/P14.html122
-rwxr-xr-xpypers/doctest_talk/P15.html116
-rwxr-xr-xpypers/doctest_talk/P16.html113
-rwxr-xr-xpypers/doctest_talk/P17.html121
-rwxr-xr-xpypers/doctest_talk/P18.html119
-rwxr-xr-xpypers/doctest_talk/P19.html110
-rwxr-xr-xpypers/doctest_talk/P20.html118
-rwxr-xr-xpypers/doctest_talk/P21.html122
-rwxr-xr-xpypers/doctest_talk/P22.html111
-rwxr-xr-xpypers/doctest_talk/P23.html120
-rwxr-xr-xpypers/doctest_talk/P24.html111
-rwxr-xr-xpypers/doctest_talk/P25.html118
-rwxr-xr-xpypers/doctest_talk/P26.html115
-rwxr-xr-xpypers/doctest_talk/P27.html113
-rwxr-xr-xpypers/doctest_talk/P28.html116
-rwxr-xr-xpypers/doctest_talk/P29.html116
-rwxr-xr-xpypers/doctest_talk/index.html16
-rwxr-xr-xpypers/doctest_talk/split.html32
-rwxr-xr-xpypers/doctest_talk/talk.html362
-rwxr-xr-xpypers/doctest_talk/x.html203
-rwxr-xr-xpypers/dot/dot.html347
-rwxr-xr-xpypers/europython05/fig.html15
-rwxr-xr-xpypers/europython05/table.html44
-rwxr-xr-xpypers/europython05/taste-python.html47
-rw-r--r--pypers/europython06/talk.html629
-rw-r--r--pypers/europython07/talk.html669
-rw-r--r--pypers/europython07/ui/default/ex.html13
-rwxr-xr-xpypers/marelli/frontpage.html16
-rwxr-xr-xpypers/marelli/materiale/corso.html1850
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P01.html110
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P02.html106
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P03.html102
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P04.html108
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P05.html107
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P06.html108
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P07.html107
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P08.html102
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P09.html114
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P10.html101
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P11.html114
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P12.html119
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P13.html111
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P14.html118
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P15.html115
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P16.html118
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P17.html116
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P18.html110
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P19.html113
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P20.html108
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P21.html117
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P22.html108
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P23.html115
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P24.html112
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P25.html110
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/P26.html113
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/index.html16
-rwxr-xr-xpypers/marelli/materiale/doctest_talk/split.html32
-rwxr-xr-xpypers/marelli/programma-svolto.html409
-rwxr-xr-xpypers/marelli/questionario-iniziale.html303
-rwxr-xr-xpypers/meta/meta1.html399
-rwxr-xr-xpypers/meta/meta2.html528
-rwxr-xr-xpypers/meta/metatype.html197
-rwxr-xr-xpypers/mro/mro.html794
-rwxr-xr-xpypers/optparse/invoice.html59
-rwxr-xr-xpypers/optparse/paper.html453
-rwxr-xr-xpypers/optparse/paper2.html373
-rwxr-xr-xpypers/oxford/all.html2366
-rwxr-xr-xpypers/oxford/doctest_talk/P01.html110
-rwxr-xr-xpypers/oxford/doctest_talk/P02.html106
-rwxr-xr-xpypers/oxford/doctest_talk/P03.html102
-rwxr-xr-xpypers/oxford/doctest_talk/P04.html108
-rwxr-xr-xpypers/oxford/doctest_talk/P05.html107
-rwxr-xr-xpypers/oxford/doctest_talk/P06.html108
-rwxr-xr-xpypers/oxford/doctest_talk/P07.html107
-rwxr-xr-xpypers/oxford/doctest_talk/P08.html102
-rwxr-xr-xpypers/oxford/doctest_talk/P09.html114
-rwxr-xr-xpypers/oxford/doctest_talk/P10.html101
-rwxr-xr-xpypers/oxford/doctest_talk/P11.html114
-rwxr-xr-xpypers/oxford/doctest_talk/P12.html119
-rwxr-xr-xpypers/oxford/doctest_talk/P13.html111
-rwxr-xr-xpypers/oxford/doctest_talk/P14.html118
-rwxr-xr-xpypers/oxford/doctest_talk/P15.html115
-rwxr-xr-xpypers/oxford/doctest_talk/P16.html118
-rwxr-xr-xpypers/oxford/doctest_talk/P17.html116
-rwxr-xr-xpypers/oxford/doctest_talk/P18.html110
-rwxr-xr-xpypers/oxford/doctest_talk/P19.html113
-rwxr-xr-xpypers/oxford/doctest_talk/P20.html108
-rwxr-xr-xpypers/oxford/doctest_talk/P21.html117
-rwxr-xr-xpypers/oxford/doctest_talk/P22.html108
-rwxr-xr-xpypers/oxford/doctest_talk/P23.html115
-rwxr-xr-xpypers/oxford/doctest_talk/P24.html112
-rwxr-xr-xpypers/oxford/doctest_talk/P25.html110
-rwxr-xr-xpypers/oxford/doctest_talk/P26.html113
-rwxr-xr-xpypers/oxford/doctest_talk/index.html16
-rwxr-xr-xpypers/oxford/doctest_talk/split.html32
-rwxr-xr-xpypers/oxford/doctest_talk/x.html203
-rwxr-xr-xpypers/oxford/loops.html753
-rwxr-xr-xpypers/oxford/magic.html717
-rwxr-xr-xpypers/oxford/mro.html788
-rwxr-xr-xpypers/oxford/objects.html743
-rwxr-xr-xpypers/pep318/__main__.html61
-rwxr-xr-xpypers/pep318/decorators.html1534
-rwxr-xr-xpypers/pep318/mydoc.html51
-rwxr-xr-xpypers/pep318/oopp.html324
-rwxr-xr-xpypers/pep318/pydoc.html508
-rwxr-xr-xpypers/pep318/safetype.html33
-rwxr-xr-xpypers/pep318/working/decorators.html1337
-rwxr-xr-xpypers/pep318/working/pep318.html1046
-rwxr-xr-xpypers/pep318/working/pydoc.html504
-rwxr-xr-xpypers/pyj/python-subtilities.html187
-rwxr-xr-xpypers/recipes/doctester.html130
-rwxr-xr-xpypers/recipes/optparse.html94
-rw-r--r--pypers/simionato_talk/formulas.html329
-rw-r--r--pypers/simionato_talk/talk.html1207
-rw-r--r--pypers/simionato_talk/ui/default/ex.html13
-rwxr-xr-xpypers/super/super.html564
-rwxr-xr-xpypers/twill/testing_web_app.html584
-rw-r--r--pypers/twisted/P01.html93
-rw-r--r--pypers/twisted/P02.html92
-rw-r--r--pypers/twisted/P03.html95
-rw-r--r--pypers/twisted/P04.html101
-rw-r--r--pypers/twisted/P05.html97
-rw-r--r--pypers/twisted/P06.html98
-rw-r--r--pypers/twisted/P07.html91
-rw-r--r--pypers/twisted/P08.html101
-rw-r--r--pypers/twisted/P09.html92
-rw-r--r--pypers/twisted/P10.html88
-rw-r--r--pypers/twisted/P11.html92
-rw-r--r--pypers/twisted/P12.html91
-rw-r--r--pypers/twisted/P13.html113
-rw-r--r--pypers/twisted/P14.html95
-rw-r--r--pypers/twisted/P15.html115
-rw-r--r--pypers/twisted/P16.html91
-rw-r--r--pypers/wsgi/formulas.html329
-rw-r--r--pypers/wsgi/talk.html1207
-rw-r--r--pypers/wsgi/ui/default-orig/ex.html13
-rw-r--r--pypers/wsgi/ui/default/ex.html13
161 files changed, 0 insertions, 47573 deletions
diff --git a/pypers/adwi/talk.html b/pypers/adwi/talk.html
deleted file mode 100644
index a2bdd12..0000000
--- a/pypers/adwi/talk.html
+++ /dev/null
@@ -1,408 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<meta name="version" content="S5 1.1" />
-<title></title>
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-12-18 01:56:14 +0100 (Sun, 18 Dec 2005) $
-:Revision: $Revision: 4224 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-
-See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
-customize this style sheet.
-*/
-
-/* used to remove borders from tables and images */
-.borderless, table.borderless td, table.borderless th {
- border: 0 }
-
-table.borderless td, table.borderless th {
- /* Override padding for "table.docutils td" with "! important".
- The right padding separates the table cells. */
- padding: 0 0.5em 0 0 ! important }
-
-.first {
- /* Override more specific margin styles with "! important". */
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em ;
- margin-right: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid 1px gray;
- margin-left: 1px }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid 1px black;
- margin-left: 1px }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-<!-- configuration parameters -->
-<meta name="defaultView" content="slideshow" />
-<meta name="controlVis" content="hidden" />
-<!-- style sheet links -->
-<script src="ui/default/slides.js" type="text/javascript"></script>
-<link rel="stylesheet" href="ui/default/slides.css"
- type="text/css" media="projection" id="slideProj" />
-<link rel="stylesheet" href="ui/default/outline.css"
- type="text/css" media="screen" id="outlineStyle" />
-<link rel="stylesheet" href="ui/default/print.css"
- type="text/css" media="print" id="slidePrint" />
-<link rel="stylesheet" href="ui/default/opera.css"
- type="text/css" media="projection" id="operaFix" />
-
-<style type="text/css">
-#currentSlide {display: none;}
-</style>
-</head>
-<body>
-<div class="layout">
-<div id="controls"></div>
-<div id="currentSlide"></div>
-<div id="header">
-
-</div>
-<div id="footer">
-<h2>StatPro Milan</h2>
-</div>
-</div>
-<div class="presentation">
-<div class="slide" id="slide0">
-
-</div>
-<div class="slide" id="rcare-internals">
-<h1>RCare Internals</h1>
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">author:</th><td class="field-body"><p class="first">Michele Simionato</p>
-</td>
-</tr>
-<tr class="field"><th class="field-name">date:</th><td class="field-body"><p class="first">2007-01-30</p>
-<p class="last"><strong>StatPro Milan</strong></p>
-</td>
-</tr>
-</tbody>
-</table>
-<!-- Definitions of interpreted text roles (classes) for S5/HTML data. -->
-<!-- This data file has been placed in the public domain. -->
-<!-- Colours
-======= -->
-<!-- Text Sizes
-========== -->
-<!-- Display in Slides (Presentation Mode) Only
-========================================== -->
-<!-- Display in Outline Mode Only
-============================ -->
-<!-- Display in Print Only
-===================== -->
-<!-- Incremental Display
-=================== -->
-</div>
-<div class="slide" id="some-numbers">
-<h1>Some numbers</h1>
-<p class="incremental">files [('.py', 273), ('.pt', 62), ('.zsql', 28)]</p>
-<p class="incremental">lines [('.py', 48327), ('.pt', 12124), ('.zsql', 1726)]</p>
-<p class="incremental">files, lines: (363, 62177)</p>
-</div>
-<div class="slide" id="where">
-<h1>Where?</h1>
-<ul class="incremental simple">
-<li>interaction with SRS (send_rhp.py, Issuer.py)</li>
-<li>interaction with SRM (MissingProductLogLoader.py)</li>
-<li>interaction with SDM (SRSTool)</li>
-<li>interaction with customers (report_tool, CheckProduct)</li>
-</ul>
-</div>
-<div class="slide" id="id1">
-<h1>RCare Internals</h1>
-<p class="incremental">or</p>
-<p class="incremental">how to write UIs</p>
-<p class="incremental">or</p>
-<p class="incremental">Real Men Don't Click! (TM)</p>
-</div>
-<div class="slide" id="examples">
-<h1>Examples</h1>
-<p class="incremental"><a class="reference" href="http://cvs2/logmanager">http://cvs2/logmanager</a></p>
-<p class="incremental"><a class="reference" href="http://simionm01:5555">http://simionm01:5555</a></p>
-<p class="incremental"><a class="reference" href="http://simionm01:8888">http://simionm01:8888</a></p>
-<p class="incremental"><a class="reference" href="http://sdm3.statpro.com:8080/rcare/issuer_manager">http://sdm3.statpro.com:8080/rcare/issuer_manager</a></p>
-</div>
-<div class="slide" id="zope-integration-1">
-<h1>Zope Integration (1)</h1>
-<p class="incremental">1 assume you have a Plone Site product</p>
-<p class="incremental">2 assume you have a Plone tool</p>
-<p class="incremental">3 assume the SitePolicy is installing the new tool</p>
-<p class="incremental">4 assume the SitePolicy is defining your users and roles</p>
-<p class="incremental">5 add a method to the Plone tool</p>
-</div>
-<div class="slide" id="zope-integration-2">
-<h1>Zope Integration (2)</h1>
-<p class="incremental">6 set the right permissions</p>
-<p class="incremental">7 make a new skins directory</p>
-<p class="incremental">8 write your template calling the tool method</p>
-<p class="incremental">9 possibly add a tab into Extensions/Install.py</p>
-<p class="incremental">10 restart the server</p>
-<p class="incremental">11 <em>regenerate</em> the Plone site</p>
-</div>
-<div class="slide" id="zope-integration-3">
-<h1>Zope Integration (3)</h1>
-<blockquote>
-... and <em>maybe</em> you are done!</blockquote>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/all.html b/pypers/all.html
deleted file mode 100755
index 0d64b1f..0000000
--- a/pypers/all.html
+++ /dev/null
@@ -1,11002 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title>OBJECT ORIENTED PROGRAMMING IN PYTHON</title>
-<meta name="author" content="Michele Simionato" />
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<h1 class="title">OBJECT ORIENTED PROGRAMMING IN PYTHON</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr><th class="docinfo-name">Version:</th>
-<td>0.5</td></tr>
-<tr><th class="docinfo-name">Author:</th>
-<td>Michele Simionato</td></tr>
-<tr class="field"><th class="docinfo-name">E-mail:</th><td class="field-body"><a class="reference" href="mailto:mis6&#64;pitt.edu">mis6&#64;pitt.edu</a></td>
-</tr>
-<tr class="field"><th class="docinfo-name">Home-page:</th><td class="field-body"><a class="reference" href="http://www.phyast.pitt.edu/~micheles/">http://www.phyast.pitt.edu/~micheles/</a></td>
-</tr>
-<tr class="field"><th class="docinfo-name">Disclaimer:</th><td class="field-body">I release this book to the general public.
-It can be freely distributed if unchanged.
-As usual, I don't give any warranty: while I have tried hard to ensure the
-correctness of what follows, I disclaim any responsability in case of
-errors . Use it at your own risk and peril !</td>
-</tr>
-</tbody>
-</table>
-<div class="document" id="object-oriented-programming-in-python">
-<div class="contents topic" id="contents">
-<p class="topic-title first"><a name="contents">Contents</a></p>
-<ul class="simple">
-<li><a class="reference" href="#preface" id="id49" name="id49">Preface</a><ul>
-<li><a class="reference" href="#the-philosophy-of-this-book" id="id50" name="id50">The philosophy of this book</a></li>
-<li><a class="reference" href="#for-who-this-book-in-intended" id="id51" name="id51">For who this book in intended</a></li>
-<li><a class="reference" href="#about-the-scripts-in-this-book" id="id52" name="id52">About the scripts in this book</a></li>
-<li><a class="reference" href="#conventions-used-in-this-book" id="id53" name="id53">Conventions used in this book</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#introduction" id="id54" name="id54">Introduction</a><ul>
-<li><a class="reference" href="#why-oop" id="id55" name="id55">Why OOP ?</a></li>
-<li><a class="reference" href="#why-python" id="id56" name="id56">Why Python ?</a></li>
-<li><a class="reference" href="#further-thoughts" id="id57" name="id57">Further thoughts</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#first-things-first" id="id58" name="id58">FIRST THINGS, FIRST</a><ul>
-<li><a class="reference" href="#what-s-an-object" id="id59" name="id59">What's an object?</a></li>
-<li><a class="reference" href="#objects-and-classes" id="id60" name="id60">Objects and classes</a></li>
-<li><a class="reference" href="#objects-have-attributes" id="id61" name="id61">Objects have attributes</a></li>
-<li><a class="reference" href="#objects-have-methods" id="id62" name="id62">Objects have methods</a></li>
-<li><a class="reference" href="#summing-objects" id="id63" name="id63">Summing objects</a></li>
-<li><a class="reference" href="#inspecting-objects" id="id64" name="id64">Inspecting objects</a></li>
-<li><a class="reference" href="#built-in-objects-iterators-and-generators" id="id65" name="id65">Built-in objects: iterators and generators</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-convenience-of-functions" id="id66" name="id66">THE CONVENIENCE OF FUNCTIONS</a><ul>
-<li><a class="reference" href="#id16" id="id67" name="id67">Introduction</a></li>
-<li><a class="reference" href="#a-few-useful-functions" id="id68" name="id68">A few useful functions</a></li>
-<li><a class="reference" href="#functions-are-objects" id="id69" name="id69">Functions are objects</a></li>
-<li><a class="reference" href="#profiling-functions" id="id70" name="id70">Profiling functions</a></li>
-<li><a class="reference" href="#about-python-speed" id="id71" name="id71">About Python speed</a></li>
-<li><a class="reference" href="#tracing-functions" id="id72" name="id72">Tracing functions</a></li>
-<li><a class="reference" href="#tracing-objects" id="id73" name="id73">Tracing objects</a></li>
-<li><a class="reference" href="#inspecting-functions" id="id74" name="id74">Inspecting functions</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-beauty-of-objects" id="id75" name="id75">THE BEAUTY OF OBJECTS</a><ul>
-<li><a class="reference" href="#user-defined-objects" id="id76" name="id76">User defined objects</a></li>
-<li><a class="reference" href="#objects-have-static-methods-and-classmethods" id="id77" name="id77">Objects have static methods and classmethods</a></li>
-<li><a class="reference" href="#objects-have-their-privacy" id="id78" name="id78">Objects have their privacy</a></li>
-<li><a class="reference" href="#objects-have-properties" id="id79" name="id79">Objects have properties</a></li>
-<li><a class="reference" href="#objects-have-special-methods" id="id80" name="id80">Objects have special methods</a></li>
-<li><a class="reference" href="#objects-can-be-called-added-subtracted" id="id81" name="id81">Objects can be called, added, subtracted, ...</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-power-of-classes" id="id82" name="id82">THE POWER OF CLASSES</a><ul>
-<li><a class="reference" href="#the-concept-of-inheritance" id="id83" name="id83">The concept of inheritance</a></li>
-<li><a class="reference" href="#inheritance-versus-run-time-class-modifications" id="id84" name="id84">Inheritance versus run-time class modifications</a></li>
-<li><a class="reference" href="#inheriting-from-built-in-types" id="id85" name="id85">Inheriting from built-in types</a></li>
-<li><a class="reference" href="#controlling-the-creation-of-objects" id="id86" name="id86">Controlling the creation of objects</a></li>
-<li><a class="reference" href="#multiple-inheritance" id="id87" name="id87">Multiple Inheritance</a></li>
-<li><a class="reference" href="#cooperative-hierarchies" id="id88" name="id88">Cooperative hierarchies</a></li>
-<li><a class="reference" href="#inheritance-and-privacy" id="id89" name="id89">Inheritance and privacy</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-sophistication-of-descriptors" id="id90" name="id90">THE SOPHISTICATION OF DESCRIPTORS</a><ul>
-<li><a class="reference" href="#motivation" id="id91" name="id91">Motivation</a></li>
-<li><a class="reference" href="#functions-versus-methods" id="id92" name="id92">Functions versus methods</a></li>
-<li><a class="reference" href="#methods-versus-functions" id="id93" name="id93">Methods versus functions</a></li>
-<li><a class="reference" href="#static-methods-and-class-methods" id="id94" name="id94">Static methods and class methods</a></li>
-<li><a class="reference" href="#properties" id="id95" name="id95">Properties</a></li>
-<li><a class="reference" href="#user-defined-attribute-descriptors" id="id96" name="id96">User-defined attribute descriptors</a></li>
-<li><a class="reference" href="#data-descriptors" id="id97" name="id97">Data descriptors</a></li>
-<li><a class="reference" href="#the-super-attribute-descriptor" id="id98" name="id98">The <tt class="literal"><span class="pre">super</span></tt> attribute descriptor</a></li>
-<li><a class="reference" href="#method-wrappers" id="id99" name="id99">Method wrappers</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-subtleties-of-multiple-inheritance" id="id100" name="id100">THE SUBTLETIES OF MULTIPLE INHERITANCE</a><ul>
-<li><a class="reference" href="#a-little-bit-of-history-why-python-2-3-has-changed-the-mro" id="id101" name="id101">A little bit of history: why Python 2.3 has changed the MRO</a></li>
-<li><a class="reference" href="#the-c3-method-resolution-order" id="id102" name="id102">The C3 Method Resolution Order</a></li>
-<li><a class="reference" href="#examples" id="id103" name="id103">Examples</a></li>
-<li><a class="reference" href="#bad-method-resolution-orders" id="id104" name="id104">Bad Method Resolution Orders</a></li>
-<li><a class="reference" href="#understanding-the-method-resolution-order" id="id105" name="id105">Understanding the Method Resolution Order</a></li>
-<li><a class="reference" href="#counting-instances" id="id106" name="id106">Counting instances</a></li>
-<li><a class="reference" href="#the-pizza-shop-example" id="id107" name="id107">The pizza-shop example</a></li>
-<li><a class="reference" href="#fixing-wrong-hierarchies" id="id108" name="id108">Fixing wrong hierarchies</a></li>
-<li><a class="reference" href="#modifying-hierarchies" id="id109" name="id109">Modifying hierarchies</a></li>
-<li><a class="reference" href="#inspecting-python-code" id="id110" name="id110">Inspecting Python code</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-magic-of-metaclasses-part-i" id="id111" name="id111">THE MAGIC OF METACLASSES - PART I</a><ul>
-<li><a class="reference" href="#metaclasses-as-class-factories" id="id112" name="id112">Metaclasses as class factories</a></li>
-<li><a class="reference" href="#metaclasses-as-class-modifiers" id="id113" name="id113">Metaclasses as class modifiers</a></li>
-<li><a class="reference" href="#a-few-caveats-about-the-usage-of-metaclasses" id="id114" name="id114">A few caveats about the usage of metaclasses</a></li>
-<li><a class="reference" href="#metaclasses-and-inheritance" id="id115" name="id115">Metaclasses and inheritance</a></li>
-<li><a class="reference" href="#conflicting-metaclasses" id="id116" name="id116">Conflicting metaclasses</a></li>
-<li><a class="reference" href="#cooperative-metaclasses" id="id117" name="id117">Cooperative metaclasses</a></li>
-<li><a class="reference" href="#metamethods-vs-class-methods" id="id118" name="id118">Metamethods vs class methods</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-magic-of-metaclasses-part-2" id="id119" name="id119">THE MAGIC OF METACLASSES - PART 2</a><ul>
-<li><a class="reference" href="#the-secrets-of-the-metaclass-hook" id="id120" name="id120">The secrets of the <tt class="literal"><span class="pre">__metaclass__</span></tt> hook</a></li>
-<li><a class="reference" href="#anonymous-inner-metaclasses" id="id121" name="id121">Anonymous inner metaclasses</a></li>
-<li><a class="reference" href="#passing-parameters-to-meta-classes" id="id122" name="id122">Passing parameters to (meta) classes</a></li>
-<li><a class="reference" href="#meta-functions" id="id123" name="id123">Meta-functions</a></li>
-<li><a class="reference" href="#anonymous-cooperative-super-calls" id="id124" name="id124">Anonymous cooperative super calls</a></li>
-<li><a class="reference" href="#more-on-metaclasses-as-class-factories" id="id125" name="id125">More on metaclasses as class factories</a></li>
-<li><a class="reference" href="#programming-with-metaclasses" id="id126" name="id126">Programming with metaclasses</a></li>
-<li><a class="reference" href="#metaclass-aided-operator-overloading" id="id127" name="id127">Metaclass-aided operator overloading</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#advanced-metaprogramming-techniques" id="id128" name="id128">ADVANCED METAPROGRAMMING TECHNIQUES</a><ul>
-<li><a class="reference" href="#on-code-processing" id="id129" name="id129">On code processing</a></li>
-<li><a class="reference" href="#regular-expressions" id="id130" name="id130">Regular expressions</a></li>
-<li><a class="reference" href="#more-on-metaclasses-and-subclassing-built-in-types" id="id131" name="id131">More on metaclasses and subclassing built-in types</a></li>
-<li><a class="reference" href="#a-simple-state-machine" id="id132" name="id132">A simple state machine</a></li>
-<li><a class="reference" href="#creating-classes" id="id133" name="id133">Creating classes</a></li>
-<li><a class="reference" href="#modifying-modules" id="id134" name="id134">Modifying modules</a></li>
-<li><a class="reference" href="#metaclasses-and-attribute-descriptors" id="id135" name="id135">Metaclasses and attribute descriptors</a></li>
-<li><a class="reference" href="#id46" id="id136" name="id136">Modifying hierarchies</a></li>
-<li><a class="reference" href="#tracing-hierarchies" id="id137" name="id137">Tracing hierarchies</a></li>
-<li><a class="reference" href="#modifying-source-code" id="id138" name="id138">Modifying source code</a></li>
-<li><a class="reference" href="#metaclass-regenerated-hierarchies" id="id139" name="id139">Metaclass regenerated hierarchies</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-programmable-programming-language" id="id140" name="id140">THE PROGRAMMABLE PROGRAMMING LANGUAGE</a><ul>
-<li><a class="reference" href="#enhancing-the-python-language" id="id141" name="id141">Enhancing the Python language</a></li>
-<li><a class="reference" href="#restricting-python-dynamism" id="id142" name="id142">Restricting Python dynamism</a></li>
-<li><a class="reference" href="#changing-the-language-without-changing-the-language" id="id143" name="id143">Changing the language without changing the language</a></li>
-<li><a class="reference" href="#recognizing-magic-comments" id="id144" name="id144">Recognizing magic comments</a></li>
-<li><a class="reference" href="#interpreting-python-source-code-on-the-fly" id="id145" name="id145">Interpreting Python source code on the fly</a></li>
-<li><a class="reference" href="#implementing-lazy-evaluation" id="id146" name="id146">Implementing lazy evaluation</a></li>
-<li><a class="reference" href="#implementing-a-ternary-operator" id="id147" name="id147">Implementing a ternary operator</a></li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="section" id="preface">
-<h1><a class="toc-backref" href="#id49" name="preface">Preface</a></h1>
-<blockquote>
-<pre class="line-block">
-<em>There is only one way to learn: trough examples</em>
-</pre>
-</blockquote>
-<div class="section" id="the-philosophy-of-this-book">
-<h2><a class="toc-backref" href="#id50" name="the-philosophy-of-this-book">The philosophy of this book</a></h2>
-<p>This book is written with the intent to help the programmer going trough
-the fascinating concepts of Object Oriented Programming (OOP), in their
-Python incarnation. Notice that I say to help, not to teach. Actually,
-I do not think that a book can teach OOP or any other non-trivial matter
-in Computer Science or other disciplines. Only the
-practice can teach: practice, then practice, and practice again.
-You must learn yourself from your experiments, not from the books.
-Nevertheless, books are useful. They cannot teach, but they can help.
-They should give you new ideas that you was not thinking about, they should
-show tricks you do not find in the manual, and in general they should be of
-some guidance in the uphill road to knowledge. That is the philosophy
-of this book. For this reason</p>
-<p>1. It is not comprehensive, not systematic;
-it is intended to give ideas and basis: from
-that the reader is expected to cover the missing part on his own,
-browsing the documentation, other sources and other books, and finally
-the definite autority, the source itself.</p>
-<p>2. It will not even try to teach the <em>best</em> practices. I will show what you can
-do with Python, not what you &quot;should&quot; do. Often I will show solutions that are
-not recommended. I am not a mammy saying this is
-good, this is bad, do this do that.</p>
-<p>3. You can only learn from your failures. If you think &quot;it should work, if I do
-X and Y&quot; and it works, then you have learned nothing new.
-You have merely verified
-that your previous knowledge was correct, but you haven't create a new
-knowledge. On the other hand, when you think &quot;it should work, if I do
-X and Y&quot; and it doesn't, then you have learned that your previous knowlegde
-was wrong or incomplete, and you are forced to learn something new to
-overcome the difficulty. For this reason, I think it is useful to report
-not only how to do something, but also to report how not to do something,
-showing the pitfalls of wrong approaches.</p>
-<p>That's in my opinion is the goal of a good book. I don't know if have
-reached this goal or not (the decision is up to the reader), but at least
-I have tried to follow these guidelines.</p>
-<p>Moreover, this is not a book on OOP,
-it is a book on OOP <em>in Python</em>.</p>
-<p>In other words, the point of view of this book is not
-to emphasize general topics of OOP that are exportable to other languages,
-but exactly the opposite: I want to emphasize specific techniques that one
-can only use in Python, or that are difficult to translate to other
-languages. Moreover, I will not provide comparisons with other
-languages (except for the section &quot;Why Python?&quot; in this introduction and
-in few selected other places),
-in order to keep the discussion focused.</p>
-<p>This choice comes from the initial motivation for this book, which was
-to fulfill a gap in the (otherwise excellent) Python documentation.
-The problem is that the available documentation still lacks an accessible
-reference of the new Python 2.2+ object-oriented features.
-Since myself I have learned Python and OOP from scratch,
-I have decided to write this book in order to fill that gap and
-help others.</p>
-<p>The emphasis in this book is not in giving
-solutions to specific problems (even if most of the recipes of this book
-can easily be tailored to solve real life concrete problems), it is in
-teaching how does it work, why it does work in some cases and why does
-not work in some other cases. Avoiding too specific problems has an
-additional bonus, since it allows me to use <em>short</em> examples (the majority
-of the scripts presented here is under 20-30 lines) which I think are
-best suited to teach a new matter <a class="footnote-reference" href="#id2" id="id1" name="id1">[1]</a> . Notice, however, that whereas
-the majority of the scripts in this book are short, it is also true
-that they are pretty <em>dense</em>. The density is due to various reasons:</p>
-<ol class="arabic simple">
-<li>I am defining a lot of helper functions and classes, that are
-reused and enhanced during all the book.</li>
-<li>I am doing a strong use of inheritance, therefore a script at the
-end of the book can inherits from the classes defined through all
-the book;</li>
-<li>A ten line script involving metaclasses can easily perform the equivalent
-of generating hundreds of lines of code in a language without metaclasses
-such as Java or C++.</li>
-</ol>
-<p>To my knowledge, there are no other books covering the same topics with
-the same focus (be warned, however, that I haven't read so many Python
-books ;-). The two references that come closest to the present book are
-the <tt class="literal"><span class="pre">Python</span> <span class="pre">Cookbook</span></tt> by Alex Martelli and David Ascher, and
-Alex Martelli's <tt class="literal"><span class="pre">Python</span> <span class="pre">in</span> <span class="pre">a</span> <span class="pre">Nutshell</span></tt>. They are quite recent books and
-therefore it covers (in much less detail) some of the 2.2 features that are
-the central topics to this book.
-However, the Cookbook reserves to OOP only one chapter and has a quite
-different philosophy from the present book, therefore there is
-practically no overlapping. Also <tt class="literal"><span class="pre">Python</span> <span class="pre">in</span> <span class="pre">a</span> <span class="pre">Nutshell</span></tt> covers
-metaclasses in few pages, whereas half of this book is essentially
-dedied to them. This means that you can read both ;-)</p>
-<table class="footnote" frame="void" id="id2" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1" name="id2">[1]</a></td><td>Readers that prefer the opposite philosophy of using longer,
-real life-like, examples, have already the excellent &quot;Dive into
-Python&quot; book <a class="reference" href="http://diveintopython.org/">http://diveintopython.org/</a> at their disposal. This is
-a very good book that I certainly recommend to any (experienced)
-Python programmer; it is also freely available (just like this ;-).
-However, the choice of arguments is quite different and there is
-essentially no overlap between my book and &quot;Dive into Python&quot;
-(therefore you can read both ;-).</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="for-who-this-book-in-intended">
-<h2><a class="toc-backref" href="#id51" name="for-who-this-book-in-intended">For who this book in intended</a></h2>
-<p>I have tried to make this tutorial useful to a large public of Pythonistas,
-i.e. both people with no previous experience of Object Oriented Programming
-and people with experience on OOP, but unfamiliar with the most
-recent Python 2.2-2.3 features (such as attribute descriptors,
-metaclasses, change of the MRO in multiple inheritance, etc).
-However, this is not a book for beginners: the non-experienced reader should
-check (at least) the Internet sites www.python.org/newbies.com and
-www.awaretek.com, that provide a nice collection of resources for Python
-newbies.</p>
-<p>These are my recommendations for the reader, according to her/his level:</p>
-<ol class="arabic simple">
-<li>If you are an absolute beginner, with no experience on programming,
-this book is <em>not</em> for you (yet ;-). Go to
-<a class="reference" href="http://www.python.org/doc/Newbies.html">http://www.python.org/doc/Newbies.html</a> and read one of the introductive
-texts listed there, then come back here. I recommend &quot;How to Think Like
-a Computer Scientist&quot;, available for free on the net (see
-<a class="reference" href="http://www.ibiblio.org/obp/thinkCSpy/">http://www.ibiblio.org/obp/thinkCSpy/</a>); I found it useful myself when
-I started learning Python; be warned, however, that it refers to the rather
-old Python version 1.5.2. There are also excellent books
-on the market (see <a class="reference" href="http://www.awaretek.com/plf.html">http://www.awaretek.com/plf.html</a>).
-<a class="reference" href="http://www.uselesspython.com/">http://www.uselesspython.com/</a> is a good resource to find recensions
-about available Python books. For free books, look at
-<a class="reference" href="http://www.tcfb.com/freetechbooks/bookphyton.html">http://www.tcfb.com/freetechbooks/bookphyton.html</a> .
-This is <em>not</em> another Python tutorial.</li>
-<li>If you know already (at least) another programming language, but you don't
-know Python, then this book is <em>not</em> for you (again ;-). Read the FAQ, the
-Python Tutorial and play a little with the Standard Library (all this
-material can be downloaded for free from <a class="reference" href="http://www.python.org">http://www.python.org</a>), then
-come back here.</li>
-<li>If you have passed steps 1 and 2, and you are confortable with Python
-at the level of simple procedural programming, but have no clue about
-objects and classes, <em>then</em> this book is for you. Read this book till
-the end and your knowledge of OOP will pass from zero to a quite advanced
-level (hopefully). Of course, you will have to play with the code in
-this book and write a lot of code on your own, first ;-)</li>
-<li>If you are confortable with Python and you also known OOP from other
-languages or from earlier version of Python, then this book is for
-you, too: you are ready to read the more advanced chapters.</li>
-<li>If you are a Python guru, then you should read the book, too. I expect
-you will find the errors and send me feedback, helping me to improve
-this tutorial.</li>
-</ol>
-</div>
-<div class="section" id="about-the-scripts-in-this-book">
-<h2><a class="toc-backref" href="#id52" name="about-the-scripts-in-this-book">About the scripts in this book</a></h2>
-<p>All the scripts in this book are free. You are expected to play
-with them, to modify them and to improve them.</p>
-<p>In order to facilitate the extraction of the scripts from the main text, both
-visually for the reader and automatically for Python, I use the
-convention of sandwiching the body of the example scripts in blocks like this</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;myfirstscript.py&gt;
-
-print &quot;Here Starts the Python Way to Object Oriented Programming !&quot;
-
-#&lt;/myfirstscript.py&gt;
-</pre>
-</blockquote>
-<p>You may extract the source of this script with the a Python program
-called &quot;test.py&quot; and provided in the distribution. Simply give the
-following command:</p>
-<blockquote>
-<pre class="literal-block">
-$ python test.py myfirstscript.py
-</pre>
-</blockquote>
-<p>This will create a file called &quot;myfirstscript.py&quot;, containing the
-source of <tt class="literal"><span class="pre">myfirstscript.py</span></tt>; moreover it will execute the script
-and write its output in a file called &quot;output.txt&quot;. I have tested
-all the scripts in this tutorial under Red Hat Linux 7.x and
-Windows 98SE. You should not have any problem in running them,
-but if a problem is there, &quot;test.py&quot; will probably discover it,
-even if, unfortunately, it will not provide the solution :-(.
-Notice that test.py requires Python 2.3+ to work, since most of
-the examples in this book heavily depends on the new features
-introduced in Python 2.2-2.3. Since the installation of Python
-2.3 is simple, quick and free, I think I am requiring to my readers
-who haven't upgraded yet a very little effort. This is well worth
-the pain since Python 2.3 fixes few bugs of 2.2 (notably in the subject of
-attribute descriptors and the <tt class="literal"><span class="pre">super</span></tt> built-in) that makes</p>
-<p>You may give more arguments to test.py, as in this example:</p>
-<blockquote>
-<pre class="literal-block">
-$ python test.py myfirstscript.py mysecondscript.py
-</pre>
-</blockquote>
-<p>The output of both scripts will still be placed in the file &quot;output.txt&quot;.
-Notice that if you give an argument which is not the name of a script in the
-book, it will be simply ignored. Morever, if you will not give any argument,
-&quot;test.py&quot; will automatically executes all the tutorial scripts, writing their
-output in &quot;output.txt&quot; <a class="footnote-reference" href="#id4" id="id3" name="id3">[2]</a> . You may want to give a look at this file, once
-you have finished the tutorial. It also contains the source code of
-the scripts, for better readability.</p>
-<p>Many examples of this tutorial depend on utility functions defined
-in a external module called <tt class="literal"><span class="pre">oopp</span></tt> (<tt class="literal"><span class="pre">oopp</span></tt> is an obvious abbreviation
-for the title of the tutorial). The module <tt class="literal"><span class="pre">oopp</span></tt> is automatically generated
-by &quot;test.py&quot;, which works by extracting from the tutorial
-text blocks of code of the form <tt class="literal"><span class="pre">#&lt;oopp.py&gt;</span> <span class="pre">something</span> <span class="pre">#&lt;/oopp.py&gt;</span></tt>
-and saving them in a file called &quot;oopp.py&quot;.
-Let me give an example. A very recent enhancement to Python (in
-Python 2.3) has been the addition of a built-in boolean type with
-values True and False:</p>
-<blockquote>
-<pre class="literal-block">
-$ python
-Python 2.3a1 (#1, Jan 6 2003, 10:31:14)
-[GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-108.7.2)] on linux2
-Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
-&gt;&gt;&gt; 1+1==2
-True
-&gt;&gt;&gt; 1+1==3
-False
-&gt;&gt;&gt; type(True)
-&lt;type 'bool'&gt;
-&gt;&gt;&gt; type(False)
-&lt;type 'bool'&gt;
-</pre>
-</blockquote>
-<p>However, previous version of Python use the integers 1 and 0 for
-True and False respectively.</p>
-<blockquote>
-<pre class="literal-block">
-$ python
-Python 2.2 (#1, Apr 12 2002, 15:29:57)
-[GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2
-Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
-&gt;&gt;&gt; 1+1==2
-1
-&gt;&gt;&gt; 1+1==3
-0
-</pre>
-</blockquote>
-<p>Following the 2.3 convension, in this tutorial I will use the names
-<tt class="literal"><span class="pre">True</span></tt> and <tt class="literal"><span class="pre">False</span></tt> to denotes the numbers 1 and 0 respectively.
-This is automatic in Python 2.2.1+, but not in Python 2.2. Therefore,
-for sake of compatibility, it is convenient to set the values <tt class="literal"><span class="pre">True</span></tt>
-and <tt class="literal"><span class="pre">False</span></tt> in our utility module:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import __builtin__
-try:
- __builtin__.True #look if True is already defined
-except AttributeError: # if not add True and False to the builtins
- __builtin__.True = 1
- __builtin__.False = 0
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here there is an example of usage:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;mysecondscript.py&gt;
-
-import oopp
-print &quot;True =&quot;,True,
-print &quot;False =&quot;,False
-
-#&lt;/mysecondscript.py&gt;
-</pre>
-</blockquote>
-<p>The output is &quot;True = 1 False = 0&quot; under Python 2.2 and
-&quot;True = True False = False&quot; under Python 2.3+.</p>
-<table class="footnote" frame="void" id="id4" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id3" name="id4">[2]</a></td><td>&quot;test.py&quot;, invoked without arguments, does not create '.py' files,
-since I don't want to kludge the distribution with dozens of ten-line
-scripts. I expect you may want to save only few scripts as standalone
-programs, and cut and paste the others.</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="conventions-used-in-this-book">
-<h2><a class="toc-backref" href="#id53" name="conventions-used-in-this-book">Conventions used in this book</a></h2>
-<p>Python expressions are denoted with monospaced fonts when in the text.
-Sections marked with an asterisk can be skipped in a first reading.
-Typically they have the purpose of clarifying some subtle point and
-are not needed for the rest of the book. These sections are intended
-for the advanced reader, but could confuse the beginner.
-An example is the section about the difference between methods and
-functions, or the difference between the inheritance constraint and
-the metaclass constraint.</p>
-</div>
-</div>
-<div class="section" id="introduction">
-<h1><a class="toc-backref" href="#id54" name="introduction">Introduction</a></h1>
-<blockquote>
-<pre class="line-block">
-<em>A language that doesn't affect the way you think about programming,
-is not worth knowing.</em> -- Alan Perlis
-</pre>
-</blockquote>
-<div class="section" id="why-oop">
-<h2><a class="toc-backref" href="#id55" name="why-oop">Why OOP ?</a></h2>
-<p>I guess some of my readers, like me, have started programming in the mid-80's,
-when traditional (i.e. non object-oriented) Basic and Pascal where popular as
-first languages. At the time OOP was not as pervasive in software development
-how it is now, most of the mainstream languages were non-object-oriented and
-C++ was just being released. That was a time when the transition from
-spaghetti-code to structured code was already well accomplished, but
-the transition from structured programming to (the first phase of)
-OOP was at the beginning.</p>
-<p>Nowaydays, we live in a similar time of transition . Today, the transition
-to (the first phase of) OOP is well accomplished and essentially all
-mainstream
-languages support some elementary form of OOP. To be clear, when I say
-mainstream langauges, I have in mind Java and C++: C is a remarkable
-exception to the rule, since it is mainstream but not object-oriented.</p>
-<p>However, both Java an C++ (I mean standard Java and C++, not special
-extension like DTS C++, that have quite powerful object oriented features)
-are quite poor object-oriented languages: they provides only the most
-elementary aspects of OOP, the features of the <em>first phase</em> of OOP.</p>
-<p>Hence, today the transition to the <em>second phase</em> of OOP is only at the
-beginning, i.e mainstream language are not yet really OO, but they will
-become OOP in the near future.</p>
-<p>By second phase of OOP I mean the phase in which the primary
-objects of concern for the programmer are no more the objects, but the
-metaobjects. In elementary OOP one works on objects, which have attributes
-and methods (the evolution of old-fashioned data and functions) defined
-by their classes; in the second phase of OOP one works on classes
-which behavior is described by metaclasses. We no more modify objects
-trough classes: nowadays we modify classes and class hierarchies
-through metaclasses and multiple inheritance.</p>
-<p>It would be tempting to represent the history of programming in the last
-quarter of century with an evolutionary table like that:</p>
-<table border class="table">
-<colgroup>
-<col width="33%" />
-<col width="27%" />
-<col width="30%" />
-<col width="10%" />
-</colgroup>
-<thead valign="bottom">
-<tr><th>~1975</th>
-<th>~1985</th>
-<th>~1995</th>
-<th>~2005</th>
-</tr>
-</thead>
-<tbody valign="top">
-<tr><td>procedural programming</td>
-<td>OOP1</td>
-<td>OOP2</td>
-<td>?</td>
-</tr>
-<tr><td>data,functions</td>
-<td>objects,classes</td>
-<td>classes,metaclasses</td>
-<td>?</td>
-</tr>
-</tbody>
-</table>
-<p>The problem is that table would be simply wrong, since in truth
-Smalltalk had metaclasses already 25 years ago! And also Lisp
-had <em>in nuce</em> everything a long <em>long</em> time ago.
-The truth is that certains languages where too much ahead of their
-time ;-)</p>
-<p>Therefore, today we already have all the ideas
-and the conceptual tools to go beyond the first phase of OOP
-(they where invented 20-30 years ago), nevertheless those ideas are
-not yet universally known, nor implemented in mainstream languages.</p>
-<p>Fortunately, there are good languages
-where you can access the bonus of the second phase of OOP (Smalltalk, CLOS,
-Dylan, ...): unfortunately
-most of them are academic and/or little known in the real world
-(often for purely commercial reasons, since typically languages are not
-chosen accordingly to their merits, helas!). Python is an exception to this
-rule, in the sense that it is an eminently practical language (it started
-as a scripting language to do Operating System administrative jobs),
-which is relatively known and used in that application niche (even if some
-people <em>wrongly</em> think that should not be used for 'serious' things).</p>
-<p>There are various reasons why most mainstream languages are rather
-poor languages, i.e. underfeatured languages (as Java) or powerful, but too
-tricky to use, as C++. Some are good reasons (for instance <em>efficiency</em>: if
-efficiency is the first concern, then poor languages can be much
-better suited to the goal: for instance Fortran for number crunching
-and C for system programming), some are less good (economical
-monopoly). There is nothing to do against these reasons: if you
-need efficiency, or if you are forced to use a proprietary language
-because it is the language used by your employer. However, if you
-are free from these restrictions, there is another reason why you
-could not choose to use a poweful language. The reason is that,
-till now, programmers working in the industrial world mostly had simple
-problems (I mean conceptually simple problems). In order to solve
-simple problems one does not need a powerful language, and the effort
-spent in learning it is not worth.</p>
-<p>However, nowadays the situations has changed. Now, with Internet and graphics
-programming everywhere, and object-oriented languages so widespread,
-now it is the time when actually people <em>needs</em> metaprogramming, the
-ability to changing classes and programs. Now everybody is programming
-in the large.</p>
-<p>In this situation, it is justified to spend some time to learn better
-way of programming. And of course, it is convenient to start from
-the language with the flattest learning curve of all.</p>
-</div>
-<div class="section" id="why-python">
-<h2><a class="toc-backref" href="#id56" name="why-python">Why Python ?</a></h2>
-<blockquote>
-<pre class="line-block">
-<em>In many ways, it's a dull language, borrowing solid old concepts from
-many other languages &amp; styles: boring syntax, unsurprising semantics,
-few automatic coercions, etc etc. But that's one of the things I like
-about it.</em> --Tim Peters on Python, 16 Sep 93
-</pre>
-</blockquote>
-<p>If you are reading this book, I assume you already have some experience
-with Python. If this is the case, you already know the obvious advantages
-of Python such as readability, easy of use and short development time.
-Nevertheless, you could only have used Python as a fast and simple
-scripting language. If you are in this situation, then your risk to
-have an incorrect opinion on the language like &quot;it is a nice little
-language, but too simple to be useful in 'real' applications&quot;. The
-truth is that Python is designed to be <em>simple</em>, and actually it
-is; but by no means it is a &quot;shallow&quot; language. Actually, it goes
-quite <em>deep</em>, but it takes some time to appreciate this fact.</p>
-<p>Let me contrast Python with Lisp, for instance. From the beginning,
-Lisp was intended to be a language for experts, for people with difficult
-problems to solve. The first
-users of Lisp were academicians, professors of CS and scientists.
-On the contrary, from the beginning Python
-was intended to be language for everybody (Python predecessor was ABC,
-a language invented to teach CS to children). Python makes great a first
-language for everybody, whereas Lisp would require especially
-clever and motivated students (and we all know that there is lack
-of them ;-)</p>
-<p>From this difference of origins, Python inherits an easy to learn syntax,
-whereas Lisp syntax is horrible for the beginner (even if not as
-horrible as C++ syntax ;-)</p>
-<blockquote>
-<pre class="line-block">
-<em>Macros are a powerful extension to weak languages.
-Powerful languages don't need macros by definition.</em>
--- Christian Tismer on c.l.p. (referring to C)
-</pre>
-</blockquote>
-<p>Despite the differences, Python borrows quite a lot from Lisp and it
-is nearly as expressive as it (I say nearly since Python is
-not as powerful as Lisp: by tradition, Lisp has always been on the top of
-hierarchy of programming language with respect to power of abstraction).
-It is true that Python lacks some powerful Lisp features: for instance
-Python object model lacks multiple dispatching (for the time being ;-)
-and the language lacks Lisp macros (but this unlikely to change in the
-near future since Pythonistas see the lack of macro as a Good Thing <a class="footnote-reference" href="#id6" id="id5" name="id5">[3]</a>):
-nevertheless, the point is that Python is much <em>much</em> easier to learn.
-You have (nearly) all the power, but without the complexity.</p>
-<p>One of the reasons, is that Python
-try to be as <em>less</em> innovative as
-possible: it takes the proven good things from others, more innovative
-languages, and avoids their pitfalls. If you are an experienced
-programmer , it will be even easier to you to learn Python, since
-there is more or less nothing which is really original to Python.
-For instance:</p>
-<ol class="arabic simple">
-<li>the object model is took from languages that are good at it, such
-as Smalltalk;</li>
-<li>multiple inheritance has been modeled from languages good in it. such
-as CLOS and Dylan;</li>
-<li>regular expression follows the road opened by Perl;</li>
-<li>functional features are borrowed from functional languages;</li>
-<li>the idea of documentation strings come from Lisp;</li>
-<li>list comprehension come from Haskell;</li>
-<li>iterators and generators come from Icon;</li>
-<li>etc. etc. (many other points here)</li>
-</ol>
-<p>I thinks the really distinctive feature of Python with respect to
-any other serious language I know, is that Python is <em>easy</em>. You have the
-power (I mean power in conceptual sense, not computational power: in
-the sense of computational power the best languages are
-non-object-oriented ones)
-of the most powerful languages with a very little investement.
-In addition to that, Python has a relatively large user base
-(as compared to Smalltalk or Ruby, or the various fragmented Lisp
-communities). Of course,
-there is quite a difference between the user base of Python with
-respect to the user base of, let say, VisualBasic or Perl. But
-I would never take in consideration VisualBasic for anything serious,
-whereas Perl is too ugly for my taste ;-).
-Finally, Python is <em>practical</em>. With this I mean the fact that
-Python has libraries that
-allow the user to do nearly everything, since you can access all the C/C++
-libraries with little or no effort, and all the Java libraries, though the
-Python implementation known as Jython. In particular, one has the choice
-between many excellent GUI's trough PyQt, wxPython, Tkinter, etc.</p>
-<p>Python started as an Object Oriented Programming
-Languages from the beginning, nevertheless is was never intended to be
-a <em>pure</em> OOPL as SmallTalk or, more recently, Ruby. Python is a
-<em>multiparadigm</em>
-language such a Lisp, that you choose your programming style according
-to your problem: spaghetti-code, structured programming, functional
-programming, object-oriented programming are all supported. You can
-even write bad code in Python, even if it is less simple than in other
-languages ;-). Python is a language which has quite evolved in its twelve
-years of life (the first public release was released in February 1991)
-and many new features have been integrated in the language with time.
-In particular, Python 2.2 (released in 2002) was a major breakthrough
-in the history of the language
-for what concerns support to Object Oriented Programming (OOP).
-Before the 2.2 revolution, Python Object
-Orientation was good; now it is <em>excellent</em>. All the fundamental features
-of OOP, including pretty sophisticated ones, as metaclasses and multiple
-inheritance, have now a very good support (the only missing thing is
-multiple dispatching).</p>
-<table class="footnote" frame="void" id="id6" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id5" name="id6">[3]</a></td><td>Python lacks macros for an intentional design choice: many people
-in the community (including Guido itself) feel that macros are
-&quot;too powerful&quot;. If you give the user the freedom to create her
-own language, you must face at least three problems: i) the risk
-to split the original language in dozens of different dialects;
-ii) in collaborative projects, the individual programmer must
-spend an huge amount of time and effort would be spent in learning
-macro systems written by others; iii) not all users are good
-language designers: the programmer will have to fight with badly
-designed macro systems. Due to these problems, it seems unlikely
-that macros will be added to Python in the future.</td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id7" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id8" name="id7">[4]</a></td><td>For a good comparison between Python and Lisp I remind the reader to
-the excellent Peter Norvig's article in
-<a class="reference" href="http://www.norvig.com/python-lisp.html">http://www.norvig.com/python-lisp.html</a></td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="further-thoughts">
-<h2><a class="toc-backref" href="#id57" name="further-thoughts">Further thoughts</a></h2>
-<p>Actually, the principal reasons why I begun studying
-Python was the documentation and the newsgroup: Python has an outstanding
-freely available documentation and an incredibly helpful newsgroup that
-make extremely easy to learn the language. If I had found a comparable
-free documentation/newsgroup for C++ or Lisp, I would have studied that
-languages instead.</p>
-<p>Unfortunately, the enormous development at the software level, had no
-correspondence with with an appropriate development of documentation.
-As a consequence, the many beatiful, powerful and extremely <em>useful</em>
-new features of Python 2.2+ object orientation are mostly remained
-confined to developers and power users: the average Python programmer
-has remained a little a part from the rapid development and she
-<em>wrongly</em> thinks she has no use for the new features. There have
-also been <em>protestations</em> of the users against developers of the
-kind &quot;please, stop adding thousands of complicated new extensions
-to the language for which we have no use&quot; !</p>
-<p>Extending a language is always a delicate thing to do, for a whole
-bunch of reasons:</p>
-<ol class="arabic simple">
-<li>once one extension is done, it is there <em>forever</em>.</li>
-</ol>
-<p>My experience has been the following.</p>
-<p>When I first read about metaclasses, in Guido's essay
-&quot;Unifying types and classes in Python 2.2&quot;, I thought &quot;Wow,
-classes of classes, cool concept, but how useful is it?
-Are metaclasses really providing some new functionality?
-What can I do with metaclasses that I cannot do without?&quot;</p>
-<p>Clearly, in these terms, the question is rather retorical, since in principle
-any Turing-complete programming languages contains all the features provided
-by metaclasses. Python metaclasses themselves are implemented in C, that has
-no metaclasses. Therefore, my real question was not &quot;What can I do
-with metaclasses that I cannot do without?&quot; but &quot;How big is the convenience
-provided by metaclasses, with respect to my typical applications?&quot;.</p>
-<p>The answer depends on the kind of problem you are considering. For certain
-classes of problems it can be <em>very</em> large, as I will show in this and in
-the next chapters.</p>
-<p>I think the biggest advantage of metaclasses is <em>elegance</em>. Altough it
-is true that most of what you can do with metaclasses, can be done without
-metaclasses, not using metaclasses can result in a much <em>uglier</em> solution.</p>
-<p>One needs difficult problems in order to appreciate the advantage
-of powerful methods.</p>
-<p>If all you need is to write few scripts for copying two or three files,
-there is no point in learning OOP.On the other hand, if you only
-write simple programs where you define only one of two classes, there
-is no point in using metaclasses. Metaclasses becomes relevant only
-when you have many classes, whole classes of classes with similar
-features that you want to modify.</p>
-<p>In this sense, metaprogramming is for experts only, i.e. with people
-with difficult problems. The point however, is that nowaydays,
-many persons have difficult problems.</p>
-<p>Finally, let me conclude this preface by recalling the
-gist of Python wisdom.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import this
-The Zen of Python, by Tim Peters
-.
-Beautiful is better than ugly.
-Explicit is better than implicit.
-Simple is better than complex.
-Complex is better than complicated.
-Flat is better than nested.
-Sparse is better than dense.
-Readability counts.
-Special cases aren't special enough to break the rules.
-Although practicality beats purity.
-Errors should never pass silently.
-Unless explicitly silenced.
-In the face of ambiguity, refuse the temptation to guess.
-There should be one-- and preferably only one --obvious way to do it.
-Although that way may not be obvious at first unless you're Dutch.
-Now is better than never.
-Although never is often better than *right* now.
-If the implementation is hard to explain, it's a bad idea.
-If the implementation is easy to explain, it may be a good idea.
-Namespaces are one honking great idea -- let's do more of those!
-</pre>
-</blockquote>
-</div>
-</div>
-<div class="section" id="first-things-first">
-<h1><a class="toc-backref" href="#id58" name="first-things-first">FIRST THINGS, FIRST</a></h1>
-<p>This is an introductory chapter, with the main purpose of fixing the
-terminology used in the sequel. In particular, I give the definitions
-of objects, classes, attributes and methods. I discuss a few examples
-and I show some of the most elementary Python introspection features.</p>
-<div class="section" id="what-s-an-object">
-<h2><a class="toc-backref" href="#id59" name="what-s-an-object">What's an object?</a></h2>
-<blockquote>
-<pre class="line-block">
-<em>So Everything Is An object.
-I'm sure the Smalltalkers are very happy :)</em>
-
--- Michael Hudson on comp.lang.python
-</pre>
-</blockquote>
-<p>&quot;What's an object&quot; is the obvious question raised by anybody starting
-to learn Object Oriented Programming. The answer is simple: in Python,
-everything in an object!</p>
-<p>An operative definition is the following: an <em>object</em>
-is everything that can be labelled with an <em>object reference</em>.</p>
-<p>In practical terms, the object reference is implemented as
-the object memory address, that is an integer number which uniquely
-specify the object. There is a simple way to retrieve the object reference:
-to use the builtin <tt class="literal"><span class="pre">id</span></tt> function. Informations on <tt class="literal"><span class="pre">id</span></tt> can be retrieved
-via the <tt class="literal"><span class="pre">help</span></tt> function <a class="footnote-reference" href="#id7" id="id8" name="id8">[4]</a>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; help(id)
-Help on built-in function id:
-id(...)
-id(object) -&gt; integer
-Return the identity of an object. This is guaranteed to be unique among
-simultaneously existing objects. (Hint: it's the object's memory address.)
-</pre>
-</blockquote>
-<p>The reader is strongly encouraged to try the help function on everything
-(including help(help) ;-). This is the best way to learn how Python works,
-even <em>better</em> than reading the standard documentation, since the on-line
-help is often more update.</p>
-<p>Suppose for instance we wonder if the number <tt class="literal"><span class="pre">1</span></tt> is an object:
-it is easy enough to ask Python for the answer:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; id(1)
-135383880
-</pre>
-</blockquote>
-<p>Therefore the number 1 is a Python object and it is stored at the memory
-address 135383880, at least in my computer and during the current session.
-Notice that the object reference is a dynamic thing; nevertheless it
-is guaranteed to be unique and constant for a given object during its
-lifetime (two objects whose lifetimes are disjunct may have the same id()
-value, though).</p>
-<p>Here there are other examples of built-in objects:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; id(1L) # long
-1074483312
-&gt;&gt;&gt; id(1.0) #float
-135682468
-&gt;&gt;&gt; id(1j) # complex
-135623440
-&gt;&gt;&gt; id('1') #string
-1074398272
-&gt;&gt;&gt; id([1]) #list
-1074376588
-&gt;&gt;&gt; id((1,)) #tuple
-1074348844
-&gt;&gt;&gt; id({1:1}) # dict
-1074338100
-</pre>
-</blockquote>
-<p>Even functions are objects:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(x): return x #user-defined function
-&gt;&gt;&gt; id(f)
-1074292020
-&gt;&gt;&gt; g=lambda x: x #another way to define functions
-&gt;&gt;&gt; id(g)
-1074292468
-&gt;&gt;&gt; id(id) #id itself is a built-in function
-1074278668
-</pre>
-</blockquote>
-<p>Modules are objects, too:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import math
-&gt;&gt;&gt; id(math) #module of the standard library
-1074239068
-&gt;&gt;&gt; id(math.sqrt) #function of the standard library
-1074469420
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">help</span></tt> itself is an object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; id(help)
-1074373452
-</pre>
-</blockquote>
-<p>Finally, we may notice that the reserved keywords are not objects:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; id(print) #error
-File &quot;&lt;string&gt;&quot;, line 1
- id(print) ^
-SyntaxError: invalid syntax
-</pre>
-</blockquote>
-<p>The operative definition is convenient since it gives a practical way
-to check if something is an object and, more importantly, if two
-objects are the same or not:</p>
-<blockquote>
-<!-- doctest -->
-<pre class="doctest-block">
-&gt;&gt;&gt; s1='spam'
-&gt;&gt;&gt; s2='spam'
-&gt;&gt;&gt; s1==s2
-True
-&gt;&gt;&gt; id(s1)==id(s2)
-True
-</pre>
-</blockquote>
-<p>A more elegant way of spelling <tt class="literal"><span class="pre">id(obj1)==id(obj2)</span></tt> is to use the
-keyword <tt class="literal"><span class="pre">is</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; s1 is s2
-True
-</pre>
-</blockquote>
-<p>However, I should warn the reader that sometimes <tt class="literal"><span class="pre">is</span></tt> can be surprising:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; id([]) == id([])
-True
-&gt;&gt;&gt; [] is []
-False
-</pre>
-</blockquote>
-<p>This is happening because writing <tt class="literal"><span class="pre">id([])</span></tt> dynamically creates an unique
-object (a list) which goes away when you're finished with it. So when an
-expression needs both at the same time (<tt class="literal"><span class="pre">[]</span> <span class="pre">is</span> <span class="pre">[]</span></tt>), two unique objects
-are created, but when an expression doesn't need both at the same time
-(<tt class="literal"><span class="pre">id([])</span> <span class="pre">==</span> <span class="pre">id([])</span></tt>), an object gets created with an ID, is destroyed,
-and then a second object is created with the same ID (since the last one
-just got reclaimed) and their IDs compare equal. In other words, &quot;the
-ID is guaranteed to be unique <em>only</em> among simultaneously existing objects&quot;.</p>
-<p>Another surprise is the following:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; a=1
-&gt;&gt;&gt; b=1
-&gt;&gt;&gt; a is b
-True
-&gt;&gt;&gt; a=556
-&gt;&gt;&gt; b=556
-&gt;&gt;&gt; a is b
-False
-</pre>
-</blockquote>
-<p>The reason is that integers between 0 and 99 are pre-instantiated by the
-interpreter, whereas larger integers are recreated each time.</p>
-<p>Notice the difference between '==' and 'is':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; 1L==1
-True
-</pre>
-</blockquote>
-<p>but</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; 1L is 1
-False
-</pre>
-</blockquote>
-<p>since they are different objects:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; id(1L) # long 1
-135625536
-&gt;&gt;&gt; id(1) # int 1
-135286080
-</pre>
-</blockquote>
-<p>The disadvantage of the operative definition is that it gives little
-understanding of what an object can be used for. To this aim, I must
-introduce the concept of <em>class</em>.</p>
-<table class="footnote" frame="void" id="id9" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id10" name="id9">[5]</a></td><td>Actually <tt class="literal"><span class="pre">help</span></tt> is not a function but a callable object. The
-difference will be discussed in a following chapter.</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="objects-and-classes">
-<h2><a class="toc-backref" href="#id60" name="objects-and-classes">Objects and classes</a></h2>
-<p>It is convenient to think of an object as an element of a set.</p>
-<p>It you think a bit, this is the most general definition that actually
-grasps what we mean by object in the common language.
-For instance, consider this book, &quot;Object Oriented Programming in Python&quot;:
-this book is an object, in the sense that it is a specific representative
-of the <em>class</em> of all possible books.
-According to this definition, objects are strictly related to classes, and
-actually we say that objects are <em>instances</em> of classes.</p>
-<p>Classes are nested: for
-instance this book belongs to the class of books about programming
-language, which is a subset of the class of all possible books;
-moreover we may further specify this book as a Python book; moreover
-we may specify this book as a Python 2.2+ book. There is no limit
-to the restrictions we may impose to our classes.
-On the other hand. it is convenient to have a &quot;mother&quot; class,
-such that any object belongs to it. All strongly Object Oriented
-Language have such a class <a class="footnote-reference" href="#id9" id="id10" name="id10">[5]</a>; in Python it is called <em>object</em>.</p>
-<p>The relation between objects and classes in Python can be investigated
-trough the built-in function <tt class="literal"><span class="pre">type</span></tt> <a class="footnote-reference" href="#id12" id="id11" name="id11">[6]</a> that gives the class of any
-Python object.</p>
-<p>Let me give some example:</p>
-<ol class="arabic simple">
-<li>Integers numbers are instances of the class <tt class="literal"><span class="pre">int</span></tt> or <tt class="literal"><span class="pre">long</span></tt>:</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(1)
-&lt;type 'int'&gt;
-&gt;&gt;&gt; type(1L)
-&lt;type 'long'&gt;
-</pre>
-</blockquote>
-<ol class="arabic simple" start="2">
-<li>Floating point numbers are instances of the class <tt class="literal"><span class="pre">float</span></tt>:</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(1.0)
-&lt;type 'float'&gt;
-</pre>
-</blockquote>
-<ol class="arabic simple" start="3">
-<li>Complex numbers are instances of the class <tt class="literal"><span class="pre">complex</span></tt>:</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(1.0+1.0j)
-&lt;type 'complex'&gt;
-</pre>
-</blockquote>
-<ol class="arabic simple" start="4">
-<li>Strings are instances of the class <tt class="literal"><span class="pre">str</span></tt>:</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type('1')
-&lt;type 'str'&gt;
-</pre>
-</blockquote>
-<ol class="arabic simple" start="5">
-<li>List, tuples and dictionaries are instances of <tt class="literal"><span class="pre">list</span></tt>, <tt class="literal"><span class="pre">tuple</span></tt> and
-<tt class="literal"><span class="pre">dict</span></tt> respectively:</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type('1')
-&lt;type 'str'&gt;
-&gt;&gt;&gt; type([1])
-&lt;type 'list'&gt;
-&gt;&gt;&gt; type((1,))
-&lt;type 'tuple'&gt;
-&gt;&gt;&gt; type({1:1})
-&lt;type 'dict'&gt;
-</pre>
-</blockquote>
-<ol class="arabic simple" start="6">
-<li>User defined functions are instances of the <tt class="literal"><span class="pre">function</span></tt> built-in type</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(f)
-&lt;type 'function'&gt;
-&gt;&gt;&gt; type(g)
-&lt;type 'function'&gt;
-</pre>
-</blockquote>
-<p>All the previous types are subclasses of object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; for cl in int,long,float,str,list,tuple,dict: issubclass(cl,object)
-True
-True
-True
-True
-True
-True
-True
-</pre>
-</blockquote>
-<p>However, Python is not a 100% pure Object
-Oriented Programming language and its object model has still some minor
-warts, due to historical accidents.</p>
-<p>Paraphrasing George Orwell, we may say that in Python 2.2-2.3,
-all objects are equal, but some objects are more equal than others.
-Actually, we may distinguish Python objects in new style objects,
-or rich man objects, and old style objects, or poor man objects.
-New style objects are instances of new style classes whereas old
-style objects are instances of old style classes.
-The difference is that new style classes are subclasses of object whereas
-old style classes are not.</p>
-<p>Old style classes are there for sake of compatibility with previous
-releases of Python, but starting from Python 2.2 practically all built-in
-classes are new style classes.</p>
-<p>Instance of old style classes are called old style objects. I will give
-few examples of old style objects in the future.</p>
-<p>In this tutorial with the term
-object <em>tout court</em> we will mean new style objects, unless the contrary
-is explicitely stated.</p>
-<table class="footnote" frame="void" id="id12" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id11" name="id12">[6]</a></td><td>one may notice that C++ does not have such a class, but C++
-is <em>not</em> a strongly object oriented language ;-)</td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id13" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id14" name="id13">[7]</a></td><td>Actually <tt class="literal"><span class="pre">type</span></tt> is not a function, but a metaclass; nevertheless,
-since this is an advanced concept, discussed in the fourth chapter;
-for the time being it is better to think of <tt class="literal"><span class="pre">type</span></tt> as a built-in
-function analogous to <tt class="literal"><span class="pre">id</span></tt>.</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="objects-have-attributes">
-<h2><a class="toc-backref" href="#id61" name="objects-have-attributes">Objects have attributes</a></h2>
-<p>All objects have attributes describing their characteristics, that may
-be accessed via the dot notation</p>
-<blockquote>
-<pre class="literal-block">
-objectname.objectattribute
-</pre>
-</blockquote>
-<p>The dot notation is common to most Object Oriented programming languages,
-therefore the reader with a little of experience should find it not surprising
-at all (Python strongly believes in the Principle of Least Surprise). However,
-Python objects also have special attributes denoted by the double-double
-underscore notation</p>
-<blockquote>
-<pre class="literal-block">
-objectname.__specialattribute__
-</pre>
-</blockquote>
-<p>with the aim of helping the wonderful Python introspection features, that
-does not have correspondence in all OOP language.</p>
-<p>Consider for example the string literal &quot;spam&quot;. We may discover its
-class by looking at its special attribute <em>__class__</em>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; 'spam'.__class__
-&lt;type 'str'&gt;
-</pre>
-</blockquote>
-<p>Using the <tt class="literal"><span class="pre">__class__</span></tt> attribute is not always equivalent to using the
-<tt class="literal"><span class="pre">type</span></tt> function, but it works for all built-in types. Consider for instance
-the number <em>1</em>: we may extract its class as follows:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; (1).__class__
-&lt;type 'int'&gt;
-</pre>
-</blockquote>
-<p>Notice that the parenthesis are needed to avoid confusion between the integer
-1 and the float (1.).</p>
-<p>The non-equivalence type/class is the key to distinguish new style objects from
-old style, since for old style objects <tt class="literal"><span class="pre">type(obj)&lt;&gt;obj.__class__</span></tt>.
-We may use this knowledge to make and utility function that discovers
-if an object is a &quot;real&quot; object (i.e. new style) or a poor man object:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def isnewstyle(obj):
- try: #some objects may lack a __class__ attribute
- obj.__class__
- except AttributeError:
- return False
- else: #look if there is unification type/class
- return type(obj) is obj.__class__
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Let us check this with various examples:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import isnewstyle
-&gt;&gt;&gt; isnewstyle(1)
-True
-&gt;&gt;&gt; isnewstyle(lambda x:x)
-True
-&gt;&gt;&gt; isnewstyle(id)
-True
-&gt;&gt;&gt; isnewstyle(type)
-True
-&gt;&gt;&gt; isnewstyle(isnewstyle)
-True
-&gt;&gt;&gt; import math
-&gt;&gt;&gt; isnewstyle(math)
-True
-&gt;&gt;&gt; isnewstyle(math.sqrt)
-True
-&gt;&gt;&gt; isnewstyle('hello')
-True
-</pre>
-</blockquote>
-<p>It is not obvious to find something which is not a real object,
-between the built-in objects, however it is possible. For instance,
-the <tt class="literal"><span class="pre">help</span></tt> &quot;function&quot; is an old style object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; isnewstyle(help)
-False
-</pre>
-</blockquote>
-<p>since</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; help.__class__
-&lt;class site._Helper at 0x8127c94&gt;
-</pre>
-</blockquote>
-<p>is different from</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(help)
-&lt;type 'instance'&gt;
-</pre>
-</blockquote>
-<p>Regular expression objects are even poorer objects with no <tt class="literal"><span class="pre">__class__</span></tt>
-attribute:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import re
-&gt;&gt;&gt; reobj=re.compile('somestring')
-&gt;&gt;&gt; isnewstyle(reobj)
-False
-&gt;&gt;&gt; type(reobj)
-&lt;type '_sre.SRE_Pattern'&gt;
-&gt;&gt;&gt; reobj.__class__ #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: __class__
-</pre>
-</blockquote>
-<p>There other special attributes other than <tt class="literal"><span class="pre">__class__</span></tt>; a particularly useful
-one is <tt class="literal"><span class="pre">__doc__</span></tt>, that contains informations on the class it
-refers to. Consider for instance the <tt class="literal"><span class="pre">str</span></tt> class: by looking at its
-<tt class="literal"><span class="pre">__doc__</span></tt> attribute we can get information on the usage of this class:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; str.__doc__
-str(object) -&gt; string
-Return a nice string representation of the object.
-If the argument is a string, the return value is the same object.
-</pre>
-</blockquote>
-<p>From that docstring we learn how to convert generic objects in strings;
-for instance we may convert numbers, lists, tuples and dictionaries:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; str(1)
-'1'
-&gt;&gt;&gt; str([1])
-'[1]'
-&gt;&gt;&gt; str((1,))
-(1,)'
-&gt;&gt;&gt; str({1:1})
-'{1: 1}'
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">str</span></tt> is implicitely called each time we use the <tt class="literal"><span class="pre">print</span></tt> statement, since
-<tt class="literal"><span class="pre">print</span> <span class="pre">obj</span></tt> is actually syntactic sugar for <tt class="literal"><span class="pre">print</span> <span class="pre">str(obj)</span></tt>.</p>
-<p>Classes and modules have another interesting special attribute, the
-<tt class="literal"><span class="pre">__dict__</span></tt> attribute that gives the content of the class/module.
-For instance, the contents of the standard <tt class="literal"><span class="pre">math</span></tt> module can be retrieved
-as follows:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import math
-&gt;&gt;&gt; for key in math.__dict__: print key,
-...
-fmod atan pow __file__ cosh ldexp hypot sinh __name__ tan ceil asin cos
-e log fabs floor tanh sqrt __doc__ frexp atan2 modf exp acos pi log10 sin
-</pre>
-</blockquote>
-<p>Alternatively, one can use the built-in function <tt class="literal"><span class="pre">vars</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; vars(math) is math.__dict__
-True
-</pre>
-</blockquote>
-<p>This identity is true for any object with a <tt class="literal"><span class="pre">__dict__</span></tt> attribute.
-Two others interesting special attributes are <tt class="literal"><span class="pre">__doc__</span></tt></p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print math.__doc__
-This module is always available. It provides access to the
-mathematical functions defined by the C standard.
-</pre>
-</blockquote>
-<p>and <tt class="literal"><span class="pre">__file__</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; math.__file__ #gives the file associated with the module
-'/usr/lib/python2.2/lib-dynload/mathmodule.so'
-</pre>
-</blockquote>
-</div>
-<div class="section" id="objects-have-methods">
-<h2><a class="toc-backref" href="#id62" name="objects-have-methods">Objects have methods</a></h2>
-<p>In addition to attributes, objects also have <em>methods</em>, i.e.
-functions attached to their classes <a class="footnote-reference" href="#id13" id="id14" name="id14">[7]</a>.
-Methods are also invoked with the dot notation, but
-they can be distinguished by attributes because they are typically
-called with parenthesis (this is a little simplistic, but it is enough for
-an introductory chapter). As a simple example, let me show the
-invocation of the <tt class="literal"><span class="pre">split</span></tt> method for a string object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; s='hello world!'
-&gt;&gt;&gt; s.split()
-['hello', 'world!']
-</pre>
-</blockquote>
-<p>In this example <tt class="literal"><span class="pre">s.split</span></tt> is called a <em>bount method</em>, since it is
-applied to the string object <tt class="literal"><span class="pre">s</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; s.split
-&lt;built-in method split of str object at 0x81572b8&gt;
-</pre>
-</blockquote>
-<p>An <em>unbound method</em>, instead, is applied to the class: in this case the
-unbound version of <tt class="literal"><span class="pre">split</span></tt> is applied to the <tt class="literal"><span class="pre">str</span></tt> class:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; str.split
-&lt;method 'split' of 'str' objects&gt;
-</pre>
-</blockquote>
-<p>A bound method is obtained from its corresponding unbound
-method by providing the object to the unbound method: for instance
-by providing <tt class="literal"><span class="pre">s</span></tt> to <tt class="literal"><span class="pre">str.split</span></tt> we obtain the same effect of <cite>s.split()</cite>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; str.split(s)
-['hello', 'world!']
-</pre>
-</blockquote>
-<p>This operation is called <em>binding</em> in the Python literature: when write
-<tt class="literal"><span class="pre">str.split(s)</span></tt> we bind the unbound method <tt class="literal"><span class="pre">str.split</span></tt> to the object <tt class="literal"><span class="pre">s</span></tt>.
-It is interesting to recognize that the bound and unbound methods are
-<em>different</em> objects:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; id(str.split) # unbound method reference
-135414364
-&gt;&gt;&gt; id(s.split) # this is a different object!
-135611408
-</pre>
-</blockquote>
-<p>The unbound method (and therefore the bound method) has a <tt class="literal"><span class="pre">__doc__</span></tt>
-attribute explaining how it works:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print str.split.__doc__
-S.split([sep [,maxsplit]]) -&gt; list of strings
-Return a list of the words in the string S, using sep as the
-delimiter string. If maxsplit is given, at most maxsplit
-splits are done. If sep is not specified or is None, any
-whitespace string is a separator.
-</pre>
-</blockquote>
-<table class="footnote" frame="void" id="id15" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id17" name="id15">[8]</a></td><td>A precise definition will be given in chapter 5 that introduces the
-concept of attribute descriptors. There are subtle
-differences between functions and methods.</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="summing-objects">
-<h2><a class="toc-backref" href="#id63" name="summing-objects">Summing objects</a></h2>
-<p>In a pure object-oriented world, there are no functions and everything is
-done trough methods. Python is not a pure OOP language, however quite a
-lot is done trough methods. For instance, it is quite interesting to analyze
-what happens when an apparently trivial statement such as</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; 1+1
-2
-</pre>
-</blockquote>
-<p>is executed in an object-oriented world.</p>
-<p>The key to understand, is to notice that the number 1 is an object, specifically
-an instance of class <tt class="literal"><span class="pre">int</span></tt>: this means that that 1 inherits all the methods
-of the <tt class="literal"><span class="pre">int</span></tt> class. In particular it inherits a special method called
-<tt class="literal"><span class="pre">__add__</span></tt>: this means 1+1 is actually syntactic sugar for</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; (1).__add__(1)
-2
-</pre>
-</blockquote>
-<p>which in turns is syntactic sugar for</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; int.__add__(1,1)
-2
-</pre>
-</blockquote>
-<p>The same is true for subtraction, multiplication, division and other
-binary operations.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; 'hello'*2
-'hellohello'
-&gt;&gt;&gt; (2).__mul__('hello')
-'hellohello'
-&gt;&gt;&gt; str.__mul__('hello',2)
-'hellohello'
-</pre>
-</blockquote>
-<p>However, notice that</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; str.__mul__(2,'hello') #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: descriptor '__mul__' requires a 'str' object but received a 'int'
-</pre>
-</blockquote>
-<p>The fact that operators are implemented as methods, is the key to
-<em>operator overloading</em>: in Python (as well as in other OOP languages)
-the user can redefine the operators. This is already done by default
-for some operators: for instance the operator <tt class="literal"><span class="pre">+</span></tt> is overloaded
-and works both for integers, floats, complex numbers and for strings.</p>
-</div>
-<div class="section" id="inspecting-objects">
-<h2><a class="toc-backref" href="#id64" name="inspecting-objects">Inspecting objects</a></h2>
-<p>In Python it is possible to retrieve most of the attributes and methods
-of an object by using the built-in function <tt class="literal"><span class="pre">dir()</span></tt>
-(try <tt class="literal"><span class="pre">help(dir)</span></tt> for more information).</p>
-<p>Let me consider the simplest case of a generic object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; obj=object()
-&gt;&gt;&gt; dir(obj)
-['__class__', '__delattr__', '__doc__', '__getattribute__',
- '__hash__', '__init__', '__new__', '__reduce__', '__repr__',
- '__setattr__', '__str__']
-</pre>
-</blockquote>
-<p>As we see, there are plenty of attributes available
-even to a do nothing object; many of them are special attributes
-providing introspection capabilities which are not
-common to all programming languages. We have already discussed the
-meaning of some of the more obvious special attributes.
-The meaning of some of the others is quite non-obvious, however.
-The docstring is invaluable in providing some clue.</p>
-<p>Notice that there are special <em>hidden</em> attributes that cannot be retrieved
-with <tt class="literal"><span class="pre">dir()</span></tt>. For instance the <tt class="literal"><span class="pre">__name__</span></tt> attribute, returning the
-name of the object (defined for classes, modules and functions)
-and the <tt class="literal"><span class="pre">__subclasses__</span></tt> method, defined for classes and returning the
-list of immediate subclasses of a class:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; str.__name__
-'str'
-&gt;&gt;&gt; str.__subclasses__.__doc__
-'__subclasses__() -&gt; list of immediate subclasses'
-&gt;&gt;&gt; str.__subclasses__() # no subclasses of 'str' are currently defined
-[]
-</pre>
-</blockquote>
-<p>For instance by doing</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; obj.__getattribute__.__doc__
-&quot;x.__getattribute__('name') &lt;==&gt; x.name&quot;
-</pre>
-</blockquote>
-<p>we discover that the expression <tt class="literal"><span class="pre">x.name</span></tt> is syntactic sugar for</p>
-<blockquote>
-<tt class="literal"><span class="pre">x.__getattribute__('name')</span></tt></blockquote>
-<p>Another equivalent form which is more often used is</p>
-<blockquote>
-<tt class="literal"><span class="pre">getattr(x,'name')</span></tt></blockquote>
-<p>We may use this trick to make a function that retrieves all the
-attributes of an object except the special ones:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def special(name): return name.startswith('__') and name.endswith('__')
-
-def attributes(obj,condition=lambda n,v: not special(n)):
- &quot;&quot;&quot;Returns a dictionary containing the accessible attributes of
- an object. By default, returns the non-special attributes only.&quot;&quot;&quot;
- dic={}
- for attr in dir(obj):
- try: v=getattr(obj,attr)
- except: continue #attr is not accessible
- if condition(attr,v): dic[attr]=v
- return dic
-
-getall = lambda n,v: True
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Notice that certain attributes may be unaccessible (we will see how
-to make attributes unaccessible in a following chapter)
-and in this case they are simply ignored.
-For instance you may retrieve the regular (i.e. non special)
-attributes of the built-in functions:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import attributes
-&gt;&gt;&gt; attributes(f).keys()
-['func_closure', 'func_dict', 'func_defaults', 'func_name',
- 'func_code', 'func_doc', 'func_globals']
-</pre>
-</blockquote>
-<p>In the same vein of the <tt class="literal"><span class="pre">getattr</span></tt> function, there is a built-in
-<tt class="literal"><span class="pre">setattr</span></tt> function (that actually calls the <tt class="literal"><span class="pre">__setattr__</span></tt> built-in
-method), that allows the user to change the attributes and methods of
-and object. Informations on <tt class="literal"><span class="pre">setattr</span></tt> can be retrieved from the help
-function:</p>
-<blockquote>
-<pre class="literal-block">
-&gt;&gt;&gt; help(setattr)
-Help on built-in function setattr:
-setattr(...)
-setattr(object, name, value)
-Set a named attribute on an object; setattr(x, 'y', v) is equivalent to
-``x.y = v''.
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">setattr</span></tt> can be used to add attributes to an object:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import sys
-
-def customize(obj,errfile=None,**kw):
- &quot;&quot;&quot;Adds attributes to an object, if possible. If not, writes an error
- message on 'errfile'. If errfile is None, skips the exception.&quot;&quot;&quot;
- for k in kw:
- try:
- setattr(obj,k,kw[k])
- except: # setting error
- if errfile:
- print &gt;&gt; errfile,&quot;Error: %s cannot be set&quot; % k
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>The attributes of built-in objects cannot be set, however:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import customize,sys
-&gt;&gt;&gt; customize(object(),errfile=sys.stdout,newattr='hello!') #error
-AttributeError: newattr cannot be set
-</pre>
-</blockquote>
-<p>On the other hand, the attributes of modules can be set:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import time
-&gt;&gt;&gt; customize(time,newattr='hello!')
-&gt;&gt;&gt; time.newattr
-'hello!'
-</pre>
-</blockquote>
-<p>Notice that this means we may enhances modules at run-time, but adding
-new routines, not only new data attributes.</p>
-<p>The <tt class="literal"><span class="pre">attributes</span></tt> and <tt class="literal"><span class="pre">customize</span></tt> functions work for any kind of objects;
-in particular, since classes are a special kind of objects, they work
-for classes, too. Here are the attributes of the <tt class="literal"><span class="pre">str</span></tt>, <tt class="literal"><span class="pre">list</span></tt> and
-<tt class="literal"><span class="pre">dict</span></tt> built-in types:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import attributes
-&gt;&gt;&gt; attributes(str).keys()
-['startswith', 'rjust', 'lstrip', 'swapcase', 'replace','encode',
- 'endswith', 'splitlines', 'rfind', 'strip', 'isdigit', 'ljust',
- 'capitalize', 'find', 'count', 'index', 'lower', 'translate','join',
- 'center', 'isalnum','title', 'rindex', 'expandtabs', 'isspace',
- 'decode', 'isalpha', 'split', 'rstrip', 'islower', 'isupper',
- 'istitle', 'upper']
-&gt;&gt;&gt; attributes(list).keys()
-['append', 'count', 'extend', 'index', 'insert', 'pop',
- 'remove', 'reverse', 'sort']
-&gt;&gt;&gt; attributes(dict).keys()
-['clear','copy','fromkeys', 'get', 'has_key', 'items','iteritems',
- 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault',
- 'update', 'values']
-</pre>
-</blockquote>
-<p>Classes and modules have a special attribute <tt class="literal"><span class="pre">__dict__</span></tt> giving the
-dictionary of their attributes. Since it is often a quite large dictionary,
-it is convenient to define an utility function printing this dictionary in a
-nice form:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def pretty(dic):
- &quot;Returns a nice string representation for the dictionary&quot;
- keys=dic.keys(); keys.sort() # sorts the keys
- return '\n'.join(['%s = %s' % (k,dic[k]) for k in keys])
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>I encourage the use of this function in order to retrieve more
-information about the modules of the standard library:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import pretty
-&gt;&gt;&gt; import time #look at the 'time' standard library module
-&gt;&gt;&gt; print pretty(vars(time))
-__doc__ = This module provides various functions to manipulate time values.
-There are two standard representations of time. One is the number
-of seconds since the Epoch, in UTC (a.k.a. GMT). It may be an integer
-or a floating point number (to represent fractions of seconds).
-The Epoch is system-defined; on Unix, it is generally January 1st, 1970.
-The actual value can be retrieved by calling gmtime(0).
-The other representation is a tuple of 9 integers giving local time.
-The tuple items are:
- year (four digits, e.g. 1998)
- month (1-12)
- day (1-31)
- hours (0-23)
- minutes (0-59)
- seconds (0-59)
- weekday (0-6, Monday is 0)
- Julian day (day in the year, 1-366)
- DST (Daylight Savings Time) flag (-1, 0 or 1)
-If the DST flag is 0, the time is given in the regular time zone;
-if it is 1, the time is given in the DST time zone;
-if it is -1, mktime() should guess based on the date and time.
-Variables:
-timezone -- difference in seconds between UTC and local standard time
-altzone -- difference in seconds between UTC and local DST time
-daylight -- whether local time should reflect DST
-tzname -- tuple of (standard time zone name, DST time zone name)
-Functions:
-time() -- return current time in seconds since the Epoch as a float
-clock() -- return CPU time since process start as a float
-sleep() -- delay for a number of seconds given as a float
-gmtime() -- convert seconds since Epoch to UTC tuple
-localtime() -- convert seconds since Epoch to local time tuple
-asctime() -- convert time tuple to string
-ctime() -- convert time in seconds to string
-mktime() -- convert local time tuple to seconds since Epoch
-strftime() -- convert time tuple to string according to format specification
-strptime() -- parse string to time tuple according to format specification
-__file__ = /usr/local/lib/python2.3/lib-dynload/time.so
-__name__ = time
-accept2dyear = 1
-altzone = 14400
-asctime = &lt;built-in function asctime&gt;
-clock = &lt;built-in function clock&gt;
-ctime = &lt;built-in function ctime&gt;
-daylight = 1
-gmtime = &lt;built-in function gmtime&gt;
-localtime = &lt;built-in function localtime&gt;
-mktime = &lt;built-in function mktime&gt;
-newattr = hello!
-sleep = &lt;built-in function sleep&gt;
-strftime = &lt;built-in function strftime&gt;
-strptime = &lt;built-in function strptime&gt;
-struct_time = &lt;type 'time.struct_time'&gt;
-time = &lt;built-in function time&gt;
-timezone = 18000
-tzname = ('EST', 'EDT')
-</pre>
-</blockquote>
-<p>The list of the built-in Python types can be found in the <tt class="literal"><span class="pre">types</span></tt> module:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import types
-&gt;&gt;&gt; t_dict=dict([(k,v) for (k,v) in vars(types).iteritems()
-... if k.endswith('Type')])
-&gt;&gt;&gt; for t in t_dict: print t,
-...
-DictType IntType TypeType FileType CodeType XRangeType EllipsisType
-SliceType BooleanType ListType MethodType TupleType ModuleType FrameType
-StringType LongType BuiltinMethodType BufferType FloatType ClassType
-DictionaryType BuiltinFunctionType UnboundMethodType UnicodeType
-LambdaType DictProxyType ComplexType GeneratorType ObjectType
-FunctionType InstanceType NoneType TracebackType
-</pre>
-</blockquote>
-<p>For a pedagogical account of the most elementary
-Python introspection features,
-Patrick O' Brien:
-<a class="reference" href="http://www-106.ibm.com/developerworks/linux/library/l-pyint.html">http://www-106.ibm.com/developerworks/linux/library/l-pyint.html</a></p>
-</div>
-<div class="section" id="built-in-objects-iterators-and-generators">
-<h2><a class="toc-backref" href="#id65" name="built-in-objects-iterators-and-generators">Built-in objects: iterators and generators</a></h2>
-<p>At the end of the last section , I have used the <tt class="literal"><span class="pre">iteritems</span></tt> method
-of the dictionary, which returns an iterator:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; dict.iteritems.__doc__
-'D.iteritems() -&gt; an iterator over the (key, value) items of D'
-</pre>
-</blockquote>
-<p>Iterators (and generators) are new features of Python 2.2 and could not be
-familiar to all readers. However, since they are unrelated to OOP, they
-are outside the scope of this book and will not be discussed here in detail.
-Nevertheless, I will give a typical example of use of a generator, since
-this construct will be used in future chapters.</p>
-<p>At the syntactical level, a generator is a &quot;function&quot; with (at least one)
-<tt class="literal"><span class="pre">yield</span></tt> statement (notice that in Python 2.2 the <tt class="literal"><span class="pre">yield</span></tt> statement is
-enabled trough the <tt class="literal"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">generators</span></tt> syntax):</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import re
-
-def generateblocks(regexp,text):
- &quot;Generator splitting text in blocks according to regexp&quot;
- start=0
- for MO in regexp.finditer(text):
- beg,end=MO.span()
- yield text[start:beg] # actual text
- yield text[beg:end] # separator
- start=end
- lastblock=text[start:]
- if lastblock: yield lastblock; yield ''
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>In order to understand this example, the reader my want to refresh his/her
-understanding of regular expressions; since this is not a subject for
-this book, I simply remind the meaning of <tt class="literal"><span class="pre">finditer</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import re
-&gt;&gt;&gt; help(re.finditer)
-finditer(pattern, string)
- Return an iterator over all non-overlapping matches in the
- string. For each match, the iterator returns a match object.
- Empty matches are included in the result.
-</pre>
-</blockquote>
-<p>Generators can be thought of as resumable functions that stop at the
-<tt class="literal"><span class="pre">yield</span></tt> statement and resume from the point where they left.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import generateblocks
-&gt;&gt;&gt; text='Python_Rules!'
-&gt;&gt;&gt; g=generateblocks(re.compile('_'),text)
-&gt;&gt;&gt; g
-&lt;generator object at 0x401b140c&gt;
-&gt;&gt;&gt; dir(g)
-['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
- '__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__',
- '__repr__', '__setattr__', '__str__', 'gi_frame', 'gi_running', 'next']
-</pre>
-</blockquote>
-<p>Generator objects can be used as iterators in a <tt class="literal"><span class="pre">for</span></tt> loop.
-In this example the generator takes a text and a regular expression
-describing a fixed delimiter; then it splits the text in blocks
-according to the delimiter. For instance, if the delimiter is
-'_', the text 'Python Rules!' is splitted as 'Python', '_' and 'Rules!':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; for n, block in enumerate(g): print n, block
-...
-0 Python
-1
-2 Rules!
-3
-</pre>
-</blockquote>
-<p>This example also show the usage of the new Python 2.3 built-in <tt class="literal"><span class="pre">enumerate</span></tt>.</p>
-<p>Under the hood the <tt class="literal"><span class="pre">for</span></tt> loop is calling the generator via its
-<tt class="literal"><span class="pre">next</span></tt> method, until the <tt class="literal"><span class="pre">StopIteration</span></tt> exception is raised.
-For this reason a new call to the <tt class="literal"><span class="pre">for</span></tt> loop will have no effect:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; for n, block in enumerate(g): print n, block
-...
-</pre>
-</blockquote>
-<p>The point is that the generator has already yield its last element:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; g.next() # error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-StopIteration
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">generateblocks</span></tt> always returns an even number of blocks; odd blocks
-are delimiters whereas even blocks are the intertwining text; there may be
-empty blocks, corresponding to the null string ''.</p>
-<p>It must be remarked the difference with the 'str.split' method</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; 'Python_Rules!'.split('_')
-['Python', 'Rules!']
-</pre>
-</blockquote>
-<p>and the regular expression split method:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; re.compile('_').split('Python_Rules!')
-['Python', 'Rules!']
-</pre>
-</blockquote>
-<p>both returns lists with an odd number of elements and both miss the separator.
-The regular expression split method can catch the separator, if wanted,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; re.compile('(_)').split('Python_Rules!')
-['Python', '_', 'Rules!']
-</pre>
-</blockquote>
-<p>but still is different from the generator, since it returns a list. The
-difference is relevant if we want to split a very large text, since
-the generator avoids to build a very large list and thus it is much more
-memory efficient (it is faster, too). Moreover, <tt class="literal"><span class="pre">generateblocks</span></tt>
-works differently in the case of multiple groups:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; delim=re.compile('(_)|(!)') #delimiter is space or exclamation mark
-&gt;&gt;&gt; for n, block in enumerate(generateblocks(delim,text)):
-... print n, block
-0 Python
-1 _
-2 Rules
-3 !
-</pre>
-</blockquote>
-<p>whereas</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; delim.split(text)
-['Python', '_', None, 'Rules', None, '!', '']
-</pre>
-</blockquote>
-<p>gives various unwanted <tt class="literal"><span class="pre">None</span></tt> (which could be skipped with
-<tt class="literal"><span class="pre">[x</span> <span class="pre">for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">delim.split(text)</span> <span class="pre">if</span> <span class="pre">x</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">None]</span></tt>); notice, that
-there are no differences (apart from the fact that <tt class="literal"><span class="pre">delim.split(text)</span></tt>
-has an odd number of elements) when one uses a single group regular expression:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; delim=re.compile('(_|!)')
-&gt;&gt;&gt; delim.split(text)
-['Python', '_', 'Rules', '!', '']
-</pre>
-</blockquote>
-<p>The reader unfamiliar with iterators and generators is encouraged
-to look at the standard documentation and other
-references. For instance, there are Alex Martelli's notes on iterators at
-<a class="reference" href="http://www.strakt.com/dev_talks.html">http://www.strakt.com/dev_talks.html</a>
-and there is a good article on generators by David Mertz
-<a class="reference" href="http://www-106.ibm.com/developerworks/linux/library/l-pycon.html">http://www-106.ibm.com/developerworks/linux/library/l-pycon.html</a></p>
-</div>
-</div>
-<div class="section" id="the-convenience-of-functions">
-<h1><a class="toc-backref" href="#id66" name="the-convenience-of-functions">THE CONVENIENCE OF FUNCTIONS</a></h1>
-<p>Functions are the most basic Python objects. They are also the simplest
-objects where one can apply the metaprogramming techniques that are
-the subject of this book. The tricks used in this chapter and the utility
-functions defined here will be used over all the book. Therefore this
-is an <em>essential</em> chapter.</p>
-<p>Since it is intended to be a gentle introduction, the tone will be
-informal.</p>
-<div class="section" id="id16">
-<h2><a class="toc-backref" href="#id67" name="id16">Introduction</a></h2>
-<p>One could be surprised that a text on OOP begins with a chapter on the
-well known old-fashioned functions. In some sense, this is also
-against the spirit of an important trend in OOP, which tries to
-shift the focus from functions to data. In pure OOP languages,
-there are no more functions, only methods. <a class="footnote-reference" href="#id15" id="id17" name="id17">[8]</a></p>
-<p>However, there are good reasons for that:</p>
-<ol class="arabic simple">
-<li>In Python, functions <em>are</em> objects. And particularly useful ones.</li>
-<li>Python functions are pretty powerful and all their secrets are probably
-<em>not</em> well known to the average Python programmer.</li>
-<li>In the solutions of many problems, you don't need the full apparatus
-of OOP: good old functions can be enough.</li>
-</ol>
-<p>Moreover, I am a believer in the multiparadigm approach to programming,
-in which you choose your tools according to your problem.
-With a bazooka you can kill a mosquito, yes, but this does not mean
-that you must use the bazooka <em>always</em>.
-In certain languages, you have no choice, and you must define
-a class (involving a lot of boiler plate code) even for the most trivial
-application. Python's philosophy is to keep simple things simple, but
-having the capability of doing even difficult things with a reasonable
-amount of effort. The message of this chapter will be: &quot;use functions when
-you don't need classes&quot;. Functions are good because:</p>
-<ol class="arabic simple">
-<li>They are easy to write (no boiler plate);</li>
-<li>They are easy to understand;</li>
-<li>They can be reused in your code;</li>
-<li>Functions are an essential building block in the construction of objects.</li>
-</ol>
-<p>Even if I think that OOP is an extremely effective strategy, with
-enormous advantages on design, maintanibility and reusability of code,
-nevertheless this book is <em>not</em> intended to be a panegyric of OOP. There
-are cases in which you don't need OOP. I think the critical parameter is
-the size of the program. These are the rules I follows usually (to be
-taken as indicative):</p>
-<ol class="arabic simple">
-<li>If I have to write a short script of 20-30 lines, that copies two or
-three files and prints some message, I use fast and dirty spaghetti-code;
-there is no use for OOP.</li>
-<li>If your script grows to one-hundred lines or more, I structure
-it write a few routines and a main program: but still I can live
-without OOP.</li>
-<li>If the script goes beyond the two hundred lines, I start
-collecting my routines in few classes.</li>
-<li>If the script goes beyond the five hundred lines, I split the program
-in various files and modules and convert it to a package.</li>
-<li>I never write a function longer than 50 lines, since 50 lines is more
-or less the size of a page in my editor, and I need to be able to
-see the entire function in a page.</li>
-</ol>
-<p>Of course your taste could be different and you could prefer to write a
-monolitic program of five thousand lines; however the average size of
-the modules in the Python standard library is of 111 lines.
-I think this is a <em>strong</em> suggestion towards
-a modular style of programming, which
-is <em>very</em> well supported in Python.</p>
-<p>The point is that OOP is especially useful for <em>large</em> programs: if you
-only use Python for short system administration scripts you may well
-live without OOP. Unfortunaly, as everybody knows, short scripts have
-an evil tendency to become medium size scripts, and medium size scripts
-have the even more evil tendency to become large scripts and possible
-even full featured applications ! For this reason it is very probable
-that at a certain moment you will feel the need for OOP.</p>
-<p>I remember my first big program, a long time ago: I wrote a program
-to draw mathematical functions in AmigaBasic. It was good and nice
-until it had size of few hundred lines; but when it passed a thousand
-of lines, it became rapidly unmanageable and unmaintenable. There where
-three problems:</p>
-<ol class="arabic simple">
-<li>I could not split the program in modules, as I wanted, due to the
-limitations of AmigaBasic;</li>
-<li>I was missing OOP to keep the logic of the program all together, but
-at the time I didn't know that;</li>
-<li>I was missing effective debugging techniques.</li>
-<li>I was missing effective refactoring tools.</li>
-</ol>
-<p>I am sure anybody who has ever written a large program has run in these
-limitations: and the biggest help of OOP is in overcoming these limitations.
-Obviously, miracles are impossible, and even object oriented programs can
-grow to a size where they become unmaintanable: the point is that the
-critical limit is much higher than the thousand lines of structured programs.
-I haven't yet reached the limit of unmanageability with Python. The fact
-that the standard library is 66492 lines long (as result from the total
-number of lines in <tt class="literal"><span class="pre">/usr/local/lib/python2.2/</span></tt>), but it is still manageable,
-give me an hope ;-)</p>
-<blockquote>
-<table class="footnote" frame="void" id="id18" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id19" name="id18">[9]</a></td><td>However, one could argue that having functions distinguished from
-methods is the best thing to do, even in a strongly object-oriented
-world. For instance, generic functions can be used to implement
-multimethods. See for instance Lisp, Dylan and MultiJava. This latter
-is forced to introduce the concept of function outside a class,
-foreign to traditional Java, just to implement multimethods.</td></tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-<div class="section" id="a-few-useful-functions">
-<h2><a class="toc-backref" href="#id68" name="a-few-useful-functions">A few useful functions</a></h2>
-<p>It is always a good idea to have a set of useful function collected in
-a user defined module. The first function we want to have in our module
-is the <tt class="literal"><span class="pre">do_nothing</span></tt> function:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def do_nothing(*args,**kw): pass
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>This function accept a variable number of arguments and keywords (I
-defer the reader to the standard documentation if she is unfamiliar
-with these concept; this is <em>not</em> another Python tutorial ;-) and
-return <tt class="literal"><span class="pre">None</span></tt>. It is very useful for debugging purposes, when in a
-complex program you may want concentrate your attention to few crucial
-functions and set the non-relevant functions to <tt class="literal"><span class="pre">do_nothing</span></tt> functions.</p>
-<p>A second function which is useful in developing programs is a timer
-function. Very ofter indeed, we may want to determine the bottleneck
-parts of a program, we are interested in profiling them and in seeing
-if we can improve the speed by improving the algorithm, or by using
-a Python &quot;compiler&quot; such as Psyco, or if really we need to write a C
-extension. In my experience, I never needed to write a C extension,
-since Python is fast enough. Nevertheless, to profile a program is
-always a good idea and Python provides a profiler module in the
-stardard library with this aim. Still, it is convenient to have
-a set of user defined functions to test the execution speed of
-few selected routines (whereas the standard profiler profiles everything).</p>
-<p>We see from the standard library documentation that
-the current time can be retrieved from the <tt class="literal"><span class="pre">time</span></tt> module: <a class="footnote-reference" href="#id18" id="id19" name="id19">[9]</a></p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import time
-&gt;&gt;&gt; time.asctime()
-'Wed Jan 15 12:46:03 2003'
-</pre>
-</blockquote>
-<p>Since we are not interested in the date but only in the time, we need
-a function to extract it. This is easily implemented:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import time
-
-def get_time():
- &quot;Return the time of the system in the format HH:MM:SS&quot;
- return time.asctime().split()[3]
-
-#&lt;/oopp.py&gt;
-
-&gt;&gt;&gt; from oopp import get_time
-&gt;&gt;&gt; get_time()
-'13:03:49'
-</pre>
-</blockquote>
-<p>Suppose, for instance, we want to know how much it takes to Python
-to write a Gigabyte of data. This can be a quite useful benchmark
-to have an idea of the I/O bottlenecks in our system. Since to take in memory
-a file of a Gigabyte can be quite problematic, let me compute the
-time spent in writing 1024 files of one Megabyte each. To this
-aim we need a <tt class="literal"><span class="pre">writefile</span></tt> function</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def writefile(fname,data):
- f=file(fname,'w')
- f.write(data)
- f.close()
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>and timing function. The idea is to wrap the <tt class="literal"><span class="pre">writefile</span></tt> function in
-a <tt class="literal"><span class="pre">with_clock</span></tt> function as follows:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def with_clock(func,n=1):
- def _(*args,**kw): # this is a closure
- print &quot;Process started on&quot;,get_time()
- print ' .. please wait ..'
- for i in range(n): func(*args,**kw)
- print &quot;Process ended on&quot;,get_time()
- return _
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>The wrapper function <tt class="literal"><span class="pre">with_clock</span></tt> has converted the function <tt class="literal"><span class="pre">writefile</span></tt>
-in a function <tt class="literal"><span class="pre">with_clock(writefile)</span></tt> which has the same arguments
-of <tt class="literal"><span class="pre">writefile</span></tt>, but contains additional features: in this case
-timing capabilities. Technically speaking, the internal function <tt class="literal"><span class="pre">_</span></tt>
-is called a <em>closure</em>. Closures are very common in functional languages
-and can be used in Python too, with very little effort <a class="footnote-reference" href="#id21" id="id20" name="id20">[10]</a>.</p>
-<p>I will use closures very often in the following, and I will use
-the convention of denoting with &quot;_&quot; the inner
-function in the closure, since there is no reason of giving to it a
-descriptive name (the name 'with_clock' in the outer function
-is descriptive enough). For the same, reason I do not use a
-docstring for &quot;_&quot;. If Python would allow multistatement lambda
-functions, &quot;_&quot; would be a good candidate for an anonymous function.</p>
-<p>Here is an example of usage:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; data='*'*1024*1024 #one megabyte
-&gt;&gt;&gt; with_clock(writefile,n=1024)('datafile',data) #.
-Process started on 21:20:01
- .. please wait ..
-Process ended on 21:20:57
-</pre>
-</blockquote>
-<p>This example shows that Python has written one Gigabyte of data (splitted in
-1024 chunks of one Megabyte each) in less than a minute. However,the
-result depends very much on the filesystem. I always suggest people
-to profile their programs, since one <em>always</em> find surprises.
-For instance, I have checked the performance of my laptop,
-a dual machine Windows 98 SE/ Red Hat Linux 7.3.
-The results are collected in the following table:</p>
-<blockquote>
-<table border class="table">
-<colgroup>
-<col width="27%" />
-<col width="34%" />
-<col width="39%" />
-</colgroup>
-<thead valign="bottom">
-<tr><th>Linux ext-3</th>
-<th>FAT under Linux</th>
-<th>FAT under Windows 98</th>
-</tr>
-</thead>
-<tbody valign="top">
-<tr><td>24-25 s</td>
-<td>56-58 s</td>
-<td>86-88 s</td>
-</tr>
-</tbody>
-</table>
-</blockquote>
-<p>We see that Linux is <em>much</em> faster: more than three times faster than
-Windows, using the same machine! Notice that the FAT filesystem under
-Linux (where it is <em>not</em> native) is remarkably faster than the FAT
-under Windows 98, where it is native !! I think that now my readers
-can begin to understand why this book has been written under Linux
-and why I <em>never</em> use Windows for programming (actually I use it only
-to see the DVD's ;-).</p>
-<p>I leave as an exercise for the reader to check the results on this
-script on their machine. Since my laptop is quite old, you will probably
-have much better performances (for instance on my linux desktop I can
-write a Gigabyte in less than 12 seconds!). However, there are <em>always</em>
-surprises: my desktop is a dual Windows 2000 machine with three different
-filesystems, Linux ext-2, FAT and NTFS. Surprisingly enough, the NT
-filesystem is the more inefficient for writing, <em>ten times slower</em>
-than Linux!</p>
-<blockquote>
-<table border class="table">
-<colgroup>
-<col width="27%" />
-<col width="34%" />
-<col width="39%" />
-</colgroup>
-<thead valign="bottom">
-<tr><th>Linux ext-2</th>
-<th>FAT under Win2000</th>
-<th>NTFS under Win2000</th>
-</tr>
-</thead>
-<tbody valign="top">
-<tr><td>11-12 s</td>
-<td>95-97 s</td>
-<td>117-120 s</td>
-</tr>
-</tbody>
-</table>
-</blockquote>
-<table class="footnote" frame="void" id="id21" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id20" name="id21">[10]</a></td><td>Users of Python 2.3 can give a look to the new <tt class="literal"><span class="pre">datetime</span></tt> module,
-if they are looking for a sophisticated clock/calendar.</td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id22" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id23" name="id22">[11]</a></td><td>There are good references on functional programming in Python;
-I suggest the Python Cookbook and the articles by David Mertz
-www.IBM.dW.</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="functions-are-objects">
-<h2><a class="toc-backref" href="#id69" name="functions-are-objects">Functions are objects</a></h2>
-<p>As we said in the first chapter, objects have attributes accessible with the
-dot notation. This is not surprising at all. However, it could be
-surprising to realize that since Python functions are objects, they
-can have attributes, too. This could be surprising since this feature is quite
-uncommon: typically or i) the language is
-not object-oriented, and therefore functions are not objects, or ii)
-the language is strongly object-oriented and does not have functions, only
-methods. Python is a multiparadigm language (which I prefer to the
-term &quot;hybrid&quot; language), therefore it has functions that are objects,
-as in Lisp and other functional languages.
-Consider for instance the <tt class="literal"><span class="pre">get_time</span></tt> function.
-That function has at least an useful attribute, its doctring:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import get_time
-&gt;&gt;&gt; print get_time.func_doc
-Return the time of the system in the format HH:MM:SS
-</pre>
-</blockquote>
-<p>The docstring can also be obtained with the <tt class="literal"><span class="pre">help</span></tt> function:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; help(get_time)
-Help on function get_time in module oopp:
-get_time()
- Return the time of the system in the format HH:MM:SS
-</pre>
-</blockquote>
-<p>Therefore <tt class="literal"><span class="pre">help</span></tt> works on user-defined functions, too, not only on
-built-in functions. Notice that <tt class="literal"><span class="pre">help</span></tt> also returns the argument list of
-the function. For instance, this is
-the help message on the <tt class="literal"><span class="pre">round</span></tt> function that we will use in the
-following:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; help(round)
-Help on built-in function round:
-round(...)
- round(number[, ndigits]) -&gt; floating point number
- Round a number to a given precision in decimal digits (default 0
- digits).This always returns a floating point number. Precision may
- be negative.
-</pre>
-</blockquote>
-<p>I strongly recommend Python programmers to use docstrings, not
-only for clarity sake during the development, but especially because
-it is possible to automatically generate nice HTML documentation from
-the docstrings, by using the standard tool &quot;pydoc&quot;.</p>
-<p>One can easily add attributes to a function. For instance:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; get_time.more_doc='get_time invokes the function time.asctime'
-&gt;&gt;&gt; print get_time.more_doc
-get_time invokes the function time.asctime
-</pre>
-</blockquote>
-<p>Attributes can be functions, too:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def IamAfunction(): print &quot;I am a function attached to a function&quot;
-&gt;&gt;&gt; get_time.f=IamAfunction
-&gt;&gt;&gt; get_time.f()
-I am a function attached to a function
-</pre>
-</blockquote>
-<p>This is a quite impressive potentiality of Python functions, which has
-no direct equivalent in most other languages.</p>
-<p>One possible application is to fake C &quot;static&quot; variables. Suppose
-for instance we need a function remembering how may times it is
-called: we can simply use</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;double.py&gt;
-
-def double(x):
- try: #look if double.counter is defined
- double.counter
- except AttributeError:
- double.counter=0 #first call
- double.counter+=1
- return 2*x
-
-double(double(2))
-print &quot;double has been called %s times&quot; % double.counter
-
-#&lt;/double.py&gt;
-</pre>
-</blockquote>
-<p>with output <tt class="literal"><span class="pre">double</span> <span class="pre">has</span> <span class="pre">been</span> <span class="pre">called</span> <span class="pre">2</span> <span class="pre">times</span></tt>.
-A more elegant approach involves closures. A closure can enhance an
-ordinary function, providing to it the capability of remembering
-the results of its previous calls and avoiding the duplication of
-computations:</p>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def withmemory(f):
- &quot;&quot;&quot;This closure invokes the callable object f only if need there is&quot;&quot;&quot;
- argskw=[]; result=[]
- def _(*args,**kw):
- akw=args,kw
- try: # returns a previously stored result
- i=argskw.index(akw)
- except ValueError: # there is no previously stored result
- res=f(*args,**kw) # returns the new result
- argskw.append(akw) # update argskw
- result.append(res) # update result
- return res
- else:
- return result[i]
- _.argskw=argskw #makes the argskw list accessible outside
- _.result=result #makes the result list accessible outside
- return _
-
-def memoize(f):
- &quot;&quot;&quot;This closure remembers all f invocations&quot;&quot;&quot;
- argskw,result = [],[]
- def _(*args,**kw):
- akw=args,kw
- try: # returns a previously stored result
- return result[argskw.index(akw)]
- except ValueError: # there is no previously stored result
- argskw.append(akw) # update argskw
- result.append(f(*args,**kw)) # update result
- return result[-1] # return the new result
- _.argskw=argskw #makes the argskw list accessible outside
- _.result=result #makes the result list accessible outside
- return _
-
-#&lt;/oopp.py&gt;
-</pre>
-<p>Now, if we call the wrapped function <tt class="literal"><span class="pre">f</span></tt> twice with the same arguments,
-Python can give the result without repeating the (possibly very long)
-computation.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(x):
-... print 'called f'
-... return x*x
-&gt;&gt;&gt; wrapped_f=withmemory(f)
-&gt;&gt;&gt; wrapped_f(2) #first call with the argument 2; executes the computation
-called f
-4
-&gt;&gt;&gt; wrapped_f(2) #does not repeat the computation
-4
-&gt;&gt;&gt; wrapped_f.result
-[4]
-&gt;&gt;&gt; wrapped_f.argskw
-[((2,), {})]
-</pre>
-</blockquote>
-</div>
-<div class="section" id="profiling-functions">
-<h2><a class="toc-backref" href="#id70" name="profiling-functions">Profiling functions</a></h2>
-<p>The <tt class="literal"><span class="pre">with_clock</span></tt> function provided before was intended to be
-pedagogical; as such it is a quite poor solution to the
-problem of profiling a Python routine. A better solution involves
-using two others functions in the time library, <tt class="literal"><span class="pre">time.time()</span></tt>
-that gives that time in seconds elapsed from a given date, and
-<tt class="literal"><span class="pre">time.clock()</span></tt> that gives the time spent by the CPU in a given
-computation. Notice that <tt class="literal"><span class="pre">time.clock()</span></tt> has not an infinite
-precision (the precision depends on the system) and one
-should expect relatively big errors if the function runs in
-a very short time. That's the reason why it is convenient
-to execute multiple times short functions and divide the total
-time by the number of repetitions. Moreover, one should subtract the
-overhead do to the looping. This can be computed with the following
-routine:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def loop_overhead(N):
- &quot;Computes the time spent in empty loop of N iterations&quot;
- t0=time.clock()
- for i in xrange(N): pass
- return time.clock()-t0
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>For instance, on my laptop an empty loop of one million of iterations
-is performed in 1.3 seconds. Typically the loop overhead is negligible,
-whereas the real problem is the function overhead.</p>
-<p>Using the attribute trick discussed above, we may
-define a <tt class="literal"><span class="pre">with_timer</span></tt> function that enhances quite a bit
-<tt class="literal"><span class="pre">with_clock</span></tt>:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def with_timer(func, modulename='__main__', n=1, logfile=sys.stdout):
- &quot;&quot;&quot;Wraps the function func and executes it n times (default n=1).
- The average time spent in one iteration, express in milliseconds,
- is stored in the attributes func.time and func.CPUtime, and saved
- in a log file which defaults to the standard output.
- &quot;&quot;&quot;
- def _(*args,**kw): # anonymous function
- time1=time.time()
- CPUtime1=time.clock()
- print 'Executing %s.%s ...' % (modulename,func.__name__),
- for i in xrange(n): res=func(*args,**kw) # executes func n times
- time2=time.time()
- CPUtime2=time.clock()
- func.time=1000*(time2-time1)/n
- func.CPUtime=1000*(CPUtime2-CPUtime1-loop_overhead(n))/n
- if func.CPUtime&lt;10: r=3 #better rounding
- else: r=1 #default rounding
- print &gt;&gt; logfile, 'Real time: %s ms' % round(func.time,r),
- print &gt;&gt; logfile, ' CPU time: %s ms' % round(func.CPUtime,r)
- return res
- return _
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here it is an example of application:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import with_timer,writefile
-&gt;&gt;&gt; data='*'*1024*1024 #one megabyte
-&gt;&gt;&gt; with_timer(writefile,n=1024)('datafile',data) #.
-Executing writefile ... Real time: 60.0 ms CPU time: 42.2 ms
-</pre>
-</blockquote>
-<p>The CPU time can be quite different from the real time,
-as you can see in the following example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import time
-&gt;&gt;&gt; def sleep(): time.sleep(1)
-...
-&gt;&gt;&gt; with_timer(sleep)() #.
-Executing sleep ... Real time: 999.7 ms CPU time: 0.0 ms
-</pre>
-</blockquote>
-<p>We see that Python has run for 999.7 ms (i.e. 1 second, up to
-approximation errors in the system clock) during which the CPU has
-worked for 0.0 ms (i.e. the CPU took a rest ;-).
-The CPU time is the relevant time to use with the purpose of
-benchmarking Python speed.</p>
-<p>I should notice that the approach pursued in <tt class="literal"><span class="pre">with_timer</span></tt> is still
-quite simple. A better approach would be to
-plot the time versus the number of iteration, do a linear interpolation
-and extract the typical time for iteration from that. This allows
-to check visually that the machine is not doing something strange
-during the execution time and it is what
-I do in my personal benchmark routine; doing something similar is
-left as an exercise for the reader ;-).</p>
-<p>Another approach is to use the <tt class="literal"><span class="pre">timeit.py</span></tt> module (new in Python 2.3,
-but works also with Python 2.2):</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import timeit,__main__,warnings
-
-warnings.filterwarnings('ignore',
-'import \* only allowed at module level',SyntaxWarning)
-
-def timeit_(stmt,setup='from __main__ import *',n=1000):
- t=timeit.Timer(stmt,setup)
- try: print t.repeat(number=n) # class timeit 3 times
- except: t.print_exc()
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>It is often stated that Python is slow and quite ineffective
-in application involving hard computations. This is generally speaking
-true, but how bad is the situation ? To test the (in)efficiency of
-Python on number crunching, let me give a function to compute the
-Mandelbrot set, which I have found in the Python Frequently Asked
-Question (FAQ 4.15. <em>Is it possible to write obfuscated one-liners
-in Python?</em>).
-This function is due to Ulf Bartelt and you should ask him to know how
-does it work ;-)</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def mandelbrot(row,col):
- &quot;Computes the Mandelbrot set in one line&quot;
- return (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(
- lambda x,y:x+y,map(lambda y,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=
- lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM, Sx=Sx,Sy=Sy:reduce(
- lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro, i=i,
- Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k&lt;=0)
- or (x*x+y*y&gt;=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):
- f(xc,yc,x,y,k,f):chr(64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),
- range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy))))(
- -2.1, 0.7, -1.2, 1.2, 30, col, row)
- # \___ ___/ \___ ___/ | | |_ lines on screen
- # V V | |______ columns on screen
- # | | |__________ maximum of &quot;iterations&quot;
- # | |_________________ range on y axis
- # |____________________________ range on x axis
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here there is the benchmark on my laptop:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import mandelbrot,with_timer
-&gt;&gt;&gt; row,col=24,75
-&gt;&gt;&gt; output=with_timer(mandelbrot,n=1)(row,col)
-Executing __main__.mandelbrot ... Real time: 427.9 ms CPU time: 410.0 ms
-&gt;&gt;&gt; for r in range(row): print output[r*col:(r+1)*col]
-...
-BBBBBBBBBBBBBBCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCC
-BBBBBBBBBBBBCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDEEEEEEFGYLFFFEEEEEDDDDDCCCCCCCCC
-BBBBBBBBBBCCCCCCCDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEFFFGIKNJLLGEEEEEEDDDDDDCCCCC
-BBBBBBBBBCCCCCDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEFFFFGHJJR^QLIHGFFEEEEEEDDDDDDCC
-BBBBBBBBCCCDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEFFFGGGHIK_______LHGFFFFFEEEEDDDDDD
-BBBBBBBCCDDDDDDDDDDDDDDDDDDDDEEEEEEEFFFGHILIIIJJKMS_____PLJJIHGGGHJFEEDDDDD
-BBBBBBCDDDDDDDDDDDDDDDDDDEEEEEFFFFFFGGGHMQ__T________________QLOUP[OGFEDDDD
-BBBBBCDDDDDDDDDDDDDDDEEEFFFFFFFFFGGGGHJNM________________________XLHGFFEEDD
-BBBBCDDDDDDDDDEEEEEFFGJKHHHHHHHHHHHHIKN[__________________________MJKGFEEDD
-BBBBDDDDEEEEEEEEFFFFGHIKPVPMNU_QMJJKKZ_____________________________PIGFEEED
-BBBCDEEEEEEEEFFFFFFHHHML___________PQ_______________________________TGFEEEE
-BBBDEEEEEEFGGGGHHHJPNQP^___________________________________________IGFFEEEE
-BBB_____________________________________________________________OKIHGFFEEEE
-BBBDEEEEEEFGGGGHHHJPNQP^___________________________________________IGFFEEEE
-BBBCDEEEEEEEEFFFFFFHHHML___________PQ_______________________________TGFEEEE
-BBBBDDDDEEEEEEEEFFFFGHIKPVPMNU_QMJJKKZ_____________________________PIGFEEED
-BBBBCDDDDDDDDDEEEEEFFGJKHHHHHHHHHHHHIKN[__________________________MJKGFEEDD
-BBBBBCDDDDDDDDDDDDDDDEEEFFFFFFFFFGGGGHJNM________________________XLHGFFEEDD
-BBBBBBCDDDDDDDDDDDDDDDDDDEEEEEFFFFFFGGGHMQ__T________________QLOUP[OGFEDDDD
-BBBBBBBCCDDDDDDDDDDDDDDDDDDDDEEEEEEEFFFGHILIIIJJKMS_____PLJJIHGGGHJFEEDDDDD
-BBBBBBBBCCCDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEFFFGGGHIK_______LHGFFFFFEEEEDDDDDD
-BBBBBBBBBCCCCCDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEFFFFGHJJR^QLIHGFFEEEEEEDDDDDDCC
-BBBBBBBBBBCCCCCCCDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEFFFGIKNJLLGEEEEEEDDDDDDCCCCC
-BBBBBBBBBBBBCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDEEEEEEFGYLFFFEEEEEDDDDDCCCCCCCCC
-</pre>
-</blockquote>
-<p>I am willing to concede that this code is not typical Python code and
-actually it could be an example of <em>bad</em> code, but I wanted a nice ASCII
-picture on my book ... :) Also, this prove that Python is not necessarily
-readable and easy to understand ;-)
-I leave for the courageous reader to convert the previous algorithm to C and
-measure the difference in speed ;-)</p>
-</div>
-<div class="section" id="about-python-speed">
-<h2><a class="toc-backref" href="#id71" name="about-python-speed">About Python speed</a></h2>
-<p>The best way to improved the speed is to improve the algorithm; in
-this sense Python is an ideal language since it allows you to test
-many algorithms in an incredibly short time: in other words, the time you
-would spend fighting with the compiler in other languages, in Python
-can be used to improve the algorithm.
-However in some cases, there is little to do: for instance, in many
-problems one has to run lots of loops, and Python loops are horribly
-inefficients as compared to C loops. In this case the simplest possibility
-is to use Psyco. Psyco is a specialing Python compiler written by Armin
-Rigo. It works for 386 based processors and allows Python to run loops at
-C speed. Installing Psyco requires $0.00 and ten minutes of your time:
-nine minutes to find the program, download it, and install it; one
-minute to understand how to use it.</p>
-<p>The following script explains both the usage and the advantages of Psyco:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;psyco1.py&gt;
-
-import oopp,sys
-try:
- import psyco
-except ImportError:
- print &quot;Psyco is not installed, sorry.&quot;
-else:
- n=1000000 # 1,000,000 loops
-
- without=oopp.loop_overhead(n)
- print &quot;Without Psyco:&quot;,without
-
- psyco.bind(oopp.loop_overhead) #compile the empty_loop
-
- with=oopp.loop_overhead(n)
- print &quot;With Psyco:&quot;,with
-
- print 'Speedup = %sx' % round(without/with,1)
-
-#&lt;/psyco1.py&gt;
-</pre>
-</blockquote>
-<p>The output is impressive:</p>
-<blockquote>
-<pre class="literal-block">
-Without Psyco: 1.3
-With Psyco: 0.02
-Speedup = 65.0x
-</pre>
-</blockquote>
-<p>Notice that repeating the test, you will obtain different speedups.
-On my laptop, the speedup for an empty loop of 10,000,000 of
-iteration is of the order of 70x, which is the same speed of a C loop,
-actually (I checked it). On my desktop, I have even found a speedup of
-94x !</p>
-<p>However, I must say that Psyco has some limitations. The problem is
-the function call overhead. Psyco enhances the overhead and in some
-programs it can even <em>worsen</em> the performance (this is way you should
-<em>never</em> use the <tt class="literal"><span class="pre">psyco.jit()</span></tt> function that wraps all the functions of
-your program: you should only wrap the bottleneck loops). Generally speaking,
-you should expect a much more modest improvement, a factor of 2 or 3
-is what I obtain usually in my programs.</p>
-<p>Look at this second example, which essentially measure the function
-call overhead by invoking the <tt class="literal"><span class="pre">do_nothing</span></tt> function:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;psyco2.py&gt;
-
-import oopp
-try:
- import psyco
-except ImportError:
- print &quot;Psyco is not installed, sorry.&quot;
-else:
- n=10000 # 10,000 loops
-
- def do_nothing_loop():
- for i in xrange(n): oopp.do_nothing()
-
- print &quot;Without Psyco:\n&quot;
- oopp.with_timer(do_nothing_loop,n=5)() #50,000 times
-
- without=do_nothing_loop.CPUtime
-
- psyco.bind(do_nothing_loop)
- print &quot;With Psyco:\n&quot;
- oopp.with_timer(do_nothing_loop,n=5)() #50,000 times
-
- with=do_nothing_loop.CPUtime
-
- print 'Speedup = %sx' % round(without/with,1)
-
-#&lt;/psyco2.py&gt;
-</pre>
-</blockquote>
-<p>The output is less incredible:</p>
-<blockquote>
-<pre class="literal-block">
-Without Psyco:
-Executing do_nothing_loop ... Real time: 138.2 ms CPU time: 130.0 ms
-With Psyco:
-Executing do_nothing_loop ... Real time: 70.0 ms CPU time: 68.0 ms
-Speedup = 1.9x
-</pre>
-</blockquote>
-<p>However, this is still impressive, if you think that you can double
-the speed of your program by adding <em>a line</em> of code! Moreover this
-example is not fair since Psyco cannot improve very much the performance
-for loops invoking functions with a variable number of arguments. On the
-other hand, it can do quite a lot for loops invoking functions with
-a fixed number of arguments. I have checked that you can easily reach
-speedups of 20x (!). The only disadvantage is that a program invoking
-Psyco takes much more memory, than a normal Python program, but this
-is not a problem for most applications in nowadays computers.
-Therefore, often Psyco
-can save you the effort of going trough a C extension. In some cases,
-however, there is no hope: I leave as an exercise for the reader
-to check (at least the version 0.4.1 I am using now) is unable to
-improve the performance on the Mandelbrot set example. This proves
-that in the case bad code, there is no point in using a compiler:
-you have to improve the algorithm first !</p>
-<p>By the way, if you really want to go trough a C extension with a minimal
-departure from Python, you can use Pyrex by Greg Ewing. A Pyrex program
-is essentially a Python program with variable declarations that is
-automatically converted to C code. Alternatively, you can inline
-C functions is Python with <tt class="literal"><span class="pre">weave</span></tt> of ...
-Finally, if you want to access C/C++ libraries, there tools
-like Swig, Booster and others.</p>
-</div>
-<div class="section" id="tracing-functions">
-<h2><a class="toc-backref" href="#id72" name="tracing-functions">Tracing functions</a></h2>
-<p>Typically, a script contains many functions that call themselves each
-other when some conditions are satisfied. Also, typically during
-debugging things do not work the way we would like and it is not
-clear which functions are called, in which order they are called,
-and which parameters are passed. The best way to know all these
-informations, is to trace the functions in our script, and to write
-all the relevant informations in a log file. In order to keep the
-distinction between the traced functions and the original one, it
-is convenient to collect all the wrapped functions in a separate dictionary.
-The tracing of a single function can be done with a closure
-like this:</p>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def with_tracer(function,namespace='__main__',output=sys.stdout, indent=[0]):
- &quot;&quot;&quot;Closure returning traced functions. It is typically invoked
- trough an auxiliary function fixing the parameters of with_tracer.&quot;&quot;&quot;
- def _(*args,**kw):
- name=function.__name__
- i=' '*indent[0]; indent[0]+=4 # increases indentation
- output.write(&quot;%s[%s] Calling '%s' with arguments\n&quot; %
- (i,namespace,name))
- output.write(&quot;%s %s ...\n&quot; % (i,str(args)+str(kw)))
- res=function(*args,**kw)
- output.write(&quot;%s[%s.%s] called with result: %s\n&quot;
- % (i,namespace,name,str(res)))
- indent[0]-=4 # restores indentation
- return res
- return _ # the traced function
-
-#&lt;/oopp.py&gt;
-</pre>
-<p>Here is an example of usage:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import with_tracer
-&gt;&gt;&gt; def fact(n): # factorial function
-... if n==1: return 1
-... else: return n*fact(n-1)
-&gt;&gt;&gt; fact=with_tracer(fact)
-&gt;&gt;&gt; fact(3)
-[__main__] Calling 'fact' with arguments
- (3,){} ...
- [__main__] Calling 'fact' with arguments
- (2,){} ...
- [__main__] Calling 'fact' with arguments
- (1,){} ...
- [__main__.fact] called with result: 1
- [__main__.fact] called with result: 2
-[__main__.fact] called with result: 6
-6
-</pre>
-</blockquote>
-<p>The logic behind <tt class="literal"><span class="pre">with_tracer</span></tt> should be clear; the only trick is the
-usage of a default list as a way to store a global indentation parameter.
-Since <tt class="literal"><span class="pre">indent</span></tt> is mutable, the value of <tt class="literal"><span class="pre">indent[0]</span></tt> changes at any
-recursive call of the traced function, resulting in a nested display.</p>
-<p>Typically, one wants to trace all the functions in a given module;
-this can be done trough the following function:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-from types import *
-
-isfunction=lambda f: isinstance(f,(FunctionType,BuiltinFunctionType))
-
-def wrapfunctions(obj,wrapper,err=None,**options):
- &quot;Traces the callable objects in an object with a dictionary&quot;
- namespace=options.get('namespace',getattr(obj,'__name__',''))
- output=options.get('output',sys.stdout)
- dic=dict([(k,wrapper(v,namespace,output))
- for k,v in attributes(obj).items() if isfunction(v)])
- customize(obj,err,**dic)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Notice that 'wrapfunctions' accepts as first argument an object with
-a <tt class="literal"><span class="pre">__dict__</span></tt> attribute (such as a module or a class) or with some
-explicit attributes (such as a simple object) and modifies it. One can
-trace a module as in this example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;tracemodule.py&gt;
-
-import oopp,random
-
-oopp.wrapfunctions(random,oopp.with_tracer)
-
-random.random()
-
-#&lt;/tracemodule.py&gt;
-</pre>
-</blockquote>
-<p>with output</p>
-<blockquote>
-<pre class="literal-block">
-[random] Calling 'random' with arguments
-(){} ...
--&gt; 'random.random' called with result: 0.175450439202
-</pre>
-</blockquote>
-<p>The beauty of the present approach is its generality: 'wrap' can be
-used to add any kind of capabilities to a pre-existing module.
-For instance, we could time the functions in a module, with the
-purpose of looking at the bottlenecks. To this aim, it is enough
-to use a 'timer' nested closure:</p>
-<p>An example of calling is <tt class="literal"><span class="pre">wrapfunction(obj,timer,iterations=1)</span></tt>.</p>
-<p>We may also compose our closures; for instance one could define a
-<tt class="literal"><span class="pre">with_timer_and_tracer</span></tt> closure:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; with_timer_and_tracer=lambda f: with_timer(with_tracer(f))
-</pre>
-</blockquote>
-<p>It should be noticed that Python comes with a standard profiler
-(in my system it is located in <tt class="literal"><span class="pre">/usr/local/lib/python2.2/profile.py</span></tt>)
-that allows to profile a script or a module (try
-python /usr/local/lib/python2.2/profile.py oopp.py)</p>
-<p>or</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import profile; help(profile)
-</pre>
-</blockquote>
-<p>and see the on-line documentation.</p>
-</div>
-<div class="section" id="tracing-objects">
-<h2><a class="toc-backref" href="#id73" name="tracing-objects">Tracing objects</a></h2>
-<p>In this section, I will give a more sophisticated example, in which
-one can easily understand why the Python ability of changing methods and
-attributes during run-time, is so useful.
-As a preparation to the real example, let me
-first introduce an utility routine that allows the user
-to add tracing capabilities to a given object.
-Needless to say, this feature can be invaluable during debugging, or in trying
-to understand the behaviour of a program written by others.</p>
-<p>This routine is a little complex and needs some explanation.</p>
-<ol class="arabic simple">
-<li>The routine looks in the attributes of the object and try to access them.</li>
-<li>If the access is possible, the routines looks for methods (methods
-are recognized trough the <tt class="literal"><span class="pre">inspect.isroutine</span></tt> function in the
-standard library) and ignores regular attributes;</li>
-<li>The routine try to override the original methods with improved ones,
-that possess tracing capabilities;</li>
-<li>the traced method is obtained with the wrapping trick discussed before.</li>
-</ol>
-<p>I give now the real life example that I have anticipated before.
-Improvements and elaborations of this example can be useful to the
-professional programmer, too. Suppose you have an XML text you want
-to parse. Python provides excellent support for this kind of operation
-and various standard modules. One of the most common is the <tt class="literal"><span class="pre">expat</span></tt>
-module (see the standard library documentation for more).</p>
-<p>If you are just starting using the module, it is certainly useful
-to have a way of tracing its behaviour; this is especially true if
-you you find some unexpected error during the parsing of a document
-(and this may happens even if you are an experience programmer ;-).</p>
-<p>The tracing routine just defined can be used to trace the parser, as
-it is exemplified in the following short script:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;expat.py&gt;
-
-import oopp, xml.parsers.expat, sys
-
-# text to be parsed
-text_xml=&quot;&quot;&quot;\
-&lt;?xml version=&quot;1.0&quot;?&gt;
-&lt;parent id=&quot;dad&quot;&gt;
-&lt;child name=&quot;kid&quot;&gt;Text goes here&lt;/child&gt;
-&lt;/parent&gt;&quot;&quot;&quot;
-
-# a few do nothing functions
-def start(*args): pass
-def end(*args): pass
-def handler(*args): pass
-
-# a parser object
-p = xml.parsers.expat.ParserCreate()
-
-p.StartElementHandler = start
-p.EndElementHandler = end
-p.CharacterDataHandler = handler
-
-#adds tracing capabilities to p
-oopp.wrapfunctions(p,oopp.with_tracer, err=sys.stdout)
-
-p.Parse(text_xml)
-
-#&lt;/expat.py&gt;
-</pre>
-</blockquote>
-<p>The output is:</p>
-<blockquote>
-<pre class="literal-block">
-Error: SetBase cannot be set
-Error: Parse cannot be set
-Error: ParseFile cannot be set
-Error: GetBase cannot be set
-Error: SetParamEntityParsing cannot be set
-Error: ExternalEntityParserCreate cannot be set
-Error: GetInputContext cannot be set
-[] Calling 'start' with arguments
- (u'parent', {u'id': u'dad'}){} ...
-[.start] called with result: None
-[] Calling 'handler' with arguments
- (u'\n',){} ...
-[.handler] called with result: None
-[] Calling 'start' with arguments
- (u'child', {u'name': u'kid'}){} ...
-[.start] called with result: None
-[] Calling 'handler' with arguments
- (u'Text goes here',){} ...
-[.handler] called with result: None
-[] Calling 'end' with arguments
- (u'child',){} ...
-[.end] called with result: None
-[] Calling 'handler' with arguments
- (u'\n',){} ...
-[.handler] called with result: None
-[] Calling 'end' with arguments
- (u'parent',){} ...
-[.end] called with result: None
-</pre>
-</blockquote>
-<p>This is a case where certain methods cannot be managed with
-<tt class="literal"><span class="pre">getattr/setattr</span></tt>, because they are internally coded in C: this
-explain the error messages at the beginning. I leave as an exercise
-for the reader to understand the rest ;-)</p>
-</div>
-<div class="section" id="inspecting-functions">
-<h2><a class="toc-backref" href="#id74" name="inspecting-functions">Inspecting functions</a></h2>
-<p>Python wonderful introspection features are really impressive when applied
-to functions. It is possible to extract a big deal of informations
-from a Python function, by looking at its associated <em>code object</em>.
-For instance, let me consider my, <tt class="literal"><span class="pre">do_nothing</span></tt> function: its associated
-code object can be extracted from the <tt class="literal"><span class="pre">func_code</span></tt> attribute:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; co=do_nothing.func_code # extracts the code object
-&gt;&gt;&gt; co
-&lt;code object do_nothing at 0x402c5d20, file &quot;oopp.py&quot;, line 48&gt;
-&gt;&gt;&gt; type(co)
-&lt;type 'code'&gt;
-</pre>
-</blockquote>
-<p>The code object is far being trivial: the docstring says it all:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print type(co).__doc__
-code(argcount, nlocals, stacksize, flags, codestring, constants, names,
- varnames, filename, name, firstlineno, lnotab[, freevars[, cellvars]])
-Create a code object. Not for the faint of heart.
-</pre>
-</blockquote>
-<p>In the case of my <tt class="literal"><span class="pre">do_nothing</span></tt> function, the code object
-possesses the following attributes:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print pretty(attributes(co))
-co_argcount = 0
-co_cellvars = ()
-co_code = dS
-co_consts = (None,)
-co_filename = oopp.py
-co_firstlineno = 48
-co_flags = 15
-co_freevars = ()
-co_lnotab =
-co_name = do_nothing
-co_names = ()
-co_nlocals = 2
-co_stacksize = 1
-co_varnames = ('args', 'kw')
-</pre>
-</blockquote>
-<p>Some of these arguments are pretty technical and implementation dependent;
-however, some of these are pretty clear and useful:</p>
-<blockquote>
-<ul class="simple">
-<li>co_argcount is the total number of arguments</li>
-<li>co_filename is the name of the file where the function is defined</li>
-<li>co_firstlineno is the line number where the function is defined</li>
-<li>co_name is the name of the function</li>
-<li>co_varnames are the names</li>
-</ul>
-</blockquote>
-<p>The programmer that it is not a &quot;faint of heart&quot; can study
-the built-in documentation on code objects; s/he should try</p>
-<blockquote>
-<pre class="literal-block">
-for k,v in attributes(co).iteritems(): print k,':',v.__doc__,'\n'
-</pre>
-<p># does not work now !!</p>
-<pre class="literal-block">
-add=[lambda x,i=i: x+i for i in range(10)]
-
-&gt;&gt;&gt; def f(y):
-... return lambda x: x+y
-...
-&gt;&gt;&gt; f(1).func_closure #closure cell object
-(&lt;cell at 0x402b56bc: int object at 0x811d6c8&gt;,)
-</pre>
-</blockquote>
-<p>func.defaults, closure, etc.</p>
-<p>#how to extract (non-default) arguments as help does.</p>
-<p>print (lambda:None).func_code.co_filename</p>
-<p>One cannot change the name of a function:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(): pass
-...
-&gt;&gt;&gt; f.__name__='ciao' # error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: readonly attribute
-</pre>
-</blockquote>
-<p>However, one can create a copy with a different name:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def copyfunc(f,newname=None): # works under Python 2.3
- if newname is None: newname=f.func_name # same name
- return FunctionType(f.func_code, globals(), newname,
- f.func_defaults, f.func_closure)
-
-#&lt;/oopp.py&gt;
-
-&gt;&gt;&gt; copyfunc(f,newname='f2')
-&lt;function f2 at 0x403e233c&gt;
-</pre>
-</blockquote>
-<p>Notice that the <tt class="literal"><span class="pre">copy</span></tt> module would not do the job:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import copy
-&gt;&gt;&gt; copy.copy(f) # error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
- File &quot;/usr/local/lib/python2.3/copy.py&quot;, line 84, in copy
- y = _reconstruct(x, reductor(), 0)
- File &quot;/usr/local/lib/python2.3/copy_reg.py&quot;, line 57, in _reduce
- raise TypeError, &quot;can't pickle %s objects&quot; % base.__name__
-TypeError: can't pickle function objects
-</pre>
-</blockquote>
-</div>
-</div>
-<div class="section" id="the-beauty-of-objects">
-<h1><a class="toc-backref" href="#id75" name="the-beauty-of-objects">THE BEAUTY OF OBJECTS</a></h1>
-<p>In this chapter I will show how to define generic objects in Python, and
-how to manipulate them.</p>
-<div class="section" id="user-defined-objects">
-<h2><a class="toc-backref" href="#id76" name="user-defined-objects">User defined objects</a></h2>
-<p>In Python, one cannot directly modify methods and attributes of built-in
-types, since this would be a potentially frightening source of bugs.
-Imagine for instance of changing the sort method of a list and invoking an
-external module expecting the standard sort: all kind of hideous outcome
-could happen.</p>
-<p>Nevertheless, in Python, as in all OOP languages, the user can define
-her own kind of objects, customized to satisfy her needs. In order to
-define a new object, the user must define the class of the objects she
-needs. The simplest possible class is a do-nothing class:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Object(object):
- &quot;A convenient Object class&quot;
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Elements of the <tt class="literal"><span class="pre">Object</span></tt> class can be created (instantiated) quite
-simply:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import Object
-&gt;&gt;&gt; obj1=Object()
-&gt;&gt;&gt; obj1
-&lt;oopp.Object object at 0x81580ec&gt;
-&gt;&gt;&gt; obj2=Object()
-obj2
-&lt;object.Object object at 0x8156704&gt;
-</pre>
-</blockquote>
-<p>Notice that the hexadecimal number 0x81580ec is nothing else that the
-unique object reference to <tt class="literal"><span class="pre">obj1</span></tt></p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; hex(id(obj1))
- '0x81580ec'
-</pre>
-</blockquote>
-<p>whereas 0x8156704 is the object reference of <tt class="literal"><span class="pre">obj2</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; hex(id(obj2))
-'0x8156704'
-</pre>
-</blockquote>
-<p>However, at this point <tt class="literal"><span class="pre">obj1</span></tt> and <tt class="literal"><span class="pre">obj2</span></tt> are generic
-doing nothing objects . Nevertheless, they have
-at least an useful attribute, the class docstring:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; obj1.__doc__ #obj1 docstring
-'A convenient Object class'
-&gt;&gt;&gt; obj2.__doc__ # obj2 docstring: it's the same
-'A convenient Object class'
-</pre>
-</blockquote>
-<p>Notice that the docstring is associate to the class and therefore all
-the instances share the same docstring, unless one explicitly assigns
-a different docstring to some instance. <tt class="literal"><span class="pre">__doc__</span></tt>
-is a class attribute (or a static attribute for readers familiar with the
-C++/Java terminology) and the expression is actually syntactic sugar for</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Object(object): # with explicit assignement to __doc__
-... __doc__ = &quot;A convenient Object class&quot;
-</pre>
-</blockquote>
-<p>Since instances of 'Object' can be modified, I can transform them in
-anything I want. For instance, I can create a simple clock:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; myclock=Object()
-&gt;&gt;&gt; myclock
-&lt;__main__.Object object at 0x8124614&gt;
-</pre>
-</blockquote>
-<p>A minimal clock should at least print the current time
-on the system. This is given by the <tt class="literal"><span class="pre">get_time</span></tt> function
-we defined in the first chapter. We may &quot;attach&quot; that function
-to our clock as follows:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import oopp
-&gt;&gt;&gt; myclock.get_time=oopp.get_time
-&gt;&gt;&gt; myclock.get_time # this is a function, not a method
-&lt;function get_time at 0x815c40c&gt;
-</pre>
-</blockquote>
-<p>In other words, we have converted the <tt class="literal"><span class="pre">oopp.get_time</span></tt> function to a
-<tt class="literal"><span class="pre">get_time</span></tt> function of the object <tt class="literal"><span class="pre">myclock</span></tt>. The procedure works</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; myclock.get_time()
-'15:04:57'
-</pre>
-</blockquote>
-<p>but has a disadvantage: if we instantiate another
-clock</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import Object
-&gt;&gt;&gt; otherclock=Object()
-</pre>
-</blockquote>
-<p>the other clock will <tt class="literal"><span class="pre">not</span></tt> have a get_time method:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; otherclock.get_time() #first attempt; error
-AttributeError: 'Object' object has no attribute 'get_time'
-</pre>
-</blockquote>
-<p>Notice instead that the docstring is a <em>class attribute</em>, i.e. it
-is defined both for the class and <em>all instances</em> of the class,
-therefore even for <tt class="literal"><span class="pre">otherclock</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Object.__doc__
-'A convenient Object class'
-&gt;&gt;&gt; otherclock.__doc__
-'A convenient Object class'
-</pre>
-</blockquote>
-<p>We would like to convert the <tt class="literal"><span class="pre">get_time</span></tt> function to a
-<tt class="literal"><span class="pre">get_time</span></tt> method for the <em>entire</em> class 'Object', i.e. for all its
-instances. Naively, one would be tempted to write the following:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Object.get_time=oopp.get_time
-</pre>
-</blockquote>
-<p>However this would not work:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; otherclock.get_time() #second attempt; still error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: oopp.get_time() takes no arguments (1 given)
-</pre>
-</blockquote>
-<p>This error message is something that all Python beginners encounter
-(and sometimes even non-beginners ;-). The solution is to introduce
-an additional argument:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Object.get_time=lambda self : oopp.get_time()
-&gt;&gt;&gt; otherclock.get_time # this is method now, not a function
-&lt;bound method Object.&lt;lambda&gt; of &lt;__main__.Object object at 0x815881c&gt;&gt;
-&gt;&gt;&gt; otherclock.get_time() #third attempt
-'15:28:41'
-</pre>
-</blockquote>
-<p>Why this works ? The explanation is the following:
-when Python encounters an expression of the form
-<tt class="literal"><span class="pre">objectname.methodname()</span></tt> it looks if there is a already a method
-<em>attached</em> to the object:</p>
-<blockquote>
-<ol class="loweralpha simple">
-<li>if yes it invokes it with no arguments
-(this is why our first example worked);</li>
-<li>if not it looks at the class of the object; if there is a method
-bound to the class it invokes that method <em>by passing the
-object as first argument</em>.</li>
-</ol>
-</blockquote>
-<p>When we invoked <tt class="literal"><span class="pre">otherclock.get_time()</span></tt> in our second attempt, Python
-found that the function <tt class="literal"><span class="pre">get_time</span></tt> was defined at the class level,
-and sent it the <tt class="literal"><span class="pre">otherclock</span></tt> object as first argument: however <tt class="literal"><span class="pre">get_time</span></tt>
-was bind to <tt class="literal"><span class="pre">func_get_time</span></tt>, which is function with <em>no</em> arguments: whence
-the error message. The third attempt worked since, thanks to the
-lambda function trick, the <tt class="literal"><span class="pre">get_time</span></tt> function has been converted to
-a function accepting a first argument.</p>
-<p>Therefore that's the rule: in Python, one can define methods
-at the class level, provided one explitely introduces a first argument
-containing the object on which the method is invoked.</p>
-<p>This first argument is traditionally called <tt class="literal"><span class="pre">self</span></tt>; the name 'self' is not
-enforced, one could use any other valid Python identifier, however the
-convention is so widespread that practically everybody uses it;
-pychecker will even raise a warning in the case you don't follow the
-convention.</p>
-<p>I have just shown one the most interesting features of Python, its
-<em>dynamicity</em>: you can create the class first and add methods to it later.
-That logic cannot be followed in typical compiled language as C++. On the
-other hand, one can also define methods in a static, more traditional way:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;clock1.py&gt;
-
-&quot;Shows how to define methods inside the class (statically)&quot;
-
-import oopp
-
-class Clock(object):
- 'Clock class; version 0.1'
- def get_time(self): # method defined inside the class
- return oopp.get_time()
-
-myclock=Clock() #creates a Clock instance
-print myclock.get_time() # print the current time
-
-#&lt;/clock1.py&gt;
-</pre>
-</blockquote>
-<p>In this case we have defined the <tt class="literal"><span class="pre">get_time</span></tt> method inside the class as a
-normal function with an explicit first argument called self; this is
-entirely equivalent to the use of a lambda function.</p>
-<p>The syntax <tt class="literal"><span class="pre">myclock.get_time()</span></tt> is actually syntactic sugar for
-<tt class="literal"><span class="pre">Clock.get_time(myclock)</span></tt>.</p>
-<p>In this second form, it is clear the <tt class="literal"><span class="pre">get_time</span></tt> is really &quot;attached&quot; to the
-class, not to the instance.</p>
-</div>
-<div class="section" id="objects-have-static-methods-and-classmethods">
-<h2><a class="toc-backref" href="#id77" name="objects-have-static-methods-and-classmethods">Objects have static methods and classmethods</a></h2>
-<blockquote>
-<pre class="line-block">
-<em>There should be one--and preferably only one--obvious way to do it</em>
--- Tim Peters, <em>The Zen of Python</em>.
-</pre>
-</blockquote>
-<p>For any rule, there is an exception, and despite the Python's motto
-there are many ways to define methods in classes. The way I presented
-before was the obvious one before the Python 2.2 revolution; however,
-nowadays there is another possibility that, even if less obvious, has the
-advantage of some elegance (and it is also slightly more efficient too, even if
-efficiency if never a primary concern for a Python programmer).
-We see that the first argument in the <tt class="literal"><span class="pre">get_time</span></tt> method is useless,
-since the time is computed from the <tt class="literal"><span class="pre">time.asctime()</span></tt> function which
-does not require any information about the object that is calling
-it. This waste is ugly, and since according to the Zen of Python</p>
-<blockquote>
-<em>Beautiful is better than ugly.</em></blockquote>
-<p>we should look for another way. The solution is to use a <em>static method</em>:
-when a static method is invoked, the calling object is <em>not</em> implicitly passed
-as first argument. Therefore we may use a normal function with no additional
-first argument to define the <tt class="literal"><span class="pre">get_time</span></tt> method:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Clock(object):
- 'Clock with a staticmethod'
- get_time=staticmethod(get_time)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here is how it works:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import Clock
-&gt;&gt;&gt; Clock().get_time() # get_time is bound both to instances
-'10:34:23'
-&gt;&gt;&gt; Clock.get_time() # and to the class
-'10:34:26'
-</pre>
-</blockquote>
-<p>The staticmethod idiom converts the lambda function to a
-static method of the class 'Clock'. Notice that one can avoid the
-lambda expression and use the (arguably more Pythonic) idiom</p>
-<blockquote>
-<pre class="literal-block">
-def get_time()
- return oopp.get_time()
-get_time=staticmethod(oopp.get_time)
-</pre>
-</blockquote>
-<p>as the documentation suggests:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print staticmethod.__doc__
-staticmethod(function) -&gt; method
-Convert a function to be a static method.
-A static method does not receive an implicit first argument.
-To declare a static method, use this idiom:
- class C:
- def f(arg1, arg2, ...): ...
- f = staticmethod(f)
-It can be called either on the class (e.g. C.f()) or on an instance
-(e.g. C().f()). The instance is ignored except for its class.
-Static methods in Python are similar to those found in Java or C++.
-For a more advanced concept, see the classmethod builtin.
-</pre>
-</blockquote>
-<p>At the present the notation for static methods is still rather ugly,
-but it is expected to improve in future versions of Python (probably
-in Python 2.4). Documentation for static methods can
-be found in Guido's essay and in the PEP.. : however this is intended for
-developers.</p>
-<p>As the docstring says, static methods are also &quot;attached&quot; to the
-class and may be called with the syntax <tt class="literal"><span class="pre">Clock.get_time()</span></tt>.</p>
-<p>A similar remark applies for the so called <em>classmethods</em>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print classmethod.__doc__
-classmethod(function) -&gt; method
-Convert a function to be a class method.
-A class method receives the class as implicit first argument,
-just like an instance method receives the instance.
-To declare a class method, use this idiom:
-class C:
- def f(cls, arg1, arg2, ...): ...
- f = classmethod(f)
-It can be called either on the class (e.g. C.f()) or on an instance
-(e.g. C().f()). The instance is ignored except for its class.
-If a class method is called for a derived class, the derived class
-object is passed as the implied first argument.
-Class methods are different than C++ or Java static methods.
-If you want those, see the staticmethod builtin.
-</pre>
-</blockquote>
-<p>#When a regular method is invoked, a reference to the calling object is
-#implicitely passed as first argument; instead, when a static method is
-#invoked, no reference to the calling object is passed.</p>
-<p>As the docstring says, classmethods are convenient when one wants to pass
-to a method the calling <em>class</em>, not the calling object. Here there is an
-example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Clock(object): pass
-&gt;&gt;&gt; Clock.name=classmethod(lambda cls: cls.__name__)
-&gt;&gt;&gt; Clock.name() # called by the class
-'Clock'
-&gt;&gt;&gt; Clock().name() # called by an instance
-'Clock'
-</pre>
-</blockquote>
-<p>Notice that classmethods (and staticmethods too)
-can only be attached to classes, not to objects:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Clock(object): pass
-&gt;&gt;&gt; c=Clock()
-&gt;&gt;&gt; c.name=classmethod(lambda cls: cls.__name__)
-&gt;&gt;&gt; c.name() #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: 'classmethod' object is not callable
-</pre>
-</blockquote>
-<p>gives a TypeError. The reason is that classmethods and staticmethods
-are implemented
-trough <em>attribute descriptors</em>. This concept will be discussed in detail in a
-forthcoming in chapter 6.</p>
-<p>Notice that classmethods are not proving any fundamental feature, since
-one could very well use a normal method and retrieve the class with
-<tt class="literal"><span class="pre">self.__class__</span></tt> as we did in the first chapter.
-Therefore, we could live without (actually, I think they are a non-essential
-complication to the language).
-Nevertheless, now that we have them, we can use them, since
-they come handy in various circumstances, as we will see in the following.</p>
-</div>
-<div class="section" id="objects-have-their-privacy">
-<h2><a class="toc-backref" href="#id78" name="objects-have-their-privacy">Objects have their privacy</a></h2>
-<p>In some situations, it is convenient to give to the developer
-some information that should be hided to the final user. To this
-aim Python uses private names (i.e. names starting with a single
-underscore) and private/protected attributes (i.e. attributes starting with
-a double underscore).</p>
-<p>Consider for instance the following script:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;privacy.py&gt;
-
-import time
-
-class Clock(object):
- __secret=&quot;This Clock is quite stupid.&quot;
-
-myclock=Clock()
-try: print myclock.__secret
-except Exception,e: print &quot;AttributeError:&quot;,e
-
-#&lt;/privacy.py&gt;
-</pre>
-</blockquote>
-<p>The output of this script is</p>
-<blockquote>
-<pre class="literal-block">
-AttributeError: 'Clock' object has no attribute '__secret'
-</pre>
-</blockquote>
-<p>Therefore, even if the Clock object <em>does</em> have a <tt class="literal"><span class="pre">__secret</span></tt> attribute,
-the user cannot access it ! In this way she cannot discover that
-actually &quot;This Clock is quite stupid.&quot;</p>
-<p>In other programming languages, attributes like <tt class="literal"><span class="pre">__secret</span></tt> are
-called &quot;private&quot; attributes. However, in Python private attributes
-are not really private and their secrets can be accessed with very
-little effort.</p>
-<p>First of all, we may notice that <tt class="literal"><span class="pre">myclock</span></tt> really contains a secret
-by using the builtin function <tt class="literal"><span class="pre">dir()</span></tt>:</p>
-<blockquote>
-<pre class="literal-block">
-dir(myclock)
-['_Clock__secret', '__class__', '__delattr__', '__dict__', '__doc__',
- '__getattribute__', '__hash__', '__init__', '__module__', '__new__',
- '__reduce__', '__repr__', '__setattr__', '__str__', '__weakref__']
-</pre>
-</blockquote>
-<p>We see that the first attribute of myclock is '_Clock__secret``,
-which we may access directly:</p>
-<blockquote>
-<pre class="literal-block">
-print myclock._Clock__secret
-This clock is quite stupid.
-</pre>
-</blockquote>
-<p>We see here the secret of private variables in Python: the <em>name mangling</em>.
-When Python sees a name starting with two underscores (and not ending
-with two underscores, otherwise it would be interpreted as a special
-attribute), internally it manage it as <tt class="literal"><span class="pre">_Classname__privatename</span></tt>.
-Notice that if 'Classname' begins with underscores, the leading underscores
-are stripped in such a way to guarantee that the private name starts with
-only <em>one</em> underscore. For instance, the '__secret' private attribute
-of classes such as 'Clock', '_Clock', '__Clock', '___Clock', etc. is
-mangled to '_Clock__secret'.</p>
-<p>Private names in Python are <em>not</em> intended to keep secrets: they
-have other uses.</p>
-<ol class="arabic simple">
-<li>On one hand, private names are a suggestion to the developer.
-When the Python programmer sees a name starting with one or two
-underscores in a program written by others, she understands
-that name should not be of concern for the final user, but it
-only concerns the internal implementation.</li>
-<li>On the other hand, private names are quite useful in class
-inheritance, since they provides safety with respect to the overriding
-operation. This point we will discussed in the next chapter.</li>
-<li>Names starting with one (or more) underscores are not imported by the
-statement <tt class="literal"><span class="pre">from</span> <span class="pre">module</span> <span class="pre">import</span> <span class="pre">*</span></tt></li>
-</ol>
-<p>Remark: it makes no sense to define names with double underscores
-outside classes, since the name mangling doesn't work in this case.
-Let me show an example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Clock(object): __secret=&quot;This Clock is quite stupid&quot;
-&gt;&gt;&gt; def tellsecret(self): return self.__secret
-&gt;&gt;&gt; Clock.tellsecret=tellsecret
-&gt;&gt;&gt; Clock().tellsecret() #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
- File &quot;&lt;stdin&gt;&quot;, line 2, in tellsecret
-AttributeError: 'Clock' object has no attribute '__secret'
-</pre>
-</blockquote>
-<p>The explanation is that since <tt class="literal"><span class="pre">tellsecret()</span></tt> is defined outside the class,
-<tt class="literal"><span class="pre">__secret</span></tt> is not expanded to <tt class="literal"><span class="pre">_Clock__secret</span></tt> and therefore cannot be
-retrieved, whereas</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Clock(object):
-... __secret=&quot;This Clock is quite stupid&quot;
-... def tellsecret(self): return self.__secret
-&gt;&gt;&gt; Clock().tellsecret()
-This Clock is quite stupid
-</pre>
-</blockquote>
-<p>will work. In other words, private variables are attached to classes,
-not objects.</p>
-</div>
-<div class="section" id="objects-have-properties">
-<h2><a class="toc-backref" href="#id79" name="objects-have-properties">Objects have properties</a></h2>
-<p>In the previous section we have shown that private variables are of
-little use for keeping secrets: if a developer really wants to restrict
-the access to some methods or attributes, she has to resort to
-<em>properties</em>.</p>
-<p>Let me show an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;secret.py&gt;
-
-import oopp
-
-class Clock(object):
- 'Clock class with a secret'
-
- you_know_the_pw=False #default
-
- def give_pw(self,pw):
- &quot;&quot;&quot;Check if your know the password. For security, one should crypt
- the password.&quot;&quot;&quot;
- self.you_know_the_pw=(pw==&quot;xyz&quot;)
-
- def get_secret(self):
- if self.you_know_the_pw:
- return &quot;This clock doesn't work.&quot;
- else:
- return &quot;You must give the right password to access 'secret'&quot;
-
- secret=property(get_secret)
-
-c=Clock()
-print c.secret # =&gt; You must give the right password to access 'secret'
-c.give_pw('xyz') # gives the right password
-print c.secret # =&gt; This clock doesn't work.
-print Clock.secret # =&gt; &lt;property object at 0x814c1b4&gt;
-
-#&lt;/secret.py&gt;
-</pre>
-</blockquote>
-<p>In this script, one wants to restrict the access to the attribute
-'secret', which can be accessed only is the user provide the
-correct password. Obviously, this example is not very secure,
-since I have hard coded the password 'xyz' in the source code,
-which is easily accessible. In reality, one should crypt the
-password a perform a more sophisticated test than the trivial
-check <tt class="literal"><span class="pre">(pw==&quot;xyz&quot;)</span></tt>; anyway, the example is only intended to
-shown the uses of properties, not to be really secure.</p>
-<p>The key action is performed by the descriptor class <tt class="literal"><span class="pre">property</span></tt> that
-converts the function <tt class="literal"><span class="pre">get_secret</span></tt> in a property object. Additional
-informations on the usage of <tt class="literal"><span class="pre">property</span></tt> can be obtained from the
-docstring:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print property.__doc__
-property(fget=None, fset=None, fdel=None, doc=None) -&gt; property attribute
-fget is a function to be used for getting an attribute value, and likewise
-fset is a function for setting, and fdel a function for del'ing, an
-attribute. Typical use is to define a managed attribute x:
-class C(object):
- def getx(self): return self.__x
- def setx(self, value): self.__x = value
- def delx(self): del self.__x
- x = property(getx, setx, delx, &quot;I'm the 'x' property.&quot;)
-</pre>
-</blockquote>
-<p>Properties are another example of attribute descriptors.</p>
-</div>
-<div class="section" id="objects-have-special-methods">
-<h2><a class="toc-backref" href="#id80" name="objects-have-special-methods">Objects have special methods</a></h2>
-<p>From the beginning, we stressed that objects have special attributes that
-may turn handy, as for instance the docstring <tt class="literal"><span class="pre">__doc__</span></tt> and the class
-name attribute <tt class="literal"><span class="pre">__class__</span></tt>. They have special methods, too.</p>
-<p>With little doubt, the most useful special method is the <tt class="literal"><span class="pre">__init__</span></tt>
-method, that <em>initializes</em> an object right after its creation. <tt class="literal"><span class="pre">__init__</span></tt>
-is typically used to pass parameters to <em>object factories</em>. Let me an
-example with geometric figures:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class GeometricFigure(object): #an example of object factory
- &quot;&quot;&quot;This class allows to define geometric figures according to their
- equation in the cartesian plane. It will be extended later.&quot;&quot;&quot;
- def __init__(self,equation,**parameters):
- &quot;Specify the cartesian equation of the object and its parameters&quot;
- self.eq=equation
- self.par=parameters
- for k,v in self.par.items(): #replaces the parameters in the equation
- self.eq=self.eq.replace(k,str(v))
- self.contains=eval('lambda x,y : '+self.eq)
- # dynamically creates the function 'contains'
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here it is how it works:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; disk=GeometricFigure('(x-x0)**2+(y-y0)**2 &lt;= r**2', x0=0,y0=0,r=5)
-&gt;&gt;&gt; # creates a disk of radius 5 centered in the origing
-&gt;&gt;&gt; disk.contains(1,2) #asks if the point (1,2) is inside the disk
-True
-&gt;&gt;&gt; disk.contains(4,4) #asks if the point (4,4) is inside the disk
-False
-</pre>
-</blockquote>
-<p>Let me continue the section on special methods with some some observations on
-<tt class="literal"><span class="pre">__repr__</span></tt> and <tt class="literal"><span class="pre">__str__</span></tt>.Notice that I
-will not discuss all the subtleties; for a thought discussion, see the
-thread &quot;Using __repr__ or __str__&quot; in c.l.p. (Google is your friend).
-The following discussion applies to new style classes, old style classes
-are subtly different; moreover.</p>
-<p>When one writes</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; disk
-&lt;oopp.GeometricFigure instance at 0x81b496c&gt;
-</pre>
-</blockquote>
-<p>one obtains the <em>string representation</em> of the object. Actually, the previous
-line is syntactic sugar for</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print repr(disk)
-&lt;oopp.GeometricFigure instance at 0x81b496c&gt;
-</pre>
-</blockquote>
-<p>or</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print disk.__repr__()
-&lt;oopp.GeometricFigure instance at 0x81b496c&gt;
-</pre>
-</blockquote>
-<p>The <tt class="literal"><span class="pre">repr</span></tt> function extracts the string representation from the
-the special method <tt class="literal"><span class="pre">__repr__</span></tt>, which can be redefined in order to
-have objects pretty printed. Notice that <tt class="literal"><span class="pre">repr</span></tt> is conceptually
-different from the <tt class="literal"><span class="pre">str</span></tt> function that controls the output of the <tt class="literal"><span class="pre">print</span></tt>
-statement. Actually, <tt class="literal"><span class="pre">print</span> <span class="pre">o</span></tt> is syntactic sugar for <tt class="literal"><span class="pre">print</span> <span class="pre">str(o)</span></tt>
-which is sugar for <tt class="literal"><span class="pre">print</span> <span class="pre">o.__str__()</span></tt>.</p>
-<p>If for instance we define</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class PrettyPrinted(object):
- formatstring='%s' # default
- def __str__(self):
- &quot;&quot;&quot;Returns the name of self in quotes, possibly formatted via
- self.formatstring. If self has no name, returns the name
- of its class in angular brackets.&quot;&quot;&quot;
- try: #look if the selfect has a name
- name=&quot;'%s'&quot; % self.__name__
- except AttributeError: #if not, use the name of its class
- name='&lt;%s&gt;' % type(self).__name__
- if hasattr(self,'formatstring'):
- return self.formatstring % name
- else:
- return name
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>then we have</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import PrettyPrinted
-&gt;&gt;&gt; o=PrettyPrinted() # o is an instance of PrettyPrinted
-&gt;&gt;&gt; print o #invokes o.__str__() which in this case returns o.__class__.name
-&lt;PrettyPrinted&gt;
-</pre>
-</blockquote>
-<p>whereas</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; o # i.e. print repr(o)
-&lt;oopp.PrettyPrinted object at 0x400a006c&gt;
-</pre>
-</blockquote>
-<p>However, in most cases <tt class="literal"><span class="pre">__repr__</span></tt> and <tt class="literal"><span class="pre">__str__</span></tt> gives the same
-output, since if <tt class="literal"><span class="pre">__str__</span></tt> is not explicitely defined it defaults
-to <tt class="literal"><span class="pre">__repr__</span></tt>. Therefore, whereas modifying <tt class="literal"><span class="pre">__str__</span></tt>
-does not change <tt class="literal"><span class="pre">__repr__</span></tt>, modifying <tt class="literal"><span class="pre">__repr__</span></tt> changes <tt class="literal"><span class="pre">__str__</span></tt>,
-if <tt class="literal"><span class="pre">__str__</span></tt> is not explicitely given:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;fairytale1.py&gt;
-
-&quot;__repr__ can also be a regular method, not a classmethod&quot;
-
-class Frog(object):
- attributes=&quot;poor, small, ugly&quot;
- def __str__(self):
- return &quot;I am a &quot;+self.attributes+' '+self.__class__.__name__
-
-class Prince(object):
- attributes='rich, tall, beautiful'
- def __str__(self):
- return &quot;I am a &quot;+self.attributes+' '+self.__class__.__name__
-
-jack=Frog(); print repr(jack),jack
-charles=Prince(); print repr(charles),charles
-
-#&lt;/fairytale1.py&gt;
-</pre>
-</blockquote>
-<p>The output of this script is:</p>
-<blockquote>
-<pre class="literal-block">
-&lt;Frog object at 0x81866ec&gt; I am a poor, small, ugly Frog
-&lt;Prince object at 0x818670c&gt; I am a rich, tall, beautiful Prince
-</pre>
-</blockquote>
-<p>for jack and charles respectively.</p>
-<p><tt class="literal"><span class="pre">__str__</span></tt> and <tt class="literal"><span class="pre">__repr__</span></tt> are also called by the formatting
-operators &quot;%s&quot; and &quot;%r&quot;.</p>
-<p>Notice that i) <tt class="literal"><span class="pre">__str__</span></tt> can be most naturally
-rewritten as a class method; ii) Python is magic:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;fairytale2.py&gt;
-
-&quot;&quot;&quot;Shows two things:
- 1) redefining __repr__ automatically changes the output of __str__
- 2) the class of an object can be dinamically changed! &quot;&quot;&quot;
-
-class Frog(object):
- attributes=&quot;poor, small, ugly&quot;
- def __repr__(cls):
- return &quot;I am a &quot;+cls.attributes+' '+cls.__name__
- __repr__=classmethod(__repr__)
-
-class Prince(object):
- attributes='rich, tall, beautiful'
- def __repr__(cls):
- return &quot;I am a &quot;+cls.attributes+' '+cls.__name__
- __repr__=classmethod(__repr__)
-
-def princess_kiss(frog):
- frog.__class__=Prince
-
-jack=Frog()
-princess_kiss(jack)
-print jack # the same as repr(jack)
-
-#&lt;/fairytale2.py&gt;
-</pre>
-</blockquote>
-<p>Now the output for jack is &quot;I am a rich, tall, beautiful Prince&quot; !
-In Python you may dynamically change the class of an object!!</p>
-<p>Of course, this is a feature to use with care ;-)</p>
-<p>There are many others special methods, such as __new__, __getattr__,
-__setattr__, etc. They will be discussed in the next chapters, in
-conjunction with inheritance.</p>
-</div>
-<div class="section" id="objects-can-be-called-added-subtracted">
-<h2><a class="toc-backref" href="#id81" name="objects-can-be-called-added-subtracted">Objects can be called, added, subtracted, ...</a></h2>
-<p>Python provides a nice generalization of functions, via the concept
-of <em>callable objects</em>. A callable object is an object with a <tt class="literal"><span class="pre">__call__</span></tt>
-special method. They can be used to define &quot;functions&quot; that remember
-how many times they are invoked:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;call.py&gt;
-
-class MultiplyBy(object):
- def __init__(self,n):
- self.n=n
- self.counter=0
- def __call__(self,x):
- self.counter+=1
- return self.n*x
-
-double=MultiplyBy(2)
-res=double(double(3)) # res=12
-print &quot;double is callable: %s&quot; % callable(double)
-print &quot;You have called double %s times.&quot; % double.counter
-
-#&lt;/call.py&gt;
-</pre>
-</blockquote>
-<p>With output</p>
-<blockquote>
-<pre class="literal-block">
-double is callable: True
-You have called double 2 times.
-</pre>
-</blockquote>
-<p>The script also show that callable objects (including functions)
-can be recognized with the <tt class="literal"><span class="pre">callable</span></tt> built-in function.</p>
-<p>Callable object solves elegantly the problem of having &quot;static&quot; variables
-inside functions (cfr. with the 'double' example in chapter 2).
-A class with a <tt class="literal"><span class="pre">__call__</span></tt> method can be used to generate an entire
-set of customized &quot;functions&quot;. For this reason, callable objects are
-especially useful in the conjunction with object factories. Let me show
-an application to my factory of geometric figures:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Makeobj(object):
- &quot;&quot;&quot;A factory of object factories. Makeobj(cls) returns instances
- of cls&quot;&quot;&quot;
- def __init__(self,cls,*args):
- self.cls=cls
- self.args=args
- def __call__(self,**pars):
- return self.cls(*self.args,**pars)
-
-#&lt;/oopp.py&gt;
-
-#&lt;factory.py&gt;
-
-from oopp import Makeobj,GeometricFigure
-
-makedisk=Makeobj(GeometricFigure,'(x-x0)**2+(y-y0)**2&lt;r**2')
-makesquare=Makeobj(GeometricFigure,'abs(x-x0)&lt;L and abs(y-y0)&lt;L')
-disk=makedisk(x0=0,y0=0,r=10) # make a disk of radius 10
-square=makesquare(x0=0,y0=0,L=20) # make a disk of side 10
-
-print disk.contains(9,9) # =&gt; False
-print square.contains(9,9) # =&gt; True
-#etc.
-
-#&lt;/factory.py&gt;
-</pre>
-</blockquote>
-<p>This factory generates callable objects, such as <tt class="literal"><span class="pre">makedisk</span></tt> and
-<tt class="literal"><span class="pre">makesquare</span></tt> that returns geometric objects. It gives a nicer interface
-to the object factory provided by 'GeometricFigure'.</p>
-<p>Notice that the use of the expression <tt class="literal"><span class="pre">disk.contains(9,9)</span></tt> in order to
-know if the point of coordinates (9,9) is contained in the disk, it is
-rather inelegant: it would be much better to be able to ask if
-<tt class="literal"><span class="pre">(9,9)</span> <span class="pre">in</span> <span class="pre">disk</span></tt>. This is possibile, indeed: and the secrets is to
-define the special method <tt class="literal"><span class="pre">__contains__</span></tt>. This is done in the next
-example, that I think give a good taste of the beauty of objects</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;funnyformatter.py&gt;
-
-from oopp import Makeobj
-
-Nrow=50; Ncol=78
-
-class GeometricFigure(object):
- &quot;&quot;&quot;This class allows to define geometric figures according to their
- equation in the cartesian plane. Moreover addition and subtraction
- of geometric figures are defined as union and subtraction of sets.&quot;&quot;&quot;
- def __init__(self,equation,**parameters):
- &quot;Initialize &quot;
- self.eq=equation
- self.par=parameters
- for (k,v) in self.par.items(): #replaces the parameters
- self.eq=self.eq.replace(k,str(v))
- self.contains=eval('lambda x,y : '+self.eq)
- def combine(self,fig,operator):
- &quot;&quot;&quot;Combine self with the geometric figure fig, using the
- operators &quot;or&quot; (addition) and &quot;and not&quot; (subtraction)&quot;&quot;&quot;
- comboeq=&quot;(&quot;+self.eq+&quot;)&quot;+operator+&quot;(&quot;+fig.eq+&quot;)&quot;
- return GeometricFigure(comboeq)
- def __add__(self,fig):
- &quot;Union of sets&quot;
- return self.combine(fig,' or ')
- def __sub__(self,fig):
- &quot;Subtraction of sets&quot;
- return self.combine(fig,' and not')
- def __contains__(self,point): #point is a tuple (x,y)
- return self.contains(*point)
-
-makedisk=Makeobj(GeometricFigure,'(x-x0)**2/4+(y-y0)**2 &lt;= r**2')
-upperdisk=makedisk(x0=38,y0=7,r=5)
-smalldisk=makedisk(x0=38,y0=30,r=5)
-bigdisk=makedisk(x0=38,y0=30,r=14)
-
-def format(text,shape):
- &quot;Format the text in the shape given by figure&quot;
- text=text.replace('\n',' ')
- out=[]; i=0; col=0; row=0; L=len(text)
- while 1:
- if (col,row) in shape:
- out.append(text[i]); i+=1
- if i==L: break
- else:
- out.append(&quot; &quot;)
- if col==Ncol-1:
- col=0; out.append('\n') # starts new row
- if row==Nrow-1: row=0 # starts new page
- else: row+=1
- else: col+=1
- return ''.join(out)
-
-composition=bigdisk-smalldisk+upperdisk
-print format(text='Python Rules!'*95,shape=composition)
-
-#&lt;/funnyformatter.py&gt;
-</pre>
-</blockquote>
-<p>I leave as an exercise for the reader to understand how does it work and to
-play with other geometric figures (he can also generate them trough the
-'Makeobj' factory). I think it is nicer to show its output:</p>
-<blockquote>
-<pre class="literal-block">
- Pyt
- hon Rules!Pyt
- hon Rules!Python
- Rules!Python Rules!
- Python Rules!Python
- Rules!Python Rules!P
- ython Rules!Python
- Rules!Python Rules!
- Python Rules!Pyth
- on Rules!Pyth
- on
-
-
-
- Rul
- es!Python Rules!Pytho
- n Rules!Python Rules!Python R
- ules!Python Rules!Python Rules!Pyth
- on Rules!Python Rules!Python Rules!Pyth
- on Rules!Python Rules!Python Rules!Python R
- ules!Python Rules!Python Rules!Python Rules!Pyt
- hon Rules!Python Rules!Python Rules!Python Rules!
- Python Rules!Python Rules!Python Rules!Python Rules
- !Python Rules!Python Rule s!Python Rules!Python Rul
- es!Python Rules!Pyth on Rules!Python Rule
- s!Python Rules!Pyth on Rules!Python Rul
- es!Python Rules!Py thon Rules!Python
- Rules!Python Rules !Python Rules!Pyth
-on Rules!Python Ru les!Python Rules!P
- ython Rules!Python Rules!Python Rule
- s!Python Rules!Pyt hon Rules!Python R
- ules!Python Rules!P ython Rules!Python
- Rules!Python Rules!P ython Rules!Python R
- ules!Python Rules!Python Rules!Python Rules!Python
- Rules!Python Rules!Python Rules!Python Rules!Pytho
- n Rules!Python Rules!Python Rules!Python Rules!Py
- thon Rules!Python Rules!Python Rules!Python Rul
- es!Python Rules!Python Rules!Python Rules!P
- ython Rules!Python Rules!Python Rules!P
- ython Rules!Python Rules!Python Rul
- es!Python Rules!Python Rules!
- Python Rules!Python R
- ule
-
-
-
-
-
-
-
- s!
-</pre>
-</blockquote>
-<p>Remark.</p>
-<p>Unfortunately, &quot;funnyformatter.py&quot; does not reuse old code: in spite of the
-fact that we already had in our library the 'GeometricFigure' class, with
-an &quot;__init__&quot; method that is exactly the same of the &quot;__init__&quot; method in
-&quot;funnyformatter.py&quot;, we did not reuse that code. We simply did a cut
-and paste. This means that if we later find a bug in the <tt class="literal"><span class="pre">__init__</span></tt> method,
-we will have to fix it twice, both in the script and in the library. Also,
-if we plan to extend the method later, we will have to extend it twice.
-Fortunately, this nasty situation can be avoided: but this requires the
-power of inheritance.</p>
-</div>
-</div>
-<div class="section" id="the-power-of-classes">
-<h1><a class="toc-backref" href="#id82" name="the-power-of-classes">THE POWER OF CLASSES</a></h1>
-<p>This chapter is devoted to the concept of class inheritance. I will discuss
-single inheritance, cooperative methods, multiple inheritance and more.</p>
-<div class="section" id="the-concept-of-inheritance">
-<h2><a class="toc-backref" href="#id83" name="the-concept-of-inheritance">The concept of inheritance</a></h2>
-<p>Inheritance is perhaps the most important basic feature in OOP, since it
-allows the reuse and incremental improvement of old code.
-To show this point, let me come back to one of the
-examples I have introduced in the last chapter, 'fairytale1.py' script,
-where I defined the classes 'Frog' and 'Prince' as</p>
-<blockquote>
-<pre class="literal-block">
-class Frog(object):
- attributes=&quot;poor, small, ugly&quot;
- def __str__(self):
- return &quot;I am a &quot;+self.attributes+' '+self.__class__.__name__
-
-class Prince(object):
- attributes='rich, tall, beautiful'
- def __str__(self):
- return &quot;I am a &quot;+self.attributes+' '+self.__class__.__name__
-</pre>
-</blockquote>
-<p>We see that the way we followed here was very bad since:</p>
-<ol class="arabic simple">
-<li>The <tt class="literal"><span class="pre">__str__</span></tt> method is duplicated both in Frog and in Prince: that
-means that if we find a bug a later, we have to fix it twice!</li>
-<li>The <tt class="literal"><span class="pre">__str__</span></tt> was already defined in the PrettyPrinted class (actually
-more elegantly), therefore we have triplicated the work and worsened the
-situation!</li>
-</ol>
-<p>This is very much against the all philosophy of OOP:</p>
-<blockquote>
-<em>never cut and paste!</em></blockquote>
-<p>We should <em>reuse</em> old code, not paste it!</p>
-<p>The solution is <em>class inheritance</em>. The idea behind inheritance is to
-define new classes as subclasses of a <em>parent</em> classes, in such a way that
-the <em>children</em> classes possess all the features of the parents.
-That means that we do not need to
-redefine the properties of the parents explicitely.
-In this example, we may derive both 'Frog' and 'Prince' from
-the 'PrettyPrinted' class, thus providing to both 'Frog' and 'Prince'
-the <tt class="literal"><span class="pre">PrettyPrinted.__str__</span></tt> method with no effort:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import PrettyPrinted
-&gt;&gt;&gt; class Frog(PrettyPrinted): attributes=&quot;poor, small, ugly&quot;
-...
-&gt;&gt;&gt; class Prince(PrettyPrinted): attributes=&quot;rich, tall, beautiful&quot;
-...
-&gt;&gt;&gt; print repr(Frog()), Frog()
-&lt;__main__.Frog object at 0x401cbeac&gt; &lt;Frog&gt;
-&gt;&gt;&gt; print Prince()
-&gt;&gt;&gt; print repr(Prince()),Prince()
-&lt;__main__.Prince object at 0x401cbaac&gt; &lt;Prince&gt;
-</pre>
-</blockquote>
-<p>Let me show explicitly that both 'Frog' and 'Prince' share the
-'PrettyPrinted.__str__' method:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; id(Frog.__str__) # of course, YMMV
-1074329476
-&gt;&gt;&gt; id(Prince.__str__)
-1074329476
-&gt;&gt;&gt; id(PrettyPrinted.__str__)
-1074329476
-</pre>
-</blockquote>
-<p>The method is always the same, since the object reference is the same
-(the precise value of the reference is not guaranteed to be 1074329476,
-however!).</p>
-<p>This example is good to show the first advantage of inheritance:
-<em>avoiding duplication of code</em>.
-Another advantage of inheritance, is <em>extensibility</em>: one can very easily
-improve existing code. For instance, having written the <tt class="literal"><span class="pre">Clock</span></tt> class once,
-I can reuse it in many different ways. for example I can build a <tt class="literal"><span class="pre">Timer</span></tt>
-to be used for benchmarks. It is enough to reuse the function <tt class="literal"><span class="pre">with_timer</span></tt>
-introduced in the first chapter (functions are good for reuse of code, too ;):</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Timer(Clock):
- &quot;Inherits the get_time staticmethod from Clock&quot;
- execute=staticmethod(with_timer)
- loop_overhead=staticmethod(loop_overhead)
-
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here there is an example of application:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import Timer
-&gt;&gt;&gt; Timer.get_time()
-'16:07:06'
-</pre>
-</blockquote>
-<p>Therefore 'Timer' inherits 'Clock.get_time'; moreover it has the additional
-method <tt class="literal"><span class="pre">execute</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def square(x): return x*x
-...
-&gt;&gt;&gt; Timer.execute(square,n=100000)(1)
-executing square ...
- Real time: 0.01 ms CPU time: 0.008 ms
-</pre>
-</blockquote>
-<p>The advantage of putting the function <tt class="literal"><span class="pre">execute</span></tt> in a class is that
-now we may <em>inherit</em> from that class and improve out timer <em>ad
-libitum</em>.</p>
-</div>
-<div class="section" id="inheritance-versus-run-time-class-modifications">
-<h2><a class="toc-backref" href="#id84" name="inheritance-versus-run-time-class-modifications">Inheritance versus run-time class modifications</a></h2>
-<p>Naively, one could think of substituting inheritance with run-time
-modification of classes, since this is allowed by Python. However,
-this is not such a good idea, in general. Let me give a simple example.
-Suppose we want to improve our previous clock, to show the date, too.
-We could reach that goal with the following script:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;clock2.py&gt;
-
-&quot;Shows how to modify and enhances classes on the fly&quot;
-
-from oopp import *
-
-clock=Clock() #creates a Clock instance
-print clock.get_time() # print the current time
-
-get_data=lambda : ' '.join(time.asctime().split()[0:3])+ \
- ' '+time.asctime().split()[-1]
-
-get_data_and_time=lambda : &quot;Today is: %s \nThe time is: %s&quot; % (
- get_data(),get_time()) # enhances get_time
-
-Clock.get_time=staticmethod(get_data_and_time)
-
-print clock.get_time() # print the current time and data
-
-#&lt;/clock2.py&gt;
-</pre>
-</blockquote>
-<p>The output of this script is:</p>
-<blockquote>
-12:51:25
-Today is: Sat Feb 22 2003
-The time is: 12:51:25</blockquote>
-<p>Notice that:</p>
-<ol class="arabic simple">
-<li>I instantiated the <tt class="literal"><span class="pre">clock</span></tt> object <em>before</em> redefining the <tt class="literal"><span class="pre">get_time</span></tt>
-method, when it only could print the time and <em>not</em> the date.</li>
-<li>However, after the redefinition of the class, the behaviour of all its
-instances is changed, <em>including the behaviour of objects instantiated
-before the change!</em>. Then <tt class="literal"><span class="pre">clock</span></tt> <em>can</em> print the date, too.</li>
-</ol>
-<p>This is not so surprising, once you recognize that Guido own a very famous
-time-machine ... ;-)</p>
-<p>Seriously, the reason is that an object does not contains a reserved copy
-of the attributes and methods of its class: it only contains <em>references</em>
-to them. If we change them in the class, the references to them in the
-object will stay the same, but the contents will change.</p>
-<p>In this example, I have solved the problem of enhancing the 'Clock' class
-without inheritance, but dynamically replaceing its <tt class="literal"><span class="pre">get_time</span></tt>
-(static) method with the <cite>get_data_and_time`</cite> (static) method.
-The dynamics modification of methods can be cool, but it should be avoided
-whenever possible, at least for two reasons <a class="footnote-reference" href="#id22" id="id23" name="id23">[11]</a>:</p>
-<ol class="arabic simple">
-<li>having a class and therefore all its instances (including the instances
-created before the modification !) changed during the life-time of the
-program can be very confusing to the programmer, if not to the interpreter.</li>
-<li>the modification is destructive: I cannot have the old <tt class="literal"><span class="pre">get_time</span></tt> method
-and the new one at the same time, unless one explicitly gives to it
-a new name (and giving new names increases the pollution of the namespace).</li>
-</ol>
-<p>Both these disadvantages can be solved by resorting to the mechanism of
-inheritance. For instance, in this example, we can derive a new class
-<tt class="literal"><span class="pre">NewClock</span></tt> from <tt class="literal"><span class="pre">Clock</span></tt> as follows:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;newclock.py&gt;
-
-import oopp,time
-
-get_data=lambda : ' '.join(time.asctime().split()[0:3])+ \
- ' '+time.asctime().split()[-1]
-
-get_data_and_time=lambda : &quot;Today is: %s \nThe time is: %s&quot; % (
- get_data(),oopp.get_time()) # enhances get_time
-
-class NewClock(oopp.Clock):
- &quot;&quot;&quot;NewClock is a class that inherits from Clock, provides get_data
- and overrides get_time.&quot;&quot;&quot;
- get_data=staticmethod(get_data)
- get_time=staticmethod(get_data_and_time)
-
-clock=oopp.Clock(); print 'clock output=',clock.get_time()
-newclock=NewClock(); print 'newclock output=',newclock.get_time()
-
-#&lt;/newclock.py&gt;
-</pre>
-</blockquote>
-<p>The output of this script is:</p>
-<blockquote>
-<pre class="literal-block">
-clock output= 16:29:17
-newclock output= Today is: Sat Feb 22 2003
-The time is: 16:29:17
-</pre>
-</blockquote>
-<p>We see that the two problems previously discussed are solved since:</p>
-<ol class="lowerroman simple">
-<li>there is no cut and paste: the old method <tt class="literal"><span class="pre">Clock.get_time()</span></tt> is used
-in the definition of the new method <tt class="literal"><span class="pre">NewClock.get_time()</span></tt>;</li>
-<li>the old method is still accessible as <tt class="literal"><span class="pre">Clock.get_time()</span></tt>; there is
-no need to invent a new name like <tt class="literal"><span class="pre">get_time_old()</span></tt>.</li>
-</ol>
-<p>We say that the method <tt class="literal"><span class="pre">get_time</span></tt> in <tt class="literal"><span class="pre">NewClock</span></tt> <em>overrides</em> the method
-<tt class="literal"><span class="pre">get_time</span></tt> in Clock.</p>
-<p>This simple example shows the power of inheritance in code
-reuse, but there is more than that.</p>
-<p>Inheritance is everywhere in Python, since
-all classes inherit from object. This means that all classes
-inherit the methods and attributes of the object class, such as <tt class="literal"><span class="pre">__doc__</span></tt>,
-<tt class="literal"><span class="pre">__class__</span></tt>, <tt class="literal"><span class="pre">__str__</span></tt>, etc.</p>
-<blockquote>
-<table class="footnote" frame="void" id="id24" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id25" name="id24">[12]</a></td><td>There are cases when run-time modifications of classes is useful
-anyway: particularly when one wants to modify the behavior of
-classes written by others without changing the source code. I
-will show an example in next chapter.</td></tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-<div class="section" id="inheriting-from-built-in-types">
-<h2><a class="toc-backref" href="#id85" name="inheriting-from-built-in-types">Inheriting from built-in types</a></h2>
-<p>However, one can subclass a built-in type, effectively creating an
-user-defined type with all the feature of a built-in type, and modify it.</p>
-<p>Suppose for instance one has a keyword dictionary such as</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; kd={'title': &quot;OOPP&quot;, 'author': &quot;M.S.&quot;, 'year': 2003}
-</pre>
-</blockquote>
-<p>it would be nice to be able to access the attributes without
-excessive quoting, i.e. using <tt class="literal"><span class="pre">kd.author</span></tt> instead of <tt class="literal"><span class="pre">kd[&quot;author&quot;]</span></tt>.
-This can be done by subclassing the built-in class <tt class="literal"><span class="pre">dict</span></tt> and
-by overriding the <tt class="literal"><span class="pre">__getattr__</span></tt> and <tt class="literal"><span class="pre">__setattr__</span></tt> special methods:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp/py&gt;
-
-class kwdict(dict):
- &quot;Keyword dictionary base class&quot;
- def __getattr__(self,attr):
- return self[attr]
- def __setattr__(self,key,val):
- self[key]=val
- __str__ = pretty
-
-#&lt;/oopp/py&gt;
-</pre>
-</blockquote>
-<p>Here there is an example of usage:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import kwdict
-&gt;&gt;&gt; book=kwdict({'title': &quot;OOPP&quot;, 'author': &quot;M.S.&quot;})
-&gt;&gt;&gt; book.author #it works
-'M.S.'
-&gt;&gt;&gt; book[&quot;author&quot;] # this also works
-'M.S.'
-&gt;&gt;&gt; book.year=2003 #you may also add new fields on the fly
-&gt;&gt;&gt; print book
-author = M.S.
-title = OOPP
-year = 2003
-</pre>
-</blockquote>
-<p>The advantage of subclassing the built-in 'dict', it that you have for free
-all the standard dictionary methods, without having to reimplement them.</p>
-<p>However, to subclass built-in it is not always a piece of cake. In
-many cases there are complications, indeed. Suppose for instance
-one wants to create an enhanced string type, with
-the ability of indent and dedent a block of text provided by
-the following functions:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def indent(block,n):
- &quot;Indent a block of code by n spaces&quot;
- return '\n'.join([' '*n+line for line in block.splitlines()])
-
-def dedent(block):
- &quot;Dedent a block of code, if need there is&quot;&quot;&quot;
- lines=block.splitlines()
- for line in lines:
- strippedline=line.lstrip()
- if strippedline: break
- spaces=len(line)-len(strippedline)
- if not spaces: return block
- return '\n'.join([line[spaces:] for line in lines])
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>The solution is to inherit from the built-in string type <tt class="literal"><span class="pre">str</span></tt>, and to
-add to the new class the <tt class="literal"><span class="pre">indent</span></tt> and <tt class="literal"><span class="pre">dedent</span></tt> methods:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import indent,dedent
-&gt;&gt;&gt; class Str(str):
-... indent=indent
-... dedent=dedent
-&gt;&gt;&gt; s=Str('spam\neggs')
-&gt;&gt;&gt; type(s)
-&lt;class '__main__.Str'&gt;
-&gt;&gt;&gt; print s.indent(4)
- spam
- eggs
-</pre>
-</blockquote>
-<p>However, this approach has a disadvantage, since the output of <tt class="literal"><span class="pre">indent</span></tt> is
-not a <tt class="literal"><span class="pre">Str</span></tt>, but a normal <tt class="literal"><span class="pre">str</span></tt>, therefore without the additional
-<tt class="literal"><span class="pre">indent</span></tt> and <tt class="literal"><span class="pre">dedent</span></tt> methods:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(s.indent(4))
-&lt;type 'str'&gt;
-&gt;&gt;&gt; s.indent(4).indent(4) #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 9, in ?
-AttributeError: 'str' object has no attribute 'indent'
-&gt;&gt;&gt; s.indent(4).dedent(4) #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 9, in ?
-AttributeError: 'str' object has no attribute 'dedent'
-</pre>
-</blockquote>
-<p>We would like <tt class="literal"><span class="pre">indent</span></tt> to return a <tt class="literal"><span class="pre">Str</span></tt> object. To solve this problem
-it is enough to rewrite the class as follows:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;Str.py&gt;
-
-from oopp import indent,dedent
-
-class Str(str):
- def indent(self,n):
- return Str(indent(self,n))
- def dedent(self):
- return Str(dedent(self))
-
-s=Str('spam\neggs').indent(4)
-print type(s)
-print s # indented s
-s=s.dedent()
-print type(s)
-print s # non-indented s
-
-#&lt;/Str.py&gt;
-</pre>
-</blockquote>
-<p>Now, everything works and the output of the previous script is</p>
-<blockquote>
-<pre class="literal-block">
-&lt;class 'Str'&gt;
- spam
- eggs
-&lt;class 'Str'&gt;
-spam
-eggs
-</pre>
-</blockquote>
-<p>The solution works because now <tt class="literal"><span class="pre">indent()</span></tt> returns an instance
-of <tt class="literal"><span class="pre">Str</span></tt>, which therefore has an <tt class="literal"><span class="pre">indent</span></tt> method. Unfortunately,
-this is not the end. Suppose we want to add another food to our list:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; s2=s+Str(&quot;\nham&quot;)
-&gt;&gt;&gt; s2.indent(4) #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'str' object has no attribute 'indent'
-</pre>
-</blockquote>
-<p>The problem is the same, again: the type of <tt class="literal"><span class="pre">s2</span></tt> is <tt class="literal"><span class="pre">str</span></tt></p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(s2)
-&lt;type 'str'&gt;
-</pre>
-</blockquote>
-<p>and therefore there is no <tt class="literal"><span class="pre">indent</span></tt> method available. There is a
-solution to this problem, i.e. to redefine the addition operator
-for objects of the class <tt class="literal"><span class="pre">Str</span></tt>. This can be done directly by hand,
-but it is <em>ugly</em> for the following reasons:</p>
-<ol class="arabic simple">
-<li>If you derive a new class from <tt class="literal"><span class="pre">Str</span></tt> you have to redefine the
-addition operator (both the left addition and the right addition <a class="footnote-reference" href="#id24" id="id25" name="id25">[12]</a>)
-again (ughh!);</li>
-<li>There are others operators you must redefine, in particular the
-the augumented assignement operator <tt class="literal"><span class="pre">+=</span></tt>, the repetition operator <tt class="literal"><span class="pre">*</span></tt>
-and its augmented version <tt class="literal"><span class="pre">*=</span></tt>;</li>
-<li>In the case of numeric types, one must redefine, <tt class="literal"><span class="pre">+,-,*,/,//,</span> <span class="pre">mod,</span></tt>,
-possibily <tt class="literal"><span class="pre">&lt;&lt;,&gt;&gt;</span></tt> and others, including the corresponding
-augumented assignement operators and the left and the right form of
-the operators.</li>
-</ol>
-<p>This is a mess, especially since due to point 1, one has to redefined
-all the operators each time she defines a new subclass. I short, one has
-to write a lot of boilerplate for a stupid job that the language
-should be able to perform itself automatically. But here are the
-good news: Python <em>can</em> do all that automatically, in an elegant
-and beautiful way, which works for all types, too.</p>
-<p>But this requires the magic of metaclasses.</p>
-<blockquote>
-<table class="footnote" frame="void" id="id26" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id27" name="id26">[13]</a></td><td>The right addition works this way. Python looks at the expression x+y
-and if x has an explicit__add__ method invokes it; on the other hand,
-if x does not define an __add__ method, Python considers y+x.
-If y defines a __radd__ method, it invokes it, otherwise
-raises an exception. The same is done for right multiplication, etc.</td></tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-<div class="section" id="controlling-the-creation-of-objects">
-<h2><a class="toc-backref" href="#id86" name="controlling-the-creation-of-objects">Controlling the creation of objects</a></h2>
-<p>Before introducing multiple inheritance, let me make a short digression on
-the mechanism of object creation in Python 2.2+. The important point is
-that new style classes have a <tt class="literal"><span class="pre">__new__</span></tt> static method that allows
-the user to take complete control of object creation. To understand how
-<tt class="literal"><span class="pre">__new__</span></tt> works, I must explain what happens when an object is instantiated
-with a statement like</p>
-<blockquote>
-<pre class="literal-block">
-s=Str(&quot;spam&quot;) #object creation
-</pre>
-</blockquote>
-<p>What happens under the hood, is that the special static method <tt class="literal"><span class="pre">__new__</span></tt>
-of the class <tt class="literal"><span class="pre">Str</span></tt> (inherited from the built-in <tt class="literal"><span class="pre">str</span></tt> class)
-is invoked <tt class="literal"><span class="pre">before</span></tt> the <tt class="literal"><span class="pre">Str.__init__</span></tt> method. This means that
-the previous line should really be considered syntactic sugar for:</p>
-<blockquote>
-<pre class="literal-block">
-s=Str.__new__(Str,&quot;spam&quot;) # Str.__new__ is actually str.__new__
-assert isinstance(s,Str)
-Str.__init__(s,&quot;spam&quot;) # Str.__init__ is actually str.__init__
-</pre>
-</blockquote>
-<p>Put it more verbosely, what happens during the object creation is the
-following:</p>
-<ol class="arabic simple">
-<li>the static method <tt class="literal"><span class="pre">__new__</span></tt> is invoked with the class of the created
-object as first argument <a class="footnote-reference" href="#id26" id="id27" name="id27">[13]</a>;</li>
-<li><tt class="literal"><span class="pre">__new__</span></tt> returns an instance of that class.</li>
-<li>the instance is then initialized by the <tt class="literal"><span class="pre">__init__</span></tt> method.</li>
-</ol>
-<p>Notice that both <tt class="literal"><span class="pre">__new__</span></tt> and <tt class="literal"><span class="pre">__init__</span></tt> are called with the same
-argument list, therefore one must make sure that they have a compatible
-signature.</p>
-<p>Let me discuss now why <tt class="literal"><span class="pre">__new__</span></tt> must be a static method.
-First of all, it cannot be a normal method with a first argument which is an
-instance of the calling class, since at the time of <tt class="literal"><span class="pre">__new__</span></tt> invocation
-that instance (<tt class="literal"><span class="pre">myclock</span></tt> in the example) has still to be created
-Since <tt class="literal"><span class="pre">__new__</span></tt> needs information about the class calling it, one
-could think of implementing <tt class="literal"><span class="pre">__new__</span></tt> as a class method. However,
-this would implicitly pass the caller class and return an instance
-of it. It is more convenient, to have the ability of creating
-instances of any class directly from C.__new__(B,*args,**kw)</p>
-<p>For this reasons, <tt class="literal"><span class="pre">__new__</span></tt> must be a static method and pass explicitly
-the class which is calling it.</p>
-<p>Let me now show an important application of the <tt class="literal"><span class="pre">__new__</span></tt> static method:
-forbidding object creation. For instance, sometimes it is useful to have
-classes that cannot be instantiated. This kind of classes can be
-obtained by inheriting from a <tt class="literal"><span class="pre">NonInstantiable</span></tt> class:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class NonInstantiableError(Exception):
- pass
-
-class NonInstantiable(object):
- def __new__(cls,*args,**kw):
- raise NonInstantiableError(&quot;%s cannot be instantiated&quot; % cls)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here there is an example of usage:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import NonInstantiable,get_time
-&gt;&gt;&gt; class Clock(NonInstantiable):
-... get_time=staticmethod(get_time)
-&gt;&gt;&gt; Clock.get_time() # works
-'18:48:08'
-Clock() #error
-Traceback (most recent call last):
- File &quot;&lt;pyshell#6&gt;&quot;, line 1, in ?
- Clock()
- File &quot;oopp.py&quot;, line 257, in __new__
- raise NonInstantiableError(&quot;%s cannot be instantiated&quot; % cls)
-NonInstantiableError: &lt;class '__main__.Clock'&gt; cannot be instantiated
-</pre>
-</blockquote>
-<p>However, the approach pursued here has a disadvantage:<tt class="literal"><span class="pre">Clock</span></tt> was already
-defined as a subclass of <tt class="literal"><span class="pre">object</span></tt> and I has to change the source code
-to make it a subclass of 'NonInstantiable'. But what happens if
-I cannot change the sources? How can I <em>reuse</em> the old code?</p>
-<p>The solution is provided by multiple inheritance.</p>
-<p>Notice that '__new__' is a staticmethod: <a class="footnote-reference" href="#id29" id="id28" name="id28">[14]</a></p>
-<blockquote>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(NonInstantiable.__dict__['__new__'])
-&lt;type 'staticmethod'&gt;
-</pre>
-</blockquote>
-<table class="footnote" frame="void" id="id29" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id28" name="id29">[14]</a></td><td>This is how <tt class="literal"><span class="pre">type(s)</span></tt> or <tt class="literal"><span class="pre">s.__class__</span></tt> get to know that
-<tt class="literal"><span class="pre">s</span></tt> is an instance of <tt class="literal"><span class="pre">Str</span></tt>, since the class information is
-explicitely passed to the newborn object trough <tt class="literal"><span class="pre">__new__</span></tt>.</td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id30" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id31" name="id30">[15]</a></td><td><p>However <tt class="literal"><span class="pre">object.__dict__['__new__']</span></tt> is not a staticmethod</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(object.__dict__['__new__']) # special case
-&lt;type 'builtin_function_or_method'&gt;
-</pre>
-</td></tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-<div class="section" id="multiple-inheritance">
-<h2><a class="toc-backref" href="#id87" name="multiple-inheritance">Multiple Inheritance</a></h2>
-<p>Multiple Inheritance (often abbreviated as MI) is often
-considered one of the most advanced topic in Object Oriented Programming.
-It is also one of the most difficult features to implement
-in an Object Oriented Programming language. Even, some languages by design
-decided to avoid it. This is for instance the case of Java, that avoided
-MI having seen its implementation in C++ (which is not for the faint of
-heart ;-) and uses a poorest form of it trough interfaces.
-For what concerns the scripting languages, of which
-the most famous are Perl, Python and Ruby (in this order, even if
-the right order would be Python, Ruby and Perl), only Python
-implements Multiple Inheritance well (Ruby has a restricted form
-of it trough mix-ins, whereas Perl implementation is too difficult
-for me to understand what it does ;).</p>
-<p>The fact that Multiple Inheritance can be hairy, does not mean that it
-is <em>always</em> hairy, however. Multiple Inheritance is used with success
-in Lisp derived languages (including Dylan).</p>
-<p>The aims of this chapter is to discuss the
-Python support for MI in the most recent version (2.2 and 2.3), which
-has considerably improved with respect to previous versions.
-The message is the following: if Python 1.5 had a basic support for
-MI inheritance (basic but nevertheless with nice features, dynamic),
-Python 2.2 has <em>greatly</em> improved that support and with the
-change of the Method Resolution Order in Python 2.3, we may say
-that support for MI is now <em>excellent</em>.</p>
-<p>I strongly encourage Python programmers to use MI a lot: this will
-allows even a stronger reuse of code than in single inheritance.</p>
-<p>Often, inheritance is used when one has a complicate class B, and she wants
-to modify (or enhance) its behavior, by deriving a child class C, which is
-only slightly different from B. In this situation, B is already a standalone
-class, providing some non-trivial functionality, independently from
-the existence of C. This kind of design it typical of the so called
-<em>top-down</em> philosophy, where one builds the
-all structure as a monolithic block, leaving room only for minor improvements.
-An alternative approach is the so called <em>bottom-up</em> programming, in
-which one builds complicate things starting from very simple building blocks.
-In this logic, it is very appealing the idea of creating classes with the
-only purpose of being derived. The 'NonInstantiable' just defined is a
-perfect example of this kind of classes, though with multiple inheritance
-in mind and often called <em>mixin</em> classes.
-It can be used to create a new class <tt class="literal"><span class="pre">NonInstantiableClock</span></tt>
-that inherits from <tt class="literal"><span class="pre">Clock</span></tt> and from <tt class="literal"><span class="pre">NonInstantiable</span></tt>.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class NonInstantiableClock(Clock,NonInstantiable):
- pass
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Now <tt class="literal"><span class="pre">NonInstantiableClock</span></tt> is both a clock</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import NonInstantiableClock
-&gt;&gt;&gt; NonInstantiableClock.get_time() # works
-'12:57:00'
-</pre>
-</blockquote>
-<p>and a non-instantiable class:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; NonInstantiableClock() # as expected, give an error
-Traceback (most recent call last):
- File &quot;&lt;pyshell#2&gt;&quot;, line 1, in ?
- NonInstantiableClock() # error
- File &quot;oopp.py&quot;, line 245, in __new__
- raise NonInstantiableError(&quot;%s cannot be instantiated&quot; % cls)
-NonInstantiableError: &lt;class 'oopp.NonInstantiableClock'&gt;
-cannot be instantiated
-</pre>
-</blockquote>
-<p>Let me give a simple example of a situation where the mixin approach
-comes handy. Suppose that the owner of a 'Pizza-shop' needs a program to
-take care of all the pizzas to-go he sell. Pizzas are distinguished
-according to their size (small, medium or large) and their toppings.
-The problem can be solved by inheriting from a generic pizza factory
-like this:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class GenericPizza(object): # to be customized
- toppinglist=[] # nothing, default
- baseprice=1 # one dollar, default
- topping_unit_price=0.5 # half dollar for each topping, default
- sizefactor={'small':1, 'medium':2, 'large':3}
- # a medium size pizza costs twice a small pizza,
- # a large pizza costs three times
- def __init__(self,size):
- self.size=size
- def price(self):
- return (self.baseprice+
- self.toppings_price())*self.sizefactor[self.size]
- def toppings_price(self):
- return len(self.toppinglist)*self.topping_unit_price
- def __str__(self):
- return '%s pizza with %s, cost $ %s' % (self.size,
- ','.join(self.toppinglist),
- self.price())
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here the base class 'GenericPizza' is written with inheritance in mind: one
-can derives many pizza classes from it by overriding the <tt class="literal"><span class="pre">toppinglist</span></tt>;
-for instance one could define</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import GenericPizza
-&gt;&gt;&gt; class Margherita(GenericPizza):
-... toppinglist=['tomato']
-</pre>
-</blockquote>
-<p>The problem of this approach is that one must define dozens of
-different pizza subclasses (Marinara, Margherita, Capricciosa, QuattroStagioni,
-Prosciutto, ProsciuttoFunghi, PizzaDellaCasa, etc. etc. <a class="footnote-reference" href="#id30" id="id31" name="id31">[15]</a>). In such a
-situation, it is better to perform the generation of subclasses in a smarter
-way, i.e. via a customizable class factory.
-A simpler approach is to use always the same class and to customize
-its instances just after creation. Both approaches can be implemented via
-the following 'Customizable' mixin class, not meant to be instantiated,
-but rather to be <em>inherited</em>:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Customizable(object):
- &quot;&quot;&quot;Classes inhering from 'Customizable' have a 'with' method acting as
- an object modifier and 'With' classmethod acting as a class factory&quot;&quot;&quot;
- def with(self,**kw):
- customize(self,**kw)# customize the instance
- return self # returns the customized instance
- def With(cls,**kw):
- class ChildOf(cls): pass # a new class inheriting from cls
- ChildOf.__name__=cls.__name__ # by default, with the same name
- customize(ChildOf,**kw) # of the original class
- return ChildOf
- With=classmethod(With)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Descendants of 'Customizable' can be customized by using
-'with', that directly acts on the instances, or 'With', that returns
-new classes. Notice that one could make 'With' to customize the
-original class, without returning a new one; however, in practice,
-this would not be safe: I remind that changing a class modifies
-automatically all its instances, even instances created <em>before</em>
-the modification. This could produce bad surprises: it is better to
-returns new classes, that may have the same name of the original one,
-but are actually completely independent from it.</p>
-<p>In order to solve the pizza shop problem we may define a 'CustomizablePizza'
-class</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class CustomizablePizza(GenericPizza,Customizable):
- pass
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>which can be used in two ways: i) to customize instances just after creation:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import CustomizablePizza
-&gt;&gt;&gt; largepizza=CustomizablePizza('large') # CustomizablePizza instance
-&gt;&gt;&gt; largemarinara=largepizza.with(toppinglist=['tomato'],baseprice=2)
-&gt;&gt;&gt; print largemarinara
-large pizza with tomato mozzarella, cost $ 7.0
-</pre>
-</blockquote>
-<p>and ii) to generated customized new classes:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Margherita=CustomizablePizza.With(
-... toppinglist=['tomato','mozzarella'], __name__='Margherita')
-&gt;&gt;&gt; print Margherita('medium')
-medium pizza with tomato,mozzarella, cost $ 4.0
-</pre>
-</blockquote>
-<p>The advantage of the bottom-up approach, is that the 'Customizable' class
-can be reused in completely different problems; for instance, it could
-be used as a class factory. For instance we could use it to generate a
-'CustomizableClock' class as in this example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; CustomizableClock=Customizable.With(get_time=staticmethod(Clock.get_time),
-... __name__='CustomizableClock') #adds get_time
-&gt;&gt;&gt; CustomizableClock.get_time() # now it works
-'09:57:50'
-</pre>
-</blockquote>
-<p>Here 'Customizable' &quot;steal&quot; the 'get_time' method from 'Clock'.
-However that would be a rather perverse usage ;) I wrote it to show
-the advantage of classmethods, more than to suggest to the reader that
-this is an example of good programming.</p>
-<blockquote>
-<table class="footnote" frame="void" id="id32" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id33" name="id32">[16]</a></td><td>In Italy, you can easily find &quot;pizzerie&quot; with more than 50 different
-kinds of pizzas (once I saw a menu with something like one hundred
-different combinations ;)</td></tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-<div class="section" id="cooperative-hierarchies">
-<h2><a class="toc-backref" href="#id88" name="cooperative-hierarchies">Cooperative hierarchies</a></h2>
-<p>The examples of multiple inheritance hierarchies given until now were pretty
-easy. The reason is that there was no interaction between the methods of the
-children and of the parents. However, things get more complicated (and
-interesting ;) when the methods in the hierarchy call each other.
-Let me consider an example coming from paleoantropology:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;paleoanthropology1.py&gt;
-
-class HomoHabilis(object):
- def can(self):
- print self,'can:'
- print &quot; - make tools&quot;
-
-class HomoSapiens(HomoHabilis):
- def can(self): #overrides HomoHabilis.can
- HomoHabilis.can(self)
- print &quot; - make abstractions&quot;
-
-class HomoSapiensSapiens(HomoSapiens):
- def can(self): #overrides HomoSapiens.can
- HomoSapiens.can(self)
- print &quot; - make art&quot;
-
-modernman=HomoSapiensSapiens()
-modernman.can()
-
-#&lt;/paleoanthropology1.py&gt;
-</pre>
-</blockquote>
-<p>In this example children methods call parent methods:
-'HomoSapiensSapiens.can' calls 'HomoSapiens.can' that in turns calls
-'HomoHabilis.can' and the final output is:</p>
-<blockquote>
-<pre class="literal-block">
-&lt;__main__.HomoSapiensSapiens object at 0x814e1fc&gt; can:
- - make tools
- - make abstractions
- - make art
-</pre>
-</blockquote>
-<p>The script works, but it is far from ideal, if code reuse and refactoring
-are considered important requirements. The point is that (very likely, as the
-research in paleoanthropology progresses) we may want to extend the
-hierarchy, for instance by adding a class on the top or in the middle.
-In the present form, this would require a non-trivial modification of
-the source code (especially
-if one think that the hierarchy could be fleshed out with dozens of others
-methods and attributes). However, the aim of OOP is to avoid as
-much as possible source code modifications. This goal can be attained in
-practice, if the source code is written to be friendly to extensions and
-improvements as much as possible. I think it is worth to spend some time
-in improving this example, since what can be learn here,
-can be lifted to real life cases.</p>
-<p>First of all, let me define a generic <em>Homo</em> class, to be used
-as first ring of the inheritance chain (actually the first ring is
-'object'):</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Homo(PrettyPrinted):
- &quot;&quot;&quot;Defines the method 'can', which is intended to be overriden
- in the children classes, and inherits '__str__' from PrettyPrinted,
- ensuring a nice printing representation for all children.&quot;&quot;&quot;
- def can(self):
- print self,'can:'
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Now, let me point out one of the shortcomings of the previous code: in each
-subclass, we explicitly call its parent class (also called super class)
-by its name. This is inconvenient, both because a change of name in
-later stages of the project would require a lot of search and replace
-(actually not a lot in this toy example, but you can imagine having
-a very big projects with dozens of named method calls) and because it makes
-difficult to insert a new element in the inheritance hierarchy.
-The solution to this problems is the
-<tt class="literal"><span class="pre">super</span></tt> built-in, which provides an easy access to the methods
-of the superclass.
-<tt class="literal"><span class="pre">super</span></tt> objects comes in two flavors: <tt class="literal"><span class="pre">super(cls,obj)</span></tt> objects return
-bound methods whereas <tt class="literal"><span class="pre">super(cls)</span></tt> objects return unbound methods.
-In the next code we will use the first form. The hierarchy can more elegantly
-be rewritten as <a class="footnote-reference" href="#id32" id="id33" name="id33">[16]</a> :</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;paleo2.py&gt;
-
-from oopp import Homo
-
-class HomoHabilis(Homo):
- def can(self):
- super(HomoHabilis,self).can()
- print &quot; - make tools&quot;
-
-class HomoSapiens(HomoHabilis):
- def can(self):
- super(HomoSapiens,self).can()
- print &quot; - make abstractions&quot;
-
-class HomoSapiensSapiens(HomoSapiens):
- def can(self):
- super(HomoSapiensSapiens,self).can()
- print &quot; - make art&quot;
-
-
-HomoSapiensSapiens().can()
-
-#&lt;/paleo2.py&gt;
-</pre>
-</blockquote>
-<p>with output</p>
-<blockquote>
-<pre class="literal-block">
-&lt;HomoSapiensSapiens&gt; can:
- - make tools
- - make abstractions
- - make art
-</pre>
-</blockquote>
-<p>This is not yet the most elegant form, since even
-if <tt class="literal"><span class="pre">super</span></tt> avoids naming the base class explicitely, still it
-requires to explicitely name the class where it is defined. This is
-rather annoying.
-Removing that restriction, i.e. implementing really anonymous
-<tt class="literal"><span class="pre">super</span></tt> calls, is possible but requires a good understand of
-private variables in inheritance.</p>
-</div>
-<div class="section" id="inheritance-and-privacy">
-<h2><a class="toc-backref" href="#id89" name="inheritance-and-privacy">Inheritance and privacy</a></h2>
-<p>In order to define anonymous cooperative super calls, we need classes
-that know themselves, i.e. containing a reference to themselves. This
-is not an obvious problem as it could seems, since it cannot be solved
-without incurring in the biggest annoyance in inheritance:
-<em>name clashing</em>. Name clashing happens when names and attributes defined
-in different ancestors overrides each other in a unwanted order.
-Name clashing is especially painful in the case of cooperative
-hierarchies and particularly in in the problem at hand.</p>
-<p>A naive solution would be to attach a plain (i.e. non-private)
-attribute '.this' to the class, containing a reference
-to itself, that can be invoked by the methods of the class.
-Suppose, for instance, that I want to use that attribute in the <tt class="literal"><span class="pre">__init__</span></tt>
-method of that class. A naive attempt would be to write something like:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B(object):
-... def __init__(self):
-... print self.this,'.__init__' # .this defined later
-&gt;&gt;&gt; B.this=B # B.this can be set only after B has been created
-&gt;&gt;&gt; B()
-&lt;class '__main__.B'&gt;
-</pre>
-</blockquote>
-<p>Unfortunately, this approach does not work with cooperative hierarchies.
-Consider, for instance, extending 'B' with a cooperative children
-class 'C' as follows:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(B):
-... def __init__(self):
-... super(self.this,self).__init__() # cooperative call
-... print type(self).this,'.__init__'
-&gt;&gt;&gt; C.this=C
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">C.__init__</span></tt> calls <tt class="literal"><span class="pre">B.__init__</span></tt> by passing a 'C' instance, therefore
-<tt class="literal"><span class="pre">C.this</span></tt> is printed and not <tt class="literal"><span class="pre">B.this</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C()
-&lt;class '__main__.C'&gt; .__init__
-&lt;class '__main__.C'&gt; .__init__
-&lt;__main__.C object at 0x4042ca6c&gt;
-</pre>
-</blockquote>
-<p>The problem is that the <tt class="literal"><span class="pre">C.this</span></tt> overrides <tt class="literal"><span class="pre">B.this</span></tt>. The only
-way of avoiding the name clashing is to use a private attribute
-<tt class="literal"><span class="pre">.__this</span></tt>, as in the following script:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;privateh.py&gt;
-
-class B(object):
- def __init__(self):
- print self.__this,'.__init__'
-B._B__this=B
-
-class C(B):
- def __init__(self):
- super(self.__this,self).__init__() # cooperative __init__
- print self.__this,'.__init__'
-C._C__this=C
-
-C()
-
-# output:
-# &lt;class '__main__.B'&gt; .__init__
-# &lt;class '__main__.C'&gt; .__init__
-
-#&lt;/privateh.py&gt;
-</pre>
-</blockquote>
-<p>The script works since, due to the magic of the mangling mechanism,
-in <tt class="literal"><span class="pre">B.__init__</span></tt>, <tt class="literal"><span class="pre">self._B__this</span></tt> i.e. <tt class="literal"><span class="pre">B</span></tt> is retrieved, whereas in
-<tt class="literal"><span class="pre">C.__init__</span></tt> <tt class="literal"><span class="pre">self._C__this</span></tt> i.e. <tt class="literal"><span class="pre">C</span></tt> is retrieved.</p>
-<p>The elegance of the mechanism can be improved with an helper function
-that makes its arguments reflective classes, i.e. classes with a
-<tt class="literal"><span class="pre">__this</span></tt> private attribute:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def reflective(*classes):
- &quot;&quot;&quot;Reflective classes know themselves, i.e. they possess a private
- attribute __this containing a reference to themselves. If the class
- name starts with '_', the underscores are stripped.&quot;&quot;&quot;
- for c in classes:
- name=c.__name__ .lstrip('_') # in 2.3
- setattr(c,'_%s__this' % name,c)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>It is trivial to rewrite the paleonthropological hierarchy in terms of
-anonymous cooperative super calls by using this trick.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class HomoHabilis(Homo):
- def can(self):
- super(self.__this,self).can()
- print &quot; - make tools&quot;
-
-class HomoSapiens(HomoHabilis):
- def can(self):
- super(self.__this,self).can()
- print &quot; - make abstractions&quot;
-
-class HomoSapiensSapiens(HomoSapiens):
- def can(self):
- super(self.__this,self).can()
- print &quot; - make art&quot;
-
-reflective(HomoHabilis,HomoSapiens,HomoSapiensSapiens)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here there is an example of usage:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; man=HomoSapiensSapiens(); man.can()
-&lt;HomoSapiensSapiens&gt; can:
- - make tools
- - make abstractions
- - make art
-</pre>
-</blockquote>
-<p>We may understand why it works by looking at the attributes of man:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print pretty(attributes(man))
-_HomoHabilis__this = &lt;class 'oopp.HomoHabilis'&gt;
-_HomoSapiensSapiens__this = &lt;class 'oopp.HomoSapiensSapiens'&gt;
-_HomoSapiens__this = &lt;class 'oopp.HomoSapiens'&gt;
-can = &lt;bound method HomoSapiensSapiens.can of
- &lt;oopp.HomoSapiensSapiens object at 0x404292ec&gt;&gt;
-formatstring = %s
-</pre>
-</blockquote>
-<p>It is also interesting to notice that the hierarchy can be entirely
-rewritten without using cooperative methods, but using private attributes,
-instead. This second approach is simpler, as the following script shows:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;privatehierarchy.py&gt;
-
-from oopp import PrettyPrinted,attributes,pretty
-
-class Homo(PrettyPrinted):
- def can(self):
- print self,'can:'
- for attr,value in attributes(self).iteritems():
- if attr.endswith('__attr'): print value
-class HomoHabilis(Homo):
- __attr=&quot; - make tools&quot;
-class HomoSapiens(HomoHabilis):
- __attr=&quot; - make abstractions&quot;
-class HomoSapiensSapiens(HomoSapiens):
- __attr=&quot; - make art&quot;
-
-modernman=HomoSapiensSapiens()
-modernman.can()
-print '----------------------------------\nAttributes of',modernman
-print pretty(attributes(modernman))
-
-#&lt;/privatehierarchy.py&gt;
-</pre>
-</blockquote>
-<p>Here I have replaced the complicate chain of cooperative methods with
-much simpler private attributes. Only the 'can' method in the 'Homo'
-class survives, and it is modified to print the value of the '__attr'
-attributes. Moreover, all the classes of the hierarchy have been made
-'Customizable', in view of future extensions.</p>
-<p>The second script is much shorter and much more elegant than the original
-one, however its logic can be a little baffling, at first. The solution
-to the mistery is provided by the attribute dictionary of 'moderman',
-given by the second part of the output:</p>
-<blockquote>
-<pre class="literal-block">
-&lt;HomoSapiensSapiens&gt; can:
- - make abstractions
- - make art
- - make tools
-------------------------------------------
-Attributes of &lt;HomoSapiensSapiens&gt;:
-_HomoHabilis__attr = - make tools
-_HomoSapiensSapiens__attr = - make art
-_HomoSapiens__attr = - make abstractions
-can = &lt;bound method HomoSapiensSapiens.can of
- &lt;__main__.HomoSapiensSapiens object at 0x402d892c&gt;&gt;
-formatstring = %s
-</pre>
-</blockquote>
-<p>We see that, in addition to the 'can' method inherited from 'Homo',
-the 'with' and 'With' method inherited from 'Customizable' and
-the 'formatstring' inherited from 'PrettyPrinted',
-<tt class="literal"><span class="pre">moderman</span></tt> has the attributes</p>
-<blockquote>
-<pre class="literal-block">
-_HomoHabilis__attr:' - make tools' # inherited from HomoHabilis
-_HomoSapiens__attr:' - make abstractions'# inherited from HomoSapiens
-_HomoSapiensSapiens__attr: ' - make art' # inherited from HomoSapiensSapiens
-</pre>
-</blockquote>
-<p>which origin is obvious, once one reminds the mangling mechanism associated
-with private variables. The important point is that the trick would <em>not</em>
-have worked for normal attributes. Had I used as variable name
-'attr' instead of '__attr', the name would have been overridden: the only
-attribute of 'HomoSapiensSapiens' would have been ' - make art'.</p>
-<p>This example explains the advantages of private variables during inheritance:
-they cannot be overridden. Using private name guarantees the absence of
-surprises due to inheritance. If a class B has only private variables,
-deriving a class C from B cannot cause name clashes.</p>
-<p>Private variables have a drawbacks, too. The most obvious disadvantages is
-the fact that in order to customize private variables outside their
-defining class, one needs to pass explicitly the name of the class.</p>
-<p>For instance we could not change an attribute with the syntax
-<tt class="literal"><span class="pre">HomoHabilis.With(__attr='</span> <span class="pre">-</span> <span class="pre">work</span> <span class="pre">the</span> <span class="pre">stone')</span></tt>, we must write the
-more verbose, error prone and redundant
-<tt class="literal"><span class="pre">HomoHabilis.With(_HomoHabilis__attr='</span> <span class="pre">-</span> <span class="pre">work</span> <span class="pre">the</span> <span class="pre">stone')</span></tt></p>
-<p>A subtler drawback will be discussed in chapter 6.</p>
-<blockquote>
-<table class="footnote" frame="void" id="id34" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id35" name="id34">[17]</a></td><td>In single inheritance hierarchies, <tt class="literal"><span class="pre">super</span></tt> can be dismissed
-in favor of <tt class="literal"><span class="pre">__base__</span></tt>: for instance,
-<tt class="literal"><span class="pre">super(HomoSapiens,self).can()</span></tt> is equivalent to
-<tt class="literal"><span class="pre">HomoSapiens.__base__.can(self)</span></tt>. Nevertheless, in view
-of possible extensions to multiple inheritance, using <tt class="literal"><span class="pre">super</span></tt> is a
-much preferable choice.</td></tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-</div>
-<div class="section" id="the-sophistication-of-descriptors">
-<h1><a class="toc-backref" href="#id90" name="the-sophistication-of-descriptors">THE SOPHISTICATION OF DESCRIPTORS</a></h1>
-<p>Attribute descriptors are important metaprogramming tools that allows
-the user to customize the behavior of attributes in custom classes.
-For instance, attribute descriptors (or descriptors for short)
-can be used as method wrappers,
-to modify or enhance methods (this is the case for the well
-known staticmethods and classmethods attribute descriptors); they
-can also be used as attribute wrappers, to change or restrict the access to
-attributes (this is the case for properties). Finally, descriptors
-allows the user to play with the resolution order of attributes:
-for instance, the <tt class="literal"><span class="pre">super</span></tt> built-in object used in (multiple) inheritance
-hierarchies, is implemented as an attribute descriptor.</p>
-<p>In this chapter, I will show how the user can define its own attribute
-descriptors and I will give some example of useful things you can do with
-them (in particular to add tracing and timing capabilities).</p>
-<div class="section" id="motivation">
-<h2><a class="toc-backref" href="#id91" name="motivation">Motivation</a></h2>
-<p>Attribute descriptors are a recent idea (they where first introduced in
-Python 2.2) nevertheless, under the hood, are everywhere in Python. It is
-a tribute to Guido's ability of hiding Python complications that
-the average user can easily miss they existence.
-If you need to do simple things, you can very well live without
-the knowledge of descriptors. On the other hand, if you need difficult
-things (such as tracing all the attribute access of your modules)
-attribute descriptors, allow you to perform
-impressive things.
-Let me start by showing why the knowledge of attribute descriptors is
-essential for any user seriously interested in metaprogramming applications.
-Suppose I want to trace the methods of a clock:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import oopp
-&gt;&gt;&gt; clock=oopp.Clock()
-</pre>
-</blockquote>
-<p>This is easily done with the <tt class="literal"><span class="pre">with_tracer</span></tt> closure of chapter 2:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; oopp.wrapfunctions(clock,oopp.with_tracer)
-&lt;oopp.Clock object at 0x4044c54c&gt;
-&gt;&gt;&gt; clock.get_time()
-[] Calling 'get_time' with arguments
-(){} ...
--&gt; '.get_time' called with result: 19:55:07
-'19:55:07'
-</pre>
-</blockquote>
-<p>However, this approach fails if I try to trace the entire class:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; oopp.wrapfunctions(oopp.Clock,oopp.with_tracer)
-&lt;class 'oopp.Clock'&gt;
-&gt;&gt;&gt; oopp.Clock.get_time() # error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 6, in ?
-TypeError: unbound method _() must be called with Clock instance
-as first argument (got nothing instead)
-</pre>
-</blockquote>
-<p>The reason is that <tt class="literal"><span class="pre">wrapfunctions</span></tt> sets the attributes of 'Clock'
-by invoking <tt class="literal"><span class="pre">customize</span></tt>, which uses <tt class="literal"><span class="pre">setattr</span></tt>. This converts
-'_' (i.e. the traced version of <tt class="literal"><span class="pre">get_time</span></tt>) in a regular method, not in
-a staticmethod!
-In order to trace staticmethods, one has to understand the nature
-of attribute descriptors.</p>
-</div>
-<div class="section" id="functions-versus-methods">
-<h2><a class="toc-backref" href="#id92" name="functions-versus-methods">Functions versus methods</a></h2>
-<p>Attribute descriptors are essential for the implementation
-of one of the most basic Python features: the automatic conversion
-of functions in methods. As I already anticipated in chapter 1, there is
-a sort of magic when one writes <tt class="literal"><span class="pre">Clock.get_time=lambda</span> <span class="pre">self:</span> <span class="pre">get_time()</span></tt>
-and Python automagically converts the right hand side, that is a
-function, to a left hand side that is a (unbound) method. In order to
-understand this magic, one needs a better comprehension of the
-relation between functions and methods.
-Actually, this relationship is quite subtle
-and has no analogous in mainstream programming languages.
-For instance, C is not OOP and has only functions, lacking the concept
-of method, whereas Java (as other OOP languages)
-has no functions, only methods.
-C++ has functions and methods, but functions are completely
-different from methods On the other hand, in Python,
-functions and methods can be transformed both ways.</p>
-<p>To show how it works, let me start by defining a simple printing
-function:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import __main__ # gives access to the __main__ namespace from the module
-
-def prn(s):
- &quot;&quot;&quot;Given an evaluable string, print its value and its object reference.
- Notice that the evaluation is done in the __main__ dictionary.&quot;&quot;&quot;
- try: obj=eval(s,__main__.__dict__)
- except: print 'problems in evaluating',s
- else: print s,'=',obj,'at',hex(id(obj))
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Now, let me define a class with a method <tt class="literal"><span class="pre">m</span></tt> equals to the identity
-function <tt class="literal"><span class="pre">f</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(x): &quot;Identity function&quot;; return x
-...
-&gt;&gt;&gt; class C(object):
-... m=f
-... print m #here m is the function f
-&lt;function f at 0x401c2b1c&gt;
-</pre>
-</blockquote>
-<p>We see that <em>inside</em> its defining class, <tt class="literal"><span class="pre">m</span></tt> coincides with the function
-<tt class="literal"><span class="pre">f</span></tt> (the object reference is the same):</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; f
-&lt;function f at 0x401c2b1c&gt;
-</pre>
-</blockquote>
-<p>We may retrieve <tt class="literal"><span class="pre">m</span></tt> from <em>outside</em> the class via the class dictionary <a class="footnote-reference" href="#id34" id="id35" name="id35">[17]</a>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__dict__['m']
-&lt;function prn at 0x401c2b1c&gt;
-</pre>
-</blockquote>
-<p>However, if we invoke <tt class="literal"><span class="pre">m</span></tt> with
-the syntax <tt class="literal"><span class="pre">C.m</span></tt>, then it (magically) becomes a (unbound) method:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.m #here m has become a method!
-&lt;unbound method C.f&gt;
-</pre>
-</blockquote>
-<p>But why it is so? How comes that in the second syntax the function
-<tt class="literal"><span class="pre">f</span></tt> is transformed in a (unbound) method? To answer that question, we have
-to understand how attributes are really invoked in Python, i.e. via
-attribute descriptors.</p>
-</div>
-<div class="section" id="methods-versus-functions">
-<h2><a class="toc-backref" href="#id93" name="methods-versus-functions">Methods versus functions</a></h2>
-<p>First of all, let me point out the differences between methods and
-functions. Here, <tt class="literal"><span class="pre">C.m</span></tt> does <em>not</em> coincides with <tt class="literal"><span class="pre">C.__dict__['m']</span></tt>
-i.e. <tt class="literal"><span class="pre">f</span></tt>, since its object reference is different:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import prn,attributes
-&gt;&gt;&gt; prn('C.m')
-C.m = &lt;unbound method C.prn&gt; at 0x81109b4
-</pre>
-</blockquote>
-<p>The difference is clear since methods and functions have different attributes:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; attributes(f).keys()
-['func_closure', 'func_dict', 'func_defaults', 'func_name',
-'func_code', 'func_doc', 'func_globals']
-</pre>
-</blockquote>
-<p>whereas</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; attributes(C.m).keys()
-['im_func', 'im_class', 'im_self']
-</pre>
-</blockquote>
-<p>We discussed few of the functions attributes in the chapter
-on functions. The instance method attributes are simpler: <tt class="literal"><span class="pre">im_self</span></tt>
-returns the object to which the method is attached,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print C.m.im_self #unbound method, attached to the class
-None
-&gt;&gt;&gt; C().m.im_self #bound method, attached to C()
-&lt;__main__.C object at 0x81bf4ec&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">im_class</span></tt> returns the class to which the
-method is attached</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.m.im_class #class of the unbound method
-&lt;class '__main__.C'&gt;
-&gt;&gt;&gt; C().m.im_class #class of the bound method,
-&lt;class '__main__.C'&gt;
-</pre>
-</blockquote>
-<p>and <tt class="literal"><span class="pre">im_func</span></tt> returns the function equivalent to
-the method.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.m.im_func
-&lt;function m at 0x8157f44&gt;
-&gt;&gt;&gt; C().m.im_func # the same
-&lt;function m at 0x8157f44&gt;
-</pre>
-</blockquote>
-<p>As the reference manual states, calling
-<tt class="literal"><span class="pre">m(*args,**kw)</span></tt> is completely equivalent to calling
-<tt class="literal"><span class="pre">m.im_func(m.im_self,</span> <span class="pre">*args,**kw)</span></tt>&quot;.</p>
-<p>As a general rule, an attribute descriptor is an object with a <tt class="literal"><span class="pre">__get__</span></tt>
-special method. The most used descriptors are the good old functions:
-they have a <tt class="literal"><span class="pre">__get__</span></tt> special method returning a <em>method-wrapper object</em></p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; f.__get__
-&lt;method-wrapper object at 0x815cdc4&gt;
-</pre>
-</blockquote>
-<p>method-wrapper objects can be transformed in (both bound and unbound) methods:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; f.__get__(None,C)
-&lt;unbound method C.f&gt;
-&gt;&gt;&gt; f.__get__(C(),C)
-&lt;bound method C.f of &lt;__main__.C object at 0x815cdc4&gt;&gt;
-</pre>
-</blockquote>
-<p>The general calling syntax for method-wrapper objects is
-<tt class="literal"><span class="pre">.__get__(obj,cls=None)</span></tt>, where the first argument is an
-instance object or None and the second (optional) argument is the class (or a
-generic superclass) of the first one.</p>
-<p>Now we see what happens when we use the syntax <tt class="literal"><span class="pre">C.m</span></tt>: Python interprets
-this as a shortcut for <tt class="literal"><span class="pre">C.__dict['m'].__get__(None,C)</span></tt> (if <tt class="literal"><span class="pre">m</span></tt> is
-in the 'C' dictionary, otherwise it looks for ancestor dictionaries).
-We may check that everything is correct by observing that
-<tt class="literal"><span class="pre">f.__get__(None,C)</span></tt> has exactly the same object reference than <tt class="literal"><span class="pre">C.m</span></tt>,
-therefore they are the same object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; hex(id(f.__get__(None,C))) # same as hex(id(C.m))
-'0x811095c'
-</pre>
-</blockquote>
-<p>The process works equally well for the syntax <tt class="literal"><span class="pre">getattr</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print getattr(C,'m'), hex(id(getattr(C,'m')))
-&lt;unbound method C.f&gt; 0x811095c
-</pre>
-</blockquote>
-<p>and for bound methods: if</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c=C()
-</pre>
-</blockquote>
-<p>is an instance of the class C, then the syntax</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; getattr(c,'m') #same as c.m
-&lt;bound method C.f of &lt;__main__.C object at 0x815cdc4&gt;&gt;
-</pre>
-</blockquote>
-<p>is a shortcut for</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(c).__dict__['m'].__get__(c,C) # or f.__get__(c,C)
-&lt;bound method C.f of &lt;__main__.C object at 0x815cdc4&gt;&gt;
-</pre>
-</blockquote>
-<p>(notice that the object reference for <tt class="literal"><span class="pre">c.m</span></tt> and <tt class="literal"><span class="pre">f.__get__(c,C)</span></tt> is
-the same, they are <em>exactly</em> the same object).</p>
-<p>Both the unbound method C.m and the bound method c.m refer to the same
-object at hexadecimal address 0x811095c. This object is common to all other
-instances of C:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c2=C()
-&gt;&gt;&gt; print c2.m,hex(id(c2.m)) #always the same method
-&lt;bound method C.m of &lt;__main__.C object at 0x815768c&gt;&gt; 0x811095c
-</pre>
-</blockquote>
-<p>One can also omit the second argument:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.m.__get__(c)
-&lt;bound method ?.m of &lt;__main__.C object at 0x81597dc&gt;&gt;
-</pre>
-</blockquote>
-<p>Finally, let me point out that methods are attribute descriptors too,
-since they have a <tt class="literal"><span class="pre">__get__</span></tt> attribute returning a method-wrapper
-object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.m.__get__
-&lt;method-wrapper object at 0x815d51c&gt;
-</pre>
-</blockquote>
-<p>Notice that this method wrapper is <em>not</em> the same than the <tt class="literal"><span class="pre">f.__get__</span></tt>
-method wrapper.</p>
-<blockquote>
-<table class="footnote" frame="void" id="id36" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id37" name="id36">[18]</a></td><td>If <tt class="literal"><span class="pre">C.__dict['m']</span></tt> is not defined, Python looks if <tt class="literal"><span class="pre">m</span></tt> is defined
-in some ancestor of C. For instance if <cite>B</cite> is the base of <cite>C</cite>, it
-looks in <tt class="literal"><span class="pre">B.__dict['m']</span></tt>, etc., by following the MRO.</td></tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-<div class="section" id="static-methods-and-class-methods">
-<h2><a class="toc-backref" href="#id94" name="static-methods-and-class-methods">Static methods and class methods</a></h2>
-<p>Whereas functions and methods are implicit attribute descriptors,
-static methods and class methods are examples of explicit
-descriptors. They allow to convert regular functions to
-specific descriptor objects. Let me show a trivial example.
-Given the identity function</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(x): return x
-</pre>
-</blockquote>
-<p>we may convert it to a staticmethod object</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; sm=staticmethod(f)
-&gt;&gt;&gt; sm
-&lt;staticmethod object at 0x4018a0a0&gt;
-</pre>
-</blockquote>
-<p>or to a classmethod object</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm=classmethod(f)
-&gt;&gt;&gt; cm
-&lt;classmethod object at 0x4018a0b0&gt;
-</pre>
-</blockquote>
-<p>In both cases the <tt class="literal"><span class="pre">__get__</span></tt> special method returns a method-wrapper object</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; sm.__get__
-&lt;method-wrapper object at 0x401751ec&gt;
-&gt;&gt;&gt; cm.__get__
-&lt;method-wrapper object at 0x4017524c&gt;
-</pre>
-</blockquote>
-<p>However the static method wrapper is quite different from the class
-method wrapper. In the first case the wrapper returns a function:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; sm.__get__(C(),C)
-&lt;function f at 0x4027a8b4&gt;
-&gt;&gt;&gt; sm.__get__(C())
-&lt;function f at 0x4027a8b4&gt;
-</pre>
-</blockquote>
-<p>in the second case it returns a method</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm.__get__(C(),C)
-&lt;bound method type.f of &lt;class '__main__.C'&gt;&gt;
-</pre>
-</blockquote>
-<p>Let me discuss more in detail the static methods, first.</p>
-<p>It is always possible to extract the function from the static method
-via the syntaxes <tt class="literal"><span class="pre">sm.__get__(a)</span></tt> and <tt class="literal"><span class="pre">sm.__get__(a,b)</span></tt> with <em>ANY</em> valid
-a and b, i.e. the result does not depend on a and b. This is correct,
-since static methods are actually function that have nothing to do
-with the class and the instances to which they are bound.</p>
-<p>This behaviour of the method wrapper makes clear why the relation between
-methods and functions is inversed for static methods with respect to
-regular methods:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... s=staticmethod(lambda : None)
-... print s
-...
-&lt;staticmethod object at 0x8158ec8&gt;
-</pre>
-</blockquote>
-<p>Static methods are non-trivial objects <em>inside</em> the class, whereas
-they are regular functions <em>outside</em> the class:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.s
-&lt;function &lt;lambda&gt; at 0x8158e7c&gt;
-&gt;&gt;&gt; C().s
-&lt;function &lt;lambda&gt; at 0x8158e7c&gt;
-</pre>
-</blockquote>
-<p>The situation is different for classmethods: inside the class they
-are non-trivial objects, just as static methods,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... cm=classmethod(lambda cls: None)
-... print cm
-...
-&lt;classmethod object at 0x8156100&gt;
-</pre>
-</blockquote>
-<p>but outside the class they are methods bound to the class,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c=C()
-&gt;&gt;&gt; prn('c.cm')
-&lt;bound method type.&lt;lambda&gt; of &lt;class '__main__.C'&gt;&gt;
-0x811095c
-</pre>
-</blockquote>
-<p>and not to the instance 'c'. The reason is that the <tt class="literal"><span class="pre">__get__</span></tt> wrapper method
-can be invoked with the syntax <tt class="literal"><span class="pre">__get__(a,cls)</span></tt> which
-is only sensitive to the second argument or with the syntax
-<tt class="literal"><span class="pre">__get__(obj)</span></tt> which is only sensitive to the type of the first
-argument:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm.__get__('whatever',C) # the first argument is ignored
-&lt;bound method type.f of &lt;class '__main__.C'&gt;&gt;
-</pre>
-</blockquote>
-<p>sensitive to the type of 'whatever':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm.__get__('whatever') # in Python 2.2 would give a serious error
-&lt;bound method type.f of &lt;type 'str'&gt;&gt;
-</pre>
-</blockquote>
-<p>Notice that the class method is actually bound to C's class, i.e.
-to 'type'.</p>
-<p>Just as regular methods (and differently
-from static methods) classmethods have attributes <tt class="literal"><span class="pre">im_class</span></tt>, <tt class="literal"><span class="pre">im_func</span></tt>,
-and <tt class="literal"><span class="pre">im_self</span></tt>. In particular one can retrieve the function wrapped inside
-the classmethod with</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm.__get__('whatever','whatever').im_func
-&lt;function f at 0x402c2534&gt;
-</pre>
-</blockquote>
-<p>The difference with regular methods is that <tt class="literal"><span class="pre">im_class</span></tt> returns the
-class of 'C' whereas <tt class="literal"><span class="pre">im_self</span></tt> returns 'C' itself.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.cm.im_self # a classmethod is attached to the class
-&lt;class '__main__.C'&gt;
-&gt;&gt;&gt; C.cm.im_class #the class of C
-&lt;type 'type'&gt;
-</pre>
-</blockquote>
-<p>Remark: Python 2.2.0 has a bug in classmethods (fixed in newer versions):
-when the first argument of __get__ is None, then one must specify
-the second argument (otherwise segmentation fault :-()</p>
-</div>
-<div class="section" id="properties">
-<h2><a class="toc-backref" href="#id95" name="properties">Properties</a></h2>
-<p>Properties are a more general kind of attribute descriptors than
-staticmethods and classmethods, since their effect can be customized
-trough arbitrary get/set/del functions. Let me give an example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def getp(self): return 'property' # get function
-...
-&gt;&gt;&gt; p=property(getp) # property object
-&gt;&gt;&gt; p
-&lt;property object at 0x815855c&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">p</span></tt> has a <tt class="literal"><span class="pre">__get__</span></tt> special method returning a method-wrapper
-object, just as it happens for other descriptors:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; p.__get__
-&lt;method-wrapper object at 0x8158a7c&gt;
-</pre>
-</blockquote>
-<p>The difference is that</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; p.__get__(None,type(p))
-&lt;property object at 0x4017016c&gt;
-&gt;&gt;&gt; p.__get__('whatever')
-'property'
-&gt;&gt;&gt; p.__get__('whatever','whatever')
-'property'
-</pre>
-</blockquote>
-<p>As for static methods, the <tt class="literal"><span class="pre">__get__</span></tt> method wrapper is independent from
-its arguments, unless the first one is None: in such a case it returns
-the property object, in all other circumstances it returns the result
-of <tt class="literal"><span class="pre">getp</span></tt>. This explains the behavior</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object): p=p
-&gt;&gt;&gt; C.p
-&lt;property object at 0x815855c&gt;
-&gt;&gt;&gt; C().p
-'property'
-</pre>
-</blockquote>
-<p>Properties are a dangerous feature, since they change the semantics
-of the language. This means that apparently trivial operations can have
-any kind of side effects:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def get(self):return 'You gave me the order to destroy your hard disk!!'
-&gt;&gt;&gt; class C(object): x=property(get)
-&gt;&gt;&gt; C().x
-'You gave me the order to destroy your hard disk!!'
-</pre>
-</blockquote>
-<p>Invoking 'C.x' could very well invoke an external program who is going
-to do anything! It is up to the programmer to not abuse properties.
-The same is true for user defined attribute descriptors.</p>
-<p>There are situations in which they are quite handy, however. For
-instance, properties can be used to trace the access data attributes.
-This can be especially useful during debugging, or for logging
-purposes.</p>
-<p>Notice that this approach has the problem that now data attributes cannot
-no more be called trough their class, but only though their instances.
-Moreover properties do not work well with <tt class="literal"><span class="pre">super</span></tt> in cooperative
-methods.</p>
-</div>
-<div class="section" id="user-defined-attribute-descriptors">
-<h2><a class="toc-backref" href="#id96" name="user-defined-attribute-descriptors">User-defined attribute descriptors</a></h2>
-<p>As we have seen, there are plenty of predefined attribute descriptors,
-such as staticmethods, classmethods and properties (the built-in
-<tt class="literal"><span class="pre">super</span></tt> is also an attribute descriptor which, for sake of
-convenience, will be discussed in the next section).
-In addition to them, the user can also define customized attribute
-descriptors, simply trough classes with a <tt class="literal"><span class="pre">__get__</span></tt> special method.
-Let me give an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;simpledescr.py&gt;
-
-class ChattyAttr(object):
- &quot;&quot;&quot;Chatty descriptor class; descriptor objects are intended to be
- used as attributes in other classes&quot;&quot;&quot;
- def __get__(self, obj, cls=None):
- binding=obj is not None
- if binding:
- return 'You are binding %s to %s' % (self,obj)
- else:
- return 'Calling %s from %s' % (self,cls)
-
-class C(object):
- d=ChattyAttr()
-
-c=C()
-
-print c.d # &lt;=&gt; type(c).__dict__['d'].__get__(c,type(c))
-print C.d # &lt;=&gt; C.__dict__['d'].__get__(None,C)
-
-#&lt;/simpledescr.py&gt;
-</pre>
-</blockquote>
-<p>with output:</p>
-<blockquote>
-<pre class="literal-block">
-You are binding &lt;ChattyAttr object at 0x401bc1cc&gt; to
-&lt;C object at 0x401bc2ec&gt;
-Calling &lt;ChattyAttr object at 0x401bc1cc&gt; from &lt;class 'C'&gt;
-</pre>
-</blockquote>
-<p>Invoking a method with the syntax <tt class="literal"><span class="pre">C.d</span></tt> or <tt class="literal"><span class="pre">c.d</span></tt> involves calling
-<tt class="literal"><span class="pre">__get__</span></tt>. The <tt class="literal"><span class="pre">__get__</span></tt> signature is fixed: it is
-`` __get__=__get__(self,obj,cls=None)``, since the notation
-<tt class="literal"><span class="pre">self.descr_attr</span></tt> automatically passes <tt class="literal"><span class="pre">self</span></tt> and <tt class="literal"><span class="pre">self.__class__</span></tt> to
-<tt class="literal"><span class="pre">__get__</span></tt>.</p>
-<p>Custom descriptors can be used to restrict the access to objects in a
-more general way than trough properties. For instance, suppose one
-wants to raise an error if a given attribute 'a' is accessed, both
-from the class and from the instance: a property cannot help here,
-since it works only from the instance. The solution is the following
-custom descriptor:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class AccessError(object):
- &quot;&quot;&quot;Descriptor raising an AttributeError when the attribute is
- accessed&quot;&quot;&quot; #could be done with a property
- def __init__(self,errormessage):
- self.msg=errormessage
- def __get__(self,obj,cls=None):
- raise AttributeError(self.msg)
-
-#&lt;/oopp.py&gt;
-
-&gt;&gt;&gt; from oopp import AccessError
-&gt;&gt;&gt; class C(object):
-... a=AccessError(&quot;'a' cannot be accessed&quot;)
-&gt;&gt;&gt; c=C()
-&gt;&gt;&gt; c.a #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
- File &quot;oopp.py&quot;, line 313, in __get__
- raise AttributeError(self.msg)
-AttributeError: 'a' cannot be accessed
-&gt;&gt;&gt; C.a #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
- File &quot;oopp.py&quot;, line 313, in __get__
- raise AttributeError(self.msg)
-AttributeError: 'a' cannot be accessed
-</pre>
-</blockquote>
-<p>It is always possibile to convert plain attributes (i.e. attributes
-without a &quot;__get__&quot; method) to descriptor objects:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class convert2descriptor(object):
- &quot;&quot;&quot;To all practical means, this class acts as a function that, given an
- object, adds to it a __get__ method if it is not already there. The
- added __get__ method is trivial and simply returns the original object,
- independently from obj and cls.&quot;&quot;&quot;
- def __new__(cls,a):
- if hasattr(a,&quot;__get__&quot;): # do nothing
- return a # a is already a descriptor
- else: # creates a trivial attribute descriptor
- cls.a=a
- return object.__new__(cls)
- def __get__(self,obj,cls=None):
- &quot;Returns self.a independently from obj and cls&quot;
- return self.a
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>This example also shows the magic of <tt class="literal"><span class="pre">__new__</span></tt>, that allows to use a
-class as a function. The output of 'convert2descriptor(a)' can be both
-an instance of 'convert2descriptor' (in this case 'convert2descriptor' acts as
-a normal class, i.e. as an object factory) or 'a' itself
-(if 'a' is already a descriptor): in this case 'convert2descriptor' acts
-as a function.</p>
-<p>For instance, a string is converted to a descriptor</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import convert2descriptor
-&gt;&gt;&gt; a2=convert2descriptor('a')
-&gt;&gt;&gt; a2
-&lt;oopp.convert2descriptor object at 0x4017506c&gt;
-&gt;&gt;&gt; a2.__get__('whatever')
-'a'
-</pre>
-</blockquote>
-<p>whereas a function is untouched:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(): pass
-&gt;&gt;&gt; f2=convert2descriptor(f) # does nothing
-&gt;&gt;&gt; f2
-&lt;function f at 0x4019110c&gt;
-</pre>
-</blockquote>
-</div>
-<div class="section" id="data-descriptors">
-<h2><a class="toc-backref" href="#id97" name="data-descriptors">Data descriptors</a></h2>
-<p>It is also possible to specify a <tt class="literal"><span class="pre">__set__</span></tt> method (descriptors
-with a <tt class="literal"><span class="pre">__set__</span></tt> method are typically data descriptors) with
-the signature <tt class="literal"><span class="pre">__set__(self,obj,value)</span></tt> as in the following
-example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;datadescr.py&gt;
-
-class DataDescriptor(object):
- value=None
- def __get__(self, obj, cls=None):
- if obj is None: obj=cls
- print &quot;Getting&quot;,obj,&quot;value =&quot;,self.value
- return self.value
- def __set__(self, obj, value):
- self.value=value
- print &quot;Setting&quot;,obj,&quot;value =&quot;,value
-
-class C(object):
- d=DataDescriptor()
-
-c=C()
-
-c.d=1 #calls C.__dict__['d'].__set__(c,1)
-c.d #calls C.__dict__['d'].__get__(c,C)
-C.d #calls C.__dict__['d'].__get__(None,C)
-C.d=0 #does *not* call __set__
-print &quot;C.d =&quot;,C.d
-
-#&lt;/datadescr.py&gt;
-</pre>
-</blockquote>
-<p>With output:</p>
-<blockquote>
-<pre class="literal-block">
-Setting &lt;C object at 0x401bc1ec&gt; value = 1
-Getting &lt;C object at 0x401bc42c&gt; value = 1
-Getting &lt;class 'C'&gt; value = 1
-C.d = 0
-</pre>
-</blockquote>
-<p>With this knowledge, we may now reconsider the clock example given
-in chapter 3. #NO!??</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import oopp
-&gt;&gt;&gt; class Clock(object): pass
-&gt;&gt;&gt; myclock=Clock()
-...
-&gt;&gt;&gt; myclock.get_time=oopp.get_time # this is a function
-&gt;&gt;&gt; Clock.get_time=lambda self : oopp.get_time() # this is a method
-</pre>
-</blockquote>
-<p>In this example, <tt class="literal"><span class="pre">myclock.get_time</span></tt>, which is attached to the <tt class="literal"><span class="pre">myclock</span></tt>
-object, is a function, whereas <tt class="literal"><span class="pre">Clock.get_time</span></tt>, which is attached to
-the <tt class="literal"><span class="pre">Clock</span></tt> class is a method. We may also check this by using the <tt class="literal"><span class="pre">type</span></tt>
-function:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(myclock.get_time)
-&lt;type 'function'&gt;
-</pre>
-</blockquote>
-<p>whereas</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(Clock.get_time)
-&lt;type 'instance method'&gt;
-</pre>
-</blockquote>
-<p>It must be remarked that user-defined attribute descriptors, just as
-properties, allow to arbitrarily change the semantics of the language
-and should be used with care.</p>
-</div>
-<div class="section" id="the-super-attribute-descriptor">
-<h2><a class="toc-backref" href="#id98" name="the-super-attribute-descriptor">The <tt class="literal"><span class="pre">super</span></tt> attribute descriptor</a></h2>
-<p>super has also a second form, where it is more used as a descriptor.</p>
-<p><tt class="literal"><span class="pre">super</span></tt> objects are attribute descriptors, too, with a <tt class="literal"><span class="pre">__get__</span></tt>
-method returning a method-wrapper object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,C()).__get__
-&lt;method-wrapper object at 0x8161074&gt;
-</pre>
-</blockquote>
-<p>Here I give some example of acceptable call:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,C()).__get__('whatever')
-&lt;super: &lt;class 'C'&gt;, &lt;C object&gt;&gt;
-&gt;&gt;&gt; super(C,C()).__get__('whatever','whatever')
-&lt;super: &lt;class 'C'&gt;, &lt;C object&gt;&gt;
-</pre>
-</blockquote>
-<p>Unfortunately, for the time being
-(i.e. for Python 2.3), the <tt class="literal"><span class="pre">super</span></tt> mechanism has various limitations.
-To show the issues, let me start by considering the following base class:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class ExampleBaseClass(PrettyPrinted):
- &quot;&quot;&quot;Contains a regular method 'm', a staticmethod 's', a classmethod
- 'c', a property 'p' and a data attribute 'd'.&quot;&quot;&quot;
- m=lambda self: 'regular method of %s' % self
- s=staticmethod(lambda : 'staticmethod')
- c=classmethod(lambda cls: 'classmethod of %s' % cls)
- p=property(lambda self: 'property of %s' % self)
- a=AccessError('Expected error')
- d='data'
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Now, let me derive a new class C from ExampleBaseClass:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import ExampleBaseClass
-&gt;&gt;&gt; class C(ExampleBaseClass): pass
-&gt;&gt;&gt; c=C()
-</pre>
-</blockquote>
-<p>Ideally, we would like to retrieve the methods and attributes of
-ExampleBaseClass from C, by using the <tt class="literal"><span class="pre">super</span></tt> mechanism.</p>
-<ol class="arabic simple">
-<li>We see that <tt class="literal"><span class="pre">super</span></tt> works without problems for regular methods,
-staticmethods and classmethods:</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,c).m()
-'regular method of &lt;C&gt;'
-&gt;&gt;&gt; super(C,c).s()
-'staticmethod'
-&gt;&gt;&gt; super(C,c).c()
-&quot;classmethod of &lt;class '__main__.C'&gt;&quot;
-</pre>
-</blockquote>
-<p>It also works for user defined attribute descriptors:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,c).a # access error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
- File &quot;oopp.py&quot;, line 340, in __get__
- raise AttributeError(self.msg)
-AttributeError: Expected error
-</pre>
-</blockquote>
-<p>and for properties (only for Python 2.3+):</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; ExampleBaseClass.p
-&lt;property object at 0x81b30fc&gt;
-</pre>
-</blockquote>
-<p>In Python 2.2 one would get an error, instead</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,c).p #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'super' object has no attribute 'p'
-</pre>
-</blockquote>
-<p>3. Moreover, certain attributes of the superclass, such as its
-<tt class="literal"><span class="pre">__name__</span></tt>, cannot be retrieved:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; ExampleBaseClass.__name__
-'ExampleBaseClass'
-&gt;&gt;&gt; super(C,c).__name__ #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'super' object has no attribute '__name__'
-</pre>
-</blockquote>
-<ol class="arabic simple" start="4">
-<li>There is no direct way to retrieve the methods of the super-superclass
-(i.e. the grandmother class, if you wish) or in general the furthest
-ancestors, since <tt class="literal"><span class="pre">super</span></tt> does not chain.</li>
-<li>Finally, there are some subtle issues with the <tt class="literal"><span class="pre">super(cls)</span></tt> syntax:</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C).m #(2) error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'super' object has no attribute 'm'
-</pre>
-</blockquote>
-<p>means <tt class="literal"><span class="pre">super(C).__get__(None,C)</span></tt>, but only
-<tt class="literal"><span class="pre">super(C).__get__(c,C).m==super(C,c)</span></tt> works.</p>
-<blockquote>
-<blockquote>
-On the other hand,</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C).__init__ #(1)
-&lt;built-in method __init__ of type object at 0x80e6fc0&gt;
-&gt;&gt;&gt; super(C).__new__ #(1)
-&lt;built-in method __init__ of type object at 0x80e6fc0&gt;
-</pre>
-<blockquote>
-seems to work, whereas in reality does not. The reason is that since
-<tt class="literal"><span class="pre">super</span></tt> objects are instances
-of <tt class="literal"><span class="pre">object</span></tt>, they inherit object's methods, and in particular
-<tt class="literal"><span class="pre">__init__</span></tt> ; therefore the <tt class="literal"><span class="pre">__init__</span></tt> method in (1) is <em>not</em>
-the <tt class="literal"><span class="pre">ExampleBaseClass.__init__</span></tt> method. The point is that <tt class="literal"><span class="pre">super</span></tt>
-objects are attribute descriptors and not references to the superclass.</blockquote>
-</blockquote>
-<p>Probably, in future versions of Python the <tt class="literal"><span class="pre">super</span></tt> mechanism will be
-improved. However, for the time being, one must provide a workaround for
-dealing with these issues. This will be discussed in the next chapter.</p>
-</div>
-<div class="section" id="method-wrappers">
-<h2><a class="toc-backref" href="#id99" name="method-wrappers">Method wrappers</a></h2>
-<p>One of the most typical applications of attribute descriptors is their
-usage as <em>method wrappers</em>.</p>
-<p>Suppose, for instance, one wants to add tracing capabilities to
-the methods of a class for debugging purposes. The problem
-can be solved with a custom descriptor class:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import inspect
-
-class wrappedmethod(Customizable):
- &quot;&quot;&quot;Customizable method factory intended for derivation.
- The wrapper method is overridden in the children.&quot;&quot;&quot;
-
- logfile=sys.stdout # default
- namespace='' # default
-
- def __new__(cls,meth): # meth is a descriptor
- if isinstance(meth,FunctionType):
- kind=0 # regular method
- func=meth
- elif isinstance(meth,staticmethod):
- kind=1 # static method
- func=meth.__get__('whatever')
- elif isinstance(meth,classmethod):
- kind=2 # class method
- func=meth.__get__('whatever','whatever').im_func
- elif isinstance(meth,wrappedmethod): # already wrapped
- return meth # do nothing
- elif inspect.ismethoddescriptor(meth):
- kind=0; func=meth # for many builtin methods
- else:
- return meth # do nothing
- self=super(wrappedmethod,cls).__new__(cls)
- self.kind=kind; self.func=func # pre-initialize
- return self
-
- def __init__(self,meth): # meth not used
- self.logfile=self.logfile # default values
- self.namespace=self.namespace # copy the current
-
- def __get__(self,obj,cls): # closure
- def _(*args,**kw):
- if obj is None: o=() # unbound method call
- else: o=(obj,) # bound method call
- allargs=[o,(),(cls,)][self.kind]+args
- return self.wrapper()(*allargs,**kw)
- return _ # the wrapped function
- # allargs is the only nontrivial line in _; it adds
- # 0 - obj if meth is a regular method
- # 1 - nothing if meth is a static method
- # 2 - cls if meth is a class method
-
- def wrapper(self): return self.func # do nothing, to be overridden
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>This class is intended for derivation: the wrapper method has to be overridden
-in the children in order to introduce the wanted feature. If I want to
-implement the capability of tracing methods, I can reuse the <tt class="literal"><span class="pre">with_tracer</span></tt>
-closure introduced in chapter 2:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class tracedmethod(wrappedmethod):
- def wrapper(self):
- return with_tracer(self.func,self.namespace,self.logfile)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Nothing prevents me from introducing timing features by reusing the
-<tt class="literal"><span class="pre">with_timer</span></tt> closure:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class timedmethod(wrappedmethod):
- iterations=1 # additional default parameter
-
- def __init__(self,meth):
- super(timedmethod,self).__init__(self,meth)
- self.iterations=self.iterations # copy
-
- def wrapper(self):
- return with_timer(self.func,self.namespace,
- self.iterations,self.logfile)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here there is an example of usage:</p>
-<p>The dictionary of wrapped functions is then built from an utility function</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def wrap(obj,wrapped,condition=lambda k,v: True, err=None):
- &quot;Retrieves obj's dictionary and wraps it&quot;
- if isinstance(obj,dict): # obj is a dictionary
- dic=obj
- else:
- dic=getattr(obj,'__dict__',{}).copy() # avoids dictproxy objects
- if not dic: dic=attributes(obj) # for simple objects
- wrapped.namespace=getattr(obj,'__name__','')
- for name,attr in dic.iteritems(): # modify dic
- if condition(name,attr): dic[name]=wrapped(attr)
- if not isinstance(obj,dict): # modify obj
- customize(obj,err,**dic)
-
-#&lt;/oopp.py&gt;
-</pre>
-<pre class="literal-block">
-#&lt;tracingmethods.py&gt;
-
-from oopp import *
-
-class C(object):
- &quot;Class with traced methods&quot;
-
- def f(self): return self
- f=tracedmethod(f)
-
- g=staticmethod(lambda:None)
- g=tracedmethod(g)
-
- h=classmethod(do_nothing)
- h=tracedmethod(h)
-
-c=C()
-
-#unbound calls
-C.f(c)
-C.g()
-C.h()
-
-#bound calls
-c.f()
-c.g()
-c.h()
-
-#&lt;/tracingmethods.py&gt;
-</pre>
-</blockquote>
-<p>Output:</p>
-<blockquote>
-<pre class="literal-block">
-[C] Calling 'f' with arguments
-(&lt;C object at 0x402042cc&gt;,){} ...
--&gt; 'C.f' called with result: &lt;C object at 0x402042cc&gt;
-
-[C] Calling '&lt;lambda&gt;' with arguments
-(){} ...
--&gt; 'C.&lt;lambda&gt;' called with result: None
-
-[C] Calling 'do_nothing' with arguments
-(&lt;class 'C'&gt;,){} ...
--&gt; 'C.do_nothing' called with result: None
-
-[C] Calling 'f' with arguments
-(&lt;C object at 0x402042cc&gt;,){} ...
--&gt; 'C.f' called with result: &lt;C object at 0x402042cc&gt;
-
-[C] Calling '&lt;lambda&gt;' with arguments
-(){} ...
--&gt; 'C.&lt;lambda&gt;' called with result: None
-
-[C] Calling 'do_nothing' with arguments
-(&lt;class 'C'&gt;,){} ...
--&gt; 'C.do_nothing' called with result: None
-</pre>
-</blockquote>
-<p>The approach in 'tracingmethods.py' works, but it is far from
-being elegant, since I had to explicitly wrap each method in the
-class by hand.</p>
-<p>Both problems can be avoided.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; wrap(Clock,tracedmethod)
-&gt;&gt;&gt; Clock.get_time()
-[Clock] Calling 'get_time' with arguments
-(){} ...
--&gt; 'Clock.get_time' called with result: 21:56:52
-'21:56:52'
-</pre>
-</blockquote>
-</div>
-</div>
-<div class="section" id="the-subtleties-of-multiple-inheritance">
-<h1><a class="toc-backref" href="#id100" name="the-subtleties-of-multiple-inheritance">THE SUBTLETIES OF MULTIPLE INHERITANCE</a></h1>
-<p>In chapter 4 we introduced the concept of multiple inheritance and discussed
-its simplest applications in absence of name collisions. When with methods
-with different names are derived from different classes multiple inheritance
-is pretty trivial. However, all kind of subtilites comes in presence of name
-clashing, i.e. when we multiply inherits different methods defined in different
-classes but with the <em>same</em> name.
-In order to understand what happens in this situation, it is essential to
-understand the concept of Method Resolution Order (MRO). For reader's
-convenience, I collect in this chapter some of the information
-reported in <a class="reference" href="http://www.python.org/2.3/mro.html">http://www.python.org/2.3/mro.html</a>.</p>
-<div class="section" id="a-little-bit-of-history-why-python-2-3-has-changed-the-mro">
-<h2><a class="toc-backref" href="#id101" name="a-little-bit-of-history-why-python-2-3-has-changed-the-mro">A little bit of history: why Python 2.3 has changed the MRO</a></h2>
-<p>Everything started with a post by Samuele Pedroni to the Python
-development mailing list <a class="footnote-reference" href="#id36" id="id37" name="id37">[18]</a>. In his post, Samuele showed that the
-Python 2.2 method resolution order is not monotonic and he proposed to
-replace it with the C3 method resolution order. Guido agreed with his
-arguments and therefore now Python 2.3 uses C3. The C3 method itself
-has nothing to do with Python, since it was invented by people working
-on Dylan and it is described in a paper intended for lispers <a class="footnote-reference" href="#id40" id="id38" name="id38">[19]</a>. The
-present paper gives a (hopefully) readable discussion of the C3
-algorithm for Pythonistas who want to understand the reasons for the
-change.</p>
-<p>First of all, let me point out that what I am going to say only applies
-to the <em>new style classes</em> introduced in Python 2.2: <em>classic classes</em>
-maintain their old method resolution order, depth first and then left to
-right. Therefore, there is no breaking of old code for classic classes;
-and even if in principle there could be breaking of code for Python 2.2
-new style classes, in practice the cases in which the C3 resolution
-order differs from the Python 2.2 method resolution order are so rare
-that no real breaking of code is expected. Therefore: don't be scared!</p>
-<p>Moreover, unless you make strong use of multiple inheritance and you
-have non-trivial hierarchies, you don't need to understand the C3
-algorithm, and you can easily skip this paper. On the other hand, if
-you really want to know how multiple inheritance works, then this paper
-is for you. The good news is that things are not as complicated as you
-might expect.</p>
-<p>Let me begin with some basic definitions.</p>
-<ol class="arabic simple">
-<li>Given a class C in a complicated multiple inheritance hierarchy, it
-is a non-trivial task to specify the order in which methods are
-overridden, i.e. to specify the order of the ancestors of C.</li>
-<li>The list of the ancestors of a class C, including the class itself,
-ordered from the nearest ancestor to the furthest, is called the
-class precedence list or the <em>linearization</em> of C.</li>
-<li>The <em>Method Resolution Order</em> (MRO) is the set of rules that
-construct the linearization. In the Python literature, the idiom
-&quot;the MRO of C&quot; is also used as a synonymous for the linearization of
-the class C.</li>
-<li>For instance, in the case of single inheritance hierarchy, if C is a
-subclass of C1, and C1 is a subclass of C2, then the linearization of
-C is simply the list [C, C1 , C2]. However, with multiple
-inheritance hierarchies, it is more difficult to construct a
-linearization that respects <em>local precedence ordering</em> and
-<em>monotonicity</em>.</li>
-<li>I will discuss the local precedence ordering later, but I can give
-the definition of monotonicity here. A MRO is monotonic when the
-following is true: <em>if C1 precedes C2 in the linearization of C,
-then C1 precedes C2 in the linearization of any subclass of C</em>.
-Otherwise, the innocuous operation of deriving a new class could
-change the resolution order of methods, potentially introducing very
-subtle bugs. Examples where this happens will be shown later.</li>
-<li>Not all classes admit a linearization. There are cases, in
-complicated hierarchies, where it is not possible to derive a class
-such that its linearization respects all the desired properties.</li>
-</ol>
-<p>Here I give an example of this situation. Consider the hierarchy</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; O = object
-&gt;&gt;&gt; class X(O): pass
-&gt;&gt;&gt; class Y(O): pass
-&gt;&gt;&gt; class A(X,Y): pass
-&gt;&gt;&gt; class B(Y,X): pass
-</pre>
-</blockquote>
-<p>which can be represented with the following inheritance graph, where I
-have denoted with O the <tt class="literal"><span class="pre">object</span></tt> class, which is the beginning of any
-hierarchy for new style classes:</p>
-<blockquote>
-<pre class="literal-block">
- -----------
-| |
-| O |
-| / \ |
- - X Y /
- | / | /
- | / |/
- A B
- \ /
- ?
-</pre>
-</blockquote>
-<p>In this case, it is not possible to derive a new class C from A and B,
-since X precedes Y in A, but Y precedes X in B, therefore the method
-resolution order would be ambiguous in C.</p>
-<p>Python 2.3 raises an exception in this situation (TypeError: MRO
-conflict among bases Y, X) forbidding the naive programmer from creating
-ambiguous hierarchies. Python 2.2 instead does not raise an exception,
-but chooses an <em>ad hoc</em> ordering (CABXYO in this case).</p>
-</div>
-<div class="section" id="the-c3-method-resolution-order">
-<h2><a class="toc-backref" href="#id102" name="the-c3-method-resolution-order">The C3 Method Resolution Order</a></h2>
-<p>Let me introduce a few simple notations which will be useful for the
-following discussion. I will use the shortcut notation</p>
-<blockquote>
-C1 C2 ... CN</blockquote>
-<p>to indicate the list of classes [C1, C2, ... , CN].</p>
-<p>The <em>head</em> of the list is its first element:</p>
-<blockquote>
-head = C1</blockquote>
-<p>whereas the <em>tail</em> is the rest of the list:</p>
-<blockquote>
-tail = C2 ... CN.</blockquote>
-<p>I shall also use the notation</p>
-<blockquote>
-C + (C1 C2 ... CN) = C C1 C2 ... CN</blockquote>
-<p>to denote the sum of the lists [C] + [C1, C2, ... ,CN].</p>
-<p>Now I can explain how the MRO works in Python 2.3.</p>
-<p>Consider a class C in a multiple inheritance hierarchy, with C
-inheriting from the base classes B1, B2, ... , BN. We want to compute
-the linearization L[C] of the class C. In order to do that, we need the
-concept of <em>merging</em> lists, since the rule says that</p>
-<blockquote>
-<em>the linearization of C is the sum of C plus the merge of a) the
-linearizations of the parents and b) the list of the parents.</em></blockquote>
-<p>In symbolic notation:</p>
-<blockquote>
-L[C(B1 ... BN)] = C + merge(L[B1] ... L[BN], B1 ... BN)</blockquote>
-<p>How is the merge computed? The rule is the following:</p>
-<blockquote>
-<em>take the head of the first list, i.e L[B1][0]; if this head is not in
-the tail of any of the other lists, then add it to the linearization
-of C and remove it from the lists in the merge, otherwise look at the
-head of the next list and take it, if it is a good head. Then repeat
-the operation until all the class are removed or it is impossible to
-find good heads. In this case, it is impossible to construct the
-merge, Python 2.3 will refuse to create the class C and will raise an
-exception.</em></blockquote>
-<p>This prescription ensures that the merge operation <em>preserves</em> the
-ordering, if the ordering can be preserved. On the other hand, if the
-order cannot be preserved (as in the example of serious order
-disagreement discussed above) then the merge cannot be computed.</p>
-<p>The computation of the merge is trivial if:</p>
-<ol class="arabic">
-<li><p class="first">C is the <tt class="literal"><span class="pre">object</span></tt> class, which has no parents; in this case its
-linearization coincides with itself,</p>
-<blockquote>
-<p>L[object] = object.</p>
-</blockquote>
-</li>
-<li><p class="first">C has only one parent (single inheritance); in this case</p>
-<blockquote>
-<p>L[C(B)] = C + merge(L[B],B) = C + L[B]</p>
-</blockquote>
-</li>
-</ol>
-<p>However, in the case of multiple inheritance things are more cumbersome
-and I don't expect you can understand the rule without a couple of
-examples ;-)</p>
-</div>
-<div class="section" id="examples">
-<h2><a class="toc-backref" href="#id103" name="examples">Examples</a></h2>
-<p>First example. Consider the following hierarchy:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; O = object
-&gt;&gt;&gt; class F(O): pass
-&gt;&gt;&gt; class E(O): pass
-&gt;&gt;&gt; class D(O): pass
-&gt;&gt;&gt; class C(D,F): pass
-&gt;&gt;&gt; class B(D,E): pass
-&gt;&gt;&gt; class A(B,C): pass
-</pre>
-</blockquote>
-<p>In this case the inheritance graph can be drawn as</p>
-<blockquote>
-<pre class="literal-block">
- 6
- ---
-Level 3 | O | (more general)
- / --- \
- / | \ |
- / | \ |
- / | \ |
- --- --- --- |
-Level 2 3 | D | 4| E | | F | 5 |
- --- --- --- |
- \ \ _ / | |
- \ / \ _ | |
- \ / \ | |
- --- --- |
-Level 1 1 | B | | C | 2 |
- --- --- |
- \ / |
- \ / \ /
- ---
-Level 0 0 | A | (more specialized)
- ---
-</pre>
-</blockquote>
-<p>The linearizations of O,D,E and F are trivial:</p>
-<blockquote>
-<pre class="literal-block">
-L[O] = O
-L[D] = D O
-L[E] = E O
-L[F] = F O
-</pre>
-</blockquote>
-<p>The linearization of B can be computed as</p>
-<blockquote>
-<pre class="literal-block">
-L[B] = B + merge(DO, EO, DE)
-</pre>
-</blockquote>
-<p>We see that D is a good head, therefore we take it and we are reduced to
-compute merge(O,EO,E). Now O is not a good head, since it is in the
-tail of the sequence EO. In this case the rule says that we have to
-skip to the next sequence. Then we see that E is a good head; we take
-it and we are reduced to compute merge(O,O) which gives O. Therefore</p>
-<blockquote>
-<pre class="literal-block">
-L[B] = B D E O
-</pre>
-</blockquote>
-<p>Using the same procedure one finds:</p>
-<blockquote>
-<pre class="literal-block">
-L[C] = C + merge(DO,FO,DF)
- = C + D + merge(O,FO,F)
- = C + D + F + merge(O,O)
- = C D F O
-</pre>
-</blockquote>
-<p>Now we can compute:</p>
-<blockquote>
-<pre class="literal-block">
-L[A] = A + merge(BDEO,CDFO,BC)
- = A + B + merge(DEO,CDFO,C)
- = A + B + C + merge(DEO,DFO)
- = A + B + C + D + merge(EO,FO)
- = A + B + C + D + E + merge(O,FO)
- = A + B + C + D + E + F + merge(O,O)
- = A B C D E F O
-</pre>
-</blockquote>
-<p>In this example, the linearization is ordered in a pretty nice way
-according to the inheritance level, in the sense that lower levels (i.e.
-more specialized classes) have higher precedence (see the inheritance
-graph). However, this is not the general case.</p>
-<p>I leave as an exercise for the reader to compute the linearization for
-my second example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; O = object
-&gt;&gt;&gt; class F(O): pass
-&gt;&gt;&gt; class E(O): pass
-&gt;&gt;&gt; class D(O): pass
-&gt;&gt;&gt; class C(D,F): pass
-&gt;&gt;&gt; class B(E,D): pass
-&gt;&gt;&gt; class A(B,C): pass
-</pre>
-</blockquote>
-<p>The only difference with the previous example is the change B(D,E) --&gt;
-B(E,D); however even such a little modification completely changes the
-ordering of the hierarchy</p>
-<blockquote>
-<pre class="literal-block">
- 6
- ---
-Level 3 | O |
- / --- \
- / | \
- / | \
- / | \
- --- --- ---
-Level 2 2 | E | 4 | D | | F | 5
- --- --- ---
- \ / \ /
- \ / \ /
- \ / \ /
- --- ---
-Level 1 1 | B | | C | 3
- --- ---
- \ /
- \ /
- ---
-Level 0 0 | A |
- ---
-</pre>
-</blockquote>
-<p>Notice that the class E, which is in the second level of the hierarchy,
-precedes the class C, which is in the first level of the hierarchy, i.e.
-E is more specialized than C, even if it is in a higher level.</p>
-<p>A lazy programmer can obtain the MRO directly from Python 2.2, since in
-this case it coincides with the Python 2.3 linearization. It is enough
-to invoke the .mro() method of class A:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; A.mro()
-(&lt;class '__main__.A'&gt;, &lt;class '__main__.B'&gt;, &lt;class '__main__.E'&gt;,
-&lt;class '__main__.C'&gt;, &lt;class '__main__.D'&gt;, &lt;class '__main__.F'&gt;,
-&lt;type 'object'&gt;)
-</pre>
-</blockquote>
-<p>Finally, let me consider the example discussed in the first section,
-involving a serious order disagreement. In this case, it is
-straightforward to compute the linearizations of O, X, Y, A and B:</p>
-<blockquote>
-<pre class="literal-block">
-L[O] = 0
-L[X] = X O
-L[Y] = Y O
-L[A] = A X Y O
-L[B] = B Y X O
-</pre>
-</blockquote>
-<p>However, it is impossible to compute the linearization for a class C
-that inherits from A and B:</p>
-<blockquote>
-<pre class="literal-block">
-L[C] = C + merge(AXYO, BYXO, AB)
- = C + A + merge(XYO, BYXO, B)
- = C + A + B + merge(XYO, YXO)
-</pre>
-</blockquote>
-<p>At this point we cannot merge the lists XYO and YXO, since X is in the
-tail of YXO whereas Y is in the tail of XYO: therefore there are no
-good heads and the C3 algorithm stops. Python 2.3 raises an error and
-refuses to create the class C.</p>
-</div>
-<div class="section" id="bad-method-resolution-orders">
-<h2><a class="toc-backref" href="#id104" name="bad-method-resolution-orders">Bad Method Resolution Orders</a></h2>
-<p>A MRO is <em>bad</em> when it breaks such fundamental properties as local
-precedence ordering and monotonicity. In this section, I will show
-that both the MRO for classic classes and the MRO for new style classes
-in Python 2.2 are bad.</p>
-<p>It is easier to start with the local precedence ordering. Consider the
-following example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; F=type('Food',(),{'remember2buy':'spam'})
-&gt;&gt;&gt; E=type('Eggs',(F,),{'remember2buy':'eggs'})
-&gt;&gt;&gt; G=type('GoodFood',(F,E),{}) #under Python 2.3 this is an error
-</pre>
-</blockquote>
-<p>with inheritance diagram</p>
-<blockquote>
-<pre class="literal-block">
- O
- |
-(buy spam) F
- | \
- | E (buy eggs)
- | /
- G
-
- (buy eggs or spam ?)
-</pre>
-</blockquote>
-<p>We see that class G inherits from F and E, with F <em>before</em> E: therefore
-we would expect the attribute <em>G.remember2buy</em> to be inherited by
-<em>F.rembermer2buy</em> and not by <em>E.remember2buy</em>: nevertheless Python 2.2
-gives</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; G.remember2buy #under Python 2.3 this is an error
-'eggs'
-</pre>
-</blockquote>
-<p>This is a breaking of local precedence ordering since the order in the
-local precedence list, i.e. the list of the parents of G, is not
-preserved in the Python 2.2 linearization of G:</p>
-<blockquote>
-<pre class="literal-block">
-L[G,P22]= G E F object # F *follows* E
-</pre>
-</blockquote>
-<p>One could argue that the reason why F follows E in the Python 2.2
-linearization is that F is less specialized than E, since F is the
-superclass of E; nevertheless the breaking of local precedence ordering
-is quite non-intuitive and error prone. This is particularly true since
-it is a different from old style classes:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class F: remember2buy='spam'
-&gt;&gt;&gt; class E(F): remember2buy='eggs'
-&gt;&gt;&gt; class G(F,E): pass
-&gt;&gt;&gt; G.remember2buy
-'spam'
-</pre>
-</blockquote>
-<p>In this case the MRO is GFEF and the local precedence ordering is
-preserved.</p>
-<p>As a general rule, hierarchies such as the previous one should be
-avoided, since it is unclear if F should override E or viceversa.
-Python 2.3 solves the ambiguity by raising an exception in the creation
-of class G, effectively stopping the programmer from generating
-ambiguous hierarchies. The reason for that is that the C3 algorithm
-fails when the merge</p>
-<blockquote>
-<pre class="literal-block">
-merge(FO,EFO,FE)
-</pre>
-</blockquote>
-<p>cannot be computed, because F is in the tail of EFO and E is in the tail
-of FE.</p>
-<p>The real solution is to design a non-ambiguous hierarchy, i.e. to derive
-G from E and F (the more specific first) and not from F and E; in this
-case the MRO is GEF without any doubt.</p>
-<blockquote>
-<pre class="literal-block">
- O
- |
- F (spam)
- / |
-(eggs) E |
- \ |
- G
- (eggs, no doubt)
-</pre>
-</blockquote>
-<p>Python 2.3 forces the programmer to write good hierarchies (or, at
-least, less error-prone ones).</p>
-<p>On a related note, let me point out that the Python 2.3 algorithm is
-smart enough to recognize obvious mistakes, as the duplication of
-classes in the list of parents:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A(object): pass
-&gt;&gt;&gt; class C(A,A): pass # error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: duplicate base class A
-</pre>
-</blockquote>
-<p>Python 2.2 (both for classic classes and new style classes) in this
-situation, would not raise any exception.</p>
-<p>Finally, I would like to point out two lessons we have learned from this
-example:</p>
-<ol class="arabic simple">
-<li>despite the name, the MRO determines the resolution order of
-attributes, not only of methods;</li>
-<li>the default food for Pythonistas is spam ! (but you already knew
-that ;-)</li>
-</ol>
-<p>Having discussed the issue of local precedence ordering, let me now
-consider the issue of monotonicity. My goal is to show that neither the
-MRO for classic classes nor that for Python 2.2 new style classes is
-monotonic.</p>
-<p>To prove that the MRO for classic classes is non-monotonic is rather
-trivial, it is enough to look at the diamond diagram:</p>
-<blockquote>
-<pre class="literal-block">
- C
- / \
- / \
-A B
- \ /
- \ /
- D
-</pre>
-</blockquote>
-<p>One easily discerns the inconsistency:</p>
-<blockquote>
-<pre class="literal-block">
-L[B,P21] = B C # B precedes C : B's methods win
-L[D,P21] = D A C B C # B follows C : C's methods win!
-</pre>
-</blockquote>
-<p>On the other hand, there are no problems with the Python 2.2 and 2.3
-MROs, they give both</p>
-<blockquote>
-<pre class="literal-block">
-L[D] = D A B C
-</pre>
-</blockquote>
-<p>Guido points out in his essay <a class="footnote-reference" href="#id41" id="id39" name="id39">[20]</a> that the classic MRO is not so bad in
-practice, since one can typically avoids diamonds for classic classes.
-But all new style classes inherit from object, therefore diamonds are
-unavoidable and inconsistencies shows up in every multiple inheritance
-graph.</p>
-<p>The MRO of Python 2.2 makes breaking monotonicity difficult, but not
-impossible. The following example, originally provided by Samuele
-Pedroni, shows that the MRO of Python 2.2 is non-monotonic:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A(object): pass
-&gt;&gt;&gt; class B(object): pass
-&gt;&gt;&gt; class C(object): pass
-&gt;&gt;&gt; class D(object): pass
-&gt;&gt;&gt; class E(object): pass
-&gt;&gt;&gt; class K1(A,B,C): pass
-&gt;&gt;&gt; class K2(D,B,E): pass
-&gt;&gt;&gt; class K3(D,A): pass
-&gt;&gt;&gt; class Z(K1,K2,K3): pass
-</pre>
-</blockquote>
-<p>Here are the linearizations according to the C3 MRO (the reader should
-verify these linearizations as an exercise and draw the inheritance
-diagram ;-)</p>
-<blockquote>
-<pre class="literal-block">
-L[A] = A O
-L[B] = B O
-L[C] = C O
-L[D] = D O
-L[E] = E O
-L[K1]= K1 A B C O
-L[K2]= K2 D B E O
-L[K3]= K3 D A O
-L[Z] = Z K1 K2 K3 D A B C E O
-</pre>
-</blockquote>
-<p>Python 2.2 gives exactly the same linearizations for A, B, C, D, E, K1,
-K2 and K3, but a different linearization for Z:</p>
-<blockquote>
-<pre class="literal-block">
-L[Z,P22] = Z K1 K3 A K2 D B C E O
-</pre>
-</blockquote>
-<p>It is clear that this linearization is <em>wrong</em>, since A comes before D
-whereas in the linearization of K3 A comes <em>after</em> D. In other words, in
-K3 methods derived by D override methods derived by A, but in Z, which
-still is a subclass of K3, methods derived by A override methods derived
-by D! This is a violation of monotonicity. Moreover, the Python 2.2
-linearization of Z is also inconsistent with local precedence ordering,
-since the local precedence list of the class Z is [K1, K2, K3] (K2
-precedes K3), whereas in the linearization of Z K2 <em>follows</em> K3. These
-problems explain why the 2.2 rule has been dismissed in favor of the C3
-rule.</p>
-<table class="footnote" frame="void" id="id40" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id38" name="id40">[19]</a></td><td>The thread on python-dev started by Samuele Pedroni:
-<a class="reference" href="http://mail.python.org/pipermail/python-dev/2002-October/029035.html">http://mail.python.org/pipermail/python-dev/2002-October/029035.html</a></td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id41" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id39" name="id41">[20]</a></td><td>The paper <em>A Monotonic Superclass Linearization for Dylan</em>:
-<a class="reference" href="http://www.webcom.com/haahr/dylan/linearization-oopsla96.html">http://www.webcom.com/haahr/dylan/linearization-oopsla96.html</a></td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id42" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id44" name="id42">[21]</a></td><td>Guido van Rossum's essay, <em>Unifying types and classes in Python 2.2</em>:
-<a class="reference" href="http://www.python.org/2.2.2/descrintro.html">http://www.python.org/2.2.2/descrintro.html</a></td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id43" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id47" name="id43">[22]</a></td><td>The (in)famous book on metaclasses, <em>Putting Metaclasses to Work</em>:
-Ira R. Forman, Scott Danforth, Addison-Wesley 1999 (out of print,
-but probably still available on <a class="reference" href="http://www.amazon.com">http://www.amazon.com</a>)</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="understanding-the-method-resolution-order">
-<h2><a class="toc-backref" href="#id105" name="understanding-the-method-resolution-order">Understanding the Method Resolution Order</a></h2>
-<p>The MRO of any given (new style) Python class is given
-by the special attribute <tt class="literal"><span class="pre">__mro__</span></tt>. Notice that since
-Python is an extremely dynamic language it is possible
-to delete and to generate whole classes at run time, therefore the MRO
-is a dynamic concept. For instance, let me show how it is possibile to
-remove a class from my
-paleoanthropological hierarchy: for instance I can
-replace the last class 'HomoSapiensSapiens' with 'HomoSapiensNeardenthalensis'
-(changing a class in the middle of the hierarchy would be more difficult). The
-following lines do the job dynamically:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; del HomoSapiensSapiens
-&gt;&gt;&gt; class HomoSapiensNeardenthalensis(HomoSapiens):
-... def can(self):
-... super(self.__this,self).can()
-... print &quot; - make something&quot;
-&gt;&gt;&gt; reflective(HomoSapiensNeardenthalensis)
-&gt;&gt;&gt; HomoSapiensNeardenthalensis().can()
-HomoSapiensNeardenthalensis can:
- - make tools
- - make abstractions
- - make something
-</pre>
-</blockquote>
-<p>In this case the MRO of 'HomoSapiensNeardenthalensis', i.e. the list of
-all its ancestors, is</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; HomoSapiensNeardenthalensis.__mro__
-[&lt;class '__main__.HomoSapiensNeardenthalensis'&gt;,&lt;class 'oopp.HomoSapiens'&gt;,
- &lt;class 'oopp.HomoHabilis'&gt;, &lt;class 'oopp.Homo'&gt;,
- &lt;class 'oopp.PrettyPrinted'&gt;, &lt;class 'oopp.object'&gt;]
-</pre>
-</blockquote>
-<p>The <tt class="literal"><span class="pre">__mro__</span></tt> attribute gives the <em>linearization</em> of the class, i.e. the
-ordered list of its ancestors, starting from the class itself and ending
-with object. The linearization of a class is essential in order to specify
-the resolution order of methods and attributes, i.e. the Method Resolution
-Order (MRO). In the case of single inheritance hierarchies, such the
-paleonthropological example, the MRO is pretty obvious; on the contrary
-it is a quite non-trivial concept in the case of multiple inheritance
-hierarchies.</p>
-<p>For instance, let me reconsider my first example of multiple inheritance,
-the <tt class="literal"><span class="pre">NonInstantiableClock</span></tt> class, inheriting from 'NonInstantiable' and
-'Clock'. I may represent the hierarchy with the following inheritance graph:</p>
-<blockquote>
-<pre class="literal-block">
- -- object --
- / (__new__) \
- / \
- / \
- Clock NonInstantiable
-(get_time) (__new__)
- \ /
- \ /
- \ /
- \ /
- \ /
- NonInstantiableClock
- (get_time,__new__)
-</pre>
-</blockquote>
-<p>The class <tt class="literal"><span class="pre">Clock</span></tt> define a <tt class="literal"><span class="pre">get_time</span></tt> method, whereas the class
-<tt class="literal"><span class="pre">NonInstantiable</span></tt> overrides the <tt class="literal"><span class="pre">__new__</span></tt> method of the <tt class="literal"><span class="pre">object</span></tt> class;
-the class <tt class="literal"><span class="pre">NonInstantiableClock</span></tt> inherits <tt class="literal"><span class="pre">get_time</span></tt> from 'Clock' and
-<tt class="literal"><span class="pre">__new__</span></tt> from 'NonInstantiable'.</p>
-<p>The linearization of 'NonInstantiableClock' is</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; NonInstantiableClock.mro()
-[&lt;class '__main__.NonInstantiableClock'&gt;, &lt;class 'oopp.Clock'&gt;,
- &lt;class 'oopp.NonInstantiable'&gt;, &lt;type 'object'&gt;]
-</pre>
-</blockquote>
-<p>In particular, since 'NonInstantiable' precedes 'object', its <tt class="literal"><span class="pre">__new__</span></tt>
-method overrides the <tt class="literal"><span class="pre">object</span></tt> new method. However, with the MRO used before
-Python 2.2, the linearization would have been <tt class="literal"><span class="pre">NonInstantiableClock,</span> <span class="pre">Clock,</span>
-<span class="pre">object,</span> <span class="pre">NonInstantiable,</span> <span class="pre">object</span></tt> and the <tt class="literal"><span class="pre">__new__</span></tt> method of object would
-have (hypothetically, of course, since before Python 2.2 there was not
-<tt class="literal"><span class="pre">__new__</span></tt> method! ;-) overridden the <tt class="literal"><span class="pre">__new__</span></tt>
-method of <tt class="literal"><span class="pre">NonInstantiable</span></tt>, therefore <tt class="literal"><span class="pre">NonInstantiableClock</span></tt> would
-have lost the property of being non-instantiable!</p>
-<p>This simple example shows that the choice of a correct Method Resolution
-Order is far from being obvious in general multiple inheritance hierarchies.
-After a false start in Python 2.2, (with a MRO failing in some subtle cases)
-Python 2.3 decided to adopt the so-called C3 MRO, invented by people working
-on Dylan (even if Dylan itself uses the MRO of Common Lisp CLOS). Since this
-is quite a technical matter, I defer the interested reader to appendix 2
-for a full discussion of the C3 algorithm.</p>
-<p>Here, I prefer to point out how the built-in
-<tt class="literal"><span class="pre">super</span></tt> object works in multiple inheritance situations. To this aim, it
-is convenient to define an utility function that retrieves the ancestors
-of a given class with respect to the MRO of one of its subclasses:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def ancestor(C,S=None):
- &quot;&quot;&quot;Returns the ancestors of the first argument with respect to the
- MRO of the second argument. If the second argument is None, then
- returns the MRO of the first argument.&quot;&quot;&quot;
- if C is object:
- raise TypeError(&quot;There is no superclass of object&quot;)
- elif S is None or S is C:
- return list(C.__mro__)
- elif issubclass(S,C): # typical case
- mro=list(S.__mro__)
- return mro[mro.index(C):] # compute the ancestors from the MRO of S
- else:
- raise TypeError(&quot;S must be a subclass of C&quot;)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Let me show how the function <tt class="literal"><span class="pre">ancestor</span></tt> works.
-Consider the class <tt class="literal"><span class="pre">Clock</span></tt> in isolation: then
-its direct superclass, i.e. the first ancestor, is <tt class="literal"><span class="pre">object</span></tt>,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; ancestor(Clock)[1]
-&lt;type 'object'&gt;
-</pre>
-</blockquote>
-<p>therefore <tt class="literal"><span class="pre">super(Clock).__new__</span></tt> retrieves the <tt class="literal"><span class="pre">object.__new__</span></tt> method:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(Clock).__new__
-&lt;built-in method __new__ of type object at 0x80e6fc0&gt;
-</pre>
-</blockquote>
-<p>Consider now the <tt class="literal"><span class="pre">Clock</span></tt> class together with its subclass
-<tt class="literal"><span class="pre">NonInstantiableClock</span></tt>:
-in this case the first ancestor of <tt class="literal"><span class="pre">Clock</span></tt>, <em>with respect to the MRO of
-'NonInstantiableClock'</em> is <tt class="literal"><span class="pre">NonInstantiable</span></tt></p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; ancestor(Clock,NonInstantiableClock)[1]
-&lt;class 'oopp.NonInstantiable'&gt;
-</pre>
-</blockquote>
-<p>Therefore <tt class="literal"><span class="pre">super(Clock,NonInstantiableClock).__new__</span></tt> retrieves the
-<tt class="literal"><span class="pre">NonInstantiable.__new__</span></tt> method:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(Clock,NonInstantiableClock).__new__
-&lt;function __new__ at 0x81b293c&gt;
-&gt;&gt;&gt; NonInstantiable.__new__
-&lt;function __new__ at 0x81b293c&gt;
-</pre>
-</blockquote>
-<p>It must be pointed out that <tt class="literal"><span class="pre">super(C,S)</span></tt> is equivalent but not the same
-than <tt class="literal"><span class="pre">ancestor(C,S)[1]</span></tt>, since it does not return the superclass:
-it returns a super object, instead:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(Clock,NonInstantiableClock)
-&lt;super: &lt;class 'Clock'&gt;, &lt;type object&gt;&gt;
-</pre>
-<p>#&lt;oopp.py&gt;</p>
-<p>#class Super(super):
-# def __init__(self,C,S=None):
-# super(Super,self).__init__(C,S)
-# self.__name__=&quot;Super(%s)&quot; % C.__name__</p>
-<p>#&lt;/oopp.py&gt;</p>
-</blockquote>
-<p>Finally, there is little quirk of super:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(PrettyPrinted): pass
-&gt;&gt;&gt; s=super(C,C())
-&gt;&gt;&gt; s.__str__()
-</pre>
-</blockquote>
-<p>but</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; str(s) # idem for print s
-&quot;&lt;super: &lt;class 'C'&gt;, &lt;C object&gt;&gt;&quot;
-</pre>
-</blockquote>
-<p>Idem for non-pre-existing methods:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(list): pass
-...
-&gt;&gt;&gt; s=super(D,D())
-&gt;&gt;&gt; s.__len__()
-0
-&gt;&gt;&gt; len(s) #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: len() of unsized object
-</pre>
-</blockquote>
-<p>The same problem comes with <tt class="literal"><span class="pre">__getattr__</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class E(object):
-... def __getattr__(self,name):
-... if name=='__len__': return lambda:0
-...
-&gt;&gt;&gt; e=E()
-&gt;&gt;&gt; e.__len__()
-0
-&gt;&gt;&gt; len(e) # error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: len() of unsized object
-</pre>
-</blockquote>
-</div>
-<div class="section" id="counting-instances">
-<h2><a class="toc-backref" href="#id106" name="counting-instances">Counting instances</a></h2>
-<blockquote>
-<pre class="line-block">
-<em>Everything should be built top-down, except the first time.</em>
--- Alan Perlis
-</pre>
-</blockquote>
-<p>Multiple inheritance adds a step further to the bottom-up philosophy and
-it makes appealing the idea of creating classes with the only
-purpose of being derived. Whereas in the top-down approach one starts
-with full featured standalone classes, to be further refined, in the
-mix-in approach one starts with bare bone classes, providing very simple
-or even trivial features, with the purpose of providing
-basic reusable components in multiple inheritance hierarchies.
-At the very end, the idea is to generate a library of <em>mixin</em> classes, to be
-composed with other classes. We already saw a couple of examples of
-mixin classes: 'NonInstantiable' and 'Customizable'. In this paragraph
-I will show three other examples: 'WithCounter','Singleton' and
-'AvoidDuplication'.</p>
-<p>A common requirement for a class is the ability to count the number of its
-instances. This is a quite easy problem: it is enough to increments a counter
-each time an instance of that class is initialized. However, this idea can
-be implemented in the wrong way. i.e. naively one could implement
-counting capabilities in a class without such capabilities by modifying the
-<tt class="literal"><span class="pre">__init__</span></tt> method explicitly in the original source code.
-A better alternative is to follow the bottom-up approach and to implement
-the counting feature in a separate mix-in class: then the feature can be
-added to the original class via multiple inheritance, without touching
-the source.
-Moreover, the counter class becomes a reusable components that can be
-useful for other problems, too. In order to use the mix-in approach, the
-<tt class="literal"><span class="pre">__new__</span></tt> method of the counter class must me cooperative, and preferably
-via an anonymous super call.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class WithCounter(object):
- &quot;&quot;&quot;Mixin class counting the total number of its instances and storing
- it in the class attribute counter.&quot;&quot;&quot;
-
- counter=0 # class attribute (or static attribute in C++/Java terms)
-
- def __new__(cls,*args,**kw):
- cls.counter+=1 # increments the class attribute
- return super(cls.__this,cls).__new__(cls,*args,**kw)
- #anonymous cooperative call to the superclass's method __new__
-
-reflective(WithCounter)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Each time an instance of 'WithCounter' is initialized, the counter 'count' is
-incremented and when 'WithCounter' is composed trough multiple inheritance,
-its '__new__' method cooperatively invokes the <tt class="literal"><span class="pre">__new__</span></tt> method
-of the other components.</p>
-<p>For instance, I can use 'WithCounter' to implement a 'Singleton', i.e.
-a class that can have only one instance. This kind of classes can be
-obtained as follows:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Singleton(WithCounter):
- &quot;If you inherit from me, you can only have one instance&quot;
- def __new__(cls,*args,**kw):
- if cls.counter==0: #first call
- cls.instance=super(cls.__this,cls).__new__(cls,*args,**kw)
- return cls.instance
-
-reflective(Singleton)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>As an application, I can create a
-class <tt class="literal"><span class="pre">SingleClock</span></tt> that inherits from <tt class="literal"><span class="pre">Clock</span></tt>
-<em>and</em> from <tt class="literal"><span class="pre">Singleton</span></tt>. This means that <tt class="literal"><span class="pre">SingleClock</span></tt> is both a
-'Clock' and a 'Singleton', i.e. there can be only a clock:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import Clock,Singleton
-&gt;&gt;&gt; class SingleClock(Clock,Singleton): pass
-...
-&gt;&gt;&gt; clock1=SingleClock()
-&gt;&gt;&gt; clock2=SingleClock()
-&gt;&gt;&gt; clock1 is clock2
-True
-</pre>
-</blockquote>
-<p>Instantiating many clocks is apparently possible (i.e. no error
-message is given) but you always obtain the same instance. This makes
-sense, since there is only one time on the system and a single
-clock is enough.</p>
-<p>A variation of the 'Singleton' is a class that generates a new
-instance only when a certain condition is satisfied. Suppose for instance
-one has a 'Disk' class, to be instantiated with the syntax
-<tt class="literal"><span class="pre">Disk(xpos,ypos,radius)</span></tt>.
-It is clear that two disks with the same radius and the same position in
-the cartesian plane, are essentially the same disk (assuming there are no
-additional attributes such as the color). Therefore it is a vaste of memory
-to instantiate two separate objects to describe the same disk. To solve
-this problem, one possibility is to store in a list the calling arguments.
-When it is time to instanciate a new objects with arguments args = xpos,ypos,
-radius, Python should check if a disk with these arguments has already
-been instanciated: in this case that disk should be returned, not a new
-one. This logic can be elegantly implemented in a mix-in class such as the
-following (compare with the <tt class="literal"><span class="pre">withmemory</span></tt> wrapper in chapter 2):</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class AvoidDuplication(object):
- def __new__(cls,*args,**kw):
- return super(cls.__this,cls).__new__(cls,*args,**kw)
- __new__=withmemory(__new__) # collects the calls in __new__.result
-
-reflective(AvoidDuplication)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Notice that 'AvoidDuplication' is introduced with the only purpose of
-giving its functionality to 'Disk': in order to reach this goal, it is enough
-to derive 'Disk' from this class and our previously
-introduced 'GeometricFigure' class by writing something like</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; class Disk(GeometricFigure,AvoidDuplication):
-... def __init__(self,xpos,ypos,radius):
-... return super(Disk,self).__init__('(x-x0)**2+(y-y0)**2 &lt;= r**2',
-... x0=xpos,y0=ypos,r=radius)
-</pre>
-</blockquote>
-<p>Now, if we create a disk</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c1=Disk(0,0,10) #creates a disk of radius 10
-</pre>
-</blockquote>
-<p>it is easy enough to check that trying to instantiate a new disk with the
-<em>same</em> arguments return the old disk:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c2=Disk(0,0,10) #returns the *same* old disk
-&gt;&gt;&gt; c1 is c2
-True
-</pre>
-</blockquote>
-<p>Here, everything works, because through the
-cooperative <tt class="literal"><span class="pre">super</span></tt> mechanism, <tt class="literal"><span class="pre">Disk.__init__</span></tt> calls
-<tt class="literal"><span class="pre">AvoidDuplication.__init__</span></tt> that calls <tt class="literal"><span class="pre">GeometricFigure.__init__</span></tt>
-that in turns initialize the disk. Inverting the order of
-'AvoidDuplication' and 'GeometricFigure' would case a disaster, since
-<tt class="literal"><span class="pre">GeometricFigure.__init__</span></tt> would override <tt class="literal"><span class="pre">AvoidDuplication.__init__</span></tt>.</p>
-<p>Alternatively, one could use the object factory 'Makeobj' implemented in
-chapter 3:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class NonDuplicatedFigure(GeometricFigure,AvoidDuplication): pass
-&gt;&gt;&gt; makedisk=Makeobj(NonDuplicatedFigure,'(x-x0)**2/4+(y-y0)**2 &lt;= r**2')
-&gt;&gt;&gt; disk1=makedisk(x0=38,y0=7,r=5)
-&gt;&gt;&gt; disk2=makedisk(x0=38,y0=7,r=5)
-&gt;&gt;&gt; disk1 is disk2
-True
-</pre>
-</blockquote>
-<p>Remark: it is interesting to notice that the previous approach would not work
-for keyword arguments, directly, since dictionary are unhashable.</p>
-</div>
-<div class="section" id="the-pizza-shop-example">
-<h2><a class="toc-backref" href="#id107" name="the-pizza-shop-example">The pizza-shop example</a></h2>
-<p>Now it is time to give a non-trivial example of multiple inheritance with
-cooperative and non-cooperative classes. The point is that multiple
-inheritance can easily leads to complicated hierarchies: where the
-resolution order of methods is far from being obvious and actually
-can give bad surprises.</p>
-<p>To explain the issue, let me extend the program for the pizza-shop owner of
-chapter 4, by following the bottom-up approach and using anonymous
-cooperative super calls.
-In this approach, one starts from the simplest thing.
-It is clear that the pizza-shop owner has interest in recording all the
-pizzas he sell.
-To this aim, he needs a class providing logging capabilities:
-each time a new instance is created, its features are stored in a log file. In
-order to count the total number of instances, 'WithLogger' must derive from
-the 'WithCounter' class. In order to have a nicely printed message,
-'WithLogger' must derive from 'PrettyPrinted'. Finally,
-since 'WithLogger' must be a general purpose
-class that I will reuse in other problem as a mixin class, it must be
-cooperative. 'WithLogger' can be implemented as follows:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class WithLogger(WithCounter,PrettyPrinted):
- &quot;&quot;&quot;WithLogger inherits from WithCounter the 'count' class attribute;
- moreover it inherits '__str__' from PrettyPrinted&quot;&quot;&quot;
- logfile=sys.stdout #default
- verboselog=False #default
- def __init__(self,*args,**kw):
- super(self.__this,self).__init__(*args,**kw) # cooperative
- dic=attributes(self) # non-special attributes dictionary
- print &gt;&gt; self.logfile,'*'*77
- print &gt;&gt; self.logfile, time.asctime()
- print &gt;&gt; self.logfile, &quot;%s. Created %s&quot; % (type(self).counter,self)
- if self.verboselog:
- print &gt;&gt; self.logfile,&quot;with accessibile non-special attributes:&quot;
- if not dic: print &gt;&gt; self.logfile,&quot;&lt;NOTHING&gt;&quot;,
- else: print &gt;&gt; self.logfile, pretty(dic)
-
-reflective(WithLogger)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here I could well use <tt class="literal"><span class="pre">super(self.__this,self).__init__(*args,**kw)</span></tt>
-instead of <tt class="literal"><span class="pre">super(self.__this,self).__init__(*args,**kw)</span></tt>, nevertheless
-the standard <tt class="literal"><span class="pre">super</span></tt> works in this case and I can use it with better
-performances.
-Thanks to the power of multiple inheritance, we may give logging features
-to the 'CustomizablePizza' class defined in chapter 4
-with just one line of code:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; class Pizza(WithLogger,CustomizablePizza):
-... &quot;Notice, WithLogger is before CustomizablePizza&quot;
-&gt;&gt;&gt; Pizza.With(toppinglist=['tomato'])('small')
-****************************************************************************
-Sat Feb 22 14:54:44 2003
-1. Created &lt;Pizza&gt;
-&lt;__main__.Pizza object at 0x816927c&gt;
-</pre>
-</blockquote>
-<p>It is also possible to have a more verbose output:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Pizza.With(verboselog=True)
-&lt;class '__main__.Pizza'&gt;
-&gt;&gt;&gt; Pizza('large')
-****************************************************************************
-Sat Feb 22 14:59:51 2003
-1. Created &lt;Pizza&gt;
-with accessibile non-special attributes:
-With = &lt;bound method type.customized of &lt;class '__main__.Pizza'&gt;&gt;
-baseprice = 1
-count = 2
-formatstring = %s
-logfile = &lt;open file '&lt;stdout&gt;', mode 'w' at 0x402c2058&gt;
-price = &lt;bound method Pizza.price of &lt;__main__.Pizza object at 0x402f6c8c&gt;&gt;
-size = large
-sizefactor = {'small': 1, 'large': 3, 'medium': 2}
-topping_unit_price = 0.5
-toppinglist = ['tomato']
-toppings_price = &lt;bound method Pizza.toppings_price of
- &lt;__main__.Pizza object at 0x402f6c8c&gt;&gt;
-verboselog = True
-with = &lt;bound method Pizza.customized of
-&lt;__main__.Pizza object at 0x402f6c8c&gt;&gt;
-&lt;__main__.Pizza object at 0x401ce7ac&gt;
-</pre>
-</blockquote>
-<p>However, there is a problem here, since the output is '&lt;Pizza&gt;' and
-not the nice 'large pizza with tomato, cost $ 4.5' that we would
-expect from a child of 'CustomizablePizza'. The solution to the
-puzzle is given by the MRO:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Pizza.mro()
-[&lt;class '__main__.Pizza'&gt;, &lt;class 'oopp.WithLogger'&gt;,
- &lt;class 'oopp.WithCounter'&gt;, &lt;class 'oopp.PrettyPrinted'&gt;,
- &lt;class 'oopp.CustomizablePizza'&gt;, &lt;class 'oopp.GenericPizza'&gt;,
- &lt;class 'oopp.Customizable'&gt;, &lt;type 'object'&gt;]
-</pre>
-</blockquote>
-<p>The inheritance graph is rather complicated:</p>
-<blockquote>
-<pre class="literal-block">
- object 7
-
- / / \ \
- / / \ \
- / / \ \
- / / \ \
- / / \ \
- / / \ \
- / / \ \
- / / \ \
- / / \ \
-2 WithCounter PrettyPrinted 3 GenericPizza 5 Customizable 6
- (__new__) (__str__,__init__) (__str__) /
- \ / / /
- \ / / /
- \ / / /
- \ / / /
- \ / CustomizablePizza 4
- \ / /
- 1 WithLogger /
- (__init__) /
- \ /
- \ /
- \ /
- \ /
- \ /
-
- Pizza O
-</pre>
-</blockquote>
-<p>As we see, the precedence in the resolution of methods is far from being
-trivial. It is denoted in the graph with numbers
-from 0 to 7: first the methods of 'Pizza' (level 0), then the methods of
-'WithLogger' (level 1), then the methods of 'WithCounter' (level 2), then
-the methods of 'PrettyPrinted' (level 3), then the methods of
-'CustomizablePizza' (level 4), then the methods of 'GenericPizza' (level 5),
-then the level of 'Customizable' (level 6), finally the 'object' methods
-(level 7).</p>
-<p>The reason why the MRO is so, can be understood by studying
-appendix 1.</p>
-<p>We see that the <tt class="literal"><span class="pre">__init__</span></tt> methods of 'WithLogger' and
-the <tt class="literal"><span class="pre">__new__</span></tt> method of 'WithCounter' are cooperative.
-<tt class="literal"><span class="pre">WithLogger.__init__</span></tt>
-calls <tt class="literal"><span class="pre">WithCounter.__init__</span></tt> that is
-inherited from <tt class="literal"><span class="pre">CustomizablePizza.__init__</span></tt> which is not cooperative,
-but this is not dangerous since <tt class="literal"><span class="pre">CustomizablePizza.__init__</span></tt> does not need
-to call any other <tt class="literal"><span class="pre">__init__</span></tt>.</p>
-<p>However, <tt class="literal"><span class="pre">PrettyPrinted.__str__</span></tt> and <tt class="literal"><span class="pre">GenericPizza.__str__</span></tt> are not
-cooperative and since 'PrettyPrinted' precedes 'GenericPizza', the
-<tt class="literal"><span class="pre">GenericPizza.__str__</span></tt> method is overridden, which is bad.</p>
-<p>If <tt class="literal"><span class="pre">WithLogger.__init__</span></tt> and <tt class="literal"><span class="pre">WithCounter.__new__</span></tt> were not
-cooperative, they would therefore badly breaking the program.</p>
-<p>The message is: when you inherit from both cooperative and non-cooperative
-classes, put cooperative classes first. The will be fair and will not
-blindly override methods of the non-cooperative classes.</p>
-<p>With multiple inheritance you can reuse old code a lot,
-however the price to pay, is to have a non-trivial hierarchy. If from
-the beginning we knew that 'Pizza' was needing a 'WithLogger',
-a 'WithCounter' and the
-ability to be 'Customizable' we could have put everything in an unique
-class. The problem is that in real life one never knows ;)
-Fortunately, Python dynamism allows to correct design mistakes</p>
-<p>Remark: in all text books about inheritance, the authors always stress
-that inheritance should be used as a &quot;is-a&quot; relation, not
-and &quot;has-a&quot; relation. In spite of this fact, I have decided to implement
-the concept of having a logger (or a counter) via a mixin class. One
-should not blindly believe text books ;)</p>
-</div>
-<div class="section" id="fixing-wrong-hierarchies">
-<h2><a class="toc-backref" href="#id108" name="fixing-wrong-hierarchies">Fixing wrong hierarchies</a></h2>
-<p>A typical metaprogramming technique, is the run-time modification of classes.
-As I said in a previous chapter, this feature can confuse the programmer and
-should not be abused (in particular it should not be used as a replacement
-of inheritance!); nevertheless, there applications where the ability of
-modifying classes at run time is invaluable: for instance,
-it can be used to correct design mistakes.</p>
-<p>In this case we would like the <tt class="literal"><span class="pre">__str__</span> <span class="pre">method</span></tt> of 'PrettyPrinted' to be
-overridden by <tt class="literal"><span class="pre">GenericPizza.__str__</span></tt>. Naively, this can be solved by
-putting 'WithLogger' after 'GenericPizza'. Unfortunately, doing so
-would cause <tt class="literal"><span class="pre">GenericPizza.__init__</span></tt> to override <tt class="literal"><span class="pre">WithLogger.__init__</span></tt>,
-therefore by loosing logging capabilitiesr, unless countermeasures
-are taken.</p>
-<p>A valid countermeasure could be to replace the non-cooperative
-<tt class="literal"><span class="pre">GenericPizza.__init__</span></tt> with a cooperative one. This can miraculously
-done at run time in few lines of code:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def coop_init(self,size): # cooperative __init__ for GenericPizza
- self.size=size
- super(self._GenericPizza__this,self).__init__(size)
-
-GenericPizza.__init__=coop_init # replace the old __init__
-
-reflective(GenericPizza) # define GenericPizza.__this
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Notice the usage of the fully qualified private attribute
-<tt class="literal"><span class="pre">self._GenericPizza__this</span></tt> inside <tt class="literal"><span class="pre">coop_init</span></tt>: since this function
-is defined outside any class, the automatica mangling mechanism cannot
-work and has to be implemented by hand. Notice also that
-<tt class="literal"><span class="pre">super(self._GenericPizza__this,self)</span></tt> could be replaced by
-<tt class="literal"><span class="pre">super(GenericPizza,self)</span></tt>; however the simpler approach is
-less safe against possible future manipulations of the hierarchy.
-Suppose, for example, we want to create a copy of the hierarchy
-with the same name but slightly different features (actually,
-in chapter 8 we will implement a traced copy of the pizza hierarchy,
-useful for debugging purposes): then, using <tt class="literal"><span class="pre">super(GenericPizza,self)</span></tt>
-would raise an error, since self would be an instance of the traced
-hierarchy and <tt class="literal"><span class="pre">GenericPizza</span></tt> the original nontraced class. Using
-the form <tt class="literal"><span class="pre">super(self._GenericPizza__this,self)</span></tt> and making
-<tt class="literal"><span class="pre">self._GenericPizza__this</span></tt> pointing to the traced 'GenericPizza'
-class (actually this will happen automatically) the problems goes
-away.</p>
-<p>Now everything works if 'WithLogger' is put after 'CustomizablePizza'</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; class PizzaWithLog(CustomizablePizza,WithLogger): pass
-&gt;&gt;&gt; PizzaWithLog.With(toppinglist=['tomato'])('large')
-****************************************************************************
-Sun Apr 13 16:19:12 2003
-1. Created large pizza with tomato, cost $ 4.5
-&lt;class '__main__.PizzaWithLog'&gt;
-</pre>
-</blockquote>
-<p>The log correctly says <tt class="literal"><span class="pre">Created</span> <span class="pre">large</span> <span class="pre">pizza</span> <span class="pre">with</span> <span class="pre">tomato,</span> <span class="pre">cost</span> <span class="pre">$</span> <span class="pre">4.5</span></tt> and not
-<tt class="literal"><span class="pre">Created</span> <span class="pre">&lt;Pizza&gt;</span></tt> as before since now <tt class="literal"><span class="pre">GenericPizza.__str__</span></tt>
-overrides <tt class="literal"><span class="pre">PrettyPrinted.__str__</span></tt>. Moreover, the hierarchy is logically
-better organized:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; PizzaWithLog.mro()
-[&lt;class '__main__.PizzaWithLog'&gt;, &lt;class 'oopp.CustomizablePizza'&gt;,
-&lt;class 'oopp.GenericPizza'&gt;, &lt;class 'oopp.Customizable'&gt;,
-&lt;class 'oopp.WithLogger'&gt;, &lt;class 'oopp.WithCounter'&gt;,
-&lt;class 'oopp.PrettyPrinted'&gt;, &lt;type 'object'&gt;]
-</pre>
-</blockquote>
-<p>I leave as an exercise for the reader to make the <tt class="literal"><span class="pre">__str__</span></tt> methods
-cooperative ;)</p>
-<p>Obviously, in this example it would have been better to correct the
-original hierarchy, by leaving 'Beautiful' instantiable from the beginning
-(that's why I said the 'Beautiful' is an example of wrong mix-in class):
-nevertheless, sometimes, one has do to with wrong hierarchies written by
-others, and it can be a pain to fix them, both directly by modifying the
-original source code, and indirectly
-by inheritance, since one must change all the names, in order to distinghish
-the original classes from the fixed ones. In those cases Python
-dynamism can save your life. This also allows you enhance original
-classes which are not wrong, but that simply don't do something you want
-to implement.</p>
-<p>Modifying classes at run-time can be trivial, as in the examples I have
-shown here, but can also be rather tricky, as in this example</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import PrettyPrinted
-&gt;&gt;&gt; class PrettyPrintedWouldBe(object): __str__ = PrettyPrinted.__str__
-&gt;&gt;&gt; print PrettyPrintedWouldBe() #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: unbound method __str__() must be called with PrettyPrinted
-instance as first argument (got nothing instead)
-</pre>
-</blockquote>
-<p>As the error message says, the problem here, is that the
-<tt class="literal"><span class="pre">PrettyPrinted.__str__</span></tt> unbound method, has not received any argument.
-This is because in this
-form <tt class="literal"><span class="pre">PrettyPrintedWouldBe.__str__</span></tt> has been defined as an attribute,
-not as a real method. The solution is to write</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class PrettyPrintedWouldBe(object):
-... __str__ = PrettyPrinted.__dict__['__str__']
-...
-&gt;&gt;&gt; print PrettyPrintedWouldBe() # now it works
-&lt;PrettyPrintedWouldBe&gt;
-</pre>
-</blockquote>
-<p>This kind of run-time modifications does not work when private variables
-are involved:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;changewithprivate.py&gt;
-
-class C(object):
- __x='C.__init__'
- def __init__(self):
- print self.__x # okay
-
-class D(object):
- __x='D.__init__'
- __init__=C.__dict__['__init__'] # error
-
-class New:
- class C(object):
- __x='New.C.__init__'
- __init__=C.__dict__['__init__'] # okay
-
-C()
-try: D()
-except AttributeError,e: print e
-
-#&lt;/changewithprivate.py&gt;
-</pre>
-</blockquote>
-<p>Gives as result</p>
-<blockquote>
-<pre class="literal-block">
-C.__init__
-'D' object has no attribute '_C__x'
-New.C.__init__
-</pre>
-</blockquote>
-<p>The problem is that when <tt class="literal"><span class="pre">C.__dict__['__init__']</span></tt> is compiled
-(to byte-code) <tt class="literal"><span class="pre">self.__x</span></tt> is expanded to <tt class="literal"><span class="pre">self._C__x</span></tt>. However,
-when one invokes <tt class="literal"><span class="pre">D.__init__</span></tt>, a D-object is passed, which has
-a <tt class="literal"><span class="pre">self._D__x</span></tt> attribute, but not a <tt class="literal"><span class="pre">self._C__x</span></tt> attribute (unless
-'D' is a subclass of 'C'. Fortunately, Python wisdom</p>
-<blockquote>
-<em>Namespaces are one honking great idea -- let's do more of those!</em></blockquote>
-<p>suggests the right solution: to use a new class with the <em>same name</em>
-of the old one, but in a different namespace, in order to avoid
-confusion. The simplest way to generate a new namespace is to
-declare a new class (the class 'New' in this example): then 'New.C'
-becomes an inner class of 'New'. Since it has the same name of the
-original class, private variables are correctly expanded and one
-can freely exchange methods from 'C' to 'New.C' (and viceversa, too).</p>
-</div>
-<div class="section" id="modifying-hierarchies">
-<h2><a class="toc-backref" href="#id109" name="modifying-hierarchies">Modifying hierarchies</a></h2>
-<blockquote>
-<pre class="literal-block">
-def mod(cls): return cls
-
-class New: pass
-
-for c in HomoSapiensSapiens.__mro__:
- setattr(New,c.__name__,mod(c))
-</pre>
-</blockquote>
-</div>
-<div class="section" id="inspecting-python-code">
-<h2><a class="toc-backref" href="#id110" name="inspecting-python-code">Inspecting Python code</a></h2>
-<p>how to inspect a class, by retrieving useful informations about its
-information.</p>
-<p>A first possibility is to use the standard <tt class="literal"><span class="pre">help</span></tt> function.
-The problem of this approach is that <tt class="literal"><span class="pre">help</span></tt> gives too much
-information.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-#plaindata=
-plainmethod=lambda m:m #identity function
-
-class Get(object):
- &quot;&quot;&quot;Invoked as Get(cls)(xxx) where xxx = staticmethod, classmethod,
- property, plainmethod, plaindata, returns the corresponding
- attributes as a keyword dictionary. It works by internally calling
- the routine inspect.classify_class_attrs. Notice that data
- attributes with double underscores are not retrieved
- (this is by design).&quot;&quot;&quot;
- def __init__(self,cls):
- self.staticmethods=kwdict()
- self.classmethods=kwdict()
- self.properties=kwdict()
- self.methods=kwdict()
- self.data=kwdict()
- for name, kind, klass, attr in inspect.classify_class_attrs(cls):
- if kind=='static method':
- self.staticmethods[name]=attr
- elif kind=='class method':
- self.classmethods[name]=attr
- elif kind=='property':
- self.properties[name]=attr
- elif kind=='method':
- self.methods[name]=attr
- elif kind=='data':
- if not special(name): self.data[name]=attr
- def __call__(self,descr): #could be done with a dict
- if descr==staticmethod: return self.staticmethods
- elif descr==classmethod: return self.classmethods
- elif descr==property: return self.properties
- elif descr==plainmethod: return self.methods
- elif descr==plaindata: return self.data
- else: raise SystemExit(&quot;Invalid descriptor&quot;)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>With similar tricks one can automatically recognize cooperative methods:
-#it is different, (better NOT to use descriptors)</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-#class Cooperative(Class):
-# __metaclass__ = WithWrappingCapabilities
-#
-# def cooperative(method):
-# &quot;&quot;&quot;Calls both the superclass method and the class
-# method (if the class has an explicit method).
-# Works for methods returning None.&quot;&quot;&quot;
-# name,cls=Cooperative.parameters # fixed by the meta-metaclass
-# def _(*args,**kw):
-# getattr(super(cls,args[0]),name)(*args[1:],**kw)
-# if method: method(*args,**kw) # call it
-# return _
-#
-# cooperative=staticmethod(cooperative)
-
-
-#&lt;/oopp.py&gt;
-</pre>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def wrapH(cls):
- for c in cls.__mro__[:-2]:
- tracer.namespace=c.__name__
- new=vars(c).get('__new__',None)
- if new: c.__new__=tracedmethod(new)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-</div>
-</div>
-<div class="section" id="the-magic-of-metaclasses-part-i">
-<h1><a class="toc-backref" href="#id111" name="the-magic-of-metaclasses-part-i">THE MAGIC OF METACLASSES - PART I</a></h1>
-<blockquote>
-<pre class="line-block">
-<em>Metaclasses are deeper magic than 99% of users should ever
-worry about. If you wonder whether you need them, you don't
-(the people who actually need them know with certainty that
-they need them, and don't need an explanation about why).</em>
---Tim Peters
-</pre>
-</blockquote>
-<p>Python always had metaclasses, since they are inherent to its object
-model. However, before Python 2.2, metaclasses where tricky and their
-study could cause the programmer's brain to explode <a class="footnote-reference" href="#id42" id="id44" name="id44">[21]</a>. Nowadays,
-the situation has changed, and the reader should be able to understand
-this chapter without risk for his/her brain (however I do not give any
-warranty ;)</p>
-<p>Put it shortly, metaclasses give to the Python programmer
-complete control on the creation of classes. This simple statement
-has far reaching consequences, since the ability of interfering with
-the process of class creation, enable the programmer to make miracles.</p>
-<p>In this and in the following chapters, I will show some of these
-miracles.</p>
-<p>This chapter will focus on subtle problems of metaclasses in inheritance
-and multiple inheritance, including multiple inheritance of metaclasses
-with classes and metaclasses with metaclasses.</p>
-<p>The next chapter will focus more on applications.</p>
-<table class="footnote" frame="void" id="id45" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a name="id45">[23]</a></td><td>Metaclasses in Python 1.5 [A.k.a the killer joke]
-<a class="reference" href="http://www.python.org/doc/essays/metaclasses/">http://www.python.org/doc/essays/metaclasses/</a></td></tr>
-</tbody>
-</table>
-<p>There is very little documentation about metaclasses, except Guido's
-essays and the papers by David Mertz and myself published in IBMdeveloperWorks</p>
-<blockquote>
-<a class="reference" href="http://www-106.ibm.com/developerworks/library/l-pymeta.html">http://www-106.ibm.com/developerworks/library/l-pymeta.html</a></blockquote>
-<div class="section" id="metaclasses-as-class-factories">
-<h2><a class="toc-backref" href="#id112" name="metaclasses-as-class-factories">Metaclasses as class factories</a></h2>
-<p>In the Python object model (inspired from the Smalltalk, that had metaclasses
-a quarter of century ago!) classes themselves are objects.
-Now, since objects are instances of classes, that means that classes
-themselves can be seen as instances of special classes called <em>metaclasses</em>.
-Notice that things get hairy soon, since by following this idea, one could
-say the metaclasses themselves are classes and therefore objects; that
-would mean than even metaclasses can be seen as
-instances of special classes called meta-metaclasses. On the other hand,
-meta-meta-classes can be seen as instances of meta-meta-metaclasses,
-etc. Now, it should be obvious why metaclasses have gained such a
-reputation of brain-exploders ;). However, fortunately, the situation
-is not so bad in practice, since the infinite recursion of metaclasses is
-avoided because there is a metaclass that is the &quot;mother of all metaclasses&quot;:
-the built-in metaclass <em>type</em>. 'type' has the property of being its own
-metaclass, therefore the recursion stops. Consider for instance the following
-example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object): pass # a generic class
-&gt;&gt;&gt; type(C) #gives the metaclass of C
-&lt;type 'type'&gt;
-&gt;&gt;&gt; type(type(C)) #gives the metaclass of type
-&lt;type 'type'&gt;
-</pre>
-</blockquote>
-<p>The recursion stops, since the metaclass of 'type' is 'type'.
-One cool consequence of classes being instances of 'type',
-is that since <em>type</em> is a subclass of object,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; issubclass(type,object)
-True
-</pre>
-</blockquote>
-<p>any Python class is not only a subclass of <tt class="literal"><span class="pre">object</span></tt>, but also
-an instance of 'object':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; isinstance(C,type)
-True
-&gt;&gt;&gt; isinstance(C,object)
-True
-&gt;&gt;&gt; issubclass(C,object)
-True
-</pre>
-</blockquote>
-<p>Notice that 'type' is an instance of itself (!) and therefore of 'object':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; isinstance(type,type) # 'type' is an instance of 'type'
-True
-&gt;&gt;&gt; isinstance(type,object) # therefore 'type' is an instance of 'object'
-True
-</pre>
-</blockquote>
-<p>As it is well known, <tt class="literal"><span class="pre">type(X)</span></tt> returns the type of <tt class="literal"><span class="pre">X</span></tt>; however,
-<tt class="literal"><span class="pre">type</span></tt> has also a second form in which it acts as a class factory.
-The form is <tt class="literal"><span class="pre">type(name,bases,dic)</span></tt> where <tt class="literal"><span class="pre">name</span></tt> is the name of
-the new class to be created, bases is the tuple of its bases and dic
-is the class dictionary. Let me give a few examples:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C=type('C',(),{})
-&gt;&gt;&gt; C
-&lt;class '__main__.C'&gt;
-&gt;&gt;&gt; C.__name__
-'C'
-&gt;&gt;&gt; C.__bases__
-(&lt;type 'object'&gt;,)
-&gt;&gt;&gt; C.__dict__
-&lt;dict-proxy object at 0x8109054&gt;
-</pre>
-</blockquote>
-<p>Notice that since all metaclasses inherits from <tt class="literal"><span class="pre">type</span></tt>, as a consequences
-all metaclasses can be used as class factories.</p>
-<p>A fairy tale example will help in understanding the concept
-and few subtle points on how attributes are transmitted from metaclasses
-to their instances.</p>
-<p>Let me start by defining a 'Nobility' metaclass :</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Nobility(type): attributes=&quot;Power,Richness,Beauty&quot;
-</pre>
-</blockquote>
-<p>instances of 'Nobility' are classes such 'Princes', 'Dukes', 'Barons', etc.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Prince=Nobility(&quot;Prince&quot;,(),{})
-</pre>
-</blockquote>
-<p>Instances of 'Nobility' inherits its attributes, just as instances of normal
-classes inherits the class docstring:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Prince.attributes
-'Power,Richness,Beauty'
-</pre>
-</blockquote>
-<p>Nevertheless, 'attributes' will not be retrieved by the <tt class="literal"><span class="pre">dir</span></tt> function:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print dir(Prince)
-['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
- '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__repr__',
- '__setattr__', '__str__', '__weakref__']
-</pre>
-</blockquote>
-<p>However, this is a limitation of <tt class="literal"><span class="pre">dir</span></tt>, in reality <tt class="literal"><span class="pre">Prince.attributes</span></tt>
-is there. On the other hand, the situation is different for a specific
-'Prince' object</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; charles=Prince()
-&gt;&gt;&gt; charles.attributes #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'Prince' object has no attribute 'attributes'
-</pre>
-</blockquote>
-<p>The transmission of metaclass attributes is not transitive:
-instances of the metaclass inherits the attributes, but not the instances
-of the instances. This behavior is by design and is needed in order to avoid
-troubles with special methods. This point will be throughly
-explained in the last paragraph. For the moment, I my notice that the
-behaviour is reasonable, since the abstract qualities 'Power,Richness,Beauty'
-are more qualities of the 'Prince' class than of one specific representative.
-They can always be retrieved via the <tt class="literal"><span class="pre">__class__</span></tt> attribute:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; charles.__class__.attributes
-'Power,Richness,Beauty'
-</pre>
-</blockquote>
-<p>Le me now define a metaclass 'Froggyness':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Frogginess(type): attributes=&quot;Powerlessness,Poverty,Uglyness&quot;
-</pre>
-</blockquote>
-<p>Instances of 'Frogginess' are classes like 'Frog', 'Toad', etc.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Frog=Frogginess(&quot;Frog&quot;,(),{})
-&gt;&gt;&gt; Frog.attributes
-'Powerlessness,Poverty,Uglyness'
-</pre>
-</blockquote>
-<p>However, in Python miracles can happen:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def miracle(Frog): Frog.__class__=Nobility
-&gt;&gt;&gt; miracle(Frog); Frog.attributes
-'Powerlessness,Richness,Beauty'
-</pre>
-</blockquote>
-<p>In this example a miracle happened on the class 'Frog', by changing its
-(meta)class to 'Nobility'; therefore its attributes have changed accordingly.</p>
-<p>However, there is subtle point here. Suppose we explicitly specify the 'Frog'
-attributes, in such a way that it can be inherited by one of its specific
-representative:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Frog.attributes=&quot;poor, small, ugly&quot;
-&gt;&gt;&gt; jack=Frog(); jack.attributes
-'poor, small, ugly'
-</pre>
-</blockquote>
-<p>Then the miracle cannot work:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;fairytale2.py&gt;
-
-class Nobility(type): attributes=&quot;Power, Richness, Beauty&quot;
-Prince=Nobility(&quot;Prince&quot;,(),{})
-charles=Prince()
-
-class Frogginess(type): attributes=&quot;Inpuissance, Poverty, Uglyness&quot;
-Frog=Frogginess(&quot;Frog&quot;,(),{})
-Frog.attributes=&quot;poor, small, ugly&quot;
-jack=Frog()
-
-def miracle(Frog): Frog.__class__=Nobility
-
-miracle(Frog)
-
-print &quot;I am&quot;,Frog.attributes,&quot;even if my class is&quot;,Frog.__class__
-
-#&lt;/fairytale2.py&gt;
-</pre>
-</blockquote>
-<p>Output:</p>
-<blockquote>
-<pre class="literal-block">
-I am poor, small, ugly even if my class is &lt;class '__main__.Nobility'&gt;
-</pre>
-</blockquote>
-<p>The reason is that Python first looks at specific attributes of an object
-(in this case the object is the class 'Frog') an only if they are not found,
-it looks at the attributes of its class (here the metaclass 'Nobility').Since
-in this example the 'Frog' class has explicit attributes, the
-result is <tt class="literal"><span class="pre">poor,</span> <span class="pre">small,</span> <span class="pre">ugly</span></tt>. If you think a bit, it makes sense.</p>
-<p>Remark:</p>
-<p>In Python 2.3 there are restrictions when changing the <tt class="literal"><span class="pre">__class__</span></tt>
-attribute for classes:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C=type('C',(),{})
-&gt;&gt;&gt; C.__class__ = Nobility #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: __class__ assignment: only for heap types
-</pre>
-</blockquote>
-<p>Here changing <tt class="literal"><span class="pre">C.__class__</span></tt> is not allowed, since 'C' is an instance
-of the built-in metaclass 'type'. This restriction, i.e. the fact that
-the built-in metaclass cannot be changed, has been imposed for
-security reasons, in order to avoid dirty tricks with the built-in
-classes. For instance, if it was possible to change the metaclass
-of the 'bool' class, we could arbitrarily change the behavior of
-boolean objects. This could led to abuses.
-Thanks to this restriction,
-the programmer is always sure that built-in classes behaves as documented.
-This is also the reason why 'bool' cannot be subclassed:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print bool.__doc__ # in Python 2.2 would give an error
-bool(x) -&gt; bool
-Returns True when the argument x is true, False otherwise.
-The builtins True and False are the only two instances of the class bool.
-The class bool is a subclass of the class int, and cannot be subclassed.
-</pre>
-</blockquote>
-<p>In any case, changing the class of a class is not a good idea, since it
-does not play well with inheritance, i.e. changing the metaclass of a base
-class does not change the metaclass of its children:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M1(type): f=lambda cls: 'M1.f' #metaclass1
-&gt;&gt;&gt; class M2(type): f=lambda cls: 'M2.f' #metaclass2
-&gt;&gt;&gt; B=M1('B',(),{}) # B receives M1.f
-&gt;&gt;&gt; class C(B): pass #C receives M1.f
-&gt;&gt;&gt; B.f()
-'M1.f'
-B.__class__=M2 #change the metaclass
-&gt;&gt;&gt; B.f() #B receives M2.f
-'M2.f'
-C.f() #however C does *not* receive M2.f
-&gt;&gt;&gt; C.f()
-'M1.f'
-&gt;&gt;&gt; type(B)
-&lt;class '__main__.M2'&gt;
-&gt;&gt;&gt; type(C)
-&lt;class '__main__.M1'&gt;
-</pre>
-</blockquote>
-</div>
-<div class="section" id="metaclasses-as-class-modifiers">
-<h2><a class="toc-backref" href="#id113" name="metaclasses-as-class-modifiers">Metaclasses as class modifiers</a></h2>
-<p>The interpretation of metaclasses in terms of class factories is quite
-straightforward and I am sure that any Pythonista will be at home
-with the concept. However, metaclasses have such a reputation of black
-magic since their typical usage is <em>not</em> as class factories, but as
-<em>class modifiers</em>. This means that metaclasses are typically
-used to modify <em>in fieri</em> classes. The trouble is that the
-modification can be utterly magical.
-Here there is another fairy tale example showing the syntax
-(via the <tt class="literal"><span class="pre">__metaclass__</span></tt> hook) and the magic of the game:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class UglyDuckling(PrettyPrinted):
- &quot;A plain, regular class&quot;
- formatstring=&quot;Not beautiful, I am %s&quot;
-
-class MagicallyTransformed(type):
- &quot;Metaclass changing the formatstring of its instances&quot;
- def __init__(cls,*args):
- cls.formatstring=&quot;Very beautiful, since I am %s&quot;
-
-class TransformedUglyDuckling(PrettyPrinted):
- &quot;A class metamagically modified&quot;
- __metaclass__ = MagicallyTransformed
- formatstring=&quot;Not beautiful, I am %s&quot; # will be changed
-
-#&lt;/oopp.py&gt;
-
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; print UglyDuckling()
-Not beautiful, I am &lt;UglyDuckling&gt;
-</pre>
-</blockquote>
-<p>In this example, even if in 'TransformedUglyDuckling' we explicitely
-set the formatstring to &quot;Not beautiful, I am %s&quot;, the metaclass changes
-it to &quot;Very beautiful, even if I am %s&quot; and thus</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print TransformedUglyDuckling() # gives
-Very beautiful, since I am &lt;TransformedUglyDuckling&gt;
-</pre>
-</blockquote>
-<p>Notice that the <tt class="literal"><span class="pre">__metaclass__</span></tt> hook passes to the metaclass
-<tt class="literal"><span class="pre">MagicallyTransformed</span></tt> the name, bases and dictionary of the class
-being created, i.e. 'TransformedUglyDucking'.</p>
-<p>Metaclasses, when used as class modifiers, act <em>differently</em>
-from functions, when inheritance is
-involved. To clarify this subtle point, consider a subclass 'Swan'
-of 'UglyDuckling':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; class Swan(UglyDuckling):
-... formatstring=&quot;Very beautiful, I am %s&quot;
-&gt;&gt;&gt; print Swan()
-Very beautiful, I am &lt;Swan&gt;
-</pre>
-</blockquote>
-<p>Now, let me define a simple function acting as a class modifier:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def magicallyTransform(cls):
-... &quot;Modifies the class formatstring&quot;
-... customize(cls,formatstring=&quot;Very beautiful, even if I am %s&quot;)
-... return cls
-</pre>
-</blockquote>
-<p>The function works:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; magicallyTransform(UglyDuckling)
-&gt;&gt;&gt; print UglyDuckling()
-Very beautiful, even if I am &lt;UglyDuckling&gt;
-</pre>
-</blockquote>
-<p>This approach is destructive, since we cannot have the original
-and the transformed class at the same time, and has potentially bad side
-effects in the derived classes. Nevertheless, in this case it works
-and it is not dangereous for the derived class 'Swan', since 'Swan'
-explicitly overrides the 'formatstring' attribute and doesn't care about
-the change in 'UglyDuckling.formatstring'. Therefore the output
-of</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print Swan()
-Very beautiful, I am &lt;Swan&gt;
-</pre>
-</blockquote>
-<p>is still the same as before the action of the function <tt class="literal"><span class="pre">magicallyTransform</span></tt>.
-The situation is quite different if we use the 'MagicallyTransformed'
-metaclass:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; class Swan(TransformedUglyDuckling):
-... formatstring=&quot;Very beautiful, I am %s&quot;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; print TransformedUglyDuckling()
-Very beautiful, since I am &lt;UglyDuckling&gt;
-&gt;&gt;&gt; print Swan() # does *not* print &quot;Very beautiful, I am &lt;Swan&gt;&quot;
-Very beautiful, since I am &lt;Swan&gt;
-</pre>
-</blockquote>
-<p>Therefore, not only the metaclass has magically transformed the
-'TransformedUglyDuckling.formatstring', it has also transformed the
-'Swan.formatstring'! And that, despite the fact that
-'Swan.formatstring' is explicitly set.</p>
-<p>The reason for this behaviour is that since 'UglyDuckling' is a base
-class with metaclass 'MagicallyTransformed', and since 'Swan' inherits from
-'UglyDuckling', then 'Swan' inherits the metaclass 'MagicallyTransformed',
-which is automatically called at 'Swan' creation time.
-That's the reason why metaclasses are much more magical and much
-more dangerous than
-functions: functions do not override attributes in the derived classes,
-metaclasses do, since they are automagically called at the time of
-creation of the subclass. In other words, functions are explicit,
-metaclasses are implicit. Nevertheless, this behavior can be pretty
-useful in many circumstances, and it is a feature, not a bug. In the
-situations where this behavior is not intended, one should use a function,
-not a metaclass. In general, metaclasses are better than functions,
-since metaclasses are classes and as such they can inherit one from each
-other. This means that one can improve a basic metaclass trough
-(multiple) inheritance, with <em>reuse</em> of code.</p>
-</div>
-<div class="section" id="a-few-caveats-about-the-usage-of-metaclasses">
-<h2><a class="toc-backref" href="#id114" name="a-few-caveats-about-the-usage-of-metaclasses">A few caveats about the usage of metaclasses</a></h2>
-<p>Let me start with some caveats about the <tt class="literal"><span class="pre">__metaclass__</span></tt> hook, which
-commonly used and quite powerful, but also quite dangereous.</p>
-<p>Let's imagine a programmer not
-knowing about metaclasses and looking at the 'TransformedUglyDuckling'
-code (assuming there are no comments): she would probably think
-that &quot;__metaclass__&quot; is some special attribute used for introspection
-purposes only, with no other effects, and she would probably expect
-the output of the script to be &quot;Not much, I am the class
-TransformedUglyDucking&quot; whereas it is exacly the contrary! In other
-words, when metaclasses are involved, <em>what you see, is not what you get</em>.
-The situation is even more implicit when the metaclass is inherited
-from some base class, therefore lacking also the visual clue of the hook.</p>
-<p>For these reasons, metaclasses are something to be used with great care;
-they can easily make your code unreadable and confuse inexpert programmers.
-Moreover, it is more difficult to debug programs involving metaclasses, since
-methods are magically transformed by routines defined in the metaclass,
-and the code you see in the class is <em>not</em> what Python sees. I think
-the least confusing way of using metaclasses, is to concentrate all
-the dynamics on them and to write empty classes except for the
-metaclass hook. If you write a class with no methods such as</p>
-<blockquote>
-<pre class="literal-block">
-class TransformedUglyDuckling(object):
- __metaclass__=MagicallyTransformed
-</pre>
-</blockquote>
-<p>then the only place to look at, is the metaclass. I have found extremely
-confusing to have some of the methods defined in the class and some in
-the metaclass, especially during debugging.</p>
-<p>Another point to make, is that the <tt class="literal"><span class="pre">__metaclass__</span></tt>
-hook should not be used to modify pre-existing classes,
-since it requires modifying the source code (even if it is enough to
-change one line only). Moreover, it is confusing, since adding a
-<tt class="literal"><span class="pre">__metaclass__</span></tt> attribute <em>after</em> the class creation would not do the job:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import UglyDuckling, MagicallyTransformed
-&gt;&gt;&gt; UglyDuckling.__metaclass__=MagicallyTransformed
-&gt;&gt;&gt; print UglyDuckling()
-&quot;Not much, I am the class UglyDuckling&quot;
-</pre>
-</blockquote>
-<p>The reason is that we have to think of UglyDuckling as an instance of
-<tt class="literal"><span class="pre">type</span></tt>, the built-in metaclasses; merely adding a <tt class="literal"><span class="pre">__metaclass__</span></tt>
-attribute does not re-initialize the class.
-The problem is elegantly solved by avoiding the hook and creating
-an enhanced copy of the original class trough <tt class="literal"><span class="pre">MagicallyTransformed</span></tt>
-used as a class factory.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; name=UglyDuckling.__name__
-&gt;&gt;&gt; bases=UglyDuckling.__bases__
-&gt;&gt;&gt; dic=UglyDuckling.__dict__.copy()
-&gt;&gt;&gt; UglyDuckling=MagicallyTransformed(name,bases,dic)
-</pre>
-</blockquote>
-<p>Notice that I have recreated 'UglyDuckling', giving to the new class
-the old identifier.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print UglyDuckling()
-Very beautiful, since I am &lt;UglyDuckling&gt;&gt;
-</pre>
-</blockquote>
-<p>The metaclass of this new 'UglyDuckling' has been specified and will
-accompanies all future children of 'UglyDuckling':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Swan(UglyDuckling): pass
-...
-&gt;&gt;&gt; type(Swan)
-&lt;class '__main__.MagicallyTransformed'&gt;
-</pre>
-</blockquote>
-<p>Another caveat, is in the overridding of `` __init__`` in the metaclass.
-This is quite common in the case of metaclasses called trough the
-<tt class="literal"><span class="pre">__metaclass__</span></tt> hook mechanism, since in this case the class
-has been already defined (if not created) in the class statement,
-and we are interested in initializing it, more than in recreating
-it (which is still possible, by the way).
-The problem is that overriding <tt class="literal"><span class="pre">__init__</span></tt> has severe limitations
-with respect to overriding <tt class="literal"><span class="pre">__new__</span></tt>,
-since the 'name', 'bases' and 'dic' arguments cannot be directly
-changed. Let me show an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;init_in_metaclass.py&gt;
-
-from oopp import *
-
-class M(type):
- &quot;Shows that dic cannot be modified in __init__, only in __new__&quot;
- def __init__(cls,name,bases,dic):
- name='C name cannot be changed in __init__'
- bases='cannot be changed'
- dic['changed']=True
-
-class C(object):
- __metaclass__=M
- changed=False
-
-print C.__name__ # =&gt; C
-print C.__bases__ # =&gt; (&lt;type 'object'&gt;,)
-print C.changed # =&gt; False
-
-#&lt;/init_in_metaclass.py&gt;
-</pre>
-</blockquote>
-<p>The output of this script is <tt class="literal"><span class="pre">False</span></tt>: the dictionary cannot be changed in
-<tt class="literal"><span class="pre">__init__</span></tt> method. However, replacing <tt class="literal"><span class="pre">dic['changed']=True</span></tt> with
-<tt class="literal"><span class="pre">cls.changed=True</span></tt> would work. Analougously, changing <tt class="literal"><span class="pre">cls.__name__</span></tt>
-would work. On the other hand, <tt class="literal"><span class="pre">__bases__</span></tt> is a read-only attribute and
-cannot be changed once the class has been created, therefore there is no
-way it can be touched in <tt class="literal"><span class="pre">__init__</span></tt>. However, <tt class="literal"><span class="pre">__bases__</span></tt> could be
-changed in <tt class="literal"><span class="pre">__new__</span></tt> before the class creation.</p>
-</div>
-<div class="section" id="metaclasses-and-inheritance">
-<h2><a class="toc-backref" href="#id115" name="metaclasses-and-inheritance">Metaclasses and inheritance</a></h2>
-<p>It is easy to get confused about the difference between a metaclass
-and a mix-in class in multiple inheritance, since
-both are denoted by adjectives and both share the same idea of
-enhancing a hierarchy. Moreover, both mix-in classes and metaclasses
-can be inherited in the whole hierarchy.
-Nevertheless, they behaves differently
-and there are various subtle point to emphasize. We have already
-noticed in the first section that attributes of a metaclass
-are transmitted to its instances, but not to the instances of the
-instances, whereas the normal inheritance is transitive: the
-grandfather transmits its attributes to the children and to the grandchild
-too. The difference can be represented with the following picture, where
-'M' is the metaclass, 'B' a base class, 'C' a children of 'B'
-and c an instance of 'C':</p>
-<blockquote>
-<pre class="literal-block">
-M (attr) B (attr)
-: |
-C (attr) C (attr)
-: :
-c () c (attr)
-</pre>
-</blockquote>
-<p>Notice that here the relation of instantiation is denoted by a dotted line.</p>
-<p>This picture is valid when C has metaclass M but not base class, on when C
-has base class but not metaclass. However, what happens whrn the class C has
-both a metaclass M and a base class B ?</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(type): a='M.a'
-&gt;&gt;&gt; class B(object): a='B.a'
-&gt;&gt;&gt; class C(B): __metaclass__=M
-&gt;&gt;&gt; c=C()
-</pre>
-</blockquote>
-<p>The situation can be represented by in the following graph,</p>
-<blockquote>
-<pre class="literal-block">
-(M.a) M B (B.a)
- : /
- : /
- (?) C
- :
- :
- (?) c
-</pre>
-</blockquote>
-<p>Here the metaclass M and the base class B are fighting one against the other.
-Who wins ? C should inherit the attribute 'B.a' from its base B, however,
-the metaclass would like to induce an attribute 'M.a'.
-The answer is that the inheritance constraint wins on the metaclass contraint:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.a
-'B.a'
-&gt;&gt;&gt; c.a
-'B.a'
-</pre>
-</blockquote>
-<p>The reason is the same we discussed in the fairy tale example: 'M.a' is
-an attribute of the metaclass, if its instance C has already a specified
-attributed C.a (in this case specified trough inheritance from B), then
-the attribute is not modified. However, one could <em>force</em> the modification:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(type):
-... def __init__(cls,*args): cls.a='M.a'
-&gt;&gt;&gt; class C(B): __metaclass__=M
-&gt;&gt;&gt; C.a
-'M.a'
-</pre>
-</blockquote>
-<p>In this case the metaclass M would win on the base class B. Actually,
-this is not surprising, since it is explicit. What could be surprising,
-had we not explained why inheritance silently wins, is that</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.a
-'B.a'
-</pre>
-</blockquote>
-<p>This explain the behaviour for special methods like
-<tt class="literal"><span class="pre">__new__,__init__,__str__</span></tt>,
-etc. which are defined both in the class and the metaclass with the same
-name (in both cases,they are inherited from <tt class="literal"><span class="pre">object</span></tt>).</p>
-<p>In the chapter on objects, we learned that the printed representation of
-an object can be modified by overring the <tt class="literal"><span class="pre">__str__</span></tt> methods of its
-class. In the same sense, the printed representation of a class can be
-modified by overring the <tt class="literal"><span class="pre">__str__</span></tt> methods of its metaclass. Let me show an
-example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Printable(PrettyPrinted,type):
- &quot;&quot;&quot;Apparently does nothing, but actually makes PrettyPrinted acting as
- a metaclass.&quot;&quot;&quot;
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Instances of 'Printable' are classes with a nice printable representation:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import Printable
-&gt;&gt;&gt; C=Printable('Classname',(),{})
-&gt;&gt;&gt; print C
-Classname
-</pre>
-</blockquote>
-<p>However, the internal string representation stays the same:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C # invokes Printable.__repr__
-&lt;class '__main__.Classname'&gt;
-</pre>
-</blockquote>
-<p>Notice that the name of class 'C' is <tt class="literal"><span class="pre">Classname</span></tt> and not 'C' !</p>
-<p>Consider for instance the following code:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(type):
-... def __str__(cls):
-... return cls.__name__
-... def method(cls):
-... return cls.__name__
-...
-&gt;&gt;&gt; class C(object):
-... __metaclass__=M
-&gt;&gt;&gt; c=C()
-</pre>
-</blockquote>
-<p>In this case the <tt class="literal"><span class="pre">__str__</span></tt> method in <tt class="literal"><span class="pre">M</span></tt> cannot override the
-<tt class="literal"><span class="pre">__str__</span></tt> method in C, which is inherited from <tt class="literal"><span class="pre">object</span></tt>.
-Moreover, if you experiment a little, you will see that</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print C # is equivalent to print M.__str__(C)
-C
-&gt;&gt;&gt; print c # is equivalent to print C.__str__(c)
-&lt;__main__.C object at 0x8158f54&gt;
-</pre>
-</blockquote>
-<p>The first <tt class="literal"><span class="pre">__str__</span></tt> is &quot;attached&quot; to the metaclass and the
-second to the class.</p>
-<p>Consider now the standard method &quot;method&quot;. It is both attached to the
-metaclass</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print M.method(C)
-C
-</pre>
-</blockquote>
-<p>and to the class</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print C.method() #in a sense, this is a class method, i.e. it receives
-C #the class as first argument
-</pre>
-</blockquote>
-<p>Actually it can be seen as a class method of 'C' (cfr. Guido van Rossum
-&quot;Unifying types and classes in Python 2.2&quot;. When he discusses
-classmethods he says: <em>&quot;Python also has real metaclasses, and perhaps
-methods defined in a metaclass have more right to the name &quot;class method&quot;;
-but I expect that most programmers won't be using metaclasses&quot;</em>). Actually,
-this is the SmallTalk terminology, Unfortunately, in Python the word
-<tt class="literal"><span class="pre">classmethod</span></tt> denotes an attribute descriptor, therefore it is better
-to call the methods defined in a metaclass <em>metamethods</em>, in order to avoid
-any possible confusion.</p>
-<p>The difference between <tt class="literal"><span class="pre">method</span></tt> and <tt class="literal"><span class="pre">__str__</span></tt> is that you cannot use the
-syntax</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print C.__str__() #error
-TypeError: descriptor '__str__' of 'object' object needs an argument
-</pre>
-</blockquote>
-<p>because of the confusion with the other __str__; you can only use the
-syntax</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print M.__str__(C)
-</pre>
-</blockquote>
-<p>Suppose now I change C's definition by adding a method called &quot;method&quot;:</p>
-<blockquote>
-<pre class="literal-block">
-class C(object):
- __metaclass__=M
- def __str__(self):
- return &quot;instance of %s&quot; % self.__class__
- def method(self):
- return &quot;instance of %s&quot; % self.__class__
-</pre>
-</blockquote>
-<p>If I do so, then there is name clashing and the previously working
-statement print C.method() gives now an error:</p>
-<blockquote>
-<pre class="literal-block">
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 24, in ?
-TypeError: unbound method method() must be called with C instance as
-first argument (got nothing instead)
-</pre>
-</blockquote>
-<p>Conclusion: <tt class="literal"><span class="pre">__str__,</span> <span class="pre">__new__,</span> <span class="pre">__init__</span></tt> etc. defined in the metaclass
-have name clashing with the standard methods defined in the class, therefore
-they must be invoked with the extended syntax (ex. <tt class="literal"><span class="pre">M.__str__(C)</span></tt>),
-whereas normal methods in the metaclass with no name clashing with the methods
-of the class can be used as class methods (ex. <tt class="literal"><span class="pre">C.method()</span></tt> instead of
-<tt class="literal"><span class="pre">M.method(C)</span></tt>).
-Metaclass methods are always bound to the metaclass, they bind to the class
-(receiving the class as first argument) only if there is no name clashing with
-already defined methods in the class. Which is the case for <tt class="literal"><span class="pre">__str__</span></tt>,
-<tt class="literal"><span class="pre">___init__</span></tt>, etc.</p>
-</div>
-<div class="section" id="conflicting-metaclasses">
-<h2><a class="toc-backref" href="#id116" name="conflicting-metaclasses">Conflicting metaclasses</a></h2>
-<p>Consider a class 'A' with metaclass 'M_A' and a class 'B' with
-metaclass 'M_B'; suppose I derive 'C' from 'A' and 'B'. The question is:
-what is the metaclass of 'C' ? Is it 'M_A' or 'M_B' ?</p>
-<p>The correct answer (see &quot;Putting metaclasses to work&quot; for a thought
-discussion) is 'M_C', where 'M_C' is a metaclass that inherits from
-'M_A' and 'M_B', as in the following graph:</p>
-<blockquote>
-<div class="figure">
-<p><img alt="fig1.gif" src="fig1.gif" /></p>
-</div>
-</blockquote>
-<p>However, Python is not yet that magic, and it does not automatically create
-'M_C'. Instead, it will raise a <tt class="literal"><span class="pre">TypeError</span></tt>, warning the programmer of
-the possible confusion:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M_A(type): pass
-&gt;&gt;&gt; class M_B(type): pass
-&gt;&gt;&gt; A=M_A('A',(),{})
-&gt;&gt;&gt; B=M_B('B',(),{})
-&gt;&gt;&gt; class C(A,B): pass #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: metatype conflict among bases
-</pre>
-</blockquote>
-<p>This is an example where the metaclasses 'M_A' and 'M_B' fight each other
-to generate 'C' instead of cooperating. The metatype conflict can be avoided
-by assegning the correct metaclass to 'C' by hand:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(A,B): __metaclass__=type(&quot;M_AM_B&quot;,(M_A,M_B),{})
-&gt;&gt;&gt; type(C)
-&lt;class '__main__.M_AM_B'&gt;
-</pre>
-</blockquote>
-<p>In general, a class A(B, C, D , ...) can be generated without conflicts only
-if type(A) is a subclass of each of type(B), type(C), ...</p>
-<p>In order to avoid conflicts, the following function, that generates
-the correct metaclass by looking at the metaclasses of the base
-classes, is handy:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-metadic={}
-
-def _generatemetaclass(bases,metas,priority):
- trivial=lambda m: sum([issubclass(M,m) for M in metas],m is type)
- # hackish!! m is trivial if it is 'type' or, in the case explicit
- # metaclasses are given, if it is a superclass of at least one of them
- metabs=tuple([mb for mb in map(type,bases) if not trivial(mb)])
- metabases=(metabs+metas, metas+metabs)[priority]
- if metabases in metadic: # already generated metaclass
- return metadic[metabases]
- elif not metabases: # trivial metabase
- meta=type
- elif len(metabases)==1: # single metabase
- meta=metabases[0]
- else: # multiple metabases
- metaname=&quot;_&quot;+''.join([m.__name__ for m in metabases])
- meta=makecls()(metaname,metabases,{})
- return metadic.setdefault(metabases,meta)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>This function is particularly smart since:</p>
-<blockquote>
-<ol class="arabic simple">
-<li>Avoid duplications ..</li>
-<li>Remember its results.</li>
-</ol>
-</blockquote>
-<p>We may generate the child of a tuple of base classes with a given metaclass
-and avoiding metatype conflicts thanks to the following <tt class="literal"><span class="pre">child</span></tt> function:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def makecls(*metas,**options):
- &quot;&quot;&quot;Class factory avoiding metatype conflicts. The invocation syntax is
- makecls(M1,M2,..,priority=1)(name,bases,dic). If the base classes have
- metaclasses conflicting within themselves or with the given metaclasses,
- it automatically generates a compatible metaclass and instantiate it.
- If priority is True, the given metaclasses have priority over the
- bases' metaclasses&quot;&quot;&quot;
-
- priority=options.get('priority',False) # default, no priority
- return lambda n,b,d: _generatemetaclass(b,metas,priority)(n,b,d)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here is an example of usage:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(A,B): __metaclass__=makecls()
-&gt;&gt;&gt; print C,type(C)
-&lt;class 'oopp.AB_'&gt; &lt;class 'oopp._M_AM_B'&gt;
-</pre>
-</blockquote>
-<p>Notice that the automatically generated metaclass does not pollute the
-namespace:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; _M_A_M_B #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-NameError: name '_M_A_M_B' is not defined
-</pre>
-</blockquote>
-<p>It can only be accessed as <tt class="literal"><span class="pre">type(C)</span></tt>.</p>
-<p>Put it shortly, the <tt class="literal"><span class="pre">child</span></tt> function allows to generate a child from bases
-enhanced by different custom metaclasses, by generating under the hood a
-compatibile metaclass via multiple inheritance from the original metaclasses.
-However, this logic can only work if the original metaclasses are
-cooperative, i.e. their methods are written in such a way to avoid
-collisions. This can be done by using the cooperative the <tt class="literal"><span class="pre">super</span></tt> call
-mechanism discussed in chapter 4.</p>
-</div>
-<div class="section" id="cooperative-metaclasses">
-<h2><a class="toc-backref" href="#id117" name="cooperative-metaclasses">Cooperative metaclasses</a></h2>
-<p>In this section I will discuss how metaclasses can be composed with
-classes and with metaclasses, too. Since we will discusss even
-complicated hierarchies, it is convenient to have an utility
-routine printing the MRO of a given class:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def MRO(cls):
- count=0; out=[]
- print &quot;MRO of %s:&quot; % cls.__name__
- for c in cls.__mro__:
- name=c.__name__
- bases=','.join([b.__name__ for b in c.__bases__])
- s=&quot; %s - %s(%s)&quot; % (count,name,bases)
- if type(c) is not type: s+=&quot;[%s]&quot; % type(c).__name__
- out.append(s); count+=1
- return '\n'.join(out)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Notice that <tt class="literal"><span class="pre">MRO</span></tt> also prints the metaclass' name in square brackets, for
-classes enhanced by a non-trivial metaclass.</p>
-<p>Consider for instance the following hierarchy:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import MRO
-&gt;&gt;&gt; class B(object): pass
-&gt;&gt;&gt; class M(B,type): pass
-&gt;&gt;&gt; class C(B): __metaclass__=M
-</pre>
-</blockquote>
-<p>Here 'M' is a metaclass that inherits from 'type' and the base class 'B'
-and 'C' is both an instance of 'M' and a child of 'B'. The inheritance
-graph can be draw as</p>
-<blockquote>
-<pre class="literal-block">
- object
- / \
-B type
-| \ /
-| M
-\ :
- \ :
- C
-</pre>
-</blockquote>
-<p>Suppose now we want to retrieve the <tt class="literal"><span class="pre">__new__</span></tt> method of B's superclass
-with respect to the MRO of C: obviously, this is <tt class="literal"><span class="pre">object.__new__</span></tt>, since</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print MRO(C)
-MRO of C:
- 0 - C(B)[M]
- 1 - B(object)
- 2 - object()
-</pre>
-</blockquote>
-<p>This allows to create an instance of 'C' in this way:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(B,C).__new__(C)
-&lt;__main__.C object at 0x4018750c&gt;
-</pre>
-</blockquote>
-<p>It is interesting to notice that this would not work in Python 2.2,
-due to a bug in the implementation of <tt class="literal"><span class="pre">super</span></tt>, therefore do not
-try this trick with older version of Python.</p>
-<p>Notice that everything works
-only because <tt class="literal"><span class="pre">B</span></tt> inherits the <tt class="literal"><span class="pre">object.__new__</span></tt> staticmethod that
-is cooperative and it turns out that it calls <tt class="literal"><span class="pre">type.__new__</span></tt>. However,
-if I give to 'B' a non-cooperative method</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; B.__new__=staticmethod(lambda cls,*args: object.__new__(cls))
-</pre>
-</blockquote>
-<p>things do not work:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; M('D',(),{}) #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
- File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;lambda&gt;
-TypeError: object.__new__(M) is not safe, use type.__new__()
-</pre>
-</blockquote>
-<p>A cooperative method would solve the problem:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; B.__new__=staticmethod(lambda m,*args: super(B,m).__new__(m,*args))
-&gt;&gt;&gt; M('D',(),{}) # calls B.__new__(M,'D',(),{})
-&lt;class '__main__.D'&gt;
-</pre>
-</blockquote>
-</div>
-<div class="section" id="metamethods-vs-class-methods">
-<h2><a class="toc-backref" href="#id118" name="metamethods-vs-class-methods">Metamethods vs class methods</a></h2>
-<p>Meta-methods, i.e. methods defined in
-a metaclass.</p>
-<p>Python has already few built-in metamethods: <tt class="literal"><span class="pre">.mro()</span></tt>
-and <tt class="literal"><span class="pre">__subclass__</span></tt>. These are methods of the metaclass 'type' and
-there of any of its sub-metaclasses.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; dir(type)
-['__base__', '__bases__', '__basicsize__', '__call__', '__class__',
- '__cmp__', '__delattr__', '__dict__', '__dictoffset__', '__doc__',
- '__flags__', '__getattribute__', '__hash__', '__init__', '__itemsize__',
- '__module__', '__mro__', '__name__', '__new__', '__reduce__', '__repr__',
- '__setattr__', '__str__', '__subclasses__', '__weakrefoffset__', 'mro']
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; print type.mro.__doc__
-mro() -&gt; list
-return a type's method resolution order
-&gt;&gt;&gt; print type.__subclasses__.__doc__
-__subclasses__() -&gt; list of immediate subclasses
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A(object): pass
-&gt;&gt;&gt; class B(A): pass
-&gt;&gt;&gt; B.mro()
-[&lt;class '__main__.B'&gt;, &lt;class '__main__.A'&gt;, &lt;type 'object'&gt;]
-&gt;&gt;&gt; A.__subclasses__()
-[&lt;class '__main__.B'&gt;]
-</pre>
-</blockquote>
-<p>Notice that <tt class="literal"><span class="pre">mro()</span></tt> and <tt class="literal"><span class="pre">__subclasses__</span></tt> are not retrieved by <tt class="literal"><span class="pre">dir</span></tt>.</p>
-<p>Let me constrast metamethods with the more traditional classmethods.
-In many senses, the to concepts are akin:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(type):
-... &quot;Metaclass with a (meta)method mm&quot;
-... def mm(cls): return cls
-&gt;&gt;&gt; D=M('D',(),{'cm':classmethod(lambda cls: cls)})
-&gt;&gt;&gt; # instance of M with a classmethod cm
-&gt;&gt;&gt; D.mm # the metamethod
-&lt;bound method M.mm of &lt;class '__main__.C'&gt;&gt;
-&gt;&gt;&gt; D.cm # the classmethod
-&lt;unbound method D.&lt;lambda&gt;&gt;
-</pre>
-</blockquote>
-<p>Notice the similarities between the classmethod and the metamethod:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; D.mm.im_self, D.cm.im_self # the same
-(&lt;class '__main__.D'&gt;, &lt;class '__main__.D'&gt;)
-&gt;&gt;&gt; D.mm.im_class, D.cm.im_class # still the same
-(&lt;class '__main__.M'&gt;, &lt;class '__main__.M'&gt;)
-</pre>
-</blockquote>
-<p>There are no surprises for <tt class="literal"><span class="pre">im_func</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; D.mm.im_func, D.cm.im_func
-(&lt;function mm at 0x402c272c&gt;, &lt;function &lt;lambda&gt; at 0x402c280c&gt;)
-</pre>
-</blockquote>
-<p>Nevertheless, there are differences: metamethods are not bounded to
-instances of the class</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; D().cm() # the classmethod works fine
-&lt;class '__main__.D'&gt;
-&gt;&gt;&gt; D().mm() # the metamethod does not: error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'D' object has no attribute 'mm'
-</pre>
-</blockquote>
-<p>and they are not retrieved by <tt class="literal"><span class="pre">dir</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; attributes(D).keys() # mm is not retrieved, only cm
-['cm']
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm.__get__('whatever') #under Python 2.2.0 would give a serious error
-Segmentation fault
-&gt;&gt;&gt; cm.__get__(None) #under Python 2.3 there is no error
-&lt;bound method type.&lt;lambda&gt; of &lt;type 'NoneType'&gt;&gt;
-</pre>
-</blockquote>
-<p>Moreover metamethods behaves differently with respect to multiple
-inheritance. If a class A define a classmethod cA and a class B
-defines a classmethod cB, then the class C(A,B) inherits both the
-classmethods cA and cB. In the case of metamethods defined in M_A
-and M_B, the same is true only if one resolves the meta-type
-conflict by hand, by generating the metaclass M_C(M_A,M_B). In this
-sense, classmethods are simpler to use than metamethods.</p>
-</div>
-</div>
-<div class="section" id="the-magic-of-metaclasses-part-2">
-<h1><a class="toc-backref" href="#id119" name="the-magic-of-metaclasses-part-2">THE MAGIC OF METACLASSES - PART 2</a></h1>
-<p>Metaclasses are so powerful that a single chapter is not enough to make
-justice to them ;) In this second chapter on metaclasses I will
-unravel their deepest secrets, covering topics such as meta-metaclasses,
-anonymous inner metaclasses, global metaclasses and advanced class factories.</p>
-<p>Moreover, I will give various magical applications of metaclasses,
-in the realm of enhancing the Python language itself. Actually, this is
-probably the most idiomatic application of metaclasses (Guido's examples
-on the metaclass usage are all in this area). I will show
-how metaclasses can be used to enhance the <tt class="literal"><span class="pre">super</span></tt> cooperatice call
-mechanism.</p>
-<p>This is not a chapter for the faint of heart.</p>
-<div class="section" id="the-secrets-of-the-metaclass-hook">
-<h2><a class="toc-backref" href="#id120" name="the-secrets-of-the-metaclass-hook">The secrets of the <tt class="literal"><span class="pre">__metaclass__</span></tt> hook</a></h2>
-<p>In the previous chapter we have seen how the <tt class="literal"><span class="pre">__metaclass__</span></tt> hook can
-be used as a way of metaclass enhancing pre-existing classes
-with a minimal change of the sourcecode.</p>
-<p>But it has much deeper secrets.</p>
-<p>The first and simplest of them,
-is the fact that the hook can be used it can also be defined
-at the module level, <em>outside</em> the class. This allows a number of neat
-tricks, since in presence of a <tt class="literal"><span class="pre">__metaclass__</span></tt> hook at the module
-level <em>all</em> the old style classes in the module (including nested ones!)
-acquire that hook. A first application is to rejuvenate old style classes
-to new style classes.</p>
-<p>I remind that old style classes are retained with compability with old
-code, but they are a pain in the back, if you want to use features
-intended for new style classes only (for instance properties etc.).
-Naively, one would expect the conversion from old style classes
-to new style to be long and error prone: suppose you have a very large
-application with hundreds of old style classes defined in dozens of modules.
-Suppose you want to update your application to Python 2.2+ classes in order
-to take advantage of the new features I have discussed extensively in this
-book: the naive way to go would be to go trough the source, look for
-all classes definitions and change</p>
-<blockquote>
-<pre class="literal-block">
-Classname: --&gt; Classname(object)
-</pre>
-</blockquote>
-<p>One could solve this problem with a regular expression search and replace
-in all modules, but this would require to change <em>all</em> the source.
-This is againt the spirit of OOP, we must <em>reuse</em> old code.</p>
-<p>Metaclasses are particularly handy to solve this problem: actually it is
-enough to add to your modules the following line as first line:</p>
-<blockquote>
-<pre class="literal-block">
-__metaclass__ = type
-</pre>
-</blockquote>
-<p>Then, all your old style classes will have 'type' as their metaclass: this
-is akin to say that all the old style classes are <em>automagically</em> rejuvenate
-to new style classes! And this also works for <em>nested</em> classes!!</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;rejuvenate.py&gt;
-
-__metaclass__ = type # this rejuvanate all the class in the module
-
-class C:
- class D: pass
-
-print dir(C) # both C and C.D
-print dir(C.D) # are now new style classes
-
-#&lt;/rejuvenate.py&gt;
-</pre>
-</blockquote>
-<p>This very first example add consistence (if needed) to the
-widespread belief that metaclasses have a well deserved reputation of magic.</p>
-<p>The explanation is that defining a global metaclass called <tt class="literal"><span class="pre">__metaclass__</span></tt>
-automatically makes all old style classes (new style class simply ignore
-the existence of the global <tt class="literal"><span class="pre">__metaclass__</span></tt>) defined in you module
-instances of the given metaclass; this automatically converts them to
-new style classes.</p>
-</div>
-<div class="section" id="anonymous-inner-metaclasses">
-<h2><a class="toc-backref" href="#id121" name="anonymous-inner-metaclasses">Anonymous inner metaclasses</a></h2>
-<p>A second, deeper secret of the <tt class="literal"><span class="pre">__metaclass__</span></tt> hook is that it can be
-used to define anonymous <em>inner metaclasses</em>. The following example
-explain what I mean:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def totuple(arg):
- &quot;Converts the argument to a tuple, if need there is&quot;
- if isinstance(arg,tuple): return arg # do nothing
- else: return (arg,) # convert to tuple
-
-class BracketCallable(object):
- &quot;&quot;&quot;Any subclass C(BracketCallable) can be called with the syntax C[t],
- where t is a tuple of arguments stored in bracket_args; returns the
- class or an instance of it, depending on the flag 'returnclass'.&quot;&quot;&quot;
-
- returnclass=True
- class __metaclass__(type): # anonymous inner metaclass
- def __getitem__(cls,args): # non cooperative metamethod
- if cls.returnclass:
- c=type(cls.__name__,(cls,),{'bracket_args':totuple(args)})
- return c # a customized copy of the original class
- else:
- self=cls(); self.bracket_args=totuple(args)
- return self
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>In this code 'BracketCallable.__metaclass__' is the anonymous (actually
-it has a special name, <tt class="literal"><span class="pre">__metaclass__</span></tt>) inner metaclass of 'BracketCallable'.</p>
-<p>The effect of 'BracketCallable.__metaclass__' is the following: it makes
-'BracketCallable' and its descendants callable with brackets. Since
-the 'returnclass' flag is set, <tt class="literal"><span class="pre">__getitem__</span></tt> returns the class
-with an attribute 'bracket_args' containing the tuple of the passed
-arguments (otherwise it returns an instance of the class).
-This works since when
-Python encounters an expression of kind <tt class="literal"><span class="pre">cls[arg]</span></tt> it interprets it
-as <tt class="literal"><span class="pre">type(cls).__getitem__(cls,arg)</span></tt>. Therefore, if <tt class="literal"><span class="pre">cls</span></tt> is a subclass
-of 'BracketCallable', this means that</p>
-<blockquote>
-<pre class="literal-block">
-cls[arg] &lt;=&gt; BracketCallable.__metaclass__.__getitem__(cls,arg)
-</pre>
-</blockquote>
-<p>Let me give few examples:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import BracketCallable
-&gt;&gt;&gt; type(BracketCallable)
-&lt;class 'oopp.__metaclass__'&gt;
-&gt;&gt;&gt; print type(BracketCallable).__name__ # not really anonymous
-__metaclass__
-&gt;&gt;&gt; print BracketCallable['a1'].bracket_args
-('a1',)
-&gt;&gt;&gt; print BracketCallable['a1','a2'].bracket_args
-('a1', 'a2')
-</pre>
-</blockquote>
-<p>This syntactical feature is an example of a thing that can be done
-<em>trough metaclasses only</em>: it cannot be emulated by functions.</p>
-<p>Anonymous inner metaclasses are the least verbose manner
-of defining metamethods. Moreover, they are a neat trick to define
-mix-in classes that, when inherited, can metamagically enhance
-an entire multiple inheritance hierarchy.</p>
-<p>In the previous example <tt class="literal"><span class="pre">__getitem__</span></tt> is noncooperative, but nothing
-forbids anonymous inner metaclasses from being made cooperative. However,
-there is some subtlety one must be aware of.
-Let me give an example. My 'WithCounter' class counts how many instances
-of 'WithCounter' and its subclasses are generated. However, it does not
-distinguishes bewteen different subclasses.
-This was correct in the pizza shop example, simple only the total
-number of produced pizzas mattered, however, in other situations,
-one may want to reset the counter each time a new subclass is created.
-This can be done automagically by a cooperative inner metaclass:</p>
-<blockquote>
-<pre class="literal-block">
-class WithMultiCounter(WithCounter):
- &quot;&quot;&quot;Each time a new subclass is derived, the counter is reset&quot;&quot;&quot;
- class __metaclass__(type):
- def __init__(cls,*args):
- cls.counter=0
- super(cls.__this,cls).__init__(*args)
- reflective(__metaclass__)
-</pre>
-</blockquote>
-<p>Notice that the order of execution of this code is subtle:</p>
-<ol class="arabic simple">
-<li>first, the fact that WithMulticounter has a non-trivial metaclass is
-registered, but nothing else is done;</li>
-<li>then, the line <tt class="literal"><span class="pre">reflective(__metaclass__)</span></tt> is executed: this means
-that the inner metaclass (and therefore its instances) get an
-attribute <tt class="literal"><span class="pre">._metaclass__this</span></tt> containing a reference to the
-inner metaclass;</li>
-<li>then, the outer class is passed to its inner metaclass and created
-by the inherited metaclass' <tt class="literal"><span class="pre">__new__</span></tt> method;</li>
-<li>at this point <tt class="literal"><span class="pre">cls</span></tt> exists and <tt class="literal"><span class="pre">cls.__this</span></tt> is inherited from
-<tt class="literal"><span class="pre">__metaclass__._metaclass__this</span></tt>; this means that the expression
-<tt class="literal"><span class="pre">super(cls.__this,cls).__init__(*args)</span></tt> is correctly recognized and
-'WithMultiCounter' can be initialized;</li>
-<li>only after that, the name 'WithMultiCounter' enters in the global namespace
-and can be recognized.</li>
-</ol>
-<p>Notice in particular that inside <tt class="literal"><span class="pre">super</span></tt>, we could also
-use <tt class="literal"><span class="pre">cls.__metaclass__</span></tt> instead of <tt class="literal"><span class="pre">cls.__this</span></tt>, but this
-would not work inside <tt class="literal"><span class="pre">__new__</span></tt>, whereas <tt class="literal"><span class="pre">__this</span></tt> would be
-recognized even in <tt class="literal"><span class="pre">__new__</span></tt>.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; print MRO(WithMultiCounter)
-1 - WithMultiCounter(WithCounter)[__metaclass__]
-2 - WithCounter(object)
-3 - object()
-</pre>
-</blockquote>
-<p>For sake of readability, often it is convenient
-to give a name even to inner classes:</p>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class WithMultiCounter(WithCounter):
- &quot;&quot;&quot;Each time a new subclass is derived, the counter is reset&quot;&quot;&quot;
- class ResetsCounter(type):
- def __init__(cls,*args):
- cls.counter=0
- super(cls.ResetsCounter,cls).__init__(*args)
- __metaclass__=ResetsCounter
-
-#&lt;/oopp.py&gt;
-</pre>
-<p>Notice that inside super we used the expression <tt class="literal"><span class="pre">cls.ResetsCounter</span></tt> and
-not <tt class="literal"><span class="pre">WithMultiCounter.ResetsCounter</span></tt>: doing that would generate a
-<tt class="literal"><span class="pre">NameError:</span> <span class="pre">global</span> <span class="pre">name</span> <span class="pre">'WithMultiCounter'</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">defined</span></tt> since at the
-time when <tt class="literal"><span class="pre">ResetsCounter.__init__</span></tt> is called for the first time,
-the class <tt class="literal"><span class="pre">WithMultiCounter</span></tt> exists but is has not yet entered the global
-namespace: this will happens only after the initialization in the
-<tt class="literal"><span class="pre">ResetsCounter</span></tt> metaclass, as we said before.</p>
-<p>Without the metaclass one can reset the counter by hand each time, or
-can reset the counter on all the classes of the hierarchy with a
-convenient function (akin to the 'traceH' routine defined in chapter 6).</p>
-<p>Example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; class GrandFather(WithMultiCounter): pass
-&gt;&gt;&gt; class Father(GrandFather): pass
-&gt;&gt;&gt; class Child(Father): pass
-&gt;&gt;&gt; GrandFather()
-&lt;__main__.GrandFather object at 0x402f7f6c&gt; # first GrandFather instance
-&gt;&gt;&gt; Father()
-&lt;__main__.Father object at 0x402f79ec&gt; # first Father instance
-&gt;&gt;&gt; Father()
-&lt;__main__.Father object at 0x402f7d4c&gt; # second Father instance
-&gt;&gt;&gt; Child.counter # zero instances
-0
-&gt;&gt;&gt; Father.counter # two instances
-2
-&gt;&gt;&gt; GrandFather.counter # one instance
-1
-</pre>
-</blockquote>
-<p>I leave as an exercise for the reader to show that the original 'WithCounter'
-would fail to count correctly the different subclasses and would put the
-total number of instances in 'Child'.</p>
-</div>
-<div class="section" id="passing-parameters-to-meta-classes">
-<h2><a class="toc-backref" href="#id122" name="passing-parameters-to-meta-classes">Passing parameters to (meta) classes</a></h2>
-<p>Calling a class with brackets is a way of passing parameters to it (or
-to its instances, if the 'returnclass' flag is not set).
-There additional ways for of doing that.
-One can control the instantiation syntax of classes by redefining the
-<tt class="literal"><span class="pre">__call__</span></tt> method of the metaclass. The point is that when we instantiate
-an object with the syntax <tt class="literal"><span class="pre">c=C()</span></tt>, Python looks
-at the <tt class="literal"><span class="pre">__call__</span></tt> method of the metaclass of 'C'; the default behaviour
-it is to call <tt class="literal"><span class="pre">C.__new__</span></tt> and <tt class="literal"><span class="pre">C.__init__</span></tt> in succession, however, that
-behavior can be overridden. Let me give an example without using
-anonymous metaclasses (for sake of clarity only).</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;metacall.py&gt;
-
-class M(type): # this is C metaclass
- def __call__(cls):
- return &quot;Called M.__call__&quot;
-
-C=M('C',(),{}) # calls type(M).__call__
-c=C() # calls type(C).__call__
-# attention: c is a string!
-print c #=&gt; Called M.__call__
-
-#&lt;/metacall.py&gt;
-</pre>
-</blockquote>
-<p>In this example, <tt class="literal"><span class="pre">M.__call__</span></tt> simply
-returns the string <tt class="literal"><span class="pre">Called</span> <span class="pre">M.__call__</span></tt>, and the class
-'C' is <em>not</em> instantiated. Overriding the metaclass
-<tt class="literal"><span class="pre">__call__</span> <span class="pre">``</span> <span class="pre">method</span> <span class="pre">therefore</span> <span class="pre">provides</span> <span class="pre">another</span> <span class="pre">way</span> <span class="pre">to</span> <span class="pre">implement</span>
-<span class="pre">the</span> <span class="pre">``Singleton</span></tt> pattern. However, savage overridings as the one in
-this example, are not a good idea, since it will confuse everybody.
-This is an example where metaclasses change the semantics: whereas
-usually the notation <tt class="literal"><span class="pre">C()</span></tt> means &quot;creates a C instance&quot;, the
-metaclass can give to the syntax <tt class="literal"><span class="pre">C()</span></tt> any meaning we want.
-Here there is both the power and the danger of metaclasses: they
-allows to make both miracles and disasters. Nevertheless, used with
-a grain of salt, they provide a pretty nice convenience.</p>
-<p>Anyway, overriding the '__call__' method of the metaclass can be
-confusing, since parenthesis are usually reserved to mean instantion,
-therefore I will prefere to pass arguments trough brackets.</p>
-<p>The beauty and the magic of metaclasses stays in the fact that this mechanism
-is completely general: since metaclasses themselves are classes, we can
-'CallableWithBrackets' to pass arguments to a metaclass, i.e.
-'CallableWithBrackets' can also be used as a meta-metaclass!</p>
-<p>I leave as an exercise for the reader to figure out
-how to define meta-meta-metaclasses, meta-meta-meta-metaclasses, etc.
-etc. (there is no limit to the abstraction level you can reach with
-metaclasses;-)</p>
-<p>Let me show an example: a magical way of making methods cooperative.
-This can be done trough a 'Cooperative' metaclass that inherits from
-'BracketCallable' and therefore has 'BracketCallable.__metaclass__'
-as (meta)metaclass:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Cooperative(BracketCallable,type):
- &quot;&quot;&quot;Bracket-callable metaclass implementing cooperative methods. Works
- well for plain methods returning None, such as __init__&quot;&quot;&quot;
- def __init__(cls,*args):
- methods=cls.bracket_args
- for meth in methods:
- setattr(cls,meth,cls.coop_method(meth,vars(cls).get(meth)))
- def coop_method(cls,name,method): # method can be None
- &quot;&quot;&quot;Calls both the superclass method and the class method (if the
- class has an explicit method). Implemented via a closure&quot;&quot;&quot;
- def _(self,*args,**kw):
- getattr(super(cls,self),name)(*args,**kw) # call the supermethod
- if method: method(self,*args,**kw) # call the method
- return _
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>The code above works for methods returing <tt class="literal"><span class="pre">None</span></tt>, such as <tt class="literal"><span class="pre">__init__</span></tt>.
-Here I give a first example of application: a hierarchy where the <tt class="literal"><span class="pre">__init__</span></tt>
-methods are automatically called (similar to automatic initialization
-in Java).</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;cooperative.py&gt;
-
-from oopp import Cooperative
-
-class B(object):
- &quot;&quot;&quot;Cooperative base class; all its descendants will automagically
- invoke their ancestors __init__ methods in chain.&quot;&quot;&quot;
- __metaclass__=Cooperative['__init__']
- def __init__(self,*args,**kw):
- print &quot;This is B.__init__&quot;
-
-class C(B):
- &quot;Has not explicit __init__&quot;
-
-class D(C):
- &quot;&quot;&quot;The metaclass makes D.__init__ to call C.__init__ and
- therefore B.__init__&quot;&quot;&quot;
- def __init__(self,*args,**kw):
- print &quot;This is D.__init__&quot;
-
-d=D()
-
-print &quot;The metaclass of B is&quot;,type(B)
-print &quot;The meta-metaclass of B is&quot;, type(type(B))
-
-#&lt;/cooperative.py&gt;
-</pre>
-</blockquote>
-<p>Output:</p>
-<blockquote>
-<pre class="literal-block">
-This is B.__init__
-This is D.__init__
-The metaclass of B is &lt;class 'oopp.Cooperative'&gt;
-The meta-metaclass of B is &lt;class 'oopp.__metaclass__'&gt;
-</pre>
-</blockquote>
-<p>A second example, is the following, an alternative way of
-making the paleoanthropological hierarchy of chapter 4 cooperative:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;paleo.py&gt;
-
-from oopp import Cooperative,Homo
-
-class HomoHabilis(Homo):
- __metaclass__=Cooperative['can']
- def can(self):
- print &quot; - make tools&quot;
-
-class HomoSapiens(HomoHabilis):
- def can(self):
- print &quot; - make abstractions&quot;
-
-class HomoSapiensSapiens(HomoSapiens):
- def can(self):
- print &quot; - make art&quot;
-
-HomoSapiensSapiens().can()
-
-# Output:
-
-# &lt;HomoSapiensSapiens&gt; can:
-# - make tools
-# - make abstractions
-# - make art
-
-#&lt;/paleo.py&gt;
-</pre>
-</blockquote>
-<p>Metaclasses can be used to violate the old good rule &quot;explicit is
-better than implicit&quot;. Looking at the source code for 'HomoSapiens'
-and 'HomoSapiensSapiens' one would never imagine the <tt class="literal"><span class="pre">can</span></tt> is
-somewhat special. That is why in the following I will prefer to
-use the anonymous super call mechanism, which is explicit, instead
-of the implicit cooperative mechanism.</p>
-</div>
-<div class="section" id="meta-functions">
-<h2><a class="toc-backref" href="#id123" name="meta-functions">Meta-functions</a></h2>
-<p>The third and deepest secret of the <tt class="literal"><span class="pre">__metaclass__</span></tt> hook is that, even if
-it is typically used in conjunction with metaclasses, actually the hook
-can refer to generic class factories callable with the signature
-<tt class="literal"><span class="pre">(name,bases,dic)</span></tt>. Let me show a few examples
-where <tt class="literal"><span class="pre">__metaclass__</span></tt> is a function or a generic callable object
-instead of being a metaclass:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;metafun.py&gt;
-
-from oopp import kwdict
-
-class Callable(object):
- def __call__(self,name,bases,dic):
- print name,bases,'\n',kwdict(dic)
- return type(name,bases,dic)
-
-callableobj=Callable()
-
-class C: __metaclass__=callableobj
-
-print &quot;type of C:&quot;,C.__class__
-
-def f(name,bases,dic):
- print name,bases,'\n',kwdict(dic)
- return type(name,bases,dic)
-
-class D: __metaclass__=f
-
-print &quot;type of D:&quot;,D.__class__
-
-class B(object):
- def __metaclass__(name,bases,dic):
- &quot;&quot;&quot;In this form, the __metaclass__ attribute is a function.
- In practice, it works as a special static method analogous
- to __new__&quot;&quot;&quot;
- print &quot;name: &quot;, name
- print &quot;bases:&quot;, bases
- print &quot;dic:\n&quot;,kwdict(dic)
- return type(name,bases,dic)
-
-class E(B): pass
-
-print &quot;type of E:&quot;,E.__class__
-print &quot;Non-called E.__metaclass__:&quot;, E.__metaclass__
-
-#&lt;/metafun.py&gt;
-</pre>
-</blockquote>
-<p>With output</p>
-<blockquote>
-<pre class="literal-block">
-C ()
-__metaclass__ = &lt;Callable object at 0x401c964c&gt;
-__module__ = __builtin__
-type of C: &lt;type 'type'&gt;
-D ()
-__metaclass__ = &lt;function f at 0x401c4994&gt;
-__module__ = __builtin__
-type of D: &lt;type 'type'&gt;
-name: B
-bases: (&lt;type 'object'&gt;,)
-dic:
-__metaclass__ = &lt;function __metaclass__ at 0x401c4a3c&gt;
-__module__ = __builtin__
-type of E: &lt;type 'type'&gt;
-Non-called E.__metaclass__: &lt;unbound method E.__metaclass__&gt;
-</pre>
-</blockquote>
-<p>The advantage/disadvantage of this solution is that the <tt class="literal"><span class="pre">__metaclass__</span></tt>
-hook is called only once, i.e. it is not called again if a new class
-is derived from the original one. For instance in this example 'E' is
-derived from 'B', but the function <tt class="literal"><span class="pre">B.__metaclass__</span></tt> is <em>not</em> called
-during the creation of 'E'.</p>
-<p>Metafunctions can also be used when one does not want to transmit the
-metaclass contraint. Therefore they usage is convenient in exactly
-the opposite situation of a cooperative metaclass.</p>
-</div>
-<div class="section" id="anonymous-cooperative-super-calls">
-<h2><a class="toc-backref" href="#id124" name="anonymous-cooperative-super-calls">Anonymous cooperative super calls</a></h2>
-<p>As I noticed in the previous chapters, the <tt class="literal"><span class="pre">super</span></tt>
-mechanism has an annoying
-problem: one needs to pass explicitely the name of the base class. Typically,
-this is simply an
-inelegance since it is annoying to be forced to retype the name of the base
-class. However, in particular
-cases, it can be a problem. This happens for instance if we try to
-pass the class's methods to a different class: one cannot do that,
-since the methods contains an explicit reference to the original class
-and would not work with the new one. Moreover, having named super calls
-is annoying in view of refactoring. Consider for
-instance the previous <tt class="literal"><span class="pre">supernew.py</span></tt> script: in the <tt class="literal"><span class="pre">__new__</span></tt> method
-defined inside the class 'B', we called <tt class="literal"><span class="pre">Super</span></tt> with the syntax
-<tt class="literal"><span class="pre">Super(B,cls)</span></tt> by repeating the name of the class 'B'. Now,
-if in the following I decide to give to 'B' a more descriptive
-name, I have to go trough the source, search all the <tt class="literal"><span class="pre">super</span></tt>
-calls, and change them accordingly to the new name. It would be
-nice having Python do the job for me. A first solution is to call
-<tt class="literal"><span class="pre">super</span></tt> (or <tt class="literal"><span class="pre">Super</span></tt>) with the syntax <tt class="literal"><span class="pre">super(self.__this,obj)</span></tt>,
-where the special name <tt class="literal"><span class="pre">__this</span></tt> is explicitly replaced by the name
-of the class where the call is defined by the 'reflective' function
-of last chapter. This approach has the disadvantage that each time we
-derive a new class, we need to invoke <em>explicitely</em> the routine
-<tt class="literal"><span class="pre">reflective</span></tt>. It would be marvelous to instruct Python to invoke
-<tt class="literal"><span class="pre">reflective</span></tt> automatically at each class creation. Actually, this
-seems to be deep magic and indeed it is: fortunately, a custom metaclass
-can perform this deep magic in few lines:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Reflective(type):
- &quot;&quot;&quot;Cooperative metaclass that defines the private variable __this in
- its instances. __this contains a reference to the class, therefore
- it allows anonymous cooperative super calls in the class.&quot;&quot;&quot;
- def __init__(cls,*args):
- super(Reflective,cls).__init__(*args)
- reflective(cls)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Now, let me show how 'Reflective' can be used in a practical example.</p>
-<p>By deriving new metaclasses from 'Reflective', one can easily
-create powerful class factories that generate reflective classes.</p>
-<p>Suppose I want to define a handy class
-factory with the abilitity of counting the number of its instances.</p>
-<p>This can be done by noticing that metaclasses are just classes, therefore
-they can be composed with regular classes in multiple inheritance. In
-particular one can derive a 'Logged' metaclass from 'WithLogger': in
-this way we send a message to a log file each time a new class is created.
-This can be done by composing 'WithLogger' with 'WithMultiCounter.__metaclass__'
-and with 'Reflective':</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Logged(WithLogger,Reflective):
- &quot;&quot;&quot;Metaclass that reuses the features provided by WithLogger. In particular
- the classes created by Logged are Reflective, PrettyPrinted
- and Customizable.&quot;&quot;&quot; #WithLogger provides logfile and verboselog
- def __init__(cls,*args,**kw):
- super(Logged,cls).__init__(*args,**kw)
- bases=','.join([c.__name__ for c in cls.__bases__])
- print &gt;&gt; cls.logfile, &quot;%s is a child of %s&quot; % (cls,bases)
- print &gt;&gt; cls.logfile,'and an instance of %s' % type(cls).__name__
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>The MRO is</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print MRO(Logged)
-MRO of Logged:
- 0 - Logged(WithLogger,Reflective)
- 1 - WithLogger(WithCounter,PrettyPrinted)
- 2 - WithCounter(object)
- 3 - PrettyPrinted(object)
- 4 - Reflective(type)
- 5 - type(object)
- 6 - object()
-</pre>
-</blockquote>
-<p>and the inheritance graph can be drawn as follows:</p>
-<blockquote>
-<pre class="literal-block">
- _____________________ object 6 ___
- / / \
-2 WithCounter 3 PrettyPrinted type 5
- \ / /
- \ / /
- \ / /
- \ / /
- \ / /
- \ / /
- 1 WithLogger Reflective 4
- \ /
- \ /
- \ /
- \ /
- Logged 0
- :
- :
- C1
-</pre>
-</blockquote>
-<p>'WithCounter' acts now as a metaclass, since WithCounter.__new__ invokes
-type.__new__. Since <tt class="literal"><span class="pre">type.__new__</span></tt> is non-cooperative,
-in the composition of a metaclass with a regular class, the metaclass
-should be put first: this guarantees that <tt class="literal"><span class="pre">__new__</span></tt> derives from
-<tt class="literal"><span class="pre">type.__new__</span></tt>, thus avoiding the error message.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Logged.verboselog=True
-&gt;&gt;&gt; C1=Logged('C1',(),{})
-*****************************************************************************
-Tue Apr 22 18:47:05 2003
-1. Created 'C1'
-with accessibile non-special attributes:
-_C1__this = 'C1'
-'C1' is a child of object
-and an instance of Logged
-</pre>
-</blockquote>
-<p>Notice that any instance of 'WithCounterReflective' inherits the 'WithCounter'
-attribute <tt class="literal"><span class="pre">counter</span></tt>, that counts the number of classes that have been
-instantiated (however it is not retrieved by <tt class="literal"><span class="pre">dir</span></tt>; moreover the
-instances of 'WithCounterReflective' instances have no <tt class="literal"><span class="pre">counter</span></tt> attribute).</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C1.counter
-1
-</pre>
-</blockquote>
-</div>
-<div class="section" id="more-on-metaclasses-as-class-factories">
-<h2><a class="toc-backref" href="#id125" name="more-on-metaclasses-as-class-factories">More on metaclasses as class factories</a></h2>
-<p>A slight disadvantage of the approach just described,
-is that 'Logged' cooperatively invokes the <tt class="literal"><span class="pre">type.__new__</span></tt>
-static method, therefore, when we invoke the metaclass, we must explicitly
-provide a name, a tuple of base classes and a dictionary, since the
-<tt class="literal"><span class="pre">type.__new__</span></tt> staticmethod requires that signature. Actually,
-the expression</p>
-<blockquote>
-<pre class="literal-block">
-C=Logged(name,bases,dic)
-</pre>
-</blockquote>
-<p>is roughly syntactic sugar for</p>
-<blockquote>
-<pre class="literal-block">
-C=Logged.__new__(Logged,name,bases,dic)
-assert isinstance(C,Logged)
-Logged.__init__(C,name,bases,dic)
-</pre>
-</blockquote>
-<p>If a different interface is desired, the best way is to use a class
-factory 'ClsFactory' analogous to the object factory 'Makeobj'
-defined in chapter 4. It is convenient to make 'ClsFactory'
-bracket-callable.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class ClsFactory(BracketCallable):
- &quot;&quot;&quot;Bracket callable non-cooperative class acting as
- a factory of class factories.
-
- ClsFactory instances are class factories accepting 0,1,2 or 3 arguments.
- . They automatically converts functions to static methods
- if the input object is not a class. If an explicit name is not passed
- the name of the created class is obtained by adding an underscore to
- the name of the original object.&quot;&quot;&quot;
-
- returnclass=False # ClsFactory[X] returns an *instance* of ClsFactory
-
- def __call__(self, *args):
- &quot;&quot;&quot;Generates a new class using self.meta and avoiding conflicts.
- The first metaobject can be a dictionary, an object with a
- dictionary (except a class), or a simple name.&quot;&quot;&quot;
-
- # default attributes
- self.name=&quot;CreatedWithClsFactory&quot;
- self.bases=()
- self.dic={}
- self.metas=self.bracket_args
-
- if len(args)==1:
- arg=args[0]
- if isinstance(arg,str): # is a name
- self.name=arg
- elif hasattr(arg,'__name__'): # has a name
- self.name=arg.__name__+'_'
- self.setbasesdic(arg)
- elif len(args)==2:
- self.name=args[0]
- assert isinstance(self.name,str) # must be a name
- self.setbasesdic(args[1])
- elif len(args)==3: # must be name,bases,dic
- self.name=args[0]
- self.bases+=args[1]
- self.dic.update(args[2])
- if len(args)&lt;3 and not self.bases: # creating class from a non-class
- for k,v in self.dic.iteritems():
- if isfunction(v): self.dic[k]=staticmethod(v)
- #return child(*self.bases,**vars(self))
- return makecls(*self.metas)(self.name,self.bases,self.dic)
-
- def setbasesdic(self,obj):
- if isinstance(obj,tuple): # is a tuple
- self.bases+=obj
- elif hasattr(obj,'__bases__'): # is a class
- self.bases+=obj.__bases__
- if isinstance(obj,dict): # is a dict
- self.dic.update(obj)
- elif hasattr(obj,&quot;__dict__&quot;): # has a dict
- self.dic.update(obj.__dict__)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>'ClsFactory[X]' where 'X' is a metaclass returns callable objects acting as
-class factories. For instance</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-Class=ClsFactory[type] # generates non-conflicting classes
-Mixin=ClsFactory[Reflective] # generates reflective classes
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>can be used as a class factories that automatically provides a default name,
-base classes and dictionary, and avoids meta-type conflicts.
-'Mixin' generates reflective classes that can be used as mixin in multiple
-inheritance hierarchies. Here I give few example of usage of 'Class':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; C1,C2,C3=[Class('C'+str(i+1)) for i in range(3)]
-&gt;&gt;&gt; C1
-&lt;class 'oopp.C1'&gt;
-&gt;&gt;&gt; C2
-&lt;class 'oopp.C2'&gt;
-&gt;&gt;&gt; C3
-&lt;class 'oopp.C3'&gt;]
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; Clock=Class('Clock',{'get_time':get_time})
-&gt;&gt;&gt; Clock
-&lt;class 'oopp.Clock'&gt;
-&gt;&gt;&gt; Clock.get_time()
-16:01:02
-</pre>
-</blockquote>
-<p>Another typical usage of 'Class' is the conversion of a module in a class:
-for instance</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; time_=Class(time)
-&gt;&gt;&gt; time_
-&lt;class 'oopp.time_'&gt;
-</pre>
-</blockquote>
-<p>Notice the convention of adding an underscore to the name of the class
-generated from the 'time' module.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; time_.asctime()
-'Mon Jan 20 16:33:21 2003'
-</pre>
-</blockquote>
-<p>Notice that all the functions in the module <tt class="literal"><span class="pre">time</span></tt> has been magically
-converted in staticmethods of the class <tt class="literal"><span class="pre">time_</span></tt>. An advantage of this
-approach is that now the module is a class and can be enhanced with
-metaclasses: for instance we could add tracing capabilities, debugging
-features, etc.</p>
-<p>By design, 'Class' and 'Reflective' also works when the first argument
-is a class or a tuple of base classes:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; ClsFactory_=Class(ClsFactory)
-&gt;&gt;&gt; type(ClsFactory_)
-&lt;class 'oopp.__metaclass__'&gt;
-&gt;&gt;&gt; ClsFactory_=Mixin(ClsFactory)
-&gt;&gt;&gt; type(ClsFactory_) # automagically generated metaclass
-&lt;class 'oopp._Reflective__metaclass__'&gt;
-</pre>
-</blockquote>
-</div>
-<div class="section" id="programming-with-metaclasses">
-<h2><a class="toc-backref" href="#id126" name="programming-with-metaclasses">Programming with metaclasses</a></h2>
-<p>In order to how a non-trivial application of metaclasses in real life,
-let me come back to the pizza shop example discussed in chapter 4 and 6.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def Pizza(toppings,**dic):
- &quot;&quot;&quot;This function produces classes inheriting from GenericPizza and
- WithLogger, using a metaclass inferred from Logged&quot;&quot;&quot;
- toppinglist=toppings.split()
- name='Pizza'+''.join([n.capitalize() for n in toppinglist])
- dic['toppinglist']=toppinglist
- return ClsFactory[Logged](name,
- (GenericPizza,WithLogger,WithMultiCounter),dic)
-
-#&lt;/oopp.py&gt;
-
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; Margherita=Pizza('tomato mozzarella',verboselog=True)
-*****************************************************************************
-Tue May 13 14:42:17 2003
-1. Created 'PizzaTomatoMozzarella'
-with accessibile non-special attributes:
-ResetsCounter = &lt;class 'oopp.ResetsCounter'&gt;
-_GenericPizza__this = &lt;class 'oopp.GenericPizza'&gt;
-_WithCounter__this = &lt;class 'oopp.WithCounter'&gt;
-_WithLogger__this = &lt;class 'oopp.WithLogger'&gt;
-baseprice = 1
-counter = 0
-formatstring = %s
-logfile = &lt;open file '&lt;stdout&gt;', mode 'w' at 0x402c2058&gt;
-price = &lt;unbound method PizzaTomatoMozzarella.price&gt;
-sizefactor = {'small': 1, 'large': 3, 'medium': 2}
-topping_unit_price = 0.5
-toppinglist = ['tomato', 'mozzarella']
-toppings_price = &lt;unbound method PizzaTomatoMozzarella.toppings_price&gt;
-verboselog = True
-'PizzaTomatoMozzarella' is a child of GenericPizza,WithLogger,
-WithMultiCounter and an instance of _LoggedResetsCounter
-</pre>
-</blockquote>
-<p>Notice the <em>deep</em> magic: <tt class="literal"><span class="pre">Pizza</span></tt> invokes <tt class="literal"><span class="pre">ClsFactory[Logged]</span></tt> which in
-turns calls the class factory <tt class="literal"><span class="pre">child</span></tt> that creates 'Margherita' from
-'GenericPizza', 'WithLogger' and 'WithMultiCounter' by using the
-metaclass 'Logged': however, since 'WithMultiCounter', has the internal
-metaclass 'ResetsCounter' , there is a metatype conflict:
-<tt class="literal"><span class="pre">child</span></tt> <em>automagically</em> solves the conflict by creating the metaclass
-'_LoggedResetsCounter' that inherits both from 'Logged' and 'ResetsCounter'.
-At this point, 'Margherita' can be safely created
-by '_LoggedResetsCounter'. As such, the creation of 'Margherita'
-will be registered in the log file and 'Margherita' (with all its
-children) will continue to be able to recognize the special identifier
-<tt class="literal"><span class="pre">this</span></tt>.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print Margherita('large')
-*****************************************************************************
-Tue May 13 14:47:03 2003
-1. Created large pizza with tomato,mozzarella, cost $ 6.0
-with accessibile non-special attributes:
-ResetsCounter = &lt;class 'oopp.ResetsCounter'&gt;
-_GenericPizza__this = &lt;class 'oopp.GenericPizza'&gt;
-_WithCounter__this = &lt;class 'oopp.WithCounter'&gt;
-_WithLogger__this = &lt;class 'oopp.WithLogger'&gt;
-baseprice = 1
-counter = 1
-formatstring = %s
-logfile = &lt;open file '&lt;stdout&gt;', mode 'w' at 0x402c2058&gt;
-price = &lt;bound method PizzaTomatoMozzarella.price of
-&lt;oopp.PizzaTomatoMozzarella object at 0x4032764c&gt;&gt;
-size = large
-sizefactor = {'small': 1, 'large': 3, 'medium': 2}
-topping_unit_price = 0.5
-toppinglist = ['tomato', 'mozzarella']
-toppings_price = &lt;bound method PizzaTomatoMozzarella.toppings_price of
-&lt;oopp.PizzaTomatoMozzarella object at 0x4032764c&gt;&gt;
-verboselog = True
-large pizza with tomato,mozzarella, cost $ 6.0
-&gt;&gt;&gt; print MRO(Margherita)
-MRO of PizzaTomatoMozzarella:
- 0 - PizzaTomatoMozzarella(GenericPizza,WithLogger)[_LoggedResetsCounter]
- 1 - GenericPizza(object)
- 2 - WithLogger(WithCounter,Customizable,PrettyPrinted)
- 3 - WithMultiCounter(WithCounter)[ResetsCounter]
- 4 - WithCounter(object)
- 5 - PrettyPrinted(object)
- 6 - object()
-</pre>
-</blockquote>
-<p>Notice that</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print Margherita
-'PizzaTomatoMozzarella'
-</pre>
-</blockquote>
-<p>The power of inheritance in this example is quite impressive, since
-I have reused the same class 'WithLogger' (and its children) both in the
-metaclass hierarchy and in the regular hierarchy: this means that I have added
-logging capabilities both to classes and their instances in a
-strike! And there is no confusion between the two. For instance,
-there is a <tt class="literal"><span class="pre">counter</span></tt> attribute for the metaclass 'Logged'
-and many independent <tt class="literal"><span class="pre">counter</span></tt> attributes for any generated class,
-i.e. for any kind of pizza.</p>
-<blockquote>
-It is interesting to notice that '' itself is an instance of
-its inner metaclass, as <tt class="literal"><span class="pre">type()</span></tt> would show. This technique
-avoids the need for inventing a new name for the metaclass. The inner
-metaclass is automatically inherited by classes inheriting from the outer
-class.</blockquote>
-</div>
-<div class="section" id="metaclass-aided-operator-overloading">
-<h2><a class="toc-backref" href="#id127" name="metaclass-aided-operator-overloading">Metaclass-aided operator overloading</a></h2>
-<p>As we discussed in chapter 4, inheriting from built-in types is generally
-painful. The problem is that if P is a primitive class, i.e. a
-Python built-in type, and D=D(P) is a derived class, then the
-primitive methods returning P-objects have to be modified (wrapped) in
-such a way to return D-objects.</p>
-<p>The problem is expecially clear in the context of operator overloading.</p>
-<p>Consider for instance the problem of defining a 'Vector' class in the
-mathematical sense. Mathematically-speaking, vectors are defined as objects
-that can be summed each other and multiplied by numbers; they can be represented
-by (finite or infinite) sequences. In the case of finite sequences, vectors
-can be represented with lists and a vector class can be naturally
-implemented by subclassing <tt class="literal"><span class="pre">list</span></tt>:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;vector.py&gt;
-
-class Vector(list):
- &quot;&quot;&quot;Implements finite dimensional vectors as lists. Can be instantiated
- as Vector([a,b,c,..]) or as Vector(a,b,c ..)&quot;&quot;&quot;
- def __add__(self,other):
- return [el+other[i] for i,el in enumerate(self)]
- __radd__=__add__
- def __mul__(self,scalar):
- return [el*scalar for el in self]
- def __rmul__(self,scalar):
- return [scalar*el for el in self]
-
-v=Vector([1,0])
-w=Vector([0,1])
-
-print v+w, type(v+w)
-print 2*v, type(2*v)
-print v*2, type(v*2)
-
-#&lt;/vector.py&gt;
-</pre>
-</blockquote>
-<p>With output</p>
-<blockquote>
-<pre class="literal-block">
-[1, 1] &lt;type 'list'&gt;
-[2, 0] &lt;type 'list'&gt;
-[2, 0] &lt;type 'list'&gt;
-</pre>
-</blockquote>
-<p>The problem is that the overloaded methods must be wrapped in such a way
-to return <tt class="literal"><span class="pre">Vector</span></tt> object and not <tt class="literal"><span class="pre">list</span></tt> object; moreover, if
-<tt class="literal"><span class="pre">Vector</span></tt> is subclassed (for instance by defining a <tt class="literal"><span class="pre">NumericVector</span></tt>),
-the overloaded methods must return instances of the subclass. There is
-only one way of doing that automatically: trough the magic of metaclasses.</p>
-<p>Here is the solution, involving an <tt class="literal"><span class="pre">autowrappedmethod</span></tt> descriptor class,
-that wraps the overloaded operators and is automatically invoked by
-the metaclass <tt class="literal"><span class="pre">AutoWrapped</span></tt>.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class autowrappedmethod(wrappedmethod):
- &quot;&quot;&quot;Makes the method returning cls instances, by wrapping its
- output with cls&quot;&quot;&quot;
- klass=None # has to be fixed dynamically from outside
- def __init__(self,meth):
- super(autowrappedmethod,self).__init__(meth) # cooperative
- self.klass=self.klass # class variable -&gt; instance variable
- def wrapper(self): # closure
- return lambda *args,**kw: self.klass(self.func(*args,**kw))
-
-class AutoWrapped(type):
- &quot;&quot;&quot;Metaclass that looks at the methods declared in the attributes
- builtinlist and wraplist of its instances and wraps them with
- autowrappedmethod.&quot;&quot;&quot;
- def __init__(cls,name,bases,dic):
- super(AutoWrapped,cls).__init__(name,bases,dic) # cooperative
- cls.builtinlist=getattr(cls,'builtinlist',[])
- if not hasattr(cls,'diclist') : # true only at the first call
- cls.diclist=[(a,vars(bases[0])[a]) for a in cls.builtinlist]
- if dic.has_key('wraplist'): # can be true at any call
- cls.diclist+=[(a,dic[a]) for a in cls.wraplist]
- wrapper=autowrappedmethod.With(klass=cls)
- d=dict([(a,wrapper(v)) for a,v in cls.diclist])
- customize(cls,**d)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Now the <tt class="literal"><span class="pre">Vector</span></tt> class can be written as</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Vector(list):
- &quot;&quot;&quot;Implements finite dimensional vectors as lists. Can be instantiated
- as Vector([a,b,c,..]) or as Vector(a,b,c ..)&quot;&quot;&quot;
- __metaclass__=AutoWrapped
- wraplist='__add__ __radd__ __mul__ __rmul__'.split()
- def __add__(self,other):
- return [el+other[i] for i,el in enumerate(self)]
- __radd__=__add__
- def __mul__(self,scalar):
- return [scalar*el for el in self]
- def __rmul__(self,scalar):
- return [el*scalar for el in self]
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here the <tt class="literal"><span class="pre">AutoWrapped</span></tt> metaclass wraps the output of <tt class="literal"><span class="pre">__add__,</span>
-<span class="pre">__radd__,</span> <span class="pre">__mul__,</span> <span class="pre">__rmul__</span></tt>, guaranteeing that they returns <tt class="literal"><span class="pre">Vector</span></tt>
-instances or instances of some subclass of <tt class="literal"><span class="pre">Vector</span></tt>, if <tt class="literal"><span class="pre">Vector</span></tt> is
-subclassed. This is an example of usage:</p>
-<blockquote>
-<!-- doctest -->
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import Vector
-&gt;&gt;&gt; v=Vector([1,0])
-&gt;&gt;&gt; v
-&lt;oopp.Vector object at 0x4032858c&gt;
-&gt;&gt;&gt; w=Vector([0,1])
-&gt;&gt;&gt; v+2*w
-&lt;oopp.Vector object at 0x403190ac&gt;
-&gt;&gt;&gt; print v+2*w
-[1, 2]
-</pre>
-</blockquote>
-<p>It should be clear by now that metaclasses are the natural framework where
-to discuss operator overloading
-(at least in languages that have metaclasses ;-). After all, operator
-overloading is another kind of (very nice) syntactic sugar and we know
-already that metaclasses are very good when we need syntactic sugar.</p>
-</div>
-</div>
-<div class="section" id="advanced-metaprogramming-techniques">
-<h1><a class="toc-backref" href="#id128" name="advanced-metaprogramming-techniques">ADVANCED METAPROGRAMMING TECHNIQUES</a></h1>
-<p>In elementary OOP, the programmer works with objects; in advanced OOP,
-the programmer works with classes, taking full advantage of
-(multiple) inheritance and metaclasses. Metaprograming is the activity of
-building, composing and modifying classes.</p>
-<p>I will give various examples of metaprogramming techniques
-using run-time class modifications
-multiple inheritance, metaclasses, attribute descriptors and
-even simple functions.</p>
-<p>Moreover, I will show show metaclasses can change the
-semantics of Python programs: hence theire reputation of <em>black</em> magic.
-That is to say that the techniques explained here are dangerous!</p>
-<div class="section" id="on-code-processing">
-<h2><a class="toc-backref" href="#id129" name="on-code-processing">On code processing</a></h2>
-<p>It is a good programming practice to avoid the direct modification
-of source code. Nevertheless, there are situations where the ability of
-modifying the source code <em>dynamically</em> is invaluable. Python has the
-capability of</p>
-<ol class="arabic simple">
-<li>generating new code from scratch;</li>
-<li>modifying pre-existing source code;</li>
-<li>executing the newly created/modified code at run-time.</li>
-</ol>
-<p>The capability of creating source code and executing it <em>immediately</em> has
-no equivalent in static languages such as C/C++/Java and it is maybe the
-most poweful feature of dynamics languages such as Java/Python/Perl.
-This feature has been exploited to its ultimate consequences in the languages
-of the Lisp family, in which one can use incredibly poweful macros, which
-in a broad sense, are programs that write themselves</p>
-<p>In this chapter I will discuss how to implement macros in Python and I will
-present some of the miracles you may perform with this technique. To this
-aim, I will discuss various ways of manipulating Python source code, by
-using regular expressions and state machines.</p>
-</div>
-<div class="section" id="regular-expressions">
-<h2><a class="toc-backref" href="#id130" name="regular-expressions">Regular expressions</a></h2>
-<blockquote>
-<pre class="line-block">
-<em>Some people, when confronted with a problem,
-think &quot;I know, I'll use regular expressions.&quot;
-Now they have two problems.</em>
- -- Jamie Zawinski
-</pre>
-</blockquote>
-<p>Python source code is a kind of text and can manipulated with the same
-techniques that are used to manipulate text:</p>
-<ol class="arabic simple">
-<li>the trivial search and replace;</li>
-<li>regular expressions;</li>
-<li>state machines;</li>
-<li>parsers</li>
-</ol>
-<p>There is not very much to say about the search and replace methods: it
-is fast, efficient and it works. It should always be used whenever
-possible. However, in this chapter I will only be interested in cases
-where something more sophisticated than a plain search and replace is
-needed. Cases that can be managed with regular expressions
-or with something even more sophisticated than them: a state machine or
-even a full featured parser.</p>
-<p>I will <em>not</em> give a primer on regular expression here, since they are
-already well documented in the standard documentation (see Andrew's
-Kuchling 'Howto') as well in many books (for instance 'Mastering Regular
-Expression' first edition and 'Python in a Nutshell').
-Instead, I will give various practical examples of usage.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import re
-&gt;&gt;&gt; reobj=re.compile(r'x')
-</pre>
-</blockquote>
-</div>
-<div class="section" id="more-on-metaclasses-and-subclassing-built-in-types">
-<h2><a class="toc-backref" href="#id131" name="more-on-metaclasses-and-subclassing-built-in-types">More on metaclasses and subclassing built-in types</a></h2>
-<p>Subclassing <tt class="literal"><span class="pre">list</span></tt> is easy since there are no methods returning lists
-except the methods correspondings to the '+' and '*' operators.
-Subclassing <tt class="literal"><span class="pre">str</span></tt> is more complicated, since one has many methods
-that return strings. Nevertheless, it can be done with the <tt class="literal"><span class="pre">AutoWrapped</span></tt>
-metaclass, simply by specifying the list of the builtins to be wrapped.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Str(str):
- __metaclass__=AutoWrapped
- builtinlist=&quot;&quot;&quot;__add__ __mod__ __mul__ __rmod__ __rmul__ capitalize
- center expandtabs join ljust lower lstrip replace rjust rstrip strip
- swapcase title translate upper zfill&quot;&quot;&quot;.split()
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here I show various tests.</p>
-<blockquote>
-<!-- doctest -->
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import Str
-&gt;&gt;&gt; sum=Str('a')+Str('b') # check the sum
-&gt;&gt;&gt; print sum, type(sum)
-ab &lt;class 'oopp.Str'&gt;
-&gt;&gt;&gt; rprod=Str('a')*2 # check the right product
-&gt;&gt;&gt; print rprod,type(rprod)
-aa &lt;class 'oopp.Str'&gt;
-&gt;&gt;&gt; lprod=2*Str('a') # check the left product
-&gt;&gt;&gt; print lprod,type(lprod)
-aa &lt;class 'oopp.Str'&gt;
-&gt;&gt;&gt; r=Str('a').replace('a','b') # check replace
-&gt;&gt;&gt; print r,type(r)
-b &lt;class 'oopp.Str'&gt;
-&gt;&gt;&gt; r=Str('a').capitalize() # check capitalize
-&gt;&gt;&gt; print r,type(r)
-A &lt;class 'oopp.Str'&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">Str</span></tt> acts as a nice base class to built abstractions based on strings.
-In particular, regular expressions can be built on top of strings describing
-their representation (I remind that if <tt class="literal"><span class="pre">x</span></tt> is a regular expression object,
-<tt class="literal"><span class="pre">x.pattern</span></tt> is its string representation). Then, the sum of two regular
-expressions <tt class="literal"><span class="pre">x</span></tt> and <tt class="literal"><span class="pre">y</span></tt> can be defined as the sum of their string
-representation, <tt class="literal"><span class="pre">(x+y).pattern=x.pattern+y.pattern</span></tt>. Moreover, it is
-convenient to define the <tt class="literal"><span class="pre">__or__</span></tt> method of two regular expression in
-such a way that <tt class="literal"><span class="pre">(x</span> <span class="pre">|</span> <span class="pre">y).pattern=x.pattern+'|'+y.pattern</span></tt>.
-All this can be achieved trough the following class:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class BaseRegexp(Str):
-
- builtinlist=['__radd__', '__ror__']
- wraplist=['__add__','__or__']
-
- __add__ = lambda self,other: self.pattern + other
- __or__ = lambda self,other: self.pattern+'|'+other
-
- def __init__ (self,regexp):
- &quot;Adds to str methods the regexp methods&quot;
- reobj=re.compile(regexp)
- for attr in dir(reobj)+['pattern']:
- setattr(self,attr,getattr(reobj,attr))
-
-#&lt;/oopp.py&gt;
-
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; aob=BaseRegexp('a')|BaseRegexp('b'); print aob
-a|b
-&gt;&gt;&gt; print pretty(attributes(aob))
-encode = &lt;built-in method encode of BaseRegexp object at 0x401b25cc&gt;
-endswith = &lt;built-in method endswith of BaseRegexp object at 0x401b25cc&gt;
-expandtabs = &lt;function _ at 0x401b69cc&gt;
-find = &lt;built-in method find of BaseRegexp object at 0x401b25cc&gt;
-findall = &lt;built-in method findall of _sre.SRE_Pattern object at 0x4019b890&gt;
-finditer = &lt;built-in method finditer of _sre.SRE_Pattern object at
-0x4019b890&gt;
-index = &lt;built-in method index of BaseRegexp object at 0x401b25cc&gt;
-isalnum = &lt;built-in method isalnum of BaseRegexp object at 0x401b25cc&gt;
-isalpha = &lt;built-in method isalpha of BaseRegexp object at 0x401b25cc&gt;
-isdigit = &lt;built-in method isdigit of BaseRegexp object at 0x401b25cc&gt;
-islower = &lt;built-in method islower of BaseRegexp object at 0x401b25cc&gt;
-isspace = &lt;built-in method isspace of BaseRegexp object at 0x401b25cc&gt;
-istitle = &lt;built-in method istitle of BaseRegexp object at 0x401b25cc&gt;
-isupper = &lt;built-in method isupper of BaseRegexp object at 0x401b25cc&gt;
-join = &lt;function _ at 0x401b6a74&gt;
-ljust = &lt;function _ at 0x401b6b1c&gt;
-lower = &lt;function _ at 0x401b6cdc&gt;
-lstrip = &lt;function _ at 0x401b6d84&gt;
-match = &lt;built-in method match of _sre.SRE_Pattern object at 0x4019b890&gt;
-pattern = ba
-replace = &lt;function _ at 0x401b6ed4&gt;
-rfind = &lt;built-in method rfind of BaseRegexp object at 0x401b25cc&gt;
-rindex = &lt;built-in method rindex of BaseRegexp object at 0x401b25cc&gt;
-rjust = &lt;function _ at 0x401ba0d4&gt;
-rstrip = &lt;function _ at 0x401ba10c&gt;
-scanner = &lt;built-in method scanner of _sre.SRE_Pattern object at 0x4019b890&gt;
-search = &lt;built-in method search of _sre.SRE_Pattern object at 0x4019b890&gt;
-split = &lt;built-in method split of _sre.SRE_Pattern object at 0x4019b890&gt;
-splitlines = &lt;built-in method splitlines of BaseRegexp object at 0x401b25cc&gt;
-startswith = &lt;built-in method startswith of BaseRegexp object at 0x401b25cc&gt;
-strip = &lt;function _ at 0x401ba25c&gt;
-sub = &lt;built-in method sub of _sre.SRE_Pattern object at 0x4019b890&gt;
-subn = &lt;built-in method subn of _sre.SRE_Pattern object at 0x4019b890&gt;
-swapcase = &lt;function _ at 0x401ba294&gt;
-title = &lt;function _ at 0x401ba4fc&gt;
-translate = &lt;function _ at 0x401ba534&gt;
-upper = &lt;function _ at 0x401ba5dc&gt;
-wraplist = ['__add__', '__radd__', '__or__', '__ror__']
-zfill = &lt;function _ at 0x401ba614&gt;
-
-#&lt;oopp.py&gt;
-
-class Regexp(BaseRegexp):
- class __metaclass__(BaseRegexp.__metaclass__):
- def __setattr__(cls,name,value):
- if name==name.upper(): # all caps means regexp constant
- if not isinstance(value,cls): value=cls(value)
- value.name=name # set regexp name
- BaseRegexp.__metaclass__.__setattr__(cls,name,value)
- # basic setattr
-
- def named(self,name=None):
- name=getattr(self,'name',name)
- if name is None: raise 'Unnamed regular expression'
- return self.__class__('(?P&lt;%s&gt;%s)' % (name,self.pattern))
-
- generateblocks=generateblocks
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>The magic of <tt class="literal"><span class="pre">Regexp.__metaclass__</span></tt> allows to generate a library of
-regular expressions in an elegant way:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-r=Regexp
-
-customize(r,
- DOTALL =r'(?s)' , # starts the DOTALL mode; must be at the beginning
- NAME =r'\b[a-zA-Z_]\w*', # plain Python name
- EXTNAME=r'\b[a-zA-Z_][\w\.]*', # Python name with or without dots
- DOTNAME=r'\b[a-zA-Z_]\w*\.[\w\.]*',# Python name with (at least one) dots
- COMMENT=r&quot;#.*?(?=\n)&quot;, # Python comment
- QUOTED1=&quot;'.+?'&quot;, # single quoted string '
- QUOTED2='&quot;.+?&quot;', # single quoted string &quot;
- TRIPLEQ1=&quot;'''.+?'''&quot;, # triple quoted string '
- TRIPLEQ2='&quot;&quot;&quot;.+?&quot;&quot;&quot;' # triple quoted string &quot;
- )
-
-r.STRING=r.TRIPLEQ1|r.TRIPLEQ2|r.QUOTED1|r.QUOTED2
-r.CODESEP=r.DOTALL+r.COMMENT.named()|r.STRING.named()
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>The trick is in the redefinition of <tt class="literal"><span class="pre">__setattr__</span></tt>, which magically converts
-all caps attributes in <tt class="literal"><span class="pre">Regexp</span></tt> objects.</p>
-<p>The features of <tt class="literal"><span class="pre">Regexp</span></tt> can be tested with the following code:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;test_re.py&gt;
-
-&quot;&quot;&quot;This script looks at its own source code and extracts dotted names,
-i.e. names containing at least one dot, such as object.attribute or
-more general one, such as obj.attr.subattr.&quot;&quot;&quot;
-
-# Notice that dotted.names in comments and literal strings are ignored
-
-from oopp import *
-import __main__
-
-text=inspect.getsource(__main__)
-
-regexp=Regexp.CODESEP| Regexp.DOTNAME.named()
-
-print 'Using the regular expression',regexp
-
-print &quot;I have found the following dotted names:\n%s&quot; % [
- MO.group() for MO in regexp.finditer(text) if MO.lastgroup=='DOTNAME']
-
-#&lt;/test_re.py&gt;
-</pre>
-</blockquote>
-<p>with output:</p>
-<blockquote>
-<pre class="literal-block">
-Using the regular expression (?s)(?P&lt;COMMENT&gt;#.*?(?=\n))|(?P&lt;STRING&gt;
-'''.+?'''|&quot;&quot;&quot;.+?&quot;&quot;&quot;|'.+?'|&quot;.+?&quot;)|(?P&lt;DOTNAME&gt;[a-zA-Z_]\w*\.[\w\.]*)
-I have found the following dotted names:
-['inspect.getsource', 'Regexp.CODESEP', 'Regexp.DOTNAME.named', 'MO.group',
- 'dotname.finditer', 'MO.lastgroup']
-</pre>
-</blockquote>
-<p>Now one can define a good <tt class="literal"><span class="pre">CodeStr</span></tt> class with replacing features</p>
-<p>Let me consider for instance the solution to the problem discussed in chapter
-4, i.e. the definition of a <tt class="literal"><span class="pre">TextStr</span></tt> class able to indent and dedent
-blocks of text.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def codeprocess(code,TPO): # TPO=text processing operator
- code=code.replace(&quot;\\'&quot;,&quot;\x01&quot;).replace('\\&quot;','\x02')
- genblock,out = Regexp.CODESEP.generateblocks(code),[]
- for block in genblock:
- out.append(TPO(block))
- out.append(genblock.next())
- return ''.join(out).replace(&quot;\x01&quot;,&quot;\\'&quot;).replace('\x02','\\&quot;')
-
-def quotencode(text):
- return text.replace(&quot;\\'&quot;,&quot;\x01&quot;).replace('\\&quot;','\x02')
-
-def quotdecode(text):
- return text.replace(&quot;\x01&quot;,&quot;\\'&quot;).replace('\x02','\\&quot;')
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here is an example of usage: replacing 'Print' with 'print' except in
-comments and literal strings.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;codeproc.py&gt;
-
-from oopp import codeprocess
-
-wrongcode=r'''
-&quot;&quot;&quot;Code processing example: replaces 'Print' with 'print' except in
-comments and literal strings&quot;&quot;&quot;
-Print &quot;This program prints \&quot;Hello World!\&quot;&quot; # look at this line!
-'''
-
-fixPrint=lambda s: s.replace('Print','print')
-validcode=codeprocess(wrongcode,fixPrint)
-
-print 'Source code:\n',validcode
-print 'Output:\n'; exec validcode
-
-#&lt;/codeproc.py&gt;
-</pre>
-</blockquote>
-<p>with output</p>
-<blockquote>
-<pre class="literal-block">
-Source code:
-
-&quot;&quot;&quot;Code processing example: replaces 'Print' with 'print' except in
-comments and literal strings&quot;&quot;&quot;
-print &quot;Prints \&quot;Hello World!\&quot;&quot; # look at this line!
-
-Output:
-
-This program prints &quot;Hello World!&quot;
-</pre>
-</blockquote>
-</div>
-<div class="section" id="a-simple-state-machine">
-<h2><a class="toc-backref" href="#id132" name="a-simple-state-machine">A simple state machine</a></h2>
-<p>Regular expression, however powerful, are limited in scope since they
-cannot recognize recursive structures. For instance, they cannot parse
-parenthesized expression.</p>
-<p>The simplest way to parse a parenthesized expression is to use a state
-machine.</p>
-<blockquote>
-<pre class="literal-block">
-(?:...) non-grouping
-(?P&lt;name&gt;...)
-
-(?=...) look-ahead
-(?!...) negative
-(?&lt;=...) look-behind
-(?&lt;!...) negative
-
-dec=\
-&quot;&quot;&quot;
-paren = ( .. )
-bracket = [ .. ]
-brace = { .. }
-comment = # .. \n
-&quot;&quot;&quot;
-
-actions=\
-&quot;&quot;&quot;
-reobj1 : R' .. (?&lt;!\\)' -&gt; Regexp(r''' .. ''')
-reobj2 : R&quot; .. (?&lt;!\\)&quot; -&gt; Regexp(r&quot;&quot;&quot; .. &quot;&quot;&quot;)
-string1 : (?&lt;!')'(?!') .. (?&lt;!\\)'(?!') -&gt; ''' .. '''
-string2 : (?&lt;!&quot;)&quot;(?!&quot;) .. (?&lt;!\\)&quot;(?!&quot;) -&gt; &quot;&quot;&quot; .. &quot;&quot;&quot;
-&quot;&quot;&quot;
-
-beg=0; end=1
-
-string1[beg]=r&quot;(?&lt;!')'(?!')&quot; # an isolated single quote
-string2[beg]=r'(?&lt;!&quot;)&quot;(?!&quot;)' # an isolated double quote
-string1[end]=r&quot;(?&lt;!\\)'(?!')&quot; # ending single quote
-string2[end]=r'(?&lt;!\\)&quot;(?!&quot;)' # ending double quote
-
-reobj1[beg]=r&quot;R'&quot;
-reobj2[beg]=r'R&quot;'
-reobj1[end]=string1[end] # ending single quote
-reobj2[end]=string2[end] # ending double quote
-
-actions=\
-&quot;&quot;&quot;
-reobj1 : R' .. (?&lt;!\\)' -&gt; Regexp(r''' .. ''')
-reobj2 : R&quot; .. (?&lt;!\\)&quot; -&gt; Regexp(r&quot;&quot;&quot; .. &quot;&quot;&quot;)
-string1 : (?&lt;!')'(?!') .. (?&lt;!\\)'(?!') -&gt; ''' .. '''
-string2 : (?&lt;!&quot;)&quot;(?!&quot;) .. (?&lt;!\\)&quot;(?!&quot;) -&gt; &quot;&quot;&quot; .. &quot;&quot;&quot;
-&quot;&quot;&quot;
-
-beg={}; end={}; ls=[]
-for line in decl.splitlines():
- mode,rest=line.split(' : ')
- s,r=rest.split(' -&gt; ')
-
- beg[mode],end[mode]=s.split(' .. ')
- ls.append('(?P&lt;beg_%s&gt;%s)' % (mode,beg[mode]))
- ls.append('(?P&lt;end_%s&gt;%s)' % (mode,end[mode]))
-
- beg2[mode],end2[mode]=r.split(' .. ')
- ls.append(beg2[mode])
- ls.append(end2[mode])
-
-delimiters='(%s)' % re.compile('|'.join(ls))
-splitlist=['']+delimiters.split(source)
-for delim,text in splitlist:
- delimiters.match(delim).lastgroup
-</pre>
-</blockquote>
-</div>
-<div class="section" id="creating-classes">
-<h2><a class="toc-backref" href="#id133" name="creating-classes">Creating classes</a></h2>
-<p>TODO</p>
-</div>
-<div class="section" id="modifying-modules">
-<h2><a class="toc-backref" href="#id134" name="modifying-modules">Modifying modules</a></h2>
-<p>Metaclasses are extremely
-useful since they allows to change the behaviour of the code without
-changing the sources. For instance, suppose you have a large library written
-by others that you want to enhance in some way.</p>
-<p>Typically, it is always a bad idea to modify the sources, for many reasons:</p>
-<ul class="simple">
-<li>touching code written by others, you may introduce new bugs;</li>
-<li>you may have many scripts that requires the original version
-of the library, not the modified one;</li>
-<li>if you change the sources and then you buy the new version of the
-library, you have to change the sources again!</li>
-</ul>
-<p>The solution is to enhance the proprierties of the library at run
-time, when the module is imported, by using metaclasses.</p>
-<p>To show a concrete example, let me consider the case of the module
-<em>commands</em> in the Standard Library. This module is Unix-specific,
-and cannot be used under Windows. It would be nice to have a
-metaclass able to enhance the module in such a way that
-when it is invoked on a Windows platform, Windows specific replacement
-of the Unix functions provided in the module are used. However,
-for sake of brevity, I will only give a metaclasses that display
-a nice message in the case we are in a Window platform, without
-raising an error (one could easily implement such a behaviour,
-however).</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;recognizewindows.py&gt;
-
-import oopp,sys,commands
-
-class WindowsAware(type):
- def __init__(cls,*args):
- if sys.platform=='win32':
- for key,val in vars(cls).iteritems():
- if isinstance(val,staticmethod):
- setattr(cls,key,staticmethod(lambda *args:
- &quot;Sorry, you are (or I pretend you are) on Windows,&quot;
- &quot; you cannot use the %s.module&quot; % cls.__name__))
-
-sys.platform=&quot;win32&quot; #just in case you are not on Windows
-
-commands=oopp.ClsFactory[WindowsAware](commands)
-
-print commands.getoutput('date') #cannot be executed on Windows
-
-#&lt;/recognizewindows.py&gt;
-</pre>
-</blockquote>
-<p>The output of this script is</p>
-<blockquote>
-<pre class="literal-block">
-Sorry, you are on Windows, you cannot use the commands.module
-</pre>
-</blockquote>
-<p>However, if you are on Linux and you comment out the line</p>
-<blockquote>
-<pre class="literal-block">
-sys.platform=&quot;win32&quot;
-</pre>
-</blockquote>
-<p>you will see that the script works.</p>
-<p>Notice that the line <tt class="literal"><span class="pre">commands=WindowsAware(commands)</span></tt> actually
-converts the 'commands' module in a 'commands' class, but since
-the usage is the same, this will fool all programs using the
-commands module. In this case the class factory 'WindowsAware'
-can also be thought as a module modifier. In this sense, it is
-very useful to denote the metaclass with an <em>adjective</em>.</p>
-</div>
-<div class="section" id="metaclasses-and-attribute-descriptors">
-<h2><a class="toc-backref" href="#id135" name="metaclasses-and-attribute-descriptors">Metaclasses and attribute descriptors</a></h2>
-<p>Descriptors are especially useful in conjunction with metaclasses, since
-a custom metaclass can use them as low level tools to modify the methods
-and the attributes of its instances. This allows to implement very
-sophisticated features with few lines of code.</p>
-<p>Notice, anyway, that
-even plain old function can be thought of as of descriptors.</p>
-<p>Descriptors share at least two features with metaclasses:</p>
-<ol class="arabic simple">
-<li>as metaclasses, descriptors are best used as adjectives, since they
-are intended to modify and enhance standard methods and attributes, in the
-same sense metaclasses modify and enhance standard classes;</li>
-<li>as metaclasses, descriptors can change the <em>semantics</em> of Python, i.e.
-what you see is not necessarely what you get. As such, they are a
-dangerous feature. Use them with judgement!</li>
-</ol>
-<p>Now I will show a possible application of properties.
-Suppose one has a given class with various kind of
-attributes (plain methods, regular methods, static methods,
-class methods, properties and data attributes) and she wants
-to trace to access to the data attributes (notice that the motivation
-for the following problem come from a real question asked in
-comp.lang.python). Then one needs to retrieve data
-attributes from the class and convert them in properties
-controlling their access syntax. The first problem is solved
-by a simple function</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def isplaindata(a):
- &quot;&quot;&quot;A data attribute has no __get__ or __set__ attributes, is not
- a built-in function, nor a built-in method.&quot;&quot;&quot;
- return not(hasattr(a,'__get__') or hasattr(a,'__set__')
- or isinstance(a,BuiltinMethodType) or
- isinstance(a,BuiltinFunctionType))
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>whereas the second problem is elegantly solved by a custom metaclass:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;tracedaccess.py&gt;
-
-from oopp import isplaindata,inspect
-
-class TracedAccess(type):
- &quot;Metaclass converting data attributes to properties&quot;
- def __init__(cls,name,bases,dic):
- cls.datadic={}
- for a in dic:
- if isplaindata(a):
- cls.datadic[a]=dic[a]
- def get(self,a=a):
- v=cls.datadic[a]
- print &quot;Accessing %s, value=%s&quot; % (a,v)
- return v
- def set(self,v,a=a):
- print &quot;Setting %s, value=%s&quot; % (a,v)
- cls.datadic[a]=v
- setattr(cls,a,property(get,set))
-
-class C(object):
- __metaclass__ = TracedAccess
- a1='x'
-
-class D(C): # shows that the approach works well with inheritance
- a2='y'
-
-i=D()
-i.a1 # =&gt; Accessing a1, value=x
-i.a2 # =&gt; Accessing a2, value=y
-i.a1='z' # =&gt; Setting a1, value=z
-i.a1 # =&gt; Accessing a1, value=z
-
-#&lt;/tracedaccess.py&gt;
-</pre>
-</blockquote>
-<p>In this example the metaclass looks at the plain data attributes (recognized
-thanks ot the <tt class="literal"><span class="pre">isplaindata</span></tt> function) of its instances and put them
-in the dictionary <tt class="literal"><span class="pre">cls.datadic</span></tt>. Then the original attributes are replaced
-with property objects tracing the access to them. The solution is a 4-line
-custom metaclass doing the boring job for me:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class Wrapped(Customizable,type):
- &quot;&quot;&quot;A customizable metaclass to wrap methods with a given wrapper and
- a given condition&quot;&quot;&quot;
- __metaclass__=Reflective
- wrapper=wrappedmethod
- condition=lambda k,v: True # wrap all
- def __init__(cls,*args):
- super(cls.__this,cls).__init__(*args)
- wrap(cls,cls.wrapper,cls.condition.im_func)
-
-Traced=Wrapped.With(wrapper=tracedmethod,__name__='Traced')
-Timed=Wrapped.With(wrapper=timedmethod,__name__='Timed')
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here is an example of usage:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; time_=ClsFactory[Traced](time)
-&gt;&gt;&gt; print time_.asctime()
-[time_] Calling 'asctime' with arguments
-(){} ...
--&gt; 'time_.asctime' called with result: Sun May 4 07:30:51 2003
-Sun May 4 07:30:51 2003
-</pre>
-</blockquote>
-<p>Another is</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;tracemain.py&gt;
-
-from oopp import ClsFactory,Traced,Reflective
-
-def f1(x): return x # nested functions
-def f2(x): return f1(x) # we want to trace
-
-f1orf2=lambda k,v : v is f1 or v is f2
-make=ClsFactory[Reflective,Traced.With(condition=f1orf2)]
-traced=make('traced',globals())
-
-traced.f2('hello!') # call traced.f2
-
-#&lt;/tracemain.py&gt;
-</pre>
-</blockquote>
-<p>with output</p>
-<blockquote>
-<pre class="literal-block">
-[__main__] Calling 'f2' with arguments
-('hello!',){} ...
-[__main__] Calling 'f1' with arguments
-('hello!',){} ...
--&gt; '__main__.f1' called with result: hello!
--&gt; '__main__.f2' called with result: hello!
-</pre>
-</blockquote>
-</div>
-<div class="section" id="id46">
-<h2><a class="toc-backref" href="#id136" name="id46">Modifying hierarchies</a></h2>
-<p>Suppose one wants to enhance a pre-existing class, for instance
-by adding tracing capabilities to it. The problem is non-trivial
-since it is not enough to derive a new class from the original
-class using the 'Traced' metaclass. For instance, we could imagine of
-tracing the 'Pizza' class introduced in chapter 4 by defining</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; class TracedTomatoPizza(GenericPizza,WithLogger):
-... __metaclass__=ClsFactory[Traced]
-... toppinglist=['tomato']
-</pre>
-</blockquote>
-<p>However, this would only trace the methods of the newly defined class,
-not of the original one. Since the new class does not introduce any
-non-trivial method, the addition of 'Traced' is practically without
-any effect:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; marinara=TracedTomatoPizza('small') # nothing happens
-*****************************************************************************
-Tue Apr 15 11:00:17 2003
-1. Created small pizza with tomato, cost $ 1.5
-</pre>
-</blockquote>
-</div>
-<div class="section" id="tracing-hierarchies">
-<h2><a class="toc-backref" href="#id137" name="tracing-hierarchies">Tracing hierarchies</a></h2>
-<blockquote>
-<pre class="literal-block">
-#&lt;traceH.py&gt;
-
-from oopp import *
-
-def wrapMRO(cls,wrapped):
- for c in cls.__mro__[:-1]:
- wrap(c,wrapped)
-
-tracing=tracedmethod.With(logfile=file('trace.txt','w'))
-wrapMRO(HomoSapiensSapiens,tracing)
-HomoSapiensSapiens().can()
-
-#&lt;/traceH.py&gt;
-</pre>
-</blockquote>
-<p>with output in trace.txt</p>
-<blockquote>
-<pre class="literal-block">
-[HomoSapiensSapiens] Calling 'can' with arguments
- (&lt;oopp.HomoSapiensSapiens object at 0x4020364c&gt;,){} ...
- [HomoSapiens] Calling 'can' with arguments
- (&lt;oopp.HomoSapiensSapiens object at 0x4020364c&gt;,){} ...
- [HomoHabilis] Calling 'can' with arguments
- (&lt;oopp.HomoSapiensSapiens object at 0x4020364c&gt;,){} ...
- [Homo] Calling 'can' with arguments
- (&lt;oopp.HomoSapiensSapiens object at 0x4020364c&gt;,){} ...
- [PrettyPrinted] Calling '__str__' with arguments
- (&lt;oopp.HomoSapiensSapiens object at 0x4020364c&gt;,){} ...
- [PrettyPrinted.__str__] called with result:
- &lt;HomoSapiensSapiens&gt;
- [Homo.can] called with result: None
- [HomoHabilis.can] called with result: None
- [HomoSapiens.can] called with result: None
-[HomoSapiensSapiens.can] called with result: None
-</pre>
-</blockquote>
-</div>
-<div class="section" id="modifying-source-code">
-<h2><a class="toc-backref" href="#id138" name="modifying-source-code">Modifying source code</a></h2>
-<p>The real solution would be to derive the original class 'GenericPizza'
-from 'Traced' and not from 'object'. One could imagine of creating
-a new class inhering from 'Traced' and with all the methods of the
-original 'GenericPizza' class; then one should create copies of
-all the classes in the whole multiple inheritance hierarchy.
-This would be a little annoying, but feasable; the real problem is
-that this approach would not work with cooperative methods, since
-cooperative calls in the derived classes would invoked methods in
-the original classes, which are not traced.</p>
-<p>This is a case where the modification of the original source code is
-much more appealing and simpler that any other method: it is enough
-to perform a search and replace in the original source code, by adding
-the metaclass 'Traced', to enhance the whole multiple inheritance hierarchy.
-Let me assume that the hierarchy is contained in a module (which is
-typical case). The idea, is to generate <em>dynamically</em> a new module from the
-modified source code, with a suitable name to avoid conflicts with the
-original module. Incredibily enough, this can be done in few lines:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def modulesub(s,r,module):
- &quot;Requires 2.3&quot;
- name=module.__name__
- source=inspect.getsource(module).replace(s,r)
- dic={name: module}; exec source in dic # exec the modified module
- module2=ModuleType(name+'2') # creates an an empty module
- customize(module2,**dic) # populates it with dic
- return module2
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Notice that the <tt class="literal"><span class="pre">sub</span></tt> function, that modifies the source code of
-a given module and returns a modified module, requires Python 2.3
-to work. This is a due to a subtle bug in <tt class="literal"><span class="pre">exec</span></tt> in Python 2.2.
-Anyway, the restriction to Python 2.3 allows me to take advantage
-of one of the most elegant convenience of Python 2.3: the name in
-the <tt class="literal"><span class="pre">types</span></tt> module acts are type factories and in particular
-<tt class="literal"><span class="pre">ModuleType(s)</span></tt> returns an (empty) module named <tt class="literal"><span class="pre">s</span></tt>.
-Here is an example of usage:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import oopp
-&gt;&gt;&gt; s='GenericPizza(object):'
-&gt;&gt;&gt; oopp2=oopp.modulesub(s,s+'\n __metaclass__=oopp.Traced',oopp)
-</pre>
-</blockquote>
-<p>Name clashes are avoided, being 'oopp2' a different module from
-'oopp'; we have simultaneously access to both the original hierarchy
-in 'oopp' (non-traced) and the modified one in 'oopp2' (traced).
-In particular 'oopp2.CustomizablePizza' is traced and therefore</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class PizzaLog(oopp2.CustomizablePizza,oopp2.WithLogger):
-... __metaclass__=makecls()
-&gt;&gt;&gt; marinara=PizzaLog.With(toppinglist=['tomato'])('small')
-</pre>
-</blockquote>
-<p>gives the output</p>
-<blockquote>
-<pre class="literal-block">
-[PizzaLog] Calling '__init__' with arguments
-(&lt;oopp.PizzaLog object at 0x40470dac&gt;, 'small'){} ...
--&gt; 'PizzaLog.__init__' called with result: None
-
-*****************************************************************************
-Thu Mar 27 09:18:28 2003
-[PizzaLog] Calling '__str__' with arguments
-(&lt;oopp.PizzaLog object at 0x40470dac&gt;,){} ...
-[PizzaLog] Calling 'price' with arguments
-(&lt;oopp.PizzaLog object at 0x40470dac&gt;,){} ...
-[PizzaLog] Calling 'toppings_price' with arguments
-(&lt;oopp.PizzaLog object at 0x40470dac&gt;,){} ...
--&gt; 'PizzaLog.toppings_price' called with result: 0.5
-
--&gt; 'PizzaLog.price' called with result: 1.5
-
--&gt; 'PizzaLog.__str__' called with result: small pizza with tomato, cost $ 1.5
-
-1. Created small pizza with tomato, cost $ 1.5
-</pre>
-</blockquote>
-<p>From that we understand what is happening:</p>
-<ul class="simple">
-<li><tt class="literal"><span class="pre">PizzaLog.__init__</span></tt> calls <tt class="literal"><span class="pre">GenericPizza.__init__</span></tt> that defines size and
-cooperatively calls <tt class="literal"><span class="pre">WithLogger.__init__</span></tt></li>
-<li>WithLogger.__init__ cooperatively calls <tt class="literal"><span class="pre">WithCounter.__init__</span></tt>
-that increments the count attribute;</li>
-<li>at this point, the instruction 'print self' in <tt class="literal"><span class="pre">WithLogger.__init__</span></tt> calls
-<tt class="literal"><span class="pre">PizzaLog.__str__</span></tt> (inherited from <tt class="literal"><span class="pre">GenericPizza.__str__</span></tt>);</li>
-<li><tt class="literal"><span class="pre">GenericPizza.__str__</span></tt> calls 'price' that in turns calls
-'toppings_price'.</li>
-</ul>
-<p>On top of that, notice that the metaclass of 'PizzaLog' is
-<tt class="literal"><span class="pre">_TracedReflective</span></tt> that has been automagically generated by
-<tt class="literal"><span class="pre">makecls</span></tt> from the metaclasses of 'CustomizablePizza' (i.e. 'Traced')
-and of 'WithLogger' (i.e. 'Reflective'); the leading underscore helps
-to understand the dynamical origin of '_TracedReflective'.
-It turns out that '_TracedReflective' has a dynamically
-generated (meta-meta)class:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print type(type(PizzaLog)) #meta-metaclass
-&lt;class 'oopp._WithWrappingCapabilitiesReflective'&gt;
-</pre>
-</blockquote>
-<p>Therefore this example has a non-trivial class hierarchy</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print oopp.MRO(PizzaLog)
-MRO of PizzaLog:
- 0 - PizzaLog(CustomizablePizza,WithLogger)[Traced]
- 1 - CustomizablePizza(GenericPizza,Customizable)[Traced]
- 2 - GenericPizza(object)[Traced]
- 3 - WithLogger(WithCounter,Customizable,PrettyPrinted)
- 4 - WithCounter(object)
- 5 - Customizable(object)
- 6 - PrettyPrinted(object)
- 7 - object()
-</pre>
-</blockquote>
-<p>a non-trivial metaclass hierarchy,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print oopp.MRO(type(PizzaLog)) # the metaclass hierarchy
-MRO of Traced:
- 0 - Traced(Reflective)[WithWrappingCapabilities]
- 1 - Reflective(type)
- 2 - type(object)
- 3 - object()
-</pre>
-</blockquote>
-<p>and a non-trivial meta-metaclass hierarchy:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print oopp.MRO(type(type(PizzaLog))) # the meta-metaclass hierarchy
-MRO of WithWrappingCapabilities:
- 0 - WithWrappingCapabilities(BracketCallable)
- 1 - CallableWithBrackets(type)
- 2 - type(object)
- 3 - object()
-</pre>
-</blockquote>
-<p>Pretty much complicated, isn't it ? ;)</p>
-<p>This example is there to show what kind of maintenance one can have
-with programs doing a large use of metaclasses, particularly, when
-they should be understood by somebody else than the autor ...</p>
-</div>
-<div class="section" id="metaclass-regenerated-hierarchies">
-<h2><a class="toc-backref" href="#id139" name="metaclass-regenerated-hierarchies">Metaclass regenerated hierarchies</a></h2>
-<blockquote>
-<pre class="literal-block">
-import types
-
-def hierarchy(self,cls):
- d=dict([(t.__name__,t) for t in vars(types).itervalues()
- if isinstance(t,type)])
- def new(c):
- bases=tuple([d[b.__name__] for b in c.__bases__])
- return self(c.__name__, bases, c.__dict__.copy())
- mro=list(cls.__mro__[:-1])
- mro.reverse()
- for c in mro:
- if not c.__name__ in d:
- d[c.__name__]=new(c)
- customize(self,**d)
-
-ClsFactory.hierarchy=hierarchy
-traced=ClsFactory[Traced,Reflective]
-</pre>
-</blockquote>
-<p>Unfortunately, this approach does not work if the original hierarchy makes
-named cooperative super calls.</p>
-<p>Therefore the source-code run-time modification has its advantages.</p>
-</div>
-</div>
-<div class="section" id="the-programmable-programming-language">
-<h1><a class="toc-backref" href="#id140" name="the-programmable-programming-language">THE PROGRAMMABLE PROGRAMMING LANGUAGE</a></h1>
-<blockquote>
-<em>I think that lisp is a better applications language than Python.
-However, Python is close enough, or at least so much better than the
-alternatives, that Python's social and glue language advantages are
-often decisive.</em> -- Andy Freeman on c.l.p.</blockquote>
-<p>I go in <em>really</em> DEEP BLACK MAGIC here.</p>
-<p>Lisp has been called the <em>programmable programming language</em> <a class="footnote-reference" href="#id43" id="id47" name="id47">[22]</a>
-since its macros allow the programmer to change the <em>syntax</em> of
-the language. Python has no macros and the syntax of the language
-cannot be changed. Nevertheless, Python metaclasses allows
-to change the <em>semantics</em> of the language. In this sense, they
-are even more powerful and more dangerous than Lisp macros.
-Python metaclass allow the user to customize the language (if not
-its syntax). This is cool enough, however it can make your programs
-unreadable by others. The techniques explained in this
-chapter should be used with care. Nevertheless, I trust the judgement
-of the programmer who has been able to reach this chapter, and I don't
-mind providing him further rope to shoot in his/her foot ;)</p>
-<table class="footnote" frame="void" id="id48" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a name="id48">[24]</a></td><td>Paul Graham, 'OnLisp'
-citing</td></tr>
-</tbody>
-</table>
-<div class="section" id="enhancing-the-python-language">
-<h2><a class="toc-backref" href="#id141" name="enhancing-the-python-language">Enhancing the Python language</a></h2>
-<p>Let me start with some minor usage of metaclasses. In this section I
-will show how the user can implement in few lines features that are
-built-in in other languages, through a minimal usage of metaclasses.</p>
-<p>For instance, suppose one wants to define a class which cannot be
-derived: in Java this can be done with the &quot;final&quot; keyword.
-In Python there is no need to add a new keyword to the language:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class NonDerivableError(Exception): pass
-
-class Final(type): # better derived from WithCounter,type
- &quot;Instances of Final cannot be derived&quot;
- def __new__(meta,name,bases,dic):
- try:
- meta.already_called is True
- except AttributeError: # not already called
- meta.already_called=True
- return super(Final,meta).__new__(meta,name,bases,dic)
- else: #if already called
- raise NonDerivableError(&quot;I cannot derive from %s&quot; % bases)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here there is an example of usage:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import Final
-&gt;&gt;&gt; class C:
-... __metaclass__=Final
-...
-&gt;&gt;&gt; class D(C): pass #error
-...
-NonDerivableError: D not created from (&lt;class 'oopp.C'&gt;,)
-</pre>
-</blockquote>
-<p>It is interesting to notice that a similar effect can be reached
-with a <tt class="literal"><span class="pre">singletonClass</span></tt> class factory: a 'MetaSingleton' inherits
-from <tt class="literal"><span class="pre">Singleton</span></tt> and from 'type' (therefore it is a metaclass):</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class S(Singleton,type): pass
-singletonClass=ClsFactory[S]
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>If we write</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import singletonClass
-&gt;&gt;&gt; C=singletonClass()
-&gt;&gt;&gt; class D(C):
-... pass
-</pre>
-</blockquote>
-<p>we see that actually 'D' is not a new instance of 'Singleton', but
-it coincides with 'C', instead:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; id(C),id(D)
-(135622140, 135622140)
-&gt;&gt;&gt; C is D
-True
-&gt;&gt;&gt; type(C)
-&lt;class '__main__._Singleton'&gt;
-&gt;&gt;&gt; type(C).__bases__
-(&lt;class 'oopp.Singleton'&gt;, &lt;type 'type'&gt;)
-&gt;&gt;&gt; c=C(); d=D()
-&gt;&gt;&gt; id(c),id(d)
-(1075378028, 1075378924)
-</pre>
-</blockquote>
-<p>Notice the order: 'SingletonClass' must inherit from 'Singleton'
-first and from <tt class="literal"><span class="pre">Class</span></tt> second, otherwise the <tt class="literal"><span class="pre">Class.__new__</span></tt> method would
-override the <tt class="literal"><span class="pre">Singleton.__new__</span></tt>, therefore losing the 'Singleton'
-basic property of having only one instance. On the other hand, in
-the correct order, 'Singleton' first and 'Class' second, the inheritance
-diagram is</p>
-<blockquote>
-<pre class="literal-block">
- object 5
- (__new__)
- / \
- / \
-2 WithCounter type 4
- (__new__) (__new__)
- | |
- | |
-1 Singleton Class 3
- (__new__) (__new__)
- \ /
- \ /
- SingletonClass 0
- (Singleton.__new__)
-</pre>
-<pre class="literal-block">
- object
- / \
- / |
-WithCounter |
- | |
-Singleton type
- \ /
- \ /
- MetaSingleton
- :
- :
- : instantiation
- :
- :
- C = D
-</pre>
-</blockquote>
-<p>whereas 'SingletonClass' inherits <tt class="literal"><span class="pre">Singleton.__new__</span></tt> which, trough
-the <tt class="literal"><span class="pre">super</span></tt> mechanism, calls 'type.__new__' and therefore creates
-the class 'C'. Notice that class 'D' is never created, it is simply
-an alias for 'C'.</p>
-<p>I think it is simpler to write down the class 'Final' explicitely
-(explicit is better than implicit) as I did; however a fanatic of code
-reuse could derive it from 'SingletonClass':</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;final.py&gt;
-
-from oopp import *
-
-class Final(Singleton,type):
- &quot;Inherits the 'instance' attribute from Singleton (default None)&quot;
- def __new__(meta,name,bases,dic):
- if meta.counter==0: # first call
- return super(Final,meta).__new__(meta,name,bases,dic)
- else:
- raise NonDerivableError(&quot;I cannot derive from %s&quot; % bases)
-
-class C: __metaclass__=Final
-
-try:
- class D(C): pass
-except NonDerivableError,e:
- print e
-
-#&lt;/final.py&gt;
-</pre>
-</blockquote>
-<p>The reader can check that this script has the correct output
-&quot;I cannot derive from &lt;class 'oopp.C'&gt;&quot;. I leave to the reader
-to understand the issues with trying to implement 'NonDerivable'
-from 'NonInstantiable'. #And why an inner metaclass would not work.</p>
-</div>
-<div class="section" id="restricting-python-dynamism">
-<h2><a class="toc-backref" href="#id142" name="restricting-python-dynamism">Restricting Python dynamism</a></h2>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def frozen(self,name,value):
- if hasattr(self,name):
- type(self).__bases__[0].__setattr__(self,name,value)
- else:
- raise AttributeError(&quot;You cannot add attributes to %s&quot; % self)
-
-class Frozen(object):
- &quot;&quot;&quot;Subclasses of Frozen are frozen, i.e. it is impossibile to add
- new attributes to them and their instances&quot;&quot;&quot;
- __setattr__ = frozen
- class __metaclass__(type):
- __setattr__ = frozen
-
-#&lt;/oopp.py&gt;
-
-
-#&lt;frozen.py&gt;
-
-from oopp import *
-
-class C(Frozen):
- c=1
- def __init__(self):
- #self.x=5 # won't work anymore, __new__ will be okay
- pass
-
-class D(C):
- d=2
-
-C.c=2
-
-print D().d
-
-#&lt;/frozen.py&gt;
-</pre>
-</blockquote>
-</div>
-<div class="section" id="changing-the-language-without-changing-the-language">
-<h2><a class="toc-backref" href="#id143" name="changing-the-language-without-changing-the-language">Changing the language without changing the language</a></h2>
-<p>In Lisp the user has the possibility of changing the syntax of the
-language to suit her purposes (or simply to fit her taste).
-In Python, the user cannot change the basic grammar of the language,
-nevertheless, to a great extent, metaclasses allows to emulate this effect.
-Notice that using metaclasses to this aim is not necessarely
-a good idea, since once you start
-changing the Python standard behaviour, it will become impossible for
-others to understand your programs (which is what happened to Lisp ;).</p>
-<p>Let me show how metaclasses can be used to provide notational convenience
-(i.e. syntactic sugar) for Python.</p>
-<p>As first example, I will show how we may use metaclasses to provide some
-convenient notation for staticmethods and classmethods:</p>
-<blockquote>
-<pre class="literal-block">
-class MetaSugar(type):
- def __init__(cls,name,bases,clsdict):
- for key,value in clsdict.iteritems():
- if key.startswith(&quot;static_&quot;):
- setattr(cls,key[7:],staticmethod(value))
- elif key.startwith(&quot;class_&quot;):
- setattr(cls,key[6:],classmethod(value))
-</pre>
-</blockquote>
-<p>The same effect can be obtained trough normal inheritance</p>
-<blockquote>
-<pre class="literal-block">
-class SyntacticSugar(object):
- def __init__(self):
- for k,v in self.__class__.__dict__.iteritems():
- if k.startswith('static_'):
- self.__class__.__dict__[k[7:]] = staticmethod(v)
- if k.startswith('static_'):
- self.__class__.__dict__[k[7:]] = staticmethod(v)
-</pre>
-</blockquote>
-<p>Let me now implement some syntactic sugar for the __metaclass__ hook.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import re
-squarednames=re.compile('\[([A-Za-z_][\w\., ]*)\]')
-
-def inferredfromdocstring(name,bases,dic):
- docstring=dic['__doc__']
- match=squarednames.match(docstring)
- if not match: return ClsFactory[Reflective](name,bases,dic)
- metanames=[name.strip() for name in match.group(1).split(',')]
- metaname=''.join(metanames)
- if len(metanames)&gt;1: # creates a new metaclass
- metaclass=type(metaname,tuple(map(eval,metanames)),{})
- else:
- metaclass=eval(metaname)
- return ClsFactory[metaclass](name,bases,dic)
-
-#&lt;/oopp.py&gt;
-
-#&lt;sugar.py&gt;
-
-from oopp import *
-__metaclass__ = inferredfromdocstring
-class B:
- &quot;Do nothing class&quot;
-
-class C:
- &quot;[Reflective]&quot;
- &quot; Do nothing class&quot;
-
-class D:
- &quot;[WithLogger,Final]&quot;
- &quot;Do nothing class&quot;
-
-class E(C):
- pass
-
-#&lt;/sugar.py&gt;
-</pre>
-</blockquote>
-<p>With output:</p>
-<blockquote>
-<pre class="literal-block">
-*****************************************************************************
-Fri Feb 21 09:35:58 2003
-Creating class Logged_C descending from (),
-instance of &lt;class 'oopp.Logged'&gt;
-
-Logged_C dictionary:
- __doc__ = Do nothing class
-*****************************************************************************
-Fri Feb 21 09:35:58 2003
-Creating class Logged_Final_D descending from (),
-instance of &lt;class 'oopp.LoggedFinal'&gt;
-
-Logged_Final_D dictionary:
-__doc__ = Do nothing class
-*****************************************************************************
-Fri Feb 21 09:35:58 2003
-Creating class E descending from (&lt;class 'oopp.Logged_C'&gt;,),
-instance of &lt;class 'oopp.Logged'&gt;
-
-E dictionary:
-&lt;EMPTY&gt;
-</pre>
-</blockquote>
-<p>At the end, let me point out few observations:
-Metaclasses can be used to provide syntactic sugar, as I have shown
-in the previous example. However, I have given the previous
-routines as a proof of concept: I do <em>not</em> use these routines in
-my actual code for many good reasons:</p>
-<ol class="arabic simple">
-<li>At the end a convenient notation will be provided in Python 2.4</li>
-<li>I don't want to use magic tricks on my code, I want others to
-be able to understand what the code is doing;</li>
-<li>I want to be able myself to understand my own code in six months
-from today ;)</li>
-</ol>
-<p>Anyway, I think it is a good thing to know about this potentiality
-of metaclasses, that can turn out to be very convenient in certain
-applications: but this does not mean that should be blindly used
-and/or abused. In other words: with great powers come
-great responsabilities ;)</p>
-</div>
-<div class="section" id="recognizing-magic-comments">
-<h2><a class="toc-backref" href="#id144" name="recognizing-magic-comments">Recognizing magic comments</a></h2>
-<p>In this section, I will begin to unravel the secrets of the black magic art
-of changing Python semantics and I will show that with few lines
-involving metaclasses
-and the standard library 'inspect' module, even comments can be made
-significant! (let me continue with my series &quot;how to do what should not
-be done&quot;).</p>
-<p>To this aim, I need a brief digression on regular expressions.</p>
-<blockquote>
-<pre class="literal-block">
-class RecognizesMagicComments(object):
- form=r'def %s(NAME)(args):#!\s?staticmethod'
- class __metaclass__(type):
- def __new__(meta,name,bases,dic):
- code=[]
- for attr in dic:
- source=inspect.getsource(dic[attr]).splitlines()
- for line in source:
- split=line.split('#!')
- if len(split)==2:
- descriptor=split[1]; code.append(split[0])
- else: code.append(line)
-
-class C(RecognizesMagicComments):
- #!staticmethod
- def f(x): #!staticmethod
- return x
-</pre>
-</blockquote>
-</div>
-<div class="section" id="interpreting-python-source-code-on-the-fly">
-<h2><a class="toc-backref" href="#id145" name="interpreting-python-source-code-on-the-fly">Interpreting Python source code on the fly</a></h2>
-<p>At this point, I can really go <em>DEEP</em> in black magic.</p>
-<blockquote>
-<pre class="literal-block">
-import sys, inspect, linecache, re
-
-def cls_source(name,module):
- lines = linecache.getlines(inspect.getsourcefile(module))
- if not lines: raise IOError, 'could not get source code'
- pat = re.compile(r'^\s*class\s*' + name + r'\b')
- for i in range(len(lines)):
- if pat.match(lines[i]): break
- else: raise IOError, 'could not find class definition'
- lines, lnum = inspect.getblock(lines[i:]), i + 1
- return ''.join(lines)
-
-class Interpreter(object):
- def __init__(self,CPO): # possible composition of code processing opers
- self.repl=CPO
- def __call__(self,name,bases,dic):
- try:
- modulename=dic['__module__'] # module where the class is defined
- except KeyError: # no __module__ attribute
- raise IOError(&quot;Class %s cannot be defined dynamically or in the\n&quot;
- &quot;interpreter and the source code cannot came from a pipe&quot;% name)
- module=sys.modules[modulename]
- source=self.repl(cls_source(name,module))
- source=re.sub('__metaclass__=.*','__metaclass__=type',source)
- #print source
- loc={}; exec source in vars(module),loc
- return loc[name]
-
-regexp_expand=Interpreter(regexp)
-</pre>
-</blockquote>
-</div>
-<div class="section" id="implementing-lazy-evaluation">
-<h2><a class="toc-backref" href="#id146" name="implementing-lazy-evaluation">Implementing lazy evaluation</a></h2>
-<p>At this point of our knowledge, it becomes trivial to implement lazy
-evaluation and then a ternary operator. (My original, simpler, implementation
-is posted on c.l.p.; see the thread 'PEP 312 (and thus 308) implemented
-with a black magic trick')</p>
-</div>
-<div class="section" id="implementing-a-ternary-operator">
-<h2><a class="toc-backref" href="#id147" name="implementing-a-ternary-operator">Implementing a ternary operator</a></h2>
-<blockquote>
-<pre class="literal-block">
-# module ternary.py
-
-&quot;PEP 308 and 312 implemented via a metaclass-powered dirty trick&quot;
-
-import inspect,__main__
-
-# the ternary operator:
-
-def if_(cond,f,g):
- &quot;Short circuiting ternary operator implemented via lambdas&quot;
- if cond: return f()
- else: return g()
-
-# the metaclass black magic:
-
-class DirtyTrick(type):
- &quot;&quot;&quot;Cooperative metaclass that looks at the source code of its instances
- and replaces the string '~' with 'lambda :' before the class creation&quot;&quot;&quot;
- def __new__(meta,name,bases,dic):
- for attr in dic.values():
- if inspect.isfunction(attr):
- code=inspect.getsource(attr)
- if code.find('~')==-1: continue # no '~' found, skip
- code=code.replace('~','lambda :')
- code=dedent(code)+'\n'
- exec code in __main__.__dict__,dic # modifies dic
- return super(DirtyTrick,meta).__new__(meta,name,bases,dic)
-
-# a convenient base class:
-
-class RecognizesImplicitLambdas:
- &quot;Children of this class do recognize implicit lambdas&quot;
- __metaclass__=DirtyTrick
-</pre>
-</blockquote>
-<p>Here there is an example of usage:</p>
-<blockquote>
-<pre class="literal-block">
-from ternary import if_, RecognizesImplicitLambdas
-from math import sqrt
-
-class C(RecognizesImplicitLambdas):
- def safesqrt(self,x):
- return if_( x&gt;0, ~sqrt(x), ~0) #short-circuiting ternary operator
-
-c=C()
-print c.safesqrt(4), c.safesqrt(-4)
-</pre>
-</blockquote>
-</div>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/bolzano/db/mysql/ui/table.html b/pypers/bolzano/db/mysql/ui/table.html
deleted file mode 100755
index c914c52..0000000
--- a/pypers/bolzano/db/mysql/ui/table.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<table border='1'>
-<tr><th>Variable</th><th>Value</th></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-</table>
diff --git a/pypers/bolzano/db/mysql/ui/x.html b/pypers/bolzano/db/mysql/ui/x.html
deleted file mode 100755
index 999462e..0000000
--- a/pypers/bolzano/db/mysql/ui/x.html
+++ /dev/null
@@ -1,104 +0,0 @@
-[['p', 'r', 'e'], ['c', 'i', 'p'], ['i', 't', 'e'], ['v', 'o', 'l'], ['i', 's', 's'], ['i', 'm', 'e'], ['v', 'o', 'l'], ['m', 'e', 'n'], ['t', 'e']]
-<table border='1'>
-<tr><th>Variable</th><th>Value</th></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-<tr><td>a</td><td>1</td></tr>
-</table>
diff --git a/pypers/bolzano/db/mysql/x.html b/pypers/bolzano/db/mysql/x.html
deleted file mode 100755
index 4a29f1c..0000000
--- a/pypers/bolzano/db/mysql/x.html
+++ /dev/null
@@ -1,2 +0,0 @@
-<h1>Histogram by genre</h1>
- <img src='genre.png'>
diff --git a/pypers/bolzano/links.html b/pypers/bolzano/links.html
deleted file mode 100755
index eee92cc..0000000
--- a/pypers/bolzano/links.html
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title>RIFERIMENTI</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="riferimenti">
-<h1 class="title">RIFERIMENTI</h1>
-<div class="section" id="in-inglese">
-<h1><a name="in-inglese">In Inglese</a></h1>
-<p>Home Page Ufficiale:: www.python.org
-Newsgroup: groups-beta.google.com/group/comp.lang.python
-Tutor:</p>
-</div>
-<div class="section" id="in-italiano">
-<h1><a name="in-italiano">In Italiano</a></h1>
-<p>Home Page Ufficiale: www.python.it
-Newsgroup: groups-beta.google.com/group/it.comp.lang.python</p>
-</div>
-<div class="section" id="libri-tutorials-in-rete">
-<h1><a name="libri-tutorials-in-rete">Libri/Tutorials in rete</a></h1>
-<p>Tradotti in italiano in www.zonapython.it/doc/</p>
-<blockquote>
-<ul class="simple">
-<li>How to Think Like a Computer Scientist</li>
-<li>Dive Into Python</li>
-</ul>
-</blockquote>
-</div>
-<div class="section" id="articoli-riviste">
-<h1><a name="articoli-riviste">Articoli/riviste</a></h1>
-<ol class="arabic simple">
-<li>la rivista italiana di Python: www.pyj.it</li>
-<li>IBMdeveloperWorks: www-130.ibm.com/developerworks/linux</li>
-<li>O' Reilly On LAMP: www.onlamp.com</li>
-</ol>
-</div>
-<div class="section" id="libri-cartacei">
-<h1><a name="libri-cartacei">Libri cartacei</a></h1>
-<p>Due soli libri in Italiano:</p>
-<ol class="arabic simple">
-<li>David Brueck, Stephan Tanner, Python 2.1 Tutto e oltre (Apogeo)</li>
-<li>Mark Lutz, David Asher, Programmare con Python (Hoeply)</li>
-</ol>
-<p>Decine di libri in inglesi. Consigliati:</p>
-<ol class="arabic simple">
-<li>Alex Martelli, Python in a Nushell (O' Reilly)</li>
-<li>Alex Martelli, Python Cookbook (O' Reilly)</li>
-<li>Mark Lutz, David Asher, Learning Python</li>
-</ol>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/bolzano/web/cgi-bin/ex_form.html b/pypers/bolzano/web/cgi-bin/ex_form.html
deleted file mode 100755
index 323edf8..0000000
--- a/pypers/bolzano/web/cgi-bin/ex_form.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<html>
-<head>
-</head>
-<body>
-<form action="hello.py">
-<input type="text" name="phonenumber" value="XXXXX"><br/>
-<input type="submit" name="submit" value="ok">
-</form>
-</body>
-</html>
diff --git a/pypers/bolzano/web/prova.html b/pypers/bolzano/web/prova.html
deleted file mode 100755
index 882f46c..0000000
--- a/pypers/bolzano/web/prova.html
+++ /dev/null
@@ -1 +0,0 @@
-<img src="file:///home/micheles/Desktop/photos-images/images/baldios.jpg">
diff --git a/pypers/classcreation.html b/pypers/classcreation.html
deleted file mode 100755
index 79674b0..0000000
--- a/pypers/classcreation.html
+++ /dev/null
@@ -1,236 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-<div class="section" id="what-happens-when-python-executes-a-class-statement">
-<h1><a name="what-happens-when-python-executes-a-class-statement">What happens when Python executes a class statement?</a></h1>
-<p>It seems an easy question, isn't ?
-But the answer is pretty sophisticated ;)</p>
-<ol class="arabic">
-<li><p class="first">First of all, Python determines which is the currect metaclass to
-use in order to create the class. Here are the rules:</p>
-<ol class="arabic simple">
-<li>if an explicit <tt class="literal"><span class="pre">__metaclass__</span></tt> is given, use it;</li>
-<li>otherwise, determine the correct metaclass from the base classes's
-metaclass.</li>
-</ol>
-<p>The determination from the base
-classes' metaclasses is based on the following principles:</p>
-<ol class="arabic simple">
-<li>custom metaclasses have the precedence over the built-in metaclasses
-<tt class="literal"><span class="pre">type</span></tt> and <tt class="literal"><span class="pre">ClassType</span></tt>;</li>
-<li><tt class="literal"><span class="pre">type</span></tt>, i.e. the default metaclass of new style classes, has the precedence
-over <tt class="literal"><span class="pre">ClassType</span></tt>, the metaclass of old style classes;</li>
-<li>in the case of same precedence the first, i.e. the leftmost
-metaclass is used.</li>
-</ol>
-</li>
-<li><p class="first">Let's call <tt class="literal"><span class="pre">M</span></tt> the correct metaclass. Then <tt class="literal"><span class="pre">M</span></tt> is called in the form
-<tt class="literal"><span class="pre">M(n,b,d)</span></tt>, where <tt class="literal"><span class="pre">n</span></tt> is the name of the class to create, <tt class="literal"><span class="pre">b</span></tt> the tuple
-of its base classes and <tt class="literal"><span class="pre">d</span></tt> its dictionary. This is equivalent to call
-<tt class="literal"><span class="pre">type(M).__call__(M,n,b,d)</span></tt>.</p>
-<p>Now, unless <tt class="literal"><span class="pre">type(M).__call__</span></tt> is overridden with a meta-metaclass,
-the standard <tt class="literal"><span class="pre">type.__call__</span></tt> will be used.</p>
-</li>
-<li><p class="first">The following happens when <tt class="literal"><span class="pre">type.__call__(M,n,b,d)</span></tt> is invoked:</p>
-<ol class="arabic simple">
-<li>Python tries to create the class <tt class="literal"><span class="pre">C</span></tt> by using <tt class="literal"><span class="pre">M.__new__(M,n,b,d)</span></tt>,
-which at a certain moment will invoke <tt class="literal"><span class="pre">type.__new__(M,n,b,d)</span></tt>.</li>
-<li>If a metaclass conflict is found in <tt class="literal"><span class="pre">type.__new__</span></tt>, Python
-raises an exception.</li>
-<li>If not, Python initializes <tt class="literal"><span class="pre">C</span></tt> by using <tt class="literal"><span class="pre">type(C).__init__(C,n,b,d)</span></tt>.</li>
-</ol>
-<p>Notice that <tt class="literal"><span class="pre">type(C)</span></tt> is usually <tt class="literal"><span class="pre">M</span></tt>, unless <tt class="literal"><span class="pre">M.__new__</span></tt> is badly
-overridden by a metaclass novice or very subtly overridden by a metaclass
-wizard.</p>
-</li>
-</ol>
-<p>I argued these rules from experiment, but it should be possible to infer
-them from Python-2.3/Objects/typeobject.c, at least for experts of Python
-internals.</p>
-</div>
-<div class="section" id="an-example-of-badly-written-metaclass">
-<h1><a name="an-example-of-badly-written-metaclass">An example of badly written metaclass</a></h1>
-<p>Let me start by checking the validity of point 3.3, i.e the fact that the
-newly created class is initialized with <tt class="literal"><span class="pre">type(C).__init__(C,n,b,d)</span></tt>
-and not with <tt class="literal"><span class="pre">M.__init__(C,n,b,d)</span></tt>. This happens when <tt class="literal"><span class="pre">M.__new__</span></tt>
-is overridden in such a way that it does not return an instance of <tt class="literal"><span class="pre">M</span></tt>.
-Here is a simple example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(type):
-... &quot;A badly written metaclass&quot;
-... def __new__(mcl,n,b,d):
-... print 'calling M.__new__, name = %s ...' % n
-... return type(n,b,d)
-... def __init__(cls,n,b,d):
-... print 'calling M.__init__, name = %s ...' % n
-</pre>
-<p>In this example <tt class="literal"><span class="pre">M.__new__</span></tt> returns an instance of <tt class="literal"><span class="pre">type</span></tt>, so it
-will be initialized with <tt class="literal"><span class="pre">type.__init__</span></tt> and not with <tt class="literal"><span class="pre">M.__init__</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C:
-... __metaclass__=M
-calling M.__new__, name = C ...
-</pre>
-<p>As you see, <tt class="literal"><span class="pre">M.__init__</span></tt> is not called since</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(C)
-&lt;type 'type'&gt;
-</pre>
-<p>Typically, missing <tt class="literal"><span class="pre">M.__init__</span></tt> is not what you want. There are two
-solutions:</p>
-<ol class="arabic simple">
-<li>returns <tt class="literal"><span class="pre">type.__call__(mcl,n,b,d)</span></tt> (the poor man solution)</li>
-<li>returns <tt class="literal"><span class="pre">super(M,mcl).__new__(mcl,n,b,d)</span></tt> (the right solution)</li>
-</ol>
-<p>The cooperative solution is the right one because it will work always,
-whereas the solution number 1 may fail when <tt class="literal"><span class="pre">M</span></tt> is composed trough
-multiple inheritance with another metaclass.</p>
-</div>
-<div class="section" id="a-simple-example">
-<h1><a name="a-simple-example">A simple example.</a></h1>
-<p>Suppose we have two classes <tt class="literal"><span class="pre">A</span></tt> (old style) and <tt class="literal"><span class="pre">B</span></tt> (new style):</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A:
-... pass
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B(object):
-... pass
-</pre>
-<p>We want to create a class <tt class="literal"><span class="pre">C</span></tt> with bases <tt class="literal"><span class="pre">A</span></tt> and <tt class="literal"><span class="pre">B</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(A,B):
-... pass
-</pre>
-<p>In order to proceed with the creation, Python argues that the metaclass
-to use is the metaclass of <tt class="literal"><span class="pre">B</span></tt>, i.e. <tt class="literal"><span class="pre">type</span></tt> and not the metaclass of
-<tt class="literal"><span class="pre">A</span></tt>, i.e. <tt class="literal"><span class="pre">ClassType</span></tt>. Then the class statement is equivalent to</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C=type('C',(A,B),{})
-</pre>
-<p>i.e. to</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(type).__call__(type,'C',(A,B),{})
-&lt;class 'C'&gt;
-</pre>
-<p>i.e. to (since <tt class="literal"><span class="pre">type</span></tt> is its own metaclass)</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type.__call__(type,'C',(A,B),{})
-&lt;class 'C'&gt;
-</pre>
-<p>Notice that</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type.__call__('C',(A,B),{})
-Traceback (most recent call last):
- ...
-TypeError: descriptor '__call__' requires a 'type' object but received a 'str'
-</pre>
-<p>will not work, i.e. it is not equivalent to
-<tt class="literal"><span class="pre">type(type).__call__(type,'C',(A,B),{})</span></tt> as it happens for regular callable
-objects. <tt class="literal"><span class="pre">type</span></tt> is special, since it is its own metaclass, so <tt class="literal"><span class="pre">__call__</span></tt>
-has to be defined on it with four and not three arguments.</p>
-</div>
-<div class="section" id="a-less-simple-example">
-<h1><a name="a-less-simple-example">A less simple example</a></h1>
-<p>In the previous examples, the class statement and the <tt class="literal"><span class="pre">type</span></tt>
-call were perfectly equivalent.
-If there is a non-trivial metaclass, the situation changes:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M1(type):
-... &quot;A chatty metaclass&quot;
-... def __new__(mcl,n,b,d):
-... print 'calling M1.__new__, name = %s ...' % n
-... return super(M1,mcl).__new__(mcl,n,b,d)
-... def __init__(cls,n,b,d):
-... print 'calling M1.__init__, name = %s ...' % n
-... super(M1,cls).__init__(n,b,d)
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A:
-... __metaclass__=M1
-calling M1.__new__, name = A ...
-calling M1.__init__, name = A ...
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(A,B):
-... pass
-calling M1.__new__, name = C ...
-calling M1.__init__, name = C ...
-</pre>
-<p>In this case the class statement is equivalent to <tt class="literal"><span class="pre">M1('C',(A,B),{})</span></tt>
-i.e. to <tt class="literal"><span class="pre">type(M1).___call__(M1,'C',(A,B),{})</span></tt> i.e.
-<tt class="literal"><span class="pre">type.___call__(M1,'C',(A,B),{})</span></tt>.
-However, it is interesting to notice that <tt class="literal"><span class="pre">type</span></tt> would work too:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type('C',(A,B),{})
-calling M1.__new__, name = C ...
-calling M1.__init__, name = C ...
-&lt;class 'C'&gt;
-</pre>
-<p>The reason is that <tt class="literal"><span class="pre">type.__call__</span></tt> is able to dispatch to the correct
-metaclass. However, the class statement is not always equivalent to a
-<tt class="literal"><span class="pre">type.__call__</span></tt> and there is a very subtle difference between the
-two. The difference only manifests itself in the
-the case in which <tt class="literal"><span class="pre">A</span></tt> and <tt class="literal"><span class="pre">B</span></tt> have incompatible metaclasses.</p>
-</div>
-<div class="section" id="a-more-sophisticated-example">
-<h1><a name="a-more-sophisticated-example">A more sophisticated example</a></h1>
-<p>Here is an example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M2(type):
-... &quot;Another chatty metaclass&quot;
-... def __new__(mcl,n,b,d):
-... print 'calling M2.__new__, name = %s ...' % n
-... return super(M2,mcl).__new__(mcl,n,b,d)
-... def __init__(cls,n,b,d):
-... print 'calling M2.__init__, name = %s ...' % n
-... super(M2,cls).__init__(n,b,d)
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B:
-... __metaclass__=M2
-calling M2.__new__, name = B ...
-calling M2.__init__, name = B ...
-</pre>
-<p>If we try to create <tt class="literal"><span class="pre">C</span></tt> with <tt class="literal"><span class="pre">type</span></tt>, we simply get a conflict:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type.__call__(type,'C',(A,B),{})
-Traceback (most recent call last):
- ...
-TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-<p>On the other hand, with a class statement we get</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(A,B):
-... pass
-calling M1.__new__, name = C ... # doctest bug here
-Traceback (most recent call last):
- File &quot;pro.py&quot;, line 4, in __new__
- return super(M1,mcl).__new__(mcl,n,b,d)
-TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-<p>The difference is that <tt class="literal"><span class="pre">M1.__new__</span></tt> is called <em>first</em>, and only after
-the conflict is discovered, when <tt class="literal"><span class="pre">M1.__new__</span></tt> invokes <tt class="literal"><span class="pre">type.__new__</span></tt>.
-The error message is pretty clear indeed.
-In other words, the class statement in this case is equivalent to
-<tt class="literal"><span class="pre">M1('C',(A,B),{})</span></tt> i.e. to <tt class="literal"><span class="pre">type.__call__(M1,'C',(A,B),{})</span></tt>.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from safetype import safetype as type
-</pre>
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="classcreation.txt">View document source</a>.
-Generated on: 2003-10-04 08:36 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/classinitializer/classinitializer.html b/pypers/classinitializer/classinitializer.html
deleted file mode 100644
index 111d480..0000000
--- a/pypers/classinitializer/classinitializer.html
+++ /dev/null
@@ -1,530 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
-<title>Let's keep it simple (or, how to do metaprogramming without metaclasses)</title>
-<meta name="author" content="Michele Simionato" />
-<meta name="date" content="10 July 2006" />
-
-</head>
-<body>
-<div class="document" id="let-s-keep-it-simple-or-how-to-do-metaprogramming-without-metaclasses">
-<h1 class="title">Let's keep it simple (or, how to do metaprogramming without metaclasses)</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr><th class="docinfo-name">Author:</th>
-<td>Michele Simionato</td></tr>
-<tr><th class="docinfo-name">Date:</th>
-<td>10 July 2006</td></tr>
-<tr><th class="docinfo-name">Version:</th>
-<td>0.5</td></tr>
-</tbody>
-</table>
-<div class="contents topic">
-<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
-<ul class="simple">
-<li><a class="reference" href="#introduction" id="id7" name="id7">Introduction</a></li>
-<li><a class="reference" href="#about-class-initialization" id="id8" name="id8">About class initialization</a></li>
-<li><a class="reference" href="#please-stop-abusing-metaclasses" id="id9" name="id9">Please stop abusing metaclasses</a></li>
-<li><a class="reference" href="#the-classinitializer-decorator" id="id10" name="id10">The <tt class="docutils literal"><span class="pre">classinitializer</span></tt> decorator</a></li>
-<li><a class="reference" href="#tricky-points-and-caveats" id="id11" name="id11">Tricky points and caveats</a></li>
-<li><a class="reference" href="#example-initializing-records" id="id12" name="id12">Example: initializing records</a></li>
-<li><a class="reference" href="#references" id="id13" name="id13">References</a></li>
-<li><a class="reference" href="#questions-and-answers" id="id14" name="id14">Questions and answers</a></li>
-</ul>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id7" id="introduction" name="introduction">Introduction</a></h1>
-<p>A few days ago I was at CERN, at the EuroPython 2006 conference. The
-conference was good, the organization perfect, the talks of
-very high level, the people extremely nice.</p>
-<p>Nevertheless, I saw a trend growing in the Python community
-that disturbed me a little and motivated
-me to write this paper. The trend I am alluding to, is the trend
-towards <em>cleverness</em>. Unfortunately, whereas once cleverness was
-mostly confined to Zope and Twisted, now is appearing everywhere.</p>
-<p>I personally don't have anything against cleverness for
-experimental projects and learning exercises. But I have a gripe
-against cleverness when I see it deployed in production frameworks
-that I am forced to cope with as an user.</p>
-<p>Cleverness means making things more complicated than
-needed, making things more fragile, making the learning curve
-steeper and, worse of all, making debugging harder.</p>
-<p>In this short paper I will try to give my small contribution against
-cleverness, at least in a case where I have some expertise, i.e.
-against metaclass abuses.</p>
-<p>Let me say that I consider <em>metaclass abuse</em> any usage of a metaclass
-in a situation where you could have solved the problem without a
-metaclass.</p>
-<p>I feel in part responsible for some of the abuses I see floating
-around in newsgroups, in conferences and in frameworks source code,
-because of my (together with David Mertz) contribution in popularizing
-metaclasses, so I have decided to make amend with this paper.</p>
-<p>This paper consider only one kind of metaprogramming technique, i.e.
-the creation at runtime of classes with attributes and methods which
-are dynamically generated. Contrarily to popular belief, this is a job
-where most of the time you <em>don't need</em> and you <em>don't want</em> a custom
-metaclass, as I will argue in the next section.</p>
-<p>The paper is intended for a double target of readers:</p>
-<ul class="simple">
-<li>average programmers, that would benefit from knowing a few
-meta-programming tricks, but are scared off by brain melting concepts;</li>
-<li>clever programmers, which are actually too clever and should know
-better <a class="footnote-reference" href="#id2" id="id1" name="id1">[1]</a>.</li>
-</ul>
-<p>If you are a lazy reader, your may just read the next paragraph and
-the last one, and forget about the details.</p>
-<table class="docutils footnote" frame="void" id="id2" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1" name="id2">[1]</a></td><td>The problem is that it is easy to be clever whereas it takes a
-lot of time to become unclever. For instance, it took me a few
-months to understand how to use metaclasses, but a few years
-to understand how <em>not</em> to use them.</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id8" id="about-class-initialization" name="about-class-initialization">About class initialization</a></h1>
-<p>By class initialization I mean setting attributes and methods of
-classes immediately after their creation, once and for all <a class="footnote-reference" href="#id4" id="id3" name="id3">[2]</a>.</p>
-<p>There are various common situations where a programmer may want to
-initialize her classes: for instance, she may want to set some default class
-attributes according to parameters read from a configuration
-file, or she may want to set class properties according to the fields
-in a database table.</p>
-<p>The easiest way to perform class initialization
-is by using an imperative style: one first creates the class,
-and then adds the dynamically generated methods and attributes.</p>
-<p>For instance, if the problem is to generate properties for an <tt class="docutils literal"><span class="pre">Article</span></tt>
-record class, an imperative solution is something like the following:</p>
-<pre class="literal-block">
-class Article(object):
- def somemethod(self):
- pass
- ...
-
-set_properties(Article, [('title', str), ('author', str), ('date', date)])
-</pre>
-<p>However, since (proper) class initialization should occur only once,
-it does not need to be distinguished by class
-creation, and it may be argued that it
-should be treated with a declarative style, with a syntax like the following:</p>
-<pre class="literal-block">
-class Article(object):
-
- def_properties([('title', str), ('author', str), ('date', date)])
-
- def somemethod(self):
- pass
-
- ...
-</pre>
-<p>This paper is about providing a generic facility to define <em>class initializers</em>
-to be used in the class scope, such as <tt class="docutils literal"><span class="pre">def_properties</span></tt>.</p>
-<p><strong>Disclaimer:</strong> the advantage of the solution I propose here,
-is that it works in current Python and it is less clever than
-metaclasses, Still I would consider it a little too clever. A clean solution
-to the problem would be to add class decorator to the language. That
-would allow a syntax like the following:</p>
-<pre class="literal-block">
-&#64;with_properties([('title', str), ('author', str), ('date', date)])
-class Article(object):
- def somemethod(self):
- pass
- ...
-</pre>
-<p>However, it is not sure at the moment if and when Guido will add class
-decorators, so my proposed solution is the lesser of two evils.</p>
-<table class="docutils footnote" frame="void" id="id4" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id3" name="id4">[2]</a></td><td>Well, in Python methods and attributes can always be changed at
-a later time, but let us assume that nobody is cheating here.</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id9" id="please-stop-abusing-metaclasses" name="please-stop-abusing-metaclasses">Please stop abusing metaclasses</a></h1>
-<p>Everybody knows how to initialize instances. One just overrides
-the class <tt class="docutils literal"><span class="pre">__init__</span></tt> method. Since classes are instances of metaclasses,
-the natural solution to the class initialization problem seems to be
-to use a custom metaclass and to override its <tt class="docutils literal"><span class="pre">__init__</span></tt> method.</p>
-<p>Un fortunately, things are not so easy, because of inheritance. The
-issue is that once you have defined a custom metaclass for your base
-class, all the derived classes will inherit the metaclass, so the
-initialization code will be run on all derived classes, magically and
-implicitly.</p>
-<p>That may be fine in specific circumstances (for instance,
-suppose you have to register in your framework all the classes you
-define: using a metaclass ensures that you cannot forget to register a
-derived class), however, in many cases you may not like this behavior because:</p>
-<ol class="arabic simple">
-<li>you may believe that <em>explicit is better than implicit</em>;</li>
-<li>if the derived classes have the same dynamic class attributes of
-the base class, implicitly setting them again for each derived
-class is a waste, since they would be available anyway by
-inheritance. This may be a real issue if the initialization code is
-slow, possibly because it must access a database, or perform some
-heavy computation: in this case one must add a check in the
-metaclass code to see if the attributes were already set in
-a parent class, but this adds plumbing and it does not give real
-control on a per-class basis;</li>
-<li>a custom metaclass will make your classes somewhat magic and
-nonstandard: you may not want to increase your chances to incur in
-metaclass conflicts, issues with <tt class="docutils literal"><span class="pre">__slots__</span></tt>, fights with (Zope)
-extension classes and other guru-level intricacies <a class="footnote-reference" href="#id6" id="id5" name="id5">[3]</a>;</li>
-<li>you feel that a custom metaclasses is overkill for the simple job
-of class initialization and you would rather use a simpler solution.</li>
-</ol>
-<p>In other words,you should use a custom metaclass only when your real
-intention is to have code running on derived classes without users of
-those classes noticing it. If this is not your case, please don't a
-metaclass and make your life (as well your users) happier.</p>
-<table class="docutils footnote" frame="void" id="id6" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id5" name="id6">[3]</a></td><td>Metaclasses are more fragile than many people realize. I
-personally have never used them for production code, even
-after four years of usage in experimental code.</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id10" id="the-classinitializer-decorator" name="the-classinitializer-decorator">The <tt class="docutils literal"><span class="pre">classinitializer</span></tt> decorator</a></h1>
-<p>The aim of this paper is to provide a decorator called
-<tt class="docutils literal"><span class="pre">classinitializer</span></tt> that can be used to define
-class initializers, i.e. procedures taking classes and setting their
-attributes and methods. In order to be concrete, consider the following
-class initializer example:</p>
-<pre class="literal-block">
-def set_defaults(cls, **kw):
- for k, v in kw.iteritems():
- setattr(cls, k, v)
-</pre>
-<p>You may use it imperatively, right after a class definition:</p>
-<pre class="literal-block">
-class ClassToBeInitialized(object):
- pass
-
-set_defaults(ClassToBeInitialized, a=1, b=2)
-</pre>
-<p>However the imperative solution has a few drawbacks:</p>
-<ol class="arabic simple">
-<li>it does not comply with DRY, i.e. the class name is repeated
-and if I change it during refactoring, I have to change it (at
-least) twice;</li>
-<li>readability is suboptimal: since class definition and class
-initialization are separated, for long class definitions I may end
-up not seeing the last line;</li>
-<li>it feels wrong to first define something and immediately right
-after to mutate it.</li>
-</ol>
-<p>Luckily, the <tt class="docutils literal"><span class="pre">classinitializer</span></tt> decorator provides a much nicer
-declarative solution. The decorator performs some deep magic and converts
-<tt class="docutils literal"><span class="pre">set_defaults(cls,</span> <span class="pre">**kw)</span></tt> into a function that can be
-used at the top scope into a class definition, with the current class
-automagically passed as first parameter:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; &#64;classinitializer # add magic to set_defaults
-... def set_defaults(cls, **kw):
-... for k, v in kw.iteritems():
-... setattr(cls, k, v)
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class ClassToBeInitialized(object):
-... set_defaults(a=1, b=2)
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; ClassToBeInitialized.a
-1
-&gt;&gt;&gt; ClassToBeInitialized.b
-2
-</pre>
-<p>If you have used Zope interfaces, you may have seen examples of class
-initializers (I mean <tt class="docutils literal"><span class="pre">zope.interface.implements</span></tt>). In fact under the hood
-<tt class="docutils literal"><span class="pre">classinitializer</span></tt> is implemented by using a trick copied from
-<tt class="docutils literal"><span class="pre">zope.interface.advice</span></tt>, which credits Phillip J. Eby. The trick
-uses the <tt class="docutils literal"><span class="pre">__metaclass__</span></tt> hook, but it <em>does not use</em> a custom
-metaclass, so that in this example <tt class="docutils literal"><span class="pre">ClassToBeInitialized</span></tt> will
-continue to keep its original metaclass, i.e. the plain old regular
-built-in metaclass <tt class="docutils literal"><span class="pre">type</span></tt> of new style classes:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(ClassToBeInitialized)
-&lt;type 'type'&gt;
-</pre>
-<p>In principle, the trick also works for old style classes,
-and it would be easy to write an implementation keeping old style
-classes old style. However, since according to Guido himself
-<em>old style classes are morally deprecated</em>, the current implementation
-automagically converts old style classes into new style classes:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class WasOldStyle:
-... set_defaults(a=1, b=2)
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; WasOldStyle.a, WasOldStyle.b
-(1, 2)
-&gt;&gt;&gt; type(WasOldStyle)
-&lt;type 'type'&gt;
-</pre>
-<p>One of the motivations for the <tt class="docutils literal"><span class="pre">classinitializer</span></tt> decorator, is to hide the
-plumbing, and to make mere mortals able to implements their own
-class initializers in an easy way, without knowing the details of
-how class creation works and the secrets of the <tt class="docutils literal"><span class="pre">__metaclass__</span></tt>
-hook. The other motivation, is that even for Python wizards it is very
-unconvenient to rewrite the code managing the <tt class="docutils literal"><span class="pre">__metaclass__</span></tt> hook
-every time one writes a new class initializer. So I have decided to
-use a decorator to allow separation of concerns and reuse of code.</p>
-<p>As a final note, let me point out that the decorated version of
-<tt class="docutils literal"><span class="pre">set_defaults</span></tt> is so smart that it will continue to
-work as the non-decorated version outside a class scope, provided that
-you pass to it an explicit class argument.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; set_defaults(WasOldStyle, a=2)
-&gt;&gt;&gt; WasOldStyle.a
-2
-</pre>
-<p>In other words, you <em>might</em> continue to use the imperative style.</p>
-<p>Here is the code for <tt class="docutils literal"><span class="pre">classinitializer</span></tt> (the point being that you
-don't need to be able to understand it to use the decorator):</p>
-<pre class="literal-block">
-#&lt;_main.py&gt;
-
-import sys
-
-def classinitializer(proc):
- # basic idea stolen from zope.interface.advice, which credits P.J. Eby
- def newproc(*args, **kw):
- frame = sys._getframe(1)
- if '__module__' in frame.f_locals and not \
- '__module__' in frame.f_code.co_varnames: # we are in a class
- if '__metaclass__' in frame.f_locals:
- raise SyntaxError(&quot;Don't use two class initializers or\n&quot;
- &quot;a class initializer together with a__metaclass__ hook&quot;)
- def makecls(name, bases, dic):
- try:
- cls = type(name, bases, dic)
- except TypeError, e:
- if &quot;can't have only classic bases&quot; in str(e):
- cls = type(name, bases + (object,), dic)
- else: # other strange errors, such as __slots__ conflicts, etc
- raise
- proc(cls, *args, **kw)
- return cls
- frame.f_locals[&quot;__metaclass__&quot;] = makecls
- else:
- proc(*args, **kw)
- newproc.__name__ = proc.__name__
- newproc.__module__ = proc.__module__
- newproc.__doc__ = proc.__doc__
- newproc.__dict__ = proc.__dict__
- return newproc
-
-#&lt;/_main.py&gt;
-</pre>
-<p>From the implementation it is clear how class initializers work:
-when you call a class initializer inside a class, your are actually defining a
-<tt class="docutils literal"><span class="pre">__metaclass__</span></tt> hook that will be called by
-the class' metaclass (typically <tt class="docutils literal"><span class="pre">type</span></tt>). The
-metaclass will create the class (as a new style one) and
-will pass it to the class initializer procedure.</p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id11" id="tricky-points-and-caveats" name="tricky-points-and-caveats">Tricky points and caveats</a></h1>
-<p>Since class initializers (re)define the <tt class="docutils literal"><span class="pre">__metaclass__</span></tt> hook,
-they don't play well with classes that define a <tt class="docutils literal"><span class="pre">__metaclass__</span></tt> hook
-explicitly (as opposed to implicitly inheriting one). The issue is
-that if a <tt class="docutils literal"><span class="pre">__metaclass__</span></tt> hook is defined <em>after</em> the
-class initializer, it <em>silently</em> overrides it.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C:
-... set_defaults(a=1)
-... def __metaclass__(name, bases, dic):
-... cls = type(name, bases, dic)
-... print 'set_defaults is silently ignored'
-... return cls
-...
-set_defaults is silently ignored
-&gt;&gt;&gt; C.a
-Traceback (most recent call last):
- ...
-AttributeError: type object 'C' has no attribute 'a'
-</pre>
-<p>This is unfortunate, but there is no general solution to this issue, and I will
-simply document it (this is one of the reasons why I feel
-class initializers to be a clever hack that should be dismissed if we
-had class decorators).</p>
-<p>On the other hand, if you call a class initializer
-<em>after</em> the <tt class="docutils literal"><span class="pre">__metaclass__</span></tt> hook, you will get an exception:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C:
-... def __metaclass__(name, bases, dic):
-... cls = type(name, bases, dic)
-... print 'calling explicit __metaclass__'
-... return cls
-... set_defaults(a=1)
-...
-Traceback (most recent call last):
- ...
-SyntaxError: Don't use two class initializers or
-a class initializer together with a__metaclass__ hook
-</pre>
-<p>I feel raising an error is preferable to silently overriding your
-explicit <tt class="docutils literal"><span class="pre">__metaclass__</span></tt> hook. As a consequence, you will get an
-error if you try to use two class initializers at the same time, or
-if you call twice the same one:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C:
-... set_defaults(a=1)
-... set_defaults(b=2)
-Traceback (most recent call last):
- ...
-SyntaxError: Don't use two class initializers or
-a class initializer together with a__metaclass__ hook
-</pre>
-<p>I feel raising an error to be better than having the second
-initializer overriding the first one, i.e. in this example
-to set the <tt class="docutils literal"><span class="pre">b</span></tt> attribute <em>without</em> setting the <tt class="docutils literal"><span class="pre">a</span></tt> attribute,
-which would be very confusing.</p>
-<p>Finally, let me show that there are no issues for inherited
-<tt class="docutils literal"><span class="pre">__metaclass__</span></tt> hooks and for custom metaclasses:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B: # a base class with a custom metaclass
-... class __metaclass__(type):
-... pass
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(B): # a class with both a custom metaclass AND a class initializer
-... set_defaults(a=1)
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.a
-1
-&gt;&gt;&gt; type(C)
-&lt;class '_main.__metaclass__'&gt;
-</pre>
-<p>The class initializer does not disturb the metaclass of <tt class="docutils literal"><span class="pre">C</span></tt>, which is
-the one inherited by its base <tt class="docutils literal"><span class="pre">B</span></tt>, and the inherited metaclass does
-not disturb the class initializer, which does its job just fine.
-You would have run into trouble, instead, if you tried to call <tt class="docutils literal"><span class="pre">set_defaults</span></tt>
-directly in the base class.</p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id12" id="example-initializing-records" name="example-initializing-records">Example: initializing records</a></h1>
-<p>In this section I will finally discuss the example I gave at the
-beginning, about how to define record classes with a class initializer.
-Here is the code for the class initializer, plus an helper function
-for managing dates:</p>
-<pre class="literal-block">
-#&lt;_main.py&gt;
-
-import datetime
-
-&#64;classinitializer
-def def_properties(cls, schema):
- &quot;&quot;&quot;
- Add properties to cls, according to the schema, which is a list
- of pairs (fieldname, typecast). A typecast is a
- callable converting the field value into a Python type.
- The initializer saves the attribute names in a list cls.fields
- and the typecasts in a list cls.types. Instances of cls are expected
- to have private attributes with names determined by the field names.
- &quot;&quot;&quot;
- cls.fields = []
- cls.types = []
- for name, typecast in schema:
- if hasattr(cls, name): # avoid accidental overriding
- raise AttributeError('You are overriding %s!' % name)
- def getter(self, name=name):
- return getattr(self, '_' + name)
- def setter(self, value, name=name, typecast=typecast):
- setattr(self, '_' + name, typecast(value))
- setattr(cls, name, property(getter, setter))
- cls.fields.append(name)
- cls.types.append(typecast)
-
-def date(isodate): # add error checking if you like
- &quot;Convert an ISO date into a datetime.date object&quot;
- return datetime.date(*map(int, isodate.split('-')))
-
-#&lt;/_main.py&gt;
-</pre>
-<p>As an example of application of the above class initializer,
-I will define an <em>Article</em> record class with fields <em>title</em>, <em>author</em>
-and <em>date</em>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Article(object):
-... # fields and types are dynamically set by the initializer
-... def_properties([('title', str), ('author', str), ('date', date)])
-... def __init__(self, values): # add error checking if you like
-... for field, cast, value in zip(self.fields, self.types, values):
-... setattr(self, '_' + field, cast(value))
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; a=Article(['How to use class initializers', 'M. Simionato', '2006-07-10'])
-&gt;&gt;&gt; a.title
-'How to use class initializers'
-&gt;&gt;&gt; a.author
-'M. Simionato'
-&gt;&gt;&gt; a.date
-datetime.date(2006, 7, 10)
-&gt;&gt;&gt; a.date = '2006-07-11'
-&gt;&gt;&gt; a.date
-datetime.date(2006, 7, 11)
-</pre>
-<p>The point of using the class initializer is that the class is completely
-dynamic and it can be built at runtime with a schema that can be read
-from a configuration file or by introspecting a database table. You
-have the advantages of a custom metaclass without any of the disadvantages.</p>
-<p>It is also interesting to notice that this approach avoids inheritance
-completely, so if you have a pre-existing record class and you want
-to change its implementation to use this trick, it is enough to add
-<tt class="docutils literal"><span class="pre">def_properties</span></tt>, you don't need any kind of (multiple)
-inheritance.</p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id13" id="references" name="references">References</a></h1>
-<p>About metaclasses:
-<a class="reference" href="http://www-128.ibm.com/developerworks/linux/library/l-pymeta.html">http://www-128.ibm.com/developerworks/linux/library/l-pymeta.html</a> and
-<a class="reference" href="http://www-128.ibm.com/developerworks/linux/library/l-pymeta2">http://www-128.ibm.com/developerworks/linux/library/l-pymeta2</a></p>
-<p>About using decorators instead of metaclasses:</p>
-<p>&lt;David's last paper&gt;</p>
-<p>The code from which everything was born:</p>
-<p><a class="reference" href="http://svn.zope.org/Zope3/trunk/src/zope/interface/advice.py">http://svn.zope.org/Zope3/trunk/src/zope/interface/advice.py</a></p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id14" id="questions-and-answers" name="questions-and-answers">Questions and answers</a></h1>
-<dl class="docutils">
-<dt>Q</dt>
-<dd>Is there any specific licence for the code discussed in the paper?</dd>
-<dt>A</dt>
-<dd>No, you may assume the Public Domain or the Python licence, whatever
-you are happier with. If you are using my code, or
-code heavily derived from my own in your frameworks/applications I
-would appreciated to be notified, just to gratify my ego.</dd>
-<dt>Q</dt>
-<dd>How do I extract snippets of code from the paper?</dd>
-<dt>A</dt>
-<dd><p class="first">Download <a class="reference" href="http://www.phyast.pitt.edu/~micheles/classinitializer.zip">http://www.phyast.pitt.edu/~micheles/classinitializer.zip</a>
-which contains the source
-version of the paper (as well as the HTML and PDF versions)
-and a doctester utility. Run</p>
-<p><tt class="docutils literal"><span class="pre">$</span> <span class="pre">python</span> <span class="pre">doctester.py</span> <span class="pre">classinitializer.txt</span></tt></p>
-<p class="last">This will run many doctests and generate a script called <tt class="docutils literal"><span class="pre">_main.py</span></tt>
-with the source code for <tt class="docutils literal"><span class="pre">classinitializer</span></tt> and <tt class="docutils literal"><span class="pre">def_properties</span></tt>.</p>
-</dd>
-<dt>Q</dt>
-<dd>The doctester is a really cool idea! Can I use it for my own projects?</dd>
-<dt>A</dt>
-<dd>Yes. See also
-<a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410052">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410052</a></dd>
-</dl>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/descr.html b/pypers/descr.html
deleted file mode 100755
index 00dab31..0000000
--- a/pypers/descr.html
+++ /dev/null
@@ -1,1085 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>THE SOPHISTICATION OF DESCRIPTORS</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="the-sophistication-of-descriptors">
-<h1 class="title">THE SOPHISTICATION OF DESCRIPTORS</h1>
-<p>Attribute descriptors are important metaprogramming tools that allows
-the user to customize the behavior of attributes in custom classes.
-For instance, attribute descriptors (or descriptors for short)
-can be used as method wrappers,
-to modify or enhance methods (this is the case for the well
-known staticmethods and classmethods attribute descriptors); they
-can also be used as attribute wrappers, to change or restrict the access to
-attributes (this is the case for properties). Finally, descriptors
-allows the user to play with the resolution order of attributes:
-for instance, the <tt class="literal"><span class="pre">super</span></tt> built-in object used in (multiple) inheritance
-hierarchies, is implemented as an attribute descriptor.</p>
-<p>In this chapter, I will show how the user can define its own attribute
-descriptors and I will give some example of useful things you can do with
-them (in particular to add tracing and timing capabilities).</p>
-<div class="section" id="motivation">
-<h1><a name="motivation">Motivation</a></h1>
-<p>Attribute descriptors are a recent idea (they where first introduced in
-Python 2.2) nevertheless, under the hood, are everywhere in Python. It is
-a tribute to Guido's ability of hiding Python complications that
-the average user can easily miss they existence.
-If you need to do simple things, you can very well live without
-the knowledge of descriptors. On the other hand, if you need difficult
-things (such as tracing all the attribute access of your modules)
-attribute descriptors, allow you to perform
-impressive things.
-Let me start by showing why the knowledge of attribute descriptors is
-essential for any user seriously interested in metaprogramming applications.
-Suppose I want to trace the methods of a clock:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import oopp
-&gt;&gt;&gt; clock=oopp.Clock()
-</pre>
-</blockquote>
-<p>This is easily done with the <tt class="literal"><span class="pre">with_tracer</span></tt> closure of chapter 2:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; oopp.wrapfunctions(clock,oopp.with_tracer)
-&lt;oopp.Clock object at 0x4044c54c&gt;
-&gt;&gt;&gt; clock.get_time()
-[] Calling 'get_time' with arguments
-(){} ...
--&gt; '.get_time' called with result: 19:55:07
-'19:55:07'
-</pre>
-</blockquote>
-<p>However, this approach fails if I try to trace the entire class:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; oopp.wrapfunctions(oopp.Clock,oopp.with_tracer)
-&lt;class 'oopp.Clock'&gt;
-&gt;&gt;&gt; oopp.Clock.get_time() # error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 6, in ?
-TypeError: unbound method _() must be called with Clock instance
-as first argument (got nothing instead)
-</pre>
-</blockquote>
-<p>The reason is that <tt class="literal"><span class="pre">wrapfunctions</span></tt> sets the attributes of 'Clock'
-by invoking <tt class="literal"><span class="pre">customize</span></tt>, which uses <tt class="literal"><span class="pre">setattr</span></tt>. This converts
-'_' (i.e. the traced version of <tt class="literal"><span class="pre">get_time</span></tt>) in a regular method, not in
-a staticmethod!
-In order to trace staticmethods, one has to understand the nature
-of attribute descriptors.</p>
-</div>
-<div class="section" id="functions-versus-methods">
-<h1><a name="functions-versus-methods">Functions versus methods</a></h1>
-<p>Attribute descriptors are essential for the implementation
-of one of the most basic Python features: the automatic conversion
-of functions in methods. As I already anticipated in chapter 1, there is
-a sort of magic when one writes <tt class="literal"><span class="pre">Clock.get_time=lambda</span> <span class="pre">self:</span> <span class="pre">get_time()</span></tt>
-and Python automagically converts the right hand side, that is a
-function, to a left hand side that is a (unbound) method. In order to
-understand this magic, one needs a better comprehension of the
-relation between functions and methods.
-Actually, this relationship is quite subtle
-and has no analogous in mainstream programming languages.
-For instance, C is not OOP and has only functions, lacking the concept
-of method, whereas Java (as other OOP languages)
-has no functions, only methods.
-C++ has functions and methods, but functions are completely
-different from methods On the other hand, in Python,
-functions and methods can be transformed both ways.</p>
-<p>To show how it works, let me start by defining a simple printing
-function:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import __main__ # gives access to the __main__ namespace from the module
-
-def prn(s):
- &quot;&quot;&quot;Given an evaluable string, print its value and its object reference.
- Notice that the evaluation is done in the __main__ dictionary.&quot;&quot;&quot;
- try: obj=eval(s,__main__.__dict__)
- except: print 'problems in evaluating',s
- else: print s,'=',obj,'at',hex(id(obj))
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Now, let me define a class with a method <tt class="literal"><span class="pre">m</span></tt> equals to the identity
-function <tt class="literal"><span class="pre">f</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(x): &quot;Identity function&quot;; return x
-...
-&gt;&gt;&gt; class C(object):
-... m=f
-... print m #here m is the function f
-&lt;function f at 0x401c2b1c&gt;
-</pre>
-</blockquote>
-<p>We see that <em>inside</em> its defining class, <tt class="literal"><span class="pre">m</span></tt> coincides with the function
-<tt class="literal"><span class="pre">f</span></tt> (the object reference is the same):</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; f
-&lt;function f at 0x401c2b1c&gt;
-</pre>
-</blockquote>
-<p>We may retrieve <tt class="literal"><span class="pre">m</span></tt> from <em>outside</em> the class via the class dictionary <a class="footnote-reference" href="#id2" id="id1" name="id1">[1]</a>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__dict__['m']
-&lt;function prn at 0x401c2b1c&gt;
-</pre>
-</blockquote>
-<p>However, if we invoke <tt class="literal"><span class="pre">m</span></tt> with
-the syntax <tt class="literal"><span class="pre">C.m</span></tt>, then it (magically) becomes a (unbound) method:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.m #here m has become a method!
-&lt;unbound method C.f&gt;
-</pre>
-</blockquote>
-<p>But why it is so? How comes that in the second syntax the function
-<tt class="literal"><span class="pre">f</span></tt> is transformed in a (unbound) method? To answer that question, we have
-to understand how attributes are really invoked in Python, i.e. via
-attribute descriptors.</p>
-</div>
-<div class="section" id="methods-versus-functions">
-<h1><a name="methods-versus-functions">Methods versus functions</a></h1>
-<p>First of all, let me point out the differences between methods and
-functions. Here, <tt class="literal"><span class="pre">C.m</span></tt> does <em>not</em> coincides with <tt class="literal"><span class="pre">C.__dict__['m']</span></tt>
-i.e. <tt class="literal"><span class="pre">f</span></tt>, since its object reference is different:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import prn,attributes
-&gt;&gt;&gt; prn('C.m')
-C.m = &lt;unbound method C.prn&gt; at 0x81109b4
-</pre>
-</blockquote>
-<p>The difference is clear since methods and functions have different attributes:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; attributes(f).keys()
-['func_closure', 'func_dict', 'func_defaults', 'func_name',
-'func_code', 'func_doc', 'func_globals']
-</pre>
-</blockquote>
-<p>whereas</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; attributes(C.m).keys()
-['im_func', 'im_class', 'im_self']
-</pre>
-</blockquote>
-<p>We discussed few of the functions attributes in the chapter
-on functions. The instance method attributes are simpler: <tt class="literal"><span class="pre">im_self</span></tt>
-returns the object to which the method is attached,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print C.m.im_self #unbound method, attached to the class
-None
-&gt;&gt;&gt; C().m.im_self #bound method, attached to C()
-&lt;__main__.C object at 0x81bf4ec&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">im_class</span></tt> returns the class to which the
-method is attached</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.m.im_class #class of the unbound method
-&lt;class '__main__.C'&gt;
-&gt;&gt;&gt; C().m.im_class #class of the bound method,
-&lt;class '__main__.C'&gt;
-</pre>
-</blockquote>
-<p>and <tt class="literal"><span class="pre">im_func</span></tt> returns the function equivalent to
-the method.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.m.im_func
-&lt;function m at 0x8157f44&gt;
-&gt;&gt;&gt; C().m.im_func # the same
-&lt;function m at 0x8157f44&gt;
-</pre>
-</blockquote>
-<p>As the reference manual states, calling
-<tt class="literal"><span class="pre">m(*args,**kw)</span></tt> is completely equivalent to calling
-<tt class="literal"><span class="pre">m.im_func(m.im_self,</span> <span class="pre">*args,**kw)</span></tt>&quot;.</p>
-<p>As a general rule, an attribute descriptor is an object with a <tt class="literal"><span class="pre">__get__</span></tt>
-special method. The most used descriptors are the good old functions:
-they have a <tt class="literal"><span class="pre">__get__</span></tt> special method returning a <em>method-wrapper object</em></p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; f.__get__
-&lt;method-wrapper object at 0x815cdc4&gt;
-</pre>
-</blockquote>
-<p>method-wrapper objects can be transformed in (both bound and unbound) methods:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; f.__get__(None,C)
-&lt;unbound method C.f&gt;
-&gt;&gt;&gt; f.__get__(C(),C)
-&lt;bound method C.f of &lt;__main__.C object at 0x815cdc4&gt;&gt;
-</pre>
-</blockquote>
-<p>The general calling syntax for method-wrapper objects is
-<tt class="literal"><span class="pre">.__get__(obj,cls=None)</span></tt>, where the first argument is an
-instance object or None and the second (optional) argument is the class (or a
-generic superclass) of the first one.</p>
-<p>Now we see what happens when we use the syntax <tt class="literal"><span class="pre">C.m</span></tt>: Python interprets
-this as a shortcut for <tt class="literal"><span class="pre">C.__dict['m'].__get__(None,C)</span></tt> (if <tt class="literal"><span class="pre">m</span></tt> is
-in the 'C' dictionary, otherwise it looks for ancestor dictionaries).
-We may check that everything is correct by observing that
-<tt class="literal"><span class="pre">f.__get__(None,C)</span></tt> has exactly the same object reference than <tt class="literal"><span class="pre">C.m</span></tt>,
-therefore they are the same object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; hex(id(f.__get__(None,C))) # same as hex(id(C.m))
-'0x811095c'
-</pre>
-</blockquote>
-<p>The process works equally well for the syntax <tt class="literal"><span class="pre">getattr</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print getattr(C,'m'), hex(id(getattr(C,'m')))
-&lt;unbound method C.f&gt; 0x811095c
-</pre>
-</blockquote>
-<p>and for bound methods: if</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c=C()
-</pre>
-</blockquote>
-<p>is an instance of the class C, then the syntax</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; getattr(c,'m') #same as c.m
-&lt;bound method C.f of &lt;__main__.C object at 0x815cdc4&gt;&gt;
-</pre>
-</blockquote>
-<p>is a shortcut for</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(c).__dict__['m'].__get__(c,C) # or f.__get__(c,C)
-&lt;bound method C.f of &lt;__main__.C object at 0x815cdc4&gt;&gt;
-</pre>
-</blockquote>
-<p>(notice that the object reference for <tt class="literal"><span class="pre">c.m</span></tt> and <tt class="literal"><span class="pre">f.__get__(c,C)</span></tt> is
-the same, they are <em>exactly</em> the same object).</p>
-<p>Both the unbound method C.m and the bound method c.m refer to the same
-object at hexadecimal address 0x811095c. This object is common to all other
-instances of C:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c2=C()
-&gt;&gt;&gt; print c2.m,hex(id(c2.m)) #always the same method
-&lt;bound method C.m of &lt;__main__.C object at 0x815768c&gt;&gt; 0x811095c
-</pre>
-</blockquote>
-<p>One can also omit the second argument:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.m.__get__(c)
-&lt;bound method ?.m of &lt;__main__.C object at 0x81597dc&gt;&gt;
-</pre>
-</blockquote>
-<p>Finally, let me point out that methods are attribute descriptors too,
-since they have a <tt class="literal"><span class="pre">__get__</span></tt> attribute returning a method-wrapper
-object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.m.__get__
-&lt;method-wrapper object at 0x815d51c&gt;
-</pre>
-</blockquote>
-<p>Notice that this method wrapper is <em>not</em> the same than the <tt class="literal"><span class="pre">f.__get__</span></tt>
-method wrapper.</p>
-<blockquote>
-<table class="footnote" frame="void" id="id2" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1" name="id2">[1]</a></td><td>If <tt class="literal"><span class="pre">C.__dict['m']</span></tt> is not defined, Python looks if <tt class="literal"><span class="pre">m</span></tt> is defined
-in some ancestor of C. For instance if <cite>B</cite> is the base of <cite>C</cite>, it
-looks in <tt class="literal"><span class="pre">B.__dict['m']</span></tt>, etc., by following the MRO.</td></tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-<div class="section" id="static-methods-and-class-methods">
-<h1><a name="static-methods-and-class-methods">Static methods and class methods</a></h1>
-<p>Whereas functions and methods are implicit attribute descriptors,
-static methods and class methods are examples of explicit
-descriptors. They allow to convert regular functions to
-specific descriptor objects. Let me show a trivial example.
-Given the identity function</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(x): return x
-</pre>
-</blockquote>
-<p>we may convert it to a staticmethod object</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; sm=staticmethod(f)
-&gt;&gt;&gt; sm
-&lt;staticmethod object at 0x4018a0a0&gt;
-</pre>
-</blockquote>
-<p>or to a classmethod object</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm=classmethod(f)
-&gt;&gt;&gt; cm
-&lt;classmethod object at 0x4018a0b0&gt;
-</pre>
-</blockquote>
-<p>In both cases the <tt class="literal"><span class="pre">__get__</span></tt> special method returns a method-wrapper object</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; sm.__get__
-&lt;method-wrapper object at 0x401751ec&gt;
-&gt;&gt;&gt; cm.__get__
-&lt;method-wrapper object at 0x4017524c&gt;
-</pre>
-</blockquote>
-<p>However the static method wrapper is quite different from the class
-method wrapper. In the first case the wrapper returns a function:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; sm.__get__(C(),C)
-&lt;function f at 0x4027a8b4&gt;
-&gt;&gt;&gt; sm.__get__(C())
-&lt;function f at 0x4027a8b4&gt;
-</pre>
-</blockquote>
-<p>in the second case it returns a method</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm.__get__(C(),C)
-&lt;bound method type.f of &lt;class '__main__.C'&gt;&gt;
-</pre>
-</blockquote>
-<p>Let me discuss more in detail the static methods, first.</p>
-<p>It is always possible to extract the function from the static method
-via the syntaxes <tt class="literal"><span class="pre">sm.__get__(a)</span></tt> and <tt class="literal"><span class="pre">sm.__get__(a,b)</span></tt> with <em>ANY</em> valid
-a and b, i.e. the result does not depend on a and b. This is correct,
-since static methods are actually function that have nothing to do
-with the class and the instances to which they are bound.</p>
-<p>This behaviour of the method wrapper makes clear why the relation between
-methods and functions is inversed for static methods with respect to
-regular methods:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... s=staticmethod(lambda : None)
-... print s
-...
-&lt;staticmethod object at 0x8158ec8&gt;
-</pre>
-</blockquote>
-<p>Static methods are non-trivial objects <em>inside</em> the class, whereas
-they are regular functions <em>outside</em> the class:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.s
-&lt;function &lt;lambda&gt; at 0x8158e7c&gt;
-&gt;&gt;&gt; C().s
-&lt;function &lt;lambda&gt; at 0x8158e7c&gt;
-</pre>
-</blockquote>
-<p>The situation is different for classmethods: inside the class they
-are non-trivial objects, just as static methods,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... cm=classmethod(lambda cls: None)
-... print cm
-...
-&lt;classmethod object at 0x8156100&gt;
-</pre>
-</blockquote>
-<p>but outside the class they are methods bound to the class,</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; c=C()
-&gt;&gt;&gt; prn('c.cm')
-&lt;bound method type.&lt;lambda&gt; of &lt;class '__main__.C'&gt;&gt;
-0x811095c
-</pre>
-</blockquote>
-<p>and not to the instance 'c'. The reason is that the <tt class="literal"><span class="pre">__get__</span></tt> wrapper method
-can be invoked with the syntax <tt class="literal"><span class="pre">__get__(a,cls)</span></tt> which
-is only sensitive to the second argument or with the syntax
-<tt class="literal"><span class="pre">__get__(obj)</span></tt> which is only sensitive to the type of the first
-argument:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm.__get__('whatever',C) # the first argument is ignored
-&lt;bound method type.f of &lt;class '__main__.C'&gt;&gt;
-</pre>
-</blockquote>
-<p>sensitive to the type of 'whatever':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm.__get__('whatever') # in Python 2.2 would give a serious error
-&lt;bound method type.f of &lt;type 'str'&gt;&gt;
-</pre>
-</blockquote>
-<p>Notice that the class method is actually bound to C's class, i.e.
-to 'type'.</p>
-<p>Just as regular methods (and differently
-from static methods) classmethods have attributes <tt class="literal"><span class="pre">im_class</span></tt>, <tt class="literal"><span class="pre">im_func</span></tt>,
-and <tt class="literal"><span class="pre">im_self</span></tt>. In particular one can retrieve the function wrapped inside
-the classmethod with</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; cm.__get__('whatever','whatever').im_func
-&lt;function f at 0x402c2534&gt;
-</pre>
-</blockquote>
-<p>The difference with regular methods is that <tt class="literal"><span class="pre">im_class</span></tt> returns the
-class of 'C' whereas <tt class="literal"><span class="pre">im_self</span></tt> returns 'C' itself.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.cm.im_self # a classmethod is attached to the class
-&lt;class '__main__.C'&gt;
-&gt;&gt;&gt; C.cm.im_class #the class of C
-&lt;type 'type'&gt;
-</pre>
-</blockquote>
-<p>Remark: Python 2.2.0 has a bug in classmethods (fixed in newer versions):
-when the first argument of __get__ is None, then one must specify
-the second argument (otherwise segmentation fault :-()</p>
-</div>
-<div class="section" id="properties">
-<h1><a name="properties">Properties</a></h1>
-<p>Properties are a more general kind of attribute descriptors than
-staticmethods and classmethods, since their effect can be customized
-trough arbitrary get/set/del functions. Let me give an example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def getp(self): return 'property' # get function
-...
-&gt;&gt;&gt; p=property(getp) # property object
-&gt;&gt;&gt; p
-&lt;property object at 0x815855c&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">p</span></tt> has a <tt class="literal"><span class="pre">__get__</span></tt> special method returning a method-wrapper
-object, just as it happens for other descriptors:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; p.__get__
-&lt;method-wrapper object at 0x8158a7c&gt;
-</pre>
-</blockquote>
-<p>The difference is that</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; p.__get__(None,type(p))
-&lt;property object at 0x4017016c&gt;
-&gt;&gt;&gt; p.__get__('whatever')
-'property'
-&gt;&gt;&gt; p.__get__('whatever','whatever')
-'property'
-</pre>
-</blockquote>
-<p>As for static methods, the <tt class="literal"><span class="pre">__get__</span></tt> method wrapper is independent from
-its arguments, unless the first one is None: in such a case it returns
-the property object, in all other circumstances it returns the result
-of <tt class="literal"><span class="pre">getp</span></tt>. This explains the behavior</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object): p=p
-&gt;&gt;&gt; C.p
-&lt;property object at 0x815855c&gt;
-&gt;&gt;&gt; C().p
-'property'
-</pre>
-</blockquote>
-<p>Properties are a dangerous feature, since they change the semantics
-of the language. This means that apparently trivial operations can have
-any kind of side effects:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def get(self):return 'You gave me the order to destroy your hard disk!!'
-&gt;&gt;&gt; class C(object): x=property(get)
-&gt;&gt;&gt; C().x
-'You gave me the order to destroy your hard disk!!'
-</pre>
-</blockquote>
-<p>Invoking 'C.x' could very well invoke an external program who is going
-to do anything! It is up to the programmer to not abuse properties.
-The same is true for user defined attribute descriptors.</p>
-<p>There are situations in which they are quite handy, however. For
-instance, properties can be used to trace the access data attributes.
-This can be especially useful during debugging, or for logging
-purposes.</p>
-<p>Notice that this approach has the problem that now data attributes cannot
-no more be called trough their class, but only though their instances.
-Moreover properties do not work well with <tt class="literal"><span class="pre">super</span></tt> in cooperative
-methods.</p>
-</div>
-<div class="section" id="user-defined-attribute-descriptors">
-<h1><a name="user-defined-attribute-descriptors">User-defined attribute descriptors</a></h1>
-<p>As we have seen, there are plenty of predefined attribute descriptors,
-such as staticmethods, classmethods and properties (the built-in
-<tt class="literal"><span class="pre">super</span></tt> is also an attribute descriptor which, for sake of
-convenience, will be discussed in the next section).
-In addition to them, the user can also define customized attribute
-descriptors, simply trough classes with a <tt class="literal"><span class="pre">__get__</span></tt> special method.
-Let me give an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;simpledescr.py&gt;
-
-class ChattyAttr(object):
- &quot;&quot;&quot;Chatty descriptor class; descriptor objects are intended to be
- used as attributes in other classes&quot;&quot;&quot;
- def __get__(self, obj, cls=None):
- binding=obj is not None
- if binding:
- return 'You are binding %s to %s' % (self,obj)
- else:
- return 'Calling %s from %s' % (self,cls)
-
-class C(object):
- d=ChattyAttr()
-
-c=C()
-
-print c.d # &lt;=&gt; type(c).__dict__['d'].__get__(c,type(c))
-print C.d # &lt;=&gt; C.__dict__['d'].__get__(None,C)
-
-#&lt;/simpledescr.py&gt;
-</pre>
-</blockquote>
-<p>with output:</p>
-<blockquote>
-<pre class="literal-block">
-You are binding &lt;ChattyAttr object at 0x401bc1cc&gt; to
-&lt;C object at 0x401bc2ec&gt;
-Calling &lt;ChattyAttr object at 0x401bc1cc&gt; from &lt;class 'C'&gt;
-</pre>
-</blockquote>
-<p>Invoking a method with the syntax <tt class="literal"><span class="pre">C.d</span></tt> or <tt class="literal"><span class="pre">c.d</span></tt> involves calling
-<tt class="literal"><span class="pre">__get__</span></tt>. The <tt class="literal"><span class="pre">__get__</span></tt> signature is fixed: it is
-`` __get__=__get__(self,obj,cls=None)``, since the notation
-<tt class="literal"><span class="pre">self.descr_attr</span></tt> automatically passes <tt class="literal"><span class="pre">self</span></tt> and <tt class="literal"><span class="pre">self.__class__</span></tt> to
-<tt class="literal"><span class="pre">__get__</span></tt>.</p>
-<p>Custom descriptors can be used to restrict the access to objects in a
-more general way than trough properties. For instance, suppose one
-wants to raise an error if a given attribute 'a' is accessed, both
-from the class and from the instance: a property cannot help here,
-since it works only from the instance. The solution is the following
-custom descriptor:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class AccessError(object):
- &quot;&quot;&quot;Descriptor raising an AttributeError when the attribute is
- accessed&quot;&quot;&quot; #could be done with a property
- def __init__(self,errormessage):
- self.msg=errormessage
- def __get__(self,obj,cls=None):
- raise AttributeError(self.msg)
-
-#&lt;/oopp.py&gt;
-
-&gt;&gt;&gt; from oopp import AccessError
-&gt;&gt;&gt; class C(object):
-... a=AccessError(&quot;'a' cannot be accessed&quot;)
-&gt;&gt;&gt; c=C()
-&gt;&gt;&gt; c.a #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
- File &quot;oopp.py&quot;, line 313, in __get__
- raise AttributeError(self.msg)
-AttributeError: 'a' cannot be accessed
-&gt;&gt;&gt; C.a #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
- File &quot;oopp.py&quot;, line 313, in __get__
- raise AttributeError(self.msg)
-AttributeError: 'a' cannot be accessed
-</pre>
-</blockquote>
-<p>It is always possibile to convert plain attributes (i.e. attributes
-without a &quot;__get__&quot; method) to descriptor objects:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class convert2descriptor(object):
- &quot;&quot;&quot;To all practical means, this class acts as a function that, given an
- object, adds to it a __get__ method if it is not already there. The
- added __get__ method is trivial and simply returns the original object,
- independently from obj and cls.&quot;&quot;&quot;
- def __new__(cls,a):
- if hasattr(a,&quot;__get__&quot;): # do nothing
- return a # a is already a descriptor
- else: # creates a trivial attribute descriptor
- cls.a=a
- return object.__new__(cls)
- def __get__(self,obj,cls=None):
- &quot;Returns self.a independently from obj and cls&quot;
- return self.a
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>This example also shows the magic of <tt class="literal"><span class="pre">__new__</span></tt>, that allows to use a
-class as a function. The output of 'convert2descriptor(a)' can be both
-an instance of 'convert2descriptor' (in this case 'convert2descriptor' acts as
-a normal class, i.e. as an object factory) or 'a' itself
-(if 'a' is already a descriptor): in this case 'convert2descriptor' acts
-as a function.</p>
-<p>For instance, a string is converted to a descriptor</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import convert2descriptor
-&gt;&gt;&gt; a2=convert2descriptor('a')
-&gt;&gt;&gt; a2
-&lt;oopp.convert2descriptor object at 0x4017506c&gt;
-&gt;&gt;&gt; a2.__get__('whatever')
-'a'
-</pre>
-</blockquote>
-<p>whereas a function is untouched:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(): pass
-&gt;&gt;&gt; f2=convert2descriptor(f) # does nothing
-&gt;&gt;&gt; f2
-&lt;function f at 0x4019110c&gt;
-</pre>
-</blockquote>
-</div>
-<div class="section" id="data-descriptors">
-<h1><a name="data-descriptors">Data descriptors</a></h1>
-<p>It is also possible to specify a <tt class="literal"><span class="pre">__set__</span></tt> method (descriptors
-with a <tt class="literal"><span class="pre">__set__</span></tt> method are typically data descriptors) with
-the signature <tt class="literal"><span class="pre">__set__(self,obj,value)</span></tt> as in the following
-example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;datadescr.py&gt;
-
-class DataDescriptor(object):
- value=None
- def __get__(self, obj, cls=None):
- if obj is None: obj=cls
- print &quot;Getting&quot;,obj,&quot;value =&quot;,self.value
- return self.value
- def __set__(self, obj, value):
- self.value=value
- print &quot;Setting&quot;,obj,&quot;value =&quot;,value
-
-class C(object):
- d=DataDescriptor()
-
-c=C()
-
-c.d=1 #calls C.__dict__['d'].__set__(c,1)
-c.d #calls C.__dict__['d'].__get__(c,C)
-C.d #calls C.__dict__['d'].__get__(None,C)
-C.d=0 #does *not* call __set__
-print &quot;C.d =&quot;,C.d
-
-#&lt;/datadescr.py&gt;
-</pre>
-</blockquote>
-<p>With output:</p>
-<blockquote>
-<pre class="literal-block">
-Setting &lt;C object at 0x401bc1ec&gt; value = 1
-Getting &lt;C object at 0x401bc42c&gt; value = 1
-Getting &lt;class 'C'&gt; value = 1
-C.d = 0
-</pre>
-</blockquote>
-<p>With this knowledge, we may now reconsider the clock example given
-in chapter 3. #NO!??</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import oopp
-&gt;&gt;&gt; class Clock(object): pass
-&gt;&gt;&gt; myclock=Clock()
-...
-&gt;&gt;&gt; myclock.get_time=oopp.get_time # this is a function
-&gt;&gt;&gt; Clock.get_time=lambda self : oopp.get_time() # this is a method
-</pre>
-</blockquote>
-<p>In this example, <tt class="literal"><span class="pre">myclock.get_time</span></tt>, which is attached to the <tt class="literal"><span class="pre">myclock</span></tt>
-object, is a function, whereas <tt class="literal"><span class="pre">Clock.get_time</span></tt>, which is attached to
-the <tt class="literal"><span class="pre">Clock</span></tt> class is a method. We may also check this by using the <tt class="literal"><span class="pre">type</span></tt>
-function:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(myclock.get_time)
-&lt;type 'function'&gt;
-</pre>
-</blockquote>
-<p>whereas</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(Clock.get_time)
-&lt;type 'instance method'&gt;
-</pre>
-</blockquote>
-<p>It must be remarked that user-defined attribute descriptors, just as
-properties, allow to arbitrarily change the semantics of the language
-and should be used with care.</p>
-</div>
-<div class="section" id="the-super-attribute-descriptor">
-<h1><a name="the-super-attribute-descriptor">The <tt class="literal"><span class="pre">super</span></tt> attribute descriptor</a></h1>
-<p>super has also a second form, where it is more used as a descriptor.</p>
-<p><tt class="literal"><span class="pre">super</span></tt> objects are attribute descriptors, too, with a <tt class="literal"><span class="pre">__get__</span></tt>
-method returning a method-wrapper object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,C()).__get__
-&lt;method-wrapper object at 0x8161074&gt;
-</pre>
-</blockquote>
-<p>Here I give some example of acceptable call:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,C()).__get__('whatever')
-&lt;super: &lt;class 'C'&gt;, &lt;C object&gt;&gt;
-&gt;&gt;&gt; super(C,C()).__get__('whatever','whatever')
-&lt;super: &lt;class 'C'&gt;, &lt;C object&gt;&gt;
-</pre>
-</blockquote>
-<p>Unfortunately, for the time being
-(i.e. for Python 2.3), the <tt class="literal"><span class="pre">super</span></tt> mechanism has various limitations.
-To show the issues, let me start by considering the following base class:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class ExampleBaseClass(PrettyPrinted):
- &quot;&quot;&quot;Contains a regular method 'm', a staticmethod 's', a classmethod
- 'c', a property 'p' and a data attribute 'd'.&quot;&quot;&quot;
- m=lambda self: 'regular method of %s' % self
- s=staticmethod(lambda : 'staticmethod')
- c=classmethod(lambda cls: 'classmethod of %s' % cls)
- p=property(lambda self: 'property of %s' % self)
- a=AccessError('Expected error')
- d='data'
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Now, let me derive a new class C from ExampleBaseClass:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import ExampleBaseClass
-&gt;&gt;&gt; class C(ExampleBaseClass): pass
-&gt;&gt;&gt; c=C()
-</pre>
-</blockquote>
-<p>Ideally, we would like to retrieve the methods and attributes of
-ExampleBaseClass from C, by using the <tt class="literal"><span class="pre">super</span></tt> mechanism.</p>
-<ol class="arabic simple">
-<li>We see that <tt class="literal"><span class="pre">super</span></tt> works without problems for regular methods,
-staticmethods and classmethods:</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,c).m()
-'regular method of &lt;C&gt;'
-&gt;&gt;&gt; super(C,c).s()
-'staticmethod'
-&gt;&gt;&gt; super(C,c).c()
-&quot;classmethod of &lt;class '__main__.C'&gt;&quot;
-</pre>
-</blockquote>
-<p>It also works for user defined attribute descriptors:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,c).a # access error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
- File &quot;oopp.py&quot;, line 340, in __get__
- raise AttributeError(self.msg)
-AttributeError: Expected error
-</pre>
-</blockquote>
-<p>and for properties (only for Python 2.3+):</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; ExampleBaseClass.p
-&lt;property object at 0x81b30fc&gt;
-</pre>
-</blockquote>
-<p>In Python 2.2 one would get an error, instead</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,c).p #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'super' object has no attribute 'p'
-</pre>
-</blockquote>
-<p>3. Moreover, certain attributes of the superclass, such as its
-<tt class="literal"><span class="pre">__name__</span></tt>, cannot be retrieved:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; ExampleBaseClass.__name__
-'ExampleBaseClass'
-&gt;&gt;&gt; super(C,c).__name__ #error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'super' object has no attribute '__name__'
-</pre>
-</blockquote>
-<ol class="arabic simple" start="4">
-<li>There is no direct way to retrieve the methods of the super-superclass
-(i.e. the grandmother class, if you wish) or in general the furthest
-ancestors, since <tt class="literal"><span class="pre">super</span></tt> does not chain.</li>
-<li>Finally, there are some subtle issues with the <tt class="literal"><span class="pre">super(cls)</span></tt> syntax:</li>
-</ol>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C).m #(2) error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'super' object has no attribute 'm'
-</pre>
-</blockquote>
-<p>means <tt class="literal"><span class="pre">super(C).__get__(None,C)</span></tt>, but only
-<tt class="literal"><span class="pre">super(C).__get__(c,C).m==super(C,c)</span></tt> works.</p>
-<blockquote>
-<blockquote>
-On the other hand,</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C).__init__ #(1)
-&lt;built-in method __init__ of type object at 0x80e6fc0&gt;
-&gt;&gt;&gt; super(C).__new__ #(1)
-&lt;built-in method __init__ of type object at 0x80e6fc0&gt;
-</pre>
-<blockquote>
-seems to work, whereas in reality does not. The reason is that since
-<tt class="literal"><span class="pre">super</span></tt> objects are instances
-of <tt class="literal"><span class="pre">object</span></tt>, they inherit object's methods, and in particular
-<tt class="literal"><span class="pre">__init__</span></tt> ; therefore the <tt class="literal"><span class="pre">__init__</span></tt> method in (1) is <em>not</em>
-the <tt class="literal"><span class="pre">ExampleBaseClass.__init__</span></tt> method. The point is that <tt class="literal"><span class="pre">super</span></tt>
-objects are attribute descriptors and not references to the superclass.</blockquote>
-</blockquote>
-<p>Probably, in future versions of Python the <tt class="literal"><span class="pre">super</span></tt> mechanism will be
-improved. However, for the time being, one must provide a workaround for
-dealing with these issues. This will be discussed in the next chapter.</p>
-</div>
-<div class="section" id="method-wrappers">
-<h1><a name="method-wrappers">Method wrappers</a></h1>
-<p>One of the most typical applications of attribute descriptors is their
-usage as <em>method wrappers</em>.</p>
-<p>Suppose, for instance, one wants to add tracing capabilities to
-the methods of a class for debugging purposes. The problem
-can be solved with a custom descriptor class:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-import inspect
-
-class wrappedmethod(Customizable):
- &quot;&quot;&quot;Customizable method factory intended for derivation.
- The wrapper method is overridden in the children.&quot;&quot;&quot;
-
- logfile=sys.stdout # default
- namespace='' # default
-
- def __new__(cls,meth): # meth is a descriptor
- if isinstance(meth,FunctionType):
- kind=0 # regular method
- func=meth
- elif isinstance(meth,staticmethod):
- kind=1 # static method
- func=meth.__get__('whatever')
- elif isinstance(meth,classmethod):
- kind=2 # class method
- func=meth.__get__('whatever','whatever').im_func
- elif isinstance(meth,wrappedmethod): # already wrapped
- return meth # do nothing
- elif inspect.ismethoddescriptor(meth):
- kind=0; func=meth # for many builtin methods
- else:
- return meth # do nothing
- self=super(wrappedmethod,cls).__new__(cls)
- self.kind=kind; self.func=func # pre-initialize
- return self
-
- def __init__(self,meth): # meth not used
- self.logfile=self.logfile # default values
- self.namespace=self.namespace # copy the current
-
- def __get__(self,obj,cls): # closure
- def _(*args,**kw):
- if obj is None: o=() # unbound method call
- else: o=(obj,) # bound method call
- allargs=[o,(),(cls,)][self.kind]+args
- return self.wrapper()(*allargs,**kw)
- return _ # the wrapped function
- # allargs is the only nontrivial line in _; it adds
- # 0 - obj if meth is a regular method
- # 1 - nothing if meth is a static method
- # 2 - cls if meth is a class method
-
- def wrapper(self): return self.func # do nothing, to be overridden
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>This class is intended for derivation: the wrapper method has to be overridden
-in the children in order to introduce the wanted feature. If I want to
-implement the capability of tracing methods, I can reuse the <tt class="literal"><span class="pre">with_tracer</span></tt>
-closure introduced in chapter 2:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class tracedmethod(wrappedmethod):
- def wrapper(self):
- return with_tracer(self.func,self.namespace,self.logfile)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Nothing prevents me from introducing timing features by reusing the
-<tt class="literal"><span class="pre">with_timer</span></tt> closure:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-class timedmethod(wrappedmethod):
- iterations=1 # additional default parameter
-
- def __init__(self,meth):
- super(timedmethod,self).__init__(self,meth)
- self.iterations=self.iterations # copy
-
- def wrapper(self):
- return with_timer(self.func,self.namespace,
- self.iterations,self.logfile)
-
-#&lt;/oopp.py&gt;
-</pre>
-</blockquote>
-<p>Here there is an example of usage:</p>
-<p>The dictionary of wrapped functions is then built from an utility function</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;oopp.py&gt;
-
-def wrap(obj,wrapped,condition=lambda k,v: True, err=None):
- &quot;Retrieves obj's dictionary and wraps it&quot;
- if isinstance(obj,dict): # obj is a dictionary
- dic=obj
- else:
- dic=getattr(obj,'__dict__',{}).copy() # avoids dictproxy objects
- if not dic: dic=attributes(obj) # for simple objects
- wrapped.namespace=getattr(obj,'__name__','')
- for name,attr in dic.iteritems(): # modify dic
- if condition(name,attr): dic[name]=wrapped(attr)
- if not isinstance(obj,dict): # modify obj
- customize(obj,err,**dic)
-
-#&lt;/oopp.py&gt;
-</pre>
-<pre class="literal-block">
-#&lt;tracingmethods.py&gt;
-
-from oopp import *
-
-class C(object):
- &quot;Class with traced methods&quot;
-
- def f(self): return self
- f=tracedmethod(f)
-
- g=staticmethod(lambda:None)
- g=tracedmethod(g)
-
- h=classmethod(do_nothing)
- h=tracedmethod(h)
-
-c=C()
-
-#unbound calls
-C.f(c)
-C.g()
-C.h()
-
-#bound calls
-c.f()
-c.g()
-c.h()
-
-#&lt;/tracingmethods.py&gt;
-</pre>
-</blockquote>
-<p>Output:</p>
-<blockquote>
-<pre class="literal-block">
-[C] Calling 'f' with arguments
-(&lt;C object at 0x402042cc&gt;,){} ...
--&gt; 'C.f' called with result: &lt;C object at 0x402042cc&gt;
-
-[C] Calling '&lt;lambda&gt;' with arguments
-(){} ...
--&gt; 'C.&lt;lambda&gt;' called with result: None
-
-[C] Calling 'do_nothing' with arguments
-(&lt;class 'C'&gt;,){} ...
--&gt; 'C.do_nothing' called with result: None
-
-[C] Calling 'f' with arguments
-(&lt;C object at 0x402042cc&gt;,){} ...
--&gt; 'C.f' called with result: &lt;C object at 0x402042cc&gt;
-
-[C] Calling '&lt;lambda&gt;' with arguments
-(){} ...
--&gt; 'C.&lt;lambda&gt;' called with result: None
-
-[C] Calling 'do_nothing' with arguments
-(&lt;class 'C'&gt;,){} ...
--&gt; 'C.do_nothing' called with result: None
-</pre>
-</blockquote>
-<p>The approach in 'tracingmethods.py' works, but it is far from
-being elegant, since I had to explicitly wrap each method in the
-class by hand.</p>
-<p>Both problems can be avoided.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from oopp import *
-&gt;&gt;&gt; wrap(Clock,tracedmethod)
-&gt;&gt;&gt; Clock.get_time()
-[Clock] Calling 'get_time' with arguments
-(){} ...
--&gt; 'Clock.get_time' called with result: 21:56:52
-'21:56:52'
-</pre>
-</blockquote>
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="descr.txt">View document source</a>.
-Generated on: 2004-02-18 07:07 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/doctest_talk/P01.html b/pypers/doctest_talk/P01.html
deleted file mode 100755
index 1f655c6..0000000
--- a/pypers/doctest_talk/P01.html
+++ /dev/null
@@ -1,115 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P01</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P02.html">Next</a></td> <td bgcolor="lightblue"><a href="P27.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing in Python: wonderful doctest!</h1><br/>
-
-<center>
-
- Italian Code Jam <br/> <br/>
-
- 09 Oct 2004 <br/> <br/>
-
- Michele Simionato <br/> <br/>
-
- m.simionato@partecs.com <br/> <br/>
-
- Partecs s.r.l. <br/> <br/>
-
-</center></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P02.html b/pypers/doctest_talk/P02.html
deleted file mode 100755
index a61f26c..0000000
--- a/pypers/doctest_talk/P02.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P02</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">Next</a></td> <td bgcolor="lightblue"><a href="P01.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P02.html">P02</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Summary</h1><br/>
-
-<ul>
- <li> What is automatic testing? </li>
- <li> Why automatic testing is better? </li>
- <li> Which kind of automatic testing? </li>
- <li> How does it work, in practice? </li>
- <li> What about the future? </li>
- <li> What's the final message?</li>
-<ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P03.html b/pypers/doctest_talk/P03.html
deleted file mode 100755
index 8522de5..0000000
--- a/pypers/doctest_talk/P03.html
+++ /dev/null
@@ -1,105 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P03</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P04.html">Next</a></td> <td bgcolor="lightblue"><a href="P02.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>What is automatic testing</h1><br/>
-
-Any methodology that allows you to test
-your application mechanically, repeatedly
-and in a <em>controlled reproducible</em> way.</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P04.html b/pypers/doctest_talk/P04.html
deleted file mode 100755
index fa763e9..0000000
--- a/pypers/doctest_talk/P04.html
+++ /dev/null
@@ -1,111 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P04</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">Next</a></td> <td bgcolor="lightblue"><a href="P03.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P04.html">P04</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing is better (1)</h1><br/>
-
-When doing manual testing typically you spend
-
-<center><h2>
-
- 1 hour of coding + 10 hours of testing/debugging
-
-</center></h2>
-
-on the other hand ...</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P05.html b/pypers/doctest_talk/P05.html
deleted file mode 100755
index 23aa94d..0000000
--- a/pypers/doctest_talk/P05.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P05</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P06.html">Next</a></td> <td bgcolor="lightblue"><a href="P04.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing is better (2)</h1><br/>
-
-... when doing automatic testing typically you spend
-
-<br/> <br/>
-<center><h2>
-
- 1 hour of coding + 10 hours of testing/debugging !
-
-</center></h2></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P06.html b/pypers/doctest_talk/P06.html
deleted file mode 100755
index 47bc44f..0000000
--- a/pypers/doctest_talk/P06.html
+++ /dev/null
@@ -1,111 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P06</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">Next</a></td> <td bgcolor="lightblue"><a href="P05.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P06.html">P06</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>However ...</h1><br/>
-
-Think about six month later!
- <br/><br/>
-<center><em>
-
- there is a difference</em>
-
- <h2><u>Refactoring!</u><h2>
-
-</center></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P07.html b/pypers/doctest_talk/P07.html
deleted file mode 100755
index 02b39ab..0000000
--- a/pypers/doctest_talk/P07.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P07</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P08.html">Next</a></td> <td bgcolor="lightblue"><a href="P06.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing in Python</h1><br/>
-
-There are two standard testing frameworks in Python:
-
-<ol>
- <li> unittest </li>
- <li> doctest </li>
-</ol>
-
-Which one should I use?</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P08.html b/pypers/doctest_talk/P08.html
deleted file mode 100755
index 8da995d..0000000
--- a/pypers/doctest_talk/P08.html
+++ /dev/null
@@ -1,105 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P08</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">Next</a></td> <td bgcolor="lightblue"><a href="P07.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P08.html">P08</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Well,</h1><br/>
-
-since my talk has <em>doctest</em> in the title ...
-
- ;-)</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P09.html b/pypers/doctest_talk/P09.html
deleted file mode 100755
index d46fe05..0000000
--- a/pypers/doctest_talk/P09.html
+++ /dev/null
@@ -1,117 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P09</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P10.html">Next</a></td> <td bgcolor="lightblue"><a href="P08.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>More seriously ...</h1><br/>
-
-Use different testing frameworks; each one has advantages
-and disadvantages; use combinations of them; invent your
-own testing procedure.
-
-I use combinations of
-
-<ul>
- <li> unittest </li>
- <li> doctest </li>
- <li> custom tests </li>
- <li> Makefile driven tests </li>
- <li> et al. </li>
-</ul>
-
-doctest emphasis is on <em>documentation</em></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P10.html b/pypers/doctest_talk/P10.html
deleted file mode 100755
index 5d265ad..0000000
--- a/pypers/doctest_talk/P10.html
+++ /dev/null
@@ -1,104 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P10</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">Next</a></td> <td bgcolor="lightblue"><a href="P09.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P10.html">P10</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>What is doctest?</h1><br/>
-
-In its simplest form (not the form I use it) it allows
-you to include tests in the docstrings of your application.</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P11.html b/pypers/doctest_talk/P11.html
deleted file mode 100755
index b068e9d..0000000
--- a/pypers/doctest_talk/P11.html
+++ /dev/null
@@ -1,118 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P11</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P12.html">Next</a></td> <td bgcolor="lightblue"><a href="P10.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Example</h1><br/>
-<pre># split.py
-import re
-SEP = re.compile(r"\s*[,;]\s*")
-
-def split(text):
- """Split a string taking as separators "," ";".
- Example:
- >>> from split import split
- >>> split("hello, world!; welcome to the Italian Code Jam!")
- ['hello', 'world!', 'welcome to the Italian Code Jam!']
- """
- return SEP.split(text)
-
-if __name__ == "__main__":
- import __main__, doctest
- doctest.testmod(__main__)
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P12.html b/pypers/doctest_talk/P12.html
deleted file mode 100755
index 2a74e07..0000000
--- a/pypers/doctest_talk/P12.html
+++ /dev/null
@@ -1,122 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P12</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">Next</a></td> <td bgcolor="lightblue"><a href="P11.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P12.html">P12</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Running doctest in verbose mode</h1><br/>
-
-<pre>
-$ python split.py -v
-Running __main__.__doc__
-0 of 0 examples failed in __main__.__doc__
-Running __main__.split.__doc__
-Trying: from split import split
-Expecting: nothing
-ok
-Trying: split("hello, world!; welcome to the Italian Code Jam!")
-Expecting: ['hello', 'world!', 'welcome to the Italian Code Jam!']
-ok
-0 of 2 examples failed in __main__.split.__doc__
-1 items had no tests:
- __main__
-1 items passed all tests:
- 2 tests in __main__.split
-2 tests in 2 items.
-2 passed and 0 failed.
-Test passed.
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P13.html b/pypers/doctest_talk/P13.html
deleted file mode 100755
index dea66af..0000000
--- a/pypers/doctest_talk/P13.html
+++ /dev/null
@@ -1,114 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P13</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P14.html">Next</a></td> <td bgcolor="lightblue"><a href="P12.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Why I do not use the standard approach</h1><br/>
-
-<ul>
-<li> It makes you end up with very large docstrings</li>
-
-<li> It abuses the original purpose of docstrings</li>
-
-<li> It conflates two different aspects (code and tests on the code)</li>
-
-<li> It is much easier to write the documentation in a separate
- text file </li>
-
-<li> Testing should be done by an external tool anyway </li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P14.html b/pypers/doctest_talk/P14.html
deleted file mode 100755
index b4f5394..0000000
--- a/pypers/doctest_talk/P14.html
+++ /dev/null
@@ -1,122 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P14</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">Next</a></td> <td bgcolor="lightblue"><a href="P13.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P14.html">P14</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>How I use doctest</h1><br/>
-
-I hacked inside doctest and wrote a custom utility to extract
-doctests from documentation files since
-
-<ul>
-
- <li> I like keeping the documentation on a separate rst file</li>
-
- <li>there is no sync problem since you run the tests all the time</li>
-
- <li>it is useful for writing articles ...</li>
-
- <li> ... but also documentation for internal usage in the company</li>
-</ul>
-
-Example:
-
-<pre>
-$ doct howto.txt
-split.txt: 42 tests passed in 0.42 seconds
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P15.html b/pypers/doctest_talk/P15.html
deleted file mode 100755
index 29976b8..0000000
--- a/pypers/doctest_talk/P15.html
+++ /dev/null
@@ -1,116 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P15</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P16.html">Next</a></td> <td bgcolor="lightblue"><a href="P14.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>The split example revisited</h1><br/>
-
-<pre>
-
-Documentation for the 'split' module
-=====================================
-
-The module contains a 'split' function, which
-splits a string taking as separators "," and ";".
-This is an example of usage:
-
->>> from split import split
->>> split("hello, world!; welcome to the Italian Code Jam!")
-['hello', 'world!', 'welcome to the Italian Code Jam!']
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P16.html b/pypers/doctest_talk/P16.html
deleted file mode 100755
index 5d6563d..0000000
--- a/pypers/doctest_talk/P16.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P16</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">Next</a></td> <td bgcolor="lightblue"><a href="P15.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P16.html">P16</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>The split example revisited (continued)</h1><br/>
-
-<pre>
-
-Notice that 'split' eats whitespaces:
-
->>> split("hello , world")
-['hello', 'world']
-
->>> split("hello , ; world")
-['hello', '', 'world']
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P17.html b/pypers/doctest_talk/P17.html
deleted file mode 100755
index ccac807..0000000
--- a/pypers/doctest_talk/P17.html
+++ /dev/null
@@ -1,121 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P17</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P18.html">Next</a></td> <td bgcolor="lightblue"><a href="P16.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Managing exceptions</h1><br/>
-
-It is possible to test that your program raises the exception you
-expect:
-
-<pre>
-
-$ echo """ # split cannot work on a list
->>> from split import split
->>> split([])
-Traceback (most recent call last):
- ...
-TypeError: expected string or buffer
-""" > x.txt
-
-$ doct x.txt
-x.txt: 2 tests passed in 0.01 seconds
-
-</pre>
-
-(notice however that relying on exception messages may be risky)</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P18.html b/pypers/doctest_talk/P18.html
deleted file mode 100755
index 29ea1c9..0000000
--- a/pypers/doctest_talk/P18.html
+++ /dev/null
@@ -1,119 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P18</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">Next</a></td> <td bgcolor="lightblue"><a href="P17.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P18.html">P18</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>When tests fail</h1><br/>
-
-<pre>
-
-$ cat split-failure.txt
-An example of failed text:
-
->>> from split import split
->>> split("hello, world")
-['hello', ' world']
-
-$ doct split-failure.txt
-*****************************************************************
-Failure in example: split("hello, world")
-from line #5 of split-failure.txt
-Expected: ['hello', ' world']
-Got: ['hello', 'world']
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P19.html b/pypers/doctest_talk/P19.html
deleted file mode 100755
index d9ffa42..0000000
--- a/pypers/doctest_talk/P19.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P19</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P20.html">Next</a></td> <td bgcolor="lightblue"><a href="P18.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Doctest caveats</h1><br/>
-<ul>
-
-<li> doctest does not stop at the first failed test.</li>
-<li> doctest is very strict about the expected output </li>
-<li> expected output must end with a newline </li>
-<li> expected output cannot contain a blank line </li>
-<li> output to stdout is captured, but not output to stderr</li>
-
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P20.html b/pypers/doctest_talk/P20.html
deleted file mode 100755
index bf9c20a..0000000
--- a/pypers/doctest_talk/P20.html
+++ /dev/null
@@ -1,118 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P20</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">Next</a></td> <td bgcolor="lightblue"><a href="P19.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P20.html">P20</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Converting doctests to unittests</h1><br/>
-
-<pre>
- import unittest
- import doctest
- import my_module_with_doctests
-
- suite = doctest.DocTestSuite(my_module_with_doctests)
- runner = unittest.TextTestRunner()
- runner.run(suite)
-</pre>
-
-<h2><em>new in Python 2.3!</em><h2>
-
-What about the future?
-----------------------
-
-Many enhacements to be expected!</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P21.html b/pypers/doctest_talk/P21.html
deleted file mode 100755
index 8d4b5ff..0000000
--- a/pypers/doctest_talk/P21.html
+++ /dev/null
@@ -1,122 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P21</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P22.html">Next</a></td> <td bgcolor="lightblue"><a href="P20.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>doctest is becoming even better</h1><br/>
-
-With Python 2.4 you can run doctests on external text files;
-you can also convert these doctests into unittests:
-
-<pre>
-
- import doctest, unittest
- suite = doctest.DocFileSuite(my_documentation_file, package=mypackage)
- unittest.TextTestRunner().run(suite)
-
-</pre>
-
-Example:
-<pre>
-$ doct -u split.txt
-.
-----------------------------------------------------------------------
-Ran 1 test in 0.012s
-
-OK
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P22.html b/pypers/doctest_talk/P22.html
deleted file mode 100755
index 080ad51..0000000
--- a/pypers/doctest_talk/P22.html
+++ /dev/null
@@ -1,111 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P22</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">Next</a></td> <td bgcolor="lightblue"><a href="P21.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P22.html">P22</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Python 2.4 recognizes blank lines</h1><br/>
-
-Blank lines can be marked with &lt;BLANKLINE&gt; :
-<pre>
->>> print 'foo\n\nbar\n'
-foo
-&lt;BLANKLINE&gt;
-bar
-&lt;BLANKLINE&gt;
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P23.html b/pypers/doctest_talk/P23.html
deleted file mode 100755
index af4cf12..0000000
--- a/pypers/doctest_talk/P23.html
+++ /dev/null
@@ -1,120 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P23</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P24.html">Next</a></td> <td bgcolor="lightblue"><a href="P22.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Python 2.4 recognizes flags!</h1><br/>
-
-<ul>
-<li> If the ellipsis flag is used, then '...' can be used to
- elide substrings in the desired output: <pre>
->>> print range(1000) #doctest: +ELLIPSIS
-[0, 1, 2, ..., 999]
-
-</pre></li>
-
-<li>
- If the whitespace normalization flag is used, then
- differences in whitespace are ignored.<pre>
->>> print range(20) #doctest: +NORMALIZE_WHITESPACE
-[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
-12, 13, 14, 15, 16, 17, 18, 19]
-
-</pre></li>
-
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P24.html b/pypers/doctest_talk/P24.html
deleted file mode 100755
index 13d32e0..0000000
--- a/pypers/doctest_talk/P24.html
+++ /dev/null
@@ -1,111 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P24</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">Next</a></td> <td bgcolor="lightblue"><a href="P23.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P24.html">P24</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Zope experience</h1><br/>
-
-Literal quote from the PyCON doctest talk:
-
-<ul>
-<li> ~ 5600 tests (~3500 in Zope 3, ~1300 in ZODB, ~800 in Zope 2)</li>
-<li> we wrote lots of tests before we knew what we were doing</li>
-<li> debugging failed tests is really hard when intent is unclear</li>
-<li> often refactor or reimplement tests to make them clearer</li>
-<li> most new tests are doctest based</li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P25.html b/pypers/doctest_talk/P25.html
deleted file mode 100755
index 1279884..0000000
--- a/pypers/doctest_talk/P25.html
+++ /dev/null
@@ -1,118 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P25</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P26.html">Next</a></td> <td bgcolor="lightblue"><a href="P24.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Conclusion (1): good reasons to use doctest</h1><br/>
-
-<quote>
-"Test coverage is important, but test readability is much more important"
-</quote>
-
-<em>-- Tim Peters and Jim Fulton</em> <br/> <br/>
-
-doctest is good since:
-
-<ol>
- <li> it is easy to understand, to explain and to use </li>
-
- <li> it makes you improve the quality of your documentation </li>
-
- <li> it can be converted to unittest anyway </li>
-
-</ol></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P26.html b/pypers/doctest_talk/P26.html
deleted file mode 100755
index 10220cd..0000000
--- a/pypers/doctest_talk/P26.html
+++ /dev/null
@@ -1,115 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P26</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">Next</a></td> <td bgcolor="lightblue"><a href="P25.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P26.html">P26</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Conclusion (2): the message of this talk</h1><br/>
-
-Automatic testing is good for tons of practical reasons, but also
-because:
-
-<ol>
-
-<li>It teaches you <em>discipline</em> </li>
-
-<li>It makes you
- <em>think differently</em> </li>
-
-<li>It is more <em>fun!</em> </li>
-
-</ol></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P27.html b/pypers/doctest_talk/P27.html
deleted file mode 100755
index 5852f3a..0000000
--- a/pypers/doctest_talk/P27.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P27</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">Next</a></td> <td bgcolor="lightblue"><a href="P26.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P27.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>References</h1><br/>
-
-<ul>
-
-<li>The standard library documentation
-http://docs.python.org/lib/module-doctest.html </li>
-
-<li> The doctest talk by Tim Peters and Jim Fulton
-http://www.python.org/pycon/dc2004/papers/4/</li>
-
-<li> doctest.py <em>(use the source, Luke!)</em></li>
-</ul>
-</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P28.html b/pypers/doctest_talk/P28.html
deleted file mode 100755
index d3d0a7c..0000000
--- a/pypers/doctest_talk/P28.html
+++ /dev/null
@@ -1,116 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P28</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">Next</a></td> <td bgcolor="lightblue"><a href="P27.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P28.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P28.html">P28</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"><a href="P28.html">P28</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>References</h1><br/>
-
-<ul>
-
-<li>The standard library documentation
-http://docs.python.org/lib/module-doctest.html </li>
-
-<li> The doctest talk by Tim Peters and Jim Fulton
-http://www.python.org/pycon/dc2004/papers/4/</li>
-
-<li> doctest.py <em>(use the source, Luke!)</em></li>
-</ul>
-</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/P29.html b/pypers/doctest_talk/P29.html
deleted file mode 100755
index 12ecce5..0000000
--- a/pypers/doctest_talk/P29.html
+++ /dev/null
@@ -1,116 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P29</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0>
-<tr>
- <td bgcolor="lightblue">
-<table border=0>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">Next</a></td> <td bgcolor="lightblue"><a href="P28.html">Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">First</a></td> <td bgcolor="lightblue"><a href="P29.html">Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P29.html">P29</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0>
-<tr>
- <td bgcolor="lightblue"><a href="P01.html">P01</a></td> <td bgcolor="lightblue"><a href="P02.html">P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P03.html">P03</a></td> <td bgcolor="lightblue"><a href="P04.html">P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P05.html">P05</a></td> <td bgcolor="lightblue"><a href="P06.html">P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P07.html">P07</a></td> <td bgcolor="lightblue"><a href="P08.html">P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P09.html">P09</a></td> <td bgcolor="lightblue"><a href="P10.html">P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P11.html">P11</a></td> <td bgcolor="lightblue"><a href="P12.html">P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P13.html">P13</a></td> <td bgcolor="lightblue"><a href="P14.html">P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P15.html">P15</a></td> <td bgcolor="lightblue"><a href="P16.html">P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P17.html">P17</a></td> <td bgcolor="lightblue"><a href="P18.html">P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P19.html">P19</a></td> <td bgcolor="lightblue"><a href="P20.html">P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P21.html">P21</a></td> <td bgcolor="lightblue"><a href="P22.html">P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P23.html">P23</a></td> <td bgcolor="lightblue"><a href="P24.html">P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P25.html">P25</a></td> <td bgcolor="lightblue"><a href="P26.html">P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P27.html">P27</a></td> <td bgcolor="lightblue"><a href="P28.html">P28</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href="P29.html">P29</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>References</h1><br/>
-
-<ul>
-
-<li>The standard library documentation
-http://docs.python.org/lib/module-doctest.html </li>
-
-<li> The doctest talk by Tim Peters and Jim Fulton
-http://www.python.org/pycon/dc2004/papers/4/</li>
-
-<li> doctest.py <em>(use the source, Luke!)</em></li>
-</ul>
-</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/doctest_talk/index.html b/pypers/doctest_talk/index.html
deleted file mode 100755
index 870e229..0000000
--- a/pypers/doctest_talk/index.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title>Partecs Training: Internal Documentation</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<h1 class="title">Partecs Training: Internal Documentation</h1>
-<div class="document" id="partecs-training-internal-documentation">
-<p><a class="reference" href="http://wiki.partecs.com/Developers/PartecsTraining/P01.html">Michele's slides for the Italian Code Jam conference</a></p>
-</div>
-</body>
-</html>
diff --git a/pypers/doctest_talk/split.html b/pypers/doctest_talk/split.html
deleted file mode 100755
index 3cc867a..0000000
--- a/pypers/doctest_talk/split.html
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title>Documentation for the 'split' module</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<h1 class="title">Documentation for the 'split' module</h1>
-<div class="document" id="documentation-for-the-split-module">
-<p>The module contains a 'split' function, which
-splits a string taking as separators &quot;,&quot; and &quot;;&quot;.
-This is an example of usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from split import split
-&gt;&gt;&gt; split(&quot;hello, world!; welcome to the Italian Code Jam!&quot;)
-['hello', 'world!', 'welcome to the Italian Code Jam!']
-</pre>
-<p>Notice that 'split' eats whitespaces:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; split(&quot;hello , world&quot;)
-['hello', 'world']
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; split(&quot;hello , ; world&quot;)
-['hello', '', 'world']
-</pre>
-</div>
-</body>
-</html>
diff --git a/pypers/doctest_talk/talk.html b/pypers/doctest_talk/talk.html
deleted file mode 100755
index a47dd9c..0000000
--- a/pypers/doctest_talk/talk.html
+++ /dev/null
@@ -1,362 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title></title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-<div class="section" id="automatic-testing-in-python-wonderful-doctest">
-<h1><a name="automatic-testing-in-python-wonderful-doctest">Automatic testing in Python: wonderful doctest!</a></h1>
-<p>&lt;center&gt;</p>
-<blockquote>
-<p>Italian Code Jam &lt;br/&gt;</p>
-<blockquote>
-09 Oct 2004 &lt;br/&gt;</blockquote>
-<p>Michele Simionato &lt;br/&gt;</p>
-<blockquote>
-Partecs s.r.l. &lt;br/&gt;</blockquote>
-</blockquote>
-<p>&lt;/center&gt;</p>
-<div class="section" id="summary">
-<h2><a name="summary">Summary</a></h2>
-<dl>
-<dt>&lt;ul&gt;</dt>
-<dd>&lt;li&gt; What is automatic testing? &lt;/li&gt;
-&lt;li&gt; Why automatic testing is better? &lt;/li&gt;
-&lt;li&gt; Which kind of automatic testing should I do? &lt;/li&gt;
-&lt;li&gt; Why I did start writing automatic tests? &lt;/li&gt;
-&lt;li&gt; A few real life examples &lt;/li&gt;</dd>
-</dl>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>talk.txt</tt>, line 26)</p>
-Definition list ends without a blank line; unexpected unindent.</div>
-<p>&lt;ul&gt;</p>
-</div>
-<div class="section" id="what-is-automatic-testing">
-<h2><a name="what-is-automatic-testing">What is automatic testing</a></h2>
-<p>Any methodology that allows you to test
-your application mechanically, repeatedly
-and in a controlled reproducible way.</p>
-</div>
-<div class="section" id="why-automatic-testing-is-better">
-<h2><a name="why-automatic-testing-is-better">Why automatic testing is better</a></h2>
-<p>Try to perform <em>manual</em> testing and you will have the answer!</p>
-</div>
-<div class="section" id="automatic-testing-in-python">
-<h2><a name="automatic-testing-in-python">Automatic testing in Python ...</a></h2>
-<p>There are two standard testing frameworks in Python:</p>
-<dl>
-<dt>&lt;ol&gt;</dt>
-<dd>&lt;li&gt; unittest &lt;/li&gt;
-&lt;li&gt; doctest &lt;/li&gt;</dd>
-</dl>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>talk.txt</tt>, line 51)</p>
-Definition list ends without a blank line; unexpected unindent.</div>
-<p>&lt;/ol&gt;</p>
-<p>Which one should I use?</p>
-</div>
-<div class="section" id="the-short-answer">
-<h2><a name="the-short-answer">The short answer</a></h2>
-<p>unitest is boring, doctest is cool, so let's
-talk about it!</p>
-<blockquote>
-;-)</blockquote>
-</div>
-<div class="section" id="more-seriously">
-<h2><a name="more-seriously">More seriously</a></h2>
-<p>Use different testing frameworks; each one has advantages
-and disadvantages; use combinations of them; invert your
-own testing procedure.</p>
-<p>I use combinations of</p>
-<dl>
-<dt>&lt;ul&gt;</dt>
-<dd>&lt;li&gt; unittest &lt;/li&gt;
-&lt;li&gt; doctest &lt;/li&gt;
-&lt;li&gt; custom tests &lt;/li&gt;
-&lt;li&gt; Makefile driven tests &lt;/li&gt;
-&lt;li&gt; poor man assertions &lt;/li&gt;
-&lt;li&gt; et al. &lt;/li&gt;</dd>
-</dl>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>talk.txt</tt>, line 81)</p>
-Definition list ends without a blank line; unexpected unindent.</div>
-<p>&lt;/ul&gt;</p>
-</div>
-<div class="section" id="what-is-doctest">
-<h2><a name="what-is-doctest">What is doctest?</a></h2>
-<p>In its simplest form (not the form I use it ;) it allows
-you to include tests in the docstrings of your application.</p>
-</div>
-<div class="section" id="example">
-<h2><a name="example">Example</a></h2>
-<p># split.py
-import re</p>
-<dl>
-<dt>def split(text, sep = re.compile(r&quot;s*[,;]s*&quot;)):</dt>
-<dd>&quot;&quot;&quot;Split a string taking as separators &quot;,&quot; &quot;;&quot;.
-Example:
-&gt;&gt;&gt; from split import split
-&gt;&gt;&gt; split(&quot;hello, world!; welcome to the Italian Code Jam!&quot;)
-['hello', 'world!', 'welcome to the Italian Code Jam!']
-&quot;&quot;&quot;
-return sep.split(text)</dd>
-<dt>if __name__ == &quot;__main__&quot;:</dt>
-<dd>import __main__, doctest
-doctest.testmod(__main__)</dd>
-</dl>
-</div>
-<div class="section" id="running-doctest-in-verbose-mode">
-<h2><a name="running-doctest-in-verbose-mode">Running doctest in verbose mode</a></h2>
-<p>&lt;pre&gt;
-$ python split.py -v
-Running __main__.__doc__
-0 of 0 examples failed in __main__.__doc__
-Running __main__.split.__doc__
-Trying: from split import split
-Expecting: nothing
-ok
-Trying: split(&quot;hello, world!; welcome to the Italian Code Jam!&quot;)
-Expecting: ['hello', 'world!', 'welcome to the Italian Code Jam!']
-ok
-0 of 2 examples failed in __main__.split.__doc__
-1 items had no tests:</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt>talk.txt</tt>, line 113)</p>
-Unexpected indentation.</div>
-<blockquote>
-__main__</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>talk.txt</tt>, line 131)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<dl>
-<dt>1 items passed all tests:</dt>
-<dd>2 tests in __main__.split</dd>
-</dl>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>talk.txt</tt>, line 133)</p>
-Definition list ends without a blank line; unexpected unindent.</div>
-<p>2 tests in 2 items.
-2 passed and 0 failed.
-Test passed.
-&lt;/pre&gt;</p>
-</div>
-<div class="section" id="why-i-do-not-use-the-standard-approach">
-<h2><a name="why-i-do-not-use-the-standard-approach">Why I do not use the standard approach</a></h2>
-<p>&lt;ul&gt;
-&lt;li&gt; It makes you end up with very large docstrings where the actual
-code is easily lost &lt;/li&gt;</p>
-<p>&lt;li&gt; It abuses the original purpose of docstrings&lt;/li&gt;</p>
-<p>&lt;li&gt; It conflates two different aspects (code and tests on the code)&lt;/li&gt;</p>
-<dl>
-<dt>&lt;li&gt; It is much easier to write the documentation in a separate</dt>
-<dd>text file &lt;/li&gt;</dd>
-</dl>
-<p>&lt;li&gt; Testing should be done by an external tool anyway &lt;/li&gt;
-&lt;/ul&gt;</p>
-</div>
-<div class="section" id="how-i-use-doctest">
-<h2><a name="how-i-use-doctest">How I use doctest</a></h2>
-<dl>
-<dt>&lt;ul&gt;</dt>
-<dd><p class="first">&lt;li&gt;I find that too long docstrings make reading the code difficult&lt;/li&gt;</p>
-<p>&lt;li&gt; I like keeping the documentation on a separate rst file&lt;/li&gt;</p>
-<p>&lt;li&gt;there is no sync problem since you run the tests all the time&lt;/li&gt;</p>
-<dl>
-<dt>&lt;li&gt; so I wrote a custom utility to extract doctests from the&lt;/li&gt;</dt>
-<dd>documentation file</dd>
-</dl>
-<p>&lt;li&gt;useful for writing articles ...&lt;/li&gt;</p>
-<p class="last">&lt;li&gt; ... but also tutorials for internal usage in the company&lt;/li&gt;</p>
-</dd>
-</dl>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>talk.txt</tt>, line 173)</p>
-Definition list ends without a blank line; unexpected unindent.</div>
-<p>&lt;/ul&gt;</p>
-</div>
-<div class="section" id="the-split-example-revisited">
-<h2><a name="the-split-example-revisited">The split example revisited</a></h2>
-<p>&lt;pre&gt;</p>
-</div>
-</div>
-<div class="section" id="documentation-for-the-split-module">
-<h1><a name="documentation-for-the-split-module">Documentation for the 'split' module</a></h1>
-<p>The module contains a 'split' function, which
-splits a string taking as separators &quot;,&quot; and &quot;;&quot;.
-This is an example of usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from split import split
-&gt;&gt;&gt; split(&quot;hello, world!; welcome to the Italian Code Jam!&quot;)
-['hello', 'world!', 'welcome to the Italian Code Jam!']
-</pre>
-<p>&lt;/pre&gt;</p>
-<div class="section" id="the-split-example-revisited-continued">
-<h2><a name="the-split-example-revisited-continued">The split example revisited (continued)</a></h2>
-<p>&lt;pre&gt;</p>
-<p>Notice that 'split' eats whitespaces:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; split(&quot;hello , world&quot;)
-['hello', 'world']
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; split(&quot;hello , ; world&quot;)
-['hello', '', 'world']
-</pre>
-<p>&lt;/pre&gt;</p>
-</div>
-<div class="section" id="when-tests-fail">
-<h2><a name="when-tests-fail">When tests fail</a></h2>
-<p>&lt;pre&gt;</p>
-<p>$ cat split-failure.txt
-An example of failed text:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from split import split
-&gt;&gt;&gt; split(&quot;hello, world&quot;)
-['hello', ' world']
-</pre>
-<div class="section" id="doct-split-failure-txt">
-<h3><a name="doct-split-failure-txt">$ doct split-failure.txt</a></h3>
-<p>Failure in example: split(&quot;hello, world&quot;)
-from line #5 of split-failure.txt
-Expected: ['hello', ' world']
-Got: ['hello', 'world']</p>
-<p>&lt;/pre&gt;</p>
-<p>Unfortunately doctest does not stop at the first failed test.</p>
-</div>
-</div>
-<div class="section" id="managing-exceptions">
-<h2><a name="managing-exceptions">Managing exceptions</a></h2>
-<p>It is possible to test that your program raises the exception you
-expect:</p>
-<p>&lt;pre&gt;</p>
-<p>$ echo &quot;&quot;&quot; # split cannot work on a list
-&gt;&gt;&gt; from split import split
-&gt;&gt;&gt; split([])
-Traceback (most recent call last):</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt>talk.txt</tt>, line 230)</p>
-Unexpected indentation.</div>
-<blockquote>
-...</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>talk.txt</tt>, line 248)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>TypeError: expected string or buffer</p>
-<p>&quot;&quot;&quot; &gt; x.txt</p>
-<p>$ doct x.txt
-x.txt: 2 tests passed in 0.01 seconds</p>
-<p>&lt;/pre&gt;</p>
-<p>(notice however that relying on exception messags may be risky)
-(IGNORE_EXCEPTION_DETAIL)</p>
-</div>
-<div class="section" id="converting-doctests-to-unittests">
-<h2><a name="converting-doctests-to-unittests">Converting doctests to unittests</a></h2>
-<blockquote>
-<p>import unittest
-import doctest
-import my_module_with_doctests</p>
-<p>suite = doctest.DocTestSuite(my_module_with_doctests)
-runner = unittest.TextTestRunner()
-runner.run(suite)</p>
-</blockquote>
-</div>
-<div class="section" id="doctest-caveats">
-<h2><a name="doctest-caveats">Doctest caveats</a></h2>
-<p>&lt;ul&gt;</p>
-<p>&lt;li&gt; Expected output must end with a newline &lt;/li&gt;
-&lt;li&gt; Expected output cannot contain a blank line &lt;/li&gt;
-&lt;li&gt; Output to stdout is captured, but not output to stderr&lt;/li&gt;</p>
-<p>&lt;/ul&gt;</p>
-</div>
-<div class="section" id="why-doctest-is-cool">
-<h2><a name="why-doctest-is-cool">Why doctest is cool</a></h2>
-<dl>
-<dt>&lt;ul&gt;</dt>
-<dd><p class="first">&lt;li&gt; it makes you improve the quality of your documentation &lt;/li&gt;</p>
-<p>&lt;li&gt; it is easy to understand and to explain &lt;/li&gt;</p>
-<p>&lt;li&gt; it can be converted to unittest anyway &lt;/li&gt;</p>
-<p class="last">&lt;li&gt; it does not allow inheritance ;-) &lt;/li&gt;</p>
-</dd>
-</dl>
-<p>&lt;/ul&gt;</p>
-</div>
-<div class="section" id="doctest-is-becoming-even-cooler">
-<h2><a name="doctest-is-becoming-even-cooler">doctest is becoming even cooler</a></h2>
-<p>With Python 2.4 you can automatically convert
-doctests in external text files into unittests:</p>
-<p>&lt;pre&gt;</p>
-<blockquote>
-import doctest, unittest
-suite = doctest.DocFileSuite(my_documentation_file, package=mypackage)
-unittest.TextTestRunner().run(suite)</blockquote>
-<p>&lt;/pre&gt;</p>
-</div>
-<div class="section" id="python-2-4-recognizes-blank-lines">
-<h2><a name="python-2-4-recognizes-blank-lines">Python 2.4 recognizes blank lines</a></h2>
-<p>Blank lines can be marked with &amp;lt;BLANKLINE&amp;gt; :
-&lt;pre&gt;
-&gt;&gt;&gt; print 'foonnbarn'
-foo
-&amp;lt;BLANKLINE&amp;gt;
-bar
-&amp;lt;BLANKLINE&amp;gt;</p>
-<p>&lt;/pre&gt;</p>
-</div>
-<div class="section" id="python-2-4-recognizes-flags">
-<h2><a name="python-2-4-recognizes-flags">Python 2.4 recognizes flags!</a></h2>
-<p>&lt;ul&gt;
-&lt;li&gt; If the ellipsis flag is used, then '...' can be used to</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt>talk.txt</tt>, line 316)</p>
-Unexpected indentation.</div>
-<blockquote>
-elide substrings in the desired output: &lt;pre&gt;</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>talk.txt</tt>, line 334)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<pre class="doctest-block">
-&gt;&gt;&gt; print range(1000) #doctest: +ELLIPSIS
-[0, 1, 2, ..., 999]
-</pre>
-<p>&lt;/pre&gt;&lt;/li&gt;</p>
-<dl>
-<dt>&lt;li&gt; </dt>
-<dd>If the whitespace normalization flag is used, then
-differences in whitespace are ignored.&lt;pre&gt;</dd>
-</dl>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>talk.txt</tt>, line 342)</p>
-Definition list ends without a blank line; unexpected unindent.</div>
-<pre class="doctest-block">
-&gt;&gt;&gt; print range(20) #doctest: +NORMALIZE_WHITESPACE
-[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
-12, 13, 14, 15, 16, 17, 18, 19]
-</pre>
-<p>&lt;/pre&gt;&lt;/li&gt;</p>
-<p>&lt;/ul&gt;</p>
-</div>
-<div class="section" id="conclusion-good-reasons-to-use-doctest">
-<h2><a name="conclusion-good-reasons-to-use-doctest">Conclusion: good reasons to use doctest</a></h2>
-<p>&lt;ol&gt;</p>
-<p>&lt;li&gt; it is cool &lt;/li&gt;
-&lt;/ol&gt;</p>
-</div>
-<div class="section" id="references">
-<h2><a name="references">References</a></h2>
-<p>&lt;ul&gt;</p>
-<p>&lt;li&gt;The standard library documentation
-<a class="reference" href="http://docs.python.org/lib/module-doctest.html">http://docs.python.org/lib/module-doctest.html</a> &lt;/li&gt;</p>
-<p>&lt;li&gt; The doctest talk by Tim Peters and Jim Fulton
-<a class="reference" href="http://www.python.org/pycon/dc2004/papers/4">http://www.python.org/pycon/dc2004/papers/4</a>/&lt;/li&gt;</p>
-<p>&lt;li&gt; doctest.py &lt;/li&gt;
-&lt;/ul&gt;</p>
-</div>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/doctest_talk/x.html b/pypers/doctest_talk/x.html
deleted file mode 100755
index 57bfa5f..0000000
--- a/pypers/doctest_talk/x.html
+++ /dev/null
@@ -1,203 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
-<html>
-<head>
- <meta name="generator" content=
- "HTML Tidy for Linux/x86 (vers 1st March 2004), see www.w3.org">
- <meta name="generator" content="Generated by Python">
-
- <title>P01</title>
- <style type="text/css">
- body { font-size: 160%; }
- </style>
-</head>
-
-<body bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue"><img src=
- "cjlogo.jpg"></td>
- </tr>
- </table>
- </td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue"><a href=
- "P02.html">Next</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P26.html">Prev</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P01.html">First</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P26.html">Last</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P01.html">P01</a></td>
-
- <td bgcolor="lightblue"></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"></td>
-
- <td bgcolor="lightblue"></td>
- </tr>
- </table>
- </td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue"><a href=
- "P01.html">P01</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P02.html">P02</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P03.html">P03</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P04.html">P04</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P05.html">P05</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P06.html">P06</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P07.html">P07</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P08.html">P08</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P09.html">P09</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P10.html">P10</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P11.html">P11</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P12.html">P12</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P13.html">P13</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P14.html">P14</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P15.html">P15</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P16.html">P16</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P17.html">P17</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P18.html">P18</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P19.html">P19</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P20.html">P20</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P21.html">P21</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P22.html">P22</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P23.html">P23</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P24.html">P24</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P25.html">P25</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P26.html">P26</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"></td>
-
- <td bgcolor="lightblue"></td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
-
- <td bgcolor="lightblue">
- <h1>Automatic testing in Python: wonderful
- doctest!</h1><br>
-
- <center>
- Italian Code Jam<br>
- <br>
- 09 Oct 2004<br>
- <br>
- Michele Simionato<br>
- <br>
- m.simionato@partecs.com<br>
- <br>
- Partecs s.r.l.
- </center><br>
- </td>
- </tr>
- </table>
-</body>
-</html>
diff --git a/pypers/dot/dot.html b/pypers/dot/dot.html
deleted file mode 100755
index d3a13db..0000000
--- a/pypers/dot/dot.html
+++ /dev/null
@@ -1,347 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.1: http://docutils.sourceforge.net/" />
-<title>Drawing graphs the easy way: an introduction to dot</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="drawing-graphs-the-easy-way-an-introduction-to-dot">
-<h1 class="title">Drawing graphs the easy way: an introduction to <tt class="literal"><span class="pre">dot</span></tt></h1>
-<div class="section" id="got-a-graphing-problem">
-<h1><a name="got-a-graphing-problem">Got a graphing problem?</a></h1>
-<p>You must give a presentation tomorrow and you haven't prepared any
-figure yet; you must document your last project and you need to plot
-your most hairy class hierarchies; you are asked to provide ten slightly
-different variations of the same picture; you are pathologically unable to put
-your finger on a mouse and drawing anything more complex that a square ...
-in all these cases, dont' worry! <tt class="literal"><span class="pre">dot</span></tt> comes at the rescue and
-can save your day!</p>
-</div>
-<div class="section" id="what-is-dot">
-<h1><a name="what-is-dot">What is <tt class="literal"><span class="pre">dot</span></tt>?</a></h1>
-<p><tt class="literal"><span class="pre">dot</span></tt> is a tool to generate nice-looking diagrams with a minimum of
-effort. <tt class="literal"><span class="pre">dot</span></tt> is distributed as a part of <tt class="literal"><span class="pre">GraphViz</span></tt>, an
-Open Source project developed at AT&amp;T and released under a MIT licence.
-It is a high quality and mature product, with very good
-documentation and support, available on all major platforms,
-including Unix/Linux, Windows and Mac. There is an official home-page and
-a supporting mailing list.</p>
-</div>
-<div class="section" id="what-can-i-do-with-dot">
-<h1><a name="what-can-i-do-with-dot">What can I do with <tt class="literal"><span class="pre">dot</span></tt> ?</a></h1>
-<p>First of all, let me make clear that <tt class="literal"><span class="pre">dot</span></tt> is not just another paint program,
-nor a vector graphics program. <tt class="literal"><span class="pre">dot</span></tt> is a scriptable batch-oriented graphing
-tool; it is to vector drawing programs as <tt class="literal"><span class="pre">LaTex</span></tt> is to word processors.
-If you want to have control on every single pixel in your diagram,
-or if you are an artistic person who likes to draw free hand, then <tt class="literal"><span class="pre">dot</span></tt>
-is not for you. <tt class="literal"><span class="pre">dot</span></tt> is a tool for the lazy developer, the one who wants
-the job done with the minimum effort and without caring too much about the details.</p>
-<p>Since <tt class="literal"><span class="pre">dot</span></tt> is not a WYSIWYG tool - even if it comes together with a WYSIWYG tool,
-<tt class="literal"><span class="pre">dotty</span></tt> - it is not intended to be used interactively:
-its strength is the ability to <em>programmatically</em> generate diagrams. To fullfill
-this aim, <tt class="literal"><span class="pre">dot</span></tt> uses a simple but powerful graph description language. You
-just give (very high level) instructions to <tt class="literal"><span class="pre">dot</span></tt> and it will draw the diagrams
-for you, taking into account all the low level details. Whereas the user
-has a faily large choice of customization
-options and can control the final output in many ways, it is not at all easy
-to force <tt class="literal"><span class="pre">dot</span></tt> to do <em>exactly</em> what one wants.</p>
-<p>Expecting that would mean to fight with the tool.
-You should think of <tt class="literal"><span class="pre">dot</span></tt> as a kind of smart boy,
-who likes to do things his own way and who is very good at it, but becomes
-nervous if the master tries to put too much pressure on him.
-The right attitude with <tt class="literal"><span class="pre">dot</span></tt> (just as with Latex) is to trust it and
-let it to do the job.
-At the end, when <tt class="literal"><span class="pre">dot</span></tt> has finished its part, the user can always
-refine the graph by hand, by using <tt class="literal"><span class="pre">dotty</span></tt>, the interactive editor
-of <tt class="literal"><span class="pre">dot</span></tt> diagrams which comes with GraphViz and has the ability to read
-and generate <tt class="literal"><span class="pre">dot</span></tt> code.
-But in most cases, the user is not expected to do anything manually,
-since <tt class="literal"><span class="pre">dot</span></tt> works pretty well. The right way to go is to customize
-<tt class="literal"><span class="pre">dot</span></tt> options, then the user can programmatically generate one or
-one hundred diagrams with the least effort.</p>
-<p><tt class="literal"><span class="pre">dot</span></tt> is especially useful in repetitive and automatic tasks, since
-it is not difficult to generate <tt class="literal"><span class="pre">dot</span></tt> code.
-For instance, <tt class="literal"><span class="pre">dot</span></tt> comes very handy in the area of automatic documentation
-of code. This kind of jobs can be down with UML tools, but <tt class="literal"><span class="pre">dot</span></tt> has an
-advantage over them in terms of easy of use, flat learning curve and
-flexibility. On top of that, <tt class="literal"><span class="pre">dot</span></tt> is very fast, since it is written in C
-and can generate very complicated diagrams in fractions of second.</p>
-</div>
-<div class="section" id="hello-world-from-dot">
-<h1><a name="hello-world-from-dot">Hello World from <tt class="literal"><span class="pre">dot</span></tt></a></h1>
-<p><tt class="literal"><span class="pre">dot</span></tt> code has a C-ish syntax and it is quite readable even from somebody
-who has not read the manual. For instance, this <tt class="literal"><span class="pre">dot</span></tt> script:</p>
-<blockquote>
-<pre class="literal-block">
-graph hello{
-
-// Comment: Hello World from ``dot``
-// a graph with a single node Node1
-
-Node1 [label=&quot;Hello, World!&quot;]
-
-}
-</pre>
-</blockquote>
-<p>generates the following picture:</p>
-<div class="figure">
-<p><img alt="fig1.png" src="fig1.png" /></p>
-</div>
-<p>Having saved this code in a file called <tt class="literal"><span class="pre">hello.dot</span></tt>, the graph can be
-generated and shown on the screen with a simple one-liner:</p>
-<blockquote>
-<pre class="literal-block">
-$ dot hello.dot -Tps | gv -
-</pre>
-</blockquote>
-<p>The <tt class="literal"><span class="pre">-Tps</span></tt> option generates postscript
-code, which is then piped to the ghostview utility. Notice that
-I am running my examples on a Linux machine with ghostview installed,
-but <tt class="literal"><span class="pre">dot</span></tt> works equally well under Windows, so you may trivially
-adapt the examples.</p>
-<p>If the user is satisfied with the output, it can save it into a file:</p>
-<blockquote>
-<pre class="literal-block">
-$ dot hello.dot -Tps -o hello.ps
-</pre>
-</blockquote>
-<p>Most probably the user may want to tweak with the options,
-for instance adding colors and changing the font size.
-This is not difficult:</p>
-<blockquote>
-<pre class="literal-block">
-graph hello2{
-
-// Hello World with nice colors and big fonts
-
-Node1 [label=&quot;Hello, World!&quot;, color=Blue, fontcolor=Red,
- fontsize=24, shape=box]
-
-}
-</pre>
-</blockquote>
-<p>This draws a blue square with a red label:</p>
-<div class="figure">
-<p><img alt="fig2.png" src="fig2.png" /></p>
-</div>
-<p>All X-Window colors and fonts are available.</p>
-<p><tt class="literal"><span class="pre">dot</span></tt> is quite tolerant: the language is case insensitive and
-quoting the options (color=&quot;Blue&quot;, shape=&quot;box&quot;) will work too.
-Moreover, in order to make happy C fans, semicolons can be used
-to terminate statements and they will simply be ignored.</p>
-</div>
-<div class="section" id="basic-concepts-of-dot">
-<h1><a name="basic-concepts-of-dot">Basic concepts of <tt class="literal"><span class="pre">dot</span></tt></a></h1>
-<p>A generic <tt class="literal"><span class="pre">dot</span></tt> graph is composed by nodes and edges.
-Our <tt class="literal"><span class="pre">hello.dot</span></tt> example contains a single node and no edges.
-Edges enter in the game when there are relationships between nodes,
-for instance hierarchical relationships as in this example:</p>
-<blockquote>
-<pre class="literal-block">
-digraph simple_hierarchy{
-
-B [label=&quot;The boss&quot;] // node B
-E [label=&quot;The employee&quot;] // node E
-
-B-&gt;E [label=&quot;commands&quot;, fontcolor=darkgreen] // edge B-&gt;E
-
-}
-</pre>
-</blockquote>
-<div class="figure">
-<p><img alt="fig3.png" src="fig3.png" /></p>
-</div>
-<p><tt class="literal"><span class="pre">dot</span></tt> is especially good at drawing directed graph such this, where
-there is a natural direction (notice that GraphViz also includes the <tt class="literal"><span class="pre">neato</span></tt>
-tool, which is quite similar to <tt class="literal"><span class="pre">dot</span></tt> and is especially targeted to
-undirected graphs).
-In this example the direction is from the boss, who commands,
-to the employee, who obeys. Of course in <tt class="literal"><span class="pre">dot</span></tt> one has the freedom
-to revert social hierarchies ;):</p>
-<blockquote>
-<pre class="literal-block">
-digraph revolution{
-
-B [label=&quot;The boss&quot;] // node B
-E [label=&quot;The employee&quot;] // node E
-
-B-&gt;E [label=&quot;commands&quot;, dir=back, fontcolor=red]
-// revert arrow direction
-
-}
-</pre>
-</blockquote>
-<div class="figure">
-<p><img alt="fig4.png" src="fig4.png" /></p>
-</div>
-<p>Sometimes, one wants to put on the same level things of the
-same importance; this can be done with the rank option, as
-in the following example, which describes a hierarchy with a boss,
-two employees of the same rank, John and Jack, and a lower
-rank employee Al who depends from John:</p>
-<blockquote>
-<pre class="literal-block">
-digraph hierarchy{
-
-nodesep=1.0 // increases the separation between nodes
-
-node [color=Red,fontname=Courier]
-edge [color=Blue, style=dashed] //setup options
-
-Boss-&gt;{ John Jack} // the boss has two employees
-
-{rank=same; John Jack} //they have the same rank
-
-John -&gt; Al // John has a subordinate
-
-John-&gt;Jack [dir=both] // but still is on the same level as Jack
-}
-</pre>
-</blockquote>
-<div class="figure">
-<p><img alt="fig5.png" src="fig5.png" /></p>
-</div>
-<p>This example shows a nifty feature of <tt class="literal"><span class="pre">dot</span></tt>: if the user forgets
-to give it explicit labels, it will use the name of the nodes as
-default labels. The default colors and style can be set for nodes and
-edges respectively. It is also possible to control the separation
-between (all) nodes by tuning the <tt class="literal"><span class="pre">nodesep</span></tt> option.
-We leave for our readers to see what happens without the rank option
-(hint: you get a very ugly graph).</p>
-<p><tt class="literal"><span class="pre">dot</span></tt> is quite sophisticated and
-there are dozen of options which are deeply discussed in the excellent
-documentation. In particular, the man page (<tt class="literal"><span class="pre">man</span> <span class="pre">dot</span></tt>) is especially
-useful and well done. The documentation also explain how to draw
-graphs containing subgraphs. However those are advanced features which
-are outside the scope of a brief presentation.</p>
-<p>Here we will discuss another feature instead: the ability to generate output
-in different formats.
-Depending on the requirements, different formats can be more or
-less suitable. For the purpose of generating printed documentation,
-the postscript format is quite handy. On the other hand, if the documentation
-has to be converted in html format and put on a Web page, a png
-format can be handy. It is quite trivial to get it:</p>
-<blockquote>
-<pre class="literal-block">
-$ dot hello.dot -Tpng -o hello.png
-</pre>
-</blockquote>
-<p>There are <em>many</em> others available formats, including all the common ones
-such as gif, jpg, wbmp, fig and more exotic ones.</p>
-</div>
-<div class="section" id="generating-dot-code">
-<h1><a name="generating-dot-code">Generating <tt class="literal"><span class="pre">dot</span></tt> code</a></h1>
-<p><tt class="literal"><span class="pre">dot</span></tt> is not a real programming language, nevertheless it is pretty easy
-to interface <tt class="literal"><span class="pre">dot</span></tt> with a real programming language. Bindings for
-many programming languages - including Java, Perl and Python - are already
-available. A more lightweight alternative is just to generate the <tt class="literal"><span class="pre">dot</span></tt> code
-from your preferred language.
-Doing so allows the user to completely automatize the graph generation.
-Here I will give a simple Python example using this technique.</p>
-<p>This example script shows how to draw Python class hierarchies
-with the least effort; it may help you in documenting your code.</p>
-<p>Here is the script:</p>
-<blockquote>
-<pre class="literal-block">
-# dot.py
-
-&quot;Require Python 2.3 (or 2.2. with from __future__ import generators)&quot;
-
-def dotcode(cls):
- setup='node [color=Green,fontcolor=Blue,fontname=Courier]\n'
- name='hierarchy_of_%s' % cls.__name__
- code='\n'.join(codegenerator(cls))
- return &quot;digraph %s{\n\n%s\n%s\n}&quot; % (name, setup, code)
-
-def codegenerator(cls):
- &quot;Returns a line of dot code at each iteration.&quot;
- # works for new style classes; see my Cookbook
- # recipe for a more general solution
- for c in cls.__mro__:
- bases=c.__bases__
- if bases: # generate edges parent -&gt; child
- yield ''.join([' %s -&gt; %s\n' % ( b.__name__,c.__name__)
- for b in bases])
- if len(bases) &gt; 1: # put all parents on the same level
- yield &quot; {rank=same; %s}\n&quot; % ''.join(
- ['%s ' % b.__name__ for b in bases])
-
-if __name__==&quot;__main__&quot;:
- # returns the dot code generating a simple diamond hierarchy
- class A(object): pass
- class B(A): pass
- class C(A): pass
- class D(B,C): pass
- print dotcode(D)
-</pre>
-</blockquote>
-<p>The function <tt class="literal"><span class="pre">dotcode</span></tt> takes a class and returns the <tt class="literal"><span class="pre">dot</span></tt> source
-code needed to plot the genealogical tree of that class.
-The source code is generated by <tt class="literal"><span class="pre">codegenerator</span></tt>, which traverses the list
-of the ancestors of the class (a.k.a. the Method Resolution Order of
-the class) and determines the edges and the nodes of the hierarchy.
-<tt class="literal"><span class="pre">codegenerator</span></tt> is a generator which returns an iterator yielding
-a line of <tt class="literal"><span class="pre">dot</span></tt> code at each iteration. Generators are a cool
-recent addition to Python; they come particularly handy for the purpose
-of generating text or source code.</p>
-<p>The output of the script is the following self-explanatory <tt class="literal"><span class="pre">dot</span></tt> code:</p>
-<blockquote>
-<pre class="literal-block">
-digraph hierarchy_of_D{
-
-node [color=Green,fontcolor=Blue,font=Courier]
-
- B -&gt; D
- C -&gt; D
-
- {rank=same; B C }
-
- A -&gt; B
-
- A -&gt; C
-
- object -&gt; A
-
-}
-</pre>
-</blockquote>
-<p>Now the simple one-liner:</p>
-<blockquote>
-<pre class="literal-block">
-$ python dot.py|dot -Tpng -o x.png
-</pre>
-</blockquote>
-<p>generates the following picture:</p>
-<div class="figure">
-<p><img alt="fig6.png" src="fig6.png" /></p>
-</div>
-</div>
-<div class="section" id="references">
-<h1><a name="references">References</a></h1>
-<p>You may download <tt class="literal"><span class="pre">dot</span></tt> and the others tool coming with GraphViz at the
-official home-page of the project:</p>
-<p><a class="reference" href="http://www.graphviz.org">http://www.graphviz.org</a></p>
-<p>You will also find plenty of documentation and links to the mailing list.</p>
-<p>Perl and Python bindings are available here</p>
-<p><a class="reference" href="http://theoryx5.uwinnipeg.ca/CPAN/data/GraphViz/GraphViz.html">http://theoryx5.uwinnipeg.ca/CPAN/data/GraphViz/GraphViz.html</a></p>
-<p>(Perl bindings, thanks to Leon Brocard)</p>
-<p>and here</p>
-<p><a class="reference" href="http://www.cs.brown.edu/~er/software/">http://www.cs.brown.edu/~er/software/</a></p>
-<p>(Python bindings, thanks to Manos Renieris).</p>
-<p>The script <tt class="literal"><span class="pre">dot.py</span></tt> I presented in this article is rather minimalistic.
-This is on purpose. A much more sophisticated version with additional
-examples is discussed in my Python Cookbook recipe</p>
-<p><a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/213898">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/213898</a></p>
-</div>
-</div>
-<hr class="footer" />
-<div class="footer">
-<a class="reference" href="dot.txt">View document source</a>.
-Generated on: 2004-03-08 08:13 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/europython05/fig.html b/pypers/europython05/fig.html
deleted file mode 100755
index 4138d50..0000000
--- a/pypers/europython05/fig.html
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title></title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-<div class="image"><img alt="python.png" src="python.png" /></div>
-</div>
-</body>
-</html>
diff --git a/pypers/europython05/table.html b/pypers/europython05/table.html
deleted file mode 100755
index d995b09..0000000
--- a/pypers/europython05/table.html
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title>Example table</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="example-table">
-<h1 class="title">Example table</h1>
-<blockquote>
-<table border="1" class="docutils">
-<colgroup>
-<col width="36%" />
-<col width="32%" />
-<col width="32%" />
-</colgroup>
-<tbody valign="top">
-<tr><td>Item</td>
-<td>400 x 3</td>
-<td>1200E</td>
-</tr>
-<tr><td>Tax</td>
-<td>20%</td>
-<td>240E</td>
-</tr>
-<tr><td>Other</td>
-<td>150 x 3</td>
-<td>450E</td>
-</tr>
-<tr><td colspan="2">Special</td>
-<td>60E</td>
-</tr>
-<tr><td colspan="2">Total</td>
-<td>1950E</td>
-</tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-</body>
-</html>
diff --git a/pypers/europython05/taste-python.html b/pypers/europython05/taste-python.html
deleted file mode 100755
index 8df2c65..0000000
--- a/pypers/europython05/taste-python.html
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title>Taste Python (EuroPython 2005)</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="taste-python-europython-2005">
-<h1 class="title">Taste Python (EuroPython 2005)</h1>
-<p>Hi Harald,</p>
-<p>I was looking at your suggestions again:</p>
-<pre class="literal-block">
-&quot;&quot;&quot;
-a) some real &quot;hello world&quot; stuff
-b) tricks and powers of the interactive console
-c) dynamic modules taken from
-- web scraping with python (beautifull soup, urllib..)
-- database access (WITHOUT sqlobject, which is presented seperately)
-- some basic system Administration Stuff
-- do a PDF
-&quot;&quot;&quot;
-</pre>
-<p>I think we should decide how to split this stuff between us and
-also have an idea of the time needed. I could do</p>
-<ol class="arabic simple">
-<li>A superfast toor of IPython (10 minutes)</li>
-<li>reStructuredText, how to make Web pages and PDFs (15 minutes)</li>
-<li>Twill, i.e. how to interact with the Web the easy way (10 minutes)</li>
-</ol>
-<p>The time are indicatives i.e. they could easily become longer (but not
-much shorter, unless we kill something). According to the interests of people
-times and topics could change at run time, but I think its is best if we have
-prepared at least a provisional program. BTW, if you don't know about Twill,
-here is a reference:</p>
-<p><a class="reference" href="http://darcs.idyll.org/~t/projects/twill/README.html">http://darcs.idyll.org/~t/projects/twill/README.html</a></p>
-<p>It is so easy to use that it makes a good candidate even for a
-total beginner course and on the other hand it is useful even to
-the expert Web developer. I am writing a paper on it for O'Reilly,
-so I am already prepared ;)</p>
-<blockquote>
-Michele Simionato</blockquote>
-</div>
-</body>
-</html>
diff --git a/pypers/europython06/talk.html b/pypers/europython06/talk.html
deleted file mode 100644
index 23db191..0000000
--- a/pypers/europython06/talk.html
+++ /dev/null
@@ -1,629 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<meta name="version" content="S5 1.1" />
-<title></title>
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-12-18 01:56:14 +0100 (Sun, 18 Dec 2005) $
-:Revision: $Revision: 4224 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-
-See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
-customize this style sheet.
-*/
-
-/* used to remove borders from tables and images */
-.borderless, table.borderless td, table.borderless th {
- border: 0 }
-
-table.borderless td, table.borderless th {
- /* Override padding for "table.docutils td" with "! important".
- The right padding separates the table cells. */
- padding: 0 0.5em 0 0 ! important }
-
-.first {
- /* Override more specific margin styles with "! important". */
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em ;
- margin-right: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid 1px gray;
- margin-left: 1px }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid 1px black;
- margin-left: 1px }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-<!-- configuration parameters -->
-<meta name="defaultView" content="slideshow" />
-<meta name="controlVis" content="hidden" />
-<!-- style sheet links -->
-<script src="ui/default/slides.js" type="text/javascript"></script>
-<link rel="stylesheet" href="ui/default/slides.css"
- type="text/css" media="projection" id="slideProj" />
-<link rel="stylesheet" href="ui/default/outline.css"
- type="text/css" media="screen" id="outlineStyle" />
-<link rel="stylesheet" href="ui/default/print.css"
- type="text/css" media="print" id="slidePrint" />
-<link rel="stylesheet" href="ui/default/opera.css"
- type="text/css" media="projection" id="operaFix" />
-
-<style type="text/css">
-#currentSlide {display: none;}
-</style>
-</head>
-<body>
-<div class="layout">
-<div id="controls"></div>
-<div id="currentSlide"></div>
-<div id="header">
-
-</div>
-<div id="footer">
-<h2>EuroPython 2006 - 4 July 2006</h2>
-</div>
-</div>
-<div class="presentation">
-<div class="slide" id="slide0">
-
-</div>
-<div class="slide" id="using-decorators">
-<h1>Using decorators</h1>
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">talk given at:</th><td class="field-body">EuroPython 2006</td>
-</tr>
-<tr class="field"><th class="field-name">by:</th><td class="field-body">Michele Simionato</td>
-</tr>
-<tr class="field"><th class="field-name">date:</th><td class="field-body">2006-07-04</td>
-</tr>
-</tbody>
-</table>
-<p>An introduction to Python 2.4 decorators.</p>
-<!-- Definitions of interpreted text roles (classes) for S5/HTML data. -->
-<!-- This data file has been placed in the public domain. -->
-<!-- Colours
-======= -->
-<!-- Text Sizes
-========== -->
-<!-- Display in Slides (Presentation Mode) Only
-========================================== -->
-<!-- Display in Outline Mode Only
-============================ -->
-<!-- Display in Print Only
-===================== -->
-<!-- Incremental Display
-=================== -->
-</div>
-<div class="slide" id="let-s-begin-with-a-poll">
-<h1>Let's begin with a poll ...</h1>
-<ol class="incremental arabic simple">
-<li>how many of you know what decorators are?</li>
-<li>how many of you have used built-in decorators?</li>
-</ol>
-<blockquote class="incremental">
-<pre class="literal-block">
-# example of built-in decorator
-&#64;classmethod
-def makeinstance(cls):
- return cls()
-</pre>
-</blockquote>
-<ol class="incremental arabic simple" start="3">
-<li>how many of you are using custom decorators?</li>
-</ol>
-</div>
-<div class="slide" id="decorators-are-out-there">
-<h1>Decorators are out there</h1>
-<p>There already libraries out there that provide custom decorators.
-I will show two examples of many.</p>
-<ol class="incremental arabic simple">
-<li>cherrypy: exposing methods</li>
-<li>standard library: making templates for the <tt class="docutils literal"><span class="pre">with</span></tt> statement</li>
-</ol>
-</div>
-<div class="slide" id="cherrypy-exposing-web-methods">
-<h1>CherryPy (exposing web methods)</h1>
-<pre class="literal-block">
-import cherrypy as cp
-
-class Root(object):
- &#64;cp.expose
- def index(self):
- return 'This is the index page'
-
-if __name__ == '__main__':
- cp.root = Root()
- cp.server.start()
-</pre>
-</div>
-<div class="slide" id="how-does-it-work">
-<h1>How does it work</h1>
-<pre class="literal-block">
-def expose(func):
- &quot;Expose a function&quot;
- func.exposed = True
- return func
-
- &#64;expose
- def foo(): pass
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; foo.exposed
-True
-</pre>
-</div>
-<div class="slide" id="decorators-as-syntactic-sugar">
-<h1>Decorators as syntactic sugar</h1>
-<p>In other words</p>
-<blockquote>
-<pre class="literal-block">
-&#64;decor
-def foo(): pass
-</pre>
-</blockquote>
-<p>is (essentially) a shortcut for</p>
-<blockquote>
-<pre class="literal-block">
-def foo(): pass
-foo = decor(foo)
-</pre>
-</blockquote>
-</div>
-<div class="slide" id="only-syntactic-sugar">
-<h1>Only syntactic sugar?</h1>
-<p><span class="incremental">all Turing-complete languages are equivalent up to syntactic sugar</span></p>
-<blockquote>
-<span class="incremental">=&gt;</span></blockquote>
-<p><span class="incremental">syntactic sugar is the most important thing ever!!</span></p>
-<blockquote>
-<span class="incremental">;-)</span></blockquote>
-<p><span class="incremental">*Decorators changed the way we think about functions*</span></p>
-</div>
-<div class="slide" id="python-2-5-contextmanager">
-<h1>Python 2.5 contextmanager</h1>
-<pre class="literal-block">
-from __future__ import with_statement
-from contextlib import contextmanager
-&#64;contextmanager
-def cursor(conn):
- curs = conn.cursor()
- try:
- yield curs
- except:
- conn.rollback(); raise
- finally:
- curs.close()
- conn.commit()
-</pre>
-</div>
-<div class="slide" id="python-2-5-transactions">
-<h1>Python 2.5 transactions</h1>
-<pre class="literal-block">
-import psycopg
-from contextlib import closing
-
-with closing(psycopg.connect('')) as conn:
- with cursor(conn) as c:
- c.execute('create table example (name char(3))')
- c.execute(&quot;insert into example values ('foo')&quot;)
- c.execute(&quot;insert into example values ('bar')&quot;)
- c.execute('select * from example')
- print c.fetchall()
-</pre>
-</div>
-<div class="slide" id="writing-your-own-decorators">
-<h1>Writing your own decorators</h1>
-<p>Naive implementation:</p>
-<pre class="literal-block">
-def traced(func):
- def newfunc(*args,**kw):
- print 'Calling %s with arguments %s, %s' % (
- func.__name__, args, kw)
- return func(*args, **kw)
- return newfunc
-
-&#64;traced
-def square(x):
- return x*x
-</pre>
-</div>
-<div class="slide" id="example">
-<h1>Example</h1>
-<pre class="doctest-block">
-&gt;&gt;&gt; square(2)
-Calling square with arguments (2,), {}
-4
-</pre>
-<p>However the naive implementation breaks introspection:</p>
-<pre class="literal-block">
-&gt;&gt;&gt; help(square)
-Help on function newfunction in module __main__:
-
-newfunction(*args, **kw)
-</pre>
-</div>
-<div class="slide" id="a-non-solution">
-<h1>A non-solution</h1>
-<pre class="incremental doctest-block">
-&gt;&gt;&gt; def traced(func):
-... def newfunc(*args,**kw):
-... print 'Calling %s with arguments %s, %s' % (
-... func.__name__, args, kw)
-... return func(*args, **kw)
-... newfunc.__name__ = func.__name__
-... newfunc.__doc__ = func.__doc__
-... newfunc.__module__ = func.__module__
-... newfunc.__dict__ = func.__dict__
-... return newfunc
-</pre>
-<p class="incremental">but the signature is still broken :-(</p>
-</div>
-<div class="slide" id="enter-the-decorator-module">
-<h1>Enter the <em>decorator</em> module</h1>
-<pre class="literal-block">
-from decorator import decorator
-
-&#64;decorator
-def traced(func, *args, **kw):
- print 'Calling %s with arguments %s, %s' % (
- func.__name__, args, kw)
- return func(*args, **kw)
-
-&#64;traced
-def square(x):
- return x*x
-</pre>
-</div>
-<div class="slide" id="look-ma-it-works">
-<h1>Look ma, it works!</h1>
-<pre class="literal-block">
-&gt;&gt;&gt; square(2)
-Calling square with arguments (2,), {}
-4
-&gt;&gt;&gt; help(square)
-Help on function square in module __main__:
-
-square(x)
-
-&gt;&gt;&gt; isinstance(traced, decorator)
-True
-</pre>
-</div>
-<div class="slide" id="nontrivial-decorators">
-<h1>Nontrivial decorators</h1>
-<ul class="incremental">
-<li><p class="first">timing:</p>
-<pre class="literal-block">
-&#64;time
-def mycomputation(): pass
-</pre>
-</li>
-<li><p class="first">logging:</p>
-<pre class="literal-block">
-&#64;log
-def myprocedure(): pass
-</pre>
-</li>
-</ul>
-</div>
-<div class="slide" id="other-applications">
-<h1>Other applications ...</h1>
-<ul>
-<li><p class="first">caching:</p>
-<pre class="literal-block">
-&#64;cached
-def mylongcomputation(): pass
-</pre>
-</li>
-</ul>
-<ul class="incremental">
-<li><p class="first">access control:</p>
-<pre class="literal-block">
-&#64;admin
-def showpage(): pass
-
-&#64;user
-def showpage(): pass
-</pre>
-</li>
-</ul>
-</div>
-<div class="slide" id="id1">
-<h1>Other applications</h1>
-<ul class="simple">
-<li>provide nice syntax in frameworks</li>
-</ul>
-<ul class="incremental">
-<li><p class="first">remove boilerplate in locking, transactions, ...</p>
-</li>
-<li><p class="first">mind boggling exercises:</p>
-<pre class="literal-block">
-&#64;tail_recursive
-def fact(n, acc=1): return fact(n-1, acc*n)
-</pre>
-</li>
-<li><p class="first">etc. etc.</p>
-</li>
-</ul>
-</div>
-<div class="slide" id="caveats">
-<h1>Caveats</h1>
-<ol class="incremental arabic simple">
-<li>you may have performance issues</li>
-<li>your traceback will become longer</li>
-<li>you may end up being too clever :-(</li>
-</ol>
-</div>
-<div class="slide" id="references">
-<h1>References</h1>
-<ul class="simple">
-<li>history of decorators
-<a class="reference" href="http://wiki.python.org/moin/PythonDecorators">http://wiki.python.org/moin/PythonDecorators</a></li>
-<li>the decorators PEP:
-<a class="reference" href="http://www.python.org/dev/peps/pep-0318/">http://www.python.org/dev/peps/pep-0318/</a></li>
-<li><a class="reference" href="http://wiki.python.org/moin/PythonDecoratorLibrary">http://wiki.python.org/moin/PythonDecoratorLibrary</a></li>
-<li>David Mertz's on IBMDeveloperWorks</li>
-<li><a class="reference" href="http://www.phyast.pitt.edu/~micheles/python/documentation.txt">http://www.phyast.pitt.edu/~micheles/python/documentation.txt</a></li>
-</ul>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/europython07/talk.html b/pypers/europython07/talk.html
deleted file mode 100644
index aa9f605..0000000
--- a/pypers/europython07/talk.html
+++ /dev/null
@@ -1,669 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" />
-<meta name="version" content="S5 1.1" />
-<title>An Introduction to Web Programming with WSGI</title>
-<meta name="organization" content="StatPro Italy" />
-<meta name="date" content="2007-07-11" />
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-12-18 01:56:14 +0100 (Sun, 18 Dec 2005) $
-:Revision: $Revision: 4224 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-
-See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
-customize this style sheet.
-*/
-
-/* used to remove borders from tables and images */
-.borderless, table.borderless td, table.borderless th {
- border: 0 }
-
-table.borderless td, table.borderless th {
- /* Override padding for "table.docutils td" with "! important".
- The right padding separates the table cells. */
- padding: 0 0.5em 0 0 ! important }
-
-.first {
- /* Override more specific margin styles with "! important". */
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em ;
- margin-right: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid 1px gray;
- margin-left: 1px }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid 1px black;
- margin-left: 1px }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-<!-- configuration parameters -->
-<meta name="defaultView" content="slideshow" />
-<meta name="controlVis" content="hidden" />
-<!-- style sheet links -->
-<script src="ui/default/slides.js" type="text/javascript"></script>
-<link rel="stylesheet" href="ui/default/slides.css"
- type="text/css" media="projection" id="slideProj" />
-<link rel="stylesheet" href="ui/default/outline.css"
- type="text/css" media="screen" id="outlineStyle" />
-<link rel="stylesheet" href="ui/default/print.css"
- type="text/css" media="print" id="slidePrint" />
-<link rel="stylesheet" href="ui/default/opera.css"
- type="text/css" media="projection" id="operaFix" />
-
-<style type="text/css">
-#currentSlide {display: none;}
-</style>
-</head>
-<body>
-<div class="layout">
-<div id="controls"></div>
-<div id="currentSlide"></div>
-<div id="header">
-
-</div>
-<div id="footer">
-<h1>An Introduction to Web Programming with WSGI</h1>
-<h2>EuroPython 2007 - 11 June 2007</h2>
-</div>
-</div>
-<div class="presentation">
-<div class="slide" id="slide0">
-<h1 class="title">An Introduction to Web Programming with WSGI</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr class="field"><th class="docinfo-name">Talk given at:</th><td class="field-body">EuroPython 2007</td>
-</tr>
-<tr class="field"><th class="docinfo-name">By:</th><td class="field-body">Michele Simionato</td>
-</tr>
-<tr><th class="docinfo-name">Organization:</th>
-<td>StatPro Italy</td></tr>
-<tr><th class="docinfo-name">Date:</th>
-<td>2007-07-11</td></tr>
-</tbody>
-</table>
-<!-- Definitions of interpreted text roles (classes) for S5/HTML data. -->
-<!-- This data file has been placed in the public domain. -->
-<!-- Colours
-======= -->
-<!-- Text Sizes
-========== -->
-<!-- Display in Slides (Presentation Mode) Only
-========================================== -->
-<!-- Display in Outline Mode Only
-============================ -->
-<!-- Display in Print Only
-===================== -->
-<!-- Incremental Display
-=================== -->
-
-</div>
-<div class="slide" id="introduction">
-<h1>Introduction</h1>
-<p>This is as a talk for beginners, only knowledge of
-CGI and a bit of HTTP protocol is expected
-<span class="incremental">(non-beginners -&gt; &quot;Zope on a Paste&quot;)</span></p>
-<ul class="incremental simple">
-<li>Have you ever heard of WSGI?</li>
-<li>Have you ever used WSGI?</li>
-<li>Have you used non WSGI-based Web frameworks?</li>
-</ul>
-</div>
-<div class="slide" id="ok-now-about-me">
-<h1>Ok, now about me</h1>
-<ul class="incremental simple">
-<li>I started to do Web programming with Zope and Plone</li>
-<li>(never liked them)</li>
-<li>I flirted with Quixote, Twisted, CherryPy, mod_python</li>
-<li>(which are ok but ...)</li>
-<li>I got in love with WSGI at last EuroPython</li>
-<li>(I am still in love with it ;)</li>
-</ul>
-</div>
-<div class="slide" id="what-i-have-done">
-<h1>What I have done</h1>
-<ul class="incremental simple">
-<li>written various helpers to simplify the usage of WSGI;</li>
-<li>debug with WSGI, deploy with Zope strategy</li>
-<li>written various simple Web tools for internal usage at <a class="reference" href="http://www.statpro.com">StatPro</a></li>
-<li>now we are going to start a major project with WSGI</li>
-</ul>
-</div>
-<div class="slide" id="wsgi">
-<h1>WSGI</h1>
-<img alt="Scotch_Whisky_(aka).png" src="Scotch_Whisky_(aka).png" />
-</div>
-<div class="slide" id="short-history-of-wsgi">
-<h1><em>Short</em> history of WSGI</h1>
-<ul class="incremental simple">
-<li>WSGI = Web Server Gateway Interface (<em>Whisky</em> for friends)</li>
-<li>the brainchild of Python guru Phillip J. Eby</li>
-<li>also input from Ian Bicking (<tt class="docutils literal"><span class="pre">paste</span></tt>) and others</li>
-<li>starting from Python 2.5, we have a WSGI web server in the standard
-library (<tt class="docutils literal"><span class="pre">wsgiref</span></tt>)</li>
-<li>there are plenty of simple and useful add-ons for WSGI applications
-out there (<tt class="docutils literal"><span class="pre">pylons</span> <span class="pre">...</span></tt>)</li>
-<li><a class="reference" href="http://video.google.com/videoplay?docid=-8502904076440714866">Guido</a> likes it!</li>
-</ul>
-</div>
-<div class="slide" id="wsgi-key-concepts">
-<h1>WSGI key concepts</h1>
-<ol class="incremental arabic">
-<li><p class="first">WSGI application:</p>
-<p>(env, resp) -&gt; chunks of text</p>
-<p>env = environment dictionary of the server;
-resp = function sending to the client the HTTP headers</p>
-</li>
-<li><p class="first">WSGI middleware:</p>
-<p>WSGI app -&gt; enhanced WSGI app</p>
-</li>
-</ol>
-</div>
-<div class="slide" id="hello-world">
-<h1>Hello World</h1>
-<pre class="literal-block">
-from wsgiref import simple_server
-
-def app(env, resp):
- resp(
- '200 OK', [('Content-type', 'text/html')])
- return ['&lt;h1&gt;Hello, World!&lt;/h1&gt;']
-
-server=simple_server.make_server('', 8000, app)
-server.serve_forever()
-</pre>
-</div>
-<div class="slide" id="a-real-life-example">
-<h1>A real-life example</h1>
-<p class="incremental">Let me show a real problem we had at <a class="reference" href="http://www.statpro.com">StatPro</a></p>
-<img alt="badpricehistory.png" class="incremental" src="badpricehistory.png" />
-</div>
-<div class="slide" id="the-history-plotter">
-<h1>The history plotter</h1>
-<p>It was easy to write a simple command line history plotter</p>
-<ul class="incremental simple">
-<li>show live example</li>
-<li>but we were not happy with it</li>
-<li>because of installation issues, etc</li>
-<li>so we wanted to go on the Web</li>
-</ul>
-</div>
-<div class="slide" id="going-on-the-web">
-<h1>Going on the Web</h1>
-<ul class="incremental simple">
-<li>tool for internal usage on our intranet</li>
-<li>convenient to integrate with other Web tools</li>
-<li>usable also for non-techical users</li>
-<li>avoid installing and mantaining on every machine</li>
-<li>possibly we may open it to our other offices in the world</li>
-<li>we like the browser interface</li>
-</ul>
-</div>
-<div class="slide" id="without-a-framework">
-<h1>Without a framework</h1>
-<ul class="incremental simple">
-<li>KISS</li>
-<li>no security concerns</li>
-<li>no scalability concerns</li>
-<li>no nice-looking concerns</li>
-<li>it must be <em>EASY</em> to change</li>
-<li>we want minimal learning curve</li>
-<li>we want no installation/configuration hassle</li>
-<li>we want no dependencies</li>
-<li>we want something even simpler than CGI, if possible!</li>
-</ul>
-</div>
-<div class="slide" id="wsgi-is-the-answer">
-<h1>WSGI is the answer!</h1>
-<p>The web plotter</p>
-<pre class="literal-block">
-$ python webplotter.py
-</pre>
-<p><a class="reference" href="http://localhost:8000">Click here for the live demonstration</a></p>
-</div>
-<div class="slide" id="some-code-i">
-<h1>Some code (I)</h1>
-<pre class="literal-block">
-def app(env, resp):
- form = getformdict(env)
- if form.get('submitted'):
- try:
- fname = make_graph(form.get('code'), batch=True)
- except Exception, e:
- resp('500 ERR', [('Content-type', 'text/plain')])
- return [traceback.format_exc()]
- else:
- resp('200 OK', [('Content-type', 'image/png')])
- return file(fname)
-</pre>
-</div>
-<div class="slide" id="some-code-ii">
-<h1>Some code (II)</h1>
-<pre class="literal-block">
-else:
- resp('200 OK', [('Content-type', 'text/html')])
- return [
- 'Try values such as &lt;pre&gt;fri-gb;AVE&lt;/pre&gt;',
- '&lt;pre&gt;fri-gb;TSCO&lt;/pre&gt; &lt;pre&gt;fri-us;DELL&lt;/pre&gt;',
- '&lt;form&gt;', 'insert code ',
- '&lt;input type=&quot;text&quot; name=&quot;code&quot;/&gt;',
- '&lt;input type=&quot;submit&quot;, name=&quot;submitted&quot;,'
- ' value=&quot;submit&quot; /&gt;',
- '&lt;/form&gt;']
-</pre>
-</div>
-<div class="slide" id="some-code-iii">
-<h1>Some code (III)</h1>
-<pre class="literal-block">
-def getformdict(env):
- qs = env.get('QUERY_STRING')
- if qs:
- return dict((k, v[0])
- for k, v in cgi.parse_qsl(qs))
- else:
- return {}
-</pre>
-</div>
-<div class="slide" id="wsgi-vs-cgi">
-<h1>WSGI vs. CGI</h1>
-<ul class="incremental simple">
-<li>WSGI is simpler than CGI<ul>
-<li><span class="incremental">using wsgiref you don't require an external server</span></li>
-<li><span class="incremental">you can keep sessions in memory</span></li>
-</ul>
-</li>
-<li>WSGI scales better than CGI<ul>
-<li><span class="incremental">there is a large choice of wsgi servers (mod_wsgi, Twisted ...)</span></li>
-<li><span class="incremental">there is a large choice of third party middleware</span></li>
-<li><span class="incremental">it is relatively easy to turn a toy application into a serious one</span></li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="slide" id="the-missing-link">
-<h1>The missing link</h1>
-<p>WSGI is a the missing link between the low-level mechanics of
-the Web and the high-level intricacies of the Web frameworks.</p>
-<img alt="Australopithecus.jpg" src="Australopithecus.jpg" />
-</div>
-<div class="slide" id="a-common-objection">
-<h1>A common objection</h1>
-<ul class="incremental simple">
-<li>Python has too many Web frameworks because it is too easy to build
-a Web framework in Python</li>
-<li>WSGI makes building a Web framework even easier, the number of framework
-will increase</li>
-<li>=&gt; WSGI fails its goal!</li>
-<li><strong>NOT TRUE</strong></li>
-<li><em>integration</em> is the key word</li>
-</ul>
-</div>
-<div class="slide" id="object-publishing-i">
-<h1>Object publishing (I)</h1>
-<pre class="literal-block">
-class Example(object):
- def __init__(self, sitename):
- self.sitename = sitename
- def __call__(self):
- yield '&lt;h1&gt;%s: index page&lt;/h1&gt;' % self.sitename
- yield 'goto &lt;a href=&quot;./page1&quot;&gt;page1&lt;/a&gt;&lt;br/&gt;'
- yield 'goto &lt;a href=&quot;./page2&quot;&gt;page2&lt;/a&gt;&lt;br/&gt;'
- yield 'goto &lt;a href=&quot;subsite&quot;&gt;subsite&lt;/a&gt;&lt;br/&gt;'
- def page1(self): yield 'page1'
- def page2(self): yield 'page2'
- page1.exposed = page2.exposed = True
-</pre>
-</div>
-<div class="slide" id="object-publishing-ii">
-<h1>Object publishing (II)</h1>
-<pre class="literal-block">
-class WSGIObjectPublisher(object):
- def __init__(self, root):
- self.root = root
- def __call__(self, env, resp):
- return self.getsubpage(self.root,env,resp)()
- def getsubpage(self, root, env, resp):
- script_name = util.shift_path_info(env)
- if not script_name: # We've arrived!
- resp('200 OK',[('content-type','text/html')])
- return root
- ...
-</pre>
-</div>
-<div class="slide" id="object-publishing-iii">
-<h1>Object publishing (III)</h1>
-<pre class="literal-block">
-try:
- page = getattr(root, script_name)
-except AttributeError:
- resp('404 Not Found',[('content-type','text/plain')])
- return lambda:['missing page %r'%script_name]
-exposed = getattr(page, 'exposed', False)
-if not exposed:
- resp('404 Not Found',[('content-type','text/plain')])
- return lambda : [
- '%r is not exposed!' % script_name]
-return self.getsubpage(page, env, resp)
-</pre>
-</div>
-<div class="slide" id="wsgi-vs-frameworks">
-<h1>WSGI vs. frameworks</h1>
-<p>Pro:</p>
-<ul class="simple">
-<li><span class="incremental">if you liked playing with Lego, you will be happy</span></li>
-<li><span class="incremental">you have much more control and you are not forced to marry a technology</span></li>
-<li><span class="incremental">you can learn a lot</span></li>
-<li><span class="incremental">others ...</span></li>
-</ul>
-</div>
-<div class="slide" id="id2">
-<h1>WSGI vs. frameworks</h1>
-<p>Contra:</p>
-<ul class="simple">
-<li><span class="incremental">you can build your own framework with WSGI, but you have to debug it</span></li>
-<li><span class="incremental">the existing WSGI frameworks are newer, there is less experience with them</span></li>
-<li><span class="incremental">WSGI is not particularly Twisted-friendly</span></li>
-<li><span class="incremental">others ...</span></li>
-</ul>
-</div>
-<div class="slide" id="and-now-middleware">
-<h1>And now middleware</h1>
-<p>No middleware in the standard library, but lots of useful middleware
-from third party sources. For instance, authentication middleware:</p>
-<pre class="literal-block">
-from paste.auth.basic import AuthBasicHandler
-
-def only_for_pippo(env, user, passwd):
- return user == 'pippo'
-
-auth_app = AuthBasicHandler(
- app, 'app realm', only_for_pippo)
-</pre>
-</div>
-<div class="slide" id="debugging-wsgi-apps">
-<h1>Debugging WSGI apps</h1>
-<pre class="literal-block">
-from wsgiref.simple_server import make_server
-from paste.evalexception import EvalException
-
-a, b = 1,0
-
-def app(env, resp):
- resp('200 OK',[('Content-type','text/html')])
- return [str(a/b)]
-
-make_server('',9090,EvalException(app)
- ).serve_forever()
-</pre>
-<p>Show <a class="reference" href="http://localhost:9090">evalexception</a></p>
-</div>
-<div class="slide" id="references">
-<h1>References</h1>
-<p>That's all, folks!</p>
-<ul class="simple">
-<li><a class="reference" href="http://wsgi.org/wsgi">http://wsgi.org/wsgi</a></li>
-<li><a class="reference" href="http://www.python.org/dev/peps/pep-0333">http://www.python.org/dev/peps/pep-0333</a></li>
-<li><a class="reference" href="http://pythonpaste.org/do-it-yourself-framework.html">http://pythonpaste.org/do-it-yourself-framework.html</a></li>
-<li><a class="reference" href="http://pylonshq.com/">http://pylonshq.com/</a></li>
-</ul>
-<p class="incremental"><strong>(P.S. at StatPro, we are hiring! ;)</strong></p>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/europython07/ui/default/ex.html b/pypers/europython07/ui/default/ex.html
deleted file mode 100644
index 798e3cc..0000000
--- a/pypers/europython07/ui/default/ex.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<html>
-<head>
-<style type="text/css">
-body
-{
-background: url(statpro_logo.gif) no-repeat top
-}
-</style>
-</head>
-<body>
-Prova Background CSS
-</body>
-</html>
diff --git a/pypers/marelli/frontpage.html b/pypers/marelli/frontpage.html
deleted file mode 100755
index 2886d8d..0000000
--- a/pypers/marelli/frontpage.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<html>
-<head>
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-</head>
-<body bgcolor="lightblue">
-<center>
-<h1>Corso di Python Avanzato</h1>
-Michele Simionato<br/><br/>
-michele.simionato@gmail.com<br/><br/>
-Corso tenuto alla Magneti Marelli<br/><br/>
-Bologna, 19-23 Settembre 2005
-</center>
-</body>
-</html>
diff --git a/pypers/marelli/materiale/corso.html b/pypers/marelli/materiale/corso.html
deleted file mode 100755
index 8a0de82..0000000
--- a/pypers/marelli/materiale/corso.html
+++ /dev/null
@@ -1,1850 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title>Corso Python Magneti Marelli</title>
-</head>
-<body>
-<div class="document" id="corso-python-magneti-marelli">
-<h1 class="title">Corso Python Magneti Marelli</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr class="field"><th class="docinfo-name">Tenuto:</th><td class="field-body">19-23 Settembre 2005</td>
-</tr>
-<tr class="field"><th class="docinfo-name">Autore:</th><td class="field-body">Michele Simionato</td>
-</tr>
-<tr class="field"><th class="docinfo-name">E-mail:</th><td class="field-body"><a class="reference" href="mailto:michele.simionato&#64;gmail.com">michele.simionato&#64;gmail.com</a></td>
-</tr>
-</tbody>
-</table>
-<p><em>Queste dispense sono un compendio informale e molto sintetico di quanto
-svolto durante il corso. Esse non si pongono in nessun modo come un testo
-sistematico di programmazione in Python. Il loro scopo principale è quello
-di tenere traccia, per quanto possibile, di quanto si è detto. Lo
-scopo secondario è quello di invogliare i partecipanti e tutti
-gli eventuali lettori ad affrontare gli argomenti qui trattati per forza
-di cose in maniera abbozzata, in maniera più sistematica andando a
-consultare le fonti più adatte alla bisogna, siano essi libri di testo,
-la documentazione ufficiale, newsgroups, siti Web dedicati e, in ultima
-instanza, il codice sorgente stesso, l'unico riferimento definitivo.</em></p>
-<div class="contents topic" id="contents">
-<p class="topic-title first"><a name="contents">Indice</a></p>
-<ul class="simple">
-<li><a class="reference" href="#i-messaggi-fondamentali-del-corso" id="id1" name="id1">I messaggi fondamentali del corso</a><ul>
-<li><a class="reference" href="#studiare-paga" id="id2" name="id2"><em>Studiare paga</em></a></li>
-<li><a class="reference" href="#disaccoppiamento-e-kiss" id="id3" name="id3"><em>Disaccoppiamento</em> e <em>KISS</em></a></li>
-<li><a class="reference" href="#non-nascondete-gli-errori-sotto-il-tappeto" id="id4" name="id4"><em>Non nascondete gli errori sotto il tappeto</em></a></li>
-</ul>
-</li>
-<li><a class="reference" href="#modulo-1-strumenti-di-introspezione-sviluppo-e-debugging" id="id5" name="id5">Modulo 1: Strumenti di introspezione, sviluppo e debugging</a><ul>
-<li><a class="reference" href="#strumenti-di-introspezione-e-come-ottenere-aiuto" id="id6" name="id6">Strumenti di introspezione e come ottenere aiuto</a></li>
-<li><a class="reference" href="#ambienti-di-sviluppo" id="id7" name="id7">Ambienti di sviluppo</a></li>
-<li><a class="reference" href="#strumenti-di-debugging" id="id8" name="id8">Strumenti di debugging</a></li>
-<li><a class="reference" href="#strumenti-utili-per-l-utenza-scientifica-ingegneristica" id="id9" name="id9">Strumenti utili per l'utenza scientifica/ingegneristica</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#modulo-2-programmazione-di-base-in-python" id="id10" name="id10">Modulo 2: Programmazione di base in Python</a><ul>
-<li><a class="reference" href="#encoding" id="id11" name="id11">Encoding</a></li>
-<li><a class="reference" href="#pathnames" id="id12" name="id12">Pathnames</a></li>
-<li><a class="reference" href="#insiemi" id="id13" name="id13">Insiemi</a></li>
-<li><a class="reference" href="#differenza-tra-mutabili-e-immutabili" id="id14" name="id14">Differenza tra mutabili e immutabili</a></li>
-<li><a class="reference" href="#getattr-e-setattr" id="id15" name="id15">getattr e setattr</a></li>
-<li><a class="reference" href="#gestione-dei-processi" id="id16" name="id16">Gestione dei processi</a></li>
-<li><a class="reference" href="#iteratori-e-generatori" id="id17" name="id17">Iteratori e generatori</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#modulo-3-tipici-errori-di-programmazione-e-gestione-delle-eccezioni" id="id18" name="id18">Modulo 3. Tipici errori di programmazione e gestione delle eccezioni</a><ul>
-<li><a class="reference" href="#l-errore-pi-tipico-con-le-eccezioni" id="id19" name="id19">L'errore più tipico con le eccezioni</a></li>
-<li><a class="reference" href="#il-try-finally-una-grande-idea" id="id20" name="id20">Il try .. finally è una grande idea</a></li>
-<li><a class="reference" href="#uso-di-assert" id="id21" name="id21">Uso di assert</a></li>
-<li><a class="reference" href="#non-usate-exec" id="id22" name="id22">Non usate exec</a></li>
-<li><a class="reference" href="#come-far-partire-pdb-automaticamente-in-caso-di-eccezioni-inaspettate" id="id23" name="id23">Come far partire pdb automaticamente in caso di eccezioni inaspettate</a></li>
-<li><a class="reference" href="#eccezioni-e-threads" id="id24" name="id24">Eccezioni e threads</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#modulo-4-sviluppo-orientato-ai-test" id="id25" name="id25">Modulo 4. Sviluppo orientato ai test</a><ul>
-<li><a class="reference" href="#consigli-di-carattere-generale" id="id26" name="id26">Consigli di carattere generale</a></li>
-<li><a class="reference" href="#usare-unittest" id="id27" name="id27">Usare unittest</a></li>
-<li><a class="reference" href="#usare-doctest" id="id28" name="id28">Usare doctest</a></li>
-<li><a class="reference" href="#un-esempio-di-programma-sviluppato-in-maniera-incrementale" id="id29" name="id29">Un esempio di programma sviluppato in maniera incrementale</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#modulo-5-design-documentazione-e-manutenzione-di-librarie" id="id30" name="id30">Modulo 5: Design, documentazione e manutenzione di librarie</a><ul>
-<li><a class="reference" href="#la-filosofia-del-python" id="id31" name="id31">La filosofia del Python</a></li>
-<li><a class="reference" href="#principio-del-disaccoppiamento" id="id32" name="id32">Principio del disaccoppiamento</a></li>
-<li><a class="reference" href="#principio-del-kiss" id="id33" name="id33">Principio del KISS</a></li>
-<li><a class="reference" href="#importanza-di-avere-un-prototipo" id="id34" name="id34">Importanza di avere un prototipo</a></li>
-<li><a class="reference" href="#moduli-e-packages" id="id35" name="id35">Moduli e packages</a></li>
-<li><a class="reference" href="#come-si-documenta-una-libreria-python" id="id36" name="id36">Come si documenta una libreria Python</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#modulo-6-domande-estemporanee" id="id37" name="id37">Modulo 6: Domande estemporanee</a><ul>
-<li><a class="reference" href="#come-funziona-import" id="id38" name="id38">Come funziona 'import'</a></li>
-<li><a class="reference" href="#come-funziona-del" id="id39" name="id39">Come funziona '__del__'</a></li>
-<li><a class="reference" href="#che-differenza-c-fra-variabili-di-classe-e-di-istanza" id="id40" name="id40">Che differenza c'è fra variabili di classe e di istanza</a></li>
-<li><a class="reference" href="#che-cosa-sono-i-metodi-che-iniziano-con" id="id41" name="id41">Che cosa sono i metodi che iniziano con &quot;__&quot;</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#soluzioni-al-questionario-di-ammissione" id="id42" name="id42">Soluzioni al questionario di ammissione</a><ul>
-<li><a class="reference" href="#scrivere-un-programma-che-testa-se-una-stringa-rappresenta-un-numero" id="id43" name="id43">Scrivere un programma che testa se una stringa rappresenta un numero</a></li>
-<li><a class="reference" href="#scrivere-un-programma-che-lista-tutti-i-files-nella-directory-corrente" id="id44" name="id44">Scrivere un programma che lista tutti i files nella directory corrente</a></li>
-<li><a class="reference" href="#listare-tutti-i-files-nelle-sottodirectories-ricorsivamente" id="id45" name="id45">Listare tutti i files nelle sottodirectories ricorsivamente</a></li>
-<li><a class="reference" href="#calcolare-lo-spazio-occupato-da-tutti-i-files-di-tipo-txt-in-una-directory" id="id46" name="id46">Calcolare lo spazio occupato da tutti i files di tipo .txt in una directory</a></li>
-<li><a class="reference" href="#listare-i-files-a-seconda-delle-dimensioni" id="id47" name="id47">Listare i files a seconda delle dimensioni</a></li>
-<li><a class="reference" href="#scrivere-un-test-per-verificate-che-una-directory-sia-vuota" id="id48" name="id48">Scrivere un test per verificate che una directory sia vuota</a></li>
-<li><a class="reference" href="#aprire-una-finestrella-contenente-la-scritta-hello-world" id="id49" name="id49">Aprire una finestrella contenente la scritta &quot;hello, world!&quot;</a></li>
-<li><a class="reference" href="#scaricare-la-pagina-web-http-www-example-com-da-internet" id="id50" name="id50">Scaricare la pagina Web http://www.example.com da Internet</a></li>
-<li><a class="reference" href="#stampare-a-schermo-una-tavola-delle-moltiplicazioni" id="id51" name="id51">Stampare a schermo una tavola delle moltiplicazioni</a></li>
-<li><a class="reference" href="#trovare-tutte-le-immagini-jpg-nel-vostro-hard-disk-e-mostrarle-a-schermo-in-formato-ridotto" id="id52" name="id52">Trovare tutte le immagini .jpg nel vostro hard disk e mostrarle a schermo in formato ridotto</a></li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="section" id="i-messaggi-fondamentali-del-corso">
-<h1><a class="toc-backref" href="#id1" name="i-messaggi-fondamentali-del-corso">I messaggi fondamentali del corso</a></h1>
-<div class="section" id="studiare-paga">
-<h2><a class="toc-backref" href="#id2" name="studiare-paga"><em>Studiare paga</em></a></h2>
-<p>Grazie alla sua macchina del tempo, Guido ha risolto i problemi
-che vi stanno affliggendo ora dieci anni fa, e sono già nel linguaggio
-e nella libreria standard. Per esempìo avete scoperto di avere a
-disposizione:</p>
-<ul class="simple">
-<li>le stringhe di documentazione per darvi la documentazione automatica
-del codice tramite strumenti quali pydoc ed altri;</li>
-<li>il try ... finally per garantirvi un &quot;gracefull exit&quot; del vostro
-programma, anche in presenza di eccezioni inaspettate;</li>
-<li>i metodi setUp e tearDown di unittest.TestCase, che vi permettono
-di inizializzare e di pulire propriamente l'ambiente per ogni test;</li>
-<li>sia unittest che doctest vi permetto di gestire le eccezioni (nel
-senso di gestire le eccezioni &quot;buone&quot;, quelle che vi aspettate);</li>
-<li>call e Popen in subprocess per aprire processi, kill per ucciderli
-(usando win32api.TerminateProcess);</li>
-<li>twisted vi gestisce la comunicazione tra processi e tutte le eccezioni
-senza problemi</li>
-</ul>
-<p>Una settimana di studio oggi può risparmiarvi mesi di frustrazioni
-domani. Sfruttare le risorse disponibili, quali tutorial, howto,
-libri, documentazione, siti Web (come il Python cookbook) e soprattutto
-i newsgroups. Ma prima di postare su di un newsgroup leggetevi &quot;How to
-ask smart questions&quot; e ricordatevi sempre che &quot;Google is you friend&quot;.</p>
-</div>
-<div class="section" id="disaccoppiamento-e-kiss">
-<h2><a class="toc-backref" href="#id3" name="disaccoppiamento-e-kiss"><em>Disaccoppiamento</em> e <em>KISS</em></a></h2>
-<p>Se potere, scomponete l'applicazione in componenti separati e testateli
-separatamente. Scegliete architetture che vi permettono di disaccoppiare
-i problemi. Se potere fare le cose semplici, fatele semplici.
-Abbiate un core minimale che faccia poco, ma che siate sicuri che
-funzioni. Non complicatevi la vita.</p>
-</div>
-<div class="section" id="non-nascondete-gli-errori-sotto-il-tappeto">
-<h2><a class="toc-backref" href="#id4" name="non-nascondete-gli-errori-sotto-il-tappeto"><em>Non nascondete gli errori sotto il tappeto</em></a></h2>
-<p>Non trappate l'inaspettato, è una ricetta sicura per avere rogne.
-Usate lo <em>sviluppo incrementale</em>, cioè verificate il funzionamento del
-programma SUBITO, e fissate l'errore SUBITO. Non debuggate mai
-a posteriori, se potete evitarlo, ma scrivete codice testato fin da subito.
-Abbiate una bella suite di test automatici di installazione, per accorgervi
-da subito se c'è un problema quando installate il software su di un'altra
-macchina.</p>
-</div>
-</div>
-<div class="section" id="modulo-1-strumenti-di-introspezione-sviluppo-e-debugging">
-<h1><a class="toc-backref" href="#id5" name="modulo-1-strumenti-di-introspezione-sviluppo-e-debugging">Modulo 1: Strumenti di introspezione, sviluppo e debugging</a></h1>
-<p><em>In questo modulo discuterò gli strumenti da me utilizzati per sviluppare
-in Python sotto Windows. Parlerò di Cygwin come ambiente di lavoro,
-di Python e di IPython come interpreti interattivi, di Idle e di PythonWin
-come IDE, di pydoc e minidoc come tools di introspezione. Inoltre discuterò
-alcune utili librerie e frameworks per Python (Numeric, matplotlib, gnuplot,
-etc.).</em></p>
-<div class="section" id="strumenti-di-introspezione-e-come-ottenere-aiuto">
-<h2><a class="toc-backref" href="#id6" name="strumenti-di-introspezione-e-come-ottenere-aiuto">Strumenti di introspezione e come ottenere aiuto</a></h2>
-<ul class="simple">
-<li><strong>Help in linea:</strong>
-Ottimo</li>
-<li><strong>Pydoc:</strong>
-Standard, può essere usato dalla riga di comando.
-<tt class="docutils literal"><span class="pre">pydoc</span> <span class="pre">-g</span></tt> oppure <tt class="docutils literal"><span class="pre">python</span> <span class="pre">-mpydoc</span> <span class="pre">-g</span></tt>
-vi dà la versione grafica, con funzionalità di search.</li>
-<li><strong>Help di ActiveState:</strong>
-Eccezionale, contiene anche libri di testo, FAQs e how-tos.</li>
-<li><strong>Google:</strong>
-Di tutto, di più.</li>
-<li><strong>Newsgroups:</strong>
-Risolvono i vostri problemi per voi, e gratis.</li>
-</ul>
-</div>
-<div class="section" id="ambienti-di-sviluppo">
-<h2><a class="toc-backref" href="#id7" name="ambienti-di-sviluppo">Ambienti di sviluppo</a></h2>
-<ul class="simple">
-<li><strong>Cygwin:</strong>
-Emulatore Unix sotto Windows. Vi permette di lavorare dalla riga di
-comando comodamente. Evitate di perdere tempo a cliccare a destra e
-a manca e avete una stabilità maggiore di quella di un ambiente
-grafico.</li>
-<li><strong>Idle:</strong>
-Ambiente di sviluppo per Python che viene con la distribuzione standard.
-Un pò povero, con qualche difetto, ma semplice e portabile ovunque.</li>
-<li><strong>PythonWin:</strong>
-Ambiente di sviluppo per Python che viene con la distribuzione ActiveState
-per Windows. Più sofisticato di Idle e più integrato con Windows. Ha dei
-pro e dei contro.</li>
-<li><strong>WingIDE, Eric/Qt Designer, Komodo, Boa Constructor:</strong>
-Ambienti di sviluppo di cui esiste una versione commerciale. In generale
-hanno un look più professionale e sono utili se uno deve dare interfacce
-grafiche. WingIDE ha il debugger migliore, a quanto ho sentito.</li>
-<li><strong>Emacs o Vi:</strong>
-Un Real Programmer (TM) vi dirà che al mondo esistono due soli editor:
-Emacs e Vi. Tutto il resto è spazzatura. Emacs e Vi girano bene sotto
-Windows, ma funzionano al meglio sotto Unix.</li>
-</ul>
-</div>
-<div class="section" id="strumenti-di-debugging">
-<h2><a class="toc-backref" href="#id8" name="strumenti-di-debugging">Strumenti di debugging</a></h2>
-<ul class="simple">
-<li><strong>print:</strong> è la soluzione usata dai migliori programmatori Python;</li>
-<li><strong>pdb:</strong> sembra il debugger dei poveri, ma è standard e funziona;</li>
-<li><strong>mille altri debuggers</strong>, compreso un nuovissimo winpdb dall'autore
-del pdb, da valutare;</li>
-<li><strong>programmazione test-driven:</strong> con questa metodologia la stragrande
-maggioranza dei bugs vengono individuati subito, non appena il
-codice viene scritto, e vi troverete ad usare il debuggere dieci
-volte di meno di quanto fate ora.</li>
-</ul>
-</div>
-<div class="section" id="strumenti-utili-per-l-utenza-scientifica-ingegneristica">
-<h2><a class="toc-backref" href="#id9" name="strumenti-utili-per-l-utenza-scientifica-ingegneristica">Strumenti utili per l'utenza scientifica/ingegneristica</a></h2>
-<ul class="simple">
-<li><strong>Numeric e/o Numarray:</strong>
-Tutto quello che serve per far conti con le matrici. Numarray è il
-successore di Numeric, con compatibilità al 99%.</li>
-<li><strong>matplotlib:</strong>
-Il meglio per plottare grafici 2D. Richiede Numeric/Numarray.</li>
-<li><strong>ipython:</strong>
-Il miglior interprete interattivo per Python. Eccezionali capacità
-di introspezione e di debugging (è integrato con il Python debugger
-pdb della libreria standard).</li>
-</ul>
-</div>
-</div>
-<div class="section" id="modulo-2-programmazione-di-base-in-python">
-<h1><a class="toc-backref" href="#id10" name="modulo-2-programmazione-di-base-in-python">Modulo 2: Programmazione di base in Python</a></h1>
-<p><em>In questo modulo si ripasseranno molto brevemente le basi di Python e
-si discuteranno le soluzioni al questionario di ammissione. Lo scopo
-più che altro è quello di conoscersi e di chiarire il livello medio
-dei partecipanti e coprire eventuali buchi nella preparazione di base.</em></p>
-<p>Le soluzioni agli esercizi sono riportate nell'ultimo capitolo. Durante le
-correzioni mi sono accordi di vari buchi nella programmazione
-di base in Python che si è cercato di riempire.</p>
-<div class="section" id="encoding">
-<h2><a class="toc-backref" href="#id11" name="encoding">Encoding</a></h2>
-<p>[Illustrato al corso 1] In versioni recenti di Python (dalla 2.3)
-se il vostro script contiene dei caratteri accentati (anche nei commenti)
-ottenete un warning tipo questo:</p>
-<pre class="literal-block">
-sys:1: DeprecationWarning: Non-ASCII character '\xe0' in file x.py
-on line 1, but no encoding declared; see
-http://www.python.org/peps/pep-0263.html for details
-</pre>
-<p>La soluzione e' aggiungere in testa al vostro programma una dichiarazione
-tipo questa:</p>
-<pre class="literal-block">
-#-*- encoding: latin-1 -*-
-</pre>
-<p>(usate latin-15 se il vostro programma contiene il simbolo dell'Euro).</p>
-</div>
-<div class="section" id="pathnames">
-<h2><a class="toc-backref" href="#id12" name="pathnames">Pathnames</a></h2>
-<p>Sfortunatamente Windows usa la backslash come separatore dei pathnames;
-la backslash e' anche il carattere di escaping, quindi ci sono
-problemi:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print 'documenti\nonna' # \n interpretato come newline
-documenti
-onna
-</pre>
-<p>La soluzione e' usare raw strings:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print r'documenti\nonna'
-documenti\nonna
-</pre>
-<p>Alternativamente, in versioni recenti di Windows, avreste potuto usare
-anche &quot;/&quot; come separatore:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import os
-&gt;&gt;&gt; os.path.exists(r'C:\Python24\python.exe')
-True
-&gt;&gt;&gt; os.path.exists(r'C:/Python24/python.exe')
-True
-</pre>
-</div>
-<div class="section" id="insiemi">
-<h2><a class="toc-backref" href="#id13" name="insiemi">Insiemi</a></h2>
-<p>In Python 2.3 gli insiemi sono stati aggiunti come un nuovo tipo di dati
-nel modulo sets (by Alex Martelli); in Python 2.4 gli insiemi sono diventati
-un tipo builtin.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; s = set('pippo')
-&gt;&gt;&gt; s
-set(['i', 'p', 'o'])
-&gt;&gt;&gt; 'i' in s
-True
-&gt;&gt;&gt; 'p' in s
-True
-&gt;&gt;&gt; 'o' in s
-True
-&gt;&gt;&gt; 'z' in s
-False
-</pre>
-<p>E' possibile calcolare l'unione e l'intersezione di insiemi:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; t = set('aglio')
-&gt;&gt;&gt; s | t
-set(['a', 'g', 'i', 'l', 'o', 'p'])
-&gt;&gt;&gt; s &amp; t
-set(['i', 'o'])
-</pre>
-<p>Il modo compatibile con il passato per usare i sets nello stesso modo nella
-2.3 e nella 2.4 è il seguente:</p>
-<pre class="literal-block">
-try:
- set:
-except NameError:
- from sets import Set as set
-</pre>
-<p>Guardare la documentazione standard per saperne di più.</p>
-</div>
-<div class="section" id="differenza-tra-mutabili-e-immutabili">
-<h2><a class="toc-backref" href="#id14" name="differenza-tra-mutabili-e-immutabili">Differenza tra mutabili e immutabili</a></h2>
-<p>Questa è una causa comune di confusione in Python:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; a = 1 # i numeri sono immutabili
-&gt;&gt;&gt; b = a
-&gt;&gt;&gt; a += 1
-&gt;&gt;&gt; a
-2
-&gt;&gt;&gt; b
-1
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; a = [1] # le liste sono mutabili
-&gt;&gt;&gt; b = a
-&gt;&gt;&gt; a += [1]
-&gt;&gt;&gt; a
-[1, 1]
-&gt;&gt;&gt; b
-[1, 1]
-</pre>
-</div>
-<div class="section" id="getattr-e-setattr">
-<h2><a class="toc-backref" href="#id15" name="getattr-e-setattr">getattr e setattr</a></h2>
-<p>[Svolto al corso 1] <tt class="docutils literal"><span class="pre">getattr</span></tt> e <tt class="docutils literal"><span class="pre">setattr</span></tt> servono per richiamare e
-settare metodi il cui nome viene determinato dinamicamente:</p>
-<pre class="literal-block">
-#&lt;getattr_ex.py&gt;
-
-class C(object):
- def m1(self):
- print &quot;chiamato m1&quot;
- def m2(self):
- print &quot;chiamato m2&quot;
-
-if __name__ == &quot;__main__&quot;:
- c = C()
- method = raw_input(&quot;Che metodo devo chiamare? [m1 o m2] &quot;)
- getattr(c, method)()
-
-#&lt;/getattr_ex.py&gt;
-</pre>
-<p><em>Non usate exec quando getattr basterebbe!</em></p>
-<pre class="doctest-block">
-&gt;&gt;&gt; method = 'm1'
-&gt;&gt;&gt; exec 'c.%s()' % method # funziona ma è brutto
-chiamato m1
-&gt;&gt;&gt; getattr(c, method)() # il modo giusto
-chiamato m1
-</pre>
-<p>Per <tt class="docutils literal"><span class="pre">setattr</span></tt> vedere la documentazione.</p>
-</div>
-<div class="section" id="gestione-dei-processi">
-<h2><a class="toc-backref" href="#id16" name="gestione-dei-processi">Gestione dei processi</a></h2>
-<p>Come far partire un processo in parallelo:</p>
-<pre class="literal-block">
-import subprocess
-
-PLAYER =&quot;mplay32&quot;
-
-def play_song(song):
- subprocess.Popen([PLAYER, &quot;/play&quot;, &quot;/close&quot;, song]) # NON BLOCCA!
- print &quot;Partito&quot;
-
-
-if __name__ == &quot;__main__&quot;:
- play_song(&quot;c:/Documents and Settings/micheles/Desktop/Music/1. &quot;
- &quot;Theme from Harry's Game.mp3&quot;)
-</pre>
-<p><tt class="docutils literal"><span class="pre">subprocess.call</span></tt> fa partire il processo e blocca il programma fintanto
-che il processo non è terminato. Ho anche fatto vedere cosa succede
-se uno dei processi solleva qualche eccezione inaspettata ma viene chiuso
-correttamente grazie al try .. finally:</p>
-<pre class="literal-block">
-#&lt;main.py&gt;
-
-&quot;Chiama due processi proc1a.py e proc1b.py&quot;
-
-import subprocess
-
-CMD_a = [&quot;python&quot;, &quot;-c&quot;, &quot;import proc1a; proc1a.main()&quot;]
-CMD_b = [&quot;python&quot;, &quot;-c&quot;, &quot;import proc1b; proc1b.main()&quot;]
-
-if __name__ == &quot;__main__&quot;:
- p_a = subprocess.Popen(CMD_a)
- p_b = subprocess.Popen(CMD_b)
-
-#&lt;/main.py&gt;
-</pre>
-<p>Processo 1a:</p>
-<pre class="literal-block">
-#&lt;proc1a.py&gt;
-
-import time
-
-def main():
- for i in range(10):
- print &quot;hello&quot;
- time.sleep(1)
-
-if __name__ == &quot;__main__&quot;:
- main()
-
-#&lt;/proc1a.py&gt;
-</pre>
-<p>Processo 1b:</p>
-<pre class="literal-block">
-#&lt;proc1b.py&gt;
-
-#-*- encoding: latin-1 -*-
-import time, sys
-
-def main():
- try:
- f = file(&quot;proc1b.py&quot;)
- for i in range(10):
- print &quot;world&quot;
- if i == 5:
- raise RuntimeError(&quot;Ahia!&quot;)
- time.sleep(1)
- finally:
- f.close()
- print &quot;Il file è stato chiuso correttamente.&quot;
-
-if __name__ == &quot;__main__&quot;:
- main()
-
-#&lt;/proc1b.py&gt;
-</pre>
-<p>Ho anche illustrato brevemente come si possono gestire i processi da
-Twisted:</p>
-<pre class="literal-block">
-#&lt;proc2a.py&gt;
-
-&quot;Un processo che genera numeri casuali e li salva nel file data.txt&quot;
-
-import random
-
-def main():
- ro = random.Random()
- out = file(&quot;data.txt&quot;, &quot;w&quot;)
- for number in ro.sample(range(1000), 100):
- print &gt;&gt; out, number
- out.close()
- print &quot;Dati salvati sul file 'data.txt'&quot;
-
-if __name__ == &quot;__main__&quot;:
- main()
-
-#&lt;/proc2a.py&gt;
-
-#&lt;proc2b.py&gt;
-
-&quot;Un processo che genera l'istogramma histo.png dai dati in data.txt&quot;
-
-from pylab import hist, savefig
-
-def main():
- hist([int(n) for n in file(&quot;dat.txt&quot;)], 10)
- savefig(&quot;histo.png&quot;)
- print &quot;Istogramma salvato sul file 'histo.png'&quot;
-
-if __name__ == &quot;__main__&quot;:
- main()
-
-#&lt;/proc2b.py&gt;
-
-#&lt;twisted_main.py&gt;
-
-&quot;Il main che chiama proc2a.py e proc2b.py nell'ordine e gestisce gli errori&quot;
-
-import webbrowser, sys
-if sys.platform == &quot;win32&quot;:
- from twisted.internet import win32eventreactor
- win32eventreactor.install()
-
-from twisted.internet.utils import getProcessOutput
-from twisted.internet import reactor
-
-def scrivi_messaggio(err):
- print err.getErrorMessage()
- reactor.stop()
- import pdb; pdb.set_trace() # fa partire il debugger in caso di errore
-
-def visualizza_histo(out_di_genera_histo):
- print out_di_genera_histo
- webbrowser.open(&quot;histo.png&quot;)
-
-def genera_histo(out_di_genera_dati):
- print out_di_genera_dati
- getProcessOutput(sys.executable, (r&quot;c:\corso\processi\proc2b.py&quot;,)) \
- .addCallback(visualizza_histo) \
- .addErrback(scrivi_messaggio)
-
-def genera_dati():
- getProcessOutput(sys.executable, (r&quot;c:\corso\processi\proc2a.py&quot;,)) \
- .addCallback(genera_histo) \
- .addErrback(scrivi_messaggio)
-
-if __name__ == &quot;__main__&quot;:
- reactor.callLater(0, genera_dati) # call &quot;genera_dati&quot; after 0 seconds
- reactor.run()
-
-#&lt;/twisted_main.py&gt;
-</pre>
-<p>In questo esempio ho usato <tt class="docutils literal"><span class="pre">sys.executable</span></tt>, che contiene il nome
-completo dell'eseguibile Python (per esempio <tt class="docutils literal"><span class="pre">C:\Python24\python.exe</span></tt>)
-con cui il programma principale è stato lanciato. Questo assicura che
-i processi secondari vengano lanciati con quella versione di Python
-(utile se avete installato contemporaneamente piu' versioni di Python
-e ci possono essere dei dubbi, oppure se il path non e' settato
-correttamente e l'eseguibile Python non viene trovato).</p>
-<p>A volte, nonostante tutta la buona volontà, i processi vanno fuori
-controllo. E' possibile ammazzarli brutalmente, con una funzione
-<tt class="docutils literal"><span class="pre">kill</span></tt> come la seguente:</p>
-<pre class="literal-block">
-import os
-
-try: # we are on Windows
- import win32api
- def kill(pid, *unix_compatibility_dummy_args):
- handle = win32api.OpenProcess(1, False, pid) # open handle to kill
- win32api.TerminateProcess(handle, -1)
- win32api.CloseHandle(handle)
- os.kill = kill # fix os
-except ImportError: # we are on Unix
- pass
-</pre>
-<p>In questo modo di fare, il modulo 'os' della libreria standard viene
-fissato automaticamente, aggiungendogli una funzione 'kill' che è
-mancante nell'ambiente Windows ma che può facilmente essere implementata
-usando le win32api (che non vengono con la distribuzione standard ma sono
-incluse con la distribuzione dell'ActiveState).</p>
-<p>Naturalmente cambiare moduli della libreria standard al volo NON È
-CONSIGLIATO, ma è sempre meglio che modificare a mano il codice
-sorgente e mantenere una propria versione modificata.</p>
-</div>
-<div class="section" id="iteratori-e-generatori">
-<h2><a class="toc-backref" href="#id17" name="iteratori-e-generatori">Iteratori e generatori</a></h2>
-<p>Un iterabile è un qualunque oggetto su cui si può iterare con un
-ciclo &quot;for&quot;; un iteratore è un oggetto con un metodo .next().
-Il modo più comune per definire iteratori è tramite un generatore,
-cioè una &quot;funzione&quot; con uno &quot;yield&quot;:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def gen123():
-... yield 1
-... yield 2
-... yield 3
-...
-&gt;&gt;&gt; it = gen123()
-&gt;&gt;&gt; it.next()
-1
-&gt;&gt;&gt; it.next()
-2
-&gt;&gt;&gt; it.next()
-3
-&gt;&gt;&gt; it.next()
-Traceback (most recent call last):
- File '&lt;stdin&gt;', line 1, in ?
-StopIteration
-</pre>
-<p>Un ciclo &quot;for&quot; internamente converte l'iterabile in un iteratore,
-chiama il metodo &quot;.next()&quot; successivamente e trappa l'eccezione StopIteration,
-uscendo dal loop quando non c'è più nulla su cui iterare:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = gen123()
-&gt;&gt;&gt; for i in it: print i
-...
-1
-2
-3
-</pre>
-</div>
-</div>
-<div class="section" id="modulo-3-tipici-errori-di-programmazione-e-gestione-delle-eccezioni">
-<h1><a class="toc-backref" href="#id18" name="modulo-3-tipici-errori-di-programmazione-e-gestione-delle-eccezioni">Modulo 3. Tipici errori di programmazione e gestione delle eccezioni</a></h1>
-<p><em>Si discuteranno buoni e cattivi esempi di programmazione presi da software
-reale scritto alla Magneti Marelli. Si discuteranno alcune tecniche
-per interpretare i tracebacks di Python e per identificare l'origine dei
-problemi.</em></p>
-<div class="section" id="l-errore-pi-tipico-con-le-eccezioni">
-<h2><a class="toc-backref" href="#id19" name="l-errore-pi-tipico-con-le-eccezioni">L'errore più tipico con le eccezioni</a></h2>
-<p>Bisogna assolutamente evitare codice come il seguente:</p>
-<pre class="literal-block">
-try:
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
- bla-bla
-except:
- bla-bla
-</pre>
-<p>Nel blocco <tt class="docutils literal"><span class="pre">try</span></tt> dev'esserci la cosa più semplice possibile, per
-limitare i tipi di eccezione che possono nascere. Inoltre l'except nudo
-e' orribile perchè trappa qualunque cosa, anche quello che non vorreste.
-La cosa giusta da fare è del tipo:</p>
-<pre class="literal-block">
-try:
- bla-bla
-except MyException, e: # sempre specificare l'eccezione aspettata
- print e
-except OtherException,e:
- print e
-...
-</pre>
-<p>Non trappate l'inaspettato, altrimenti non capirete mai qual è stata
-l'origine di un problema.</p>
-</div>
-<div class="section" id="il-try-finally-una-grande-idea">
-<h2><a class="toc-backref" href="#id20" name="il-try-finally-una-grande-idea">Il try .. finally è una grande idea</a></h2>
-<p>Molto spesso quello che volete non è tanto il try .. except, quanto il
-try .. finally: il vantaggio del try .. finally è che
-<em>non vi nasconde l'eccezione</em> e nello stesso tempo vi <em>garantisce che quello
-che deve essere chiuso correttamente venga chiuso correttamente</em> in ogni caso.
-C'è un eccezione a questa regola: se ammazzate un processo di brutto con un
-kill, il try .. finally non può salvarvi. Il try .. finally vi
-salva per tutte le eccezioni Python, compreso il CTRL-C (KeyboardInterrupt)
-e il sys.exit() (SystemExit).</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; try:
-... raise RuntimeError(&quot;Ahia&quot;)
-... finally:
-... print &quot;Io vengo eseguito SEMPRE, anche se c'è un'eccezione!&quot;
-...
-Io vengo eseguito SEMPRE, anche se c'e' un'eccezione!
-Traceback (most recent call last):
- File '&lt;stdin&gt;', line 2, in ?
-RuntimeError: Ahia
-</pre>
-</div>
-<div class="section" id="uso-di-assert">
-<h2><a class="toc-backref" href="#id21" name="uso-di-assert">Uso di assert</a></h2>
-<p>Per asserire che una condizione è verificata con certezza:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def div2(x):
-... assert isinstance(x, int), '%s non è un numero intero' % x
-... return x/2
-...
-&gt;&gt;&gt; div2(14)
-7
-&gt;&gt;&gt; div2(14.0)
-Traceback (most recent call last):
- File '&lt;stdin&gt;', line 1, in ?
- File '&lt;stdin&gt;', line 2, in div2
-AssertionError: 14.0 non è un numero intero
-</pre>
-<p>Tipicamente si usa in &quot;sanity checks&quot;, per essere sicuri che un parametro
-sia esattamente quello che ci si aspetta, in casi di eccezioni gravi; se
-l'assert non è rispettato, tutto il programma deve bloccarsi.</p>
-</div>
-<div class="section" id="non-usate-exec">
-<h2><a class="toc-backref" href="#id22" name="non-usate-exec">Non usate exec</a></h2>
-<p>'exec' è un costrutto pericolosissimo che va riservato solo a chi sa
-cosa sta facendo. Spesso e volentieri si usa soltanto per ignoranza
-dell'esistenza di una soluzione migliore.</p>
-<p>Esempio:</p>
-<pre class="literal-block">
-exec file(&quot;myscript.py&quot;).read()
-</pre>
-<p>è UN ERRORE GRAVE per vari motivi.</p>
-<p>In primo luogo, in caso di eccezioni sollevate in 'myscript.py'
-perdete informazione su dove si trova l'errore (cioè nel file &quot;myscript.py&quot;)
-e rendete impossibile la vita al debugger; in secondo luogo, sporcate il
-namespace del vostro programma in maniera potenzialmente pericolosa. La cosa
-giusta da fare è:</p>
-<pre class="literal-block">
-dic = {}
-execfile(&quot;myscript.py&quot;, dic)
-</pre>
-<p>che non perde informazioni e non sporca il namespace, perchè i nomi
-definiti in myscript.py verranno confinati nel dizionario. Leggetevi
-la documentazione di 'execfilè per saperne di più.</p>
-</div>
-<div class="section" id="come-far-partire-pdb-automaticamente-in-caso-di-eccezioni-inaspettate">
-<h2><a class="toc-backref" href="#id23" name="come-far-partire-pdb-automaticamente-in-caso-di-eccezioni-inaspettate">Come far partire pdb automaticamente in caso di eccezioni inaspettate</a></h2>
-<p>[Illustrato al corso 1]</p>
-<pre class="literal-block">
-#&lt;exc_debug.py&gt;
-
-# recipe in the Python cookbook first edition, chapter 14.5
-
-import sys
-
-def info(type, value, tb):
- if hasattr(sys, 'ps1') or not sys.stderr.isatty() or \
- type == SyntaxError:
- # we are in interactive mode or we don't have a tty-like
- # device, so we call the default hook
- sys.__excepthook__(type, value, tb)
- else:
- import traceback, pdb
- # we are NOT in interactive mode, print the exception...
- traceback.print_exception(type, value, tb)
- print
- # ...then start the debugger in post-mortem mode.
- pdb.pm()
-
-sys.excepthook = info
-
-#&lt;/exc_debug.py&gt;
-</pre>
-<p>Se un programma importa <tt class="docutils literal"><span class="pre">exc_debug</span></tt>, il Python debugger partirà
-automaticamente in caso di eccezioni non trappate. Per esempio eseguire</p>
-<pre class="literal-block">
-#&lt;example.py&gt;
-import exc_debug
-a = 1
-b = 0
-a/b
-#&lt;/example.py&gt;
-</pre>
-<p>fa partire il debugger:</p>
-<pre class="literal-block">
-$ python example.py
-Traceback (most recent call last):
- File &quot;example.py&quot;, line 4, in ?
- a/b
-ZeroDivisionError: integer division or modulo by zero
-
-&gt; /mnt/hda2/cygwin/home/micheles/md/pypers/marelli/materiale/example.py(4)?()
--&gt; a/b
-(Pdb) print a
-1
-(Pdb) print b
-0
-Pdb) !b = 1 # cambia il valore di b
-(Pdb) print a/b
-1
-</pre>
-<p>Date <tt class="docutils literal"><span class="pre">help</span> <span class="pre">pdb</span></tt> dall'interno del debugger per avere informazioni sul suo
-funzionamento.</p>
-</div>
-<div class="section" id="eccezioni-e-threads">
-<h2><a class="toc-backref" href="#id24" name="eccezioni-e-threads">Eccezioni e threads</a></h2>
-<p>Un'eccezione non trappata blocca soltanto il thread in cui si è verificata,
-NON tutto il programma:</p>
-<pre class="literal-block">
-#&lt;esempio1.py&gt;
-
-import threading, time, sys
-
-def print_hello():
- for i in range(10):
- print &quot;hello&quot;
- if i == 5:
- raise RuntimeError(&quot;Problema a runtime&quot;)
- time.sleep(1)
-
-def print_world():
- for i in range(10):
- print &quot;world&quot;
- time.sleep(1)
-
-threading.Thread(target=print_hello).start()
-threading.Thread(target=print_world).start()
-
-#&lt;/esempio1.py&gt;
-</pre>
-<p>dà come output:</p>
-<pre class="literal-block">
-$ python esempio1.py
-hello
-world
-hello
-world
-hello
-world
-hello
-world
-hello
-world
-hello
-world
-Exception in thread Thread-1:
-Traceback (most recent call last):
- File &quot;/usr/lib/python2.4/threading.py&quot;, line 442, in __bootstrap
- self.run()
- File &quot;/usr/lib/python2.4/threading.py&quot;, line 422, in run
- self.__target(*self.__args, **self.__kwargs)
- File &quot;esempio1.py&quot;, line 7, in print_hello
- raise RuntimeError(&quot;Problema a runtime&quot;)
-RuntimeError: Problema a runtime
-
-world
-world
-world
-world
-</pre>
-<p>Quindi uno è costretto a implementare un meccanismo di controllo, tipo
-il seguente:</p>
-<pre class="literal-block">
-import threading, time, sys
-
-END = False
-
-def print_hello():
- global END
- i = 0
- while not END:
- i += 1
- print &quot;hello&quot;
- if i == 5:
- try:
- raise RuntimeError(&quot;Problema a runtime&quot;)
- except RuntimeError, e:
- END = True
- time.sleep(1)
-
-def print_world():
- i = 0
- while not END:
- print &quot;world&quot;
- time.sleep(1)
-
-threading.Thread(target=print_hello).start()
-threading.Thread(target=print_world).start()
-</pre>
-<p>Questa è una soluzione artigianale, che usa una variabile globale, sfruttando
-il fatto che le variabili globali sono condivise fra tutti i thread (questo
-può anche causare danni, se non si sta attenti).</p>
-<p>La strada consigliata per comunicare fra threads è quella di usare una coda
-[esempio svolto al corso 1]:</p>
-<pre class="literal-block">
-&quot;Esempio di due threads comunicanti tramite una queue.&quot;
-
-import time, threading, Tkinter, Queue
-
-queue = Queue.Queue()
-
-def print_hello():
- for i in range(10):
- try:
- messaggio = queue.get_nowait()
- except Queue.Empty:
- pass
- else:
- if messaggio == &quot;terminate&quot;: break
- print &quot;%s, hello&quot; % i
- time.sleep(1)
-
-def print_world():
- for i in range(10):
- print &quot;%s, world&quot; % i
- if i == 5:
- queue.put(&quot;terminate&quot;) # manda il messaggio di terminazione
- root.quit()
- raise RuntimeError(&quot;Errore nel thread print_world!&quot;)
- time.sleep(1)
-
-root = Tkinter.Tk()
-
-for func in print_hello, print_world:
- th = threading.Thread(target=func)
- th.start()
-
-root.mainloop()
-</pre>
-<p>Questo esempio fa anche vedere che chiudere la finestrella grafica NON
-uccide i threads che stanno girando.</p>
-<p>I meccanismi di controllo per bloccare i thread sono notoriamente fragili
-e piccoli errori possono farvi grossi danni.</p>
-<p>Debuggare i threads è notoriamente un macello.</p>
-<p>L'unica soluzione vera è evitare i threads quando è possibile.</p>
-</div>
-</div>
-<div class="section" id="modulo-4-sviluppo-orientato-ai-test">
-<h1><a class="toc-backref" href="#id25" name="modulo-4-sviluppo-orientato-ai-test">Modulo 4. Sviluppo orientato ai test</a></h1>
-<p><em>Come scrivere software con tecnologie agili, con lo scopo di ridurre e
-tenere sotto controllo i bugs. Discussione di doctest, py.test e unittest.
-Esempi di programmazione test driven.</em></p>
-<div class="section" id="consigli-di-carattere-generale">
-<h2><a class="toc-backref" href="#id26" name="consigli-di-carattere-generale">Consigli di carattere generale</a></h2>
-<ul class="simple">
-<li>testate SUBITO, non debuggate dopo (ad ogni una riga di codice che si
-scrive, si testa che funzioni e che non distrugga quello che funzionava
-prima).</li>
-<li>scrivete software in maniera che sia testabile (per esempio create
-sempre anche una versione non-grafica di un programma grafico, perchè
-la versione testuale si testa <strong>molto</strong> più facilmente).</li>
-<li>non abbiate paura a scrivervi un vostro ambiente di test personalizzato.</li>
-<li>tenete conto che unittest e doctest esistono e possono aiutarvi infinitamente
-nel gestire i vostri test.</li>
-</ul>
-</div>
-<div class="section" id="usare-unittest">
-<h2><a class="toc-backref" href="#id27" name="usare-unittest">Usare unittest</a></h2>
-<p>Tipicamente con unittest si divide la libreria da testare:</p>
-<pre class="literal-block">
-#&lt;isnumber.py&gt;
-
-def is_number(arg):
- &quot;Verifica se la stringa arg è un numero valido&quot;
- try:
- float(arg)
- except ValueError:
- return False
- else:
- return True
-
-#&lt;/isnumber.py&gt;
-</pre>
-<p>dal file di test, che convenzionalmente ha un nome che inizia per &quot;test&quot;:</p>
-<pre class="literal-block">
-#&lt;test_isnumber.py&gt;
-
-import unittest
-
-from isnumber import is_number
-
-class TestIsNumber(unittest.TestCase):
-
- def setUp(self):
- print &quot;sto inizializzando&quot;
-
- # test positivi
- def test_1(self):
- &quot;Testa che '1' è un numero buono.&quot;
- self.assertTrue(is_number(&quot;1&quot;))
- def test_2(self):
- &quot;Testa che '1.3' è un numero buono.&quot;
- self.assertTrue(is_number(&quot;1.3&quot;))
- def test_3(self):
- &quot;Testa che '+1.3' è un numero buono.&quot;
- self.assertTrue(is_number(&quot;+1.3&quot;))
- def test_4(self):
- &quot;Testa che '-1.3' è un numero buono.&quot;
- self.assertTrue(is_number(&quot;-1.3&quot;))
-
- # test negativi
- def test_5(self):
- &quot;Testa che '1-.3' non è un numero buono.&quot;
- self.assertFalse(is_number(&quot;1-.3&quot;))
- def test_6(self):
- &quot;Testa che 'à non è un numero buono.&quot;
- self.assertFalse(is_number(&quot;a&quot;))
- def test_7(self):
- &quot;Testa che '42' è un numero buono.&quot;
- self.assertTrue(is_number(&quot;42&quot;))
-
- def tearDown(self):
- print &quot;Sto chiudendo quello che c'è da chiudere&quot;
-
-if __name__ == &quot;__main__&quot;:
- unittest.main()
-
-#&lt;/test_isnumber.py&gt;
-</pre>
-<p>Eseguire i tests con l'opzione verbose da:</p>
-<pre class="literal-block">
-$ python test_isnumber.py -v
-Testa che '1' è un numero buono. ... sto inizializzando
-Sto chiudendo quello che c'è da chiudere
-ok
-Testa che '1.3' è un numero buono. ... sto inizializzando
-Sto chiudendo quello che c'è da chiudere
-ok
-Testa che '+1.3' è un numero buono. ... sto inizializzando
-Sto chiudendo quello che c'è da chiudere
-ok
-Testa che '-1.3' è un numero buono. ... sto inizializzando
-Sto chiudendo quello che c'è da chiudere
-ok
-Testa che '1-.3' non è un numero buono. ... sto inizializzando
-Sto chiudendo quello che c'è da chiudere
-ok
-Testa che 'à non è un numero buono. ... sto inizializzando
-Sto chiudendo quello che c'è da chiudere
-ok
-Testa che '42' è un numero buono. ... sto inizializzando
-Sto chiudendo quello che c'è da chiudere
-ok
-
-----------------------------------------------------------------------
-Ran 7 tests in 0.001s
-
-OK
-</pre>
-<p>Questo mostra che i metodi <tt class="docutils literal"><span class="pre">setUp</span></tt> e <tt class="docutils literal"><span class="pre">tearDown</span></tt> vengono chiamati
-<em>per ogni test</em>, quindi tutti i test si svolgono in un ambiente pulito.</p>
-<p>E' normale avere un file di test più lungo della libreria da testare.</p>
-<p>E' possibile specificare le eccezioni aspettate:</p>
-<pre class="literal-block">
-#&lt;test_exc.py&gt;
-
-import unittest
-
-def divide(a, b):
- return a/b
-
-class TestIsNumber(unittest.TestCase):
- def test_1(self):
- &quot;Divide 4/2&quot;
- self.assertEqual(divide(4,2), 2)
- def test_2(self):
- &quot;Divide 4/0&quot;
- self.assertRaises(ZeroDivisionError, divide, 4, 0)
-
-
-if __name__ == &quot;__main__&quot;:
- unittest.main()
-
-#&lt;/test_exc.py&gt;
-
-$ python test_exc.py -v
-Divide 4/2 ... ok
-Divide 4/0 ... ok
-
-----------------------------------------------------------------------
-Ran 2 tests in 0.001s
-
-OK
-</pre>
-</div>
-<div class="section" id="usare-doctest">
-<h2><a class="toc-backref" href="#id28" name="usare-doctest">Usare doctest</a></h2>
-<p>L'uso più semplice, eseguire i doctest che si trovano nelle stringhe
-di documentazione di un modulo:</p>
-<pre class="literal-block">
-#&lt;esempio_banale.py&gt;
-
-def sum12():
- &quot;&quot;&quot;Questa funzione ritorna la somma di 1 + 2::
- &gt;&gt;&gt; sum12()
- 3&quot;&quot;&quot;
- return 1+2
-
-if __name__ == &quot;__main__&quot;:
- import doctest; doctest.testmod()
-
-#&lt;/esempio_banale.py&gt;
-</pre>
-<p>Ecco come eseguire i tests con l'opzione verbose:</p>
-<pre class="literal-block">
-$ python esempio_banale.py -v
-Trying:
- sum12()
-Expecting:
- 3
-ok
-1 items had no tests:
- __main__
-1 items passed all tests:
- 1 tests in __main__.sum12
-1 tests in 2 items.
-1 passed and 0 failed.
-Test passed.
-</pre>
-<p>Eseguire i doctest che si trovano in un file di testo separato (nuova
-funzionalità di Python 2.4):</p>
-<pre class="literal-block">
-#&lt;doctest_runner.py&gt;
-
-import doctest
-
-if __name__== &quot;__main__&quot;:
- doctest.testfile(&quot;test_isnumber.txt&quot;)
-
-#&lt;/doctest_runner.py&gt;
-</pre>
-<p>Contenuto di 'test_isnumber.txt':</p>
-<pre class="literal-block">
-Questa è la documentazione della funzione isnumber
-====================================================
-
-Esempi di uso:
-
-&gt;&gt;&gt; from isnumber import is_number
-&gt;&gt;&gt; is_number(&quot;1&quot;)
-True
-&gt;&gt;&gt; is_number(&quot;1.3&quot;)
-True
-&gt;&gt;&gt; is_number(&quot;+1.3&quot;)
-True
-&gt;&gt;&gt; is_number(&quot;-1.3&quot;)
-True
-&gt;&gt;&gt; is_number(&quot;1-.3&quot;)
-False
-&gt;&gt;&gt; is_number(&quot;a&quot;)
-False
-&gt;&gt;&gt; is_number(&quot;42&quot;)
-True
-&gt;&gt;&gt; 1/0
-Traceback (most recent call last):
- kkkkdjjfkf
-ZeroDivisionError: integer division or modulo by zero
-</pre>
-<p>Eseguire i tests:</p>
-<pre class="literal-block">
-$ python doctest_runner.py -v
-Trying:
- from isnumber import is_number
-Expecting nothing
-ok
-Trying:
- is_number(&quot;1&quot;)
-Expecting:
- True
-ok
-Trying:
- is_number(&quot;1.3&quot;)
-Expecting:
- True
-ok
-Trying:
- is_number(&quot;+1.3&quot;)
-Expecting:
- True
-ok
-Trying:
- is_number(&quot;-1.3&quot;)
-Expecting:
- True
-ok
-Trying:
- is_number(&quot;1-.3&quot;)
-Expecting:
- False
-ok
-Trying:
- is_number(&quot;a&quot;)
-Expecting:
- False
-ok
-Trying:
- is_number(&quot;42&quot;)
-Expecting:
- True
-ok
-Trying:
- 1/0
-Expecting:
- Traceback (most recent call last):
- kkkkdjjfkf
- ZeroDivisionError: integer division or modulo by zero
-ok
-1 items passed all tests:
- 9 tests in test_isnumber.txt
-9 tests in 1 items.
-9 passed and 0 failed.
-Test passed.
-</pre>
-<p>Confrontare la leggibilità di <tt class="docutils literal"><span class="pre">test_isnumber.txt</span></tt> con la leggibilità
-di <tt class="docutils literal"><span class="pre">test_isnumber.py</span></tt>, basato su unittest. Leggetevi il mio seminario su
-doctest (in allegato) per convincervi che doctest è il migliore. Anche perchè
-i doctest possono essere convertiti in unittest automaticamente, a partire
-da Python 2.4</p>
-<p>Per convertire i test contenuti in 'mymodulè da doctest a unittest:</p>
-<pre class="literal-block">
-import doctest, unittest, mymodule
-
-if __name__== &quot;__main__&quot;:
- suite = doctest.DocTestSuite(mymodule)
- unittest.TextTestRunner(verbosity=2).run(suite)
-</pre>
-<p>E' anche possibile contenere i tests contenuti in un file di
-tipo testo da doctest a unittest, vedere la documentazione.</p>
-<p>Correntemente, doctest non ha un meccanismo predefinito corrispondente
-ai metodi <tt class="docutils literal"><span class="pre">setUp</span></tt> e <tt class="docutils literal"><span class="pre">tearDown</span></tt> di unittest, ma potete impostarlo a mano.</p>
-</div>
-<div class="section" id="un-esempio-di-programma-sviluppato-in-maniera-incrementale">
-<h2><a class="toc-backref" href="#id29" name="un-esempio-di-programma-sviluppato-in-maniera-incrementale">Un esempio di programma sviluppato in maniera incrementale</a></h2>
-<p>Il seguente esempio svolto al corso intendeva dimostrare:</p>
-<ol class="arabic simple">
-<li>Come si sviluppa un programma in maniera incrementale (ad ogni nuova riga di
-codice si fa una verifica immediata del funzionamento dell'insieme);</li>
-<li>Come si fanno scelte architetturali in maniera tale da assicurare la
-testabilità del prodotto finale in maniera semplice ed automatica;</li>
-<li>Come sfruttare la libreria standard di Python al meglio, usando il
-modulo cmd;</li>
-<li>Come dividere il codice in metodi pubblici, metodi di utilità e
-metodi di debugging;</li>
-<li>Come assicurarsi che il programma venga chiuso propriamente, anche
-nel caso di eccezioni impreviste e imprevedibili;</li>
-</ol>
-<pre class="literal-block">
-# -*- encoding: latin-1 -*-
-import os, cmd, subprocess, lib, time # lib fissa os.kill
-from pywintypes import error as WindowsProcessDidNotStartCorrectly
-
-MUSICDIR = &quot;C:/Documents and Settings/micheles/Desktop/Music&quot;
-
-def play_song(name):
- po = subprocess.Popen([&quot;mplay32&quot;, &quot;/play&quot;, &quot;/close&quot;, name])
- return po.pid
-
-class InterpreteDiComandi(cmd.Cmd):
- cwd = MUSICDIR
- prompt = &quot;Player&gt; &quot;
- def preloop(self):
- self.process_list = []
- os.chdir(MUSICDIR)
-
- def do_play(self, arg):
- &quot;Suona una canzone&quot;
- if not arg:
- print &quot;Per favore scrivi il nome di una canzone!&quot;
- else:
- self.process_list.append(play_song(arg))
-
- def do_quit(self, dummy):
- &quot;Esce dall'interprete.&quot;
- return True
-
- def safe_kill(self, pid):
- try:
- os.kill(pid)
- except WindowsProcessDidNotStartCorrectly, e:
- print e
-
- def do_kill(self, arg):
- &quot;Uccide il player&quot;
- try:
- pid = self.process_list.pop()
- except IndexError:
- print &quot;Hai già ucciso tutti i processi!&quot;
- else:
- self.safe_kill(pid)
-
- def postloop(self):
- for pid in self.process_list:
- self.safe_kill(pid)
- print &quot;Ho ucciso tutto!&quot;
- os.chdir(os.path.dirname(os.path.abspath(__file__)))
-
- # metodi che possono essere utili per il debugging
- def do_print_dir(self, arg):
- &quot;Comando utile per il debugging&quot;
- print self.cwd
-
- def do_raise_exc(self, dummy):
- raise RuntimeError(&quot;Tanto per vedere che succede&quot;)
-
- def do_sleep(self, arg):
- &quot;utile per vedere quello che i test automatici stanno facendo&quot;
- time.sleep(int(arg))
-
-i = InterpreteDiComandi()
-
-try:
- i.cmdloop()
-finally: # assicura la chiusura anche in caso di eccezione
- i.postloop()
-</pre>
-<p>Nel caso regolare (senza eccezioni impreviste) .postloop è chiamato 2 volte,
-ma questo non fa danno.</p>
-<p>Questo potrebbe essere il codice corrispondente ad un test automatico:</p>
-<pre class="literal-block">
-$ more test_player.cmd
-play
-sleep 2
-play 2. Croi Croga.mp
-sleep 2
-play 2. Croi Croga.mp3
-sleep 2
-kill
-sleep 2
-quit
-</pre>
-<p>(la prima canzone non esiste, in modo da poter vedere come viene segnalato
-l'errore) che verrebbe eseguito così:</p>
-<pre class="literal-block">
-$ python player.py &lt; test_player.cmd
-</pre>
-</div>
-</div>
-<div class="section" id="modulo-5-design-documentazione-e-manutenzione-di-librarie">
-<h1><a class="toc-backref" href="#id30" name="modulo-5-design-documentazione-e-manutenzione-di-librarie">Modulo 5: Design, documentazione e manutenzione di librarie</a></h1>
-<p><em>Pratiche di programmazione &quot;in the large&quot;. Moduli, packages, strumenti di
-documentazione e di installazione. Applicazioni pratiche di principi generali
-quali disaccoppiamento, modularità, non duplicazione del codice.</em></p>
-<div class="section" id="la-filosofia-del-python">
-<h2><a class="toc-backref" href="#id31" name="la-filosofia-del-python">La filosofia del Python</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; import this
-The Zen of Python, by Tim Peters
-Beautiful is better than ugly.
-Explicit is better than implicit.
-Simple is better than complex.
-Complex is better than complicated.
-Flat is better than nested.
-Sparse is better than dense.
-Readability counts.
-Special cases aren't special enough to break the rules.
-Although practicality beats purity.
-Errors should never pass silently.
-Unless explicitly silenced.
-In the face of ambiguity, refuse the temptation to guess.
-There should be one-- and preferably only one --obvious way to do it.
-Although that way may not be obvious at first unless you are Dutch.
-Now is better than never.
-Although never is often better than *right* now.
-If the implementation is hard to explain, it's a bad idea.
-If the implementation is easy to explain, it may be a good idea.
-Namespaces are one honking great idea -- let's do more of those!
-</pre>
-</div>
-<div class="section" id="principio-del-disaccoppiamento">
-<h2><a class="toc-backref" href="#id32" name="principio-del-disaccoppiamento">Principio del disaccoppiamento</a></h2>
-<p>Questo è il principio guida di tutta la programmazione e non solo, tutto
-il resto nasce di conseguenza.</p>
-<p>Il principio dice: <strong>cercate di disaccoppiare il più possibile
-le componenti del vostro sistema</strong>.</p>
-<p><em>Un componente si dice disaccoppiato se
-può essere rimosso o sostituito senza danneggiare il resto del sistema.</em></p>
-<p>Per esempio:</p>
-<ul class="simple">
-<li>disaccoppiare l'ambiente di sviluppo dall'ambiente di esecuzione (è più
-sicuro lanciare un programma dalla riga di comando che dall' IDE; un
-debugger disaccoppiato come pdb è più sicuro di un debugger integrato
-come quello di PythoWin, un editor vero è più sicuro dell'editor dell'
-IDE, etc.)</li>
-<li>disaccoppiare l'interfaccia grafica: il programma deve poter funzionare
-senza di essa, o sostituendo il GUI toolkit con un altro.</li>
-<li>i threads vi accoppiano tutto, se uno va male può bloccare tutti gli
-altri: evitateli se potete.</li>
-<li>l'ereditarietà vi accoppia il parente al figlio (per sapere quello che
-fa il figlio bisogna andare a vedere quello che fanno il padre, il nonno,
-il bisnonno, il trisavolo, etc.). Evitatela se potete.</li>
-<li>la modularità è un modo concreto per applicare il principio del
-disaccoppiamento al codice: funzioni che logicamente vanno insieme,
-vanno messe in un modulo comune, funzioni separate vanno separate.
-Se c'è un problema nel modulo X, questo non deve interferire con
-il modulo Y (almeno in un mondo ideale). La modularità rende anche
-più semplice rimpiazzare un modulo sbagliato o vecchio con uno
-corretto o più recente.</li>
-<li>la non-duplicazione del codice è una conseguenza della modularità:
-avendo raggruppato le funzioni di uso generale in un modulo comune,
-si acquista in concisione, semplicità, leggibilità, debuggabilità,
-si evita di correggere lo stesso errore più volte, e in generale tutto
-diviene più facile da mantenere.</li>
-</ul>
-</div>
-<div class="section" id="principio-del-kiss">
-<h2><a class="toc-backref" href="#id33" name="principio-del-kiss">Principio del KISS</a></h2>
-<p><em>Keep it simple, stupid</em>. In Italiano: <em>non facciamoci del male</em>.</p>
-<p>Se potete fare le cose in maniera semplice, fatele in maniera semplice.</p>
-<p>Chiedetevi sempre se una cosa vi serve veramente oppure no.</p>
-</div>
-<div class="section" id="importanza-di-avere-un-prototipo">
-<h2><a class="toc-backref" href="#id34" name="importanza-di-avere-un-prototipo">Importanza di avere un prototipo</a></h2>
-<p>Non c'è nulla di più sbagliato che partire scrivendosi l'architettura di
-un progetto complesso sulla carta. Si parte sempre scrivendo un prototipo,
-<em>testato sul campo di battaglia</em>, che magari ha l'1% delle funzionalità
-che vi interessano, ma che <em>funziona</em>. A quel punto è possibile decidere
-l'architettura e il prototipo diventerà il core e la parte più testata
-e sicura della vostra applicazione.</p>
-<p>Il prototipo/core deve <em>rimuovere tutto l'inessenziale</em>. Più povero è,
-meglio è.</p>
-</div>
-<div class="section" id="moduli-e-packages">
-<h2><a class="toc-backref" href="#id35" name="moduli-e-packages">Moduli e packages</a></h2>
-<p>Qualunque file Python può essere visto come un modulo. Un package invece,
-è una directory contente un file <tt class="docutils literal"><span class="pre">__init__.py</span></tt> che contiene il codice di
-inizializzazione (<tt class="docutils literal"><span class="pre">__init__.py</span></tt> può benissimo essere vuoto, oppure può
-consistere solo di 'import' dei moduli di quel package).</p>
-<p>Importare un package non importa automaticamente tutti i suoi moduli,
-a meno che questo non sia detto esplicitamente nell' <tt class="docutils literal"><span class="pre">__init__.py</span></tt>.</p>
-<p>I package possono essere nidificati senza limite.</p>
-<p>Le variabili globali di un modulo sono locali a quel modulo, quindi
-non c'è mai il rischio di fare danni (a meno che un modulo non importi
-esplicitamente una variabile corrispondente ad un oggetto mutabile e
-la cambi esplicitamente).</p>
-<p>E' possibile mettere un package nel Python path automaticamente per
-tutti gli utenti listando il nome del package in un file <tt class="docutils literal"><span class="pre">.pth</span></tt> nella
-directory site-packages (vedere la documentazione di distutils).</p>
-</div>
-<div class="section" id="come-si-documenta-una-libreria-python">
-<h2><a class="toc-backref" href="#id36" name="come-si-documenta-una-libreria-python">Come si documenta una libreria Python</a></h2>
-<p>Python è un linguaggio &quot;self-documenting&quot; grazie alle doctrings.
-Usatele. In più guardate come è documentato un progetto Python
-tipico (io suggerisco di guardare a <em>docutils</em>) e copiate le convenzioni
-usate lì. Ci sono dei file standard come il README.txt, l'HISTORY.txt,
-il BUGS.txt, una directory docs, una directory test, un file setup.py,
-etc.</p>
-<p>Tenete presente che grazie a <em>doctest</em> potete inserire dei test automatici
-all'interno della vostra documentazione.</p>
-</div>
-</div>
-<div class="section" id="modulo-6-domande-estemporanee">
-<h1><a class="toc-backref" href="#id37" name="modulo-6-domande-estemporanee">Modulo 6: Domande estemporanee</a></h1>
-<p><em>Risponderò alle domande dell'audience, anche al di fuori dal programma,
-se di interesse generale</em>.</p>
-<div class="section" id="come-funziona-import">
-<h2><a class="toc-backref" href="#id38" name="come-funziona-import">Come funziona 'import'</a></h2>
-<p>Se un modulo è già stato importato e chiamate 'import' una seconda
-volta, il modulo NON viene importato due volte. Questo può essere
-un problema nell'interprete interattivo. Se importate un modulo,
-poi lo modificate e lo importate di nuovo, vi resterà in memoria
-la copia <em>vecchia</em>, quella non modificata. La soluzione è usare
-'reload', che vi importerà veramente la nuova versione.</p>
-</div>
-<div class="section" id="come-funziona-del">
-<h2><a class="toc-backref" href="#id39" name="come-funziona-del">Come funziona '__del__'</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; a = 1
-&gt;&gt;&gt; del a
-</pre>
-<p>vi cancella il nome dal namespace:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; a
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-NameError: name 'a' is not defined
-</pre>
-<p>Tuttavia l'oggetto cui si riferisce <em>non viene cancellato immediatamente</em>.
-Verrà cancellato dal garbage collector <em>quando serve</em>, ma soltanto
-<em>se non vi sono altre referenze</em> all'oggetto da qualche altra parte.
-Inoltre per oggetti C, dovrete definirvi un metodo <tt class="docutils literal"><span class="pre">__del__</span></tt> custom
-che ha accesso all'oggetto a livello C. Tenete anche conto che tipicamente
-il debugger tiene referenze agli oggetti aggiuntive, quindi in modalità
-di debugger i problemi con oggetti non cancellati peggiorano.</p>
-<p>Ecco un esempio di un metodo <tt class="docutils literal"><span class="pre">__del__</span></tt> custom piuttosto banale:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... def __del__(self):
-... print 'Hai usato del'
-...
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; del c
-Hai usato del
-</pre>
-<p>Il metodo <tt class="docutils literal"><span class="pre">__del__</span></tt> viene chiamato automaticamente all'uscita
-dall'interprete:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... def __del__(self):
-... print 'Hai usato del'
-...
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; &lt;CTRL-Z&gt; per uscire dall'interprete
-Hai usato del
-</pre>
-<p>In principio, all'uscita del programma Python
-<em>dovrebbe chiamare ``__del__`` automaticamente anche se vi sono eccezioni</em>:</p>
-<pre class="literal-block">
-#&lt;del_with_exc.py&gt;
-
-class C(object):
- def __del__(self):
- print &quot;Hai chiamato del&quot;
-
-c = C()
-raise RuntimeError(&quot;Ahi ahi!&quot;)
-
-#&lt;/del_with_exc.py&gt;
-
-$ python del_with_exc.py
-Traceback (most recent call last):
- File &quot;del_with_exc.py&quot;, line 6, in ?
- raise RuntimeError(&quot;Ahi ahi!&quot;)
-RuntimeError: Ahi ahi!
-Hai chiamato del
-</pre>
-<p>Tuttavia per oggetti <tt class="docutils literal"><span class="pre">C</span></tt> ed eccezioni le cose possono essere delicate ed
-è sempre meglio chiamare <tt class="docutils literal"><span class="pre">del</span></tt> <em>esplicitamente</em>, magari in un
-<tt class="docutils literal"><span class="pre">try</span> <span class="pre">..</span> <span class="pre">finally</span></tt>.</p>
-</div>
-<div class="section" id="che-differenza-c-fra-variabili-di-classe-e-di-istanza">
-<h2><a class="toc-backref" href="#id40" name="che-differenza-c-fra-variabili-di-classe-e-di-istanza">Che differenza c'è fra variabili di classe e di istanza</a></h2>
-<p>Questo esempio dovrebbe chiarire la differenza:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... pippo = 'sono una variabile di classe'
-... def __init__(self):
-... self.poppi = 'sono una variabile di istanza'
-...
-</pre>
-<p>Le variabili di classe sono le stesse per tutte le istanze:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; c1 = C()
-&gt;&gt;&gt; c2 = C()
-&gt;&gt;&gt; c1.pippo
-'sono una variabile di classe'
-&gt;&gt;&gt; c2.pippo
-'sono una variabile di classe'
-</pre>
-<p>Se cambio una variabile di classe, cambia per tutte le istanze, anche
-per quelle che sono state create <em>prima</em> del cambiamento:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.pippo = 'adesso la cambio'
-&gt;&gt;&gt; c1.pippo
-'adesso la cambio'
-&gt;&gt;&gt; c2.pippo
-'adesso la cambio'
-</pre>
-<p>Lo stesso vale per i metodi, che non sono altro che variabili di classe.</p>
-<p>Le variabili di istanza invece sono indipendenti:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; c1.poppi
-'sono una variabile di instanza'
-&gt;&gt;&gt; c2.poppi
-'sono una variabile di instanza'
-&gt;&gt;&gt; c1.poppi = 'cambio la variabile dell'istanza c1'
-&gt;&gt;&gt; c1.poppi
-'cambio la variabile dell'istanza c1'
-&gt;&gt;&gt; c2.poppi # questa rimane quella che era prima
-'sono una variabile di instanza'
-</pre>
-</div>
-<div class="section" id="che-cosa-sono-i-metodi-che-iniziano-con">
-<h2><a class="toc-backref" href="#id41" name="che-cosa-sono-i-metodi-che-iniziano-con">Che cosa sono i metodi che iniziano con &quot;__&quot;</a></h2>
-<p>Sono metodi protetti. Sono utili per evitare rogne con l'ereditarietà.
-Per capire il problema dò un esempio semplice qui di seguito.</p>
-<p>Normalmente l'ereditarietà accoppia il padre con il figlio, nel senso che
-il figlio può sovrascrivere i metodi del padre, e i metodi del padre andranno
-automaticamente a chiamare i metodi del figlio:</p>
-<pre class="literal-block">
-class B(object): # padre
- def __init__(self):
- self.hello()
- def hello(self):
- print &quot;hello!&quot;
-
-class C(B): # figlio
- def hello(self):
- print &quot;cucu!&quot;
-
-b = B() # stampa 'hello!'
-c = C() # stampa 'cucu!'
-</pre>
-<p>In questo esempio l'__init__ del padre chiama l'hello del figlio. Tuttavia,
-a volte uno vuole essere sicuro che l'__init__ del padre chiami l'hello
-del padre, e non quello del figlio (sempre per via del principio del
-disaccoppiamento). Per questo ci sono i <em>metodi protetti</em>:</p>
-<pre class="literal-block">
-class B(object):
- def __init__(self): # call the '__hello' method in THIS class
- self.__hello()
- def __hello(self):
- print &quot;hello!&quot;
-
-class C(B):
- def __hello(self): # won't be called by B.__init__
- print &quot;cucu!&quot;
-
-b = B() # stampa 'hello!'
-c = C() # stampe 'hello!'
-</pre>
-<p>I metodi protetti di tipo <tt class="docutils literal"><span class="pre">__&lt;nome</span> <span class="pre">metodo&gt;</span></tt> non vanno confusi con i metodi
-privati di tipo <tt class="docutils literal"><span class="pre">_&lt;nome</span> <span class="pre">metodo&gt;</span></tt> (un solo underscore):</p>
-<ol class="arabic">
-<li><p class="first">i metodi privati non andrebbero chiamati mai, se non sapendo al 100% quello
-che si sta facendo, e solo in caso di errori nel design della libreria che
-si sta utilizzando;</p>
-</li>
-<li><p class="first">i metodi protetti possono essere chiamati con tranquillità. Proprio
-perchè sono protetti, c'è la garanzia che sovrascrivendoli nella
-sottoclasse non si va ad alterare il comportamento ereditato dal padre
-(nel nostro esempio l'<tt class="docutils literal"><span class="pre">__init__</span></tt> del padre continuerà a chiamare il
-proprio <tt class="docutils literal"><span class="pre">__hello</span></tt>, non l'<tt class="docutils literal"><span class="pre">__hello</span></tt> del figlio). D'altra parte i
-metodi definiti nel figlio vedranno solo l'<tt class="docutils literal"><span class="pre">__hello</span></tt> del figlio e
-non quello del padre.</p>
-</li>
-<li><p class="first">i metodi protetti non possono essere chiamati accidentalmente, perchè
-per esempio <tt class="docutils literal"><span class="pre">c.__hello()</span></tt> non funziona. Tuttavia è possibile chiamarli,
-quindi non sono veramente privati: nel nostro esempio è possibile
-chiamare</p>
-<p><tt class="docutils literal"><span class="pre">c._B__hello</span></tt> (<tt class="docutils literal"><span class="pre">__hello</span></tt> del padre) oppure
-<tt class="docutils literal"><span class="pre">c._C__hello</span></tt> (<tt class="docutils literal"><span class="pre">__hello</span></tt> del figlio)</p>
-<p>Siccome bisogna specificare il nome della classe dove il metodo è definito
-non c'è il rischio di sbagliarsi (a meno di non essere masochisti e di
-non dare lo stesso nome al padre e al figlio).</p>
-</li>
-</ol>
-<p>I metodi protetti vengono usati raramente. Vedere &quot;Python in a Nutshell&quot;
-per maggiori informazioni sul loro uso.</p>
-</div>
-</div>
-<div class="section" id="soluzioni-al-questionario-di-ammissione">
-<h1><a class="toc-backref" href="#id42" name="soluzioni-al-questionario-di-ammissione">Soluzioni al questionario di ammissione</a></h1>
-<div class="section" id="scrivere-un-programma-che-testa-se-una-stringa-rappresenta-un-numero">
-<h2><a class="toc-backref" href="#id43" name="scrivere-un-programma-che-testa-se-una-stringa-rappresenta-un-numero">Scrivere un programma che testa se una stringa rappresenta un numero</a></h2>
-<p>Soluzione standard (vedere anche il tutorial di Python):</p>
-<pre class="literal-block">
-try:
- int(x)
-except ValueError:
- print &quot;This is not a number!&quot;
-</pre>
-<p>Soluzione usando tkSimpleDialog:</p>
-<pre class="literal-block">
-from tkSimpleDialog import askfloat
-askfloat(&quot;Enter a number&quot;, &quot;Number:&quot;)
-</pre>
-</div>
-<div class="section" id="scrivere-un-programma-che-lista-tutti-i-files-nella-directory-corrente">
-<h2><a class="toc-backref" href="#id44" name="scrivere-un-programma-che-lista-tutti-i-files-nella-directory-corrente">Scrivere un programma che lista tutti i files nella directory corrente</a></h2>
-<pre class="literal-block">
-for f in os.listdir(&quot;.&quot;):
- print f
-</pre>
-</div>
-<div class="section" id="listare-tutti-i-files-nelle-sottodirectories-ricorsivamente">
-<h2><a class="toc-backref" href="#id45" name="listare-tutti-i-files-nelle-sottodirectories-ricorsivamente">Listare tutti i files nelle sottodirectories ricorsivamente</a></h2>
-<pre class="literal-block">
-for cwd, dirs, files in os.walk(&quot;.&quot;):
- for f in files:
- print f
-</pre>
-</div>
-<div class="section" id="calcolare-lo-spazio-occupato-da-tutti-i-files-di-tipo-txt-in-una-directory">
-<h2><a class="toc-backref" href="#id46" name="calcolare-lo-spazio-occupato-da-tutti-i-files-di-tipo-txt-in-una-directory">Calcolare lo spazio occupato da tutti i files di tipo .txt in una directory</a></h2>
-<p>[Soluzione svolta al corso 1]</p>
-<pre class="literal-block">
-import os
-
-def get_text_files(d):
- for cwd, dirs, files in os.walk(d):
- for f in files:
- if f.lower().endswith(&quot;.txt&quot;):
- fullname = os.path.join(cwd, f)
- size = os.path.getsize(fullname)
- yield fullname, size
-
-from operator import itemgetter
-print sum(map(itemgetter(1), get_text_files(&quot;.&quot;)))
-</pre>
-</div>
-<div class="section" id="listare-i-files-a-seconda-delle-dimensioni">
-<h2><a class="toc-backref" href="#id47" name="listare-i-files-a-seconda-delle-dimensioni">Listare i files a seconda delle dimensioni</a></h2>
-<pre class="literal-block">
-print sorted(get_text_files(&quot;.&quot;), key=itemgetter(1))
-</pre>
-</div>
-<div class="section" id="scrivere-un-test-per-verificate-che-una-directory-sia-vuota">
-<h2><a class="toc-backref" href="#id48" name="scrivere-un-test-per-verificate-che-una-directory-sia-vuota">Scrivere un test per verificate che una directory sia vuota</a></h2>
-<pre class="literal-block">
-def is_empty(d):
- if os.listdir(d): return False
- else: return True
-</pre>
-<p>Sarebbe ridondante scrivere</p>
-<pre class="literal-block">
-if os.listdir(d) != []:
-</pre>
-<p>perchè la lista vuota ha già di per sè un valore booleano &quot;False&quot;.</p>
-</div>
-<div class="section" id="aprire-una-finestrella-contenente-la-scritta-hello-world">
-<h2><a class="toc-backref" href="#id49" name="aprire-una-finestrella-contenente-la-scritta-hello-world">Aprire una finestrella contenente la scritta &quot;hello, world!&quot;</a></h2>
-<p>[In maniera portabile]</p>
-<p>Soluzione più semplice:</p>
-<pre class="literal-block">
-# hellotk.pyw
-from tkMessageBox import showinfo
-showinfo(message=&quot;hello&quot;)
-</pre>
-<p>Soluzione alternativa:</p>
-<pre class="literal-block">
-# hellotk.pyw
-import Tkinter as t
-root = t.Tk()
-l = t.Label(text=&quot;hello&quot;)
-l.pack()
-root.mainloop()
-</pre>
-<p>Guardatevi sull'help di ActiveState la differenza tra l'estensione <tt class="docutils literal"><span class="pre">.py</span></tt>
-e l'estensione <tt class="docutils literal"><span class="pre">.pyw</span></tt> (dovrebbe essere nelle FAQ).</p>
-</div>
-<div class="section" id="scaricare-la-pagina-web-http-www-example-com-da-internet">
-<h2><a class="toc-backref" href="#id50" name="scaricare-la-pagina-web-http-www-example-com-da-internet">Scaricare la pagina Web <a class="reference" href="http://www.example.com">http://www.example.com</a> da Internet</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; from urllib2 import urlopen
-&gt;&gt;&gt; print urlopen('http://www.example.com').read()
-</pre>
-</div>
-<div class="section" id="stampare-a-schermo-una-tavola-delle-moltiplicazioni">
-<h2><a class="toc-backref" href="#id51" name="stampare-a-schermo-una-tavola-delle-moltiplicazioni">Stampare a schermo una tavola delle moltiplicazioni</a></h2>
-<p>Soluzione senza generatori:</p>
-<pre class="literal-block">
-#&lt;maketable.py&gt;
-
-# non graphic
-N = 10
-for i in range(1, N+1):
- for j in range(1, N+1):
- print &quot;%4d&quot; % (i*j),
- print
-
-# HTML
-def maketable(iterable, N):
- iterable = iter(iterable)
- print &quot;&lt;table border='1'&gt;&quot;
- stop = False
- while not stop:
- print &quot;&lt;tr&gt;&quot;
- for j in range(1, N+1):
- try:
- print &quot;&lt;td&gt;%s&lt;/td&gt;&quot; % iterable.next(),
- except StopIteration:
- print &quot;&lt;td&gt;&lt;/td&gt;&quot;
- stop = True
- print &quot;&lt;/tr&gt;&quot;
- print &quot;&lt;/table&gt;&quot;
-
-import tempfile, webbrowser, os, sys
-
-def showtable(iterable, N):
- stdout = sys.stdout # shows how to redirect stdout correctly
- fd, name = tempfile.mkstemp(suffix=&quot;.html&quot;)
- sys.stdout = os.fdopen(fd, &quot;w&quot;)
- maketable(iterable, N)
- webbrowser.open(name)
- sys.stdout = stdout
-
-showtable((i*j for j in range(1, N+1) for i in range(1, N+1)), N)
-
-#&lt;/maketable.py&gt;
-</pre>
-<p>Soluzione usando i generatori, non HTML:</p>
-<pre class="literal-block">
-#&lt;gentable.py&gt;
-
-def gentable(N):
- for i in range(1, N+1):
- for j in range(1, N+1):
- yield i*j
-
-def printtable(lst, N):
- for i, el in enumerate(lst):
- print &quot;%4d&quot; % el,
- if (i+1) % 10 == 0:
- print
-
-if __name__ == &quot;__main__&quot;:
- printtable(gentable(10), 10)
-
-#&lt;/gentable.py&gt;
-</pre>
-</div>
-<div class="section" id="trovare-tutte-le-immagini-jpg-nel-vostro-hard-disk-e-mostrarle-a-schermo-in-formato-ridotto">
-<h2><a class="toc-backref" href="#id52" name="trovare-tutte-le-immagini-jpg-nel-vostro-hard-disk-e-mostrarle-a-schermo-in-formato-ridotto">Trovare tutte le immagini .jpg nel vostro hard disk e mostrarle a schermo in formato ridotto</a></h2>
-<p>Soluzione svolta al corso 1:</p>
-<pre class="literal-block">
-import os, webbrowser
-
-def gentableHTML(iterable, N):
- iterator = iter(iterable)
- yield &quot;&lt;HTML&gt;&quot;
- yield &quot;&lt;BODY&gt;&quot;
- yield &quot;&lt;TABLE border='1'&gt;&quot;
- for i in range(N):
- yield &quot;&lt;TR&gt;&quot;
- for j in range(N):
- yield '&lt;TD&gt;&lt;img src=&quot;%s&quot; width=&quot;50&quot;, height=&quot;50&quot;&gt;&lt;/TD&gt;\n' % \
- iterator.next()
- yield &quot;&lt;/TR&gt;\n&quot;
- yield &quot;&lt;/TABLE&gt;&quot;
- yield &quot;&lt;/BODY&gt;&quot;
- yield &quot;&lt;/HTML&gt;&quot;
-
-# generatore di file names
-def get_files_with_ext(ext_set, d):
- &quot;&quot;&quot;
- ext_set is a set of valid extensions.
- &quot;&quot;&quot;
- assert isinstance(ext_set, set), &quot;%r is not a set!&quot; % ext_set
- for cwd, dirs, files in os.walk(d):
- for f in files:
- name, ext = os.path.splitext(f)
- fullname = os.path.join(cwd, f)
- if ext.lower() in ext_set and os.path.getsize(fullname):
- yield fullname
-
-if __name__ == &quot;__main__&quot;:
- # genera il file e lo mostra
- images = file(&quot;images.html&quot;, &quot;w&quot;)
- for el in gentableHTML(get_files_with_ext(set([&quot;.png&quot;]),
- &quot;C:\\Documents and Settings&quot;), 15):
- print &gt;&gt; images, el,
- images.close()
- webbrowser.open(&quot;images.html&quot;)
-</pre>
-<p>Soluzione più sofisticata, per darvi qualcosa su cui pensare:</p>
-<pre class="literal-block">
-#&lt;maketable.py&gt;
-
-def get_files_with_ext(ext, d):
- &quot;&quot;&quot;
- ext can be a string or a set of strings; for instance
- get_files_with_ext(&quot;.png&quot;) or get_files_with_ext(set(&quot;.png&quot;, &quot;.gif&quot;))
- &quot;&quot;&quot;
- if not isinstance(ext, set):
- ext_set = set([ext])
- for cwd, dirs, files in os.walk(d):
- for f in files:
- name, ext = os.path.splitext(f)
- if ext.lower() in ext_set:
- yield os.path.join(cwd, f)
-
-class Picture(object):
- &quot;&quot;&quot;An example of the utility of __str__&quot;&quot;&quot;
- def __init__(self, pathname):
- self.pathname = pathname
- self.name = os.path.basename(pathname)
- def __str__(self):
- return &quot;&lt;img src=%r width=100&gt;&quot; % self.pathname
-
-if sys.platform == 'win32':
- drive = &quot;C:\\&quot;
-else:
- drive = &quot;/&quot;
-showtable(map(Picture, get_files_with_ext(&quot;.jpg&quot;, drive)), N)
-
-#&lt;/maketable.py&gt;
-</pre>
-</div>
-</div>
-</div>
-</body>
-</html>
-
diff --git a/pypers/marelli/materiale/doctest_talk/P01.html b/pypers/marelli/materiale/doctest_talk/P01.html
deleted file mode 100755
index a3a9e4d..0000000
--- a/pypers/marelli/materiale/doctest_talk/P01.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P01</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P02.html'>Next</a></td> <td bgcolor="lightblue"><a href='P25.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P01</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing in Python: wonderful doctest!</h1><br/>
-
-<center>
-
- ACCU Conference 2005 <br/> <br/>
-
- 22 Apr 2005 <br/> <br/>
-
- Michele Simionato <br/> <br/>
-
- michele.simionato@gmail.com <br/> <br/>
-
-</center></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P02.html b/pypers/marelli/materiale/doctest_talk/P02.html
deleted file mode 100755
index b187e50..0000000
--- a/pypers/marelli/materiale/doctest_talk/P02.html
+++ /dev/null
@@ -1,106 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P02</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>Next</a></td> <td bgcolor="lightblue"><a href='P01.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P02</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Summary</h1><br/>
-
-<ul>
- <li> What is automatic testing? </li>
- <li> Why automatic testing is better? </li>
- <li> Which kind of automatic testing? </li>
- <li> How does it work, in practice? </li>
- <li> What's the message?</li>
-<ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P03.html b/pypers/marelli/materiale/doctest_talk/P03.html
deleted file mode 100755
index dbfc5f8..0000000
--- a/pypers/marelli/materiale/doctest_talk/P03.html
+++ /dev/null
@@ -1,102 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P03</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P04.html'>Next</a></td> <td bgcolor="lightblue"><a href='P02.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P03</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>What is automatic testing</h1><br/>
-
-Any methodology that allows you to test
-your application mechanically, repeatedly
-and in a <em>controlled reproducible</em> way.</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P04.html b/pypers/marelli/materiale/doctest_talk/P04.html
deleted file mode 100755
index b05ff1a..0000000
--- a/pypers/marelli/materiale/doctest_talk/P04.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P04</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>Next</a></td> <td bgcolor="lightblue"><a href='P03.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P04</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing is better (1)</h1><br/>
-
-When doing manual testing typically you spend
-
-<center><h2>
-
- 1 hour of coding + 10 hours of testing/debugging
-
-</center></h2>
-
-on the other hand ...</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P05.html b/pypers/marelli/materiale/doctest_talk/P05.html
deleted file mode 100755
index 62b628a..0000000
--- a/pypers/marelli/materiale/doctest_talk/P05.html
+++ /dev/null
@@ -1,107 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P05</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P06.html'>Next</a></td> <td bgcolor="lightblue"><a href='P04.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P05</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing is better (2)</h1><br/>
-
-... when doing automatic testing typically you spend
-
-<br/> <br/>
-<center><h2>
-
- 1 hour of coding + 10 hours of testing/debugging !
-
-</center></h2></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P06.html b/pypers/marelli/materiale/doctest_talk/P06.html
deleted file mode 100755
index f4a18cb..0000000
--- a/pypers/marelli/materiale/doctest_talk/P06.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P06</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>Next</a></td> <td bgcolor="lightblue"><a href='P05.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P06</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>However ...</h1><br/>
-
-Think about six month later!
- <br/><br/>
-<center><em>
-
- there is a difference</em>
-
- <h2><u>Refactoring!</u><h2>
-
-</center></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P07.html b/pypers/marelli/materiale/doctest_talk/P07.html
deleted file mode 100755
index b6c31ae..0000000
--- a/pypers/marelli/materiale/doctest_talk/P07.html
+++ /dev/null
@@ -1,107 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P07</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P08.html'>Next</a></td> <td bgcolor="lightblue"><a href='P06.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P07</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing in Python</h1><br/>
-
-There are two standard testing frameworks in Python:
-
-<ol>
- <li> unittest </li>
- <li> doctest </li>
-</ol>
-
-Which one should I use?</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P08.html b/pypers/marelli/materiale/doctest_talk/P08.html
deleted file mode 100755
index 6c6c43e..0000000
--- a/pypers/marelli/materiale/doctest_talk/P08.html
+++ /dev/null
@@ -1,102 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P08</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>Next</a></td> <td bgcolor="lightblue"><a href='P07.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P08</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Well,</h1><br/>
-
-since my talk has <em>doctest</em> in the title ...
-
- ;-)</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P09.html b/pypers/marelli/materiale/doctest_talk/P09.html
deleted file mode 100755
index 0e92531..0000000
--- a/pypers/marelli/materiale/doctest_talk/P09.html
+++ /dev/null
@@ -1,114 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P09</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P10.html'>Next</a></td> <td bgcolor="lightblue"><a href='P08.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P09</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>More seriously ...</h1><br/>
-
-Use different testing frameworks; each one has advantages
-and disadvantages; use combinations of them; invent your
-own testing procedure.
-
-I use combinations of
-
-<ul>
- <li> unittest </li>
- <li> doctest </li>
- <li> custom tests </li>
- <li> Makefile driven tests </li>
- <li> et al. </li>
-</ul>
-
-doctest emphasis is on <em>documentation</em></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P10.html b/pypers/marelli/materiale/doctest_talk/P10.html
deleted file mode 100755
index 19c6e36..0000000
--- a/pypers/marelli/materiale/doctest_talk/P10.html
+++ /dev/null
@@ -1,101 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P10</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>Next</a></td> <td bgcolor="lightblue"><a href='P09.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P10</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>What is doctest?</h1><br/>
-
-In its simplest form (which I do not use that much) doctest allows
-you to include tests in the docstrings of your application.</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P11.html b/pypers/marelli/materiale/doctest_talk/P11.html
deleted file mode 100755
index e838716..0000000
--- a/pypers/marelli/materiale/doctest_talk/P11.html
+++ /dev/null
@@ -1,114 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P11</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P12.html'>Next</a></td> <td bgcolor="lightblue"><a href='P10.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P11</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Example</h1><br/>
-<pre># split.py
-import re
-SEP = re.compile(r"\s*[,;]\s*")
-
-def split(text):
- """Split a string taking as separators "," ";".
- Example:
- >>> from split import split
- >>> split("hello, world!; welcome to PyUK!")
- ['hello', 'world!', 'welcome to PyUK!']
- """
- return SEP.split(text)
-
-if __name__ == "__main__":
- import doctest; doctest.testmod()
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P12.html b/pypers/marelli/materiale/doctest_talk/P12.html
deleted file mode 100755
index 230eb27..0000000
--- a/pypers/marelli/materiale/doctest_talk/P12.html
+++ /dev/null
@@ -1,119 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P12</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>Next</a></td> <td bgcolor="lightblue"><a href='P11.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P12</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Running doctest in verbose mode</h1><br/>
-
-<pre>
-$ python split.py -v
-Running __main__.__doc__
-0 of 0 examples failed in __main__.__doc__
-Running __main__.split.__doc__
-Trying: from split import split
-Expecting: nothing
-ok
-Trying: split("hello, world!; welcome to Oxford!")
-Expecting: ['hello', 'world!', 'welcome to Oxford!']
-ok
-0 of 2 examples failed in __main__.split.__doc__
-1 items had no tests:
- __main__
-1 items passed all tests:
- 2 tests in __main__.split
-2 tests in 2 items.
-2 passed and 0 failed.
-Test passed.
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P13.html b/pypers/marelli/materiale/doctest_talk/P13.html
deleted file mode 100755
index b2fe415..0000000
--- a/pypers/marelli/materiale/doctest_talk/P13.html
+++ /dev/null
@@ -1,111 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P13</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P14.html'>Next</a></td> <td bgcolor="lightblue"><a href='P12.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P13</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Why I do not use the docstring approach</h1><br/>
-
-<ul>
-<li> It makes you end up with very large docstrings</li>
-
-<li> It abuses the original purpose of docstrings</li>
-
-<li> It conflates two different aspects (code and tests on the code)</li>
-
-<li> It is much easier to write the documentation in a separate
- text file </li>
-
-<li> Testing should be done by an external tool anyway </li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P14.html b/pypers/marelli/materiale/doctest_talk/P14.html
deleted file mode 100755
index 5c16abf..0000000
--- a/pypers/marelli/materiale/doctest_talk/P14.html
+++ /dev/null
@@ -1,118 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P14</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>Next</a></td> <td bgcolor="lightblue"><a href='P13.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P14</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>How I use doctest</h1><br/>
-
-I hacked inside doctest and wrote a custom utility
-to extract doctests from documentation files since
-
-<ul>
- <li>I like keeping the documentation on a separate rst file</li>
-
- <li>there is no sync problem since you run the tests all the time</li>
-
- <li>it is useful for writing articles ...</li>
-
- <li> ... but also documentation for internal usage in the company</li>
-</ul>
-
-http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410052
-
-<pre>
-$ python -m doctester < split.txt
-doctest: run 4 tests, failed 0
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P15.html b/pypers/marelli/materiale/doctest_talk/P15.html
deleted file mode 100755
index a6843e3..0000000
--- a/pypers/marelli/materiale/doctest_talk/P15.html
+++ /dev/null
@@ -1,115 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P15</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P16.html'>Next</a></td> <td bgcolor="lightblue"><a href='P14.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P15</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Testing the doctester frontend</h1><br/>
-
-<pre>
->>> from ms.webtester import start_server, stop_server
->>> from ms.http_utils import urlopen
->>> baseurl = "http://localhost:7080/"
->>> home = "/home/micheles/md/python/quixote/"
-
->>> start_server(home + "doctester_frontend.py")
->>> import time; time.sleep(2) # wait a bit
-
-Making a POST:
-
->>> res = urlopen(baseurl, dict(txt=">>> 1 + 1\n2")).read()
->>> assert "tests" in res
->>> stop_server()
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P16.html b/pypers/marelli/materiale/doctest_talk/P16.html
deleted file mode 100755
index d5b4541..0000000
--- a/pypers/marelli/materiale/doctest_talk/P16.html
+++ /dev/null
@@ -1,118 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P16</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>Next</a></td> <td bgcolor="lightblue"><a href='P15.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P16</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Managing exceptions</h1><br/>
-
-It is possible to test that your program raises the exception you
-expect:
-
-<pre>
-
-$ echo "# split cannot work on a list
->>> from split import split
->>> split([])
-Traceback (most recent call last):
- ...
-TypeError: expected string or buffer
-" > x.txt
-
-$ doct x.txt
-x.txt: 2 tests passed in 0.01 seconds
-
-</pre>
-
-(notice however that relying on exception messages may be risky)</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P17.html b/pypers/marelli/materiale/doctest_talk/P17.html
deleted file mode 100755
index da93de5..0000000
--- a/pypers/marelli/materiale/doctest_talk/P17.html
+++ /dev/null
@@ -1,116 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P17</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P18.html'>Next</a></td> <td bgcolor="lightblue"><a href='P16.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P17</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>When tests fail</h1><br/>
-
-<pre>
-
-$ cat split-failure.txt
-An example of failed text:
-
->>> from split import split
->>> split("hello, world")
-['hello', ' world']
-
-$ doct split-failure.txt
-*****************************************************************
-Failure in example: split("hello, world")
-from line #5 of split-failure.txt
-Expected: ['hello', ' world']
-Got: ['hello', 'world']
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P18.html b/pypers/marelli/materiale/doctest_talk/P18.html
deleted file mode 100755
index 0acc512..0000000
--- a/pypers/marelli/materiale/doctest_talk/P18.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P18</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>Next</a></td> <td bgcolor="lightblue"><a href='P17.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P18</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Converting doctests to unittests</h1><br/>
-
-<pre>
- import unittest
- import doctest
- import my_module_with_doctests
-
- suite = doctest.DocTestSuite(my_module_with_doctests)
- runner = unittest.TextTestRunner()
- runner.run(suite)
-</pre>
-
-<h2>For Python 2.3+<h2></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P19.html b/pypers/marelli/materiale/doctest_talk/P19.html
deleted file mode 100755
index 744a43b..0000000
--- a/pypers/marelli/materiale/doctest_talk/P19.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P19</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P20.html'>Next</a></td> <td bgcolor="lightblue"><a href='P18.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P19</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>doctest is becoming even better</h1><br/>
-
-With Python 2.4 you can run doctests on external text files:
-
-<pre>
- import doctest, unittest
- doctest.testfile(my_documentation_file, package=mypackage)
-</pre>
-
-you can also convert these doctests into unittests:
-
-<pre>
- import doctest, unittest
- suite = doctest.DocFileSuite(my_documentation_file, package=mypackage)
- unittest.TextTestRunner().run(suite)
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P20.html b/pypers/marelli/materiale/doctest_talk/P20.html
deleted file mode 100755
index 8aea60d..0000000
--- a/pypers/marelli/materiale/doctest_talk/P20.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P20</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>Next</a></td> <td bgcolor="lightblue"><a href='P19.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P20</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Python 2.4 recognizes blank lines</h1><br/>
-
-Blank lines can be marked with &lt;BLANKLINE&gt; :
-<pre>
->>> print 'foo\n\nbar\n'
-foo
-&lt;BLANKLINE&gt;
-bar
-&lt;BLANKLINE&gt;
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P21.html b/pypers/marelli/materiale/doctest_talk/P21.html
deleted file mode 100755
index 34a3aa5..0000000
--- a/pypers/marelli/materiale/doctest_talk/P21.html
+++ /dev/null
@@ -1,117 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P21</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P22.html'>Next</a></td> <td bgcolor="lightblue"><a href='P20.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P21</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Python 2.4 recognizes flags!</h1><br/>
-
-<ul>
-<li> If the ellipsis flag is used, then '...' can be used to
- elide substrings in the desired output: <pre>
->>> print range(1000) #doctest: +ELLIPSIS
-[0, 1, 2, ..., 999]
-
-</pre></li>
-
-<li>
- If the whitespace normalization flag is used, then
- differences in whitespace are ignored.<pre>
->>> print range(20) #doctest: +NORMALIZE_WHITESPACE
-[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
-12, 13, 14, 15, 16, 17, 18, 19]
-
-</pre></li>
-
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P22.html b/pypers/marelli/materiale/doctest_talk/P22.html
deleted file mode 100755
index 929bbb5..0000000
--- a/pypers/marelli/materiale/doctest_talk/P22.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P22</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>Next</a></td> <td bgcolor="lightblue"><a href='P21.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P22</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Zope experience</h1><br/>
-
-Literal quote from the PyCON doctest talk:
-
-<ul>
-<li> ~ 5600 tests (~3500 in Zope 3, ~1300 in ZODB, ~800 in Zope 2)</li>
-<li> we wrote lots of tests before we knew what we were doing</li>
-<li> debugging failed tests is really hard when intent is unclear</li>
-<li> often refactor or reimplement tests to make them clearer</li>
-<li> most new tests are doctest based</li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P23.html b/pypers/marelli/materiale/doctest_talk/P23.html
deleted file mode 100755
index 4ab3427..0000000
--- a/pypers/marelli/materiale/doctest_talk/P23.html
+++ /dev/null
@@ -1,115 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P23</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P24.html'>Next</a></td> <td bgcolor="lightblue"><a href='P22.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P23</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Conclusion (1): good reasons to use doctest</h1><br/>
-
-<quote>
-"Test coverage is important, but test readability is much more important"
-</quote>
-
-<em>-- Tim Peters and Jim Fulton</em> <br/> <br/>
-
-doctest is good since:
-
-<ol>
- <li> it is easy to understand, to explain and to use </li>
-
- <li> it makes you improve the quality of your documentation </li>
-
- <li> it can be converted to unittest anyway </li>
-
-</ol></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P24.html b/pypers/marelli/materiale/doctest_talk/P24.html
deleted file mode 100755
index 276299f..0000000
--- a/pypers/marelli/materiale/doctest_talk/P24.html
+++ /dev/null
@@ -1,112 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P24</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Next</a></td> <td bgcolor="lightblue"><a href='P23.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P24</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Conclusion (2): the message of this talk</h1><br/>
-
-Automatic testing is good for tons of practical reasons, but also
-because:
-
-<ol>
-
-<li>It teaches you <em>discipline</em> </li>
-
-<li>It makes you
- <em>think differently</em> </li>
-
-<li>It is more <em>fun!</em> </li>
-
-</ol></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P25.html b/pypers/marelli/materiale/doctest_talk/P25.html
deleted file mode 100755
index daae306..0000000
--- a/pypers/marelli/materiale/doctest_talk/P25.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P25</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>Next</a></td> <td bgcolor="lightblue"><a href='P24.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P25</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>References</h1><br/>
-
-<ul>
-
-<li>The standard library documentation
-http://docs.python.org/lib/module-doctest.html </li>
-
-<li> The doctest talk by Tim Peters and Jim Fulton
-http://www.python.org/pycon/dc2004/papers/4/</li>
-
-<li> doctest.py <em>(use the source, Luke!)</em></li>
-</ul>
-</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/P26.html b/pypers/marelli/materiale/doctest_talk/P26.html
deleted file mode 100755
index cb376d4..0000000
--- a/pypers/marelli/materiale/doctest_talk/P26.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P26</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>Next</a></td> <td bgcolor="lightblue"><a href='P25.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P26.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P26</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"><a href='P26.html'>P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>References</h1><br/>
-
-<ul>
-
-<li>The standard library documentation
-http://docs.python.org/lib/module-doctest.html </li>
-
-<li> The doctest talk by Tim Peters and Jim Fulton
-http://www.python.org/pycon/dc2004/papers/4/</li>
-
-<li> doctest.py <em>(use the source, Luke!)</em></li>
-</ul>
-</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/index.html b/pypers/marelli/materiale/doctest_talk/index.html
deleted file mode 100755
index 870e229..0000000
--- a/pypers/marelli/materiale/doctest_talk/index.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title>Partecs Training: Internal Documentation</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<h1 class="title">Partecs Training: Internal Documentation</h1>
-<div class="document" id="partecs-training-internal-documentation">
-<p><a class="reference" href="http://wiki.partecs.com/Developers/PartecsTraining/P01.html">Michele's slides for the Italian Code Jam conference</a></p>
-</div>
-</body>
-</html>
diff --git a/pypers/marelli/materiale/doctest_talk/split.html b/pypers/marelli/materiale/doctest_talk/split.html
deleted file mode 100755
index 3cc867a..0000000
--- a/pypers/marelli/materiale/doctest_talk/split.html
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title>Documentation for the 'split' module</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<h1 class="title">Documentation for the 'split' module</h1>
-<div class="document" id="documentation-for-the-split-module">
-<p>The module contains a 'split' function, which
-splits a string taking as separators &quot;,&quot; and &quot;;&quot;.
-This is an example of usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from split import split
-&gt;&gt;&gt; split(&quot;hello, world!; welcome to the Italian Code Jam!&quot;)
-['hello', 'world!', 'welcome to the Italian Code Jam!']
-</pre>
-<p>Notice that 'split' eats whitespaces:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; split(&quot;hello , world&quot;)
-['hello', 'world']
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; split(&quot;hello , ; world&quot;)
-['hello', '', 'world']
-</pre>
-</div>
-</body>
-</html>
diff --git a/pypers/marelli/programma-svolto.html b/pypers/marelli/programma-svolto.html
deleted file mode 100755
index 104798c..0000000
--- a/pypers/marelli/programma-svolto.html
+++ /dev/null
@@ -1,409 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.10: http://docutils.sourceforge.net/" />
-<title>Corso Python Magneti Marelli</title>
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-06-06 15:09:07 +0200 (Mon, 06 Jun 2005) $
-:Version: $Revision: 3442 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-*/
-
-/* "! important" is used here to override other ``margin-top`` and
- ``margin-bottom`` styles that are later in the stylesheet or
- more specific. See http://www.w3.org/TR/CSS1#the-cascade */
-.first {
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-img.borderless {
- border: 0 }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.line-block {
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid thin gray }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid thin black }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-</head>
-<body>
-<div class="document" id="corso-python-magneti-marelli">
-<h1 class="title">Corso Python Magneti Marelli</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr class="field"><th class="docinfo-name">Data:</th><td class="field-body">19-23 Settembre</td>
-</tr>
-<tr class="field"><th class="docinfo-name">Docente:</th><td class="field-body">Michele Simionato</td>
-</tr>
-</tbody>
-</table>
-<div class="section" id="programma">
-<h1><a name="programma">Programma</a></h1>
-<p>Si tratta di un corso di 20 ore suddiviso in 5 moduli di 4 ore ciascuno.</p>
-<div class="section" id="modulo-1-programmazione-di-base-in-python">
-<h2><a name="modulo-1-programmazione-di-base-in-python">Modulo 1: Programmazione di base in Python.</a></h2>
-<p><em>In questo modulo si ripasseranno molto brevemente le basi di Python e
-si discuteranno le soluzioni al questionario di ammissione. Lo scopo
-piu' che altro e' quello di conoscersi e di chiarire il livello medio
-dei partecipanti e coprire eventuali buchi nella preparazione di base.</em></p>
-<ul class="simple">
-<li>correzione esercizi ... OK</li>
-<li>gestione processi ... OK</li>
-<li>iteratori e generatori ... *</li>
-<li>differenza mutabili/immutabili ... *</li>
-<li>python -m &lt;nome module&gt; ... OK</li>
-<li>set ... OK</li>
-</ul>
-</div>
-<div class="section" id="modulo-2-strumenti-di-sviluppo-debugging-e-introspezione">
-<h2><a name="modulo-2-strumenti-di-sviluppo-debugging-e-introspezione">Modulo 2: Strumenti di sviluppo, debugging e introspezione.</a></h2>
-<p><a href="#id1" name="id2"><span class="problematic" id="id2">*</span></a>In questo modulo discutero' gli strumenti da me utilizzati per sviluppare
-in Python sotto Windows. Parlero' di Cygwin come ambiente di lavoro,
-di Python e di IPython come interpreti interattivi, di Idle e di PythonWin
-come IDE, di pydoc e minidoc come tools di introspezione. Inoltre discutero'
-alcune utili librerie e frameworks per Python (Numeric, matplotlib, gnuplot,
-etc.).</p>
-<div class="system-message" id="id1">
-<p class="system-message-title">System Message: <a name="id1">WARNING/2</a> (<tt class="docutils">programma-svolto.txt</tt>, line 31); <em><a href="#id2">backlink</a></em></p>
-Inline emphasis start-string without end-string.</div>
-<ul class="simple">
-<li>cygwin ... OK</li>
-<li>Idle ... OK</li>
-<li>PythonWin ... OK</li>
-<li>WingIDE, Eric/Qt Designer, Komodo, Boa Constructor ...</li>
-<li>Emacs/Vi ... OK</li>
-<li>help in linea ... OK</li>
-<li>pydoc ... OK</li>
-<li>ActiveState help ... OK</li>
-<li>ipython ... *</li>
-<li>matplotlib ... *</li>
-<li>numarray ... *</li>
-</ul>
-</div>
-<div class="section" id="modulo-3-tipici-errori-di-programmazione-e-gestione-delle-eccezioni">
-<h2><a name="modulo-3-tipici-errori-di-programmazione-e-gestione-delle-eccezioni">Modulo 3. Tipici errori di programmazione e gestione delle eccezioni.</a></h2>
-<p><em>Si discuteranno buoni e cattivi esempi di programmazione presi da software
-reale scritto alla Magneti Marelli. Si discuteranno alcune tecniche
-per interpretare i tracebacks di Python e per identificare l'origine dei
-problemi.</em></p>
-<ul class="simple">
-<li>uso di 'assert' ... OK</li>
-<li>come scrivere le proprie classi di eccezioni ... OK</li>
-<li>evitare blocchi try grossi ... OK</li>
-<li>possibilita' di multiple except clause ... OK</li>
-<li>evitare except nudi .. OK</li>
-<li>evitare eccezioni di tipo stringa ... OK</li>
-<li>problemi delle eccezioni con i threads ... OK</li>
-<li>segreti del try/finally ... OK</li>
-<li>problemi con exec ... OK</li>
-<li>__import__ e execfile ... OK</li>
-<li>analisi del Launcher ... OK</li>
-</ul>
-</div>
-<div class="section" id="modulo-4-sviluppo-orientato-ai-test">
-<h2><a name="modulo-4-sviluppo-orientato-ai-test">Modulo 4. Sviluppo orientato ai test</a></h2>
-<p><em>Come scrivere software con tecnologie agili, con lo scopo di ridurre e
-tenere sotto controllo i bugs. Discussione di doctest, py.test e unittest.
-Esempi di programmazione test driven.</em></p>
-<ul class="simple">
-<li>doctest ... OK</li>
-<li>unittest ... *</li>
-</ul>
-</div>
-<div class="section" id="modulo-5-design-documentazione-e-manutenzione-di-librarie">
-<h2><a name="modulo-5-design-documentazione-e-manutenzione-di-librarie">Modulo 5: Design, documentazione e manutenzione di librarie</a></h2>
-<p><em>Pratiche di programmazione &quot;in the large&quot;. Moduli, packages, strumenti di
-documentazione e di installazione. Applicazioni pratiche di principi generali
-quali disaccoppiamento, modularità, non duplicazione del codice.</em></p>
-<ul class="simple">
-<li>README.txt, HISTORY.txt, ... OK</li>
-<li>zipimport ... OK</li>
-<li>moduli, paths ...</li>
-<li>packages, .pth ...</li>
-<li>docutils ... OK</li>
-<li>distutils ...</li>
-<li>come fissare moduli di terze parti ... *</li>
-<li>evitare l'ereditarieta' multipla ... *</li>
-<li>interfacce grafiche/testuali ... *</li>
-<li>variabili dummies &quot;_&quot; ... OK</li>
-<li>a volte la docstring puo' rimpiazzare il commento ... OK</li>
-</ul>
-</div>
-<div class="section" id="modulo-6-domande-estemporanee">
-<h2><a name="modulo-6-domande-estemporanee">Modulo 6: Domande estemporanee</a></h2>
-<p><em>Rispondero' alle domande dell'audience, anche al di fuori dal programma,
-se di interesse generale</em>.</p>
-<ul class="simple">
-<li>come faccio a trovare le informazioni ... OK
-+ newsgroups!
-+ Python Cookbook
-+ Libri</li>
-<li>dove posso trovare esempi di buon codice Python ... OK</li>
-<li>come funziona 'del' ... OK</li>
-<li>come funziona 'import', 'reload' ... OK</li>
-<li>comunicazione tra processi ... *</li>
-</ul>
-</div>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/marelli/questionario-iniziale.html b/pypers/marelli/questionario-iniziale.html
deleted file mode 100755
index eef63aa..0000000
--- a/pypers/marelli/questionario-iniziale.html
+++ /dev/null
@@ -1,303 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.10: http://docutils.sourceforge.net/" />
-<title>Domande di conoscenza generale di Python, giusto per avere un'idea della vostra preparazione di base.</title>
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-06-06 15:09:07 +0200 (Mon, 06 Jun 2005) $
-:Version: $Revision: 3442 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-*/
-
-/* "! important" is used here to override other ``margin-top`` and
- ``margin-bottom`` styles that are later in the stylesheet or
- more specific. See http://www.w3.org/TR/CSS1#the-cascade */
-.first {
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-img.borderless {
- border: 0 }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.line-block {
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid thin gray }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid thin black }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-</head>
-<body>
-<div class="document" id="domande-di-conoscenza-generale-di-python-giusto-per-avere-un-idea-della-vostra-preparazione-di-base">
-<h1 class="title">Domande di conoscenza generale di Python, giusto per avere un'idea della vostra preparazione di base.</h1>
-<ol class="arabic simple">
-<li>Scrivere un programma che testa se una stringa rappresenta un numero.</li>
-<li>Scrivere un programma che lista tutti i files nella directory corrente.</li>
-<li>Come al punto 2, ma il programma deve anche listare tutti i files nelle sottodirectories ricorsivamente.</li>
-<li>Calcolare lo spazio occupato da tutti i files di tipo .txt contenuti in una directory.</li>
-<li>Listare i files a seconda delle dimensioni (dal più piccolo al più grande, in bytes).</li>
-<li>Scrivere un test per verificate che una directory sia vuota.</li>
-<li>Aprire una finestrella contenente la scritta &quot;hello, world!&quot;.</li>
-<li>Scaricare la pagina Web <a class="reference" href="http://www.example.com">http://www.example.com</a> da Internet usando Python.</li>
-<li>Stampare a schermo una tavola delle moltiplicazioni.</li>
-<li>Trovare tutte le immagini .jpg nel vostro hard disk e mostrarle a schermo in formato ridotto (thumbnails).</li>
-</ol>
-</div>
-</body>
-</html>
diff --git a/pypers/meta/meta1.html b/pypers/meta/meta1.html
deleted file mode 100755
index 683a2a8..0000000
--- a/pypers/meta/meta1.html
+++ /dev/null
@@ -1,399 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title></title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-<p>Metaclass programming in Python
-Contents:
-Review of object-oriented programming
-A metaprogramming rejoinder
-Metaclasses: a solution looking for a problem?
-Solving problems with magic
-More ways to solve problems with magic
-Meta conveniences
-Resources
-About the authors
-Rate this article
-Related content:
-AspectJ brings AOP to the Java language
-XML Matters: Enforcing validity with the gnosis.xml.validity library
-Guide to Python introspection
-Subscribe to the developerWorks newsletter
-developerWorks Toolbox subscription
-Also in the Linux zone:
-Tutorials
-Tools and products
-Code and components
-Articles
-Pushing object-oriented programming to the next level</p>
-<p>Level: Introductory</p>
-<p>David Mertz, Ph.D. (<a class="reference" href="mailto:mertz&#64;gnosis.cx">mertz&#64;gnosis.cx</a>), Developer, Gnosis Software, Inc.
-Michele Simionato, Ph.D. (<a class="reference" href="mailto:mis6+&#64;pitt.edu">mis6+&#64;pitt.edu</a>), Physicist, University of Pittsburgh</p>
-<p>February 26, 2003
-Most readers are already familiar with the concepts of object-oriented
-programming: inheritance, encapsulation, polymorphism. But the creation
-of objects of a given class, with certain parents, is usually thought of
-as a &quot;just so&quot; operation. It turns out that a number of new programming
-constructs become either easier, or possible at all, when you can
-customize the process of object creation. Metaclasses enable certain
-types of &quot;aspect-oriented programming,&quot; for example, you can enhance
-classes with features like tracing capabilities, object persistence,
-exception logging, and more.</p>
-<p>Review of object-oriented programming
-Let's start with a 30-second review of just what OOP is. In an object-oriented programming language, you can define classes, whose purpose is to bundle together related data and behaviors. These classes can inherit some or all of their qualities from their parents, but they can also define attributes (data) or methods (behaviors) of their own. At the end of the process, classes generally act as templates for the creation of instances (at times also called simply objects). Different instances of the same class will typically have different data, but it will come in the same shape -- for example, the Employee objects bob and jane both have a .salary and a .room_number, but not the same room and salary as each other.</p>
-<p>Some OOP languages, including Python, allow for objects to be introspective (also called reflective). That is, an introspective object is able to describe itself: What class does the instance belong to? What ancestors does that class have? What methods and attributes are available to the object? Introspection lets a function or method that handles objects make decisions based on what kind of object it is passed. Even without introspection, functions frequently branch based on instance data -- for example, the route to jane.room_number differs from that to bob.room_number because they are in different rooms. With introspection, you can also safely calculate the bonus jane gets, while skipping the calculation for bob, for example, because jane has a .profit_share attribute, or because bob is an instance of the subclass Hourly(Employee).</p>
-<p>A metaprogramming rejoinder
-The basic OOP system sketched above is quite powerful. But there is one element brushed over in the description: in Python (and other languages), classes are themselves objects that can be passed around and introspected. Since objects, as stated, are produced using classes as templates, what acts as a template for producing classes? The answer, of course, is metaclasses.</p>
-<p>Python has always had metaclasses. But the machinery involved in metaclasses became much better exposed with Python 2.2. Specifically, with version 2.2, Python stopped being a language with just one special (mostly hidden) metaclass that created every class object. Now programmers can subclass the aboriginal metaclass type and even dynamically generate classes with varying metaclasses. Of course, just because you can manipulate metaclasses in Python 2.2, that does not explain why you might want to.</p>
-<p>Moreover, you do not need to use custom metaclasses to manipulate the production of classes. A slightly less brain-melting concept is a class factory: An ordinary function can return a class that was dynamically created within the function body. In traditional Python syntax, you can write:</p>
-<p>Python 1.5.2 (#0, Jun 27 1999, 11:23:01) [...]
-Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
-&gt;&gt;&gt; def class_with_method(func):
-... class klass: pass
-... setattr(klass, func.__name__, func)
-... return klass
-...
-&gt;&gt;&gt; def say_foo(self): print 'foo'
-...
-&gt;&gt;&gt; Foo = class_with_method(say_foo)
-&gt;&gt;&gt; foo = Foo()
-&gt;&gt;&gt; foo.say_foo()
-foo</p>
-<p>The factory function class_with_method() dynamically creates and returns a class that contains the method/function passed into the factory. The class itself is manipulated within the function body before being returned. The new module provides a more concise spelling, but without the same options for custom code within the body of the class factory, for example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from new import classobj
-&gt;&gt;&gt; Foo2 = classobj('Foo2',(Foo,),{'bar':lambda self:'bar'})
-&gt;&gt;&gt; Foo2().bar()
-'bar'
-&gt;&gt;&gt; Foo2().say_foo()
-foo
-</pre>
-<p>In all these cases, the behaviors of the class (Foo, Foo2) are not directly written as code, but are instead created by calling functions at runtime, with dynamic arguments. And it should be emphasized that it is not merely the instances that are so dynamically created, but the classes themselves.</p>
-<p>Metaclasses: a solution looking for a problem?
-Metaclasses are deeper magic than 99% of users should ever worry about. If you wonder whether you need them, you don't (the people who actually need them know with certainty that they need them, and don't need an explanation about why). -- Python Guru Tim Peters</p>
-<p>Methods (of classes), like plain functions, can return objects. So in that sense it is obvious that class factories can be classes just as easily as they can be functions. In particular, Python 2.2+ provides a special class called type that is just such a class factory. Of course, readers will recognize type() as a less ambitious built-in function of older Python versions -- fortunately, the behaviors of the old type() function are maintained by the type class (in other words, type(obj) returns the type/class of the object obj). The new type class works as a class factory in just the same way that the function new.classobj long has:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; X = type('X',(),{'foo':lambda self:'foo'})
-&gt;&gt;&gt; X, X().foo()
-(&lt;class '__main__.X'&gt;, 'foo')
-</pre>
-<p>But since type is now a (meta)class, you are free to subclass it:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class ChattyType(type):
-... def __new__(cls, name, bases, dct):
-... print &quot;Allocating memory for class&quot;, name
-... return type.__new__(cls, name, bases, dct)
-... def __init__(cls, name, bases, dct):
-... print &quot;Init'ing (configuring) class&quot;, name
-... super(ChattyType, cls).__init__(name, bases, dct)
-...
-&gt;&gt;&gt; X = ChattyType('X',(),{'foo':lambda self:'foo'})
-Allocating memory for class X
-Init'ing (configuring) class X
-&gt;&gt;&gt; X, X().foo()
-(&lt;class '__main__.X'&gt;, 'foo')
-</pre>
-<p>The magic methods .__new__() and .__init__() are special, but in conceptually the same way they are for any other class. The .__init__() method lets you configure the created object; the .__new__() method lets you customize its allocation. The latter, of course, is not widely used, but exists for every Python 2.2 new-style class (usually inherited but not overridden).</p>
-<p>There is one feature of type descendents to be careful about; it catches everyone who first plays with metaclasses. The first argument to methods is conventionally called cls rather than self, because the methods operate on the produced class, not the metaclass. Actually, there is nothing special about this; all methods attach to their instances, and the instance of a metaclass is a class. A non-special name makes this more obvious:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Printable(type):
-... def whoami(cls): print &quot;I am a&quot;, cls.__name__
-...
-&gt;&gt;&gt; Foo = Printable('Foo',(),{})
-&gt;&gt;&gt; Foo.whoami()
-I am a Foo
-&gt;&gt;&gt; Printable.whoami()
-Traceback (most recent call last):
-TypeError: unbound method whoami() [...]
-</pre>
-<p>All this surprisingly non-remarkable machinery comes with some syntax sugar that both makes working with metaclasses easier, and confuses new users. There are several elements to the extra syntax. The resolution order of these new variations is tricky though. Classes can inherit metaclasses from their ancestors -- notice that this is not the same thing as having metaclasses as ancestors (another common confusion). For old-style classes, defining a global _metaclass_ variable can force a custom metaclass to be used. But most of the time, and the safest approach, is to set a _metaclass_ class attribute for a class that wants to be created via a custom metaclass. You must set the variable in the class definition itself since the metaclass is not used if the attribute is set later (after the class object has already been created). For example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Bar:
-... __metaclass__ = Printable
-... def foomethod(self): print 'foo'
-...
-&gt;&gt;&gt; Bar.whoami()
-I am a Bar
-&gt;&gt;&gt; Bar().foomethod()
-foo
-</pre>
-<p>Solving problems with magic
-So far, we have seen the basics of metaclasses. But putting metaclasses to work is more subtle. The challenge with utilizing metaclasses is that in typical OOP design, classes do not really do much. The inheritance structure of classes is useful to encapsulate and package data and methods, but it is typically instances that one works with in the concrete.</p>
-<p>There are two general categories of programming tasks where we think metaclasses are genuinely valuable.</p>
-<p>The first, and probably more common category is where you do not know at design time exactly what a class needs to do. Obviously, you will have some idea about it, but some particular detail might depend on information that is not available until later. &quot;Later&quot; itself can be of two sorts: (a) When a library module is used by an application; (b) At runtime when some situation exists. This category is close to what is often called &quot;Aspect-Oriented Programming&quot; (AOP). We'll show what we think is an elegant example:</p>
-<p>% cat dump.py
-#!/usr/bin/python
-import sys
-if len(sys.argv) &gt; 2:</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt class="docutils">meta1.txt</tt>, line 153)</p>
-Unexpected indentation.</div>
-<blockquote>
-module, metaklass = sys.argv[1:3]
-m = __import__(module, globals(), locals(), [metaklass])
-__metaclass__ = getattr(m, metaklass)</blockquote>
-<dl class="docutils">
-<dt>class Data:</dt>
-<dd><dl class="first docutils">
-<dt>def __init__(self):</dt>
-<dd>self.num = 38
-self.lst = ['a','b','c']
-self.str = 'spam'</dd>
-</dl>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 162)</p>
-Definition list ends without a blank line; unexpected unindent.</div>
-<p class="last">dumps = lambda self: <cite>self</cite>
-__str__ = lambda self: self.dumps()</p>
-</dd>
-</dl>
-<p>data = Data()
-print data</p>
-<p>% dump.py
-&lt;__main__.Data instance at 1686a0&gt;</p>
-<p>As you would expect, this application prints out a rather generic description of the data object (a conventional instance object). But if runtime arguments are passed to the application, we can get a rather different result:</p>
-<p>% dump.py gnosis.magic MetaXMLPickler
-&lt;?xml version=&quot;1.0&quot;?&gt;
-&lt;!DOCTYPE PyObject SYSTEM &quot;PyObjects.dtd&quot;&gt;
-&lt;PyObject module=&quot;__main__&quot; class=&quot;Data&quot; id=&quot;720748&quot;&gt;
-&lt;attr name=&quot;lst&quot; type=&quot;list&quot; id=&quot;980012&quot; &gt;</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt class="docutils">meta1.txt</tt>, line 180)</p>
-Unexpected indentation.</div>
-<blockquote>
-&lt;item type=&quot;string&quot; value=&quot;a&quot; /&gt;
-&lt;item type=&quot;string&quot; value=&quot;b&quot; /&gt;
-&lt;item type=&quot;string&quot; value=&quot;c&quot; /&gt;</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 183)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>&lt;/attr&gt;
-&lt;attr name=&quot;num&quot; type=&quot;numeric&quot; value=&quot;38&quot; /&gt;
-&lt;attr name=&quot;str&quot; type=&quot;string&quot; value=&quot;spam&quot; /&gt;
-&lt;/PyObject&gt;</p>
-<p>The particular example uses the serialization style of gnosis.xml.pickle, but the most current gnosis.magic package also contains metaclass serializers MetaYamlDump, MetaPyPickler, and MetaPrettyPrint. Moreover, a user of the dump.py &quot;application&quot; can impose the use of any &quot;MetaPickler&quot; desired, from any Python package that defines one. Writing an appropriate metaclass for this purpose will look something like:</p>
-<dl class="docutils">
-<dt>class MetaPickler(type):</dt>
-<dd><p class="first">&quot;Metaclass for gnosis.xml.pickle serialization&quot;
-def __init__(cls, name, bases, dict):</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt class="docutils">meta1.txt</tt>, line 195)</p>
-Unexpected indentation.</div>
-<blockquote class="last">
-from gnosis.xml.pickle import dumps
-super(MetaPickler, cls).__init__(name, bases, dict)
-setattr(cls, 'dumps', dumps)</blockquote>
-</dd>
-</dl>
-<p>The remarkable achievement of this arrangement is that the application programmer need have no knowledge about what serialization will be used -- nor even whether serialization or some other cross-sectional capability will be added at the command-line.</p>
-<p>Perhaps the most common use of metaclasses is similar to that of MetaPicklers: adding, deleting, renaming, or substituting methods for those defined in the produced class. In our example, a &quot;native&quot; Data.dump() method is replaced by a different one from outside the application, at the time the class Data is created (and therefore in every subsequent instance).</p>
-<p>More ways to solve problems with magic
-There is a programming niche where classes are often more important than instances. For example, declarative mini-languages are Python libraries whose program logic is expressed directly in class declarations. David examines them in his article &quot;Create declarative mini-languages&quot;. In such cases, using metaclasses to affect the process of class creation can be quite powerful.</p>
-<p>One class-based declarative framework is gnosis.xml.validity. Under this framework, you declare a number of &quot;validity classes&quot; that express a set of constraints about valid XML documents. These declarations are very close to those contained in DTDs. For example, a &quot;dissertation&quot; document can be configured with the code:</p>
-<p>from gnosis.xml.validity import *
-class figure(EMPTY): pass
-class _mixedpara(Or): _disjoins = (PCDATA, figure)
-class paragraph(Some): _type = _mixedpara
-class title(PCDATA): pass
-class _paras(Some): _type = paragraph
-class chapter(Seq): _order = (title, _paras)
-class dissertation(Some): _type = chapter</p>
-<p>If you try to instantiate the dissertation class without the right component subelements, a descriptive exception is raised; likewise for each of the subelements. The proper subelements will be generated from simpler arguments when there is only one unambiguous way of &quot;lifting&quot; the arguments to the correct types.</p>
-<p>Even though validity classes are often (informally) based on a pre-existing DTD, instances of these classes print themselves as unadorned XML document fragments, for example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from simple_diss import *
-&gt;&gt;&gt; ch = LiftSeq(chapter, ('It Starts','When it began'))
-&gt;&gt;&gt; print ch
-&lt;chapter&gt;&lt;title&gt;It Starts&lt;/title&gt;
-&lt;paragraph&gt;When it began&lt;/paragraph&gt;
-&lt;/chapter&gt;
-</pre>
-<p>By using a metaclass to create the validity classes, we can generate a DTD out of the class declarations themselves (and add an extra method to the classes while we do it):</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from gnosis.magic import DTDGenerator, \
-... import_with_metaclass, \
-... from_import
-&gt;&gt;&gt; d = import_with_metaclass('simple_diss',DTDGenerator)
-&gt;&gt;&gt; from_import(d,'**')
-&gt;&gt;&gt; ch = LiftSeq(chapter, ('It Starts','When it began'))
-&gt;&gt;&gt; print ch.with_internal_subset()
-&lt;?xml version='1.0'?&gt;
-&lt;!DOCTYPE chapter [
-&lt;!ELEMENT figure EMPTY&gt;
-&lt;!ELEMENT dissertation (chapter)+&gt;
-&lt;!ELEMENT chapter (title,paragraph+)&gt;
-&lt;!ELEMENT title (#PCDATA)&gt;
-&lt;!ELEMENT paragraph ((#PCDATA|figure))+&gt;
-]&gt;
-&lt;chapter&gt;&lt;title&gt;It Starts&lt;/title&gt;
-&lt;paragraph&gt;When it began&lt;/paragraph&gt;
-&lt;/chapter&gt;
-</pre>
-<p>The package gnosis.xml.validity knows nothing about DTDs and internal subsets. Those concepts and capabilities are introduced entirely by the metaclass DTDGenerator, without any change made to either gnosis.xml.validity or simple_diss.py. DTDGenerator does not substitute its own .__str__() method into classes it produces -- you can still print the unadorned XML fragment -- but it a metaclass could easily modify such magic methods.</p>
-<p>Meta conveniences
-The package gnosis.magic contains several utilities for working with
-metaclasses, as well as some sample metaclasses you can use in
-aspect-oriented programming. The most important of these utilities
-is import_with_metaclass(). This function, utilized in the above
-example, lets you import a third-party module, but create all the
-module classes using a custom metaclass rather than type. Whatever
-new capability you might want to impose on that third-party module
-can be defined in a metaclass that you create (or get from somewhere
-else altogether). gnosis.magic contains some pluggable serialization
-metaclasses; some other package might contain tracing capabilities,
-or object persistence, or exception logging, or something else.</p>
-<p>The import_with_metclass() function illustrates several qualities
-of metaclass programming:</p>
-<dl class="docutils">
-<dt>def import_with_metaclass(modname, metaklass):</dt>
-<dd><p class="first">&quot;Module importer substituting custom metaclass&quot;
-class Meta(object): __metaclass__ = metaklass
-dct = {'__module__':modname}
-mod = __import__(modname)
-for key, val in mod.__dict__.items():</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt class="docutils">meta1.txt</tt>, line 281)</p>
-Unexpected indentation.</div>
-<blockquote>
-<dl class="docutils">
-<dt>if inspect.isclass(val):</dt>
-<dd>setattr(mod, key, type(key,(val,Meta),dct))</dd>
-</dl>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 283)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p class="last">return mod</p>
-</dd>
-</dl>
-<p>One notable style in this function is that an ordinary class Meta is
-produced using the specified metaclass. But once Meta is added as an
-ancestor, its descendent is also produced using the custom metaclass.
-In principle, a class like Meta could carry with it both a metaclass
-producer and a set of inheritable methods -- the two aspects of its
-bequest are orthogonal.</p>
-<p>Resources</p>
-<blockquote>
-<ul class="simple">
-<li>A useful book on metaclasses is Putting Metaclasses to Work by</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 295)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>Ira R. Forman and Scott Danforth (Addison-Wesley; 1999).</p>
-<blockquote>
-<ul class="simple">
-<li>For metaclasses in Python specifically, Guido van Rossum's</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 298)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>essay, &quot;Unifying types and classes in Python 2.2&quot; is useful as well.</p>
-<blockquote>
-<ul>
-<li><dl class="first docutils">
-<dt>Also by David on developerWorks, read:</dt>
-<dd><p class="first last">o &quot;Guide to Python introspection&quot;
-o &quot;Create declarative mini-languages&quot;
-o &quot;XML Matters: Enforcing validity with the gnosis.xml.</p>
-</dd>
-</dl>
-</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 304)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>validity library&quot;</p>
-<blockquote>
-<ul class="simple">
-<li>Don't know Tim Peters? You should! Begin with Tim's wiki page</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 308)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>and end with reading <a class="reference" href="news:comp.lang.python">news:comp.lang.python</a> more regularly.</p>
-<blockquote>
-<ul class="simple">
-<li>New to AOP? You may find this &quot;Introduction to Aspect-Oriented</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 311)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>Programming&quot; (PDF) by Ken Wing Kuen Lee of the Hong Kong University
-of Science and Technology interesting.</p>
-<blockquote>
-<ul class="simple">
-<li>Gregor Kiczales and his team at Xerox PARC coined the term</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 315)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>aspect-oriented programming in the 1990s and championed it as a
-way to allow software programmers to spend more time writing code
-and less time correcting it.</p>
-<blockquote>
-<ul class="simple">
-<li>&quot;Connections between Demeter/Adaptive Programming and</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 320)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>Aspect-Oriented Programming (AOP)&quot; by Karl J. Lieberherr also
-describes AOP.</p>
-<blockquote>
-<ul class="simple">
-<li>You'll also find subject-oriented programming interesting. As</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 324)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>described by the folks at IBM Research, it's essentially the same
-thing as aspect-oriented programming.</p>
-<blockquote>
-<ul class="simple">
-<li>Find and download the Gnosis utils, mentioned several times in</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 328)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>this article, at David's site.</p>
-<blockquote>
-<ul class="simple">
-<li>Find more resources for Linux developers in the developerWorks</li>
-</ul>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils">meta1.txt</tt>, line 331)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>Linux zone.</p>
-<p>About the authors
-David Mertz David Mertz thought his brain would melt when he wrote
-about continuations or semi-coroutines, but he put the gooey mess
-back in his skull cavity and moved on to metaclasses. David may be
-reached at <a class="reference" href="mailto:mertz&#64;gnosis.cx">mertz&#64;gnosis.cx</a>; his life pored over at his personal
-Web page. Suggestions and recommendations on this, past, or future
-columns are welcome. Learn about his forthcoming book, Text
-Processing in Python.</p>
-<p>Michele Simionato Michele Simionato is a plain, ordinary, theoretical
-physicist who was driven to Python by a quantum fluctuation that could
-well have passed without consequences had he not met David Mertz. He
-will let his readers judge the final outcome. Michele can be reached
-at <a class="reference" href="mailto:mis6+&#64;pitt.edu">mis6+&#64;pitt.edu</a>.</p>
-</div>
-</body>
-</html>
diff --git a/pypers/meta/meta2.html b/pypers/meta/meta2.html
deleted file mode 100755
index e97bd7d..0000000
--- a/pypers/meta/meta2.html
+++ /dev/null
@@ -1,528 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>Metaclass Programming in Python, Part 2: Understanding the Arcana of Inheritance and Instance Creation</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="metaclass-programming-in-python-part-2-understanding-the-arcana-of-inheritance-and-instance-creation">
-<h1 class="title">Metaclass Programming in Python, Part 2: Understanding the Arcana of Inheritance and Instance Creation</h1>
-<blockquote>
-<table class="field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">author:</th><td class="field-body">Michele Simionato, Ph.D., University of Pittsburgh</td>
-</tr>
-<tr class="field"><th class="field-name">author:</th><td class="field-body">David Mertz, Ph.D., Gnosis Software, Inc.</td>
-</tr>
-<tr class="field"><th class="field-name">date:</th><td class="field-body">June 2003</td>
-</tr>
-<tr class="field"><th class="field-name">Abstract:</th><td class="field-body">Our initial developerWorks article on metaclass programming
-prompted quite a bit of feedback, some of it from perplexed
-readers still trying to grasp the subtleties of Python
-metaclasses. This article revisits the working of
-metaclasses and their relation to other OOP concepts. We
-contrast class instantiation with inheritance, distinguish
-classmethods and metamethods, and explain and solve metaclass
-conflicts.</td>
-</tr>
-</tbody>
-</table>
-</blockquote>
-<div class="section" id="metaclasses-and-their-discontents">
-<h1><a name="metaclasses-and-their-discontents">METACLASSES AND THEIR DISCONTENTS</a></h1>
-<blockquote>
-<p>In our earlier article on metaclass programming in Python, we
-introduced the concept of metaclasses, showed some of their power,
-and demonstrated their use in solving problems such as dynamic
-customization of classes and libraries at run-time.</p>
-<p>That article has proved quite popular, but there were ellisions in
-our condensed initial summary. Certain details in the use of
-metaclasses merit futher explanation. Based on the feedback of our
-readers and on discussions in comp.lang.python, we decided to
-address some of those trickier point in this second article. In
-particular, we think the following points are important for any
-programmer wanting to master metaclasses:</p>
-<p>(1) Users must understand the differences and interactions between
-metaclass programming and traditional object-oriented programming
-(under both single and multiple inheritance).</p>
-<p>(2) Python 2.2 added the built-in functions 'staticmethod()' and
-'classmethod()' to create methods that do not require an instance
-object during invocation. To an extent, -classmethods- overlap in
-purpose with (meta)methods defined in metaclasses. But the precise
-similarities and differences have also generated confusion in the
-mind of many programmers.</p>
-<p>(3) User should understand the cause and the resolution of metatype
-conflicts. This becomes essential when you want to use more than
-one custom metaclass. We explain the concept of -composition- of
-metaclasses.</p>
-</blockquote>
-</div>
-<div class="section" id="instantiation-versus-inheritance">
-<h1><a name="instantiation-versus-inheritance">INSTANTIATION VERSUS INHERITANCE</a></h1>
-<blockquote>
-<p>Many programmers are confused about the difference between a
-metaclass and a base class. At the superficial level of &quot;determing&quot;
-a class, both look similar. But once you look any deeper, the
-concepts drift apart.</p>
-<p>Before presenting some examples, it is worth being precise about
-some nomenclature. An -instance- is a Python object that was
-&quot;manufactured&quot; by a class; the class acts as a sort of template for
-the instance. Every instance is an instance of -exactly one- class
-(but a class might have multiple instances). What we often call an
-instance object--or perhaps a &quot;simple instance&quot;--is &quot;final&quot; in the
-sense it cannot act as a template for other objects (but it might
-still be a -factory- or a -delegate-, which serve overlapping
-purposes).</p>
-<p>Some instance objects are themselves classes; and all classes are
-instances of a corresponding -metaclass-. Even classes only come
-into existence through the instantiation mechanism. Usually classes
-are instances of the built-in, standard metaclass 'type'; it is only
-when we specify metaclasses other than 'type' that we need to think
-about metaclass programming. We also call the class used to
-instantiate an object the -type- of that object.</p>
-<p>Running -orthogonal- to the idea of instantiation is the notion of
-inheritance. Here, a class can have one or multiple parents, not
-just one unique type. And parents can have parents, creating a
-transitive subclass relation, conveniently accessible with the
-built-in function 'issubclass()'. For example, if we define a few
-classes and an istance:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A(object): a1 = &quot;A&quot;
-...
-&gt;&gt;&gt; class B(object): a2 = &quot;B&quot;
-...
-&gt;&gt;&gt; class C(A,B): a3 = &quot;C(A,B)&quot;
-...
-&gt;&gt;&gt; class D(C): a4 = &quot;D(C)&quot;
-...
-&gt;&gt;&gt; d = D()
-&gt;&gt;&gt; d.a5 = &quot;instance d of D&quot;
-</pre>
-</blockquote>
-<p>Then we can test the relations:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; issubclass(D,C)
-True
-&gt;&gt;&gt; issubclass(D,A)
-True
-&gt;&gt;&gt; issubclass(A,B)
-False
-&gt;&gt;&gt; issubclass(d,D)
-[...]
-TypeError: issubclass() arg 1 must be a class
-</pre>
-</blockquote>
-<p>The interesting question now--the one necessary for understanding
-the contrast between superclasses and metaclasses--is how an
-attribute like 'd.attr' is resolved. For simplicity, we discuss
-only the standard look-rule, not the fallback to '.__getattr__()'.
-The first step in such resolution is to look in 'd.__dict__' for the
-name 'attr'. If found, that's that; but if not, something fancy
-needs to happen, e.g.:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; d.__dict__, d.a5, d.a1
-({'a5': 'instance d'}, 'instance d', 'A')
-</pre>
-</blockquote>
-<p>The trick to finding an attribute that isn't attached to an instance
-is to look for it in the class of the instance, then after that in
-all the superclasses. The order in which superclasses are checked
-is called the -method resolution order- for the class. You can look
-at it with the (meta)method '.mro()' (but only from class objects):</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; [k.__name__ for k in d.__class__.mro()]
-['D', 'C', 'A', 'B', 'object']
-</pre>
-</blockquote>
-<p>In other words, the access to 'd.attr' first looks in 'd.__dict__',
-then in 'D.__dict__', 'C.__dict__', 'A.__dict__', 'B.__dict__', and
-finally in 'object.__dict__'. If the name is not found in any of
-those places, an 'AttributeError' is raised.</p>
-<p>Notice that metaclasses were never mentioned in the lookup procedure.</p>
-</blockquote>
-</div>
-<div class="section" id="metaclasses-versus-ancestors">
-<h1><a name="metaclasses-versus-ancestors">METACLASSES VERSUS ANCESTORS</a></h1>
-<blockquote>
-<p>Here is a simple example of normal inheritance. We define a 'Noble'
-base class, with subclasses such as 'Prince', 'Duke', 'Baron', etc.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; for s in &quot;Power Wealth Beauty&quot;.split(): exec '%s=&quot;%s&quot;'%(s,s)
-...
-&gt;&gt;&gt; class Noble(object): # ...in fairy tale world
-... attributes = Power, Wealth, Beauty
-...
-&gt;&gt;&gt; class Prince(Noble):
-... pass
-...
-&gt;&gt;&gt; Prince.attributes
-('Power', 'Wealth', 'Beauty')
-</pre>
-</blockquote>
-<p>The class 'Prince' inherits the attributes of the class 'Noble'. An
-instance of 'Prince' still follows the lookup chain discussed above:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; charles=Prince()
-&gt;&gt;&gt; charles.attributes # ...remember, not the real world
-('Power', 'Wealth', 'Beauty')
-</pre>
-</blockquote>
-<p>If the 'Duke' class should happen to have a custom metaclasses, it
-can obtain some attributes that way:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Nobility(type): attributes = Power, Wealth, Beauty
-...
-&gt;&gt;&gt; class Duke(object): __metaclass__ = Nobility
-...
-</pre>
-</blockquote>
-<p>As well as being a class, 'Duke' is an instance of the metaclass
-'Nobility'--attribute lookup proceeds as with any object:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Duke.attributes
-('Power', 'Wealth', 'Beauty')
-</pre>
-</blockquote>
-<p>But 'Nobility' is -not- a superclass of 'Duke', so there is no
-reason why an -instance- of 'Duke' would find 'Nobility.attributes':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; Duke.mro()
-[&lt;class '__main__.Duke'&gt;, &lt;type 'object'&gt;]
-&gt;&gt;&gt; earl = Duke()
-&gt;&gt;&gt; earl.attributes
-[...]
-AttributeError: 'Duke' object has no attribute 'attributes'
-</pre>
-</blockquote>
-<p>The availability of metaclass attributes is not transitive; i.e. the
-attributes of a metaclass are available to its instances, but not to
-the instances of the instances. Just this is the main difference
-between metaclasses and superclasses. A diagram emphasizes the
-orthogonality of inheritence and instantiation:</p>
-<div class="figure">
-<p><img alt="fig1.png" src="fig1.png" /></p>
-</div>
-<p>Figure 1--Instantiation versus Inheritance</p>
-<p>Since 'earl' still has a class, you can indirectly retrieve the
-attributes, however:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; earl.__class__.attributes
-</pre>
-</blockquote>
-<p>Figure 1 contrasts simple cases where -either- inheritance or
-metaclasses are involved, but not both. Sometimes, however, a class
-C has both a custom metaclass M and a base class B:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(type):
-... a = 'M.a'
-... x = 'M.x'
-...
-&gt;&gt;&gt; class B(object): a = 'B.a'
-...
-&gt;&gt;&gt; class C(B): __metaclass__=M
-...
-&gt;&gt;&gt; c=C()
-</pre>
-</blockquote>
-<p>Graphically:</p>
-<div class="figure">
-<p><img alt="fig2.png" src="fig2.png" /></p>
-<p class="caption">Figure 2--Combined Superclass and Metaclass</p>
-</div>
-<p>From the prior explanation, we could imagine that 'C.a' would
-resolve to -either- 'M.a' or 'B.a'. As it turns out, lookup on a
-class follows its MRO before it looks in its instantiating
-metaclass:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.a, C.x
-('B.a', 'M.x')
-&gt;&gt;&gt; c.a
-'B.a'
-&gt;&gt;&gt; c.x
-[...]
-AttributeError: 'C' object has no attribute 'x'
-</pre>
-</blockquote>
-<p>You can still enforce a attribute value using a metaclass, you just
-need to set it on the class object being instantiated rather than as
-an attribute of the metaclass:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(type):
-... def __init__(cls, *args):
-... cls.a = 'M.a'
-...
-&gt;&gt;&gt; class C(B): __metaclass__=M
-...
-&gt;&gt;&gt; C.a, C().a
-('M.a', 'M.a')
-</pre>
-</blockquote>
-</blockquote>
-</div>
-<div class="section" id="more-on-class-magic">
-<h1><a name="more-on-class-magic">MORE ON CLASS MAGIC</a></h1>
-<blockquote>
-<p>The fact that the instantiation constraint is weaker than the
-inheritance constraint is essential for implementing the special
-methods like '.__new__()', '.__init__()', '.__str__()', etc. We
-will discuss the '.__str__()' method; an analysis is similar for the
-other special methods.</p>
-<p>Readers probably know that the printed representation of a class
-object can be modified by overring its '.__str__()' method. In the
-same sense, the printed representation of a class can be modified by
-overring the '.__str__()' methods of its metaclass. For instance:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Printable(type):
-... def __str__(cls):
-... return &quot;This is class %s&quot; % cls.__name__
-...
-&gt;&gt;&gt; class C(object): __metaclass__ = Printable
-...
-&gt;&gt;&gt; print C # equivalent to print Printable.__str__(C)
-This is class C
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; print c # equivalent to print C.__str__(c)
-&lt;C object at 0x40380a6c&gt;
-</pre>
-</blockquote>
-<p>The situation can be represented with the following diagram:</p>
-<div class="figure">
-<p><img alt="fig3.png" src="fig3.png" /></p>
-<p class="caption">Figure 3-Metaclasses and Magic Methods</p>
-</div>
-<p>From the previous discussion, it is clear that the '.__str__()'
-method in 'Printable' cannot override the '.__str__()' method in C,
-which is inherited from 'object' and therefore has precedence;
-printing 'c' still gives the standard result.</p>
-<p>If C inherited its '.__str__()' method from 'Printable' rather than
-from 'object', it would cause a problem: 'C' instances do not have
-a '.__name__' attribute and printing 'c' would generate an error.
-Of course, you could still define a '.__str__()' method in 'C' that
-would change the way 'c' prints.</p>
-</blockquote>
-</div>
-<div class="section" id="classmethods-vs-metamethods">
-<h1><a name="classmethods-vs-metamethods">CLASSMETHODS VS. METAMETHODS</a></h1>
-<blockquote>
-<p>Another common confusion arise between Python classmethods and
-methods defined in a metaclass, best called -metamethods-.</p>
-<p>Consider this example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(Printable):
-... def mm(cls):
-... return &quot;I am a metamethod of %s&quot; % cls.__name__
-...
-&gt;&gt;&gt; class C(object):
-... __metaclass__=M
-... def cm(cls):
-... return &quot;I am a classmethod of %s&quot; % cls.__name__
-... cm=classmethod(cm)
-...
-&gt;&gt;&gt; c=C()
-</pre>
-</blockquote>
-<p>Part of the confusion is due to the fact that in the Smalltalk
-terminology, 'C.mm' would be called a &quot;class method of 'C'.&quot;
-Python classmethods are a different beast, however.</p>
-<p>The metamethod &quot;mm&quot; can be invoked both from either the metaclass or
-from the class, but not from the instance. The classmethod can be
-called both from the class and from its instances (but does not
-exist in the metaclass).</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print M.mm(C)
-I am a metamethod of C
-&gt;&gt;&gt; print C.mm()
-I am a metamethod of C
-&gt;&gt;&gt; print c.mm()
-[...]
-AttributeError: 'C' object has no attribute 'mm'
-&gt;&gt;&gt; print C.cm()
-I am a classmethod of C
-&gt;&gt;&gt; print c.cm()
-I am a classmethod of C
-</pre>
-</blockquote>
-<p>Also, the metamethod is retrieved by 'dir(M)' but not by 'dir(C)'
-whereas the classmethod is retrieved by 'dir(C)' and 'dir(c)'.</p>
-<p>You can only call the metaclass method that are defined in the
-class MRO by dispatching on the metaclass (built-ins like 'print' do
-this behind the scenes):</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; print C.__str__()
-[...]
-TypeError: descriptor '__str__' of 'object' object needs an argument
-&gt;&gt;&gt; print M.__str__(C)
-This is class C
-</pre>
-</blockquote>
-<p>It is important to notice that this dispatch conflict is not limited
-to magic methods. If we change 'C' by adding an attribute 'C.mm',
-the same issue exists (it does not matter if the name is a regular
-method, classmethod, staticmethod, or simple attribute):</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.mm=lambda self: &quot;I am a regular method of %s&quot; % self.__class__
-&gt;&gt;&gt; print C.mm()
-[...]
-TypeError: unbound method &lt;lambda&gt;() must be called with
- C instance as first argument (got nothing instead)
-</pre>
-</blockquote>
-</blockquote>
-</div>
-<div class="section" id="conflicting-metaclasses">
-<h1><a name="conflicting-metaclasses">CONFLICTING METACLASSES</a></h1>
-<blockquote>
-<p>Once you work seriously with metaclasses, you will be bitten at
-least once by metaclass/metatype conflicts. Consider a class 'A'
-with metaclass 'M_A' and a class 'B' with metaclass 'M_B'; suppose
-we derive 'C' from 'A' and 'B'. The question is: what is the
-metaclass of 'C'? Is it 'M_A' or 'M_B'?</p>
-<p>The correct answer (see &quot;Putting metaclasses to work&quot; for a
-discussion) is 'M_C', where 'M_C' is a metaclass that inherits from
-'M_A' and 'M_B', as in the following graph:</p>
-<dl>
-<dt>{Figure 4--Avoiding the Metaclass Conflict:</dt>
-<dd><a class="reference" href="http://gnosis.cx/secret/metaclass-conflict.gif">http://gnosis.cx/secret/metaclass-conflict.gif</a>}</dd>
-</dl>
-<p>However, Python does not (yet) automatically create 'M_C'. Instead,
-it raises a 'TypeError', warning the programmer of the conflict:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M_A(type): pass
-...
-&gt;&gt;&gt; class M_B(type): pass
-...
-&gt;&gt;&gt; class A(object): __metaclass__ = M_A
-...
-&gt;&gt;&gt; class B(object): __metaclass__ = M_B
-...
-&gt;&gt;&gt; class C(A,B): pass # Error message less specific under 2.2
-[...]
-TypeError: metaclass conflict: the metaclass of a derived class must
- be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-</blockquote>
-<p>The metatype conflict can be avoided by manually creating the needed
-metaclass for 'C':</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; M_AM_B = type(&quot;M_AM_B&quot;, (M_A,M_B), {})
-&gt;&gt;&gt; class C(A,B): __metaclass__ = M_AM_B
-...
-&gt;&gt;&gt; type(C)
-&lt;class 'M_AM_B'&gt;
-</pre>
-</blockquote>
-<p>The resolution of metatype conflicts becomes more complicated when
-you wish to &quot;inject&quot; additional metaclasses into a class, beyond
-those in its ancestors. As well, depending on the metaclasses of
-parent classes, redundant metaclasses can occur--both identical
-metaclasses in different ancestors and superclass/subclass
-relationships among metaclasses. The module [noconflict] is
-available to help users resolve these issues in a robust and
-automatic way (see Resources).</p>
-</blockquote>
-</div>
-<div class="section" id="conclusion">
-<h1><a name="conclusion">CONCLUSION</a></h1>
-<blockquote>
-There are quite a number of warnings and corner cases discussed in
-this article. Working with metaclasses requires a certain degree of
-trial-and-error before the behavior becomes wholly intuitive.
-However, the issues are by no means intractable--this fairly short
-article touches on most of the pitfalls. Play with the cases
-yourself. You will find, at the end of the day, that whole new
-realms of program generalization are available with metaclasses; the
-gains are well worth the few dangers.</blockquote>
-</div>
-<div class="section" id="resources">
-<h1><a name="resources">RESOURCES</a></h1>
-<blockquote>
-<p>We continue to recomment this useful book on metaclasses:</p>
-<blockquote>
-<em>Putting Metaclasses to Work</em> by Ira R. Forman, Scott Danforth,
-Addison-Wesley 1999</blockquote>
-<p>For metaclasses in Python specifically, Guido van Rossum's
-essay, <em>Unifying types and classes in Python 2.2</em> is useful:</p>
-<blockquote>
-<a class="reference" href="http://www.python.org/2.2/descrintro.html">http://www.python.org/2.2/descrintro.html</a></blockquote>
-<p>Raymond Hettinger has written an excellent article on the
--descriptor protocol- introducted in Python 2.2. Descriptors
-are a means to to alter the behavior of attribute/method
-access, which is an interesting programming technique in
-itself. But of particular value relative to this article is
-Hettinger's explanation of the lookup chain that underlies
-Python's concept of OOP:</p>
-<blockquote>
-<a class="reference" href="http://users.rcn.com/python/download/Descriptor.htm">http://users.rcn.com/python/download/Descriptor.htm</a></blockquote>
-<p>Michele's [noconflict] module is discussed in the online Active
-State Python Cookbook. This module lets users automatically resolve
-metatype conflicts.</p>
-<blockquote>
-<a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197</a></blockquote>
-<p>The Gnosis Utilities library contains a number of tools for
-working with metaclasses, generally within the [gnosis.magic]
-subpackage. You may download the last stable version of whole
-package from:</p>
-<blockquote>
-<a class="reference" href="http://gnosis.cx/download/Gnosis_Utils-current.tar.gz">http://gnosis.cx/download/Gnosis_Utils-current.tar.gz</a></blockquote>
-<p>Or browse the experimental branch, which includes a version of
-[noconflict] at:</p>
-<blockquote>
-<a class="reference" href="http://gnosis.cx/download/gnosis/">http://gnosis.cx/download/gnosis/</a></blockquote>
-<p>Coauthor Michele has written an article on the new method
-resolution order (MRO) algorithm in Python 2.3. While most
-programmers can remain blissfully ignorant on the details of
-the changes, it is worthwhile for all Python programmers to
-understand the concept of MRO--and perhaps have an inkling
-that better and worse approaches exist:</p>
-<blockquote>
-<a class="reference" href="http://www.python.org/2.3/mro.html">http://www.python.org/2.3/mro.html</a></blockquote>
-</blockquote>
-</div>
-<div class="section" id="about-the-authors">
-<h1><a name="about-the-authors">ABOUT THE AUTHORS</a></h1>
-<blockquote>
-<p><img alt="img_dqm.png" src="img_dqm.png" /></p>
-<p>David Mertz thought his brain would melt when he wrote about
-continuations or semi-coroutines, but he put the gooey mess
-back in his skull cavity and moved on to metaclasses. David
-may be reached at <a class="reference" href="mailto:mertz&#64;gnosis.cx">mertz&#64;gnosis.cx</a>; his life pored over at
-<a class="reference" href="http://gnosis.cx/publish/">http://gnosis.cx/publish/</a>. Suggestions and recommendations on
-this, past, or future, columns are welcomed. His book <em>Text
-Processing in Python</em> has a webpage at <a class="reference" href="http://gnosis.cx/TPiP/">http://gnosis.cx/TPiP/</a>.</p>
-<p><img alt="m-simionato.png" src="m-simionato.png" /></p>
-<p>Michele Simionato is a plain, ordinary, theoretical physicist
-who was driven to Python by a quantum fluctuation that could
-well have passed without consequences, had he not met David
-Mertz. Now he has been trapped in Python gravitational field.
-He will let his readers judge the final outcome. Michele can
-be reached at <a class="reference" href="http://www.phyast.pitt.edu/~micheles/">http://www.phyast.pitt.edu/~micheles/</a></p>
-</blockquote>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/meta/metatype.html b/pypers/meta/metatype.html
deleted file mode 100755
index f83b6bb..0000000
--- a/pypers/meta/metatype.html
+++ /dev/null
@@ -1,197 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.8: http://docutils.sourceforge.net/" />
-<title>SOLVING THE METACLASS CONFLICT</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="solving-the-metaclass-conflict">
-<h1 class="title">SOLVING THE METACLASS CONFLICT</h1>
-<div class="section" id="summary">
-<h1><a name="summary">Summary:</a></h1>
-<p>Any serious user of metaclasses has been bitten at least once by the
-infamous metaclass/metatype conflict. Here I give a general recipe to
-solve the problem, as well as some theory and some examples.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;noconflict.py&gt;
-
-def _generatemetaclass(bases,metas):
- &quot;&quot;&quot;Internal function called by inferred. 'bases' is tuple of base classes
- and 'metas' a tuple of metaclasses.&quot;&quot;&quot;
-
- metas=[m for m in metas if m is not type]
- trivial=lambda m: m is type or m in metas
- metabases=metas+[mb for mb in map(type,bases) if not trivial(mb)]
- metaname=&quot;_&quot;+''.join([m.__name__ for m in metabases])
- if not metabases: # trivial metabase
- return type
- elif len(metabases)==1: # single metabase
- return metabases[0]
- else: # multiple metabases
- # creates new metaclass,shift possible conflict to meta-metaclasses
- return type(metaname,tuple(metabases),{})
-
-def memoize(f):
- &quot;&quot;&quot;This closure remembers all f invocations&quot;&quot;&quot;
- argskw,result = [],[]
- def _(*args,**kw):
- akw=args,kw
- try: # returns a previously stored result
- return result[argskw.index(akw)]
- except ValueError: # there is no previously stored result
- argskw.append(akw) # update argskw
- result.append(f(*args,**kw)) # update result
- return result[-1] # return the new result
- _.argskw=argskw #makes the argskw list accessible outside
- _.result=result #makes the result list accessible outside
- return _
-
-_generatemetaclass=memoize(_generatemetaclass)
-
-def inferred(*metas):
- &quot;&quot;&quot;Class factory avoiding metatype conflicts: if the base classes have
- metaclasses conflicting within themselves or with the given metaclass,
- it automatically generates a compatible metaclass and instantiate the
- inferred class from it.&quot;&quot;&quot;
- return lambda n,b,d: _generatemetaclass(b,metas or (type,))(n,b,d)
-
-#&lt;/noconflict.py&gt;
-</pre>
-</blockquote>
-</div>
-<div class="section" id="discussion">
-<h1><a name="discussion">Discussion</a></h1>
-<p>I think that not too many programmers are familiar with metaclasses and
-metatype conflicts, therefore let me be pedagogical ;)</p>
-<p>The simplest case where a metatype conflict happens is the following.
-Consider a class <tt class="literal"><span class="pre">A</span></tt> with metaclass <tt class="literal"><span class="pre">M_A</span></tt> and a class <tt class="literal"><span class="pre">B</span></tt> with
-an independent metaclass <tt class="literal"><span class="pre">M_B</span></tt>; suppose we derive <tt class="literal"><span class="pre">C</span></tt> from <tt class="literal"><span class="pre">A</span></tt>
-and <tt class="literal"><span class="pre">B</span></tt>. The question is: what is the metaclass of <tt class="literal"><span class="pre">C</span></tt> ?
-Is it <tt class="literal"><span class="pre">M_A</span></tt> or <tt class="literal"><span class="pre">M_B</span></tt> ?</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M_A(type):
-... pass
-&gt;&gt;&gt; class M_B(type):
-... pass
-&gt;&gt;&gt; class A(object):
-... __metaclass__=M_A
-&gt;&gt;&gt; class B(object):
-... __metaclass__=M_B
-&gt;&gt;&gt; class C(A,B):
-... pass
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-</blockquote>
-<p>The correct answer (see the book &quot;Putting metaclasses to work&quot; for a
-thought discussion) is <tt class="literal"><span class="pre">M_C</span></tt>, where <tt class="literal"><span class="pre">M_C</span></tt> is a metaclass that inherits
-from <tt class="literal"><span class="pre">M_A</span></tt> and <tt class="literal"><span class="pre">M_B</span></tt>, as in the following graph, where instantiation
-is denoted by colon lines:</p>
-<blockquote>
-<pre class="literal-block">
-M_A M_B
- : \ / :
- : \ / :
- A M_C B
- \ : /
- \ : /
- C
-</pre>
-</blockquote>
-<p>However, Python is not that magic, and it does not automatically create
-<tt class="literal"><span class="pre">M_C</span></tt>. Instead, it raises a <tt class="literal"><span class="pre">TypeError</span></tt>, warning the programmer of
-the possible confusion. The metatype conflict can be avoided
-by assegning the correct metaclass to <tt class="literal"><span class="pre">C</span></tt> by hand:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M_AM_B(M_A,M_B): pass
-...
-&gt;&gt;&gt; class C(A,B):
-... __metaclass__=M_AM_B
-&gt;&gt;&gt; C,type(C)
-(&lt;class 'C'&gt;, &lt;class 'M_AM_B'&gt;)
-</pre>
-</blockquote>
-<p>In general, a class <tt class="literal"><span class="pre">A(B,</span> <span class="pre">C,</span> <span class="pre">D</span> <span class="pre">,</span> <span class="pre">...)</span></tt> can be generated without conflicts
-only if <tt class="literal"><span class="pre">type(A)</span></tt> is a subclass of each of <tt class="literal"><span class="pre">type(B),</span> <span class="pre">type(C),</span> <span class="pre">...</span></tt></p>
-<p>It is possible to automatically avoid conflicts, by defining a smart
-class factory that generates the correct metaclass by looking at the
-metaclasses of the base classes. This is done via the <tt class="literal"><span class="pre">inferred</span></tt>
-class factory, wich internally invokes the <tt class="literal"><span class="pre">_generatemetaclass</span></tt>
-function. When <tt class="literal"><span class="pre">_generatemetaclass</span></tt> is invoked with the same bases and
-the same metaclasses it should return the same metaclass. This is done by
-keeping a list of the generated metaclasses thanks to the <tt class="literal"><span class="pre">with_memory</span></tt>
-closure. Now, when <tt class="literal"><span class="pre">_generatemetaclass</span></tt> is invoked with the same arguments
-it returns the same metaclass.</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import sys; sys.path.append('.') # for doctest purposes
-&gt;&gt;&gt; from noconflict import inferred
-&gt;&gt;&gt; class C(A,B):
-... __metaclass__=inferred()
-&gt;&gt;&gt; C
-&lt;class 'C'&gt;
-&gt;&gt;&gt; type(C) # automatically generated metaclass
-&lt;class 'noconflict._M_AM_B'&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M_A(type): pass
-...
-&gt;&gt;&gt; class M_B(type): pass
-...
-&gt;&gt;&gt; class A: __metaclass__=M_A
-...
-&gt;&gt;&gt; class B: __metaclass__=M_B
-...
-&gt;&gt;&gt; class E(A,B):
-... __metaclass__=inferred()
-&gt;&gt;&gt; type(E)
-&lt;class 'noconflict._M_AM_B'&gt;
-&gt;&gt;&gt; class F(A,B):
-... __metaclass__=inferred()
-&gt;&gt;&gt; type(F)
-&lt;class 'noconflict._M_AM_B'&gt;
-&gt;&gt;&gt; type(E) is type(F)
-True
-</pre>
-</blockquote>
-<p>Another example where <tt class="literal"><span class="pre">inferred()</span></tt> can solve the conflict is the
-following:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(A):
-... __metaclass__=M_B
-Traceback (most recent call last):
- File &quot;&lt;string&gt;&quot;, line 1, in ?
-TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-</blockquote>
-<p>Here the problem is that since <tt class="literal"><span class="pre">D</span></tt> inherits from <tt class="literal"><span class="pre">A</span></tt>, its metaclass
-must inherit from <tt class="literal"><span class="pre">M_A</span></tt> and cannot be <tt class="literal"><span class="pre">M_B</span></tt>.</p>
-<p><tt class="literal"><span class="pre">inferred</span></tt> solves the problem by automatically inheriting both from
-<tt class="literal"><span class="pre">M_B</span></tt> and <tt class="literal"><span class="pre">M_A</span></tt>:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(A):
-... __metaclass__=inferred(M_B)
-&gt;&gt;&gt; type(D)
-&lt;class 'noconflict._M_BM_A'&gt;
-</pre>
-</blockquote>
-<p>Note: these examples here have been checked with doctest on Python 2.3b1.</p>
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="metatype.txt">View document source</a>.
-Generated on: 2003-06-06 22:08 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/mro/mro.html b/pypers/mro/mro.html
deleted file mode 100755
index 6788fad..0000000
--- a/pypers/mro/mro.html
+++ /dev/null
@@ -1,794 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>The Python 2.3 Method Resolution Order</title>
-<meta name="author" content="Michele Simionato" />
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="the-python-2-3-method-resolution-order">
-<h1 class="title">The Python 2.3 Method Resolution Order</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr><th class="docinfo-name">Version:</th>
-<td>1.4</td></tr>
-<tr><th class="docinfo-name">Author:</th>
-<td>Michele Simionato</td></tr>
-<tr class="field"><th class="docinfo-name">E-mail:</th><td class="field-body"><a class="reference" href="mailto:michelesimionato&#64;libero.it">michelesimionato&#64;libero.it</a></td>
-</tr>
-<tr><th class="docinfo-name">Address:</th>
-<td><pre class="address">
-Department of Physics and Astronomy
-210 Allen Hall Pittsburgh PA 15260 U.S.A.
-</pre>
-</td></tr>
-<tr class="field"><th class="docinfo-name">Home-page:</th><td class="field-body"><a class="reference" href="http://www.phyast.pitt.edu/~micheles/">http://www.phyast.pitt.edu/~micheles/</a></td>
-</tr>
-</tbody>
-</table>
-<div class="abstract topic">
-<p class="topic-title">Abstract</p>
-<p><em>This document is intended for Python programmers who want to
-understand the C3 Method Resolution Order used in Python 2.3.
-Although it is not intended for newbies, it is quite pedagogical with
-many worked out examples. I am not aware of other publicly available
-documents with the same scope, therefore it should be useful.</em></p>
-</div>
-<p>Disclaimer:</p>
-<blockquote>
-I donate this document to the Python Software Foundation, under the
-Python 2.3 license. As usual in these circumstances, I warn the
-reader that what follows <em>should</em> be correct, but I don't give any
-warranty. Use it at your own risk and peril!</blockquote>
-<p>Acknowledgments:</p>
-<blockquote>
-All the people of the Python mailing list who sent me their support.
-Paul Foley who pointed out various imprecisions and made me to add the
-part on local precedence ordering. David Goodger for help with the
-formatting in reStructuredText. David Mertz for help with the editing.
-Joan G. Stark for the pythonic pictures. Finally, Guido van Rossum who
-enthusiastically added this document to the official Python 2.3 home-page.</blockquote>
-<hr />
-<blockquote>
-<pre class="literal-block">
- .-=-. .--.
- __ .' '. / &quot; )
- _ .' '. / .-. \ / .-'\
- ( \ / .-. \ / / \ \ / / ^
- \ `-` / \ `-' / \ `-` /
-jgs`-.-` '.____.' `.____.'
-</pre>
-</blockquote>
-<div class="section" id="the-beginning">
-<h1><a name="the-beginning">The beginning</a></h1>
-<blockquote>
-<em>Felix qui potuit rerum cognoscere causas</em> -- Virgilius</blockquote>
-<p>Everything started with a post by Samuele Pedroni to the Python
-development mailing list <a class="footnote-reference" href="#id4" id="id1" name="id1">[1]</a>. In his post, Samuele showed that the
-Python 2.2 method resolution order is not monotonic and he proposed to
-replace it with the C3 method resolution order. Guido agreed with his
-arguments and therefore now Python 2.3 uses C3. The C3 method itself
-has nothing to do with Python, since it was invented by people working
-on Dylan and it is described in a paper intended for lispers <a class="footnote-reference" href="#id5" id="id2" name="id2">[2]</a>. The
-present paper gives a (hopefully) readable discussion of the C3
-algorithm for Pythonistas who want to understand the reasons for the
-change.</p>
-<p>First of all, let me point out that what I am going to say only applies
-to the <em>new style classes</em> introduced in Python 2.2: <em>classic classes</em>
-maintain their old method resolution order, depth first and then left to
-right. Therefore, there is no breaking of old code for classic classes;
-and even if in principle there could be breaking of code for Python 2.2
-new style classes, in practice the cases in which the C3 resolution
-order differs from the Python 2.2 method resolution order are so rare
-that no real breaking of code is expected. Therefore:</p>
-<blockquote>
-<em>Don't be scared!</em></blockquote>
-<p>Moreover, unless you make strong use of multiple inheritance and you
-have non-trivial hierarchies, you don't need to understand the C3
-algorithm, and you can easily skip this paper. On the other hand, if
-you really want to know how multiple inheritance works, then this paper
-is for you. The good news is that things are not as complicated as you
-might expect.</p>
-<p>Let me begin with some basic definitions.</p>
-<ol class="arabic simple">
-<li>Given a class C in a complicated multiple inheritance hierarchy, it
-is a non-trivial task to specify the order in which methods are
-overridden, i.e. to specify the order of the ancestors of C.</li>
-<li>The list of the ancestors of a class C, including the class itself,
-ordered from the nearest ancestor to the furthest, is called the
-class precedence list or the <em>linearization</em> of C.</li>
-<li>The <em>Method Resolution Order</em> (MRO) is the set of rules that
-construct the linearization. In the Python literature, the idiom
-&quot;the MRO of C&quot; is also used as a synonymous for the linearization of
-the class C.</li>
-<li>For instance, in the case of single inheritance hierarchy, if C is a
-subclass of C1, and C1 is a subclass of C2, then the linearization of
-C is simply the list [C, C1 , C2]. However, with multiple
-inheritance hierarchies, the construction of the linearization is
-more cumbersome, since it is more difficult to construct a
-linearization that respects <em>local precedence ordering</em> and
-<em>monotonicity</em>.</li>
-<li>I will discuss the local precedence ordering later, but I can give
-the definition of monotonicity here. A MRO is monotonic when the
-following is true: <em>if C1 precedes C2 in the linearization of C,
-then C1 precedes C2 in the linearization of any subclass of C</em>.
-Otherwise, the innocuous operation of deriving a new class could
-change the resolution order of methods, potentially introducing very
-subtle bugs. Examples where this happens will be shown later.</li>
-<li>Not all classes admit a linearization. There are cases, in
-complicated hierarchies, where it is not possible to derive a class
-such that its linearization respects all the desired properties.</li>
-</ol>
-<p>Here I give an example of this situation. Consider the hierarchy</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; O = object
-&gt;&gt;&gt; class X(O): pass
-&gt;&gt;&gt; class Y(O): pass
-&gt;&gt;&gt; class A(X,Y): pass
-&gt;&gt;&gt; class B(Y,X): pass
-</pre>
-</blockquote>
-<p>which can be represented with the following inheritance graph, where I
-have denoted with O the <tt class="literal"><span class="pre">object</span></tt> class, which is the beginning of any
-hierarchy for new style classes:</p>
-<blockquote>
-<pre class="literal-block">
- -----------
-| |
-| O |
-| / \ |
- - X Y /
- | / | /
- | / |/
- A B
- \ /
- ?
-</pre>
-</blockquote>
-<p>In this case, it is not possible to derive a new class C from A and B,
-since X precedes Y in A, but Y precedes X in B, therefore the method
-resolution order would be ambiguous in C.</p>
-<p>Python 2.3 raises an exception in this situation (TypeError: MRO
-conflict among bases Y, X) forbidding the naive programmer from creating
-ambiguous hierarchies. Python 2.2 instead does not raise an exception,
-but chooses an <em>ad hoc</em> ordering (CABXYO in this case).</p>
-<hr />
-<blockquote>
-<pre class="literal-block">
- _ .-=-. .-==-.
- { } __ .' O o '. / -&lt;' )
- { } .' O'. / o .-. O \ / .--v`
- { } / .-. o\ /O / \ o\ /O /
- \ `-` / \ O`-'o / \ O`-`o /
-jgs `-.-` '.____.' `.____.'
-</pre>
-</blockquote>
-</div>
-<div class="section" id="the-c3-method-resolution-order">
-<h1><a name="the-c3-method-resolution-order">The C3 Method Resolution Order</a></h1>
-<p>Let me introduce a few simple notations which will be useful for the
-following discussion. I will use the shortcut notation</p>
-<blockquote>
-C1 C2 ... CN</blockquote>
-<p>to indicate the list of classes [C1, C2, ... , CN].</p>
-<p>The <em>head</em> of the list is its first element:</p>
-<blockquote>
-head = C1</blockquote>
-<p>whereas the <em>tail</em> is the rest of the list:</p>
-<blockquote>
-tail = C2 ... CN.</blockquote>
-<p>I shall also use the notation</p>
-<blockquote>
-C + (C1 C2 ... CN) = C C1 C2 ... CN</blockquote>
-<p>to denote the sum of the lists [C] + [C1, C2, ... ,CN].</p>
-<p>Now I can explain how the MRO works in Python 2.3.</p>
-<p>Consider a class C in a multiple inheritance hierarchy, with C
-inheriting from the base classes B1, B2, ... , BN. We want to
-compute the linearization L[C] of the class C. The rule is the
-following:</p>
-<blockquote>
-<em>the linearization of C is the sum of C plus the merge of the
-linearizations of the parents and the list of the parents.</em></blockquote>
-<p>In symbolic notation:</p>
-<blockquote>
-L[C(B1 ... BN)] = C + merge(L[B1] ... L[BN], B1 ... BN)</blockquote>
-<p>In particular, if C is the <tt class="literal"><span class="pre">object</span></tt> class, which has no parents, the
-linearization is trivial:</p>
-<blockquote>
-L[object] = object.</blockquote>
-<p>However, in general one has to compute the merge according to the following
-prescription:</p>
-<blockquote>
-<em>take the head of the first list, i.e L[B1][0]; if this head is not in
-the tail of any of the other lists, then add it to the linearization
-of C and remove it from the lists in the merge, otherwise look at the
-head of the next list and take it, if it is a good head. Then repeat
-the operation until all the class are removed or it is impossible to
-find good heads. In this case, it is impossible to construct the
-merge, Python 2.3 will refuse to create the class C and will raise an
-exception.</em></blockquote>
-<p>This prescription ensures that the merge operation <em>preserves</em> the
-ordering, if the ordering can be preserved. On the other hand, if the
-order cannot be preserved (as in the example of serious order
-disagreement discussed above) then the merge cannot be computed.</p>
-<p>The computation of the merge is trivial if C has only one parent
-(single inheritance); in this case</p>
-<blockquote>
-L[C(B)] = C + merge(L[B],B) = C + L[B]</blockquote>
-<p>However, in the case of multiple inheritance things are more cumbersome
-and I don't expect you can understand the rule without a couple of
-examples ;-)</p>
-<hr />
-<blockquote>
-<pre class="literal-block">
- .-'-.
- /' `\
- /' _.-.-._ `\
- | (|) (|) |
- | \__&quot;__/ |
- \ |v.v| /
- \ | | | /
- `\ |=^-| /'
- `|=-=|'
- | - |
- |= |
- |-=-|
- _.-=-=|= -|=-=-._
- ( |___| )
- ( `-=-=-=-=-=-=-=-` )
- (`-=-=-=-=-=-=-=-=-`)
- (`-=-=-=-=-=-=-=-=-`)
- (`-=-=-=-=-=-=-=-`)
- (`-=-=-=-=-=-=-`)
-jgs `-=-=-=-=-=-=-`
-</pre>
-</blockquote>
-</div>
-<div class="section" id="examples">
-<h1><a name="examples">Examples</a></h1>
-<p>First example. Consider the following hierarchy:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; O = object
-&gt;&gt;&gt; class F(O): pass
-&gt;&gt;&gt; class E(O): pass
-&gt;&gt;&gt; class D(O): pass
-&gt;&gt;&gt; class C(D,F): pass
-&gt;&gt;&gt; class B(D,E): pass
-&gt;&gt;&gt; class A(B,C): pass
-</pre>
-</blockquote>
-<p>In this case the inheritance graph can be drawn as</p>
-<blockquote>
-<pre class="literal-block">
- 6
- ---
-Level 3 | O | (more general)
- / --- \
- / | \ |
- / | \ |
- / | \ |
- --- --- --- |
-Level 2 3 | D | 4| E | | F | 5 |
- --- --- --- |
- \ \ _ / | |
- \ / \ _ | |
- \ / \ | |
- --- --- |
-Level 1 1 | B | | C | 2 |
- --- --- |
- \ / |
- \ / \ /
- ---
-Level 0 0 | A | (more specialized)
- ---
-</pre>
-</blockquote>
-<p>The linearizations of O,D,E and F are trivial:</p>
-<blockquote>
-<pre class="literal-block">
-L[O] = O
-L[D] = D O
-L[E] = E O
-L[F] = F O
-</pre>
-</blockquote>
-<p>The linearization of B can be computed as</p>
-<blockquote>
-<pre class="literal-block">
-L[B] = B + merge(DO, EO, DE)
-</pre>
-</blockquote>
-<p>We see that D is a good head, therefore we take it and we are reduced to
-compute <tt class="literal"><span class="pre">merge(O,EO,E)</span></tt>. Now O is not a good head, since it is in the
-tail of the sequence EO. In this case the rule says that we have to
-skip to the next sequence. Then we see that E is a good head; we take
-it and we are reduced to compute <tt class="literal"><span class="pre">merge(O,O)</span></tt> which gives O. Therefore</p>
-<blockquote>
-<pre class="literal-block">
-L[B] = B D E O
-</pre>
-</blockquote>
-<p>Using the same procedure one finds:</p>
-<blockquote>
-<pre class="literal-block">
-L[C] = C + merge(DO,FO,DF)
- = C + D + merge(O,FO,F)
- = C + D + F + merge(O,O)
- = C D F O
-</pre>
-</blockquote>
-<p>Now we can compute:</p>
-<blockquote>
-<pre class="literal-block">
-L[A] = A + merge(BDEO,CDFO,BC)
- = A + B + merge(DEO,CDFO,C)
- = A + B + C + merge(DEO,DFO)
- = A + B + C + D + merge(EO,FO)
- = A + B + C + D + E + merge(O,FO)
- = A + B + C + D + E + F + merge(O,O)
- = A B C D E F O
-</pre>
-</blockquote>
-<p>In this example, the linearization is ordered in a pretty nice way
-according to the inheritance level, in the sense that lower levels (i.e.
-more specialized classes) have higher precedence (see the inheritance
-graph). However, this is not the general case.</p>
-<p>I leave as an exercise for the reader to compute the linearization for
-my second example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; O = object
-&gt;&gt;&gt; class F(O): pass
-&gt;&gt;&gt; class E(O): pass
-&gt;&gt;&gt; class D(O): pass
-&gt;&gt;&gt; class C(D,F): pass
-&gt;&gt;&gt; class B(E,D): pass
-&gt;&gt;&gt; class A(B,C): pass
-</pre>
-</blockquote>
-<p>The only difference with the previous example is the change B(D,E) --&gt;
-B(E,D); however even such a little modification completely changes the
-ordering of the hierarchy</p>
-<blockquote>
-<pre class="literal-block">
- 6
- ---
-Level 3 | O |
- / --- \
- / | \
- / | \
- / | \
- --- --- ---
-Level 2 2 | E | 4 | D | | F | 5
- --- --- ---
- \ / \ /
- \ / \ /
- \ / \ /
- --- ---
-Level 1 1 | B | | C | 3
- --- ---
- \ /
- \ /
- ---
-Level 0 0 | A |
- ---
-</pre>
-</blockquote>
-<p>Notice that the class E, which is in the second level of the hierarchy,
-precedes the class C, which is in the first level of the hierarchy, i.e.
-E is more specialized than C, even if it is in a higher level.</p>
-<p>A lazy programmer can obtain the MRO directly from Python 2.2, since in
-this case it coincides with the Python 2.3 linearization. It is enough
-to invoke the .mro() method of class A:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; A.mro()
-(&lt;class '__main__.A'&gt;, &lt;class '__main__.B'&gt;, &lt;class '__main__.E'&gt;,
-&lt;class '__main__.C'&gt;, &lt;class '__main__.D'&gt;, &lt;class '__main__.F'&gt;,
-&lt;type 'object'&gt;)
-</pre>
-</blockquote>
-<p>Finally, let me consider the example discussed in the first section,
-involving a serious order disagreement. In this case, it is
-straightforward to compute the linearizations of O, X, Y, A and B:</p>
-<blockquote>
-<pre class="literal-block">
-L[O] = 0
-L[X] = X O
-L[Y] = Y O
-L[A] = A X Y O
-L[B] = B Y X O
-</pre>
-</blockquote>
-<p>However, it is impossible to compute the linearization for a class C
-that inherits from A and B:</p>
-<blockquote>
-<pre class="literal-block">
-L[C] = C + merge(AXYO, BYXO, AB)
- = C + A + merge(XYO, BYXO, B)
- = C + A + B + merge(XYO, YXO)
-</pre>
-</blockquote>
-<p>At this point we cannot merge the lists XYO and YXO, since X is in the
-tail of YXO whereas Y is in the tail of XYO: therefore there are no
-good heads and the C3 algorithm stops. Python 2.3 raises an error and
-refuses to create the class C.</p>
-<hr />
-<blockquote>
-<pre class="literal-block">
- __
- (\ .-. .-. /_&quot;)
- \\_//^\\_//^\\_//
-jgs `&quot;` `&quot;` `&quot;`
-</pre>
-</blockquote>
-</div>
-<div class="section" id="bad-method-resolution-orders">
-<h1><a name="bad-method-resolution-orders">Bad Method Resolution Orders</a></h1>
-<p>A MRO is <em>bad</em> when it breaks such fundamental properties as local
-precedence ordering and monotonicity. In this section, I will show
-that both the MRO for classic classes and the MRO for new style classes
-in Python 2.2 are bad.</p>
-<p>It is easier to start with the local precedence ordering. Consider the
-following example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; F=type('Food',(),{'remember2buy':'spam'})
-&gt;&gt;&gt; E=type('Eggs',(F,),{'remember2buy':'eggs'})
-&gt;&gt;&gt; G=type('GoodFood',(F,E),{}) # under Python 2.3 this is an error!
-</pre>
-</blockquote>
-<p>with inheritance diagram</p>
-<blockquote>
-<pre class="literal-block">
- O
- |
-(buy spam) F
- | \
- | E (buy eggs)
- | /
- G
-
- (buy eggs or spam ?)
-</pre>
-</blockquote>
-<p>We see that class G inherits from F and E, with F <em>before</em> E: therefore
-we would expect the attribute <em>G.remember2buy</em> to be inherited by
-<em>F.rembermer2buy</em> and not by <em>E.remember2buy</em>: nevertheless Python 2.2
-gives</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; G.remember2buy
-'eggs'
-</pre>
-</blockquote>
-<p>This is a breaking of local precedence ordering since the order in the
-local precedence list, i.e. the list of the parents of G, is not
-preserved in the Python 2.2 linearization of G:</p>
-<blockquote>
-<pre class="literal-block">
-L[G,P22]= G E F object # F *follows* E
-</pre>
-</blockquote>
-<p>One could argue that the reason why F follows E in the Python 2.2
-linearization is that F is less specialized than E, since F is the
-superclass of E; nevertheless the breaking of local precedence ordering
-is quite non-intuitive and error prone. This is particularly true since
-it is a different from old style classes:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class F: remember2buy='spam'
-&gt;&gt;&gt; class E(F): remember2buy='eggs'
-&gt;&gt;&gt; class G(F,E): pass
-&gt;&gt;&gt; G.remember2buy
-'spam'
-</pre>
-</blockquote>
-<p>In this case the MRO is GFEF and the local precedence ordering is
-preserved.</p>
-<p>As a general rule, hierarchies such as the previous one should be
-avoided, since it is unclear if F should override E or viceversa.
-Python 2.3 solves the ambiguity by raising an exception in the creation
-of class G, effectively stopping the programmer from generating
-ambiguous hierarchies. The reason for that is that the C3 algorithm
-fails when the merge</p>
-<blockquote>
-<pre class="literal-block">
-merge(FO,EFO,FE)
-</pre>
-</blockquote>
-<p>cannot be computed, because F is in the tail of EFO and E is in the tail
-of FE.</p>
-<p>The real solution is to design a non-ambiguous hierarchy, i.e. to derive
-G from E and F (the more specific first) and not from F and E; in this
-case the MRO is GEF without any doubt.</p>
-<blockquote>
-<pre class="literal-block">
- O
- |
- F (spam)
- / |
-(eggs) E |
- \ |
- G
- (eggs, no doubt)
-</pre>
-</blockquote>
-<p>Python 2.3 forces the programmer to write good hierarchies (or, at
-least, less error-prone ones).</p>
-<p>On a related note, let me point out that the Python 2.3 algorithm is
-smart enough to recognize obvious mistakes, as the duplication of
-classes in the list of parents:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A(object): pass
-&gt;&gt;&gt; class C(A,A): pass # error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: duplicate base class A
-</pre>
-</blockquote>
-<p>Python 2.2 (both for classic classes and new style classes) in this
-situation, would not raise any exception.</p>
-<p>Finally, I would like to point out two lessons we have learned from this
-example:</p>
-<ol class="arabic simple">
-<li>despite the name, the MRO determines the resolution order of
-attributes, not only of methods;</li>
-<li>the default food for Pythonistas is spam ! (but you already knew
-that ;-)</li>
-</ol>
-<hr />
-<blockquote>
-<pre class="literal-block">
- __
- (\ .-. .-. /_&quot;)
- \\_//^\\_//^\\_//
-jgs `&quot;` `&quot;` `&quot;`
-</pre>
-</blockquote>
-<p>Having discussed the issue of local precedence ordering, let me now
-consider the issue of monotonicity. My goal is to show that neither the
-MRO for classic classes nor that for Python 2.2 new style classes is
-monotonic.</p>
-<p>To prove that the MRO for classic classes is non-monotonic is rather
-trivial, it is enough to look at the diamond diagram:</p>
-<blockquote>
-<pre class="literal-block">
- C
- / \
- / \
-A B
- \ /
- \ /
- D
-</pre>
-</blockquote>
-<p>One easily discerns the inconsistency:</p>
-<blockquote>
-<pre class="literal-block">
-L[B,P21] = B C # B precedes C : B's methods win
-L[D,P21] = D A C B C # B follows C : C's methods win!
-</pre>
-</blockquote>
-<p>On the other hand, there are no problems with the Python 2.2 and 2.3
-MROs, they give both</p>
-<blockquote>
-<pre class="literal-block">
-L[D] = D A B C
-</pre>
-</blockquote>
-<p>Guido points out in his essay <a class="footnote-reference" href="#id6" id="id3" name="id3">[3]</a> that the classic MRO is not so bad in
-practice, since one can typically avoids diamonds for classic classes.
-But all new style classes inherit from <tt class="literal"><span class="pre">object</span></tt>, therefore diamonds are
-unavoidable and inconsistencies shows up in every multiple inheritance
-graph.</p>
-<p>The MRO of Python 2.2 makes breaking monotonicity difficult, but not
-impossible. The following example, originally provided by Samuele
-Pedroni, shows that the MRO of Python 2.2 is non-monotonic:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A(object): pass
-&gt;&gt;&gt; class B(object): pass
-&gt;&gt;&gt; class C(object): pass
-&gt;&gt;&gt; class D(object): pass
-&gt;&gt;&gt; class E(object): pass
-&gt;&gt;&gt; class K1(A,B,C): pass
-&gt;&gt;&gt; class K2(D,B,E): pass
-&gt;&gt;&gt; class K3(D,A): pass
-&gt;&gt;&gt; class Z(K1,K2,K3): pass
-</pre>
-</blockquote>
-<p>Here are the linearizations according to the C3 MRO (the reader should
-verify these linearizations as an exercise and draw the inheritance
-diagram ;-)</p>
-<blockquote>
-<pre class="literal-block">
-L[A] = A O
-L[B] = B O
-L[C] = C O
-L[D] = D O
-L[E] = E O
-L[K1]= K1 A B C O
-L[K2]= K2 D B E O
-L[K3]= K3 D A O
-L[Z] = Z K1 K2 K3 D A B C E O
-</pre>
-</blockquote>
-<p>Python 2.2 gives exactly the same linearizations for A, B, C, D, E, K1,
-K2 and K3, but a different linearization for Z:</p>
-<blockquote>
-<pre class="literal-block">
-L[Z,P22] = Z K1 K3 A K2 D B C E O
-</pre>
-</blockquote>
-<p>It is clear that this linearization is <em>wrong</em>, since A comes before D
-whereas in the linearization of K3 A comes <em>after</em> D. In other words, in
-K3 methods derived by D override methods derived by A, but in Z, which
-still is a subclass of K3, methods derived by A override methods derived
-by D! This is a violation of monotonicity. Moreover, the Python 2.2
-linearization of Z is also inconsistent with local precedence ordering,
-since the local precedence list of the class Z is [K1, K2, K3] (K2
-precedes K3), whereas in the linearization of Z K2 <em>follows</em> K3. These
-problems explain why the 2.2 rule has been dismissed in favor of the C3
-rule.</p>
-<hr />
-<blockquote>
-<pre class="literal-block">
- __
- (\ .-. .-. .-. .-. .-. .-. .-. .-. /_&quot;)
- \\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//
-jgs `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;`
-</pre>
-</blockquote>
-</div>
-<div class="section" id="the-end">
-<h1><a name="the-end">The end</a></h1>
-<p>This section is for the impatient reader, who skipped all the previous
-sections and jumped immediately to the end. This section is for the
-lazy programmer too, who didn't want to exercise her/his brain.
-Finally, it is for the programmer with some hubris, otherwise s/he would
-not be reading a paper on the C3 method resolution order in multiple
-inheritance hierarchies ;-) These three virtues taken all together (and
-<em>not</em> separately) deserve a prize: the prize is a short Python 2.2
-script that allows you to compute the 2.3 MRO without risk to your
-brain. Simply change the last line to play with the various examples I
-have discussed in this paper.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;mro.py&gt;
-
-&quot;&quot;&quot;C3 algorithm by Samuele Pedroni (with readability enhanced by me).&quot;&quot;&quot;
-
-class __metaclass__(type):
- &quot;All classes are metamagically modified to be nicely printed&quot;
- __repr__ = lambda cls: cls.__name__
-
-class ex_2:
- &quot;Serious order disagreement&quot; #From Guido
- class O: pass
- class X(O): pass
- class Y(O): pass
- class A(X,Y): pass
- class B(Y,X): pass
- try:
- class Z(A,B): pass #creates Z(A,B) in Python 2.2
- except TypeError:
- pass # Z(A,B) cannot be created in Python 2.3
-
-class ex_5:
- &quot;My first example&quot;
- class O: pass
- class F(O): pass
- class E(O): pass
- class D(O): pass
- class C(D,F): pass
- class B(D,E): pass
- class A(B,C): pass
-
-class ex_6:
- &quot;My second example&quot;
- class O: pass
- class F(O): pass
- class E(O): pass
- class D(O): pass
- class C(D,F): pass
- class B(E,D): pass
- class A(B,C): pass
-
-class ex_9:
- &quot;Difference between Python 2.2 MRO and C3&quot; #From Samuele
- class O: pass
- class A(O): pass
- class B(O): pass
- class C(O): pass
- class D(O): pass
- class E(O): pass
- class K1(A,B,C): pass
- class K2(D,B,E): pass
- class K3(D,A): pass
- class Z(K1,K2,K3): pass
-
-def merge(seqs):
- print '\n\nCPL[%s]=%s' % (seqs[0][0],seqs),
- res = []; i=0
- while 1:
- nonemptyseqs=[seq for seq in seqs if seq]
- if not nonemptyseqs: return res
- i+=1; print '\n',i,'round: candidates...',
- for seq in nonemptyseqs: # find merge candidates among seq heads
- cand = seq[0]; print ' ',cand,
- nothead=[s for s in nonemptyseqs if cand in s[1:]]
- if nothead: cand=None #reject candidate
- else: break
- if not cand: raise &quot;Inconsistent hierarchy&quot;
- res.append(cand)
- for seq in nonemptyseqs: # remove cand
- if seq[0] == cand: del seq[0]
-
-def mro(C):
- &quot;Compute the class precedence list (mro) according to C3&quot;
- return merge([[C]]+map(mro,C.__bases__)+[list(C.__bases__)])
-
-def print_mro(C):
- print '\nMRO[%s]=%s' % (C,mro(C))
- print '\nP22 MRO[%s]=%s' % (C,C.mro())
-
-print_mro(ex_9.Z)
-
-#&lt;/mro.py&gt;
-</pre>
-</blockquote>
-<p>That's all folks,</p>
-<blockquote>
-enjoy !</blockquote>
-<hr />
-<blockquote>
-<pre class="literal-block">
- __
- (&quot;_\ .-. .-. .-. .-. .-. .-. .-. .-. /)
- \\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//
-jgs `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;`
-</pre>
-</blockquote>
-</div>
-<div class="section" id="resources">
-<h1><a name="resources">Resources</a></h1>
-<table class="footnote" frame="void" id="id4" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1" name="id4">[1]</a></td><td>The thread on python-dev started by Samuele Pedroni:
-<a class="reference" href="http://mail.python.org/pipermail/python-dev/2002-October/029035.html">http://mail.python.org/pipermail/python-dev/2002-October/029035.html</a></td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id5" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id2" name="id5">[2]</a></td><td>The paper <em>A Monotonic Superclass Linearization for Dylan</em>:
-<a class="reference" href="http://www.webcom.com/haahr/dylan/linearization-oopsla96.html">http://www.webcom.com/haahr/dylan/linearization-oopsla96.html</a></td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id6" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id3" name="id6">[3]</a></td><td>Guido van Rossum's essay, <em>Unifying types and classes in Python 2.2</em>:
-<a class="reference" href="http://www.python.org/2.2.2/descrintro.html">http://www.python.org/2.2.2/descrintro.html</a></td></tr>
-</tbody>
-</table>
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="mro.txt">View document source</a>.
-Generated on: 2003-11-17 04:32 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/optparse/invoice.html b/pypers/optparse/invoice.html
deleted file mode 100755
index 4c7de9a..0000000
--- a/pypers/optparse/invoice.html
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title></title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-<p>Invoice for beehive KG (optparse article)</p>
-<p>From:</p>
-<pre class="literal-block">
-Michele Simionato, Ph. D.
-Via Nervi 2
-00055 Ladispoli (ROMA)
-Telefono: 06 99229171
-Codice Fiscale: SMNMHL69D11F241A
-Partita IVA: 07905191008
-</pre>
-<p>To:</p>
-<pre class="literal-block">
-beehive KG
-Neues Kranzler Eck
-Kurfuerstendamm 21
-
-D - 10719 Berlin
-Germany
-</pre>
-<p>For:</p>
-<pre class="literal-block">
-Article optparse published in Py magazine
-</pre>
-<p>Amount:</p>
-<blockquote>
-Euro 97,02</blockquote>
-<p>My Bank info:</p>
-<pre class="literal-block">
-Cassa di Risparmio di Venezia
-Filiale di Pianiga
-Via Roma 1
-ITALY
-
-ABI: C 06345
-CAB: 36230
-Account: 0700075870H
-Code swift/bic: CVCEIT2V
-IBAN: IT47 C063 4536 2300 7400 0758 70H
-</pre>
-<dl>
-<dt>Signed</dt>
-<dd>Michele Simionato</dd>
-<dt>Date</dt>
-<dd>31 Aug 2004</dd>
-</dl>
-</div>
-</body>
-</html>
diff --git a/pypers/optparse/paper.html b/pypers/optparse/paper.html
deleted file mode 100755
index a22df52..0000000
--- a/pypers/optparse/paper.html
+++ /dev/null
@@ -1,453 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.1: http://docutils.sourceforge.net/" />
-<title>The optparse module: writing command-line tools the easy way</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="the-optparse-module-writing-command-line-tools-the-easy-way">
-<h1 class="title">The optparse module: writing command-line tools the easy way</h1>
-<blockquote>
-<table class="field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">Status:</th><td class="field-body">Draft</td>
-</tr>
-<tr class="field"><th class="field-name">Author:</th><td class="field-body">Michele Simionato</td>
-</tr>
-<tr class="field"><th class="field-name">E-mail:</th><td class="field-body"><a class="reference" href="mailto:michele.simionato&#64;partecs.com">michele.simionato&#64;partecs.com</a></td>
-</tr>
-<tr class="field"><th class="field-name">Date:</th><td class="field-body">May 2004</td>
-</tr>
-</tbody>
-</table>
-</blockquote>
-<p><em>The optparse module is a powerful, flexible, extensible, easy-to-use
-command-line parsing library for Python. Using optparse, you can add
-intelligent, sophisticated handling of command-line options to your
-scripts with very little overhead.</em> -- Greg Ward, optparse author</p>
-<div class="section" id="introduction">
-<h1><a name="introduction">Introduction</a></h1>
-<p>Once upon a time, when graphic interfaces were still to be dreamed
-about, command-line tools were the body and the soul of all programming
-tools. Many years have passed since then, but some things have not
-changed: command-line tools are still fast, efficient, portable, easy
-to use and - more importantly - reliable. You can count on them.
-You can expect command-line scripts to work in any situation,
-during the installation phase, in a situation of disaster recovery, when
-your window manager breaks down and even in systems with severe
-memory/hardware constraints. When you really need them, command-line
-tools are always there.</p>
-<p>Hence, it is important for a programming language - especially
-one that wants to be called a &quot;scripting&quot; language - to provide
-facilities to help the programmer in the task of writing command-line
-tools. For a long time Python support for this kind of tasks has
-been provided by the``getopt`` module. I have never
-been particularly fond of <tt class="literal"><span class="pre">getopt</span></tt>, since it required
-a sensible amount of coding even for the parsing of simple
-command-lines. However, with the coming of Python 2.3 the situation
-has changed: thanks to the great job of Greg Ward (the author of
-<tt class="literal"><span class="pre">optparse</span></tt> a.k.a. <tt class="literal"><span class="pre">Optik</span></tt>) now the Python programmer
-has at her disposal (in the standard library and not as an
-add-on module) a fully fledged Object Oriented API for
-command-line arguments parsing, which makes writing Unix-style
-command-line tools easy, efficient and fast.</p>
-<p>The only disadvantage of <tt class="literal"><span class="pre">optparse</span></tt> is that it is
-sophisticated tool, which requires some time to be fully mastered.
-The purpose of this paper is to help the reader to rapidly get the
-10% of the features of <tt class="literal"><span class="pre">optparse</span></tt> that she will use in the 90% of
-the cases. Taking as an example a real life application - a search and
-replace tool - I will guide the reader through (some of) the wonders
-of <tt class="literal"><span class="pre">optparse</span></tt>. Also, I will show some trick that will make your life
-with <tt class="literal"><span class="pre">optparse</span></tt> much happier.
-This paper is intended for both Unix and
-Windows programmers - actually I will argue that Windows programmers
-need <tt class="literal"><span class="pre">optparse</span></tt> even more than Unix programmers; it does not
-require any particular expertise to be fully appreciated.</p>
-</div>
-<div class="section" id="a-simple-example">
-<h1><a name="a-simple-example">A simple example</a></h1>
-<p>I will take as pedagogical example a little tool I wrote some time ago,
-a multiple files search and replace tool. I needed it because I am
-not always working under Unix, and I do not always have sed/awk or
-even Emacs installed, so it made sense to have this
-little Python script in my toolbox. It is only few lines long,
-it can always be modified and extended with a minimal effort,
-works on every platform (including my PDA) and has the advantage
-of being completely command-line driven:
-it does not require to have any graphics library installed
-and I can use it when I work on a remote machine via ssh.</p>
-<p>The tool takes a bunch of files and replace a given regular expression
-everywhere in-place; moreover, it saves a backup copy of the original
-un-modified files and give the option to recover
-them when I want to. Of course, all of this can be done more efficiently
-in the Unix world with specialized tools, but those tools are written
-in C and they are not as easily customizable as a Python script, that
-you may change in real time to suit your needs. So, it makes sense
-to write this kind of utilities in Python, and actually many people
-(including myself) are actively replacing some Unix commands and bash
-scripts with Python scripts. In real life, I have extended a lot
-the minimal tool that I describe here, and I continue to tune it as
-needed. For instance, you can make it to work recursively and/or on
-remote directories.</p>
-<p>As a final note, let me notice that I find <tt class="literal"><span class="pre">optparse</span></tt>
-to be much more useful in the Windows world than in the Unix/Linux/Mac OS X
-world. The reason is that the pletora
-of pretty good command-line tools which are available under Unix are
-missing in the Windows environment, or do not have a satisfactory
-equivalent. Therefore,
-it makes sense to write a personal collection of command-line scripts
-for your more common task, if you need to work on many platforms and
-portability is an important requirement.
-Using Python and <tt class="literal"><span class="pre">optparse</span></tt>, you may write your own scripts
-once and having them to run on every platform running Python,
-which means in practice any traditional platform and increasingly
-more of the non-traditional ones - Python is spreading into the
-embedded market too, including PDA's, cellular phones, and more.</p>
-</div>
-<div class="section" id="the-unix-philosophy-for-command-line-arguments">
-<h1><a name="the-unix-philosophy-for-command-line-arguments">The Unix philosophy for command-line arguments</a></h1>
-<p>In order to understand how <tt class="literal"><span class="pre">optparse</span></tt> works, it is essential
-to understand the Unix philosophy about command-lines arguments.
-As Greg Ward puts it:</p>
-<p><em>The purpose of optparse is to make it very easy to provide the
-most standard, obvious, straightforward, and user-friendly user
-interface for Unix command-line programs. The optparse philosophy
-is heavily influenced by the Unix and GNU toolkits ...</em></p>
-<p>So, I think my Windows readers will be best served if I put here
-a brief summary of the Unix terminology. Old time Unix geeks may safely
-skip this section. Let me just notice that <tt class="literal"><span class="pre">optparse</span></tt> could be
-extended to implement other kinds of conventions for optional argument
-parsing..</p>
-<p>Here is optparse/Unix/GNU terminology:
-the arguments given to a command-line script - <em>i.e.</em> the arguments
-that Python stores in the list <tt class="literal"><span class="pre">sys.argv[1:]</span></tt> - are classified in
-three groups: options, option arguments and positional arguments.
-Options can be distinguished since they are prefixed by a dash
-or a double dash; options can have arguments or not
-(there is at most an option argument right after each option);
-options without arguments are called flags. Positional arguments
-are what it is left in the command-line after you remove options
-and option arguments.</p>
-<p>In the example of the search/replace tool,
-I will need two options with an argument - since I want
-to pass to the script a regular expression and a replacement string -
-and I will need a flag specifying whether or not a backup of the original
-files needs to be performed. Finally, I will need a number of positional
-arguments to store the names of the files on which the search and
-replace will act.</p>
-<p>Consider - for the sake of the example - the following situations:
-you have a bunch of text files in the current directory containing dates
-in the European format DD-MM-YYYY, and that you want to convert them in
-the American format MM-DD-YYYY. If you are sure that all your dates
-are in the correct format, your can match them with a simple regular
-expression such as <tt class="literal"><span class="pre">(\d\d)-(\d\d)-(\d\d\d\d)</span></tt>
-(this regular expression looks for strings composed of three
-groups of digits separated by dashes, with the first and
-second group composed by two digits and the last group
-composed by four digits).</p>
-<p>In this particular example it is not so important to make a backup
-copy of the original files, since to revert to the original
-format it is enough to run the script again. So the syntax to use
-would be something like</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py --nobackup --regx=&quot;(\d\d)-(\d\d)-(\d\d\d\d)&quot; \
- --repl=&quot;\2-\1-\3&quot; *.txt
-</pre>
-</blockquote>
-<p>In order to emphasize the portability, I have used a generic
-<tt class="literal"><span class="pre">$&gt;</span></tt> promtp, meaning that these examples work equally well on
-both Unix and Windows (of course on Unix I could do the same
-job with sed or awk, but these tools are not as flexible as
-a Python script).</p>
-<p>The syntax here has the advantage of being
-quite clear, but the disadvantage of being quite verbose, and it is
-handier to use abbreviations for the name of the options. For instance,
-sensible abbreviations can be <tt class="literal"><span class="pre">-x</span></tt> for <tt class="literal"><span class="pre">--regx</span></tt>, <tt class="literal"><span class="pre">-r</span></tt> for <tt class="literal"><span class="pre">--repl</span></tt>
-and <tt class="literal"><span class="pre">-n</span></tt> for <tt class="literal"><span class="pre">--nobackup</span></tt>; moreover, the <tt class="literal"><span class="pre">=</span></tt> sign can safely be
-removed. Then the previous command reads</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py -n -x&quot;(\dd)-(\dd)-(\d\d\d\d)&quot; -r&quot;\2-\1-\3&quot; *.txt
-</pre>
-</blockquote>
-<p>You see here the Unix convention at work: one-letter options
-(a.k.a. short options) are prefixed with a single dash, whereas
-long options are prefixed with a double dash. The advantage of the
-convention is that short options can be composed: for instance</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py -nx &quot;(\dd)-(\dd)-(\d\d\d\d)&quot; -r &quot;\2-\1-\3&quot; *.txt
-</pre>
-</blockquote>
-<p>means the same as the previous line, i.e. <tt class="literal"><span class="pre">-nx</span></tt> is parsed as
-<tt class="literal"><span class="pre">-n</span> <span class="pre">-x</span></tt>. You can also freely exchange the order of the options,
-for instance in this way:</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py -nr &quot;\2-\1-\3&quot; *.txt -x &quot;(\dd)-(\dd)-(\d\d\d\d)&quot;
-</pre>
-</blockquote>
-<p>This command will be parsed exactly as before, i.e. options and option
-arguments are not positional.</p>
-</div>
-<div class="section" id="how-does-it-work-in-practice">
-<h1><a name="how-does-it-work-in-practice">How does it work in practice?</a></h1>
-<p>Having stated the requirements, we may start implementing our
-search and replace tool. The first step, and the most important
-one, is to write down the documentation string, even if you
-will have to wait until the last section to understand
-why the docstring is the most important part of this script ;)</p>
-<blockquote>
-<pre class="literal-block">
-#!/usr/bin/env python
-&quot;&quot;&quot;
-Given a sequence of text files, replaces everywhere
-a regular expression x with a replacement string s.
-
- usage: %prog files [options]
- -x, --regx=REGX: regular expression
- -r, --repl=REPL: replacement string
- -n, --nobackup: do not make backup copies
-&quot;&quot;&quot;
-</pre>
-</blockquote>
-<p>On Windows the first line in unnecessary, but is good practice to have it
-in the Unix world.</p>
-<p>The next step is to write down a simple search and replace routine:</p>
-<blockquote>
-<pre class="literal-block">
-import re
-
-def replace(regx, repl, files, backup_option=True):
- rx = re.compile(regx)
- for fname in files:
- txt = file(fname, &quot;U&quot;).read()
- if backup_option:
- print &gt;&gt; file(fname+&quot;.bak&quot;, &quot;w&quot;), txt,
- print &gt;&gt; file(fname, &quot;w&quot;), rx.sub(repl, txt),
-</pre>
-</blockquote>
-<p>This replace routine is entirely unsurprising, the only thing you
-may notice is the usage of the &quot;U&quot; option in the line</p>
-<blockquote>
-<pre class="literal-block">
-txt=file(fname,&quot;U&quot;).read()
-</pre>
-</blockquote>
-<p>This is a new feature of Python 2.3. Text files open with the &quot;U&quot;
-option are read in &quot;Universal&quot; mode: this means that Python takes
-care for you of the newline pain, i.e. this script will work
-correctly everywhere, independently by the newline
-conventions of your operating system. The script works by reading
-the whole file in memory: this is bad practice, and here I am assuming
-that you will use this script only on short files that will fit in
-your memory, otherwise you should &quot;massage&quot; the code a bit.
-Also, a full fledged script would check if the file exists
-and can be read, and would do something in the case it is not,
-but I ask you to forgive me for skipping on these points,
-since the thing I am really interested in is the <tt class="literal"><span class="pre">optparse</span></tt>
-module.</p>
-<p>So, how does it work? It is quite simple, really.
-First you need to instantiate an argument line parser from
-the <tt class="literal"><span class="pre">OptionParser</span></tt> class provided by <tt class="literal"><span class="pre">optparse</span></tt>:</p>
-<blockquote>
-<pre class="literal-block">
-import optparse
-parser = optparse.OptionParser(&quot;usage: %prog files [options]&quot;)
-</pre>
-</blockquote>
-<p>The string <tt class="literal"><span class="pre">&quot;usage:</span> <span class="pre">%prog</span> <span class="pre">files</span> <span class="pre">[options]&quot;</span></tt> will be used to
-print a customized usage message, where <tt class="literal"><span class="pre">%prog</span></tt> will be replaced
-by the name of the script (in this case <cite>replace.py`</cite>). You
-may safely omit it and <tt class="literal"><span class="pre">optparse</span></tt> will use a default
-<tt class="literal"><span class="pre">&quot;usage:</span> <span class="pre">%prog</span> <span class="pre">[options]&quot;</span></tt> string.</p>
-<p>Then, you tell the parser informations about which options
-it must recognize:</p>
-<blockquote>
-<pre class="literal-block">
-parser.add_option(&quot;-x&quot;, &quot;--regx&quot;,
- help=&quot;regular expression&quot;)
-parser.add_option(&quot;-r&quot;, &quot;--repl&quot;,
- help=&quot;replacement string&quot;)
-parser.add_option(&quot;-n&quot;, &quot;--nobackup&quot;,
- action=&quot;store_true&quot;,
- help=&quot;do not make backup copies&quot;)
-</pre>
-</blockquote>
-<p>The <tt class="literal"><span class="pre">help</span></tt> keyword argument is intended to document the
-intent of the given option; it is also used by <tt class="literal"><span class="pre">optparse</span></tt> in the
-usage message. The <tt class="literal"><span class="pre">action=store_true</span></tt> keyword argument is
-used to distinguish flags from options with arguments, it tells
-<tt class="literal"><span class="pre">optparse</span></tt> to set the flag <tt class="literal"><span class="pre">nobackup</span></tt> to <tt class="literal"><span class="pre">True</span></tt> if <tt class="literal"><span class="pre">-n</span></tt>
-or <tt class="literal"><span class="pre">--nobackup</span></tt> is given in the command line.</p>
-<p>Finally, you tell the parse to do its job and to parse the command line:</p>
-<blockquote>
-<pre class="literal-block">
-option, files = parser.parse_args()
-</pre>
-</blockquote>
-<p>The <tt class="literal"><span class="pre">.parse_args()</span></tt> method returns two values: <tt class="literal"><span class="pre">option</span></tt>,
-which is an instance of the <tt class="literal"><span class="pre">optparse.Option</span></tt> class, and <tt class="literal"><span class="pre">files</span></tt>,
-which is a list of positional arguments.
-The <tt class="literal"><span class="pre">option</span></tt> object has attributes - called <em>destionations</em> in
-<tt class="literal"><span class="pre">optparse</span></tt> terminology - corresponding to the given options.
-In our example, <tt class="literal"><span class="pre">option</span></tt> will have the attributes <tt class="literal"><span class="pre">option.regx</span></tt>,
-<tt class="literal"><span class="pre">option.repl</span></tt> and <tt class="literal"><span class="pre">option.nobackup</span></tt>.</p>
-<p>If no options are passed to the command line, all these attributes
-are initialized to <tt class="literal"><span class="pre">None</span></tt>, otherwise they are initialized to
-the argument option. In particular flag options are initialized to
-<tt class="literal"><span class="pre">True</span></tt> if they are given, to <tt class="literal"><span class="pre">None</span></tt> otherwise. So, in our example
-<tt class="literal"><span class="pre">option.nobackup</span></tt> is <tt class="literal"><span class="pre">True</span></tt> if the flag <tt class="literal"><span class="pre">-n</span></tt> or <tt class="literal"><span class="pre">--nobackup</span></tt>
-is given.
-The list <tt class="literal"><span class="pre">files</span></tt> contains the files passed
-to the command line (assuming you passed
-the names of accessible text files in your system).</p>
-<p>The main logic can be as simple as the following:</p>
-<blockquote>
-<pre class="literal-block">
-if not files:
- print &quot;No files given!&quot;
-elif option.regx and option.repl:
- replace(option.regex, option.repl, files, not option.nobackup)
-else:
- print &quot;Missing options or unrecognized options.&quot;
- print __doc__ # documentation on how to use the script
-</pre>
-</blockquote>
-<p>A nice feature of <tt class="literal"><span class="pre">optparse</span></tt> is that an help option is automatically
-created, so <tt class="literal"><span class="pre">replace.py</span> <span class="pre">-h</span></tt> (or <tt class="literal"><span class="pre">replace.py</span> <span class="pre">--help</span></tt>) will work as
-you may expect:</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py --help
-usage: replace.py files [options]
-
-
-options:
- -h, --help show this help message and exit
- -xREGX, --regx=REGX regular expression
- -rREPL, --repl=REPL replacement string
- -n, --nobackup do not make backup copies
-</pre>
-</blockquote>
-<p>You may programmatically print the usage message by invoking
-<tt class="literal"><span class="pre">parser.print_help()</span></tt>.</p>
-<p>At this point you may test your script and see that it works as
-advertised.</p>
-</div>
-<div class="section" id="how-to-reduce-verbosity-and-make-your-life-with-optparse-happier">
-<h1><a name="how-to-reduce-verbosity-and-make-your-life-with-optparse-happier">How to reduce verbosity and make your life with <tt class="literal"><span class="pre">optparse</span></tt> happier</a></h1>
-<p>The approach we followed in the previous example has a disadvantage:
-it involves a certain amount of verbosity/redundance. Suppose for instance
-we want to add the ability to restore the original file from the backup copy.
-Then, we have to change the script in three points: in the docstring,
-in the <tt class="literal"><span class="pre">add_option</span></tt> list, and in the <tt class="literal"><span class="pre">if</span> <span class="pre">..</span> <span class="pre">elif</span> <span class="pre">..</span> <span class="pre">else</span> <span class="pre">...</span></tt>
-statement. At least one of this is redundant.
-One would be tempted to think that the information in the documentation
-string is redundant, since it is already magically provided in the help
-options: however, I will take the opposite view, that the information
-in the help options is redundant, since it is already contained in
-the docstring. It is a sacrilege to write a Python script without a
-docstring, since the docstring should always be available to automatic
-documentation tools such as pydoc.
-Since the docstring cannot be removed or shortened, the idea is to
-extract information from it, in such a way to avoid the boring task
-of writing by hand the <tt class="literal"><span class="pre">parser.add_option</span></tt> lines.
-I implemented this idea in a cookbook recipe, by writing an
-<tt class="literal"><span class="pre">optionparse</span></tt> module which is just a thin wrapper around <tt class="literal"><span class="pre">optparse</span></tt>.
-The relevant code is <a class="reference" href="optionparse.py">here</a>. The relevant functions are <tt class="literal"><span class="pre">optionparse.parse</span></tt>
-which parses the docstring and <tt class="literal"><span class="pre">optionparse.exit</span></tt> which exits the
-execution by displaying an usage message.
-To show how to use them, let me rewrite the
-search and replace tool (including the new restore option) in this way:</p>
-<pre class="literal-block">
-#!/usr/bin/env python
-&quot;&quot;&quot;
-Given a sequence of text files, replaces everywhere
-a regular expression x with a replacement string s.
-
- usage: %prog files [options]
- -x, --regx=REGX: regular expression
- -r, --repl=REPL: replacement string
- -n, --nobackup: do not make backup copies
- -R, --restore: restore the original from the backup
-&quot;&quot;&quot;
-import optionparse, os, shutil, re
-
-def replace(regx, repl, files, backup_option=True):
- rx = re.compile(regx)
- for fname in files:
- # TODO: add a test to see if the file exists and can be read
- txt = file(fname, &quot;U&quot;).read()
- if backup_option:
- print &gt;&gt; file(fname+&quot;.bak&quot;, &quot;w&quot;), txt
- print &gt;&gt; file(fname, &quot;w&quot;), rx.sub(repl,txt)
-
-def restore(files): # restor original files from backup files
- for fname in files:
- if os.path.exists(fname+&quot;.bak&quot;):
- shutil.copyfile(fname+&quot;.bak&quot;,fname)
- else:
- print &quot;Sorry, there is no backup copy for %s&quot; % fname
-
-if __name__=='__main__':
- option, files = optionparse.parse(__doc__)
- # optionparse.parse parses both the docstring and the command line!
- if not files:
- optionparse.exit()
- elif option.regx and option.repl:
- replace(option.regex, option.repl, files, not option.nobackup)
- elif option.restore:
- restore(files)
- else:
- print &quot;Missing options or unrecognized options.&quot;
-</pre>
-<p>The code is quite readable. Internally <tt class="literal"><span class="pre">optionparse.parse(__doc__)</span></tt>
-works by generating an option parser from the docstring, then applying it
-to the command-line arguments.
-Working a bit more, one could also devise various tricks to avoid
-the redundance in the <tt class="literal"><span class="pre">if</span></tt> statement (for instance using a
-dictionary of functions and dispatching according to the name of
-the given option). However this simple recipe is good enough to
-provide a minimal wrapper to <tt class="literal"><span class="pre">optparse</span></tt>. It requires a minimum effort
-and works well for the most common case. For instance, the paper you are
-reading now has been written by using <tt class="literal"><span class="pre">optionparse</span></tt>: I used it to
-write a simple wrapper to docutils - the standard
-Python tool which converts (restructured) text files to HTML pages.
-It is also nice to notice that internally
-docutils itself uses <tt class="literal"><span class="pre">optparse</span></tt> to do its job, so actually this
-paper has been composed by using <tt class="literal"><span class="pre">optparse</span></tt> twice!</p>
-<p>Finally, you should keep in mind that this article only scratch the
-surface of <tt class="literal"><span class="pre">optparse</span></tt>, which is quite sophisticated.
-For instance you can specify default values, different destinations,
-a <tt class="literal"><span class="pre">store_false</span></tt> action and much more, even if often you don't need
-all this power. Still, it is handy to have the power at your disposal when
-you need it. The serious user of <tt class="literal"><span class="pre">optparse</span></tt> is strongly
-encorauged to read the documentation in the standard library, which
-is pretty good and detailed. I will think that this article has fullfilled
-its function of &quot;appetizer&quot; to <tt class="literal"><span class="pre">optparse</span></tt>, if it has stimulate
-the reader to study more.</p>
-</div>
-<div class="section" id="references">
-<h1><a name="references">References</a></h1>
-<ul class="simple">
-<li><tt class="literal"><span class="pre">optparse</span></tt> is documented in the standard library</li>
-<li>the <tt class="literal"><span class="pre">optionparse</span></tt> module can be found <a class="reference" href="optionparse.py">here</a>.</li>
-<li>I wrote a Python Cookbook <a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278844">recipe</a> about optionparse.</li>
-</ul>
-</div>
-</div>
-<hr class="footer" />
-<div class="footer">
-<a class="reference" href="paper.txt">View document source</a>.
-Generated on: 2004-05-28 09:31 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/optparse/paper2.html b/pypers/optparse/paper2.html
deleted file mode 100755
index 67f132a..0000000
--- a/pypers/optparse/paper2.html
+++ /dev/null
@@ -1,373 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.9: http://docutils.sourceforge.net/" />
-<title>The optparse module: writing command-line tools the easy way</title>
-</head>
-<body>
-<div class="document" id="the-optparse-module-writing-command-line-tools-the-easy-way">
-<h1 class="title">The optparse module: writing command-line tools the easy way</h1>
-<blockquote>
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">Status:</th><td class="field-body">Draft</td>
-</tr>
-<tr class="field"><th class="field-name">Author:</th><td class="field-body">Michele Simionato</td>
-</tr>
-<tr class="field"><th class="field-name">E-mail:</th><td class="field-body"><a class="reference" href="mailto:michele.simionato&#64;gmail.com">michele.simionato&#64;gmail.com</a></td>
-</tr>
-<tr class="field"><th class="field-name">Date:</th><td class="field-body">May 2004</td>
-</tr>
-</tbody>
-</table>
-</blockquote>
-<p><em>The optparse module is a powerful, flexible, extensible, easy-to-use
-command-line parsing library for Python. Using optparse, you can add
-intelligent, sophisticated handling of command-line options to your
-scripts with very little overhead.</em> -- Greg Ward, optparse author</p>
-<div class="section" id="introduction">
-<h1><a name="introduction">Introduction</a></h1>
-<p>Once upon a time, when graphic interfaces were still to be dreamed
-about, command-line tools were the body and the soul of all programming
-tools. Many years have passed since then, but some things have not
-changed: command-line tools are still fast, efficient, portable, easy
-to use and - more importantly - reliable. You can count on them.
-You can expect command-line scripts to work in any situation,
-during the installation phase, in a situation of disaster recovery, when
-your window manager breaks down and even in systems with severe
-memory/hardware constraints. When you really need them, command-line
-tools are always there.</p>
-<p>Hence, it is important for a programming language - especially
-one that wants to be called a &quot;scripting&quot; language - to provide
-facilities to help the programmer in the task of writing command-line
-tools. For a long time Python support for this kind of tasks has
-been provided by the``getopt`` module. I have never
-been particularly fond of <tt class="docutils literal"><span class="pre">getopt</span></tt>, since it required
-a sensible amount of coding even for the parsing of simple
-command-lines. However, with the coming of Python 2.3 the situation
-has changed: thanks to the great job of Greg Ward (the author of
-<tt class="docutils literal"><span class="pre">optparse</span></tt> a.k.a. <tt class="docutils literal"><span class="pre">Optik</span></tt>) now the Python programmer
-has at her disposal (in the standard library and not as an
-add-on module) a fully fledged Object Oriented API for
-command-line arguments parsing, which makes writing Unix-style
-command-line tools easy, efficient and fast.</p>
-<p>The only disadvantage of <tt class="docutils literal"><span class="pre">optparse</span></tt> is that it is a
-sophisticated tool, which requires some time to be fully mastered.
-The purpose of this paper is to help the reader to rapidly get the
-10% of the features of <tt class="docutils literal"><span class="pre">optparse</span></tt> that she will use in the 90% of
-the cases. Taking as an example a real life application - a search and
-replace tool - I will guide the reader through (some of) the wonders
-of <tt class="docutils literal"><span class="pre">optparse</span></tt>. Also, I will show some trick that will make your life
-with <tt class="docutils literal"><span class="pre">optparse</span></tt> much happier.
-This paper is intended for both Unix and
-Windows programmers - actually I will argue that Windows programmers
-need <tt class="docutils literal"><span class="pre">optparse</span></tt> even more than Unix programmers; it does not
-require any particular expertise to be fully appreciated.</p>
-</div>
-<div class="section" id="a-simple-example">
-<h1><a name="a-simple-example">A simple example</a></h1>
-<p>I will take as pedagogical example a little tool I wrote some time ago,
-a multiple files search and replace tool. I needed it because I am
-not always working under Unix, and I do not always have sed/awk or
-even Emacs installed, so it made sense to have this
-little Python script in my toolbox. It is only few lines long,
-it can always be modified and extended with a minimal effort,
-works on every platform (including my PDA) and has the advantage
-of being completely command-line driven:
-it does not require to have any graphics library installed
-and I can use it when I work on a remote machine via ssh.</p>
-<p>The tool takes a bunch of files and replace a given regular expression
-everywhere in-place; moreover, it saves a backup copy of the original
-un-modified files and give the option to recover
-them when I want to. Of course, all of this can be done more efficiently
-in the Unix world with specialized tools, but those tools are written
-in C and they are not as easily customizable as a Python script, that
-you may change in real time to suit your needs. So, it makes sense
-to write this kind of utility in Python (or in Perl, but I am writing on
-Pyzine now ;)</p>
-<p>As a final note, let me notice that I find <tt class="docutils literal"><span class="pre">optparse</span></tt>
-to be much more useful in the Windows world than in the Unix/Linux/Mac OS X
-world. The reason is that the pletora
-of pretty good command-line tools which are available under Unix are
-missing in the Windows environment, or do not have a satisfactory
-equivalent. Therefore,
-it makes sense to write a personal collection of command-line scripts
-for your more common task, if you need to work on many platforms and
-portability is an important requirement.
-Using Python and <tt class="docutils literal"><span class="pre">optparse</span></tt>, you may write your own scripts
-once and having them to run on every platform running Python,
-which means in practice any traditional platform and increasingly
-more of the non-traditional ones - Python is spreading into the
-embedded market too, including PDA's, cellular phones, and more.</p>
-</div>
-<div class="section" id="the-unix-philosophy-for-command-line-arguments">
-<h1><a name="the-unix-philosophy-for-command-line-arguments">The Unix philosophy for command-line arguments</a></h1>
-<p>In order to understand how <tt class="docutils literal"><span class="pre">optparse</span></tt> works, it is essential
-to understand the Unix philosophy about command-lines arguments.</p>
-<p>As Greg Ward puts it:</p>
-<p><em>The purpose of optparse is to make it very easy to provide the
-most standard, obvious, straightforward, and user-friendly user
-interface for Unix command-line programs. The optparse philosophy
-is heavily influenced by the Unix and GNU toolkits ...</em></p>
-<p>Here is a brief summary of the terminology:
-the arguments given to a command-line script - <em>i.e.</em> the arguments
-that Python stores in the list <tt class="docutils literal"><span class="pre">sys.argv[1:]</span></tt> - are classified in
-three groups: options, option arguments and positional arguments.
-Options can be distinguished since they are prefixed by a dash
-or a double dash; options can have arguments or not
-(there is at most an option argument right after each option);
-options without arguments are called flags. Positional arguments
-are what it is left in the command-line after you remove options
-and option arguments.</p>
-<p>In the example of the search/replace tool,
-I will need two options with an argument - I want
-to pass to the script a regular expression and a replacement string -
-and I will need a flag specifying whether or not a backup of the original
-files needs to be performed. Finally, I will need a number of positional
-arguments to store the names of the files on which the search and
-replace will act.</p>
-<p>Consider - for the sake of the example - the following situations:
-you have a bunch of text files in the current directory containing dates
-in the European format DD-MM-YYYY, and that you want to convert them in
-the American format MM-DD-YYYY. If you are sure that all your dates
-are in the correct format, your can match them with a simple regular
-expression such as <tt class="docutils literal"><span class="pre">(\d\d)-(\d\d)-(\d\d\d\d)</span></tt>.</p>
-<p>In this particular example it is not so important to make a backup
-copy of the original files, since to revert to the original
-format it is enough to run the script again. So the syntax to use
-would be something like</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py --nobackup --regx=&quot;(\d\d)-(\d\d)-(\d\d\d\d)&quot; \
- --repl=&quot;\2-\1-\3&quot; *.txt
-</pre>
-</blockquote>
-<p>In order to emphasize the portability, I have used a generic
-<tt class="docutils literal"><span class="pre">$&gt;</span></tt> promtp, meaning that these examples work equally well on
-both Unix and Windows (of course on Unix I could do the same
-job with sed or awk, but these tools are not as flexible as
-a Python script).</p>
-<p>The syntax here has the advantage of being
-quite clear, but the disadvantage of being quite verbose, and it is
-handier to use abbreviations for the name of the options. For instance,
-sensible abbreviations can be <tt class="docutils literal"><span class="pre">-x</span></tt> for <tt class="docutils literal"><span class="pre">--regx</span></tt>, <tt class="docutils literal"><span class="pre">-r</span></tt> for <tt class="docutils literal"><span class="pre">--repl</span></tt>
-and <tt class="docutils literal"><span class="pre">-n</span></tt> for <tt class="docutils literal"><span class="pre">--nobackup</span></tt>; moreover, the <tt class="docutils literal"><span class="pre">=</span></tt> sign can safely be
-removed. Then the previous command reads</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py -n -x&quot;(\dd)-(\dd)-(\d\d\d\d)&quot; -r&quot;\2-\1-\3&quot; *.txt
-</pre>
-</blockquote>
-<p>You see here the Unix convention at work: one-letter options
-(a.k.a. short options) are prefixed with a single dash, whereas
-long options are prefixed with a double dash. The advantage of the
-convention is that short options can be composed: for instance</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py -nx &quot;(\dd)-(\dd)-(\d\d\d\d)&quot; -r &quot;\2-\1-\3&quot; *.txt
-</pre>
-</blockquote>
-<p>means the same as the previous line, i.e. <tt class="docutils literal"><span class="pre">-nx</span></tt> is parsed as
-<tt class="docutils literal"><span class="pre">-n</span> <span class="pre">-x</span></tt>. You can also freely exchange the order of the options,
-for instance in this way:</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py -nr &quot;\2-\1-\3&quot; *.txt -x &quot;(\dd)-(\dd)-(\d\d\d\d)&quot;
-</pre>
-</blockquote>
-<p>This command will be parsed exactly as before, i.e. options and option
-arguments are not positional.</p>
-</div>
-<div class="section" id="how-does-it-work-in-practice">
-<h1><a name="how-does-it-work-in-practice">How does it work in practice?</a></h1>
-<p>Having stated the requirements, we may start implementing our
-search and replace tool. The first step, is to write down the
-documentation string:</p>
-<blockquote>
-<pre class="literal-block">
-#!/usr/bin/env python
-&quot;&quot;&quot;
-Given a sequence of text files, replaces everywhere
-a regular expression x with a replacement string s.
-
- usage: %prog files [options]
- -x, --regx=REGX: regular expression
- -r, --repl=REPL: replacement string
- -n, --nobackup: do not make backup copies
-&quot;&quot;&quot;
-</pre>
-</blockquote>
-<p>On Windows the first line in unnecessary, but is good practice to have it
-in the Unix world.</p>
-<p>The next step is to write down a simple search and replace routine:</p>
-<blockquote>
-<pre class="literal-block">
-import re
-
-def replace(regx, repl, files, backup_option=True):
- rx = re.compile(regx)
- for fname in files:
- txt = file(fname, &quot;U&quot;).read() # quick &amp; dirty
- if backup_option:
- print &gt;&gt; file(fname+&quot;.bak&quot;, &quot;w&quot;), txt,
- print &gt;&gt; file(fname, &quot;w&quot;), rx.sub(repl, txt),
-</pre>
-</blockquote>
-<p>This replace routine is entirely unsurprising, the only thing you
-may notice is the usage of the &quot;U&quot; option in the line</p>
-<blockquote>
-<pre class="literal-block">
-txt=file(fname,&quot;U&quot;).read()
-</pre>
-</blockquote>
-<p>This is a new feature of Python 2.3. Text files open with the &quot;U&quot;
-option are read in &quot;Universal&quot; mode: this means that Python takes
-care for you of the newline pain, i.e. this script will work
-correctly everywhere, independently by the newline
-conventions of your operating system. The script works by reading
-the whole file in memory: this is bad practice, and here I am assuming
-that you will use this script only on short files that will fit in
-your memory, otherwise you should &quot;massage&quot; the code a bit.
-Also, a full fledged script would check if the file exists
-and can be read, and would do something in the case it is not.</p>
-<p>So, how does it work? It is quite simple, really.
-First you need to instantiate an argument line parser from
-the <tt class="docutils literal"><span class="pre">OptionParser</span></tt> class provided by <tt class="docutils literal"><span class="pre">optparse</span></tt>:</p>
-<blockquote>
-<pre class="literal-block">
-import optparse
-parser = optparse.OptionParser(&quot;usage: %prog files [options]&quot;)
-</pre>
-</blockquote>
-<p>The string <tt class="docutils literal"><span class="pre">&quot;usage:</span> <span class="pre">%prog</span> <span class="pre">files</span> <span class="pre">[options]&quot;</span></tt> will be used to
-print a customized usage message, where <tt class="docutils literal"><span class="pre">%prog</span></tt> will be replaced
-by the name of the script (in this case <cite>replace.py`</cite>). You
-may safely omit it and <tt class="docutils literal"><span class="pre">optparse</span></tt> will use a default
-<tt class="docutils literal"><span class="pre">&quot;usage:</span> <span class="pre">%prog</span> <span class="pre">[options]&quot;</span></tt> string.</p>
-<p>Then, you tell the parser informations about which options
-it must recognize:</p>
-<blockquote>
-<pre class="literal-block">
-parser.add_option(&quot;-x&quot;, &quot;--regx&quot;,
- help=&quot;regular expression&quot;)
-parser.add_option(&quot;-r&quot;, &quot;--repl&quot;,
- help=&quot;replacement string&quot;)
-parser.add_option(&quot;-n&quot;, &quot;--nobackup&quot;,
- action=&quot;store_true&quot;,
- help=&quot;do not make backup copies&quot;)
-</pre>
-</blockquote>
-<p>The <tt class="docutils literal"><span class="pre">help</span></tt> keyword argument is intended to document the
-intent of the given option; it is also used by <tt class="docutils literal"><span class="pre">optparse</span></tt> in the
-usage message. The <tt class="docutils literal"><span class="pre">action=store_true</span></tt> keyword argument is
-used to distinguish flags from options with arguments, it tells
-<tt class="docutils literal"><span class="pre">optparse</span></tt> to set the flag <tt class="docutils literal"><span class="pre">nobackup</span></tt> to <tt class="docutils literal"><span class="pre">True</span></tt> if <tt class="docutils literal"><span class="pre">-n</span></tt>
-or <tt class="docutils literal"><span class="pre">--nobackup</span></tt> is given in the command line.</p>
-<p>Finally, you tell the parse to do its job and to parse the command line:</p>
-<blockquote>
-<pre class="literal-block">
-option, files = parser.parse_args()
-</pre>
-</blockquote>
-<p>The <tt class="docutils literal"><span class="pre">.parse_args()</span></tt> method returns two values: <tt class="docutils literal"><span class="pre">option</span></tt>,
-which is an instance of the <tt class="docutils literal"><span class="pre">optparse.Option</span></tt> class, and <tt class="docutils literal"><span class="pre">files</span></tt>,
-which is a list of positional arguments.
-The <tt class="docutils literal"><span class="pre">option</span></tt> object has attributes - called <em>destionations</em> in
-<tt class="docutils literal"><span class="pre">optparse</span></tt> terminology - corresponding to the given options.
-In our example, <tt class="docutils literal"><span class="pre">option</span></tt> will have the attributes <tt class="docutils literal"><span class="pre">option.regx</span></tt>,
-<tt class="docutils literal"><span class="pre">option.repl</span></tt> and <tt class="docutils literal"><span class="pre">option.nobackup</span></tt>.</p>
-<p>If no options are passed to the command line, all these attributes
-are initialized to <tt class="docutils literal"><span class="pre">None</span></tt>, otherwise they are initialized to
-the argument option. In particular flag options are initialized to
-<tt class="docutils literal"><span class="pre">True</span></tt> if they are given, to <tt class="docutils literal"><span class="pre">None</span></tt> otherwise. So, in our example
-<tt class="docutils literal"><span class="pre">option.nobackup</span></tt> is <tt class="docutils literal"><span class="pre">True</span></tt> if the flag <tt class="docutils literal"><span class="pre">-n</span></tt> or <tt class="docutils literal"><span class="pre">--nobackup</span></tt>
-is given.
-The list <tt class="docutils literal"><span class="pre">files</span></tt> contains the files passed
-to the command line (assuming you passed
-the names of accessible text files in your system).</p>
-<p>The main logic can be as simple as the following:</p>
-<blockquote>
-<pre class="literal-block">
-if not files:
- print &quot;No files given!&quot;
-elif option.regx and option.repl:
- replace(option.regex, option.repl, files, not option.nobackup)
-else:
- print &quot;Missing options or unrecognized options.&quot;
- print __doc__ # documentation on how to use the script
-</pre>
-</blockquote>
-<p>A nice feature of <tt class="docutils literal"><span class="pre">optparse</span></tt> is that an help option is automatically
-created, so <tt class="docutils literal"><span class="pre">replace.py</span> <span class="pre">-h</span></tt> (or <tt class="docutils literal"><span class="pre">replace.py</span> <span class="pre">--help</span></tt>) will work as
-you may expect:</p>
-<blockquote>
-<pre class="literal-block">
-$&gt; replace.py --help
-usage: replace.py files [options]
-
-
-options:
- -h, --help show this help message and exit
- -xREGX, --regx=REGX regular expression
- -rREPL, --repl=REPL replacement string
- -n, --nobackup do not make backup copies
-</pre>
-</blockquote>
-<p>You may programmatically print the usage message by invoking
-<tt class="docutils literal"><span class="pre">parser.print_help()</span></tt>.</p>
-<p>At this point you may test your script and see that it works as
-advertised.</p>
-</div>
-<div class="section" id="how-to-reduce-verbosity-and-make-your-life-with-optparse-happier">
-<h1><a name="how-to-reduce-verbosity-and-make-your-life-with-optparse-happier">How to reduce verbosity and make your life with <tt class="docutils literal"><span class="pre">optparse</span></tt> happier</a></h1>
-<p>The power of <tt class="docutils literal"><span class="pre">optparse``comes</span> <span class="pre">with</span> <span class="pre">a</span> <span class="pre">penalty:</span> <span class="pre">using</span> <span class="pre">``optparse</span></tt> in
-the standard way, as I explained before, involves a certain amount of
-verbosity/redundance.</p>
-<p>Suppose for instance
-I want to add the ability to restore the original file from the backup copy.
-Then, we have to change the script in three points: in the docstring,
-in the <tt class="docutils literal"><span class="pre">add_option</span></tt> list, and in the <tt class="docutils literal"><span class="pre">if</span> <span class="pre">..</span> <span class="pre">elif</span> <span class="pre">..</span> <span class="pre">else</span> <span class="pre">...</span></tt>
-statement. At least one of this is redundant.</p>
-<p>The redundance can be removed by parsing the docstring to infer the
-options to be recognized. This avoids the boring task
-of writing by hand the <tt class="docutils literal"><span class="pre">parser.add_option</span></tt> lines.
-I implemented this idea in a cookbook recipe, by writing an
-<tt class="docutils literal"><span class="pre">optionparse</span></tt> module which is just a thin wrapper around <tt class="docutils literal"><span class="pre">optparse</span></tt>.
-For sake of space, I cannot repeat it here, but you can find the code
-and a small explanation in the Python Cookbook (see the reference below).
-It is really easy to use. For instance, the paper you are
-reading now has been written by using <tt class="docutils literal"><span class="pre">optionparse</span></tt>: I used it to
-write a simple wrapper to docutils - the standard
-Python tool which converts (restructured) text files to HTML pages.
-It is also nice to notice that internally
-docutils itself uses <tt class="docutils literal"><span class="pre">optparse</span></tt> to do its job, so actually this
-paper has been composed by using <tt class="docutils literal"><span class="pre">optparse</span></tt> twice!</p>
-<p>Finally, you should keep in mind that this article only scratch the
-surface of <tt class="docutils literal"><span class="pre">optparse</span></tt>, which is quite sophisticated.
-For instance you can specify default values, different destinations,
-a <tt class="docutils literal"><span class="pre">store_false</span></tt> action and much more, even if often you don't need
-all this power. Still, it is handy to have the power at your disposal when
-you need it. The serious user of <tt class="docutils literal"><span class="pre">optparse</span></tt> is strongly
-encorauged to read the documentation in the standard library, which
-is pretty good and detailed. I think that this article has fullfilled
-its function of &quot;appetizer&quot; to <tt class="docutils literal"><span class="pre">optparse</span></tt>, if it has stimulate
-the reader to learn more.</p>
-</div>
-<div class="section" id="references">
-<h1><a name="references">References</a></h1>
-<ul class="simple">
-<li><tt class="docutils literal"><span class="pre">optparse/optik</span></tt> is a sourceforge project on its own:
-<a class="reference" href="http://optik.sourceforge.net">http://optik.sourceforge.net</a></li>
-<li>starting from Python 2.3, <tt class="docutils literal"><span class="pre">optparse</span></tt> is included in the standard library:
-<a class="reference" href="http://www.python.org/doc/2.3.4/lib/module-optparse.html">http://www.python.org/doc/2.3.4/lib/module-optparse.html</a></li>
-<li>I wrote a Python Cookbook recipe about optparse:
-<a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278844">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278844</a></li>
-</ul>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/oxford/all.html b/pypers/oxford/all.html
deleted file mode 100755
index 56f2314..0000000
--- a/pypers/oxford/all.html
+++ /dev/null
@@ -1,2366 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.10: http://docutils.sourceforge.net/" />
-<title>Lectures on Advanced Python Programming</title>
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-06-06 15:09:07 +0200 (Mon, 06 Jun 2005) $
-:Version: $Revision: 3442 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-*/
-
-/* "! important" is used here to override other ``margin-top`` and
- ``margin-bottom`` styles that are later in the stylesheet or
- more specific. See http://www.w3.org/TR/CSS1#the-cascade */
-.first {
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-img.borderless {
- border: 0 }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.line-block {
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid thin gray }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid thin black }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-</head>
-<body>
-<div class="document" id="lectures-on-advanced-python-programming">
-<h1 class="title">Lectures on Advanced Python Programming</h1>
-<img alt="accu2005.png" src="accu2005.png" />
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">Author:</th><td class="field-body">Michele Simionato</td>
-</tr>
-<tr class="field"><th class="field-name">Given:</th><td class="field-body">19 April 2005</td>
-</tr>
-<tr class="field"><th class="field-name">Revised:</th><td class="field-body">7 September 2005</td>
-</tr>
-</tbody>
-</table>
-<div class="contents topic" id="contents">
-<p class="topic-title first"><a name="contents">Contents</a></p>
-<ul class="simple">
-<li><a class="reference" href="#lecture-1-loops-i-e-iterators-generators" id="id1" name="id1">Lecture 1: Loops (i.e. iterators &amp; generators)</a><ul>
-<li><a class="reference" href="#part-i-iterators" id="id2" name="id2">Part I: iterators</a><ul>
-<li><a class="reference" href="#iterators-are-everywhere" id="id3" name="id3">Iterators are everywhere</a></li>
-<li><a class="reference" href="#iterables-and-iterators" id="id4" name="id4">Iterables and iterators</a></li>
-<li><a class="reference" href="#simpler-way-to-get-an-iterator" id="id5" name="id5">Simpler way to get an iterator</a></li>
-<li><a class="reference" href="#sentinel-syntax-iter-callable-sentinel" id="id6" name="id6">Sentinel syntax iter(callable, sentinel)</a></li>
-<li><a class="reference" href="#second-simpler-way-to-get-an-iterator-generator-expressions" id="id7" name="id7">Second simpler way to get an iterator: generator-expressions</a></li>
-<li><a class="reference" href="#iteration-caveats" id="id8" name="id8">Iteration caveats</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#part-ii-generators" id="id9" name="id9">Part II: generators</a><ul>
-<li><a class="reference" href="#a-simple-recipe-skip-redundant" id="id10" name="id10">A simple recipe: skip redundant</a></li>
-<li><a class="reference" href="#another-real-life-example-working-with-nested-structures" id="id11" name="id11">Another real life example: working with nested structures</a></li>
-<li><a class="reference" href="#another-typical-use-case-for-generators-parsers" id="id12" name="id12">Another typical use case for generators: parsers</a></li>
-<li><a class="reference" href="#other-kinds-of-iterables" id="id13" name="id13">Other kinds of iterables</a></li>
-<li><a class="reference" href="#the-itertools-module" id="id14" name="id14">The itertools module</a></li>
-<li><a class="reference" href="#anytrue" id="id15" name="id15">anyTrue</a></li>
-<li><a class="reference" href="#chop" id="id16" name="id16">chop</a></li>
-<li><a class="reference" href="#tee" id="id17" name="id17">tee</a></li>
-<li><a class="reference" href="#grouping-and-sorting" id="id18" name="id18">Grouping and sorting</a></li>
-</ul>
-</li>
-</ul>
-</li>
-<li><a class="reference" href="#lecture-2-objects-delegation-inheritance" id="id19" name="id19">Lecture 2: Objects (delegation &amp; inheritance)</a><ul>
-<li><a class="reference" href="#part-i-delegation" id="id20" name="id20">Part I: delegation</a><ul>
-<li><a class="reference" href="#accessing-simple-attributes" id="id21" name="id21">Accessing simple attributes</a></li>
-<li><a class="reference" href="#accessing-methods" id="id22" name="id22">Accessing methods</a></li>
-<li><a class="reference" href="#converting-functions-into-methods" id="id23" name="id23">Converting functions into methods</a></li>
-<li><a class="reference" href="#hack-a-very-slick-adder" id="id24" name="id24">Hack: a very slick adder</a></li>
-<li><a class="reference" href="#descriptor-protocol" id="id25" name="id25">Descriptor Protocol</a></li>
-<li><a class="reference" href="#multilingual-attribute" id="id26" name="id26">Multilingual attribute</a></li>
-<li><a class="reference" href="#another-use-case-for-properties-storing-users" id="id27" name="id27">Another use case for properties: storing users</a></li>
-<li><a class="reference" href="#low-level-delegation-via-getattribute" id="id28" name="id28">Low-level delegation via __getattribute__</a></li>
-<li><a class="reference" href="#traditional-delegation-via-getattr" id="id29" name="id29">Traditional delegation via __getattr__</a></li>
-<li><a class="reference" href="#keyword-dictionaries-with-getattr-setattr" id="id30" name="id30">Keyword dictionaries with __getattr__/__setattr__</a></li>
-<li><a class="reference" href="#delegation-to-special-methods-caveat" id="id31" name="id31">Delegation to special methods caveat</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#part-ii-inheritance" id="id32" name="id32">Part II: Inheritance</a><ul>
-<li><a class="reference" href="#why-you-need-to-know-about-mi-even-if-you-do-not-use-it" id="id33" name="id33">Why you need to know about MI even if you do not use it</a></li>
-<li><a class="reference" href="#a-few-details-about-super-not-the-whole-truth" id="id34" name="id34">A few details about <tt class="docutils literal"><span class="pre">super</span></tt> (not the whole truth)</a></li>
-<li><a class="reference" href="#subclassing-built-in-types-new-vs-init" id="id35" name="id35">Subclassing built-in types; __new__ vs. __init__</a></li>
-<li><a class="reference" href="#be-careful-when-using-new-with-mutable-types" id="id36" name="id36">Be careful when using __new__ with mutable types</a></li>
-</ul>
-</li>
-</ul>
-</li>
-<li><a class="reference" href="#lecture-3-magic-i-e-decorators-and-metaclasses" id="id37" name="id37">Lecture 3: Magic (i.e. decorators and metaclasses)</a><ul>
-<li><a class="reference" href="#part-i-decorators" id="id38" name="id38">Part I: decorators</a><ul>
-<li><a class="reference" href="#a-typical-decorator-traced" id="id39" name="id39">A typical decorator: traced</a></li>
-<li><a class="reference" href="#a-decorator-factory-timed" id="id40" name="id40">A decorator factory: Timed</a></li>
-<li><a class="reference" href="#a-powerful-decorator-pattern" id="id41" name="id41">A powerful decorator pattern</a></li>
-<li><a class="reference" href="#a-deferred-decorator" id="id42" name="id42">A deferred decorator</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#part-ii-metaclasses" id="id43" name="id43">Part II: metaclasses</a><ul>
-<li><a class="reference" href="#rejuvenating-old-style-classes" id="id44" name="id44">Rejuvenating old-style classes</a></li>
-<li><a class="reference" href="#a-typical-metaclass-example-metatracer" id="id45" name="id45">A typical metaclass example: MetaTracer</a></li>
-<li><a class="reference" href="#real-life-example-check-overriding" id="id46" name="id46">Real life example: check overriding</a></li>
-<li><a class="reference" href="#logfile" id="id47" name="id47">LogFile</a></li>
-<li><a class="reference" href="#cooperative-hierarchies" id="id48" name="id48">Cooperative hierarchies</a></li>
-<li><a class="reference" href="#metaclass-enhanced-modules" id="id49" name="id49">Metaclass-enhanced modules</a></li>
-<li><a class="reference" href="#magic-properties" id="id50" name="id50">Magic properties</a></li>
-<li><a class="reference" href="#hack-evil-properties" id="id51" name="id51">Hack: evil properties</a></li>
-<li><a class="reference" href="#why-i-suggest-not-to-use-metaclasses-in-production-code" id="id52" name="id52">Why I suggest <em>not</em> to use metaclasses in production code</a></li>
-<li><a class="reference" href="#is-there-an-automatic-way-of-solving-the-conflict" id="id53" name="id53">Is there an automatic way of solving the conflict?</a></li>
-</ul>
-</li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="section" id="lecture-1-loops-i-e-iterators-generators">
-<h1><a class="toc-backref" href="#id1" name="lecture-1-loops-i-e-iterators-generators">Lecture 1: Loops (i.e. iterators &amp; generators)</a></h1>
-<div class="section" id="part-i-iterators">
-<h2><a class="toc-backref" href="#id2" name="part-i-iterators">Part I: iterators</a></h2>
-<div class="section" id="iterators-are-everywhere">
-<h3><a class="toc-backref" href="#id3" name="iterators-are-everywhere">Iterators are everywhere</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; for i in 1, 2, 3:
-... print i
-1
-2
-3
-</pre>
-<p>The 'for' loop is using <em>iterators</em> internally:</p>
-<pre class="literal-block">
-it = iter((1,2,3))
-while True:
- try:
- print it.next()
- except StopIteration:
- break
-</pre>
-</div>
-<div class="section" id="iterables-and-iterators">
-<h3><a class="toc-backref" href="#id4" name="iterables-and-iterators">Iterables and iterators</a></h3>
-<p><em>Iterable</em> = anything you can loop over = any sequence + any object with an __iter__ method;</p>
-<p>Not every sequence has an __iter__ method:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; &quot;hello&quot;.__iter__()
-Traceback (most recent call last):
- ...
-AttributeError: 'str' object has no attribute '__iter__'
-</pre>
-<p><em>Iterator</em> = any object with a .next method and an __iter__ method returning self</p>
-</div>
-<div class="section" id="simpler-way-to-get-an-iterator">
-<h3><a class="toc-backref" href="#id5" name="simpler-way-to-get-an-iterator">Simpler way to get an iterator</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = iter(&quot;hello&quot;)
-&gt;&gt;&gt; it.next()
-'h'
-&gt;&gt;&gt; it.next()
-'e'
-&gt;&gt;&gt; it.next()
-'l'
-&gt;&gt;&gt; it.next()
-'l'
-&gt;&gt;&gt; it.next()
-'o'
-&gt;&gt;&gt; it.next()
-Traceback (most recent call last):
- ...
-StopIteration
-</pre>
-</div>
-<div class="section" id="sentinel-syntax-iter-callable-sentinel">
-<h3><a class="toc-backref" href="#id6" name="sentinel-syntax-iter-callable-sentinel">Sentinel syntax iter(callable, sentinel)</a></h3>
-<p>Example:</p>
-<pre class="literal-block">
-$ echo -e &quot;value1\nvalue2\nEND\n&quot; &gt; data.txt
-$ python -c &quot;print list(iter(file('data.txt').readline, 'END\n'))&quot;
-['value1\n', 'value2\n']
-</pre>
-<p>Beware of infinite iterators:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; repeat = iter(lambda : &quot;some value&quot;, &quot;&quot;)
-&gt;&gt;&gt; repeat.next()
-'some value'
-</pre>
-</div>
-<div class="section" id="second-simpler-way-to-get-an-iterator-generator-expressions">
-<h3><a class="toc-backref" href="#id7" name="second-simpler-way-to-get-an-iterator-generator-expressions">Second simpler way to get an iterator: generator-expressions</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; squares = (i*i for i in range(1,11))
-&gt;&gt;&gt; list(squares)
-[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
-</pre>
-<p>Excessive parenthesis can be skipped, so use</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; dict((i, i*i) for i in range(1,11))
-{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100}
-</pre>
-<p>instead of</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; dict([(i, i*i) for i in range(1,11)])
-{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100}
-</pre>
-<p>(as usual, the most elegant version is the most efficient).</p>
-</div>
-<div class="section" id="iteration-caveats">
-<h3><a class="toc-backref" href="#id8" name="iteration-caveats">Iteration caveats</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; ls = [i for i in (1,2,3)]
-&gt;&gt;&gt; i
-3
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = (j for j in (1,2,3))
-&gt;&gt;&gt; j
-Traceback (most recent call last):
- ...
-NameError: name 'j' is not defined
-</pre>
-<p>A subtler example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; ls = [lambda :i for i in (1,2,3)]
-&gt;&gt;&gt; ls[0]()
-3
-</pre>
-<p>instead</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = (lambda :i for i in (1,2,3))
-&gt;&gt;&gt; it.next()()
-1
-&gt;&gt;&gt; it.next()()
-2
-&gt;&gt;&gt; it.next()()
-3
-</pre>
-<p><em>seems</em> to be working but it is not really the case:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = (lambda :i for i in (1,2,3))
-&gt;&gt;&gt; f1 = it.next()
-&gt;&gt;&gt; f2 = it.next()
-&gt;&gt;&gt; f3 = it.next()
-&gt;&gt;&gt; f1()
-3
-</pre>
-<p>The reason is that Python does LATE binding <em>always</em>. The solution is ugly:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = list(lambda i=i:i for i in (1,2,3))
-&gt;&gt;&gt; it[0]()
-1
-&gt;&gt;&gt; it[1]()
-2
-&gt;&gt;&gt; it[2]()
-3
-</pre>
-</div>
-</div>
-<div class="section" id="part-ii-generators">
-<h2><a class="toc-backref" href="#id9" name="part-ii-generators">Part II: generators</a></h2>
-<p>Trivial example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def gen123(): # &quot;function&quot; which returns an iterator over the values 1, 2, 3
-... yield 1
-... yield 2
-... yield 3
-...
-&gt;&gt;&gt; it = gen123()
-&gt;&gt;&gt; it.next()
-1
-&gt;&gt;&gt; it.next()
-2
-&gt;&gt;&gt; it.next()
-3
-&gt;&gt;&gt; it.next()
-Traceback (most recent call last):
- ...
-StopIteration
-</pre>
-<p>Real life example: using generators to generate HTML tables</p>
-<pre class="literal-block">
-#&lt;htmltable.py&gt;
-
-def HTMLTablegen(table):
- yield &quot;&lt;table&gt;&quot;
- for row in table:
- yield &quot;&lt;tr&gt;&quot;
- for col in row:
- yield &quot;&lt;td&gt;%s&lt;/td&gt;&quot; % col
- yield &quot;&lt;/tr&gt;&quot;
- yield &quot;&lt;/table&gt;&quot;
-
-def test():
- return &quot;\n&quot;.join(HTMLTablegen([[&quot;Row&quot;, &quot;City&quot;],
- [1,'London'], [2, 'Oxford']]))
-
-if __name__ == &quot;__main__&quot;: # example
- print test()
-
-#&lt;/htmltable.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from htmltable import test
-&gt;&gt;&gt; print test()
-&lt;table&gt;
-&lt;tr&gt;
-&lt;td&gt;Row&lt;/td&gt;
-&lt;td&gt;City&lt;/td&gt;
-&lt;/tr&gt;
-&lt;tr&gt;
-&lt;td&gt;1&lt;/td&gt;
-&lt;td&gt;London&lt;/td&gt;
-&lt;/tr&gt;
-&lt;tr&gt;
-&lt;td&gt;2&lt;/td&gt;
-&lt;td&gt;Oxford&lt;/td&gt;
-&lt;/tr&gt;
-&lt;/table&gt;
-</pre>
-<div class="section" id="a-simple-recipe-skip-redundant">
-<h3><a class="toc-backref" href="#id10" name="a-simple-recipe-skip-redundant">A simple recipe: skip redundant</a></h3>
-<p>How to remove duplicates by keeping the order:</p>
-<pre class="literal-block">
-#&lt;skip_redundant.py&gt;
-
-def skip_redundant(iterable, skipset=None):
- &quot;Redundant items are repeated items or items in the original skipset.&quot;
- if skipset is None: skipset = set()
- for item in iterable:
- if item not in skipset:
- skipset.add(item)
- yield item
-
-#&lt;/skip_redundant.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from skip_redundant import skip_redundant
-&gt;&gt;&gt; print list(skip_redundant(&quot;&lt;hello, world&gt;&quot;, skipset=set(&quot;&lt;&gt;&quot;)))
-['h', 'e', 'l', 'o', ',', ' ', 'w', 'r', 'd']
-</pre>
-</div>
-<div class="section" id="another-real-life-example-working-with-nested-structures">
-<h3><a class="toc-backref" href="#id11" name="another-real-life-example-working-with-nested-structures">Another real life example: working with nested structures</a></h3>
-<pre class="literal-block">
-#&lt;walk.py&gt;
-
-def walk(iterable, level=0):
- for obj in iterable:
- if not hasattr(obj, &quot;__iter__&quot;): # atomic object
- yield obj, level
- else: # composed object: iterate again
- for subobj, lvl in walk(obj, level + 1):
- yield subobj, lvl
-
-def flatten(iterable):
- return (obj for obj, level in walk(iterable))
-
-def pprint(iterable):
- for obj, level in walk(iterable):
- print &quot; &quot;*level, obj
-
-#&lt;/walk.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from walk import flatten, pprint
-&gt;&gt;&gt; nested_ls = [1,[2,[3,[[[4,5],6]]]],7]
-&gt;&gt;&gt; pprint(nested_ls)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
-&gt;&gt;&gt; pprint(flatten(nested_ls))
- 1
- 2
- 3
- 4
- 5
- 6
- 7
-</pre>
-</div>
-<div class="section" id="another-typical-use-case-for-generators-parsers">
-<h3><a class="toc-backref" href="#id12" name="another-typical-use-case-for-generators-parsers">Another typical use case for generators: parsers</a></h3>
-<p>A very stripped down parser for nested expressions</p>
-<pre class="literal-block">
-#&lt;sexpr2indent.py&gt;
-&quot;&quot;&quot;A simple s-expression formatter.&quot;&quot;&quot;
-
-import re
-
-def parse(sexpr):
- position = 0
- nesting_level = 0
- paren = re.compile(r&quot;(?P&lt;paren_beg&gt;\()|(?P&lt;paren_end&gt;\))&quot;)
- while True:
- match = paren.search(sexpr, position)
- if match:
- yield nesting_level, sexpr[position: match.start()]
- if match.lastgroup == &quot;paren_beg&quot;:
- nesting_level += 1
- elif match.lastgroup == &quot;paren_end&quot;:
- nesting_level -= 1
- position = match.end()
- else:
- break
-
-def sexpr_indent(sexpr):
- for nesting, text in parse(sexpr.replace(&quot;\n&quot;, &quot;&quot;)):
- if text.strip(): print &quot; &quot;*nesting, text
-
-#&lt;/sexpr2indent.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from sexpr2indent import sexpr_indent
-&gt;&gt;&gt; sexpr_indent(&quot;&quot;&quot;\
-... (html (head (title Example)) (body (h1 s-expr formatter example)
-... (a (&#64; (href http://www.example.com)) A link)))&quot;&quot;&quot;)
-... #doctest: +NORMALIZE_WHITESPACE
- html
- head
- title Example
- body
- h1 s-expr formatter example
- a
- &#64;
- href http://www.example.com
- A link
-</pre>
-</div>
-<div class="section" id="other-kinds-of-iterables">
-<h3><a class="toc-backref" href="#id13" name="other-kinds-of-iterables">Other kinds of iterables</a></h3>
-<p>The following class generates iterable which are not iterators:</p>
-<pre class="literal-block">
-#&lt;reiterable.py&gt;
-
-class ReIter(object):
- &quot;A re-iterable object.&quot;
- def __iter__(self):
- yield 1
- yield 2
- yield 3
-
-#&lt;/reiterable.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from reiterable import ReIter
-&gt;&gt;&gt; rit = ReIter()
-&gt;&gt;&gt; list(rit)
-[1, 2, 3]
-&gt;&gt;&gt; list(rit) # it is reiterable!
-[1, 2, 3]
-</pre>
-</div>
-<div class="section" id="the-itertools-module">
-<h3><a class="toc-backref" href="#id14" name="the-itertools-module">The itertools module</a></h3>
-<blockquote>
-<ul class="simple">
-<li>count([n]) --&gt; n, n+1, n+2, ...</li>
-<li>cycle(p) --&gt; p0, p1, ... plast, p0, p1, ...</li>
-<li>repeat(elem [,n]) --&gt; elem, elem, elem, ... endlessly or up to n times</li>
-<li>izip(p, q, ...) --&gt; (p[0], q[0]), (p[1], q[1]), ...</li>
-<li>ifilter(pred, seq) --&gt; elements of seq where pred(elem) is True</li>
-<li>ifilterfalse(pred, seq) --&gt; elements of seq where pred(elem) is False</li>
-<li>islice(seq, [start,] stop [, step]) --&gt; elements from seq[start:stop:step]</li>
-<li>imap(fun, p, q, ...) --&gt; fun(p0, q0), fun(p1, q1), ...</li>
-<li>starmap(fun, seq) --&gt; fun(*seq[0]), fun(*seq[1]), ...</li>
-<li>tee(it, n=2) --&gt; (it1, it2 , ... itn) splits one iterator into n</li>
-<li>chain(p, q, ...) --&gt; p0, p1, ... plast, q0, q1, ...</li>
-<li>takewhile(pred, seq) --&gt; seq[0], seq[1], until pred fails</li>
-<li>dropwhile(pred, seq) --&gt; seq[n], seq[n+1], starting when pred fails</li>
-<li>groupby(iterable[, keyfunc]) --&gt; sub-iterators grouped by value of keyfunc(v)</li>
-</ul>
-</blockquote>
-</div>
-<div class="section" id="anytrue">
-<h3><a class="toc-backref" href="#id15" name="anytrue">anyTrue</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; import itertools
-&gt;&gt;&gt; def anyTrue(predicate, iterable):
-... return True in itertools.imap(predicate, iterable)
-...
-&gt;&gt;&gt; fname = &quot;picture.gif&quot;
-&gt;&gt;&gt; anyTrue(fname.endswith, &quot;.jpg .gif .png&quot;.split())
-True
-</pre>
-<p>AnyTrue does <em>short-circuit</em>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def is3(i):
-... print &quot;i=%s&quot; % i
-... return i == 3
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; anyTrue(is3, range(10))
-i=0
-i=1
-i=2
-i=3
-True
-</pre>
-</div>
-<div class="section" id="chop">
-<h3><a class="toc-backref" href="#id16" name="chop">chop</a></h3>
-<p>You want to chop an iterable in batches of a given size:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from chop import chop
-&gt;&gt;&gt; list(chop([1, 2, 3, 4], 2))
-[[1, 2], [3, 4]]
-&gt;&gt;&gt; list(chop([1, 2, 3, 4, 5, 6, 7],3))
-[[1, 2, 3], [4, 5, 6], [7]]
-</pre>
-<p>Here is a possible implementation:</p>
-<pre class="literal-block">
-#&lt;chop.py&gt;
-
-# see also http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279
-
-import itertools
-
-def chop(iterable, batchsize):
- it = iter(iterable)
- while True:
- batch = list(itertools.islice(it, batchsize))
- if batch: yield batch
- else: break
-
-#&lt;/chop.py&gt;
-</pre>
-<p>For people thinking Python is too readable, here is a one-liner:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; chop = lambda it, n : itertools.izip(*(iter(it),)*n)
-...
-&gt;&gt;&gt; list(chop([1,2,3,4], 2))
-[(1, 2), (3, 4)]
-</pre>
-</div>
-<div class="section" id="tee">
-<h3><a class="toc-backref" href="#id17" name="tee">tee</a></h3>
-<p>To make copies of iterables; typically used in parsers:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from itertools import tee, chain, izip
-&gt;&gt;&gt; chars, prevs = tee(&quot;abc&quot;)
-&gt;&gt;&gt; prevs = chain([None], prevs)
-&gt;&gt;&gt; for char, prev in izip(chars, prevs):
-... print char, prev
-...
-a None
-b a
-c b
-</pre>
-</div>
-<div class="section" id="grouping-and-sorting">
-<h3><a class="toc-backref" href="#id18" name="grouping-and-sorting">Grouping and sorting</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; from itertools import groupby
-&gt;&gt;&gt; from operator import itemgetter
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; NAME, AGE = 0, 1
-&gt;&gt;&gt; query_result = (&quot;Smith&quot;, 34), (&quot;Donaldson&quot;, 34), (&quot;Lee&quot;, 22), (&quot;Orr&quot;, 22)
-</pre>
-<p>Grouping together people of the same age:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for k, g in groupby(query_result, key=itemgetter(AGE)):
-... print k, list(g)
-...
-34 [('Smith', 34), ('Donaldson', 34)]
-22 [('Lee', 22), ('Orr', 22)]
-</pre>
-<p>Sorting by name:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for tup in sorted(query_result, key=itemgetter(NAME)):
-... print tup
-('Donaldson', 34)
-('Lee', 22)
-('Orr', 22)
-('Smith', 34)
-</pre>
-</div>
-</div>
-</div>
-<div class="section" id="lecture-2-objects-delegation-inheritance">
-<h1><a class="toc-backref" href="#id19" name="lecture-2-objects-delegation-inheritance">Lecture 2: Objects (delegation &amp; inheritance)</a></h1>
-<div class="section" id="part-i-delegation">
-<h2><a class="toc-backref" href="#id20" name="part-i-delegation">Part I: delegation</a></h2>
-<p>Understanding how attribute access works: internal delegation via <em>descriptors</em></p>
-<div class="section" id="accessing-simple-attributes">
-<h3><a class="toc-backref" href="#id21" name="accessing-simple-attributes">Accessing simple attributes</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... a = 2
-... def __init__(self, x):
-... self.x = x
-...
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; c = C(1)
-&gt;&gt;&gt; c.x
-1
-&gt;&gt;&gt; c.a
-2
-</pre>
-<p>We are retrieving</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.__dict__[&quot;x&quot;]
-1
-</pre>
-<p>If there is nothing in c.__dict__, Python looks at C.__dict__:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print c.__dict__.get(&quot;a&quot;)
-None
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__dict__[&quot;a&quot;]
-2
-</pre>
-<p>If there is nothing in C.__dict__, Python looks at the superclasses according
-to the MRO (see part II).</p>
-</div>
-<div class="section" id="accessing-methods">
-<h3><a class="toc-backref" href="#id22" name="accessing-methods">Accessing methods</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.__init__ #doctest: +ELLIPSIS
-&lt;bound method C.__init__ of &lt;__main__.C object at 0x...&gt;&gt;
-</pre>
-<p>since __init__ is not in c.__dict__ Python looks in the class dictionary
-and finds</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__dict__[&quot;__init__&quot;] #doctest: +ELLIPSIS
-&lt;function __init__ at 0x...&gt;
-</pre>
-<p>Then it magically converts the function into a method bound to the instance
-&quot;c&quot;.</p>
-<p>NOTE: this mechanism works for new-style classes only.</p>
-<p>The old-style mechanism is less consistent and the attribute lookup of special
-methods is special: (*)</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object): pass
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; c.__str__ = lambda : &quot;hello!&quot;
-&gt;&gt;&gt; print c #doctest: +ELLIPSIS
-&lt;__main__.C object at ...&gt;
-</pre>
-<p>whereas for old-style classes</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C: pass
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; c.__str__ = lambda : &quot;hello!&quot;
-&gt;&gt;&gt; print c
-hello!
-</pre>
-<p>the special method is looked for in the instance dictionary too.</p>
-<p>(*) modulo a very subtle difference for __getattr__-delegated special methods,
-see later.</p>
-</div>
-<div class="section" id="converting-functions-into-methods">
-<h3><a class="toc-backref" href="#id23" name="converting-functions-into-methods">Converting functions into methods</a></h3>
-<p>It is possible to convert a function into a bound or unbound method
-by invoking the <tt class="docutils literal"><span class="pre">__get__</span></tt> special method:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(x): pass
-&gt;&gt;&gt; f.__get__ #doctest: +ELLIPSIS
-&lt;method-wrapper object at 0x...&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object): pass
-...
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(self): pass
-...
-&gt;&gt;&gt; f.__get__(C(), C) #doctest: +ELLIPSIS
-&lt;bound method C.f of &lt;__main__.C object at 0x...&gt;&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; f.__get__(None, C)
-&lt;unbound method C.f&gt;
-</pre>
-<p>Functions are the simplest example of <em>descriptors</em>.</p>
-<p>Access to methods works since internally Python transforms</p>
-<blockquote>
-<tt class="docutils literal"><span class="pre">c.__init__</span> <span class="pre">-&gt;</span> <span class="pre">type(c).__dict__['__init__'].__get__(c,</span> <span class="pre">type(c))</span></tt></blockquote>
-<p>Note: not <em>all</em> functions are descriptors:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from operator import add
-&gt;&gt;&gt; add.__get__
-Traceback (most recent call last):
- ...
-AttributeError: 'builtin_function_or_method' object has no attribute '__get__'
-</pre>
-</div>
-<div class="section" id="hack-a-very-slick-adder">
-<h3><a class="toc-backref" href="#id24" name="hack-a-very-slick-adder">Hack: a very slick adder</a></h3>
-<p>The descriptor protocol can be (ab)used as a way to avoid the late binding
-issue in for loops:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def add(x,y):
-... return x + y
-&gt;&gt;&gt; closures = [add.__get__(i) for i in range(10)]
-&gt;&gt;&gt; closures[5](1000)
-1005
-</pre>
-<p>Notice: operator.add will not work.</p>
-</div>
-<div class="section" id="descriptor-protocol">
-<h3><a class="toc-backref" href="#id25" name="descriptor-protocol">Descriptor Protocol</a></h3>
-<p>Everything at <a class="reference" href="http://users.rcn.com/python/download/Descriptor.htm">http://users.rcn.com/python/download/Descriptor.htm</a></p>
-<p>Formally:</p>
-<pre class="literal-block">
-descr.__get__(self, obj, type=None) --&gt; value
-descr.__set__(self, obj, value) --&gt; None
-descr.__delete__(self, obj) --&gt; None
-</pre>
-<p>Examples of custom descriptors:</p>
-<pre class="literal-block">
-#&lt;descriptor.py&gt;
-
-
-class AttributeDescriptor(object):
- def __get__(self, obj, cls=None):
- if obj is None and cls is None:
- raise TypeError(&quot;__get__(None, None) is invalid&quot;)
- elif obj is None:
- return self.get_from_class(cls)
- else:
- return self.get_from_obj(obj)
- def get_from_class(self, cls):
- print &quot;Getting %s from %s&quot; % (self, cls)
- def get_from_obj(self, obj):
- print &quot;Getting %s from %s&quot; % (self, obj)
-
-
-class Staticmethod(AttributeDescriptor):
- def __init__(self, func):
- self.func = func
- def get_from_class(self, cls):
- return self.func
- get_from_obj = get_from_class
-
-
-class Classmethod(AttributeDescriptor):
- def __init__(self, func):
- self.func = func
- def get_from_class(self, cls):
- return self.func.__get__(cls, type(cls))
- def get_from_obj(self, obj):
- return self.get_from_class(obj.__class__)
-
-class C(object):
- s = Staticmethod(lambda : 1)
- c = Classmethod(lambda cls : cls.__name__)
-
-c = C()
-
-assert C.s() == c.s() == 1
-assert C.c() == c.c() == &quot;C&quot;
-
-#&lt;/descriptor.py&gt;
-</pre>
-</div>
-<div class="section" id="multilingual-attribute">
-<h3><a class="toc-backref" href="#id26" name="multilingual-attribute">Multilingual attribute</a></h3>
-<p>Inspirated by a question in the Italian Newsgroup:</p>
-<pre class="literal-block">
-#&lt;multilingual.py&gt;
-
-import sys
-from descriptor import AttributeDescriptor
-
-class MultilingualAttribute(AttributeDescriptor):
- &quot;&quot;&quot;When a MultilingualAttribute is accessed, you get the translation
- corresponding to the currently selected language.
- &quot;&quot;&quot;
- def __init__(self, **translations):
- self.trans = translations
- def get_from_class(self, cls):
- return self.trans[getattr(cls, &quot;language&quot;, None) or
- sys.modules[cls.__module__].language]
- def get_from_obj(self, obj):
- return self.trans[getattr(obj, &quot;language&quot;, None) or
- sys.modules[obj.__class__.__module__].language]
-
-
-language = &quot;en&quot;
-
-# a dummy User class
-class DefaultUser(object):
- def has_permission(self):
- return False
-
-class WebApplication(object):
- error_msg = MultilingualAttribute(
- en=&quot;You cannot access this page&quot;,
- it=&quot;Questa pagina non e' accessibile&quot;,
- fr=&quot;Vous ne pouvez pas acceder cette page&quot;,)
- user = DefaultUser()
- def __init__(self, language=None):
- self.language = language or getattr(self.__class__, &quot;language&quot;, None)
- def show_page(self):
- if not self.user.has_permission():
- return self.error_msg
-
-
-app = WebApplication()
-assert app.show_page() == &quot;You cannot access this page&quot;
-
-app.language = &quot;fr&quot;
-assert app.show_page() == &quot;Vous ne pouvez pas acceder cette page&quot;
-
-app.language = &quot;it&quot;
-assert app.show_page() == &quot;Questa pagina non e' accessibile&quot;
-
-app.language = &quot;en&quot;
-assert app.show_page() == &quot;You cannot access this page&quot;
-
-#&lt;/multilingual.py&gt;
-</pre>
-<p>The same can be done with properties:</p>
-<pre class="literal-block">
-#&lt;multilingualprop.py&gt;
-
-language = &quot;en&quot;
-
-# a dummy User class
-class DefaultUser(object):
- def has_permission(self):
- return False
-
-def multilingualProperty(**trans):
- def get(self):
- return trans[self.language]
- def set(self, value):
- trans[self.language] = value
- return property(get, set)
-
-class WebApplication(object):
- language = language
- error_msg = multilingualProperty(
- en=&quot;You cannot access this page&quot;,
- it=&quot;Questa pagina non e' accessibile&quot;,
- fr=&quot;Vous ne pouvez pas acceder cette page&quot;,)
- user = DefaultUser()
- def __init__(self, language=None):
- if language: self.language = self.language
- def show_page(self):
- if not self.user.has_permission():
- return self.error_msg
-
-#&lt;/multilingualprop.py&gt;
-</pre>
-<p>This also gives the possibility to set the error messages.</p>
-<p>The difference with the descriptor approach</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from multilingual import WebApplication
-&gt;&gt;&gt; app = WebApplication()
-&gt;&gt;&gt; print app.error_msg
-You cannot access this page
-&gt;&gt;&gt; print WebApplication.error_msg
-You cannot access this page
-</pre>
-<p>is that with properties there is no nice access from the class:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from multilingualprop import WebApplication
-&gt;&gt;&gt; WebApplication.error_msg #doctest: +ELLIPSIS
-&lt;property object at ...&gt;
-</pre>
-</div>
-<div class="section" id="another-use-case-for-properties-storing-users">
-<h3><a class="toc-backref" href="#id27" name="another-use-case-for-properties-storing-users">Another use case for properties: storing users</a></h3>
-<p>Consider a library providing a simple User class:</p>
-<pre class="literal-block">
-#&lt;crypt_user.py&gt;
-
-class User(object):
- def __init__(self, username, password):
- self.username, self.password = username, password
-
-#&lt;/crypt_user.py&gt;
-</pre>
-<p>The User objects are stored in a database as they are.
-For security purpose, in a second version of the library it is
-decided to crypt the password, so that only crypted passwords
-are stored in the database. With properties, it is possible to
-implement this functionality without changing the source code for
-the User class:</p>
-<pre class="literal-block">
-#&lt;crypt_user.py&gt;
-
-from crypt import crypt
-
-def cryptedAttribute(seed=&quot;x&quot;):
- def get(self):
- return getattr(self, &quot;_pw&quot;, None)
- def set(self, value):
- self._pw = crypt(value, seed)
- return property(get, set)
-
-User.password = cryptedAttribute()
-</pre>
-<p>#&lt;/crypt_user.py&gt;</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from crypt_user import User
-&gt;&gt;&gt; u = User(&quot;michele&quot;, &quot;secret&quot;)
-&gt;&gt;&gt; print u.password
-xxZREZpkHZpkI
-</pre>
-<p>Notice the property factory approach used here.</p>
-</div>
-<div class="section" id="low-level-delegation-via-getattribute">
-<h3><a class="toc-backref" href="#id28" name="low-level-delegation-via-getattribute">Low-level delegation via __getattribute__</a></h3>
-<p>Attribute access is managed by the__getattribute__ special method:</p>
-<pre class="literal-block">
-#&lt;tracedaccess.py&gt;
-
-class TracedAccess(object):
- def __getattribute__(self, name):
- print &quot;Accessing %s&quot; % name
- return object.__getattribute__(self, name)
-
-
-class C(TracedAccess):
- s = staticmethod(lambda : 'staticmethod')
- c = classmethod(lambda cls: 'classmethod')
- m = lambda self: 'method'
- a = &quot;hello&quot;
-
-#&lt;/tracedaccess.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from tracedaccess import C
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; print c.s()
-Accessing s
-staticmethod
-&gt;&gt;&gt; print c.c()
-Accessing c
-classmethod
-&gt;&gt;&gt; print c.m()
-Accessing m
-method
-&gt;&gt;&gt; print c.a
-Accessing a
-hello
-&gt;&gt;&gt; print c.__init__ #doctest: +ELLIPSIS
-Accessing __init__
-&lt;method-wrapper object at 0x...&gt;
-&gt;&gt;&gt; try: c.x
-... except AttributeError, e: print e
-...
-Accessing x
-'C' object has no attribute 'x'
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.y = 'y'
-&gt;&gt;&gt; c.y
-Accessing y
-'y'
-</pre>
-<p>You are probably familiar with <tt class="docutils literal"><span class="pre">__getattr__</span></tt> which is similar
-to <tt class="docutils literal"><span class="pre">__getattribute__</span></tt>, but it is called <em>only for missing attributes</em>.</p>
-</div>
-<div class="section" id="traditional-delegation-via-getattr">
-<h3><a class="toc-backref" href="#id29" name="traditional-delegation-via-getattr">Traditional delegation via __getattr__</a></h3>
-<p>Realistic use case in &quot;object publishing&quot;:</p>
-<pre class="literal-block">
-#&lt;webapp.py&gt;
-
-class WebApplication(object):
- def __getattr__(self, name):
- return name.capitalize()
-
-
-app = WebApplication()
-
-assert app.page1 == 'Page1'
-assert app.page2 == 'Page2'
-
-#&lt;/webapp.py&gt;
-</pre>
-<p>Here is another use case in HTML generation:</p>
-<pre class="literal-block">
-#&lt;XMLtag.py&gt;
-
-def makeattr(dict_or_list_of_pairs):
- dic = dict(dict_or_list_of_pairs)
- return &quot; &quot;.join('%s=&quot;%s&quot;' % (k, dic[k]) for k in dic) # simplistic
-
-class XMLTag(object):
- def __getattr__(self, name):
- def tag(value, **attr):
- &quot;&quot;&quot;value can be a string or a sequence of strings.&quot;&quot;&quot;
- if hasattr(value, &quot;__iter__&quot;): # is iterable
- value = &quot; &quot;.join(value)
- return &quot;&lt;%s %s&gt;%s&lt;/%s&gt;&quot; % (name, makeattr(attr), value, name)
- return tag
-
-class XMLShortTag(object):
- def __getattr__(self, name):
- def tag(**attr):
- return &quot;&lt;%s %s /&gt;&quot; % (name, makeattr(attr))
- return tag
-
-tag = XMLTag()
-tg = XMLShortTag()
-
-#&lt;/XMLtag.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from XMLtag import tag, tg
-&gt;&gt;&gt; print tag.a(&quot;example.com&quot;, href=&quot;http://www.example.com&quot;)
-&lt;a href=&quot;http://www.example.com&quot;&gt;example.com&lt;/a&gt;
-&gt;&gt;&gt; print tg.br(**{'class':&quot;br_style&quot;})
-&lt;br class=&quot;br_style&quot; /&gt;
-</pre>
-</div>
-<div class="section" id="keyword-dictionaries-with-getattr-setattr">
-<h3><a class="toc-backref" href="#id30" name="keyword-dictionaries-with-getattr-setattr">Keyword dictionaries with __getattr__/__setattr__</a></h3>
-<pre class="literal-block">
-#&lt;kwdict.py&gt;
-
-class kwdict(dict): # or UserDict, to make it to work with Zope
- &quot;&quot;&quot;A typing shortcut used in place of a keyword dictionary.&quot;&quot;&quot;
- def __getattr__(self, name):
- return self[name]
- def __setattr__(self, name, value):
- self[name] = value
-
-#&lt;/kwdict.py&gt;
-</pre>
-<p>And now for a completely different solution:</p>
-<pre class="literal-block">
-#&lt;dictwrapper.py&gt;
-
-class DictWrapper(object):
- def __init__(self, **kw):
- self.__dict__.update(kw)
-
-#&lt;/dictwrapper.py&gt;
-</pre>
-</div>
-<div class="section" id="delegation-to-special-methods-caveat">
-<h3><a class="toc-backref" href="#id31" name="delegation-to-special-methods-caveat">Delegation to special methods caveat</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; class ListWrapper(object):
-... def __init__(self, ls):
-... self._list = ls
-... def __getattr__(self, name):
-... if name == &quot;__getitem__&quot;: # special method
-... return self._list.__getitem__
-... elif name == &quot;reverse&quot;: # regular method
-... return self._list.reverse
-... else:
-... raise AttributeError(&quot;%r is not defined&quot; % name)
-...
-&gt;&gt;&gt; lw = ListWrapper([0,1,2])
-&gt;&gt;&gt; print lw.x
-Traceback (most recent call last):
- ...
-AttributeError: 'x' is not defined
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; lw.reverse()
-&gt;&gt;&gt; print lw.__getitem__(0)
-2
-&gt;&gt;&gt; print lw.__getitem__(1)
-1
-&gt;&gt;&gt; print lw.__getitem__(2)
-0
-&gt;&gt;&gt; print lw[0]
-Traceback (most recent call last):
- ...
-TypeError: unindexable object
-</pre>
-</div>
-</div>
-<div class="section" id="part-ii-inheritance">
-<h2><a class="toc-backref" href="#id32" name="part-ii-inheritance">Part II: Inheritance</a></h2>
-<p>The major changes in inheritance from Python 2.1 to 2.2+ are:</p>
-<ol class="arabic simple">
-<li>you can subclass built-in types (as a consequence the constructor__new__
-has been exposed to the user, to help subclassing immutable types);</li>
-<li>the Method Resolution Order (MRO) has changed;</li>
-<li>now Python allows <em>cooperative method calls</em>, i.e. we have <em>super</em>.</li>
-</ol>
-<div class="section" id="why-you-need-to-know-about-mi-even-if-you-do-not-use-it">
-<h3><a class="toc-backref" href="#id33" name="why-you-need-to-know-about-mi-even-if-you-do-not-use-it">Why you need to know about MI even if you do not use it</a></h3>
-<p>In principle, the last two changes are relevant only if you use multiple
-inheritance. If you use single inheritance only, you don't need <tt class="docutils literal"><span class="pre">super</span></tt>:
-you can just name the superclass.
-However, somebody else may want to use your class in a MI hierarchy,
-and you would make her life difficult if you don't use <tt class="docutils literal"><span class="pre">super</span></tt>.</p>
-<p>My SI hierarchy:</p>
-<pre class="literal-block">
-#&lt;why_super.py&gt;
-
-class Base(object):
- def __init__(self):
- print &quot;B.__init__&quot;
-
-class MyClass(Base):
- &quot;I do not cooperate with others&quot;
- def __init__(self):
- print &quot;MyClass.__init__&quot;
- Base.__init__(self) #instead of super(MyClass, self).__init__()
-
-#&lt;/why_super.py&gt;
-</pre>
-<p>Her MI hierarchy:</p>
-<pre class="literal-block">
-#&lt;why_super.py&gt;
-
-class Mixin(Base):
- &quot;I am cooperative with others&quot;
- def __init__(self):
- print &quot;Mixin.__init__&quot;
- super(Mixin, self).__init__()
-
-class HerClass(MyClass, Mixin):
- &quot;I am supposed to be cooperative too&quot;
- def __init__(self):
- print &quot;HerClass.__init__&quot;
- super(HerClass, self).__init__()
-
-#&lt;/why_super.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from why_super import HerClass
-&gt;&gt;&gt; h = HerClass() # Mixin.__init__ is not called!
-HerClass.__init__
-MyClass.__init__
-B.__init__
-</pre>
-<blockquote>
-<pre class="literal-block">
- 4 object
- |
- 3 Base
- / \
-1 MyClass 2 Mixin
- \ /
- 0 HerClass
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; [ancestor.__name__ for ancestor in HerClass.mro()]
-['HerClass', 'MyClass', 'Mixin', 'Base', 'object']
-</pre>
-<p>In order to be polite versus your future users, you should use <tt class="docutils literal"><span class="pre">super</span></tt>
-always. This adds a cognitive burden even for people not using MI :-(</p>
-<p>Notice that there is no good comprehensive reference on <tt class="docutils literal"><span class="pre">super</span></tt> (yet)
-Your best bet is still <a class="reference" href="http://www.python.org/2.2.3/descrintro.html#cooperation">http://www.python.org/2.2.3/descrintro.html#cooperation</a></p>
-<p>The MRO instead is explained here: <a class="reference" href="http://www.python.org/2.3/mro.html">http://www.python.org/2.3/mro.html</a></p>
-<p>Notice that I DO NOT recommand Multiple Inheritance.</p>
-<p>More often than not you are better off using composition/delegation/wrapping,
-etc.</p>
-<p>See Zope 2 -&gt; Zope 3 experience.</p>
-</div>
-<div class="section" id="a-few-details-about-super-not-the-whole-truth">
-<h3><a class="toc-backref" href="#id34" name="a-few-details-about-super-not-the-whole-truth">A few details about <tt class="docutils literal docutils literal"><span class="pre">super</span></tt> (not the whole truth)</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B(object):
-... def __init__(self): print &quot;B.__init__&quot;
-...
-&gt;&gt;&gt; class C(B):
-... def __init__(self): print &quot;C.__init__&quot;
-...
-&gt;&gt;&gt; c = C()
-C.__init__
-</pre>
-<p><tt class="docutils literal"><span class="pre">super(cls,</span> <span class="pre">instance)</span></tt>, where <tt class="docutils literal"><span class="pre">instance</span></tt> is an instance of <tt class="docutils literal"><span class="pre">cls</span></tt> or of
-a subclass of <tt class="docutils literal"><span class="pre">cls</span></tt>, retrieves the right method in the MRO:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, c).__init__ #doctest: +ELLIPSIS
-&lt;bound method C.__init__ of &lt;__main__.C object at 0x...&gt;&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, c).__init__.im_func is B.__init__.im_func
-True
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, c).__init__()
-B.__init__
-</pre>
-<p><tt class="docutils literal"><span class="pre">super(cls,</span> <span class="pre">subclass)</span></tt> works for unbound methods:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, C).__init__
-&lt;unbound method C.__init__&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, C).__init__.im_func is B.__init__.im_func
-True
-&gt;&gt;&gt; super(C, C).__init__(c)
-B.__init__
-</pre>
-<p><tt class="docutils literal"><span class="pre">super(cls,</span> <span class="pre">subclass)</span></tt> is also necessary for classmethods and staticmethods.
-Properties and custom descriptorsw works too:</p>
-<pre class="literal-block">
-#&lt;super_ex.py&gt;
-
-from descriptor import AttributeDescriptor
-
-class B(object):
- &#64;staticmethod
- def sm(): return &quot;staticmethod&quot;
-
- &#64;classmethod
- def cm(cls): return cls.__name__
-
- p = property()
- a = AttributeDescriptor()
-
-class C(B): pass
-
-#&lt;/super_ex.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from super_ex import C
-</pre>
-<p>Staticmethod usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, C).sm #doctest: +ELLIPSIS
-&lt;function sm at 0x...&gt;
-&gt;&gt;&gt; super(C, C).sm()
-'staticmethod'
-</pre>
-<p>Classmethod usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, C()).cm
-&lt;bound method type.cm of &lt;class 'super_ex.C'&gt;&gt;
-&gt;&gt;&gt; super(C, C).cm() # C is automatically passed
-'C'
-</pre>
-<p>Property usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print super(C, C).p #doctest: +ELLIPSIS
-&lt;property object at 0x...&gt;
-&gt;&gt;&gt; super(C, C).a #doctest: +ELLIPSIS
-Getting &lt;descriptor.AttributeDescriptor object at 0x...&gt; from &lt;class 'super_ex.C'&gt;
-</pre>
-<p><tt class="docutils literal"><span class="pre">super</span></tt> does not work with old-style classes, however you can use the
-following trick:</p>
-<pre class="literal-block">
-#&lt;super_old_new.py&gt;
-class O:
- def __init__(self):
- print &quot;O.__init__&quot;
-
-class N(O, object):
- def __init__(self):
- print &quot;N.__init__&quot;
- super(N, self).__init__()
-
-#&lt;/super_old_new.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from super_old_new import N
-&gt;&gt;&gt; new = N()
-N.__init__
-O.__init__
-</pre>
-<p>There are dozens of tricky points concerning <tt class="docutils literal"><span class="pre">super</span></tt>, be warned!</p>
-</div>
-<div class="section" id="subclassing-built-in-types-new-vs-init">
-<h3><a class="toc-backref" href="#id35" name="subclassing-built-in-types-new-vs-init">Subclassing built-in types; __new__ vs. __init__</a></h3>
-<pre class="literal-block">
-#&lt;point.py&gt;
-
-class NotWorkingPoint(tuple):
- def __init__(self, x, y):
- super(NotWorkingPoint, self).__init__((x,y))
- self.x, self.y = x, y
-
-#&lt;/point.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from point import NotWorkingPoint
-&gt;&gt;&gt; p = NotWorkingPoint(2,3)
-Traceback (most recent call last):
- ...
-TypeError: tuple() takes at most 1 argument (2 given)
-</pre>
-<pre class="literal-block">
-#&lt;point.py&gt;
-
-class Point(tuple):
- def __new__(cls, x, y):
- return super(Point, cls).__new__(cls, (x,y))
- def __init__(self, x, y):
- super(Point, self).__init__((x, y))
- self.x, self.y = x, y
-
-#&lt;/point.py&gt;
-</pre>
-<p>Notice that__new__ is a staticmethod, not a classmethod, so one needs
-to pass the class explicitely.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from point import Point
-&gt;&gt;&gt; p = Point(2,3)
-&gt;&gt;&gt; print p, p.x, p.y
-(2, 3) 2 3
-</pre>
-</div>
-<div class="section" id="be-careful-when-using-new-with-mutable-types">
-<h3><a class="toc-backref" href="#id36" name="be-careful-when-using-new-with-mutable-types">Be careful when using __new__ with mutable types</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; class ListWithDefault(list):
-... def __new__(cls):
-... return super(ListWithDefault, cls).__new__(cls, [&quot;hello&quot;])
-...
-&gt;&gt;&gt; print ListWithDefault() # beware! NOT [&quot;hello&quot;]!
-[]
-</pre>
-<p>Reason: lists are re-initialized to empty lists in list.__init__!</p>
-<p>Instead</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class ListWithDefault(list):
-... def __init__(self):
-... super(ListWithDefault, self).__init__([&quot;hello&quot;])
-...
-&gt;&gt;&gt; print ListWithDefault() # works!
-['hello']
-</pre>
-</div>
-</div>
-</div>
-<div class="section" id="lecture-3-magic-i-e-decorators-and-metaclasses">
-<h1><a class="toc-backref" href="#id37" name="lecture-3-magic-i-e-decorators-and-metaclasses">Lecture 3: Magic (i.e. decorators and metaclasses)</a></h1>
-<div class="section" id="part-i-decorators">
-<h2><a class="toc-backref" href="#id38" name="part-i-decorators">Part I: decorators</a></h2>
-<p>Decorators are just sugar: their functionality was already in the language</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def s(): pass
-&gt;&gt;&gt; s = staticmethod(s)
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; &#64;staticmethod
-... def s(): pass
-...
-</pre>
-<p>However sugar <em>does</em> matter.</p>
-<div class="section" id="a-typical-decorator-traced">
-<h3><a class="toc-backref" href="#id39" name="a-typical-decorator-traced">A typical decorator: traced</a></h3>
-<pre class="literal-block">
-#&lt;traced.py&gt;
-
-def traced(func):
- def tracedfunc(*args, **kw):
- print &quot;calling %s.%s&quot; % (func.__module__, func.__name__)
- return func(*args, **kw)
- tracedfunc.__name__ = func.__name__
- return tracedfunc
-
-&#64;traced
-def f(): pass
-
-#&lt;/traced.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from traced import f
-&gt;&gt;&gt; f()
-calling traced.f
-</pre>
-</div>
-<div class="section" id="a-decorator-factory-timed">
-<h3><a class="toc-backref" href="#id40" name="a-decorator-factory-timed">A decorator factory: Timed</a></h3>
-<pre class="literal-block">
-#&lt;timed.py&gt;
-
-import sys, time
-
-class Timed(object):
- &quot;&quot;&quot;Decorator factory: each decorator object wraps a function and
- executes it many times (default 100 times).
- The average time spent in one iteration, expressed in milliseconds,
- is stored in the attributes wrappedfunc.time and wrappedfunc.clocktime,
- and displayed into a log file which defaults to stdout.
- &quot;&quot;&quot;
- def __init__(self, repeat=100, logfile=sys.stdout):
- self.repeat = repeat
- self.logfile = logfile
- def __call__(self, func):
- def wrappedfunc(*args, **kw):
- fullname = &quot;%s.%s ...&quot; % (func.__module__, func.func_name)
- print &gt;&gt; self.logfile, 'Executing %s' % fullname.ljust(30),
- time1 = time.time()
- clocktime1 = time.clock()
- for i in xrange(self.repeat):
- res = func(*args,**kw) # executes func self.repeat times
- time2 = time.time()
- clocktime2 = time.clock()
- wrappedfunc.time = 1000*(time2-time1)/self.repeat
- wrappedfunc.clocktime = 1000*(clocktime2 - clocktime1)/self.repeat
- print &gt;&gt; self.logfile, \
- 'Real time: %s ms;' % self.rounding(wrappedfunc.time),
- print &gt;&gt; self.logfile, \
- 'Clock time: %s ms' % self.rounding(wrappedfunc.clocktime)
- return res
- wrappedfunc.func_name = func.func_name
- wrappedfunc.__module__ = func.__module__
- return wrappedfunc
- &#64;staticmethod
- def rounding(float_):
- &quot;Three digits rounding for small numbers, 1 digit rounding otherwise.&quot;
- if float_ &lt; 10.:
- return &quot;%5.3f&quot; % float_
- else:
- return &quot;%5.1f&quot; % float_
-
-#&lt;/timed.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from timed import Timed
-&gt;&gt;&gt; from random import sample
-&gt;&gt;&gt; example_ls = sample(xrange(1000000), 1000)
-&gt;&gt;&gt; &#64;Timed()
-... def list_sort(ls):
-... ls.sort()
-...
-&gt;&gt;&gt; list_sort(example_ls) #doctest: +ELLIPSIS
-Executing __main__.list_sort ... Real time: 0... ms; Clock time: 0... ms
-</pre>
-</div>
-<div class="section" id="a-powerful-decorator-pattern">
-<h3><a class="toc-backref" href="#id41" name="a-powerful-decorator-pattern">A powerful decorator pattern</a></h3>
-<pre class="literal-block">
-#&lt;traced_function2.py&gt;
-
-from decorators import decorator
-
-def trace(f, *args, **kw):
- print &quot;calling %s with args %s, %s&quot; % (f.func_name, args, kw)
- return f(*args, **kw)
-
-traced_function = decorator(trace)
-
-&#64;traced_function
-def f1(x):
- pass
-
-&#64;traced_function
-def f2(x, y):
- pass
-
-#&lt;/traced_function2.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from traced_function2 import traced_function, f1, f2
-&gt;&gt;&gt; f1(1)
-calling f1 with args (1,), {}
-&gt;&gt;&gt; f2(1,2)
-calling f2 with args (1, 2), {}
-</pre>
-<p>works with pydoc:</p>
-<pre class="literal-block">
-$ pydoc2.4 traced_function2.f2
-Help on function f1 in traced_function2:
-
-traced_function2.f1 = f1(x)
-
-$ pydoc2.4 traced_function2.f2
-Help on function f2 in traced_function2:
-
-traced_function2.f2 = f2(x, y)
-</pre>
-<p>Here is the source code:</p>
-<pre class="literal-block">
-#&lt;decorators.py&gt;
-
-import inspect, itertools
-
-def getinfo(func):
- &quot;&quot;&quot;Return an info dictionary containing:
- - name (the name of the function : str)
- - argnames (the names of the arguments : list)
- - defarg (the values of the default arguments : list)
- - fullsign (the full signature : str)
- - shortsign (the short signature : str)
- - arg0 ... argn (shortcuts for the names of the arguments)
-
- &gt;&gt; def f(self, x=1, y=2, *args, **kw): pass
-
- &gt;&gt; info = getinfo(f)
-
- &gt;&gt; info[&quot;name&quot;]
- 'f'
- &gt;&gt; info[&quot;argnames&quot;]
- ['self', 'x', 'y', 'args', 'kw']
-
- &gt;&gt; info[&quot;defarg&quot;]
- (1, 2)
-
- &gt;&gt; info[&quot;shortsign&quot;]
- 'self, x, y, *args, **kw'
-
- &gt;&gt; info[&quot;fullsign&quot;]
- 'self, x=defarg[0], y=defarg[1], *args, **kw'
-
- &gt;&gt; info[&quot;arg0&quot;], info[&quot;arg1&quot;], info[&quot;arg2&quot;], info[&quot;arg3&quot;], info[&quot;arg4&quot;]
- ('self', 'x', 'y', 'args', 'kw')
- &quot;&quot;&quot;
- assert inspect.ismethod(func) or inspect.isfunction(func)
- regargs, varargs, varkwargs, defaults = inspect.getargspec(func)
- argnames = list(regargs)
- if varargs: argnames.append(varargs)
- if varkwargs: argnames.append(varkwargs)
- counter = itertools.count()
- fullsign = inspect.formatargspec(
- regargs, varargs, varkwargs, defaults,
- formatvalue=lambda value: &quot;=defarg[%i]&quot; % counter.next())[1:-1]
- shortsign = inspect.formatargspec(
- regargs, varargs, varkwargs, defaults,
- formatvalue=lambda value: &quot;&quot;)[1:-1]
- dic = dict((&quot;arg%s&quot; % n, name) for n, name in enumerate(argnames))
- dic.update(name=func.__name__, argnames=argnames, shortsign=shortsign,
- fullsign = fullsign, defarg = func.func_defaults or ())
- return dic
-
-def _contains_reserved_names(dic): # helper
- return &quot;_call_&quot; in dic or &quot;_func_&quot; in dic
-
-def _decorate(func, caller):
- &quot;&quot;&quot;Takes a function and a caller and returns the function
- decorated with that caller. The decorated function is obtained
- by evaluating a lambda function with the correct signature.
- &quot;&quot;&quot;
- infodict = getinfo(func)
- assert not _contains_reserved_names(infodict[&quot;argnames&quot;]), \
- &quot;You cannot use _call_ or _func_ as argument names!&quot;
- execdict=dict(_func_=func, _call_=caller, defarg=func.func_defaults or ())
- if func.__name__ == &quot;&lt;lambda&gt;&quot;:
- lambda_src = &quot;lambda %(fullsign)s: _call_(_func_, %(shortsign)s)&quot; \
- % infodict
- dec_func = eval(lambda_src, execdict)
- else:
- func_src = &quot;&quot;&quot;def %(name)s(%(fullsign)s):
- return _call_(_func_, %(shortsign)s)&quot;&quot;&quot; % infodict
- exec func_src in execdict
- dec_func = execdict[func.__name__]
- dec_func.__doc__ = func.__doc__
- dec_func.__dict__ = func.__dict__
- return dec_func
-
-class decorator(object):
- &quot;&quot;&quot;General purpose decorator factory: takes a caller function as
-input and returns a decorator. A caller function is any function like this::
-
- def caller(func, *args, **kw):
- # do something
- return func(*args, **kw)
-
-Here is an example of usage:
-
- &gt;&gt; &#64;decorator
- .. def chatty(f, *args, **kw):
- .. print &quot;Calling %r&quot; % f.__name__
- .. return f(*args, **kw)
-
- &gt;&gt; &#64;chatty
- .. def f(): pass
- ..
- &gt;&gt; f()
- Calling 'f'
- &quot;&quot;&quot;
- def __init__(self, caller):
- self.caller = caller
- def __call__(self, func):
- return _decorate(func, self.caller)
-
-
-#&lt;/decorators.py&gt;
-</pre>
-<p>The possibilities of this pattern are endless.</p>
-</div>
-<div class="section" id="a-deferred-decorator">
-<h3><a class="toc-backref" href="#id42" name="a-deferred-decorator">A deferred decorator</a></h3>
-<p>You want to execute a procedure only after a certain time delay (for instance
-for use within an asyncronous Web framework):</p>
-<pre class="literal-block">
-#&lt;deferred.py&gt;
-&quot;Deferring the execution of a procedure (function returning None)&quot;
-
-import threading
-from decorators import decorator
-
-def deferred(nsec):
- def call_later(func, *args, **kw):
- return threading.Timer(nsec, func, args, kw).start()
- return decorator(call_later)
-
-&#64;deferred(2)
-def hello():
- print &quot;hello&quot;
-
-if __name__ == &quot;__main__&quot;:
- hello()
- print &quot;Calling hello() ...&quot;
-
-
-#&lt;/deferred.py&gt;
-
-$ python deferred.py
-</pre>
-<p>Show an example of an experimental decorator based web framework
-(doctester_frontend).</p>
-</div>
-</div>
-<div class="section" id="part-ii-metaclasses">
-<h2><a class="toc-backref" href="#id43" name="part-ii-metaclasses">Part II: metaclasses</a></h2>
-<p>Metaclasses are there! Consider this example from a recent post on c.l.py:</p>
-<pre class="literal-block">
-#&lt;BaseClass.py&gt;
-
-class BaseClass(object):
- &quot;Do something&quot;
-
-#&lt;/BaseClass.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; import BaseClass # instead of 'from BaseClass import BaseClass'
-&gt;&gt;&gt; class C(BaseClass): pass
-...
-Traceback (most recent call last):
- ...
-TypeError: Error when calling the metaclass bases
- module.__init__() takes at most 2 arguments (3 given)
-</pre>
-<p>The reason for the error is that class <tt class="docutils literal"><span class="pre">C(BaseClass):</span> <span class="pre">pass</span></tt> is
-actually calling the <tt class="docutils literal"><span class="pre">type</span></tt> metaclass with three arguments:</p>
-<pre class="literal-block">
-C = type(&quot;C&quot;, (BaseClass,), {})
-</pre>
-<p><tt class="docutils literal"><span class="pre">type.__new__</span></tt> tries to use <tt class="docutils literal"><span class="pre">type(BaseClass)</span></tt> as metaclass,
-but since BaseClass here is a module, and <tt class="docutils literal"><span class="pre">ModuleType</span></tt> is not
-a metaclass, it cannot work. The error message reflects a conflict with
-the signature of ModuleType which requires two parameters and not three.</p>
-<p>So even if you don't use them, you may want to know they exist.</p>
-<div class="section" id="rejuvenating-old-style-classes">
-<h3><a class="toc-backref" href="#id44" name="rejuvenating-old-style-classes">Rejuvenating old-style classes</a></h3>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Old: pass
-&gt;&gt;&gt; print type(Old)
-&lt;type 'classobj'&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; __metaclass__ = type # to rejuvenate class
-&gt;&gt;&gt; class NotOld: pass
-...
-&gt;&gt;&gt; print NotOld.__class__
-&lt;type 'type'&gt;
-</pre>
-</div>
-<div class="section" id="a-typical-metaclass-example-metatracer">
-<h3><a class="toc-backref" href="#id45" name="a-typical-metaclass-example-metatracer">A typical metaclass example: MetaTracer</a></h3>
-<pre class="literal-block">
-#&lt;metatracer.py&gt;
-
-import inspect
-from decorators import decorator
-
-&#64;decorator
-def traced(meth, *args, **kw):
- cls = meth.__cls__
- modname = meth.__module__ or cls.__module__
- print &quot;calling %s.%s.%s&quot; % (modname, cls.__name__, meth.__name__)
- return meth(*args, **kw)
-
-class MetaTracer(type):
- def __init__(cls, name, bases, dic):
- super(MetaTracer, cls).__init__(name, bases, dic)
- for k, v in dic.iteritems():
- if inspect.isfunction(v):
- v.__cls__ = cls # so we know in which class v was defined
- setattr(cls, k, traced(v))
-
-#&lt;/metatracer.py&gt;
-</pre>
-<p>Usage: exploring classes in the standard library</p>
-<pre class="literal-block">
-#&lt;dictmixin.py&gt;
-
-from metatracer import MetaTracer
-from UserDict import DictMixin
-
-class TracedDM(DictMixin, object):
- __metaclass__ = MetaTracer
- def __getitem__(self, item):
- return item
- def keys(self):
- return [1,2,3]
-
-#&lt;/dictmixin.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from dictmixin import TracedDM
-&gt;&gt;&gt; print TracedDM()
-calling dictmixin.TracedDM.keys
-calling dictmixin.TracedDM.__getitem__
-calling dictmixin.TracedDM.__getitem__
-calling dictmixin.TracedDM.__getitem__
-{1: 1, 2: 2, 3: 3}
-</pre>
-</div>
-<div class="section" id="real-life-example-check-overriding">
-<h3><a class="toc-backref" href="#id46" name="real-life-example-check-overriding">Real life example: check overriding</a></h3>
-<pre class="literal-block">
-#&lt;check_overriding.py&gt;
-
-class Base(object):
- a = 0
-
-class CheckOverriding(type):
- &quot;Prints a message if we are overriding a name.&quot;
- def __new__(mcl, name, bases, dic):
- for name, val in dic.iteritems():
- if name.startswith(&quot;__&quot;) and name.endswith(&quot;__&quot;):
- continue # ignore special names
- a_base_has_name = True in (hasattr(base, name) for base in bases)
- if a_base_has_name:
- print &quot;AlreadyDefinedNameWarning: &quot; + name
- return super(CheckOverriding, mcl).__new__(mcl, name, bases, dic)
-
-class MyClass(Base):
- __metaclass__ = CheckOverriding
- a = 1
-
-class ChildClass(MyClass):
- a = 2
-</pre>
-<p>#&lt;/check_overriding.py&gt;</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import check_overriding
-AlreadyDefinedNameWarning: a
-AlreadyDefinedNameWarning: a
-</pre>
-</div>
-<div class="section" id="logfile">
-<h3><a class="toc-backref" href="#id47" name="logfile">LogFile</a></h3>
-<pre class="literal-block">
-#&lt;logfile.py&gt;
-
-import subprocess
-
-def memoize(func):
- memoize_dic = {}
- def wrapped_func(*args):
- if args in memoize_dic:
- return memoize_dic[args]
- else:
- result = func(*args)
- memoize_dic[args] = result
- return result
- wrapped_func.__name__ = func.__name__
- wrapped_func.__doc__ = func.__doc__
- wrapped_func.__dict__ = func.__dict__
- return wrapped_func
-
-class Memoize(type): # Singleton is a special case of Memoize
- &#64;memoize
- def __call__(cls, *args):
- return super(Memoize, cls).__call__(*args)
-
-class LogFile(file):
- &quot;&quot;&quot;Open a file for append.&quot;&quot;&quot;
- __metaclass__ = Memoize
- def __init__(self, name = &quot;/tmp/err.log&quot;):
- self.viewer_cmd = 'xterm -e less'.split()
- super(LogFile, self).__init__(name, &quot;a&quot;)
-
- def display(self, *ls):
- &quot;Use 'less' to display the log file in a separate xterm.&quot;
- print &gt;&gt; self, &quot;\n&quot;.join(map(str, ls)); self.flush()
- subprocess.call(self.viewer_cmd + [self.name])
-
- def reset(self):
- &quot;Erase the log file.&quot;
- print &gt;&gt; file(self.name, &quot;w&quot;)
-
-if __name__ == &quot;__main__&quot;: # test
- print &gt;&gt; LogFile(), &quot;hello&quot;
- print &gt;&gt; LogFile(), &quot;world&quot;
- LogFile().display()
-
-#&lt;/logfile.py&gt;
-
-$ python logfile.py
-</pre>
-</div>
-<div class="section" id="cooperative-hierarchies">
-<h3><a class="toc-backref" href="#id48" name="cooperative-hierarchies">Cooperative hierarchies</a></h3>
-<pre class="literal-block">
-#&lt;cooperative_init.py&gt;
-
-&quot;&quot;&quot;Given a hierarchy, makes __init__ cooperative.
-The only change needed is to add a line
-
- __metaclass__ = CooperativeInit
-
-to the base class of your hierarchy.&quot;&quot;&quot;
-
-from decorators import decorator
-
-class CooperativeInit(type):
- def __init__(cls, name, bases, dic):
-
- &#64;decorator
- def make_cooperative(__init__, self, *args, **kw):
- super(cls, self).__init__(*args, **kw)
- __init__(self, *args, **kw)
-
- __init__ = dic.get(&quot;__init__&quot;)
- if __init__:
- cls.__init__ = make_cooperative(__init__)
-
-class Base:
- __metaclass__ = CooperativeInit
- def __init__(self):
- print &quot;B.__init__&quot;
-
-class C1(Base):
- def __init__(self):
- print &quot;C1.__init__&quot;
-
-class C2(Base):
- def __init__(self):
- print &quot;C2.__init__&quot;
-
-class D(C1, C2):
- def __init__(self):
- print &quot;D.__init__&quot;
-
-#&lt;/cooperative_init.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from cooperative_init import D
-&gt;&gt;&gt; d = D()
-B.__init__
-C2.__init__
-C1.__init__
-D.__init__
-</pre>
-</div>
-<div class="section" id="metaclass-enhanced-modules">
-<h3><a class="toc-backref" href="#id49" name="metaclass-enhanced-modules">Metaclass-enhanced modules</a></h3>
-<pre class="literal-block">
-#&lt;import_with_metaclass.py&gt;
-&quot;&quot;&quot;
-``import_with_metaclass(metaclass, modulepath)`` generates
-a new module from and old module, by enhancing all of its classes.
-This is not perfect, but it should give you a start.&quot;&quot;&quot;
-
-import os, sys, inspect, types
-
-def import_with_metaclass(metaclass, modulepath):
- modname = os.path.basename(modulepath)[:-3] # simplistic
- mod = types.ModuleType(modname)
- locs = dict(
- __module__ = modname,
- __metaclass__ = metaclass,
- object = metaclass(&quot;object&quot;, (), {}))
- execfile(modulepath, locs)
- for k, v in locs.iteritems():
- if inspect.isclass(v): # otherwise it would be &quot;__builtin__&quot;
- v.__module__ = &quot;__dynamic__&quot;
- setattr(mod, k, v)
- return mod
-</pre>
-<p>#&lt;/import_with_metaclass.py&gt;</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from import_with_metaclass import import_with_metaclass
-&gt;&gt;&gt; from metatracer import MetaTracer
-&gt;&gt;&gt; traced_optparse = import_with_metaclass(MetaTracer,
-... &quot;/usr/lib/python2.4/optparse.py&quot;)
-&gt;&gt;&gt; op = traced_optparse.OptionParser()
-calling __dynamic__.OptionParser.__init__
-calling __dynamic__.OptionContainer.__init__
-calling __dynamic__.OptionParser._create_option_list
-calling __dynamic__.OptionContainer._create_option_mappings
-calling __dynamic__.OptionContainer.set_conflict_handler
-calling __dynamic__.OptionContainer.set_description
-calling __dynamic__.OptionParser.set_usage
-calling __dynamic__.IndentedHelpFormatter.__init__
-calling __dynamic__.HelpFormatter.__init__
-calling __dynamic__.HelpFormatter.set_parser
-calling __dynamic__.OptionParser._populate_option_list
-calling __dynamic__.OptionParser._add_help_option
-calling __dynamic__.OptionContainer.add_option
-calling __dynamic__.Option.__init__
-calling __dynamic__.Option._check_opt_strings
-calling __dynamic__.Option._set_opt_strings
-calling __dynamic__.Option._set_attrs
-calling __dynamic__.OptionContainer._check_conflict
-calling __dynamic__.OptionParser._init_parsing_state
-</pre>
-<p>traced_optparse is a dynamically generated module not leaving in the
-file system.</p>
-</div>
-<div class="section" id="magic-properties">
-<h3><a class="toc-backref" href="#id50" name="magic-properties">Magic properties</a></h3>
-<pre class="literal-block">
-#&lt;magicprop.py&gt;
-
-class MagicProperties(type):
- def __init__(cls, name, bases, dic):
- prop_names = set(name[3:] for name in dic
- if name.startswith(&quot;get&quot;)
- or name.startswith(&quot;set&quot;))
- for name in prop_names:
- getter = getattr(cls, &quot;get&quot; + name, None)
- setter = getattr(cls, &quot;set&quot; + name, None)
- setattr(cls, name, property(getter, setter))
-
-class Base(object):
- __metaclass__ = MagicProperties
- def getx(self):
- return self._x
- def setx(self, value):
- self._x = value
-
-class Child(Base):
- def getx(self):
- print &quot;getting x&quot;
- return super(Child, self).getx()
- def setx(self, value):
- print &quot;setting x&quot;
- super(Child, self).setx(value)
-
-#&lt;/magicprop.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from magicprop import Child
-&gt;&gt;&gt; c = Child()
-&gt;&gt;&gt; c.x = 1
-setting x
-&gt;&gt;&gt; print c.x
-getting x
-1
-</pre>
-</div>
-<div class="section" id="hack-evil-properties">
-<h3><a class="toc-backref" href="#id51" name="hack-evil-properties">Hack: evil properties</a></h3>
-<pre class="literal-block">
-#&lt;evilprop.py&gt;
-
-def convert2property(name, bases, d):
- return property(d.get('get'), d.get('set'),
- d.get('del'),d.get('__doc__'))
-
-class C(object):
- class x:
- &quot;&quot;&quot;An evil test property&quot;&quot;&quot;
- __metaclass__ = convert2property
- def get(self):
- print 'Getting %s' % self._x
- return self._x
- def set(self, value):
- self._x = value
- print 'Setting to', value
-
-#&lt;/evilprop.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from evilprop import C
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; c.x = 5
-Setting to 5
-&gt;&gt;&gt; c.x
-Getting 5
-5
-&gt;&gt;&gt; print C.x.__doc__
-An evil test property
-</pre>
-</div>
-<div class="section" id="why-i-suggest-not-to-use-metaclasses-in-production-code">
-<h3><a class="toc-backref" href="#id52" name="why-i-suggest-not-to-use-metaclasses-in-production-code">Why I suggest <em>not</em> to use metaclasses in production code</a></h3>
-<blockquote>
-<ul class="simple">
-<li>there are very few good use case for metaclasses in production code
-(i.e. 99% of time you don't need them)</li>
-<li>they put a cognitive burden on the developer;</li>
-<li>a design without metaclasses is less magic and likely more robust;</li>
-<li>a design with metaclasses makes it difficult to use other metaclasses
-for debugging.</li>
-</ul>
-</blockquote>
-<p>As far as I know, string.Template is the only metaclass-enhanced class
-in the standard library; the metaclass is used to give the possibility to
-change the defaults:</p>
-<pre class="literal-block">
-delimiter = '$'
-idpattern = r'[_a-z][_a-z0-9]*'
-</pre>
-<p>in subclasses of Template.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from string import Template
-&gt;&gt;&gt; from metatracer import MetaTracer
-&gt;&gt;&gt; class TracedTemplate(Template):
-... __metaclass__ = MetaTracer
-...
-Traceback (most recent call last):
- ...
-TypeError: Error when calling the metaclass bases
- metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-<p>Solution: use a consistent metaclass</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class GoodMeta(MetaTracer, type(Template)): pass
-...
-&gt;&gt;&gt; class TracedTemplate(Template):
-... __metaclass__ = GoodMeta
-</pre>
-</div>
-<div class="section" id="is-there-an-automatic-way-of-solving-the-conflict">
-<h3><a class="toc-backref" href="#id53" name="is-there-an-automatic-way-of-solving-the-conflict">Is there an automatic way of solving the conflict?</a></h3>
-<p>Yes, but you really need to be a metaclass wizard.</p>
-<p><a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197</a></p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from noconflict import classmaker
-&gt;&gt;&gt; class TracedTemplate(Template):
-... __metaclass__ = classmaker((MetaTracer,))
-&gt;&gt;&gt; print type(TracedTemplate)
-&lt;class 'noconflict._MetaTracer_TemplateMetaclass'&gt;
-</pre>
-<pre class="literal-block">
-#&lt;noconflict.py&gt;
-
-import inspect, types, __builtin__
-from skip_redundant import skip_redundant
-
-memoized_metaclasses_map = {}
-
-# utility function
-def remove_redundant(metaclasses):
- skipset = set([types.ClassType])
- for meta in metaclasses: # determines the metaclasses to be skipped
- skipset.update(inspect.getmro(meta)[1:])
- return tuple(skip_redundant(metaclasses, skipset))
-
-##################################################################
-## now the core of the module: two mutually recursive functions ##
-##################################################################
-
-def get_noconflict_metaclass(bases, left_metas, right_metas):
- &quot;&quot;&quot;Not intended to be used outside of this module, unless you know
- what you are doing.&quot;&quot;&quot;
- # make tuple of needed metaclasses in specified priority order
- metas = left_metas + tuple(map(type, bases)) + right_metas
- needed_metas = remove_redundant(metas)
-
- # return existing confict-solving meta, if any
- if needed_metas in memoized_metaclasses_map:
- return memoized_metaclasses_map[needed_metas]
- # nope: compute, memoize and return needed conflict-solving meta
- elif not needed_metas: # wee, a trivial case, happy us
- meta = type
- elif len(needed_metas) == 1: # another trivial case
- meta = needed_metas[0]
- # check for recursion, can happen i.e. for Zope ExtensionClasses
- elif needed_metas == bases:
- raise TypeError(&quot;Incompatible root metatypes&quot;, needed_metas)
- else: # gotta work ...
- metaname = '_' + ''.join([m.__name__ for m in needed_metas])
- meta = classmaker()(metaname, needed_metas, {})
- memoized_metaclasses_map[needed_metas] = meta
- return meta
-
-def classmaker(left_metas=(), right_metas=()):
- def make_class(name, bases, adict):
- metaclass = get_noconflict_metaclass(bases, left_metas, right_metas)
- return metaclass(name, bases, adict)
- return make_class
-
-#################################################################
-## and now a conflict-safe replacement for 'type' ##
-#################################################################
-
-__type__=__builtin__.type # the aboriginal 'type'
-# left available in case you decide to rebind __builtin__.type
-
-class safetype(__type__):
- # this is REALLY DEEP MAGIC
- &quot;&quot;&quot;Overrides the ``__new__`` method of the ``type`` metaclass, making the
- generation of classes conflict-proof.&quot;&quot;&quot;
- def __new__(mcl, *args):
- nargs = len(args)
- if nargs == 1: # works as __builtin__.type
- return __type__(args[0])
- elif nargs == 3: # creates the class using the appropriate metaclass
- n, b, d = args # name, bases and dictionary
- meta = get_noconflict_metaclass(b, (mcl,), ())
- if meta is mcl: # meta is trivial, dispatch to the default __new__
- return super(safetype, mcl).__new__(mcl, n, b, d)
- else: # non-trivial metaclass, dispatch to the right __new__
- # (it will take a second round) # print mcl, meta
- return super(mcl, meta).__new__(meta, n, b, d)
- else:
- raise TypeError('%s() takes 1 or 3 arguments' % mcl.__name__)
-
-#&lt;/noconflict.py&gt;
-</pre>
-</div>
-</div>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/oxford/doctest_talk/P01.html b/pypers/oxford/doctest_talk/P01.html
deleted file mode 100755
index a3a9e4d..0000000
--- a/pypers/oxford/doctest_talk/P01.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P01</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P02.html'>Next</a></td> <td bgcolor="lightblue"><a href='P25.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P01</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing in Python: wonderful doctest!</h1><br/>
-
-<center>
-
- ACCU Conference 2005 <br/> <br/>
-
- 22 Apr 2005 <br/> <br/>
-
- Michele Simionato <br/> <br/>
-
- michele.simionato@gmail.com <br/> <br/>
-
-</center></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P02.html b/pypers/oxford/doctest_talk/P02.html
deleted file mode 100755
index b187e50..0000000
--- a/pypers/oxford/doctest_talk/P02.html
+++ /dev/null
@@ -1,106 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P02</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>Next</a></td> <td bgcolor="lightblue"><a href='P01.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P02</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Summary</h1><br/>
-
-<ul>
- <li> What is automatic testing? </li>
- <li> Why automatic testing is better? </li>
- <li> Which kind of automatic testing? </li>
- <li> How does it work, in practice? </li>
- <li> What's the message?</li>
-<ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P03.html b/pypers/oxford/doctest_talk/P03.html
deleted file mode 100755
index dbfc5f8..0000000
--- a/pypers/oxford/doctest_talk/P03.html
+++ /dev/null
@@ -1,102 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P03</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P04.html'>Next</a></td> <td bgcolor="lightblue"><a href='P02.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P03</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>What is automatic testing</h1><br/>
-
-Any methodology that allows you to test
-your application mechanically, repeatedly
-and in a <em>controlled reproducible</em> way.</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P04.html b/pypers/oxford/doctest_talk/P04.html
deleted file mode 100755
index b05ff1a..0000000
--- a/pypers/oxford/doctest_talk/P04.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P04</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>Next</a></td> <td bgcolor="lightblue"><a href='P03.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P04</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing is better (1)</h1><br/>
-
-When doing manual testing typically you spend
-
-<center><h2>
-
- 1 hour of coding + 10 hours of testing/debugging
-
-</center></h2>
-
-on the other hand ...</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P05.html b/pypers/oxford/doctest_talk/P05.html
deleted file mode 100755
index 62b628a..0000000
--- a/pypers/oxford/doctest_talk/P05.html
+++ /dev/null
@@ -1,107 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P05</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P06.html'>Next</a></td> <td bgcolor="lightblue"><a href='P04.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P05</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing is better (2)</h1><br/>
-
-... when doing automatic testing typically you spend
-
-<br/> <br/>
-<center><h2>
-
- 1 hour of coding + 10 hours of testing/debugging !
-
-</center></h2></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P06.html b/pypers/oxford/doctest_talk/P06.html
deleted file mode 100755
index f4a18cb..0000000
--- a/pypers/oxford/doctest_talk/P06.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P06</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>Next</a></td> <td bgcolor="lightblue"><a href='P05.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P06</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>However ...</h1><br/>
-
-Think about six month later!
- <br/><br/>
-<center><em>
-
- there is a difference</em>
-
- <h2><u>Refactoring!</u><h2>
-
-</center></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P07.html b/pypers/oxford/doctest_talk/P07.html
deleted file mode 100755
index b6c31ae..0000000
--- a/pypers/oxford/doctest_talk/P07.html
+++ /dev/null
@@ -1,107 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P07</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P08.html'>Next</a></td> <td bgcolor="lightblue"><a href='P06.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P07</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Automatic testing in Python</h1><br/>
-
-There are two standard testing frameworks in Python:
-
-<ol>
- <li> unittest </li>
- <li> doctest </li>
-</ol>
-
-Which one should I use?</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P08.html b/pypers/oxford/doctest_talk/P08.html
deleted file mode 100755
index 6c6c43e..0000000
--- a/pypers/oxford/doctest_talk/P08.html
+++ /dev/null
@@ -1,102 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P08</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>Next</a></td> <td bgcolor="lightblue"><a href='P07.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P08</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Well,</h1><br/>
-
-since my talk has <em>doctest</em> in the title ...
-
- ;-)</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P09.html b/pypers/oxford/doctest_talk/P09.html
deleted file mode 100755
index 0e92531..0000000
--- a/pypers/oxford/doctest_talk/P09.html
+++ /dev/null
@@ -1,114 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P09</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P10.html'>Next</a></td> <td bgcolor="lightblue"><a href='P08.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P09</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>More seriously ...</h1><br/>
-
-Use different testing frameworks; each one has advantages
-and disadvantages; use combinations of them; invent your
-own testing procedure.
-
-I use combinations of
-
-<ul>
- <li> unittest </li>
- <li> doctest </li>
- <li> custom tests </li>
- <li> Makefile driven tests </li>
- <li> et al. </li>
-</ul>
-
-doctest emphasis is on <em>documentation</em></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P10.html b/pypers/oxford/doctest_talk/P10.html
deleted file mode 100755
index 19c6e36..0000000
--- a/pypers/oxford/doctest_talk/P10.html
+++ /dev/null
@@ -1,101 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P10</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>Next</a></td> <td bgcolor="lightblue"><a href='P09.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P10</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>What is doctest?</h1><br/>
-
-In its simplest form (which I do not use that much) doctest allows
-you to include tests in the docstrings of your application.</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P11.html b/pypers/oxford/doctest_talk/P11.html
deleted file mode 100755
index e838716..0000000
--- a/pypers/oxford/doctest_talk/P11.html
+++ /dev/null
@@ -1,114 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P11</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P12.html'>Next</a></td> <td bgcolor="lightblue"><a href='P10.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P11</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Example</h1><br/>
-<pre># split.py
-import re
-SEP = re.compile(r"\s*[,;]\s*")
-
-def split(text):
- """Split a string taking as separators "," ";".
- Example:
- >>> from split import split
- >>> split("hello, world!; welcome to PyUK!")
- ['hello', 'world!', 'welcome to PyUK!']
- """
- return SEP.split(text)
-
-if __name__ == "__main__":
- import doctest; doctest.testmod()
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P12.html b/pypers/oxford/doctest_talk/P12.html
deleted file mode 100755
index 230eb27..0000000
--- a/pypers/oxford/doctest_talk/P12.html
+++ /dev/null
@@ -1,119 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P12</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>Next</a></td> <td bgcolor="lightblue"><a href='P11.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P12</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Running doctest in verbose mode</h1><br/>
-
-<pre>
-$ python split.py -v
-Running __main__.__doc__
-0 of 0 examples failed in __main__.__doc__
-Running __main__.split.__doc__
-Trying: from split import split
-Expecting: nothing
-ok
-Trying: split("hello, world!; welcome to Oxford!")
-Expecting: ['hello', 'world!', 'welcome to Oxford!']
-ok
-0 of 2 examples failed in __main__.split.__doc__
-1 items had no tests:
- __main__
-1 items passed all tests:
- 2 tests in __main__.split
-2 tests in 2 items.
-2 passed and 0 failed.
-Test passed.
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P13.html b/pypers/oxford/doctest_talk/P13.html
deleted file mode 100755
index b2fe415..0000000
--- a/pypers/oxford/doctest_talk/P13.html
+++ /dev/null
@@ -1,111 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P13</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P14.html'>Next</a></td> <td bgcolor="lightblue"><a href='P12.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P13</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Why I do not use the docstring approach</h1><br/>
-
-<ul>
-<li> It makes you end up with very large docstrings</li>
-
-<li> It abuses the original purpose of docstrings</li>
-
-<li> It conflates two different aspects (code and tests on the code)</li>
-
-<li> It is much easier to write the documentation in a separate
- text file </li>
-
-<li> Testing should be done by an external tool anyway </li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P14.html b/pypers/oxford/doctest_talk/P14.html
deleted file mode 100755
index 5c16abf..0000000
--- a/pypers/oxford/doctest_talk/P14.html
+++ /dev/null
@@ -1,118 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P14</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>Next</a></td> <td bgcolor="lightblue"><a href='P13.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P14</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>How I use doctest</h1><br/>
-
-I hacked inside doctest and wrote a custom utility
-to extract doctests from documentation files since
-
-<ul>
- <li>I like keeping the documentation on a separate rst file</li>
-
- <li>there is no sync problem since you run the tests all the time</li>
-
- <li>it is useful for writing articles ...</li>
-
- <li> ... but also documentation for internal usage in the company</li>
-</ul>
-
-http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410052
-
-<pre>
-$ python -m doctester < split.txt
-doctest: run 4 tests, failed 0
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P15.html b/pypers/oxford/doctest_talk/P15.html
deleted file mode 100755
index a6843e3..0000000
--- a/pypers/oxford/doctest_talk/P15.html
+++ /dev/null
@@ -1,115 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P15</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P16.html'>Next</a></td> <td bgcolor="lightblue"><a href='P14.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P15</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Testing the doctester frontend</h1><br/>
-
-<pre>
->>> from ms.webtester import start_server, stop_server
->>> from ms.http_utils import urlopen
->>> baseurl = "http://localhost:7080/"
->>> home = "/home/micheles/md/python/quixote/"
-
->>> start_server(home + "doctester_frontend.py")
->>> import time; time.sleep(2) # wait a bit
-
-Making a POST:
-
->>> res = urlopen(baseurl, dict(txt=">>> 1 + 1\n2")).read()
->>> assert "tests" in res
->>> stop_server()
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P16.html b/pypers/oxford/doctest_talk/P16.html
deleted file mode 100755
index d5b4541..0000000
--- a/pypers/oxford/doctest_talk/P16.html
+++ /dev/null
@@ -1,118 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P16</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>Next</a></td> <td bgcolor="lightblue"><a href='P15.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P16</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Managing exceptions</h1><br/>
-
-It is possible to test that your program raises the exception you
-expect:
-
-<pre>
-
-$ echo "# split cannot work on a list
->>> from split import split
->>> split([])
-Traceback (most recent call last):
- ...
-TypeError: expected string or buffer
-" > x.txt
-
-$ doct x.txt
-x.txt: 2 tests passed in 0.01 seconds
-
-</pre>
-
-(notice however that relying on exception messages may be risky)</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P17.html b/pypers/oxford/doctest_talk/P17.html
deleted file mode 100755
index da93de5..0000000
--- a/pypers/oxford/doctest_talk/P17.html
+++ /dev/null
@@ -1,116 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P17</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P18.html'>Next</a></td> <td bgcolor="lightblue"><a href='P16.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P17</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>When tests fail</h1><br/>
-
-<pre>
-
-$ cat split-failure.txt
-An example of failed text:
-
->>> from split import split
->>> split("hello, world")
-['hello', ' world']
-
-$ doct split-failure.txt
-*****************************************************************
-Failure in example: split("hello, world")
-from line #5 of split-failure.txt
-Expected: ['hello', ' world']
-Got: ['hello', 'world']
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P18.html b/pypers/oxford/doctest_talk/P18.html
deleted file mode 100755
index 0acc512..0000000
--- a/pypers/oxford/doctest_talk/P18.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P18</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>Next</a></td> <td bgcolor="lightblue"><a href='P17.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P18</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Converting doctests to unittests</h1><br/>
-
-<pre>
- import unittest
- import doctest
- import my_module_with_doctests
-
- suite = doctest.DocTestSuite(my_module_with_doctests)
- runner = unittest.TextTestRunner()
- runner.run(suite)
-</pre>
-
-<h2>For Python 2.3+<h2></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P19.html b/pypers/oxford/doctest_talk/P19.html
deleted file mode 100755
index 744a43b..0000000
--- a/pypers/oxford/doctest_talk/P19.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P19</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P20.html'>Next</a></td> <td bgcolor="lightblue"><a href='P18.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P19</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>doctest is becoming even better</h1><br/>
-
-With Python 2.4 you can run doctests on external text files:
-
-<pre>
- import doctest, unittest
- doctest.testfile(my_documentation_file, package=mypackage)
-</pre>
-
-you can also convert these doctests into unittests:
-
-<pre>
- import doctest, unittest
- suite = doctest.DocFileSuite(my_documentation_file, package=mypackage)
- unittest.TextTestRunner().run(suite)
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P20.html b/pypers/oxford/doctest_talk/P20.html
deleted file mode 100755
index 8aea60d..0000000
--- a/pypers/oxford/doctest_talk/P20.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P20</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>Next</a></td> <td bgcolor="lightblue"><a href='P19.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P20</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Python 2.4 recognizes blank lines</h1><br/>
-
-Blank lines can be marked with &lt;BLANKLINE&gt; :
-<pre>
->>> print 'foo\n\nbar\n'
-foo
-&lt;BLANKLINE&gt;
-bar
-&lt;BLANKLINE&gt;
-
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P21.html b/pypers/oxford/doctest_talk/P21.html
deleted file mode 100755
index 34a3aa5..0000000
--- a/pypers/oxford/doctest_talk/P21.html
+++ /dev/null
@@ -1,117 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P21</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P22.html'>Next</a></td> <td bgcolor="lightblue"><a href='P20.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P21</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Python 2.4 recognizes flags!</h1><br/>
-
-<ul>
-<li> If the ellipsis flag is used, then '...' can be used to
- elide substrings in the desired output: <pre>
->>> print range(1000) #doctest: +ELLIPSIS
-[0, 1, 2, ..., 999]
-
-</pre></li>
-
-<li>
- If the whitespace normalization flag is used, then
- differences in whitespace are ignored.<pre>
->>> print range(20) #doctest: +NORMALIZE_WHITESPACE
-[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
-12, 13, 14, 15, 16, 17, 18, 19]
-
-</pre></li>
-
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P22.html b/pypers/oxford/doctest_talk/P22.html
deleted file mode 100755
index 929bbb5..0000000
--- a/pypers/oxford/doctest_talk/P22.html
+++ /dev/null
@@ -1,108 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P22</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>Next</a></td> <td bgcolor="lightblue"><a href='P21.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P22</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Zope experience</h1><br/>
-
-Literal quote from the PyCON doctest talk:
-
-<ul>
-<li> ~ 5600 tests (~3500 in Zope 3, ~1300 in ZODB, ~800 in Zope 2)</li>
-<li> we wrote lots of tests before we knew what we were doing</li>
-<li> debugging failed tests is really hard when intent is unclear</li>
-<li> often refactor or reimplement tests to make them clearer</li>
-<li> most new tests are doctest based</li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P23.html b/pypers/oxford/doctest_talk/P23.html
deleted file mode 100755
index 4ab3427..0000000
--- a/pypers/oxford/doctest_talk/P23.html
+++ /dev/null
@@ -1,115 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P23</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P24.html'>Next</a></td> <td bgcolor="lightblue"><a href='P22.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P23</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Conclusion (1): good reasons to use doctest</h1><br/>
-
-<quote>
-"Test coverage is important, but test readability is much more important"
-</quote>
-
-<em>-- Tim Peters and Jim Fulton</em> <br/> <br/>
-
-doctest is good since:
-
-<ol>
- <li> it is easy to understand, to explain and to use </li>
-
- <li> it makes you improve the quality of your documentation </li>
-
- <li> it can be converted to unittest anyway </li>
-
-</ol></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P24.html b/pypers/oxford/doctest_talk/P24.html
deleted file mode 100755
index 276299f..0000000
--- a/pypers/oxford/doctest_talk/P24.html
+++ /dev/null
@@ -1,112 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P24</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Next</a></td> <td bgcolor="lightblue"><a href='P23.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P24</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Conclusion (2): the message of this talk</h1><br/>
-
-Automatic testing is good for tons of practical reasons, but also
-because:
-
-<ol>
-
-<li>It teaches you <em>discipline</em> </li>
-
-<li>It makes you
- <em>think differently</em> </li>
-
-<li>It is more <em>fun!</em> </li>
-
-</ol></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P25.html b/pypers/oxford/doctest_talk/P25.html
deleted file mode 100755
index daae306..0000000
--- a/pypers/oxford/doctest_talk/P25.html
+++ /dev/null
@@ -1,110 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P25</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>Next</a></td> <td bgcolor="lightblue"><a href='P24.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P25</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>References</h1><br/>
-
-<ul>
-
-<li>The standard library documentation
-http://docs.python.org/lib/module-doctest.html </li>
-
-<li> The doctest talk by Tim Peters and Jim Fulton
-http://www.python.org/pycon/dc2004/papers/4/</li>
-
-<li> doctest.py <em>(use the source, Luke!)</em></li>
-</ul>
-</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/P26.html b/pypers/oxford/doctest_talk/P26.html
deleted file mode 100755
index cb376d4..0000000
--- a/pypers/oxford/doctest_talk/P26.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P26</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "accu2005.png" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>Next</a></td> <td bgcolor="lightblue"><a href='P25.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P26.html'>Last</a></td> <td bgcolor="lightblue"><a href='P01.html'>First</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue">Current</td> <td bgcolor="lightblue">P26</td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P17.html'>P17</a></td> <td bgcolor="lightblue"><a href='P18.html'>P18</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P19.html'>P19</a></td> <td bgcolor="lightblue"><a href='P20.html'>P20</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P21.html'>P21</a></td> <td bgcolor="lightblue"><a href='P22.html'>P22</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P23.html'>P23</a></td> <td bgcolor="lightblue"><a href='P24.html'>P24</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P25.html'>P25</a></td> <td bgcolor="lightblue"><a href='P26.html'>P26</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>References</h1><br/>
-
-<ul>
-
-<li>The standard library documentation
-http://docs.python.org/lib/module-doctest.html </li>
-
-<li> The doctest talk by Tim Peters and Jim Fulton
-http://www.python.org/pycon/dc2004/papers/4/</li>
-
-<li> doctest.py <em>(use the source, Luke!)</em></li>
-</ul>
-</td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/oxford/doctest_talk/index.html b/pypers/oxford/doctest_talk/index.html
deleted file mode 100755
index 870e229..0000000
--- a/pypers/oxford/doctest_talk/index.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title>Partecs Training: Internal Documentation</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<h1 class="title">Partecs Training: Internal Documentation</h1>
-<div class="document" id="partecs-training-internal-documentation">
-<p><a class="reference" href="http://wiki.partecs.com/Developers/PartecsTraining/P01.html">Michele's slides for the Italian Code Jam conference</a></p>
-</div>
-</body>
-</html>
diff --git a/pypers/oxford/doctest_talk/split.html b/pypers/oxford/doctest_talk/split.html
deleted file mode 100755
index 3cc867a..0000000
--- a/pypers/oxford/doctest_talk/split.html
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title>Documentation for the 'split' module</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<h1 class="title">Documentation for the 'split' module</h1>
-<div class="document" id="documentation-for-the-split-module">
-<p>The module contains a 'split' function, which
-splits a string taking as separators &quot;,&quot; and &quot;;&quot;.
-This is an example of usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from split import split
-&gt;&gt;&gt; split(&quot;hello, world!; welcome to the Italian Code Jam!&quot;)
-['hello', 'world!', 'welcome to the Italian Code Jam!']
-</pre>
-<p>Notice that 'split' eats whitespaces:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; split(&quot;hello , world&quot;)
-['hello', 'world']
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; split(&quot;hello , ; world&quot;)
-['hello', '', 'world']
-</pre>
-</div>
-</body>
-</html>
diff --git a/pypers/oxford/doctest_talk/x.html b/pypers/oxford/doctest_talk/x.html
deleted file mode 100755
index 57bfa5f..0000000
--- a/pypers/oxford/doctest_talk/x.html
+++ /dev/null
@@ -1,203 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
-<html>
-<head>
- <meta name="generator" content=
- "HTML Tidy for Linux/x86 (vers 1st March 2004), see www.w3.org">
- <meta name="generator" content="Generated by Python">
-
- <title>P01</title>
- <style type="text/css">
- body { font-size: 160%; }
- </style>
-</head>
-
-<body bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue"><img src=
- "cjlogo.jpg"></td>
- </tr>
- </table>
- </td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue"><a href=
- "P02.html">Next</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P26.html">Prev</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P01.html">First</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P26.html">Last</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P01.html">P01</a></td>
-
- <td bgcolor="lightblue"></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"></td>
-
- <td bgcolor="lightblue"></td>
- </tr>
- </table>
- </td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue">
- <table border="0">
- <tr>
- <td bgcolor="lightblue"><a href=
- "P01.html">P01</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P02.html">P02</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P03.html">P03</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P04.html">P04</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P05.html">P05</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P06.html">P06</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P07.html">P07</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P08.html">P08</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P09.html">P09</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P10.html">P10</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P11.html">P11</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P12.html">P12</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P13.html">P13</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P14.html">P14</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P15.html">P15</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P16.html">P16</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P17.html">P17</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P18.html">P18</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P19.html">P19</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P20.html">P20</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P21.html">P21</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P22.html">P22</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P23.html">P23</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P24.html">P24</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"><a href=
- "P25.html">P25</a></td>
-
- <td bgcolor="lightblue"><a href=
- "P26.html">P26</a></td>
- </tr>
-
- <tr>
- <td bgcolor="lightblue"></td>
-
- <td bgcolor="lightblue"></td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
-
- <td bgcolor="lightblue">
- <h1>Automatic testing in Python: wonderful
- doctest!</h1><br>
-
- <center>
- Italian Code Jam<br>
- <br>
- 09 Oct 2004<br>
- <br>
- Michele Simionato<br>
- <br>
- m.simionato@partecs.com<br>
- <br>
- Partecs s.r.l.
- </center><br>
- </td>
- </tr>
- </table>
-</body>
-</html>
diff --git a/pypers/oxford/loops.html b/pypers/oxford/loops.html
deleted file mode 100755
index 7c55eac..0000000
--- a/pypers/oxford/loops.html
+++ /dev/null
@@ -1,753 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.10: http://docutils.sourceforge.net/" />
-<title>Lecture 1: Loops (i.e. iterators &amp; generators)</title>
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-06-06 15:09:07 +0200 (Mon, 06 Jun 2005) $
-:Version: $Revision: 3442 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-*/
-
-/* "! important" is used here to override other ``margin-top`` and
- ``margin-bottom`` styles that are later in the stylesheet or
- more specific. See http://www.w3.org/TR/CSS1#the-cascade */
-.first {
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-img.borderless {
- border: 0 }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.line-block {
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid thin gray }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid thin black }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-</head>
-<body>
-<div class="document" id="lecture-1-loops-i-e-iterators-generators">
-<h1 class="title">Lecture 1: Loops (i.e. iterators &amp; generators)</h1>
-<div class="section" id="part-i-iterators">
-<h1><a name="part-i-iterators">Part I: iterators</a></h1>
-<div class="section" id="iterators-are-everywhere">
-<h2><a name="iterators-are-everywhere">Iterators are everywhere</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; for i in 1, 2, 3:
-... print i
-1
-2
-3
-</pre>
-<p>The 'for' loop is using <em>iterators</em> internally:</p>
-<pre class="literal-block">
-it = iter((1,2,3))
-while True:
- try:
- print it.next()
- except StopIteration:
- break
-</pre>
-</div>
-<div class="section" id="iterables-and-iterators">
-<h2><a name="iterables-and-iterators">Iterables and iterators</a></h2>
-<p><em>Iterable</em> = anything you can loop over = any sequence + any object with an __iter__ method;</p>
-<p>Not every sequence has an __iter__ method:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; &quot;hello&quot;.__iter__()
-Traceback (most recent call last):
- ...
-AttributeError: 'str' object has no attribute '__iter__'
-</pre>
-<p><em>Iterator</em> = any object with a .next method and an __iter__ method returning self</p>
-</div>
-<div class="section" id="simpler-way-to-get-an-iterator">
-<h2><a name="simpler-way-to-get-an-iterator">Simpler way to get an iterator</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = iter(&quot;hello&quot;)
-&gt;&gt;&gt; it.next()
-'h'
-&gt;&gt;&gt; it.next()
-'e'
-&gt;&gt;&gt; it.next()
-'l'
-&gt;&gt;&gt; it.next()
-'l'
-&gt;&gt;&gt; it.next()
-'o'
-&gt;&gt;&gt; it.next()
-Traceback (most recent call last):
- ...
-StopIteration
-</pre>
-</div>
-<div class="section" id="sentinel-syntax-iter-callable-sentinel">
-<h2><a name="sentinel-syntax-iter-callable-sentinel">Sentinel syntax iter(callable, sentinel)</a></h2>
-<p>Example:</p>
-<pre class="literal-block">
-$ echo -e &quot;value1\nvalue2\nEND\n&quot; &gt; data.txt
-$ python -c &quot;print list(iter(file('data.txt').readline, 'END\n'))&quot;
-['value1\n', 'value2\n']
-</pre>
-<p>Beware of infinite iterators:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; repeat = iter(lambda : &quot;some value&quot;, &quot;&quot;)
-&gt;&gt;&gt; repeat.next()
-'some value'
-</pre>
-</div>
-<div class="section" id="second-simpler-way-to-get-an-iterator-generator-expressions">
-<h2><a name="second-simpler-way-to-get-an-iterator-generator-expressions">Second simpler way to get an iterator: generator-expressions</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; squares = (i*i for i in range(1,11))
-&gt;&gt;&gt; list(squares)
-[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
-</pre>
-<p>Excessive parenthesis can be skipped, so use</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; dict((i, i*i) for i in range(1,11))
-{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100}
-</pre>
-<p>instead of</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; dict([(i, i*i) for i in range(1,11)])
-{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100}
-</pre>
-<p>(as usual, the most elegant version is the most efficient).</p>
-</div>
-<div class="section" id="iteration-caveats">
-<h2><a name="iteration-caveats">Iteration caveats</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; ls = [i for i in (1,2,3)]
-&gt;&gt;&gt; i
-3
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = (j for j in (1,2,3))
-&gt;&gt;&gt; j
-Traceback (most recent call last):
- ...
-NameError: name 'j' is not defined
-</pre>
-<p>A subtler example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; ls = [lambda :i for i in (1,2,3)]
-&gt;&gt;&gt; ls[0]()
-3
-</pre>
-<p>instead</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = (lambda :i for i in (1,2,3))
-&gt;&gt;&gt; it.next()()
-1
-&gt;&gt;&gt; it.next()()
-2
-&gt;&gt;&gt; it.next()()
-3
-</pre>
-<p><em>seems</em> to be working but it is not really the case:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = (lambda :i for i in (1,2,3))
-&gt;&gt;&gt; f1 = it.next()
-&gt;&gt;&gt; f2 = it.next()
-&gt;&gt;&gt; f3 = it.next()
-&gt;&gt;&gt; f1()
-3
-</pre>
-<p>The reason is that Python does LATE binding <em>always</em>. The solution is ugly:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; it = list(lambda i=i:i for i in (1,2,3))
-&gt;&gt;&gt; it[0]()
-1
-&gt;&gt;&gt; it[1]()
-2
-&gt;&gt;&gt; it[2]()
-3
-</pre>
-</div>
-</div>
-<div class="section" id="part-ii-generators">
-<h1><a name="part-ii-generators">Part II: generators</a></h1>
-<p>Trivial example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def gen123(): # &quot;function&quot; which returns an iterator over the values 1, 2, 3
-... yield 1
-... yield 2
-... yield 3
-...
-&gt;&gt;&gt; it = gen123()
-&gt;&gt;&gt; it.next()
-1
-&gt;&gt;&gt; it.next()
-2
-&gt;&gt;&gt; it.next()
-3
-&gt;&gt;&gt; it.next()
-Traceback (most recent call last):
- ...
-StopIteration
-</pre>
-<p>Real life example: using generators to generate HTML tables</p>
-<pre class="literal-block">
-#&lt;htmltable.py&gt;
-
-def HTMLTablegen(table):
- yield &quot;&lt;table&gt;&quot;
- for row in table:
- yield &quot;&lt;tr&gt;&quot;
- for col in row:
- yield &quot;&lt;td&gt;%s&lt;/td&gt;&quot; % col
- yield &quot;&lt;/tr&gt;&quot;
- yield &quot;&lt;/table&gt;&quot;
-
-def test():
- return &quot;\n&quot;.join(HTMLTablegen([[&quot;Row&quot;, &quot;City&quot;],
- [1,'London'], [2, 'Oxford']]))
-
-if __name__ == &quot;__main__&quot;: # example
- print test()
-
-#&lt;/htmltable.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from htmltable import test
-&gt;&gt;&gt; print test()
-&lt;table&gt;
-&lt;tr&gt;
-&lt;td&gt;Row&lt;/td&gt;
-&lt;td&gt;City&lt;/td&gt;
-&lt;/tr&gt;
-&lt;tr&gt;
-&lt;td&gt;1&lt;/td&gt;
-&lt;td&gt;London&lt;/td&gt;
-&lt;/tr&gt;
-&lt;tr&gt;
-&lt;td&gt;2&lt;/td&gt;
-&lt;td&gt;Oxford&lt;/td&gt;
-&lt;/tr&gt;
-&lt;/table&gt;
-</pre>
-<div class="section" id="a-simple-recipe-skip-redundant">
-<h2><a name="a-simple-recipe-skip-redundant">A simple recipe: skip redundant</a></h2>
-<p>How to remove duplicates by keeping the order:</p>
-<pre class="literal-block">
-#&lt;skip_redundant.py&gt;
-
-def skip_redundant(iterable, skipset=None):
- &quot;Redundant items are repeated items or items in the original skipset.&quot;
- if skipset is None: skipset = set()
- for item in iterable:
- if item not in skipset:
- skipset.add(item)
- yield item
-
-#&lt;/skip_redundant.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from skip_redundant import skip_redundant
-&gt;&gt;&gt; print list(skip_redundant(&quot;&lt;hello, world&gt;&quot;, skipset=set(&quot;&lt;&gt;&quot;)))
-['h', 'e', 'l', 'o', ',', ' ', 'w', 'r', 'd']
-</pre>
-</div>
-<div class="section" id="another-real-life-example-working-with-nested-structures">
-<h2><a name="another-real-life-example-working-with-nested-structures">Another real life example: working with nested structures</a></h2>
-<pre class="literal-block">
-#&lt;walk.py&gt;
-
-def walk(iterable, level=0):
- for obj in iterable:
- if not hasattr(obj, &quot;__iter__&quot;): # atomic object
- yield obj, level
- else: # composed object: iterate again
- for subobj, lvl in walk(obj, level + 1):
- yield subobj, lvl
-
-def flatten(iterable):
- return (obj for obj, level in walk(iterable))
-
-def pprint(iterable):
- for obj, level in walk(iterable):
- print &quot; &quot;*level, obj
-
-#&lt;/walk.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from walk import flatten, pprint
-&gt;&gt;&gt; nested_ls = [1,[2,[3,[[[4,5],6]]]],7]
-&gt;&gt;&gt; pprint(nested_ls)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
-&gt;&gt;&gt; pprint(flatten(nested_ls))
- 1
- 2
- 3
- 4
- 5
- 6
- 7
-</pre>
-</div>
-<div class="section" id="another-typical-use-case-for-generators-parsers">
-<h2><a name="another-typical-use-case-for-generators-parsers">Another typical use case for generators: parsers</a></h2>
-<p>A very stripped down parser for nested expressions</p>
-<pre class="literal-block">
-#&lt;sexpr2indent.py&gt;
-&quot;&quot;&quot;A simple s-expression formatter.&quot;&quot;&quot;
-
-import re
-
-def parse(sexpr):
- position = 0
- nesting_level = 0
- paren = re.compile(r&quot;(?P&lt;paren_beg&gt;\()|(?P&lt;paren_end&gt;\))&quot;)
- while True:
- match = paren.search(sexpr, position)
- if match:
- yield nesting_level, sexpr[position: match.start()]
- if match.lastgroup == &quot;paren_beg&quot;:
- nesting_level += 1
- elif match.lastgroup == &quot;paren_end&quot;:
- nesting_level -= 1
- position = match.end()
- else:
- break
-
-def sexpr_indent(sexpr):
- for nesting, text in parse(sexpr.replace(&quot;\n&quot;, &quot;&quot;)):
- if text.strip(): print &quot; &quot;*nesting, text
-
-#&lt;/sexpr2indent.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from sexpr2indent import sexpr_indent
-&gt;&gt;&gt; sexpr_indent(&quot;&quot;&quot;\
-... (html (head (title Example)) (body (h1 s-expr formatter example)
-... (a (&#64; (href http://www.example.com)) A link)))&quot;&quot;&quot;)
-... #doctest: +NORMALIZE_WHITESPACE
- html
- head
- title Example
- body
- h1 s-expr formatter example
- a
- &#64;
- href http://www.example.com
- A link
-</pre>
-</div>
-<div class="section" id="other-kinds-of-iterables">
-<h2><a name="other-kinds-of-iterables">Other kinds of iterables</a></h2>
-<p>The following class generates iterable which are not iterators:</p>
-<pre class="literal-block">
-#&lt;reiterable.py&gt;
-
-class ReIter(object):
- &quot;A re-iterable object.&quot;
- def __iter__(self):
- yield 1
- yield 2
- yield 3
-
-#&lt;/reiterable.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from reiterable import ReIter
-&gt;&gt;&gt; rit = ReIter()
-&gt;&gt;&gt; list(rit)
-[1, 2, 3]
-&gt;&gt;&gt; list(rit) # it is reiterable!
-[1, 2, 3]
-</pre>
-</div>
-<div class="section" id="the-itertools-module">
-<h2><a name="the-itertools-module">The itertools module</a></h2>
-<blockquote>
-<ul class="simple">
-<li>count([n]) --&gt; n, n+1, n+2, ...</li>
-<li>cycle(p) --&gt; p0, p1, ... plast, p0, p1, ...</li>
-<li>repeat(elem [,n]) --&gt; elem, elem, elem, ... endlessly or up to n times</li>
-<li>izip(p, q, ...) --&gt; (p[0], q[0]), (p[1], q[1]), ...</li>
-<li>ifilter(pred, seq) --&gt; elements of seq where pred(elem) is True</li>
-<li>ifilterfalse(pred, seq) --&gt; elements of seq where pred(elem) is False</li>
-<li>islice(seq, [start,] stop [, step]) --&gt; elements from seq[start:stop:step]</li>
-<li>imap(fun, p, q, ...) --&gt; fun(p0, q0), fun(p1, q1), ...</li>
-<li>starmap(fun, seq) --&gt; fun(*seq[0]), fun(*seq[1]), ...</li>
-<li>tee(it, n=2) --&gt; (it1, it2 , ... itn) splits one iterator into n</li>
-<li>chain(p, q, ...) --&gt; p0, p1, ... plast, q0, q1, ...</li>
-<li>takewhile(pred, seq) --&gt; seq[0], seq[1], until pred fails</li>
-<li>dropwhile(pred, seq) --&gt; seq[n], seq[n+1], starting when pred fails</li>
-<li>groupby(iterable[, keyfunc]) --&gt; sub-iterators grouped by value of keyfunc(v)</li>
-</ul>
-</blockquote>
-</div>
-<div class="section" id="anytrue">
-<h2><a name="anytrue">anyTrue</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; import itertools
-&gt;&gt;&gt; def anyTrue(predicate, iterable):
-... return True in itertools.imap(predicate, iterable)
-...
-&gt;&gt;&gt; fname = &quot;picture.gif&quot;
-&gt;&gt;&gt; anyTrue(fname.endswith, &quot;.jpg .gif .png&quot;.split())
-True
-</pre>
-<p>AnyTrue does <em>short-circuit</em>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def is3(i):
-... print &quot;i=%s&quot; % i
-... return i == 3
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; anyTrue(is3, range(10))
-i=0
-i=1
-i=2
-i=3
-True
-</pre>
-</div>
-<div class="section" id="chop">
-<h2><a name="chop">chop</a></h2>
-<p>You want to chop an iterable in batches of a given size:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from chop import chop
-&gt;&gt;&gt; list(chop([1, 2, 3, 4], 2))
-[[1, 2], [3, 4]]
-&gt;&gt;&gt; list(chop([1, 2, 3, 4, 5, 6, 7],3))
-[[1, 2, 3], [4, 5, 6], [7]]
-</pre>
-<p>Here is a possible implementation:</p>
-<pre class="literal-block">
-#&lt;chop.py&gt;
-
-# see also http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279
-
-import itertools
-
-def chop(iterable, batchsize):
- it = iter(iterable)
- while True:
- batch = list(itertools.islice(it, batchsize))
- if batch: yield batch
- else: break
-
-#&lt;/chop.py&gt;
-</pre>
-<p>For people thinking Python is too readable, here is a one-liner:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; chop = lambda it, n : itertools.izip(*(iter(it),)*n)
-...
-&gt;&gt;&gt; list(chop([1,2,3,4], 2))
-[(1, 2), (3, 4)]
-</pre>
-</div>
-<div class="section" id="tee">
-<h2><a name="tee">tee</a></h2>
-<p>To make copies of iterables; typically used in parsers:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from itertools import tee, chain, izip
-&gt;&gt;&gt; chars, prevs = tee(&quot;abc&quot;)
-&gt;&gt;&gt; prevs = chain([None], prevs)
-&gt;&gt;&gt; for char, prev in izip(chars, prevs):
-... print char, prev
-...
-a None
-b a
-c b
-</pre>
-</div>
-<div class="section" id="grouping-and-sorting">
-<h2><a name="grouping-and-sorting">Grouping and sorting</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; from itertools import groupby
-&gt;&gt;&gt; from operator import itemgetter
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; NAME, AGE = 0, 1
-&gt;&gt;&gt; query_result = (&quot;Smith&quot;, 34), (&quot;Donaldson&quot;, 34), (&quot;Lee&quot;, 22), (&quot;Orr&quot;, 22)
-</pre>
-<p>Grouping together people of the same age:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for k, g in groupby(query_result, key=itemgetter(AGE)):
-... print k, list(g)
-...
-34 [('Smith', 34), ('Donaldson', 34)]
-22 [('Lee', 22), ('Orr', 22)]
-</pre>
-<p>Sorting by name:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for tup in sorted(query_result, key=itemgetter(NAME)):
-... print tup
-('Donaldson', 34)
-('Lee', 22)
-('Orr', 22)
-('Smith', 34)
-</pre>
-</div>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/oxford/magic.html b/pypers/oxford/magic.html
deleted file mode 100755
index 048c237..0000000
--- a/pypers/oxford/magic.html
+++ /dev/null
@@ -1,717 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title>Lecture 3: Magic (i.e. decorators and metaclasses)</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="lecture-3-magic-i-e-decorators-and-metaclasses">
-<h1 class="title">Lecture 3: Magic (i.e. decorators and metaclasses)</h1>
-<div class="section" id="part-i-decorators">
-<h1><a name="part-i-decorators">Part I: decorators</a></h1>
-<p>Decorators are just sugar: their functionality was already in the language</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def s(): pass
-&gt;&gt;&gt; s = staticmethod(s)
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; &#64;staticmethod
-... def s(): pass
-...
-</pre>
-<p>However sugar <em>does</em> matter.</p>
-<div class="section" id="a-typical-decorator-traced">
-<h2><a name="a-typical-decorator-traced">A typical decorator: traced</a></h2>
-<pre class="literal-block">
-#&lt;traced.py&gt;
-
-def traced(func):
- def tracedfunc(*args, **kw):
- print &quot;calling %s.%s&quot; % (func.__module__, func.__name__)
- return func(*args, **kw)
- tracedfunc.__name__ = func.__name__
- return tracedfunc
-
-&#64;traced
-def f(): pass
-
-#&lt;/traced.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from traced import f
-&gt;&gt;&gt; f()
-calling traced.f
-</pre>
-</div>
-<div class="section" id="a-decorator-factory-timed">
-<h2><a name="a-decorator-factory-timed">A decorator factory: Timed</a></h2>
-<pre class="literal-block">
-#&lt;timed.py&gt;
-
-import sys, time
-
-class Timed(object):
- &quot;&quot;&quot;Decorator factory: each decorator object wraps a function and
- executes it many times (default 100 times).
- The average time spent in one iteration, expressed in milliseconds,
- is stored in the attributes wrappedfunc.time and wrappedfunc.clocktime,
- and displayed into a log file which defaults to stdout.
- &quot;&quot;&quot;
- def __init__(self, repeat=100, logfile=sys.stdout):
- self.repeat = repeat
- self.logfile = logfile
- def __call__(self, func):
- def wrappedfunc(*args, **kw):
- fullname = &quot;%s.%s ...&quot; % (func.__module__, func.func_name)
- print &gt;&gt; self.logfile, 'Executing %s' % fullname.ljust(30),
- time1 = time.time()
- clocktime1 = time.clock()
- for i in xrange(self.repeat):
- res = func(*args,**kw) # executes func self.repeat times
- time2 = time.time()
- clocktime2 = time.clock()
- wrappedfunc.time = 1000*(time2-time1)/self.repeat
- wrappedfunc.clocktime = 1000*(clocktime2 - clocktime1)/self.repeat
- print &gt;&gt; self.logfile, \
- 'Real time: %s ms;' % self.rounding(wrappedfunc.time),
- print &gt;&gt; self.logfile, \
- 'Clock time: %s ms' % self.rounding(wrappedfunc.clocktime)
- return res
- wrappedfunc.func_name = func.func_name
- wrappedfunc.__module__ = func.__module__
- return wrappedfunc
- &#64;staticmethod
- def rounding(float_):
- &quot;Three digits rounding for small numbers, 1 digit rounding otherwise.&quot;
- if float_ &lt; 10.:
- return &quot;%5.3f&quot; % float_
- else:
- return &quot;%5.1f&quot; % float_
-
-#&lt;/timed.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from timed import Timed
-&gt;&gt;&gt; from random import sample
-&gt;&gt;&gt; example_ls = sample(xrange(1000000), 1000)
-&gt;&gt;&gt; &#64;Timed()
-... def list_sort(ls):
-... ls.sort()
-...
-&gt;&gt;&gt; list_sort(example_ls) #doctest: +ELLIPSIS
-Executing __main__.list_sort ... Real time: 0... ms; Clock time: 0... ms
-</pre>
-</div>
-<div class="section" id="towards-decorator-patterns">
-<h2><a name="towards-decorator-patterns">Towards decorator patterns</a></h2>
-<pre class="literal-block">
-#&lt;traced_function2.py&gt;
-
-from decorators import decorator
-
-def trace(f, *args, **kw):
- print &quot;calling %s with args %s, %s&quot; % (f.func_name, args, kw)
- return f(*args, **kw)
-
-traced_function = decorator(trace)
-
-&#64;traced_function
-def f1(x):
- pass
-
-&#64;traced_function
-def f2(x, y):
- pass
-
-#&lt;/traced_function2.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from traced_function2 import traced_function, f1, f2
-&gt;&gt;&gt; f1(1)
-calling f1 with args (1,), {}
-&gt;&gt;&gt; f2(1,2)
-calling f2 with args (1, 2), {}
-</pre>
-<p>works with pydoc:</p>
-<pre class="literal-block">
-$ pydoc2.4 traced_function2.f2
-Help on function f1 in traced_function2:
-
-traced_function2.f1 = f1(x)
-
-$ pydoc2.4 traced_function2.f2
-Help on function f2 in traced_function2:
-
-traced_function2.f2 = f2(x, y)
-</pre>
-<p>Here is the source code:</p>
-<pre class="literal-block">
-#&lt;decorators.py&gt;
-
-import inspect
-
-def _signature_gen(func, rm_defaults=False):
- argnames, varargs, varkwargs, defaults = inspect.getargspec(func)
- argdefs = defaults or ()
- n_args = func.func_code.co_argcount
- n_default_args = len(argdefs)
- n_non_default_args = n_args - n_default_args
- non_default_names = argnames[:n_non_default_args]
- default_names = argnames[n_non_default_args:]
- for name in non_default_names:
- yield &quot;%s&quot; % name
- for i, name in enumerate(default_names):
- if rm_defaults:
- yield name
- else:
- yield &quot;%s = arg[%s]&quot; % (name, i)
- if varargs:
- yield &quot;*%s&quot; % varargs
- if varkwargs:
- yield &quot;**%s&quot; % varkwargs
-
-def _decorate(func, caller):
- signature = &quot;, &quot;.join(_signature_gen(func))
- variables = &quot;, &quot;.join(_signature_gen(func, rm_defaults=True))
- lambda_src = &quot;lambda %s: call(func, %s)&quot; % (signature, variables)
- evaldict = dict(func=func, call=caller, arg=func.func_defaults or ())
- dec_func = eval(lambda_src, evaldict)
- dec_func.__name__ = func.__name__
- dec_func.__doc__ = func.__doc__
- dec_func.__dict__ = func.__dict__ # copy if you want to avoid sharing
- return dec_func
-
-class decorator(object):
- &quot;&quot;&quot;General purpose decorator factory, taking a caller function as
- input. A caller function is any function like this:
-
- def caller(func, *args, **kw):
- # do something
- return func(*args, **kw)
- &quot;&quot;&quot;
- def __init__(self, caller):
- self.caller = caller
- def __call__(self, func):
- return _decorate(func, self.caller)
-
-#&lt;/decorators.py&gt;
-</pre>
-<p>The possibilities of this pattern are endless:</p>
-<pre class="literal-block">
-#&lt;deferred.py&gt;
-
-import threading
-from decorators import decorator
-
-def deferred(nsec):
- def inner_deferred(func, *args, **kw):
- return threading.Timer(nsec, func, args, kw).start()
- return decorator(inner_deferred)
-
-&#64;deferred(2)
-def hello():
- print &quot;hello&quot;
-
-#&lt;deferred.py&gt;
-</pre>
-<p>Show an example of an experimental decorator based web framework
-(doctester_frontend).</p>
-</div>
-</div>
-<div class="section" id="part-ii-metaclasses">
-<h1><a name="part-ii-metaclasses">Part II: metaclasses</a></h1>
-<p>Metaclasses are there! Consider this example from a recent post on c.l.py:</p>
-<pre class="literal-block">
-#&lt;BaseClass.py&gt;
-
-class BaseClass(object):
- &quot;Do something&quot;
-
-#&lt;/BaseClass.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; import BaseClass # instead of 'from BaseClass import BaseClass'
-&gt;&gt;&gt; class C(BaseClass): pass
-...
-Traceback (most recent call last):
- ...
-TypeError: Error when calling the metaclass bases
- module.__init__() takes at most 2 arguments (3 given)
-</pre>
-<p>The reason for the error is that class <tt class="docutils literal"><span class="pre">C(BaseClass):</span> <span class="pre">pass</span></tt> is
-actually calling the <tt class="docutils literal"><span class="pre">type</span></tt> metaclass with three arguments:</p>
-<pre class="literal-block">
-C = type(&quot;C&quot;, (BaseClass,), {})
-</pre>
-<p><tt class="docutils literal"><span class="pre">type.__new__</span></tt> tries to use <tt class="docutils literal"><span class="pre">type(BaseClass)</span></tt> as metaclass,
-but since BaseClass here is a module, and <tt class="docutils literal"><span class="pre">ModuleType</span></tt> is not
-a metaclass, it cannot work. The error message reflects a conflict with
-the signature of ModuleType which requires two parameters and not three.</p>
-<p>So even if you don't use them, you may want to know they exist.</p>
-<div class="section" id="rejuvenating-old-style-classes">
-<h2><a name="rejuvenating-old-style-classes">Rejuvenating old-style classes</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; class Old: pass
-&gt;&gt;&gt; print type(Old)
-&lt;type 'classobj'&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; __metaclass__ = type # to rejuvenate class
-&gt;&gt;&gt; class NotOld: pass
-...
-&gt;&gt;&gt; print NotOld.__class__
-&lt;type 'type'&gt;
-</pre>
-</div>
-<div class="section" id="a-typical-metaclass-example-metatracer">
-<h2><a name="a-typical-metaclass-example-metatracer">A typical metaclass example: MetaTracer</a></h2>
-<pre class="literal-block">
-#&lt;metatracer.py&gt;
-import inspect
-
-def trace(meth, cls):
- def traced(*args, **kw):
- modname = meth.__module__ or cls.__module__
- print &quot;calling %s.%s.%s&quot; % (modname, cls.__name__, meth.__name__)
- return meth(*args, **kw)
- traced.__name__ = meth.__name__
- return traced
-
-class MetaTracer(type):
- def __init__(cls, name, bases, dic):
- super(MetaTracer, cls).__init__(name, bases, dic)
- for k, v in dic.iteritems():
- if inspect.isfunction(v):
- setattr(cls, k, trace(v, cls))
-
-#&lt;/metatracer.py&gt;
-</pre>
-<p>Usage: exploring classes in the standard library</p>
-<pre class="literal-block">
-#&lt;dictmixin.py&gt;
-
-from metatracer import MetaTracer
-from UserDict import DictMixin
-
-class TracedDM(DictMixin, object):
- __metaclass__ = MetaTracer
- def __getitem__(self, item):
- return item
- def keys(self):
- return [1,2,3]
-
-#&lt;/dictmixin.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from dictmixin import TracedDM
-&gt;&gt;&gt; print TracedDM()
-calling dictmixin.TracedDM.keys
-calling dictmixin.TracedDM.__getitem__
-calling dictmixin.TracedDM.__getitem__
-calling dictmixin.TracedDM.__getitem__
-{1: 1, 2: 2, 3: 3}
-</pre>
-</div>
-<div class="section" id="real-life-example-check-overriding">
-<h2><a name="real-life-example-check-overriding">Real life example: check overriding</a></h2>
-<pre class="literal-block">
-#&lt;check_overriding.py&gt;
-
-class Base(object):
- a = 0
-
-class CheckOverriding(type):
- &quot;Prints a message if we are overriding a name.&quot;
- def __new__(mcl, name, bases, dic):
- for name, val in dic.iteritems():
- if name.startswith(&quot;__&quot;) and name.endswith(&quot;__&quot;):
- continue # ignore special names
- a_base_has_name = True in (hasattr(base, name) for base in bases)
- if a_base_has_name:
- print &quot;AlreadyDefinedNameWarning: &quot; + name
- return super(CheckOverriding, mcl).__new__(mcl, name, bases, dic)
-
-class MyClass(Base):
- __metaclass__ = CheckOverriding
- a = 1
-
-class ChildClass(MyClass):
- a = 2
-</pre>
-<p>#&lt;/check_overriding.py&gt;</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import check_overriding
-AlreadyDefinedNameWarning: a
-AlreadyDefinedNameWarning: a
-</pre>
-</div>
-<div class="section" id="logfile">
-<h2><a name="logfile">LogFile</a></h2>
-<pre class="literal-block">
-#&lt;logfile.py&gt;
-
-import subprocess
-
-def memoize(func):
- memoize_dic = {}
- def wrapped_func(*args):
- if args in memoize_dic:
- return memoize_dic[args]
- else:
- result = func(*args)
- memoize_dic[args] = result
- return result
- wrapped_func.__name__ = func.__name__
- wrapped_func.__doc__ = func.__doc__
- wrapped_func.__dict__ = func.__dict__
- return wrapped_func
-
-class Memoize(type): # Singleton is a special case of Memoize
- &#64;memoize
- def __call__(cls, *args):
- return super(Memoize, cls).__call__(*args)
-
-class LogFile(file):
- &quot;&quot;&quot;Open a file for append.&quot;&quot;&quot;
- __metaclass__ = Memoize
- def __init__(self, name = &quot;/tmp/err.log&quot;):
- self.viewer_cmd = 'xterm -e less'.split()
- super(LogFile, self).__init__(name, &quot;a&quot;)
-
- def display(self, *ls):
- &quot;Use 'less' to display the log file in a separate xterm.&quot;
- print &gt;&gt; self, &quot;\n&quot;.join(map(str, ls)); self.flush()
- subprocess.call(self.viewer_cmd + [self.name])
-
- def reset(self):
- &quot;Erase the log file.&quot;
- print &gt;&gt; file(self.name, &quot;w&quot;)
-
-if __name__ == &quot;__main__&quot;: # test
- print &gt;&gt; LogFile(), &quot;hello&quot;
- print &gt;&gt; LogFile(), &quot;world&quot;
- LogFile().display()
-
-#&lt;/logfile.py&gt;
-
-$ python logfile.py
-</pre>
-</div>
-<div class="section" id="cooperative-hierarchies">
-<h2><a name="cooperative-hierarchies">Cooperative hierarchies</a></h2>
-<pre class="literal-block">
-#&lt;cooperative_init.py&gt;
-
-&quot;&quot;&quot;Given a hierarchy, makes __init__ cooperative.
-The only change needed is to add a line
-
- __metaclass__ = CooperativeInit
-
-to the base class of your hierarchy.&quot;&quot;&quot;
-
-from decorators import decorator
-
-def make_cooperative_init(cls, name, bases, dic):
-
- def call_cooperatively(__init__, self, *args, **kw):
- super(cls, self).__init__(*args, **kw)
- __init__(self, *args, **kw)
-
- __init__ = cls.__dict__.get(&quot;__init__&quot;)
- if __init__:
- cls.__init__ = decorator(call_cooperatively)(__init__)
-
-class CooperativeInit(type):
- __init__ = make_cooperative_init
-
-class Base:
- __metaclass__ = CooperativeInit
- def __init__(self):
- print &quot;B.__init__&quot;
-
-class C1(Base):
- def __init__(self):
- print &quot;C1.__init__&quot;
-
-class C2(Base):
- def __init__(self):
- print &quot;C2.__init__&quot;
-
-class D(C1, C2):
- def __init__(self):
- print &quot;D.__init__&quot;
-
-#&lt;/cooperative_init.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from cooperative_init import D
-&gt;&gt;&gt; d = D()
-B.__init__
-C2.__init__
-C1.__init__
-D.__init__
-</pre>
-</div>
-<div class="section" id="metaclass-enhanced-modules">
-<h2><a name="metaclass-enhanced-modules">Metaclass-enhanced modules</a></h2>
-<pre class="literal-block">
-#&lt;import_with_metaclass.py&gt;
-&quot;&quot;&quot;
-``import_with_metaclass(metaclass, modulepath)`` generates
-a new module from and old module, by enhancing all of its classes.
-This is not perfect, but it should give you a start.&quot;&quot;&quot;
-
-import os, sys, inspect, types
-
-def import_with_metaclass(metaclass, modulepath):
- modname = os.path.basename(modulepath)[:-3] # simplistic
- mod = types.ModuleType(modname)
- locs = dict(
- __module__ = modname,
- __file__ = modulepath,
- __metaclass__ = metaclass,
- object = metaclass(&quot;object&quot;, (), {}))
- execfile(modulepath, locs)
- for k, v in locs.iteritems():
- setattr(mod, k, v)
- return mod
-</pre>
-<p>#&lt;/import_with_metaclass.py&gt;</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from import_with_metaclass import import_with_metaclass
-&gt;&gt;&gt; from tracer import MetaTracer
-&gt;&gt;&gt; traced_optparse = import_with_metaclass(MetaTracer,
-... &quot;/usr/lib/python2.4/optparse.py&quot;)
-&gt;&gt;&gt; op = traced_optparse.OptionParser()
-calling __main__.OptionParser.__init__
-calling __main__.OptionContainer.__init__
-calling __main__.OptionParser._create_option_list
-calling __main__.OptionContainer._create_option_mappings
-calling __main__.OptionContainer.set_conflict_handler
-calling __main__.OptionContainer.set_description
-calling __main__.OptionParser.set_usage
-calling __main__.IndentedHelpFormatter.__init__
-calling __main__.HelpFormatter.__init__
-calling __main__.HelpFormatter.set_parser
-calling __main__.OptionParser._populate_option_list
-calling __main__.OptionParser._add_help_option
-calling __main__.OptionContainer.add_option
-calling __main__.Option.__init__
-calling __main__.Option._check_opt_strings
-calling __main__.Option._set_opt_strings
-calling __main__.Option._set_attrs
-calling __main__.OptionContainer._check_conflict
-calling __main__.OptionParser._init_parsing_state
-</pre>
-</div>
-<div class="section" id="magic-properties">
-<h2><a name="magic-properties">Magic properties</a></h2>
-<pre class="literal-block">
-#&lt;magicprop.py&gt;
-
-class MagicProperties(type):
- def __init__(cls, name, bases, dic):
- prop_names = set(name[3:] for name in dic
- if name.startswith(&quot;get&quot;)
- or name.startswith(&quot;set&quot;))
- for name in prop_names:
- getter = getattr(cls, &quot;get&quot; + name, None)
- setter = getattr(cls, &quot;set&quot; + name, None)
- setattr(cls, name, property(getter, setter))
-
-class Base(object):
- __metaclass__ = MagicProperties
- def getx(self):
- return self._x
- def setx(self, value):
- self._x = value
-
-class Child(Base):
- def getx(self):
- print &quot;getting x&quot;
- return super(Child, self).getx()
- def setx(self, value):
- print &quot;setting x&quot;
- super(Child, self).setx(value)
-
-#&lt;/magicprop.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from magicprop import Child
-&gt;&gt;&gt; c = Child()
-&gt;&gt;&gt; c.x = 1
-setting x
-&gt;&gt;&gt; print c.x
-getting x
-1
-</pre>
-</div>
-<div class="section" id="hack-evil-properties">
-<h2><a name="hack-evil-properties">Hack: evil properties</a></h2>
-<pre class="literal-block">
-#&lt;evilprop.py&gt;
-
-def convert2property(name, bases, d):
- return property(d.get('get'), d.get('set'),
- d.get('del'),d.get('__doc__'))
-
-class C(object):
- class x:
- &quot;&quot;&quot;An evil test property&quot;&quot;&quot;
- __metaclass__ = convert2property
- def get(self):
- print 'Getting %s' % self._x
- return self._x
- def set(self, value):
- self._x = value
- print 'Setting to', value
-
-#&lt;/evilprop.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from evilprop import C
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; c.x = 5
-Setting to 5
-&gt;&gt;&gt; c.x
-Getting 5
-5
-&gt;&gt;&gt; print C.x.__doc__
-An evil test property
-</pre>
-</div>
-<div class="section" id="why-i-suggest-not-to-use-metaclasses-in-production-code">
-<h2><a name="why-i-suggest-not-to-use-metaclasses-in-production-code">Why I suggest <em>not</em> to use metaclasses in production code</a></h2>
-<blockquote>
-<ul class="simple">
-<li>there are very few good use case for metaclasses in production code
-(i.e. 99% of time you don't need them)</li>
-<li>they put a cognitive burden on the developer;</li>
-<li>a design without metaclasses is less magic and likely more robust;</li>
-<li>a design with metaclasses makes it difficult to use other metaclasses
-for debugging.</li>
-</ul>
-</blockquote>
-<p>As far as I know, string.Template is the only metaclass-enhanced class
-in the standard library; the metaclass is used to give the possibility to
-change the defaults:</p>
-<pre class="literal-block">
-delimiter = '$'
-idpattern = r'[_a-z][_a-z0-9]*'
-</pre>
-<p>in subclasses of Template.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from string import Template
-&gt;&gt;&gt; from tracer import MetaTracer
-&gt;&gt;&gt; class TracedTemplate(Template):
-... __metaclass__ = MetaTracer
-...
-Traceback (most recent call last):
- ...
-TypeError: Error when calling the metaclass bases
- metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-<p>Solution: use a consistent metaclass</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class GoodMeta(MetaTracer, type(Template)): pass
-...
-&gt;&gt;&gt; class TracedTemplate(Template):
-... __metaclass__ = GoodMeta
-</pre>
-</div>
-<div class="section" id="is-there-an-automatic-way-of-solving-the-conflict">
-<h2><a name="is-there-an-automatic-way-of-solving-the-conflict">Is there an automatic way of solving the conflict?</a></h2>
-<p>Yes, but you really need to be a metaclass wizard.</p>
-<p><a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197</a></p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from noconflict import classmaker
-&gt;&gt;&gt; class TracedTemplate(Template):
-... __metaclass__ = classmaker((MetaTracer,))
-&gt;&gt;&gt; print type(TracedTemplate)
-&lt;class 'noconflict._MetaTracer_TemplateMetaclass'&gt;
-</pre>
-<pre class="literal-block">
-#&lt;noconflict.py&gt;
-
-import inspect, types, __builtin__
-from skip_redundant import skip_redundant
-
-memoized_metaclasses_map = {}
-
-# utility function
-def remove_redundant(metaclasses):
- skipset = set([types.ClassType])
- for meta in metaclasses: # determines the metaclasses to be skipped
- skipset.update(inspect.getmro(meta)[1:])
- return tuple(skip_redundant(metaclasses, skipset))
-
-##################################################################
-## now the core of the module: two mutually recursive functions ##
-##################################################################
-
-def get_noconflict_metaclass(bases, left_metas, right_metas):
- &quot;&quot;&quot;Not intended to be used outside of this module, unless you know
- what you are doing.&quot;&quot;&quot;
- # make tuple of needed metaclasses in specified priority order
- metas = left_metas + tuple(map(type, bases)) + right_metas
- needed_metas = remove_redundant(metas)
-
- # return existing confict-solving meta, if any
- if needed_metas in memoized_metaclasses_map:
- return memoized_metaclasses_map[needed_metas]
- # nope: compute, memoize and return needed conflict-solving meta
- elif not needed_metas: # wee, a trivial case, happy us
- meta = type
- elif len(needed_metas) == 1: # another trivial case
- meta = needed_metas[0]
- # check for recursion, can happen i.e. for Zope ExtensionClasses
- elif needed_metas == bases:
- raise TypeError(&quot;Incompatible root metatypes&quot;, needed_metas)
- else: # gotta work ...
- metaname = '_' + ''.join([m.__name__ for m in needed_metas])
- meta = classmaker()(metaname, needed_metas, {})
- memoized_metaclasses_map[needed_metas] = meta
- return meta
-
-def classmaker(left_metas=(), right_metas=()):
- def make_class(name, bases, adict):
- metaclass = get_noconflict_metaclass(bases, left_metas, right_metas)
- return metaclass(name, bases, adict)
- return make_class
-
-#################################################################
-## and now a conflict-safe replacement for 'type' ##
-#################################################################
-
-__type__=__builtin__.type # the aboriginal 'type'
-# left available in case you decide to rebind __builtin__.type
-
-class safetype(__type__):
- # this is REALLY DEEP MAGIC
- &quot;&quot;&quot;Overrides the ``__new__`` method of the ``type`` metaclass, making the
- generation of classes conflict-proof.&quot;&quot;&quot;
- def __new__(mcl, *args):
- nargs = len(args)
- if nargs == 1: # works as __builtin__.type
- return __type__(args[0])
- elif nargs == 3: # creates the class using the appropriate metaclass
- n, b, d = args # name, bases and dictionary
- meta = get_noconflict_metaclass(b, (mcl,), ())
- if meta is mcl: # meta is trivial, dispatch to the default __new__
- return super(safetype, mcl).__new__(mcl, n, b, d)
- else: # non-trivial metaclass, dispatch to the right __new__
- # (it will take a second round) # print mcl, meta
- return super(mcl, meta).__new__(meta, n, b, d)
- else:
- raise TypeError('%s() takes 1 or 3 arguments' % mcl.__name__)
-
-#&lt;/noconflict.py&gt;
-</pre>
-</div>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/oxford/mro.html b/pypers/oxford/mro.html
deleted file mode 100755
index d49609c..0000000
--- a/pypers/oxford/mro.html
+++ /dev/null
@@ -1,788 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title>The Python 2.3 Method Resolution Order</title>
-<meta name="author" content="Michele Simionato" />
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="the-python-2-3-method-resolution-order">
-<h1 class="title">The Python 2.3 Method Resolution Order</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr><th class="docinfo-name">Version:</th>
-<td>1.4</td></tr>
-<tr><th class="docinfo-name">Author:</th>
-<td>Michele Simionato</td></tr>
-<tr class="field"><th class="docinfo-name">E-mail:</th><td class="field-body"><a class="reference" href="mailto:michelesimionato&#64;libero.it">michelesimionato&#64;libero.it</a></td>
-</tr>
-<tr><th class="docinfo-name">Address:</th>
-<td><pre class="address">
-Department of Physics and Astronomy
-210 Allen Hall Pittsburgh PA 15260 U.S.A.
-</pre>
-</td></tr>
-<tr class="field"><th class="docinfo-name">Home-page:</th><td class="field-body"><a class="reference" href="http://www.phyast.pitt.edu/~micheles/">http://www.phyast.pitt.edu/~micheles/</a></td>
-</tr>
-</tbody>
-</table>
-<div class="abstract topic">
-<p class="topic-title first">Abstract</p>
-<p><em>This document is intended for Python programmers who want to
-understand the C3 Method Resolution Order used in Python 2.3.
-Although it is not intended for newbies, it is quite pedagogical with
-many worked out examples. I am not aware of other publicly available
-documents with the same scope, therefore it should be useful.</em></p>
-</div>
-<p>Disclaimer:</p>
-<blockquote>
-I donate this document to the Python Software Foundation, under the
-Python 2.3 license. As usual in these circumstances, I warn the
-reader that what follows <em>should</em> be correct, but I don't give any
-warranty. Use it at your own risk and peril!</blockquote>
-<p>Acknowledgments:</p>
-<blockquote>
-All the people of the Python mailing list who sent me their support.
-Paul Foley who pointed out various imprecisions and made me to add the
-part on local precedence ordering. David Goodger for help with the
-formatting in reStructuredText. David Mertz for help with the editing.
-Joan G. Stark for the pythonic pictures. Finally, Guido van Rossum who
-enthusiastically added this document to the official Python 2.3 home-page.</blockquote>
-<hr class="docutils" />
-<blockquote>
-<pre class="literal-block">
- .-=-. .--.
- __ .' '. / &quot; )
- _ .' '. / .-. \ / .-'\
- ( \ / .-. \ / / \ \ / / ^
- \ `-` / \ `-' / \ `-` /
-jgs`-.-` '.____.' `.____.'
-</pre>
-</blockquote>
-<div class="section" id="the-beginning">
-<h1><a name="the-beginning">The beginning</a></h1>
-<blockquote>
-<em>Felix qui potuit rerum cognoscere causas</em> -- Virgilius</blockquote>
-<p>Everything started with a post by Samuele Pedroni to the Python
-development mailing list <a class="footnote-reference" href="#id4" id="id1" name="id1">[1]</a>. In his post, Samuele showed that the
-Python 2.2 method resolution order is not monotonic and he proposed to
-replace it with the C3 method resolution order. Guido agreed with his
-arguments and therefore now Python 2.3 uses C3. The C3 method itself
-has nothing to do with Python, since it was invented by people working
-on Dylan and it is described in a paper intended for lispers <a class="footnote-reference" href="#id5" id="id2" name="id2">[2]</a>. The
-present paper gives a (hopefully) readable discussion of the C3
-algorithm for Pythonistas who want to understand the reasons for the
-change.</p>
-<p>First of all, let me point out that what I am going to say only applies
-to the <em>new style classes</em> introduced in Python 2.2: <em>classic classes</em>
-maintain their old method resolution order, depth first and then left to
-right. Therefore, there is no breaking of old code for classic classes;
-and even if in principle there could be breaking of code for Python 2.2
-new style classes, in practice the cases in which the C3 resolution
-order differs from the Python 2.2 method resolution order are so rare
-that no real breaking of code is expected. Therefore:</p>
-<blockquote>
-<em>Don't be scared!</em></blockquote>
-<p>Moreover, unless you make strong use of multiple inheritance and you
-have non-trivial hierarchies, you don't need to understand the C3
-algorithm, and you can easily skip this paper. On the other hand, if
-you really want to know how multiple inheritance works, then this paper
-is for you. The good news is that things are not as complicated as you
-might expect.</p>
-<p>Let me begin with some basic definitions.</p>
-<ol class="arabic simple">
-<li>Given a class C in a complicated multiple inheritance hierarchy, it
-is a non-trivial task to specify the order in which methods are
-overridden, i.e. to specify the order of the ancestors of C.</li>
-<li>The list of the ancestors of a class C, including the class itself,
-ordered from the nearest ancestor to the furthest, is called the
-class precedence list or the <em>linearization</em> of C.</li>
-<li>The <em>Method Resolution Order</em> (MRO) is the set of rules that
-construct the linearization. In the Python literature, the idiom
-&quot;the MRO of C&quot; is also used as a synonymous for the linearization of
-the class C.</li>
-<li>For instance, in the case of single inheritance hierarchy, if C is a
-subclass of C1, and C1 is a subclass of C2, then the linearization of
-C is simply the list [C, C1 , C2]. However, with multiple
-inheritance hierarchies, the construction of the linearization is
-more cumbersome, since it is more difficult to construct a
-linearization that respects <em>local precedence ordering</em> and
-<em>monotonicity</em>.</li>
-<li>I will discuss the local precedence ordering later, but I can give
-the definition of monotonicity here. A MRO is monotonic when the
-following is true: <em>if C1 precedes C2 in the linearization of C,
-then C1 precedes C2 in the linearization of any subclass of C</em>.
-Otherwise, the innocuous operation of deriving a new class could
-change the resolution order of methods, potentially introducing very
-subtle bugs. Examples where this happens will be shown later.</li>
-<li>Not all classes admit a linearization. There are cases, in
-complicated hierarchies, where it is not possible to derive a class
-such that its linearization respects all the desired properties.</li>
-</ol>
-<p>Here I give an example of this situation. Consider the hierarchy</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; O = object
-&gt;&gt;&gt; class X(O): pass
-&gt;&gt;&gt; class Y(O): pass
-&gt;&gt;&gt; class A(X,Y): pass
-&gt;&gt;&gt; class B(Y,X): pass
-</pre>
-</blockquote>
-<p>which can be represented with the following inheritance graph, where I
-have denoted with O the <tt class="docutils literal"><span class="pre">object</span></tt> class, which is the beginning of any
-hierarchy for new style classes:</p>
-<blockquote>
-<pre class="literal-block">
- -----------
-| |
-| O |
-| / \ |
- - X Y /
- | / | /
- | / |/
- A B
- \ /
- ?
-</pre>
-</blockquote>
-<p>In this case, it is not possible to derive a new class C from A and B,
-since X precedes Y in A, but Y precedes X in B, therefore the method
-resolution order would be ambiguous in C.</p>
-<p>Python 2.3 raises an exception in this situation (TypeError: MRO
-conflict among bases Y, X) forbidding the naive programmer from creating
-ambiguous hierarchies. Python 2.2 instead does not raise an exception,
-but chooses an <em>ad hoc</em> ordering (CABXYO in this case).</p>
-<hr class="docutils" />
-<blockquote>
-<pre class="literal-block">
- _ .-=-. .-==-.
- { } __ .' O o '. / -&lt;' )
- { } .' O'. / o .-. O \ / .--v`
- { } / .-. o\ /O / \ o\ /O /
- \ `-` / \ O`-'o / \ O`-`o /
-jgs `-.-` '.____.' `.____.'
-</pre>
-</blockquote>
-</div>
-<div class="section" id="the-c3-method-resolution-order">
-<h1><a name="the-c3-method-resolution-order">The C3 Method Resolution Order</a></h1>
-<p>Let me introduce a few simple notations which will be useful for the
-following discussion. I will use the shortcut notation</p>
-<blockquote>
-C1 C2 ... CN</blockquote>
-<p>to indicate the list of classes [C1, C2, ... , CN].</p>
-<p>The <em>head</em> of the list is its first element:</p>
-<blockquote>
-head = C1</blockquote>
-<p>whereas the <em>tail</em> is the rest of the list:</p>
-<blockquote>
-tail = C2 ... CN.</blockquote>
-<p>I shall also use the notation</p>
-<blockquote>
-C + (C1 C2 ... CN) = C C1 C2 ... CN</blockquote>
-<p>to denote the sum of the lists [C] + [C1, C2, ... ,CN].</p>
-<p>Now I can explain how the MRO works in Python 2.3.</p>
-<p>Consider a class C in a multiple inheritance hierarchy, with C
-inheriting from the base classes B1, B2, ... , BN. We want to
-compute the linearization L[C] of the class C. The rule is the
-following:</p>
-<blockquote>
-<em>the linearization of C is the sum of C plus the merge of the
-linearizations of the parents and the list of the parents.</em></blockquote>
-<p>In symbolic notation:</p>
-<blockquote>
-L[C(B1 ... BN)] = C + merge(L[B1] ... L[BN], B1 ... BN)</blockquote>
-<p>In particular, if C is the <tt class="docutils literal"><span class="pre">object</span></tt> class, which has no parents, the
-linearization is trivial:</p>
-<blockquote>
-L[object] = object.</blockquote>
-<p>However, in general one has to compute the merge according to the following
-prescription:</p>
-<blockquote>
-<em>take the head of the first list, i.e L[B1][0]; if this head is not in
-the tail of any of the other lists, then add it to the linearization
-of C and remove it from the lists in the merge, otherwise look at the
-head of the next list and take it, if it is a good head. Then repeat
-the operation until all the class are removed or it is impossible to
-find good heads. In this case, it is impossible to construct the
-merge, Python 2.3 will refuse to create the class C and will raise an
-exception.</em></blockquote>
-<p>This prescription ensures that the merge operation <em>preserves</em> the
-ordering, if the ordering can be preserved. On the other hand, if the
-order cannot be preserved (as in the example of serious order
-disagreement discussed above) then the merge cannot be computed.</p>
-<p>The computation of the merge is trivial if C has only one parent
-(single inheritance); in this case</p>
-<blockquote>
-L[C(B)] = C + merge(L[B],B) = C + L[B]</blockquote>
-<p>However, in the case of multiple inheritance things are more cumbersome
-and I don't expect you can understand the rule without a couple of
-examples ;-)</p>
-<hr class="docutils" />
-<blockquote>
-<pre class="literal-block">
- .-'-.
- /' `\
- /' _.-.-._ `\
- | (|) (|) |
- | \__&quot;__/ |
- \ |v.v| /
- \ | | | /
- `\ |=^-| /'
- `|=-=|'
- | - |
- |= |
- |-=-|
- _.-=-=|= -|=-=-._
- ( |___| )
- ( `-=-=-=-=-=-=-=-` )
- (`-=-=-=-=-=-=-=-=-`)
- (`-=-=-=-=-=-=-=-=-`)
- (`-=-=-=-=-=-=-=-`)
- (`-=-=-=-=-=-=-`)
-jgs `-=-=-=-=-=-=-`
-</pre>
-</blockquote>
-</div>
-<div class="section" id="examples">
-<h1><a name="examples">Examples</a></h1>
-<p>First example. Consider the following hierarchy:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; O = object
-&gt;&gt;&gt; class F(O): pass
-&gt;&gt;&gt; class E(O): pass
-&gt;&gt;&gt; class D(O): pass
-&gt;&gt;&gt; class C(D,F): pass
-&gt;&gt;&gt; class B(D,E): pass
-&gt;&gt;&gt; class A(B,C): pass
-</pre>
-</blockquote>
-<p>In this case the inheritance graph can be drawn as</p>
-<blockquote>
-<pre class="literal-block">
- 6
- ---
-Level 3 | O | (more general)
- / --- \
- / | \ |
- / | \ |
- / | \ |
- --- --- --- |
-Level 2 3 | D | 4| E | | F | 5 |
- --- --- --- |
- \ \ _ / | |
- \ / \ _ | |
- \ / \ | |
- --- --- |
-Level 1 1 | B | | C | 2 |
- --- --- |
- \ / |
- \ / \ /
- ---
-Level 0 0 | A | (more specialized)
- ---
-</pre>
-</blockquote>
-<p>The linearizations of O,D,E and F are trivial:</p>
-<blockquote>
-<pre class="literal-block">
-L[O] = O
-L[D] = D O
-L[E] = E O
-L[F] = F O
-</pre>
-</blockquote>
-<p>The linearization of B can be computed as</p>
-<blockquote>
-<pre class="literal-block">
-L[B] = B + merge(DO, EO, DE)
-</pre>
-</blockquote>
-<p>We see that D is a good head, therefore we take it and we are reduced to
-compute <tt class="docutils literal"><span class="pre">merge(O,EO,E)</span></tt>. Now O is not a good head, since it is in the
-tail of the sequence EO. In this case the rule says that we have to
-skip to the next sequence. Then we see that E is a good head; we take
-it and we are reduced to compute <tt class="docutils literal"><span class="pre">merge(O,O)</span></tt> which gives O. Therefore</p>
-<blockquote>
-<pre class="literal-block">
-L[B] = B D E O
-</pre>
-</blockquote>
-<p>Using the same procedure one finds:</p>
-<blockquote>
-<pre class="literal-block">
-L[C] = C + merge(DO,FO,DF)
- = C + D + merge(O,FO,F)
- = C + D + F + merge(O,O)
- = C D F O
-</pre>
-</blockquote>
-<p>Now we can compute:</p>
-<blockquote>
-<pre class="literal-block">
-L[A] = A + merge(BDEO,CDFO,BC)
- = A + B + merge(DEO,CDFO,C)
- = A + B + C + merge(DEO,DFO)
- = A + B + C + D + merge(EO,FO)
- = A + B + C + D + E + merge(O,FO)
- = A + B + C + D + E + F + merge(O,O)
- = A B C D E F O
-</pre>
-</blockquote>
-<p>In this example, the linearization is ordered in a pretty nice way
-according to the inheritance level, in the sense that lower levels (i.e.
-more specialized classes) have higher precedence (see the inheritance
-graph). However, this is not the general case.</p>
-<p>I leave as an exercise for the reader to compute the linearization for
-my second example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; O = object
-&gt;&gt;&gt; class F(O): pass
-&gt;&gt;&gt; class E(O): pass
-&gt;&gt;&gt; class D(O): pass
-&gt;&gt;&gt; class C(D,F): pass
-&gt;&gt;&gt; class B(E,D): pass
-&gt;&gt;&gt; class A(B,C): pass
-</pre>
-</blockquote>
-<p>The only difference with the previous example is the change B(D,E) --&gt;
-B(E,D); however even such a little modification completely changes the
-ordering of the hierarchy</p>
-<blockquote>
-<pre class="literal-block">
- 6
- ---
-Level 3 | O |
- / --- \
- / | \
- / | \
- / | \
- --- --- ---
-Level 2 2 | E | 4 | D | | F | 5
- --- --- ---
- \ / \ /
- \ / \ /
- \ / \ /
- --- ---
-Level 1 1 | B | | C | 3
- --- ---
- \ /
- \ /
- ---
-Level 0 0 | A |
- ---
-</pre>
-</blockquote>
-<p>Notice that the class E, which is in the second level of the hierarchy,
-precedes the class C, which is in the first level of the hierarchy, i.e.
-E is more specialized than C, even if it is in a higher level.</p>
-<p>A lazy programmer can obtain the MRO directly from Python 2.2, since in
-this case it coincides with the Python 2.3 linearization. It is enough
-to invoke the .mro() method of class A:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; A.mro()
-(&lt;class '__main__.A'&gt;, &lt;class '__main__.B'&gt;, &lt;class '__main__.E'&gt;,
-&lt;class '__main__.C'&gt;, &lt;class '__main__.D'&gt;, &lt;class '__main__.F'&gt;,
-&lt;type 'object'&gt;)
-</pre>
-</blockquote>
-<p>Finally, let me consider the example discussed in the first section,
-involving a serious order disagreement. In this case, it is
-straightforward to compute the linearizations of O, X, Y, A and B:</p>
-<blockquote>
-<pre class="literal-block">
-L[O] = 0
-L[X] = X O
-L[Y] = Y O
-L[A] = A X Y O
-L[B] = B Y X O
-</pre>
-</blockquote>
-<p>However, it is impossible to compute the linearization for a class C
-that inherits from A and B:</p>
-<blockquote>
-<pre class="literal-block">
-L[C] = C + merge(AXYO, BYXO, AB)
- = C + A + merge(XYO, BYXO, B)
- = C + A + B + merge(XYO, YXO)
-</pre>
-</blockquote>
-<p>At this point we cannot merge the lists XYO and YXO, since X is in the
-tail of YXO whereas Y is in the tail of XYO: therefore there are no
-good heads and the C3 algorithm stops. Python 2.3 raises an error and
-refuses to create the class C.</p>
-<hr class="docutils" />
-<blockquote>
-<pre class="literal-block">
- __
- (\ .-. .-. /_&quot;)
- \\_//^\\_//^\\_//
-jgs `&quot;` `&quot;` `&quot;`
-</pre>
-</blockquote>
-</div>
-<div class="section" id="bad-method-resolution-orders">
-<h1><a name="bad-method-resolution-orders">Bad Method Resolution Orders</a></h1>
-<p>A MRO is <em>bad</em> when it breaks such fundamental properties as local
-precedence ordering and monotonicity. In this section, I will show
-that both the MRO for classic classes and the MRO for new style classes
-in Python 2.2 are bad.</p>
-<p>It is easier to start with the local precedence ordering. Consider the
-following example:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; F=type('Food',(),{'remember2buy':'spam'})
-&gt;&gt;&gt; E=type('Eggs',(F,),{'remember2buy':'eggs'})
-&gt;&gt;&gt; G=type('GoodFood',(F,E),{}) # under Python 2.3 this is an error!
-</pre>
-</blockquote>
-<p>with inheritance diagram</p>
-<blockquote>
-<pre class="literal-block">
- O
- |
-(buy spam) F
- | \
- | E (buy eggs)
- | /
- G
-
- (buy eggs or spam ?)
-</pre>
-</blockquote>
-<p>We see that class G inherits from F and E, with F <em>before</em> E: therefore
-we would expect the attribute <em>G.remember2buy</em> to be inherited by
-<em>F.rembermer2buy</em> and not by <em>E.remember2buy</em>: nevertheless Python 2.2
-gives</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; G.remember2buy
-'eggs'
-</pre>
-</blockquote>
-<p>This is a breaking of local precedence ordering since the order in the
-local precedence list, i.e. the list of the parents of G, is not
-preserved in the Python 2.2 linearization of G:</p>
-<blockquote>
-<pre class="literal-block">
-L[G,P22]= G E F object # F *follows* E
-</pre>
-</blockquote>
-<p>One could argue that the reason why F follows E in the Python 2.2
-linearization is that F is less specialized than E, since F is the
-superclass of E; nevertheless the breaking of local precedence ordering
-is quite non-intuitive and error prone. This is particularly true since
-it is a different from old style classes:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class F: remember2buy='spam'
-&gt;&gt;&gt; class E(F): remember2buy='eggs'
-&gt;&gt;&gt; class G(F,E): pass
-&gt;&gt;&gt; G.remember2buy
-'spam'
-</pre>
-</blockquote>
-<p>In this case the MRO is GFEF and the local precedence ordering is
-preserved.</p>
-<p>As a general rule, hierarchies such as the previous one should be
-avoided, since it is unclear if F should override E or viceversa.
-Python 2.3 solves the ambiguity by raising an exception in the creation
-of class G, effectively stopping the programmer from generating
-ambiguous hierarchies. The reason for that is that the C3 algorithm
-fails when the merge</p>
-<blockquote>
-<pre class="literal-block">
-merge(FO,EFO,FE)
-</pre>
-</blockquote>
-<p>cannot be computed, because F is in the tail of EFO and E is in the tail
-of FE.</p>
-<p>The real solution is to design a non-ambiguous hierarchy, i.e. to derive
-G from E and F (the more specific first) and not from F and E; in this
-case the MRO is GEF without any doubt.</p>
-<blockquote>
-<pre class="literal-block">
- O
- |
- F (spam)
- / |
-(eggs) E |
- \ |
- G
- (eggs, no doubt)
-</pre>
-</blockquote>
-<p>Python 2.3 forces the programmer to write good hierarchies (or, at
-least, less error-prone ones).</p>
-<p>On a related note, let me point out that the Python 2.3 algorithm is
-smart enough to recognize obvious mistakes, as the duplication of
-classes in the list of parents:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A(object): pass
-&gt;&gt;&gt; class C(A,A): pass # error
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-TypeError: duplicate base class A
-</pre>
-</blockquote>
-<p>Python 2.2 (both for classic classes and new style classes) in this
-situation, would not raise any exception.</p>
-<p>Finally, I would like to point out two lessons we have learned from this
-example:</p>
-<ol class="arabic simple">
-<li>despite the name, the MRO determines the resolution order of
-attributes, not only of methods;</li>
-<li>the default food for Pythonistas is spam ! (but you already knew
-that ;-)</li>
-</ol>
-<hr class="docutils" />
-<blockquote>
-<pre class="literal-block">
- __
- (\ .-. .-. /_&quot;)
- \\_//^\\_//^\\_//
-jgs `&quot;` `&quot;` `&quot;`
-</pre>
-</blockquote>
-<p>Having discussed the issue of local precedence ordering, let me now
-consider the issue of monotonicity. My goal is to show that neither the
-MRO for classic classes nor that for Python 2.2 new style classes is
-monotonic.</p>
-<p>To prove that the MRO for classic classes is non-monotonic is rather
-trivial, it is enough to look at the diamond diagram:</p>
-<blockquote>
-<pre class="literal-block">
- C
- / \
- / \
-A B
- \ /
- \ /
- D
-</pre>
-</blockquote>
-<p>One easily discerns the inconsistency:</p>
-<blockquote>
-<pre class="literal-block">
-L[B,P21] = B C # B precedes C : B's methods win
-L[D,P21] = D A C B C # B follows C : C's methods win!
-</pre>
-</blockquote>
-<p>On the other hand, there are no problems with the Python 2.2 and 2.3
-MROs, they give both</p>
-<blockquote>
-<pre class="literal-block">
-L[D] = D A B C
-</pre>
-</blockquote>
-<p>Guido points out in his essay <a class="footnote-reference" href="#id6" id="id3" name="id3">[3]</a> that the classic MRO is not so bad in
-practice, since one can typically avoids diamonds for classic classes.
-But all new style classes inherit from <tt class="docutils literal"><span class="pre">object</span></tt>, therefore diamonds are
-unavoidable and inconsistencies shows up in every multiple inheritance
-graph.</p>
-<p>The MRO of Python 2.2 makes breaking monotonicity difficult, but not
-impossible. The following example, originally provided by Samuele
-Pedroni, shows that the MRO of Python 2.2 is non-monotonic:</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A(object): pass
-&gt;&gt;&gt; class B(object): pass
-&gt;&gt;&gt; class C(object): pass
-&gt;&gt;&gt; class D(object): pass
-&gt;&gt;&gt; class E(object): pass
-&gt;&gt;&gt; class K1(A,B,C): pass
-&gt;&gt;&gt; class K2(D,B,E): pass
-&gt;&gt;&gt; class K3(D,A): pass
-&gt;&gt;&gt; class Z(K1,K2,K3): pass
-</pre>
-</blockquote>
-<p>Here are the linearizations according to the C3 MRO (the reader should
-verify these linearizations as an exercise and draw the inheritance
-diagram ;-)</p>
-<blockquote>
-<pre class="literal-block">
-L[A] = A O
-L[B] = B O
-L[C] = C O
-L[D] = D O
-L[E] = E O
-L[K1]= K1 A B C O
-L[K2]= K2 D B E O
-L[K3]= K3 D A O
-L[Z] = Z K1 K2 K3 D A B C E O
-</pre>
-</blockquote>
-<p>Python 2.2 gives exactly the same linearizations for A, B, C, D, E, K1,
-K2 and K3, but a different linearization for Z:</p>
-<blockquote>
-<pre class="literal-block">
-L[Z,P22] = Z K1 K3 A K2 D B C E O
-</pre>
-</blockquote>
-<p>It is clear that this linearization is <em>wrong</em>, since A comes before D
-whereas in the linearization of K3 A comes <em>after</em> D. In other words, in
-K3 methods derived by D override methods derived by A, but in Z, which
-still is a subclass of K3, methods derived by A override methods derived
-by D! This is a violation of monotonicity. Moreover, the Python 2.2
-linearization of Z is also inconsistent with local precedence ordering,
-since the local precedence list of the class Z is [K1, K2, K3] (K2
-precedes K3), whereas in the linearization of Z K2 <em>follows</em> K3. These
-problems explain why the 2.2 rule has been dismissed in favor of the C3
-rule.</p>
-<hr class="docutils" />
-<blockquote>
-<pre class="literal-block">
- __
- (\ .-. .-. .-. .-. .-. .-. .-. .-. /_&quot;)
- \\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//
-jgs `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;`
-</pre>
-</blockquote>
-</div>
-<div class="section" id="the-end">
-<h1><a name="the-end">The end</a></h1>
-<p>This section is for the impatient reader, who skipped all the previous
-sections and jumped immediately to the end. This section is for the
-lazy programmer too, who didn't want to exercise her/his brain.
-Finally, it is for the programmer with some hubris, otherwise s/he would
-not be reading a paper on the C3 method resolution order in multiple
-inheritance hierarchies ;-) These three virtues taken all together (and
-<em>not</em> separately) deserve a prize: the prize is a short Python 2.2
-script that allows you to compute the 2.3 MRO without risk to your
-brain. Simply change the last line to play with the various examples I
-have discussed in this paper.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;mro.py&gt;
-
-&quot;&quot;&quot;C3 algorithm by Samuele Pedroni (with readability enhanced by me).&quot;&quot;&quot;
-
-class __metaclass__(type):
- &quot;All classes are metamagically modified to be nicely printed&quot;
- __repr__ = lambda cls: cls.__name__
-
-class ex_2:
- &quot;Serious order disagreement&quot; #From Guido
- class O: pass
- class X(O): pass
- class Y(O): pass
- class A(X,Y): pass
- class B(Y,X): pass
- try:
- class Z(A,B): pass #creates Z(A,B) in Python 2.2
- except TypeError:
- pass # Z(A,B) cannot be created in Python 2.3
-
-class ex_5:
- &quot;My first example&quot;
- class O: pass
- class F(O): pass
- class E(O): pass
- class D(O): pass
- class C(D,F): pass
- class B(D,E): pass
- class A(B,C): pass
-
-class ex_6:
- &quot;My second example&quot;
- class O: pass
- class F(O): pass
- class E(O): pass
- class D(O): pass
- class C(D,F): pass
- class B(E,D): pass
- class A(B,C): pass
-
-class ex_9:
- &quot;Difference between Python 2.2 MRO and C3&quot; #From Samuele
- class O: pass
- class A(O): pass
- class B(O): pass
- class C(O): pass
- class D(O): pass
- class E(O): pass
- class K1(A,B,C): pass
- class K2(D,B,E): pass
- class K3(D,A): pass
- class Z(K1,K2,K3): pass
-
-def merge(seqs):
- print '\n\nCPL[%s]=%s' % (seqs[0][0],seqs),
- res = []; i=0
- while 1:
- nonemptyseqs=[seq for seq in seqs if seq]
- if not nonemptyseqs: return res
- i+=1; print '\n',i,'round: candidates...',
- for seq in nonemptyseqs: # find merge candidates among seq heads
- cand = seq[0]; print ' ',cand,
- nothead=[s for s in nonemptyseqs if cand in s[1:]]
- if nothead: cand=None #reject candidate
- else: break
- if not cand: raise &quot;Inconsistent hierarchy&quot;
- res.append(cand)
- for seq in nonemptyseqs: # remove cand
- if seq[0] == cand: del seq[0]
-
-def mro(C):
- &quot;Compute the class precedence list (mro) according to C3&quot;
- return merge([[C]]+map(mro,C.__bases__)+[list(C.__bases__)])
-
-def print_mro(C):
- print '\nMRO[%s]=%s' % (C,mro(C))
- print '\nP22 MRO[%s]=%s' % (C,C.mro())
-
-print_mro(ex_9.Z)
-
-#&lt;/mro.py&gt;
-</pre>
-</blockquote>
-<p>That's all folks,</p>
-<blockquote>
-enjoy !</blockquote>
-<hr class="docutils" />
-<blockquote>
-<pre class="literal-block">
- __
- (&quot;_\ .-. .-. .-. .-. .-. .-. .-. .-. /)
- \\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//^\\_//
-jgs `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;` `&quot;`
-</pre>
-</blockquote>
-</div>
-<div class="section" id="resources">
-<h1><a name="resources">Resources</a></h1>
-<table class="docutils footnote" frame="void" id="id4" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1" name="id4">[1]</a></td><td>The thread on python-dev started by Samuele Pedroni:
-<a class="reference" href="http://mail.python.org/pipermail/python-dev/2002-October/029035.html">http://mail.python.org/pipermail/python-dev/2002-October/029035.html</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id5" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id2" name="id5">[2]</a></td><td>The paper <em>A Monotonic Superclass Linearization for Dylan</em>:
-<a class="reference" href="http://www.webcom.com/haahr/dylan/linearization-oopsla96.html">http://www.webcom.com/haahr/dylan/linearization-oopsla96.html</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id6" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id3" name="id6">[3]</a></td><td>Guido van Rossum's essay, <em>Unifying types and classes in Python 2.2</em>:
-<a class="reference" href="http://www.python.org/2.2.2/descrintro.html">http://www.python.org/2.2.2/descrintro.html</a></td></tr>
-</tbody>
-</table>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/oxford/objects.html b/pypers/oxford/objects.html
deleted file mode 100755
index 644fb0a..0000000
--- a/pypers/oxford/objects.html
+++ /dev/null
@@ -1,743 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title>Lecture 2: Objects (delegation &amp; inheritance)</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="lecture-2-objects-delegation-inheritance">
-<h1 class="title">Lecture 2: Objects (delegation &amp; inheritance)</h1>
-<div class="section" id="part-i-delegation">
-<h1><a name="part-i-delegation">Part I: delegation</a></h1>
-<p>Understanding how attribute access works: internal delegation via <em>descriptors</em></p>
-<div class="section" id="accessing-simple-attributes">
-<h2><a name="accessing-simple-attributes">Accessing simple attributes</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... a = 2
-... def __init__(self, x):
-... self.x = x
-...
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; c = C(1)
-&gt;&gt;&gt; c.x
-1
-&gt;&gt;&gt; c.a
-2
-</pre>
-<p>We are retrieving</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.__dict__[&quot;x&quot;]
-1
-</pre>
-<p>If there is nothing in c.__dict__, Python looks at C.__dict__:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print c.__dict__.get(&quot;a&quot;)
-None
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__dict__[&quot;a&quot;]
-2
-</pre>
-<p>If there is nothing in C.__dict__, Python looks at the superclasses according
-to the MRO (see part II).</p>
-</div>
-<div class="section" id="accessing-methods">
-<h2><a name="accessing-methods">Accessing methods</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.__init__ #doctest: +ELLIPSIS
-&lt;bound method C.__init__ of &lt;__main__.C object at 0x...&gt;&gt;
-</pre>
-<p>since __init__ is not in c.__dict__ Python looks in the class dictionary
-and finds</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__dict__[&quot;__init__&quot;] #doctest: +ELLIPSIS
-&lt;function __init__ at 0x...&gt;
-</pre>
-<p>Then it magically converts the function into a method bound to the instance
-&quot;c&quot;.</p>
-<p>NOTE: this mechanism works for new-style classes only.</p>
-<p>The old-style mechanism is less consistent and the attribute lookup of special
-methods is special: (*)</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object): pass
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; c.__str__ = lambda : &quot;hello!&quot;
-&gt;&gt;&gt; print c #doctest: +ELLIPSIS
-&lt;__main__.C object at ...&gt;
-</pre>
-<p>whereas for old-style classes</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C: pass
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; c.__str__ = lambda : &quot;hello!&quot;
-&gt;&gt;&gt; print c
-hello!
-</pre>
-<p>the special method is looked for in the instance dictionary too.</p>
-<p>(*) modulo a very subtle difference for __getattr__-delegated special methods,
-see later.</p>
-</div>
-<div class="section" id="converting-functions-into-methods">
-<h2><a name="converting-functions-into-methods">Converting functions into methods</a></h2>
-<p>It is possible to convert a function into a bound or unbound method
-by invoking the <tt class="docutils literal"><span class="pre">__get__</span></tt> special method:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(x): pass
-&gt;&gt;&gt; f.__get__ #doctest: +ELLIPSIS
-&lt;method-wrapper object at 0x...&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object): pass
-...
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(self): pass
-...
-&gt;&gt;&gt; f.__get__(C(), C) #doctest: +ELLIPSIS
-&lt;bound method C.f of &lt;__main__.C object at 0x...&gt;&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; f.__get__(None, C)
-&lt;unbound method C.f&gt;
-</pre>
-<p>Functions are the simplest example of <em>descriptors</em>.</p>
-<p>Access to methods works since internally Python transforms</p>
-<blockquote>
-<tt class="docutils literal"><span class="pre">c.__init__</span> <span class="pre">-&gt;</span> <span class="pre">type(c).__dict__['__init__'].__get__(c,</span> <span class="pre">type(c))</span></tt></blockquote>
-<p>Note: not <em>all</em> functions are descriptors:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from operator import add
-&gt;&gt;&gt; add.__get__
-Traceback (most recent call last):
- ...
-AttributeError: 'builtin_function_or_method' object has no attribute '__get__'
-</pre>
-</div>
-<div class="section" id="hack-a-very-slick-adder">
-<h2><a name="hack-a-very-slick-adder">Hack: a very slick adder</a></h2>
-<p>The descriptor protocol can be (ab)used as a way to avoid the late binding
-issue in for loops:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def add(x,y):
-... return x + y
-&gt;&gt;&gt; closures = [add.__get__(i) for i in range(10)]
-&gt;&gt;&gt; closures[5](1000)
-1005
-</pre>
-<p>Notice: operator.add will not work.</p>
-</div>
-<div class="section" id="descriptor-protocol">
-<h2><a name="descriptor-protocol">Descriptor Protocol</a></h2>
-<p>Everything at <a class="reference" href="http://users.rcn.com/python/download/Descriptor.htm">http://users.rcn.com/python/download/Descriptor.htm</a></p>
-<p>Formally:</p>
-<pre class="literal-block">
-descr.__get__(self, obj, type=None) --&gt; value
-descr.__set__(self, obj, value) --&gt; None
-descr.__delete__(self, obj) --&gt; None
-</pre>
-<p>Examples of custom descriptors:</p>
-<pre class="literal-block">
-#&lt;descriptor.py&gt;
-
-
-class AttributeDescriptor(object):
- def __get__(self, obj, cls=None):
- if obj is None and cls is None:
- raise TypeError(&quot;__get__(None, None) is invalid&quot;)
- elif obj is None:
- return self.get_from_class(cls)
- else:
- return self.get_from_obj(obj)
- def get_from_class(self, cls):
- print &quot;Getting %s from %s&quot; % (self, cls)
- def get_from_obj(self, obj):
- print &quot;Getting %s from %s&quot; % (self, obj)
-
-
-class Staticmethod(AttributeDescriptor):
- def __init__(self, func):
- self.func = func
- def get_from_class(self, cls):
- return self.func
- get_from_obj = get_from_class
-
-
-class Classmethod(AttributeDescriptor):
- def __init__(self, func):
- self.func = func
- def get_from_class(self, cls):
- return self.func.__get__(cls, type(cls))
- def get_from_obj(self, obj):
- return self.get_from_class(obj.__class__)
-
-class C(object):
- s = Staticmethod(lambda : 1)
- c = Classmethod(lambda cls : cls.__name__)
-
-c = C()
-
-assert C.s() == c.s() == 1
-assert C.c() == c.c() == &quot;C&quot;
-
-#&lt;/descriptor.py&gt;
-</pre>
-</div>
-<div class="section" id="multilingual-attribute">
-<h2><a name="multilingual-attribute">Multilingual attribute</a></h2>
-<p>Inspirated by a question in the Italian Newsgroup:</p>
-<pre class="literal-block">
-#&lt;multilingual.py&gt;
-
-import sys
-from descriptor import AttributeDescriptor
-
-class MultilingualAttribute(AttributeDescriptor):
- &quot;&quot;&quot;When a MultilingualAttribute is accessed, you get the translation
- corresponding to the currently selected language.
- &quot;&quot;&quot;
- def __init__(self, **translations):
- self.trans = translations
- def get_from_class(self, cls):
- return self.trans[getattr(cls, &quot;language&quot;, None) or
- sys.modules[cls.__module__].language]
- def get_from_obj(self, obj):
- return self.trans[getattr(obj, &quot;language&quot;, None) or
- sys.modules[obj.__class__.__module__].language]
-
-
-language = &quot;en&quot;
-
-# a dummy User class
-class DefaultUser(object):
- def has_permission(self):
- return False
-
-class WebApplication(object):
- error_msg = MultilingualAttribute(
- en=&quot;You cannot access this page&quot;,
- it=&quot;Questa pagina non e' accessibile&quot;,
- fr=&quot;Vous ne pouvez pas acceder cette page&quot;,)
- user = DefaultUser()
- def __init__(self, language=None):
- self.language = language or getattr(self.__class__, &quot;language&quot;, None)
- def show_page(self):
- if not self.user.has_permission():
- return self.error_msg
-
-
-app = WebApplication()
-assert app.show_page() == &quot;You cannot access this page&quot;
-
-app.language = &quot;fr&quot;
-assert app.show_page() == &quot;Vous ne pouvez pas acceder cette page&quot;
-
-app.language = &quot;it&quot;
-assert app.show_page() == &quot;Questa pagina non e' accessibile&quot;
-
-app.language = &quot;en&quot;
-assert app.show_page() == &quot;You cannot access this page&quot;
-
-#&lt;/multilingual.py&gt;
-</pre>
-<p>The same can be done with properties:</p>
-<pre class="literal-block">
-#&lt;multilingualprop.py&gt;
-
-language = &quot;en&quot;
-
-# a dummy User class
-class DefaultUser(object):
- def has_permission(self):
- return False
-
-def multilingualProperty(**trans):
- def get(self):
- return trans[self.language]
- def set(self, value):
- trans[self.language] = value
- return property(get, set)
-
-class WebApplication(object):
- language = language
- error_msg = multilingualProperty(
- en=&quot;You cannot access this page&quot;,
- it=&quot;Questa pagina non e' accessibile&quot;,
- fr=&quot;Vous ne pouvez pas acceder cette page&quot;,)
- user = DefaultUser()
- def __init__(self, language=None):
- if language: self.language = self.language
- def show_page(self):
- if not self.user.has_permission():
- return self.error_msg
-
-#&lt;/multilingualprop.py&gt;
-</pre>
-<p>This also gives the possibility to set the error messages.</p>
-<p>The difference with the descriptor approach</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from multilingual import WebApplication
-&gt;&gt;&gt; app = WebApplication()
-&gt;&gt;&gt; print app.error_msg
-You cannot access this page
-&gt;&gt;&gt; print WebApplication.error_msg
-You cannot access this page
-</pre>
-<p>is that with properties there is no nice access from the class:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from multilingualprop import WebApplication
-&gt;&gt;&gt; WebApplication.error_msg #doctest: +ELLIPSIS
-&lt;property object at ...&gt;
-</pre>
-</div>
-<div class="section" id="another-use-case-for-properties-storing-users">
-<h2><a name="another-use-case-for-properties-storing-users">Another use case for properties: storing users</a></h2>
-<p>Consider a library providing a simple User class:</p>
-<pre class="literal-block">
-#&lt;crypt_user.py&gt;
-
-class User(object):
- def __init__(self, username, password):
- self.username, self.password = username, password
-
-#&lt;/crypt_user.py&gt;
-</pre>
-<p>The User objects are stored in a database as they are.
-For security purpose, in a second version of the library it is
-decided to crypt the password, so that only crypted passwords
-are stored in the database. With properties, it is possible to
-implement this functionality without changing the source code for
-the User class:</p>
-<pre class="literal-block">
-#&lt;crypt_user.py&gt;
-
-from crypt import crypt
-
-def cryptedAttribute(seed=&quot;x&quot;):
- def get(self):
- return getattr(self, &quot;_pw&quot;, None)
- def set(self, value):
- self._pw = crypt(value, seed)
- return property(get, set)
-
-User.password = cryptedAttribute()
-</pre>
-<p>#&lt;/crypt_user.py&gt;</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from crypt_user import User
-&gt;&gt;&gt; u = User(&quot;michele&quot;, &quot;secret&quot;)
-&gt;&gt;&gt; print u.password
-xxZREZpkHZpkI
-</pre>
-<p>Notice the property factory approach used here.</p>
-</div>
-<div class="section" id="low-level-delegation-via-getattribute">
-<h2><a name="low-level-delegation-via-getattribute">Low-level delegation via __getattribute__</a></h2>
-<p>Attribute access is managed by the__getattribute__ special method:</p>
-<pre class="literal-block">
-#&lt;tracedaccess.py&gt;
-
-class TracedAccess(object):
- def __getattribute__(self, name):
- print &quot;Accessing %s&quot; % name
- return object.__getattribute__(self, name)
-
-
-class C(TracedAccess):
- s = staticmethod(lambda : 'staticmethod')
- c = classmethod(lambda cls: 'classmethod')
- m = lambda self: 'method'
- a = &quot;hello&quot;
-
-#&lt;/tracedaccess.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from tracedaccess import C
-&gt;&gt;&gt; c = C()
-&gt;&gt;&gt; print c.s()
-Accessing s
-staticmethod
-&gt;&gt;&gt; print c.c()
-Accessing c
-classmethod
-&gt;&gt;&gt; print c.m()
-Accessing m
-method
-&gt;&gt;&gt; print c.a
-Accessing a
-hello
-&gt;&gt;&gt; print c.__init__ #doctest: +ELLIPSIS
-Accessing __init__
-&lt;method-wrapper object at 0x...&gt;
-&gt;&gt;&gt; try: c.x
-... except AttributeError, e: print e
-...
-Accessing x
-'C' object has no attribute 'x'
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.y = 'y'
-&gt;&gt;&gt; c.y
-Accessing y
-'y'
-</pre>
-<p>You are probably familiar with <tt class="docutils literal"><span class="pre">__getattr__</span></tt> which is similar
-to <tt class="docutils literal"><span class="pre">__getattribute__</span></tt>, but it is called <em>only for missing attributes</em>.</p>
-</div>
-<div class="section" id="traditional-delegation-via-getattr">
-<h2><a name="traditional-delegation-via-getattr">Traditional delegation via __getattr__</a></h2>
-<p>Realistic use case in &quot;object publishing&quot;:</p>
-<pre class="literal-block">
-#&lt;webapp.py&gt;
-
-class WebApplication(object):
- def __getattr__(self, name):
- return name.capitalize()
-
-
-app = WebApplication()
-
-assert app.page1 == 'Page1'
-assert app.page2 == 'Page2'
-
-#&lt;/webapp.py&gt;
-</pre>
-<p>Here is another use case in HTML generation:</p>
-<pre class="literal-block">
-#&lt;XMLtag.py&gt;
-
-def makeattr(dict_or_list_of_pairs):
- dic = dict(dict_or_list_of_pairs)
- return &quot; &quot;.join('%s=&quot;%s&quot;' % (k, dic[k]) for k in dic) # simplistic
-
-class XMLTag(object):
- def __getattr__(self, name):
- def tag(value, **attr):
- &quot;&quot;&quot;value can be a string or a sequence of strings.&quot;&quot;&quot;
- if hasattr(value, &quot;__iter__&quot;): # is iterable
- value = &quot; &quot;.join(value)
- return &quot;&lt;%s %s&gt;%s&lt;/%s&gt;&quot; % (name, makeattr(attr), value, name)
- return tag
-
-class XMLShortTag(object):
- def __getattr__(self, name):
- def tag(**attr):
- return &quot;&lt;%s %s /&gt;&quot; % (name, makeattr(attr))
- return tag
-
-tag = XMLTag()
-tg = XMLShortTag()
-
-#&lt;/XMLtag.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from XMLtag import tag, tg
-&gt;&gt;&gt; print tag.a(&quot;example.com&quot;, href=&quot;http://www.example.com&quot;)
-&lt;a href=&quot;http://www.example.com&quot;&gt;example.com&lt;/a&gt;
-&gt;&gt;&gt; print tg.br(**{'class':&quot;br_style&quot;})
-&lt;br class=&quot;br_style&quot; /&gt;
-</pre>
-</div>
-<div class="section" id="keyword-dictionaries-with-getattr-setattr">
-<h2><a name="keyword-dictionaries-with-getattr-setattr">Keyword dictionaries with __getattr__/__setattr__</a></h2>
-<pre class="literal-block">
-#&lt;kwdict.py&gt;
-
-class kwdict(dict): # UserDict not dict, to make it to work with Zope
- &quot;&quot;&quot;A typing shortcut used in place of a keyword dictionary.
- It also has two useful 'fromfile' and 'fromstring' constructors
- &quot;&quot;&quot;
- def __getattr__(self, name):
- return self[name]
- def __setattr__(self, name, value):
- self[name] = value
-
-#&lt;/kwdict.py&gt;
-</pre>
-<p>An now for a completely different solution:</p>
-<pre class="literal-block">
-#&lt;dictwrapper.py&gt;
-
-class DictWrapper(object):
- def __init__(self, **kw):
- self.__dict__.update(kw)
-
-#&lt;/dictwrapper.py&gt;
-</pre>
-</div>
-<div class="section" id="delegation-to-special-methods-caveat">
-<h2><a name="delegation-to-special-methods-caveat">Delegation to special methods caveat</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; class ListWrapper(object):
-... def __init__(self, ls):
-... self._list = ls
-... def __getattr__(self, name):
-... if name == &quot;__getitem__&quot;: # special method
-... return self._list.__getitem__
-... elif name == &quot;reverse&quot;: # regular method
-... return self._list.reverse
-... else:
-... raise AttributeError(&quot;%r is not defined&quot; % name)
-...
-&gt;&gt;&gt; lw = ListWrapper([0,1,2])
-&gt;&gt;&gt; print lw.x
-Traceback (most recent call last):
- ...
-AttributeError: 'x' is not defined
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; lw.reverse()
-&gt;&gt;&gt; print lw.__getitem__(0)
-2
-&gt;&gt;&gt; print lw.__getitem__(1)
-1
-&gt;&gt;&gt; print lw.__getitem__(2)
-0
-&gt;&gt;&gt; print lw[0]
-Traceback (most recent call last):
- ...
-TypeError: unindexable object
-</pre>
-</div>
-</div>
-<div class="section" id="part-ii-inheritance">
-<h1><a name="part-ii-inheritance">Part II: Inheritance</a></h1>
-<p>The major changes in inheritance from Python 2.1 to 2.2+ are:</p>
-<ol class="arabic simple">
-<li>you can subclass built-in types (as a consequence the constructor__new__
-has been exposed to the user, to help subclassing immutable types);</li>
-<li>the Method Resolution Order (MRO) has changed;</li>
-<li>now Python allows <em>cooperative method calls</em>, i.e. we have <em>super</em>.</li>
-</ol>
-<p>In principle, the last two changes are relevant only if you use multiple
-inheritance. If you use single inheritance only, you don't need <tt class="docutils literal"><span class="pre">super</span></tt>;
-you can just name the superclass or use tricks such as:</p>
-<pre class="literal-block">
-self.__class__.__base__.__init__(self, *args, **kw)
-</pre>
-<p>instead of:</p>
-<pre class="literal-block">
-super(CurrentClass, self).__init__(*args, **kw)
-</pre>
-<p>However, somebody else may want to use your class in a MI hierarchy,
-and you would make her life difficult if you don't use <tt class="docutils literal"><span class="pre">super</span></tt>:</p>
-<pre class="literal-block">
-#&lt;why_super.py&gt;
-
-class Base(object):
- def __init__(self):
- print &quot;B.__init__&quot;
-
-class MyClass(Base):
- &quot;I do not cooperate with others&quot;
- def __init__(self):
- print &quot;MyClass.__init__&quot;
- Base.__init__(self) #instead of super(MyClass, self).__init__()
-
-
-class Mixin(Base):
- &quot;I am cooperative with others&quot;
- def __init__(self):
- print &quot;Mixin.__init__&quot;
- super(Mixin, self).__init__()
-
-class HerClass(MyClass, Mixin):
- &quot;I am cooperative too&quot;
- def __init__(self):
- print &quot;HerClass.__init__&quot;
- super(HerClass, self).__init__()
-
-#&lt;/why_super.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from why_super import HerClass
-&gt;&gt;&gt; h = HerClass() # Mixin.__init__ is not called!
-HerClass.__init__
-MyClass.__init__
-B.__init__
-</pre>
-<p>So to be polite versus your future users you should use <tt class="docutils literal"><span class="pre">super</span></tt> always.
-This adds a cognitive burden even for people not using MI :-(</p>
-<p>Notice that there is no good comprehensive reference on <tt class="docutils literal"><span class="pre">super</span></tt> (yet)
-Your best bet is still <a class="reference" href="http://www.python.org/2.2.3/descrintro.html#cooperation">http://www.python.org/2.2.3/descrintro.html#cooperation</a></p>
-<p>The MRO instead is explained here: <a class="reference" href="http://www.python.org/2.3/mro.html">http://www.python.org/2.3/mro.html</a></p>
-<p>Notice that I DO NOT recommand Multiple Inheritance.</p>
-<p>More often than not you are better off using composition/delegation/wrapping,
-etc.</p>
-<p>See Zope 2 -&gt; Zope 3 experience.</p>
-<div class="section" id="elementary-introduction-to-the-most-sophisticated-descriptor-ever-super">
-<h2><a name="elementary-introduction-to-the-most-sophisticated-descriptor-ever-super">Elementary introduction to the most sophisticated descriptor ever: <em>super</em></a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B(object):
-... def __init__(self): print &quot;B.__init__&quot;
-...
-&gt;&gt;&gt; class C(B):
-... def __init__(self): print &quot;C.__init__&quot;
-...
-&gt;&gt;&gt; c = C()
-C.__init__
-</pre>
-<p><tt class="docutils literal"><span class="pre">super(cls,</span> <span class="pre">instance)</span></tt>, where <tt class="docutils literal"><span class="pre">instance</span></tt> is an instance of <tt class="docutils literal"><span class="pre">cls</span></tt> or of
-a subclass of <tt class="docutils literal"><span class="pre">cls</span></tt>, retrieves the right method in the MRO:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, c).__init__ #doctest: +ELLIPSIS
-&lt;bound method C.__init__ of &lt;__main__.C object at 0x...&gt;&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, c).__init__.im_func is B.__init__.im_func
-True
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, c).__init__()
-B.__init__
-</pre>
-<p><tt class="docutils literal"><span class="pre">super(cls,</span> <span class="pre">subclass)</span></tt> works for unbound methods:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, C).__init__
-&lt;unbound method C.__init__&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, C).__init__.im_func is B.__init__.im_func
-True
-&gt;&gt;&gt; super(C, C).__init__(c)
-B.__init__
-</pre>
-<p><tt class="docutils literal"><span class="pre">super(cls,</span> <span class="pre">subclass)</span></tt> is also necessary for classmethods and staticmethods.
-Properties and custom descriptorsw works too:</p>
-<pre class="literal-block">
-#&lt;super_ex.py&gt;
-
-from descriptor import AttributeDescriptor
-
-class B(object):
- &#64;staticmethod
- def sm(): return &quot;staticmethod&quot;
-
- &#64;classmethod
- def cm(cls): return cls.__name__
-
- p = property()
- a = AttributeDescriptor()
-
-class C(B): pass
-
-#&lt;/super_ex.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from super_ex import C
-</pre>
-<p>Staticmethod usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, C).sm #doctest: +ELLIPSIS
-&lt;function sm at 0x...&gt;
-&gt;&gt;&gt; super(C, C).sm()
-'staticmethod'
-</pre>
-<p>Classmethod usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C, C()).cm
-&lt;bound method type.cm of &lt;class 'super_ex.C'&gt;&gt;
-&gt;&gt;&gt; super(C, C).cm() # C is automatically passed
-'C'
-</pre>
-<p>Property usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print super(C, C).p #doctest: +ELLIPSIS
-&lt;property object at 0x...&gt;
-&gt;&gt;&gt; super(C, C).a #doctest: +ELLIPSIS
-Getting &lt;descriptor.AttributeDescriptor object at 0x...&gt; from &lt;class 'super_ex.C'&gt;
-</pre>
-<p><tt class="docutils literal"><span class="pre">super</span></tt> does not work with old-style classes, however you can use the
-following trick:</p>
-<pre class="literal-block">
-#&lt;super_old_new.py&gt;
-class O:
- def __init__(self):
- print &quot;O.__init__&quot;
-
-class N(O, object):
- def __init__(self):
- print &quot;N.__init__&quot;
- super(N, self).__init__()
-</pre>
-<p>#&lt;/super_old_new.py&gt;</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from super_old_new import N
-&gt;&gt;&gt; new = N()
-N.__init__
-O.__init__
-</pre>
-<p>There are dozens of tricky points concerning <tt class="docutils literal"><span class="pre">super</span></tt>, be warned!</p>
-</div>
-<div class="section" id="subclassing-built-in-types-new-vs-init">
-<h2><a name="subclassing-built-in-types-new-vs-init">Subclassing built-in types; __new__ vs. __init__</a></h2>
-<pre class="literal-block">
-#&lt;point.py&gt;
-
-class NotWorkingPoint(tuple):
- def __init__(self, x, y):
- super(NotWorkingPoint, self).__init__((x,y))
- self.x, self.y = x, y
-
-#&lt;/point.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from point import NotWorkingPoint
-&gt;&gt;&gt; p = NotWorkingPoint(2,3)
-Traceback (most recent call last):
- ...
-TypeError: tuple() takes at most 1 argument (2 given)
-</pre>
-<blockquote>
-<p>#&lt;point.py&gt;</p>
-<dl class="docutils">
-<dt>class Point(tuple):</dt>
-<dd><dl class="first last docutils">
-<dt>def __new__(cls, x, y):</dt>
-<dd>return super(Point, cls).__new__(cls, (x,y))</dd>
-<dt>def __init__(self, x, y):</dt>
-<dd>super(Point, self).__init__((x, y))
-self.x, self.y = x, y</dd>
-</dl>
-</dd>
-</dl>
-<p>#&lt;/point.py&gt;</p>
-</blockquote>
-<p>Notice that__new__ is a staticmethod, not a classmethod, so one needs
-to pass the class explicitely.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from point import Point
-&gt;&gt;&gt; p = Point(2,3)
-&gt;&gt;&gt; print p, p.x, p.y
-(2, 3) 2 3
-</pre>
-</div>
-<div class="section" id="be-careful-when-using-new-with-mutable-types">
-<h2><a name="be-careful-when-using-new-with-mutable-types">Be careful when using __new__ with mutable types</a></h2>
-<pre class="doctest-block">
-&gt;&gt;&gt; class ListWithDefault(list):
-... def __new__(cls):
-... return super(ListWithDefault, cls).__new__(cls, [&quot;hello&quot;])
-...
-&gt;&gt;&gt; print ListWithDefault() # beware! NOT [&quot;hello&quot;]!
-[]
-</pre>
-<p>Reason: lists are re-initialized to empty lists in list.__init__!</p>
-<p>Instead</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class ListWithDefault(list):
-... def __init__(self):
-... super(ListWithDefault, self).__init__([&quot;hello&quot;])
-...
-&gt;&gt;&gt; print ListWithDefault() # works!
-['hello']
-</pre>
-</div>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/pep318/__main__.html b/pypers/pep318/__main__.html
deleted file mode 100755
index 06494a9..0000000
--- a/pypers/pep318/__main__.html
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>Documentation of the __main__ module</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="documentation-of-the-main-module">
-<h1 class="title">Documentation of the __main__ module</h1>
-<p>Short utility to extract documentation from a module</p>
-<div class="section" id="documented-metaclasses">
-<h1><a name="documented-metaclasses">Documented metaclasses</a></h1>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt>__main__.rst</tt>, line 6)</p>
-Section empty; must have contents.</div>
-</div>
-<div class="section" id="documented-classes">
-<h1><a name="documented-classes">Documented classes</a></h1>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt>__main__.rst</tt>, line 10)</p>
-Section empty; must have contents.</div>
-</div>
-<div class="section" id="documented-functions">
-<h1><a name="documented-functions">Documented functions</a></h1>
-<p><tt class="literal"><span class="pre">publish_cmdline(reader=None,</span> <span class="pre">reader_name='standalone'</span></tt></p>
-<p>Set up &amp; run a <cite>Publisher</cite>. For command-line front ends.</p>
-<p>Parameters:</p>
-<ul class="simple">
-<li><cite>reader</cite>: A <cite>docutils.readers.Reader</cite> object.</li>
-<li><cite>reader_name</cite>: Name or alias of the Reader class to be instantiated if
-no <cite>reader</cite> supplied.</li>
-<li><cite>parser</cite>: A <cite>docutils.parsers.Parser</cite> object.</li>
-<li><cite>parser_name</cite>: Name or alias of the Parser class to be instantiated if
-no <cite>parser</cite> supplied.</li>
-<li><cite>writer</cite>: A <cite>docutils.writers.Writer</cite> object.</li>
-<li><cite>writer_name</cite>: Name or alias of the Writer class to be instantiated if
-no <cite>writer</cite> supplied.</li>
-<li><cite>settings</cite>: Runtime settings object.</li>
-<li><cite>settings_spec</cite>: Extra settings specification; a <cite>docutils.SettingsSpec</cite>
-subclass. Used only if no <cite>settings</cite> specified.</li>
-<li><cite>settings_overrides</cite>: A dictionary containing program-specific overrides
-of component settings.</li>
-<li><cite>argv</cite>: Command-line argument list to use instead of <tt class="literal"><span class="pre">sys.argv[1:]</span></tt>.</li>
-<li><cite>usage</cite>: Usage string, output if there's a problem parsing the command
-line.</li>
-<li><cite>description</cite>: Program description, output for the &quot;--help&quot; option
-(along with command-line option descriptions).</li>
-</ul>
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="__main__.rst">View document source</a>.
-Generated on: 2003-09-20 09:39 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/pep318/decorators.html b/pypers/pep318/decorators.html
deleted file mode 100755
index 59d584f..0000000
--- a/pypers/pep318/decorators.html
+++ /dev/null
@@ -1,1534 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>Implementing PEP 318 (decorators)</title>
-<meta name="author" content="Michele Simionato" />
-<meta name="date" content="September 2003" />
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="implementing-pep-318-decorators">
-<h1 class="title">Implementing PEP 318 (decorators)</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr class="field"><th class="docinfo-name">Module:</th><td class="field-body">decorators</td>
-</tr>
-<tr><th class="docinfo-name">Version:</th>
-<td>0.5</td></tr>
-<tr><th class="docinfo-name">Author:</th>
-<td>Michele Simionato</td></tr>
-<tr class="field"><th class="docinfo-name">e-mail:</th><td class="field-body"><a class="reference" href="mailto:MicheleSimionato&#64;libero.it">MicheleSimionato&#64;libero.it</a></td>
-</tr>
-<tr class="field"><th class="docinfo-name">Licence:</th><td class="field-body">Python-like</td>
-</tr>
-<tr><th class="docinfo-name">Date:</th>
-<td>September 2003</td></tr>
-<tr class="field"><th class="docinfo-name">Disclaimer:</th><td class="field-body">This is experimental code. Use it at your own risk!</td>
-</tr>
-</tbody>
-</table>
-<div class="contents topic" id="contents">
-<p class="topic-title"><a name="contents">Contents</a></p>
-<ul class="simple">
-<li><a class="reference" href="#using-decorators" id="id4" name="id4">Using decorators</a><ul>
-<li><a class="reference" href="#basics" id="id5" name="id5">Basics</a></li>
-<li><a class="reference" href="#decorating-methods" id="id6" name="id6">Decorating methods</a></li>
-<li><a class="reference" href="#decorating-classes" id="id7" name="id7">Decorating classes</a></li>
-<li><a class="reference" href="#adding-magic" id="id8" name="id8">Adding magic</a></li>
-<li><a class="reference" href="#defining-method-decorators" id="id9" name="id9">Defining method decorators</a></li>
-<li><a class="reference" href="#defining-class-decorators" id="id10" name="id10">Defining class decorators</a></li>
-<li><a class="reference" href="#composing-decorators" id="id11" name="id11">Composing decorators</a></li>
-<li><a class="reference" href="#diving-into-magic" id="id12" name="id12">Diving into magic</a></li>
-<li><a class="reference" href="#advanced-usage" id="id13" name="id13">Advanced usage</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-implementation" id="id14" name="id14">The implementation</a><ul>
-<li><a class="reference" href="#module-decorators" id="id15" name="id15">Module <tt class="literal"><span class="pre">decorators</span></tt></a><ul>
-<li><a class="reference" href="#id3" id="id16" name="id16">Metaclasses</a></li>
-<li><a class="reference" href="#classes" id="id17" name="id17">Classes</a></li>
-<li><a class="reference" href="#functions" id="id18" name="id18">Functions</a></li>
-</ul>
-</li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="section" id="using-decorators">
-<h1><a class="toc-backref" href="#id4" name="using-decorators">Using decorators</a></h1>
-<p>Having plenty of free time in these days, I have finished an old
-project of mine, the implementation of <a class="reference" href="http://www.python.org/pep">PEP 318</a> in pure Python
-(2.3).</p>
-<p>Here is the rationale:</p>
-<ul class="simple">
-<li>some kind of decorator syntax is scheduled to go in Python 2.4,
-therefore it is interesting to play with the concept;</li>
-<li>it is nice to play with decorators now, without having to
-wait for one year or so;</li>
-<li>it is much easier to experiment with a pure Python implementation
-than with a C implementation;</li>
-<li>the implementation can be seen as an exercise on modern Python
-programming and may be valuable to people wanting to study the most
-advanced new constructs in Python (<a class="reference" href="http://users.rcn.com/python/download/Descriptor.htm">descriptors</a>, <a class="reference" href="http://www-106.ibm.com/developerworks/library/l-pymeta2.html">metaclasses</a>,
-<a class="reference" href="http://www.python.org/2.3/descrintro.html">cooperative methods</a>, etc.)</li>
-</ul>
-<div class="section" id="basics">
-<h2><a class="toc-backref" href="#id5" name="basics">Basics</a></h2>
-<p>PEP 318 has the goal of providing a nice syntactic sugar for expressions like</p>
-<blockquote>
-<pre class="literal-block">
-def identity(x):
- return x
-identity=staticmethod(identity)
-</pre>
-</blockquote>
-<p>or</p>
-<blockquote>
-<pre class="literal-block">
-def name(cls):
- return cls.__name__
-name=classmethod(name)
-</pre>
-</blockquote>
-<p>which are pretty verbose. It is clear that having new syntax (as
-for instance the proposed square bracket notation)</p>
-<blockquote>
-<pre class="literal-block">
-def identity(x)[staticmethod]:
- return x
-
-def name(cls)[classmethod]:
- return cls.__name__
-</pre>
-</blockquote>
-<p>involves changing the grammar and modifying the interpreter at the
-C level. This means a lot of work. Fortunately, it is possible to
-have the same effect without changing the Python grammar.
-The idea is to use magic docstrings like this:</p>
-<blockquote>
-<pre class="literal-block">
-def identity(x):
- &quot;[staticmethod]&quot;
- return x
-
-def name(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-</pre>
-</blockquote>
-<p>The implementation is able to recognize such magic docstrings
-and automatically converts methods with magic docstrings in
-method decorators.</p>
-<p>Decorators are nothing else than a sophisticated kind of wrappers.
-The <tt class="literal"><span class="pre">decorators</span></tt> module provides support both for method decorators
-and class decorators:</p>
-<ul class="simple">
-<li><em>Method decorators</em> are classes taking a single function as input and
-producing a descriptor object as output. <tt class="literal"><span class="pre">staticmethod</span></tt> and
-<tt class="literal"><span class="pre">classmethod</span></tt> are two examples of already existing
-method decorators (actually my implementation rewrites them).
-A knowledge of descriptors <a class="footnote-reference" href="#id2" id="id1" name="id1">[1]</a> is not needed in order to use the <tt class="literal"><span class="pre">decorator</span></tt>
-module; however it is welcomed for advanced users wanting to implement
-custom method decorators.</li>
-<li><em>Class decorators</em> are metaclasses taking a class as imput and returning
-a decorated class as output. A good understanding of metaclasses is needed
-in order to be able to write custom class decorators, but no knowledge
-at all is required in order to use the pre-defined class decorators
-provided by the module.</li>
-</ul>
-<p>Notice that properties are not decorators according to my definitions,
-since they take four functions as input, <tt class="literal"><span class="pre">get,</span> <span class="pre">set,</span> <span class="pre">del_</span></tt> and <tt class="literal"><span class="pre">doc</span></tt>.
-Whereas the decorators concept could be generalized to the case of
-multiple inputs, I don't see the need for such complication, so
-properties are not implemented as method decorators. Moreover, I
-think it is much better to use them trough a class decorator.</p>
-<p>Finally, the module is meant to be extensible; so one could
-define new kind of decorators. For instance, the original version of
-the module also had the concept of module decorators; however I have cut
-down that part in order to keep the documentation short.</p>
-<p>Admittedly, the implementation
-is not for the faint of heart, nevertheless I have tried to make the
-basic usage easy and simple to understand.</p>
-<table class="footnote" frame="void" id="id2" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1" name="id2">[1]</a></td><td>Descriptors are objects with a <tt class="literal"><span class="pre">__get__</span></tt> method; they are quite
-sophisticated, but fortunately they have been wonderfully explained by
-Raymond Hettinger already, so I am allowed to skip on this point ;).</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="decorating-methods">
-<h2><a class="toc-backref" href="#id6" name="decorating-methods">Decorating methods</a></h2>
-<p>Before talking about the implementation details, I will show
-how the <tt class="literal"><span class="pre">decorators</span></tt> module works in practice. The simplest and safest
-usage is by means of the <tt class="literal"><span class="pre">decorators.decorated()</span></tt> function, which
-takes an object (a function or a class) and checks its docstring: if
-a magic docstring is found, it returns a decorated version of the object,
-otherwise it returns the original object. Using <tt class="literal"><span class="pre">decorators.decorated()</span></tt>
-is simple but verbose, so magic shortcuts will be discussed in the next
-sections.</p>
-<p>Here, let me give an example, showing that method decorators work both for
-<a class="reference" href="http://www.python.org/2.3/descrintro.html">new style classes and old style classes</a>:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example1.py&gt;
-
-import decorators
-
-def do_nothing(self):
- &quot;No magic docstring here&quot;
-dec_do_nothing=decorators.decorated(do_nothing)
-
-def identity(x):
- &quot;[staticmethod]&quot;
- return x
-dec_identity=decorators.decorated(identity)
-
-def name(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-dec_name=decorators.decorated(name)
-
-class OldStyle:
- do_nothing=dec_do_nothing
- identity=dec_identity
-
-class NewStyle(object):
- name=dec_name
-
-o=OldStyle() # creates an old style instance
-n=NewStyle() # creates a new style instance
-
-#&lt;/example1.py&gt;
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example1 import * # for testing purposes
-</pre>
-<p>In this example, both <tt class="literal"><span class="pre">dec_identity</span></tt> and <tt class="literal"><span class="pre">dec_name</span></tt> are decorator objects,
-i.e. descriptors modifiying the attribute access. It is easy to recognize
-decorators objects in the interpreter, since they have a re-defined
-printing representation:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print dec_identity
-&lt;staticmethod:identity&gt;
-&gt;&gt;&gt; print dec_name
-&lt;classmethod:name&gt;
-</pre>
-<p>On the other hand, <tt class="literal"><span class="pre">do_nothing</span></tt> does not have a magic
-docstring, therefore it is not converted to a decorator object;
-actually it is <em>exactly</em> the original function</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; dec_do_nothing is do_nothing # not converted
-True
-</pre>
-<p>and it works as a standard method:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; o.do_nothing() # does nothing, correct
-</pre>
-<p>On the contrary, <tt class="literal"><span class="pre">dec_</span> <span class="pre">identity</span></tt> works as a staticmethod,</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; OldStyle.identity(1) # called from the class
-1
-&gt;&gt;&gt; o.identity(1) # called from the instance
-1
-</pre>
-<p>whereas <tt class="literal"><span class="pre">dec_name</span></tt> works as a classmethod:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; NewStyle.name() # called from the class
-'NewStyle'
-&gt;&gt;&gt; n.name() # called from the instance
-'NewStyle'
-</pre>
-<p>Notice that, I have re-implemented the built-in
-<tt class="literal"><span class="pre">staticmethod</span></tt> and <tt class="literal"><span class="pre">classmethod</span></tt>, so</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; isinstance(dec_identity,staticmethod)
-False
-</pre>
-<p>and</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; isinstance(dec_name,classmethod)
-False
-</pre>
-<p>It is possible to recognize method decorators since they provides
-a couple of special attributes:</p>
-<ul>
-<li><p class="first"><tt class="literal"><span class="pre">__func__</span></tt>: returning the function from which they originated:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; assert dec_identity.__func__ is identity
-&gt;&gt;&gt; assert dec_name.__func__ is name
-</pre>
-</li>
-<li><p class="first"><tt class="literal"><span class="pre">__klass__</span></tt>: returning the class where they where defined:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; dec_identity.__klass__
-&lt;class 'safetype.?'&gt;
-</pre>
-</li>
-</ul>
-<p>The question mark here means that the definition class is unknown.
-The <tt class="literal"><span class="pre">__klass__</span></tt> attribute can be set by hand or automatically
-with the trick explained in the next section.</p>
-</div>
-<div class="section" id="decorating-classes">
-<h2><a class="toc-backref" href="#id7" name="decorating-classes">Decorating classes</a></h2>
-<p>The problem with the approach just described
-is that it does not present any significant advantage over
-the already existing mechanism. A real step forward would be to
-have classes with the ability of automatically decorating their
-methods according to the docstrings.
-This sounds a bit of magic, but actually can be done very simply
-by adding to the class a docstring starting with &quot;[Decorated]&quot;
-and by decorating the class.
-Here is an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example2.py&gt;
-
-from decorators import decorated
-from example1 import do_nothing,identity,name
-
-class B(object):
- &quot;This is a regular class&quot;
-
-B=decorated(B) # does nothing
-
-class C(B):
- &quot;[Decorated]&quot;
- do_nothing=do_nothing
- identity=identity
- class Inner: # old style class
- &quot;[Decorated]&quot; # required docstring
- name=name
-
-C=decorated(C) # regenerates the class converting methods in decorators
-c=C()
-
-#&lt;/example2.py&gt;
-</pre>
-</blockquote>
-<p>Under the hood <tt class="literal"><span class="pre">decorators.decorated()</span></tt> recognizes the class level
-magic docstring &quot;[Decorated]&quot; and creates an instance of the
-<tt class="literal"><span class="pre">decorators.Decorated</span></tt> metaclass.
-Internally the metaclass invokes <tt class="literal"><span class="pre">decorators.decorated()</span></tt>
-on the methods of its instances: this is why they becomes decorated
-if a suitable docstring is found. Moreover, it decorates inner classes,
-if a suitable docstring is found, and it works recursively.</p>
-<p>Here is the testing:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example2 import *
-&gt;&gt;&gt; assert C.identity(1) == 1
-&gt;&gt;&gt; assert C.Inner.name() == 'Inner'
-&gt;&gt;&gt; assert c.identity(1) == 1
-&gt;&gt;&gt; assert c.Inner.name() == 'Inner'
-</pre>
-<p>Notice that adding <tt class="literal"><span class="pre">identity</span></tt> after the class creation with the syntax
-<tt class="literal"><span class="pre">C.identity=identity</span></tt> would not work;
-<tt class="literal"><span class="pre">C.identity=decorators.decorated(identity)</span></tt> is required:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.identity=decorators.decorated(identity)
-&gt;&gt;&gt; C.identity(1) # it works
-1
-</pre>
-<p>If a class misses the magic docstring, nothing happens:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; B # returns the original B
-&lt;class 'example2.B'&gt;
-</pre>
-<p>The mechanism works for old style classes too,
-since the metaclass automagically converts the old style classes in a
-new style one:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(C.Inner) # C.Inner is an instance of decorator.Decorated
-&lt;class 'decorators.Decorated'&gt;
-</pre>
-<p>The enhancement provided by the metaclass includes a new default
-printing representation for both the class</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print C # returns the name of D and of its metaclass
-&lt;class C[Decorated]&gt;
-</pre>
-<p>and its instances:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print c
-&lt;C instance&gt;
-</pre>
-<p>On the other hand, if a custom printing representation is already
-defined, the metaclass takes it without any change.</p>
-<p>One can even forget the docstring in subclasses of decorated
-classes, since metaclasses are inherited:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(C):
-... def name(cls):
-... &quot;[classmethod]&quot;
-... return cls.__name__
-&gt;&gt;&gt; print D.name()
-D
-</pre>
-<p>Decorating whole classes presents another advantage: the decorated methods know
-the class where they were defined via the special attribute <tt class="literal"><span class="pre">__klass__</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; D.__dict__['name'].__klass__ # the class where 'name' is defined
-&lt;class 'D'&gt;
-</pre>
-<p>This is useful for introspection and debugging purposes.</p>
-</div>
-<div class="section" id="adding-magic">
-<h2><a class="toc-backref" href="#id8" name="adding-magic">Adding magic</a></h2>
-<p>The problem of the previous approach is that one must explicitely
-decorate the classes by hand, by invoking <tt class="literal"><span class="pre">decorators.decorated()</span></tt>
-each time. However, it is possible to add more magic
-and to decorate all the classes automatically.
-It is as easy as writing <tt class="literal"><span class="pre">decorators.enhance_classes()</span></tt>
-on top of you module. Then all methods in all classes with a magic docstring
-will be checked for magic docstrings and automagically decorated if needed.
-For instance, the previous example would be written</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example3.py&gt;
-
-import decorators; decorators.enhance_classes()
-
-class C:
- &quot;[Decorated]&quot; # magic docstring here
- def do_nothing(self):
- &quot;No magic docstring here&quot;
-
- def identity(x):
- &quot;[staticmethod]&quot;
- return x
-
-class D(object):
- &quot;Undecorated&quot; # no magic docstring here
- def name(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-
-c=C(); d=D()
-
-#&lt;/example3.py&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">C</span></tt> has a <tt class="literal"><span class="pre">[Decorated]</span></tt> docstring, so its methods
-are automatically decorated:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example3 import *
-&gt;&gt;&gt; assert c.do_nothing() is None
-&gt;&gt;&gt; assert C.identity(1) == 1
-&gt;&gt;&gt; assert c.identity(1) == 1
-</pre>
-<p>On the other hand, since <tt class="literal"><span class="pre">D</span></tt> misses a magic docstring,
-its <tt class="literal"><span class="pre">name</span></tt> method is not decorated:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; hasattr(D.__dict__['name'],'__func__') # not a decorator
-False
-</pre>
-<p>Since <tt class="literal"><span class="pre">D.name</span></tt> is a regular method and not a classmethod, <tt class="literal"><span class="pre">D.name()</span></tt>
-gives an error:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; D.name()
-Traceback (most recent call last):
- ...
-TypeError: unbound method name() must be called with D instance as first argument (got nothing instead)
-</pre>
-<p>Under the hood, the magic works by enhancing the <tt class="literal"><span class="pre">object</span></tt> class
-of the module with a <tt class="literal"><span class="pre">decorators.ClassDecorator</span></tt> metaclass:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import example4
-&gt;&gt;&gt; type(example4.object)
-&lt;class 'decorators.ClassDecorator'&gt;
-</pre>
-<p>Notice that for safety reasons the enhancement is only on the module
-<tt class="literal"><span class="pre">object</span></tt> class, not on the <tt class="literal"><span class="pre">__builtin__.object</span></tt> class. The dangers of
-adding too much magic are discussed in the <a class="reference" href="#diving-into-magic">Diving into magic</a> section.</p>
-</div>
-<div class="section" id="defining-method-decorators">
-<h2><a class="toc-backref" href="#id9" name="defining-method-decorators">Defining method decorators</a></h2>
-<p>The <tt class="literal"><span class="pre">decorators</span></tt> module contains two predefinite method decorators,
-<tt class="literal"><span class="pre">staticmethod</span></tt> and <tt class="literal"><span class="pre">classmethod</span></tt>, which emulate the built-ins
-with the same names. However, it is possible to write your own
-custom decorators. The <tt class="literal"><span class="pre">decorators.MethodDecorator</span></tt> class which is here
-exactly for that purpose.</p>
-<p>Custom decorators are expected to be implemented by subclassing
-<tt class="literal"><span class="pre">MethodDecorator</span></tt> and by overriding its <tt class="literal"><span class="pre">get</span></tt> method. The
-<tt class="literal"><span class="pre">get</span></tt> method automagically induces a <tt class="literal"><span class="pre">__get__</span></tt> method, turning the
-class in a descriptor. The machinery is needed since <tt class="literal"><span class="pre">__get__</span></tt> cannot
-be made cooperative using the standard <tt class="literal"><span class="pre">super</span></tt> mechanism because
-there would be a confusion between <tt class="literal"><span class="pre">super.__get__</span></tt> and the decorator
-<tt class="literal"><span class="pre">__get__</span></tt>. This is a bit tricky, but the causal programmer is not
-expected to write custom decorators, and actually I don't want to make
-the access to decorators <em>too</em> easy, since they are potentially dangerous.</p>
-<p>In order to give a simple example, let me show the implementation
-of a <tt class="literal"><span class="pre">chattymethod</span></tt> that prints a message when it is called:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-from decorators import *
-
-class chattymethod(MethodDecorator):
- logfile=sys.stdout # default
- def get(self,obj,cls=None): # same signature as __get__
- self.logfile.write('calling %s from %s\n' % (self,obj or cls))
- return super(chattymethod,self).get(obj,cls)
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p>Notice the usage of the <tt class="literal"><span class="pre">super().get</span></tt> trick. This guarantees that
-<tt class="literal"><span class="pre">chattymethod</span></tt> will play well with other decorators (i.e. it
-can be nicely composed via multiple inheritance). The point will
-be fully discussed in the section on composing decorators.</p>
-<p>Here is an example of usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import customdec # adds chattymethod to the list of known decorators
-&gt;&gt;&gt; customdec.enhance_classes() # automagically enhances classes
-&gt;&gt;&gt; class C:
-... &quot; [Decorated] &quot;
-... def f(self):
-... &quot;&quot;&quot;
-... [ chattymethod ]
-... &quot;&quot;&quot;
-&gt;&gt;&gt; c=C()
-&gt;&gt;&gt; c.f()
-calling &lt;chattymethod:f&gt; from &lt;C instance&gt;
-</pre>
-<p>By the way, this shows that one can safely add whitespaces (including
-newlines) to the magic docstring: they are simply ignored.</p>
-<p>One can check that the syntax <tt class="literal"><span class="pre">C.f(c)</span></tt> works too:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.f(c)
-calling &lt;chattymethod:f&gt; from &lt;class C[Decorated]&gt;
-</pre>
-<p>A tricky point of the decorators mechanism is the issue of parameter passing.
-In comp.lang.python there was the proposal of allowing explicit parameter
-passing to decorators, with a syntax of kind</p>
-<blockquote>
-<pre class="literal-block">
-def f(self)[chattymethod(logfile=file('file1.log','w'))]
-</pre>
-</blockquote>
-<p>In my view, there are too many parenthesis in this syntax, and it
-becomes rapidly unreadable. Moreover, it complicates the implementation
-without any real benefit, so the <tt class="literal"><span class="pre">decorators</span></tt> module does not allow
-this kind of parameter passings. There are however viable
-workarounds, so you should not miss the syntax.</p>
-<p>A simple minded solution is to change the defaults by hand:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from customdec import chattymethod,decorated
-&gt;&gt;&gt; chattymethod.logfile=file('file.log','w')
-&gt;&gt;&gt; def g(self):
-... &quot;[chattymethod]&quot;
-&gt;&gt;&gt; C.g=decorated(g)
-&gt;&gt;&gt; c.g() # will print a message on file.log
-</pre>
-<p>This approach has the drawback that chattymethods created before changing
-the logfile will also print to the new logfile, if invoked after the
-change. Therefore</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.f()
-</pre>
-<p>will print a message to <tt class="literal"><span class="pre">file.log</span></tt> too, and not to standard output.
-Here is the confirmation:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; chattymethod.logfile.close()
-&gt;&gt;&gt; print file('file.log').read().rstrip()
-calling &lt;chattymethod:g&gt; from &lt;C instance&gt;
-calling &lt;chattymethod:f&gt; from &lt;C instance&gt;
-</pre>
-<p>A better solution is to pass
-parameters to method decorators as function attributes: then the function
-attributes can be converted to attributes of the decorator
-in the <tt class="literal"><span class="pre">__init__</span></tt> method. Here is an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-class chattymethod2(chattymethod):
- logfile=sys.stdout # default
- def __init__(self,objfunc):
- super(chattymethod2,self).__init__(objfunc)
- logfile=getattr(self.__func__,'logfile',None)
- if logfile: self.logfile=logfile
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p>Notice that the <tt class="literal"><span class="pre">__init__</span></tt> method has the signature
-<tt class="literal"><span class="pre">__init__(self,objfunc)</span></tt>, where the <tt class="literal"><span class="pre">objfunc</span></tt> object is a
-decorator object or the function to be converted in the decorator
-object, and that it is cooperative.
-This is the suggested way of overriding <tt class="literal"><span class="pre">__init__</span></tt>.</p>
-<p>Here is the testing:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;chatty2.py&gt;
-
-import customdec; customdec.enhance_classes()
-
-# sets the log files
-log1=file('file1.log','w')
-log2=file('file2.log','w')
-
-class C:
- &quot;[Decorated]&quot;
- def f(self):
- &quot;[chattymethod2]&quot;
- f.logfile=log1 # function attribute
- def g(self):
- &quot;[chattymethod2]&quot;
- g.logfile=log2 # function attribute
-
-assert C.__dict__['f'].logfile is log1 # check the conversion
-assert C.__dict__['g'].logfile is log2 # function attr. -&gt; decorator attr.
-
-c=C() # C instantiation
-
-c.f() # print a message in file1.log
-c.g() # print a message in file2.log
-
-log1.close(); log2.close() # finally
-
-#&lt;/chatty2.py&gt;
-</pre>
-</blockquote>
-<p>Let me check the contents of the log files:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import chatty2
-&gt;&gt;&gt; print file('file1.log').read().rstrip()
-calling &lt;chattymethod2:f&gt; from &lt;C instance&gt;
-&gt;&gt;&gt; print file('file2.log').read().rstrip()
-calling &lt;chattymethod2:g&gt; from &lt;C instance&gt;
-</pre>
-<p><tt class="literal"><span class="pre">chattymethod</span></tt> is the poor man version of <tt class="literal"><span class="pre">tracedmethod</span></tt>, a
-sophisticated decorator for tracing methods.
-Here is the code, given for pedagogical purposes; the lazy reader can
-skip it and go directly to the usage section.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-class tracedmethod(MethodDecorator):
- &quot;Descriptor class, converts a method in a traced method&quot;
- indent=0; output=sys.stdout # defaults
-
- def __init__(self,objfunc):
- super(tracedmethod,self).__init__(objfunc)
- self.funcname=self.__func__.__name__
- output=getattr(self.__func__,'output',None)
- if output: self.output=output # func.attr. -&gt; dec.attr.
-
- def get(self,obj,cls):
- clsname=self.__klass__.__name__ # definition clas
- def tracedmeth(obj,*args,**kw):
- i=' '*self.indent # default indentation
- self.__class__.indent+=4 # increases indentation
- self.output.write(&quot;%sCalling '%s.%s' with arguments &quot; %
- (i,clsname,self.funcname))
- self.output.write(&quot;%s%s ...\n&quot; % (obj or '',str(args)+str(kw)))
- res=super(tracedmethod,self).get(obj,cls)(*args,**kw)
- self.output.write(&quot;%s'%s.%s' called with result: %s\n&quot;
- % (i,clsname,self.funcname,res))
- self.__class__.indent-=4 # restores default indentation
- return res
- return tracedmeth.__get__(obj,cls) # method wrapper
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">tracedmethod.get</span></tt> returns a method wrapper object, so it is
-possible to use <tt class="literal"><span class="pre">im_func</span></tt> to retrieve the internal function
-<tt class="literal"><span class="pre">tracedmeth</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C:
-... &quot;[Decorated]&quot;
-... def f(self):
-... &quot;[tracedmethod]&quot;
-&gt;&gt;&gt; c=C(); c.f()
-Calling 'C.f' with arguments &lt;C instance&gt;(){} ...
-'C.f' called with result: None
-&gt;&gt;&gt; c.f.im_func.__name__
-'tracedmeth'
-</pre>
-<p>As soon as the <tt class="literal"><span class="pre">tracedmethod</span></tt> module is loaded, the <tt class="literal"><span class="pre">tracedmethod</span></tt> class
-is added to the list of know decorators, so one should use the
-&quot;[tracedmethod]&quot; docstring and not something like
-&quot;[customdec.tracedmethod]&quot;.</p>
-<p>Here is a less trivial example of usage, writing in a log file the
-internal working of a recursive function:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example9.py&gt;
-
-import customdec; customdec.enhance_classes()
-
-logfile=file('file3.log','w')
-
-class C(object):
- &quot;[Decorated]&quot;
- def fact(self,n):
- &quot;[tracedmethod] The good old factorial.&quot;
- if n==0: return 1
- else: return n*self.fact(n-1)
- fact.output=logfile
-
-C().fact(2) # write a message to logfile
-
-logfile.close()
-
-#&lt;/example9.py&gt;
-</pre>
-</blockquote>
-<p>Here is the content of <tt class="literal"><span class="pre">file3.log</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import example9 # creates file3.log
-&gt;&gt;&gt; print file('file3.log').read().rstrip()
-Calling 'C.fact' with arguments &lt;C instance&gt;(2,){} ...
- Calling 'C.fact' with arguments &lt;C instance&gt;(1,){} ...
- Calling 'C.fact' with arguments &lt;C instance&gt;(0,){} ...
- 'C.fact' called with result: 1
- 'C.fact' called with result: 1
-'C.fact' called with result: 2
-</pre>
-</div>
-<div class="section" id="defining-class-decorators">
-<h2><a class="toc-backref" href="#id10" name="defining-class-decorators">Defining class decorators</a></h2>
-<p>PEP 318 proposes to decorate methods by using descriptors; it is
-quite natural to extend this idea and to decorate classes by using
-class decorators implemented as metaclasses. We already saw a couple of
-class decorator at work, the metaclass <tt class="literal"><span class="pre">ClassDecorator</span></tt>, which gives
-to its instances the ability to interpret class level magic docstrings, and
-its subclass <tt class="literal"><span class="pre">Decorated</span></tt>, which converts functions in method decorators
-if suitable docstrings are found.</p>
-<p>To define a custom class decorator is easy: one defines a custom metaclass
-as usual, with the only difference of deriving from <tt class="literal"><span class="pre">ClassDecorator</span></tt> instead
-of deriving from <tt class="literal"><span class="pre">type</span></tt>.</p>
-<p>To understand how this works in practice, let me
-show how to add logging capabilities to a given class. The first
-step is to define a suitable class decorator, such as the following:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-class Logged(ClassDecorator):
- output=sys.stdout
- def __init__(cls,name,bases,dic):
- super(Logged,cls).__init__(name,bases,dic)
- print &gt;&gt; cls.output,&quot;%s created&quot; % cls
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">Logged</span></tt> is derived by the metaclass <tt class="literal"><span class="pre">ClassDecorator</span></tt>,
-which provides a certain amount of magic under the hood (in particular
-its printing representation and its calling syntax are redefined by its
-(meta-)metaclass <tt class="literal"><span class="pre">MetaDecorator</span></tt>).
-Logging capabilities can be added to a class
-by simply using the magic docstring syntax:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;logged.py&gt;
-
-import customdec; customdec.enhance_classes()
-
-class D(object): # will print a message at D creation
- &quot;[Logged]&quot;
-
-#&lt;/logged.py&gt;
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import logged
-&lt;class 'logged.D'&gt; created
-</pre>
-<p>Notice that the printing representation of <tt class="literal"><span class="pre">D</span></tt> involves the name
-of <tt class="literal"><span class="pre">D</span></tt> preceded by the name of its metaclass, which in this case
-is <tt class="literal"><span class="pre">Logged</span></tt></p>
-<p>Each time an instance of <tt class="literal"><span class="pre">Logged</span></tt> is created, a similar message is printed:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class E(logged.D):
-... pass
-&lt;class 'E'&gt; created
-</pre>
-<p>Notice that <tt class="literal"><span class="pre">E</span></tt> does not have any magic docstring</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; E.__doc__ # no docstring
-</pre>
-<p>but still it inherits its magic from <tt class="literal"><span class="pre">D</span></tt>.</p>
-<p>Another simple example of class decorator is the following metaclass
-which modifies the docstrings of the methods of its instances,
-by magically inducing tracing capabilities on them:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-from types import FunctionType
-
-class Traced(Decorated):
- def __init__(cls,n,b,d):
- for name,func in d.iteritems():
- if isinstance(func,FunctionType) and name!='__str__':
- # cannot trace __str__, since it is invoked by
- # tracedmethod and would generate infinite recursion
- func.__doc__=&quot;[tracedmethod] &quot; + (func.__doc__ or '')
- super(Traced,cls).__init__(n,b,d) # decorates the methods
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p>Here is an example of usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... &quot;&quot;&quot;[Traced] The class decorator adds the magic docstring
-... '[tracedmethod]' to f1 and f2, which are then converted
-... in method decorator objects.&quot;&quot;&quot;
-... def f1(self): pass
-... def f2(self): pass
-...
-&gt;&gt;&gt; type(C)
-&lt;class 'customdec.Traced'&gt;
-&gt;&gt;&gt; c=C()
-&gt;&gt;&gt; c.f1()
-Calling 'C.f1' with arguments &lt;C instance&gt;(){} ...
-'C.f1' called with result: None
-&gt;&gt;&gt; c.f2()
-Calling 'C.f2' with arguments &lt;C instance&gt;(){} ...
-'C.f2' called with result: None
-</pre>
-<p>By default, the decorators module only decorates classes with a magic
-docstring (and they subclasses, even without magic docstrings).
-If all the classes of your module have the same magic docstring,
-it makes sense to decorate them all
-with a single command. It is enough to use <tt class="literal"><span class="pre">decorators.enhance_classes()</span></tt>
-with a magic docstring corresponding to a class decorator as argument,
-as in this example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example7.py&gt;
-
-from example2 import identity,name
-import inspect, decorators; decorators.enhance_classes(&quot;[Decorated]&quot;)
-
-class C1(object): # automagically converted to a decorated class
- identity=identity
-
-class C2: # automagically converted to a decorated class
- name=name
-
-c1=C1() # C1 instance
-c2=C2() # C2 instance
-
-#&lt;/example7.py&gt;
-</pre>
-</blockquote>
-<p>The magic works both for new style classes such as <tt class="literal"><span class="pre">C1</span></tt></p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example7 import C1,c1
-&gt;&gt;&gt; assert C1.identity(1) == 1
-&gt;&gt;&gt; assert c1.identity(1) == 1
-</pre>
-<p>and old style classes such as <tt class="literal"><span class="pre">C2</span></tt> by implicitly converting them
-to new style classes:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example7 import C2,c2
-&gt;&gt;&gt; assert C2.name() == 'C2'
-&gt;&gt;&gt; assert c2.name() == 'C2'
-</pre>
-</div>
-<div class="section" id="composing-decorators">
-<h2><a class="toc-backref" href="#id11" name="composing-decorators">Composing decorators</a></h2>
-<p>Decorators can be composed by using magic docstrings with comma-separated
-decorator names. For instance, you can trace a classmethod:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example6.py&gt;
-
-&quot;How to trace a class method&quot;
-
-import customdec; customdec.enhance_classes()
-
-class C(object):
- &quot;[Decorated]&quot;
- def fact(cls,n): # a traced classmethod
- &quot;[classmethod,tracedmethod]&quot;
- if n==0: return 1
- else: return n*cls.fact(n-1)
-
-#&lt;/example6.py&gt;
-</pre>
-</blockquote>
-<p>Here is the testing:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example6 import C
-&gt;&gt;&gt; C.fact(2)
-Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(2,){} ...
- Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(1,){} ...
- Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(0,){} ...
- 'C.fact' called with result: 1
- 'C.fact' called with result: 1
-'C.fact' called with result: 2
-2
-</pre>
-<p>You may easily check that calling <tt class="literal"><span class="pre">C().fact</span></tt> will work too.</p>
-<p>Under the hood the syntax</p>
-<blockquote>
-<pre class="literal-block">
-[classmethod,tracedmethod]
-</pre>
-</blockquote>
-<p>generates a <tt class="literal"><span class="pre">classmethodtracedmethod</span></tt> class obtained via
-multiple inheritance:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(C.__dict__['fact'])
-&lt;class 'safetype.classmethodtracedmethod'&gt;
-</pre>
-<p>Notice that the order <em>does</em> matter and using the docstring
-&quot;[tracedmethod,classmethod]&quot; will not work:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D:
-... &quot;[Decorated]&quot;
-... def f(cls):
-... &quot;[tracedmethod,classmethod]&quot;
-&gt;&gt;&gt; D.f()
-Traceback (most recent call last):
- ...
-TypeError: unbound method tracedmeth() must be called with D instance as first argument (got nothing instead)
-</pre>
-<p>The problem here is that <tt class="literal"><span class="pre">tracedmethod.get</span></tt> returns a method-wrapper object
-which expects a D instance as first argument whereas it gets <tt class="literal"><span class="pre">None</span></tt> since
-it is called from the class. On the other hand,</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; D().f()
-Calling 'D.f' with arguments &lt;D instance&gt;(){} ...
-'D.f' called with result: None
-</pre>
-<p>will work. When <tt class="literal"><span class="pre">classmethod</span></tt> precedes <tt class="literal"><span class="pre">tracedmethod</span></tt>, then
-<tt class="literal"><span class="pre">classmethod</span></tt> passes to <tt class="literal"><span class="pre">tracedmeth</span></tt> a non-empty first argument,
-i.e. the calling class, even when called from the instance:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C().fact(2)
-Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(2,){} ...
- Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(1,){} ...
- Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(0,){} ...
- 'C.fact' called with result: 1
- 'C.fact' called with result: 1
-'C.fact' called with result: 2
-2
-</pre>
-<p>If we try to trace a staticmethod, we will get a different error with
-the order &quot;tracedmethod, staticmethod&quot;:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class F(object):
-... &quot;[Decorated]&quot;
-... def fact(n):
-... &quot;[tracedmethod,staticmethod]&quot;
-... if n==0: return 1
-... else: return n*F.fact(n-1)
-&gt;&gt;&gt; F.fact(2)
-Traceback (most recent call last):
- ...
-TypeError: unbound method tracedmeth() must be called with F instance as first argument (got int instance instead)
-</pre>
-<p>The message is self-explanatory.</p>
-<p>On the other hand, composing the decorators in the order
-&quot;[tracedmethod,staticmethod]&quot; will work just fine.</p>
-<p>It is possible to compose class decorators just as method decorators,
-by using the docstring syntax: for instance we may create a class
-which is both <tt class="literal"><span class="pre">Decorated</span></tt> and <tt class="literal"><span class="pre">Logged</span></tt> and by trivially writing</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C:
-... &quot;[Decorated,Logged]&quot;
-... def f():
-... &quot;[staticmethod]&quot;
-... return 'it works!'
-&lt;class C[DecoratedLogged]&gt; created
-&gt;&gt;&gt; C().f()
-'it works!'
-</pre>
-</div>
-<div class="section" id="diving-into-magic">
-<h2><a class="toc-backref" href="#id12" name="diving-into-magic">Diving into magic</a></h2>
-<p>If you never use metaclasses, this part can be safely skipped. On the
-other hand, if you are a metaclass user, you <em>must</em> read this section
-in order to keep your code working.</p>
-<p>The <tt class="literal"><span class="pre">decorators</span></tt> module provide a <tt class="literal"><span class="pre">ClassDecorator</span></tt> metaclass which
-converts a regular (both old style or new style) class in a class with
-the ability to recognize magic docstrings. Under the hood, the
-<tt class="literal"><span class="pre">decorators.enhance_classes()</span></tt> trick works by decorating the
-<tt class="literal"><span class="pre">object</span></tt> class with <tt class="literal"><span class="pre">decorators.ClassDecorator</span></tt> and by setting
-the custom metaclass to <tt class="literal"><span class="pre">decorators.ClassDecorator</span></tt> and it is
-equivalent to</p>
-<blockquote>
-<pre class="literal-block">
-import decorators
-object=decorators.ClassDecorator(object) # decorates new style classes
-__metaclass__= decorators.ClassDecorator # decorates old style classes
-</pre>
-</blockquote>
-<p>If you want the magic to work only for new style classes only, you may
-forget the second line; if you want the magic to work for old style
-classes only, you may forget the first line.</p>
-<p>The <tt class="literal"><span class="pre">decorators.enhance_classes(&quot;[SomeClassDec]&quot;)</span></tt> syntax looks at the
-magic docstring and executes something like</p>
-<blockquote>
-<pre class="literal-block">
-import decorators
-object=decorators.SomeClassDec(object) # decorates all new style classes
-__metaclass__= decorators.SomeClassDec # decorates all old style classes
-</pre>
-</blockquote>
-<p>The problem with the <tt class="literal"><span class="pre">enhance_classes()</span></tt> syntaxes is that it is
-not 100% safe under metaclass conflicts. In order to explain the issue,
-let me give an example.</p>
-<p>Suppose we enhance the <tt class="literal"><span class="pre">object</span></tt> class in the interpreter namespace:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import decorators; decorators.enhance_classes()
-</pre>
-<p>making it an instance of <tt class="literal"><span class="pre">ClassDecorator</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; object.__class__
-&lt;class 'decorators.ClassDecorator'&gt;
-</pre>
-<p>Now, if we naively create a custom metaclass <tt class="literal"><span class="pre">M</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(type):
-... &quot;Some non-trivial code here...&quot;
-</pre>
-<p>and we try to use it to enhance a new style class <tt class="literal"><span class="pre">NwithM</span></tt>, we will get a
-conflict:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class NwithM(object): __metaclass__=M # does not work!
-...
-Traceback (most recent call last):
- ...
-TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-<p>The problem is that the previous line tries to create a class <tt class="literal"><span class="pre">NwithM</span></tt>
-which should have both metaclasses <tt class="literal"><span class="pre">ClassDecorator</span></tt> and <tt class="literal"><span class="pre">M</span></tt>:
-a conflict follows.</p>
-<p>Fortunately, the decorators module imports the <tt class="literal"><span class="pre">type</span></tt> metaclass from
-my <tt class="literal"><span class="pre">safetype</span></tt> module just to avoid this kind of problems. If we
-derive <tt class="literal"><span class="pre">M</span></tt> from <tt class="literal"><span class="pre">decorators.type</span></tt> (which is really <tt class="literal"><span class="pre">safetype.type</span></tt>)
-the conflict is automagically avoided:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(decorators.type):
-... &quot;This metaclass is conflict-proof&quot;
-&gt;&gt;&gt; class NwithM(object): # it works!
-... __metaclass__=M
-</pre>
-<p>The reason why the conflict is avoided is that the <tt class="literal"><span class="pre">safetype</span></tt> module
-(which makes use of really <em>deep</em> metaclass magic) automatically
-creates the composed class <tt class="literal"><span class="pre">MClassDecorator</span></tt> by multiply inheriting
-from <tt class="literal"><span class="pre">M</span></tt> and from <tt class="literal"><span class="pre">ClassDecorator</span></tt>. Then, <tt class="literal"><span class="pre">NwithM</span></tt> can be safely
-created as an instance of <tt class="literal"><span class="pre">safetype.MClassDecorator</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(NwithM)
-&lt;class 'safetype.MClassDecorator'&gt;
-</pre>
-<p>The situation with old style classes is worse since
-apparently</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class OwithM: # old style class with metaclass M
-... __metaclass__=M
-... def sm():
-... &quot;[staticmethod]&quot;
-</pre>
-<p>gives no error, but actually <tt class="literal"><span class="pre">M</span></tt> overrides
-<tt class="literal"><span class="pre">ClassDecorator</span></tt>, so <tt class="literal"><span class="pre">OwithM</span></tt> will not recognize magic docstrings:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(OwithM)
-&lt;class 'M'&gt;
-&gt;&gt;&gt; OwithM.sm()
-Traceback (most recent call last):
- ...
-TypeError: unbound method sm() must be called with OwithM instance as first argument (got nothing instead)
-</pre>
-<p>The simpler solution is to convert <tt class="literal"><span class="pre">OwithM</span></tt> in a new style class:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class NwithM(OwithM,object):
-... __metaclass__=M
-... def sm():
-... &quot;[staticmethod]&quot;
-&gt;&gt;&gt; type(NwithM)
-&lt;class 'safetype.MClassDecorator'&gt;
-</pre>
-<p>Now <tt class="literal"><span class="pre">NwithM</span></tt> is not decorated since it does miss a magic docstring, but
-it provides the ability to recognizing magic docstrings, so <tt class="literal"><span class="pre">NwithM</span></tt>
-subclasses with a &quot;[Decorated]&quot; docstring will be decorated:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class E(NwithM):
-... &quot;[Decorated]&quot;
-... def cm(cls):
-... &quot;[classmethod]&quot;
-... print '.cm() called from',cls
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; E.cm() # it works
-.cm() called from &lt;class E[MClassDecoratorDecorated]&gt;
-</pre>
-<p>Notice that <tt class="literal"><span class="pre">sm</span></tt> was defined in <tt class="literal"><span class="pre">NwithM</span></tt>, the undecorated class: therefore
-it is not decorated:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; E.sm() # correctly, does not work
-Traceback (most recent call last):
- ...
-TypeError: unbound method sm() must be called with E instance as first argument (got nothing instead)
-</pre>
-<p>The error message says that <tt class="literal"><span class="pre">sm</span></tt> is an unbound method and not a
-static method.</p>
-<p>It is possible to go even deeper in <strong>black</strong> magic, and to decorate all
-the new style classes in <em>all</em> modules, by decorating the
-<tt class="literal"><span class="pre">__builtin__.object</span></tt>. Still, naively redefining the <tt class="literal"><span class="pre">__builtin__object</span></tt>
-class is risky, since it will induce metaclass conflicts in other modules
-using metaclasses. In other words, it will work only if you import modules
-not using metaclasses, or modules using metaclasses safely, i.e. modules
-taking care of possible conflicts by using <tt class="literal"><span class="pre">safetype.type</span></tt> as base metaclass.
-If you really enjoy black magic, you may solve the problem by
-redefining the <tt class="literal"><span class="pre">__builtin__.type</span></tt> as <tt class="literal"><span class="pre">safetype.type</span></tt>.
-The <tt class="literal"><span class="pre">decorators</span></tt> module does not go so deep in dark magic, but still
-there are cases where you may want to do it. In these cases you must be
-explicit and redefine the builtins by hand, without help from the
-module. For instance, one of my original motivation for the usage
-of metaclasses/class decorators was to use them for debugging purposes.
-For instance, I wanted to trace the execution of methods in
-complicate inheritance hierarchies, <em>without changing the source code</em>.
-For simple situations, i.e. in absence of inheritance and of pre-existing
-metaclasses, the function <tt class="literal"><span class="pre">import_with_metaclass</span></tt> discussed in the
-<a class="reference" href="http://www-106.ibm.com/developerworks/library/l-pymeta.html">first paper on metaclasses</a> written in collaboration with David Mertz, works
-fine but in general the implementation of a working <tt class="literal"><span class="pre">import_with_metaclass</span></tt>
-is cumbersome. For debugging purposes, the quick and dirty way can be a
-good enough way, so let me show how we can redefine the builtins <tt class="literal"><span class="pre">object</span></tt> and
-<tt class="literal"><span class="pre">type</span></tt> <em>before</em> importing the module, in such a way to enhance <em>all</em>
-its classes with tracing capabilities.</p>
-<p>Let me start from a module using an unsafe metaclass <tt class="literal"><span class="pre">M</span></tt>, such that it
-cannot be traced trivially by decorating its classes <em>after</em> the import;
-moreover there is an inheritance hierarchy, such that it cannot be
-traced correctly by naively decorating all the classes one after the
-other (unless one modifies the original source code, but this forbidden
-by the rules of the game ;)</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;tracing.py&gt;
-
-&quot;&quot;&quot;
-This is a pre-existing module not using decorators but using multiple
-inheritance and unsafe metaclasses. We want to trace it for debugging
-purposes.
-&quot;&quot;&quot;
-
-class M(type):
- &quot;There should be some non-trivial code here&quot;
-
-class B(object):
- def __init__(self):
- super(B,self).__init__()
-
-class D(object):
- __metaclass__=M
- def __init__(self):
- super(D,self).__init__()
-
-class E(B,D):
- def __init__(self):
- super(E,self).__init__()
-
- #&lt;/tracing.py&gt;
-</pre>
-</blockquote>
-<p>Everything works is we modify the builtins before importing the module:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import __builtin__
-&gt;&gt;&gt; __object__=__builtin__.object # the original 'object' class
-&gt;&gt;&gt; __builtin__.object=customdec.Traced('tracedobject',(),{})
-&gt;&gt;&gt; __builtin__.type=customdec.type # a safe 'type' class
-</pre>
-<p>Now, when we import the module, all the classes <tt class="literal"><span class="pre">M</span></tt>, <tt class="literal"><span class="pre">B</span></tt>, <tt class="literal"><span class="pre">D</span></tt> and <tt class="literal"><span class="pre">E</span></tt>
-will be created starting for the tricked builtins, so they will be traced
-and safe under conflicts. For instance, let me show that <tt class="literal"><span class="pre">E</span></tt> is created
-with a conflict safe <tt class="literal"><span class="pre">MTraced</span></tt> metaclass:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from tracing import E
-&gt;&gt;&gt; print E
-&lt;class E[MTraced]&gt;
-</pre>
-<p>This shows that the <tt class="literal"><span class="pre">__init__</span></tt> methods are traced indeed and shows the
-Method Resolution Order:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; e=E()
-Calling 'E.__init__' with arguments &lt;E instance&gt;(){} ...
- Calling 'B.__init__' with arguments &lt;E instance&gt;(){} ...
- Calling 'D.__init__' with arguments &lt;E instance&gt;(){} ...
- 'D.__init__' called with result: None
- 'B.__init__' called with result: None
-'E.__init__' called with result: None
-</pre>
-<p>This works, indeed. At the end, one should not forget to restore
-the standard builtins, otherwise it will trace <em>all</em> the classes
-created thereafter.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; __builtin__.object=__object__ # restore the __builtin__
-&gt;&gt;&gt; __builtin__.type=decorators.__type__ # restore the __builtin__
-</pre>
-<p>At the end, I will notice that it is possible to solve the problem more
-nicely, without redefining the builtins, but I will discuss the solution
-elsewhere ;)</p>
-</div>
-<div class="section" id="advanced-usage">
-<h2><a class="toc-backref" href="#id13" name="advanced-usage">Advanced usage</a></h2>
-<p>Whereas the average programmer is expected to use the <tt class="literal"><span class="pre">decorated()</span></tt>
-and <tt class="literal"><span class="pre">enhance_classes()</span></tt> functions only, the <tt class="literal"><span class="pre">decorators</span></tt> module provides
-facilities which may be useful to the advanced programmer.</p>
-<p>The simplest is an utility function which retrieves the list of
-recognized decorators, <tt class="literal"><span class="pre">decorators.getdec()</span></tt>. The precise syntax is
-<tt class="literal"><span class="pre">decorators.getdec(docstring)</span></tt>, where <tt class="literal"><span class="pre">docstring</span></tt>
-is a magic docstring, i.e. a bracketed comma-separated list
-of decorator names. For instance <tt class="literal"><span class="pre">decorators.getdec('[MethodDecorator]')</span></tt>
-gives the list of all subclasses of <tt class="literal"><span class="pre">MethodDecorator</span></tt>, i.e. all method
-decorators, whereas <tt class="literal"><span class="pre">decorators.getdec('[ClassDecorator]')</span></tt>
-gives the list of the known class decorators. The utility of the function
-is that it also returns decorators that have been automagically created:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; decorators.getdec(&quot;[classmethodtracedmethod]&quot;)
-[&lt;class 'safetype.classmethodtracedmethod'&gt;]
-</pre>
-<p>It is even possible to use the comma notation:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; decorators.getdec(&quot;[classmethod,tracedmethod]&quot;)
-[&lt;class 'safetype.classmethodtracedmethod'&gt;]
-</pre>
-<p>If you mispell a decorator name you get an helpful error message:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class E:
-... &quot;[Decorated]&quot;
-... def f():
-... &quot;[staticmeth]&quot;
-Traceback (most recent call last):
- .. a cryptic traceback here ..
-UnknownDecoratorError: staticmeth
-</pre>
-<p>By design, the <tt class="literal"><span class="pre">decorated</span></tt> function is quite limited, and does not
-decorate functions without magic docstrings. This is safe and also convenient
-for internal usage of the <tt class="literal"><span class="pre">decorated</span></tt> function in the <tt class="literal"><span class="pre">Decorated</span></tt>
-metaclass. Nevertheless, advanced users may want to have the ability
-of decorating functions by hand, without invoking <cite>decorators.decorated()`</cite>
-and magic docstrings. This is possible, by calling the decorator directly.
-For instance, here is how to convert a lambda function in a staticmethod:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; do_nothing=decorators.staticmethod(lambda:None)
-&gt;&gt;&gt; print do_nothing # ``do_nothing`` is a static method
-&lt;staticmethod:&lt;lambda&gt;&gt;
-</pre>
-<p>The most convenient usage of this feature is in the composition of decorators.
-For instance, we may compose the just defined <tt class="literal"><span class="pre">staticmethod</span></tt> with a
-<tt class="literal"><span class="pre">chattymethod2</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; chattystatic=customdec.chattymethod2(do_nothing)
-&gt;&gt;&gt; print chattystatic
-&lt;chattymethod2staticmethod:&lt;lambda&gt;&gt;
-</pre>
-<p>The syntax</p>
-<blockquote>
-<tt class="literal"><span class="pre">decorator1(decorator2(obj))</span></tt></blockquote>
-<p>automagically creates a composed class <tt class="literal"><span class="pre">decorator1decorator2</span></tt> in the
-<tt class="literal"><span class="pre">safetype</span></tt> module (or recycle it, if <tt class="literal"><span class="pre">decorator1decorator2</span></tt> has
-been already created) and it is equivalent to</p>
-<blockquote>
-<tt class="literal"><span class="pre">decorator1decorator2(obj)</span></tt></blockquote>
-<p>Here is the check that everything works:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B:
-... chattystatic=chattystatic
-&gt;&gt;&gt; B.chattystatic()
-calling &lt;chattymethod2staticmethod:&lt;lambda&gt;&gt; from &lt;class 'B'&gt;
-</pre>
-<p>Notice that <tt class="literal"><span class="pre">chattystatic</span></tt> does not know the class where it
-is defined:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; chattystatic.__klass__
-&lt;class 'safetype.?'&gt;
-</pre>
-<p>unless the <tt class="literal"><span class="pre">__klass__</span></tt> attribute is explicitly set.</p>
-<p>This is the hierarchy:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for C in type(chattystatic).mro(): print C
-...
-&lt;class 'safetype.chattymethod2staticmethod'&gt;
-&lt;class 'customdec.chattymethod2'&gt;
-&lt;class 'customdec.chattymethod'&gt;
-&lt;class 'decorators.staticmethod'&gt;
-&lt;class 'decorators.MethodDecorator'&gt;
-&lt;class 'decorators.Decorator'&gt;
-&lt;type 'object'&gt;
-</pre>
-<p>One can also compose classes by hand, by using class decorators:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C:
-... &quot;[Logged]&quot;
-... def f(): &quot;[staticmethod]&quot;
-...
-&lt;class 'C'&gt; created
-&gt;&gt;&gt; C=customdec.Traced(C)
-&lt;class C[TracedLogged]&gt; created
-</pre>
-<p>The <tt class="literal"><span class="pre">decorators.enhance_classes(&lt;classdecorator&gt;)</span></tt> syntax performs
-the composition automagically:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example8.py&gt;
-
-from example2 import identity,name
-import inspect, decorators; decorators.enhance_classes(&quot;[Decorated]&quot;)
-
-class C1: # automagically converted to a Decorated class
- identity=identity
-
-class C2: # automagically converted to a DecoratedLogged class
- &quot;[Logged]&quot;
- name=name
-
-c1=C1() # C1 instance
-c2=C2() # C2 instance
-
-#&lt;/example8.py&gt;
-</pre>
-</blockquote>
-<p>In this example the class <tt class="literal"><span class="pre">C2</span></tt> has already a magic docstring. This means that
-<tt class="literal"><span class="pre">C2</span></tt> has to be enhanced both from <tt class="literal"><span class="pre">Logged</span></tt> and from <tt class="literal"><span class="pre">Decorated</span></tt>.
-This is done by automagically creating a <tt class="literal"><span class="pre">DecoratedLogged</span></tt> class
-decorator:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example8 import C1,C2,c1,c2
-&lt;class C2[DecoratedLogged]&gt; created
-</pre>
-<p>The second line is printed because of the logging capabilities of <tt class="literal"><span class="pre">C2</span></tt>.
-Moreover, since <tt class="literal"><span class="pre">C2</span></tt> is decorated too, the following will work:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; assert C2.name() == 'C2'
-&gt;&gt;&gt; assert c2.name() == 'C2'
-</pre>
-<p>Idem for <tt class="literal"><span class="pre">C1</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; assert C1.identity(1) == 1
-&gt;&gt;&gt; assert c1.identity(1) == 1
-</pre>
-</div>
-</div>
-<div class="section" id="the-implementation">
-<h1><a class="toc-backref" href="#id14" name="the-implementation">The implementation</a></h1>
-<p>This part can be safely skipped, unless you are a <em>really</em> curious and
-you want to know how the implementation works.</p>
-<p>The module is rather short (less than 150 lines if you skip comments and
-docstrings) but far from being trivial, since it is based on extensive
-usage of metaclass wizardry. Moreover,
-it invokes the <tt class="literal"><span class="pre">safetype</span></tt> module to solve metaclass conflicts, and
-<tt class="literal"><span class="pre">safetype</span></tt> contains 50 lines of <em>really</em> deep metaclass wizardry.</p>
-<blockquote>
-<div class="figure">
-<p><img alt="decorators.png" src="decorators.png" /></p>
-</div>
-</blockquote>
-<p>The main class-metaclass hierarchy is represented in the figure, where
-boxes denote classes and ovals denote metaclasses; instantiation is
-denoted by dashed green lines whereas inheritance is denoted by continuous
-blue lines.</p>
-<p>For instance, this is the Method Resolution Order for the <tt class="literal"><span class="pre">Decorated</span></tt>
-metaclass:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for i,c in enumerate(decorators.Decorated.__mro__):
-... print i,c,&quot;[%s]&quot; % type(c).__name__
-0 &lt;class 'decorators.Decorated'&gt; [MetaDecorator]
-1 &lt;class 'decorators.ClassDecorator'&gt; [MetaDecorator]
-2 &lt;class 'safetype.safetype'&gt; [type]
-3 &lt;type 'type'&gt; [type]
-4 &lt;class 'decorators.Decorator'&gt; [MetaDecorator]
-5 &lt;type 'object'&gt; [type]
-</pre>
-<p><tt class="literal"><span class="pre">Decorator</span></tt> is the mother of all decorators. Its main purpose it to
-provide the <tt class="literal"><span class="pre">MetaDecorator</span></tt>
-metaclass to all decorators.</p>
-<p>The <tt class="literal"><span class="pre">safetype</span></tt> metaclass, imported from the <tt class="literal"><span class="pre">safetype</span></tt> module,
-ensures that class decorators can generate classes without incurring
-in conflicts.</p>
-<p>Since class decorators are metaclasses,
-<tt class="literal"><span class="pre">MetaDecorator</span></tt> is actually a meta-metaclass with respect to
-instances of decorated classes. For this reason if</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C=decorators.ClassDecorator('C',(),{})
-</pre>
-<p>then</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__class__
-&lt;class 'decorators.ClassDecorator'&gt;
-</pre>
-<p>but</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__metaclass__
-&lt;class 'decorators.MetaDecorator'&gt;
-</pre>
-<p>since the <tt class="literal"><span class="pre">C.__metaclass__</span></tt> attribute is inherited from <tt class="literal"><span class="pre">Decorator</span></tt>.</p>
-<p>On the other hand, <tt class="literal"><span class="pre">MetaDecorator</span></tt> is a simple metaclass with
-respect to instances of decorated methods.</p>
-<p>The implementation is relatively smart. Consider for instance the case of
-the <tt class="literal"><span class="pre">logged</span></tt> example. In that example class <tt class="literal"><span class="pre">D</span></tt> was a subclass
-of a tricked <tt class="literal"><span class="pre">object</span></tt> class, enhanced by <tt class="literal"><span class="pre">ClassDecorator</span></tt>. Moreover <tt class="literal"><span class="pre">D</span></tt>
-had a <tt class="literal"><span class="pre">Logged</span></tt> docstring. Therefore it should have been an instance of a
-<tt class="literal"><span class="pre">ClassDecoratorLogged</span></tt> metaclass. But logged was
-a subclass of <tt class="literal"><span class="pre">ClassDecorator</span></tt>, therefore it already had all the features
-of <tt class="literal"><span class="pre">ClassDecorator</span></tt> and it would have been redundant to create
-<tt class="literal"><span class="pre">ClassDecoratorLogged</span></tt>, when``Logged`` would have been enough.
-So <tt class="literal"><span class="pre">Logged</span></tt> was used and <tt class="literal"><span class="pre">ClassDecoratorLogged</span></tt> was never created.
-All this magic is in the <tt class="literal"><span class="pre">safetype.remove_redundant(*classes)</span></tt> function.</p>
-<p>The current implementation does not make any attempt of optimization and
-there may be alternative implementations faster or more memory efficient.
-At this experimental level I didn't care to explore about performances
-issues. Probably, they do not matter unless one has to decorate
-thousands or millions of functions and classes.</p>
-<p>Finally, a word about bugs. The <tt class="literal"><span class="pre">decorators</span></tt> module is fairly sophisticated,
-therefore whereas I can guarantee that it passes my test suite (which involves
-~200 tests, most of them extracted from the documentation you are reading),
-I cannot guarantee that it is correct. If somebody finds a bug or an
-unexpected behavior, please let me know and I will fix it or document it.</p>
-<!-- References: -->
-<div class="section" id="module-decorators">
-<h2><a class="toc-backref" href="#id15" name="module-decorators">Module <tt class="literal"><span class="pre">decorators</span></tt></a></h2>
-<p>A module to implement pep318 (decorator syntax) via magic doctrings.
-For the full documentation see
-<a class="reference" href="http://www.phyast.pitt.edu/~micheles/python/decorators.html">http://www.phyast.pitt.edu/~micheles/python/decorators.html</a> .</p>
-<div class="section" id="id3">
-<h3><a class="toc-backref" href="#id16" name="id3">Metaclasses</a></h3>
-<p><tt class="literal"><span class="pre">metaclass</span> <span class="pre">ClassDecorator(type,Decorator):</span></tt></p>
-<blockquote>
-Metaclass callable with one or three arguments, having its calling
-syntax redefined by <tt class="literal"><span class="pre">MetaDecorator</span></tt>.</blockquote>
-<p><tt class="literal"><span class="pre">metaclass</span> <span class="pre">Decorated(ClassDecorator):</span></tt></p>
-<blockquote>
-<p>Metaclass which decorates the methods of its instances according
-to the docstrings. It redefines <tt class="literal"><span class="pre">__str__</span></tt> on
-its instances and the default <tt class="literal"><span class="pre">__str__</span></tt> on the instances of its
-instances.</p>
-<p><tt class="literal"><span class="pre">__str__(cls):</span></tt></p>
-<blockquote>
-Redefine the printing representation of classes</blockquote>
-</blockquote>
-<p><tt class="literal"><span class="pre">metaclass</span> <span class="pre">safetype(type):</span></tt></p>
-<blockquote>
-Overrides the <tt class="literal"><span class="pre">__new__</span></tt> method of the <tt class="literal"><span class="pre">type</span></tt> metaclass, making the
-generation of classes conflict-proof.</blockquote>
-<p><tt class="literal"><span class="pre">metaclass</span> <span class="pre">MetaDecorator(type):</span></tt></p>
-<blockquote>
-<p>Metaclass inducing a certain amount of magic on decorators:</p>
-<ol class="arabic simple">
-<li>Each time a decorator is defined in any module, it is stored in
-MetaDecorator.dic and MetaDecorator.ls.</li>
-<li>If the (method) decorator has a 'get' method, a '__get__' method
-is automagically created as an alias to 'get'.</li>
-<li>Decorators calls are dispatched to the decorator _call_
-classmethod.</li>
-</ol>
-<p><tt class="literal"><span class="pre">__call__(dec,*args):</span></tt></p>
-<blockquote>
-This is the heart of the module. Infers the correct decorator class
-from <tt class="literal"><span class="pre">dec</span></tt> and the docstring and creates the correct decorator object.
-Returns the original object if <tt class="literal"><span class="pre">dec</span></tt> is the trivial <tt class="literal"><span class="pre">Decorator</span></tt>
-class and no docstring is found.</blockquote>
-<p><tt class="literal"><span class="pre">__init__(dec,*args):</span></tt></p>
-<blockquote>
-Update the metaclass attributes <tt class="literal"><span class="pre">dic</span></tt> and <tt class="literal"><span class="pre">ls</span></tt>;
-alias <tt class="literal"><span class="pre">get</span></tt> to <tt class="literal"><span class="pre">__get__</span></tt>.</blockquote>
-</blockquote>
-</div>
-<div class="section" id="classes">
-<h3><a class="toc-backref" href="#id17" name="classes">Classes</a></h3>
-<p><tt class="literal"><span class="pre">class</span> <span class="pre">UnknownDecoratorError(Exception):</span></tt></p>
-<blockquote>
-The name says it all.</blockquote>
-<p><tt class="literal"><span class="pre">class</span> <span class="pre">Decorator(object):</span></tt></p>
-<blockquote>
-Instance of MetaDecorator and mothers of all decorators. When called
-in the form <tt class="literal"><span class="pre">Decorator(obj)</span></tt> with obj having a magic docstring, it returns
-a decorated object; otherwise it returns the original object.</blockquote>
-<p><tt class="literal"><span class="pre">class</span> <span class="pre">staticmethod(MethodDecorator):</span></tt></p>
-<blockquote>
-Decorator, converts a function in a staticmethod</blockquote>
-<p><tt class="literal"><span class="pre">class</span> <span class="pre">MethodDecorator(Decorator):</span></tt></p>
-<blockquote>
-<p>Descriptor class callable with a function or a descriptor object
-as argument. It defines a default printing representation on method
-decorators objects and a default <tt class="literal"><span class="pre">get</span></tt> method. All the rest is
-provided by the metaclass <tt class="literal"><span class="pre">MetaDecorator</span></tt>.</p>
-<p><tt class="literal"><span class="pre">get(self,obj,cls=None):</span></tt></p>
-<blockquote>
-aliased to __get__ by the metaclass, to be overridden</blockquote>
-<p><tt class="literal"><span class="pre">__str__(self):</span></tt></p>
-<blockquote>
-Printing representation of kind &lt;decoratorclass:functionname&gt;</blockquote>
-<p><tt class="literal"><span class="pre">__init__(self,objfunc):</span></tt></p>
-<blockquote>
-objfunc is a decorator object or a function</blockquote>
-</blockquote>
-<p><tt class="literal"><span class="pre">class</span> <span class="pre">classmethod(MethodDecorator):</span></tt></p>
-<blockquote>
-Decorator, converts a function in a classmethod</blockquote>
-</div>
-<div class="section" id="functions">
-<h3><a class="toc-backref" href="#id18" name="functions">Functions</a></h3>
-<p><tt class="literal"><span class="pre">enhance_classes(magicstring='[ClassDecorator]'):</span></tt></p>
-<blockquote>
-Enhances all the classes in the caller module with a metaclass
-built from the given magicstring.</blockquote>
-<p><tt class="literal"><span class="pre">remove_redundant(bases):</span></tt></p>
-<blockquote>
-<p>Returns a tuple of non-redundant base classes.
-Given a sequence of base classes, a class is redundant if it is duplicated
-or if it is implied by the others, i.e. it is an ancestor of at least one
-of the other classes. For instance, if <tt class="literal"><span class="pre">C</span></tt> is derived from <tt class="literal"><span class="pre">B</span></tt>, in the
-sequence <tt class="literal"><span class="pre">C,B</span></tt> the class <tt class="literal"><span class="pre">B</span></tt> is redundant, since all its features are
-already provided by <tt class="literal"><span class="pre">C</span></tt>. Therefore <tt class="literal"><span class="pre">B</span></tt>
-is removed and <tt class="literal"><span class="pre">remove_redundant</span></tt> returns the tuple <tt class="literal"><span class="pre">(C,)</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B(object): pass
-...
-&gt;&gt;&gt; class C(B): pass
-...
-&gt;&gt;&gt; import safetype; safetype.remove_redundant([C,B])
-(&lt;class 'C'&gt;,)
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">compose(dclasses,*defaultclasses):</span></tt></p>
-<blockquote>
-Retrieves or creates a decorator for a tuple of decorators. If
-defaults decorators are given, they get the precedence. It removes
-redundant classes.</blockquote>
-<p><tt class="literal"><span class="pre">instance_str(self):</span></tt></p>
-<blockquote>
-Redefines the printing representation of simple objects</blockquote>
-<p><tt class="literal"><span class="pre">getdec(magicstring=&quot;[Decorator]&quot;):</span></tt></p>
-<blockquote>
-Given a magicstring describing a valid decorator name, returns the list
-of its subclasses. By default returns the full list of decorators.</blockquote>
-<p><tt class="literal"><span class="pre">decorate(objdict):</span></tt></p>
-<blockquote>
-Takes an object with a dictionary and decorates all its functions
-and classes according to their docstrings.</blockquote>
-<p><tt class="literal"><span class="pre">decorators_in(docstring):</span></tt></p>
-<blockquote>
-Takes a docstring and returns a (possibly empty) tuple of decorator
-classes.</blockquote>
-</div>
-</div>
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="decorators.txt">View document source</a>.
-Generated on: 2003-09-30 10:07 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/pep318/mydoc.html b/pypers/pep318/mydoc.html
deleted file mode 100755
index fb70714..0000000
--- a/pypers/pep318/mydoc.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>Documentation of the mydoc module</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="documentation-of-the-mydoc-module">
-<h1 class="title">Documentation of the mydoc module</h1>
-<p>Short utility to extract documentation from a module</p>
-<div class="section" id="documented-functions">
-<h1><a name="documented-functions">Documented functions</a></h1>
-<p><tt class="literal"><span class="pre">publish_cmdline(reader=None,</span> <span class="pre">reader_name='standalone'</span></tt></p>
-<blockquote>
-<p>Set up &amp; run a <cite>Publisher</cite>. For command-line front ends.</p>
-<p>Parameters:</p>
-<ul class="simple">
-<li><cite>reader</cite>: A <cite>docutils.readers.Reader</cite> object.</li>
-<li><cite>reader_name</cite>: Name or alias of the Reader class to be instantiated if
-no <cite>reader</cite> supplied.</li>
-<li><cite>parser</cite>: A <cite>docutils.parsers.Parser</cite> object.</li>
-<li><cite>parser_name</cite>: Name or alias of the Parser class to be instantiated if
-no <cite>parser</cite> supplied.</li>
-<li><cite>writer</cite>: A <cite>docutils.writers.Writer</cite> object.</li>
-<li><cite>writer_name</cite>: Name or alias of the Writer class to be instantiated if
-no <cite>writer</cite> supplied.</li>
-<li><cite>settings</cite>: Runtime settings object.</li>
-<li><cite>settings_spec</cite>: Extra settings specification; a <cite>docutils.SettingsSpec</cite>
-subclass. Used only if no <cite>settings</cite> specified.</li>
-<li><cite>settings_overrides</cite>: A dictionary containing program-specific overrides
-of component settings.</li>
-<li><cite>argv</cite>: Command-line argument list to use instead of <tt class="literal"><span class="pre">sys.argv[1:]</span></tt>.</li>
-<li><cite>usage</cite>: Usage string, output if there's a problem parsing the command
-line.</li>
-<li><cite>description</cite>: Program description, output for the &quot;--help&quot; option
-(along with command-line option descriptions).</li>
-</ul>
-</blockquote>
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="mydoc.rst">View document source</a>.
-Generated on: 2003-09-20 11:43 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/pep318/oopp.html b/pypers/pep318/oopp.html
deleted file mode 100755
index 948dad1..0000000
--- a/pypers/pep318/oopp.html
+++ /dev/null
@@ -1,324 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>Documentation of the oopp module</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="documentation-of-the-oopp-module">
-<h1 class="title">Documentation of the oopp module</h1>
-<div class="section" id="documented-metaclasses">
-<h1><a name="documented-metaclasses">Documented metaclasses</a></h1>
-<p><tt class="literal"><span class="pre">Final(type):</span> <span class="pre">#</span> <span class="pre">better</span> <span class="pre">derived</span> <span class="pre">from</span> <span class="pre">WithCounter,typ</span></tt></p>
-<blockquote>
-Instances of Final cannot be derived</blockquote>
-<p><tt class="literal"><span class="pre">AutoWrapped(type)</span></tt></p>
-<blockquote>
-Metaclass that looks at the methods declared in the attributes
-builtinlist and wraplist of its instances and wraps them with
-autowrappedmethod.</blockquote>
-<p><tt class="literal"><span class="pre">Wrapped(Customizable,type)</span></tt></p>
-<blockquote>
-<p>A customizable metaclass to wrap methods with a given wrapper and
-a given condition</p>
-<p><tt class="literal"><span class="pre">Reflective(type)</span></tt></p>
-<blockquote>
-Cooperative metaclass that defines the private variable __this in
-its instances. __this contains a reference to the class, therefore
-it allows anonymous cooperative super calls in the class.</blockquote>
-<p><tt class="literal"><span class="pre">wrappedmethod(Customizable)</span></tt></p>
-<blockquote>
-Customizable method factory intended for derivation.
-The wrapper method is overridden in the children.</blockquote>
-</blockquote>
-<p><tt class="literal"><span class="pre">Cooperative(BracketCallable,type)</span></tt></p>
-<blockquote>
-<p>Bracket-callable metaclass implementing cooperative methods. Works
-well for plain methods returning None, such as __init__</p>
-<p><tt class="literal"><span class="pre">coop_method(cls,name,method):</span> <span class="pre">#</span> <span class="pre">method</span> <span class="pre">can</span> <span class="pre">be</span> <span class="pre">Non</span></tt></p>
-<blockquote>
-Calls both the superclass method and the class method (if the
-class has an explicit method). Implemented via a closure</blockquote>
-</blockquote>
-<p><tt class="literal"><span class="pre">Logged(WithLogger,Reflective)</span></tt></p>
-<blockquote>
-Metaclass that reuses the features provided by WithLogger.
-In particular the classes created by Logged are Reflective,
-PrettyPrinted and Customizable.</blockquote>
-<p><tt class="literal"><span class="pre">MagicallyTransformed(type)</span></tt></p>
-<blockquote>
-Metaclass changing the formatstring of its instances</blockquote>
-<p><tt class="literal"><span class="pre">Printable(PrettyPrinted,type)</span></tt></p>
-<blockquote>
-Apparently does nothing, but actually makes PrettyPrinted acting as
-a metaclass.</blockquote>
-</div>
-<div class="section" id="documented-classes">
-<h1><a name="documented-classes">Documented classes</a></h1>
-<p><tt class="literal"><span class="pre">convert2descriptor(object)</span></tt></p>
-<blockquote>
-<p>To all practical means, this class acts as a function that, given an
-object, adds to it a __get__ method if it is not already there. The
-added __get__ method is trivial and simply returns the original object,
-independently from obj and cls.</p>
-<p><tt class="literal"><span class="pre">__get__(self,obj,cls=None)</span></tt></p>
-<blockquote>
-Returns self.a independently from obj and cls</blockquote>
-</blockquote>
-<p><tt class="literal"><span class="pre">Object(object)</span></tt></p>
-<blockquote>
-A convenient Object class</blockquote>
-<p><tt class="literal"><span class="pre">GeometricFigure(object):</span> <span class="pre">#an</span> <span class="pre">example</span> <span class="pre">of</span> <span class="pre">object</span> <span class="pre">factor</span></tt></p>
-<blockquote>
-<p>This class allows to define geometric figures according to their
-equation in the cartesian plane. It will be extended later.</p>
-<p><tt class="literal"><span class="pre">__init__(self,equation,**parameters)</span></tt></p>
-<blockquote>
-Specify the cartesian equation of the object and its parameters</blockquote>
-</blockquote>
-<p><tt class="literal"><span class="pre">UglyDuckling(PrettyPrinted)</span></tt></p>
-<blockquote>
-A plain, regular class</blockquote>
-<p><tt class="literal"><span class="pre">autowrappedmethod(wrappedmethod)</span></tt></p>
-<blockquote>
-Makes the method returning cls instances, by wrapping its
-output with cls</blockquote>
-<p><tt class="literal"><span class="pre">Clock(object)</span></tt></p>
-<blockquote>
-Clock with a staticmethod</blockquote>
-<p><tt class="literal"><span class="pre">AccessError(object)</span></tt></p>
-<blockquote>
-Descriptor raising an AttributeError when the attribute is
-accessed</blockquote>
-<p><tt class="literal"><span class="pre">Frozen(object)</span></tt></p>
-<blockquote>
-Subclasses of Frozen are frozen, i.e. it is impossibile to add
-new attributes to them and their instances</blockquote>
-<p><tt class="literal"><span class="pre">Timer(Clock)</span></tt></p>
-<blockquote>
-Inherits the get_time staticmethod from Clock</blockquote>
-<p><tt class="literal"><span class="pre">Vector(list)</span></tt></p>
-<blockquote>
-Implements finite dimensional vectors as lists. Can be instantiated
-as Vector([a,b,c,..]) or as Vector(a,b,c ..)</blockquote>
-<p><tt class="literal"><span class="pre">Singleton(WithCounter)</span></tt></p>
-<blockquote>
-If you inherit from me, you can only have one instance</blockquote>
-<p><tt class="literal"><span class="pre">Homo(PrettyPrinted)</span></tt></p>
-<blockquote>
-Defines the method 'can', which is intended to be overriden
-in the children classes, and inherits '__str__' from PrettyPrinted,
-ensuring a nice printing representation for all children.</blockquote>
-<p><tt class="literal"><span class="pre">kwdict(dict)</span></tt></p>
-<blockquote>
-<p>Keyword dictionary base class</p>
-<p><tt class="literal"><span class="pre">pretty(dic)</span></tt></p>
-<blockquote>
-Returns a nice string representation for the dictionary</blockquote>
-</blockquote>
-<p><tt class="literal"><span class="pre">WithLogger(WithCounter,PrettyPrinted)</span></tt></p>
-<blockquote>
-WithLogger inherits from WithCounter the 'count' class attribute;
-moreover it inherits '__str__' from PrettyPrinted</blockquote>
-<p><tt class="literal"><span class="pre">Get(object)</span></tt></p>
-<blockquote>
-Invoked as Get(cls)(xxx) where xxx = staticmethod, classmethod,
-property, plainmethod, plaindata, returns the corresponding
-attributes as a keyword dictionary. It works by internally calling
-the routine inspect.classify_class_attrs. Notice that special data
-attributes are not retrieved (this is by design).</blockquote>
-<p><tt class="literal"><span class="pre">Makeobj(object)</span></tt></p>
-<blockquote>
-A factory of object factories. Makeobj(cls) returns instances
-of cls</blockquote>
-<p><tt class="literal"><span class="pre">ExampleBaseClass(PrettyPrinted)</span></tt></p>
-<blockquote>
-Contains a regular method 'm', a staticmethod 's', a classmethod
-'c', a property 'p' and a data attribute 'd'.</blockquote>
-<p><tt class="literal"><span class="pre">TransformedUglyDuckling(PrettyPrinted)</span></tt></p>
-<blockquote>
-A class metamagically modified</blockquote>
-<p><tt class="literal"><span class="pre">Customizable(object)</span></tt></p>
-<blockquote>
-Classes inhering from 'Customizable' have a 'with' method acting as
-an object modifier and 'With' classmethod acting as a class factory</blockquote>
-<p><tt class="literal"><span class="pre">WithMultiCounter(WithCounter)</span></tt></p>
-<blockquote>
-Each time a new subclass is derived, the counter is reset</blockquote>
-<p><tt class="literal"><span class="pre">BracketCallable(object)</span></tt></p>
-<blockquote>
-Any subclass C(BracketCallable) can be called with the syntax C[t],
-where t is a tuple of arguments stored in bracket_args; returns the
-class or an instance of it, depending on the flag 'returnclass'.</blockquote>
-<p><tt class="literal"><span class="pre">ClsFactory(BracketCallable)</span></tt></p>
-<blockquote>
-<dl>
-<dt>Bracket callable non-cooperative class acting as </dt>
-<dd>a factory of class factories.
-ClsFactory instances are class factories accepting 0,1,2 or 3 arguments.</dd>
-<dt>. They automatically converts functions to static methods </dt>
-<dd>if the input object is not a class. If an explicit name is not passed
-the name of the created class is obtained by adding an underscore to
-the name of the original object.</dd>
-</dl>
-<p><tt class="literal"><span class="pre">__call__(self,</span> <span class="pre">*args)</span></tt></p>
-<blockquote>
-Generates a new class using self.meta and avoiding conflicts.
-The first metaobject can be a dictionary, an object with a
-dictionary (except a class), or a simple name.</blockquote>
-</blockquote>
-<p><tt class="literal"><span class="pre">WithCounter(object)</span></tt></p>
-<blockquote>
-Mixin class counting the total number of its instances and storing
-it in the class attribute counter.</blockquote>
-</div>
-<div class="section" id="documented-functions">
-<h1><a name="documented-functions">Documented functions</a></h1>
-<p><tt class="literal"><span class="pre">mandelbrot(row,col)</span></tt></p>
-<blockquote>
-Computes the Mandelbrot set in one line</blockquote>
-<p><tt class="literal"><span class="pre">with_tracer(function,namespace='__main__',output=sys.stdout,</span> <span class="pre">indent=[0])</span></tt></p>
-<blockquote>
-Closure returning traced functions. It is typically invoked
-trough an auxiliary function fixing the parameters of with_tracer.</blockquote>
-<p><tt class="literal"><span class="pre">ancestor(C,S=None)</span></tt></p>
-<blockquote>
-Returns the ancestors of the first argument with respect to the
-MRO of the second argument. If the second argument is None, then
-returns the MRO of the first argument.</blockquote>
-<p><tt class="literal"><span class="pre">customize(obj,errfile=None,**kw)</span></tt></p>
-<blockquote>
-Adds attributes to an object, if possible. If not, writes an error
-message on 'errfile'. If errfile is None, skips the exception.</blockquote>
-<p><tt class="literal"><span class="pre">loop_overhead(N)</span></tt></p>
-<blockquote>
-Computes the time spent in empty loop of N iterations</blockquote>
-<p><tt class="literal"><span class="pre">indent(block,n)</span></tt></p>
-<blockquote>
-Indent a block of code by n spaces</blockquote>
-<p><tt class="literal"><span class="pre">totuple(arg)</span></tt></p>
-<blockquote>
-Converts the argument to a tuple, if need there is</blockquote>
-<p><tt class="literal"><span class="pre">attributes(obj,condition=lambda</span> <span class="pre">n,v:</span> <span class="pre">not</span> <span class="pre">special(n))</span></tt></p>
-<blockquote>
-Returns a dictionary containing the accessible attributes of
-an object. By default, returns the non-special attributes only.</blockquote>
-<p><tt class="literal"><span class="pre">generateblocks(regexp,text)</span></tt></p>
-<blockquote>
-Generator splitting text in blocks according to regexp</blockquote>
-<p><tt class="literal"><span class="pre">wrapfunctions(obj,wrapper,err=None,**options)</span></tt></p>
-<blockquote>
-Traces the callable objects in an object with a dictionary</blockquote>
-<p><tt class="literal"><span class="pre">wrap(obj,wrapped,condition=lambda</span> <span class="pre">k,v:</span> <span class="pre">True,</span> <span class="pre">err=None)</span></tt></p>
-<blockquote>
-Retrieves obj's dictionary and wraps it</blockquote>
-<p><tt class="literal"><span class="pre">reflective(*classes)</span></tt></p>
-<blockquote>
-Reflective classes know themselves, i.e. they own a private
-attribute __this containing a reference to themselves. If the class
-name starts with '_', the underscores are stripped. This is needed
-to make the mangling mechanism work.</blockquote>
-<p><tt class="literal"><span class="pre">withmemory(f)</span></tt></p>
-<blockquote>
-This closure invokes the callable object f only if need there is</blockquote>
-<p><tt class="literal"><span class="pre">get_time()</span></tt></p>
-<blockquote>
-Return the time of the system in the format HH:MM:SS</blockquote>
-<p><tt class="literal"><span class="pre">prn(s)</span></tt></p>
-<blockquote>
-Given an evaluable string, print its value and its object reference.
-Notice that the evaluation is done in the __main__ dictionary.</blockquote>
-<p><tt class="literal"><span class="pre">isplaindata(a)</span></tt></p>
-<blockquote>
-A data attribute has no __get__ or __set__ attributes, is not
-a built-in function, nor a built-in method.</blockquote>
-<p><tt class="literal"><span class="pre">Pizza(toppings,**dic)</span></tt></p>
-<blockquote>
-This function produces classes inheriting from GenericPizza and
-WithLogger, using a metaclass inferred from Logged</blockquote>
-<p><tt class="literal"><span class="pre">modulesub(s,r,module)</span></tt></p>
-<blockquote>
-Requires 2.3</blockquote>
-<p><tt class="literal"><span class="pre">memoize(f)</span></tt></p>
-<blockquote>
-This closure remembers all f invocations</blockquote>
-<p><tt class="literal"><span class="pre">with_timer(func,</span> <span class="pre">modulename='__main__',</span> <span class="pre">n=1,</span> <span class="pre">logfile=sys.stdout)</span></tt></p>
-<blockquote>
-Wraps the function func and executes it n times (default n=1).
-The average time spent in one iteration, express in milliseconds,
-is stored in the attributes func.time and func.CPUtime, and saved
-in a log file which defaults to the standard output.</blockquote>
-<p><tt class="literal"><span class="pre">dedent(text)</span></tt></p>
-<blockquote>
-<p>dedent(text : string) -&gt; string</p>
-<blockquote>
-<blockquote>
-<p>Remove any whitespace than can be uniformly removed from the left
-of every line in <cite>text</cite>.</p>
-<p>This can be used e.g. to make triple-quoted strings line up with
-the left edge of screen/whatever, while still presenting it in the
-source code in indented form.</p>
-<p>For example:</p>
-<blockquote>
-<blockquote>
-<dl>
-<dt>def test():</dt>
-<dd><p class="first"># end first line with to avoid the empty line!
-s = ''' hello</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt>oopp.rst</tt>, line 337)</p>
-Unexpected indentation.</div>
-<blockquote>
-world</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>oopp.rst</tt>, line 338)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p class="last">'''
-print repr(s) # prints ' hello</p>
-</dd>
-</dl>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>oopp.rst</tt>, line 340)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>world</p>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>oopp.rst</tt>, line 341)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<dl>
-<dt>'</dt>
-<dd>print repr(dedent(s)) # prints 'hello</dd>
-</dl>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>oopp.rst</tt>, line 343)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>world</p>
-</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>oopp.rst</tt>, line 344)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>'</p>
-</blockquote>
-<p><tt class="literal"><span class="pre">makecls(*metas,**options)</span></tt></p>
-<blockquote>
-Class factory avoiding metatype conflicts. The invocation syntax is
-makecls(M1,M2,..,priority=1)(name,bases,dic). If the base classes have
-metaclasses conflicting within themselves or with the given metaclasses,
-it automatically generates a compatible metaclass and instantiate it.
-If priority is True, the given metaclasses have priority over the
-bases' metaclasses</blockquote>
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="oopp.rst">View document source</a>.
-Generated on: 2003-09-20 12:54 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/pep318/pydoc.html b/pypers/pep318/pydoc.html
deleted file mode 100755
index 8de6660..0000000
--- a/pypers/pep318/pydoc.html
+++ /dev/null
@@ -1,508 +0,0 @@
-
-<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html><head><title>Python: module decorators</title>
-</head><body bgcolor="#f0f0f8">
-
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
-<tr bgcolor="#7799ee">
-<td valign=bottom>&nbsp;<br>
-<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>decorators</strong></big></big></font></td
-><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/mnt/exp/MyDocs/pypers/pep318/decorators.py">/mnt/exp/MyDocs/pypers/pep318/decorators.py</a></font></td></tr></table>
- <p><tt>A&nbsp;module&nbsp;to&nbsp;implement&nbsp;pep318&nbsp;(decorator&nbsp;syntax)&nbsp;via&nbsp;magic&nbsp;doctrings.<br>
-For&nbsp;the&nbsp;documentation&nbsp;see<br>
-&nbsp;<br>
-<a href="http://www.phyast.pitt.edu/~micheles/python/decorators,html">http://www.phyast.pitt.edu/~micheles/python/decorators,html</a><br>
-&nbsp;<br>
-and&nbsp;the&nbsp;on-line&nbsp;help.</tt></p>
-<p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#aa55cc">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
-
-<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
-<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="__builtin__.html">__builtin__</a><br>
-<a href="inspect.html">inspect</a><br>
-</td><td width="25%" valign=top><a href="noconflict.html">noconflict</a><br>
-<a href="re.html">re</a><br>
-</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
-</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ee77aa">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
-
-<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
-<td width="100%"><dl>
-<dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#UnknownDecoratorError">UnknownDecoratorError</a>
-</font></dt></dl>
-</dd>
-<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#Decorator">Decorator</a>
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#ClassDecorator">ClassDecorator</a>(<a href="__builtin__.html#type">__builtin__.type</a>, <a href="decorators.html#Decorator">Decorator</a>)
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#Decorated">Decorated</a>
-</font></dt></dl>
-</dd>
-<dt><font face="helvetica, arial"><a href="decorators.html#MethodDecorator">MethodDecorator</a>
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#classmethod">classmethod</a>
-</font></dt><dt><font face="helvetica, arial"><a href="decorators.html#staticmethod">staticmethod</a>
-</font></dt></dl>
-</dd>
-</dl>
-</dd>
-</dl>
-</dd>
-<dt><font face="helvetica, arial"><a href="__builtin__.html#type">__builtin__.type</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#ClassDecorator">ClassDecorator</a>(<a href="__builtin__.html#type">__builtin__.type</a>, <a href="decorators.html#Decorator">Decorator</a>)
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#Decorated">Decorated</a>
-</font></dt></dl>
-</dd>
-<dt><font face="helvetica, arial"><a href="decorators.html#MetaDecorator">MetaDecorator</a>
-</font></dt></dl>
-</dd>
-</dl>
- <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="ClassDecorator">class <strong>ClassDecorator</strong></a>(<a href="__builtin__.html#type">__builtin__.type</a>, <a href="decorators.html#Decorator">Decorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>Metaclass&nbsp;callable&nbsp;with&nbsp;one&nbsp;or&nbsp;three&nbsp;arguments,&nbsp;having&nbsp;its&nbsp;calling<br>
-syntax&nbsp;redefined&nbsp;by&nbsp;the&nbsp;meta-metaclass&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.&nbsp;It&nbsp;redefines<br>
-__str__&nbsp;both&nbsp;on&nbsp;classes&nbsp;and&nbsp;instances.<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#ClassDecorator">ClassDecorator</a></dd>
-<dd><a href="__builtin__.html#type">__builtin__.type</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="ClassDecorator-__init__"><strong>__init__</strong></a>(cls, name, bases, dic)</dt></dl>
-
-<dl><dt><a name="ClassDecorator-__str__"><strong>__str__</strong></a>(cls)</dt></dl>
-
-<hr>
-Methods inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><a name="ClassDecorator-__call__"><strong>__call__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__call__">__call__</a>(...)&nbsp;&lt;==&gt;&nbsp;x(...)</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__cmp__"><strong>__cmp__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__cmp__">__cmp__</a>(y)&nbsp;&lt;==&gt;&nbsp;cmp(x,y)</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__hash__"><strong>__hash__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__hash__">__hash__</a>()&nbsp;&lt;==&gt;&nbsp;hash(x)</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__subclasses__"><strong>__subclasses__</strong></a>(...)</dt><dd><tt><a href="#ClassDecorator-__subclasses__">__subclasses__</a>()&nbsp;-&gt;&nbsp;list&nbsp;of&nbsp;immediate&nbsp;subclasses</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-mro"><strong>mro</strong></a>(...)</dt><dd><tt><a href="#ClassDecorator-mro">mro</a>()&nbsp;-&gt;&nbsp;list<br>
-return&nbsp;a&nbsp;<a href="__builtin__.html#type">type</a>'s&nbsp;method&nbsp;resolution&nbsp;order</tt></dd></dl>
-
-<hr>
-Data and other attributes inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><strong>__base__</strong> = &lt;type 'type'&gt;</dl>
-
-<dl><dt><strong>__bases__</strong> = (&lt;type 'type'&gt;, &lt;class 'decorators.Decorator'&gt;)</dl>
-
-<dl><dt><strong>__basicsize__</strong> = 420</dl>
-
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;</dl>
-
-<dl><dt><strong>__dictoffset__</strong> = 132</dl>
-
-<dl><dt><strong>__flags__</strong> = 22523</dl>
-
-<dl><dt><strong>__itemsize__</strong> = 20</dl>
-
-<dl><dt><strong>__mro__</strong> = (&lt;class 'decorators.ClassDecorator'&gt;, &lt;type 'type'&gt;, &lt;class 'decorators.Decorator'&gt;, &lt;type 'object'&gt;)</dl>
-
-<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#ClassDecorator-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;<a href="__builtin__.html#type">type</a>&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
-
-<dl><dt><strong>__weakrefoffset__</strong> = 184</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined&nbsp;in&nbsp;any&nbsp;module,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in<br>
-&nbsp;&nbsp;&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-2.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-&nbsp;&nbsp;&nbsp;is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.<br>
-3.&nbsp;Decorators&nbsp;calls&nbsp;are&nbsp;dispatched&nbsp;to&nbsp;the&nbsp;decorator&nbsp;_call_<br>
-&nbsp;&nbsp;&nbsp;<a href="#classmethod">classmethod</a>.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="Decorated">class <strong>Decorated</strong></a>(<a href="decorators.html#ClassDecorator">ClassDecorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>Metaclass&nbsp;which&nbsp;decorates&nbsp;its&nbsp;instances<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#Decorated">Decorated</a></dd>
-<dd><a href="decorators.html#ClassDecorator">ClassDecorator</a></dd>
-<dd><a href="__builtin__.html#type">__builtin__.type</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="Decorated-__init__"><strong>__init__</strong></a>(cls, name, bases, dic)</dt></dl>
-
-<hr>
-Methods inherited from <a href="decorators.html#ClassDecorator">ClassDecorator</a>:<br>
-<dl><dt><a name="Decorated-__str__"><strong>__str__</strong></a>(cls)</dt></dl>
-
-<hr>
-Methods inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><a name="Decorated-__call__"><strong>__call__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__call__">__call__</a>(...)&nbsp;&lt;==&gt;&nbsp;x(...)</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__cmp__"><strong>__cmp__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__cmp__">__cmp__</a>(y)&nbsp;&lt;==&gt;&nbsp;cmp(x,y)</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__hash__"><strong>__hash__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__hash__">__hash__</a>()&nbsp;&lt;==&gt;&nbsp;hash(x)</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__subclasses__"><strong>__subclasses__</strong></a>(...)</dt><dd><tt><a href="#Decorated-__subclasses__">__subclasses__</a>()&nbsp;-&gt;&nbsp;list&nbsp;of&nbsp;immediate&nbsp;subclasses</tt></dd></dl>
-
-<dl><dt><a name="Decorated-mro"><strong>mro</strong></a>(...)</dt><dd><tt><a href="#Decorated-mro">mro</a>()&nbsp;-&gt;&nbsp;list<br>
-return&nbsp;a&nbsp;<a href="__builtin__.html#type">type</a>'s&nbsp;method&nbsp;resolution&nbsp;order</tt></dd></dl>
-
-<hr>
-Data and other attributes inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><strong>__base__</strong> = &lt;class 'decorators.ClassDecorator'&gt;</dl>
-
-<dl><dt><strong>__bases__</strong> = (&lt;class 'decorators.ClassDecorator'&gt;,)</dl>
-
-<dl><dt><strong>__basicsize__</strong> = 420</dl>
-
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;</dl>
-
-<dl><dt><strong>__dictoffset__</strong> = 132</dl>
-
-<dl><dt><strong>__flags__</strong> = 22523</dl>
-
-<dl><dt><strong>__itemsize__</strong> = 20</dl>
-
-<dl><dt><strong>__mro__</strong> = (&lt;class 'decorators.Decorated'&gt;, &lt;class 'decorators.ClassDecorator'&gt;, &lt;type 'type'&gt;, &lt;class 'decorators.Decorator'&gt;, &lt;type 'object'&gt;)</dl>
-
-<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#Decorated-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;<a href="__builtin__.html#type">type</a>&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
-
-<dl><dt><strong>__weakrefoffset__</strong> = 184</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined&nbsp;in&nbsp;any&nbsp;module,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in<br>
-&nbsp;&nbsp;&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-2.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-&nbsp;&nbsp;&nbsp;is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.<br>
-3.&nbsp;Decorators&nbsp;calls&nbsp;are&nbsp;dispatched&nbsp;to&nbsp;the&nbsp;decorator&nbsp;_call_<br>
-&nbsp;&nbsp;&nbsp;<a href="#classmethod">classmethod</a>.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="Decorator">class <strong>Decorator</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>Instance&nbsp;of&nbsp;<a href="#MetaDecorator">MetaDecorator</a>&nbsp;and&nbsp;mothers&nbsp;of&nbsp;all&nbsp;decorators.&nbsp;When&nbsp;called<br>
-in&nbsp;the&nbsp;form&nbsp;<a href="#Decorator">Decorator</a>(obj),&nbsp;with&nbsp;obj&nbsp;having&nbsp;a&nbsp;magic&nbsp;docstring,&nbsp;it&nbsp;returns<br>
-an&nbsp;instance&nbsp;of&nbsp;the&nbsp;correct&nbsp;decorator,&nbsp;otherwise&nbsp;it&nbsp;returns&nbsp;None.<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%">Data and other attributes defined here:<br>
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
-
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined&nbsp;in&nbsp;any&nbsp;module,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in<br>
-&nbsp;&nbsp;&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-2.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-&nbsp;&nbsp;&nbsp;is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.<br>
-3.&nbsp;Decorators&nbsp;calls&nbsp;are&nbsp;dispatched&nbsp;to&nbsp;the&nbsp;decorator&nbsp;_call_<br>
-&nbsp;&nbsp;&nbsp;<a href="#classmethod">classmethod</a>.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="MetaDecorator">class <strong>MetaDecorator</strong></a>(<a href="__builtin__.html#type">__builtin__.type</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined&nbsp;in&nbsp;any&nbsp;module,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in<br>
-&nbsp;&nbsp;&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-2.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-&nbsp;&nbsp;&nbsp;is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.<br>
-3.&nbsp;Decorators&nbsp;calls&nbsp;are&nbsp;dispatched&nbsp;to&nbsp;the&nbsp;decorator&nbsp;_call_<br>
-&nbsp;&nbsp;&nbsp;<a href="#classmethod">classmethod</a>.<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#MetaDecorator">MetaDecorator</a></dd>
-<dd><a href="__builtin__.html#type">__builtin__.type</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="MetaDecorator-__call__"><strong>__call__</strong></a>(dec, *args)</dt></dl>
-
-<dl><dt><a name="MetaDecorator-__init__"><strong>__init__</strong></a>(dec, *args)</dt></dl>
-
-<hr>
-Data and other attributes defined here:<br>
-<dl><dt><strong>dic</strong> = {'ClassDecorator': &lt;class 'decorators.ClassDecorator'&gt;, 'Decorated': &lt;class 'decorators.Decorated'&gt;, 'Decorator': &lt;class 'decorators.Decorator'&gt;, 'MethodDecorator': &lt;class 'decorators.MethodDecorator'&gt;, 'classmethod': &lt;class 'decorators.classmethod'&gt;, 'staticmethod': &lt;class 'decorators.staticmethod'&gt;}</dl>
-
-<dl><dt><strong>ls</strong> = [&lt;class 'decorators.Decorator'&gt;, &lt;class 'decorators.MethodDecorator'&gt;, &lt;class 'decorators.ClassDecorator'&gt;, &lt;class 'decorators.Decorated'&gt;, &lt;class 'decorators.staticmethod'&gt;, &lt;class 'decorators.classmethod'&gt;]</dl>
-
-<hr>
-Methods inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><a name="MetaDecorator-__cmp__"><strong>__cmp__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__cmp__">__cmp__</a>(y)&nbsp;&lt;==&gt;&nbsp;cmp(x,y)</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__hash__"><strong>__hash__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__hash__">__hash__</a>()&nbsp;&lt;==&gt;&nbsp;hash(x)</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__subclasses__"><strong>__subclasses__</strong></a>(...)</dt><dd><tt><a href="#MetaDecorator-__subclasses__">__subclasses__</a>()&nbsp;-&gt;&nbsp;list&nbsp;of&nbsp;immediate&nbsp;subclasses</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-mro"><strong>mro</strong></a>(...)</dt><dd><tt><a href="#MetaDecorator-mro">mro</a>()&nbsp;-&gt;&nbsp;list<br>
-return&nbsp;a&nbsp;<a href="__builtin__.html#type">type</a>'s&nbsp;method&nbsp;resolution&nbsp;order</tt></dd></dl>
-
-<hr>
-Data and other attributes inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><strong>__base__</strong> = &lt;type 'type'&gt;</dl>
-
-<dl><dt><strong>__bases__</strong> = (&lt;type 'type'&gt;,)</dl>
-
-<dl><dt><strong>__basicsize__</strong> = 420</dl>
-
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;</dl>
-
-<dl><dt><strong>__dictoffset__</strong> = 132</dl>
-
-<dl><dt><strong>__flags__</strong> = 22523</dl>
-
-<dl><dt><strong>__itemsize__</strong> = 20</dl>
-
-<dl><dt><strong>__mro__</strong> = (&lt;class 'decorators.MetaDecorator'&gt;, &lt;type 'type'&gt;, &lt;type 'object'&gt;)</dl>
-
-<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#MetaDecorator-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;<a href="__builtin__.html#type">type</a>&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
-
-<dl><dt><strong>__weakrefoffset__</strong> = 184</dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="MethodDecorator">class <strong>MethodDecorator</strong></a>(<a href="decorators.html#Decorator">Decorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>Descriptor&nbsp;class&nbsp;callable&nbsp;with&nbsp;a&nbsp;function&nbsp;as&nbsp;argument.&nbsp;The&nbsp;calling<br>
-syntax&nbsp;is&nbsp;redefined&nbsp;by&nbsp;the&nbsp;meta-metaclass&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.&nbsp;It&nbsp;redefines<br>
-__str__&nbsp;and&nbsp;get&nbsp;(i.e.&nbsp;__get__)&nbsp;on&nbsp;its&nbsp;instances.<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#MethodDecorator">MethodDecorator</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="MethodDecorator-__get__"><strong>__get__</strong></a> = <a href="#MethodDecorator-get">get</a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<dl><dt><a name="MethodDecorator-__init__"><strong>__init__</strong></a>(self, func)</dt></dl>
-
-<dl><dt><a name="MethodDecorator-__str__"><strong>__str__</strong></a>(self)</dt></dl>
-
-<dl><dt><a name="MethodDecorator-get"><strong>get</strong></a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<hr>
-Data and other attributes defined here:<br>
-<dl><dt><strong>__klass__</strong> = &lt;class 'decorators.?'&gt;</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
-
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined&nbsp;in&nbsp;any&nbsp;module,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in<br>
-&nbsp;&nbsp;&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-2.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-&nbsp;&nbsp;&nbsp;is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.<br>
-3.&nbsp;Decorators&nbsp;calls&nbsp;are&nbsp;dispatched&nbsp;to&nbsp;the&nbsp;decorator&nbsp;_call_<br>
-&nbsp;&nbsp;&nbsp;<a href="#classmethod">classmethod</a>.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="UnknownDecoratorError">class <strong>UnknownDecoratorError</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>The&nbsp;name&nbsp;says&nbsp;it&nbsp;all<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%">Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
-<dl><dt><a name="UnknownDecoratorError-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl>
-
-<dl><dt><a name="UnknownDecoratorError-__init__"><strong>__init__</strong></a>(...)</dt></dl>
-
-<dl><dt><a name="UnknownDecoratorError-__str__"><strong>__str__</strong></a>(...)</dt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="classmethod">class <strong>classmethod</strong></a>(<a href="decorators.html#MethodDecorator">MethodDecorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt><a href="#Decorator">Decorator</a>,&nbsp;converts&nbsp;a&nbsp;function&nbsp;in&nbsp;a&nbsp;<a href="#classmethod">classmethod</a><br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#classmethod">classmethod</a></dd>
-<dd><a href="decorators.html#MethodDecorator">MethodDecorator</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="classmethod-__get__"><strong>__get__</strong></a> = <a href="#classmethod-get">get</a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<dl><dt><a name="classmethod-get"><strong>get</strong></a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<hr>
-Methods inherited from <a href="decorators.html#MethodDecorator">MethodDecorator</a>:<br>
-<dl><dt><a name="classmethod-__init__"><strong>__init__</strong></a>(self, func)</dt></dl>
-
-<dl><dt><a name="classmethod-__str__"><strong>__str__</strong></a>(self)</dt></dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#MethodDecorator">MethodDecorator</a>:<br>
-<dl><dt><strong>__klass__</strong> = &lt;class 'decorators.?'&gt;</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
-
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined&nbsp;in&nbsp;any&nbsp;module,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in<br>
-&nbsp;&nbsp;&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-2.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-&nbsp;&nbsp;&nbsp;is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.<br>
-3.&nbsp;Decorators&nbsp;calls&nbsp;are&nbsp;dispatched&nbsp;to&nbsp;the&nbsp;decorator&nbsp;_call_<br>
-&nbsp;&nbsp;&nbsp;<a href="#classmethod">classmethod</a>.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="staticmethod">class <strong>staticmethod</strong></a>(<a href="decorators.html#MethodDecorator">MethodDecorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt><a href="#Decorator">Decorator</a>,&nbsp;converts&nbsp;a&nbsp;function&nbsp;in&nbsp;a&nbsp;<a href="#staticmethod">staticmethod</a><br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#staticmethod">staticmethod</a></dd>
-<dd><a href="decorators.html#MethodDecorator">MethodDecorator</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="staticmethod-__get__"><strong>__get__</strong></a> = <a href="#staticmethod-get">get</a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<dl><dt><a name="staticmethod-get"><strong>get</strong></a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<hr>
-Methods inherited from <a href="decorators.html#MethodDecorator">MethodDecorator</a>:<br>
-<dl><dt><a name="staticmethod-__init__"><strong>__init__</strong></a>(self, func)</dt></dl>
-
-<dl><dt><a name="staticmethod-__str__"><strong>__str__</strong></a>(self)</dt></dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#MethodDecorator">MethodDecorator</a>:<br>
-<dl><dt><strong>__klass__</strong> = &lt;class 'decorators.?'&gt;</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
-
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined&nbsp;in&nbsp;any&nbsp;module,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in<br>
-&nbsp;&nbsp;&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-2.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-&nbsp;&nbsp;&nbsp;is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.<br>
-3.&nbsp;Decorators&nbsp;calls&nbsp;are&nbsp;dispatched&nbsp;to&nbsp;the&nbsp;decorator&nbsp;_call_<br>
-&nbsp;&nbsp;&nbsp;<a href="#classmethod">classmethod</a>.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table></td></tr></table><p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#eeaa77">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
-
-<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
-<td width="100%"><dl><dt><a name="-decorate"><strong>decorate</strong></a>(objdict)</dt><dd><tt>Takes&nbsp;an&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;a&nbsp;dictionary&nbsp;and&nbsp;decorates&nbsp;all&nbsp;its&nbsp;functions<br>
-and&nbsp;classes&nbsp;according&nbsp;to&nbsp;their&nbsp;docstrings.</tt></dd></dl>
- <dl><dt><a name="-decorated"><strong>decorated</strong></a>(obj)</dt><dd><tt>Returns&nbsp;a&nbsp;new&nbsp;decorated&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;created&nbsp;from&nbsp;obj,&nbsp;if&nbsp;obj&nbsp;is&nbsp;a&nbsp;function<br>
-or&nbsp;a&nbsp;class;&nbsp;otherwise&nbsp;it&nbsp;returns&nbsp;None</tt></dd></dl>
- <dl><dt><a name="-decorator_from"><strong>decorator_from</strong></a>(docstring, defaultdec<font color="#909090">=None</font>)</dt><dd><tt>Takes&nbsp;a&nbsp;magic&nbsp;docstring&nbsp;and&nbsp;a&nbsp;default&nbsp;decorator<br>
-and&nbsp;returns&nbsp;a&nbsp;decorator&nbsp;class&nbsp;or&nbsp;None.&nbsp;It&nbsp;tries&nbsp;to&nbsp;be&nbsp;smart.</tt></dd></dl>
- <dl><dt><a name="-enhance_classes"><strong>enhance_classes</strong></a>(docstring<font color="#909090">=''</font>)</dt><dd><tt>Enhance&nbsp;all&nbsp;the&nbsp;classes&nbsp;in&nbsp;the&nbsp;caller&nbsp;module&nbsp;with&nbsp;a&nbsp;metaclass<br>
-built&nbsp;from&nbsp;the&nbsp;given&nbsp;docstring;&nbsp;the&nbsp;default&nbsp;is&nbsp;<a href="#ClassDecorator">ClassDecorator</a>.</tt></dd></dl>
- <dl><dt><a name="-get"><strong>get</strong></a>(docstring<font color="#909090">=None</font>)</dt><dd><tt>List&nbsp;of&nbsp;recognized&nbsp;decorators</tt></dd></dl>
-</td></tr></table><p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#55aa55">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
-
-<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
-<td width="100%"><strong>MAGICDOC</strong> = &lt;_sre.SRE_Pattern object&gt;</td></tr></table>
-</body></html> \ No newline at end of file
diff --git a/pypers/pep318/safetype.html b/pypers/pep318/safetype.html
deleted file mode 100755
index a3c3cd4..0000000
--- a/pypers/pep318/safetype.html
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>Module safetype</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="module-safetype">
-<h1 class="title">Module safetype</h1>
-<p>Deep, DEEP magic to remove metaclass conflicts.
-Metaclasses derived from safetype.type by cooperatively overriding __new__
-are safe under conflicts.
-The suggested import syntax for usage in other modules is</p>
-<blockquote>
-from safetype import type</blockquote>
-<div class="section" id="documented-metaclasses">
-<h1><a name="documented-metaclasses">Documented metaclasses</a></h1>
-<p><tt class="literal"><span class="pre">safetype(type)</span></tt></p>
-<blockquote>
-Redefines the 'type' metaclass, making it safe under conflicts.</blockquote>
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="safetype.rst">View document source</a>.
-Generated on: 2003-09-20 16:41 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/pep318/working/decorators.html b/pypers/pep318/working/decorators.html
deleted file mode 100755
index ceac9b6..0000000
--- a/pypers/pep318/working/decorators.html
+++ /dev/null
@@ -1,1337 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>Implementing PEP 318 (decorators)</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="implementing-pep-318-decorators">
-<h1 class="title">Implementing PEP 318 (decorators)</h1>
-<blockquote>
-<table class="field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">Module:</th><td class="field-body">decorators</td>
-</tr>
-<tr class="field"><th class="field-name">Version:</th><td class="field-body">0.5</td>
-</tr>
-<tr class="field"><th class="field-name">Author:</th><td class="field-body">Michele Simionato</td>
-</tr>
-<tr class="field"><th class="field-name">e-mail:</th><td class="field-body"><a class="reference" href="mailto:MicheleSimionato&#64;libero.it">MicheleSimionato&#64;libero.it</a></td>
-</tr>
-<tr class="field"><th class="field-name">Licence:</th><td class="field-body">Python-like</td>
-</tr>
-<tr class="field"><th class="field-name">Disclaimer:</th><td class="field-body">This is experimental code. Use it at your own risk!</td>
-</tr>
-</tbody>
-</table>
-</blockquote>
-<div class="contents topic" id="contents">
-<p class="topic-title"><a name="contents">Contents</a></p>
-<ul class="simple">
-<li><a class="reference" href="#basics" id="id1" name="id1">Basics</a></li>
-<li><a class="reference" href="#simple-usage-of-decorators" id="id2" name="id2">Simple usage of decorators</a></li>
-<li><a class="reference" href="#decorating-classes" id="id3" name="id3">Decorating classes</a></li>
-<li><a class="reference" href="#adding-magic" id="id4" name="id4">Adding magic</a></li>
-<li><a class="reference" href="#the-dangers-of-magic" id="id5" name="id5">The dangers of magic</a></li>
-<li><a class="reference" href="#defining-method-decorators" id="id6" name="id6">Defining method decorators</a></li>
-<li><a class="reference" href="#composing-decorators" id="id7" name="id7">Composing decorators</a></li>
-<li><a class="reference" href="#defining-class-decorators" id="id8" name="id8">Defining class decorators</a></li>
-<li><a class="reference" href="#advanced-usage" id="id9" name="id9">Advanced usage</a></li>
-<li><a class="reference" href="#the-implementation" id="id10" name="id10">The implementation</a></li>
-</ul>
-</div>
-<p>Having plenty of free time in these days, I have finished an old
-project of mine, the implementation of PEP 318 in pure Python.</p>
-<p>Here is the rationale:</p>
-<ul class="simple">
-<li>some kind of decorator syntax is scheduled to go in Python 2.4,
-therefore it is interesting to play with the concept;</li>
-<li>it is nice to play with decorators now, without having to
-wait for one year or so;</li>
-<li>it is much easier levelto experiment with a pure Python implementation
-than with a C implementation;</li>
-<li>the implementation can be seen as an exercise on modern Python
-programming and may be valuable to people wanting to study the most
-advanced new constructs in Python 2.2 (<a class="reference" href="http://users.rcn.com/python/download/Descriptor.htm">descriptors</a>, <a class="reference" href="http://www-106.ibm.com/developerworks/library/l-pymeta2.html">metaclasses</a>,
-<a class="reference" href="http://www.python.org/2.3/descrintro.html">cooperative methods</a>, etc.)</li>
-</ul>
-<div class="section" id="basics">
-<h1><a class="toc-backref" href="#id1" name="basics">Basics</a></h1>
-<p>PEP 318 has the goal of providing a nice syntactic sugar for expressions like</p>
-<blockquote>
-<pre class="literal-block">
-def identity(x):
- return x
-identity=staticmethod(identity)
-</pre>
-</blockquote>
-<p>or</p>
-<blockquote>
-<pre class="literal-block">
-def name(cls):
- return cls.__name__
-name=classmethod(name)
-</pre>
-</blockquote>
-<p>which are pretty verbose. It is clear that having new syntax (as
-for instance the proposed square bracket notation)</p>
-<blockquote>
-<pre class="literal-block">
-def identity(x)[staticmethod]:
- return x
-
-def name(cls)[classmethod]:
- return cls.__name__
-</pre>
-</blockquote>
-<p>involves changing the grammar and modifying the interpreter at the
-C level. This means a lot of work. Fortunately, it is possible to
-have the same effect without changing the Python grammar.
-The idea is to use magic docstrings like this:</p>
-<blockquote>
-<pre class="literal-block">
-def identity(x):
- &quot;[staticmethod]&quot;
- return x
-
-def name(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-</pre>
-</blockquote>
-<p>The implementation is able to recognize such docstrings
-and to automagically convert those methods in decorators.</p>
-<p>Decorators are nothing else than a sophisticated kind of wrappers.
-The <tt class="literal"><span class="pre">decorators</span></tt> module provides support both for method decorators,
-which wrap functions and class decorator, which wrap classes.
-<tt class="literal"><span class="pre">staticmethod</span></tt> and <tt class="literal"><span class="pre">classmethod</span></tt> are two examples of already existing
-method decorators (actually my implementation rewrites them, but let me
-pass on this detail). Technically speaking, method decorators are classes
-taking a single function as input and producing a descriptor object
-as output (properties are not decorators according to this definition,
-since they take four functions as input, <tt class="literal"><span class="pre">get,</span> <span class="pre">set,</span> <span class="pre">del_</span></tt> and <tt class="literal"><span class="pre">doc</span></tt>).
-Descriptors are objects with a <tt class="literal"><span class="pre">__get__</span></tt> method; they are quite
-sophisticated, but fortunately they have been wonderfully explained by
-Raymond Hettinger already, so I am allowed to skip on this point ;).
-A knowledge of descriptors is not needed in order to use the <tt class="literal"><span class="pre">decorator</span></tt>
-module; however it is welcomed for advanced users wanting to implement
-custom method decorators.
-Class decorators are metaclasses taking a class as imput and returning
-a decorated class as output. A good understanding of metaclasses is needed
-in order to be able to write custom class decorators, but no knowledge
-at all is required in order to use the pre-defined class decorators
-provided by the module.
-Finally, the module is meant to be extensible; so one could
-define new kind of decorators. For instance, the original version of
-the module also had the concept of module decorators; however I have cut
-down that part in order to keep the module short.</p>
-<p>Admittedly, the implementation
-is not for the faint of heart, nevertheless I have tried to make the
-basic usage easy and simple to understand.</p>
-</div>
-<div class="section" id="simple-usage-of-decorators">
-<h1><a class="toc-backref" href="#id2" name="simple-usage-of-decorators">Simple usage of decorators</a></h1>
-<p>Before talking about the implementation details, I will show
-how the <tt class="literal"><span class="pre">decorators</span></tt> module works in practice. The simplest and safest
-usage is by means of the <tt class="literal"><span class="pre">decorators.decorated()</span></tt> function, which
-takes an object (a function or a class) and checks its docstring: if
-a magic docstring is found, it returns a decorated version of the object,
-otherwise it returns the original object. Using <tt class="literal"><span class="pre">decorators.decorated()</span></tt>
-is simple but verbose, so magic shortcuts will be discussed in the next
-section.</p>
-<p>Here, let me give an example, showing that method decorators work both for
-<a class="reference" href="http://www.python.org/2.3/descrintro.html">new style classes and old style classes</a>:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example1.py&gt;
-
-import decorators
-
-def do_nothing(self):
- &quot;No magic docstring here&quot;
-dec_do_nothing=decorators.decorated(do_nothing)
-
-def identity(x):
- &quot;[staticmethod]&quot;
- return x
-dec_identity=decorators.decorated(identity)
-
-def name(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-dec_name=decorators.decorated(name)
-
-class OldStyle:
- do_nothing=dec_do_nothing
- identity=dec_identity
-
-class NewStyle(object):
- name=dec_name
-
-o=OldStyle() # creates an old style instance
-n=NewStyle() # creates a new style instance
-
-#&lt;/example1.py&gt;
-</pre>
-</blockquote>
-<p>In this example, both <tt class="literal"><span class="pre">dec_identity</span></tt> and <tt class="literal"><span class="pre">dec_name</span></tt> are decorator objects,
-i.e. descriptors modifiying the attribute access. It is easy to recognize
-decorators objects, since they have a re-defined printing representation:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example1 import *
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; print dec_identity
-&lt;staticmethod:identity&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; print dec_name
-&lt;classmethod:name&gt;
-</pre>
-<p>Now, let me check that <tt class="literal"><span class="pre">dec_</span> <span class="pre">identity</span></tt> works as a staticmethod,</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; assert OldStyle.identity(1) == 1 # called from the class
-&gt;&gt;&gt; assert o.identity(1) == 1 # called from the instance
-</pre>
-<p>whereas <tt class="literal"><span class="pre">dec_name</span></tt> works as a classmethod:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; assert NewStyle.name() == 'NewStyle' # called from the class
-&gt;&gt;&gt; assert n.name() == 'NewStyle' # called from the instance
-</pre>
-<p>On the other hand, <tt class="literal"><span class="pre">do_nothing</span></tt> does not have a magic
-docstring, therefore it is not converted to a decorator object;
-actually it is <em>exactly</em> the original function:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; assert dec_do_nothing is do_nothing # not converted
-</pre>
-<p>Therefore it works without surprises:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; o.do_nothing() # does nothing, correct
-</pre>
-<p>For sake of convenience, I have re-implemented the built-in
-<tt class="literal"><span class="pre">staticmethod</span></tt> and <tt class="literal"><span class="pre">classmethod</span></tt>, so</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; isinstance(dec_identity,staticmethod)
-False
-</pre>
-<p>and</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; isinstance(dec_name,classmethod)
-False
-</pre>
-<p>but</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; isinstance(dec_identity,decorators.staticmethod)
-True
-</pre>
-<p>and</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; isinstance(dec_name,decorators.classmethod)
-True
-</pre>
-<p>It is possible to recognize method decorators since they provides
-a couple of special attributes:</p>
-<p><tt class="literal"><span class="pre">__func__</span></tt>, returning the function from which they originated</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; assert dec_identity.__func__ is identity
-&gt;&gt;&gt; assert dec_name.__func__ is name
-</pre>
-</blockquote>
-<p>and <tt class="literal"><span class="pre">__klass__</span></tt>, returning the class where they where defined</p>
-<blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; dec_identity.__klass__
-&lt;class 'decorators.?'&gt;
-</pre>
-</blockquote>
-<p>The question mark here means that the definition class is unknown.</p>
-</div>
-<div class="section" id="decorating-classes">
-<h1><a class="toc-backref" href="#id3" name="decorating-classes">Decorating classes</a></h1>
-<p>The problem with the approach described in the previous section
-is that it does not present any significant advantage over
-the already existing mechanism. A real step forward would be to
-have classes with the ability of automatically converting their
-methods to method decorators according to the docstrings.
-This sounds a bit of magic, but actually can be done very simply
-by adding to the class a docstring starting with &quot;[Decorated]&quot;
-and decorating the class.
-Here is an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example2.py&gt;
-
-from decorators import decorated
-from example1 import do_nothing,identity,name
-
-class B(object):
- &quot;This is a regular class&quot;
-
-B=decorated(B) # does nothing
-
-class C(B):
- &quot;[Decorated]&quot;
- do_nothing=do_nothing
- identity=identity
- name=name
-
-C=decorated(C) # regenerates the class converting methods in decorators
-c=C()
-
-#&lt;/example2.py&gt;
-</pre>
-</blockquote>
-<p>Here is the testing:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example2 import *
-&gt;&gt;&gt; assert C.identity(1) == 1
-&gt;&gt;&gt; assert C.name() == 'C'
-&gt;&gt;&gt; assert c.identity(1) == 1
-&gt;&gt;&gt; assert c.name() == 'C'
-</pre>
-<p>Notice that adding <tt class="literal"><span class="pre">identity</span></tt> after the class creation with the syntax
-<tt class="literal"><span class="pre">C.identity=identity</span></tt> would not work;
-<tt class="literal"><span class="pre">C.identity=decorators.decorated(identity)</span></tt> is required:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.identity=decorators.decorated(identity)
-&gt;&gt;&gt; C.identity(1) # it works
-1
-</pre>
-<p>If a class misses the magic docstring, nothing happens:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; B # returns the original B
-&lt;class 'example2.B'&gt;
-</pre>
-<p>The mechanism works for old style classes too:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example2.py&gt;
-
-class D: # old style
- &quot;[Decorated]&quot;
- def identity(x):
- &quot;[staticmethod]&quot;
- return x
-
-D=decorated(D)
-
-d=D()
-
-# test
-assert d.identity(1) == 1
-assert D.identity(1) == 1
-
-#&lt;/example2.py&gt;
-</pre>
-</blockquote>
-<p>Under the hood <tt class="literal"><span class="pre">decorators.decorated()</span></tt> recognizes the class level
-magic docstring &quot;[Decorated]&quot; and creates an instance of the
-<tt class="literal"><span class="pre">decorators.Decorated</span></tt> metaclass; incidentally,
-this converts old style classes in new style classes:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example2 import D,d
-&gt;&gt;&gt; type(D) # D is an instance of decorator.Decorated
-&lt;class 'decorators.Decorated'&gt;
-</pre>
-<p>Internally the metaclass invokes <tt class="literal"><span class="pre">decorators.decorated()</span></tt>
-on the methods of its instances: this is why they becomes decorated
-if a suitable docstring is found. By the way, if you mispell a
-decorator name you get an helpful error message:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class E:
-... &quot;[Decorated]&quot;
-... def f():
-... &quot;[staticmeth]&quot;
-&gt;&gt;&gt; E=decorators.decorated(E)
-Traceback (most recent call last):
- .. a long and cryptic traceback here ..
-UnknownDecoratorError: staticmeth
-</pre>
-<p>The enhancement provided by the metaclass includes a new default
-printing representation for both the class</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print D # returns the name of D and of its metaclass
-&lt;class D[Decorated]&gt;
-</pre>
-<p>and its instances:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print d
-&lt;D instance&gt;
-</pre>
-<p>One can even forget the docstring in subclasses of decorated
-classes, since metaclasses are inherited:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class E(D):
-... def name(cls):
-... &quot;[classmethod]&quot;
-... return cls.__name__
-&gt;&gt;&gt; print E.name()
-E
-</pre>
-<p>This approach presents another advantage: the decorated methods know
-the class where they were defined via the special attribute <tt class="literal"><span class="pre">__klass__</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; E.__dict__['name'].__klass__ # the class where 'name' is defined
-&lt;class 'E'&gt;
-</pre>
-<p>This is useful for introspection and debugging purposes.</p>
-</div>
-<div class="section" id="adding-magic">
-<h1><a class="toc-backref" href="#id4" name="adding-magic">Adding magic</a></h1>
-<p>The problem of the previous approach is that one must explicitely
-decorate the classes by hand, by invoking <tt class="literal"><span class="pre">decorators.decorated()</span></tt>
-each time. However, it is possible to add more magic
-and to decorate all the classes automatically.
-It is as easy as writing <tt class="literal"><span class="pre">decorators.enhance_classes()</span></tt>
-on top of the module. Then all methods in all classes of the module
-with a magic docstring will be checked for magic docstrings and
-automagically decorated if needed.
-For instance, the previous example would be written</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example4.py&gt;
-
-import decorators; decorators.enhance_classes()
-
-class C:
- &quot;[Decorated]&quot; # magic docstring here
- def do_nothing(self):
- &quot;No magic docstring here&quot;
-
- def identity(x):
- &quot;[staticmethod]&quot;
- return x
-
-class D(object):
- &quot;Undecorated&quot; # no magic docstring here
- def name(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-
-c=C(); d=D()
-
-#&lt;/example4.py&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">C</span></tt> has a <tt class="literal"><span class="pre">[Decorated]</span></tt> docstring, so its methods
-are automatically decorated:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example4 import *
-&gt;&gt;&gt; assert c.do_nothing() is None
-&gt;&gt;&gt; assert C.identity(1) == 1
-&gt;&gt;&gt; assert c.identity(1) == 1
-</pre>
-<p>On the other hand, since <tt class="literal"><span class="pre">D</span></tt> misses a magic docstring,
-its <tt class="literal"><span class="pre">name</span></tt> method is not decorated:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; hasattr(D.__dict__['name'],'__func__') # not a decorator
-False
-</pre>
-<p>Since <tt class="literal"><span class="pre">D.name</span></tt> is a regular method and not a classmethod, <tt class="literal"><span class="pre">D.name()</span></tt>
-gives an error:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; D.name()
-Traceback (most recent call last):
- ...
-TypeError: unbound method name() must be called with D instance as first argument (got nothing instead)
-</pre>
-<p>The trick works for classes containing inner classes, too:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example5.py&gt;
-
-import decorators; decorators.enhance_classes()
-
-class C:
- &quot;[Decorated]&quot; # required docstring
- def identity(x):
- &quot;[staticmethod]&quot;
- return x
- class Inner:
- &quot;[Decorated]&quot; # required docstring
- def name(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-
-
-assert C.identity(1) == 1
-assert C.Inner.name() == 'Inner'
-
-#&lt;/example5.py&gt;
-</pre>
-</blockquote>
-<p>Under the hood, the magic works by enhancing the <tt class="literal"><span class="pre">object</span></tt> class
-of the module with a <tt class="literal"><span class="pre">decorators.ClassDecorator</span></tt> metaclass:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import example5
-&gt;&gt;&gt; type(example5.object)
-&lt;class 'decorators.ClassDecorator'&gt;
-</pre>
-<p>Notice that for safety reasons the enhancement is only on the module
-<tt class="literal"><span class="pre">object</span></tt> class, not on the <tt class="literal"><span class="pre">__builtin__.object</span></tt> class. The problem
-is that adding too much magic can be risky.</p>
-</div>
-<div class="section" id="the-dangers-of-magic">
-<h1><a class="toc-backref" href="#id5" name="the-dangers-of-magic">The dangers of magic</a></h1>
-<p>For the sake of metaclass users, in this section I will point out the
-dangers of the <tt class="literal"><span class="pre">enhance_classes()</span></tt> syntax. On the other hand, if you
-never use metaclasses, you may safely skip to the following section.</p>
-<p>The problem is that the <tt class="literal"><span class="pre">enhance_classes()</span></tt> syntax is not 100% safe,
-because of possible metaclass conflicts.
-Here is an example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import decorators; decorators.enhance_classes()
-</pre>
-<p>This line enhances the <tt class="literal"><span class="pre">object</span></tt> class in the interpreter namespace:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print object
-&lt;class object[ClassDecorator]&gt;
-</pre>
-<p>This shows that <tt class="literal"><span class="pre">object</span></tt> is an instance of <tt class="literal"><span class="pre">ClassDecorator</span></tt>.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class M(type):
-... &quot;Some non-trivial code here...&quot;
-</pre>
-<p>This line creates a custom metaclass we want to use to enhance our classes.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(object): __metaclass__=M # does not work!
-...
-Traceback (most recent call last):
- ...
-TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-<p>The problem is that the previous line tries to create a class <tt class="literal"><span class="pre">D</span></tt>
-which should have both metaclasses <tt class="literal"><span class="pre">ClassDecorator</span></tt> and <tt class="literal"><span class="pre">M</span></tt>:
-a conflict follows.</p>
-<p>Fortunately, the decorators module imports the <tt class="literal"><span class="pre">makecls</span></tt> function from my
-<tt class="literal"><span class="pre">noconflict</span></tt> module (described in the <a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197">cookbook</a>)
-just to avoid this kind of problems:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(object):
-... __metaclass__=decorators.makecls(M)
-</pre>
-<p>Now the class has been safely created as an instance of the composed
-class <tt class="literal"><span class="pre">ClassDecoratorM</span></tt>.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(D)
-&lt;class 'noconflict.ClassDecoratorM'&gt;
-</pre>
-<p>If we want <tt class="literal"><span class="pre">M</span></tt> to have the priority over <tt class="literal"><span class="pre">ClassDecorator</span></tt>, the
-option <tt class="literal"><span class="pre">priority=True</span></tt> makes the job:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(object):
-... __metaclass__=decorators.makecls(M,priority=True)
-&gt;&gt;&gt; type(D)
-&lt;class 'noconflict.MClassDecorator'&gt;
-</pre>
-<p>The situation for old style classes is worse, since</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D:
-... __metaclass__=M
-... def sm():
-... &quot;[staticmethod]&quot;
-</pre>
-<p>apparently gives no error, but actually the metaclass <tt class="literal"><span class="pre">M</span></tt> overrides
-<tt class="literal"><span class="pre">ClassDecorator</span></tt>, so <tt class="literal"><span class="pre">D</span></tt> will not recognize magic docstrings:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; type(D)
-&lt;class 'M'&gt;
-&gt;&gt;&gt; D.sm()
-Traceback (most recent call last):
- ...
-TypeError: unbound method sm() must be called with D instance as first argument (got nothing instead)
-</pre>
-<p>Using <tt class="literal"><span class="pre">decorators.makecls(M)</span></tt> will not help here (because of the way Python
-assigns metaclasses) and the only solution is to be completely explicit:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D:
-... __metaclass__=decorators.makecls(decorators.ClassDecorator,M)
-... def sm():
-... &quot;[staticmethod]&quot;
-&gt;&gt;&gt; type(D)
-&lt;class 'noconflict.ClassDecoratorM'&gt;
-</pre>
-<p>Now <tt class="literal"><span class="pre">D</span></tt> is not decorated since it does miss a magic docstring, but
-it provides the ability to recognizing magic docstrings, so <tt class="literal"><span class="pre">D</span></tt>
-subclasses with a &quot;[Decorated]&quot; docstring will be decorated:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class E(D):
-... &quot;[Decorated]&quot;
-... def cm(cls):
-... &quot;[classmethod]&quot;
-... print '.cm() called from',cls
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; E.cm() # it works
-.cm() called from &lt;class E[ClassDecoratorMDecorated]&gt;
-</pre>
-<p>Notice that <tt class="literal"><span class="pre">sm</span></tt> was defined in <tt class="literal"><span class="pre">D</span></tt>, the undecorated class: therefore
-it is not decorated:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; E.sm() # correctly, does not work
-Traceback (most recent call last):
- ...
-TypeError: unbound method sm() must be called with E instance as first argument (got nothing instead)
-</pre>
-<p>The error message says clearly that <tt class="literal"><span class="pre">sm</span></tt> is an unbound method and not
-a static method.</p>
-</div>
-<div class="section" id="defining-method-decorators">
-<h1><a class="toc-backref" href="#id6" name="defining-method-decorators">Defining method decorators</a></h1>
-<p>The <tt class="literal"><span class="pre">decorators</span> <span class="pre">module</span></tt> contains two predefinite method decorators,
-<tt class="literal"><span class="pre">staticmethod</span></tt> and <tt class="literal"><span class="pre">classmethod</span></tt>, which emulate the built-ins
-with the same names. However, it is possible to write your own
-custom decorators. The <tt class="literal"><span class="pre">decorators.MethodDecorator</span></tt> class which is here
-exactly for that purpose.</p>
-<p>Custom decorators are expected to be implemented by subclassing
-<tt class="literal"><span class="pre">MethodDecorator</span></tt> and by overriding its <tt class="literal"><span class="pre">get</span></tt> method. The
-<tt class="literal"><span class="pre">get</span></tt> method automagically induces a <tt class="literal"><span class="pre">__get__</span></tt> method, turning the
-class in a descriptor. The machinery is needed since <tt class="literal"><span class="pre">__get__</span></tt> cannot
-be made cooperative using the standard <tt class="literal"><span class="pre">super</span></tt> mechanism because
-there would be a confusion between <tt class="literal"><span class="pre">super.__get__</span></tt> and the decorator
-<tt class="literal"><span class="pre">__get__</span></tt>. This is a bit tricky, but the causal programmer is not
-expected to write custom decorators, and actually I don't want to make
-the access to decorators <em>too</em> easy, since they are potentially dangerous.</p>
-<p>In order to give a simple example, let me show the implementation
-of a <tt class="literal"><span class="pre">chattymethod</span></tt> that prints a message when it is called:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-from decorators import *
-
-class chattymethod(MethodDecorator):
- logfile=sys.stdout # default
- def get(self,obj,cls=None): # same signature as __get__
- self.logfile.write('calling %s from %s\n' % (self,obj or cls))
- return super(chattymethod,self).get(obj,cls)
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p>Notice the usage of the <tt class="literal"><span class="pre">super().get</span></tt> trick. This guarantees that
-<tt class="literal"><span class="pre">chattymethod</span></tt> will play well with other decorators (i.e. it
-can be nicely composed via multiple inheritance). The point will
-be fully discussed in the section on composing decorators.</p>
-<p>Here is an example of usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import customdec # adds chattymethod to the list of known decorators
-&gt;&gt;&gt; customdec.enhance_classes() # automagically enhances classes when needed
-&gt;&gt;&gt; class C:
-... &quot; [Decorated] &quot;
-... def f(self):
-... &quot;&quot;&quot;
-... [ chattymethod ]
-... &quot;&quot;&quot;
-&gt;&gt;&gt; c=C()
-&gt;&gt;&gt; c.f()
-calling &lt;chattymethod:f&gt; from &lt;C instance&gt;
-</pre>
-<p>By the way, this shows that one can safely add whitespaces (including
-newlines) to the magic docstring: they are simply ignored.</p>
-<p>One can check that the syntax <tt class="literal"><span class="pre">C.f(c)</span></tt> works too:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.f(c)
-calling &lt;chattymethod:f&gt; from &lt;class C[Decorated]&gt;
-</pre>
-<p>A tricky point of the decorators mechanism is the issue of parameter passing.
-In comp.lang.python there was the proposal of allowing explicit parameter
-passing to decorators, with a syntax of kind</p>
-<blockquote>
-<pre class="literal-block">
-def f(self)[chattymethod(logfile=file('file1.log','w'))]
-</pre>
-</blockquote>
-<p>In my view, there are too many parenthesis in this syntax, and it may
-become rapidly unreadable. Moreover, it complicates the implementation
-without any real benefit, so the decorators module does not allow
-this kind of parameter passings. There are however viable
-workarounds, so you should not miss the syntax.</p>
-<p>A simple minded solution is to change the defaults by hand:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from customdec import chattymethod,decorated
-&gt;&gt;&gt; chattymethod.logfile=file('file.log','w')
-&gt;&gt;&gt; def g(self):
-... &quot;[chattymethod]&quot;
-&gt;&gt;&gt; C.g=decorated(g)
-&gt;&gt;&gt; c.g() # will print a message on file.log
-</pre>
-<p>This approach has the drawback that chattymethods created before changing
-the logfile will also print to the new logfile, if invoked after the
-change. Therefore</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; c.f()
-</pre>
-<p>will print a message to <tt class="literal"><span class="pre">file.log</span></tt> too, and not to standard output.
-Here is the confirmation:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; chattymethod.logfile.close()
-&gt;&gt;&gt; print file('file.log').read().rstrip()
-calling &lt;chattymethod:g&gt; from &lt;C instance&gt;
-calling &lt;chattymethod:f&gt; from &lt;C instance&gt;
-</pre>
-<p>A much better solution is to pass
-parameters to method decorators as function attributes: then the function
-attributes can be converted to attributes of the decorator
-in the <tt class="literal"><span class="pre">__init__</span></tt> method. Here is an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-class chattymethod2(chattymethod):
- logfile=sys.stdout # default
- def __init__(self,objfunc):
- super(chattymethod2,self).__init__(objfunc)
- logfile=getattr(self.__func__,'logfile',None)
- if logfile: self.logfile=logfile
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p>Notice that the <tt class="literal"><span class="pre">__init__</span></tt> method has the signature
-<tt class="literal"><span class="pre">__init__(self,objfunc)</span></tt>, where the <tt class="literal"><span class="pre">objfunc</span></tt> object is a
-decorator object or the function to be converted in the decorator
-object, and that it is cooperative.
-This is the suggested way of overriding <tt class="literal"><span class="pre">__init__</span></tt> (see also
-<tt class="literal"><span class="pre">help(decorators.MethodDecorator.__init__)</span></tt>).</p>
-<p>Here is the testing:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;chatty2.py&gt;
-
-import customdec; customdec.enhance_classes(&quot;[Decorated]&quot;)
-
-# sets the log files
-log1=file('file1.log','w')
-log2=file('file2.log','w')
-
-class C:
- def f(self):
- &quot;[chattymethod2]&quot;
- f.logfile=log1 # function attribute
- def g(self):
- &quot;[chattymethod2]&quot;
- g.logfile=log2 # function attribute
-
-assert C.__dict__['f'].logfile is log1 # check the conversion
-assert C.__dict__['g'].logfile is log2 # function attr. -&gt; decorator attr.
-
-c=C() # C instantiation
-
-c.f() # print a message in file1.log
-c.g() # print a message in file2.log
-
-log1.close(); log2.close() # finally
-
-#&lt;/chatty2.py&gt;
-</pre>
-</blockquote>
-<p>Let me check the contents of the log files:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import chatty2
-&gt;&gt;&gt; print file('file1.log').read().rstrip()
-calling &lt;chattymethod2:f&gt; from &lt;C instance&gt;
-&gt;&gt;&gt; print file('file2.log').read().rstrip()
-calling &lt;chattymethod2:g&gt; from &lt;C instance&gt;
-</pre>
-<p><tt class="literal"><span class="pre">chattymethod</span></tt> is the poor man version of <tt class="literal"><span class="pre">tracedmethod</span></tt>, a
-sophisticated decorator for tracing methods.
-Here is the code, given for pedagogical purposes; the lazy reader can
-skip it and go directly to the usage section.</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-class tracedmethod(MethodDecorator):
- &quot;Descriptor class, converts a method in a traced method&quot;
- indent=0; output=sys.stdout # defaults
-
- def __init__(self,objfunc):
- super(tracedmethod,self).__init__(objfunc)
- self.funcname=self.__func__.__name__
- output=getattr(self.__func__,'output',None)
- if output: self.output=output # func.attr. -&gt; dec.attr.
-
- def get(self,obj,cls):
- clsname=self.__klass__.__name__ # definition clas
- def tracedmeth(obj,*args,**kw):
- i=' '*self.indent # default indentation
- self.__class__.indent+=4 # increases indentation
- self.output.write(&quot;%sCalling '%s.%s' with arguments &quot; %
- (i,clsname,self.funcname))
- self.output.write(&quot;%s%s ...\n&quot; % (obj or '',str(args)+str(kw)))
- res=super(tracedmethod,self).get(obj,cls)(*args,**kw)
- self.output.write(&quot;%s'%s.%s' called with result: %s\n&quot;
- % (i,clsname,self.funcname,res))
- self.__class__.indent-=4 # restores default indentation
- return res
- return tracedmeth.__get__(obj,cls) # method wrapper
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">tracedmethod.get</span></tt> returns a method wrapper object, so it is
-possible to use <tt class="literal"><span class="pre">im_func</span></tt> to retrieve the internal function
-<tt class="literal"><span class="pre">tracedmeth</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C:
-... &quot;[Decorated]&quot;
-... def f(self):
-... &quot;[tracedmethod]&quot;
-&gt;&gt;&gt; c=C(); c.f()
-Calling 'C.f' with arguments &lt;C instance&gt;(){} ...
-'C.f' called with result: None
-&gt;&gt;&gt; c.f.im_func.__name__
-'tracedmeth'
-</pre>
-<p>As soon as the <tt class="literal"><span class="pre">tracedmethod</span></tt> module is loaded, the <tt class="literal"><span class="pre">tracedmethod</span></tt> class
-is added to the list of know decorators, so one should use the
-&quot;[tracedmethod]&quot; docstring and not something like
-&quot;[customdec.tracedmethod]&quot;.</p>
-<p>Here is a less trivial example of usage, writing in a log file the
-internal working of a recursive function:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example9.py&gt;
-
-import customdec; customdec.enhance_classes()
-
-logfile=file('file3.log','w')
-
-class C(object):
- &quot;[Decorated]&quot;
- def fact(self,n):
- &quot;[tracedmethod] The good old factorial.&quot;
- if n==0: return 1
- else: return n*self.fact(n-1)
- fact.output=logfile
-
-C().fact(2) # write a message to logfile
-
-logfile.close()
-
-#&lt;/example9.py&gt;
-</pre>
-</blockquote>
-<p>Here is the content of the <tt class="literal"><span class="pre">file3.log</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import example9
-&gt;&gt;&gt; print file('file3.log').read().rstrip()
-Calling 'C.fact' with arguments &lt;C instance&gt;(2,){} ...
- Calling 'C.fact' with arguments &lt;C instance&gt;(1,){} ...
- Calling 'C.fact' with arguments &lt;C instance&gt;(0,){} ...
- 'C.fact' called with result: 1
- 'C.fact' called with result: 1
-'C.fact' called with result: 2
-</pre>
-</div>
-<div class="section" id="composing-decorators">
-<h1><a class="toc-backref" href="#id7" name="composing-decorators">Composing decorators</a></h1>
-<p>Decorators can be composed by using magic docstrings with comma-separated
-decorator names. For instance, you can trace a classmethod as in this example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example6.py&gt;
-
-&quot;How to trace a class method&quot;
-
-import customdec; customdec.enhance_classes()
-
-class C(object):
- &quot;[Decorated]&quot;
- def fact(cls,n): # a traced classmethod
- &quot;[classmethod,tracedmethod]&quot;
- if n==0: return 1
- else: return n*cls.fact(n-1)
-
-#&lt;/example6.py&gt;
-</pre>
-</blockquote>
-<p>Here is the testing:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example6 import C
-&gt;&gt;&gt; C.fact(2)
-Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(2,){} ...
- Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(1,){} ...
- Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(0,){} ...
- 'C.fact' called with result: 1
- 'C.fact' called with result: 1
-'C.fact' called with result: 2
-2
-</pre>
-<p>You may easily check that calling <tt class="literal"><span class="pre">.fact</span></tt> from the instance will work too.</p>
-<p>Under the hood the syntax</p>
-<blockquote>
-<pre class="literal-block">
-[classmethod,tracedmethod]
-</pre>
-</blockquote>
-<p>generates a <tt class="literal"><span class="pre">classmethodtracedmethod</span></tt> class obtained via
-multiple inheritance:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__dict__['fact'].__class__
-&lt;class 'noconflict.classmethodtracedmethod'&gt;
-</pre>
-<p>Notice that the order does matter and using the docstring
-&quot;[tracedmethod,classmethod]&quot; will not work:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D:
-... &quot;[Decorated]&quot;
-... def f(cls):
-... &quot;[tracedmethod,classmethod]&quot;
-&gt;&gt;&gt; D.f()
-Traceback (most recent call last):
- ...
-TypeError: unbound method tracedmeth() must be called with D instance as first argument (got nothing instead)
-</pre>
-<p>The problem here is that <tt class="literal"><span class="pre">tracedmethod.get</span></tt> returns a method-wrapper object
-which expects a D instance as first argument whereas it gets <tt class="literal"><span class="pre">None</span></tt> since
-it is called from the class. On the other hand,</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; D().f()
-Calling 'D.f' with arguments &lt;D instance&gt;(){} ...
-'D.f' called with result: None
-</pre>
-<p>will work. When <tt class="literal"><span class="pre">classmethod</span></tt> precedes <tt class="literal"><span class="pre">tracedmethod</span></tt>, then
-<tt class="literal"><span class="pre">classmethod</span></tt> passes to <tt class="literal"><span class="pre">tracedmeth</span></tt> a non-empty first argument,
-i.e. the calling class, even when called from the instance:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C().fact(2)
-Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(2,){} ...
- Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(1,){} ...
- Calling 'C.fact' with arguments &lt;class C[Decorated]&gt;(0,){} ...
- 'C.fact' called with result: 1
- 'C.fact' called with result: 1
-'C.fact' called with result: 2
-2
-</pre>
-<p>If we try to trace a staticmethod, we will get a different error with
-the order &quot;tracedmethod, staticmethod&quot;:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class F(object):
-... &quot;[Decorated]&quot;
-... def fact(n):
-... &quot;[tracedmethod,staticmethod]&quot;
-... if n==0: return 1
-... else: return n*F.fact(n-1)
-&gt;&gt;&gt; F.fact(2)
-Traceback (most recent call last):
- ...
-TypeError: unbound method tracedmeth() must be called with F instance as first argument (got int instance instead)
-</pre>
-<p>The message is self-explanatory.</p>
-<p>On the other hand, composing the decorators in the other order
-&quot;[tracedmethod,staticmethod]&quot; will work just fine.</p>
-</div>
-<div class="section" id="defining-class-decorators">
-<h1><a class="toc-backref" href="#id8" name="defining-class-decorators">Defining class decorators</a></h1>
-<p>PEP 318 proposes to decorate methods by using descriptors; it is
-quite natural to extend this idea and to decorate classes by using
-class decorators implemented as metaclasses. We already saw a
-class decorator at work, the metaclass <tt class="literal"><span class="pre">Decorated</span></tt>, giving
-to its instances the ability to interpret magic docstrings,
-and converting functions in method decorators.</p>
-<p>To define a custom class decorator is easy: one defines a custom metaclass
-as usual, with the only difference from deriving by <tt class="literal"><span class="pre">ClassDecorator</span></tt> instead
-of deriving from <tt class="literal"><span class="pre">type</span></tt>. To understand how this works in practice, let me
-show how to add logging capabilities to a given class. The first
-step is to define a suitable class decorator, such as the following:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-class Logged(ClassDecorator):
- output=sys.stdout
- def __init__(cls,name,bases,dic):
- super(Logged,cls).__init__(name,bases,dic)
- print &gt;&gt; cls.output,&quot;%s created&quot; % cls
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">Logged</span></tt> is derived by the metaclass <tt class="literal"><span class="pre">ClassDecorator</span></tt>,
-which provides a certain amount of magic under the hood (in particular
-its printing representation and its calling syntax are redefined by its
-metaclass <tt class="literal"><span class="pre">MetaDecorator</span></tt>). Logging capabilities can be added to a class
-by simply using the magic docstring syntax:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;logged.py&gt;
-
-import customdec; customdec.enhance_classes()
-
-class D(object): # will print a message at D creation
- &quot;[Logged]&quot;
-
-#&lt;/logged.py&gt;
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; import logged
-&lt;class D[Logged]&gt; created
-</pre>
-<p>Notice that the printing representation of <tt class="literal"><span class="pre">D</span></tt> involves the name
-of <tt class="literal"><span class="pre">D</span></tt> preceded by the name of its metaclass, which in this case
-is <tt class="literal"><span class="pre">Logged</span></tt></p>
-<p>Each time an instance of <tt class="literal"><span class="pre">Logged</span></tt> is created, a similar message is printed:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class E(logged.D):
-... pass
-&lt;class E[Logged]&gt; created
-</pre>
-<p>Notice that <tt class="literal"><span class="pre">E</span></tt> does not have any magic docstring</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; E.__doc__ # no docstring
-</pre>
-<p>but still it inherits its magic from <tt class="literal"><span class="pre">D</span></tt>.</p>
-<p>Another simple example of class decorator is the following metaclass
-which modifies the docstrings of the methods of its instances,
-by magically inducing tracing capabilities on them:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;customdec.py&gt;
-
-from types import FunctionType
-
-class Traced(ClassDecorator):
- def __init__(cls,n,b,d):
- for name,func in d.iteritems():
- if isinstance(func,FunctionType): # modifies the docstring
- func.__doc__=&quot;[tracedmethod] &quot; + (func.__doc__ or '')
- super(Traced,cls).__init__(n,b,d)
-
-
-#&lt;/customdec.py&gt;
-</pre>
-</blockquote>
-<p>Here is an example of usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... &quot;&quot;&quot;[Decorated,Traced] The class decorator adds the magic docstring
-... '[tracedmethod]' to f1 and f2, which are then converted
-... to method decorator objects.&quot;&quot;&quot;
-... def f1(self): pass
-... def f2(self): pass
-...
-&gt;&gt;&gt; type(C)
-&lt;class 'noconflict.DecoratedTraced'&gt;
-&gt;&gt;&gt; c=C()
-&gt;&gt;&gt; c.f1()
-Calling 'C.f1' with arguments &lt;C instance&gt;(){} ...
-'C.f1' called with result: None
-&gt;&gt;&gt; c.f2()
-Calling 'C.f2' with arguments &lt;C instance&gt;(){} ...
-'C.f2' called with result: None
-</pre>
-<p>By default, the decorators module only decorates classes with a magic
-docstring (and they subclasses, even without magic docstrings).
-If all the classes of your module have the same magic docstring,
-it makes sense to decorate them all
-with a single command. It is enough to use <tt class="literal"><span class="pre">decorators.enhance_classes()</span></tt>
-with a magic docstring corresponding to a class decorator as argument,
-as in this example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example.py&gt;
-
-from example2 import identity,name
-import inspect, decorators; decorators.enhance_classes(&quot;[Decorated]&quot;)
-
-class C1: # automagically converted to a decorated class
- identity=identity
-
-class C2: # automagically converted to a DecoratedLogged class
- &quot;[Logged]&quot;
- name=name
-
-c1=C1() # C1 instance
-c2=C2() # C2 instance
-
-#&lt;/example.py&gt;
-</pre>
-</blockquote>
-<p>Notice that class <tt class="literal"><span class="pre">C2</span></tt> has already a magic docstring. This means that
-<tt class="literal"><span class="pre">C2</span></tt> has to be enhanced both from <tt class="literal"><span class="pre">Logged</span></tt> and from <tt class="literal"><span class="pre">Decorated</span></tt>.
-This is done by automagically creating a <tt class="literal"><span class="pre">DecoratedLogged</span></tt> class
-decorator:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example import C1,C2,c1,c2
-&lt;class C2[DecoratedLogged]&gt; created
-</pre>
-<p>The second line is printed because of the logging capabilities of <tt class="literal"><span class="pre">C2</span></tt>.
-Moreover, since <tt class="literal"><span class="pre">C2</span></tt> is decorated too, the following will work:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; assert C2.name() == 'C2'
-&gt;&gt;&gt; assert c2.name() == 'C2'
-</pre>
-<p>Idem for <tt class="literal"><span class="pre">C1</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; assert C1.identity(1) == 1
-&gt;&gt;&gt; assert c1.identity(1) == 1
-</pre>
-<p>You may check that the magic works both for new style classes (decorating
-module <tt class="literal"><span class="pre">object</span></tt> class) and old style classes (by setting the module level
-<tt class="literal"><span class="pre">__metaclass</span></tt> attribute and by implicitly converting the classes
-to new style classes).</p>
-<p>This magical approach is the easiest way to go if you want to trace
-inheritance hierarchies. For instance, here is how to trace cooperative
-methods in complicate (which is useful for debugging):</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;tracing.py&gt;
-
-import customdec; customdec.enhance_classes(&quot;[Decorated]&quot;)
-
-class B(object):
- def __init__(self):
- &quot;[tracedmethod]&quot;
- super(B,self).__init__()
-
-class D(object):
- def __init__(self):
- &quot;[tracedmethod]&quot;
- super(D,self).__init__()
-
-class E(B,D):
- def __init__(self):
- &quot;[tracedmethod]&quot;
- super(E,self).__init__()
-
- #&lt;/tracing.py&gt;
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from tracing import E
-&gt;&gt;&gt; e=E()
-Calling 'E.__init__' with arguments &lt;E instance&gt;(){} ...
- Calling 'B.__init__' with arguments &lt;E instance&gt;(){} ...
- Calling 'D.__init__' with arguments &lt;E instance&gt;(){} ...
- 'D.__init__' called with result: None
- 'B.__init__' called with result: None
-'E.__init__' called with result: None
-</pre>
-</div>
-<div class="section" id="advanced-usage">
-<h1><a class="toc-backref" href="#id9" name="advanced-usage">Advanced usage</a></h1>
-<p>Whereas the average programmer is expected to use the
-<tt class="literal"><span class="pre">decorators.decorated</span></tt> function only, the module provides access to
-its underlining implementation, which may be useful to the advanced
-programmer.</p>
-<p>The module provides an utility functions to retrieve the list of
-recognized decorators: <tt class="literal"><span class="pre">decorators.get(docstring)</span></tt>, where <tt class="literal"><span class="pre">docstring</span></tt>
-is a magic docstring, i.e. a bracketed comma-separated list
-of decorator names. For instance <tt class="literal"><span class="pre">decorators.get('[MethodDecorator]')</span></tt>
-gives the list of all subclasses of <tt class="literal"><span class="pre">MethodDecorator</span></tt>, i.e. all method
-decorators, whereas <tt class="literal"><span class="pre">decorators.get('[ClassDecorator]')</span></tt>
-gives the list of the known class decorators. It is even possible
-to use the comma notation:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; decorators.get(&quot;[classmethod,tracedmethod]&quot;)
-[&lt;class 'noconflict.classmethodtracedmethod'&gt;]
-</pre>
-<p>For instance, it is possible to decorate functions by hand,
-without using magic docstring. Here is an example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; do_nothing=decorators.staticmethod(lambda:None)
-&gt;&gt;&gt; print do_nothing # ``do_nothing`` is a static method
-&lt;staticmethod:&lt;lambda&gt;&gt;
-</pre>
-<p>One can even compose decorators by hand:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B: pass
-...
-&gt;&gt;&gt; B.chattystatic=customdec.chattymethod2(do_nothing)
-&gt;&gt;&gt; B.chattystatic()
-calling &lt;chattymethod2staticmethod:&lt;lambda&gt;&gt; from &lt;class B[ClassDecorator]&gt;
-</pre>
-<p>In other words</p>
-<blockquote>
-<tt class="literal"><span class="pre">decorator1(decorator2(obj))</span></tt></blockquote>
-<p>automagically creates a composed class <tt class="literal"><span class="pre">decorator1decorator2</span></tt> in the
-<tt class="literal"><span class="pre">noconflict</span></tt> module (or recycle it, if <tt class="literal"><span class="pre">decorator1decorator2</span></tt> has
-been already created) and it is equivalent to</p>
-<blockquote>
-<tt class="literal"><span class="pre">decorator1decorator2(obj)</span></tt></blockquote>
-<p>Here is the check:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; decorators.get(&quot;[chattymethod2staticmethod]&quot;)
-[&lt;class 'noconflict.chattymethod2staticmethod'&gt;]
-</pre>
-<p>Here is another example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from customdec import tracedmethod
-&gt;&gt;&gt; class C(object):
-... def fact(self,n):
-... if n==0: return 1
-... else: return n*self.fact(n-1)
-... fact=tracedmethod(fact)
-&gt;&gt;&gt; c=C()
-&gt;&gt;&gt; c.fact(2)
-Calling '?.fact' with arguments &lt;C instance&gt;(2,){} ...
- Calling '?.fact' with arguments &lt;C instance&gt;(1,){} ...
- Calling '?.fact' with arguments &lt;C instance&gt;(0,){} ...
- '?.fact' called with result: 1
- '?.fact' called with result: 1
-'?.fact' called with result: 2
-2
-</pre>
-<p>In this second syntax <tt class="literal"><span class="pre">fact</span></tt> does not know where it
-is defined, unless the containing class is explicitly set:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C.__dict__['fact'].__klass__=C
-</pre>
-<p>Now the code will work as with the docstring syntax.</p>
-<p>What happens if you try to decorate something which is already
-decorated? You get <tt class="literal"><span class="pre">None</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def f(x): &quot;[tracedmethod]&quot;
-...
-&gt;&gt;&gt; tm=decorators.decorated(f) # creates a tracedmethod from f
-&gt;&gt;&gt; print decorators.decorated(tm) # trying to decorate a tracedmethod
-None
-</pre>
-<p>You can compose decorators in a trivial way:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; cmtm=decorators.classmethod(tm)
-&gt;&gt;&gt; print cmtm
-&lt;classmethodtracedmethod:f&gt;
-</pre>
-<p>whereas you can compose classes:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C: &quot;[Decorated]&quot;
-...
-&gt;&gt;&gt; print customdec.Traced(C)
-&lt;class C[TracedDecorated]&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D: pass
-...
-&gt;&gt;&gt; print customdec.Decorated(customdec.Traced(D))
-&lt;class D[DecoratedTraced]&gt;
-</pre>
-<p>This is the hierarchy:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for C in type(cmtm).mro(): print C
-...
-&lt;class 'noconflict.classmethodtracedmethod'&gt;
-&lt;class 'decorators.classmethod'&gt;
-&lt;class 'customdec.tracedmethod'&gt;
-&lt;class 'decorators.MethodDecorator'&gt;
-&lt;class 'decorators.Decorator'&gt;
-&lt;type 'object'&gt;
-</pre>
-<p>One can also decorate classes by hand, by using class decorators.
-<tt class="literal"><span class="pre">decorators.ClassDecorator</span></tt> which converts a regular (both old
-style or new style) class in a class with the ability to recognize
-magic docstrings. Actually, the <tt class="literal"><span class="pre">decorators.enhance_classes()</span></tt>
-trick works by decorating the <tt class="literal"><span class="pre">object</span></tt> class with
-<tt class="literal"><span class="pre">decorators.ClassDecorator</span></tt> and by setting the custom metaclass to
-<tt class="literal"><span class="pre">decorators.ClassDecorator</span></tt> and it is equivalent to write</p>
-<blockquote>
-<pre class="literal-block">
-import decorators
-object=decorators.ClassDecorator(object) # decorates all new style classes
-__metaclass__= decorators.ClassDecorator # decorates all old style classes
-</pre>
-</blockquote>
-<p>on top of your module.
-If you want the magic to work only for new style classes only, you may
-forget the
-second line; if you want the magic to work for old style classes only, you
-may forget the first line.</p>
-<p>If the module contains a magic docstring which is an explicit class decorator,
-such as <tt class="literal"><span class="pre">decorators.Decorated</span></tt>, then <tt class="literal"><span class="pre">decorators.decorated</span></tt> look at the
-magic docstring and executes something like</p>
-<blockquote>
-<pre class="literal-block">
-import decorators
-object=decorators.Decorated(object) # decorates all new style classes
-__metaclass__= decorators.Decorated # decorates all old style classes
-</pre>
-</blockquote>
-<p>It is possible to go even deeper in black magic, and to decorate all
-the new style classes in <em>all</em> modules, by decorating <tt class="literal"><span class="pre">__builtin__.object</span></tt>:</p>
-<blockquote>
-<pre class="literal-block">
-import decorators,__builtin__
-__builtin.object=decorators.decorated(object)
-</pre>
-</blockquote>
-<p>Still, redefining <tt class="literal"><span class="pre">__builtin__object</span></tt> is not recommended since it
-may induce metaclass conflicts in other modules using metaclasses.
-It will work only if you import modules not using metaclasses, or
-modules using metaclasses safely, i.e. modules taking care of
-possible conflicts by using the <tt class="literal"><span class="pre">makecls</span></tt> function or an equivalent one.</p>
-</div>
-<div class="section" id="the-implementation">
-<h1><a class="toc-backref" href="#id10" name="the-implementation">The implementation</a></h1>
-<p>This part can be safely skipped, unless you are a <em>really</em> curious and
-you want to know how the implementation works.</p>
-<p>The module is rather short (~150 lines) but far from being trivial,
-since it is based on extensive usage of metaclass wizardry.</p>
-<p>The main class-metaclass hierarchy is represented in figure 1, where
-boxes denote classes and ovals denote metaclasses; instantiation is
-denoted by dashed green lines whereas inheritance is denoted by continuous
-blue lines.</p>
-<div class="figure">
-<p><img alt="decorators.png" src="decorators.png" /></p>
-</div>
-<p>Notice that <tt class="literal"><span class="pre">MetaDecorator</span></tt> (inherited via <tt class="literal"><span class="pre">Decorator</span></tt>) is the
-metaclass of all decorators. Class decorators are already metaclasses,
-so <tt class="literal"><span class="pre">MetaDecorator</span></tt> is actually a meta-metaclass with respect to
-instances of decorated classes, whereas it is a simple metaclass with
-respect to instances of decorated methods. For this reason in the
-presenced of class decorators the unusual relation</p>
-<p>assert object.__metaclass__ != object.__class__</p>
-<p>holds. More specifically</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; object.__class__
-&lt;class 'decorators.ClassDecorator'&gt;
-</pre>
-<p>but</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; object.__metaclass__
-&lt;class 'decorators.MetaDecorator'&gt;
-</pre>
-<p>since <tt class="literal"><span class="pre">object</span></tt> the <tt class="literal"><span class="pre">__metaclass__</span></tt>
-attribute is inherited from <tt class="literal"><span class="pre">Decorator</span></tt>.</p>
-<p>The implementation is relatively smart. Consider for instance the case of
-the logged example. In that example class <tt class="literal"><span class="pre">D</span></tt> was a subclass of a tricked
-<tt class="literal"><span class="pre">object</span></tt> class, enhanced by a metaclass <tt class="literal"><span class="pre">ClassDecorator</span></tt>. Moreover <tt class="literal"><span class="pre">D</span></tt>
-had a <tt class="literal"><span class="pre">Logged</span></tt> docstring. Therefore it should have been an instance of
-<tt class="literal"><span class="pre">_ClassDecoratorLogged</span></tt> metaclass. But logged was
-a subclass of <tt class="literal"><span class="pre">ClassDecorator</span></tt>, therefore it already had all the features
-of <tt class="literal"><span class="pre">ClassDecorator</span></tt> and it would have been redundant to create
-<tt class="literal"><span class="pre">_ClassDecoratorLogged</span></tt>, when``Logged`` would have been enough.
-So <tt class="literal"><span class="pre">Logged</span></tt>
-was used and <tt class="literal"><span class="pre">_ClassDecoratorLogged</span></tt> was never created. All the magic is in
-the <tt class="literal"><span class="pre">noconflict</span></tt> module discussed in my <a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197">cookbook</a> recipe.</p>
-<p>The current implementation does not make any attempt of optimization and
-there may be alternative implementations faster or more memory efficient.
-At this experimental level I didn't care to explore about performances
-issues. They does not probably matter unless one has to decorate
-thousands or millions of functions and classes.</p>
-<p>Things to do: adding more error checking.</p>
-<p>Finally, a word about bugs. The <tt class="literal"><span class="pre">decorators</span></tt> module is fairly sophisticated,
-therefore whereas I can guarantee that it passes my test suite (which involves
-~100 tests automatically extracted from the documentation you are reading),
-I cannot guarantee that it is correct.
-If somebody finds a bug or an unexpected
-behavior, please let me know and I will try to fix it.</p>
-<!-- References: -->
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="decorators.txt">View document source</a>.
-Generated on: 2003-09-17 14:45 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/pep318/working/pep318.html b/pypers/pep318/working/pep318.html
deleted file mode 100755
index a3ce15b..0000000
--- a/pypers/pep318/working/pep318.html
+++ /dev/null
@@ -1,1046 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.2.9: http://docutils.sourceforge.net/" />
-<title>Implementing PEP 318 (decorators)</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="implementing-pep-318-decorators">
-<h1 class="title">Implementing PEP 318 (decorators)</h1>
-<div class="contents topic" id="contents">
-<p class="topic-title"><a name="contents">Contents</a></p>
-<ul class="simple">
-<li><a class="reference" href="#basics" id="id1" name="id1">Basics</a></li>
-<li><a class="reference" href="#simple-usage-of-decorators" id="id2" name="id2">Simple usage of decorators</a></li>
-<li><a class="reference" href="#adding-a-bit-of-magic" id="id3" name="id3">Adding a bit of magic</a></li>
-<li><a class="reference" href="#adding-more-magic" id="id4" name="id4">Adding more magic</a></li>
-<li><a class="reference" href="#defining-method-decorators" id="id5" name="id5">Defining method decorators</a></li>
-<li><a class="reference" href="#tracing-methods" id="id6" name="id6">Tracing methods</a></li>
-<li><a class="reference" href="#composition-of-decorators" id="id7" name="id7">Composition of decorators</a></li>
-<li><a class="reference" href="#class-decorators" id="id8" name="id8">Class decorators</a></li>
-<li><a class="reference" href="#module-decorators" id="id9" name="id9">Module decorators</a></li>
-<li><a class="reference" href="#introspection-features" id="id10" name="id10">Introspection features</a></li>
-<li><a class="reference" href="#the-implementation" id="id11" name="id11">The implementation</a></li>
-</ul>
-</div>
-<p>Having plenty of free time in these days, I have finished an old
-project of mine, the implementation of PEP 318 in pure Python.</p>
-<p>Here is the rationale:</p>
-<ul class="simple">
-<li>some kind of decorator syntax is scheduled to go in Python 2.4,
-therefore it is interesting to play with the concept;</li>
-<li>it is nice to play with decorators now, without having to
-wait for one year or so;</li>
-<li>it is much easier to experiment with the pure Python implementation;</li>
-<li>the implementation can be seen as an exercise on modern Python
-programming and may be valuable to people wanting to study the most
-advanced new constructs in Python 2.2 (descriptors, metaclasses,
-cooperative methods, etc.)</li>
-</ul>
-<div class="section" id="basics">
-<h1><a class="toc-backref" href="#id1" name="basics">Basics</a></h1>
-<p>As people in this list most probably know, PEP 318 has the goal
-of providing a nice syntactic sugar for expressions like</p>
-<blockquote>
-<pre class="literal-block">
-def identity(x):
- return x
-identity=staticmethod(identity)
-</pre>
-</blockquote>
-<p>or</p>
-<blockquote>
-<pre class="literal-block">
-def nameof(cls):
- return cls.__name__
-nameof=classmethod(nameof)
-</pre>
-</blockquote>
-<p>which are pretty verbose. It is clear that having new syntax (as
-for instance the proposed square bracket notation)</p>
-<blockquote>
-<pre class="literal-block">
-def identity(x)[staticmethod]:
- return x
-
-def nameof(cls)[classmethod]:
- return cls.__name__
-</pre>
-</blockquote>
-<p>involves changing the grammar and modifying the interpreter at the
-C level. However, it is possible to have the same effect without
-changing the Python grammar. The idea is to use magic docstrings
-like this:</p>
-<blockquote>
-<pre class="literal-block">
-def identity(x):
- &quot;[staticmethod]&quot;
- return x
-
-def nameof(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-</pre>
-</blockquote>
-<p>The implementation is able to recognize such docstrings
-and to automagically convert the functions in (method) decorators.</p>
-<p>Method decorators are nothing else than a sophisticated kind of wrappers.
-<tt class="literal"><span class="pre">staticmethod</span></tt> and <tt class="literal"><span class="pre">classmethod</span></tt> are two examples of already existing
-decorators (actually my implementation rewrites them, but let me pass on
-this detail). Technically speaking, method decorators are classes
-taking a single function as input and producing a descriptor object
-as output (properties are not decorators according to this definition,
-since they take four functions as input, <tt class="literal"><span class="pre">get,</span> <span class="pre">set,</span> <span class="pre">del_</span></tt> and <tt class="literal"><span class="pre">doc</span></tt>).
-<a class="reference" href="http://users.rcn.com/python/download/Descriptor.htm">Descriptors</a> are objects with a <tt class="literal"><span class="pre">__get__</span></tt> method; they are quite
-sophisticated, but fortunately they have been wonderfully explained by
-Raymond Hettinger already, so I am allowed to skip this point ;). A knowledge
-of descriptors is not needed in order to use the <tt class="literal"><span class="pre">decorator</span></tt> module;
-however it is welcomed for advanced users wanting to implement
-custom decorators.</p>
-</div>
-<div class="section" id="simple-usage-of-decorators">
-<h1><a class="toc-backref" href="#id2" name="simple-usage-of-decorators">Simple usage of decorators</a></h1>
-<p>Before talking about the implementation details, I will show
-how the <tt class="literal"><span class="pre">decorators</span></tt> module works in practice. The simplest and
-safest usage is by means of the functions <tt class="literal"><span class="pre">decorators.decorate</span></tt>
-and <tt class="literal"><span class="pre">decorators.decorated</span></tt>:</p>
-<ol class="arabic simple">
-<li><tt class="literal"><span class="pre">decorators.decorated(obj)</span></tt> takes an object and checks its docstring;
-if a magic docstring is found, it returns a decorated version of the
-object, otherwise it returns <tt class="literal"><span class="pre">None</span></tt>;</li>
-<li><tt class="literal"><span class="pre">decorators.decorate(obj)</span></tt> takes a dictionary or an object with a
-<tt class="literal"><span class="pre">.__dict__</span></tt> attribute and returns <tt class="literal"><span class="pre">None</span></tt>. It works by
-invoking <tt class="literal"><span class="pre">decorators.decorated</span></tt> on the elements of the dictionary
-and by modifying them if needed.</li>
-</ol>
-<p>Here is an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example1.py&gt;
-
-&quot;How to use ``decorators.decorate`` and ``decorators.decorated``&quot;
-
-import decorators
-
-def do_nothing(self):
- &quot;No magic docstring here&quot;
-
-def identity(x):
- &quot;[staticmethod]&quot; # magic docstring here
- return x
-
-def nameof(cls):
- &quot;[classmethod]&quot; # magic docstring here too
- return cls.__name__
-
-dic={'nameof': nameof, 'do_nothing': do_nothing}
-decorators.decorate(dic) # converts nameof -&gt; classmethod
-
-C=type('C',(),dic) # creates the class with the modified dictionary
-C.identity=decorators.decorated(identity) # converts identity -&gt; staticmethod
-c=C() # creates the instance
-
-#&lt;/example1.py&gt;
-</pre>
-</blockquote>
-<p>and here is the testing:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example1 import C,c
-&gt;&gt;&gt; assert c.do_nothing() is None
-&gt;&gt;&gt; assert C.identity(1) == 1
-&gt;&gt;&gt; assert C.nameof() == 'C'
-&gt;&gt;&gt; assert c.identity(1) == 1
-&gt;&gt;&gt; assert c.nameof() == 'C'
-</pre>
-<p>One can even pass the <tt class="literal"><span class="pre">globals()</span></tt> dictionary since objects without
-a magic docstring are simply ignored. Therefore the previous example
-can be rewritten as</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example2.py&gt;
-
-import decorators
-
-def do_nothing(self):
- &quot;No magic docstring here&quot;
-
-def identity(x):
- &quot;[staticmethod]&quot;
- return x
-
-def nameof(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-
-decorators.decorate(globals()) # decorates the functions
-
-class C(object):
- identity=identity
- nameof=nameof
- do_nothing=do_nothing
-
-c=C()
-
-#&lt;/example2.py&gt;
-</pre>
-</blockquote>
-<p>Here is the testing:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example2 import c,C
-&gt;&gt;&gt; assert c.do_nothing() is None
-&gt;&gt;&gt; assert C.identity(1) == 1
-&gt;&gt;&gt; assert C.nameof() == 'C'
-&gt;&gt;&gt; assert c.identity(1) == 1
-&gt;&gt;&gt; assert c.nameof() == 'C'
-</pre>
-<p>Notice that the call to <tt class="literal"><span class="pre">decorators.decorate(globals())</span></tt> must be done
-<em>after</em> the function definitions, otherwise the functions would
-not converted, since they were not in the global dictionary at the
-time of the call. Moreover, one should not try to pass the <tt class="literal"><span class="pre">locals()</span></tt>
-dictionary, since it will not work when <tt class="literal"><span class="pre">locals()</span> <span class="pre">!=</span> <span class="pre">globals()</span></tt>.</p>
-<p>Alternatively, one can just decorate the class:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example3.py&gt;
-
-import decorators
-
-def identity(x):
- &quot;[staticmethod]&quot;
- return x
-
-def nameof(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-
-class C:
- identity=identity
- nameof=nameof
-
-decorators.decorate(C)
-
-c=C()
-
-# testing
-assert C.identity(1) == 1
-assert C.nameof() == 'C'
-assert c.identity(1) == 1
-assert c.nameof() == 'C'
-
-#&lt;/example3.py&gt;
-</pre>
-</blockquote>
-<p>This example also shows that decorators work both for <a class="reference" href="http://www.python.org/2.3/descrintro.html">new style classes
-and old style classes</a>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example3 import *
-&gt;&gt;&gt; type(C) # C is an old style class
-&lt;type 'classobj'&gt;
-</pre>
-<p>At this point the difference between <tt class="literal"><span class="pre">decorators.decorate</span></tt> and
-<tt class="literal"><span class="pre">decorators.decorated</span></tt> should be pointed out. The first syntax
-modifies the class dictionary, whereas the second creates a new
-class with the same name of the first one:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D:
-... identity=identity
-&gt;&gt;&gt; decorators.decorated(D)
-&lt;class 'D'&gt;
-&gt;&gt;&gt; D.identity(1) # this is the old D
-Traceback (most recent call last):
- ...
-TypeError: unbound method identity() must be called with D instance as first argument (got int instance instead)
-</pre>
-<p>Therefore one has to redefine to old class in order the statement to
-have effect:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; D=decorators.decorated(D)
-&gt;&gt;&gt; D.identity(1) # this is the new D
-1
-</pre>
-</div>
-<div class="section" id="adding-a-bit-of-magic">
-<h1><a class="toc-backref" href="#id3" name="adding-a-bit-of-magic">Adding a bit of magic</a></h1>
-<p>It would be nice to have classes with the ability of automatically
-converting their methods to method decorators according to the docstrings.
-This sounds a bit of magic, but actually can be done very simply by adding
-to the class a docstring starting with &quot;[Decorated]&quot;.
-Here is an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example.py&gt;
-
-import decorators
-
-class C: # works for old style classes too
- &quot;[Decorated]&quot;
- def identity(x):
- &quot;[staticmethod]&quot;
- return x
-
-decorators.decorate(globals())
-
-c=C()
-
-# test
-assert C.identity(1) == 1
-assert c.identity(1) == 1
-
-#&lt;/example.py&gt;
-</pre>
-</blockquote>
-<p>Under the hood, the magic docstring &quot;[Decorated]&quot; creates an instance of the
-<tt class="literal"><span class="pre">decorators.Decorated</span></tt> metaclass and replace the original class <tt class="literal"><span class="pre">C</span></tt>
-in the global namespace with the new class <tt class="literal"><span class="pre">C</span></tt>; incidentally,
-this converts <tt class="literal"><span class="pre">C</span></tt> in a new style class:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example import C
-&gt;&gt;&gt; type(C)
-&lt;class 'decorators.Decorated'&gt;
-</pre>
-<p>On the other hand using <tt class="literal"><span class="pre">decorators.decorate(C)</span></tt> would decorate <tt class="literal"><span class="pre">C</span></tt>, but
-without re-creating it as an instance of &quot;[Decorated]&quot;. One can also
-forget the docstring in subclasses of decorated classes:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(C):
-... def nameof(cls):
-... &quot;[classmethod]&quot;
-... return cls.__name__
-&gt;&gt;&gt; print D.nameof()
-D
-</pre>
-<p>The trick works for classes containing inner classes, too:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example4.py&gt;
-
-import decorators
-
-class C:
- &quot;[Decorated]&quot; # required docstring
- def identity(x):
- &quot;[staticmethod]&quot;
- return x
- class Inner:
- &quot;[Decorated]&quot; # required docstring
- def nameof(cls):
- &quot;[classmethod]&quot;
- return cls.__name__
-
-decorators.decorate(globals())
-
-assert C.identity(1) == 1
-assert C.Inner.nameof() == 'Inner'
-
-#&lt;/example4.py&gt;
-</pre>
-</blockquote>
-</div>
-<div class="section" id="adding-more-magic">
-<h1><a class="toc-backref" href="#id4" name="adding-more-magic">Adding more magic</a></h1>
-<p>There is a neat trick to simplify the usage of decorators: decorating the
-<tt class="literal"><span class="pre">object</span></tt> class. Then all methods in all new style classes of your module
-will be checked for magic docstrings and automagically decorated if needed.
-This can be done by simply writing</p>
-<blockquote>
-<pre class="literal-block">
-import decorators
-object=decorators.decorated(object)
-</pre>
-</blockquote>
-<p>on top of your module. Here is an example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example.py&gt;
-
-import inspect, decorators
-object=decorators.decorated(object)
-
-def identity(x):
- &quot;[staticmethod] defined outside a class&quot;
- return x
-
-assert inspect.isfunction(identity) # not yet a decorator
-
-class C1(object):
- def nameof(cls):
- &quot;[classmethod] defined inside a class&quot;
- return cls.__name__
- identity=identity # automagically converted to a decorator
-
-c1=C1() # C1 instance
-
-# testing
-
-assert C1.identity(1) == 1
-assert C1.nameof() == 'C1'
-assert c1.identity(1) == 1
-assert c1.nameof() == 'C1'
-
-#&lt;/example.py&gt;
-</pre>
-</blockquote>
-<p>Notice that adding <tt class="literal"><span class="pre">identity</span></tt> after the class creation with the syntax
-<tt class="literal"><span class="pre">C.identity=identity</span></tt> would not work. Moreover, the magic only works
-for new style classes, since the implementation operates
-by enhancing the <tt class="literal"><span class="pre">object</span></tt> class in the calling module.
-The enhancement includes providing a new default printing representation
-for instances:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example import c1
-&gt;&gt;&gt; print c1
-&lt;instance of C1&gt;
-</pre>
-<p>The <tt class="literal"><span class="pre">decorated(object)</span></tt> trick (and the &quot;[Decorated]&quot; syntax too)
-is not 100% safe, because of possible metaclass conflicts:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; import decorators; object=decorators.decorated(object)
-&gt;&gt;&gt; class M(type): pass
-...
-&gt;&gt;&gt; class D(object):
-... __metaclass__=M
-Traceback (most recent call last):
- ...
-TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-</pre>
-<p>The decorators module imports the <tt class="literal"><span class="pre">makecls</span></tt> function from my
-<tt class="literal"><span class="pre">noconflict</span></tt> module just to avoid this kind of problems:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(object):
-... __metaclass__=decorators.makecls(M)
-&gt;&gt;&gt; type(D)
-&lt;class 'noconflict._DecoratedM'&gt;
-</pre>
-<p>It is possible to go even deeper in black magic, and to decorate all
-the new style classes in <em>all</em> modules, by decorating <tt class="literal"><span class="pre">__builtin__.object</span></tt>:</p>
-<blockquote>
-<pre class="literal-block">
-import decorators,__builtin__
-__builtin.object=decorators.decorated(object)
-</pre>
-</blockquote>
-<p>Still, redefining <tt class="literal"><span class="pre">__builtin__object</span></tt> is not recommended since it
-may induce metaclass conflicts in other modules using metaclasses.
-It will work only if you import modules not using metaclasses, or
-modules using metaclasses safely, i.e. modules taking care of
-possible conflicts by using the <tt class="literal"><span class="pre">makecls</span></tt> function or an equivalent one.</p>
-</div>
-<div class="section" id="defining-method-decorators">
-<h1><a class="toc-backref" href="#id5" name="defining-method-decorators">Defining method decorators</a></h1>
-<p>The decorators module contains two predefinite method decorators,
-<tt class="literal"><span class="pre">staticmethod</span></tt> and <tt class="literal"><span class="pre">classmethod</span></tt>, which emulate the built-ins
-with the same names. However, it is possible to write your own
-custom decorators. The <tt class="literal"><span class="pre">decorators</span></tt> module provides a
-<tt class="literal"><span class="pre">MethodDecorator</span></tt> class which is here exactly for that purpose.</p>
-<p>Custom decorators are expected to be implemented by subclassing
-<tt class="literal"><span class="pre">MethodDecorator</span></tt> and by overriding its <tt class="literal"><span class="pre">get</span></tt> method, which
-automagically induces a <tt class="literal"><span class="pre">__get__</span></tt> method, turning the class
-in a descriptor. This
-machinery is needed since <tt class="literal"><span class="pre">__get__</span></tt> cannot be made cooperative
-using the standard <tt class="literal"><span class="pre">super</span></tt> mechanism (there would be a confusion
-between <tt class="literal"><span class="pre">super.__get__</span></tt> and the decorator <tt class="literal"><span class="pre">__get__</span></tt>). This is a bit
-tricky, but the causal programmer is not expected to write custom
-decorators, and actually I don't want to make the access to decorators
-<em>too</em> easy</p>
-<p>For instance, let me show the implementation of a <tt class="literal"><span class="pre">chattymethod</span></tt>
-that prints a message when it is called:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;chatty.py&gt;
-
-from decorators import *
-object=decorated(object)
-
-class chattymethod(MethodDecorator):
- logfile=file('file1.log','w')
- def get(self,obj,cls=None): # same signature as __get__
- print &gt;&gt; self.logfile,'calling %s from %s' % (self,obj or cls)
- return super(chattymethod,self).get(obj,cls)
-
-#&lt;/chatty.py&gt;
-</pre>
-</blockquote>
-<p>Notice the usage of the <tt class="literal"><span class="pre">super().get</span></tt> trick. This guarantees that
-<tt class="literal"><span class="pre">chattymethod</span></tt> will play well with other decorators (i.e. it
-can be nicely composed via multiple inheritance)</p>
-<p>Here is an example of usage</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;chatty.py&gt;
-
-class C(object):
- def f():
- &quot;[chattymethod,staticmethod]&quot;
-
-c=C()
-
-c.f()
-C.f()
-
-#&lt;/chatty.py&gt;
-</pre>
-</blockquote>
-<p>The content of the logfile is then</p>
-<blockquote>
-<pre class="literal-block">
-calling &lt;chattymethodstaticmethod:f&gt; from &lt;instance of C&gt;
-calling &lt;chattymethodstaticmethod:f&gt; from &lt;class C[Decorated]&gt;
-</pre>
-</blockquote>
-<p>From this output we see how the &quot;[chattymethod,staticmethod]&quot;
-magic docstring is responsible for the creation of a new decorator class
-<tt class="literal"><span class="pre">chattymethodstaticmethod</span></tt>, obtained via multiple inheritance from
-<tt class="literal"><span class="pre">chattymethod</span></tt> and <tt class="literal"><span class="pre">staticmethod</span></tt> respectively.</p>
-<p>One can easily change the logfile, if need there is</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;chatty.py&gt;
-
-chattymethod.logfile=file('file2.log','w')
-
-def g():
- &quot;[chattymethod,staticmethod]&quot;
-
-C.g=decorated(g)
-C.g # message written in file2.log
-C.f # message written in file2.log
-
-#&lt;/chatty.py&gt;
-</pre>
-</blockquote>
-<p>Now <tt class="literal"><span class="pre">file2.log</span></tt> will contains the messages</p>
-<blockquote>
-<pre class="literal-block">
-calling &lt;chattymethodstaticmethod:g&gt; from &lt;class C[Decorated]&gt;
-calling &lt;chattymethodstaticmethod:f&gt; from &lt;class C[Decorated]&gt;
-</pre>
-</blockquote>
-<p>This approach has the drawback that chattymethods created before changing
-the logfile will also print to the new logfile, if invoked after the
-change. This can be avoided by converting <tt class="literal"><span class="pre">logfile</span></tt> from a class variable
-to an instance variable in the <tt class="literal"><span class="pre">__init__</span></tt> method:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;chatty2.py&gt;
-
-import sys
-from chatty import *
-
-class chattymethod2(chattymethod):
- def __init__(self,func):
- super(chattymethod2,self).__init__(func)
- self.logfile=self.logfile # class variable becomes instance variable
-
-class C(object):
- chattymethod2.logfile=sys.stdout
- f=chattymethod2(lambda self:None)
- chattymethod2.logfile=file('file3.log','w')
- g=chattymethod2(lambda self:None)
-
-c=C()
-
-#&lt;/chatty2.py&gt;
-</pre>
-</blockquote>
-<p>Notice that the <tt class="literal"><span class="pre">__init__</span></tt> method should have the signature
-<tt class="literal"><span class="pre">__init__(self,func)</span></tt>, where <tt class="literal"><span class="pre">func</span></tt> is the function to be
-converted in the decorator object. Here is the testing:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from chatty2 import c
-&gt;&gt;&gt; c.f()
-calling &lt;chattymethod2:&lt;lambda&gt;&gt; from &lt;instance of C&gt;
-&gt;&gt;&gt; c.g() # message written in file3.log
-&gt;&gt;&gt; c.f() # message written in stdout, not in file3.log!
-calling &lt;chattymethod2:&lt;lambda&gt;&gt; from &lt;instance of C&gt;
-</pre>
-</div>
-<div class="section" id="tracing-methods">
-<h1><a class="toc-backref" href="#id6" name="tracing-methods">Tracing methods</a></h1>
-<p>In order to show a non-trivial example, I will show how
-decorators can be used to implement traced methods.
-Here is the code (notice: the lazy reader can safely skip the
-implementation details and go directly to the usage section ;)</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;tracedmethod.py&gt;
-
-import sys,decorators
-
-class tracedmethod(decorators.MethodDecorator):
- &quot;Descriptor class, converts a method in a traced method&quot;
- indent=0; output=sys.stdout # defaults
- def __init__(self,func):
- super(tracedmethod,self).__init__(func)
- self.funcname=self.func.__name__
- def get(self,obj,cls):
- if obj is None: name=self.inside.__name__ # called from class
- else: name='&lt;%s&gt;' % self.inside.__name__ # from instance
- methodwrapper=super(tracedmethod,self).get(obj,cls)
- def _(*args,**kw):
- i=' '*self.indent # default indentation
- self.__class__.indent+=4 # increases indentation
- self.output.write(&quot;%sCalling '%s.%s' with arguments &quot; %
- (i,name,self.funcname))
- self.output.write(&quot;%s ...\n&quot; % (str(args)+str(kw)))
- res=methodwrapper(*args,**kw)
- self.output.write(&quot;%s'%s.%s' called with result: %s\n&quot;
- % (i,name,self.funcname,res))
- self.__class__.indent-=4 # restores default indentation
- return res
- return _
-
-#&lt;/tracedmethod.py&gt;
-</pre>
-</blockquote>
-<p>As soon as the <tt class="literal"><span class="pre">tracedmethod</span></tt> module is loaded, the <tt class="literal"><span class="pre">tracedmethod</span></tt> class
-is added to the list of know decorators, so one should use the &quot;[tracedmethod]&quot;
-docstring instead and not &quot;[tracedmethod.tracedmethod]&quot;.</p>
-<p><tt class="literal"><span class="pre">tracedmethod</span></tt> which is quite useful during
-debugging. Here is an example of usage, in tracing the internal working
-of a recursive function:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example4.py&gt;
-
-import decorators,tracedmethod
-
-class C(object):
- def fact(self,n):
- &quot;[tracedmethod]&quot;
- if n==0: return 1
- else: return n*self.fact(n-1)
-
-decorators.decorate(C)
-
-c=C()
-
-#&lt;/example4.py&gt;
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example4 import c
-&gt;&gt;&gt; c.fact(2)
-Calling '&lt;C&gt;.fact' with arguments (2,){} ...
- Calling '&lt;C&gt;.fact' with arguments (1,){} ...
- Calling '&lt;C&gt;.fact' with arguments (0,){} ...
- '&lt;C&gt;.fact' called with result: 1
- '&lt;C&gt;.fact' called with result: 1
-'&lt;C&gt;.fact' called with result: 2
-2
-</pre>
-<p>An alternative spelling, not involving magic docstrings, nor the
-decorators module, is the following:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example5.py&gt;
-
-from tracedmethod import tracedmethod
-
-class C(object):
- def fact(self,n):
- if n==0: return 1
- else: return n*self.fact(n-1)
- fact=tracedmethod(fact)
-
-c=C()
-
-#&lt;/example5.py&gt;
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example5 import c
-&gt;&gt;&gt; c.fact(2)
-Calling '&lt;?&gt;.fact' with arguments (2,){} ...
- Calling '&lt;?&gt;.fact' with arguments (1,){} ...
- Calling '&lt;?&gt;.fact' with arguments (0,){} ...
- '&lt;?&gt;.fact' called with result: 1
- '&lt;?&gt;.fact' called with result: 1
-'&lt;?&gt;.fact' called with result: 2
-2
-</pre>
-<p>Notice that in this second syntax <tt class="literal"><span class="pre">fact</span></tt> does not know where it
-is defined; however the containing class can be explicitly set:</p>
-<blockquote>
-<tt class="literal"><span class="pre">C.__dict__['fact'].inside=C</span></tt></blockquote>
-<p>The <tt class="literal"><span class="pre">inside</span></tt> attribute is automagically set if the docstring syntax
-is used.</p>
-<p>Here is how to trace cooperative methods in complicate hierarchies
-(which is useful for debugging):</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;tracing.py&gt;
-
-import decorators,tracedmethod
-object=decorators.decorated(object)
-
-class B(object):
- def __init__(self):
- &quot;[tracedmethod]&quot;
- super(B,self).__init__()
-
-class D(object):
- def __init__(self):
- &quot;[tracedmethod]&quot;
- super(D,self).__init__()
-
-class E(B,D):
- def __init__(self):
- &quot;[tracedmethod]&quot;
- super(E,self).__init__()
-
- #&lt;/tracing.py&gt;
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from tracing import E
-&gt;&gt;&gt; e=E()
-Calling '&lt;E&gt;.__init__' with arguments (){} ...
- Calling '&lt;B&gt;.__init__' with arguments (){} ...
- Calling '&lt;D&gt;.__init__' with arguments (){} ...
- '&lt;D&gt;.__init__' called with result: None
- '&lt;B&gt;.__init__' called with result: None
-'&lt;E&gt;.__init__' called with result: None
-</pre>
-<p>In this example decorating <tt class="literal"><span class="pre">object</span></tt> is the easiest way to go.</p>
-</div>
-<div class="section" id="composition-of-decorators">
-<h1><a class="toc-backref" href="#id7" name="composition-of-decorators">Composition of decorators</a></h1>
-<p>Decorators can be composed: for instance, you can trace a
-classmethod as in this example:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;example6.py&gt;
-
-import tracedmethod
-from decorators import decorated
-object=decorated(object)
-
-class C(object):
- def fact(cls,n):
- &quot;[tracedmethod,classmethod]&quot;
- if n==0: return 1
- else: return n*cls.fact(n-1)
-
-#&lt;/example6.py&gt;
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example6 import C
-&gt;&gt;&gt; C.fact(2)
-Calling 'C.fact' with arguments (2,){} ...
- Calling 'C.fact' with arguments (1,){} ...
- Calling 'C.fact' with arguments (0,){} ...
- 'C.fact' called with result: 1
- 'C.fact' called with result: 1
-'C.fact' called with result: 2
-2
-</pre>
-<p>Under the hood the syntax</p>
-<blockquote>
-<pre class="literal-block">
-[tracedmethod,classmethod]
-</pre>
-</blockquote>
-<p>generates a <tt class="literal"><span class="pre">tracedmethodclassmethod</span></tt> class obtained via
-multiple inheritance:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for c in type(C.__dict__['fact']).__mro__: print c
-...
-&lt;class 'noconflict.tracedmethodclassmethod'&gt;
-&lt;class 'tracedmethod.tracedmethod'&gt;
-&lt;class 'decorators.classmethod'&gt;
-&lt;class 'decorators.MethodDecorator'&gt;
-&lt;class 'decorators.Decorator'&gt;
-&lt;type 'object'&gt;
-</pre>
-<p>In this case the order does not matter and using the docstring
-&quot;[classmethod,tracedmethod]&quot; would work too, but
-in general one must pay attention to precedence issues.
-For instance the following will not work:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... def fact(n):
-... &quot;[staticmethod,tracedmethod]&quot;
-... if n==0: return 1
-... else: return n*C.fact(n-1)
-&gt;&gt;&gt; C.fact(2)
-Traceback (most recent call last):
- ...
-AttributeError: 'function' object has no attribute 'im_func'
-</pre>
-<p>The problem here is that <tt class="literal"><span class="pre">staticmethod.get</span></tt> invokes <tt class="literal"><span class="pre">tracedmethod.get</span></tt>
-which returns a function and not a method-wrapper with an <tt class="literal"><span class="pre">im_func</span></tt> method.
-On the other hand, composing the decorators in the other order
-&quot;[tracedmethod,staticmethod]&quot; will work just fine.</p>
-</div>
-<div class="section" id="class-decorators">
-<h1><a class="toc-backref" href="#id8" name="class-decorators">Class decorators</a></h1>
-<p>PEP 318 proposes to decorate methods by using descriptors; it is
-quite natural to extend this idea and to decorate classes by using
-class decorators implemented as metaclasses. We already saw a
-class decorator at work, the metaclass <tt class="literal"><span class="pre">Decorated</span></tt>, giving
-to its instances the ability to interpret magic docstrings,
-and converting functions in method decorators.</p>
-<p>To define a custom class decorator is easy: one defines a custom metaclasses
-as usual, with the only difference from deriving by <tt class="literal"><span class="pre">ClassDecorator</span></tt> instead
-of deriving from <tt class="literal"><span class="pre">type</span></tt>. To understand how this works in practice, let me
-show how to add logging capabilities to a given class. The first
-step is to define a suitable class decorator, such as the following:</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;logged.py&gt;
-
-from decorators import *
-
-class Logged(ClassDecorator):
- def __init__(cls,name,bases,dic):
- super(Logged,cls).__init__(name,bases,dic)
- print &quot;%s created&quot; % cls
-
-#&lt;/logged.py&gt;
-</pre>
-</blockquote>
-<p><tt class="literal"><span class="pre">Logged</span></tt> is derived by the metaclass <tt class="literal"><span class="pre">ClassDecorator</span></tt>,
-which provides a certain amount of magic under the hood (in particular
-its printing representation and its calling syntax are redefined by its
-metaclass <tt class="literal"><span class="pre">MetaDecorator</span></tt>). Logging capabilities can be added to a class
-by simply using the magic docstring syntax:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from logged import *
-&gt;&gt;&gt; object=decorators.decorated(object)
-&gt;&gt;&gt; class D(object):
-... &quot;[Logged]&quot;
-&lt;class D[_DecoratedLogged]&gt; created
-</pre>
-<p>Notice that <tt class="literal"><span class="pre">D</span></tt> inherits the <tt class="literal"><span class="pre">Decorated</span></tt> metaclass from <tt class="literal"><span class="pre">object</span></tt>
-and the <tt class="literal"><span class="pre">Logged</span></tt> metaclass from the docstring; the conflict is
-automagically avoid by the miracolous creation of a <tt class="literal"><span class="pre">_DecoratedLogged</span></tt>
-metaclass, obtained via multiple inheritance from <tt class="literal"><span class="pre">Decorated</span></tt> and
-<tt class="literal"><span class="pre">Logged</span></tt>. All the magic is performed in the <tt class="literal"><span class="pre">noconflict</span></tt> module,
-discussed in a <a class="reference" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204197">cookbook</a> recipe of mine.</p>
-<p>Notice that the printing representation of <tt class="literal"><span class="pre">D</span></tt> involves the name
-of <tt class="literal"><span class="pre">D</span></tt> preceded by the name of its metaclass, which in this case
-is <tt class="literal"><span class="pre">_DecoratedLogged</span></tt></p>
-<p>Each time an instance of <tt class="literal"><span class="pre">Logged</span></tt> is created, a similar message is printed:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class E(D):
-... pass
-&lt;class E[_DecoratedLogged]&gt; created
-</pre>
-<p>Notice that <tt class="literal"><span class="pre">E</span></tt> does not have any magic docstring</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; E.__doc__ # no docstring
-</pre>
-<p>but still it inherits its magic from <tt class="literal"><span class="pre">D</span></tt>.</p>
-<p>The <tt class="literal"><span class="pre">decorators</span></tt> module provides the already saw class decorator
-<tt class="literal"><span class="pre">Decorated</span></tt>, which converts methods in method decorators.</p>
-<p>Another example is</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;Traced.py&gt;
-
-import tracedmethod
-from decorators import *
-from types import FunctionType
-object=decorated(object)
-
-class Traced(ClassDecorator):
- def __init__(cls,n,b,d):
- for name,func in d.iteritems():
- if isinstance(func,FunctionType):
- func.__doc__=&quot;[tracedmethod] &quot; + (func.__doc__ or '')
- super(Traced,cls).__init__(n,b,d)
-
-class C(object):
- &quot;&quot;&quot;[Traced] The class decorator adds the magic docstring
- '[tracedmethod]' to f1 and f2, which are then converted
- to method decorator objects.&quot;&quot;&quot;
- def f1(self): pass
- def f2(self): pass
-
-c=C()
-
-#&lt;/Traced.py&gt;
-</pre>
-</blockquote>
-<p>Here is an example of usage:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from Traced import C; c=C()
-&gt;&gt;&gt; c.f1()
-Calling '&lt;C&gt;.f1' with arguments (){} ...
-'&lt;C&gt;.f1' called with result: None
-&gt;&gt;&gt; c.f2()
-Calling '&lt;C&gt;.f2' with arguments (){} ...
-'&lt;C&gt;.f2' called with result: None
-</pre>
-</div>
-<div class="section" id="module-decorators">
-<h1><a class="toc-backref" href="#id9" name="module-decorators">Module decorators</a></h1>
-<p>Finally, one can decorate entire modules through the concept of
-<em>module decorators</em>. Module decorators have the ability of decorating
-modules by changing their dictionary. Custom module decorators
-should be derived from the class <tt class="literal"><span class="pre">decorators.ModuleDecorator</span></tt>, by
-cooperatively overriding its <tt class="literal"><span class="pre">__init__(self,mod)</span></tt> method. Writing
-a module decorator is a bit tricky, but I do expect only
-expert programmers to play this kind of game.
-For instance, suppose one wants to trace all the functions in a module,
-unless they have the docstring &quot;-untraced-&quot; . This can be done with a
-suitable module decorator which modifies the module dictionary.
-Here is an example</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;tracefunctions.py&gt;
-
-from decorators import *
-
-class TraceFunctions(ModuleDecorator):
- def __init__(self,mod):
- super(TraceFunctions,self).__init__(mod)
- for name,func in self.__dict__.items():
- if inspect.isfunction(func):
- doc=func.__doc__ or ''
- if doc.startswith('-untraced-'):
- pass # do nothing
- else:
- def tracedfunc(func=func): # default argument trick
- def _(*args,**kw):
- print 'called',func.__name__
- return func(*args,**kw)
- return _
- setattr(self,name,tracedfunc())
-
-#&lt;/tracefunctions.py&gt;
-</pre>
-</blockquote>
-<p>Let me test that the module decorator does its job. Consider the module</p>
-<blockquote>
-<pre class="literal-block">
-#&lt;mod.py&gt;
-
-#&quot;[TraceFunctions]&quot;
-
-def f1(): pass
-
-def f2(): pass
-
-def f3(): &quot;-untraced-&quot;
-
-#&lt;/mod.py&gt;
-</pre>
-</blockquote>
-<p>By importing this module, only the functions <tt class="literal"><span class="pre">f1</span></tt> and <tt class="literal"><span class="pre">f2</span></tt> should
-be traced. This is indeed the case:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from tracefunctions import TraceFunctions
-&gt;&gt;&gt; mod=TraceFunctions('mod',{})
-&gt;&gt;&gt; mod.f1()
-called f1
-&gt;&gt;&gt; mod.f2()
-called f2
-&gt;&gt;&gt; mod.f3() # does nothing, correct
-</pre>
-<blockquote>
-<pre class="literal-block">
-#&lt;module.py&gt;
-
-&quot;Magically decorated module&quot;
-
-import decorators,sys
-
-thismodule=sys.modules[__name__]
-
-class MyClass: &quot;[Decorated]&quot;
-
-newmod=decorators.decorated(thismodule)
-
-#&lt;/module.py&gt;
-</pre>
-</blockquote>
-<pre class="doctest-block">
-&gt;&gt;&gt; from module import *
-&gt;&gt;&gt; assert isinstance(newmod.MyClass, decorators.Decorated)
-&gt;&gt;&gt; assert isinstance(newmod,decorators.DecoratedModule)
-</pre>
-</div>
-<div class="section" id="introspection-features">
-<h1><a class="toc-backref" href="#id10" name="introspection-features">Introspection features</a></h1>
-<p>The module provides three utilities functions to retrieve the list of
-recognized decorators: <tt class="literal"><span class="pre">decorators.methodlike()</span></tt>, <tt class="literal"><span class="pre">decorators.classlike()</span></tt>
-and <tt class="literal"><span class="pre">decorators.modulelike()</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for d in decorators.methodlike(): print d
-...
-MethodDecorator
-tracedmethodclassmethod
-tracedmethod
-classmethod
-chattymethodstaticmethod
-staticmethodtracedmethod
-staticmethod
-chattymethod2
-chattymethod
-&gt;&gt;&gt; decorators.classlike()
-['Traced', 'Logged', '_DecoratedLogged', 'ClassDecorator', '_DecoratedM', 'Decorated', '_DecoratedTraced']
-&gt;&gt;&gt; decorators.modulelike()
-['ModuleDecorator', 'DecoratedModule', 'TraceFunctions']
-</pre>
-</div>
-<div class="section" id="the-implementation">
-<h1><a class="toc-backref" href="#id11" name="the-implementation">The implementation</a></h1>
-<p>This part can be safely skipped, unless you are a <em>really</em> curious and
-you want to know how the implementation works.</p>
-<p>The module is rather short (~250 lines) but far from being trivial,
-since it is based on extensive usage of metaclass wizardry.</p>
-<p>The main class-metaclass hierarchy is represented in figure 1, where
-boxes denote classes and ovals denote metaclasses; instantiation is
-denoted by dashed lines whereas inheritance is denoted by continuous
-lines.</p>
-<div class="figure">
-<p><img alt="decorators.png" src="decorators.png" /></p>
-</div>
-<p>The implementation is relatively smart. Suppose for instance
-that a programmer wrote something like</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from decorators import *
-&gt;&gt;&gt; object=decorated(object)
-&gt;&gt;&gt; class C(object):
-... def f():
-... &quot;[staticmethod,MethodDecorator]&quot;
-</pre>
-<p>to document the fact that <tt class="literal"><span class="pre">staticmethod</span></tt> is a method decorator
-and not the built-in <tt class="literal"><span class="pre">staticmethod</span></tt>. Since <tt class="literal"><span class="pre">staticmethod</span></tt> already
-derives from <tt class="literal"><span class="pre">MethodDecorator</span></tt>, it is redundant to repeat
-<tt class="literal"><span class="pre">MethodDecorator</span></tt>. Apparently, there is the risk of generating
-an useless <tt class="literal"><span class="pre">staticmethodMethodDecorator</span></tt> class, doing the same
-as <tt class="literal"><span class="pre">staticmethod</span></tt>. Fortunately, the implementation is able
-to recognize redundant class. In this case, a class called
-<tt class="literal"><span class="pre">MethodDecoratorDecorator</span></tt> is <em>not</em> created; <tt class="literal"><span class="pre">staticmethod</span></tt>
-is used instead:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print type(C.__dict__['f'])
-&lt;class 'decorators.staticmethod'&gt;
-</pre>
-<p>The current implementation does not make any attempt of optimization and
-there may be alternative implementations faster or more memory efficient.
-At this experimental level I didn't care to explore about performances
-issues. They does not probably matter unless one has to decorate
-thousands or millions of functions and classes.</p>
-<p>Finally, a word about bugs. The <tt class="literal"><span class="pre">decorators</span></tt> module is fairly sophisticated,
-therefore whereas I can guarantee that it passes my test suite (which is extracted
-from the documentation that you are reading), I cannot guarantee that it
-is correct. If somebody finds a bug or an unexpected behavior, please let me
-know and I will try to fix it.</p>
-<!-- References: -->
-</div>
-</div>
-<hr class="footer"/>
-<div class="footer">
-<a class="reference" href="pep318.txt">View document source</a>.
-Generated on: 2003-09-09 16:26 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/pep318/working/pydoc.html b/pypers/pep318/working/pydoc.html
deleted file mode 100755
index 8422868..0000000
--- a/pypers/pep318/working/pydoc.html
+++ /dev/null
@@ -1,504 +0,0 @@
-
-<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html><head><title>Python: module decorators</title>
-</head><body bgcolor="#f0f0f8">
-
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
-<tr bgcolor="#7799ee">
-<td valign=bottom>&nbsp;<br>
-<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>decorators</strong></big></big></font></td
-><td align=right valign=bottom
-><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/mnt/exp/MyDocs/pypers/pep318/decorators.py">/mnt/exp/MyDocs/pypers/pep318/decorators.py</a></font></td></tr></table>
- <p><tt>A&nbsp;module&nbsp;to&nbsp;implement&nbsp;pep318&nbsp;(decorator&nbsp;syntax)&nbsp;via&nbsp;magic&nbsp;doctrings.<br>
-For&nbsp;the&nbsp;documentation&nbsp;see<br>
-&nbsp;<br>
-<a href="http://www.phyast.pitt.edu/~micheles/python/decorators,html">http://www.phyast.pitt.edu/~micheles/python/decorators,html</a><br>
-&nbsp;<br>
-help&nbsp;and&nbsp;pydoc&nbsp;are&nbsp;useful&nbsp;too.</tt></p>
-<p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#aa55cc">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
-
-<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
-<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="__builtin__.html">__builtin__</a><br>
-<a href="inspect.html">inspect</a><br>
-</td><td width="25%" valign=top><a href="noconflict.html">noconflict</a><br>
-<a href="re.html">re</a><br>
-</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
-<a href="types.html">types</a><br>
-</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ee77aa">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
-
-<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
-<td width="100%"><dl>
-<dt><font face="helvetica, arial"><a href="exceptions.html#Exception">exceptions.Exception</a>
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#UnknownDecoratorError">UnknownDecoratorError</a>
-</font></dt></dl>
-</dd>
-<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#Decorator">Decorator</a>
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#ClassDecorator">ClassDecorator</a>(<a href="__builtin__.html#type">__builtin__.type</a>, <a href="decorators.html#Decorator">Decorator</a>)
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#Decorated">Decorated</a>
-</font></dt></dl>
-</dd>
-<dt><font face="helvetica, arial"><a href="decorators.html#MethodDecorator">MethodDecorator</a>
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#classmethod">classmethod</a>
-</font></dt><dt><font face="helvetica, arial"><a href="decorators.html#staticmethod">staticmethod</a>
-</font></dt></dl>
-</dd>
-</dl>
-</dd>
-</dl>
-</dd>
-<dt><font face="helvetica, arial"><a href="__builtin__.html#type">__builtin__.type</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#ClassDecorator">ClassDecorator</a>(<a href="__builtin__.html#type">__builtin__.type</a>, <a href="decorators.html#Decorator">Decorator</a>)
-</font></dt><dd>
-<dl>
-<dt><font face="helvetica, arial"><a href="decorators.html#Decorated">Decorated</a>
-</font></dt></dl>
-</dd>
-<dt><font face="helvetica, arial"><a href="decorators.html#MetaDecorator">MetaDecorator</a>
-</font></dt></dl>
-</dd>
-</dl>
- <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="ClassDecorator">class <strong>ClassDecorator</strong></a>(<a href="__builtin__.html#type">__builtin__.type</a>, <a href="decorators.html#Decorator">Decorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>Metaclass&nbsp;callable&nbsp;with&nbsp;one&nbsp;or&nbsp;three&nbsp;arguments,&nbsp;having&nbsp;its&nbsp;__call__<br>
-method&nbsp;redefined&nbsp;by&nbsp;the&nbsp;meta-metaclass&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.&nbsp;It&nbsp;redefines<br>
-__str__&nbsp;both&nbsp;on&nbsp;classes&nbsp;and&nbsp;instances.<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#ClassDecorator">ClassDecorator</a></dd>
-<dd><a href="__builtin__.html#type">__builtin__.type</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="ClassDecorator-__init__"><strong>__init__</strong></a>(cls, name, bases, dic)</dt></dl>
-
-<dl><dt><a name="ClassDecorator-__str__"><strong>__str__</strong></a>(cls)</dt></dl>
-
-<hr>
-Methods inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><a name="ClassDecorator-__call__"><strong>__call__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__call__">__call__</a>(...)&nbsp;&lt;==&gt;&nbsp;x(...)</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__cmp__"><strong>__cmp__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__cmp__">__cmp__</a>(y)&nbsp;&lt;==&gt;&nbsp;cmp(x,y)</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__hash__"><strong>__hash__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__hash__">__hash__</a>()&nbsp;&lt;==&gt;&nbsp;hash(x)</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#ClassDecorator-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-__subclasses__"><strong>__subclasses__</strong></a>(...)</dt><dd><tt><a href="#ClassDecorator-__subclasses__">__subclasses__</a>()&nbsp;-&gt;&nbsp;list&nbsp;of&nbsp;immediate&nbsp;subclasses</tt></dd></dl>
-
-<dl><dt><a name="ClassDecorator-mro"><strong>mro</strong></a>(...)</dt><dd><tt><a href="#ClassDecorator-mro">mro</a>()&nbsp;-&gt;&nbsp;list<br>
-return&nbsp;a&nbsp;<a href="__builtin__.html#type">type</a>'s&nbsp;method&nbsp;resolution&nbsp;order</tt></dd></dl>
-
-<hr>
-Data and other attributes inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><strong>__base__</strong> = &lt;type 'type'&gt;</dl>
-
-<dl><dt><strong>__bases__</strong> = (&lt;type 'type'&gt;, &lt;class 'decorators.Decorator'&gt;)</dl>
-
-<dl><dt><strong>__basicsize__</strong> = 420</dl>
-
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;</dl>
-
-<dl><dt><strong>__dictoffset__</strong> = 132</dl>
-
-<dl><dt><strong>__flags__</strong> = 22523</dl>
-
-<dl><dt><strong>__itemsize__</strong> = 20</dl>
-
-<dl><dt><strong>__mro__</strong> = (&lt;class 'decorators.ClassDecorator'&gt;, &lt;type 'type'&gt;, &lt;class 'decorators.Decorator'&gt;, &lt;type 'object'&gt;)</dl>
-
-<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#ClassDecorator-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;<a href="__builtin__.html#type">type</a>&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
-
-<dl><dt><strong>__weakrefoffset__</strong> = 184</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Guarantees&nbsp;the&nbsp;calling&nbsp;syntax&nbsp;decorator(obj)<br>
-2.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic<br>
-&nbsp;&nbsp;&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-3.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="Decorated">class <strong>Decorated</strong></a>(<a href="decorators.html#ClassDecorator">ClassDecorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>Metaclass&nbsp;which&nbsp;decorates&nbsp;its&nbsp;instances<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#Decorated">Decorated</a></dd>
-<dd><a href="decorators.html#ClassDecorator">ClassDecorator</a></dd>
-<dd><a href="__builtin__.html#type">__builtin__.type</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="Decorated-__init__"><strong>__init__</strong></a>(cls, name, bases, dic)</dt></dl>
-
-<hr>
-Methods inherited from <a href="decorators.html#ClassDecorator">ClassDecorator</a>:<br>
-<dl><dt><a name="Decorated-__str__"><strong>__str__</strong></a>(cls)</dt></dl>
-
-<hr>
-Methods inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><a name="Decorated-__call__"><strong>__call__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__call__">__call__</a>(...)&nbsp;&lt;==&gt;&nbsp;x(...)</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__cmp__"><strong>__cmp__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__cmp__">__cmp__</a>(y)&nbsp;&lt;==&gt;&nbsp;cmp(x,y)</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__hash__"><strong>__hash__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__hash__">__hash__</a>()&nbsp;&lt;==&gt;&nbsp;hash(x)</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#Decorated-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
-
-<dl><dt><a name="Decorated-__subclasses__"><strong>__subclasses__</strong></a>(...)</dt><dd><tt><a href="#Decorated-__subclasses__">__subclasses__</a>()&nbsp;-&gt;&nbsp;list&nbsp;of&nbsp;immediate&nbsp;subclasses</tt></dd></dl>
-
-<dl><dt><a name="Decorated-mro"><strong>mro</strong></a>(...)</dt><dd><tt><a href="#Decorated-mro">mro</a>()&nbsp;-&gt;&nbsp;list<br>
-return&nbsp;a&nbsp;<a href="__builtin__.html#type">type</a>'s&nbsp;method&nbsp;resolution&nbsp;order</tt></dd></dl>
-
-<hr>
-Data and other attributes inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><strong>__base__</strong> = &lt;class 'decorators.ClassDecorator'&gt;</dl>
-
-<dl><dt><strong>__bases__</strong> = (&lt;class 'decorators.ClassDecorator'&gt;,)</dl>
-
-<dl><dt><strong>__basicsize__</strong> = 420</dl>
-
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;</dl>
-
-<dl><dt><strong>__dictoffset__</strong> = 132</dl>
-
-<dl><dt><strong>__flags__</strong> = 22523</dl>
-
-<dl><dt><strong>__itemsize__</strong> = 20</dl>
-
-<dl><dt><strong>__mro__</strong> = (&lt;class 'decorators.Decorated'&gt;, &lt;class 'decorators.ClassDecorator'&gt;, &lt;type 'type'&gt;, &lt;class 'decorators.Decorator'&gt;, &lt;type 'object'&gt;)</dl>
-
-<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#Decorated-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;<a href="__builtin__.html#type">type</a>&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
-
-<dl><dt><strong>__weakrefoffset__</strong> = 184</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Guarantees&nbsp;the&nbsp;calling&nbsp;syntax&nbsp;decorator(obj)<br>
-2.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic<br>
-&nbsp;&nbsp;&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-3.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="Decorator">class <strong>Decorator</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>Instance&nbsp;of&nbsp;<a href="#MetaDecorator">MetaDecorator</a>,&nbsp;i.e.&nbsp;each&nbsp;time&nbsp;<a href="#Decorator">Decorator</a>&nbsp;is<br>
-subclassed,&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic&nbsp;is&nbsp;updated.<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%">Data and other attributes defined here:<br>
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
-
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Guarantees&nbsp;the&nbsp;calling&nbsp;syntax&nbsp;decorator(obj)<br>
-2.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic<br>
-&nbsp;&nbsp;&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-3.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="MetaDecorator">class <strong>MetaDecorator</strong></a>(<a href="__builtin__.html#type">__builtin__.type</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Guarantees&nbsp;the&nbsp;calling&nbsp;syntax&nbsp;decorator(obj)<br>
-2.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic<br>
-&nbsp;&nbsp;&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-3.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#MetaDecorator">MetaDecorator</a></dd>
-<dd><a href="__builtin__.html#type">__builtin__.type</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="MetaDecorator-__call__"><strong>__call__</strong></a>(dec, *args)</dt><dd><tt>Dispatch&nbsp;to&nbsp;the&nbsp;decorator&nbsp;_call_&nbsp;<a href="#classmethod">classmethod</a></tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__init__"><strong>__init__</strong></a>(dec, *args)</dt></dl>
-
-<hr>
-Data and other attributes defined here:<br>
-<dl><dt><strong>dic</strong> = {'ClassDecorator': &lt;class 'decorators.ClassDecorator'&gt;, 'Decorated': &lt;class 'decorators.Decorated'&gt;, 'Decorator': &lt;class 'decorators.Decorator'&gt;, 'MethodDecorator': &lt;class 'decorators.MethodDecorator'&gt;, 'classmethod': &lt;class 'decorators.classmethod'&gt;, 'staticmethod': &lt;class 'decorators.staticmethod'&gt;}</dl>
-
-<dl><dt><strong>ls</strong> = [&lt;class 'decorators.Decorator'&gt;, &lt;class 'decorators.MethodDecorator'&gt;, &lt;class 'decorators.ClassDecorator'&gt;, &lt;class 'decorators.Decorated'&gt;, &lt;class 'decorators.staticmethod'&gt;, &lt;class 'decorators.classmethod'&gt;]</dl>
-
-<hr>
-Methods inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><a name="MetaDecorator-__cmp__"><strong>__cmp__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__cmp__">__cmp__</a>(y)&nbsp;&lt;==&gt;&nbsp;cmp(x,y)</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__hash__"><strong>__hash__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__hash__">__hash__</a>()&nbsp;&lt;==&gt;&nbsp;hash(x)</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#MetaDecorator-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-__subclasses__"><strong>__subclasses__</strong></a>(...)</dt><dd><tt><a href="#MetaDecorator-__subclasses__">__subclasses__</a>()&nbsp;-&gt;&nbsp;list&nbsp;of&nbsp;immediate&nbsp;subclasses</tt></dd></dl>
-
-<dl><dt><a name="MetaDecorator-mro"><strong>mro</strong></a>(...)</dt><dd><tt><a href="#MetaDecorator-mro">mro</a>()&nbsp;-&gt;&nbsp;list<br>
-return&nbsp;a&nbsp;<a href="__builtin__.html#type">type</a>'s&nbsp;method&nbsp;resolution&nbsp;order</tt></dd></dl>
-
-<hr>
-Data and other attributes inherited from <a href="__builtin__.html#type">__builtin__.type</a>:<br>
-<dl><dt><strong>__base__</strong> = &lt;type 'type'&gt;</dl>
-
-<dl><dt><strong>__bases__</strong> = (&lt;type 'type'&gt;,)</dl>
-
-<dl><dt><strong>__basicsize__</strong> = 420</dl>
-
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;</dl>
-
-<dl><dt><strong>__dictoffset__</strong> = 132</dl>
-
-<dl><dt><strong>__flags__</strong> = 22523</dl>
-
-<dl><dt><strong>__itemsize__</strong> = 20</dl>
-
-<dl><dt><strong>__mro__</strong> = (&lt;class 'decorators.MetaDecorator'&gt;, &lt;type 'type'&gt;, &lt;type 'object'&gt;)</dl>
-
-<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object&gt;<dd><tt>T.<a href="#MetaDecorator-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;<a href="__builtin__.html#type">type</a>&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
-
-<dl><dt><strong>__weakrefoffset__</strong> = 184</dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="MethodDecorator">class <strong>MethodDecorator</strong></a>(<a href="decorators.html#Decorator">Decorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt><a href="#MethodDecorator">MethodDecorator</a>&nbsp;objects&nbsp;provide&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'str'&nbsp;method<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#MethodDecorator">MethodDecorator</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="MethodDecorator-__get__"><strong>__get__</strong></a> = <a href="#MethodDecorator-get">get</a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<dl><dt><a name="MethodDecorator-__init__"><strong>__init__</strong></a>(self, func)</dt></dl>
-
-<dl><dt><a name="MethodDecorator-__str__"><strong>__str__</strong></a>(self)</dt></dl>
-
-<dl><dt><a name="MethodDecorator-get"><strong>get</strong></a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<hr>
-Data and other attributes defined here:<br>
-<dl><dt><strong>__klass__</strong> = &lt;class 'decorators.?'&gt;</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
-
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Guarantees&nbsp;the&nbsp;calling&nbsp;syntax&nbsp;decorator(obj)<br>
-2.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic<br>
-&nbsp;&nbsp;&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-3.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="UnknownDecoratorError">class <strong>UnknownDecoratorError</strong></a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt>The&nbsp;name&nbsp;says&nbsp;it&nbsp;all<br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%">Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
-<dl><dt><a name="UnknownDecoratorError-__getitem__"><strong>__getitem__</strong></a>(...)</dt></dl>
-
-<dl><dt><a name="UnknownDecoratorError-__init__"><strong>__init__</strong></a>(...)</dt></dl>
-
-<dl><dt><a name="UnknownDecoratorError-__str__"><strong>__str__</strong></a>(...)</dt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="classmethod">class <strong>classmethod</strong></a>(<a href="decorators.html#MethodDecorator">MethodDecorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt><a href="#Decorator">Decorator</a>,&nbsp;converts&nbsp;a&nbsp;function&nbsp;in&nbsp;a&nbsp;<a href="#classmethod">classmethod</a><br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#classmethod">classmethod</a></dd>
-<dd><a href="decorators.html#MethodDecorator">MethodDecorator</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="classmethod-__get__"><strong>__get__</strong></a> = <a href="#classmethod-get">get</a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<dl><dt><a name="classmethod-get"><strong>get</strong></a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<hr>
-Methods inherited from <a href="decorators.html#MethodDecorator">MethodDecorator</a>:<br>
-<dl><dt><a name="classmethod-__init__"><strong>__init__</strong></a>(self, func)</dt></dl>
-
-<dl><dt><a name="classmethod-__str__"><strong>__str__</strong></a>(self)</dt></dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#MethodDecorator">MethodDecorator</a>:<br>
-<dl><dt><strong>__klass__</strong> = &lt;class 'decorators.?'&gt;</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
-
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Guarantees&nbsp;the&nbsp;calling&nbsp;syntax&nbsp;decorator(obj)<br>
-2.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic<br>
-&nbsp;&nbsp;&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-3.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table> <p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#ffc8d8">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#000000" face="helvetica, arial"><a name="staticmethod">class <strong>staticmethod</strong></a>(<a href="decorators.html#MethodDecorator">MethodDecorator</a>)</font></td></tr>
-
-<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
-<td colspan=2><tt><a href="#Decorator">Decorator</a>,&nbsp;converts&nbsp;a&nbsp;function&nbsp;in&nbsp;a&nbsp;<a href="#staticmethod">staticmethod</a><br>&nbsp;</tt></td></tr>
-<tr><td>&nbsp;</td>
-<td width="100%"><dl><dt>Method resolution order:</dt>
-<dd><a href="decorators.html#staticmethod">staticmethod</a></dd>
-<dd><a href="decorators.html#MethodDecorator">MethodDecorator</a></dd>
-<dd><a href="decorators.html#Decorator">Decorator</a></dd>
-<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
-</dl>
-<hr>
-Methods defined here:<br>
-<dl><dt><a name="staticmethod-__get__"><strong>__get__</strong></a> = <a href="#staticmethod-get">get</a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<dl><dt><a name="staticmethod-get"><strong>get</strong></a>(self, obj, cls<font color="#909090">=None</font>)</dt></dl>
-
-<hr>
-Methods inherited from <a href="decorators.html#MethodDecorator">MethodDecorator</a>:<br>
-<dl><dt><a name="staticmethod-__init__"><strong>__init__</strong></a>(self, func)</dt></dl>
-
-<dl><dt><a name="staticmethod-__str__"><strong>__str__</strong></a>(self)</dt></dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#MethodDecorator">MethodDecorator</a>:<br>
-<dl><dt><strong>__klass__</strong> = &lt;class 'decorators.?'&gt;</dl>
-
-<hr>
-Data and other attributes inherited from <a href="decorators.html#Decorator">Decorator</a>:<br>
-<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
-
-<dl><dt><strong>__metaclass__</strong> = &lt;class 'decorators.MetaDecorator'&gt;<dd><tt>Metaclass&nbsp;inducing&nbsp;a&nbsp;certain&nbsp;amount&nbsp;of&nbsp;magic&nbsp;on&nbsp;decorators:<br>
-1.&nbsp;Guarantees&nbsp;the&nbsp;calling&nbsp;syntax&nbsp;decorator(obj)<br>
-2.&nbsp;Each&nbsp;time&nbsp;a&nbsp;decorator&nbsp;is&nbsp;defined,&nbsp;it&nbsp;is&nbsp;stored&nbsp;in&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.dic<br>
-&nbsp;&nbsp;&nbsp;and&nbsp;<a href="#MetaDecorator">MetaDecorator</a>.ls.<br>
-3.&nbsp;If&nbsp;the&nbsp;(method)&nbsp;decorator&nbsp;has&nbsp;a&nbsp;'get'&nbsp;method,&nbsp;a&nbsp;'__get__'&nbsp;method<br>
-is&nbsp;automagically&nbsp;created&nbsp;as&nbsp;an&nbsp;alias&nbsp;to&nbsp;'get'.</tt></dl>
-
-<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'Decorator' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;(if&nbsp;defined)</tt></dl>
-
-</td></tr></table></td></tr></table><p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#eeaa77">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
-
-<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
-<td width="100%"><dl><dt><a name="-anyTrue"><strong>anyTrue</strong></a> = sum(...)</dt><dd><tt>sum(sequence,&nbsp;start=0)&nbsp;-&gt;&nbsp;value<br>
-&nbsp;<br>
-Returns&nbsp;the&nbsp;sum&nbsp;of&nbsp;a&nbsp;sequence&nbsp;of&nbsp;numbers&nbsp;(NOT&nbsp;strings)&nbsp;plus&nbsp;the&nbsp;value<br>
-of&nbsp;parameter&nbsp;'start'.&nbsp;&nbsp;When&nbsp;the&nbsp;sequence&nbsp;is&nbsp;empty,&nbsp;returns&nbsp;start.</tt></dd></dl>
- <dl><dt><a name="-decorate"><strong>decorate</strong></a>(objdict)</dt><dd><tt>takes&nbsp;an&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;a&nbsp;dictionary&nbsp;and&nbsp;decorates&nbsp;all&nbsp;its&nbsp;functions<br>
-and&nbsp;classes&nbsp;according&nbsp;to&nbsp;their&nbsp;docstrings.</tt></dd></dl>
- <dl><dt><a name="-decorated"><strong>decorated</strong></a>(obj<font color="#909090">=None</font>)</dt><dd><tt>Returns&nbsp;a&nbsp;new&nbsp;decorated&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;created&nbsp;from&nbsp;obj,&nbsp;or&nbsp;None,&nbsp;if&nbsp;obj<br>
-cannot&nbsp;be&nbsp;decorated.</tt></dd></dl>
- <dl><dt><a name="-decorator_from"><strong>decorator_from</strong></a>(magicstring)</dt><dd><tt>Takes&nbsp;a&nbsp;magic&nbsp;string,&nbsp;i.e.&nbsp;a&nbsp;list&nbsp;of&nbsp;comma-separated&nbsp;decorator&nbsp;names,<br>
-and&nbsp;returns&nbsp;a&nbsp;decorator&nbsp;class&nbsp;or&nbsp;None&nbsp;(if&nbsp;the&nbsp;string&nbsp;is&nbsp;not&nbsp;matched).</tt></dd></dl>
- <dl><dt><a name="-get"><strong>get</strong></a>(magicstring<font color="#909090">='Decorator'</font>)</dt><dd><tt>List&nbsp;of&nbsp;recognized&nbsp;decorators</tt></dd></dl>
- <dl><dt><a name="-magicstring"><strong>magicstring</strong></a>(docstring)</dt></dl>
- <dl><dt><a name="-printerr"><strong>printerr</strong></a>(*args)</dt><dd><tt>For&nbsp;debugging&nbsp;purposes</tt></dd></dl>
-</td></tr></table><p>
-<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
-<tr bgcolor="#55aa55">
-<td colspan=3 valign=bottom>&nbsp;<br>
-<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
-
-<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
-<td width="100%"><strong>MAGICDOC</strong> = &lt;_sre.SRE_Pattern object&gt;<br>
-<strong>err</strong> = &lt;open file 'err', mode 'w'&gt;</td></tr></table>
-</body></html> \ No newline at end of file
diff --git a/pypers/pyj/python-subtilities.html b/pypers/pyj/python-subtilities.html
deleted file mode 100755
index 976402f..0000000
--- a/pypers/pyj/python-subtilities.html
+++ /dev/null
@@ -1,187 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.1: http://docutils.sourceforge.net/" />
-<title>Python gotchas</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="python-gotchas">
-<h1 class="title">Python gotchas</h1>
-<p>One of the strenghts of Python is its ability to be easy to understand and
-unsurprising most of the times. However, easy does not mean trivial and
-there actually situations where Python can surprise the new user (and
-sometimes even the old timer). In this rubric we will discuss few of
-those Python gotchas.</p>
-<p>The choice will be based on questions which are periodically asked on
-the Python newsgroup: the fact that those questions are repeated means
-that i) they are non-trivial and ii) more than few persons are caught
-by those gotchas.</p>
-<p>I will start with a gotcha who got me actually, and was the reason
-for my first post on comp.lang.python.</p>
-<p>The issue has been discussed in many threads on comp.lang.python; the
-one where I understood the issue is this one:</p>
-<p><a class="reference" href="http://groups.google.it/groups?hl=it&amp;lr=&amp;ie=UTF-8&amp;oe=UTF-8&amp;threadm=tyfsmgtbewl.fsf%40lxplus030.cern.ch&amp;rnum=1&amp;prev=/groups%3Fhl%3Dit%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3Dsimionato%2Blambda%26btnG%3DCerca%26meta%3Dgroup%253Dcomp.lang.python">http://groups.google.it/groups?hl=it&amp;lr=&amp;ie=UTF-8&amp;oe=UTF-8&amp;threadm=tyfsmgtbewl.fsf%40lxplus030.cern.ch&amp;rnum=1&amp;prev=/groups%3Fhl%3Dit%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3Dsimionato%2Blambda%26btnG%3DCerca%26meta%3Dgroup%253Dcomp.lang.python</a>.*</p>
-<div class="section" id="statement-of-the-issue">
-<h1><a name="statement-of-the-issue">Statement of the issue</a></h1>
-<p>This gotcha is related to the scope rules of Python in loops: it often
-appears in conjunction with lambda functions, but actually has nothing
-to do with them, since lambda functions are not special at all in
-Python. To show what the surprising behaviour is, consider the
-following code:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def make_adders(n):
-... return [(lambda x: x+i) for i in range(n)]
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; add0,add1=make_adders(n=2)
-</pre>
-<p>Now, it is clear what add1(0) will do:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; add1(0)
-1
-</pre>
-<p>The surprise is with add0(0), which does not return 0, as you
-would probably expect:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; add0(0)
-1
-</pre>
-<p>The issue has nothing to do with lambda functions and list comprehensions,
-since</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def make_adders(n):
-... ls=[]
-... for i in range(n):
-... def f(x):
-... return x+i
-... ls.append(f)
-... return ls
-</pre>
-<p>has the same exact behavior:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; add1(0)
-1
-&gt;&gt;&gt; add0(0)
-1
-</pre>
-<p>The behavior is even more surprising if you think that other languages
-(such as Haskell, the language from which Python stole list comprehensions)
-do the &quot;right&quot; thing, i.e.</p>
-<pre class="literal-block">
-Prelude&gt; let make-adders n = [ \x -&gt; x + i | i &lt;- [0..n-1] ]
-Prelude&gt; let [add0,add1] = make_adders 2
-Prelude&gt; add0 0
-0
-Prelude&gt; add1 0
-1
-</pre>
-<p>(this example was provided to me by a Haskell expert, I never actually used
-the language, but I report it here just to show that there are languages
-where you get what you expect).</p>
-<p>So one could consider this as a Python wart. However, the truth is more
-complex.</p>
-</div>
-<div class="section" id="explanation-of-the-issue">
-<h1><a name="explanation-of-the-issue">Explanation of the issue</a></h1>
-<p>The reason why Python acts as it does, is that <em>by design</em> Python
-loops (both &quot;for&quot; loops and &quot;while&quot; loops) do not introduce a new
-scope.</p>
-<p>So, if I write</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; a = 1 # no-new-scope
-&gt;&gt;&gt; for i in range(1,10):
-... a = i
-... if i == 2: break
-&gt;&gt;&gt; a
-2
-</pre>
-<p>the &quot;a&quot; inside the for loop is exactly the same as the &quot;a&quot; defined outside
-the &quot;for&quot; loop. This is what I want: if the &quot;for&quot; loop introduced a new
-scope, then the inner &quot;a&quot; would be a local variable and the result of
-this code would be &quot;a=1&quot; for the original global variable. Since
-Python does not have the ability to rebind variables in outer scopes,
-there would be no way to change &quot;a&quot; from inside the loop <a class="footnote-reference" href="#id2" id="id1" name="id1">[1]</a>.</p>
-<p>But what exactly happens, when Python encounters a &quot;for&quot; loop?
-The answer is that the form</p>
-<pre class="literal-block">
-for i in iterable:
- &lt;do_something i&gt;
-</pre>
-<p>is essentially interpreted as</p>
-<pre class="literal-block">
-try:
- it = iter(iterable)
- while True:
- i = it.next()
- &lt;do_something i&gt;
-except StopIteration:
- pass
-</pre>
-<p>As you see, this does not introduce any new scope. In order to solve the
-&quot;issue&quot; you have to introduce a new scope. In Python, the natural way
-to introduce a new scope is via a function.
-If the &quot;for&quot; loop was interpreted as follows</p>
-<pre class="literal-block">
-try:
- it = iter(iterable)
- def helper(i): # helper function
- &lt;do_something i&gt;
- while True:
- helper(it.next())
-except StopIteration:
- pass
-</pre>
-<p>then a new &quot;i&quot; would enter in the scope at each iteration.</p>
-<p>For instance, in the example I am talking about,</p>
-<pre class="literal-block">
-def make_adders(n):
- return [lambda x: x+i for i in range(n)]
-</pre>
-<p>would be interpreted as</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def make_adders(n):
-... try:
-... adders=[]
-... it = iter(range(2))
-... def helper(i):
-... adders.append(lambda x: x+i)
-... while True:
-... helper(it.next())
-... except StopIteration:
-... return adders
-</pre>
-<p>You can check that with this definition <tt class="literal"><span class="pre">make_adders</span></tt> does the right thing:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; add0,add1 = make_adders(n=2)
-&gt;&gt;&gt; add1(0)
-1
-&gt;&gt;&gt; add0(0)
-0
-</pre>
-<p>Essentially, the &quot;i&quot; variable would be passed via the helper function
-call and at each iteration the lambda function would see a different
-value of it.</p>
-<p>Unfortunately, changing Python &quot;for&quot; loops in this way would cause
-an even worse wart, as I discussed in the <tt class="literal"><span class="pre">no-new-scope</span></tt> example.</p>
-<p>That is the reason why the present behavior will
-not change.</p>
-<table class="footnote" frame="void" id="id2" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1" name="id2">[1]</a></td><td>Unless you use contorsion involving making &quot;a&quot; an element of
-a mutable container.</td></tr>
-</tbody>
-</table>
-</div>
-</div>
-<hr class="footer" />
-<div class="footer">
-<a class="reference" href="python-subtilities.txt">View document source</a>.
-Generated on: 2004-05-03 15:26 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/recipes/doctester.html b/pypers/recipes/doctester.html
deleted file mode 100755
index 0223832..0000000
--- a/pypers/recipes/doctester.html
+++ /dev/null
@@ -1,130 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.7: http://docutils.sourceforge.net/" />
-<title></title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-<p>I use this little script a lot: to test my posts to
-c.l.py, to test my articles, and to test my libraries.
-Since the script is extremely simple and useful, I thought I
-will share it.</p>
-<p>The first thing you need is a text like this, with
-cut and pasted interpreter sessions:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; 1 + 1
-2
-</pre>
-<p>The doctester will look for snippets of this form and will
-test them. The magic is performed by the doctest module in the
-standard library. I have just added the possibity of inserting
-named modules in the text file, like this one:</p>
-<pre class="literal-block">
-#&lt;example_module.py&gt;
-
-a = 1
-
-#&lt;/example_module.py&gt;
-</pre>
-<p>The doctester will extract code like this and save it in your
-current directory, under the name <tt class="docutils literal"><span class="pre">example_module.py</span></tt>,
-<em>before</em> running the tests. In this way you can import
-the module in your tests:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example_module import a
-&gt;&gt;&gt; print a
-1
-</pre>
-<p>You may define any number of modules in the same way.
-You can also add code to a previously defined module, simply by
-repeating the module name:</p>
-<pre class="literal-block">
-#&lt;example_module.py&gt;
-
-b = 2
-
-#&lt;/example_module.py&gt;
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; from example_module import b
-&gt;&gt;&gt; print b
-2
-</pre>
-<p>Ideally, in future extensions, it will be possible to insert snippets
-of code in other languages (for instance bash).</p>
-<p>The doctester can be used from the command line or called from
-an external program. For instance, you could pass to the doctester
-this text you are reading now: suppose it is stored in a file
-called doctester.txt, you will get</p>
-<pre class="literal-block">
-$ python doctester.py &lt; doctester.txt
-doctest: 0 failed 5 ok
-</pre>
-<p>or, if you prefer a more explicit output,</p>
-<pre class="literal-block">
-$ python doctester.py -v &lt; doctester.txt
-Trying:
- 1 + 1
-Expecting:
- 2
-ok
-Trying:
- from example_module import a
-Expecting nothing
-ok
-Trying:
- print a
-Expecting:
- 1
-ok
-Trying:
- from example_module import b
-Expecting nothing
-ok
-Trying:
- print b
-Expecting:
- 2
-ok
-1 items passed all tests:
- 5 tests in &lt;current-buffer&gt;
-5 tests in 1 items.
-5 passed and 0 failed.
-Test passed.
-</pre>
-<p>The message says that the tests were defined in '&lt;current-buffer&gt;': the
-reason is that I usually call the doctester from Emacs, when I am editing
-the text. If you have Python 2.4 and the doctester in installed in
-your current Python path, you can just put the following in your .emacs:</p>
-<pre class="literal-block">
-;; passing the current buffer to an external tool
-(defun run-doctest ()
- (interactive)
- (shell-command-on-region (beginning-of-buffer)
- (end-of-buffer)
- &quot;python2.4 -m doctester&quot;
- current-prefix-arg
- current-prefix-arg))
-
-(defun run-doctest-verbose ()
- (interactive)
- (shell-command-on-region (beginning-of-buffer)
- (end-of-buffer)
- &quot;python2.4 -m doctester -v&quot;
- current-prefix-arg
- current-prefix-arg))
-
-;; F6 for regular output, SHIFT-F6 for verbose output
-(global-set-key [f6] 'run-doctest)
-(global-set-key [(shift f6)] 'run-doctest-verbose)
-</pre>
-<p>If you have Python 2.3 you may want to work a bit more, or
-just insert the full pathname of the doctester script.
-Obviously you may change the keybindings to whatever you like.</p>
-</div>
-</body>
-</html>
diff --git a/pypers/recipes/optparse.html b/pypers/recipes/optparse.html
deleted file mode 100755
index 1399714..0000000
--- a/pypers/recipes/optparse.html
+++ /dev/null
@@ -1,94 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.1: http://docutils.sourceforge.net/" />
-<title>Parsing the command line</title>
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="parsing-the-command-line">
-<h1 class="title">Parsing the command line</h1>
-<p>The module optparse was a great addition to Python 2.3, since it is much more
-powerful and easier to use than getopt. Using optparse, writing command-line
-tools is a breeze. However, the power of optparse comes together with a certain
-verbosity. This recipe allows to use optparse with a minimum of boilerplate,
-trading flexibility for easy of use. Still, it covers 95% of my common needs,
-so I think it may be useful to others.</p>
-<p>The following script is an example of how to use the optionparse module.</p>
-<p>&lt;pre&gt;</p>
-<p>&quot;&quot;&quot;An example script invoking optionparse.</p>
-<blockquote>
-usage: %prog [options] args
--p, --positional: print positional arguments
--1, --option1=OPTION1: print option1
--2, --option2=OPTION2: print option2</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>optparse.txt</tt>, line 21)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<p>&quot;&quot;&quot;</p>
-<p>import optionparse
-opt, args = optionparse.parse(__doc__)
-if not opt and not args:</p>
-<div class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<tt>optparse.txt</tt>, line 26)</p>
-Unexpected indentation.</div>
-<blockquote>
-optionparse.exit()</blockquote>
-<div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<tt>optparse.txt</tt>, line 27)</p>
-Block quote ends without a blank line; unexpected unindent.</div>
-<dl>
-<dt>if opt.positional:</dt>
-<dd>print args</dd>
-<dt>if opt.option1:</dt>
-<dd>print opt.option1</dd>
-<dt>if opt.option2:</dt>
-<dd>print opt.option2</dd>
-</dl>
-<p>&lt;/pre&gt;</p>
-<p>The optionparse.parse() function parses the docstring and internally builds
-an option parser object using optparse; then it uses that parser to
-parse the command line arguments. It returns an object containing
-the given options and a list of positional arguments.</p>
-<p>If no options and positional arguments are given, the script
-exits and returns an useful message:</p>
-<p>&lt;pre&gt;</p>
-<p>$ python example.py
-An example script invoking optionparse.</p>
-<blockquote>
-usage: example.py [options] args
--p, --positional: print positional arguments
--1, --option1=OPTION1: print option1
--2, --option2=OPTION2: print option2</blockquote>
-<p>&lt;/pre&gt;</p>
-<p>A similar message is also obtained if the -h or --help option is
-passed.</p>
-<p>If the -p flag is passed, the list of positional arguments is displayed:</p>
-<p>&lt;pre&gt;</p>
-<p>$ python example.py -p <a href="#id1" name="id2"><span class="problematic" id="id2">*</span></a>.txt
-[&lt;the list of text files in the current directory&gt;]</p>
-<div class="system-message" id="id1">
-<p class="system-message-title">System Message: <a name="id1">WARNING/2</a> (<tt>optparse.txt</tt>, line 63); <em><a href="#id2">backlink</a></em></p>
-Inline emphasis start-string without end-string.</div>
-<p>&lt;/pre&gt;</p>
-<p>If the option argument 1 or 2 are passed, they are displayed:</p>
-<p>&lt;pre&gt;</p>
-<p>$ python example.py -1file1.txt -2file2.txt
-file1.txt
-file2.txt</p>
-<p>&lt;/pre&gt;</p>
-<p>I think you get the idea. Notice that with the current implementation
-there are restrictions with the format of the usage block in the
-docstring: for instance it cannot contain blank lines and one must
-be careful with characters such as &quot;:&quot; &quot;,&quot; &quot;=&quot;.</p>
-</div>
-<hr class="footer" />
-<div class="footer">
-<a class="reference" href="optparse.txt">View document source</a>.
-Generated on: 2004-04-18 07:16 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/simionato_talk/formulas.html b/pypers/simionato_talk/formulas.html
deleted file mode 100644
index c98eec7..0000000
--- a/pypers/simionato_talk/formulas.html
+++ /dev/null
@@ -1,329 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" />
-<meta name="version" content="S5 1.1" />
-<title></title>
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-12-18 01:56:14 +0100 (Sun, 18 Dec 2005) $
-:Revision: $Revision: 4224 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-
-See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
-customize this style sheet.
-*/
-
-/* used to remove borders from tables and images */
-.borderless, table.borderless td, table.borderless th {
- border: 0 }
-
-table.borderless td, table.borderless th {
- /* Override padding for "table.docutils td" with "! important".
- The right padding separates the table cells. */
- padding: 0 0.5em 0 0 ! important }
-
-.first {
- /* Override more specific margin styles with "! important". */
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em ;
- margin-right: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid 1px gray;
- margin-left: 1px }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid 1px black;
- margin-left: 1px }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-<!-- configuration parameters -->
-<meta name="defaultView" content="slideshow" />
-<meta name="controlVis" content="hidden" />
-<!-- style sheet links -->
-<script src="ui/default/slides.js" type="text/javascript"></script>
-<link rel="stylesheet" href="ui/default/slides.css"
- type="text/css" media="projection" id="slideProj" />
-<link rel="stylesheet" href="ui/default/outline.css"
- type="text/css" media="screen" id="outlineStyle" />
-<link rel="stylesheet" href="ui/default/print.css"
- type="text/css" media="print" id="slidePrint" />
-<link rel="stylesheet" href="ui/default/opera.css"
- type="text/css" media="projection" id="operaFix" />
-
-<style type="text/css">
-#currentSlide {display: none;}
-</style>
-</head>
-<body>
-<div class="layout">
-<div id="controls"></div>
-<div id="currentSlide"></div>
-<div id="header">
-
-</div>
-<div id="footer">
-
-</div>
-</div>
-<div class="presentation">
-<div class="slide" id="slide0">
-<math xmlns='http://www.w3.org/1998/Math/MathML'>
-<mi>&Phi;</mi>
-<mo>(</mo><mi>x</mi><mo>)</mo><mo>=</mo><mfrac><mn>12</mn><mo>+</mo></mfrac><mfrac><mn>12</mn><mi>erf</mi></mfrac><mo>(</mo><mi>x</mi><mo>/</mo><msqrt><mo>(</mo></msqrt><mn>2</mn><mo>)</mo><mo>)</mo>
-</math></div>
-</div>
-</body>
-</html>
diff --git a/pypers/simionato_talk/talk.html b/pypers/simionato_talk/talk.html
deleted file mode 100644
index 925b833..0000000
--- a/pypers/simionato_talk/talk.html
+++ /dev/null
@@ -1,1207 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" />
-<meta name="version" content="S5 1.1" />
-<title>SciPy on WSGI</title>
-<meta name="organization" content="StatPro Italy" />
-<meta name="date" content="2007-06-09" />
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-12-18 01:56:14 +0100 (Sun, 18 Dec 2005) $
-:Revision: $Revision: 4224 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-
-See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
-customize this style sheet.
-*/
-
-/* used to remove borders from tables and images */
-.borderless, table.borderless td, table.borderless th {
- border: 0 }
-
-table.borderless td, table.borderless th {
- /* Override padding for "table.docutils td" with "! important".
- The right padding separates the table cells. */
- padding: 0 0.5em 0 0 ! important }
-
-.first {
- /* Override more specific margin styles with "! important". */
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em ;
- margin-right: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid 1px gray;
- margin-left: 1px }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid 1px black;
- margin-left: 1px }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-<!-- configuration parameters -->
-<meta name="defaultView" content="slideshow" />
-<meta name="controlVis" content="hidden" />
-<!-- style sheet links -->
-<script src="ui/default/slides.js" type="text/javascript"></script>
-<link rel="stylesheet" href="ui/default/slides.css"
- type="text/css" media="projection" id="slideProj" />
-<link rel="stylesheet" href="ui/default/outline.css"
- type="text/css" media="screen" id="outlineStyle" />
-<link rel="stylesheet" href="ui/default/print.css"
- type="text/css" media="print" id="slidePrint" />
-<link rel="stylesheet" href="ui/default/opera.css"
- type="text/css" media="projection" id="operaFix" />
-
-<style type="text/css">
-#currentSlide {display: none;}
-</style>
-</head>
-<body>
-<div class="layout">
-<div id="controls"></div>
-<div id="currentSlide"></div>
-<div id="header">
-
-</div>
-<div id="footer">
-<h1>SciPy on WSGI</h1>
-<h2>PyCon Uno 2007 - 09 June 2007</h2>
-</div>
-</div>
-<div class="presentation">
-<div class="slide" id="slide0">
-<h1 class="title">SciPy on WSGI</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr class="field"><th class="docinfo-name">Talk given at:</th><td class="field-body">PyCon Uno 2007</td>
-</tr>
-<tr class="field"><th class="docinfo-name">By:</th><td class="field-body">Michele Simionato</td>
-</tr>
-<tr><th class="docinfo-name">Organization:</th>
-<td>StatPro Italy</td></tr>
-<tr><th class="docinfo-name">Date:</th>
-<td>2007-06-09</td></tr>
-</tbody>
-</table>
-<!-- Definitions of interpreted text roles (classes) for S5/HTML data. -->
-<!-- This data file has been placed in the public domain. -->
-<!-- Colours
-======= -->
-<!-- Text Sizes
-========== -->
-<!-- Display in Slides (Presentation Mode) Only
-========================================== -->
-<!-- Display in Outline Mode Only
-============================ -->
-<!-- Display in Print Only
-===================== -->
-<!-- Incremental Display
-=================== -->
-<p class="center"><strong>Subtitle</strong>: <em>Science on the Web for pedestrians</em></p>
-
-</div>
-<div class="slide" id="before-i-start">
-<h1>Before I start</h1>
-<p>What about you?</p>
-<p class="incremental">Are you more of a programmer or more of a scientist/engineer?</p>
-<p class="incremental">What kind of scientific tools are you using, if any?</p>
-<p class="incremental">Have you ever heard of SciPy?</p>
-<p class="incremental">Have you ever heard of WSGI?</p>
-</div>
-<div class="slide" id="ok-now-i-can-begin">
-<h1>Ok, now I can begin ;)</h1>
-<p>The motivation from this talk comes from a real problem at <a class="reference" href="http://www.statpro.com">StatPro</a></p>
-<p class="incremental">we have bad histories for many financial products</p>
-<p class="incremental">wrong prices at some dates in the past</p>
-</div>
-<div class="slide" id="a-picture">
-<h1>A picture</h1>
-<img alt="badpricehistory.png" src="badpricehistory.png" />
-<p class="incremental">(damn data providers!)</p>
-</div>
-<div class="slide" id="discarding-values">
-<h1>Discarding values ...</h1>
-<img alt="badpricehistory2.png" src="badpricehistory2.png" />
-<p>... is tricky!</p>
-</div>
-<div class="slide" id="issues">
-<h1>Issues</h1>
-<p>We cannot use the conventional criterium</p>
-<img alt="nongaussian.png" class="incremental" src="nongaussian.png" />
-</div>
-<div class="slide" id="strategy">
-<h1>Strategy</h1>
-<ul class="incremental simple">
-<li>price distributions (ln p_i/p) are known to decay with power laws</li>
-<li>fit the distributions with a &quot;reasonable&quot; curve and determine
-a suitable criterium for the spikes at some confidence level</li>
-<li>a reasonably simple ansatz gives a family of distributions depending
-on a parameter delta</li>
-<li><a class="reference" href="formulas.pdf">show formulae</a></li>
-</ul>
-</div>
-<div class="slide" id="delta-distribution">
-<h1>delta-distribution</h1>
-<img alt="delta-dist.png" src="delta-dist.png" />
-<p>From Dirac delta (delta -&gt; 0) to Gaussian
-distribution (delta -&gt; oo)</p>
-</div>
-<div class="slide" id="cumulative-dist">
-<h1>Cumulative dist</h1>
-<img alt="cdf-dist.png" src="cdf-dist.png" />
-<p>VAR-XX = Max loss at XX% confidence level [<a class="reference" href="http://integrals.wolfram.com/index.jsp">i</a>]</p>
-</div>
-<div class="slide" id="relation-var-vol">
-<h1>Relation VAR-vol.</h1>
-<p>If you assume a given distribution, there is a fixed relation between
-VAR-XX and volatility</p>
-<ul class="incremental simple">
-<li>for the Gaussian VAR-95 = 1.64 sigma, for a lot of our distributions
-VAR-95 &lt; 1.0 sigma</li>
-<li>we don't want to make assumptions on the distribution function
-for computing the VAR</li>
-<li>but we are willing to make assumptions for the sake of eliminating
-statistically invalid values</li>
-</ul>
-</div>
-<div class="slide" id="the-tool-we-need">
-<h1>The tool we need</h1>
-<pre class="literal-block">
-$ python simpleplotter.py &quot;fri-gb;AVE&quot;
-</pre>
-<p>(not 100% finished yet!)</p>
-</div>
-<div class="slide" id="enter-scipy-co">
-<h1>Enter SciPy &amp; Co.</h1>
-<p>In order to perform our analysis we looked
-at many scientific tools</p>
-<ul class="incremental simple">
-<li>a good plotting tool (matplotlib)</li>
-<li>support for histograms (matplotlib)</li>
-<li>support for special functions (scipy.special)</li>
-<li>support for non-linear fitting (scipy.leastsq)</li>
-<li>good performance (scipy)</li>
-<li>interactive and IPython-friendly (scipy)</li>
-<li>bla-bla</li>
-<li>cheating: I actually used Gnuplot!! ;-)</li>
-</ul>
-</div>
-<div class="slide" id="installation">
-<h1>Installation</h1>
-<p>If you are lucky, it is trivial:</p>
-<pre class="literal-block">
-$ apt-get install ipython
-$ apt-get install python-matplotlib
-$ apt-get install python-numpy
-$ apt-get install python-numpy-ext
-$ apt-get install python-scipy
-</pre>
-<p>If you are unlucky, or if you try to build from sources,
-YMMV ...</p>
-</div>
-<div class="slide" id="what-s-in-scipy">
-<h1>What's in Scipy</h1>
-<ul class="incremental simple">
-<li>support for multi-dimensional array (numpy)</li>
-<li>linear algebra and minimization routines</li>
-<li>solving, integration, interpolation, fitting</li>
-<li>special functions and statistical functions</li>
-<li>etc. etc.</li>
-</ul>
-</div>
-<div class="slide" id="special-functions">
-<h1>Special functions</h1>
-<p>Airy Functions:</p>
-<pre class="literal-block">
-airy
---Airy functions and their derivatives.
-airye
---Exponentially scaled Airy functions
-ai_zeros
---Zeros of Airy functions Ai(x) and Ai'(x)
-bi_zeros
---Zeros of Airy functions Bi(x) and Bi'(x)
-</pre>
-</div>
-<div class="slide" id="elliptic-functions-and-integrals">
-<h1>Elliptic Functions and Integrals</h1>
-<pre class="literal-block">
-ellipj
---Jacobian elliptic functions
-ellipk
---Complete elliptic integral of the first kind.
-ellipkinc
---Incomplete elliptic integral of the first kind.
-ellipe
---Complete elliptic integral of the second kind.
-ellipeinc
---Incomplete elliptic integral of the second kind.
-</pre>
-</div>
-<div class="slide" id="bessel-functions">
-<h1>Bessel Functions</h1>
-<pre class="literal-block">
-jn
---Bessel function of integer order and real argument.
-jv
---Bessel function of real-valued order and complex argument.
-jve
---Exponentially scaled Bessel function.
-yn
---Bessel function of second kind (integer order).
-yv
---Bessel function of the second kind (real-valued order).
-yve
---Exponentially scaled Bessel function of the second kind.
-kn
---Modified Bessel function of the third kind (integer order).
-kv
---Modified Bessel function of the third kind (real order).
-kve
---Exponentially scaled modified Bessel function of the third kind.
-iv
---Modified Bessel function.
-ive
---Exponentially scaled modified Bessel function.
-hankel1
---Hankel function of the first kind.
-hankel1e
---Exponentially scaled Hankel function of the first kind.
-hankel2
---Hankel function of the second kind.
-hankel2e
---Exponentially scaled Hankel function of the second kind.
-
-lmbda
---Sequence of lambda functions with arbitrary order v.
-</pre>
-</div>
-<div class="slide" id="zeros-of-bessel-functions">
-<h1>Zeros of Bessel Functions</h1>
-<pre class="literal-block">
-jnjnp_zeros
---Zeros of integer-order Bessel functions and derivatives
- sorted in order.
-jnyn_zeros
---Zeros of integer-order Bessel functions and derivatives
- as separate arrays.
-jn_zeros
---Zeros of Jn(x)
-jnp_zeros
---Zeros of Jn'(x)
-yn_zeros
---Zeros of Yn(x)
-ynp_zeros
---Zeros of Yn'(x)
-y0_zeros
---Complex zeros: Y0(z0)=0 and values of Y0'(z0)
-y1_zeros
---Complex zeros: Y1(z1)=0 and values of Y1'(z1)
-y1p_zeros
---Complex zeros of Y1'(z1')=0 and values of Y1(z1')
-</pre>
-</div>
-<div class="slide" id="faster-versions">
-<h1>Faster versions</h1>
-<pre class="literal-block">
-j0
---Bessel function of order 0.
-j1
---Bessel function of order 1.
-y0
---Bessel function of second kind of order 0.
-y1
---Bessel function of second kind of order 1.
-i0
---Modified Bessel function of order 0.
-i0e
---Exponentially scaled modified Bessel function of order 0.
-i1
---Modified Bessel function of order 1.
-i1e
---Exponentially scaled modified Bessel function of order 1.
-k0
---Modified Bessel function of the third kind of order 0.
-k0e
---Exponentially scaled modified Bessel function of the
- third kind of order 0.
-k1
---Modified Bessel function of the third kind of order 1.
-k1e
---Exponentially scaled modified Bessel function of the
- third kind of order 1.
-</pre>
-</div>
-<div class="slide" id="integrals-of-bessel-functions">
-<h1>Integrals of Bessel Functions</h1>
-<pre class="literal-block">
-itj0y0
---Basic integrals of j0 and y0 from 0 to x.
-it2j0y0
---Integrals of (1-j0(t))/t from 0 to x and
- y0(t)/t from x to inf.
-iti0k0
---Basic integrals of i0 and k0 from 0 to x.
-it2i0k0
---Integrals of (i0(t)-1)/t from 0 to x and
- k0(t)/t from x to inf.
-besselpoly
---Integral of a bessel function: Jv(2*a*x) * x^lambda
- from x=0 to 1.
-</pre>
-</div>
-<div class="slide" id="derivatives-of-bessel-functions">
-<h1>Derivatives of Bessel Functions</h1>
-<pre class="literal-block">
-jvp
---Nth derivative of Jv(v,z)
-yvp
---Nth derivative of Yv(v,z)
-kvp
---Nth derivative of Kv(v,z)
-ivp
---Nth derivative of Iv(v,z)
-h1vp
---Nth derivative of H1v(v,z)
-h2vp
---Nth derivative of H2v(v,z)
-</pre>
-</div>
-<div class="slide" id="spherical-bessel-functions">
-<h1>Spherical Bessel Functions</h1>
-<pre class="literal-block">
-sph_jn
---Sequence of spherical Bessel functions, jn(z)
-sph_yn
---Sequence of spherical Bessel functions, yn(z)
-sph_jnyn
---Sequence of spherical Bessel functions, jn(z) and yn(z)
-sph_in
---Sequence of spherical Bessel functions, in(z)
-sph_kn
---Sequence of spherical Bessel functions, kn(z)
-sph_inkn
---Sequence of spherical Bessel functions, in(z) and kn(z)
-</pre>
-</div>
-<div class="slide" id="riccati-bessel-fun">
-<h1>Riccati-Bessel Fun.</h1>
-<pre class="literal-block">
-riccati_jn
---Sequence of Ricatti-Bessel functions
- of first kind.
-riccati_yn
---Sequence of Ricatti-Bessel functions
- of second kind.
-</pre>
-</div>
-<div class="slide" id="struve-functions">
-<h1>Struve Functions</h1>
-<pre class="literal-block">
-struve
---Struve function --- Hv(x)
-modstruve
---Modified struve function --- Lv(x)
-itstruve0
---Integral of H0(t) from 0 to x
-it2struve0
---Integral of H0(t)/t from x to Inf.
-itmodstruve0
---Integral of L0(t) from 0 to x.
-</pre>
-</div>
-<div class="slide" id="statistical-functions">
-<h1>Statistical Functions</h1>
-<pre class="literal-block">
-bdtr
---Sum of terms 0 through k of of the binomial pdf.
-bdtrc
---Sum of terms k+1 through n of the binomial pdf.
-bdtri
---Inverse of bdtr
-btdtr
---Integral from 0 to x of beta pdf.
-btdtri
---Quantiles of beta distribution
-fdtr
---Integral from 0 to x of F pdf.
-fdtrc
---Integral from x to infinity under F pdf.
-fdtri
---Inverse of fdtrc
-gdtr
---Integral from 0 to x of gamma pdf.
-gdtrc
---Integral from x to infinity under gamma pdf.
-gdtri
---Quantiles of gamma distribution
-nbdtr
---Sum of terms 0 through k of the negative binomial pdf.
-nbdtrc
---Sum of terms k+1 to infinity under negative binomial pdf.
-nbdtri
---Inverse of nbdtr
-pdtr
---Sum of terms 0 through k of the Poisson pdf.
-pdtrc
---Sum of terms k+1 to infinity of the Poisson pdf.
-pdtri
---Inverse of pdtr
-stdtr
---Integral from -infinity to t of the Student-t pdf.
-stdtri
---Inverse of stdtr (quantiles)
-chdtr
---Integral from 0 to x of the Chi-square pdf.
-chdtrc
---Integral from x to infnity of Chi-square pdf.
-chdtri
---Inverse of chdtrc.
-ndtr
---Integral from -infinity to x of standard normal pdf
-ndtri
---Inverse of ndtr (quantiles)
-smirnov
---Kolmogorov-Smirnov complementary CDF for one-sided
- test statistic (Dn+ or Dn-)
-smirnovi
---Inverse of smirnov.
-kolmogorov
---The complementary CDF of the (scaled) two-sided test
- statistic (Kn*) valid for large n.
-kolmogi
---Inverse of kolmogorov
-tklmbda
---Tukey-Lambda CDF
-</pre>
-</div>
-<div class="slide" id="gamma-and-related-functions">
-<h1>Gamma and Related Functions</h1>
-<pre class="literal-block">
-gamma
---Gamma function.
-gammaln
---Log of the absolute value of the gamma function.
-gammainc
---Incomplete gamma integral.
-gammaincinv
---Inverse of gammainc.
-gammaincc
---Complemented incomplete gamma integral.
-gammainccinv
---Inverse of gammaincc.
-beta
---Beta function.
-betaln
---Log of the absolute value of the beta function.
-betainc
---Incomplete beta integral.
-betaincinv
---Inverse of betainc.
-betaincinva
---Inverse (in first argument, a) of betainc
-betaincinvb
---Inverse (in first argument, b) of betainc
-psi(digamma)
---Logarithmic derivative of the gamma function.
-rgamma
---One divided by the gamma function.
-polygamma
---Nth derivative of psi function.
-</pre>
-</div>
-<div class="slide" id="error-function-and-fresnel-int">
-<h1>Error Function and Fresnel Int.</h1>
-<pre class="literal-block">
-erf
---Error function.
-erfc
---Complemented error function (1- erf(x))
-erfinv
---Inverse of error function
-erfcinv
---Inverse of erfc
-erf_zeros
---Complex zeros of erf(z)
-fresnel
---Fresnel sine and cosine integrals.
-fresnel_zeros
---Complex zeros of both Fresnel integrals
-fresnelc_zeros
---Complex zeros of fresnel cosine integrals
-fresnels_zeros
---Complex zeros of fresnel sine integrals
-modfresnelp
---Modified Fresnel integrals F_+(x) and K_+(x)
-modfresnelm
---Modified Fresnel integrals F_-(x) and K_-(x)
-</pre>
-</div>
-<div class="slide" id="legendre-functions">
-<h1>Legendre Functions</h1>
-<pre class="literal-block">
-lpn
---Legendre Functions (polynomials) of the first kind
-lqn
---Legendre Functions of the second kind.
-lpmn
---Associated Legendre Function of the first kind.
-lqmn
---Associated Legendre Function of the second kind.
-lpmv
---Associated Legendre Function of arbitrary non-negative
- degree v.
-sph_harm
---Spherical Harmonics (complex-valued) Y^m_n(theta,phi)
-</pre>
-</div>
-<div class="slide" id="orthogonal-polyn">
-<h1>Orthogonal polyn.</h1>
-<pre class="literal-block">
-legendre
---Legendre polynomial P_n(x)
-chebyt
---Chebyshev polynomial T_n(x)
-chebyu
---Chebyshev polynomial U_n(x)
-chebyc
---Chebyshev polynomial C_n(x)
-chebys
---Chebyshev polynomial S_n(x)
-jacobi
---Jacobi polynomial P^(alpha,beta)_n(x)
-laguerre
---Laguerre polynomial, L_n(x)
-genlaguerre
---Generalized (Associated) Laguerre polynomial, L^alpha_n(x)
-hermite
---Hermite polynomial H_n(x)
-hermitenorm
---Normalized Hermite polynomial, He_n(x)
-gegenbauer
---Gegenbauer (Ultraspherical) polynomials, C^(alpha)_n(x)
-sh_legendre
---shifted Legendre polynomial, P*_n(x)
-sh_chebyt
---shifted Chebyshev polynomial, T*_n(x)
-sh_chebyu
---shifted Chebyshev polynomial, U*_n(x)
-sh_jacobi
---shifted Jacobi polynomial, J*_n(x) = G^(p,q)_n(x)
-</pre>
-</div>
-<div class="slide" id="hypergeometric-functions">
-<h1>HyperGeometric Functions</h1>
-<pre class="literal-block">
-hyp2f1
---Gauss hypergeometric function (2F1)
-hyp1f1
---Confluent hypergeometric function (1F1)
-hyperu
---Confluent hypergeometric function (U)
-hyp0f1
---Confluent hypergeometric limit function (0F1)
-hyp2f0
---Hypergeometric function (2F0)
-hyp1f2
---Hypergeometric function (1F2)
-hyp3f0
---Hypergeometric function (3F0)
-</pre>
-</div>
-<div class="slide" id="parabolic-cylinder-functions">
-<h1>Parabolic Cylinder Functions</h1>
-<pre class="literal-block">
-pbdv
---Parabolic cylinder function Dv(x) and derivative.
-pbvv
---Parabolic cylinder function Vv(x) and derivative.
-pbwa
---Parabolic cylinder function W(a,x) and derivative.
-pbdv_seq
---Sequence of parabolic cylinder functions Dv(x)
-pbvv_seq
---Sequence of parabolic cylinder functions Vv(x)
-pbdn_seq
---Sequence of parabolic cylinder functions Dn(z), complex z
-</pre>
-</div>
-<div class="slide" id="mathieu-functions">
-<h1>Mathieu functions</h1>
-<pre class="literal-block">
-mathieu_a
---Characteristic values for even solution (ce_m)
-mathieu_b
---Characteristic values for odd solution (se_m)
-mathieu_even_coef
---sequence of expansion coefficients for even solution
-mathieu_odd_coef
---sequence of expansion coefficients for odd solution
- ** All the following return both function and first derivative **
-mathieu_cem
---Even mathieu function
-mathieu_sem
---Odd mathieu function
-mathieu_modcem1
---Even modified mathieu function of the first kind
-mathieu_modcem2
---Even modified mathieu function of the second kind
-mathieu_modsem1
---Odd modified mathieu function of the first kind
-mathieu_modsem2
---Odd modified mathieu function of the second kind
-</pre>
-</div>
-<div class="slide" id="spheroidal-wave-functions">
-<h1>Spheroidal Wave Functions</h1>
-<pre class="literal-block">
-pro_ang1
---Prolate spheroidal angular function of the first kind
-pro_rad1
---Prolate spheroidal radial function of the first kind
-pro_rad2
---Prolate spheroidal radial function of the second kind
-obl_ang1
---Oblate spheroidal angluar function of the first kind
-obl_rad1
---Oblate spheroidal radial function of the first kind
-obl_rad2
---Oblate spheroidal radial function of the second kind
-pro_cv
---Compute characteristic value for prolate functions
-obl_cv
---Compute characteristic value for oblate functions
-pro_cv_seq
---Compute sequence of prolate characteristic values
-obl_cv_seq
---Compute sequence of oblate characteristic values
- ** The following functions require pre-computed characteristic values **
-pro_ang1_cv
---Prolate spheroidal angular function of the first kind
-pro_rad1_cv
---Prolate spheroidal radial function of the first kind
-pro_rad2_cv
---Prolate spheroidal radial function of the second kind
-obl_ang1_cv
---Oblate spheroidal angluar function of the first kind
-obl_rad1_cv
---Oblate spheroidal radial function of the first kind
-obl_rad2_cv
---Oblate spheroidal radial function of the second kind
-</pre>
-</div>
-<div class="slide" id="kelvin-functions">
-<h1>Kelvin Functions</h1>
-<pre class="literal-block">
-kelvin
---All Kelvin functions (order 0) and derivatives.
-kelvin_zeros
---Zeros of All Kelvin functions (order 0) and derivatives
-ber
---Kelvin function ber x
-bei
---Kelvin function bei x
-berp
---Derivative of Kelvin function ber x
-beip
---Derivative of Kelvin function bei x
-ker
---Kelvin function ker x
-kei
---Kelvin function kei x
-kerp
---Derivative of Kelvin function ker x
-keip
---Derivative of Kelvin function kei x
-ber_zeros
---Zeros of Kelvin function bei x
-bei_zeros
---Zeros of Kelvin function ber x
-berp_zeros
---Zeros of derivative of Kelvin function ber x
-beip_zeros
---Zeros of derivative of Kelvin function bei x
-ker_zeros
---Zeros of Kelvin function kei x
-kei_zeros
---Zeros of Kelvin function ker x
-kerp_zeros
---Zeros of derivative of Kelvin function ker x
-keip_zeros
---Zeros of derivative of Kelvin function kei x
-</pre>
-</div>
-<div class="slide" id="other-special-functions">
-<h1>Other Special Functions</h1>
-<pre class="literal-block">
-expn
---Exponential integral.
-exp1
---Exponential integral of order 1 (for complex argument)
-expi
---Another exponential integral
---Ei(x)
-wofz
---Fadeeva function.
-dawsn
---Dawson's integral.
-shichi
---Hyperbolic sine and cosine integrals.
-sici
---Integral of the sinc and &quot;cosinc&quot; functions.
-spence
---Dilogarithm integral.
-zeta
---Riemann zeta function of two arguments.
-zetac
---1.0 - standard Riemann zeta function.
-</pre>
-</div>
-<div class="slide" id="convenience-functions">
-<h1>Convenience Functions</h1>
-<pre class="literal-block">
-cbrt
---Cube root.
-exp10
---10 raised to the x power.
-exp2
---2 raised to the x power.
-radian
---radian angle given degrees, minutes, and seconds.
-cosdg
---cosine of the angle given in degrees.
-sindg
---sine of the angle given in degrees.
-tandg
---tangent of the angle given in degrees.
-cotdg
---cotangent of the angle given in degrees.
-log1p
---log(1+x)
-expm1
---exp(x)-1
-cosm1
---cos(x)-1
-round
---round the argument to the nearest integer. If argument
- ends in 0.5 exactly, pick the nearest even integer.
-</pre>
-</div>
-<div class="slide" id="and-more">
-<h1>... and more!</h1>
-<p>but let us go back to our problem</p>
-<ul class="incremental simple">
-<li>at the present we are cleaning our histories in production with a
-quick and dirty criterium;</li>
-<li>we want to be able to see the histories case by case in order to take
-specific actions;</li>
-<li>we want to go on the Web (--&gt; next)</li>
-</ul>
-</div>
-<div class="slide" id="going-on-the-web">
-<h1>Going on the Web</h1>
-<ul class="incremental simple">
-<li>we want a simple tool for internal usage on our intranet;</li>
-<li>convenient to integrate with other Web tools;</li>
-<li>usable also for non-techical users;</li>
-<li>avoid installing and mantaining on every machine;</li>
-<li>possibly we may open it to our other offices in the world;</li>
-<li>we like the browser interface.</li>
-</ul>
-</div>
-<div class="slide" id="without-a-framework">
-<h1>Without a framework</h1>
-<ul class="incremental simple">
-<li>no security concerns;</li>
-<li>no scalability concerns;</li>
-<li>no nice-looking concerns;</li>
-<li>it must be <em>EASY</em> to change;</li>
-<li>we want minimal learning curve;</li>
-<li>we want no installation/configuration hassle;</li>
-<li>we want no dependencies;</li>
-<li>we want something even simpler than CGI, if possible!</li>
-</ul>
-</div>
-<div class="slide" id="enter-wsgi">
-<h1>Enter WSGI</h1>
-<ul class="incremental simple">
-<li>WSGI = Web Server Gateway Interface (<em>Whiskey</em> for friends)</li>
-<li>the brainchild of Python guru Phillip J. Eby;</li>
-<li>also input from Ian Bicking (<tt class="docutils literal"><span class="pre">paste</span></tt>) and others;</li>
-<li>starting from Python 2.5, we have a WSGI web server in the standard
-library (<tt class="docutils literal"><span class="pre">wsgiref</span></tt>);</li>
-<li>there are plenty of simple and useful add-ons for WSGI applications
-out there;</li>
-<li>even <tt class="docutils literal"><span class="pre">wsgiref</span></tt> fullfills all of our requirements, let's use it!
-(following the example of <a class="reference" href="http://video.google.com/videoplay?docid=-8502904076440714866">Guido</a> ...)</li>
-</ul>
-</div>
-<div class="slide" id="wsgi-key-concepts">
-<h1>WSGI key concepts</h1>
-<ol class="incremental arabic">
-<li><p class="first">WSGI application:</p>
-<p>(env, resp) -&gt; chunks of text</p>
-<p>env = environment dictionary of the server;
-resp = function sending to the client the HTTP headers;</p>
-</li>
-<li><p class="first">WSGI middleware:</p>
-<p>WSGI app -&gt; enhanced WSGI app</p>
-</li>
-</ol>
-</div>
-<div class="slide" id="ex1-hello-world">
-<h1>Ex1: Hello World</h1>
-<pre class="literal-block">
-from wsgiref import simple_server
-
-def app(env, resp):
- resp(
- '200 OK', [('Content-type', 'text/html')])
- return ['&lt;h1&gt;Hello, World!&lt;/h1&gt;']
-
-server=simple_server.make_server('', 8000, app)
-server.serve_forever()
-</pre>
-<p><a class="reference" href="http://localhost:8000">show live example</a></p>
-</div>
-<div class="slide" id="ex2-middleware">
-<h1>Ex2: middleware</h1>
-<p>No middleware in the standard library, but lots of useful middleware
-from third party sources. For instance, authentication middleware:</p>
-<pre class="literal-block">
-from paste.auth.basic import AuthBasicHandler
-
-def only_for_pippo(env, user, passwd):
- return user == 'pippo'
-
-auth_app = AuthBasicHandler(
- app, 'app realm', only_for_pippo)
-</pre>
-</div>
-<div class="slide" id="other-middleware">
-<h1>Other middleware</h1>
-<pre class="literal-block">
-from wsgiref.simple_server import make_server
-from paste.evalexception import EvalException
-
-a, b = 1,0
-
-def app(env, resp):
- resp('200 OK', [('Content-type', 'text/html')])
- return [str(a/b)]
-
-make_server('', 9090, EvalException(app)).serve_forever()
-</pre>
-<p>Show <a class="reference" href="http://localhost:9090">evalexception</a></p>
-</div>
-<div class="slide" id="wsgi-vs-cgi">
-<h1>WSGI vs. CGI</h1>
-<ul class="simple">
-<li>WSGI is simpler than CGI<ul>
-<li><span class="incremental">using wsgiref you don't require an external server</span></li>
-<li><span class="incremental">you can keep sessions in memory</span></li>
-</ul>
-</li>
-<li>WSGI scales better than CGI<ul>
-<li><span class="incremental">there is a large choice of wsgi servers (mod_wsgi, Twisted ...)</span></li>
-<li><span class="incremental">there is a large choice of third party middleware</span></li>
-<li><span class="incremental">it is relatively easy to turn a toy application into a serious one</span></li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="slide" id="wsgi-vs-frameworks">
-<h1>WSGI vs. frameworks</h1>
-<p>Pro:</p>
-<ul class="simple">
-<li><span class="incremental">if you liked playing with Lego, you will be happy</span></li>
-<li><span class="incremental">you have much more control and you are not forced to marry a technology</span></li>
-<li><span class="incremental">you can learn a lot</span></li>
-<li><span class="incremental">others ...</span></li>
-</ul>
-</div>
-<div class="slide" id="id1">
-<h1>WSGI vs. frameworks</h1>
-<p>Contra:</p>
-<ul class="simple">
-<li><span class="incremental">you can build your own framework with WSGI, but you have to debug it</span></li>
-<li><span class="incremental">the existing WSGI frameworks are newer, there is less experience with them</span></li>
-<li><span class="incremental">WSGI is not particularly Twisted-friendly</span></li>
-<li><span class="incremental">others ...</span></li>
-</ul>
-</div>
-<div class="slide" id="the-history-plotter">
-<h1>The history plotter</h1>
-<pre class="literal-block">
-$ python webplotter.py
-</pre>
-<p><a class="reference" href="http://localhost:8000">Click here for the live demonstration</a></p>
-</div>
-<div class="slide" id="references">
-<h1>References</h1>
-<p>That's all, folks!</p>
-<ul class="simple">
-<li><a class="reference" href="http://www.scipy.org">http://www.scipy.org</a></li>
-<li><a class="reference" href="http://www.python.org/dev/peps/pep-0333">http://www.python.org/dev/peps/pep-0333</a></li>
-<li><a class="reference" href="http://pythonpaste.org/do-it-yourself-framework.html">http://pythonpaste.org/do-it-yourself-framework.html</a></li>
-</ul>
-<p class="incremental"><strong>(P.S. at StatPro, we are hiring! ;)</strong></p>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/simionato_talk/ui/default/ex.html b/pypers/simionato_talk/ui/default/ex.html
deleted file mode 100644
index 798e3cc..0000000
--- a/pypers/simionato_talk/ui/default/ex.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<html>
-<head>
-<style type="text/css">
-body
-{
-background: url(statpro_logo.gif) no-repeat top
-}
-</style>
-</head>
-<body>
-Prova Background CSS
-</body>
-</html>
diff --git a/pypers/super/super.html b/pypers/super/super.html
deleted file mode 100755
index a970a18..0000000
--- a/pypers/super/super.html
+++ /dev/null
@@ -1,564 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.4: http://docutils.sourceforge.net/" />
-<title>The truth about super</title>
-<meta name="author" content="Michele Simionato" />
-<meta name="date" content="June 2004" />
-<link rel="stylesheet" href="default.css" type="text/css" />
-</head>
-<body>
-<h1 class="title">The truth about <tt class="literal"><span class="pre">super</span></tt></h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr><th class="docinfo-name">Author:</th>
-<td>Michele Simionato</td></tr>
-<tr class="field"><th class="docinfo-name">Email:</th><td class="field-body"><a class="reference" href="mailto:michele.simionato&#64;libero.it">michele.simionato&#64;libero.it</a></td>
-</tr>
-<tr><th class="docinfo-name">Date:</th>
-<td>June 2004</td></tr>
-<tr><th class="docinfo-name">Status:</th>
-<td>Draft</td></tr>
-</tbody>
-</table>
-<div class="document" id="the-truth-about-super">
-<p><tt class="literal"><span class="pre">super</span></tt> is a new built-in, first introduced in Python 2.2 and slightly
-improved and fixed in Python 2.3, which is little known to the average
-Python programmer. One of the reason for this
-fact is its poor documentation`: at the time of this writing
-(June 2004) <tt class="literal"><span class="pre">super</span></tt> documentation is incomplete and in some parts
-misleading and even wrong. For instance, it was recently pointed out
-on comp.lang.python that the standard library (Python 2.3.4, section 2.1)
-still says:</p>
-<pre class="literal-block">
-super(type[, object-or-type])
- Return the superclass of type. If the second argument is omitted the
- super object returned is unbound. If the second argument is an object,
- isinstance(obj, type) must be true. If the second argument is a type,
- issubclass(type2, type) must be true. super() only works for new-style
- classes.
-</pre>
-<p>The first sentence is just plain wrong. <tt class="literal"><span class="pre">super</span></tt> does not return the
-superclass. There is no such a thing as &quot;the&quot; superclass in a Multiple
-Inheritance (MI) language. Also, the sentence about 'unbound' is misleading,
-since it may easily lead the programmer to think about bound and unbound
-methods, whereas it has nothing to do with that concept. Finally, there
-subtle pitfalls of <tt class="literal"><span class="pre">super</span></tt> which are not at all mentioned. IMNSHO
-<tt class="literal"><span class="pre">super</span></tt> is one of the most trickiest and surprising Python constructs,
-so it absolutely needs a document to share light on some of his secrets:
-the present article aims to fix the issues with the current documentation,
-and tell you the &quot;truth&quot; about <tt class="literal"><span class="pre">super</span></tt>. At least the amount of truth
-I have discovered with my experimentations, which is certainly
-not the whole truth ;)</p>
-<p>Here is the plan: first I will discuss the concept of superclass in
-a Multiple Inheritance (MI) world (there is no such a thing as
-&quot;the&quot; superclass!); second, I will show that <tt class="literal"><span class="pre">super</span></tt> is a proxy
-object, able to dispatch to the right methods/attributes in the
-MRO; third,</p>
-<p>recall some background on
-how the resolution of methods works on how
-descriptors work and
-(essentially pointing out to the standard references); then
-I will discuss the more common invocation of <tt class="literal"><span class="pre">super</span></tt> -
-the invocation with two arguments - and finally I will discuss
-the most tricky part, i.e. invoking <tt class="literal"><span class="pre">super</span></tt> with just one
-argument and I will discuss pitfalls.</p>
-<p>Finally, a fair warning: this document is aimed to expert
-Pythonistas. It is not for the faint of heart ;)</p>
-<div class="section" id="first-truth-there-is-no-superclass-in-a-mi-world">
-<h1><a name="first-truth-there-is-no-superclass-in-a-mi-world">First truth: there is no superclass in a MI world</a></h1>
-<p>Readers familiar will single inheritance languages, such as
-Java or Smalltalk, will have a clear concept of superclass
-in mind. This concept, however, has <em>no useful meaning</em> in Python or in
-other Multiple Inheritance languages. This fact was proved to
-me by Bjorn Pettersen in a thread on comp.lang.python in May 2003
-(at that time I was mistakenly thinking that one could define a
-superclass concept in Python). Consider this example from that
-discussion:</p>
-<pre class="literal-block">
- +-----+
- | T |
- |a = 0|
- +-----+
- / \
- / \
-+-------+ +-------+
-| A | | B |
-| | | a = 2 |
-+-------+ +-------+
- \ /
- \ /
- +-----+
- | C |
- +-----+
- :
- : instantiation
- c
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class T(object):
-... a = 0
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class A(T):
-... pass
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B(T):
-... a = 2
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(A,B):
-... pass
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; c = C()
-</pre>
-<p>Who is the superclass of C? There are two direct superclasses (i.e. bases)
-of C: A and B. A comes before B, so one would naturally think
-that the superclass of C is A. A inherits the attribute 'a' from T,
-so if <tt class="literal"><span class="pre">super(C,c)</span></tt> was returning the superclass of C, then
-it should return 'A'. 'A' inherits its attribute 'a' from T,
-where 'a' has the value 0, so <tt class="literal"><span class="pre">super(C,c).a</span></tt> would return 0. This
-is NOT what happens. Instead, <tt class="literal"><span class="pre">super(C,c).a</span></tt> walks trought the
-method resolution order <a class="footnote-reference" href="#id4" id="id1" name="id1">[1]</a> of the class of <tt class="literal"><span class="pre">c</span></tt> (which is 'C')
-and retrieves the attribute from the first class above 'C' which
-defines it. In this example the MRO of 'C' is [C, A, B, T, object], so
-B is the first class above C which defines 'a' and <tt class="literal"><span class="pre">super(C,c).a</span></tt>
-correctly returns the value 2, not 0:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,c).a
-2
-</pre>
-<p>You may call 'A' the superclass of 'C', but this is not an useful
-concept since the methods are resolved by looking at the classes
-in the MRO of 'C', and not by looking at the classes in the MRO of A
-(which in this case is [A,T, object] and does not contain B).</p>
-<p>So, using the word <em>superclass</em> in the standard doc is completely
-misleading and should be avoided altogether.</p>
-</div>
-<div class="section" id="second-truth-super-returns-proxy-objects">
-<h1><a name="second-truth-super-returns-proxy-objects">Second truth: <tt class="literal"><span class="pre">super</span></tt> returns proxy objects</a></h1>
-<p>Having understood that <tt class="literal"><span class="pre">super</span></tt> cannot return and does not return the
-mythical superclass, we ask ourselves what the hell is returning
-<tt class="literal"><span class="pre">super</span></tt> ;) The truth is that <tt class="literal"><span class="pre">super</span></tt> returns proxy objects.
-Informally speaking, a proxy object is an object with
-the ability to dispatch to methods of other classes via delegation.</p>
-<p>Technically, <tt class="literal"><span class="pre">super</span></tt> works by overriding the <tt class="literal"><span class="pre">__getattribute__</span></tt>
-method in such a way that its instances becomes proxy objects providing
-access to the methods in the MRO. The dispatch is done in such a way
-that</p>
-<p><tt class="literal"><span class="pre">super(cls,</span> <span class="pre">instance-or-subclass).meth(*args,</span> <span class="pre">**kw)</span></tt></p>
-<p>corresponds to</p>
-<p><tt class="literal"><span class="pre">&lt;right</span> <span class="pre">method</span> <span class="pre">in</span> <span class="pre">the</span> <span class="pre">MRO&gt;(instance-or-subclass,</span> <span class="pre">*args,</span> <span class="pre">**kw)</span></tt></p>
-<p>There is a caveat at this point: the second argument can be
-an instance of the first argument, or a subclass of it, but
-in <em>both cases</em> a bound method is returned (one could naivily
-think, instead, that when a subclass is passed one gets an
-unbound method).</p>
-<p>For instance, in this example</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B(object):
-... def __repr__(self):
-... return &quot;&lt;instance of %s&gt;&quot; % self.__class__.__name__
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(B):
-... pass
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(C):
-... pass
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; d = D()
-</pre>
-<p>both</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print super(C,d).__repr__
-&lt;bound method D.__repr__ of &lt;instance of D&gt;&gt;
-</pre>
-<p>and</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print super(C,D).__repr__
-&lt;bound method D.__repr__ of &lt;class 'D'&gt;&gt;
-</pre>
-<p>returns bound methods. This means that when I call those methods,
-I get</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print super(C,d).__repr__()
-&lt;instance of D&gt;
-</pre>
-<p>(here d, a D instance is being passed to <tt class="literal"><span class="pre">__repr__</span></tt>) and</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print super(C,D).__repr__()
-&lt;instance of type&gt;
-</pre>
-<p>(here D, an instance of the (meta)class <tt class="literal"><span class="pre">type</span></tt> is being passed
-to <tt class="literal"><span class="pre">__repr__</span></tt>).</p>
-<p>Reading the docs,one could think that in order to get unbound methods,
-she needs to switch to the alternative syntax of <tt class="literal"><span class="pre">super</span></tt>, the single
-argument syntax. This is actually completely WRONG.</p>
-</div>
-<div class="section" id="third-truth-the-unbound-syntax-does-not-access-unbound-methods">
-<h1><a name="third-truth-the-unbound-syntax-does-not-access-unbound-methods">Third truth: the 'unbound' syntax does not access unbound methods</a></h1>
-<p>Suppose 'B' has a method called 'meth' like this:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; B.meth = lambda self :'You called B.meth with first argument %s' % self
-</pre>
-<p>Then <tt class="literal"><span class="pre">B.meth</span></tt> is an unbound method and, mislead by the documentation,
-one could expect to be able to access it with the syntax <tt class="literal"><span class="pre">super(C).meth</span></tt>.
-This is not the case. You get an error instead:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C).meth
-Traceback (most recent call last):
- ...
-AttributeError: 'super' object has no attribute 'meth'
-</pre>
-<p>The truth is that unbound super objects cannot be accessed directly,
-they must be converted to bound objects in order to make them
-to dispatch properly. Unbound super objects can be converted to
-bound super objects via the descriptor protocol. For instance,
-in this example I can convert <tt class="literal"><span class="pre">super(C)</span></tt> in a super object
-bound to the instance 'd' in this way:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; boundsuper = super(C).__get__(d, D) # this is the same as super(C,d)
-</pre>
-<p>Now I can access the bound method 'd.meth':</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print boundsuper.meth
-&lt;bound method D.&lt;lambda&gt; of &lt;instance of D&gt;&gt;
-</pre>
-<p>To really access the unbound method 'D.meth' is tricky; it could be
-done in this way:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print boundsuper.meth.__get__(None,D)
-&lt;unbound method D.&lt;lambda&gt;&gt;
-</pre>
-<p>All those tricks requires a good grasp of descriptors (see next
-paragraph). Here I would like just to point out that in my opinion
-having an unbound syntax for descriptors is generating more
-confusion than needed. First of all, there is a problem of poor
-documentation.</p>
-<p>The distinction bound/unbound
-can easily be confused with the distinction between bound and unbound
-methods. So you could expect <tt class="literal"><span class="pre">super(C).meth</span></tt> to be an unbound method
-of the superclass of C (superclass here is intended in some nebolous way).
-This is not that dangerous when you get an error; it is much more
-dangerous when you don't get an error, but you get a result which is
-not what you expect. This happens for special methods which are
-already defined in <tt class="literal"><span class="pre">super</span></tt>.
-For instance <tt class="literal"><span class="pre">super(C).__repr__</span></tt> does not give any error,
-but it is <em>not</em> returning a proxy to <tt class="literal"><span class="pre">D.__repr__</span></tt>, it is
-returning <tt class="literal"><span class="pre">super.__repr__</span></tt> bound to the (unbound) super object <tt class="literal"><span class="pre">super(C)</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print super(C).__repr__() # same as repr(super(C))
-&lt;super: &lt;class 'C'&gt;, NULL&gt;
-</pre>
-<p>Very tricky. Notice that <tt class="literal"><span class="pre">super</span></tt> also redefines <tt class="literal"><span class="pre">__new__</span></tt>,
-<tt class="literal"><span class="pre">__init</span></tt>, <tt class="literal"><span class="pre">__get__</span></tt>, <tt class="literal"><span class="pre">__getattribute</span></tt>, as well as inheriting
-other special attributes from <tt class="literal"><span class="pre">object</span></tt>. So you will dispatch to
-these methods in <tt class="literal"><span class="pre">super</span></tt> and not to the right methods defined in
-the hierarchy at hand. On the other hand, the two-argument syntax
-does not have this problem. For instance</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print super(C,C).__repr__()
-&lt;instance of type&gt;
-</pre>
-<p>does the right thing. There is a single use case for the single argument
-syntax of <tt class="literal"><span class="pre">super</span></tt> that I am aware of, but I think it gives more troubles
-than advantages. The use case is the implementation of &quot;autosuper&quot; made
-by Guido on his essay about new-style classes.</p>
-<p>The idea there is to use the unbound super objects as private
-attributes. For instance, in our example, we could define the
-private attribute <tt class="literal"><span class="pre">__sup</span></tt> in the class <tt class="literal"><span class="pre">C</span></tt> as the unbound
-super object <tt class="literal"><span class="pre">super(C)</span></tt>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; C._C__sup = super(C)
-</pre>
-<p>With this definition inside the methods the syntax
-<tt class="literal"><span class="pre">self.__sup.meth(arg)</span></tt> can be used
-as an alternative to <tt class="literal"><span class="pre">super(C,</span> <span class="pre">self).meth(arg)</span></tt>, and the advantage is
-that you avoid to repeat the name of the class in the calling
-syntax, since that name is hidden in the mangling mechanism of
-private names. The creation of the <tt class="literal"><span class="pre">__sup</span></tt> attributes can be hidden
-in a metaclass and made automatic. So, all this seems to work: but
-actually this <em>not</em> the case.
-Things may wrong in various case, for instance for classmethods,
-as in this example:</p>
-<pre class="literal-block">
-#&lt;ex.py&gt;
-
-class B(object):
- def __repr__(self):
- return '&lt;instance of %s&gt;' % self.__class__.__name__
- def meth(self):
- print &quot;B.meth(%s)&quot; % self
- meth = classmethod(meth)
-
-class C(B):
- def meth(self):
- print &quot;C.meth(%s)&quot; % self
- self.__super.meth()
- meth = classmethod(meth)
-
-C._C__super = super(C)
-
-class D(C):
- pass
-
-D._D__super = super(D)
-
-
-d=D()
-
-d.meth()
-
-#&lt;/ex.py&gt;
-</pre>
-<p>The last line raises an <tt class="literal"><span class="pre">AttributeError:</span> <span class="pre">'super'</span> <span class="pre">object</span> <span class="pre">has</span> <span class="pre">no</span> <span class="pre">attribute</span>
-<span class="pre">'meth'.</span></tt></p>
-<p>So, using a <tt class="literal"><span class="pre">__super</span></tt> unbound super object is not a robust solution
-(notice that everything would work by substituting <tt class="literal"><span class="pre">self.__super.meth()</span></tt>
-with <tt class="literal"><span class="pre">super(C,self).meth()</span></tt>. There are other ways to avoid repeating
-the class name, see for instance my cookbook recipe.</p>
-<p>If it was me, I would just remove the single argument syntax of <tt class="literal"><span class="pre">super</span></tt>,
-making it illegal. But this would probably break someone code, so
-I don't think it will ever happen. Another solution would be just to
-deprecate it. There is no need for this syntax, one can always circumvent it.</p>
-</div>
-<div class="section" id="forth-truth-super-returns-descriptor-objects">
-<h1><a name="forth-truth-super-returns-descriptor-objects">Forth truth: <tt class="literal"><span class="pre">super</span></tt> returns descriptor objects</a></h1>
-<p>Descriptors (more properly I should speak of the descriptor protocol) were
-introduced in Python 2.2 by Guido van Rossum. Their primary motivation
-is technical, since they were needed to implement the new-style object
-system. Descriptors were also used to introduce new standard concepts in
-Python, such as classmethods, staticmethods and properties. Moreover,
-according to the traditional transparency policy of Python, descriptors
-were exposed to the application programmer, giving him/her the freedom
-to write custom descriptors. <a class="footnote-reference" href="#id6" id="id2" name="id2">[2]</a> Any serious Python programmer should have
-a look at descriptors: luckily they are now very well documented (which was
-not the case when I first studied them :-/) thanks to the beautiful essay
-of Raimond Hettinger <a class="footnote-reference" href="#id7" id="id3" name="id3">[3]</a>. You should read it before continuing this article,
-since it explains all the details. However, for the sake of our discussion
-of <tt class="literal"><span class="pre">super</span></tt>, it is enough to say that a <em>descriptor class</em> is just a
-regular new-style class which implements a .``__get__`` method with
-signature <tt class="literal"><span class="pre">__get__(self,</span> <span class="pre">obj,</span> <span class="pre">objtyp</span> <span class="pre">=</span> <span class="pre">None)</span></tt>. A <em>descriptor object</em>
-is just an instance of a descriptor class.</p>
-<p>Descriptor objects are intended to be used as attributes (hence their
-complete name attribute descriptors). Suppose that 'descr' is a
-given descriptor object used as attribute of a given class C.
-Then the syntax <tt class="literal"><span class="pre">C.descr</span></tt> is actually implemented by Python as a
-call to <tt class="literal"><span class="pre">descr.__get__(None,</span> <span class="pre">C)</span></tt>, whereas the same syntax for an
-instance of C corresponds to a call to <tt class="literal"><span class="pre">descr.__get__(c,</span> <span class="pre">type(c))</span></tt>.</p>
-<p>This explanation is relevant in order to understand how the <tt class="literal"><span class="pre">super</span></tt>
-built-in works when it is called with only one argument, i.e. in the
-unbound form. In this case <tt class="literal"><span class="pre">super(C)</span></tt> returns a descriptor which
-is intended to be used as an attribute in other classes. This is
-an example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(C):
-... sup = super(C)
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; d = D()
-&gt;&gt;&gt; d.sup.a
-2
-</pre>
-<p>This works since <tt class="literal"><span class="pre">d.sup.a</span></tt> calls</p>
-<table class="footnote" frame="void" id="id4" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1" name="id4">[1]</a></td><td>Descriptors gives an enormous power to the application
-programmer, especially when combined with metaclasses. For instance,
-using descriptors I did implement a prototype-based object system for
-Python in few lines: see of course this was an hack, only useful as proof
-of concept.</td></tr>
-</tbody>
-</table>
-</div>
-<div class="section" id="fifth-truth-super-does-not-work-with-meta-attributes">
-<h1><a name="fifth-truth-super-does-not-work-with-meta-attributes">Fifth truth: <tt class="literal"><span class="pre">super</span></tt> does not work with meta-attributes</a></h1>
-<p>If you start using <tt class="literal"><span class="pre">super</span></tt> intensively, soon or latter you will find
-a number of subtilities. One of these is the fact that <tt class="literal"><span class="pre">super</span></tt> does not
-work well with the <tt class="literal"><span class="pre">__name__</span></tt> special attribute. Consider this example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B(object):
-... &quot;This is class B&quot;
-...
-&gt;&gt;&gt; class C(B):
-... pass
-...
-</pre>
-<p>Here the special class attribute <tt class="literal"><span class="pre">__doc__</span></tt> is retrieved as you would expect:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,C).__doc__ == super(C,C()).__doc__ == B.__doc__
-True
-</pre>
-<p>On the other hand, the special attribute <tt class="literal"><span class="pre">__name__</span></tt> is not
-retrieved correctly:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; super(C,C).__name__ # one would expect it to be 'B'
-Traceback (most recent call last):
- File &quot;&lt;stdin&gt;&quot;, line 1, in ?
-AttributeError: 'super' object has no attribute '__name__'
-</pre>
-<p>The problem is that <tt class="literal"><span class="pre">__name__</span></tt> is not just a plain class
-attribute: it is actually a &quot;getset descriptor&quot; defined on
-the metaclass &quot;type&quot; (try to run <tt class="literal"><span class="pre">help(type.__dict__['__name__'])</span></tt>
-and you will see for yourself). More in general, <tt class="literal"><span class="pre">super</span></tt> has
-problems with meta-attributes, i.e. class attributes of metaclasses.
-Meta-attributes differs from regular attributes since they are not
-transmitted to the instances of the instances.You can find the
-rationale for this behaviour elsewhere <a class="footnote-reference" href="#id8" id="id5" name="id5">[4]</a>: here I am only interested
-to the issues with <tt class="literal"><span class="pre">super</span></tt>. Consider this example:</p>
-<p>#&lt;example1.py&gt;</p>
-<dl>
-<dt>class M(type):</dt>
-<dd>&quot;A metaclass with a class attribute 'a'.&quot;
-a = 1</dd>
-<dt>class B:</dt>
-<dd>&quot;An instance of M with a meta-attribute 'a'.&quot;
-__metaclass__ = M</dd>
-<dt>class C(B):</dt>
-<dd>&quot;An instance of M with the same meta-attribute 'a'&quot;</dd>
-<dt>if __name__ == &quot;__main__&quot;:</dt>
-<dd>print B.a, C.a # =&gt; 1 1
-print super(C,C).a #=&gt; attribute error</dd>
-</dl>
-<p>#&lt;/example1.py&gt;</p>
-<p>If you run this, you will get an attribute error. This is a case
-where <tt class="literal"><span class="pre">super</span></tt> is doing the <em>right</em> thing, since 'a' is <em>not</em> inherited
-from B, but it comes directly from the metaclass (again, look at my second
-article with David Mertz to understand why it is so), so 'a'
-is <em>not</em> in the MRO of C. A similar thing happens for the &quot;__name__&quot;
-attribute (the fact that it is a descriptor and not a plain
-attribute does not matter), so <tt class="literal"><span class="pre">super</span></tt> is working correctly, but
-still it may seems surprising at first.</p>
-</div>
-<div class="section" id="the-final-truth-there-are-other-bugs-and-pitfalls">
-<h1><a name="the-final-truth-there-are-other-bugs-and-pitfalls">The final truth: there are other bugs and pitfalls</a></h1>
-<p>There are various <tt class="literal"><span class="pre">super</span></tt> pitfalls currently undocumented and
-that experienced Python programmers should be aware of.</p>
-<p>The unbound form of <tt class="literal"><span class="pre">super</span></tt> does not play well with pydoc.
-The problems is still there in Python 2.3.4 (see bug report SF729103)</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class B(object): pass
-...
-&gt;&gt;&gt; class C:
-... s=super(B)
-...
-&gt;&gt;&gt; help(C)
-Traceback (most recent call last):
- ...
- ... lots of stuff here
- ...
-File &quot;/usr/lib/python2.3/pydoc.py&quot;, line 1198, in docother
- chop = maxlen - len(line)
-TypeError: unsupported operand type(s) for -: 'classobj' and 'int'
-</pre>
-<p>I have not yet clear what the cause is, but it is certainly quite
-tricky.</p>
-<p>There is also another subtle pitfall which is not directly related
-to <tt class="literal"><span class="pre">super</span></tt> but which is often encountered working with <tt class="literal"><span class="pre">super</span></tt>.
-This came up at least three or four times in the newsgroup, and there
-are various independent bug reports on sourceforge about it, so possibly
-you may face it too. Bjorn Pettersen was the first one who pointed out the
-problem to me (see also bug report SF 729913): the issue is that</p>
-<p><tt class="literal"><span class="pre">super(MyCls,</span> <span class="pre">self).__getitem__(5)</span></tt></p>
-<p>works, but not</p>
-<p><tt class="literal"><span class="pre">super(MyCls,</span> <span class="pre">self)[5]</span></tt>.</p>
-<p>The problem is general to all special methods, not only to <tt class="literal"><span class="pre">__getitem__</span></tt>,
-and the explanation for that has to do with the implementation of
-attribute lookup for special methods. Clear explanations of what is
-going on are provided by Michael Hudson as a comment to the bug report:
-SF789262 and by Raymond Hetting as a comment to the bug report SF805304.
-Shortly put, this is not a problem of <tt class="literal"><span class="pre">super</span></tt> per se, the problem is
-that (using <tt class="literal"><span class="pre">__getitem__</span></tt> as example)</p>
-<blockquote>
-<tt class="literal"><span class="pre">x[5]</span> <span class="pre">==</span> <span class="pre">type(x).__getitem__(x,5)</span></tt></blockquote>
-<p><em>only if</em> <tt class="literal"><span class="pre">__getitem__</span></tt> is explicitely defined in <tt class="literal"><span class="pre">type(x)</span></tt>. If
-<tt class="literal"><span class="pre">type(x)</span></tt> does not define <tt class="literal"><span class="pre">__getitem__</span></tt> directly, but only
-indirectly via delegation (i.e. overriding <tt class="literal"><span class="pre">__getattribute__</span></tt>),
-then the second form works but not the first one, i.e. the <tt class="literal"><span class="pre">[]</span></tt> syntax
-is not automatically converted to the second form, the working one.</p>
-<p>This restriction will likely stay in Python because it would involve
-a really big change and a loss of performances, so it has to be
-considered just a documentation bug, since nowhere in
-the docs it is mentioned that special calling syntaxes (such as
-the <tt class="literal"><span class="pre">[]</span></tt> call, the <tt class="literal"><span class="pre">iter</span></tt> call, the <tt class="literal"><span class="pre">repr</span></tt> call, etc. etc.)
-are special and bypass <tt class="literal"><span class="pre">__getattribute__</span></tt>. Guido advice is:
-just use the more explicit form and everything will work.</p>
-<p>Finally, there may be other bugs and pitfalls I am not aware of. Certainly
-there are many other issues and bugs in previous versions of Python that
-I have not mentioned here, since they have been fixed, but that you may
-encounter if you use Python 2.2 (and maybe even in 2.3).</p>
-</div>
-<div class="section" id="the-final-truth-when-it-comes-to-super-don-t-trust-even-guido-himself">
-<h1><a name="the-final-truth-when-it-comes-to-super-don-t-trust-even-guido-himself">The final truth: when it comes to <tt class="literal"><span class="pre">super</span></tt> don't trust even Guido himself!</a></h1>
-<p>In order to explain how <tt class="literal"><span class="pre">super</span></tt> works, Guido describes a
-&quot;fully functional implementation of the super() built-in class in
-pure Python&quot; in &quot;Unifying types and classes in Python 2.2&quot;.
-Unfortunately, that implemenentation is more harmful than helpful, since
-the current <tt class="literal"><span class="pre">super</span></tt> DOES NOT work in the same way :-(
-Take for instance this example:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; class C(object):
-... f='C.f'
-</pre>
-<pre class="doctest-block">
-&gt;&gt;&gt; class D(C):
-... f='D.f'
-</pre>
-<p>Here the <tt class="literal"><span class="pre">super</span></tt> works fine,
-df</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; print super(D,D()).f
-C.f
-</pre>
-<p>but the class <tt class="literal"><span class="pre">Super</span></tt> described by Guido will raise an attribute
-error when invoked as <tt class="literal"><span class="pre">Super(D,D()).f</span></tt>. Therefore Super is NOT
-equivalent to the currently implemented <tt class="literal"><span class="pre">super</span></tt> built-in</p>
-</div>
-<div class="section" id="notes">
-<h1><a name="notes">Notes</a></h1>
-<table class="footnote" frame="void" id="id6" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id2" name="id6">[2]</a></td><td>I wrote an essay on Python 2.3 Method Resolution Order which
-you may find here:</td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id7" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id3" name="id7">[3]</a></td><td>Raymond Hetting wrote a beautiful essay on descriptors here:</td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id8" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id5" name="id8">[4]</a></td><td>David Mertz and me wrote a couple of articles on metaclasses;
-the second one is the relevant one for the issues discussed here:</td></tr>
-</tbody>
-</table>
-<table class="footnote" frame="void" id="id9" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a name="id9">[5]</a></td><td><a class="reference" href="http://groups.google.it/groups?hl=it&amp;lr=&amp;ie=UTF-8&amp;threadm=2259b0e2.0304300625.4e0ebace%40posting.google.com&amp;rnum=3&amp;prev=/groups%3Fhl%3Dit%26lr%3D%26ie%3DUTF-8%26q%3Dsimionato%2Bpettersen%2Bsuper%26btnG%3DCerca%26meta%3Dgroup%253Dcomp.lang.python">http://groups.google.it/groups?hl=it&amp;lr=&amp;ie=UTF-8&amp;threadm=2259b0e2.0304300625.4e0ebace%40posting.google.com&amp;rnum=3&amp;prev=/groups%3Fhl%3Dit%26lr%3D%26ie%3DUTF-8%26q%3Dsimionato%2Bpettersen%2Bsuper%26btnG%3DCerca%26meta%3Dgroup%253Dcomp.lang.python</a>.*</td></tr>
-</tbody>
-</table>
-</div>
-</div>
-<hr class="footer" />
-<div class="footer">
-<a class="reference" href="super.txt">View document source</a>.
-Generated on: 2004-06-13 20:23 UTC.
-Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
-</div>
-</body>
-</html>
diff --git a/pypers/twill/testing_web_app.html b/pypers/twill/testing_web_app.html
deleted file mode 100755
index 1425b8e..0000000
--- a/pypers/twill/testing_web_app.html
+++ /dev/null
@@ -1,584 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.3.9: http://docutils.sourceforge.net/" />
-<title>Testing Web Applications with Python</title>
-<meta name="author" content="Michele Simionato" />
-<meta name="date" content="June 2005" />
-</head>
-<body>
-<div class="document" id="testing-web-applications-with-python">
-<h1 class="title">Testing Web Applications with Python</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr><th class="docinfo-name">Author:</th>
-<td>Michele Simionato</td></tr>
-<tr><th class="docinfo-name">Date:</th>
-<td>June 2005</td></tr>
-</tbody>
-</table>
-<div class="section" id="introduction">
-<h1><a name="introduction">Introduction</a></h1>
-<p>You have just finished your beautiful Web application, with
-lots of pages, links, forms and buttons; you have spent weeks
-making sure that everything works fine,
-that the special cases are handled correctly, that the user cannot
-crash your system whatever she does.</p>
-<p>Now you are happy and you are ready to ship. But at the last minute
-the customer ask for a change: you have the time to apply the change,
-but not the time - nor the will - to pass trough another testing
-ordalia. So you ship anyway, hoping that your last little fix did not break
-some other part of the application. The result is that the hidden bug
-shows up at the first day of usage.</p>
-<p>If you recognized yourself in this situation then this paper
-is for you, keep reading. If not, well, keep reading anyway,
-I am sure you will find something interesting, among the following topics:</p>
-<ul class="simple">
-<li>how to separate unit tests from functional tests;</li>
-<li>how to test web applications (written in any language) using
-standard Python libraries;</li>
-<li>how to use twill, a nice and easy to learn web testing tool.</li>
-</ul>
-</div>
-<div class="section" id="to-test-or-not-to-test-this-is-the-problem">
-<h1><a name="to-test-or-not-to-test-this-is-the-problem">To test or not to test, this is the problem</a></h1>
-<p>Let me begin with a brief personal recollection of how I became
-interested in testing methodologies, and of what I have learned in
-the last couple of years.</p>
-<p>I have been aware of the importance of testing from the beginning, and
-I have heard about automatic testing for years. However, having
-heard about automatic testing is not the same as doing automatic testing,
-and not the same as doing automatic testing well.
-It takes some time and experience to get into the testing mood, as well
-as the ability to challenge some widespread misconceptions.</p>
-<p>For instance, when I began studying test driven methodologies,
-I had gathered two wrong ideas:</p>
-<ul class="simple">
-<li>that testing was all about unit testing;</li>
-<li>that the more you test, the better.</li>
-</ul>
-<p>After some experience I quickly realized myself that unit tests were
-not the only tool, nor the best tool to effectively test my application <a class="footnote-reference" href="#id11" id="id1" name="id1">[1]</a>.
-But to overcome the second misconception, I needed some help.</p>
-<p>The help come from an XP seminar I attended last year, were I
-actually asked the question &quot;how do I test the user interface of
-a Web application, i.e. that when the user click on a given page she gets
-the expected result?&quot;.</p>
-<p>The answer was: &quot;You don't. Why do you want to test that your browser is
-working?&quot;</p>
-<div class="section" id="the-case-for-not-testing-everything">
-<h2><a name="the-case-for-not-testing-everything">The case for not testing everything</a></h2>
-<p>The answer made me rethink many things. Obviously I was well aware
-from the beginning that full test coverage is a myth, still I thought
-one programmer should try to test as much as he can.</p>
-<p>But this is not the right approach. Instead, it is important to
-discriminate about the infinite amount of things that could be
-tested, and focus on the things that are of your responsability.</p>
-<p>If your customer wants functionality X, you must be sure functionality X
-is there. But if in order to get functionality X you need to rely on
-functionalities X1, X2 ,... XN, you don't need to test for all
-of them. You test only the functionality you are payed to
-implement. You don't test that the browser is working, it is
-not your job.</p>
-<p>For instance, in the case of a Web application,
-you can interact with it <em>indirectly</em>, via the HTTP protocol, or <em>directly</em>,
-via the internal API. If you check that when the user clicks
-on button B method M is called and the result R is displayed, you are
-testing both your application <em>and</em> the correctness of the
-HTTP protocol implementation both in the browser and in the server. This is
-way too much. You may rely on the HTTP protocol and just test the API, i.e
-just test that if method M is called the right result R is returned.</p>
-<p>Of course, a similar viewpoint is applicable to GUIs. In the same
-vein, you must test that the interface to the DB you wrote is working, but
-you don't need to test that the database itself is working, this
-is not your responsability.</p>
-<p>The basic point is to separate the indirect testing of the user
-interface - via the HTTP protocol - from the testing of the inner API.
-To this aim, it is important to write your
-application in such a way that you can test the logic independently
-from the user interface. Working in this way you also have the additional
-bonus that you can change the user interface later, without having to
-change a single tests for the logic part.</p>
-<p>The problem is that typically the customer will give his specifications
-in terms of the user interface. He will tell you &quot;There must be a page where
-the user will enter her order, then she will enter her credit card number,
-then the system must send a confirmation email, ...&quot;</p>
-<p>This kind of specification is a kind of very high level test - a
-functional test - which has to be converted into a low-level test:
-for instance you may have unit testing telling you that the ordered
-item has been registered in the database, that the
-<tt class="docutils literal"><span class="pre">send_confirmation_email</span> <span class="pre">method</span></tt> has been called etc.</p>
-<p>The conversion requires some thinking and practice and it an art more
-than a science. Actually I think that the art of testing is not in <em>how</em>
-to test, but in <em>what</em> to test. The best advice and best answer to somebody
-asking about &quot;how do I test a Web application?&quot; is probably &quot;make a priority
-lists of the things you would like to test and test as little as possible&quot;.</p>
-<p>For instance, one should never tests the details of the
-implementation. If you make this mistake (as I did at the beginning)
-your tests will get in your way at refactoring time, i.e. they will
-have exactly the opposite of the intended effect. Generally speaking,
-good advices are: don't spend time testing third party software, don't
-waste time testing code which API is likely to change, split
-the UI testing from the application logic testing.</p>
-<p>Ideally you should be able to determine what is the minimal set
-of tests needed to make your customer happy, and restrict yourself to
-those tests.</p>
-</div>
-<div class="section" id="the-case-for-testing-everything">
-<h2><a name="the-case-for-testing-everything">The case for testing everything</a></h2>
-<p>The previous advice is nice and reasonable, especially in an ideal world
-where third party software is bug free and everything is configured correctly.
-Unfortunately, the real world is a bit different.</p>
-<p>For instance you must be aware that your application
-does not work on some buggy browser, or that it cannot work in specific
-circumstances with some database. Also, you may have a nice and
-comprehensive test suite which runs flawlessly
-on your development machine, but still
-that the application may not work correctly when installed on a different
-machine, because the database could be installed improperly, or
-the mail server settings could be incorrect, or the Internet
-connection could be down, etc. In the same vein, if you want
-to really be sure that if the user - using a specifing browser in a
-specific environment - clicks on that button she gets that result,
-you have to emulate exactly that situation.</p>
-<p>It looks like we are back to square one, i.e. the need of testing everything.
-But we have learned something in the process: whereas <em>in principle</em>
-you would like to test everything, <em>in practice</em> you can effectively
-prioritize your tests, focusing on some more than on others,and
-splitting them in separate categories to be run separately at
-different times.</p>
-<p>You definitely need to test that the
-application is working as intended when deployed on a different
-machine: and from the failures to these installation tests you may also infer
-what is wrong and correct the problem. These installation tests
-- tests of the environment where your software is running - must
-be kept decoupled from the unit tests checking the
-application logic. If you are sure that the logic is right, then you are
-sure also sure that the problems are in the environment, and you can
-focus your debugging skills in the right direction.</p>
-<p>In any case, you need to have both high level (functional, integration,
-installation) tests and low level tests (unit tests, doctests). High level
-tests include tests of the user interface. In particular, you need a test to
-make sure that if an user click X he gets Y, so you are sure that the
-Internet connection, the web server, the database, the mail
-server, your application, the browser, all work nicely
-together. But you should not focus on these global kind
-of tests. You don't need to write a thousands of these
-high level tests, if you already have many specific low-level
-tests checking that the logic and the various components
-of your application are working.</p>
-</div>
-</div>
-<div class="section" id="how-to-test-the-user-interface">
-<h1><a name="how-to-test-the-user-interface">How to test the user interface</a></h1>
-<p>Having structured your application properly, you will need a smaller
-number of user interface tests, but still you will need at
-least a few. How do you write these tests then?</p>
-<p>There are two possibilities: the hard way and the easy way.</p>
-<p>The hard way is just doing everything by hand, by using your
-favorite programming language Web libraries to perform GET and POST
-requests and to verify the results. The easy way is to leverage on
-tools built by others. Of course,internally these tools work just by calling
-the low level libraries, so it is convenient to say a couple of words on the
-hard way, just to understand what is going on, in case the high level tool
-give you some problem. Moreover, there is always the possibility than
-you need something more customized, and knowledge of
-the low level libraries can be precious.</p>
-<p>The interaction between the user and a Web application
-passes through the HTTP protocol, so it is perfectly possible
-to simulate the action of an user clicking on a browser
-just by sending to the server an equivalent HTTP request (let me
-ignore the existence of Javascript for the moment).</p>
-<p>Any modern programming language has libraries to interact with the
-HTTP protocol, but here I will give my examples in Python, since Python
-is both a common language for Web programming and a readable one. In Python
-the interaction with the Web is managed via the urllib libraries <a class="footnote-reference" href="#id12" id="id2" name="id2">[2]</a>.
-You have two of them: urllib, which can be used in absence of authentication,
-and urllib2 which can also manage cookie-based authentication. A complete
-discussion of these two libraries would take a long
-time, but explaining the basics is pretty simple. I will just give
-a couple of recipes based on urllib2, the newest and most powerful library.</p>
-<p>I will notice here that the support for cookies in Python 2.4
-has improved (essentially by including the third party ClientCookie
-library) so you may not be aware of the trick I am going to explain, even
-if have used the urllib libraries in the past. So, don't skip the
-next two sections ;)</p>
-<div class="section" id="recipe-1-how-to-send-get-and-post-requests">
-<h2><a name="recipe-1-how-to-send-get-and-post-requests">Recipe 1: how to send GET and POST requests</a></h2>
-<p>Suppose you want to access a site which does not require authentication.
-Then making a GET request is pretty easy, just type at the intepreter
-prompt</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from urllib2 import urlopen
-&gt;&gt;&gt; page = urlopen(&quot;http://www.example.com&quot;)
-</pre>
-<p>Now you have a file like-object which contains the HTML code
-of the page <a class="reference" href="http://www.example.com">http://www.example.com</a>:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; for line in page: print line,
-&lt;HTML&gt;
-&lt;HEAD&gt;
- &lt;TITLE&gt;Example Web Page&lt;/TITLE&gt;
-&lt;/HEAD&gt;
-&lt;body&gt;
-&lt;p&gt;You have reached this web page by typing &amp;quot;example.com&amp;quot;,
-&amp;quot;example.net&amp;quot;,
- or &amp;quot;example.org&amp;quot; into your web browser.&lt;/p&gt;
-&lt;p&gt;These domain names are reserved for use in documentation and are not available
- for registration. See &lt;a href=&quot;http://www.rfc-editor.org/rfc/rfc2606.txt&quot;&gt;RFC
- 2606&lt;/a&gt;, Section 3.&lt;/p&gt;
-&lt;/BODY&gt;
-&lt;/HTML&gt;
-</pre>
-<p>If you try to access a non-existent page, or if your Internet
-connection is down, you will get an <tt class="docutils literal"><span class="pre">urllib2.URLError</span></tt> instead.
-Incidentally, this is why the <tt class="docutils literal"><span class="pre">urllib2.urlopen</span></tt> function is better
-than the older <tt class="docutils literal"><span class="pre">urllib.urlopen</span></tt>, which would just silently retrieve
-a page containing the error message.</p>
-<p>You can easily imagine how to use urlopen to check your Web application:
-for instance, you could retrieve a page, extract all the links and
-check that they refer to existing pages; or you can verify that
-the retrieved page contains the right information, for instance
-by matching it with a regular expression. In practice, <tt class="docutils literal"><span class="pre">urlopen</span></tt>
-(possibly coupled with a third party HTML parsing tool, such as
-BeautifulSoup <a class="footnote-reference" href="#id13" id="id3" name="id3">[3]</a>) gives you all the fine granted control you may wish for.</p>
-<p>Moreover, <tt class="docutils literal"><span class="pre">urlopen</span></tt> gives you the possibility to make a POST:
-just pass the query
-string as second argument to urlopen. As an example, I will make a POST
-to <a class="reference" href="http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/widgets">http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/widgets</a>, which is a
-page containing the example form coming with Quixote, a nice small
-Pythonic Web Framework <a class="footnote-reference" href="#id14" id="id4" name="id4">[4]</a>.</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; page = urlopen(&quot;http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/widgets&quot;,
-... &quot;name=MICHELE&amp;password=SECRET&amp;time=1118766328.56&quot;)
-&gt;&gt;&gt; print page.read()
-&lt;html&gt;
-&lt;head&gt;&lt;title&gt;Quixote Widget Demo&lt;/title&gt;&lt;/head&gt;
-&lt;body&gt;
-&lt;h2&gt;You entered the following values:&lt;/h2&gt;
-&lt;table&gt;
- &lt;tr&gt;&lt;th align=&quot;left&quot;&gt;name&lt;/th&gt;&lt;td&gt;MICHELE&lt;/td&gt;&lt;/tr&gt;
- &lt;tr&gt;&lt;th align=&quot;left&quot;&gt;password&lt;/th&gt;&lt;td&gt;SECRET&lt;/td&gt;&lt;/tr&gt;
- &lt;tr&gt;&lt;th align=&quot;left&quot;&gt;confirmation&lt;/th&gt;&lt;td&gt;False&lt;/td&gt;&lt;/tr&gt;
- &lt;tr&gt;&lt;th align=&quot;left&quot;&gt;eye colour&lt;/th&gt;&lt;td&gt;&lt;i&gt;nothing&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;
- &lt;tr&gt;&lt;th align=&quot;left&quot;&gt;pizza size&lt;/th&gt;&lt;td&gt;&lt;i&gt;nothing&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;
- &lt;tr&gt;&lt;th align=&quot;left&quot;&gt;pizza toppings&lt;/th&gt;&lt;td&gt;&lt;i&gt;nothing&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;
-&lt;/table&gt;
-&lt;p&gt;It took you 163.0 sec to fill out and submit the form&lt;/p&gt;
-&lt;/body&gt;
-&lt;/html&gt;
-</pre>
-<p>Now <tt class="docutils literal"><span class="pre">page</span></tt> will contain the result of your POST. Notice that I had to
-pass explicitly a value for <tt class="docutils literal"><span class="pre">time</span></tt>, which is an hidden widget in
-the form.</p>
-<p>That was easy, isn't it?</p>
-<p>If the site requires authentication, things are slightly more complicated,
-but not much, at least if you have Python 2.4 installed.</p>
-</div>
-<div class="section" id="recipe-2-managing-authentication">
-<h2><a name="recipe-2-managing-authentication">Recipe 2: managing authentication</a></h2>
-<p>In order to manage cookie-based authentication procedures,
-you need to import a few utilities from urllib2:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from urllib2 import build_opener, HTTPCookieProcessor, Request
-</pre>
-<p>Notice that <tt class="docutils literal"><span class="pre">HTTPCookieProcessor</span></tt> is new in Python 2.4: if you have
-an older version of Python you need third party libraries
-such as <cite>ClientCookie</cite> <a class="footnote-reference" href="#id15" id="id5" name="id5">[5]</a>.</p>
-<p><tt class="docutils literal"><span class="pre">build_opener</span></tt> and <tt class="docutils literal"><span class="pre">HTTPCookieProcessor</span></tt> are used to create an opener
-object that can manage the cookies sent by the Web server:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; opener = build_opener(HTTPCookieProcessor)
-</pre>
-<p>The opener object has an <tt class="docutils literal"><span class="pre">open</span></tt> method that can be used to retrieve
-the Web page corresponding to a given request. The request itself is
-encapsulated in a <tt class="docutils literal"><span class="pre">Request</span></tt> object, which is built from the
-URL address, the query string, and some HTTP headers information.
-In order togenerate the query string, it is pretty convenient
-to use the <tt class="docutils literal"><span class="pre">urlencode</span></tt> function defined in <tt class="docutils literal"><span class="pre">urllib</span></tt> (<em>not</em> in <tt class="docutils literal"><span class="pre">urllib2</span></tt>):</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; from urllib import urlencode
-</pre>
-<p><tt class="docutils literal"><span class="pre">urlencode</span></tt> generates the query string from a dictionary
-or a list of pairs, taking care of the quoting and escaping
-rules required by the HTTP protocol. For instance</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; urlencode(dict(user=&quot;MICHELE&quot;, password=&quot;SECRET&quot;))
-'password=SECRET&amp;user=MICHELE'
-</pre>
-<p>Notice that the order is not preserved when you use a dictionary
-(quite obviously), but this is usually
-not an issue. Now, let me define a helper function:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; def urlopen2(url, data=None, user_agent='urlopen2'):
-... &quot;&quot;&quot;Can be used to retrieve cookie-enabled Web pages (when 'data' is
-... None) and to post Web forms (when 'data' is a list, tuple or dictionary
-... containing the parameters of the form).
-... &quot;&quot;&quot;
-... if hasattr(data, &quot;__iter__&quot;):
-... data = urllib.urlencode(data)
-... headers = {'User-Agent' : user_agent}
-... return opener.open(urllib2.Request(url, data, headers))
-</pre>
-<p>With <tt class="docutils literal"><span class="pre">urlopen2</span></tt>, you can POST your form in just one line.
-On the other hand, if the page you are posting to does not contain a form,
-you will get an HTTPError:</p>
-<pre class="doctest-block">
-&gt;&gt;&gt; urlopen2(&quot;http://www.example.com&quot;, dict(user=&quot;MICHELE&quot;, password=&quot;SECRET&quot;))
-Traceback (most recent call last):
- ...
-HTTPError: HTTP Error 405: Method Not Allowed
-</pre>
-<p>If you just need to perform a GET, simply forget about the second argument
-to <tt class="docutils literal"><span class="pre">urlopen2</span></tt>, or use an empty dictionary or tuple. You can even fake a
-browser by passing a convenient user agent string, such as
-&quot;Mozilla&quot;, &quot;Internet Explorer&quot;, etc. This is pretty useful if you want
-to make sure that your application works with different browsers.</p>
-<p>Using these two recipes it is not that difficilt to write your own web
-testing framework. But you may be better off by leveraging the work
-of somebody else</p>
-</div>
-</div>
-<div class="section" id="testing-web-applications-the-easy-way-twill">
-<h1><a name="testing-web-applications-the-easy-way-twill">Testing web applications the easy way: twill</a></h1>
-<p>I am a big fan of mini languages, i.e. small languages
-written to perform a specific task (see for instance my O'Reilly article
-on the graph-generation language &quot;dot&quot; <a class="footnote-reference" href="#id16" id="id6" name="id6">[6]</a>). I was very happy when I
-discovered that there a nice little language expressely designed to test
-Web applications. Actually there are two implementations of it: Titus Brown's
-twill <a class="footnote-reference" href="#id17" id="id7" name="id7">[7]</a> and Cory Dodt's Python Browser Poseur, PBP <a class="footnote-reference" href="#id18" id="id8" name="id8">[8]</a>.</p>
-<p>PBP came first, but twill seems to be developing faster. At the time
-of this writing, twill is still pretty young (I am using
-version 0.7.1), but it already works pretty well in most situations.
-Both PBP and twill are based on tools by
-John J. Lee, i.e. mechanize (inspired by Perl), ClientForm and ClientCookie,
-that you may find at <a class="reference" href="http://wwwsearch.sourceforge.net">http://wwwsearch.sourceforge.net</a>. twill also use
-Paul McGuire's PyParsing <a class="footnote-reference" href="#id19" id="id9" name="id9">[9]</a>. However, you don't need to install these
-libraries: twill includes them as zipped libraries (leveraging on the
-new Python 2.3 <tt class="docutils literal"><span class="pre">zipimport</span></tt> module). As a consequence twill installation
-is absolutely obvious and painless (nothing more than the usual
-<tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt>).</p>
-<p>The simplest way to use twill is interactively from the command line.
-Let me show a simple session example:</p>
-<pre class="literal-block">
-$ twill-sh
- -= Welcome to twill! =-
-
-current page: *empty page*
-
-&gt;&gt; go http://www.example.com
-==&gt; at http://www.example.com
-
-&gt;&gt; show
-&lt;HTML&gt;
-&lt;HEAD&gt;
- &lt;TITLE&gt;Example Web Page&lt;/TITLE&gt;
-&lt;/HEAD&gt;
-&lt;body&gt;
-&lt;p&gt;You have reached this web page by typing &amp;quot;example.com&amp;quot;,
-&amp;quot;example.net&amp;quot;,
- or &amp;quot;example.org&amp;quot; into your web browser.&lt;/p&gt;
-&lt;p&gt;These domain names are reserved for use in documentation and are not available
- for registration. See &lt;a href=&quot;http://www.rfc-editor.org/rfc/rfc2606.txt&quot;&gt;RFC
- 2606&lt;/a&gt;, Section 3.&lt;/p&gt;
-&lt;/BODY&gt;
-&lt;/HTML&gt;
-</pre>
-<p>twill recognizes a few intuitive commands, such as</p>
-<blockquote>
-<pre class="literal-block">
-go, show, find, notfind, echo, code, back, reload, agent, follow
-</pre>
-</blockquote>
-<p>and few others. The example shows how you can access
-a particular HTML page and display its content.</p>
-<p>The <tt class="docutils literal"><span class="pre">find</span></tt> command matches the page against a regular
-expression: thus</p>
-<pre class="literal-block">
-&gt;&gt; find(&quot;Example Web Page&quot;)
-</pre>
-<p>is a test asserting that the current page contains what we expect.
-Similarly, the <tt class="docutils literal"><span class="pre">notfind</span></tt> command asserts that the current page does
-not match the given regular expression.</p>
-<p>The other twill commands are pretty obvious: <tt class="docutils literal"><span class="pre">echo</span> <span class="pre">&lt;message&gt;</span></tt>
-prints a message on standard output, <tt class="docutils literal"><span class="pre">code</span> <span class="pre">&lt;http_error_code&gt;</span></tt> checks
-that you are getting the right HTTP error code (200 if everything is
-alright), <tt class="docutils literal"><span class="pre">back</span></tt> allows you to go back to the previously visited page,
-<tt class="docutils literal"><span class="pre">reload</span></tt> reloads the current page, <tt class="docutils literal"><span class="pre">agent</span> <span class="pre">&lt;user-agent&gt;</span></tt> allows you
-to change the current user agent, thus faking different browsers,
-<tt class="docutils literal"><span class="pre">follow</span> <span class="pre">&lt;regex&gt;</span></tt> finds the first matching link on the page and visit it.</p>
-<p>The full lists of the commands can be obtained
-by giving <tt class="docutils literal"><span class="pre">help</span></tt> at the prompt; <tt class="docutils literal"><span class="pre">EOF</span></tt> of <tt class="docutils literal"><span class="pre">CTRL-D</span></tt> allows you to exit.</p>
-<p>Once you have tested your application interactively, it is pretty easy
-to cut &amp; paste your twill session and convert it in a twill script.
-Then, you can run your twill script in a batch process:</p>
-<pre class="literal-block">
-$ twill-sh mytests.twill
-</pre>
-<p>As you may imagine, you can put more than one script in the command line and
-test many of them at the same time. Since twill is written in Python, you
-can control it from Python entirely, and you can even extends its command
-set just by adding new commands in the <tt class="docutils literal"><span class="pre">commands.py</span></tt> module.</p>
-<p>At the moment, twill is pretty young and it does not have the
-capability to convert scripts in unit tests automatically, so that
-you can easily run entire suites of regression tests. However,
-it is not that difficult to implement that capability yourself,
-and it is not unlikely that twill will gain good integration with
-unittest and doctest in the future.</p>
-<div class="section" id="retrieving-and-submitting-web-forms">
-<h2><a name="retrieving-and-submitting-web-forms">Retrieving and submitting web forms</a></h2>
-<p>twill is especially good at retrieving and submitting web forms. The
-form-related functionality is implemented with the following commands:</p>
-<ul class="simple">
-<li>showforms</li>
-<li>formvalue &lt;form_id&gt; &lt;name&gt; &lt;value&gt;</li>
-<li>submit &lt;button_id&gt;</li>
-<li>formclear &lt;form_id&gt;</li>
-</ul>
-<p>Explaining the commands is pretty straightforward.</p>
-<p><tt class="docutils literal"><span class="pre">showforms</span></tt> shows the forms contained in a web page. For instance, try
-the following:</p>
-<pre class="literal-block">
-&gt;&gt; go http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/widgets
-&gt;&gt; showforms
-Form #1
-## __Name______ __Type___ __ID________ __Value__________________
- name text (None)
- password password (None)
- confirm checkbox (None) [] of ['yes']
- colour radio (None) [] of ['green', 'blue', 'brown', 'ot ...
- size select (None) ['Medium (10&quot;)'] of ['Tiny (4&quot;)', 'S ...
- toppings select (None) ['cheese'] of ['cheese', 'pepperoni' ...
- time hidden (None) 1118768019.17
-1 submit (None) Submit
-current page: http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/widgets
-</pre>
-<p>Notice that <tt class="docutils literal"><span class="pre">twill</span></tt> makes a good job at emulating a browser, so it fills
-the hidden <tt class="docutils literal"><span class="pre">time</span></tt> widget automatically, whereas
-we had to fill it explicitely with <tt class="docutils literal"><span class="pre">urlopen</span></tt>.</p>
-<p>Unnamed forms get an ordinal number to be used as form id
-in the <tt class="docutils literal"><span class="pre">formvalue</span></tt> command, which fill a field
-of the specified form with a given value. You can give many
-formvalue commands in succession; if you are a lazy typist
-you can also use <tt class="docutils literal"><span class="pre">fv</span></tt> as an alias for <tt class="docutils literal"><span class="pre">formvalue</span></tt>:</p>
-<pre class="literal-block">
-&gt;&gt; fv 1 name MICHELES
-current page: http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/widgets
-&gt;&gt; fv 1 password SECRET
-current page: http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/widgets
-</pre>
-<p><tt class="docutils literal"><span class="pre">formclear</span></tt> reset all the fields in a form and <tt class="docutils literal"><span class="pre">submit</span></tt> allows
-you to press a <tt class="docutils literal"><span class="pre">submit</span></tt> botton, thus submitting the form:</p>
-<pre class="literal-block">
-&gt;&gt; submit 1
-current page: http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/widgets
-</pre>
-<p>A simple <tt class="docutils literal"><span class="pre">show</span></tt> will convince you that the forms has been submitted.
-The best way to understand how does it work is just experimenting
-on your own. The base distribution contains a few examples you may
-play with.</p>
-</div>
-</div>
-<div class="section" id="enlarging-the-horizon">
-<h1><a name="enlarging-the-horizon">Enlarging the horizon</a></h1>
-<p>In this article I have shown two easy ways to test your web
-application: by hand, using urllib, or with a simple tool such as twill.
-There is more under the sun. Much more. There are many sophisticated
-Web testing frameworks out there, including enterprise-oriented ones,
-with lots of functionalities and a steep learning curve. Here, on purpose,
-I have decided to start from the small, and to discuss the topic from a
-do-it-yourself attitude, since sometimes the simplest things works best: or
-because you don't need the sophistication, or because your preferred
-testing framework lacks the functionality you wish for, or because
-it is just buggy. If you need something more sophisticated, a great source for
-everything testing-related is Grig Gheorghiu's blog:</p>
-<p><a class="reference" href="http://agiletesting.blogspot.com/2005/02/articles-and-tutorials.html">http://agiletesting.blogspot.com/2005/02/articles-and-tutorials.html</a></p>
-<p>A new framework which is especially interesting is Selenium, which
-is also used to test Plone applications. Selenium is <em>really</em> spectacular,
-since it is Javascript based and it really tests your browser, clicking
-on links, submitting forms, opening popup windows, all in real time. It
-completely emulates the user experience, at highest possible level.
-It also gives
-you all kind of bells and whistles, eye candies and colored HTML output
-(which you may like or not, but that surely will impress your customer
-if you are going to demonstrate him that the application is conform to
-the specifications).
-I cannot render justice to Selenium in a few lines and maybe I should write
-a whole new paper on it, when I find the time. For the moment, however I make
-no promises and I refer you to the available documentation <a class="footnote-reference" href="#id20" id="id10" name="id10">[10]</a>.</p>
-</div>
-<div class="section" id="references">
-<h1><a name="references">References</a></h1>
-<table class="docutils footnote" frame="void" id="id11" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id1" name="id11">[1]</a></td><td>I am an early adopter and supporter of doctests, see for
-instance my talk at the ACCU conference,
-<a class="reference" href="http://www.reportlab.org/~andy/accu2005/pyuk2005_simionato_doctest.zip">http://www.reportlab.org/~andy/accu2005/pyuk2005_simionato_doctest.zip</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id12" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id2" name="id12">[2]</a></td><td>For the <tt class="docutils literal"><span class="pre">urllib</span></tt> libraries see the Python docs
-<a class="reference" href="http://docs.python.org/lib/module-urllib2.html">http://docs.python.org/lib/module-urllib2.html</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id13" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id3" name="id13">[3]</a></td><td>For <cite>BeautifulSoup``</cite> see <a class="reference" href="http://www.crummy.com/software/BeautifulSoup">http://www.crummy.com/software/BeautifulSoup</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id14" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id4" name="id14">[4]</a></td><td>For Quixote see <a class="reference" href="http://www.mems-exchange.org/software/quixote">http://www.mems-exchange.org/software/quixote</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id15" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id5" name="id15">[5]</a></td><td>For <tt class="docutils literal"><span class="pre">mechanize</span></tt> and <tt class="docutils literal"><span class="pre">ClientCookie</span></tt> see
-<a class="reference" href="http://wwwsearch.sourceforge.net">http://wwwsearch.sourceforge.net</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id16" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id6" name="id16">[6]</a></td><td><a class="reference" href="http://www.linuxdevcenter.com/pub/a/linux/2004/05/06/graphviz_dot.html">http://www.linuxdevcenter.com/pub/a/linux/2004/05/06/graphviz_dot.html</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id17" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id7" name="id17">[7]</a></td><td>For <tt class="docutils literal"><span class="pre">twill</span></tt> see
-<a class="reference" href="http://darcs.idyll.org/%7Et/projects/twill/README.html">http://darcs.idyll.org/%7Et/projects/twill/README.html</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id18" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id8" name="id18">[8]</a></td><td>For the <tt class="docutils literal"><span class="pre">Python</span> <span class="pre">Browser</span> <span class="pre">Poseur</span></tt> see <a class="reference" href="http://pbp.berlios.de">http://pbp.berlios.de</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id19" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id9" name="id19">[9]</a></td><td>For <tt class="docutils literal"><span class="pre">PyParsing</span></tt> see <a class="reference" href="http://pyparsing.sourceforge.net">http://pyparsing.sourceforge.net</a></td></tr>
-</tbody>
-</table>
-<table class="docutils footnote" frame="void" id="id20" rules="none">
-<colgroup><col class="label" /><col /></colgroup>
-<tbody valign="top">
-<tr><td class="label"><a class="fn-backref" href="#id10" name="id20">[10]</a></td><td>For <tt class="docutils literal"><span class="pre">Selenium</span></tt> see <a class="reference" href="http://selenium.thoughtworks.com/index.html">http://selenium.thoughtworks.com/index.html</a></td></tr>
-</tbody>
-</table>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/twisted/P01.html b/pypers/twisted/P01.html
deleted file mode 100644
index eb3ae60..0000000
--- a/pypers/twisted/P01.html
+++ /dev/null
@@ -1,93 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P01</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P02.html'>Next</a></td> <td bgcolor="lightblue"><a href='P16.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>An Introduction to Twisted</h1><br/>
-
-<center>
-Seminar given at StatPro Italia<br/>
-15 September 2005 <br/>
-Michele Simionato<br/>
-
-</center></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P02.html b/pypers/twisted/P02.html
deleted file mode 100644
index 10ff392..0000000
--- a/pypers/twisted/P02.html
+++ /dev/null
@@ -1,92 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P02</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>Next</a></td> <td bgcolor="lightblue"><a href='P01.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P02.html'>P02</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Three things</h1><br/>
-
-<ul>
- <li> What's Twisted <em>(life in an asynchronous world)</em> </li>
- <li> Using deferreds <em>(the Hollywood principle)</em> </li>
- <li> Writing servers and clients with Twisted </li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P03.html b/pypers/twisted/P03.html
deleted file mode 100644
index 04ec67a..0000000
--- a/pypers/twisted/P03.html
+++ /dev/null
@@ -1,95 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P03</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P04.html'>Next</a></td> <td bgcolor="lightblue"><a href='P02.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>What's Twisted?</h1><br/>
-
-Asynchronous Framework for Network Programming
-
-<ul>
- <li> Synchronous </li>
- <li> Threaded </li>
- <li> Multiprocess </li>
- <li> Asynchronous </li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P04.html b/pypers/twisted/P04.html
deleted file mode 100644
index 603a3d3..0000000
--- a/pypers/twisted/P04.html
+++ /dev/null
@@ -1,101 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P04</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>Next</a></td> <td bgcolor="lightblue"><a href='P03.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P04.html'>P04</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Example: a file downloader</h1><br/>
-
-<pre>
-class Downloader(cmd.Cmd):
- out = TkWindow()
- def postloop(self):
- self.out.close()
- def do_quit(self, arg):
- return True
- def download(self, fname):
- self.out.write("BEGIN %s" % fname)
- for line in file(fname):
- time.sleep(.1)
- self.out.write(".")
- self.out.write(" END %s\n" % fname)
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P05.html b/pypers/twisted/P05.html
deleted file mode 100644
index 072b18c..0000000
--- a/pypers/twisted/P05.html
+++ /dev/null
@@ -1,97 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P05</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P06.html'>Next</a></td> <td bgcolor="lightblue"><a href='P04.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Threaded file downloader</h1><br/>
-
-<pre>
-class ThreadedDownloader(Downloader):
- def do_download(self, arg):
- self.thread = threading.Thread(
- target=self.download, args=(arg,))
- self.thread.start()
- def postloop(self):
- self.thread.join() # wait before closing self.out
- Downloader.postloop(self)
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P06.html b/pypers/twisted/P06.html
deleted file mode 100644
index 0760355..0000000
--- a/pypers/twisted/P06.html
+++ /dev/null
@@ -1,98 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P06</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>Next</a></td> <td bgcolor="lightblue"><a href='P05.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P06.html'>P06</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Issues with threads</h1><br/>
-
-<ul>
- <li>Platform bugs </li>
- <li>Your own bugs</li>
- <li>You <em>cannot kill threads</em></li>
- <ul>
- <li>unhandled exceptions do not stop the program</li>
- <li>sys.exit does not work </li>
- <li>CTRL-C does not work</li>
- </ul>
- <li>Performance and scalability issues</li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P07.html b/pypers/twisted/P07.html
deleted file mode 100644
index 326bd4e..0000000
--- a/pypers/twisted/P07.html
+++ /dev/null
@@ -1,91 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P07</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P08.html'>Next</a></td> <td bgcolor="lightblue"><a href='P06.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Solution: split the computation in steps.</h1><br/>
-
-<ul>
-<li>Need a way to switch between multiple tasks</li>
-<li>Need a non-blocking mainloop</li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P08.html b/pypers/twisted/P08.html
deleted file mode 100644
index 3b7a213..0000000
--- a/pypers/twisted/P08.html
+++ /dev/null
@@ -1,101 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P08</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>Next</a></td> <td bgcolor="lightblue"><a href='P07.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P08.html'>P08</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Multi iterator</h1><br/>
-
-<pre>
-def multi_iter(iterlist, terminate=True):
- while True:
- for it in iterlist:
- try:
- yield it.next()
- except StopIteration:
- iterlist.remove(it)
- if not iterlist:
- if terminate:
- break
- else:
- yield Nothing
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P09.html b/pypers/twisted/P09.html
deleted file mode 100644
index fb5b514..0000000
--- a/pypers/twisted/P09.html
+++ /dev/null
@@ -1,92 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P09</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P10.html'>Next</a></td> <td bgcolor="lightblue"><a href='P08.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Non-blocking mainloops</h1><br/>
-
-<ul>
-<li> Hand-made command loop </li>
-<li> Twisted mainloop </li>
-<li> Tkinter mainloop </li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P10.html b/pypers/twisted/P10.html
deleted file mode 100644
index 1c80f9c..0000000
--- a/pypers/twisted/P10.html
+++ /dev/null
@@ -1,88 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P10</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>Next</a></td> <td bgcolor="lightblue"><a href='P09.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P10.html'>P10</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Performance</h1><br/>
-
-show <em>million.py</em></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P11.html b/pypers/twisted/P11.html
deleted file mode 100644
index e7dde82..0000000
--- a/pypers/twisted/P11.html
+++ /dev/null
@@ -1,92 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P11</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P12.html'>Next</a></td> <td bgcolor="lightblue"><a href='P10.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Deferreds</h1><br/>
-
-<ul>
- <li> getProcessOutput </li>
- <li> deferToThread </li>
- <li> dbpool.runQuery </li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P12.html b/pypers/twisted/P12.html
deleted file mode 100644
index 9405fb9..0000000
--- a/pypers/twisted/P12.html
+++ /dev/null
@@ -1,91 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P12</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>Next</a></td> <td bgcolor="lightblue"><a href='P11.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P12.html'>P12</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Writing servers</h1><br/>
-
-<ul>
- <li>A server spawning processes</li>
- <li>The server version of the file downloader</li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P13.html b/pypers/twisted/P13.html
deleted file mode 100644
index 049184b..0000000
--- a/pypers/twisted/P13.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P13</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P14.html'>Next</a></td> <td bgcolor="lightblue"><a href='P12.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>A server spawning processes</h1><br/>
-
-<pre>
-class FakeTelnet(protocol.Protocol):
- dirToRunIn = os.getcwd()
- def connectionMade(self):
- print 'connection made'
- self.pp = ProcessProtocol(self)
- cmd = self.factory.cmd_list
- reactor.spawnProcess(self.pp, cmd[0], cmd, os.environ,
- self.dirToRunIn, usePTY=True)
- def dataReceived(self, data):
- self.pp.transport.write(data)
- def connectionLost(self, reason=None):
- print 'connection lost'
- self.pp.transport.loseConnection()
-
-class ProcessProtocol(protocol.ProcessProtocol):
- def __init__(self, telnet):
- self.telnet = telnet
- def outReceived(self, data):
- self.telnet.transport.write(data)
- def errReceived(self, data):
- self.telnet.transport.write("! " + data)
- def processEnded(self, status):
- print 'protocol connection lost'
- self.telnet.transport.loseConnection()
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P14.html b/pypers/twisted/P14.html
deleted file mode 100644
index c3334a6..0000000
--- a/pypers/twisted/P14.html
+++ /dev/null
@@ -1,95 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P14</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>Next</a></td> <td bgcolor="lightblue"><a href='P13.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P14.html'>P14</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>How to run it</h1><br/>
-
-<pre>
-def run(cmd_list, port=1025):
- factory = protocol.ServerFactory()
- factory.protocol = FakeTelnet
- factory.cmd_list = cmd_list
- reactor.listenTCP(port, factory)
- reactor.run()
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P15.html b/pypers/twisted/P15.html
deleted file mode 100644
index a36f1d8..0000000
--- a/pypers/twisted/P15.html
+++ /dev/null
@@ -1,115 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P15</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P16.html'>Next</a></td> <td bgcolor="lightblue"><a href='P14.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Writing clients</h1><br/>
-
-<pre>
-from twisted.internet.protocol import ClientFactory
-from twisted.protocols.basic import LineReceiver
-from twisted.internet import reactor
-
-class EchoClient(LineReceiver):
- end="Bye-bye!"
- def connectionMade(self):
- self.sendLine("Hello, world!")
- self.sendLine("What a fine day it is.")
- self.sendLine(self.end)
- def lineReceived(self, line):
- print "receive:", line
- if line == self.end:
- self.transport.loseConnection()
-
-class EchoClientFactory(ClientFactory):
- protocol = EchoClient
- def clientConnectionFailed(self, connector, reason):
- print 'connection failed:', reason.getErrorMessage()
- reactor.stop()
- def clientConnectionLost(self, connector, reason):
- print 'connection lost:', reason.getErrorMessage()
- reactor.stop()
-
-reactor.connectTCP('localhost', 8000, EchoClientFactory())
-reactor.run()
-</pre></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/twisted/P16.html b/pypers/twisted/P16.html
deleted file mode 100644
index f55310f..0000000
--- a/pypers/twisted/P16.html
+++ /dev/null
@@ -1,91 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
- <html>
- <head>
- <meta name="generator" content="Generated by Python">
- <title>P16</title>
-
-<STYLE TYPE="text/css">
- body { font-size: 160%; }
-</STYLE>
-
- </head>
-<body bgcolor="lightblue">
-
-
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><small>
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><img src = "cjlogo.jpg" alt = "logo"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>Next</a></td> <td bgcolor="lightblue"><a href='P15.html'>Prev</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>First</a></td> <td bgcolor="lightblue"><a href='P16.html'>Last</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P16.html'>P16</a></td> <td bgcolor="lightblue"></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-<tr>
- <td bgcolor="lightblue">
-<table border=0 summary='a table'>
-<tr>
- <td bgcolor="lightblue"><a href='P01.html'>P01</a></td> <td bgcolor="lightblue"><a href='P02.html'>P02</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P03.html'>P03</a></td> <td bgcolor="lightblue"><a href='P04.html'>P04</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P05.html'>P05</a></td> <td bgcolor="lightblue"><a href='P06.html'>P06</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P07.html'>P07</a></td> <td bgcolor="lightblue"><a href='P08.html'>P08</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P09.html'>P09</a></td> <td bgcolor="lightblue"><a href='P10.html'>P10</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P11.html'>P11</a></td> <td bgcolor="lightblue"><a href='P12.html'>P12</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P13.html'>P13</a></td> <td bgcolor="lightblue"><a href='P14.html'>P14</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"><a href='P15.html'>P15</a></td> <td bgcolor="lightblue"><a href='P16.html'>P16</a></td>
-</tr>
-<tr>
- <td bgcolor="lightblue"></td> <td bgcolor="lightblue"></td>
-</tr>
-</table>
-</td>
-</tr>
-</table>
-</small></td> <td bgcolor="lightblue"><h1>Not only Twisted ...</h1><br/>
-
-<ul>
- <li>greenlets</li>
- <li>back button</li>
-</ul></td>
-</tr>
-</table>
-
- </body>
-
-</html>
diff --git a/pypers/wsgi/formulas.html b/pypers/wsgi/formulas.html
deleted file mode 100644
index c98eec7..0000000
--- a/pypers/wsgi/formulas.html
+++ /dev/null
@@ -1,329 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" />
-<meta name="version" content="S5 1.1" />
-<title></title>
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-12-18 01:56:14 +0100 (Sun, 18 Dec 2005) $
-:Revision: $Revision: 4224 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-
-See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
-customize this style sheet.
-*/
-
-/* used to remove borders from tables and images */
-.borderless, table.borderless td, table.borderless th {
- border: 0 }
-
-table.borderless td, table.borderless th {
- /* Override padding for "table.docutils td" with "! important".
- The right padding separates the table cells. */
- padding: 0 0.5em 0 0 ! important }
-
-.first {
- /* Override more specific margin styles with "! important". */
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em ;
- margin-right: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid 1px gray;
- margin-left: 1px }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid 1px black;
- margin-left: 1px }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-<!-- configuration parameters -->
-<meta name="defaultView" content="slideshow" />
-<meta name="controlVis" content="hidden" />
-<!-- style sheet links -->
-<script src="ui/default/slides.js" type="text/javascript"></script>
-<link rel="stylesheet" href="ui/default/slides.css"
- type="text/css" media="projection" id="slideProj" />
-<link rel="stylesheet" href="ui/default/outline.css"
- type="text/css" media="screen" id="outlineStyle" />
-<link rel="stylesheet" href="ui/default/print.css"
- type="text/css" media="print" id="slidePrint" />
-<link rel="stylesheet" href="ui/default/opera.css"
- type="text/css" media="projection" id="operaFix" />
-
-<style type="text/css">
-#currentSlide {display: none;}
-</style>
-</head>
-<body>
-<div class="layout">
-<div id="controls"></div>
-<div id="currentSlide"></div>
-<div id="header">
-
-</div>
-<div id="footer">
-
-</div>
-</div>
-<div class="presentation">
-<div class="slide" id="slide0">
-<math xmlns='http://www.w3.org/1998/Math/MathML'>
-<mi>&Phi;</mi>
-<mo>(</mo><mi>x</mi><mo>)</mo><mo>=</mo><mfrac><mn>12</mn><mo>+</mo></mfrac><mfrac><mn>12</mn><mi>erf</mi></mfrac><mo>(</mo><mi>x</mi><mo>/</mo><msqrt><mo>(</mo></msqrt><mn>2</mn><mo>)</mo><mo>)</mo>
-</math></div>
-</div>
-</body>
-</html>
diff --git a/pypers/wsgi/talk.html b/pypers/wsgi/talk.html
deleted file mode 100644
index 925b833..0000000
--- a/pypers/wsgi/talk.html
+++ /dev/null
@@ -1,1207 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!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" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" />
-<meta name="version" content="S5 1.1" />
-<title>SciPy on WSGI</title>
-<meta name="organization" content="StatPro Italy" />
-<meta name="date" content="2007-06-09" />
-<style type="text/css">
-
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2005-12-18 01:56:14 +0100 (Sun, 18 Dec 2005) $
-:Revision: $Revision: 4224 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-
-See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
-customize this style sheet.
-*/
-
-/* used to remove borders from tables and images */
-.borderless, table.borderless td, table.borderless th {
- border: 0 }
-
-table.borderless td, table.borderless th {
- /* Override padding for "table.docutils td" with "! important".
- The right padding separates the table cells. */
- padding: 0 0.5em 0 0 ! important }
-
-.first {
- /* Override more specific margin styles with "! important". */
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em ;
- margin-right: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid 1px gray;
- margin-left: 1px }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid 1px black;
- margin-left: 1px }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
-
-</style>
-<!-- configuration parameters -->
-<meta name="defaultView" content="slideshow" />
-<meta name="controlVis" content="hidden" />
-<!-- style sheet links -->
-<script src="ui/default/slides.js" type="text/javascript"></script>
-<link rel="stylesheet" href="ui/default/slides.css"
- type="text/css" media="projection" id="slideProj" />
-<link rel="stylesheet" href="ui/default/outline.css"
- type="text/css" media="screen" id="outlineStyle" />
-<link rel="stylesheet" href="ui/default/print.css"
- type="text/css" media="print" id="slidePrint" />
-<link rel="stylesheet" href="ui/default/opera.css"
- type="text/css" media="projection" id="operaFix" />
-
-<style type="text/css">
-#currentSlide {display: none;}
-</style>
-</head>
-<body>
-<div class="layout">
-<div id="controls"></div>
-<div id="currentSlide"></div>
-<div id="header">
-
-</div>
-<div id="footer">
-<h1>SciPy on WSGI</h1>
-<h2>PyCon Uno 2007 - 09 June 2007</h2>
-</div>
-</div>
-<div class="presentation">
-<div class="slide" id="slide0">
-<h1 class="title">SciPy on WSGI</h1>
-<table class="docinfo" frame="void" rules="none">
-<col class="docinfo-name" />
-<col class="docinfo-content" />
-<tbody valign="top">
-<tr class="field"><th class="docinfo-name">Talk given at:</th><td class="field-body">PyCon Uno 2007</td>
-</tr>
-<tr class="field"><th class="docinfo-name">By:</th><td class="field-body">Michele Simionato</td>
-</tr>
-<tr><th class="docinfo-name">Organization:</th>
-<td>StatPro Italy</td></tr>
-<tr><th class="docinfo-name">Date:</th>
-<td>2007-06-09</td></tr>
-</tbody>
-</table>
-<!-- Definitions of interpreted text roles (classes) for S5/HTML data. -->
-<!-- This data file has been placed in the public domain. -->
-<!-- Colours
-======= -->
-<!-- Text Sizes
-========== -->
-<!-- Display in Slides (Presentation Mode) Only
-========================================== -->
-<!-- Display in Outline Mode Only
-============================ -->
-<!-- Display in Print Only
-===================== -->
-<!-- Incremental Display
-=================== -->
-<p class="center"><strong>Subtitle</strong>: <em>Science on the Web for pedestrians</em></p>
-
-</div>
-<div class="slide" id="before-i-start">
-<h1>Before I start</h1>
-<p>What about you?</p>
-<p class="incremental">Are you more of a programmer or more of a scientist/engineer?</p>
-<p class="incremental">What kind of scientific tools are you using, if any?</p>
-<p class="incremental">Have you ever heard of SciPy?</p>
-<p class="incremental">Have you ever heard of WSGI?</p>
-</div>
-<div class="slide" id="ok-now-i-can-begin">
-<h1>Ok, now I can begin ;)</h1>
-<p>The motivation from this talk comes from a real problem at <a class="reference" href="http://www.statpro.com">StatPro</a></p>
-<p class="incremental">we have bad histories for many financial products</p>
-<p class="incremental">wrong prices at some dates in the past</p>
-</div>
-<div class="slide" id="a-picture">
-<h1>A picture</h1>
-<img alt="badpricehistory.png" src="badpricehistory.png" />
-<p class="incremental">(damn data providers!)</p>
-</div>
-<div class="slide" id="discarding-values">
-<h1>Discarding values ...</h1>
-<img alt="badpricehistory2.png" src="badpricehistory2.png" />
-<p>... is tricky!</p>
-</div>
-<div class="slide" id="issues">
-<h1>Issues</h1>
-<p>We cannot use the conventional criterium</p>
-<img alt="nongaussian.png" class="incremental" src="nongaussian.png" />
-</div>
-<div class="slide" id="strategy">
-<h1>Strategy</h1>
-<ul class="incremental simple">
-<li>price distributions (ln p_i/p) are known to decay with power laws</li>
-<li>fit the distributions with a &quot;reasonable&quot; curve and determine
-a suitable criterium for the spikes at some confidence level</li>
-<li>a reasonably simple ansatz gives a family of distributions depending
-on a parameter delta</li>
-<li><a class="reference" href="formulas.pdf">show formulae</a></li>
-</ul>
-</div>
-<div class="slide" id="delta-distribution">
-<h1>delta-distribution</h1>
-<img alt="delta-dist.png" src="delta-dist.png" />
-<p>From Dirac delta (delta -&gt; 0) to Gaussian
-distribution (delta -&gt; oo)</p>
-</div>
-<div class="slide" id="cumulative-dist">
-<h1>Cumulative dist</h1>
-<img alt="cdf-dist.png" src="cdf-dist.png" />
-<p>VAR-XX = Max loss at XX% confidence level [<a class="reference" href="http://integrals.wolfram.com/index.jsp">i</a>]</p>
-</div>
-<div class="slide" id="relation-var-vol">
-<h1>Relation VAR-vol.</h1>
-<p>If you assume a given distribution, there is a fixed relation between
-VAR-XX and volatility</p>
-<ul class="incremental simple">
-<li>for the Gaussian VAR-95 = 1.64 sigma, for a lot of our distributions
-VAR-95 &lt; 1.0 sigma</li>
-<li>we don't want to make assumptions on the distribution function
-for computing the VAR</li>
-<li>but we are willing to make assumptions for the sake of eliminating
-statistically invalid values</li>
-</ul>
-</div>
-<div class="slide" id="the-tool-we-need">
-<h1>The tool we need</h1>
-<pre class="literal-block">
-$ python simpleplotter.py &quot;fri-gb;AVE&quot;
-</pre>
-<p>(not 100% finished yet!)</p>
-</div>
-<div class="slide" id="enter-scipy-co">
-<h1>Enter SciPy &amp; Co.</h1>
-<p>In order to perform our analysis we looked
-at many scientific tools</p>
-<ul class="incremental simple">
-<li>a good plotting tool (matplotlib)</li>
-<li>support for histograms (matplotlib)</li>
-<li>support for special functions (scipy.special)</li>
-<li>support for non-linear fitting (scipy.leastsq)</li>
-<li>good performance (scipy)</li>
-<li>interactive and IPython-friendly (scipy)</li>
-<li>bla-bla</li>
-<li>cheating: I actually used Gnuplot!! ;-)</li>
-</ul>
-</div>
-<div class="slide" id="installation">
-<h1>Installation</h1>
-<p>If you are lucky, it is trivial:</p>
-<pre class="literal-block">
-$ apt-get install ipython
-$ apt-get install python-matplotlib
-$ apt-get install python-numpy
-$ apt-get install python-numpy-ext
-$ apt-get install python-scipy
-</pre>
-<p>If you are unlucky, or if you try to build from sources,
-YMMV ...</p>
-</div>
-<div class="slide" id="what-s-in-scipy">
-<h1>What's in Scipy</h1>
-<ul class="incremental simple">
-<li>support for multi-dimensional array (numpy)</li>
-<li>linear algebra and minimization routines</li>
-<li>solving, integration, interpolation, fitting</li>
-<li>special functions and statistical functions</li>
-<li>etc. etc.</li>
-</ul>
-</div>
-<div class="slide" id="special-functions">
-<h1>Special functions</h1>
-<p>Airy Functions:</p>
-<pre class="literal-block">
-airy
---Airy functions and their derivatives.
-airye
---Exponentially scaled Airy functions
-ai_zeros
---Zeros of Airy functions Ai(x) and Ai'(x)
-bi_zeros
---Zeros of Airy functions Bi(x) and Bi'(x)
-</pre>
-</div>
-<div class="slide" id="elliptic-functions-and-integrals">
-<h1>Elliptic Functions and Integrals</h1>
-<pre class="literal-block">
-ellipj
---Jacobian elliptic functions
-ellipk
---Complete elliptic integral of the first kind.
-ellipkinc
---Incomplete elliptic integral of the first kind.
-ellipe
---Complete elliptic integral of the second kind.
-ellipeinc
---Incomplete elliptic integral of the second kind.
-</pre>
-</div>
-<div class="slide" id="bessel-functions">
-<h1>Bessel Functions</h1>
-<pre class="literal-block">
-jn
---Bessel function of integer order and real argument.
-jv
---Bessel function of real-valued order and complex argument.
-jve
---Exponentially scaled Bessel function.
-yn
---Bessel function of second kind (integer order).
-yv
---Bessel function of the second kind (real-valued order).
-yve
---Exponentially scaled Bessel function of the second kind.
-kn
---Modified Bessel function of the third kind (integer order).
-kv
---Modified Bessel function of the third kind (real order).
-kve
---Exponentially scaled modified Bessel function of the third kind.
-iv
---Modified Bessel function.
-ive
---Exponentially scaled modified Bessel function.
-hankel1
---Hankel function of the first kind.
-hankel1e
---Exponentially scaled Hankel function of the first kind.
-hankel2
---Hankel function of the second kind.
-hankel2e
---Exponentially scaled Hankel function of the second kind.
-
-lmbda
---Sequence of lambda functions with arbitrary order v.
-</pre>
-</div>
-<div class="slide" id="zeros-of-bessel-functions">
-<h1>Zeros of Bessel Functions</h1>
-<pre class="literal-block">
-jnjnp_zeros
---Zeros of integer-order Bessel functions and derivatives
- sorted in order.
-jnyn_zeros
---Zeros of integer-order Bessel functions and derivatives
- as separate arrays.
-jn_zeros
---Zeros of Jn(x)
-jnp_zeros
---Zeros of Jn'(x)
-yn_zeros
---Zeros of Yn(x)
-ynp_zeros
---Zeros of Yn'(x)
-y0_zeros
---Complex zeros: Y0(z0)=0 and values of Y0'(z0)
-y1_zeros
---Complex zeros: Y1(z1)=0 and values of Y1'(z1)
-y1p_zeros
---Complex zeros of Y1'(z1')=0 and values of Y1(z1')
-</pre>
-</div>
-<div class="slide" id="faster-versions">
-<h1>Faster versions</h1>
-<pre class="literal-block">
-j0
---Bessel function of order 0.
-j1
---Bessel function of order 1.
-y0
---Bessel function of second kind of order 0.
-y1
---Bessel function of second kind of order 1.
-i0
---Modified Bessel function of order 0.
-i0e
---Exponentially scaled modified Bessel function of order 0.
-i1
---Modified Bessel function of order 1.
-i1e
---Exponentially scaled modified Bessel function of order 1.
-k0
---Modified Bessel function of the third kind of order 0.
-k0e
---Exponentially scaled modified Bessel function of the
- third kind of order 0.
-k1
---Modified Bessel function of the third kind of order 1.
-k1e
---Exponentially scaled modified Bessel function of the
- third kind of order 1.
-</pre>
-</div>
-<div class="slide" id="integrals-of-bessel-functions">
-<h1>Integrals of Bessel Functions</h1>
-<pre class="literal-block">
-itj0y0
---Basic integrals of j0 and y0 from 0 to x.
-it2j0y0
---Integrals of (1-j0(t))/t from 0 to x and
- y0(t)/t from x to inf.
-iti0k0
---Basic integrals of i0 and k0 from 0 to x.
-it2i0k0
---Integrals of (i0(t)-1)/t from 0 to x and
- k0(t)/t from x to inf.
-besselpoly
---Integral of a bessel function: Jv(2*a*x) * x^lambda
- from x=0 to 1.
-</pre>
-</div>
-<div class="slide" id="derivatives-of-bessel-functions">
-<h1>Derivatives of Bessel Functions</h1>
-<pre class="literal-block">
-jvp
---Nth derivative of Jv(v,z)
-yvp
---Nth derivative of Yv(v,z)
-kvp
---Nth derivative of Kv(v,z)
-ivp
---Nth derivative of Iv(v,z)
-h1vp
---Nth derivative of H1v(v,z)
-h2vp
---Nth derivative of H2v(v,z)
-</pre>
-</div>
-<div class="slide" id="spherical-bessel-functions">
-<h1>Spherical Bessel Functions</h1>
-<pre class="literal-block">
-sph_jn
---Sequence of spherical Bessel functions, jn(z)
-sph_yn
---Sequence of spherical Bessel functions, yn(z)
-sph_jnyn
---Sequence of spherical Bessel functions, jn(z) and yn(z)
-sph_in
---Sequence of spherical Bessel functions, in(z)
-sph_kn
---Sequence of spherical Bessel functions, kn(z)
-sph_inkn
---Sequence of spherical Bessel functions, in(z) and kn(z)
-</pre>
-</div>
-<div class="slide" id="riccati-bessel-fun">
-<h1>Riccati-Bessel Fun.</h1>
-<pre class="literal-block">
-riccati_jn
---Sequence of Ricatti-Bessel functions
- of first kind.
-riccati_yn
---Sequence of Ricatti-Bessel functions
- of second kind.
-</pre>
-</div>
-<div class="slide" id="struve-functions">
-<h1>Struve Functions</h1>
-<pre class="literal-block">
-struve
---Struve function --- Hv(x)
-modstruve
---Modified struve function --- Lv(x)
-itstruve0
---Integral of H0(t) from 0 to x
-it2struve0
---Integral of H0(t)/t from x to Inf.
-itmodstruve0
---Integral of L0(t) from 0 to x.
-</pre>
-</div>
-<div class="slide" id="statistical-functions">
-<h1>Statistical Functions</h1>
-<pre class="literal-block">
-bdtr
---Sum of terms 0 through k of of the binomial pdf.
-bdtrc
---Sum of terms k+1 through n of the binomial pdf.
-bdtri
---Inverse of bdtr
-btdtr
---Integral from 0 to x of beta pdf.
-btdtri
---Quantiles of beta distribution
-fdtr
---Integral from 0 to x of F pdf.
-fdtrc
---Integral from x to infinity under F pdf.
-fdtri
---Inverse of fdtrc
-gdtr
---Integral from 0 to x of gamma pdf.
-gdtrc
---Integral from x to infinity under gamma pdf.
-gdtri
---Quantiles of gamma distribution
-nbdtr
---Sum of terms 0 through k of the negative binomial pdf.
-nbdtrc
---Sum of terms k+1 to infinity under negative binomial pdf.
-nbdtri
---Inverse of nbdtr
-pdtr
---Sum of terms 0 through k of the Poisson pdf.
-pdtrc
---Sum of terms k+1 to infinity of the Poisson pdf.
-pdtri
---Inverse of pdtr
-stdtr
---Integral from -infinity to t of the Student-t pdf.
-stdtri
---Inverse of stdtr (quantiles)
-chdtr
---Integral from 0 to x of the Chi-square pdf.
-chdtrc
---Integral from x to infnity of Chi-square pdf.
-chdtri
---Inverse of chdtrc.
-ndtr
---Integral from -infinity to x of standard normal pdf
-ndtri
---Inverse of ndtr (quantiles)
-smirnov
---Kolmogorov-Smirnov complementary CDF for one-sided
- test statistic (Dn+ or Dn-)
-smirnovi
---Inverse of smirnov.
-kolmogorov
---The complementary CDF of the (scaled) two-sided test
- statistic (Kn*) valid for large n.
-kolmogi
---Inverse of kolmogorov
-tklmbda
---Tukey-Lambda CDF
-</pre>
-</div>
-<div class="slide" id="gamma-and-related-functions">
-<h1>Gamma and Related Functions</h1>
-<pre class="literal-block">
-gamma
---Gamma function.
-gammaln
---Log of the absolute value of the gamma function.
-gammainc
---Incomplete gamma integral.
-gammaincinv
---Inverse of gammainc.
-gammaincc
---Complemented incomplete gamma integral.
-gammainccinv
---Inverse of gammaincc.
-beta
---Beta function.
-betaln
---Log of the absolute value of the beta function.
-betainc
---Incomplete beta integral.
-betaincinv
---Inverse of betainc.
-betaincinva
---Inverse (in first argument, a) of betainc
-betaincinvb
---Inverse (in first argument, b) of betainc
-psi(digamma)
---Logarithmic derivative of the gamma function.
-rgamma
---One divided by the gamma function.
-polygamma
---Nth derivative of psi function.
-</pre>
-</div>
-<div class="slide" id="error-function-and-fresnel-int">
-<h1>Error Function and Fresnel Int.</h1>
-<pre class="literal-block">
-erf
---Error function.
-erfc
---Complemented error function (1- erf(x))
-erfinv
---Inverse of error function
-erfcinv
---Inverse of erfc
-erf_zeros
---Complex zeros of erf(z)
-fresnel
---Fresnel sine and cosine integrals.
-fresnel_zeros
---Complex zeros of both Fresnel integrals
-fresnelc_zeros
---Complex zeros of fresnel cosine integrals
-fresnels_zeros
---Complex zeros of fresnel sine integrals
-modfresnelp
---Modified Fresnel integrals F_+(x) and K_+(x)
-modfresnelm
---Modified Fresnel integrals F_-(x) and K_-(x)
-</pre>
-</div>
-<div class="slide" id="legendre-functions">
-<h1>Legendre Functions</h1>
-<pre class="literal-block">
-lpn
---Legendre Functions (polynomials) of the first kind
-lqn
---Legendre Functions of the second kind.
-lpmn
---Associated Legendre Function of the first kind.
-lqmn
---Associated Legendre Function of the second kind.
-lpmv
---Associated Legendre Function of arbitrary non-negative
- degree v.
-sph_harm
---Spherical Harmonics (complex-valued) Y^m_n(theta,phi)
-</pre>
-</div>
-<div class="slide" id="orthogonal-polyn">
-<h1>Orthogonal polyn.</h1>
-<pre class="literal-block">
-legendre
---Legendre polynomial P_n(x)
-chebyt
---Chebyshev polynomial T_n(x)
-chebyu
---Chebyshev polynomial U_n(x)
-chebyc
---Chebyshev polynomial C_n(x)
-chebys
---Chebyshev polynomial S_n(x)
-jacobi
---Jacobi polynomial P^(alpha,beta)_n(x)
-laguerre
---Laguerre polynomial, L_n(x)
-genlaguerre
---Generalized (Associated) Laguerre polynomial, L^alpha_n(x)
-hermite
---Hermite polynomial H_n(x)
-hermitenorm
---Normalized Hermite polynomial, He_n(x)
-gegenbauer
---Gegenbauer (Ultraspherical) polynomials, C^(alpha)_n(x)
-sh_legendre
---shifted Legendre polynomial, P*_n(x)
-sh_chebyt
---shifted Chebyshev polynomial, T*_n(x)
-sh_chebyu
---shifted Chebyshev polynomial, U*_n(x)
-sh_jacobi
---shifted Jacobi polynomial, J*_n(x) = G^(p,q)_n(x)
-</pre>
-</div>
-<div class="slide" id="hypergeometric-functions">
-<h1>HyperGeometric Functions</h1>
-<pre class="literal-block">
-hyp2f1
---Gauss hypergeometric function (2F1)
-hyp1f1
---Confluent hypergeometric function (1F1)
-hyperu
---Confluent hypergeometric function (U)
-hyp0f1
---Confluent hypergeometric limit function (0F1)
-hyp2f0
---Hypergeometric function (2F0)
-hyp1f2
---Hypergeometric function (1F2)
-hyp3f0
---Hypergeometric function (3F0)
-</pre>
-</div>
-<div class="slide" id="parabolic-cylinder-functions">
-<h1>Parabolic Cylinder Functions</h1>
-<pre class="literal-block">
-pbdv
---Parabolic cylinder function Dv(x) and derivative.
-pbvv
---Parabolic cylinder function Vv(x) and derivative.
-pbwa
---Parabolic cylinder function W(a,x) and derivative.
-pbdv_seq
---Sequence of parabolic cylinder functions Dv(x)
-pbvv_seq
---Sequence of parabolic cylinder functions Vv(x)
-pbdn_seq
---Sequence of parabolic cylinder functions Dn(z), complex z
-</pre>
-</div>
-<div class="slide" id="mathieu-functions">
-<h1>Mathieu functions</h1>
-<pre class="literal-block">
-mathieu_a
---Characteristic values for even solution (ce_m)
-mathieu_b
---Characteristic values for odd solution (se_m)
-mathieu_even_coef
---sequence of expansion coefficients for even solution
-mathieu_odd_coef
---sequence of expansion coefficients for odd solution
- ** All the following return both function and first derivative **
-mathieu_cem
---Even mathieu function
-mathieu_sem
---Odd mathieu function
-mathieu_modcem1
---Even modified mathieu function of the first kind
-mathieu_modcem2
---Even modified mathieu function of the second kind
-mathieu_modsem1
---Odd modified mathieu function of the first kind
-mathieu_modsem2
---Odd modified mathieu function of the second kind
-</pre>
-</div>
-<div class="slide" id="spheroidal-wave-functions">
-<h1>Spheroidal Wave Functions</h1>
-<pre class="literal-block">
-pro_ang1
---Prolate spheroidal angular function of the first kind
-pro_rad1
---Prolate spheroidal radial function of the first kind
-pro_rad2
---Prolate spheroidal radial function of the second kind
-obl_ang1
---Oblate spheroidal angluar function of the first kind
-obl_rad1
---Oblate spheroidal radial function of the first kind
-obl_rad2
---Oblate spheroidal radial function of the second kind
-pro_cv
---Compute characteristic value for prolate functions
-obl_cv
---Compute characteristic value for oblate functions
-pro_cv_seq
---Compute sequence of prolate characteristic values
-obl_cv_seq
---Compute sequence of oblate characteristic values
- ** The following functions require pre-computed characteristic values **
-pro_ang1_cv
---Prolate spheroidal angular function of the first kind
-pro_rad1_cv
---Prolate spheroidal radial function of the first kind
-pro_rad2_cv
---Prolate spheroidal radial function of the second kind
-obl_ang1_cv
---Oblate spheroidal angluar function of the first kind
-obl_rad1_cv
---Oblate spheroidal radial function of the first kind
-obl_rad2_cv
---Oblate spheroidal radial function of the second kind
-</pre>
-</div>
-<div class="slide" id="kelvin-functions">
-<h1>Kelvin Functions</h1>
-<pre class="literal-block">
-kelvin
---All Kelvin functions (order 0) and derivatives.
-kelvin_zeros
---Zeros of All Kelvin functions (order 0) and derivatives
-ber
---Kelvin function ber x
-bei
---Kelvin function bei x
-berp
---Derivative of Kelvin function ber x
-beip
---Derivative of Kelvin function bei x
-ker
---Kelvin function ker x
-kei
---Kelvin function kei x
-kerp
---Derivative of Kelvin function ker x
-keip
---Derivative of Kelvin function kei x
-ber_zeros
---Zeros of Kelvin function bei x
-bei_zeros
---Zeros of Kelvin function ber x
-berp_zeros
---Zeros of derivative of Kelvin function ber x
-beip_zeros
---Zeros of derivative of Kelvin function bei x
-ker_zeros
---Zeros of Kelvin function kei x
-kei_zeros
---Zeros of Kelvin function ker x
-kerp_zeros
---Zeros of derivative of Kelvin function ker x
-keip_zeros
---Zeros of derivative of Kelvin function kei x
-</pre>
-</div>
-<div class="slide" id="other-special-functions">
-<h1>Other Special Functions</h1>
-<pre class="literal-block">
-expn
---Exponential integral.
-exp1
---Exponential integral of order 1 (for complex argument)
-expi
---Another exponential integral
---Ei(x)
-wofz
---Fadeeva function.
-dawsn
---Dawson's integral.
-shichi
---Hyperbolic sine and cosine integrals.
-sici
---Integral of the sinc and &quot;cosinc&quot; functions.
-spence
---Dilogarithm integral.
-zeta
---Riemann zeta function of two arguments.
-zetac
---1.0 - standard Riemann zeta function.
-</pre>
-</div>
-<div class="slide" id="convenience-functions">
-<h1>Convenience Functions</h1>
-<pre class="literal-block">
-cbrt
---Cube root.
-exp10
---10 raised to the x power.
-exp2
---2 raised to the x power.
-radian
---radian angle given degrees, minutes, and seconds.
-cosdg
---cosine of the angle given in degrees.
-sindg
---sine of the angle given in degrees.
-tandg
---tangent of the angle given in degrees.
-cotdg
---cotangent of the angle given in degrees.
-log1p
---log(1+x)
-expm1
---exp(x)-1
-cosm1
---cos(x)-1
-round
---round the argument to the nearest integer. If argument
- ends in 0.5 exactly, pick the nearest even integer.
-</pre>
-</div>
-<div class="slide" id="and-more">
-<h1>... and more!</h1>
-<p>but let us go back to our problem</p>
-<ul class="incremental simple">
-<li>at the present we are cleaning our histories in production with a
-quick and dirty criterium;</li>
-<li>we want to be able to see the histories case by case in order to take
-specific actions;</li>
-<li>we want to go on the Web (--&gt; next)</li>
-</ul>
-</div>
-<div class="slide" id="going-on-the-web">
-<h1>Going on the Web</h1>
-<ul class="incremental simple">
-<li>we want a simple tool for internal usage on our intranet;</li>
-<li>convenient to integrate with other Web tools;</li>
-<li>usable also for non-techical users;</li>
-<li>avoid installing and mantaining on every machine;</li>
-<li>possibly we may open it to our other offices in the world;</li>
-<li>we like the browser interface.</li>
-</ul>
-</div>
-<div class="slide" id="without-a-framework">
-<h1>Without a framework</h1>
-<ul class="incremental simple">
-<li>no security concerns;</li>
-<li>no scalability concerns;</li>
-<li>no nice-looking concerns;</li>
-<li>it must be <em>EASY</em> to change;</li>
-<li>we want minimal learning curve;</li>
-<li>we want no installation/configuration hassle;</li>
-<li>we want no dependencies;</li>
-<li>we want something even simpler than CGI, if possible!</li>
-</ul>
-</div>
-<div class="slide" id="enter-wsgi">
-<h1>Enter WSGI</h1>
-<ul class="incremental simple">
-<li>WSGI = Web Server Gateway Interface (<em>Whiskey</em> for friends)</li>
-<li>the brainchild of Python guru Phillip J. Eby;</li>
-<li>also input from Ian Bicking (<tt class="docutils literal"><span class="pre">paste</span></tt>) and others;</li>
-<li>starting from Python 2.5, we have a WSGI web server in the standard
-library (<tt class="docutils literal"><span class="pre">wsgiref</span></tt>);</li>
-<li>there are plenty of simple and useful add-ons for WSGI applications
-out there;</li>
-<li>even <tt class="docutils literal"><span class="pre">wsgiref</span></tt> fullfills all of our requirements, let's use it!
-(following the example of <a class="reference" href="http://video.google.com/videoplay?docid=-8502904076440714866">Guido</a> ...)</li>
-</ul>
-</div>
-<div class="slide" id="wsgi-key-concepts">
-<h1>WSGI key concepts</h1>
-<ol class="incremental arabic">
-<li><p class="first">WSGI application:</p>
-<p>(env, resp) -&gt; chunks of text</p>
-<p>env = environment dictionary of the server;
-resp = function sending to the client the HTTP headers;</p>
-</li>
-<li><p class="first">WSGI middleware:</p>
-<p>WSGI app -&gt; enhanced WSGI app</p>
-</li>
-</ol>
-</div>
-<div class="slide" id="ex1-hello-world">
-<h1>Ex1: Hello World</h1>
-<pre class="literal-block">
-from wsgiref import simple_server
-
-def app(env, resp):
- resp(
- '200 OK', [('Content-type', 'text/html')])
- return ['&lt;h1&gt;Hello, World!&lt;/h1&gt;']
-
-server=simple_server.make_server('', 8000, app)
-server.serve_forever()
-</pre>
-<p><a class="reference" href="http://localhost:8000">show live example</a></p>
-</div>
-<div class="slide" id="ex2-middleware">
-<h1>Ex2: middleware</h1>
-<p>No middleware in the standard library, but lots of useful middleware
-from third party sources. For instance, authentication middleware:</p>
-<pre class="literal-block">
-from paste.auth.basic import AuthBasicHandler
-
-def only_for_pippo(env, user, passwd):
- return user == 'pippo'
-
-auth_app = AuthBasicHandler(
- app, 'app realm', only_for_pippo)
-</pre>
-</div>
-<div class="slide" id="other-middleware">
-<h1>Other middleware</h1>
-<pre class="literal-block">
-from wsgiref.simple_server import make_server
-from paste.evalexception import EvalException
-
-a, b = 1,0
-
-def app(env, resp):
- resp('200 OK', [('Content-type', 'text/html')])
- return [str(a/b)]
-
-make_server('', 9090, EvalException(app)).serve_forever()
-</pre>
-<p>Show <a class="reference" href="http://localhost:9090">evalexception</a></p>
-</div>
-<div class="slide" id="wsgi-vs-cgi">
-<h1>WSGI vs. CGI</h1>
-<ul class="simple">
-<li>WSGI is simpler than CGI<ul>
-<li><span class="incremental">using wsgiref you don't require an external server</span></li>
-<li><span class="incremental">you can keep sessions in memory</span></li>
-</ul>
-</li>
-<li>WSGI scales better than CGI<ul>
-<li><span class="incremental">there is a large choice of wsgi servers (mod_wsgi, Twisted ...)</span></li>
-<li><span class="incremental">there is a large choice of third party middleware</span></li>
-<li><span class="incremental">it is relatively easy to turn a toy application into a serious one</span></li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="slide" id="wsgi-vs-frameworks">
-<h1>WSGI vs. frameworks</h1>
-<p>Pro:</p>
-<ul class="simple">
-<li><span class="incremental">if you liked playing with Lego, you will be happy</span></li>
-<li><span class="incremental">you have much more control and you are not forced to marry a technology</span></li>
-<li><span class="incremental">you can learn a lot</span></li>
-<li><span class="incremental">others ...</span></li>
-</ul>
-</div>
-<div class="slide" id="id1">
-<h1>WSGI vs. frameworks</h1>
-<p>Contra:</p>
-<ul class="simple">
-<li><span class="incremental">you can build your own framework with WSGI, but you have to debug it</span></li>
-<li><span class="incremental">the existing WSGI frameworks are newer, there is less experience with them</span></li>
-<li><span class="incremental">WSGI is not particularly Twisted-friendly</span></li>
-<li><span class="incremental">others ...</span></li>
-</ul>
-</div>
-<div class="slide" id="the-history-plotter">
-<h1>The history plotter</h1>
-<pre class="literal-block">
-$ python webplotter.py
-</pre>
-<p><a class="reference" href="http://localhost:8000">Click here for the live demonstration</a></p>
-</div>
-<div class="slide" id="references">
-<h1>References</h1>
-<p>That's all, folks!</p>
-<ul class="simple">
-<li><a class="reference" href="http://www.scipy.org">http://www.scipy.org</a></li>
-<li><a class="reference" href="http://www.python.org/dev/peps/pep-0333">http://www.python.org/dev/peps/pep-0333</a></li>
-<li><a class="reference" href="http://pythonpaste.org/do-it-yourself-framework.html">http://pythonpaste.org/do-it-yourself-framework.html</a></li>
-</ul>
-<p class="incremental"><strong>(P.S. at StatPro, we are hiring! ;)</strong></p>
-</div>
-</div>
-</body>
-</html>
diff --git a/pypers/wsgi/ui/default-orig/ex.html b/pypers/wsgi/ui/default-orig/ex.html
deleted file mode 100644
index 798e3cc..0000000
--- a/pypers/wsgi/ui/default-orig/ex.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<html>
-<head>
-<style type="text/css">
-body
-{
-background: url(statpro_logo.gif) no-repeat top
-}
-</style>
-</head>
-<body>
-Prova Background CSS
-</body>
-</html>
diff --git a/pypers/wsgi/ui/default/ex.html b/pypers/wsgi/ui/default/ex.html
deleted file mode 100644
index 798e3cc..0000000
--- a/pypers/wsgi/ui/default/ex.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<html>
-<head>
-<style type="text/css">
-body
-{
-background: url(statpro_logo.gif) no-repeat top
-}
-</style>
-</head>
-<body>
-Prova Background CSS
-</body>
-</html>