Strings
Utility Helpers Module
STR_BOOL_MAP = {'1': True, 'y': True, 't': True, 'on': True, 'yes': True, 'true': True, '0': False, 'n': False, 'f': False, 'no': False, 'off': False, 'false': False}
module-attribute
- Util classes
StrEnum
Bases: str
, Enum
Enum where the value is always a string.
Source code in src/utils/strings.py
39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
StrEnumMeta
Bases: EnumMeta
Metaclass for StrEnum.
Source code in src/utils/strings.py
32 33 34 35 36 |
|
get_bullet_points(text, char='•')
Turns a list of strings into a joined string bullet point list. @param text: List of strings. @param char: Character to use as bullet. @return: Joined string with bullet points and newlines.
Source code in src/utils/strings.py
228 229 230 231 232 233 234 235 236 237 238 |
|
get_line(text, i, sep='\n')
Get line by index from a multiline string.
@param text: Multiline string.
@param i: Index of the line.
@param sep: Newline separator to use for split, defaults to '
'. @return: Isolated line.
Source code in src/utils/strings.py
100 101 102 103 104 105 106 107 108 109 110 |
|
get_lines(text, num, sep='\n')
Separate a number of lines from a multiline string.
@param text: Multiline string.
@param num: Number of lines to separate and return, negative integer for trailing lines.
@param sep: Newline separator to use for split, defaults to '
'. @return: Isolated lines.
Source code in src/utils/strings.py
113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
is_multiline(text)
Check if text or list of texts given contains multiline text (a newline character). @param text: String to check or list of strings to check. @return: True/False or list of True/False values.
Source code in src/utils/strings.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
msg_bold(msg)
Wraps a console string with a bold tag. @param msg: Message to wrap. @return: Wrapped message.
Source code in src/utils/strings.py
170 171 172 173 174 175 176 |
|
msg_error(msg, reason=None)
Adds unified error color tag to Proxyshop console message. @param msg: String to add tag to. @param reason: Reason for the error, if needed. @return: Formatted string.
Source code in src/utils/strings.py
188 189 190 191 192 193 194 195 196 |
|
msg_info(msg)
Adds unified info color tag to Proxyshop console message. @param msg: String to add tag to. @return: Formatted string.
Source code in src/utils/strings.py
219 220 221 222 223 224 225 |
|
msg_italics(msg)
Wraps a console string with an italics tag. @param msg: Message to wrap. @return: Wrapped message.
Source code in src/utils/strings.py
179 180 181 182 183 184 185 |
|
msg_success(msg)
Adds unified success color tag to Proxyshop console message. @param msg: String to add tag to. @return: Formatted string.
Source code in src/utils/strings.py
210 211 212 213 214 215 216 |
|
msg_warn(msg, reason=None)
Adds unified warning color tag to Proxyshop console message. @param msg: String to add tag to. @param reason: Reason for the warning, if needed. @return: Formatted string.
Source code in src/utils/strings.py
199 200 201 202 203 204 205 206 207 |
|
normalize_str(st, no_space=False)
Normalizes a string for safe comparison. @param st: String to normalize. @param no_space: Remove spaces. @return: Normalized string.
Source code in src/utils/strings.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
str_to_bool(st)
Converts a truthy string value to a bool. Conversion is case-insensitive. @param st: True values are y, yes, t, true, on and 1. False values are n, no, f, false, off and 0. @return: Adjacent boolean value. @raise: ValueError if string provided isn't a recognized truthy expression.
Source code in src/utils/strings.py
151 152 153 154 155 156 157 158 159 160 161 162 |
|
strip_lines(text, num, sep='\n')
Removes a number of leading or trailing lines from a multiline string.
@param text: Multiline string.
@param num: Positive integer for number leading lines, negative integer for number of trailing lines.
@param sep: Newline separator to use for split, defaults to '
'. @return: String with lines stripped.
Source code in src/utils/strings.py
85 86 87 88 89 90 91 92 93 94 95 96 97 |
|