Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ test:
testone:
cd test && python test.py -- -knownfailure

.PHONY: testwarn
testwarn:
cd test && python -Wd test.py -- -knownfailure

.PHONY: testredos
testredos:
python test/test_redos.py
Expand Down
11 changes: 4 additions & 7 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
__author__ = "Trent Mick"

import argparse
import codecs
import logging
import re
import sys
Expand Down Expand Up @@ -179,9 +178,8 @@ def markdown_path(
footnote_return_symbol: Optional[str] = None,
use_file_vars: bool = False
) -> 'UnicodeWithAttrs':
fp = codecs.open(path, 'r', encoding)
text = fp.read()
fp.close()
with open(path, 'r', encoding=encoding) as f:
text = f.read()
return Markdown(html4tags=html4tags, tab_width=tab_width,
safe_mode=safe_mode, extras=extras,
link_patterns=link_patterns,
Expand Down Expand Up @@ -4766,9 +4764,8 @@ def main(argv=None):
if path == '-':
text = sys.stdin.read()
else:
fp = codecs.open(path, 'r', opts.encoding)
text = fp.read()
fp.close()
with open(path, 'r', encoding=opts.encoding) as f:
text = f.read()
if opts.compare:
from subprocess import PIPE, Popen
print("==== Markdown.pl ====")
Expand Down
31 changes: 14 additions & 17 deletions perf/gen_perf_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from glob import glob
import operator
import shutil
import codecs


TMP = "tmp-"
Expand All @@ -16,16 +15,16 @@ def gen_aspn_cases(limit=0):
base_dir = TMP+'aspn-cases'
if exists(base_dir):
print("'%s' exists, skipping" % base_dir)
return
return
os.makedirs(base_dir)
sys.stdout.write("generate %s" % base_dir); sys.stdout.flush()
recipes_path = expanduser("~/as/code.as.com/db/aspn/recipes.pprint")
recipe_dicts = eval(open(recipes_path).read())
with open(recipes_path) as f:
recipe_dicts = eval(f.read())
for i, r in enumerate(recipe_dicts):
sys.stdout.write('.'); sys.stdout.flush()
f = codecs.open(join(base_dir, "r%04d.text" % i), "w", "utf-8")
f.write(r["desc"])
f.close()
with open(join(base_dir, "r%04d.text" % i), "w", encoding="utf-8") as f:
f.write(r["desc"])

for j, c in enumerate(sorted(r["comments"],
key=operator.itemgetter("pub_date"))):
Expand All @@ -36,10 +35,8 @@ def gen_aspn_cases(limit=0):
headline += '.'
headline = _markdown_from_aspn_html(headline).strip()
text = "**" + headline + "** " + text
f = codecs.open(join(base_dir, "r%04dc%02d.text" % (i, j)),
'w', "utf-8")
f.write(text)
f.close()
with open(join(base_dir, "r%04dc%02d.text" % (i, j)), 'w', encoding="utf-8") as f:
f.write(text)

if limit and i >= limit:
break
Expand All @@ -49,7 +46,7 @@ def gen_test_cases():
base_dir = TMP+"test-cases"
if exists(base_dir):
print("'%s' exists, skipping" % base_dir)
return
return
os.makedirs(base_dir)
print("generate %s" % base_dir)
for test_cases_dir in glob(join("..", "test", "*-cases")):
Expand Down Expand Up @@ -106,10 +103,10 @@ def _markdown_from_aspn_html(html):
if title is None:
replacement = '[{}]({})'.format(content, escaped_href)
else:
replacement = '[{}]({} "{}")'.format(content, escaped_href,
replacement = '[{}]({} "{}")'.format(content, escaped_href,
title.replace('"', "'"))
markdown = markdown[:start] + replacement + markdown[end:]

markdown = markdown.replace(" ", ' ')

# <pre> part 1: Pull out <pre>-blocks and put in placeholders
Expand Down Expand Up @@ -179,18 +176,18 @@ def _markdown_from_aspn_html(html):
# Recipe: dedent (0.1.2)
def _dedentlines(lines, tabsize=8, skip_first_line=False):
"""_dedentlines(lines, tabsize=8, skip_first_line=False) -> dedented lines

"lines" is a list of lines to dedent.
"tabsize" is the tab width to use for indent width calculations.
"skip_first_line" is a boolean indicating if the first line should
be skipped for calculating the indent width and for dedenting.
This is sometimes useful for docstrings and similar.

Same as dedent() except operates on a sequence of lines. Note: the
lines list is modified **in-place**.
"""
DEBUG = False
if DEBUG:
if DEBUG:
print("dedent: dedent(..., tabsize=%d, skip_first_line=%r)"\
% (tabsize, skip_first_line))
indents = []
Expand Down Expand Up @@ -255,7 +252,7 @@ def _dedent(text, tabsize=8, skip_first_line=False):
"skip_first_line" is a boolean indicating if the first line should
be skipped for calculating the indent width and for dedenting.
This is sometimes useful for docstrings and similar.

textwrap.dedent(s), but don't expand tabs to spaces
"""
lines = text.splitlines(1)
Expand Down
3 changes: 2 additions & 1 deletion perf/strip_cookbook_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

def doit():
recipes_path = expanduser("recipes.pprint")
recipe_dicts = eval(open(recipes_path).read())
with open(recipes_path) as f:
recipe_dicts = eval(f.read())
for r in recipe_dicts:
for key in r.keys():
if key not in ('desc', 'comments'):
Expand Down
Loading
Loading