Commits

Anonymous committed f6d2dd0

added the script's execution result by running "paver cog"

Comments (0)

Files changed (100)

PyMOTW/ConfigParser/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'configparser_example.py'))
 .. }}}
+
+::
+
+	$ python configparser_example.py
+	http://localhost:8080/Portal
+
 .. {{{end}}}
 
 

PyMOTW/Cookie/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'Cookie_setheaders.py'))
 .. }}}
+
+::
+
+	$ python Cookie_setheaders.py
+	Set-Cookie: mycookie=cookie_value
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'Cookie_Morsel.py'))
 .. }}}
+
+::
+
+	$ python Cookie_Morsel.py
+	Set-Cookie: encoded_value_cookie="\"cookie_value\""; Comment=Notice that this cookie value has escaped quotes
+	Set-Cookie: expires_at_time=cookie_value; expires=Sat, 14 Feb 2009 19:30:14
+	Set-Cookie: restricted_cookie=cookie_value; Domain=PyMOTW; Path=/sub/path; secure
+	Set-Cookie: with_max_age="expires in 5 minutes"; Max-Age=300
+	
+	key = restricted_cookie
+	  value = cookie_value
+	  coded_value = cookie_value
+	  domain = PyMOTW
+	  secure = True
+	  path = /sub/path
+	
+	key = with_max_age
+	  value = expires in 5 minutes
+	  coded_value = "expires in 5 minutes"
+	  max-age = 300
+	
+	key = encoded_value_cookie
+	  value = "cookie_value"
+	  coded_value = "\"cookie_value\""
+	  comment = Notice that this cookie value has escaped quotes
+	
+	key = expires_at_time
+	  value = cookie_value
+	  coded_value = cookie_value
+	  expires = Sat, 14 Feb 2009 19:30:14
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'Cookie_coded_value.py'))
 .. }}}
+
+::
+
+	$ python Cookie_coded_value.py
+	integer
+	  Set-Cookie: integer=5
+	  value=5 <type 'str'>
+	  coded_value=5
+	
+	string_with_quotes
+	  Set-Cookie: string_with_quotes="He said, \"Hello, World!\""
+	  value=He said, "Hello, World!" <type 'str'>
+	  coded_value="He said, \"Hello, World!\""
+	
+
 .. {{{end}}}
 
 Receiving and Parsing Cookie Headers
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'Cookie_parse.py'))
 .. }}}
+
+::
+
+	$ python Cookie_parse.py
+	From constructor:
+	Set-Cookie: integer=5
+	Set-Cookie: string_with_quotes="He said, \"Hello, World!\""
+	
+	From load():
+	Set-Cookie: integer=5
+	Set-Cookie: string_with_quotes="He said, \"Hello, World!\""
+
 .. {{{end}}}
 
 Alternative Output Formats
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'Cookie_js_output.py'))
 .. }}}
+
+::
+
+	$ python Cookie_js_output.py
+	
+	        <script type="text/javascript">
+	        <!-- begin hiding
+	        document.cookie = "another_cookie="second value"";
+	        // end hiding -->
+	        </script>
+	        
+	        <script type="text/javascript">
+	        <!-- begin hiding
+	        document.cookie = "mycookie=cookie_value";
+	        // end hiding -->
+	        </script>
+	        
+
 .. {{{end}}}
 
 

PyMOTW/Queue/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'Queue_fifo.py'))
 .. }}}
+
+::
+
+	$ python Queue_fifo.py
+	0
+	1
+	2
+	3
+	4
+
 .. {{{end}}}
 
 LIFO Queue
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'Queue_lifo.py'))
 .. }}}
+
+::
+
+	$ python Queue_lifo.py
+	4
+	3
+	2
+	1
+	0
+
 .. {{{end}}}
 
 .. _Queue-PriorityQueue:
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'Queue_priority.py'))
 .. }}}
+
+::
+
+	$ python Queue_priority.py
+	New job: Mid-level job
+	New job: Low-level job
+	New job: Important job
+	Processing job: Important job
+	Processing job: Mid-level job
+	Processing job: Low-level job
+
 .. {{{end}}}
 
 

PyMOTW/SocketServer/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'SocketServer_echo.py'))
 .. }}}
+
+::
+
+	$ python SocketServer_echo.py
+	EchoServer: __init__
+	EchoServer: server_activate
+	EchoServer: waiting for request
+	client: Server on 127.0.0.1:38907
+	EchoServer: Handling requests, press <Ctrl-C> to quit
+	client: creating socket
+	client: connecting to server
+	client: sending data: "Hello, world"
+	client: waiting for response
+	EchoServer: handle_request
+	EchoServer: verify_request(<socket._socketobject object at 0x8155c6c>, ('127.0.0.1', 44172))
+	EchoServer: process_request(<socket._socketobject object at 0x8155c6c>, ('127.0.0.1', 44172))
+	EchoServer: finish_request(<socket._socketobject object at 0x8155c6c>, ('127.0.0.1', 44172))
+	EchoRequestHandler: __init__
+	EchoRequestHandler: setup
+	EchoRequestHandler: handle
+	EchoRequestHandler: recv()->"Hello, world"
+	EchoRequestHandler: finish
+	client: response from server: "Hello, world"
+	EchoServer: close_request(<socket._socketobject object at 0x8155c6c>)
+	client: closing socket
+	EchoServer: handle_request
+	client: done
+
 .. {{{end}}}
 
 The port number used will change each time you run it, as the kernel
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'SocketServer_echo_simple.py'))
 .. }}}
+
+::
+
+	$ python SocketServer_echo_simple.py
+	Sending : "Hello, world"
+	Received: "Hello, world"
+
 .. {{{end}}}
 
 Threading and Forking
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'SocketServer_threaded.py'))
 .. }}}
+
+::
+
+	$ python SocketServer_threaded.py
+	Server loop running in thread: Thread-1
+	Sending : "Hello, world"
+	Received: "Thread-2: Hello, world"
+
 .. {{{end}}}
 
 To use separate processes, use the :class:`ForkingMixIn`:
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'SocketServer_forking.py'))
 .. }}}
+
+::
+
+	$ python SocketServer_forking.py
+	Server loop running in process: 5778
+	Sending : "Hello, world"
+	Received: "5780: Hello, world"
+
 .. {{{end}}}
 
 

PyMOTW/StringIO/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'stringio_examples.py'))
 .. }}}
+
+::
+
+	$ python stringio_examples.py
+	This goes into the buffer. And so does this.
+	
+	Inital value for read buffer
+
 .. {{{end}}}
 
 ..

PyMOTW/abc/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'abc_register.py'))
 .. }}}
+
+::
+
+	$ python abc_register.py
+	Subclass: True
+	Instance: True
+
 .. {{{end}}}
 
 Implementation Through Subclassing
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'abc_subclass.py'))
 .. }}}
+
+::
+
+	$ python abc_subclass.py
+	Subclass: True
+	Instance: True
+
 .. {{{end}}}
 
 A side-effect of using direct subclassing is it is possible to find
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'abc_find_subclasses.py'))
 .. }}}
