Skip to content

Commit 997f7f5

Browse files
authored
Replacing os.path.sep with os.sep in loader (#1698)
1 parent 7f936de commit 997f7f5

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/jinja2/loaders.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def split_template_path(template: str) -> t.List[str]:
2828
pieces = []
2929
for piece in template.split("/"):
3030
if (
31-
os.path.sep in piece
31+
os.sep in piece
3232
or (os.path.altsep and os.path.altsep in piece)
3333
or piece == os.path.pardir
3434
):
@@ -225,8 +225,8 @@ def list_templates(self) -> t.List[str]:
225225
for filename in filenames:
226226
template = (
227227
os.path.join(dirpath, filename)[len(searchpath) :]
228-
.strip(os.path.sep)
229-
.replace(os.path.sep, "/")
228+
.strip(os.sep)
229+
.replace(os.sep, "/")
230230
)
231231
if template[:2] == "./":
232232
template = template[2:]
@@ -274,12 +274,12 @@ def __init__(
274274
package_path: "str" = "templates",
275275
encoding: str = "utf-8",
276276
) -> None:
277-
package_path = os.path.normpath(package_path).rstrip(os.path.sep)
277+
package_path = os.path.normpath(package_path).rstrip(os.sep)
278278

279279
# normpath preserves ".", which isn't valid in zip paths.
280280
if package_path == os.path.curdir:
281281
package_path = ""
282-
elif package_path[:2] == os.path.curdir + os.path.sep:
282+
elif package_path[:2] == os.path.curdir + os.sep:
283283
package_path = package_path[2:]
284284

285285
self.package_path = package_path
@@ -300,7 +300,7 @@ def __init__(
300300
if isinstance(loader, zipimport.zipimporter):
301301
self._archive = loader.archive
302302
pkgdir = next(iter(spec.submodule_search_locations)) # type: ignore
303-
template_root = os.path.join(pkgdir, package_path).rstrip(os.path.sep)
303+
template_root = os.path.join(pkgdir, package_path).rstrip(os.sep)
304304
else:
305305
roots: t.List[str] = []
306306

@@ -373,9 +373,9 @@ def list_templates(self) -> t.List[str]:
373373
offset = len(self._template_root)
374374

375375
for dirpath, _, filenames in os.walk(self._template_root):
376-
dirpath = dirpath[offset:].lstrip(os.path.sep)
376+
dirpath = dirpath[offset:].lstrip(os.sep)
377377
results.extend(
378-
os.path.join(dirpath, name).replace(os.path.sep, "/")
378+
os.path.join(dirpath, name).replace(os.sep, "/")
379379
for name in filenames
380380
)
381381
else:
@@ -386,16 +386,13 @@ def list_templates(self) -> t.List[str]:
386386
)
387387

388388
# Package is a zip file.
389-
prefix = (
390-
self._template_root[len(self._archive) :].lstrip(os.path.sep)
391-
+ os.path.sep
392-
)
389+
prefix = self._template_root[len(self._archive) :].lstrip(os.sep) + os.sep
393390
offset = len(prefix)
394391

395392
for name in self._loader._files.keys(): # type: ignore
396393
# Find names under the templates directory that aren't directories.
397-
if name.startswith(prefix) and name[-1] != os.path.sep:
398-
results.append(name[offset:].replace(os.path.sep, "/"))
394+
if name.startswith(prefix) and name[-1] != os.sep:
395+
results.append(name[offset:].replace(os.sep, "/"))
399396

400397
results.sort()
401398
return results

0 commit comments

Comments
 (0)