srctools
A number of utilities are present in the toplevel of the srctools
package.
File Handling
-
srctools.
is_plain_text
(name: str,) bool
valid_chars: Container[str] = frozenset({' ', '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '|'}), Check to see if any characters are not in the whitelist.
-
srctools.
escape_quote_split
(line: str) List[str] Split quote values on a line, handling " correctly.
-
class
srctools.
AtomicWriter
() Atomically overwrite a file. Deprecated, use atomicwrites.AtomicWriter.
Use as a context manager - the returned temporary file should be written to. When cleanly exiting, the file will be transferred. If an exception occurs in the body, the temporary data will be discarded.
This is not reentrant, but can be repeated - starting the context manager clears the file.
Type Conversion
-
srctools.
bool_as_int
(val: object) str Convert a True/False value into ‘1’ or ‘0’.
Valve uses these strings for True/False in editoritems and other config files.
-
srctools.
conv_int
() Union[ValT, int] Converts a string to an integer, using a default if it fails.
-
srctools.
conv_float
() Union[ValT, float] Converts a string to an float, using a default if it fails.
-
srctools.
conv_bool
() Union[ValT, bool] Converts a string to a boolean, using a default if it fails.
Accepts any of ‘0’, ‘1’, ‘false’, ‘true’, ‘yes’, ‘no’. If Val is None, this always returns the default. 0, 1, True and False will be passed through unchanged.
BOOL_LOOKUP
is a constant mapping string values to the appropriate boolean result, the same way conv_bool()
functions.
-
srctools.
EmptyMapping
: collections.abc.MutableMapping
This is a constant mapping which behaves as if it is always empty. It is intended for use in default parameter values, and other fallbacks. It also supports writing operations, which simply do nothing.
Aliases
Several classes from other modules are automatically imported, allowing for more convenient access.
-
class
srctools.
Vec
Canonical: srctools.math.Vec
-
class
srctools.
Angle
Canonical: srctools.math.Angle
-
class
srctools.
Matrix
Canonical: srctools.math.Matrix
-
class
srctools.
Vec_tuple
Canonical: srctools.math.Vec_tuple
-
srctools.
parse_vec_str
() Canonical: srctools.math.parse_vec_str()
-
srctools.
lerp
() Canonical: srctools.math.lerp()
-
class
srctools.
NoKeyError
Canonical: srctools.keyvalues.NoKeyError
-
class
srctools.
KeyValError
Canonical: srctools.keyvalues.KeyValError
-
class
srctools.
Keyvalues
Canonical: srctools.keyvalues.Keyvalues
-
class
srctools.
FileSystem
Canonical: srctools.filesys.FileSystem
-
class
srctools.
FileSystemChain
Canonical: srctools.filesys.FileSystemChain
-
srctools.
get_filesystem
() Canonical: srctools.filesys.get_filesystem()
-
class
srctools.
VMF
Canonical: srctools.vmf.VMF
-
class
srctools.
Entity
Canonical: srctools.vmf.Entity
-
class
srctools.
Solid
Canonical: srctools.vmf.Solid
-
class
srctools.
Side
Canonical: srctools.vmf.Side
-
class
srctools.
Output
Canonical: srctools.vmf.Output
-
class
srctools.
UVAxis
Canonical: srctools.vmf.UVAxis
-
class
srctools.
SurfaceProp
Canonical: srctools.surfaceprop.SurfaceProp
-
class
srctools.
SurfChar
Canonical: srctools.surfaceprop.SurfChar
-
class
srctools.
VPK
Canonical: srctools.vpk.VPK
-
class
srctools.
FGD
Canonical: srctools.fgd.FGD
-
class
srctools.
GameID
Canonical: srctools.const.GameID
-
class
srctools.
VTF
Canonical: srctools.vtf.VTF