codekingpro/portable-devtools
114k
1from enum import IntEnum, unique2 3 4@unique5class ExitStatus(IntEnum):6 """Program exit status code constants."""7 SUCCESS = 08 ERROR = 19 ERROR_TIMEOUT = 210 11 # See --check-status12 ERROR_HTTP_3XX = 313 ERROR_HTTP_4XX = 414 ERROR_HTTP_5XX = 515 16 ERROR_TOO_MANY_REDIRECTS = 617 PLUGIN_ERROR = 718 # 128+2 SIGINT19 # <http://www.tldp.org/LDP/abs/html/exitcodes.html>20 ERROR_CTRL_C = 13021 22 23def http_status_to_exit_status(http_status: int, follow=False) -> ExitStatus:24 """25 Translate HTTP status code to exit status code.26 27 (Relevant only when invoked with --check-status or --download.)28 29 """30 if 300 <= http_status <= 399 and not follow:31 # Redirect32 return ExitStatus.ERROR_HTTP_3XX33 elif 400 <= http_status <= 499:34 # Client Error35 return ExitStatus.ERROR_HTTP_4XX36 elif 500 <= http_status <= 599:37 # Server Error38 return ExitStatus.ERROR_HTTP_5XX39 else:40 return ExitStatus.SUCCESS41 