Implement rich comparison using @total_ordering (2.7+, 3.2+)

This commit is contained in:
Martin Panter 2014-01-18 01:43:01 +00:00
parent 5143df8561
commit a6fd013a77

View File

@ -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):