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.
Copyright 2026 Wilbur Jaywright d.b.a. Marswide BGL.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
S.D.G.
MD5Ex
MD5 extended hashing utilities
Source code in cocorum/utils.py
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
badges_to_glyph_string(badges)
Convert a list of badges into a string of glyphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
badges
|
list[str]
|
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
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
base_10_to_36(b10)
Convert a base 10 number to base 36.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b10
|
SupportsInt
|
The base 10 number. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
B36 |
str
|
The same number in base 36. |
Source code in cocorum/utils.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
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
|
SupportsInt | 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
193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
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
124 125 126 127 128 129 130 131 132 133 134 | |
calc_password_hashes(password, salts)
Hash a password for Rumble authentication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
The password to hash. |
required |
salts
|
Sequence[str]
|
The three salts to use for hashing. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Hashes |
(str, str, str)
|
The three results of hashing. |
Source code in cocorum/utils.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
ensure_b10(num, assume_10=False)
No matter wether a number is base 36 or 10, return 10.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
SupportsInt | 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
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
ensure_b36(num, assume_10=False)
No matter wether a number is base 36 or 10, return 36.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
SupportsInt | 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
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
form_timestamp(seconds)
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
91 92 93 94 95 96 97 98 99 100 101 | |
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
252 253 254 255 256 257 258 259 260 261 262 | |
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
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
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
78 79 80 81 82 83 84 85 86 87 88 | |
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
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
S.D.G.