Mercurial > hgrepos > Python > apps > py-cutils
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 123:4a0c3c9eead7 | 124:3bd3f32b5e60 |
|---|---|
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 # :- | 2 # :- |
| 3 # :Copyright: (c) 2020-2024 Franz Glasner | 3 # :Copyright: (c) 2020-2025 Franz Glasner |
| 4 # :License: BSD-3-Clause | 4 # :License: BSD-3-Clause |
| 5 # :- | 5 # :- |
| 6 r"""Utility package. | 6 r"""Utility package. |
| 7 | 7 |
| 8 """ | 8 """ |
| 16 ] | 16 ] |
| 17 | 17 |
| 18 | 18 |
| 19 import argparse | 19 import argparse |
| 20 import hashlib | 20 import hashlib |
| 21 import os | |
| 21 | 22 |
| 22 | 23 |
| 23 def get_blake2b(): | 24 def get_blake2b(): |
| 24 """Get the factory for blake2b""" | 25 """Get the factory for blake2b""" |
| 25 try: | 26 try: |
| 141 else: | 142 else: |
| 142 raise ValueError("unknown algorithm: {}".format(s)) | 143 raise ValueError("unknown algorithm: {}".format(s)) |
| 143 | 144 |
| 144 | 145 |
| 145 def normalize_filename(filename, strip_leading_dot_slash=False): | 146 def normalize_filename(filename, strip_leading_dot_slash=False): |
| 146 filename = filename.replace("\\", "/") | 147 if isinstance(filename, bytes): |
| 147 if strip_leading_dot_slash: | 148 filename = filename.replace(b"\\", b"/") |
| 148 while filename.startswith("./"): | 149 if strip_leading_dot_slash: |
| 149 filename = filename[2:] | 150 while filename.startswith(b"./"): |
| 151 filename = filename[2:] | |
| 152 else: | |
| 153 filename = filename.replace("\\", "/") | |
| 154 if strip_leading_dot_slash: | |
| 155 while filename.startswith("./"): | |
| 156 filename = filename[2:] | |
| 150 return filename | 157 return filename |
| 158 | |
| 159 | |
| 160 def fsencode(what): | |
| 161 """A somewhat compatibility function for :func:`os.fsencode`. | |
| 162 | |
| 163 If `what` is of type :class:`bytes` no :func:`os.fsencode` is required. | |
| 164 | |
| 165 """ | |
| 166 if isinstance(what, bytes): | |
| 167 return what | |
| 168 return os.fsencode(what) |
