Skip to content
Myr

Merge pull request #4394 from zaneb/document-status_codes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add documentation for available status codes

authored by Cory Benfield · committed by GitHub · parents e68ef0e, c250701 · Browse files · 2 files+34 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+34 added−16 removed

  • other:+34 added−16 removed

2 files+34 added−16 removed

modified:docs/api.rst+1 added-11 removed
107 unmodified lines
108------------------109110.. autoclass:: requests.codes111112::112.. automodule:: requests.status_codes113114 >>> requests.codes['temporary_redirect']115 307114117 >>> requests.codes.teapot118 418119120 >>> requests.codes['\o/']121 200122123124115Migrating to 1.x116----------------117118This section details the main differences between 0.x and 1.x and is meant
142 unmodified lines
modified:requests/status_codes.py+33 added-5 removed
1# -*- coding: utf-8 -*-23"""4The ``codes`` object defines a mapping from common names for HTTP statuses5to their numerical codes, accessible either as attributes or as dictionary6items.78>>> requests.codes['temporary_redirect']930710>>> requests.codes.teapot1141812>>> requests.codes['\o/']132001415Some codes have multiple names, and both upper- and lower-case versions of16the names are allowed. For example, ``codes.ok``, ``codes.OK``, and17``codes.okay`` all correspond to the HTTP status code 200.18"""1920from .structures import LookupDict2122_codes = {23
76 unmodified lines
100}101102codes = LookupDict(name='status_codes')103104def _init():87for code, titles in _codes.items():88 for title in titles:89 setattr(codes, title, code)90 if not title.startswith(('\\', '/')):91 setattr(codes, title.upper(), code)105 for code, titles in _codes.items():106 for title in titles:107 setattr(codes, title, code)108 if not title.startswith(('\\', '/')):109 setattr(codes, title.upper(), code)110111 def doc(code):112 names = ', '.join('``%s``' % n for n in _codes[code])113 return '* %d: %s' % (code, names)114115 global __doc__116 __doc__ = (__doc__ + '\n' +117 '\n'.join(doc(code) for code in sorted(_codes)))118119_init()