Merge: Add compatibility to Python 3 (and retain Python 2)
Merge branch 'py6' of https://github.com/mlell/redo * 'py6' of https://github.com/mlell/redo: Remove python<3.0 restriction in setup.py Make compatible to BeautifulSoup4 Accept octal representations of Python 2 (0nnn) and Python 3 (0onnn) Prevent iterator being changed while iterating Python 2/3 compatible treatment of max(n, None) Prevent "Exception ... ignored" in `redo-log ... | head` Distinguish byte (python2 str type) and unicode strings (python 3 str type) Set file descriptor as inheritable for all pythons >=3.4 Unify print function usage for Python 2 and 3 via __future__ import Run 2to3 utility Remove python interpreter selection
This commit is contained in:
commit
68d355178e
18 changed files with 90 additions and 49 deletions
|
|
@ -1,5 +1,11 @@
|
|||
from __future__ import print_function
|
||||
import sys, os, markdown, re
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
try:
|
||||
from BeautifulSoup import BeautifulSoup
|
||||
bsver = 3
|
||||
except ModuleNotFoundError:
|
||||
from bs4 import BeautifulSoup
|
||||
bsver = 4
|
||||
|
||||
def _split_lines(s):
|
||||
return re.findall(r'([^\n]*\n?)', s)
|
||||
|
|
@ -179,7 +185,10 @@ def do_definition(tag):
|
|||
|
||||
def do_list(tag):
|
||||
for i in tag:
|
||||
name = getattr(i, 'name', '').lower()
|
||||
name = getattr(i, 'name', '')
|
||||
# BeautifulSoup4 sometimes results in 'tag' having attributes that have
|
||||
# content 'None'
|
||||
name = name.lower() if name is not None else ''
|
||||
if not name and not str(i).strip():
|
||||
pass
|
||||
elif name != 'li':
|
||||
|
|
@ -194,7 +203,11 @@ def do_list(tag):
|
|||
|
||||
|
||||
def do(tag):
|
||||
name = getattr(tag, 'name', '').lower()
|
||||
name = getattr(tag, 'name', None)
|
||||
# BeautifulSoup4 sometimes results in 'tag' having attributes that have
|
||||
# content 'None'
|
||||
name = name.lower() if name is not None else ''
|
||||
|
||||
if not name:
|
||||
text(tag)
|
||||
elif name == 'h1':
|
||||
|
|
@ -245,7 +258,7 @@ if len(sys.argv) != 3:
|
|||
|
||||
infile = sys.argv[1]
|
||||
htmlfile = sys.argv[2]
|
||||
lines += open(infile).read().decode('utf8').split('\n')
|
||||
lines += open(infile, 'rb').read().decode('utf8').split('\n')
|
||||
|
||||
# parse pandoc-style document headers (not part of markdown)
|
||||
g = re.match(r'^%\s+(.*?)\((.*?)\)\s+(.*)$', lines[0])
|
||||
|
|
@ -273,7 +286,12 @@ if AUTHOR:
|
|||
|
||||
html = markdown.markdown(inp)
|
||||
open(htmlfile, 'w').write(html)
|
||||
soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES)
|
||||
|
||||
if(bsver == 3):
|
||||
soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES)
|
||||
elif(bsver == 4):
|
||||
soup = BeautifulSoup(html, features = "html.parser")
|
||||
else: assert 0
|
||||
|
||||
macro('.TH', PROD.upper(), SECTION, DATE, VENDOR, GROUPNAME)
|
||||
macro('.ad', 'l') # left justified
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue