import optparse
from random import random, randint
import codecs
-from urllib import quote
+from urllib.parse import quote
try:
import uuid
except ImportError:
- SECRET_SALT = str(randint(0, 1000000))
+ SECRET_SALT = str(randint(0, 1000000)).encode('utf-8')
else:
- SECRET_SALT = str(uuid.uuid4())
+ SECRET_SALT = str(uuid.uuid4()).encode('utf-8')
def _hash_ascii(s):
#return md5(s).hexdigest() # Markdown.pl effectively does this.
- return 'md5-' + md5(SECRET_SALT + s).hexdigest()
+ return 'md5-' + md5(SECRET_SALT + s.encode("utf-8")).hexdigest()
def _hash_text(s):
return 'md5-' + md5(SECRET_SALT + s.encode("utf-8")).hexdigest()
# articles):
self.reset()
- if not isinstance(text, unicode):
+ if not isinstance(text, str):
#TODO: perhaps shouldn't presume UTF-8 for string input?
- text = unicode(text, 'utf-8')
+ text = text.decode('utf-8')
if self.use_file_vars:
# Look for emacs-style file variable hints.
# Delimiters for next comment block.
try:
start_idx = text.index("<!--", start)
- except ValueError, ex:
+ except ValueError as ex:
break
try:
end_idx = text.index("-->", start_idx) + 3
- except ValueError, ex:
+ except ValueError as ex:
break
# Start position for next comment block search.
#---- internal support functions
-class UnicodeWithAttrs(unicode):
+class UnicodeWithAttrs(str):
"""A subclass of unicode used for the return value of conversion to
possibly attach some attributes. E.g. the "toc_html" attribute when
the "toc" extra is used.
"""
DEBUG = False
if DEBUG:
- print "dedent: dedent(..., tabsize=%d, skip_first_line=%r)"\
- % (tabsize, skip_first_line)
+ print(f"dedent: dedent(..., tabsize={tabsize}, skip_first_line={skip_first_line})")
indents = []
margin = None
for i, line in enumerate(lines):
break
else:
continue # skip all-whitespace lines
- if DEBUG: print "dedent: indent=%d: %r" % (indent, line)
+ if DEBUG: print(f"dedent: indent={indent}: {line}")
if margin is None:
margin = indent
else:
margin = min(margin, indent)
- if DEBUG: print "dedent: margin=%r" % margin
+ if DEBUG: print(f"dedent: margin={margin}")
if margin is not None and margin > 0:
for i, line in enumerate(lines):
elif ch == '\t':
removed += tabsize - (removed % tabsize)
elif ch in '\r\n':
- if DEBUG: print "dedent: %r: EOL -> strip up to EOL" % line
+ if DEBUG: print("dedent: {line}: EOL -> strip up to EOL")
lines[i] = lines[i][j:]
break
else:
"line %r while removing %d-space margin"
% (ch, line, margin))
if DEBUG:
- print "dedent: %r: %r -> removed %d/%d"\
- % (line, ch, removed, margin)
+ print(f"dedent: {line}: {ch} -> removed {removed}/{margin}")
if removed == margin:
lines[i] = lines[i][j+1:]
break
"Markdown.pl")
for path in paths:
if opts.compare:
- print "==== Markdown.pl ===="
+ print("==== Markdown.pl ====")
perl_cmd = 'perl %s "%s"' % (markdown_pl, path)
o = os.popen(perl_cmd)
perl_html = o.read()
o.close()
sys.stdout.write(perl_html)
- print "==== markdown2.py ===="
+ print("==== markdown2.py ====")
html = markdown_path(path, encoding=opts.encoding,
html4tags=opts.html4tags,
safe_mode=opts.safe_mode,
else:
norm_html = html
norm_perl_html = perl_html
- print "==== match? %r ====" % (norm_perl_html == norm_html)
+ did_match = (norm_perl_html == norm_html)
+ print(f"==== match? {did_match} ====")
if __name__ == "__main__":