From f0ebbe0bd038787f7fae041f2b8d630df68ba526 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Thu, 8 Mar 2001 22:46:41 +0000 Subject: Re-order some method descriptions for a more logical grouping. (Based on reader comment!) --- Doc/lib/libmultifile.tex | 50 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Doc/lib/libmultifile.tex b/Doc/lib/libmultifile.tex index dd90b43..2d5bcdc 100644 --- a/Doc/lib/libmultifile.tex +++ b/Doc/lib/libmultifile.tex @@ -39,19 +39,6 @@ own pattern for section-divider and end-marker lines. A \class{MultiFile} instance has the following methods: -\begin{methoddesc}{push}{str} -Push a boundary string. When an appropriately decorated version of -this boundary is found as an input line, it will be interpreted as a -section-divider or end-marker. All subsequent -reads will return the empty string to indicate end-of-file, until a -call to \method{pop()} removes the boundary a or \method{next()} call -reenables it. - -It is possible to push more than one boundary. Encountering the -most-recently-pushed boundary will return EOF; encountering any other -boundary will raise an error. -\end{methoddesc} - \begin{methoddesc}{readline}{str} Read a line. If the line is data (not a section-divider or end-marker or real EOF) return it. If the line matches the most-recently-stacked @@ -71,18 +58,6 @@ Read all lines, up to the next section. Return them as a single (multiline) string. Note that this doesn't take a size argument! \end{methoddesc} -\begin{methoddesc}{next}{} -Skip lines to the next section (that is, read lines until a -section-divider or end-marker has been consumed). Return true if -there is such a section, false if an end-marker is seen. Re-enable -the most-recently-pushed boundary. -\end{methoddesc} - -\begin{methoddesc}{pop}{} -Pop a section boundary. This boundary will no longer be interpreted -as EOF. -\end{methoddesc} - \begin{methoddesc}{seek}{pos\optional{, whence}} Seek. Seek indices are relative to the start of the current section. The \var{pos} and \var{whence} arguments are interpreted as for a file @@ -93,6 +68,13 @@ seek. Return the file position relative to the start of the current section. \end{methoddesc} +\begin{methoddesc}{next}{} +Skip lines to the next section (that is, read lines until a +section-divider or end-marker has been consumed). Return true if +there is such a section, false if an end-marker is seen. Re-enable +the most-recently-pushed boundary. +\end{methoddesc} + \begin{methoddesc}{is_data}{str} Return true if \var{str} is data and false if it might be a section boundary. As written, it tests for a prefix other than \code{'-}\code{-'} at @@ -104,6 +86,24 @@ boundary tests; if it always returns false it will merely slow processing, not cause it to fail. \end{methoddesc} +\begin{methoddesc}{push}{str} +Push a boundary string. When an appropriately decorated version of +this boundary is found as an input line, it will be interpreted as a +section-divider or end-marker. All subsequent +reads will return the empty string to indicate end-of-file, until a +call to \method{pop()} removes the boundary a or \method{next()} call +reenables it. + +It is possible to push more than one boundary. Encountering the +most-recently-pushed boundary will return EOF; encountering any other +boundary will raise an error. +\end{methoddesc} + +\begin{methoddesc}{pop}{} +Pop a section boundary. This boundary will no longer be interpreted +as EOF. +\end{methoddesc} + \begin{methoddesc}{section_divider}{str} Turn a boundary into a section-divider line. By default, this method prepends \code{'-}\code{-'} (which MIME section boundaries have) but -- cgit v0.12 id='n7' href='#n7'>7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
# tests for slice objects; in particular the indices method.

import unittest
from test import test_support

import sys

class SliceTest(unittest.TestCase):

    def test_constructor(self):
        self.assertRaises(TypeError, slice)
        self.assertRaises(TypeError, slice, 1, 2, 3, 4)

    def test_repr(self):
        self.assertEqual(repr(slice(1, 2, 3)), "slice(1, 2, 3)")

    def test_hash(self):
        # Verify clearing of SF bug #800796
        self.assertRaises(TypeError, hash, slice(5))
        self.assertRaises(TypeError, slice(5).__hash__)

    def test_cmp(self):
        s1 = slice(1, 2, 3)
        s2 = slice(1, 2, 3)
        s3 = slice(1, 2, 4)
        self.assertEqual(s1, s2)
        self.assertNotEqual(s1, s3)

        class Exc(Exception):
            pass

        class BadCmp(object):
            def __eq__(self, other):
                raise Exc

        s1 = slice(BadCmp())
        s2 = slice(BadCmp())
        self.assertRaises(Exc, cmp, s1, s2)
        self.assertEqual(s1, s1)

        s1 = slice(1, BadCmp())
        s2 = slice(1, BadCmp())
        self.assertEqual(s1, s1)
        self.assertRaises(Exc, cmp, s1, s2)

        s1 = slice(1, 2, BadCmp())
        s2 = slice(1, 2, BadCmp())
        self.assertEqual(s1, s1)
        self.assertRaises(Exc, cmp, s1, s2)

    def test_members(self):
        s = slice(1)
        self.assertEqual(s.start, None)
        self.assertEqual(s.stop, 1)
        self.assertEqual(s.step, None)

        s = slice(1, 2)
        self.assertEqual(s.start, 1)
        self.assertEqual(s.stop, 2)
        self.assertEqual(s.step, None)

        s = slice(1, 2, 3)
        self.assertEqual(s.start, 1)
        self.assertEqual(s.stop, 2)
        self.assertEqual(s.step, 3)

        class AnyClass:
            pass

        obj = AnyClass()
        s = slice(obj)
        self.assert_(s.stop is obj)

    def test_indices(self):
        self.assertEqual(slice(None           ).indices(10), (0, 10,  1))
        self.assertEqual(slice(None,  None,  2).indices(10), (0, 10,  2))
        self.assertEqual(slice(1,     None,  2).indices(10), (1, 10,  2))
        self.assertEqual(slice(None,  None, -1).indices(10), (9, -1, -1))
        self.assertEqual(slice(None,  None, -2).indices(10), (9, -1, -2))
        self.assertEqual(slice(3,     None, -2).indices(10), (3, -1, -2))
        self.assertEqual(
            slice(-100,  100     ).indices(10),
            slice(None).indices(10)
        )
        self.assertEqual(
            slice(100,  -100,  -1).indices(10),
            slice(None, None, -1).indices(10)
        )
        self.assertEqual(slice(-100L, 100L, 2L).indices(10), (0, 10,  2))

        self.assertEqual(range(10)[::sys.maxint - 1], [0])

        self.assertRaises(OverflowError, slice(None).indices, 1L<<100)

def test_main():
    test_support.run_unittest(SliceTest)

if __name__ == "__main__":
    test_main()