MCPcopy Index your code
hub / github.com/python/cpython / register_namespace

Function register_namespace

Lib/xml/etree/ElementTree.py:979–996  ·  view source on GitHub ↗

Register a namespace prefix. The registry is global, and any existing mapping for either the given prefix or the namespace URI will be removed. *prefix* is the namespace prefix, *uri* is a namespace uri. Tags and attributes in this namespace will be serialized with prefix if possib

(prefix, uri)

Source from the content-addressed store, hash-verified

977
978
979def register_namespace(prefix, uri):
980 """Register a namespace prefix.
981
982 The registry is global, and any existing mapping for either the
983 given prefix or the namespace URI will be removed.
984
985 *prefix* is the namespace prefix, *uri* is a namespace uri. Tags and
986 attributes in this namespace will be serialized with prefix if possible.
987
988 ValueError is raised if prefix is reserved or is invalid.
989
990 """
991 if re.match(r"ns\d+$", prefix):
992 raise ValueError("Prefix format reserved for internal use")
993 for k, v in list(_namespace_map.items()):
994 if k == uri or v == prefix:
995 del _namespace_map[k]
996 _namespace_map[uri] = prefix
997
998_namespace_map = {
999 # "well-known" namespace prefixes

Callers

nothing calls this directly

Calls 3

listClass · 0.85
matchMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…