31
31
-h, --help
32
32
Print this help message and exit.
33
33
34
- The optional arguments ``peps`` are either pep numbers or .txt files.
34
+ The optional arguments ``peps`` are either pep numbers, .rst or .txt files.
35
35
"""
36
36
37
37
from __future__ import print_function , unicode_literals
38
38
39
39
import sys
40
40
import os
41
41
import re
42
- import cgi
43
42
import glob
44
43
import getopt
45
44
import errno
75
74
DTD = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"\n '
76
75
' "http://www.w3.org/TR/REC-html40/loose.dtd">' )
77
76
78
- fixpat = re .compile ("((https?|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt)?)|"
77
+ fixpat = re .compile ("((https?|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt|.rst )?)|"
79
78
"(RFC[- ]?(?P<rfcnum>\d+))|"
80
79
"(PEP\s+(?P<pepnum>\d+))|"
81
80
"." )
@@ -367,10 +366,13 @@ def get_input_lines(inpath):
367
366
368
367
369
368
def find_pep (pep_str ):
370
- """Find the .txt file indicated by a cmd line argument"""
369
+ """Find the .rst or . txt file indicated by a cmd line argument"""
371
370
if os .path .exists (pep_str ):
372
371
return pep_str
373
372
num = int (pep_str )
373
+ rstpath = "pep-%04d.rst" % num
374
+ if os .path .exists (rstpath ):
375
+ return rstpath
374
376
return "pep-%04d.txt" % num
375
377
376
378
def make_html (inpath , verbose = 0 ):
@@ -449,7 +451,7 @@ def check_requirements():
449
451
PEP_TYPE_DISPATCH ['text/x-rst' ] = None
450
452
PEP_TYPE_MESSAGES ['text/x-rst' ] = (
451
453
'Docutils not present for "%(pep_type)s" PEP file %(inpath)s. '
452
- 'See README.txt for installation.' )
454
+ 'See README.rst for installation.' )
453
455
else :
454
456
installed = [int (part ) for part in docutils .__version__ .split ('.' )]
455
457
required = [int (part ) for part in REQUIRES ['docutils' ].split ('.' )]
@@ -458,7 +460,7 @@ def check_requirements():
458
460
PEP_TYPE_MESSAGES ['text/x-rst' ] = (
459
461
'Docutils must be reinstalled for "%%(pep_type)s" PEP '
460
462
'processing (%%(inpath)s). Version %s or better required; '
461
- '%s present. See README.txt for installation.'
463
+ '%s present. See README.rst for installation.'
462
464
% (REQUIRES ['docutils' ], docutils .__version__ ))
463
465
464
466
def pep_type_error (inpath , pep_type ):
@@ -469,7 +471,7 @@ def pep_type_error(inpath, pep_type):
469
471
def browse_file (pep ):
470
472
import webbrowser
471
473
file = find_pep (pep )
472
- if file .endswith (".txt" ):
474
+ if file .startswith ( 'pep-' ) and file . endswith (( ".txt" , '.rst' ) ):
473
475
file = file [:- 3 ] + "html"
474
476
file = os .path .abspath (file )
475
477
url = "file:" + file
@@ -478,7 +480,7 @@ def browse_file(pep):
478
480
def browse_remote (pep ):
479
481
import webbrowser
480
482
file = find_pep (pep )
481
- if file .endswith (".txt" ):
483
+ if file .startswith ( 'pep-' ) and file . endswith (( ".txt" , '.rst' ) ):
482
484
file = file [:- 3 ] + "html"
483
485
url = PEPDIRRUL + file
484
486
webbrowser .open (url )
@@ -520,32 +522,32 @@ def main(argv=None):
520
522
browse = 1
521
523
522
524
if args :
523
- peptxt = []
525
+ pep_list = []
524
526
html = []
525
527
for pep in args :
526
528
file = find_pep (pep )
527
- peptxt .append (file )
529
+ pep_list .append (file )
528
530
newfile = make_html (file , verbose = verbose )
529
531
if newfile :
530
532
html .append (newfile )
531
533
if browse and not update :
532
534
browse_file (pep )
533
535
else :
534
536
# do them all
535
- peptxt = []
537
+ pep_list = []
536
538
html = []
537
- files = glob .glob ("pep-*.txt" )
539
+ files = glob .glob ("pep-*.txt" ) + glob . glob ( "pep-*.rst" )
538
540
files .sort ()
539
541
for file in files :
540
- peptxt .append (file )
542
+ pep_list .append (file )
541
543
newfile = make_html (file , verbose = verbose )
542
544
if newfile :
543
545
html .append (newfile )
544
546
if browse and not update :
545
547
browse_file ("0" )
546
548
547
549
if update :
548
- push_pep (html , peptxt , username , verbose , local = local )
550
+ push_pep (html , pep_list , username , verbose , local = local )
549
551
if browse :
550
552
if args :
551
553
for pep in args :
0 commit comments