PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/WebKit/Examples/Error.py

https://bitbucket.org/wmalinowski/webware
Python | 42 lines | 33 code | 8 blank | 1 comment | 5 complexity | e05eb8484cc78069db0e01b7433d06ff MD5 | raw file
Possible License(s): 0BSD
  1. from ExamplePage import ExamplePage
  2. class CustomError:
  3. """Custom classic class not based on Exception (for testing)."""
  4. def __init__(self, msg):
  5. self.msg = msg
  6. def __str__(self):
  7. return self.msg
  8. class Error(ExamplePage):
  9. def title(self):
  10. return 'Error raising Example'
  11. def writeContent(self):
  12. error = self.request().field('error', None)
  13. if error:
  14. msg = 'You clicked that button!'
  15. if error.startswith('String'):
  16. error = msg
  17. elif error.startswith('Custom'):
  18. error = CustomError(msg)
  19. elif error.startswith('System'):
  20. error = SystemError(msg)
  21. else:
  22. error = StandardError(msg)
  23. self.writeln('<p>About to raise an error...</p>')
  24. raise error
  25. self.writeln('''<h1>Error Test</h1>
  26. <form action="Error" method="post">
  27. <p><select name="error" size="1">
  28. <option selected>Standard Error</option>
  29. <option>System Error</option>
  30. <option>Custom Class (old)</option>
  31. <option>String (deprecated)</option>
  32. </select>
  33. <input type="submit" value="Don't click this button!"></p>
  34. </form>''')