comparison configmix/config.py @ 541:25b61f0a1958

Docs for _split_ns() and _split_filters()
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 29 Dec 2021 13:33:11 +0100
parents 33856ae1cc0b
children f71d34dda19f
comparison
equal deleted inserted replaced
540:33856ae1cc0b 541:25b61f0a1958
343 return tuple([unquote(p) for p in varname.split(_HIER_SEPARATOR)]) 343 return tuple([unquote(p) for p in varname.split(_HIER_SEPARATOR)])
344 else: 344 else:
345 return tuple() 345 return tuple()
346 346
347 347
348 def _split_ns(s): 348 def _split_ns(varname):
349 ns, sep, rest = s.partition(_NS_SEPARATOR) 349 """Split the variable name string `varname` into the namespace and
350 the namespace-specific name
351
352 :type varname: str
353 :return: A tuple containing the namespace (or `None`) and the
354 namespace-specific (variable-)name
355 :rtype: tuple(str or None, str)
356
357 """
358
359 ns, sep, rest = varname.partition(_NS_SEPARATOR)
350 if sep: 360 if sep:
351 return (unquote(ns), rest) 361 return (unquote(ns), rest)
352 else: 362 else:
353 return (None, ns) 363 return (None, ns)
354 364
355 365
356 def _split_filters(s): 366 def _split_filters(varname):
357 name, sep, filters = s.partition(_FILTER_SEPARATOR) 367 """Split off the filter part from the `varname` string
368
369 :type varname: str
370 :return: The tuple of the variable name without the filters and a list
371 of filters
372 :rtype: tuple(str, list)
373
374 """
375 name, sep, filters = varname.partition(_FILTER_SEPARATOR)
358 if sep: 376 if sep:
359 filters = filters.strip() 377 filters = filters.strip()
360 if filters: 378 if filters:
361 return (name.rstrip(), 379 return (name.rstrip(),
362 filters.split(_FILTER_SEPARATOR)) 380 filters.split(_FILTER_SEPARATOR))