FileAttributeMatcher
- class FileAttributeMatcher(**kwargs)
Determines if a string matches a file attribute.
Constructors
- class FileAttributeMatcher
- classmethod new(attributes: str) FileAttributeMatcher
Creates a new file attribute matcher, which matches attributes against a given string.
FileAttributeMatcher
are reference counted structures, and are created with a reference count of 1. If the number of references falls to 0, theFileAttributeMatcher
is automatically destroyed.The
attributes
string should be formatted with specific keys separated from namespaces with a double colon. Several “namespace::key” strings may be concatenated with a single comma (e.g. “standard::type,standard::is-hidden”). The wildcard “*” may be used to match all keys and namespaces, or “namespace::*” will match all keys in a given namespace.Examples of file attribute matcher strings and results
"*"
: matches all attributes."standard::is-hidden"
: matches only the key is-hidden in the standard namespace."standard::type,unix::*"
: matches the type key in the standard namespace and all keys in the unix namespace.
- param attributes:
an attribute string to match.
Methods
- class FileAttributeMatcher
- enumerate_namespace(ns: str) bool
Checks if the matcher will match all of the keys in a given namespace. This will always return
True
if a wildcard character is in use (e.g. if matcher was created with “standard::” and ``ns`` is “standard”, or if matcher was created using “” and namespace is anything.)TODO: this is awkwardly worded.
- Parameters:
ns – a string containing a file attribute namespace.
- enumerate_next() str | None
Gets the next matched attribute from a
FileAttributeMatcher
.
- matches(attribute: str) bool
Checks if an attribute will be matched by an attribute matcher. If the matcher was created with the “*” matching string, this function will always return
True
.- Parameters:
attribute – a file attribute key.
- matches_only(attribute: str) bool
Checks if an attribute matcher only matches a given attribute. Always returns
False
if “*” was used when creating the matcher.- Parameters:
attribute – a file attribute key.
- subtract(subtract: FileAttributeMatcher | None = None) FileAttributeMatcher | None
Subtracts all attributes of
subtract
frommatcher
and returns a matcher that supports those attributes.Note that currently it is not possible to remove a single attribute when the
matcher
matches the whole namespace - or remove a namespace or attribute when the matcher matches everything. This is a limitation of the current implementation, but may be fixed in the future.- Parameters:
subtract – The matcher to subtract