Mercurial > hgrepos > Python > apps > py-cutils
diff cutils/util/__init__.py @ 124:3bd3f32b5e60
A first version of "treesum" is working
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 02 Jan 2025 13:29:20 +0100 |
| parents | a548783381b6 |
| children | fa7dd54e9715 |
line wrap: on
line diff
--- a/cutils/util/__init__.py Thu Jan 02 12:43:40 2025 +0100 +++ b/cutils/util/__init__.py Thu Jan 02 13:29:20 2025 +0100 @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # :- -# :Copyright: (c) 2020-2024 Franz Glasner +# :Copyright: (c) 2020-2025 Franz Glasner # :License: BSD-3-Clause # :- r"""Utility package. @@ -18,6 +18,7 @@ import argparse import hashlib +import os def get_blake2b(): @@ -143,8 +144,25 @@ def normalize_filename(filename, strip_leading_dot_slash=False): - filename = filename.replace("\\", "/") - if strip_leading_dot_slash: - while filename.startswith("./"): - filename = filename[2:] + if isinstance(filename, bytes): + filename = filename.replace(b"\\", b"/") + if strip_leading_dot_slash: + while filename.startswith(b"./"): + filename = filename[2:] + else: + filename = filename.replace("\\", "/") + if strip_leading_dot_slash: + while filename.startswith("./"): + filename = filename[2:] return filename + + +def fsencode(what): + """A somewhat compatibility function for :func:`os.fsencode`. + + If `what` is of type :class:`bytes` no :func:`os.fsencode` is required. + + """ + if isinstance(what, bytes): + return what + return os.fsencode(what)
