cryptography-docs.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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
  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. content = nodes.paragraph("", message)
  22. admonition_node = Hazmat("\n".join(content))
  23. self.state.nested_parse(content, self.content_offset, admonition_node)
  24. admonition_node.line = self.lineno
  25. return [admonition_node]
  26. class Hazmat(nodes.Admonition, nodes.Element):
  27. pass
  28. def html_visit_hazmat_node(self, node):
  29. return self.visit_admonition(node, "danger")
  30. def latex_visit_hazmat_node(self, node):
  31. return self.visit_admonition(node)
  32. def depart_hazmat_node(self, node):
  33. return self.depart_admonition(node)
  34. def setup(app):
  35. app.add_node(
  36. Hazmat,
  37. html=(html_visit_hazmat_node, depart_hazmat_node),
  38. latex=(latex_visit_hazmat_node, depart_hazmat_node),
  39. )
  40. app.add_directive("hazmat", HazmatDirective)
  41. return {
  42. "parallel_read_safe": True,
  43. }