Skip to content
Myr

Replacing os.path.sep with os.sep in loader (#1698)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tilman Klaeger · committed by GitHub · parent 7f936de · Browse files · 1 file+11 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+11 added−14 removed

  • other:+11 added−14 removed

1 file+11 added−14 removed

modified:src/jinja2/loaders.py+11 added-14 removed
26 unmodified lines
27 """28 pieces = []29 for piece in template.split("/"):30 if (31 os.path.sep in piece31 os.sep in piece32 or (os.path.altsep and os.path.altsep in piece)33 or piece == os.path.pardir34 ):35 raise TemplateNotFound(template)
188 unmodified lines
224 for dirpath, _, filenames in walk_dir:225 for filename in filenames:226 template = (227 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, "/")230 )231 if template[:2] == "./":232 template = template[2:]233 if template not in found:
39 unmodified lines
273 package_name: str,274 package_path: "str" = "templates",275 encoding: str = "utf-8",276 ) -> None:277 package_path = os.path.normpath(package_path).rstrip(os.path.sep)277 package_path = os.path.normpath(package_path).rstrip(os.sep)278279 # normpath preserves ".", which isn't valid in zip paths.280 if package_path == os.path.curdir:281 package_path = ""282 elif package_path[:2] == os.path.curdir + os.path.sep:282 elif package_path[:2] == os.path.curdir + os.sep:283 package_path = package_path[2:]284285 self.package_path = package_path286 self.package_name = package_name
12 unmodified lines
299300 if isinstance(loader, zipimport.zipimporter):301 self._archive = loader.archive302 pkgdir = next(iter(spec.submodule_search_locations)) # type: ignore303 template_root = os.path.join(pkgdir, package_path).rstrip(os.path.sep)303 template_root = os.path.join(pkgdir, package_path).rstrip(os.sep)304 else:305 roots: t.List[str] = []306307 # One element for regular packages, multiple for namespace
64 unmodified lines
372 # Package is a directory.373 offset = len(self._template_root)374375 for dirpath, _, filenames in os.walk(self._template_root):376 dirpath = dirpath[offset:].lstrip(os.path.sep)376 dirpath = dirpath[offset:].lstrip(os.sep)377 results.extend(378 os.path.join(dirpath, name).replace(os.path.sep, "/")378 os.path.join(dirpath, name).replace(os.sep, "/")379 for name in filenames380 )381 else:382 if not hasattr(self._loader, "_files"):
2 unmodified lines
385 " metadata to list templates."386 )387388 # Package is a zip file.389 prefix = (390 self._template_root[len(self._archive) :].lstrip(os.path.sep)391 + os.path.sep392 )389 prefix = self._template_root[len(self._archive) :].lstrip(os.sep) + os.sep390 offset = len(prefix)391392 for name in self._loader._files.keys(): # type: ignore393 # 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, "/"))396397 results.sort()398 return results399
259 unmodified lines