def remove(self, val): isAtom = False if val == 'set': raise OVSExceptions.OVSValueError("scalar value can't be removed") if len(self) == 3 and self[0] == 'set': isAtom = True super(OVSSet, self).remove(val) if isAtom: self = self[1]
def commit(self, transaction): if not isinstance(transaction, Transaction): raise OVSExceptions.OVSValueError("Unexpected Transaction Value") self.sock.send(bytes(json.dumps(transaction)), 'utf-8') responses = self.get_responses(self.sock.recv(self.BUFF_SIZE)) for response in responses: res = json.loads(response) transaction.handleResult(res) self.update_notification(res) self.cur_id += 1
def append(self, atom): if not isinstance(atom, OVSAtom): raise OVSExceptions.OVSValueError("value must be an OVSAtom") if len(self) == 2 and self[0] == 'set': self = [] for val in atom: super(OVSSet, self).append(val) return elif len(self) == 2 and self[0] != 'set': tmp_atom = [self[0], self[1]] self = [] self.append('set') self.append(tmp_atom) self.append(atom) return super(OVSSet, self).append(atom)
def __init__(self, l=None): if l and len(l) > 2: raise OVSExceptions.OVSValueError( "Atom shouldn't be more than 2 fields") super(OVSAtom, self).__init__(l)
def pop(self, index): if index == 0: raise OVSExceptions.OVSValueError("scalar value can't be removed") super(OVSSet, self).pop(index)
def insert(self, index, atom): if not isinstance(atom, OVSAtom): raise OVSExceptions.OVSValueError("value must be an OVSAtom") super(OVSSet, self).insert(index, atom)