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

12 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:53 +0000

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.brain.helpers import register_module_extender 

9from astroid.builder import AstroidBuilder 

10from astroid.manager import AstroidManager 

11 

12 

13def _http_transform(): 

14 code = textwrap.dedent( 

15 """ 

16 from enum import IntEnum 

17 from collections import namedtuple 

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

19 

20 class HTTPStatus(IntEnum): 

21 

22 @property 

23 def phrase(self): 

24 return "" 

25 @property 

26 def value(self): 

27 return 0 

28 @property 

29 def description(self): 

30 return "" 

31 

32 # informational 

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

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

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

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

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

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

39 ACCEPTED = _HTTPStatus(202, 'Accepted', 

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

41 NON_AUTHORITATIVE_INFORMATION = _HTTPStatus(203, 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

56 'Document has not changed since given time') 

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

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

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

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

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

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

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

64 'Bad request syntax or unsupported method') 

65 UNAUTHORIZED = _HTTPStatus(401, 'Unauthorized', 

66 'No permission -- see authorization schemes') 

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

68 'No payment -- see charging schemes') 

69 FORBIDDEN = _HTTPStatus(403, 'Forbidden', 

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

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

72 'Nothing matches the given URI') 

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

74 'Specified method is invalid for this resource') 

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

76 'URI not available in preferred format') 

77 PROXY_AUTHENTICATION_REQUIRED = _HTTPStatus(407, 

78 'Proxy Authentication Required', 

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

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

81 'Request timed out; try again later') 

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

83 GONE = _HTTPStatus(410, 'Gone', 

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

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

86 'Client must specify Content-Length') 

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

88 'Precondition in headers is false') 

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

90 'Entity is too large') 

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

92 'URI is too long') 

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

94 'Entity body in unsupported format') 

95 REQUESTED_RANGE_NOT_SATISFIABLE = _HTTPStatus(416, 

96 'Requested Range Not Satisfiable', 

97 'Cannot satisfy request range') 

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

99 'Expect condition could not be satisfied') 

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

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

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

103 LOCKED = _HTTPStatus(423, 'Locked') 

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

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

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

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

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

109 'The user has sent too many requests in ' 

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

111 REQUEST_HEADER_FIELDS_TOO_LARGE = _HTTPStatus(431, 

112 'Request Header Fields Too Large', 

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

114 'fields are too large') 

115 UNAVAILABLE_FOR_LEGAL_REASONS = _HTTPStatus(451, 

116 'Unavailable For Legal Reasons', 

117 'The server is denying access to the ' 

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

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

120 'Server got itself in trouble') 

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

122 'Server does not support this operation') 

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

124 'Invalid responses from another server/proxy') 

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

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

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

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

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

130 'Cannot fulfill request') 

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

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

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

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

135 NETWORK_AUTHENTICATION_REQUIRED = _HTTPStatus(511, 

136 'Network Authentication Required', 

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

138 """ 

139 ) 

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

141 

142 

143def _http_client_transform(): 

