Skip to content

Commit d8317c9

Browse files
committed
Delete unnecessary slashfix functions
1 parent e1bd0fc commit d8317c9

File tree

4 files changed

+15
-27
lines changed

4 files changed

+15
-27
lines changed

common.py

-10
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,6 @@ def askyesno(question, default=True):
122122
print("Please type y, n or nothing at all.")
123123

124124

125-
def slashfix(path):
126-
"""Replace / with os.sep."""
127-
return path.replace('/', os.sep)
128-
129-
130-
def slashfix_open(file, mode):
131-
"""An easy way to use slashfix() and open() together."""
132-
return open(slashfix(file), mode)
133-
134-
135125
@contextlib.contextmanager
136126
def backup(filename):
137127
"""A context manager that backs up a file."""

linkcheck.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,17 @@ def check(this_file, target, title, titledict):
5959

6060
path = posixpath.join(posixpath.dirname(this_file), target)
6161
path = posixpath.normpath(path)
62-
real_path = common.slashfix(path)
6362

64-
if not os.path.exists(real_path):
63+
if not os.path.exists(path):
6564
return "doesn't exist"
6665

6766
if target.endswith('/'):
6867
# A directory.
69-
if not os.path.isdir(real_path):
68+
if not os.path.isdir(path):
7069
return "not a directory"
7170
else:
7271
# A file.
73-
if not os.path.isfile(real_path):
72+
if not os.path.isfile(path):
7473
return "not a file"
7574

7675
if title is not None and title not in titledict[path]:
@@ -82,7 +81,7 @@ def find_titles(filename):
8281
"""Read titles of a markdown file and return a list of them."""
8382
result = []
8483

85-
with common.slashfix_open(filename, 'r') as f:
84+
with open(filename, 'r') as f:
8685
for line in f:
8786
if line.startswith('```'):
8887
# it's a code block, let's skip to the end of it to
@@ -103,7 +102,7 @@ def find_links(this_file):
103102
"""
104103
result = []
105104

106-
with common.slashfix_open(this_file, 'r') as f:
105+
with open(this_file, 'r') as f:
107106
for match, lineno in common.find_links(f):
108107
target = match.group(2)
109108
if '#' in target:
@@ -122,7 +121,7 @@ def find_links(this_file):
122121

123122
def get_line(filename, lineno):
124123
"""Return the lineno'th line of a file."""
125-
with common.slashfix_open(filename, 'r') as f:
124+
with open(filename, 'r') as f:
126125
for lineno2, line in enumerate(f, start=1):
127126
if lineno == lineno2:
128127
return line

make-html.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ class TutorialStyle(pygments.style.Style):
9292
"""
9393

9494

95-
def mkdir_slashfix_open(filename, mode):
96-
"""Like common.slashfix_open(), but make directories as needed."""
97-
real_filename = common.slashfix(filename)
98-
directory = os.path.dirname(real_filename)
95+
def mkdir_and_open(filename, mode):
96+
"""Like open(), but make directories as needed."""
97+
directory = os.path.dirname(filename)
9998
os.makedirs(directory, exist_ok=True)
100-
return open(real_filename, mode)
99+
return open(filename, mode)
101100

102101

103102
def fix_filename(filename):
@@ -252,7 +251,7 @@ def main():
252251
htmlfile = posixpath.join(args.outdir, fixed_file)
253252
print(' %-30.30s --> %-30.30s' % (markdownfile, htmlfile), end='\r')
254253

255-
with common.slashfix_open(markdownfile, 'r') as f:
254+
with open(markdownfile, 'r') as f:
256255
markdown = f.read()
257256
renderer = TutorialRenderer(args.pygments_style)
258257
body = mistune.markdown(markdown, renderer=renderer)
@@ -264,7 +263,7 @@ def main():
264263
body=body,
265264
stylefile=stylefile,
266265
)
267-
with mkdir_slashfix_open(htmlfile, 'w') as f:
266+
with mkdir_and_open(htmlfile, 'w') as f:
268267
print(html, file=f)
269268
print()
270269

update-ends.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def update_end(filename, end):
8585
separator.
8686
"""
8787
end = '\n***\n\n' + end
88-
with common.slashfix_open(filename, 'r') as f:
88+
with open(filename, 'r') as f:
8989
content = f.read()
9090
if content.endswith(end):
9191
# No need to do anything.
@@ -96,11 +96,11 @@ def update_end(filename, end):
9696
# We need to remove the old ending first.
9797
print(" Removing old end:", filename)
9898
where = content.index('\n***\n')
99-
with common.slashfix_open(filename, 'w') as f:
99+
with open(filename, 'w') as f:
100100
f.write(content[:where])
101101

102102
print(" Adding end:", filename)
103-
with common.slashfix_open(filename, 'a') as f:
103+
with open(filename, 'a') as f:
104104
f.write(end)
105105

106106

0 commit comments

Comments
 (0)