Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/util/__init__.py @ 376:54a6d4534ef4
Convert some further value checks from plain Python assertions into real checks
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 05 May 2025 13:04:49 +0200 |
| parents | bfe1160fbfd3 |
| children | 6d7659a709f2 |
comparison
equal
deleted
inserted
replaced
| 375:7044c2900890 | 376:54a6d4534ef4 |
|---|---|
| 391 return formatstr % values | 391 return formatstr % values |
| 392 # Workaround with a Latin-1 dance | 392 # Workaround with a Latin-1 dance |
| 393 tformatstr = formatstr.decode("latin1") | 393 tformatstr = formatstr.decode("latin1") |
| 394 tvalues = [] | 394 tvalues = [] |
| 395 for v in values: | 395 for v in values: |
| 396 # Do not automatically convert text (unicode) string values into bytes. | |
| 396 if PY2: | 397 if PY2: |
| 397 if isinstance(v, unicode): # noqa: F821 undefined name 'unicode' | 398 if isinstance(v, unicode): # noqa: F821 undefined name 'unicode' |
| 398 assert False | 399 raise TypeError( |
| 400 "unicode values not supported when interpolating" | |
| 401 " into bytes") | |
| 399 else: | 402 else: |
| 400 if isinstance(v, str): | 403 if isinstance(v, str): |
| 401 assert False | 404 raise TypeError( |
| 405 "unicode (native string) values not supported when" | |
| 406 " interpolating into bytes") | |
| 402 if isinstance(v, bytes): | 407 if isinstance(v, bytes): |
| 403 tvalues.append(v.decode("latin1")) | 408 tvalues.append(v.decode("latin1")) |
| 404 else: | 409 else: |
| 405 tvalues.append(v) | 410 tvalues.append(v) |
| 406 return (tformatstr % tuple(tvalues)).encode("latin1") | 411 return (tformatstr % tuple(tvalues)).encode("latin1") |
