Replace framework module exceptions with asserts

In the future, deployment to Google App Engine will be changed to strip
out these assert statements, allowing code to be deployed that skips
programmer error-related checks in production.