def test_section_RFC822(self): errata = [{"doc-id": "RFC0822"}] doc = apply_errata(errata, None, None) doc.loadDocument("Tests/RFC822.txt") doc.sectionDocument() expectedSections = [ "header", "table of contents", "1", "1.1", "1.2", "2", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8", "3", "3.1", "3.1.1", "3.1.2", "3.1.3", "3.1.4", "3.2", "3.3", "3.4", "3.4.1", "3.4.2", "3.4.3", "3.4.4", "3.4.5", "3.4.6", "3.4.7", "3.4.8", "3.4.9", "3.4.10", "4", "4.1", "4.2", "4.3", "4.3.1", "4.3.2", "4.4", "4.4.1", "4.4.2", "4.4.3", "4.4.4", "4.5", "4.5.1", "4.5.2", "4.5.3", "4.6", "4.6.1", "4.6.2", "4.6.3", "4.6.4", "4.7", "4.7.1", "4.7.2", "4.7.3", "4.7.4", "4.7.5", "5", "5.1", "5.2", "6", "6.1", "6.2", "6.2.1", "6.2.2", "6.2.3", "6.2.4", "6.2.5", "6.2.6", "6.2.7", "6.3", "7", "a", "a.1", "a.1.1", "a.1.2", "a.1.3", "a.1.4", "a.1.5", "a.2", "a.2.1", "a.2.2", "a.2.3", "a.2.4", "a.2.5", "a.2.6", "a.2.7", "a.3", "a.3.1", "a.3.2", "a.3.3", "b", "b.1", "b.2", "c", "c.1", "c.1.1", "c.2", "c.2.1", "c.2.2", "c.2.3", "c.2.4", "c.3", "c.3.1", "c.3.2", "c.3.3", "c.3.4", "c.3.5", "c.3.6", "c.3.7", "c.3.8", "c.4", "c.4.1", "c.5", "c.5.1", "c.5.2", "c.5.3", "c.5.4", "c.5.5", "c.5.6", "c.6", "d" ] self.assertSequenceEqual(doc.allSections, expectedSections)
def test_section_RFC1122(self): errata = [{"doc-id": "RFC1122"}] doc = apply_errata(errata, None, None) doc.loadDocument("Tests/RFC1122.txt") doc.sectionDocument() # self.maxDiff = None expectedSections = [ "header", "status of this memo", "table of contents", "1", "1.1", "1.1.1", "1.1.2", "1.1.3", "1.1.4", "1.2", "1.2.1", "1.2.2", "1.2.3", "1.2.4", "1.3", "1.3.1", "1.3.2", "1.3.3", "1.4", "2", "2.1", "2.2", "2.3", "2.3.1", "2.3.2", "2.3.2.1", "2.3.2.2", "2.3.3", "2.4", "2.5", "3", "3.1", "3.2", "3.2.1", "3.2.1.1", "3.2.1.2", "3.2.1.3", "3.2.1.4", "3.2.1.5", "3.2.1.6", "3.2.1.7", "3.2.1.8", "3.2.2", "3.2.2.1", "3.2.2.2", "3.2.2.3", "3.2.2.4", "3.2.2.5", "3.2.2.6", "3.2.2.7", "3.2.2.8", "3.2.2.9", "3.2.3", "3.3", "3.3.1", "3.3.1.1", "3.3.1.2", "3.3.1.3", "3.3.1.4", "3.3.1.5", "3.3.1.6", "3.3.2", "3.3.3", "3.3.4", "3.3.4.1", "3.3.4.2", "3.3.4.3", "3.3.5", "3.3.6", "3.3.7", "3.3.8", "3.4", "3.5", "4", "4.1", "4.1.1", "4.1.2", "4.1.3", "4.1.3.1", "4.1.3.2", "4.1.3.3", "4.1.3.4", "4.1.3.5", "4.1.3.6", "4.1.4", "4.1.5", "4.2", "4.2.1", "4.2.2", "4.2.2.1", "4.2.2.2", "4.2.2.3", "4.2.2.4", "4.2.2.5", "4.2.2.6", "4.2.2.7", "4.2.2.8", "4.2.2.9", "4.2.2.10", "4.2.2.11", "4.2.2.12", "4.2.2.13", "4.2.2.14", "4.2.2.15", "4.2.2.16", "4.2.2.17", "4.2.2.18", "4.2.2.19", "4.2.2.20", "4.2.2.21", "4.2.3", "4.2.3.1", "4.2.3.2", "4.2.3.3", "4.2.3.4", "4.2.3.5", "4.2.3.6", "4.2.3.7", "4.2.3.8", "4.2.3.9", "4.2.3.10", "4.2.3.11", "4.2.3.12", "4.2.4", "4.2.4.1", "4.2.4.2", "4.2.4.3", "4.2.4.4", "4.2.5", "5", "security considerations", "author's address" ] self.assertSequenceEqual(doc.allSections, expectedSections)
def test_section_RFC854(self): errata = [{"doc-id": "RFC0854"}] doc = apply_errata(errata, None, None) doc.loadDocument("Tests/RFC854.txt") doc.sectionDocument() expectedSections = ["header"] self.assertSequenceEqual(doc.allSections, expectedSections)
def test_section_RFC4543(self): errata = [{"doc-id": "RFC4543"}] doc = apply_errata(errata, None, None) doc.loadDocument("Tests/RFC4543.txt") doc.sectionDocument() self.maxDiff = None expectedSections = [ "header", "status of this memo", "copyright notice", "abstract", "table of contents", "1", "1.1", "2", "3", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "4", "5", "5.1", "5.2", "5.3", "5.4", "6", "7", "8", "9", "10", "11", "11.1", "11.2", "authors' addresses", "full copyright statement" ] self.assertSequenceEqual(doc.allSections, expectedSections)
def test_section_RFC1322(self): errata = [{"doc-id": "RFC1322"}] doc = apply_errata(errata, None, None) doc.loadDocument("Tests/RFC1322.txt") doc.sectionDocument() # self.maxDiff = None expectedSections = [ "header", "status of this memo", "abstract", "1", "1.1", "1.2", "2", "2.1", "2.1.1", "2.1.2", "2.1.3", "2.2", "2.3", "2.3.1", "2.3.2", "2.4", "2.5", "2.6", "3", "3.1", "3.2", "3.2.1", "3.3", "3.3.1", "3.3.2", "3.3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "4", "4.1", "4.2", "4.2.1", "4.2.2", "4.3", "5", "5.1", "5.2", "6", "7", "8", "security considerations", "authors' addresses" ] self.assertSequenceEqual(doc.allSections, expectedSections)
def test_section_RFC793(self): errata = [{"doc-id": "RFC0793"}] doc = apply_errata(errata, None, None) doc.loadDocument("Tests/RFC793.txt") preDoc = "".join(doc.source) doc.sectionDocument() expectedSections = [ "header", "table of contents", "1.1", "1.2", "1.3", "1.4", "1.5", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8", "2.9", "2.10", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9" ] self.assertSequenceEqual(doc.allSections, expectedSections) doc.unsectionDocument() postDoc = "".join(doc.source, ) self.assertEqual(preDoc, postDoc)
def test_errata(self): with open("Tests/quote1.json", encoding='utf-8') as f: errata = json.load(f) if not os.path.exists("Temp"): os.mkdir("Temp") state = {"text": "./Tests", "html": "./Temp", "ossPath": "css"} options = Values(defaults={'search': False}) doc = apply_errata(errata, options, state) templates = Templates( os.path.join(os.path.dirname(__file__), "Template")) doc.apply(True, templates) self.assertEqual(doc.InlineCount, 0) self.assertEqual(doc.SectionCount, 1) self.assertEqual(doc.EndnoteCount, 0) self.assertTrue( compare_file("./Temp/RFC8275.html", "./Results/quote1.html", True))
def processRFC(self, rfc, force, templates): if rfc not in self.byRfc: print("{0} does not have any current errata".format(rfc)) return 0 try: txt_file = os.path.join(self.state["text"], "{0}.txt".format(rfc)) if not os.path.isfile(txt_file): retries = 3 while retries: try: if not self.connection: self.connection = HTTPSConnection( self.state["serverName"]) # print("RFC = {0}".format(rfc)) rfcNum = int(rfc[3:]) self.connection.request( 'GET', '/rfc/rfc{0}.txt'.format(rfcNum).lower()) res = self.connection.getresponse() with open(txt_file, "wb") as f: f.write(res.read()) retries = 0 except HTTPException as e: if retries: if self.options.verbose: print( "Close and reopen connection because '{0}'" .format(e)) self.connection.close() self.connection = None retries -= 1 else: errText = "Error '{1}' downloading 'errata.json' from '{0}'".format( self.state["serverName"], e) if self.options.verbose: print(errText) with open("errors.log", "a") as f: f.write(datetime.datetime.now().isoformat() + ": " + errText) return 1 x = apply_errata(self.byRfc[rfc], self.options, self.state) x.apply(force, templates) self.inlineCount += x.InlineCount self.sectionCount += x.SectionCount self.endnoteCount += x.EndnoteCount if x.EndnoteCount + x.SectionCount > 0 and self.options.verbose: print("{0} {1} {2} {3}".format(rfc, x.InlineCount, x.SectionCount, x.EndnoteCount)) if rfc not in Reported: for item in x.toApply: if not item["section2"] in IgnoreSections: print(" {0} --> {1}".format( item["section"], item["section2"])) if "dest" in self.state and (x.InlineCount > 0 or x.SectionCount > 0 or x.EndnoteCount > 0): htmlFile = rfc + ".html" htmlSource = os.path.join(self.state["html"], htmlFile) for dest in self.state["dest"]: shutil.copyfile(htmlSource, os.path.join(dest, htmlFile)) except Exception as e: if self.options.verbose: print("Error processing {0}. {1}\n".format(rfc, e)) with open("errors.log", "a") as f: f.write(datetime.datetime.now().isoformat() + ": Error processing {0}. {1}\n".format(rfc, e)) return 1 return 0