77import urllib
88from http .client import HTTPResponse
99from ssl import SSLContext
10- from typing import Dict , Optional , List
10+ from typing import Dict , Optional , List , Any
1111from urllib .error import HTTPError
1212from urllib .request import Request , urlopen , OpenerDirector , ProxyHandler , HTTPSHandler
1313
@@ -89,7 +89,7 @@ def __init__(
8989 def schemas (
9090 self ,
9191 * ,
92- query_params : Optional [Dict [str , any ]] = None ,
92+ query_params : Optional [Dict [str , Any ]] = None ,
9393 headers : Optional [Dict [str , str ]] = None ,
9494 ) -> AuditLogsResponse :
9595 """Returns information about the kind of objects which the Audit Logs API
@@ -111,7 +111,7 @@ def schemas(
111111 def actions (
112112 self ,
113113 * ,
114- query_params : Optional [Dict [str , any ]] = None ,
114+ query_params : Optional [Dict [str , Any ]] = None ,
115115 headers : Optional [Dict [str , str ]] = None ,
116116 ) -> AuditLogsResponse :
117117 """Returns information about the kind of actions that the Audit Logs API
@@ -140,7 +140,7 @@ def logs(
140140 action : Optional [str ] = None ,
141141 actor : Optional [str ] = None ,
142142 entity : Optional [str ] = None ,
143- additional_query_params : Optional [Dict [str , any ]] = None ,
143+ additional_query_params : Optional [Dict [str , Any ]] = None ,
144144 headers : Optional [Dict [str , str ]] = None ,
145145 ) -> AuditLogsResponse :
146146 """This is the primary endpoint for retrieving actual audit events from your organization.
@@ -188,8 +188,8 @@ def api_call(
188188 * ,
189189 http_verb : str = "GET" ,
190190 path : str ,
191- query_params : Optional [Dict [str , any ]] = None ,
192- body_params : Optional [Dict [str , any ]] = None ,
191+ query_params : Optional [Dict [str , Any ]] = None ,
192+ body_params : Optional [Dict [str , Any ]] = None ,
193193 headers : Optional [Dict [str , str ]] = None ,
194194 ) -> AuditLogsResponse :
195195 """Performs a Slack API request and returns the result."""
@@ -214,7 +214,7 @@ def _perform_http_request(
214214 * ,
215215 http_verb : str = "GET" ,
216216 url : str ,
217- body : Optional [Dict [str , any ]] = None ,
217+ body : Optional [Dict [str , Any ]] = None ,
218218 headers : Dict [str , str ],
219219 ) -> AuditLogsResponse :
220220 if body is not None :
@@ -261,11 +261,20 @@ def _perform_http_request(
261261 url = url ,
262262 status_code = e .code ,
263263 raw_body = response_body ,
264- headers = e .headers ,
264+ headers = dict ( e .headers . items ()) ,
265265 )
266266 if e .code == 429 :
267267 # for backward-compatibility with WebClient (v.2.5.0 or older)
268- resp .headers ["Retry-After" ] = resp .headers ["retry-after" ]
268+ if (
269+ "retry-after" not in resp .headers
270+ and "Retry-After" in resp .headers
271+ ):
272+ resp .headers ["retry-after" ] = resp .headers ["Retry-After" ]
273+ if (
274+ "Retry-After" not in resp .headers
275+ and "retry-after" in resp .headers
276+ ):
277+ resp .headers ["Retry-After" ] = resp .headers ["retry-after" ]
269278 _debug_log_response (self .logger , resp )
270279
271280 # Try to find a retry handler for this error
@@ -356,20 +365,20 @@ def _perform_http_request_internal(
356365 raise SlackRequestError (f"Invalid URL detected: { url } " )
357366
358367 # NOTE: BAN-B310 is already checked above
359- resp : Optional [HTTPResponse ] = None
368+ http_resp : Optional [HTTPResponse ] = None
360369 if opener :
361- resp = opener .open (req , timeout = self .timeout ) # skipcq: BAN-B310
370+ http_resp = opener .open (req , timeout = self .timeout ) # skipcq: BAN-B310
362371 else :
363- resp = urlopen ( # skipcq: BAN-B310
372+ http_resp = urlopen ( # skipcq: BAN-B310
364373 req , context = self .ssl , timeout = self .timeout
365374 )
366- charset : str = resp .headers .get_content_charset () or "utf-8"
367- response_body : str = resp .read ().decode (charset )
375+ charset : str = http_resp .headers .get_content_charset () or "utf-8"
376+ response_body : str = http_resp .read ().decode (charset )
368377 resp = AuditLogsResponse (
369378 url = url ,
370- status_code = resp .status ,
379+ status_code = http_resp .status ,
371380 raw_body = response_body ,
372- headers = resp .headers ,
381+ headers = http_resp .headers ,
373382 )
374383 _debug_log_response (self .logger , resp )
375384 return resp
0 commit comments