Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.10/site-packages/astroid/brain/brain_http.py: 79%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

14 statements  

1# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html 

2# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE 

3# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt 

4 

5"""Astroid brain hints for some of the `http` module.""" 

6import textwrap 

7 

8from astroid import nodes 

9from astroid.brain.helpers import register_module_extender 

10from astroid.builder import AstroidBuilder 

11from astroid.manager import AstroidManager 

12 

13 

14def _http_transform() -> nodes.Module: 

15 code = textwrap.dedent( 

16 """ 

17 from enum import IntEnum 

18 from collections import namedtuple 

19 _HTTPStatus = namedtuple('_HTTPStatus', 'value phrase description') 

20 

21 class HTTPStatus(IntEnum): 

22 

23 @property 

24 def phrase(self): 

25 return "" 

26 @property 

27 def value(self): 

28 return 0 

29 @property 

30 def description(self): 

31 return "" 

32 

33 # informational 

34 CONTINUE = _HTTPStatus(100, 'Continue', 'Request received, please continue') 

35 SWITCHING_PROTOCOLS = _HTTPStatus(101, 'Switching Protocols', 

36 'Switching to new protocol; obey Upgrade header') 

37 PROCESSING = _HTTPStatus(102, 'Processing', '') 

38 OK = _HTTPStatus(200, 'OK', 'Request fulfilled, document follows') 

39 CREATED = _HTTPStatus(201, 'Created', 'Document created, URL follows') 

40 ACCEPTED = _HTTPStatus(202, 'Accepted', 

41 'Request accepted, processing continues off-line') 

42 NON_AUTHORITATIVE_INFORMATION = _HTTPStatus(203, 

43 'Non-Authoritative Information', 'Request fulfilled from cache') 

44 NO_CONTENT = _HTTPStatus(204, 'No Content', 'Request fulfilled, nothing follows') 

45 RESET_CONTENT =_HTTPStatus(205, 'Reset Content', 'Clear input form for further input') 

46 PARTIAL_CONTENT = _HTTPStatus(206, 'Partial Content', 'Partial content follows') 

47 MULTI_STATUS = _HTTPStatus(207, 'Multi-Status', '') 

48 ALREADY_REPORTED = _HTTPStatus(208, 'Already Reported', '') 

49 IM_USED = _HTTPStatus(226, 'IM Used', '') 

50 MULTIPLE_CHOICES = _HTTPStatus(300, 'Multiple Choices', 

51 'Object has several resources -- see URI list') 

52 MOVED_PERMANENTLY = _HTTPStatus(301, 'Moved Permanently', 

53 'Object moved permanently -- see URI list') 

54 FOUND = _HTTPStatus(302, 'Found', 'Object moved temporarily -- see URI list') 

55 SEE_OTHER = _HTTPStatus(303, 'See Other', 'Object moved -- see Method and URL list') 

56 NOT_MODIFIED = _HTTPStatus(304, 'Not Modified', 

57 'Document has not changed since given time') 

58 USE_PROXY = _HTTPStatus(305, 'Use Proxy', 

59 'You must use proxy specified in Location to access this resource') 

60 TEMPORARY_REDIRECT = _HTTPStatus(307, 'Temporary Redirect', 

61 'Object moved temporarily -- see URI list') 

62 PERMANENT_REDIRECT = _HTTPStatus(308, 'Permanent Redirect', 

63 'Object moved permanently -- see URI list') 

64 BAD_REQUEST = _HTTPStatus(400, 'Bad Request', 

65 'Bad request syntax or unsupported method') 

66 UNAUTHORIZED = _HTTPStatus(401, 'Unauthorized', 

67 'No permission -- see authorization schemes') 

68 PAYMENT_REQUIRED = _HTTPStatus(402, 'Payment Required', 

69 'No payment -- see charging schemes') 

70 FORBIDDEN = _HTTPStatus(403, 'Forbidden', 

71 'Request forbidden -- authorization will not help') 

72 NOT_FOUND = _HTTPStatus(404, 'Not Found', 

73 'Nothing matches the given URI') 

74 METHOD_NOT_ALLOWED = _HTTPStatus(405, 'Method Not Allowed', 

75 'Specified method is invalid for this resource') 

76 NOT_ACCEPTABLE = _HTTPStatus(406, 'Not Acceptable', 

77 'URI not available in preferred format') 

78 PROXY_AUTHENTICATION_REQUIRED = _HTTPStatus(407, 

79 'Proxy Authentication Required', 

80 'You must authenticate with this proxy before proceeding') 

81 REQUEST_TIMEOUT = _HTTPStatus(408, 'Request Timeout', 

82 'Request timed out; try again later') 

83 CONFLICT = _HTTPStatus(409, 'Conflict', 'Request conflict') 

84 GONE = _HTTPStatus(410, 'Gone', 

85 'URI no longer exists and has been permanently removed') 

86 LENGTH_REQUIRED = _HTTPStatus(411, 'Length Required', 

87 'Client must specify Content-Length') 

88 PRECONDITION_FAILED = _HTTPStatus(412, 'Precondition Failed', 

89 'Precondition in headers is false') 

90 REQUEST_ENTITY_TOO_LARGE = _HTTPStatus(413, 'Request Entity Too Large', 

91 'Entity is too large') 

92 REQUEST_URI_TOO_LONG = _HTTPStatus(414, 'Request-URI Too Long', 

93 'URI is too long') 

94 UNSUPPORTED_MEDIA_TYPE = _HTTPStatus(415, 'Unsupported Media Type', 

95 'Entity body in unsupported format') 

96 REQUESTED_RANGE_NOT_SATISFIABLE = _HTTPStatus(416, 

97 'Requested Range Not Satisfiable', 

98 'Cannot satisfy request range') 

99 EXPECTATION_FAILED = _HTTPStatus(417, 'Expectation Failed', 

100 'Expect condition could not be satisfied') 

101 MISDIRECTED_REQUEST = _HTTPStatus(421, 'Misdirected Request', 

102 'Server is not able to produce a response') 

103 UNPROCESSABLE_ENTITY = _HTTPStatus(422, 'Unprocessable Entity') 

104 LOCKED = _HTTPStatus(423, 'Locked') 

105 FAILED_DEPENDENCY = _HTTPStatus(424, 'Failed Dependency') 

106 UPGRADE_REQUIRED = _HTTPStatus(426, 'Upgrade Required') 

107 PRECONDITION_REQUIRED = _HTTPStatus(428, 'Precondition Required', 

108 'The origin server requires the request to be conditional') 

109 TOO_MANY_REQUESTS = _HTTPStatus(429, 'Too Many Requests', 

110 'The user has sent too many requests in ' 

111 'a given amount of time ("rate limiting")') 

112 REQUEST_HEADER_FIELDS_TOO_LARGE = _HTTPStatus(431, 

113 'Request Header Fields Too Large', 

114 'The server is unwilling to process the request because its header ' 

115 'fields are too large') 

116 UNAVAILABLE_FOR_LEGAL_REASONS = _HTTPStatus(451, 

117 'Unavailable For Legal Reasons', 

118 'The server is denying access to the ' 

119 'resource as a consequence of a legal demand') 

120 INTERNAL_SERVER_ERROR = _HTTPStatus(500, 'Internal Server Error', 

121 'Server got itself in trouble') 

122 NOT_IMPLEMENTED = _HTTPStatus(501, 'Not Implemented', 

123 'Server does not support this operation') 

124 BAD_GATEWAY = _HTTPStatus(502, 'Bad Gateway', 

125 'Invalid responses from another server/proxy') 

126 SERVICE_UNAVAILABLE = _HTTPStatus(503, 'Service Unavailable', 

127 'The server cannot process the request due to a high load') 

128 GATEWAY_TIMEOUT = _HTTPStatus(504, 'Gateway Timeout', 

129 'The gateway server did not receive a timely response') 

130 HTTP_VERSION_NOT_SUPPORTED = _HTTPStatus(505, 'HTTP Version Not Supported', 

131 'Cannot fulfill request') 

132 VARIANT_ALSO_NEGOTIATES = _HTTPStatus(506, 'Variant Also Negotiates') 

133 INSUFFICIENT_STORAGE = _HTTPStatus(507, 'Insufficient Storage') 

134 LOOP_DETECTED = _HTTPStatus(508, 'Loop Detected') 

135 NOT_EXTENDED = _HTTPStatus(510, 'Not Extended') 

136 NETWORK_AUTHENTICATION_REQUIRED = _HTTPStatus(511, 

137 'Network Authentication Required', 

138 'The client needs to authenticate to gain network access') 

139 """ 

140 ) 

