2 This file contains the constants for the actions program.
3 These are used to standardise error logging and other sections of the program.
6from typing
import Union
8from datetime
import datetime, date
9from .secrets
import Secrets
13TYPE_UNKNOWN =
"UNKNOWN LOGGING TYPE"
15TYPE_SERVICE =
"SERVICE"
16TYPE_SERVICE_TRIGGER =
"SERVICE TRIGGER"
17TYPE_SERVICE_ACTION =
"SERVICE ACTION"
19TYPE_UNDEFINED =
"UNDEFINED"
20TYPE_MISMATCH =
"MISMATCH"
21TYPE_BEFORE_ASSIGNEMENT =
"REFERENCED BEFORE ASSIGNEMENT"
22TYPE_DIV_ZERO =
"DIVISION BY ZERO"
23TYPE_SYNTAX_ERROR =
"SYNTAX ERROR"
24TYPE_RUNTIME_ERROR =
"RUNTIME ERROR"
25TYPE_INCOMPARABLE =
"INCOMPARABLE TYPES"
26TYPE_OVERFLOW =
"VALUE OVERFLOW"
27TYPE_UNDERFLOW =
"VALUE UNDERFLOW"
42LEVEL_UNKNOWN =
"UNKNOWN"
44LEVEL_SUCCESS =
"SUCCESS"
46LEVEL_WARNING =
"WARNING"
48LEVEL_CRITICAL =
"CRITICAL"
53MSG_UNKNOWN =
"Unknown: Operation executed with unknown status."
54MSG_INFO =
"Information: Operation executed without any issues."
55MSG_SUCCESS =
"Success: Operation completed successfully."
56MSG_DEBUG =
"Debug: Tracking detailed operational data for diagnostics."
57MSG_WARNING =
"Warning: Potential issue detected. Review is recommended."
58MSG_ERROR =
"Error: Operation could not be completed successfully."
59MSG_CRITICAL =
"Critical: Immediate attention required to prevent severe impact."
60MSG_FATAL =
"Fatal: System failure imminent. Immediate intervention necessary."
65 CODE_UNKNOWN: LEVEL_UNKNOWN,
66 CODE_INFO: LEVEL_INFO,
67 CODE_SUCCESS: LEVEL_SUCCESS,
68 CODE_DEBUG: LEVEL_DEBUG,
69 CODE_WARNING: LEVEL_WARNING,
70 CODE_ERROR: LEVEL_ERROR,
71 CODE_CRITICAL: LEVEL_CRITICAL,
72 CODE_FATAL: LEVEL_FATAL,
75LOG_MESSAGE_EQUIVALENCE = {
76 CODE_UNKNOWN: MSG_UNKNOWN,
78 CODE_SUCCESS: MSG_SUCCESS,
79 CODE_DEBUG: MSG_DEBUG,
80 CODE_WARNING: MSG_WARNING,
81 CODE_ERROR: MSG_ERROR,
82 CODE_CRITICAL: MSG_CRITICAL,
83 CODE_FATAL: MSG_FATAL,
97 TYPE_BEFORE_ASSIGNEMENT,
143 """Compares two values and returns:
149 a: The first value to compare.
150 b: The second value to compare.
153 int: -1, 0, or 1 based on the comparison.
185 "equal to": operator.eq,
186 "less than": operator.lt,
187 "not equal to": operator.ne,
188 "greater than": operator.gt,
189 "less than or equal to": operator.le,
190 "greater than or equal to": operator.ge,
194SECRETS_EQUIVALENCE = {
195 "secrets.now": Secrets.now_server,
196 "secrets.current_date": Secrets.current_date,
197 "secrets.current_time": Secrets.current_time,
198 "secrets.now_utc": Secrets.now_utc,
199 "secrets.current_date_utc": Secrets.current_date_utc,
200 "secrets.current_time_utc": Secrets.current_time_utc,
201 "secrets.now_server": Secrets.now_server,
202 "secrets.current_date_server": Secrets.current_date_server,
203 "secrets.current_time_server": Secrets.current_time_server,
204 "secret.now": Secrets.now_server,
205 "secret.current_date": Secrets.current_date,
206 "secret.current_time": Secrets.current_time,
207 "secret.now_utc": Secrets.now_utc,
208 "secret.current_date_utc": Secrets.current_date_utc,
209 "secret.current_time_utc": Secrets.current_time_utc,
210 "secret.now_server": Secrets.now_server,
211 "secret.current_date_server": Secrets.current_date_server,
212 "secret.current_time_server": Secrets.current_time_server,
213 "now": Secrets.now_server,
214 "current_date": Secrets.current_date,
215 "current_time": Secrets.current_time,
216 "now_utc": Secrets.now_utc,
217 "current_date_utc": Secrets.current_date_utc,
218 "current_time_utc": Secrets.current_time_utc,
219 "now_server": Secrets.now_server,
220 "current_date_server": Secrets.current_date_server,
221 "current_time_server": Secrets.current_time_server
227CONTENT_TYPE_KEY =
"type"
228CONTENT_KEY =
"content"
230CONTENT_TYPES_JSON = {
"application/json",
"application/ld+json"}
231CONTENT_TYPES_TEXT = {
238CONTENT_TYPES_XML = {
"application/xml",
"application/xhtml+xml",
"text/xml"}
239CONTENT_TYPES_BINARY = {
240 "application/octet-stream",
243 "application/x-gzip",
245 "application/x-7z-compressed",
246 "application/x-rar-compressed",
247 "application/x-bzip2",
249 "application/x-lzip",
250 "application/x-lzma",
251 "application/x-lzop",
252 "application/x-snappy-framed",
255 "application/x-cpio",
256 "application/x-shar",
257 "application/x-compress",
259 "application/x-stuffit",
260 "application/x-stuffitx",
261 "application/x-iso9660-image",
263 "application/x-gear",
265 "application/x-cfs-compressed",
266 "application/x-astrotite-afa",
267 "application/x-squeeze",
268 "application/x-lzh-compressed",
270 "application/x-lrzip",
271 "application/x-lrzip-compressed-tar",
285 "application/x-java-archive",
286 "application/x-webarchive",
294 "application/java-archive",
295 "application/x-shockwave-flash",
296 "application/x-www-form-urlencoded",
297 "application/vnd.ms-excel",
298 "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
299 "application/vnd.ms-powerpoint",
300 "application/vnd.openxmlformats-officedocument.presentationml.presentation",
301 "application/msword",
302 "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
303 "application/vnd.android.package-archive"
305CONTENT_TYPES_AUDIO = {
316 "audio/vnd.rn-realaudio"
318CONTENT_TYPES_IMAGES = {
325 "image/vnd.microsoft.icon",
330CONTENT_TYPES_VIDEO = {
341RESPONSE_NODE_BODY_KEY =
"body"
342RESPONSE_NODE_BODY_TYPE_KEY =
"body_type"
343RESPONSE_NODE_HEADERS_KEY =
"headers"
344RESPONSE_NODE_HEADERS_TYPE_KEY =
"headers_type"
345RESPONSE_NODE_ENCODING_KEY =
"encoding"
346RESPONSE_NODE_HISTORY_KEY =
"history"
347RESPONSE_NODE_COOKIES_KEY =
"cookies"
348RESPONSE_NODE_ELAPSED_KEY =
"elapsed"
349RESPONSE_NODE_REASON_KEY =
"reason"
350RESPONSE_NODE_URL_KEY =
"url"
351RESPONSE_NODE_METHOD_KEY =
"method"
352RESPONSE_NODE_STATUS_CODE_KEY =
"status_code"
354RESPONSE_NODE_KEY_EQUIVALENCE = {
355 "elapsed": RESPONSE_NODE_ELAPSED_KEY,
356 "url": RESPONSE_NODE_URL_KEY,
357 "urls": RESPONSE_NODE_URL_KEY,
358 "reason": RESPONSE_NODE_REASON_KEY,
359 "reasons": RESPONSE_NODE_REASON_KEY,
360 "encoding": RESPONSE_NODE_ENCODING_KEY,
361 "encodings": RESPONSE_NODE_ENCODING_KEY,
362 "cookie": RESPONSE_NODE_COOKIES_KEY,
363 "cookies": RESPONSE_NODE_COOKIES_KEY,
364 "header": RESPONSE_NODE_HEADERS_KEY,
365 "headers": RESPONSE_NODE_HEADERS_KEY,
366 "method": RESPONSE_NODE_METHOD_KEY,
367 "methods": RESPONSE_NODE_METHOD_KEY,
368 "history": RESPONSE_NODE_HISTORY_KEY,
369 "historie": RESPONSE_NODE_HISTORY_KEY,
370 "historys": RESPONSE_NODE_HISTORY_KEY,
371 "histore": RESPONSE_NODE_HISTORY_KEY,
372 "histores": RESPONSE_NODE_HISTORY_KEY,
373 "histories": RESPONSE_NODE_HISTORY_KEY,
374 "body_type": RESPONSE_NODE_BODY_TYPE_KEY,
375 "body_types": RESPONSE_NODE_BODY_TYPE_KEY,
376 "bodys_type": RESPONSE_NODE_BODY_TYPE_KEY,
377 "bodies_type": RESPONSE_NODE_BODY_TYPE_KEY,
378 "bodies_types": RESPONSE_NODE_BODY_TYPE_KEY,
379 "header_type": RESPONSE_NODE_HEADERS_TYPE_KEY,
380 "headers_type": RESPONSE_NODE_HEADERS_TYPE_KEY,
381 "header_types": RESPONSE_NODE_HEADERS_TYPE_KEY,
382 "headers_types": RESPONSE_NODE_HEADERS_TYPE_KEY,
383 "body": RESPONSE_NODE_BODY_KEY,
384 "bodys": RESPONSE_NODE_BODY_KEY,
385 "bodies": RESPONSE_NODE_BODY_KEY,
386 "bodie": RESPONSE_NODE_BODY_KEY,
387 "status_code": RESPONSE_NODE_STATUS_CODE_KEY,
388 "status_codes": RESPONSE_NODE_STATUS_CODE_KEY,
389 "statuses_codes": RESPONSE_NODE_STATUS_CODE_KEY,
390 "statuses_code": RESPONSE_NODE_STATUS_CODE_KEY,
391 "statuss_code": RESPONSE_NODE_STATUS_CODE_KEY,
392 "statuss_codes": RESPONSE_NODE_STATUS_CODE_KEY
400 from datetime
import datetime
402 current_time = datetime.now().isoformat(sep=
"T", timespec=
"seconds")
403 expiration = datetime.fromisoformat(oauth_token)
405 if current_time >= expiration:
412BRUTEFORCE_DATETIME_FORMATS = [
413 "%Y-%m-%dT%H:%M:%S.%f%z",
414 "%Y-%m-%dT%H:%M:%S%z",
419BRUTEFORCE_DATE_FORMATS = [
428 Detects the type of the input string and converts it to the appropriate Python type.
431 value (str): The string to be converted.
434 int, float, bool, None, datetime, date, or str: The converted value based on its detected type.
436 if isinstance(value, str)
is False:
438 value = value.strip()
439 lvalue = value.lower()
444 if lvalue ==
"false":
455 for fmt
in BRUTEFORCE_DATETIME_FORMATS:
457 return datetime.strptime(value, fmt)
461 for fmt
in BRUTEFORCE_DATE_FORMATS:
463 return datetime.strptime(value, fmt).date()
bool check_if_oauth_is_valid(str oauth_token)
Union[int, float, bool, None, datetime, date, str] detect_and_convert(str value)