cocorum.utils
This module provides various functions that stand by themselves and are used by a lot of different classes in the package. While most of these functions aren't usually meant to be used directly, you might find some of them handy. At least one function is not currently used by the rest of the package at all, but I figured it might be useful in the future.
Rumble API utilities
This submodule provides some utilities for working with the APIs S.D.G.
MD5Ex
MD5 extended hashing utilities
Source code in cocorum/utils.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
hash(message)
staticmethod
Hash a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
Message to hash. |
required |
Returns:
Name | Type | Description |
---|---|---|
Hash |
str
|
The hex digest hash result. |
Source code in cocorum/utils.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
hash_stretch(password, salt, iterations=1024)
staticmethod
Stretch-hash a password with a salt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
password
|
str
|
The password to hash. |
required |
salt
|
str
|
The salt to add to the password. |
required |
iterations
|
int
|
Number of times to stretch the hashing. |
1024
|
Returns:
Name | Type | Description |
---|---|---|
Hash |
str
|
The completed stretched hash. |
Source code in cocorum/utils.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
badges_to_glyph_string(badges)
Convert a list of badges into a string of glyphs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
badges
|
list
|
A list of str or objects with str method that are valid badge slugs. |
required |
Returns:
Name | Type | Description |
---|---|---|
Glyphs |
str
|
The badge list as a UTF-8 glyph string, uses ? for unknown badges. |
Source code in cocorum/utils.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
base_10_to_36(b10)
Convert a base 10 number to base 36.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b10
|
int
|
The base 10 number. |
required |
Returns:
Name | Type | Description |
---|---|---|
B36 |
str
|
The same number in base 36. |
Source code in cocorum/utils.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
base_36_and_10(num, assume_10=False)
Take a base 36 or base 10 number, and return both base 36 and 10.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
(int, str)
|
The number in either base 10 or 36. |
required |
assume_10
|
bool
|
If the number is a string but looks like base 10, should we assume it is? Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
B36 |
str
|
The number in base 36. |
B10 |
int
|
The number in base 10. |
Source code in cocorum/utils.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
base_36_to_10(b36)
Convert a base 36 number to base 10.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b36
|
str
|
The base 36 number. |
required |
Returns:
Name | Type | Description |
---|---|---|
B10 |
int
|
The same number in base 10. |
Source code in cocorum/utils.py
104 105 106 107 108 109 110 111 112 113 114 |
|
calc_password_hashes(password, salts)
Hash a password for Rumble authentication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
password
|
str
|
The password to hash. |
required |
salts
|
iter
|
The three salts to use for hashing. |
required |
Returns:
Name | Type | Description |
---|---|---|
Hashes |
iter
|
The three results of hashing. |
Source code in cocorum/utils.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
ensure_b10(num, assume_10=False)
No matter wether a number is base 36 or 10, return 10.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
(int, str)
|
The number in either base 10 or 36. |
required |
assume_10
|
bool
|
If the number is a string but looks like base 10, should we assume it is? Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Number |
int
|
The number in base 10. |
Source code in cocorum/utils.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
ensure_b36(num, assume_10=False)
No matter wether a number is base 36 or 10, return 36.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
(int, str)
|
The number in either base 10 or 36. |
required |
assume_10
|
bool
|
If the number is a string but looks like base 10, should we assume it is? Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Number |
str
|
The number in base 36. |
Source code in cocorum/utils.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
form_timestamp(seconds, suffix='+00:00')
Form a Rumble timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seconds
|
float
|
Timestamp in seconds since Epoch, UTC. |
required |
Returns:
Name | Type | Description |
---|---|---|
Timestamp |
str
|
The same timestamp value, in Rumble's API format. |
Source code in cocorum/utils.py
73 74 75 76 77 78 79 80 81 82 83 |
|
generate_request_id()
Generate a UUID for API requests
Returns:
Name | Type | Description |
---|---|---|
UUID |
str
|
Random base64 encoded UUID. |
Source code in cocorum/utils.py
226 227 228 229 230 231 232 233 234 235 |
|
options_check(url, method, origin=static.URI.rumble_base, cookies={}, params={})
Check of we are allowed to do method on url via an options request
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL to check at. |
required |
method
|
str
|
The HTTP method to check permission for. |
required |
origin
|
str
|
The origin header of the options request. Defaults to static.URI.rumble_base |
rumble_base
|
cookies
|
dict
|
Cookie dict to use in the request. Defaults to no cookies. |
{}
|
params
|
dict
|
Parameters to use in the request. Defaults to no parameters. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Result |
bool
|
Is the HTTP method allowed at the URL? |
Source code in cocorum/utils.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
parse_timestamp(timestamp)
Parse a Rumble timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timestamp
|
str
|
Timestamp in Rumble's API format. |
required |
Returns:
Name | Type | Description |
---|---|---|
Timestamp |
float
|
The same timestamp value, in seconds since Epoch, UTC. |
Source code in cocorum/utils.py
60 61 62 63 64 65 66 67 68 69 70 71 |
|
test_session_cookie(session_cookie)
Test if a session cookie dict is valid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_cookie
|
dict
|
The session cookie dict to test. |
required |
Returns:
Name | Type | Description |
---|---|---|
Result |
bool
|
Is the cookie dict valid? |
Source code in cocorum/utils.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
S.D.G.