def delMsg(id, topic, what, param, hard): if topic == None and param != None: topic = param param = None if not topic: topic = default_topic stdoutln(id, topic, what, param, hard) enum_what = None before = None seq_list = None user = None if what == 'msg': enum_what = pb.ClientDel.MSG if param == 'all': seq_list = [pb.DelQuery(range=pb.SeqRange(low=1, hi=0x8FFFFFF))] elif param != None: seq_list = [ pb.DelQuery(seq_id=int(x.strip())) for x in param.split(',') ] stdoutln(seq_list) elif what == 'sub': enum_what = pb.ClientDel.SUB user = param elif what == 'topic': enum_what = pb.ClientDel.TOPIC # Field named 'del' conflicts with the keyword 'del. This is a work around. msg = pb.ClientMsg(on_behalf_of=default_user) xdel = getattr(msg, 'del') """ setattr(msg, 'del', pb.ClientDel(id=str(id), topic=topic, what=enum_what, hard=hard, del_seq=seq_list, user_id=user)) """ xdel.id = str(id) xdel.topic = topic xdel.what = enum_what if hard != None: xdel.hard = hard if seq_list != None: xdel.del_seq.extend(seq_list) if user != None: xdel.user_id = user return msg
def delMsg(id, cmd, ignored): if not cmd.what: stdoutln("Must specify what to delete") return None cmd.topic = cmd.topic if cmd.topic else DefaultTopic cmd.user = cmd.user if cmd.user else DefaultUser enum_what = None before = None seq_list = None if cmd.what == 'msg': if not cmd.topic: stdoutln("Must specify topic to delete messages") return None enum_what = pb.ClientDel.MSG cmd.user = None if cmd.msglist == 'all': seq_list = [pb.DelQuery(range=pb.SeqRange(low=1, hi=0x8FFFFFF))] elif cmd.msglist != None: seq_list = [ pb.DelQuery(seq_id=int(x.strip())) for x in cmd.msglist.split(',') ] elif cmd.what == 'sub': if not cmd.user or not cmd.topic: stdoutln("Must specify topic and user to delete subscription") return None enum_what = pb.ClientDel.SUB elif cmd.what == 'topic': if not cmd.topic: stdoutln("Must specify topic to delete") return None enum_what = pb.ClientDel.TOPIC cmd.user = None elif cmd.what == 'user': enum_what = pb.ClientDel.USER cmd.topic = None else: stdoutln("Unrecognized delete option '", cmd.what, "'") return None msg = pb.ClientMsg(on_behalf_of=DefaultUser) # Field named 'del' conflicts with the keyword 'del. This is a work around. xdel = getattr(msg, 'del') """ setattr(msg, 'del', pb.ClientDel(id=str(id), topic=topic, what=enum_what, hard=hard, del_seq=seq_list, user_id=user)) """ xdel.id = str(id) xdel.what = enum_what if cmd.hard != None: xdel.hard = cmd.hard if seq_list != None: xdel.del_seq.extend(seq_list) if cmd.user != None: xdel.user_id = cmd.user if cmd.topic != None: xdel.topic = cmd.topic return msg