Utility API¶
Describes various utility and configuration options. Mostly should be used by client code to set configuration properties.
-
class
tgdb.utils.
Class
¶ The class-based utilities required by this API.
-
class
tgdb.utils.
ConfigName
(value)¶ Stores Configuration Related Keys, Default Values, and Descriptions
-
property
aliasname
¶ The aliasname. This should be a shortened version of the
propertyname
attribute and should be unique across allaliasname
.- Returns
The shortened, unique name for this configuration property.
- Return type
-
property
defaultvalue
¶ The default value for this configuration property.
- Returns
The default value.
- Return type
typing.Optional[str]
-
property
description
¶ A description of this configuration property.
- Returns
The description.
- Return type
-
classmethod
fromName
(name: str)¶ Converts a name into a
ConfigName
object.- Parameters
name (str) – The name to use as a lookup.
- Returns
The
ConfigName
object that matches the name.- Return type
-
property
-
class
tgdb.utils.
HexUtils
¶ A class for all of the hex utilities used by this API.
-
classmethod
formatHex
(buf: Union[bytes, bytearray], buflen: int = 0, ll: int = 48, cl: int = 2, prettyprint: bool = True) → str¶ Prints bytes as a hex string
- Parameters
buf (typing.Union[bytes, bytearray]) – bytes to print as hex string
buflen (int) – how many bytes of the buffer to print, if less than 1, then print the whole thing (default: 0).
ll (int) – how many bytes to print on a line (default: 48). Only used when pretty printing.
cl (int) – how many bytes to print before inserting a space (default: 2). Only used when pretty printing.
prettyprint (bool) – whether to print the format in a more human-readable format (if True), or something machines can more easily decipher (if False) (default: True).
- Returns
The formatted hexadecimal of the bytes-like.
- Return type
-
classmethod
-
class
tgdb.utils.
TGProperties
(*args, **kwds)¶ Intended for accessing configuration data.
-
get
(k: Union[str, tgdb.utils.ConfigName], v: Any = None)¶ Gets a particular property from this TGProperties instance, with a fallback if it doesn’t exist
- Parameters
k (typing.Union[str, ConfigName]) – The key for this property
v (typing.Any) – A value for this property if one doesn’t already exist
- Returns
the value for that property, or None if that property doesn’t exist.
- Return type
typing.Any
-
getDef
(k: tgdb.utils.ConfigName)¶ Gets the default value of k if not set in the properties.
- Parameters
k – The property configuration file.
- Type
- Returns
The configuration value for that property, or that configuration name’s default value.
- Return type
typing.Optional[str]
-
-
class
tgdb.utils.
TGProtocolVersion
¶ TGProtocolVersion keeps track of protocol constants.
-
classmethod
getProtocolVersion
() → int¶ Gets the protocol version as a single integer
- Returns
The protocol major version and minor version.
- Return type
-
classmethod