Project

General

Profile

1 2359 aaronmk
# Objects
2
3 4492 aaronmk
import strings
4 2362 aaronmk
import util
5
6 2359 aaronmk
class BasicObject:
7
    '''Provides default implementations of commonly-used methods'''
8
9 4492 aaronmk
    def __str__(self): return util.class_name(self)+strings.urepr(self.__dict__)
10 2359 aaronmk
11 4491 aaronmk
    def __repr__(self): return self.__str__()
12 2362 aaronmk
13
    def __eq__(self, other):
14
        return (other != None and other.__class__ == self.__class__
15 2700 aaronmk
            and other._compare_on() == self._compare_on())
16 2362 aaronmk
17 2700 aaronmk
    def __hash__(self): return hash(tuple(self._compare_on().iteritems()))
18
19
    def _compare_on(self): return self.__dict__