MCPcopy Create free account
hub / github.com/pydata/xarray / is_valid_nc3_name

Function is_valid_nc3_name

xarray/backends/netcdf3.py:142–170  ·  view source on GitHub ↗

Test whether an object can be validly converted to a netCDF-3 dimension, variable or attribute name Earlier versions of the netCDF C-library reference implementation enforced a more restricted set of characters in creating new names, but permitted reading names containing arbitrary

(s)

Source from the content-addressed store, hash-verified

140
141
142def is_valid_nc3_name(s):
143 """Test whether an object can be validly converted to a netCDF-3
144 dimension, variable or attribute name
145
146 Earlier versions of the netCDF C-library reference implementation
147 enforced a more restricted set of characters in creating new names,
148 but permitted reading names containing arbitrary bytes. This
149 specification extends the permitted characters in names to include
150 multi-byte UTF-8 encoded Unicode and additional printing characters
151 from the US-ASCII alphabet. The first character of a name must be
152 alphanumeric, a multi-byte UTF-8 character, or '_' (reserved for
153 special names with meaning to implementations, such as the
154 "_FillValue" attribute). Subsequent characters may also include
155 printing special characters, except for '/' which is not allowed in
156 names. Names that have trailing space characters are also not
157 permitted.
158 """
159 if not isinstance(s, str):
160 return False
161 num_bytes = len(s.encode("utf-8"))
162 return (
163 (unicodedata.normalize("NFC", s) == s)
164 and (s not in _reserved_names)
165 and (num_bytes >= 0)
166 and ("/" not in s)
167 and (s[-1] != " ")
168 and (_isalnumMUTF8(s[0]) or (s[0] == "_"))
169 and all(_isalnumMUTF8(c) or c in _specialchars for c in s)
170 )

Callers 1

_validate_attr_keyMethod · 0.90

Calls 3

_isalnumMUTF8Function · 0.85
normalizeMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…