On this page
stringprep
Prev: string | Up: stdlib_module | Next: struct
Rel: string, re, difflib, textwrap, unicodedata
Ref: docs.python.org — stringprep
Tags: #public #python3 #stdlib
Import
import stringprep
Overview
RFC 3454 Stringprep Unicode character-classification tables (in_table_a1(), in_table_c12(), map_table_b1(), etc.) used to normalize and validate internationalized protocol identifiers (such as legacy IDNA2003 domain names, SASL, and XMPP). Use stringprep only when implementing an RFC that explicitly cites RFC 3454; for general Unicode normalization, use unicodedata.
Quick Start
import stringprep
# Table C.1.2 checks for non-ASCII space characters (e.g., U+00A0 NO-BREAK SPACE)
assert stringprep.in_table_c12("\u00a0") is True
assert stringprep.in_table_c12(" ") is False
Implementation Walkthrough
1. Checking Prohibited Control Characters
Protocols using Stringprep reject characters in tables like C.2.1 (ASCII control characters) or C.2.2 (non-ASCII control characters):
import stringprep
def has_prohibited_controls(text: str) -> bool:
return any(stringprep.in_table_c21(ch) or stringprep.in_table_c22(ch) for ch in text)
assert has_prohibited_controls("hello\x00world") is True
assert has_prohibited_controls("hello world") is False
Gotchas & Boundaries
- Frozen to Unicode 3.2 (RFC 3454):
stringprepintentionally mirrors the old Unicode 3.2 tables required by RFC 3454 and is superseded for modern protocols by PRECIS (RFC 8264) and IDNA2008 (idnaon PyPI). - Single-character inputs: All
in_table_*andmap_table_*functions expect a single 1-characterstr.
Common Functions
- stringprep.in_table_a1() —
in_table_a1(code)—stringprep.in_table_a1()function. - stringprep.in_table_b1() —
in_table_b1(code)—stringprep.in_table_b1()function. - stringprep.in_table_c11() —
in_table_c11(code)—stringprep.in_table_c11()function. - stringprep.in_table_c11_c12() —
in_table_c11_c12(code)—stringprep.in_table_c11_c12()function. - stringprep.in_table_c12() —
in_table_c12(code)—stringprep.in_table_c12()function. - stringprep.in_table_c21() —
in_table_c21(code)—stringprep.in_table_c21()function. - stringprep.in_table_c21_c22() —
in_table_c21_c22(code)—stringprep.in_table_c21_c22()function. - stringprep.in_table_c22() —
in_table_c22(code)—stringprep.in_table_c22()function. - stringprep.in_table_c3() —
in_table_c3(code)—stringprep.in_table_c3()function. - stringprep.in_table_c4() —
in_table_c4(code)—stringprep.in_table_c4()function. - stringprep.in_table_c5() —
in_table_c5(code)—stringprep.in_table_c5()function. - stringprep.in_table_c6() —
in_table_c6(code)—stringprep.in_table_c6()function. - stringprep.in_table_c7() —
in_table_c7(code)—stringprep.in_table_c7()function. - stringprep.in_table_c8() —
in_table_c8(code)—stringprep.in_table_c8()function. - stringprep.in_table_c9() —
in_table_c9(code)—stringprep.in_table_c9()function. - stringprep.in_table_d1() —
in_table_d1(code)—stringprep.in_table_d1()function. - stringprep.in_table_d2() —
in_table_d2(code)—stringprep.in_table_d2()function. - stringprep.map_table_b2() —
map_table_b2(a)—stringprep.map_table_b2()function. - stringprep.map_table_b3() —
map_table_b3(code)—stringprep.map_table_b3()function.
Constants & Attributes
stringprep.b1_set(set) ={65024, 65025, 65026, 65027, 65028, 65029, 6150, 65030, 6...stringprep.b3_exceptions(dict) ={181: 'μ', 223: 'ss', 304: 'i̇', 329: 'ʼn', 383: 's', 496...stringprep.c22_specials(set) ={8204, 8205, 6158, 1807, 8232, 8233, 1757, 8288, 8289, 82...stringprep.c6_set(set) ={65529, 65530, 65531, 65532, 65533}stringprep.c7_set(set) ={12272, 12273, 12274, 12275, 12276, 12277, 12278, 12279, ...stringprep.c8_set(set) ={832, 833, 8234, 8235, 8236, 8237, 8206, 8207, 8238, 8298...stringprep.c9_set(set) ={917505, 917536, 917537, 917538, 917539, 917540, 917541, ...stringprep.unicodedata(UCD) =<unicodedata.UCD object at 0x109dd0ac0>
Linked from
- tuts/python3/stdlib_module
- tuts/python3/stdlib_module/difflib
- tuts/python3/stdlib_module/re
- tuts/python3/stdlib_module/stdlib_module
- tuts/python3/stdlib_module/string
- tuts/python3/stdlib_module/stringprep/in_table_a1
- tuts/python3/stdlib_module/stringprep/in_table_b1
- tuts/python3/stdlib_module/stringprep/in_table_c11
- tuts/python3/stdlib_module/stringprep/in_table_c11_c12
- tuts/python3/stdlib_module/stringprep/in_table_c12
- tuts/python3/stdlib_module/stringprep/in_table_c21
- tuts/python3/stdlib_module/stringprep/in_table_c21_c22
- tuts/python3/stdlib_module/stringprep/in_table_c22
- tuts/python3/stdlib_module/stringprep/in_table_c3
- tuts/python3/stdlib_module/stringprep/in_table_c4
- tuts/python3/stdlib_module/stringprep/in_table_c5
- tuts/python3/stdlib_module/stringprep/in_table_c6
- tuts/python3/stdlib_module/stringprep/in_table_c7
- tuts/python3/stdlib_module/stringprep/in_table_c8
- tuts/python3/stdlib_module/stringprep/in_table_c9
- tuts/python3/stdlib_module/stringprep/in_table_d1
- tuts/python3/stdlib_module/stringprep/in_table_d2
- tuts/python3/stdlib_module/stringprep/map_table_b2
- tuts/python3/stdlib_module/stringprep/map_table_b3
- tuts/python3/stdlib_module/struct
- tuts/python3/stdlib_module/textwrap
- tuts/python3/stdlib_module/unicodedata
Related notes
- tuts/python3/stdlib_module/difflib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/re Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stdlib_module Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/string Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stringprep/in_table_a1 Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stringprep/in_table_b1 Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stringprep/in_table_c11 Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stringprep/in_table_c11_c12 Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stringprep/in_table_c12 Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stringprep/in_table_c21 Linked here; links to this page; shared tags: #stdlib