diff options
author | Guido van Rossum <guido@python.org> | 2000-02-04 15:10:34 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-02-04 15:10:34 (GMT) |
commit | 54f22ed30bab2e64909ba2d79205cb4b87c69db2 (patch) | |
tree | ed398e54a04bf75e3f26845e7aacb72452a10627 /Lib/multifile.py | |
parent | 8b6323d3ef78042118c08703f26cb2adf741ea2e (diff) | |
download | cpython-54f22ed30bab2e64909ba2d79205cb4b87c69db2.zip cpython-54f22ed30bab2e64909ba2d79205cb4b87c69db2.tar.gz cpython-54f22ed30bab2e64909ba2d79205cb4b87c69db2.tar.bz2 |
More trivial comment -> docstring transformations by Ka-Ping Yee,
who writes:
Here is batch 2, as a big collection of CVS context diffs.
Along with moving comments into docstrings, i've added a
couple of missing docstrings and attempted to make sure more
module docstrings begin with a one-line summary.
I did not add docstrings to the methods in profile.py for
fear of upsetting any careful optimizations there, though
i did move class documentation into class docstrings.
The convention i'm using is to leave credits/version/copyright
type of stuff in # comments, and move the rest of the descriptive
stuff about module usage into module docstrings. Hope this is
okay.
Diffstat (limited to 'Lib/multifile.py')
-rw-r--r-- | Lib/multifile.py | 79 |
1 files changed, 41 insertions, 38 deletions
diff --git a/Lib/multifile.py b/Lib/multifile.py index ce84087..977b92f 100644 --- a/Lib/multifile.py +++ b/Lib/multifile.py @@ -1,28 +1,31 @@ -# A class that makes each part of a multipart message "feel" like an -# ordinary file, as long as you use fp.readline(). Allows recursive -# use, for nested multipart messages. Probably best used together -# with module mimetools. -# -# Suggested use: -# -# real_fp = open(...) -# fp = MultiFile(real_fp) -# -# "read some lines from fp" -# fp.push(separator) -# while 1: -# "read lines from fp until it returns an empty string" (A) -# if not fp.next(): break -# fp.pop() -# "read remaining lines from fp until it returns an empty string" -# -# The latter sequence may be used recursively at (A). -# It is also allowed to use multiple push()...pop() sequences. -# -# If seekable is given as 0, the class code will not do the bookeeping -# it normally attempts in order to make seeks relative to the beginning of the -# current file part. This may be useful when using MultiFile with a non- -# seekable stream object. +"""A readline()-style interface to the parts of a multipart message. + +The MultiFile class makes each part of a multipart message "feel" like +an ordinary file, as long as you use fp.readline(). Allows recursive +use, for nested multipart messages. Probably best used together +with module mimetools. + +Suggested use: + +real_fp = open(...) +fp = MultiFile(real_fp) + +"read some lines from fp" +fp.push(separator) +while 1: + "read lines from fp until it returns an empty string" (A) + if not fp.next(): break +fp.pop() +"read remaining lines from fp until it returns an empty string" + +The latter sequence may be used recursively at (A). +It is also allowed to use multiple push()...pop() sequences. + +If seekable is given as 0, the class code will not do the bookeeping +it normally attempts in order to make seeks relative to the beginning of the +current file part. This may be useful when using MultiFile with a non- +seekable stream object. +""" import sys import string @@ -30,9 +33,9 @@ import string Error = 'multifile.Error' class MultiFile: - # + seekable = 0 - # + def __init__(self, fp, seekable=1): self.fp = fp self.stack = [] # Grows down @@ -42,12 +45,12 @@ class MultiFile: self.seekable = 1 self.start = self.fp.tell() self.posstack = [] # Grows down - # + def tell(self): if self.level > 0: return self.lastpos return self.fp.tell() - self.start - # + def seek(self, pos, whence=0): here = self.tell() if whence: @@ -64,7 +67,7 @@ class MultiFile: self.fp.seek(pos + self.start) self.level = 0 self.last = 0 - # + def readline(self): if self.level > 0: return '' @@ -105,7 +108,7 @@ class MultiFile: if self.level > 1: raise Error,'Missing endmarker in MultiFile.readline()' return '' - # + def readlines(self): list = [] while 1: @@ -113,10 +116,10 @@ class MultiFile: if not line: break list.append(line) return list - # + def read(self): # Note: no size argument -- read until EOF only! return string.joinfields(self.readlines(), '') - # + def next(self): while self.readline(): pass if self.level > 1 or self.last: @@ -126,7 +129,7 @@ class MultiFile: if self.seekable: self.start = self.fp.tell() return 1 - # + def push(self, sep): if self.level > 0: raise Error, 'bad MultiFile.push() call' @@ -134,7 +137,7 @@ class MultiFile: if self.seekable: self.posstack.insert(0, self.start) self.start = self.fp.tell() - # + def pop(self): if self.stack == []: raise Error, 'bad MultiFile.pop() call' @@ -149,12 +152,12 @@ class MultiFile: del self.posstack[0] if self.level > 0: self.lastpos = abslastpos - self.start - # + def is_data(self, line): return line[:2] <> '--' - # + def section_divider(self, str): return "--" + str - # + def end_marker(self, str): return "--" + str + "--" |