docs.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import xml.etree.ElementTree as ET
  2. class Doc():
  3. def __init__(self, tree):
  4. self.tree = tree
  5. def get_tree(self):
  6. """Get this Doc's tree.
  7. Returns:
  8. The xml.etree.ElementTree object of the documentation.
  9. """
  10. return self.tree
  11. def __eq__(self, other):
  12. if other is None or other.get_tree() is None:
  13. return None
  14. return ET.tostring(self.tree.getroot()) == \
  15. ET.tostring(other.get_tree().getroot())
  16. class ClassDoc(Doc):
  17. pass
  18. class FreeDoc(Doc):
  19. pass
  20. class Docs():
  21. def __init__(self, class_docs, free_docs):
  22. # These are dicts that map file_path -> Doc
  23. self.class_docs = class_docs
  24. self.free_docs = free_docs
  25. def get_class_docs(self, class_name):
  26. '''Get the documentation for the class.
  27. Arguments:
  28. class_name -- the name of the class
  29. Returns:
  30. The ClassDoc with the class's documentation. None if the class does not
  31. exist.
  32. '''
  33. return self.class_docs.get(class_name)
  34. def get_free_docs(self, free_func_name):
  35. '''Get the documentation for a free function.
  36. Arguments:
  37. free_func_name -- the name of the free function
  38. Returns:
  39. The FreeDoc with the free function's documentation. None if the class
  40. does not exist.
  41. '''
  42. return self.free_docs.get(free_func_name)
  43. def get_class_docs_keys_list(self):
  44. return list(self.class_docs)
  45. def get_free_docs_keys_list(self):
  46. return list(self.free_docs)
  47. def get_class_docs_values_list(self):
  48. return list(self.class_docs.values())
  49. def get_free_docs_values_list(self):
  50. return list(self.free_docs.values())