Mercurial > cpython-lru_cache-weakref
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 |
| 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 | 2 |
| 3 # Print From and Subject of messages in $MAIL. | |
| 4 # Extension to multiple mailboxes and other bells & whistles are left | |
| 5 # as exercises for the reader. | |
| 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 | 8 |
| 9 # Open mailbox file. Exits with exception when this fails. | |
| 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 | 21 |
| 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 |
