'explicit state set from pickling'

def __setstate__(self, value):

    if isinstance(value, dict):
        oid = value['_ObjectId__id']
    else:
        oid = value
    if (PY3 and isinstance(oid, text_type)):
        self.__id = oid.encode('latin-1')
    else:
        self.__id = oid
