Fix nested safearray contexts

Prior to this the `safearray_as_ndarray` context manager did not work properly when nested with itself. This fixes that issue and adds pep8 cleanup to the touched files.