MCPcopy Index your code
hub / github.com/RustPython/RustPython / _start

Method _start

Lib/xml/etree/ElementTree.py:1941–2008  ·  view source on GitHub ↗
(self, tag, attrs, new_namespaces, qname_text=None)

Source from the content-addressed store, hash-verified

1939 self._start(tag, attrs, new_namespaces)
1940
1941 def _start(self, tag, attrs, new_namespaces, qname_text=None):
1942 if self._exclude_attrs is not None and attrs:
1943 attrs = {k: v for k, v in attrs.items() if k not in self._exclude_attrs}
1944
1945 qnames = {tag, *attrs}
1946 resolved_names = {}
1947
1948 # Resolve prefixes in attribute and tag text.
1949 if qname_text is not None:
1950 qname = resolved_names[qname_text] = self._resolve_prefix_name(qname_text)
1951 qnames.add(qname)
1952 if self._find_qname_aware_attrs is not None and attrs:
1953 qattrs = self._find_qname_aware_attrs(attrs)
1954 if qattrs:
1955 for attr_name in qattrs:
1956 value = attrs[attr_name]
1957 if _looks_like_prefix_name(value):
1958 qname = resolved_names[value] = self._resolve_prefix_name(value)
1959 qnames.add(qname)
1960 else:
1961 qattrs = None
1962 else:
1963 qattrs = None
1964
1965 # Assign prefixes in lexicographical order of used URIs.
1966 parse_qname = self._qname
1967 parsed_qnames = {n: parse_qname(n) for n in sorted(
1968 qnames, key=lambda n: n.split('}', 1))}
1969
1970 # Write namespace declarations in prefix order ...
1971 if new_namespaces:
1972 attr_list = [
1973 ('xmlns:' + prefix if prefix else 'xmlns', uri)
1974 for uri, prefix in new_namespaces
1975 ]
1976 attr_list.sort()
1977 else:
1978 # almost always empty
1979 attr_list = []
1980
1981 # ... followed by attributes in URI+name order
1982 if attrs:
1983 for k, v in sorted(attrs.items()):
1984 if qattrs is not None and k in qattrs and v in resolved_names:
1985 v = parsed_qnames[resolved_names[v]][0]
1986 attr_qname, attr_name, uri = parsed_qnames[k]
1987 # No prefix for attributes in default ('') namespace.
1988 attr_list.append((attr_qname if uri else attr_name, v))
1989
1990 # Honour xml:space attributes.
1991 space_behaviour = attrs.get('{http://www.w3.org/XML/1998/namespace}space')
1992 self._preserve_space.append(
1993 space_behaviour == 'preserve' if space_behaviour
1994 else self._preserve_space[-1])
1995
1996 # Write the tag.
1997 write = self._write
1998 write('<' + parsed_qnames[tag][0])

Callers 2

_flushMethod · 0.95
startMethod · 0.95

Calls 12

_resolve_prefix_nameMethod · 0.95
sortedFunction · 0.85
_escape_attrib_c14nFunction · 0.85
_escape_cdata_c14nFunction · 0.85
writeFunction · 0.50
itemsMethod · 0.45
addMethod · 0.45
splitMethod · 0.45
sortMethod · 0.45
appendMethod · 0.45
getMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected