James Bennett on Nostr: A quick #Python tip/plea: the standard library "http" module, since Python 3.5, has ...
A quick #Python tip/plea: the standard library "http" module, since Python 3.5, has contained an enum of the HTTP status codes:
https://docs.python.org/3/library/http.html#http.HTTPStatusYou can import it and write things like
assert my_success_response.status_code == HTTPStatus.OK
And this replaces both raw integer "magic number" values and framework-specific constants/enums, so you no longer have to remember that Web Framework A calls it "HTTP_200_OK" while Framework B calls it "HTTP_STATUS_OK", etc.
I plan to ensure all of my own projects switch to this as their standard way of referencing status codes, and urge everyone else to do the same (and web frameworks to deprecate and begin removal of their own variations on status-code constants/enums).
Published at
2023-09-12 21:54:36Event JSON
{
"id": "15355448d80d2ded12824044398ea5ebc4d9812b527d10289911e3ad0ba0a1d2",
"pubkey": "8002422e202ebb643b31c68e25d30ef9f41e21fce2dd1aea9a171b41e18a612b",
"created_at": 1694555676,
"kind": 1,
"tags": [
[
"t",
"python"
],
[
"proxy",
"https://infosec.exchange/users/ubernostrum/statuses/111054400793530233",
"activitypub"
]
],
"content": "A quick #Python tip/plea: the standard library \"http\" module, since Python 3.5, has contained an enum of the HTTP status codes: https://docs.python.org/3/library/http.html#http.HTTPStatus\n\nYou can import it and write things like\n\nassert my_success_response.status_code == HTTPStatus.OK\n\nAnd this replaces both raw integer \"magic number\" values and framework-specific constants/enums, so you no longer have to remember that Web Framework A calls it \"HTTP_200_OK\" while Framework B calls it \"HTTP_STATUS_OK\", etc.\n\nI plan to ensure all of my own projects switch to this as their standard way of referencing status codes, and urge everyone else to do the same (and web frameworks to deprecate and begin removal of their own variations on status-code constants/enums).",
"sig": "81dc7ecd4bc65fc04f1341b8f7fd6bf7316663635d63337e90ca30603d43200da0d89e5d4df0eaf2bbff9e77dca7a1095ca22a5b3f17621e2306ed3009b5e1a5"
}