source: titan/mediathek/localhoster/lib/requests/status_codes.py @ 44466

Last change on this file since 44466 was 44466, checked in by obi, 4 years ago

fix cloudflare

File size: 4.0 KB
Line 
1# -*- coding: utf-8 -*-
2
3r"""
4The ``codes`` object defines a mapping from common names for HTTP statuses
5to their numerical codes, accessible either as attributes or as dictionary
6items.
7
8>>> requests.codes['temporary_redirect']
9307
10>>> requests.codes.teapot
11418
12>>> requests.codes['\o/']
13200
14
15Some codes have multiple names, and both upper- and lower-case versions of
16the names are allowed. For example, ``codes.ok``, ``codes.OK``, and
17``codes.okay`` all correspond to the HTTP status code 200.
18"""
19
20from .structures import LookupDict
21
22_codes = {
23
24    # Informational.
25    100: ('continue',),
26    101: ('switching_protocols',),
27    102: ('processing',),
28    103: ('checkpoint',),
29    122: ('uri_too_long', 'request_uri_too_long'),
30    200: ('ok', 'okay', 'all_ok', 'all_okay', 'all_good', '\\o/', '✓'),
31    201: ('created',),
32    202: ('accepted',),
33    203: ('non_authoritative_info', 'non_authoritative_information'),
34    204: ('no_content',),
35    205: ('reset_content', 'reset'),
36    206: ('partial_content', 'partial'),
37    207: ('multi_status', 'multiple_status', 'multi_stati', 'multiple_stati'),
38    208: ('already_reported',),
39    226: ('im_used',),
40
41    # Redirection.
42    300: ('multiple_choices',),
43    301: ('moved_permanently', 'moved', '\\o-'),
44    302: ('found',),
45    303: ('see_other', 'other'),
46    304: ('not_modified',),
47    305: ('use_proxy',),
48    306: ('switch_proxy',),
49    307: ('temporary_redirect', 'temporary_moved', 'temporary'),
50    308: ('permanent_redirect',
51          'resume_incomplete', 'resume',),  # These 2 to be removed in 3.0
52
53    # Client Error.
54    400: ('bad_request', 'bad'),
55    401: ('unauthorized',),
56    402: ('payment_required', 'payment'),
57    403: ('forbidden',),
58    404: ('not_found', '-o-'),
59    405: ('method_not_allowed', 'not_allowed'),
60    406: ('not_acceptable',),
61    407: ('proxy_authentication_required', 'proxy_auth', 'proxy_authentication'),
62    408: ('request_timeout', 'timeout'),
63    409: ('conflict',),
64    410: ('gone',),
65    411: ('length_required',),
66    412: ('precondition_failed', 'precondition'),
67    413: ('request_entity_too_large',),
68    414: ('request_uri_too_large',),
69    415: ('unsupported_media_type', 'unsupported_media', 'media_type'),
70    416: ('requested_range_not_satisfiable', 'requested_range', 'range_not_satisfiable'),
71    417: ('expectation_failed',),
72    418: ('im_a_teapot', 'teapot', 'i_am_a_teapot'),
73    421: ('misdirected_request',),
74    422: ('unprocessable_entity', 'unprocessable'),
75    423: ('locked',),
76    424: ('failed_dependency', 'dependency'),
77    425: ('unordered_collection', 'unordered'),
78    426: ('upgrade_required', 'upgrade'),
79    428: ('precondition_required', 'precondition'),
80    429: ('too_many_requests', 'too_many'),
81    431: ('header_fields_too_large', 'fields_too_large'),
82    444: ('no_response', 'none'),
83    449: ('retry_with', 'retry'),
84    450: ('blocked_by_windows_parental_controls', 'parental_controls'),
85    451: ('unavailable_for_legal_reasons', 'legal_reasons'),
86    499: ('client_closed_request',),
87
88    # Server Error.
89    500: ('internal_server_error', 'server_error', '/o\\', '✗'),
90    501: ('not_implemented',),
91    502: ('bad_gateway',),
92    503: ('service_unavailable', 'unavailable'),
93    504: ('gateway_timeout',),
94    505: ('http_version_not_supported', 'http_version'),
95    506: ('variant_also_negotiates',),
96    507: ('insufficient_storage',),
97    509: ('bandwidth_limit_exceeded', 'bandwidth'),
98    510: ('not_extended',),
99    511: ('network_authentication_required', 'network_auth', 'network_authentication'),
100}
101
102codes = LookupDict(name='status_codes')
103
104def _init():
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)
110
111    def doc(code):
112        names = ', '.join('``%s``' % n for n in _codes[code])
113        return '* %d: %s' % (code, names)
114
115    global __doc__
116    __doc__ = (__doc__ + '\n' +
117               '\n'.join(doc(code) for code in sorted(_codes))
118               if __doc__ is not None else None)
119
120_init()
Note: See TracBrowser for help on using the repository browser.