annotate Demo/scripts/from.py @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents 932a1f8d92f7
children 71a294bd7950
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: '):
932a1f8d92f7 Fixed to use new Python features and use more commonly accepted style
Moshe Zadka <moshez@math.huji.ac.il>
parents: 4573
diff changeset
34 print `line[9:-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
35 print