+
+::
+
+	$ python abc_find_subclasses.py
+	SubclassImplementation
+
 .. {{{end}}}
 
 Dr. André Roberge `has described
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'abc_incomplete.py', ignore_error=True))
 .. }}}
+
+::
+
+	$ python abc_incomplete.py
+	Subclass: True
+	Instance:
+	Traceback (most recent call last):
+	  File "abc_incomplete.py", line 22, in <module>
+	    print 'Instance:', isinstance(IncompleteImplementation(), PluginBase)
+	TypeError: Can't instantiate abstract class IncompleteImplementation with abstract methods load
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'abc_concrete_method.py'))
 .. }}}
+
+::
+
+	$ python abc_concrete_method.py
+	base class reading data
+	subclass sorting data
+	['line one', 'line three', 'line two']
+	
+
 .. {{{end}}}
 
 .. _abc-abstract-properties:
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'abc_abstractproperty.py'))
 .. }}}
+
+::
+
+	$ python abc_abstractproperty.py
+	ERROR: Can't instantiate abstract class Base with abstract methods value
+	Implementation.value: concrete property
+
 .. {{{end}}}
 
 You can also define abstract read/write properties.
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'abc_abstractproperty_rw.py'))
 .. }}}
+
+::
+
+	$ python abc_abstractproperty_rw.py
+	ERROR: Can't instantiate abstract class Base with abstract methods value
+	ERROR: Can't instantiate abstract class PartialImplementation with abstract methods value
+	Implementation.value: Default value
+	Changed value: New value
+
 .. {{{end}}}
 
 To use the decorator syntax does with read/write abstract properties,
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'abc_abstractproperty_rw_deco.py'))
 .. }}}
+
+::
+
+	$ python abc_abstractproperty_rw_deco.py
+	Implementation.value: Default value
+	Changed value: New value
+
 .. {{{end}}}
 
 .. _abc-collection-types:

PyMOTW/anydbm/index.rst

 .. sh("cd %s; rm -f /tmp/example.db" % workdir)
 .. cog.out(run_script(cog.inFile, 'anydbm_new.py'))
 .. }}}
+
+::
+
+	$ python anydbm_new.py
+	
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'anydbm_whichdb.py'))
 .. }}}
+
+::
+
+	$ python anydbm_whichdb.py
+	dbhash
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'anydbm_existing.py'))
 .. }}}
+
+::
+
+	$ python anydbm_existing.py
+	keys(): ['author', 'key', 'today']
+	iterating: author Doug
+	iterating: key value
+	iterating: today Sunday
+	db["author"] = Doug
+
 .. {{{end}}}
 
 Error Cases
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'anydbm_intkeys.py', ignore_error=True))
 .. }}}
+
+::
+
+	$ python anydbm_intkeys.py
+	Traceback (most recent call last):
+	  File "anydbm_intkeys.py", line 16, in <module>
+	    db[1] = 'one'
+	  File "/usr/lib/python2.6/bsddb/__init__.py", line 276, in __setitem__
+	    _DeadlockWrap(wrapF)  # self.db[key] = value
+	  File "/usr/lib/python2.6/bsddb/dbutils.py", line 68, in DeadlockWrap
+	    return function(*_args, **_kwargs)
+	  File "/usr/lib/python2.6/bsddb/__init__.py", line 275, in wrapF
+	    self.db[key] = value
+	TypeError: Integer keys only allowed for Recno and Queue DB's
+
 .. {{{end}}}
 
 Values must be strings or ``None``.
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'anydbm_intvalue.py', ignore_error=True))
 .. }}}
+
+::
+
+	$ python anydbm_intvalue.py
+	Traceback (most recent call last):
+	  File "anydbm_intvalue.py", line 16, in <module>
+	    db['one'] = 1
+	  File "/usr/lib/python2.6/bsddb/__init__.py", line 276, in __setitem__
+	    _DeadlockWrap(wrapF)  # self.db[key] = value
+	  File "/usr/lib/python2.6/bsddb/dbutils.py", line 68, in DeadlockWrap
+	    return function(*_args, **_kwargs)
+	  File "/usr/lib/python2.6/bsddb/__init__.py", line 275, in wrapF
+	    self.db[key] = value
+	TypeError: Data values must be of type string or None.
+
 .. {{{end}}}
 
 .. seealso::

PyMOTW/array/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'array_string.py'))
 .. }}}
+
+::
+
+	$ python array_string.py
+	As string: This is the array.
+	As array : array('c', 'This is the array.')
+	As hex   : 54686973206973207468652061727261792e
+
 .. {{{end}}}
 
 ..
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'array_sequence.py'))
 .. }}}
+
+::
+
+	$ python array_sequence.py
+	Initial : array('i', [0, 1, 2, 3, 4])
+	Extended: array('i', [0, 1, 2, 3, 4, 0, 1, 2, 3, 4])
+	Slice   : array('i', [3, 4, 0])
+	Iterator: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 0), (6, 1), (7, 2), (8, 3), (9, 4)]
+
 .. {{{end}}}
 
 ..
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'array_file.py'))
 .. }}}
+
+::
+
+	$ python array_file.py
+	A1: array('i', [0, 1, 2, 3, 4])
+	Raw Contents: 0000000001000000020000000300000004000000
+	A2: array('i', [0, 1, 2, 3, 4])
+
 .. {{{end}}}
 
 ..
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'array_byteswap.py'))
 .. }}}
+
+::
+
+	$ python array_byteswap.py
+	    A1 hex         A1     A2 hex         A2
+	---------- ---------- ---------- ----------
+	  00000000          0   00000000          0
+	  01000000          1   00000001   16777216
+	  02000000          2   00000002   33554432
+	  03000000          3   00000003   50331648
+	  04000000          4   00000004   67108864
+
 .. {{{end}}}
 
 ..

PyMOTW/asynchat/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'asynchat_echo_main.py'))
 .. }}}
+
+::
+
+	$ python asynchat_echo_main.py
+	EchoClient: connecting to ('127.0.0.1', 36523)
+	EchoClient: handle_connect()
+	EchoProducer: more() -> (512)
+	"""Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque vel arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra f"""
+	EchoProducer: more() -> (512)
+	"""ringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque vel arcu. Vivamus
+	purus orci, iac"""
+	EchoHandler('127.0.0.1', 36523): collect_incoming_data() -> (9)
+	"""ECHO 1474"""
+	EchoHandler('127.0.0.1', 36523): found_terminator()
+	EchoHandler('127.0.0.1', 36523): _process_command() "ECHO 1474"
+	EchoHandler('127.0.0.1', 36523): collect_incoming_data() -> (1024)
+	"""Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque vel arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra fringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque vel arcu. Vivamus
+	purus orci, iac"""
+	EchoProducer: more() -> (450)
+	"""ulis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra fringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	"""
+	EchoHandler('127.0.0.1', 36523): collect_incoming_data() -> (450)
+	"""ulis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra fringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	"""
+	EchoHandler('127.0.0.1', 36523): found_terminator()
+	EchoHandler('127.0.0.1', 36523): _process_message() echoing
+	"""Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque vel arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra fringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque vel arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra fringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	"""
+	EchoProducer: more() -> (0)
+	""""""
+	EchoClient: collect_incoming_data() -> (1474)
+	"""Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque vel arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra fringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque vel arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra fringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	"""
+	EchoClient: found_terminator()
+	EchoClient: RECEIVED COPY OF MESSAGE
+
 .. {{{end}}}
 
 

PyMOTW/asyncore/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'asyncore_http_client.py'))
 .. }}}
+
+::
+
+	$ python asyncore_http_client.py
+	http://www.python.org/: connecting to ('www.python.org', 80)
+	http://www.doughellmann.com/PyMOTW/contents.html: connecting to ('www.doughellmann.com', 80)
+	root: LOOP STARTING
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: writable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: writable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_connect()
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_write() -> "GET http://www.doughellmann.com/PyMOTW/contents.html HTTP/1.0
+	
+	"
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: writable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_connect()
+	http://www.python.org/: handle_write() -> "GET http://www.python.org/ HTTP/1.0
+	
+	"
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 268 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 4206 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 2804 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_read() -> 1776 bytes
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: handle_close()
+	http://www.python.org/: handle_read() -> 0 bytes
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1173 bytes
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_close()
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 0 bytes
+	root: LOOP DONE
+	http://www.python.org/ got 18600 bytes
+	http://www.doughellmann.com/PyMOTW/contents.html got 27965 bytes
+
 .. {{{end}}}
 
 Servers
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'asyncore_echo_server.py'))
 .. }}}
+
+::
+
+	$ python asyncore_echo_server.py
+	EchoServer: binding to ('127.0.0.1', 58842)
+	EchoClient: connecting to ('127.0.0.1', 58842)
+	EchoClient: writable() -> True
+	EchoServer: handle_accept() -> ('127.0.0.1', 35264)
+	EchoServer: handle_close()
+	EchoClient: handle_connect()
+	EchoClient: handle_write() -> (512) "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque vel arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra f"
+	EchoClient: writable() -> True
+	EchoHandler('127.0.0.1', 58842): writable() -> False
+	EchoHandler('127.0.0.1', 58842): handle_read() -> (256) "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque ve"
+	EchoClient: handle_write() -> (225) "ringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	"
+	EchoClient: writable() -> False
+	EchoHandler('127.0.0.1', 58842): writable() -> True
+	EchoHandler('127.0.0.1', 58842): handle_read() -> (256) "l arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra f"
+	EchoHandler('127.0.0.1', 58842): handle_write() -> (256) "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque ve"
+	EchoHandler('127.0.0.1', 58842): writable() -> True
+	EchoClient: writable() -> False
+	EchoHandler('127.0.0.1', 58842): writable() -> True
+	EchoClient: handle_read() -> (256) "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque ve"
+	EchoHandler('127.0.0.1', 58842): handle_read() -> (225) "ringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	"
+	EchoHandler('127.0.0.1', 58842): handle_write() -> (256) "l arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra f"
+	EchoHandler('127.0.0.1', 58842): writable() -> True
+	EchoClient: writable() -> False
+	EchoHandler('127.0.0.1', 58842): writable() -> True
+	EchoClient: handle_read() -> (256) "l arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra f"
+	EchoHandler('127.0.0.1', 58842): handle_write() -> (225) "ringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	"
+	EchoHandler('127.0.0.1', 58842): writable() -> False
+	EchoHandler('127.0.0.1', 58842): handle_close()
+	EchoClient: writable() -> False
+	EchoClient: handle_read() -> (225) "ringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	"
+	EchoClient: writable() -> False
+	EchoClient: handle_close()
+	EchoClient: RECEIVED COPY OF MESSAGE
+	EchoClient: handle_read() -> (0) ""
+
 .. {{{end}}}
 
 In this example the server, handler, and client objects are all being maintained in the same socket map by asyncore in a single process. To separate the server from the client, simply instantiate them from separate scripts and run ``asyncore.loop()`` in both. When a dispatcher is closed, it is removed from the map maintained by asyncore and the loop exits when the map is empty.
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'asyncore_loop.py'))
 .. }}}
+
+::
+
+	$ python asyncore_loop.py
+	http://www.doughellmann.com/PyMOTW/contents.html: connecting to ('www.doughellmann.com', 80)
+	http://www.python.org/: connecting to ('www.python.org', 80)
+	root: loop_counter=1
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: writable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: writable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_connect()
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_write() -> "GET http://www.doughellmann.com/PyMOTW/contents.html HTTP/1.0
+	
+	"
+	root: loop_counter=2
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: writable() -> True
+	http://www.python.org/: handle_connect()
+	http://www.python.org/: handle_write() -> "GET http://www.python.org/ HTTP/1.0
+	
+	"
+	root: loop_counter=3
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 268 bytes
+	root: loop_counter=4
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=5
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=6
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	root: loop_counter=7
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: handle_read() -> 2804 bytes
+	root: loop_counter=8
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=9
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=10
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=11
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=12
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=13
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=14
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=15
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	root: loop_counter=16
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: handle_read() -> 5608 bytes
+	root: loop_counter=17
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	root: loop_counter=18
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=19
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=20
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=21
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=22
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=23
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=24
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=25
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=26
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=27
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: handle_read() -> 1402 bytes
+	root: loop_counter=28
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: handle_read() -> 4580 bytes
+	root: loop_counter=29
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.python.org/: readable() -> True
+	http://www.python.org/: handle_close()
+	http://www.python.org/: handle_read() -> 0 bytes
+	root: loop_counter=30
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1396 bytes
+	root: loop_counter=31
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 1173 bytes
+	root: loop_counter=32
+	http://www.doughellmann.com/PyMOTW/contents.html: readable() -> True
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_close()
+	http://www.doughellmann.com/PyMOTW/contents.html: handle_read() -> 0 bytes
+
 .. {{{end}}}
 
 Working with Files
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'asyncore_file_dispatcher.py'))
 .. }}}
+
+::
+
+	$ python asyncore_file_dispatcher.py
+	READ: (256) "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
+	egestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo, a
+	elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nulla
+	facilisi. Sed tristique eros eu libero. Pellentesque ve"
+	READ: (256) "l arcu. Vivamus
+	purus orci, iaculis ac, suscipit sit amet, pulvinar eu,
+	lacus. Praesent placerat tortor sed nisl. Nunc blandit diam egestas
+	dui. Pellentesque habitant morbi tristique senectus et netus et
+	malesuada fames ac turpis egestas. Aliquam viverra f"
+	READ: (225) "ringilla
+	leo. Nulla feugiat augue eleifend nulla. Vivamus mauris. Vivamus sed
+	mauris in nibh placerat egestas. Suspendisse potenti. Mauris massa. Ut
+	eget velit auctor tortor blandit sollicitudin. Suspendisse imperdiet
+	justo.
+	"
+	READ: (0) ""
+
 .. {{{end}}}
 
 

PyMOTW/atexit/atexit_signal_parent.py

 import subprocess
 import time
 
-proc = subprocess.Popen('atexit_signal_child.py')
+proc = subprocess.Popen('./atexit_signal_child.py')
 print 'PARENT: Pausing before sending signal...'
 time.sleep(1)
 print 'PARENT: Signaling child'
-os.kill(proc.pid, signal.SIGTERM)
+os.kill(proc.pid, signal.SIGTERM)

PyMOTW/atexit/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'atexit_simple.py'))
 .. }}}
+
+::
+
+	$ python atexit_simple.py
+	Registering
+	Registered
+	all_done()
+
 .. {{{end}}}
 
 It is also possible to register more than one function, and to pass arguments.
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'atexit_multiple.py'))
 .. }}}
+
+::
+
+	$ python atexit_multiple.py
+	my_cleanup(third)
+	my_cleanup(second)
+	my_cleanup(first)
+
 .. {{{end}}}
 
 When are atexit functions not called?
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'atexit_signal_parent.py'))
 .. }}}
+
+::
+
+	$ python atexit_signal_parent.py
+	CHILD: Registering atexit handler
+	CHILD: Pausing to wait for signal
+	PARENT: Pausing before sending signal...
+	PARENT: Signaling child
+
 .. {{{end}}}
 
 Note that the child does not print the message embedded in not_called().
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'atexit_os_exit.py'))
 .. }}}
+
+::
+
+	$ python atexit_os_exit.py
+	
+
 .. {{{end}}}
 
 If we had instead used sys.exit(), the callbacks would still have been called.
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'atexit_sys_exit.py'))
 .. }}}
+
+::
+
+	$ python atexit_sys_exit.py
+	Registering
+	Registered
+	Exiting...
+	all_done()
+
 .. {{{end}}}
 
 Simulating a fatal error in the Python interpreter is left as an exercise to
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'atexit_exception.py'))
 .. }}}
+
+::
+
+	$ python atexit_exception.py
+	Error in atexit._run_exitfuncs:
+	Traceback (most recent call last):
+	  File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
+	    func(*targs, **kargs)
+	  File "atexit_exception.py", line 37, in exit_with_exception
+	    raise RuntimeError(message)
+	RuntimeError: Registered second
+	Error in atexit._run_exitfuncs:
+	Traceback (most recent call last):
+	  File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
+	    func(*targs, **kargs)
+	  File "atexit_exception.py", line 37, in exit_with_exception
+	    raise RuntimeError(message)
+	RuntimeError: Registered first
+	Error in sys.exitfunc:
+	Traceback (most recent call last):
+	  File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
+	    func(*targs, **kargs)
+	  File "atexit_exception.py", line 37, in exit_with_exception
+	    raise RuntimeError(message)
+	RuntimeError: Registered first
+
 .. {{{end}}}
 
 

PyMOTW/base64/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'base64_b64encode.py'))
 .. }}}
+
+::
+
+	$ python base64_b64encode.py
+	145 bytes before encoding
+	Expect 2 padding bytes
+	196 bytes after encoding
+	
+	CgppbXBvcnQgYmFzZTY0CgojIOOBk+OBruOCveOD
+	vOOCueODleOCoeOCpOODq+OCkuiqreOBv+i+vOOC
+	k+OBp+ODmOODg+ODgOOCkuWPluOCiumZpOOBjeOB
+	vuOBmQppbml0aWFsX2RhdGEgPSBvcGVuKF9fZmls
+	ZV9fLCAncnQnKS5yZWFkKCkuc3BsaXQoJw==
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'base64_b64decode.py'))
 .. }}}
+
+::
+
+	$ python base64_b64decode.py
+	Original: This is the data, in the clear.
+	Encoded : VGhpcyBpcyB0aGUgZGF0YSwgaW4gdGhlIGNsZWFyLg==
+	Decoded : This is the data, in the clear.
+
 .. {{{end}}}
 
 ..
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'base64_urlsafe.py'))
 .. }}}
+
+::
+
+	$ python base64_urlsafe.py
+	Original         : '\xfb\xef'
+	Standard encoding: ++8=
+	URL-safe encoding: --8=
+	
+	Original         : '\xff\xff'
+	Standard encoding: //8=
+	URL-safe encoding: __8=
+	
+
 .. {{{end}}}
 
 ..
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'base64_base32.py'))
 .. }}}
+
+::
+
+	$ python base64_base32.py
+	Original: This is the data, in the clear.
+	Encoded : KRUGS4ZANFZSA5DIMUQGIYLUMEWCA2LOEB2GQZJAMNWGKYLSFY======
+	Decoded : This is the data, in the clear.
+
 .. {{{end}}}
 
 ..
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'base64_base16.py'))
 .. }}}
+
+::
+
+	$ python base64_base16.py
+	Original: This is the data, in the clear.
+	Encoded : 546869732069732074686520646174612C20696E2074686520636C6561722E
+	Decoded : This is the data, in the clear.
+
 .. {{{end}}}
 
 ..

PyMOTW/bisect/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'bisect_example.py'))
 .. }}}
+
+::
+
+	$ python bisect_example.py
+	14  0 [14]
+	85  1 [14, 85]
+	77  1 [14, 77, 85]
+	26  1 [14, 26, 77, 85]
+	50  2 [14, 26, 50, 77, 85]
+	45  2 [14, 26, 45, 50, 77, 85]
+	66  4 [14, 26, 45, 50, 66, 77, 85]
+	79  6 [14, 26, 45, 50, 66, 77, 79, 85]
+	10  0 [10, 14, 26, 45, 50, 66, 77, 79, 85]
+	 3  0 [3, 10, 14, 26, 45, 50, 66, 77, 79, 85]
+	84  9 [3, 10, 14, 26, 45, 50, 66, 77, 79, 84, 85]
+	44  4 [3, 10, 14, 26, 44, 45, 50, 66, 77, 79, 84, 85]
+	77  9 [3, 10, 14, 26, 44, 45, 50, 66, 77, 77, 79, 84, 85]
+	 1  0 [1, 3, 10, 14, 26, 44, 45, 50, 66, 77, 77, 79, 84, 85]
+	45  7 [1, 3, 10, 14, 26, 44, 45, 45, 50, 66, 77, 77, 79, 84, 85]
+	73 10 [1, 3, 10, 14, 26, 44, 45, 45, 50, 66, 73, 77, 77, 79, 84, 85]
+	23  4 [1, 3, 10, 14, 23, 26, 44, 45, 45, 50, 66, 73, 77, 77, 79, 84, 85]
+	95 17 [1, 3, 10, 14, 23, 26, 44, 45, 45, 50, 66, 73, 77, 77, 79, 84, 85, 95]
+	91 17 [1, 3, 10, 14, 23, 26, 44, 45, 45, 50, 66, 73, 77, 77, 79, 84, 85, 91, 95]
+
 .. {{{end}}}
 
 The first column shows the new random number. The second column shows the
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'bisect_example2.py'))
 .. }}}
+
+::
+
+	$ python bisect_example2.py
+	14  0 [14]
+	85  1 [14, 85]
+	77  1 [14, 77, 85]
+	26  1 [14, 26, 77, 85]
+	50  2 [14, 26, 50, 77, 85]
+	45  2 [14, 26, 45, 50, 77, 85]
+	66  4 [14, 26, 45, 50, 66, 77, 85]
+	79  6 [14, 26, 45, 50, 66, 77, 79, 85]
+	10  0 [10, 14, 26, 45, 50, 66, 77, 79, 85]
+	 3  0 [3, 10, 14, 26, 45, 50, 66, 77, 79, 85]
+	84  9 [3, 10, 14, 26, 45, 50, 66, 77, 79, 84, 85]
+	44  4 [3, 10, 14, 26, 44, 45, 50, 66, 77, 79, 84, 85]
+	77  8 [3, 10, 14, 26, 44, 45, 50, 66, 77, 77, 79, 84, 85]
+	 1  0 [1, 3, 10, 14, 26, 44, 45, 50, 66, 77, 77, 79, 84, 85]
+	45  6 [1, 3, 10, 14, 26, 44, 45, 45, 50, 66, 77, 77, 79, 84, 85]
+	73 10 [1, 3, 10, 14, 26, 44, 45, 45, 50, 66, 73, 77, 77, 79, 84, 85]
+	23  4 [1, 3, 10, 14, 23, 26, 44, 45, 45, 50, 66, 73, 77, 77, 79, 84, 85]
+	95 17 [1, 3, 10, 14, 23, 26, 44, 45, 45, 50, 66, 73, 77, 77, 79, 84, 85, 95]
+	91 17 [1, 3, 10, 14, 23, 26, 44, 45, 45, 50, 66, 73, 77, 77, 79, 84, 85, 91, 95]
+
 .. {{{end}}}
 
 

PyMOTW/bz2/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'bz2_memory.py'))
 .. }}}
+
+::
+
+	$ python bz2_memory.py
+	Original     : 26 This is the original text.
+	Compressed   : 62 425a683931415926535916be35a600000293804001040022e59c402000314c000111e93d434da223028cf9e73148cae0a0d6ed7f17724538509016be35a6
+	Decompressed : 26 This is the original text.
+
 .. {{{end}}}
 
 Notice that for short text, the compressed version can be
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'bz2_lengths.py'))
 .. }}}
+
+::
+
+	$ python bz2_lengths.py
+	      len(data)  len(compressed)
+	---------------  ---------------
+	              0               14 *
+	             26               62 *
+	             52               68 *
+	             78               70 
+	            104               72 
+	            130               77 
+	            156               77 
+	            182               73 
+	            208               75 
+	            234               80 
+	            260               80 
+	            286               81 
+	            312               80 
+	            338               81 
+	            364               81 
+	            390               76 
+	            416               78 
+	            442               84 
+	            468               84 
+	            494               87 
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'bz2_mixed.py'))
 .. }}}
+
+::
+
+	$ python bz2_mixed.py
+	Decompressed matches lorem: True
+	Unused data matches lorem : True
+
 .. {{{end}}}
 
 
 .. sh("cd %s; rm -f example.txt.bzw" % workdir)
 .. cog.out(run_script(cog.inFile, 'bz2_file_write.py'))
 .. }}}
+
+::
+
+	$ python bz2_file_write.py
+	example.txt.bz2: bzip2 compressed data, block size = 900k
+
 .. {{{end}}}
 
 
 .. sh("cd %s; rm -f example_lines.txt.bz2" % workdir)
 .. cog.out(run_script(cog.inFile, 'bz2_file_writelines.py'))
 .. }}}
+
+::
+
+	$ python bz2_file_writelines.py
+	The same line, over and over.
+	The same line, over and over.
+	The same line, over and over.
+	The same line, over and over.
+	The same line, over and over.
+	The same line, over and over.
+	The same line, over and over.
+	The same line, over and over.
+	The same line, over and over.
+	The same line, over and over.
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'bz2_file_read.py'))
 .. }}}
+
+::
+
+	$ python bz2_file_read.py
+	Contents of the example file go here.
+	
+
 .. {{{end}}}
     
 While reading a file, it is also possible to seek and read only part
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'bz2_file_seek.py'))
 .. }}}
+
+::
+
+	$ python bz2_file_seek.py
+	Entire file:
+	Contents of the example file go here.
+	
+	Starting at position 5 for 10 bytes:
+	nts of the
+	
+	True
+
 .. {{{end}}}
 
 

PyMOTW/calendar/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'calendar_textcalendar.py'))
 .. }}}
+
+::
+
+	$ python calendar_textcalendar.py
+	     July 2007
+	Su Mo Tu We Th Fr Sa
+	 1  2  3  4  5  6  7
+	 8  9 10 11 12 13 14
+	15 16 17 18 19 20 21
+	22 23 24 25 26 27 28
+	29 30 31
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'calendar_htmlcalendar.py'))
 .. }}}
+
+::
+
+	$ python calendar_htmlcalendar.py
+	<table border="0" cellpadding="0" cellspacing="0" class="month">
+	<tr><th colspan="7" class="month">July 2007</th></tr>
+	<tr><th class="sun">Sun</th><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th></tr>
+	<tr><td class="sun">1</td><td class="mon">2</td><td class="tue">3</td><td class="wed">4</td><td class="thu">5</td><td class="fri">6</td><td class="sat">7</td></tr>
+	<tr><td class="sun">8</td><td class="mon">9</td><td class="tue">10</td><td class="wed">11</td><td class="thu">12</td><td class="fri">13</td><td class="sat">14</td></tr>
+	<tr><td class="sun">15</td><td class="mon">16</td><td class="tue">17</td><td class="wed">18</td><td class="thu">19</td><td class="fri">20</td><td class="sat">21</td></tr>
+	<tr><td class="sun">22</td><td class="mon">23</td><td class="tue">24</td><td class="wed">25</td><td class="thu">26</td><td class="fri">27</td><td class="sat">28</td></tr>
+	<tr><td class="sun">29</td><td class="mon">30</td><td class="tue">31</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
+	</table>
+	
+
 .. {{{end}}}
 
 If you need to produce output in a format other than one of the available
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'calendar_yeardays2calendar.py'))
 .. }}}
+
+::
+
+	$ python calendar_yeardays2calendar.py
+	[[[[(0, 6), (1, 0), (2, 1), (3, 2), (4, 3), (5, 4), (6, 5)],
+	   [(7, 6), (8, 0), (9, 1), (10, 2), (11, 3), (12, 4), (13, 5)],
+	   [(14, 6), (15, 0), (16, 1), (17, 2), (18, 3), (19, 4), (20, 5)],
+	   [(21, 6), (22, 0), (23, 1), (24, 2), (25, 3), (26, 4), (27, 5)],
+	   [(28, 6), (29, 0), (30, 1), (31, 2), (0, 3), (0, 4), (0, 5)]],
+	  [[(0, 6), (0, 0), (0, 1), (0, 2), (1, 3), (2, 4), (3, 5)],
+	   [(4, 6), (5, 0), (6, 1), (7, 2), (8, 3), (9, 4), (10, 5)],
+	   [(11, 6), (12, 0), (13, 1), (14, 2), (15, 3), (16, 4), (17, 5)],
+	   [(18, 6), (19, 0), (20, 1), (21, 2), (22, 3), (23, 4), (24, 5)],
+	   [(25, 6), (26, 0), (27, 1), (28, 2), (0, 3), (0, 4), (0, 5)]]],
+	 [[[(0, 6), (0, 0), (0, 1), (0, 2), (1, 3), (2, 4), (3, 5)],
+	   [(4, 6), (5, 0), (6, 1), (7, 2), (8, 3), (9, 4), (10, 5)],
+	   [(11, 6), (12, 0), (13, 1), (14, 2), (15, 3), (16, 4), (17, 5)],
+	   [(18, 6), (19, 0), (20, 1), (21, 2), (22, 3), (23, 4), (24, 5)],
+	   [(25, 6), (26, 0), (27, 1), (28, 2), (29, 3), (30, 4), (31, 5)]],
+	  [[(1, 6), (2, 0), (3, 1), (4, 2), (5, 3), (6, 4), (7, 5)],
+	   [(8, 6), (9, 0), (10, 1), (11, 2), (12, 3), (13, 4), (14, 5)],
+	   [(15, 6), (16, 0), (17, 1), (18, 2), (19, 3), (20, 4), (21, 5)],
+	   [(22, 6), (23, 0), (24, 1), (25, 2), (26, 3), (27, 4), (28, 5)],
+	   [(29, 6), (30, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5)]]],
+	 [[[(0, 6), (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5)],
+	   [(6, 6), (7, 0), (8, 1), (9, 2), (10, 3), (11, 4), (12, 5)],
+	   [(13, 6), (14, 0), (15, 1), (16, 2), (17, 3), (18, 4), (19, 5)],
+	   [(20, 6), (21, 0), (22, 1), (23, 2), (24, 3), (25, 4), (26, 5)],
+	   [(27, 6), (28, 0), (29, 1), (30, 2), (31, 3), (0, 4), (0, 5)]],
+	  [[(0, 6), (0, 0), (0, 1), (0, 2), (0, 3), (1, 4), (2, 5)],
+	   [(3, 6), (4, 0), (5, 1), (6, 2), (7, 3), (8, 4), (9, 5)],
+	   [(10, 6), (11, 0), (12, 1), (13, 2), (14, 3), (15, 4), (16, 5)],
+	   [(17, 6), (18, 0), (19, 1), (20, 2), (21, 3), (22, 4), (23, 5)],
+	   [(24, 6), (25, 0), (26, 1), (27, 2), (28, 3), (29, 4), (30, 5)]]],
+	 [[[(1, 6), (2, 0), (3, 1), (4, 2), (5, 3), (6, 4), (7, 5)],
+	   [(8, 6), (9, 0), (10, 1), (11, 2), (12, 3), (13, 4), (14, 5)],
+	   [(15, 6), (16, 0), (17, 1), (18, 2), (19, 3), (20, 4), (21, 5)],
+	   [(22, 6), (23, 0), (24, 1), (25, 2), (26, 3), (27, 4), (28, 5)],
+	   [(29, 6), (30, 0), (31, 1), (0, 2), (0, 3), (0, 4), (0, 5)]],
+	  [[(0, 6), (0, 0), (0, 1), (1, 2), (2, 3), (3, 4), (4, 5)],
+	   [(5, 6), (6, 0), (7, 1), (8, 2), (9, 3), (10, 4), (11, 5)],
+	   [(12, 6), (13, 0), (14, 1), (15, 2), (16, 3), (17, 4), (18, 5)],
+	   [(19, 6), (20, 0), (21, 1), (22, 2), (23, 3), (24, 4), (25, 5)],
+	   [(26, 6), (27, 0), (28, 1), (29, 2), (30, 3), (31, 4), (0, 5)]]],
+	 [[[(0, 6), (0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 5)],
+	   [(2, 6), (3, 0), (4, 1), (5, 2), (6, 3), (7, 4), (8, 5)],
+	   [(9, 6), (10, 0), (11, 1), (12, 2), (13, 3), (14, 4), (15, 5)],
+	   [(16, 6), (17, 0), (18, 1), (19, 2), (20, 3), (21, 4), (22, 5)],
+	   [(23, 6), (24, 0), (25, 1), (26, 2), (27, 3), (28, 4), (29, 5)],
+	   [(30, 6), (0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5)]],
+	  [[(0, 6), (1, 0), (2, 1), (3, 2), (4, 3), (5, 4), (6, 5)],
+	   [(7, 6), (8, 0), (9, 1), (10, 2), (11, 3), (12, 4), (13, 5)],
+	   [(14, 6), (15, 0), (16, 1), (17, 2), (18, 3), (19, 4), (20, 5)],
+	   [(21, 6), (22, 0), (23, 1), (24, 2), (25, 3), (26, 4), (27, 5)],
+	   [(28, 6), (29, 0), (30, 1), (31, 2), (0, 3), (0, 4), (0, 5)]]],
+	 [[[(0, 6), (0, 0), (0, 1), (0, 2), (1, 3), (2, 4), (3, 5)],
+	   [(4, 6), (5, 0), (6, 1), (7, 2), (8, 3), (9, 4), (10, 5)],
+	   [(11, 6), (12, 0), (13, 1), (14, 2), (15, 3), (16, 4), (17, 5)],
+	   [(18, 6), (19, 0), (20, 1), (21, 2), (22, 3), (23, 4), (24, 5)],
+	   [(25, 6), (26, 0), (27, 1), (28, 2), (29, 3), (30, 4), (0, 5)]],
+	  [[(0, 6), (0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 5)],
+	   [(2, 6), (3, 0), (4, 1), (5, 2), (6, 3), (7, 4), (8, 5)],
+	   [(9, 6), (10, 0), (11, 1), (12, 2), (13, 3), (14, 4), (15, 5)],
+	   [(16, 6), (17, 0), (18, 1), (19, 2), (20, 3), (21, 4), (22, 5)],
+	   [(23, 6), (24, 0), (25, 1), (26, 2), (27, 3), (28, 4), (29, 5)],
+	   [(30, 6), (31, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5)]]]]
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'calendar_formatyear.py'))
 .. }}}
+
+::
+
+	$ python calendar_formatyear.py
+	                   2007
+	
+	      January               February
+	Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
+	    1  2  3  4  5  6               1  2  3
+	 7  8  9 10 11 12 13   4  5  6  7  8  9 10
+	14 15 16 17 18 19 20  11 12 13 14 15 16 17
+	21 22 23 24 25 26 27  18 19 20 21 22 23 24
+	28 29 30 31           25 26 27 28
+	
+	       March                 April
+	Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
+	             1  2  3   1  2  3  4  5  6  7
+	 4  5  6  7  8  9 10   8  9 10 11 12 13 14
+	11 12 13 14 15 16 17  15 16 17 18 19 20 21
+	18 19 20 21 22 23 24  22 23 24 25 26 27 28
+	25 26 27 28 29 30 31  29 30
+	
+	        May                   June
+	Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
+	       1  2  3  4  5                  1  2
+	 6  7  8  9 10 11 12   3  4  5  6  7  8  9
+	13 14 15 16 17 18 19  10 11 12 13 14 15 16
+	20 21 22 23 24 25 26  17 18 19 20 21 22 23
+	27 28 29 30 31        24 25 26 27 28 29 30
+	
+	        July                 August
+	Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
+	 1  2  3  4  5  6  7            1  2  3  4
+	 8  9 10 11 12 13 14   5  6  7  8  9 10 11
+	15 16 17 18 19 20 21  12 13 14 15 16 17 18
+	22 23 24 25 26 27 28  19 20 21 22 23 24 25
+	29 30 31              26 27 28 29 30 31
+	
+	     September              October
+	Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
+	                   1      1  2  3  4  5  6
+	 2  3  4  5  6  7  8   7  8  9 10 11 12 13
+	 9 10 11 12 13 14 15  14 15 16 17 18 19 20
+	16 17 18 19 20 21 22  21 22 23 24 25 26 27
+	23 24 25 26 27 28 29  28 29 30 31
+	30
+	
+	      November              December
+	Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
+	             1  2  3                     1
+	 4  5  6  7  8  9 10   2  3  4  5  6  7  8
+	11 12 13 14 15 16 17   9 10 11 12 13 14 15
+	18 19 20 21 22 23 24  16 17 18 19 20 21 22
+	25 26 27 28 29 30     23 24 25 26 27 28 29
+	                      30 31
+	
+
 .. {{{end}}}
 
 If you want to format the output yourself for some reason (such as including
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'calendar_monthcalendar.py'))
 .. }}}
+
+::
+
+	$ python calendar_monthcalendar.py
+	[[0, 0, 0, 0, 0, 0, 1],
+	 [2, 3, 4, 5, 6, 7, 8],
+	 [9, 10, 11, 12, 13, 14, 15],
+	 [16, 17, 18, 19, 20, 21, 22],
+	 [23, 24, 25, 26, 27, 28, 29],
+	 [30, 31, 0, 0, 0, 0, 0]]
+
 .. {{{end}}}
 
 
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'calendar_secondthursday.py'))
 .. }}}
+
+::
+
+	$ python calendar_secondthursday.py
+	  1: 11
+	  2:  8
+	  3:  8
+	  4: 12
+	  5: 10
+	  6: 14
+	  7: 12
+	  8:  9
+	  9: 13
+	 10: 11
+	 11:  8
+	 12: 13
+
 .. {{{end}}}
 
 

PyMOTW/cgitb/index.rst

 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'cgitb_basic_traceback.py', ignore_error=True))
 .. }}}
+
+::
+
+	$ python cgitb_basic_traceback.py
+	Traceback (most recent call last):
+	  File "cgitb_basic_traceback.py", line 22, in <module>
+	    func1(1)
+	  File "cgitb_basic_traceback.py", line 12, in func1
+	    return func2(local_var)
+	  File "cgitb_basic_traceback.py", line 16, in func2
+	    return func3(local_var)
+	  File "cgitb_basic_traceback.py", line 19, in func3
+	    local_var = arg2 / 2
+	NameError: global name 'arg2' is not defined
+
 .. {{{end}}}
 
 Enabling Detailed Tracebacks
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'cgitb_extended_traceback.py', ignore_error=True))
 .. }}}
+
+::
+
+	$ python cgitb_extended_traceback.py
+	/usr/lib/python2.6/cgitb.py:245: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
+	  value = pydoc.text.repr(getattr(evalue, name))
+	<type 'exceptions.NameError'>
+	Python 2.6.2: /usr/bin/python
+	Wed Jul 21 18:59:38 2010
+	
+	A problem occurred in a Python script.  Here is the sequence of
+	function calls leading up to the error, in the order they occurred.
+	
+	 /home/morimoto/work/translate/02_pymotw/pymotw-ja/PyMOTW/cgitb/cgitb_extended_traceback.py in <module>()
+	   21 def func3(arg3):
+	   22     local_var = arg2 / 2
+	   23     return local_var
+	   24 
+	   25 func1(1)
+	func1 = <function func1 at 0xb778d72c>
+	
+	 /home/morimoto/work/translate/02_pymotw/pymotw-ja/PyMOTW/cgitb/cgitb_extended_traceback.py in func1(arg1=1)
+	   13 def func1(arg1):
+	   14     local_var = arg1 * 2
+	   15     return func2(local_var)
+	   16 
+	   17 def func2(arg2):
+	global func2 = <function func2 at 0xb778d6f4>
+	local_var = 2
+	
+	 /home/morimoto/work/translate/02_pymotw/pymotw-ja/PyMOTW/cgitb/cgitb_extended_traceback.py in func2(arg2=2)
+	   17 def func2(arg2):
+	   18     local_var = arg2 + 2
+	   19     return func3(local_var)
+	   20 
+	   21 def func3(arg3):
+	global func3 = <function func3 at 0xb778d684>
+	local_var = 4
+	
+	 /home/morimoto/work/translate/02_pymotw/pymotw-ja/PyMOTW/cgitb/cgitb_extended_traceback.py in func3(arg3=4)
+	   20 
+	   21 def func3(arg3):
+	   22     local_var = arg2 / 2
+	   23     return local_var
+	   24 
+	local_var undefined
+	arg2 undefined
+	<type 'exceptions.NameError'>: global name 'arg2' is not defined
+	    __class__ = <type 'exceptions.NameError'>
+	    __delattr__ = <method-wrapper '__delattr__' of exceptions.NameError object at 0xb779112c>
+	    __dict__ = {}
+	    __doc__ = 'Name not found globally.'
+	    __format__ = <built-in method __format__ of exceptions.NameError object at 0xb779112c>
+	    __getattribute__ = <method-wrapper '__getattribute__' of exceptions.NameError object at 0xb779112c>
+	    __getitem__ = <method-wrapper '__getitem__' of exceptions.NameError object at 0xb779112c>
+	    __getslice__ = <method-wrapper '__getslice__' of exceptions.NameError object at 0xb779112c>
+	    __hash__ = <method-wrapper '__hash__' of exceptions.NameError object at 0xb779112c>
+	    __init__ = <method-wrapper '__init__' of exceptions.NameError object at 0xb779112c>
+	    __new__ = <built-in method __new__ of type object at 0x475dca0>
+	    __reduce__ = <built-in method __reduce__ of exceptions.NameError object at 0xb779112c>
+	    __reduce_ex__ = <built-in method __reduce_ex__ of exceptions.NameError object at 0xb779112c>
+	    __repr__ = <method-wrapper '__repr__' of exceptions.NameError object at 0xb779112c>
+	    __setattr__ = <method-wrapper '__setattr__' of exceptions.NameError object at 0xb779112c>
+	    __setstate__ = <built-in method __setstate__ of exceptions.NameError object at 0xb779112c>
+	    __sizeof__ = <built-in method __sizeof__ of exceptions.NameError object at 0xb779112c>
+	    __str__ = <method-wrapper '__str__' of exceptions.NameError object at 0xb779112c>
+	    __subclasshook__ = <built-in method __subclasshook__ of type object at 0x475dca0>
+	    __unicode__ = <built-in method __unicode__ of exceptions.NameError object at 0xb779112c>
+	    args = ("global name 'arg2' is not defined",)
+	    message = "global name 'arg2' is not defined"
+	
+	The above is a description of an error in a Python program.  Here is
+	the original traceback:
+	
+	Traceback (most recent call last):
+	  File "cgitb_extended_traceback.py", line 25, in <module>
+	    func1(1)
+	  File "cgitb_extended_traceback.py", line 15, in func1
+	    return func2(local_var)
+	  File "cgitb_extended_traceback.py", line 19, in func2
+	    return func3(local_var)
+	  File "cgitb_extended_traceback.py", line 22, in func3
+	    local_var = arg2 / 2
+	NameError: global name 'arg2' is not defined
+	
+	
+
 .. {{{end}}}
 
 The end of the output also includes the full details of the exception
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'cgitb_local_vars.py', ignore_error=True))
 .. }}}
+
+::
+
+	$ python cgitb_local_vars.py
+	/usr/lib/python2.6/cgitb.py:245: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
+	  value = pydoc.text.repr(getattr(evalue, name))
+	<type 'exceptions.ZeroDivisionError'>
+	Python 2.6.2: /usr/bin/python
+	Wed Jul 21 18:59:39 2010
+	
+	A problem occurred in a Python script.  Here is the sequence of
+	function calls leading up to the error, in the order they occurred.
+	
+	 /home/morimoto/work/translate/02_pymotw/pymotw-ja/PyMOTW/cgitb/cgitb_local_vars.py in <module>()
+	   16 def func1(a, b):
+	   17     c = b - 5
+	   18     return func2(a, c)
+	   19 
+	   20 func1(1, 5)
+	func1 = <function func1 at 0xb770656c>
+	
+	 /home/morimoto/work/translate/02_pymotw/pymotw-ja/PyMOTW/cgitb/cgitb_local_vars.py in func1(a=1, b=5)
+	   16 def func1(a, b):
+	   17     c = b - 5
+	   18     return func2(a, c)
+	   19 
+	   20 func1(1, 5)
+	global func2 = <function func2 at 0xb77065a4>
+	a = 1
+	c = 0
+	
+	 /home/morimoto/work/translate/02_pymotw/pymotw-ja/PyMOTW/cgitb/cgitb_local_vars.py in func2(a=1, divisor=0)
+	   12 
+	   13 def func2(a, divisor):
+	   14     return a / divisor
+	   15 
+	   16 def func1(a, b):
+	a = 1
+	divisor = 0
+	<type 'exceptions.ZeroDivisionError'>: integer division or modulo by zero
+	    __class__ = <type 'exceptions.ZeroDivisionError'>
+	    __delattr__ = <method-wrapper '__delattr__' of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __dict__ = {}
+	    __doc__ = 'Second argument to a division or modulo operation was zero.'
+	    __format__ = <built-in method __format__ of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __getattribute__ = <method-wrapper '__getattribute__' of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __getitem__ = <method-wrapper '__getitem__' of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __getslice__ = <method-wrapper '__getslice__' of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __hash__ = <method-wrapper '__hash__' of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __init__ = <method-wrapper '__init__' of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __new__ = <built-in method __new__ of type object at 0x475ec60>
+	    __reduce__ = <built-in method __reduce__ of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __reduce_ex__ = <built-in method __reduce_ex__ of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __repr__ = <method-wrapper '__repr__' of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __setattr__ = <method-wrapper '__setattr__' of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __setstate__ = <built-in method __setstate__ of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __sizeof__ = <built-in method __sizeof__ of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __str__ = <method-wrapper '__str__' of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    __subclasshook__ = <built-in method __subclasshook__ of type object at 0x475ec60>
+	    __unicode__ = <built-in method __unicode__ of exceptions.ZeroDivisionError object at 0xb770a12c>
+	    args = ('integer division or modulo by zero',)
+	    message = 'integer division or modulo by zero'
+	
+	The above is a description of an error in a Python program.  Here is
+	the original traceback:
+	
+	Traceback (most recent call last):
+	  File "cgitb_local_vars.py", line 20, in <module>
+	    func1(1, 5)
+	  File "cgitb_local_vars.py", line 18, in func1
+	    return func2(a, c)
+	  File "cgitb_local_vars.py", line 14, in func2
+	    return a / divisor
+	ZeroDivisionError: integer division or modulo by zero
+	
+	
+
 .. {{{end}}}
 
 The code in :mod:`cgitb` that examines the variables used in the stack
 .. {{{cog
 .. cog.out(run_script(cog.inFile, 'cgitb_with_classes.py', ignore_error=True))
 .. }}}
+
+::
+
+	$ python cgitb_with_classes.py
+	/usr/lib/python2.6/cgitb.py:245: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
+	  value = pydoc.text.repr(getattr(evalue, name))
+	<type 'exceptions.ZeroDivisionError'>
+	Python 2.6.2: /usr/bin/python
+	Wed Jul 21 18:59:39 2010
+	
+	A problem occurred in a Python script.  Here is the sequence of
+	function calls leading up to the error, in the order they occurred.
+	
+	 /home/morimoto/work/translate/02_pymotw/pymotw-ja/PyMOTW/cgitb/cgitb_with_classes.py in <module>()
+	   24         return
+	   25 
+	   26 o = BrokenClass(1, 0)
+	   27 
+	   28 
+	o undefined
+	BrokenClass = <class '__main__.BrokenClass'>
+	
+	 /home/morimoto/work/translate/02_pymotw/pymotw-ja/PyMOTW/cgitb/cgitb_with_classes.py in __init__(self=<__main__.BrokenClass object at 0xb77c558c>, a=1, b=0)
+	   21         self.b = b
+	   22         self.c = self.a * self.b
+	   23         self.d = self.a / self.b
+	   24         return
+	   25 
+	self = <__main__.BrokenClass object at 0xb77c558c>
+	self.d undefined
+	self.a = 1
+	self.b = 0
+	<type 'exceptions.ZeroDivisionError'>: integer division or modulo by zero
+	    __class__ = <type 'exceptions.ZeroDivisionError'>
+	    __delattr__ = <method-wrapper '__delattr__' of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __dict__ = {}
+	    __doc__ = 'Second argument to a division or modulo operation was zero.'
+	    __format__ = <built-in method __format__ of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __getattribute__ = <method-wrapper '__getattribute__' of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __getitem__ = <method-wrapper '__getitem__' of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __getslice__ = <method-wrapper '__getslice__' of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __hash__ = <method-wrapper '__hash__' of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __init__ = <method-wrapper '__init__' of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __new__ = <built-in method __new__ of type object at 0x475ec60>
+	    __reduce__ = <built-in method __reduce__ of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __reduce_ex__ = <built-in method __reduce_ex__ of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __repr__ = <method-wrapper '__repr__' of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __setattr__ = <method-wrapper '__setattr__' of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __setstate__ = <built-in method __setstate__ of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __sizeof__ = <built-in method __sizeof__ of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __str__ = <method-wrapper '__str__' of exceptions.ZeroDivisionError object at 0xb77c55ac>
+	    __subclassho