Skip to content

Commit 4a025c5

Browse files
committed
Added module descriptions
1 parent dffcc6f commit 4a025c5

69 files changed

Lines changed: 456 additions & 24 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/codext/base/_base.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# -*- coding: UTF-8 -*-
22
"""Generic baseN functions.
33
4+
This module holds the common machinery of the base codecs: the charset selection (a charset may depend on the variant
5+
given in the codec name, e.g. "-inv" for inverted charsets), the generic base conversion and the codec factory, the
6+
generic "baseN-generic" codec (N from 2 to 255, with a generated charset) and the command-line tool factory used by the
7+
baseXX console scripts.
8+
9+
When N is not a power of 2, the whole input is converted as a single big integer written in base N (most significant
10+
digit first), each leading null byte of the input being kept as a leading first character of the charset (as Base58
11+
does).
412
"""
513
from argparse import ArgumentParser, RawTextHelpFormatter
614
from math import log

‎src/codext/base/_base2n.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- coding: UTF-8 -*-
22
"""BaseN functions with N a power of 2.
33
4+
When N is a power of 2 (2, 4, 8, 16, 32, 64, ...), each character holds a fixed number of bits (log2(N)): the input
5+
bytes are read as a stream of bits, cut into groups of that size and mapped to the charset, the last group being padded
6+
with zero bits. The output is then padded with "=" up to a whole number of quanta (the smallest number of characters
7+
holding a whole number of bytes, e.g. 4 characters for 3 bytes with Base64), as RFC 4648 does.
48
"""
59
from math import ceil, log
610

‎src/codext/base/base100.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# -*- coding: UTF-8 -*-
22
"""Base100 Codec - base100 content encoding.
33
4-
Note: only works in Python3 ; strongly inspired from https://github.com/MasterGroosha/pybase100
4+
Base100, also known as the emoji encoding, was created by Adam Niederer. Each byte is written with one of 256 emojis,
5+
from U+1F3F7 to U+1F4F6, whose UTF-8 encoding is the 4 bytes F0 9F followed by two bytes computed from the byte value
6+
(hence a fixed expansion factor of 4 in bytes, but of 1 in characters). This implementation is strongly inspired by
7+
pybase100.
58
69
This codec:
710
- en/decodes strings from str to str
811
- en/decodes strings from bytes to bytes
912
- decodes file content to str (read)
1013
- encodes file content from str to bytes (write)
14+
15+
Reference: https://github.com/AdamNiederer/base100
16+
https://github.com/MasterGroosha/pybase100
1117
"""
1218
from ._base import main
1319
from ..__common__ import *

‎src/codext/base/base122.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
# -*- coding: UTF-8 -*-
22
"""Base122 Codec - base122 content encoding.
33
4+
Base122, created by Kevin Albertson, is a binary-to-text encoding optimised for UTF-8 (e.g. for embedding binary data in
5+
web pages). The data is read by groups of 7 bits, each group being written as a single-byte UTF-8 character ; as 6
6+
values would be harmful in HTML or JSON (null, line feed, carriage return, double quote, ampersand and backslash), a
7+
group having one of these values is written with the next 7 bits in a two-byte UTF-8 character, hence an expansion of
8+
about 14%.
9+
410
This codec:
511
- en/decodes strings from str to str
612
- en/decodes strings from bytes to bytes
713
- decodes file content to str (read)
814
- encodes file content from str to bytes (write)
15+
16+
Reference: http://blog.kevinalbs.com/base122
917
"""
1018
from ._base import main
1119
from ..__common__ import *

‎src/codext/base/base45.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# -*- coding: UTF-8 -*-
22
"""Base45 Codec - base45 content encoding.
33
4+
Base45 (RFC 9285) was designed for QR codes, whose alphanumeric mode only holds 45 characters (digits, uppercase
5+
letters, space and "$%*+-./:"), and is used e.g. by the EU Digital COVID Certificates. The data is taken by pairs of
6+
bytes, each pair (a 16-bit integer) being written with 3 characters, least significant digit first ; a last single byte
7+
is written with 2 characters. The "-inv" variant swaps the digits and the letters in the charset.
8+
49
This codec:
510
- en/decodes strings from str to str
611
- en/decodes strings from bytes to bytes
712
- decodes file content to str (read)
813
- encodes file content from str to bytes (write)
14+
15+
Reference: https://datatracker.ietf.org/doc/html/rfc9285
916
"""
1017
from ._base import _get_charset, digits, lower, main, upper
1118
from ..__common__ import *

‎src/codext/base/base85.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# -*- coding: UTF-8 -*-
22
"""Base85 Codec - base85 content encoding.
33
4-
This is a simple wrapper for adding base64.b85**code to the codecs.
4+
Base85 writes each group of 4 bytes (a 32-bit integer) with 5 characters among 85, hence an expansion of only 25%. It
5+
comes in several variants with different charsets and conventions:
6+
7+
- Ascii85 (btoa), with the characters from "!" to "u", "z" standing for a group of 4 null bytes
8+
- Adobe's variant, framed by "<~" and "~>"
9+
- xbtoa, with "y" standing for 4 spaces, framed by the "xbtoa Begin" and "xbtoa End" lines (holding the size and
10+
checksums)
11+
- RFC 1924 (for IPv6 addresses), Z85 (ZeroMQ) and the XML variant (draft-kwiatkowski-base85-for-xml), with their own
12+
charsets
513
614
This codec:
715
- en/decodes strings from str to str
816
- en/decodes strings from bytes to bytes
917
- decodes file content to str (read)
1018
- encodes file content from str to bytes (write)
19+
20+
Reference: https://en.wikipedia.org/wiki/Ascii85
21+
https://datatracker.ietf.org/doc/html/rfc1924
22+
https://rfc.zeromq.org/spec/32
1123
"""
1224
import base64
1325

