def rm(self, aliases, force=False): ur = Uri(self.dburi, self.db) aliases = uniq(aliases) for a in aliases: if not ur.exist_uri(a) and not force: raise Error (ENOREC, a) for a in aliases: try: ur.rm_uri(a, force=force) except Error, inst: warning(str(inst))
def add(self, uri, aliases, force=False): do = Domain(self.dburi, self.db) ur = Uri(self.dburi, self.db) us = User(self.dburi, self.db) try: uid = ur.get_uid(uri) except: if force: return raise try: user, did = ur.uri2id(uri) except: if force: return raise if not us.exist(uid): if force: return raise Error (ENOUSER, user) aliases = uniq(aliases) try: n = aliases.index(uri) aliases = aliases[:n] + aliases[n+1:] except: pass for a in aliases: if ur.exist_uri(a) and not force: raise Error (EDUPL, a) u, d = split_sip_uri(a) if not do.exist_domain(d) and not force: raise Error (ENODOMAIN, d) for a in aliases: try: ur.add(uid, a, force=force) except Error, inst: warning(str(inst))