I've implemented some context managers here:
Note the legacy module prefix.
Also, be aware that using multiple context managers in a single with statement will result in undesired behavior due to the order that python unwinds them.
Ie:
with matrix_mode( GL_PROJECTION ), matrix( projmatrix ):
pass
Python unwinds in the same order it set (go figure), so the following will occur:
matrix mode begins unknown
matrix mode push - matrix mode now projection
matrix push - matrix added to projection matrix stack
matrix mode pop - projection mode popped from matrix mode, matrix mode unknown
matrix pop - matrix popped from unknown matrix stack
Cheers,
Adam