‎src/codext/base/base91.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# -*- coding: UTF-8 -*-
22
"""Base91 Codec - base91 content encoding.
33
4+
basE91, designed by Joachim Henke, uses 91 printable ASCII characters (all but space, "-", "\" and "'"). The input bits
5+
are read by groups of 13 bits (or 14 bits when the value of the 13 bits is small enough), each group being written with
6+
2 characters, hence an expansion of about 23%. The "-alt" variant uses another charset and always reads 13 bits, while
7+
the "-inv" variants swap the groups of characters of the charset.
8+
49
This codec:
510
- en/decodes strings from str to str
611
- en/decodes strings from bytes to bytes
712
- decodes file content to str (read)
813
- encodes file content from str to bytes (write)
14+
15+
Reference: http://base91.sourceforge.net
916
"""
1017
from ._base import _get_charset, digits, lower, main, upper
1118
from ..__common__ import *

‎src/codext/base/baseN.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
# -*- coding: UTF-8 -*-
22
"""BaseN Codecs - base content encodings.
33
4+
These are the classical base encodings, defined by their charsets (most of them also with an inverted variant, "-inv",
5+
swapping the groups of characters, e.g. digits and letters):
6+
7+
- base1 (unary), base2, base3, base4, base8, base10 (decimal), base11, base16 (hexadecimal), base26 (letters), base36,
8+
base62, base63 (with "_"), base67 (with "-_.!~") and base128 (ASCII)
9+
- base32 (RFC 4648) and its variants: extended hex (RFC 4648), z-base-32 (Zimmermann), Crockford's and Geohash
10+
- base58 in its Bitcoin, Ripple and Flickr (short URL) variants
11+
- base64 (RFC 4648) and its URL- and filename-safe variant
12+
13+
The bases that are powers of 2 group the bits of the input (with "=" padding, as in RFC 4648), while the other ones
14+
convert the whole input as a single big integer.
15+
416
These codecs:
517
- en/decode strings from str to str
618
- en/decode strings from bytes to bytes
719
- decode file content to str (read)
820
- encode file content from str to bytes (write)
21+
22+
Reference: https://datatracker.ietf.org/doc/html/rfc4648
23+
https://en.bitcoinwiki.org/wiki/Base58
924
"""
1025
from ..__common__ import *
1126
from ._base import base, base_generic, digits, lower, main, upper

‎src/codext/binary/baudot.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
# -*- coding: UTF-8 -*-
2-
"""Baudot Codec - baudot content conversion to HTML.
2+
"""Baudot Codec - baudot content encoding.
3+
4+
The Baudot code was invented by Emile Baudot in the 1870s for telegraphy, then reworked by Donald Murray and
5+
standardised as the International Telegraph Alphabets (ITA1, then ITA2, used by teleprinters and radioteletype). Each
6+
character is written with 5 bits ; as 32 codes are not enough, two special codes switch between the letters and the
7+
figures (digits and punctuation) shifts, which are inserted in the output when needed.
8+
9+
Several alphabets are supported (CCITT-1, CCITT-2, the original Baudot code (EU/FR), ITA1, ITA2 and its US and
10+
meteorological variants, MTK-2, Murray, UK), as well as the bit order ("-lsb" or "-msb"). The "baudot-spaced" variant
11+
separates the groups of 5 bits with spaces, while "baudot-tape" draws them as a punched paper tape.
312
413
This codec:
514
- en/decodes strings from str to str
615
- en/decodes strings from bytes to bytes
716
- decodes file content to str (read)
817
- encodes file content from str to bytes (write)
18+
19+
Reference: https://en.wikipedia.org/wiki/Baudot_code
920
"""
1021
from ..__common__ import *
1122

‎src/codext/binary/bcd.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# -*- coding: UTF-8 -*-
22
"""BCD Codec - Binary Coded Decimal content encoding.
33
4+
Binary Coded Decimal writes each decimal digit with its own group of 4 bits (0000 to 1001), as used e.g. by calculators,
5+
clocks and some financial systems. Each character is encoded from its ordinal, written with 3 decimal digits
6+
(zero-left-padded), the resulting nibbles being packed into bytes (the last one being padded with 0000). The extended
7+
variants write a single digit per byte, prefixed with the bits 0000 ("bcd-extended0") or 1111 ("bcd-extended1").
8+
49
This codec:
510
- en/decodes strings from str to str
611
- en/decodes strings from bytes to bytes
712
- decodes file content to str (read)
813
- encodes file content from str to bytes (write)
14+
15+
Reference: https://en.wikipedia.org/wiki/Binary-coded_decimal
916
"""
1017
from ..__common__ import *
1118

0 commit comments

Comments
 (0)