def __init__(self, name, default=NoDefault, doc=None, get_cperm=1, set_cperm='manager', get_func=None, set_func=None, conv_func=None, get_conv_func=None, update_func=None): self.name = name self.default = default self.doc = doc self.get_cperm = translate_cperm(get_cperm) self.set_cperm = translate_cperm(set_cperm) self.get_func = get_func self.set_func = set_func self.conv_func = conv_func self.get_conv_func = get_conv_func self.update_func = update_func
def find_object(self, obj_name): """find an object in the modules and return it takes the object pathname (as in 'module.command' or just 'command') and returns the python object, along with its perm_object. """ parts = obj_name.split('.') # only return public objects (nothing that starts with '_') for p in parts: if not p or p[0] == '_': return (None, None) if len(parts) == 1: data = self._find_module(parts[0]) if not data[0]: data = self._find_obj_in_module_path(parts[0]) elif len(parts) == 2: data = self._find_obj_in_module(*parts) else: self.bot.log(5, 'OBJECT NAME too many chunks: %s' % obj_name) data = (None, None, None, None) obj, cperm, cperm_parent, cperm_name = data if not obj: return (None, None) elif cperm == NoPerm: return (obj, None) elif isinstance(cperm, CPerm): return (obj, cperm) else: new_cperm = translate_cperm(cperm) setattr(cperm_parent, cperm_name, new_cperm) self.bot.log(6, 'translating %s to %s' % (cperm, new_cperm)) return (obj, new_cperm)