You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ee726c2
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/pages/howto.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,12 @@ Whatever solution is chosen, the following arguments shall be considered:
25
25
26
26
-`ename` (first positional argument): Choose the shortest possible encoding name. If it clashes with another codec, always remember that `codext` resolves codecs in order of registry, that is from the first added. Also, it resolves codecs based on the given pattern. So, a codec with a clashing name could still be selected if the pattern does not match for the codec with the precedence but matches for this codec.
27
27
-`pattern` (keyword-argument): If not defined, it defaults to the encoding name. It can be a regular expression ; in this case, it should not be too broad. A codec decode or encode function can be parametrized through the pattern using the **first capture group**. It is important to note that the first capture group is used and not any other. This means that any other group definition shall use the do-not-capture specifier, that is "`(?:...)`".
28
+
- `plain` and `encoded` (keyword-arguments): These tell the kind of the plain side (what is encoded) and of the encoded side of the codec: "`bytes`" for data, handled byte for byte, or "`text`" for characters. They decide how a `bytes` input is passed to the encode and decode functions and how their output is turned back into `bytes`: a "`bytes`" side is passed byte for byte (as a `str` of the characters 0 to 255, which [`b`](https://github.com/dhondta/python-codext/blob/main/src/codext/utils.py) turns back into the same bytes), while a "`text`" side is read from UTF-8 (or Latin-1 if not valid UTF-8) and written in UTF-8. If both sides are "`text`" and the input is not valid UTF-8, the output is written in Latin-1 (e.g. `rot13` turns `b"caf\xe9"` into `b"pns\xe9"`). By default, the plain side holds bytes for the `base`, `binary`, `checksum`, `compression` and `hashing` categories, and the encoded side for the `binary` and `compression` ones (and for barcodes, except their `-text` variants) ; both hold text otherwise. Each can also be a function giving the kind from the encoding name.
29
+
30
+
!!! note "Bytes or text ?"
31
+
32
+
A codec that works on the bytes of its input (e.g. a base encoding, a compression or a cipher on bytes) has a "`bytes`" plain side, so that any data is recovered exactly, including bytes that happen to be valid UTF-8 ; a codec that works on characters (e.g. a substitution of letters, a case conversion or a codec encoding the code points of the characters) has a "`text`" plain side, so that a UTF-8 text given as `bytes` gives the same result as the same text given as a `str`. The tests in `tests/test_bytes.py` check these properties for every codec.
0 commit comments