From e28fb326a30556d76b4878516a1fa3b849ee4cde Mon Sep 17 00:00:00 2001
From: Adam Turner <9087854+aa-turner@users.noreply.github.com>
Date: Wed, 2 Mar 2022 01:06:07 +0000
Subject: [PATCH] PRS: Remove text/plain, upload, and browse logic from
pep2html.py
---
pep2html.py | 452 +---------------------------------------------------
1 file changed, 7 insertions(+), 445 deletions(-)
diff --git a/pep2html.py b/pep2html.py
index ba0ec100ba9..9997c79ef08 100755
--- a/pep2html.py
+++ b/pep2html.py
@@ -5,26 +5,6 @@
Options:
--u, --user
- python.org username
-
--b, --browse
- After generating the HTML, direct your web browser to view it
- (using the Python webbrowser module). If both -i and -b are
- given, this will browse the on-line HTML; otherwise it will
- browse the local HTML. If no pep arguments are given, this
- will browse PEP 0.
-
--i, --install
- After generating the HTML, install it and the plaintext source file
- (.txt) on python.org. In that case the user's name is used in the scp
- and ssh commands, unless "-u username" is given (in which case, it is
- used instead). Without -i, -u is ignored.
-
--l, --local
- Same as -i/--install, except install on the local machine. Use this
- when logged in to the python.org machine (dinsdale).
-
-q, --quiet
Turn off verbose messages.
@@ -34,22 +14,15 @@
The optional arguments ``peps`` are either pep numbers, .rst or .txt files.
"""
-from __future__ import print_function, unicode_literals
-
import sys
import os
import re
import glob
import getopt
import errno
-import random
import time
from io import open
from pathlib import Path
-try:
- from html import escape
-except ImportError:
- from cgi import escape
from docutils import core, nodes, utils
from docutils.readers import standalone
@@ -60,41 +33,9 @@
class DataError(Exception):
pass
-REQUIRES = {'python': '2.6',
- 'docutils': '0.2.7'}
PROGRAM = sys.argv[0]
-RFCURL = 'http://www.faqs.org/rfcs/rfc%d.html'
-PEPURL = 'pep-%04d.html'
PEPCVSURL = ('https://hg.python.org/peps/file/tip/pep-%04d.txt')
-PEPDIRRUL = 'http://www.python.org/peps/'
-
-
-HOST = "dinsdale.python.org" # host for update
-HDIR = "/data/ftp.python.org/pub/www.python.org/peps" # target host directory
-LOCALVARS = "Local Variables:"
-
-COMMENT = """"""
-
-# The generated HTML doesn't validate -- you cannot use
and
inside
-#
tags. But if I change that, the result doesn't look very nice...
-DTD = ('')
-fixpat = re.compile(r"((https?|ftp):[-_a-zA-Z0-9/.+~:?#$=&,]+)|(pep-\d+(.txt|.rst)?)|"
- r"(RFC[- ]?(?P\d+))|"
- r"(PEP\s+(?P\d+))|"
- r".")
-
-EMPTYSTRING = ''
-SPACE = ' '
-COMMASPACE = ', '
-
-
-
def usage(code, msg=''):
"""Print usage message and exit. Uses stderr if code != 0."""
if code == 0:
@@ -106,222 +47,6 @@ def usage(code, msg=''):
print(msg, file=out)
sys.exit(code)
-
-
-def fixanchor(current, match):
- text = match.group(0)
- link = None
- if (text.startswith('http:') or text.startswith('https:')
- or text.startswith('ftp:')):
- # Strip off trailing punctuation. Pattern taken from faqwiz.
- ltext = list(text)
- while ltext:
- c = ltext.pop()
- if c not in '''();:,.?'"<>''':
- ltext.append(c)
- break
- link = EMPTYSTRING.join(ltext)
- elif text.startswith('pep-') and text != current:
- link = os.path.splitext(text)[0] + ".html"
- elif text.startswith('PEP'):
- pepnum = int(match.group('pepnum'))
- link = PEPURL % pepnum
- elif text.startswith('RFC'):
- rfcnum = int(match.group('rfcnum'))
- link = RFCURL % rfcnum
- if link:
- return '%s' % (escape(link), escape(text))
- return escape(match.group(0)) # really slow, but it works...
-
-
-
-NON_MASKED_EMAILS = [
- 'peps@python.org',
- 'python-list@python.org',
- 'python-dev@python.org',
- ]
-
-def fixemail(address, pepno):
- if address.lower() in NON_MASKED_EMAILS:
- # return hyperlinked version of email address
- return linkemail(address, pepno)
- else:
- # return masked version of email address
- parts = address.split('@', 1)
- return '%s at %s' % (parts[0], parts[1])
-
-
-def linkemail(address, pepno):
- parts = address.split('@', 1)
- return (''
- '%s at %s'
- % (parts[0], parts[1], pepno, parts[0], parts[1]))
-
-
-def fixfile(inpath, input_lines, outfile):
- try:
- from email.Utils import parseaddr
- except ImportError:
- from email.utils import parseaddr
- basename = os.path.basename(inpath)
- infile = iter(input_lines)
- # convert plaintext pep to minimal XHTML markup
- print(DTD, file=outfile)
- print('', file=outfile)
- print(COMMENT, file=outfile)
- print('', file=outfile)
- # head
- header = []
- pep = ""
- title = ""
- for line in infile:
- if not line.strip():
- break
- if line[0].strip():
- if ":" not in line:
- break
- key, value = line.split(":", 1)
- value = value.strip()
- header.append((key, value))
- else:
- # continuation line
- key, value = header[-1]
- value = value + line
- header[-1] = key, value
- if key.lower() == "title":
- title = value
- elif key.lower() == "pep":
- pep = value
- if pep:
- title = "PEP " + pep + " -- " + title
- if title:
- print(' %s' % escape(title), file=outfile)
- r = random.choice(list(range(64)))
- print((
- ' \n'
- '\n'
- '\n'
- '
', file=outfile)
- need_pre = 1
- for line in infile:
- if line[0] == '\f':
- continue
- if line.strip() == LOCALVARS:
- break
- if line[0].strip():
- if not need_pre:
- print('', file=outfile)
- print('
%s
' % line.strip(), file=outfile)
- need_pre = 1
- elif not line.strip() and need_pre:
- continue
- else:
- # PEP 0 has some special treatment
- if basename == 'pep-0000.txt':
- parts = line.split()
- if len(parts) > 1 and re.match(r'\s*\d{1,4}', parts[1]):
- # This is a PEP summary line, which we need to hyperlink
- url = PEPURL % int(parts[1])
- if need_pre:
- print('
', file=outfile)
- need_pre = 0
- print(re.sub(
- parts[1],
- '%s' % (url, parts[1]),
- line, 1), end='', file=outfile)
- continue
- elif parts and '@' in parts[-1]:
- # This is a pep email address line, so filter it.
- url = fixemail(parts[-1], pep)
- if need_pre:
- print('