Skip to content

Instantly share code, notes, and snippets.

@mtreacy002
Last active July 6, 2020 05:19
Show Gist options
  • Save mtreacy002/3cb67497f971c4651cf2cacdf5fae532 to your computer and use it in GitHub Desktop.
Save mtreacy002/3cb67497f971c4651cf2cacdf5fae532 to your computer and use it in GitHub Desktop.
Python decorator - tuple to namedtuple
@http_response_namedtuple_converter
def http_response_checker(result):
if result.status_code == HTTPStatus.NOT_FOUND:
result = http_not_found_status_checker(result)
#... more 'if' here
return result
@http_response_namedtuple_converter
def http_not_found_status_checker(result):
if result.message == messages.WRONG_USERNAME_OR_PASSWORD:
return result._replace(status_code=HTTPStatus.UNAUTHORIZED)
#... more 'if' here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment