def __init__(self): self.contents = Contents() self.contents_stack = [self.contents] self.index = Index() self.metadata = {} self.base = None
class SpecParser(XmlParser): """DevHelp spec file parser.""" def __init__(self): self.contents = Contents() self.contents_stack = [self.contents] self.index = Index() self.metadata = {} self.base = None def translate_link(self, link): if self.base is None: return link else: return urlparse.urljoin(self.base, link) def start_book(self, name, title, link, base = None, author = None, version = None, **dummy): assert len(self.contents_stack) == 1 if base is not None: # Must be first self.base = base self.contents.name = title self.contents.link = self.translate_link(link) # Metadata self.metadata['name'] = name if version is not None: self.metadata['version'] = version if author is not None: self.metadata['author'] = author def end_book(self): assert len(self.contents_stack) == 1 def start_chapter(self, name, link, **dummy): assert len(self.contents_stack) > 0 entry = ContentsEntry(name, self.translate_link(link)) self.contents_stack[-1].append(entry) self.contents_stack.append(entry) def end_chapter(self): assert len(self.contents_stack) > 1 self.contents_stack.pop() start_sub = start_chapter end_sub = end_chapter def start_function(self, name, link, **dummy): entry = IndexEntry(name, self.translate_link(link)) self.index.append(entry)
class SpecParser(XmlParser): """DevHelp spec file parser.""" def __init__(self): self.contents = Contents() self.contents_stack = [self.contents] self.index = Index() self.metadata = {} self.base = None def translate_link(self, link): if self.base is None: return link else: return urlparse.urljoin(self.base, link) def start_book(self, name, title, link, base=None, author=None, version=None, **dummy): assert len(self.contents_stack) == 1 if base is not None: # Must be first self.base = base self.contents.name = title self.contents.link = self.translate_link(link) # Metadata self.metadata['name'] = name if version is not None: self.metadata['version'] = version if author is not None: self.metadata['author'] = author def end_book(self): assert len(self.contents_stack) == 1 def start_chapter(self, name, link, **dummy): assert len(self.contents_stack) > 0 entry = ContentsEntry(name, self.translate_link(link)) self.contents_stack[-1].append(entry) self.contents_stack.append(entry) def end_chapter(self): assert len(self.contents_stack) > 1 self.contents_stack.pop() start_sub = start_chapter end_sub = end_chapter def start_function(self, name, link, **dummy): entry = IndexEntry(name, self.translate_link(link)) self.index.append(entry)