141 return AstroidBuilder(AstroidManager()).string_build(code) 

142 

143 

144def _http_client_transform() -> nodes.Module: 

145 return AstroidBuilder(AstroidManager()).string_build( 

146 textwrap.dedent( 

147 """ 

148 from http import HTTPStatus 

149 

150 CONTINUE = HTTPStatus.CONTINUE 

151 SWITCHING_PROTOCOLS = HTTPStatus.SWITCHING_PROTOCOLS 

152 PROCESSING = HTTPStatus.PROCESSING 

153 OK = HTTPStatus.OK 

154 CREATED = HTTPStatus.CREATED 

155 ACCEPTED = HTTPStatus.ACCEPTED 

156 NON_AUTHORITATIVE_INFORMATION = HTTPStatus.NON_AUTHORITATIVE_INFORMATION 

157 NO_CONTENT = HTTPStatus.NO_CONTENT 

158 RESET_CONTENT = HTTPStatus.RESET_CONTENT 

159 PARTIAL_CONTENT = HTTPStatus.PARTIAL_CONTENT 

160 MULTI_STATUS = HTTPStatus.MULTI_STATUS 

161 ALREADY_REPORTED = HTTPStatus.ALREADY_REPORTED 

162 IM_USED = HTTPStatus.IM_USED 

163 MULTIPLE_CHOICES = HTTPStatus.MULTIPLE_CHOICES 

164 MOVED_PERMANENTLY = HTTPStatus.MOVED_PERMANENTLY 

165 FOUND = HTTPStatus.FOUND 

166 SEE_OTHER = HTTPStatus.SEE_OTHER 

167 NOT_MODIFIED = HTTPStatus.NOT_MODIFIED 

168 USE_PROXY = HTTPStatus.USE_PROXY 

169 TEMPORARY_REDIRECT = HTTPStatus.TEMPORARY_REDIRECT 

170 PERMANENT_REDIRECT = HTTPStatus.PERMANENT_REDIRECT 

171 BAD_REQUEST = HTTPStatus.BAD_REQUEST 

172 UNAUTHORIZED = HTTPStatus.UNAUTHORIZED 

173 PAYMENT_REQUIRED = HTTPStatus.PAYMENT_REQUIRED 

174 FORBIDDEN = HTTPStatus.FORBIDDEN 

175 NOT_FOUND = HTTPStatus.NOT_FOUND 

176 METHOD_NOT_ALLOWED = HTTPStatus.METHOD_NOT_ALLOWED 

177 NOT_ACCEPTABLE = HTTPStatus.NOT_ACCEPTABLE 

178 PROXY_AUTHENTICATION_REQUIRED = HTTPStatus.PROXY_AUTHENTICATION_REQUIRED 

179 REQUEST_TIMEOUT = HTTPStatus.REQUEST_TIMEOUT 

180 CONFLICT = HTTPStatus.CONFLICT 

181 GONE = HTTPStatus.GONE 

182 LENGTH_REQUIRED = HTTPStatus.LENGTH_REQUIRED 

183 PRECONDITION_FAILED = HTTPStatus.PRECONDITION_FAILED 

184 REQUEST_ENTITY_TOO_LARGE = HTTPStatus.REQUEST_ENTITY_TOO_LARGE 

185 REQUEST_URI_TOO_LONG = HTTPStatus.REQUEST_URI_TOO_LONG 

186 UNSUPPORTED_MEDIA_TYPE = HTTPStatus.UNSUPPORTED_MEDIA_TYPE 

187 REQUESTED_RANGE_NOT_SATISFIABLE = HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE 

188 EXPECTATION_FAILED = HTTPStatus.EXPECTATION_FAILED 

189 UNPROCESSABLE_ENTITY = HTTPStatus.UNPROCESSABLE_ENTITY 

190 LOCKED = HTTPStatus.LOCKED 

191 FAILED_DEPENDENCY = HTTPStatus.FAILED_DEPENDENCY 

192 UPGRADE_REQUIRED = HTTPStatus.UPGRADE_REQUIRED 

193 PRECONDITION_REQUIRED = HTTPStatus.PRECONDITION_REQUIRED 

194 TOO_MANY_REQUESTS = HTTPStatus.TOO_MANY_REQUESTS 

195 REQUEST_HEADER_FIELDS_TOO_LARGE = HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE 

196 INTERNAL_SERVER_ERROR = HTTPStatus.INTERNAL_SERVER_ERROR 

197 NOT_IMPLEMENTED = HTTPStatus.NOT_IMPLEMENTED 

198 BAD_GATEWAY = HTTPStatus.BAD_GATEWAY 

199 SERVICE_UNAVAILABLE = HTTPStatus.SERVICE_UNAVAILABLE 

200 GATEWAY_TIMEOUT = HTTPStatus.GATEWAY_TIMEOUT 

201 HTTP_VERSION_NOT_SUPPORTED = HTTPStatus.HTTP_VERSION_NOT_SUPPORTED 

202 VARIANT_ALSO_NEGOTIATES = HTTPStatus.VARIANT_ALSO_NEGOTIATES 

203 INSUFFICIENT_STORAGE = HTTPStatus.INSUFFICIENT_STORAGE 

204 LOOP_DETECTED = HTTPStatus.LOOP_DETECTED 

205 NOT_EXTENDED = HTTPStatus.NOT_EXTENDED 

206 NETWORK_AUTHENTICATION_REQUIRED = HTTPStatus.NETWORK_AUTHENTICATION_REQUIRED 

207 """ 

208 ) 

209 ) 

210 

211 

212def register(manager: AstroidManager) -> None: 

213 register_module_extender(manager, "http", _http_transform) 

214 register_module_extender(manager, "http.client", _http_client_transform)