utils ¤
Utils module.
This module contains simple utility classes and functions.
Classes:
-
SignalHandler
–A helper class to handle signals.
Functions:
-
bool_or_value
–Return
True
for"true"
,False
for"false"
, original value otherwise. -
bool_to_str
–Return
"true"
forTrue
,"false"
forFalse
, original value otherwise. -
get_version
–Return the current
aria2p
version. -
human_readable_bytes
–Return a human-readable bytes value as a string.
-
human_readable_timedelta
–Return a human-readable time delta as a string.
-
load_configuration
–Return dict from TOML formatted string or file.
-
read_lines
–Read lines in a file.
SignalHandler ¤
A helper class to handle signals.
Parameters:
Methods:
-
trigger
–Mark this instance as 'triggered' (a specified signal was received).
Source code in src/aria2p/utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
trigger ¤
Mark this instance as 'triggered' (a specified signal was received).
Parameters:
Source code in src/aria2p/utils.py
53 54 55 56 57 58 59 60 61 62 63 |
|
bool_or_value ¤
Return True
for "true"
, False
for "false"
, original value otherwise.
Parameters:
-
value
(Any
) –Any kind of value.
Returns:
-
Any
–One of these values:
True
for"true"
False
for"false"
- Original value otherwise
Source code in src/aria2p/utils.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
bool_to_str ¤
Return "true"
for True
, "false"
for False
, original value otherwise.
Parameters:
-
value
(Any
) –Any kind of value.
Returns:
Source code in src/aria2p/utils.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
get_version ¤
get_version() -> str
Return the current aria2p
version.
Returns:
-
str
–The current
aria2p
version.
Source code in src/aria2p/utils.py
168 169 170 171 172 173 174 175 176 177 |
|
human_readable_bytes ¤
Return a human-readable bytes value as a string.
Parameters:
-
value
(int
) –The bytes value.
-
digits
(int
, default:2
) –How many decimal digits to use.
-
delim
(str
, default:''
) –String to add between value and unit.
-
postfix
(str
, default:''
) –String to add at the end.
Returns:
-
str
–The human-readable version of the bytes.
Source code in src/aria2p/utils.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
human_readable_timedelta ¤
Return a human-readable time delta as a string.
Parameters:
-
value
(timedelta
) –The timedelta.
-
precision
(int
, default:0
) –The precision to use:
0
to display all units1
to display the biggest unit only2
to display the first two biggest units onlyn
for the first N biggest units, etc.
Returns:
-
str
–A string representing the time delta.
Source code in src/aria2p/utils.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
load_configuration ¤
Return dict from TOML formatted string or file.
Returns:
Source code in src/aria2p/utils.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
read_lines ¤
Read lines in a file.
Parameters:
Returns:
Source code in src/aria2p/utils.py
259 260 261 262 263 264 265 266 267 268 |
|