Delete unnecessary slashfix functions · alchemistphantom/python-tutorial@d8317c9 · GitHub
Skip to content

Commit d8317c9

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

4 files changed

Lines changed: 15 additions & 27 deletions

File tree

‎common.py‎

Lines changed: 0 additions & 10 deletions

‎linkcheck.py‎

Lines changed: 6 additions & 7 deletions
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‎

Lines changed: 6 additions & 7 deletions
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‎

Lines changed: 3 additions & 3 deletions

0 commit comments

Comments
 (0)