diff --git a/PIL/OleFileIO.py b/PIL/OleFileIO.py index 108a9693a..d13bcb0a9 100644 --- a/PIL/OleFileIO.py +++ b/PIL/OleFileIO.py @@ -224,6 +224,7 @@ import io import sys from PIL import _binary import struct, array, os.path, datetime +from functools import total_ordering #[PL] Define explicitly the public API to avoid private objects in pydoc: __all__ = ['OleFileIO', 'isOleFile'] @@ -706,6 +707,7 @@ class _OleStream(io.BytesIO): #--- _OleDirectoryEntry ------------------------------------------------------- +@total_ordering class _OleDirectoryEntry: """ @@ -851,7 +853,7 @@ class _OleDirectoryEntry: # in the OLE file, entries are sorted on (length, name). # for convenience, we sort them on name instead: - # (see __cmp__ method in this class) + # (see rich comparison methods in this class) self.kids.sort() @@ -899,11 +901,14 @@ class _OleDirectoryEntry: child.build_storage_tree() - def __cmp__(self, other): + def __eq__(self, other): "Compare entries by name" - return cmp(self.name, other.name) - #TODO: replace by the same function as MS implementation ? - # (order by name length first, then case-insensitive order) + return self.name == other.name + def __lt__(self, other): + "Compare entries by name" + return self.name < other.name + #TODO: replace by the same function as MS implementation ? + # (order by name length first, then case-insensitive order) def dump(self, tab = 0):