API reference¶
Glob
¶
Glob pattern matcher with configurable features.
Use Glob.default() for POSIX fnmatch-like matching (bracket expansion
and escape sequences enabled), or Glob.empty() for a minimal
configuration. Chain builder methods to enable or disable features, then
call match() to test patterns.
Examples:
>>> from globlin import Glob
>>> glob = Glob.default()
>>> glob.match("*.py", "foo.py")
True
>>> glob.match("*.py", "foo.txt")
False
New in version 0.3.
Methods:
-
default–Create a glob with POSIX fnmatch-like defaults.
-
empty–Create a glob with no features enabled.
-
from_flags–Create a glob from raw bitflags.
-
globstar–Enable
**globstar matching. -
no_globstar–Disable
**globstar matching. -
bracket_expansion–Enable
[abc]/[a-z]bracket expansion. -
no_bracket_expansion–Disable
[abc]/[a-z]bracket expansion. -
brace_expansion–Enable
{a,b,c}brace expansion. -
no_brace_expansion–Disable
{a,b,c}brace expansion. -
negate–Enable
!patternnegation. -
no_negate–Disable
!patternnegation. -
escape–Enable
\escape sequences. -
no_escape–Disable
\escape sequences. -
path_separator–Enable path separator handling (
*and?do not match/). -
no_path_separator–Disable path separator handling (
*and?match/). -
match–Match a glob pattern against a value.
default
classmethod
¶
default() -> Glob
Create a glob with POSIX fnmatch-like defaults.
Enables bracket expansion and escape sequences. Additional features like globstar can be added via builder methods.
Examples:
>>> glob = Glob.default()
>>> glob.match("[abc]", "b")
True
>>> glob.match(r"\*", "*")
True
New in version 0.3.
Source code in python/globlin/__init__.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
empty
classmethod
¶
empty() -> Glob
Create a glob with no features enabled.
Only * and ? wildcards work.
Examples:
>>> glob = Glob.empty()
>>> glob.match("*.py", "foo.py")
True
>>> glob.match("[abc]", "b")
False
New in version 0.3.
Source code in python/globlin/__init__.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
from_flags
classmethod
¶
Create a glob from raw bitflags.
Parameters:
Raises:
-
ValueError–If any bits outside the valid range are set.
Examples:
>>> from globlin import Flags
>>> glob = Glob.from_flags(Flags.GLOB_STAR | Flags.PATH_SEPARATOR | Flags.ESCAPE)
>>> glob.match("src/**/*.py", "src/a/b/foo.py")
True
New in version 0.3.
Source code in python/globlin/__init__.py
62 63 64 65 66 67 68 69 70 71 | |
globstar
¶
globstar() -> Self
Enable ** globstar matching.
Implies path_separator() since globstar is only meaningful when
/ is treated as a path separator.
Examples:
>>> glob = Glob.default().globstar()
>>> glob.match("src/**/*.py", "src/a/b/foo.py")
True
>>> glob.match("src/**/*.py", "src/foo.py")
True
New in version 0.3.
bracket_expansion
¶
bracket_expansion() -> Self
Enable [abc] / [a-z] bracket expansion.
Examples:
>>> glob = Glob.empty().bracket_expansion()
>>> glob.match("[a-z]", "m")
True
>>> glob.match("[!abc]", "d")
True
New in version 0.3.
no_bracket_expansion
¶
no_bracket_expansion() -> Self
Disable [abc] / [a-z] bracket expansion.
Examples:
>>> glob = Glob.default().no_bracket_expansion()
>>> glob.match("[abc]", "[abc]")
True
New in version 0.3.
brace_expansion
¶
brace_expansion() -> Self
Enable {a,b,c} brace expansion.
Examples:
>>> glob = Glob.default().brace_expansion()
>>> glob.match("{src,lib}/*.py", "src/foo.py")
True
>>> glob.match("{src,lib}/*.py", "test/foo.py")
False
New in version 0.3.
no_brace_expansion
¶
no_brace_expansion() -> Self
Disable {a,b,c} brace expansion.
New in version 0.3.
negate
¶
negate() -> Self
Enable !pattern negation.
Examples:
>>> glob = Glob.default().negate()
>>> glob.match("!*.py", "foo.txt")
True
>>> glob.match("!*.py", "foo.py")
False
New in version 0.3.
escape
¶
escape() -> Self
Enable \ escape sequences.
Examples:
>>> glob = Glob.empty().escape()
>>> glob.match("\\*", "*")
True
>>> glob.match("\\*", "foo")
False
New in version 0.3.
no_escape
¶
no_escape() -> Self
Disable \ escape sequences.
Examples:
>>> glob = Glob.default().no_escape()
>>> glob.match("\\*", "\\foo")
True
New in version 0.3.
path_separator
¶
path_separator() -> Self
Enable path separator handling (* and ? do not match /).
Examples:
>>> glob = Glob.default().path_separator()
>>> glob.match("*.py", "foo.py")
True
>>> glob.match("*.py", "dir/foo.py")
False
New in version 0.3.
no_path_separator
¶
no_path_separator() -> Self
Disable path separator handling (* and ? match /).
New in version 0.3.
Flags
¶
Bases: IntFlag
Low-level flag constants for bitwise composition.
Attributes:
-
EMPTY–No features enabled.
-
GLOB_STAR–Enable
**globstar matching. -
BRACKET_EXPANSION–Enable
[abc]/[a-z]bracket expansion. -
BRACE_EXPANSION–Enable
{a,b,c}brace expansion. -
NEGATE–Enable
!patternnegation. -
ESCAPE–Enable
\escape sequences. -
PATH_SEPARATOR–Treat
/as path separator —*and?do not match/. -
ALL–All features enabled.
-
DEFAULT–POSIX fnmatch-like defaults (
BRACKET_EXPANSION | ESCAPE).
GLOB_STAR
class-attribute
instance-attribute
¶
GLOB_STAR = GLOB_STAR
Enable ** globstar matching.
New in version 0.3.
BRACKET_EXPANSION
class-attribute
instance-attribute
¶
BRACKET_EXPANSION = BRACKET_EXPANSION
Enable [abc] / [a-z] bracket expansion.
New in version 0.3.
BRACE_EXPANSION
class-attribute
instance-attribute
¶
BRACE_EXPANSION = BRACE_EXPANSION
Enable {a,b,c} brace expansion.
New in version 0.3.
NEGATE
class-attribute
instance-attribute
¶
NEGATE = NEGATE
Enable !pattern negation.
New in version 0.3.
ESCAPE
class-attribute
instance-attribute
¶
ESCAPE = ESCAPE
Enable \ escape sequences.
New in version 0.3.
PATH_SEPARATOR
class-attribute
instance-attribute
¶
PATH_SEPARATOR = PATH_SEPARATOR
Treat / as path separator — * and ? do not match /.
New in version 0.3.
DEFAULT
class-attribute
instance-attribute
¶
DEFAULT = DEFAULT
POSIX fnmatch-like defaults (BRACKET_EXPANSION | ESCAPE).
New in version 0.3.
fnmatch
builtin
¶
Deprecated
Use Glob.default() instead
Match a glob pattern against a value.
Flag
deprecated
¶
Deprecated
Use Glob instead
Flag enum for fnmatch.
Attributes:
-
EMPTY(Flag) –No features enabled.
-
GLOB_STAR(Flag) –Enable
**globstar matching. -
BRACKET_EXPANSION(Flag) –Enable
[abc]/[a-z]bracket expansion. -
BRACE_EXPANSION(Flag) –Enable
{a,b,c}brace expansion. -
NEGATE(Flag) –Enable
!patternnegation. -
ESCAPE(Flag) –Enable
\escape sequences. -
NO_PATH(Flag) –*and?match/(disables path separator handling).