def extract_bibliographic(self, field_list): docinfo = nodes.docinfo() bibliofields = self.language.bibliographic_fields labels = self.language.labels topics = {"dedication": None, "abstract": None} for field in field_list: try: name = field[0][0].astext() normedname = nodes.fully_normalize_name(name) if not ( len(field) == 2 and normedname in bibliofields and self.check_empty_biblio_field(field, name) ): raise TransformError canonical = bibliofields[normedname] biblioclass = self.biblio_nodes[canonical] if issubclass(biblioclass, nodes.TextElement): if not self.check_compound_biblio_field(field, name): raise TransformError utils.clean_rcs_keywords( field[1][0], self.rcs_keyword_substitutions ) docinfo.append(biblioclass("", "", *field[1][0])) elif issubclass(biblioclass, nodes.authors): self.extract_authors(field, name, docinfo) elif issubclass(biblioclass, nodes.topic): if topics[canonical]: field[-1] += self.document.reporter.warning( 'There can only be one "%s" field.' % name, base_node=field ) raise TransformError title = nodes.title(name, labels[canonical]) title[0].rawsource = labels[canonical] topics[canonical] = biblioclass( "", title, classes=[canonical], *field[1].children ) else: docinfo.append(biblioclass("", *field[1].children)) except TransformError: if len(field[-1]) == 1 and isinstance(field[-1][0], nodes.paragraph): utils.clean_rcs_keywords( field[-1][0], self.rcs_keyword_substitutions ) # if normedname not in bibliofields: classvalue = nodes.make_id(normedname) if classvalue: field["classes"].append(classvalue) docinfo.append(field) nodelist = [] if len(docinfo) != 0: nodelist.append(docinfo) for name in ("dedication", "abstract"): if topics[name]: nodelist.append(topics[name]) return nodelist
def extract_bibliographic(self, field_list): docinfo = nodes.docinfo() bibliofields = self.language.bibliographic_fields labels = self.language.labels topics = {'dedication': None, 'abstract': None} for field in field_list: try: name = field[0][0].astext() normedname = nodes.fully_normalize_name(name) if not (len(field) == 2 and normedname in bibliofields and self.check_empty_biblio_field(field, name)): raise TransformError canonical = bibliofields[normedname] biblioclass = self.biblio_nodes[canonical] if issubclass(biblioclass, nodes.TextElement): if not self.check_compound_biblio_field(field, name): raise TransformError utils.clean_rcs_keywords( field[1][0], self.rcs_keyword_substitutions) docinfo.append(biblioclass('', '', *field[1][0])) elif issubclass(biblioclass, nodes.authors): self.extract_authors(field, name, docinfo) elif issubclass(biblioclass, nodes.topic): if topics[canonical]: field[-1] += self.document.reporter.warning( 'There can only be one "%s" field.' % name, base_node=field) raise TransformError title = nodes.title(name, labels[canonical]) topics[canonical] = biblioclass( '', title, classes=[canonical], *field[1].children) else: docinfo.append(biblioclass('', *field[1].children)) except TransformError: if len(field[-1]) == 1 \ and isinstance(field[-1][0], nodes.paragraph): utils.clean_rcs_keywords( field[-1][0], self.rcs_keyword_substitutions) if normedname not in bibliofields: classvalue = nodes.make_id(normedname) if classvalue: field['classes'].append(classvalue) docinfo.append(field) nodelist = [] if len(docinfo) != 0: nodelist.append(docinfo) for name in ('dedication', 'abstract'): if topics[name]: nodelist.append(topics[name]) return nodelist
def extract_bibliographic(self, field_list): docinfo = nodes.docinfo() bibliofields = self.language.bibliographic_fields labels = self.language.labels topics = {'dedication': None, 'abstract': None} for field in field_list: try: name = field[0][0].astext() normedname = nodes.fully_normalize_name(name) if not (len(field) == 2 and bibliofields.has_key(normedname) and self.check_empty_biblio_field(field, name)): raise TransformError canonical = bibliofields[normedname] biblioclass = self.biblio_nodes[canonical] if issubclass(biblioclass, nodes.TextElement): if not self.check_compound_biblio_field(field, name): raise TransformError utils.clean_rcs_keywords(field[1][0], self.rcs_keyword_substitutions) docinfo.append(biblioclass('', '', *field[1][0])) elif issubclass(biblioclass, nodes.authors): self.extract_authors(field, name, docinfo) elif issubclass(biblioclass, nodes.topic): if topics[canonical]: field[-1] += self.document.reporter.warning( 'There can only be one "%s" field.' % name, base_node=field) raise TransformError title = nodes.title(name, labels[canonical]) topics[canonical] = biblioclass('', title, CLASS=canonical, *field[1].children) else: docinfo.append(biblioclass('', *field[1].children)) except TransformError: if len(field[-1]) == 1 \ and isinstance(field[-1][0], nodes.paragraph): utils.clean_rcs_keywords(field[-1][0], self.rcs_keyword_substitutions) docinfo.append(field) nodelist = [] if len(docinfo) != 0: nodelist.append(docinfo) for name in ('dedication', 'abstract'): if topics[name]: nodelist.append(topics[name]) return nodelist
def apply(self): if not len(self.document): # @@@ replace these DataErrors with proper system messages raise DataError('Document tree is empty.') header = self.document[0] if not isinstance(header, nodes.field_list) or \ 'rfc2822' not in header['classes']: raise DataError('Document does not begin with an RFC-2822 ' 'header; it is not a PEP.') pep = None for field in header: if field[0].astext().lower() == 'pep': # should be the first field value = field[1].astext() try: pep = int(value) cvs_url = self.pep_cvs_url % pep except ValueError: pep = value cvs_url = None msg = self.document.reporter.warning( '"PEP" header must contain an integer; "%s" is an ' 'invalid value.' % pep, base_node=field) msgid = self.document.set_id(msg) prb = nodes.problematic(value, value or '(none)', refid=msgid) prbid = self.document.set_id(prb) msg.add_backref(prbid) if len(field[1]): field[1][0][:] = [prb] else: field[1] += nodes.paragraph('', '', prb) break if pep is None: raise DataError('Document does not contain an RFC-2822 "PEP" ' 'header.') if pep == 0: # Special processing for PEP 0. pending = nodes.pending(peps.PEPZero) self.document.insert(1, pending) self.document.note_pending(pending) if len(header) < 2 or header[1][0].astext().lower() != 'title': raise DataError('No title!') for field in header: name = field[0].astext().lower() body = field[1] if len(body) > 1: raise DataError('PEP header field body contains multiple ' 'elements:\n%s' % field.pformat(level=1)) elif len(body) == 1: if not isinstance(body[0], nodes.paragraph): raise DataError('PEP header field body may only contain ' 'a single paragraph:\n%s' % field.pformat(level=1)) elif name == 'last-modified': date = time.strftime( '%d-%b-%Y', time.localtime(os.stat(self.document['source'])[8])) if cvs_url: body += nodes.paragraph( '', '', nodes.reference('', date, refuri=cvs_url)) else: # empty continue para = body[0] if name in ('author', 'bdfl-delegate', 'sponsor'): for node in para: if isinstance(node, nodes.reference): node.replace_self(peps.mask_email(node)) elif name == 'discussions-to': for node in para: if isinstance(node, nodes.reference): node.replace_self(peps.mask_email(node, pep)) elif name in ('replaces', 'superseded-by', 'requires'): newbody = [] space = nodes.Text(' ') for refpep in re.split(r',?\s+', body.astext()): pepno = int(refpep) newbody.append(nodes.reference( refpep, refpep, refuri=(self.document.settings.pep_base_url + self.pep_url % pepno))) newbody.append(space) para[:] = newbody[:-1] # drop trailing space elif name == 'last-modified': utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions) if cvs_url: date = para.astext() para[:] = [nodes.reference('', date, refuri=cvs_url)] elif name == 'content-type': pep_type = para.astext() uri = self.document.settings.pep_base_url + self.pep_url % 12 para[:] = [nodes.reference('', pep_type, refuri=uri)] elif name == 'version' and len(body): utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)
def apply(self): if not len(self.document): # @@@ replace these DataErrors with proper system messages raise DataError("Document tree is empty.") header = self.document[0] if ( not isinstance(header, nodes.field_list) or "rfc2822" not in header["classes"] ): raise DataError( "Document does not begin with an RFC-2822 " "header; it is not a PEP." ) pep = None for field in header: if field[0].astext().lower() == "pep": # should be the first field value = field[1].astext() try: pep = int(value) cvs_url = self.pep_cvs_url % pep except ValueError: pep = value cvs_url = None msg = self.document.reporter.warning( '"PEP" header must contain an integer; "%s" is an ' "invalid value." % pep, base_node=field, ) msgid = self.document.set_id(msg) prb = nodes.problematic(value, value or "(none)", refid=msgid) prbid = self.document.set_id(prb) msg.add_backref(prbid) if len(field[1]): field[1][0][:] = [prb] else: field[1] += nodes.paragraph("", "", prb) break if pep is None: raise DataError('Document does not contain an RFC-2822 "PEP" ' "header.") if pep == 0: # Special processing for PEP 0. pending = nodes.pending(PEPZero) self.document.insert(1, pending) self.document.note_pending(pending) if len(header) < 2 or header[1][0].astext().lower() != "title": raise DataError("No title!") for field in header: name = field[0].astext().lower() body = field[1] if len(body) > 1: raise DataError( "PEP header field body contains multiple " "elements:\n%s" % field.pformat(level=1) ) elif len(body) == 1: if not isinstance(body[0], nodes.paragraph): raise DataError( "PEP header field body may only contain " "a single paragraph:\n%s" % field.pformat(level=1) ) elif name == "last-modified": date = time.strftime( "%d-%b-%Y", time.localtime(os.stat(self.document["source"])[8]) ) if cvs_url: body += nodes.paragraph( "", "", nodes.reference("", date, refuri=cvs_url) ) else: # empty continue para = body[0] if name == "author": for node in para: if isinstance(node, nodes.reference): node.replace_self(mask_email(node)) elif name == "discussions-to": for node in para: if isinstance(node, nodes.reference): node.replace_self(mask_email(node, pep)) elif name in ("replaces", "replaced-by", "requires"): newbody = [] space = nodes.Text(" ") for refpep in re.split(r",?\s+", body.astext()): pepno = int(refpep) newbody.append( nodes.reference( refpep, refpep, refuri=( self.document.settings.pep_base_url + self.pep_url % pepno ), ) ) newbody.append(space) para[:] = newbody[:-1] # drop trailing space elif name == "last-modified": utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions) if cvs_url: date = para.astext() para[:] = [nodes.reference("", date, refuri=cvs_url)] elif name == "content-type": pep_type = para.astext() uri = self.document.settings.pep_base_url + self.pep_url % 12 para[:] = [nodes.reference("", pep_type, refuri=uri)] elif name == "version" and len(body): utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)
def apply(self): if not len(self.document): # @@@ replace these DataErrors with proper system messages raise DataError("Document tree is empty.") header = self.document[0] if not isinstance(header, nodes.field_list) or "rfc2822" not in header["classes"]: raise DataError("Document does not begin with an RFC-2822 " "header; it is not a PEP.") pep = None for field in header: if field[0].astext().lower() == "pep": # should be the first field value = field[1].astext() try: pep = int(value) cvs_url = self.pep_cvs_url % pep except ValueError: pep = value cvs_url = None msg = self.document.reporter.warning( '"PEP" header must contain an integer; "%s" is an ' "invalid value." % pep, base_node=field ) msgid = self.document.set_id(msg) prb = nodes.problematic(value, value or "(none)", refid=msgid) prbid = self.document.set_id(prb) msg.add_backref(prbid) if len(field[1]): field[1][0][:] = [prb] else: field[1] += nodes.paragraph("", "", prb) break if pep is None: raise DataError('Document does not contain an RFC-2822 "PEP" ' "header.") if pep == 0: # Special processing for PEP 0. pending = nodes.pending(PEPZero) self.document.insert(1, pending) self.document.note_pending(pending) if len(header) < 2 or header[1][0].astext().lower() != "title": raise DataError("No title!") for field in header: name = field[0].astext().lower() body = field[1] if len(body) > 1: raise DataError("PEP header field body contains multiple " "elements:\n%s" % field.pformat(level=1)) elif len(body) == 1: if not isinstance(body[0], nodes.paragraph): raise DataError( "PEP header field body may only contain " "a single paragraph:\n%s" % field.pformat(level=1) ) elif name == "last-modified": date = time.strftime("%d-%b-%Y", time.localtime(os.stat(self.document["source"])[8])) if cvs_url: body += nodes.paragraph("", "", nodes.reference("", date, refuri=cvs_url)) else: # empty continue para = body[0] if name == "author": for node in para: if isinstance(node, nodes.reference): node.parent.replace(node, mask_email(node)) elif name == "discussions-to": for node in para: if isinstance(node, nodes.reference): node.parent.replace(node, mask_email(node, pep)) elif name in ("replaces", "replaced-by", "requires"): newbody = [] space = nodes.Text(" ") for refpep in re.split(",?\s+", body.astext()): pepno = int(refpep) newbody.append( nodes.reference( refpep, refpep, refuri=(self.document.settings.pep_base_url + self.pep_url % pepno) ) ) newbody.append(space) para[:] = newbody[:-1] # drop trailing space elif name == "last-modified": utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions) if cvs_url: date = para.astext() para[:] = [nodes.reference("", date, refuri=cvs_url)] elif name == "content-type": pep_type = para.astext() uri = self.document.settings.pep_base_url + self.pep_url % 12 para[:] = [nodes.reference("", pep_type, refuri=uri)] elif name == "version" and len(body): utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)