144 return AstroidBuilder(AstroidManager()).string_build( 

145 textwrap.dedent( 

146 """ 

147 from http import HTTPStatus 

148 

149 CONTINUE = HTTPStatus.CONTINUE 

150 SWITCHING_PROTOCOLS = HTTPStatus.SWITCHING_PROTOCOLS 

151 PROCESSING = HTTPStatus.PROCESSING 

152 OK = HTTPStatus.OK 

153 CREATED = HTTPStatus.CREATED 

154 ACCEPTED = HTTPStatus.ACCEPTED 

155 NON_AUTHORITATIVE_INFORMATION = HTTPStatus.NON_AUTHORITATIVE_INFORMATION 

156 NO_CONTENT = HTTPStatus.NO_CONTENT 

157 RESET_CONTENT = HTTPStatus.RESET_CONTENT 

158 PARTIAL_CONTENT = HTTPStatus.PARTIAL_CONTENT 

159 MULTI_STATUS = HTTPStatus.MULTI_STATUS 

160 ALREADY_REPORTED = HTTPStatus.ALREADY_REPORTED 

161 IM_USED = HTTPStatus.IM_USED 

162 MULTIPLE_CHOICES = HTTPStatus.MULTIPLE_CHOICES 

163 MOVED_PERMANENTLY = HTTPStatus.MOVED_PERMANENTLY 

164 FOUND = HTTPStatus.FOUND 

165 SEE_OTHER = HTTPStatus.SEE_OTHER 

166 NOT_MODIFIED = HTTPStatus.NOT_MODIFIED 

167 USE_PROXY = HTTPStatus.USE_PROXY 

168 TEMPORARY_REDIRECT = HTTPStatus.TEMPORARY_REDIRECT 

169 PERMANENT_REDIRECT = HTTPStatus.PERMANENT_REDIRECT 

170 BAD_REQUEST = HTTPStatus.BAD_REQUEST 

171 UNAUTHORIZED = HTTPStatus.UNAUTHORIZED 

172 PAYMENT_REQUIRED = HTTPStatus.PAYMENT_REQUIRED 

173 FORBIDDEN = HTTPStatus.FORBIDDEN 

174 NOT_FOUND = HTTPStatus.NOT_FOUND 

175 METHOD_NOT_ALLOWED = HTTPStatus.METHOD_NOT_ALLOWED 

176 NOT_ACCEPTABLE = HTTPStatus.NOT_ACCEPTABLE 

177 PROXY_AUTHENTICATION_REQUIRED = HTTPStatus.PROXY_AUTHENTICATION_REQUIRED 

178 REQUEST_TIMEOUT = HTTPStatus.REQUEST_TIMEOUT 

179 CONFLICT = HTTPStatus.CONFLICT 

180 GONE = HTTPStatus.GONE 

181 LENGTH_REQUIRED = HTTPStatus.LENGTH_REQUIRED 

182 PRECONDITION_FAILED = HTTPStatus.PRECONDITION_FAILED 

183 REQUEST_ENTITY_TOO_LARGE = HTTPStatus.REQUEST_ENTITY_TOO_LARGE 

184 REQUEST_URI_TOO_LONG = HTTPStatus.REQUEST_URI_TOO_LONG 

185 UNSUPPORTED_MEDIA_TYPE = HTTPStatus.UNSUPPORTED_MEDIA_TYPE 

186 REQUESTED_RANGE_NOT_SATISFIABLE = HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE 

187 EXPECTATION_FAILED = HTTPStatus.EXPECTATION_FAILED 

188 UNPROCESSABLE_ENTITY = HTTPStatus.UNPROCESSABLE_ENTITY 

189 LOCKED = HTTPStatus.LOCKED 

190 FAILED_DEPENDENCY = HTTPStatus.FAILED_DEPENDENCY 

191 UPGRADE_REQUIRED = HTTPStatus.UPGRADE_REQUIRED 

192 PRECONDITION_REQUIRED = HTTPStatus.PRECONDITION_REQUIRED 

193 TOO_MANY_REQUESTS = HTTPStatus.TOO_MANY_REQUESTS 

194 REQUEST_HEADER_FIELDS_TOO_LARGE = HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE 

195 INTERNAL_SERVER_ERROR = HTTPStatus.INTERNAL_SERVER_ERROR 

196 NOT_IMPLEMENTED = HTTPStatus.NOT_IMPLEMENTED 

197 BAD_GATEWAY = HTTPStatus.BAD_GATEWAY 

198 SERVICE_UNAVAILABLE = HTTPStatus.SERVICE_UNAVAILABLE 

199 GATEWAY_TIMEOUT = HTTPStatus.GATEWAY_TIMEOUT 

200 HTTP_VERSION_NOT_SUPPORTED = HTTPStatus.HTTP_VERSION_NOT_SUPPORTED 

201 VARIANT_ALSO_NEGOTIATES = HTTPStatus.VARIANT_ALSO_NEGOTIATES 

202 INSUFFICIENT_STORAGE = HTTPStatus.INSUFFICIENT_STORAGE 

203 LOOP_DETECTED = HTTPStatus.LOOP_DETECTED 

204 NOT_EXTENDED = HTTPStatus.NOT_EXTENDED 

205 NETWORK_AUTHENTICATION_REQUIRED = HTTPStatus.NETWORK_AUTHENTICATION_REQUIRED 

206 """ 

207 ) 

208 ) 

209 

210 

211register_module_extender(AstroidManager(), "http", _http_transform) 

212register_module_extender(AstroidManager(), "http.client", _http_client_transform)