Cbridge: major merge of changes since 2011

I don't think I made any mistakes, the conflict were minimal, mostly relating to the transition to Python3.

@ATenderholt: could you just check if the cbridge code is intact?