annotate Demo/scripts/from.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 71a294bd7950
children 7d16b42fcdbd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4573
73758db2f464 /usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents: 1267
diff changeset
1 #! /usr/bin/env python
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # Print From and Subject of messages in $MAIL.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 # Extension to multiple mailboxes and other bells & whistles are left
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 # as exercises for the reader.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
756
5d2f62ad8dee change posix to os; and change error message
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
7 import sys, os
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 # Open mailbox file. Exits with exception when this fails.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
501
ddbcd532c114 Improved error handling.
Guido van Rossum <guido@python.org>
parents: 274
diff changeset
11 try:
16705
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
12 mailbox = os.environ['MAIL']
756
5d2f62ad8dee change posix to os; and change error message
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
13 except (AttributeError, KeyError):
16705
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
14 sys.stderr.write('No environment variable $MAIL\n')
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
15 sys.exit(2)
501
ddbcd532c114 Improved error handling.
Guido van Rossum <guido@python.org>
parents: 274
diff changeset
16
ddbcd532c114 Improved error handling.
Guido van Rossum <guido@python.org>
parents: 274
diff changeset
17 try:
16705
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
18 mail = open(mailbox)
870
9715fdc1e462 IOError instead of RuntimeError
Guido van Rossum <guido@python.org>
parents: 756
diff changeset
19 except IOError:
16705
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
20 sys.exit('Cannot open mailbox file: ' + mailbox)
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 while 1:
16705
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
23 line = mail.readline()
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
24 if not line:
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
25 break # EOF
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
26 if line.startswith('From '):
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
27 # Start of message found
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
28 print line[:-1],
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
29 while 1:
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
30 line = mail.readline()
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
31 if not line or line == '\n':
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
32 break
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
33 if line.startswith('Subject: '):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 16705
diff changeset
34 print repr(line[9:-1]),
16705
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
35 print