CategorizedWildcard¶
-
class
lsst.daf.butler.registry.wildcards.
CategorizedWildcard
(strings: list, patterns: list, items: list)¶ Bases:
object
The results of preprocessing a wildcard expression to separate match patterns from strings.
The
fromExpression
method should almost always be used to construct instances, as the regular constructor performs no checking of inputs (and that can lead to confusing error messages downstream).Methods Summary
fromExpression
(expression, *, allowAny, …)Categorize a wildcard expression. Methods Documentation
-
classmethod
fromExpression
(expression: Any, *, allowAny: bool = True, allowPatterns: bool = True, coerceUnrecognized: Optional[collections.abc.Callable[Any, tuple[str, typing.Any] | str[tuple, str]], None] = None, coerceItemValue: Optional[collections.abc.Callable[Any, Any], None] = None, defaultItemValue: Optional[Any, None] = None) → lsst.daf.butler.registry.wildcards.CategorizedWildcard | ellipsis[lsst.daf.butler.registry.wildcards.CategorizedWildcard, ellipsis]¶ Categorize a wildcard expression.
Parameters: - expression
- The expression to categorize. May be any of:
str
(including glob patterns ifallowPatterns
isTrue
);re.Pattern
(only ifallowPatterns
isTrue
);- objects recognized by
coerceUnrecognized
(if provided); - two-element tuples of (
str
, value) where value is recognized bycoerceItemValue
(if provided); - a non-
str
, non-mapping iterable containing any of the above; - the special value
(only if
allowAny
isTrue
), which matches anything; - a mapping from
str
to a value are recognized bycoerceItemValue
(if provided); - a
CategorizedWildcard
instance (passed through unchanged if it meets the requirements specified by keyword arguments).
- allowAny: `bool`, optional
If
False
(True
is default) raiseTypeError
ifis encountered.
- allowPatterns: `bool`, optional
If
False
(True
is default) raiseTypeError
if are.Pattern
is encountered, or ifexpression
is aCategorizedWildcard
withpatterns
not empty.- coerceUnrecognized: `Callable`, optional
A callback that takes a single argument of arbitrary type and returns either a
str
- appended tostrings
- or atuple
of (str
,Any
) to be appended toitems
. This will be called on objects of unrecognized type. Exceptions will be reraised asTypeError
(and chained).- coerceItemValue: `Callable`, optional
If provided,
expression
may be a mapping fromstr
to any type that can be passed to this function; the result of that call will be stored instead as the value inself.items
.- defaultItemValue: `Any`, optional
If provided, combine this value with any string values encountered (including any returned by
coerceUnrecognized
) to form atuple
and add it toitems
, guaranteeing thatstrings
will be empty. Patterns are never added toitems
.
Returns: - categorized :
CategorizedWildcard
or...
. The struct describing the wildcard.
...
is passed through unchanged.
Raises: - TypeError
Raised if an unsupported type is found in the expression.
-
classmethod