annotate Lib/mhlib.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 2cac31fc17c2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
1 """MH interface -- purely object-oriented (well, almost)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
2
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
3 Executive summary:
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
4
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
5 import mhlib
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
6
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
7 mh = mhlib.MH() # use default mailbox directory and profile
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
8 mh = mhlib.MH(mailbox) # override mailbox location (default from profile)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
9 mh = mhlib.MH(mailbox, profile) # override mailbox and profile
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
10
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
11 mh.error(format, ...) # print error message -- can be overridden
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
12 s = mh.getprofile(key) # profile entry (None if not set)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
13 path = mh.getpath() # mailbox pathname
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
14 name = mh.getcontext() # name of current folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
15 mh.setcontext(name) # set name of current folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
16
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
17 list = mh.listfolders() # names of top-level folders
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
18 list = mh.listallfolders() # names of all folders, including subfolders
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
19 list = mh.listsubfolders(name) # direct subfolders of given folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
20 list = mh.listallsubfolders(name) # all subfolders of given folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
21
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
22 mh.makefolder(name) # create new folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
23 mh.deletefolder(name) # delete folder -- must have no subfolders
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
24
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
25 f = mh.openfolder(name) # new open folder object
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
26
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
27 f.error(format, ...) # same as mh.error(format, ...)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
28 path = f.getfullname() # folder's full pathname
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
29 path = f.getsequencesfilename() # full pathname of folder's sequences file
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
30 path = f.getmessagefilename(n) # full pathname of message n in folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
31
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
32 list = f.listmessages() # list of messages in folder (as numbers)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
33 n = f.getcurrent() # get current message
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
34 f.setcurrent(n) # set current message
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
35 list = f.parsesequence(seq) # parse msgs syntax into list of messages
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
36 n = f.getlast() # get last message (0 if no messagse)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
37 f.setlast(n) # set last message (internal use only)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
38
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
39 dict = f.getsequences() # dictionary of sequences in folder {name: list}
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
40 f.putsequences(dict) # write sequences back to folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
41
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
42 f.createmessage(n, fp) # add message from file f as number n
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
43 f.removemessages(list) # remove messages in list from folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
44 f.refilemessages(list, tofolder) # move messages in list to other folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
45 f.movemessage(n, tofolder, ton) # move one message to a given destination
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
46 f.copymessage(n, tofolder, ton) # copy one message to a given destination
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
47
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
48 m = f.openmessage(n) # new open message object (costs a file descriptor)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
49 m is a derived class of mimetools.Message(rfc822.Message), with:
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
50 s = m.getheadertext() # text of message's headers
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
51 s = m.getheadertext(pred) # text of message's headers, filtered by pred
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
52 s = m.getbodytext() # text of message's body, decoded
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
53 s = m.getbodytext(0) # text of message's body, not decoded
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
54 """
46858
2cac31fc17c2 Deprecated the mhlib module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 34545
diff changeset
55 from warnings import warnpy3k
2cac31fc17c2 Deprecated the mhlib module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 34545
diff changeset
56 warnpy3k("the mhlib module has been removed in Python 3.0; use the mailbox "
2cac31fc17c2 Deprecated the mhlib module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 34545
diff changeset
57 "module instead", stacklevel=2)
2cac31fc17c2 Deprecated the mhlib module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 34545
diff changeset
58 del warnpy3k
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
59
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 # XXX To do, functionality:
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 # - annotate messages
10293
26db1e96caf3 Patch by Lars Wirzenius:
Guido van Rossum <guido@python.org>
parents: 8542
diff changeset
62 # - send messages
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 #
2050
19363f8570a2 * Lib/mhlib.py: added movemessage(), copymessage(), added copy
Guido van Rossum <guido@python.org>
parents: 1872
diff changeset
64 # XXX To do, organization:
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 # - move IntSet to separate file
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 # - move most Message functionality to module mimetools
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
68
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 # Customizable defaults
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 MH_PROFILE = '~/.mh_profile'
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 PATH = '~/Mail'
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 MH_SEQUENCES = '.mh_sequences'
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 FOLDER_PROTECT = 0700
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
75
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 # Imported modules
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
78
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 import os
3632
44161fb04b7e added setcontext and parsesequence; several small fixes
Guido van Rossum <guido@python.org>
parents: 2246
diff changeset
80 import sys
6519
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
81 import re
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 import mimetools
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 import multifile
2050
19363f8570a2 * Lib/mhlib.py: added movemessage(), copymessage(), added copy
Guido van Rossum <guido@python.org>
parents: 1872
diff changeset
84 import shutil
5331
6232acba7eb2 Rewrite parsesequence() to emulate MH without invoking pick.
Guido van Rossum <guido@python.org>
parents: 5228
diff changeset
85 from bisect import bisect
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
16198
32755b456369 a few more modules get __all__
Skip Montanaro <skip@pobox.com>
parents: 15543
diff changeset
87 __all__ = ["MH","Error","Folder","Message"]
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
88
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 # Exported constants
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
13115
8193e045787b Convert to use class-based exceptions.
Fred Drake <fdrake@acm.org>
parents: 11706
diff changeset
91 class Error(Exception):
8193e045787b Convert to use class-based exceptions.
Fred Drake <fdrake@acm.org>
parents: 11706
diff changeset
92 pass
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
94
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
95 class MH:
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
96 """Class representing a particular collection of folders.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
97 Optional constructor arguments are the pathname for the directory
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
98 containing the collection, and the MH profile to use.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
99 If either is omitted or empty a default is used; the default
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
100 directory is taken from the MH profile if it is specified there."""
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
101
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
102 def __init__(self, path = None, profile = None):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
103 """Constructor."""
23622
5edd80726d96 Replace boolean test with is None.
Raymond Hettinger <python@rcn.com>
parents: 23620
diff changeset
104 if profile is None: profile = MH_PROFILE
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
105 self.profile = os.path.expanduser(profile)
23622
5edd80726d96 Replace boolean test with is None.
Raymond Hettinger <python@rcn.com>
parents: 23620
diff changeset
106 if path is None: path = self.getprofile('Path')
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
107 if not path: path = PATH
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
108 if not os.path.isabs(path) and path[0] != '~':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
109 path = os.path.join('~', path)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
110 path = os.path.expanduser(path)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
111 if not os.path.isdir(path): raise Error, 'MH() path not found'
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
112 self.path = path
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
113
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
114 def __repr__(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
115 """String representation."""
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
116 return 'MH(%r, %r)' % (self.path, self.profile)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
117
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
118 def error(self, msg, *args):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
119 """Routine to print an error. May be overridden by a derived class."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
120 sys.stderr.write('MH error: %s\n' % (msg % args))
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
121
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
122 def getprofile(self, key):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
123 """Return a profile entry, None if not found."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
124 return pickline(self.profile, key)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
126 def getpath(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
127 """Return the path (the name of the collection's directory)."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
128 return self.path
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
130 def getcontext(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
131 """Return the name of the current folder."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
132 context = pickline(os.path.join(self.getpath(), 'context'),
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
133 'Current-Folder')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
134 if not context: context = 'inbox'
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
135 return context
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
136
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
137 def setcontext(self, context):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
138 """Set the name of the current folder."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
139 fn = os.path.join(self.getpath(), 'context')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
140 f = open(fn, "w")
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
141 f.write("Current-Folder: %s\n" % context)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
142 f.close()
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
143
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
144 def listfolders(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
145 """Return the names of the top-level folders."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
146 folders = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
147 path = self.getpath()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
148 for name in os.listdir(path):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
149 fullname = os.path.join(path, name)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
150 if os.path.isdir(fullname):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
151 folders.append(name)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
152 folders.sort()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
153 return folders
3632
44161fb04b7e added setcontext and parsesequence; several small fixes
Guido van Rossum <guido@python.org>
parents: 2246
diff changeset
154
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
155 def listsubfolders(self, name):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
156 """Return the names of the subfolders in a given folder
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
157 (prefixed with the given folder name)."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
158 fullname = os.path.join(self.path, name)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
159 # Get the link count so we can avoid listing folders
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
160 # that have no subfolders.
23625
65cf478950ff Replaced obsolete stat module constants with equivalent attributes
Raymond Hettinger <python@rcn.com>
parents: 23622
diff changeset
161 nlinks = os.stat(fullname).st_nlink
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
162 if nlinks <= 2:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
163 return []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
164 subfolders = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
165 subnames = os.listdir(fullname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
166 for subname in subnames:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
167 fullsubname = os.path.join(fullname, subname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
168 if os.path.isdir(fullsubname):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
169 name_subname = os.path.join(name, subname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
170 subfolders.append(name_subname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
171 # Stop looking for subfolders when
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
172 # we've seen them all
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
173 nlinks = nlinks - 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
174 if nlinks <= 2:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
175 break
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
176 subfolders.sort()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
177 return subfolders
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
178
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
179 def listallfolders(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
180 """Return the names of all folders and subfolders, recursively."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
181 return self.listallsubfolders('')
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
182
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
183 def listallsubfolders(self, name):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
184 """Return the names of subfolders in a given folder, recursively."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
185 fullname = os.path.join(self.path, name)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
186 # Get the link count so we can avoid listing folders
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
187 # that have no subfolders.
23625
65cf478950ff Replaced obsolete stat module constants with equivalent attributes
Raymond Hettinger <python@rcn.com>
parents: 23622
diff changeset
188 nlinks = os.stat(fullname).st_nlink
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
189 if nlinks <= 2:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
190 return []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
191 subfolders = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
192 subnames = os.listdir(fullname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
193 for subname in subnames:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
194 if subname[0] == ',' or isnumeric(subname): continue
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
195 fullsubname = os.path.join(fullname, subname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
196 if os.path.isdir(fullsubname):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
197 name_subname = os.path.join(name, subname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
198 subfolders.append(name_subname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
199 if not os.path.islink(fullsubname):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
200 subsubfolders = self.listallsubfolders(
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
201 name_subname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
202 subfolders = subfolders + subsubfolders
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
203 # Stop looking for subfolders when
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
204 # we've seen them all
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
205 nlinks = nlinks - 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
206 if nlinks <= 2:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
207 break
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
208 subfolders.sort()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
209 return subfolders
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
210
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
211 def openfolder(self, name):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
212 """Return a new Folder object for the named folder."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
213 return Folder(self, name)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
214
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
215 def makefolder(self, name):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
216 """Create a new folder (or raise os.error if it cannot be created)."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
217 protect = pickline(self.profile, 'Folder-Protect')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
218 if protect and isnumeric(protect):
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
219 mode = int(protect, 8)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
220 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
221 mode = FOLDER_PROTECT
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
222 os.mkdir(os.path.join(self.getpath(), name), mode)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
223
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
224 def deletefolder(self, name):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
225 """Delete a folder. This removes files in the folder but not
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
226 subdirectories. Raise os.error if deleting the folder itself fails."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
227 fullname = os.path.join(self.getpath(), name)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
228 for subname in os.listdir(fullname):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
229 fullsubname = os.path.join(fullname, subname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
230 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
231 os.unlink(fullsubname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
232 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
233 self.error('%s not deleted, continuing...' %
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
234 fullsubname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
235 os.rmdir(fullname)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
236
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
237
6519
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
238 numericprog = re.compile('^[1-9][0-9]*$')
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 def isnumeric(str):
6519
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
240 return numericprog.match(str) is not None
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
241
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 class Folder:
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
243 """Class representing a particular folder."""
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
244
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
245 def __init__(self, mh, name):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
246 """Constructor."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
247 self.mh = mh
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
248 self.name = name
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
249 if not os.path.isdir(self.getfullname()):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
250 raise Error, 'no folder %s' % name
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
251
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
252 def __repr__(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
253 """String representation."""
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
254 return 'Folder(%r, %r)' % (self.mh, self.name)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
255
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
256 def error(self, *args):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
257 """Error message handler."""
28089
14f65d661084 Get rid of many apply() calls.
Guido van Rossum <guido@python.org>
parents: 23651
diff changeset
258 self.mh.error(*args)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
259
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
260 def getfullname(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
261 """Return the full pathname of the folder."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
262 return os.path.join(self.mh.path, self.name)
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
263
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
264 def getsequencesfilename(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
265 """Return the full pathname of the folder's sequences file."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
266 return os.path.join(self.getfullname(), MH_SEQUENCES)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
267
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
268 def getmessagefilename(self, n):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
269 """Return the full pathname of a message in the folder."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
270 return os.path.join(self.getfullname(), str(n))
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
271
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
272 def listsubfolders(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
273 """Return list of direct subfolders."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
274 return self.mh.listsubfolders(self.name)
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
275
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
276 def listallsubfolders(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
277 """Return list of all subfolders."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
278 return self.mh.listallsubfolders(self.name)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
279
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
280 def listmessages(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
281 """Return the list of messages currently present in the folder.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
282 As a side effect, set self.last to the last message (or 0)."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
283 messages = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
284 match = numericprog.match
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
285 append = messages.append
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
286 for name in os.listdir(self.getfullname()):
8542
5c2f19d19643 "if match(x) >= 0:" smells of regex matching; should use "if match(x):"
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
287 if match(name):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
288 append(name)
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
289 messages = map(int, messages)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
290 messages.sort()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
291 if messages:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
292 self.last = messages[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
293 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
294 self.last = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
295 return messages
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
296
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
297 def getsequences(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
298 """Return the set of sequences for the folder."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
299 sequences = {}
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
300 fullname = self.getsequencesfilename()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
301 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
302 f = open(fullname, 'r')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
303 except IOError:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
304 return sequences
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
305 while 1:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
306 line = f.readline()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
307 if not line: break
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
308 fields = line.split(':')
15543
785155e2cfca Update the code to better reflect recommended style:
Fred Drake <fdrake@acm.org>
parents: 13620
diff changeset
309 if len(fields) != 2:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
310 self.error('bad sequence in %s: %s' %
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
311 (fullname, line.strip()))
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
312 key = fields[0].strip()
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
313 value = IntSet(fields[1].strip(), ' ').tolist()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
314 sequences[key] = value
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
315 return sequences
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
316
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
317 def putsequences(self, sequences):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
318 """Write the set of sequences back to the folder."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
319 fullname = self.getsequencesfilename()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
320 f = None
23651
f0ca3935d011 Replace .keys() with .iteritems(). Second review and test by Alex.
Raymond Hettinger <python@rcn.com>
parents: 23631
diff changeset
321 for key, seq in sequences.iteritems():
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
322 s = IntSet('', ' ')
23651
f0ca3935d011 Replace .keys() with .iteritems(). Second review and test by Alex.
Raymond Hettinger <python@rcn.com>
parents: 23631
diff changeset
323 s.fromlist(seq)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
324 if not f: f = open(fullname, 'w')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
325 f.write('%s: %s\n' % (key, s.tostring()))
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
326 if not f:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
327 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
328 os.unlink(fullname)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
329 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
330 pass
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
331 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
332 f.close()
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
333
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
334 def getcurrent(self):
13115
8193e045787b Convert to use class-based exceptions.
Fred Drake <fdrake@acm.org>
parents: 11706
diff changeset
335 """Return the current message. Raise Error when there is none."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
336 seqs = self.getsequences()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
337 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
338 return max(seqs['cur'])
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
339 except (ValueError, KeyError):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
340 raise Error, "no cur message"
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
341
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
342 def setcurrent(self, n):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
343 """Set the current message."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
344 updateline(self.getsequencesfilename(), 'cur', str(n), 0)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
345
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
346 def parsesequence(self, seq):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
347 """Parse an MH sequence specification into a message list.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
348 Attempt to mimic mh-sequence(5) as close as possible.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
349 Also attempt to mimic observed behavior regarding which
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
350 conditions cause which error messages."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
351 # XXX Still not complete (see mh-format(5)).
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
352 # Missing are:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
353 # - 'prev', 'next' as count
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
354 # - Sequence-Negation option
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
355 all = self.listmessages()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
356 # Observed behavior: test for empty folder is done first
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
357 if not all:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
358 raise Error, "no messages in %s" % self.name
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
359 # Common case first: all is frequently the default
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
360 if seq == 'all':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
361 return all
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
362 # Test for X:Y before X-Y because 'seq:-n' matches both
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
363 i = seq.find(':')
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
364 if i >= 0:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
365 head, dir, tail = seq[:i], '', seq[i+1:]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
366 if tail[:1] in '-+':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
367 dir, tail = tail[:1], tail[1:]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
368 if not isnumeric(tail):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
369 raise Error, "bad message list %s" % seq
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
370 try:
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
371 count = int(tail)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
372 except (ValueError, OverflowError):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
373 # Can't use sys.maxint because of i+count below
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
374 count = len(all)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
375 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
376 anchor = self._parseindex(head, all)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
377 except Error, msg:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
378 seqs = self.getsequences()
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 22830
diff changeset
379 if not head in seqs:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
380 if not msg:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
381 msg = "bad message list %s" % seq
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
382 raise Error, msg, sys.exc_info()[2]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
383 msgs = seqs[head]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
384 if not msgs:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
385 raise Error, "sequence %s empty" % head
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
386 if dir == '-':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
387 return msgs[-count:]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
388 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
389 return msgs[:count]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
390 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
391 if not dir:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
392 if head in ('prev', 'last'):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
393 dir = '-'
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
394 if dir == '-':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
395 i = bisect(all, anchor)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
396 return all[max(0, i-count):i]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
397 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
398 i = bisect(all, anchor-1)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
399 return all[i:i+count]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
400 # Test for X-Y next
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
401 i = seq.find('-')
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
402 if i >= 0:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
403 begin = self._parseindex(seq[:i], all)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
404 end = self._parseindex(seq[i+1:], all)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
405 i = bisect(all, begin-1)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
406 j = bisect(all, end)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
407 r = all[i:j]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
408 if not r:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
409 raise Error, "bad message list %s" % seq
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
410 return r
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
411 # Neither X:Y nor X-Y; must be a number or a (pseudo-)sequence
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
412 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
413 n = self._parseindex(seq, all)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
414 except Error, msg:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
415 seqs = self.getsequences()
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 22830
diff changeset
416 if not seq in seqs:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
417 if not msg:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
418 msg = "bad message list %s" % seq
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
419 raise Error, msg
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
420 return seqs[seq]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
421 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
422 if n not in all:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
423 if isnumeric(seq):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
424 raise Error, "message %d doesn't exist" % n
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
425 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
426 raise Error, "no %s message" % seq
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
427 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
428 return [n]
3632
44161fb04b7e added setcontext and parsesequence; several small fixes
Guido van Rossum <guido@python.org>
parents: 2246
diff changeset
429
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
430 def _parseindex(self, seq, all):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
431 """Internal: parse a message number (or cur, first, etc.)."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
432 if isnumeric(seq):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
433 try:
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
434 return int(seq)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
435 except (OverflowError, ValueError):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
436 return sys.maxint
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
437 if seq in ('cur', '.'):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
438 return self.getcurrent()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
439 if seq == 'first':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
440 return all[0]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
441 if seq == 'last':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
442 return all[-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
443 if seq == 'next':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
444 n = self.getcurrent()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
445 i = bisect(all, n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
446 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
447 return all[i]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
448 except IndexError:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
449 raise Error, "no next message"
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
450 if seq == 'prev':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
451 n = self.getcurrent()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
452 i = bisect(all, n-1)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
453 if i == 0:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
454 raise Error, "no prev message"
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
455 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
456 return all[i-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
457 except IndexError:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
458 raise Error, "no prev message"
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
459 raise Error, None
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
460
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
461 def openmessage(self, n):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
462 """Open a message -- returns a Message object."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
463 return Message(self, n)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
464
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
465 def removemessages(self, list):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
466 """Remove one or more messages -- may raise os.error."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
467 errors = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
468 deleted = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
469 for n in list:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
470 path = self.getmessagefilename(n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
471 commapath = self.getmessagefilename(',' + str(n))
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
472 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
473 os.unlink(commapath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
474 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
475 pass
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
476 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
477 os.rename(path, commapath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
478 except os.error, msg:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
479 errors.append(msg)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
480 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
481 deleted.append(n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
482 if deleted:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
483 self.removefromallsequences(deleted)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
484 if errors:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
485 if len(errors) == 1:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
486 raise os.error, errors[0]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
487 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
488 raise os.error, ('multiple errors:', errors)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
489
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
490 def refilemessages(self, list, tofolder, keepsequences=0):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
491 """Refile one or more messages -- may raise os.error.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
492 'tofolder' is an open folder object."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
493 errors = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
494 refiled = {}
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
495 for n in list:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
496 ton = tofolder.getlast() + 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
497 path = self.getmessagefilename(n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
498 topath = tofolder.getmessagefilename(ton)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
499 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
500 os.rename(path, topath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
501 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
502 # Try copying
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
503 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
504 shutil.copy2(path, topath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
505 os.unlink(path)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
506 except (IOError, os.error), msg:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
507 errors.append(msg)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
508 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
509 os.unlink(topath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
510 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
511 pass
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
512 continue
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
513 tofolder.setlast(ton)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
514 refiled[n] = ton
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
515 if refiled:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
516 if keepsequences:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
517 tofolder._copysequences(self, refiled.items())
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
518 self.removefromallsequences(refiled.keys())
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
519 if errors:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
520 if len(errors) == 1:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
521 raise os.error, errors[0]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
522 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
523 raise os.error, ('multiple errors:', errors)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
524
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
525 def _copysequences(self, fromfolder, refileditems):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
526 """Helper for refilemessages() to copy sequences."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
527 fromsequences = fromfolder.getsequences()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
528 tosequences = self.getsequences()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
529 changed = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
530 for name, seq in fromsequences.items():
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
531 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
532 toseq = tosequences[name]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
533 new = 0
18380
d1c60b07217f Clean up a bare except: clause.
unknown <tools@python.org>
parents: 16548
diff changeset
534 except KeyError:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
535 toseq = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
536 new = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
537 for fromn, ton in refileditems:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
538 if fromn in seq:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
539 toseq.append(ton)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
540 changed = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
541 if new and toseq:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
542 tosequences[name] = toseq
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
543 if changed:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
544 self.putsequences(tosequences)
3755
6598a518668f Added option to refilemessages() to keep sequences
Guido van Rossum <guido@python.org>
parents: 3632
diff changeset
545
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
546 def movemessage(self, n, tofolder, ton):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
547 """Move one message over a specific destination message,
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
548 which may or may not already exist."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
549 path = self.getmessagefilename(n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
550 # Open it to check that it exists
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
551 f = open(path)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
552 f.close()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
553 del f
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
554 topath = tofolder.getmessagefilename(ton)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
555 backuptopath = tofolder.getmessagefilename(',%d' % ton)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
556 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
557 os.rename(topath, backuptopath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
558 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
559 pass
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
560 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
561 os.rename(path, topath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
562 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
563 # Try copying
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
564 ok = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
565 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
566 tofolder.setlast(None)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
567 shutil.copy2(path, topath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
568 ok = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
569 finally:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
570 if not ok:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
571 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
572 os.unlink(topath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
573 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
574 pass
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
575 os.unlink(path)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
576 self.removefromallsequences([n])
2050
19363f8570a2 * Lib/mhlib.py: added movemessage(), copymessage(), added copy
Guido van Rossum <guido@python.org>
parents: 1872
diff changeset
577
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
578 def copymessage(self, n, tofolder, ton):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
579 """Copy one message over a specific destination message,
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
580 which may or may not already exist."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
581 path = self.getmessagefilename(n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
582 # Open it to check that it exists
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
583 f = open(path)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
584 f.close()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
585 del f
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
586 topath = tofolder.getmessagefilename(ton)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
587 backuptopath = tofolder.getmessagefilename(',%d' % ton)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
588 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
589 os.rename(topath, backuptopath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
590 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
591 pass
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
592 ok = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
593 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
594 tofolder.setlast(None)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
595 shutil.copy2(path, topath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
596 ok = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
597 finally:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
598 if not ok:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
599 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
600 os.unlink(topath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
601 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
602 pass
2050
19363f8570a2 * Lib/mhlib.py: added movemessage(), copymessage(), added copy
Guido van Rossum <guido@python.org>
parents: 1872
diff changeset
603
5899
f82b608afb56 Added createmessage() -- Lars Wirzenius.
Guido van Rossum <guido@python.org>
parents: 5332
diff changeset
604 def createmessage(self, n, txt):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
605 """Create a message, with text from the open file txt."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
606 path = self.getmessagefilename(n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
607 backuppath = self.getmessagefilename(',%d' % n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
608 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
609 os.rename(path, backuppath)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
610 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
611 pass
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
612 ok = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
613 BUFSIZE = 16*1024
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
614 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
615 f = open(path, "w")
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
616 while 1:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
617 buf = txt.read(BUFSIZE)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
618 if not buf:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
619 break
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
620 f.write(buf)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
621 f.close()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
622 ok = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
623 finally:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
624 if not ok:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
625 try:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
626 os.unlink(path)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
627 except os.error:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
628 pass
5899
f82b608afb56 Added createmessage() -- Lars Wirzenius.
Guido van Rossum <guido@python.org>
parents: 5332
diff changeset
629
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
630 def removefromallsequences(self, list):
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 13115
diff changeset
631 """Remove one or more messages from all sequences (including last)
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
632 -- but not from 'cur'!!!"""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
633 if hasattr(self, 'last') and self.last in list:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
634 del self.last
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
635 sequences = self.getsequences()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
636 changed = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
637 for name, seq in sequences.items():
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
638 if name == 'cur':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
639 continue
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
640 for n in list:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
641 if n in seq:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
642 seq.remove(n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
643 changed = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
644 if not seq:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
645 del sequences[name]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
646 if changed:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
647 self.putsequences(sequences)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
648
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
649 def getlast(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
650 """Return the last message number."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
651 if not hasattr(self, 'last'):
20486
4bfdbc82310f Folder.getlast(): avoid PyChecker warning.
Guido van Rossum <guido@python.org>
parents: 18380
diff changeset
652 self.listmessages() # Set self.last
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
653 return self.last
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
654
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
655 def setlast(self, last):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
656 """Set the last message number."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
657 if last is None:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
658 if hasattr(self, 'last'):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
659 del self.last
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
660 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
661 self.last = last
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
662
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
663 class Message(mimetools.Message):
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
664
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
665 def __init__(self, f, n, fp = None):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
666 """Constructor."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
667 self.folder = f
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
668 self.number = n
23622
5edd80726d96 Replace boolean test with is None.
Raymond Hettinger <python@rcn.com>
parents: 23620
diff changeset
669 if fp is None:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
670 path = f.getmessagefilename(n)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
671 fp = open(path, 'r')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
672 mimetools.Message.__init__(self, fp)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
673
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
674 def __repr__(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
675 """String representation."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
676 return 'Message(%s, %s)' % (repr(self.folder), self.number)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
677
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
678 def getheadertext(self, pred = None):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
679 """Return the message's header text as a string. If an
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
680 argument is specified, it is used as a filter predicate to
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
681 decide which headers to return (its argument is the header
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
682 name converted to lower case)."""
23622
5edd80726d96 Replace boolean test with is None.
Raymond Hettinger <python@rcn.com>
parents: 23620
diff changeset
683 if pred is None:
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
684 return ''.join(self.headers)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
685 headers = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
686 hit = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
687 for line in self.headers:
16548
da8681f17b50 String method cleanup.
Eric S. Raymond <esr@thyrsus.com>
parents: 16511
diff changeset
688 if not line[0].isspace():
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
689 i = line.find(':')
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
690 if i > 0:
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
691 hit = pred(line[:i].lower())
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
692 if hit: headers.append(line)
16511
18ef3d5eab4f Test with an actual mbox caught a trivial error.
Eric S. Raymond <esr@thyrsus.com>
parents: 16497
diff changeset
693 return ''.join(headers)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
694
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
695 def getbodytext(self, decode = 1):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
696 """Return the message's body text as string. This undoes a
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
697 Content-Transfer-Encoding, but does not interpret other MIME
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
698 features (e.g. multipart messages). To suppress decoding,
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
699 pass 0 as an argument."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
700 self.fp.seek(self.startofbody)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
701 encoding = self.getencoding()
10293
26db1e96caf3 Patch by Lars Wirzenius:
Guido van Rossum <guido@python.org>
parents: 8542
diff changeset
702 if not decode or encoding in ('', '7bit', '8bit', 'binary'):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
703 return self.fp.read()
34293
cd517701fd93 Use cStringIO where available.
Raymond Hettinger <python@rcn.com>
parents: 31515
diff changeset
704 try:
cd517701fd93 Use cStringIO where available.
Raymond Hettinger <python@rcn.com>
parents: 31515
diff changeset
705 from cStringIO import StringIO
cd517701fd93 Use cStringIO where available.
Raymond Hettinger <python@rcn.com>
parents: 31515
diff changeset
706 except ImportError:
cd517701fd93 Use cStringIO where available.
Raymond Hettinger <python@rcn.com>
parents: 31515
diff changeset
707 from StringIO import StringIO
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
708 output = StringIO()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
709 mimetools.decode(self.fp, output, encoding)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
710 return output.getvalue()
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
711
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
712 def getbodyparts(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
713 """Only for multipart messages: return the message's body as a
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
714 list of SubMessage objects. Each submessage object behaves
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
715 (almost) as a Message object."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
716 if self.getmaintype() != 'multipart':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
717 raise Error, 'Content-Type is not multipart/*'
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
718 bdry = self.getparam('boundary')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
719 if not bdry:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
720 raise Error, 'multipart/* without boundary param'
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
721 self.fp.seek(self.startofbody)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
722 mf = multifile.MultiFile(self.fp)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
723 mf.push(bdry)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
724 parts = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
725 while mf.next():
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
726 n = "%s.%r" % (self.number, 1 + len(parts))
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
727 part = SubMessage(self.folder, n, mf)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
728 parts.append(part)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
729 mf.pop()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
730 return parts
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
731
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
732 def getbody(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
733 """Return body, either a string or a list of messages."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
734 if self.getmaintype() == 'multipart':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
735 return self.getbodyparts()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
736 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
737 return self.getbodytext()
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
738
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
739
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
740 class SubMessage(Message):
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
741
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
742 def __init__(self, f, n, fp):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
743 """Constructor."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
744 Message.__init__(self, f, n, fp)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
745 if self.getmaintype() == 'multipart':
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
746 self.body = Message.getbodyparts(self)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
747 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
748 self.body = Message.getbodytext(self)
10293
26db1e96caf3 Patch by Lars Wirzenius:
Guido van Rossum <guido@python.org>
parents: 8542
diff changeset
749 self.bodyencoded = Message.getbodytext(self, decode=0)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
750 # XXX If this is big, should remember file pointers
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
751
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
752 def __repr__(self):
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
753 """String representation."""
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
754 f, n, fp = self.folder, self.number, self.fp
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
755 return 'SubMessage(%s, %s, %s)' % (f, n, fp)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
756
10293
26db1e96caf3 Patch by Lars Wirzenius:
Guido van Rossum <guido@python.org>
parents: 8542
diff changeset
757 def getbodytext(self, decode = 1):
26db1e96caf3 Patch by Lars Wirzenius:
Guido van Rossum <guido@python.org>
parents: 8542
diff changeset
758 if not decode:
26db1e96caf3 Patch by Lars Wirzenius:
Guido van Rossum <guido@python.org>
parents: 8542
diff changeset
759 return self.bodyencoded
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
760 if type(self.body) == type(''):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
761 return self.body
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
762
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
763 def getbodyparts(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
764 if type(self.body) == type([]):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
765 return self.body
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
766
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
767 def getbody(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
768 return self.body
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
769
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
770
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
771 class IntSet:
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
772 """Class implementing sets of integers.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
773
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
774 This is an efficient representation for sets consisting of several
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
775 continuous ranges, e.g. 1-100,200-400,402-1000 is represented
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
776 internally as a list of three pairs: [(1,100), (200,400),
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
777 (402,1000)]. The internal representation is always kept normalized.
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
778
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
779 The constructor has up to three arguments:
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
780 - the string used to initialize the set (default ''),
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
781 - the separator between ranges (default ',')
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
782 - the separator between begin and end of a range (default '-')
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
783 The separators must be strings (not regexprs) and should be different.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
784
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
785 The tostring() function yields a string that can be passed to another
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
786 IntSet constructor; __repr__() is a valid IntSet constructor itself.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
787 """
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
788
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
789 # XXX The default begin/end separator means that negative numbers are
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
790 # not supported very well.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
791 #
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 10293
diff changeset
792 # XXX There are currently no operations to remove set elements.
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
793
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
794 def __init__(self, data = None, sep = ',', rng = '-'):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
795 self.pairs = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
796 self.sep = sep
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
797 self.rng = rng
23631
1a5216235602 Make test_mhlib run again.
Michael W. Hudson <mwh@python.net>
parents: 23625
diff changeset
798 if data: self.fromstring(data)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
799
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
800 def reset(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
801 self.pairs = []
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
802
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
803 def __cmp__(self, other):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
804 return cmp(self.pairs, other.pairs)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
805
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
806 def __hash__(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
807 return hash(self.pairs)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
808
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
809 def __repr__(self):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
810 return 'IntSet(%r, %r, %r)' % (self.tostring(), self.sep, self.rng)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
811
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
812 def normalize(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
813 self.pairs.sort()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
814 i = 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
815 while i < len(self.pairs):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
816 alo, ahi = self.pairs[i-1]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
817 blo, bhi = self.pairs[i]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
818 if ahi >= blo-1:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
819 self.pairs[i-1:i+1] = [(alo, max(ahi, bhi))]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
820 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
821 i = i+1
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
822
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
823 def tostring(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
824 s = ''
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
825 for lo, hi in self.pairs:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
826 if lo == hi: t = repr(lo)
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
827 else: t = repr(lo) + self.rng + repr(hi)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
828 if s: s = s + (self.sep + t)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
829 else: s = t
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
830 return s
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
831
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
832 def tolist(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
833 l = []
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
834 for lo, hi in self.pairs:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
835 m = range(lo, hi+1)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
836 l = l + m
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
837 return l
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
838
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
839 def fromlist(self, list):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
840 for i in list:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
841 self.append(i)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
842
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
843 def clone(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
844 new = IntSet()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
845 new.pairs = self.pairs[:]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
846 return new
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
847
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
848 def min(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
849 return self.pairs[0][0]
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
850
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
851 def max(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
852 return self.pairs[-1][-1]
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
853
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
854 def contains(self, x):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
855 for lo, hi in self.pairs:
22830
a9dd5e6d6805 Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents: 20486
diff changeset
856 if lo <= x <= hi: return True
a9dd5e6d6805 Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents: 20486
diff changeset
857 return False
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
858
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
859 def append(self, x):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
860 for i in range(len(self.pairs)):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
861 lo, hi = self.pairs[i]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
862 if x < lo: # Need to insert before
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
863 if x+1 == lo:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
864 self.pairs[i] = (x, hi)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
865 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
866 self.pairs.insert(i, (x, x))
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
867 if i > 0 and x-1 == self.pairs[i-1][1]:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
868 # Merge with previous
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
869 self.pairs[i-1:i+1] = [
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
870 (self.pairs[i-1][0],
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
871 self.pairs[i][1])
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
872 ]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
873 return
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
874 if x <= hi: # Already in set
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
875 return
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
876 i = len(self.pairs) - 1
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
877 if i >= 0:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
878 lo, hi = self.pairs[i]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
879 if x-1 == hi:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
880 self.pairs[i] = lo, x
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
881 return
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
882 self.pairs.append((x, x))
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
883
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
884 def addpair(self, xlo, xhi):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
885 if xlo > xhi: return
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
886 self.pairs.append((xlo, xhi))
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
887 self.normalize()
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
888
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
889 def fromstring(self, data):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
890 new = []
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
891 for part in data.split(self.sep):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
892 list = []
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
893 for subp in part.split(self.rng):
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
894 s = subp.strip()
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
895 list.append(int(s))
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
896 if len(list) == 1:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
897 new.append((list[0], list[0]))
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
898 elif len(list) == 2 and list[0] <= list[1]:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
899 new.append((list[0], list[1]))
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
900 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
901 raise ValueError, 'bad data passed to IntSet'
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
902 self.pairs = self.pairs + new
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
903 self.normalize()
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
904
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
905
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
906 # Subroutines to read/write entries in .mh_profile and .mh_sequences
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
907
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
908 def pickline(file, key, casefold = 1):
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
909 try:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
910 f = open(file, 'r')
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
911 except IOError:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
912 return None
6519
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
913 pat = re.escape(key) + ':'
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
914 prog = re.compile(pat, casefold and re.IGNORECASE)
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
915 while 1:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
916 line = f.readline()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
917 if not line: break
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
918 if prog.match(line):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
919 text = line[len(key)+1:]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
920 while 1:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
921 line = f.readline()
16548
da8681f17b50 String method cleanup.
Eric S. Raymond <esr@thyrsus.com>
parents: 16511
diff changeset
922 if not line or not line[0].isspace():
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
923 break
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
924 text = text + line
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
925 return text.strip()
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
926 return None
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
927
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
928 def updateline(file, key, value, casefold = 1):
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
929 try:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
930 f = open(file, 'r')
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
931 lines = f.readlines()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
932 f.close()
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
933 except IOError:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
934 lines = []
6519
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
935 pat = re.escape(key) + ':(.*)\n'
24da035ceb6e Convert all remaining *simple* cases of regex usage to re usage.
Guido van Rossum <guido@python.org>
parents: 6347
diff changeset
936 prog = re.compile(pat, casefold and re.IGNORECASE)
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
937 if value is None:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
938 newline = None
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
939 else:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
940 newline = '%s: %s\n' % (key, value)
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
941 for i in range(len(lines)):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
942 line = lines[i]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
943 if prog.match(line):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
944 if newline is None:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
945 del lines[i]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
946 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
947 lines[i] = newline
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
948 break
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
949 else:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
950 if newline is not None:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
951 lines.append(newline)
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
952 tempfile = file + "~"
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
953 f = open(tempfile, 'w')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
954 for line in lines:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
955 f.write(line)
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
956 f.close()
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
957 os.rename(tempfile, file)
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
958
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
959
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
960 # Test program
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
961
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
962 def test():
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
963 global mh, f
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
964 os.system('rm -rf $HOME/Mail/@test')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
965 mh = MH()
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
966 def do(s): print s; print eval(s)
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
967 do('mh.listfolders()')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
968 do('mh.listallfolders()')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
969 testfolders = ['@test', '@test/test1', '@test/test2',
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
970 '@test/test1/test11', '@test/test1/test12',
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
971 '@test/test1/test11/test111']
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
972 for t in testfolders: do('mh.makefolder(%r)' % (t,))
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
973 do('mh.listsubfolders(\'@test\')')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
974 do('mh.listallsubfolders(\'@test\')')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
975 f = mh.openfolder('@test')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
976 do('f.listsubfolders()')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
977 do('f.listallsubfolders()')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
978 do('f.getsequences()')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
979 seqs = f.getsequences()
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
980 seqs['foo'] = IntSet('1-10 12-20', ' ').tolist()
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
981 print seqs
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
982 f.putsequences(seqs)
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
983 do('f.getsequences()')
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
984 for t in reversed(testfolders): do('mh.deletefolder(%r)' % (t,))
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
985 do('mh.getcontext()')
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
986 context = mh.getcontext()
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
987 f = mh.openfolder(context)
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
988 do('f.getcurrent()')
34545
9d66fba78444 Replace list of constants with tuples of constants.
Raymond Hettinger <python@rcn.com>
parents: 34293
diff changeset
989 for seq in ('first', 'last', 'cur', '.', 'prev', 'next',
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
990 'first:3', 'last:3', 'cur:3', 'cur:-3',
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
991 'prev:3', 'next:3',
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
992 '1:3', '1:-3', '100:3', '100:-3', '10000:3', '10000:-3',
34545
9d66fba78444 Replace list of constants with tuples of constants.
Raymond Hettinger <python@rcn.com>
parents: 34293
diff changeset
993 'all'):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
994 try:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
995 do('f.parsesequence(%r)' % (seq,))
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
996 except Error, msg:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
997 print "Error:", msg
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30865
diff changeset
998 stuff = os.popen("pick %r 2>/dev/null" % (seq,)).read()
16497
d329606361f8 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16198
diff changeset
999 list = map(int, stuff.split())
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6941
diff changeset
1000 print list, "<-- pick"
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
1001 do('f.listmessages()')
1681
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
1002
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
1003
dc8e1d72d78d mhlib.py: new interface to MH folders and messages
Guido van Rossum <guido@python.org>
parents:
diff changeset
1004 if __name__ == '__main__':
5332
8dfc252963c7 Reindented with 4 spaces.
Guido van Rossum <guido@python.org>
parents: 5331
diff changeset
1005 test()