cryptography-docs.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. from __future__ import absolute_import, division, print_function
  5. from docutils import nodes
  6. from sphinx.util.compat import Directive, make_admonition
  7. DANGER_MESSAGE = """
  8. This is a "Hazardous Materials" module. You should **ONLY** use it if you're
  9. 100% absolutely sure that you know what you're doing because this module is
  10. full of land mines, dragons, and dinosaurs with laser guns.
  11. """
  12. DANGER_ALTERNATE = """
  13. You may instead be interested in :doc:`{alternate}`.
  14. """
  15. class HazmatDirective(Directive):
  16. has_content = True
  17. def run(self):
  18. message = DANGER_MESSAGE
  19. if self.content:
  20. message += DANGER_ALTERNATE.format(alternate=self.content[0])
  21. ad = make_admonition(
  22. Hazmat,
  23. self.name,
  24. [],
  25. self.options,
  26. nodes.paragraph("", message),
  27. self.lineno,
  28. self.content_offset,
  29. self.block_text,
  30. self.state,
  31. self.state_machine
  32. )
  33. ad[0].line = self.lineno
  34. return ad
  35. class Hazmat(nodes.Admonition, nodes.Element):
  36. pass
  37. def html_visit_hazmat_node(self, node):
  38. return self.visit_admonition(node, "danger")
  39. def latex_visit_hazmat_node(self, node):
  40. return self.visit_admonition(node)
  41. def depart_hazmat_node(self, node):
  42. return self.depart_admonition(node)
  43. def setup(app):
  44. app.add_node(
  45. Hazmat,
  46. html=(html_visit_hazmat_node, depart_hazmat_node),
  47. latex=(latex_visit_hazmat_node, depart_hazmat_node),
  48. )
  49. app.add_directive("hazmat", HazmatDirective)