def METHOD_NAME(p, data):
    while len(data):
        sent = p.send(data)
        if sent is None:
            raise Exception(message)
        try:
            data = buffer(data, sent)
        except NameError:
            # in Python 3, buffer is (sort of) replaced by memoryview
            data = memoryview(data[sent:].encode())