@@ -34,36 +34,8 @@ def convert_pep0():
3434 """
3535 pep0_path = os .path .join (settings .PEP_REPO_PATH , 'pep-0000.html' )
3636 pep0_content = open (pep0_path ).read ()
37-
38- soup = BeautifulSoup (pep0_content , 'lxml' )
39-
40- body_children = list (soup .body .children )
41-
42- # Grab header and PEP body
43- header = body_children [3 ]
44- pep_content = body_children [7 ]
45-
46- # Fix PEP links
47- body_links = pep_content .find_all ("a" )
48-
49- pep_href_re = re .compile (r'pep-(\d+)\.html' )
50-
51- for b in body_links :
52- m = pep_href_re .search (b .attrs ['href' ])
53-
54- # Skip anything not matching 'pep-XXXX.html'
55- if not m :
56- continue
57-
58- b .attrs ['href' ] = '/dev/peps/pep-{}/' .format (m .group (1 ))
59-
60- # Remove Version from header
61- header_rows = header .find_all ('th' )
62- for t in header_rows :
63- if 'Version:' in t .text and 'N/A' in t .next_sibling .text :
64- t .parent .extract ()
65-
66- return '' .join ([str (header ), str (pep_content )])
37+ data = convert_pep_page (0 , pep0_content )
38+ return data ['content' ]
6739
6840
6941def get_pep0_page (commit = True ):
@@ -180,16 +152,6 @@ def convert_pep_page(pep_number, content):
180152 pep_content .body .unwrap ()
181153
182154 data ['content' ] = str (pep_content )
183-
184- pep_ext = '.txt'
185- pep_rst_source = os .path .join (settings .PEP_REPO_PATH ,
186- 'pep-{}.rst' .format (pep_number ))
187- if os .path .exists (pep_rst_source ):
188- pep_ext = '.rst'
189-
190- source_link = 'https://github.com/python/peps/blob/master/pep-{}{}' .format (
191- pep_number , pep_ext )
192- data ['content' ] += """Source: <a href="{0}">{0}</a>""" .format (source_link )
193155 return data
194156
195157
@@ -204,6 +166,13 @@ def get_pep_page(pep_number, commit=True):
204166 return
205167
206168 pep_content = convert_pep_page (pep_number , open (pep_path ).read ())
169+ pep_rst_source = os .path .join (
170+ settings .PEP_REPO_PATH , 'pep-{}.rst' .format (pep_number ),
171+ )
172+ pep_ext = '.rst' if os .path .exists (pep_rst_source ) else '.txt'
173+ source_link = 'https://github.com/python/peps/blob/master/pep-{}{}' .format (
174+ pep_number , pep_ext )
175+ pep_content ['content' ] += """Source: <a href="{0}">{0}</a>""" .format (source_link )
207176
208177 pep_page , _ = Page .objects .get_or_create (path = pep_url (pep_number ))
209178
0 commit comments