47
47
from adafruit_connection_manager import get_connection_manager
48
48
49
49
if not sys .implementation .name == "circuitpython" :
50
- from io import FileIO
51
50
from types import TracebackType
52
51
from typing import Any , Dict , Optional , Type
53
52
@@ -345,6 +344,14 @@ def iter_content(self, chunk_size: int = 1, decode_unicode: bool = False) -> byt
345
344
self .close ()
346
345
347
346
347
+ def _generate_boundary_str ():
348
+ hex_characters = "0123456789abcdef"
349
+ _boundary = ""
350
+ for _ in range (32 ):
351
+ _boundary += random .choice (hex_characters )
352
+ return _boundary
353
+
354
+
348
355
class Session :
349
356
"""HTTP session that shares sockets and ssl context."""
350
357
@@ -396,13 +403,6 @@ def _send(socket: SocketType, data: bytes):
396
403
def _send_as_bytes (self , socket : SocketType , data : str ):
397
404
return self ._send (socket , bytes (data , "utf-8" ))
398
405
399
- def _generate_boundary_str (self ):
400
- hex_characters = "0123456789abcdef"
401
- _boundary = ""
402
- for i in range (32 ):
403
- _boundary += random .choice (hex_characters )
404
- return _boundary
405
-
406
406
def _send_header (self , socket , header , value ):
407
407
if value is None :
408
408
return
@@ -414,8 +414,7 @@ def _send_header(self, socket, header, value):
414
414
self ._send_as_bytes (socket , value )
415
415
self ._send (socket , b"\r \n " )
416
416
417
- # pylint: disable=too-many-arguments
418
- def _send_request (
417
+ def _send_request ( # pylint: disable=too-many-arguments
419
418
self ,
420
419
socket : SocketType ,
421
420
host : str ,
@@ -425,7 +424,7 @@ def _send_request(
425
424
data : Any ,
426
425
json : Any ,
427
426
files : Optional [Dict [str , tuple ]],
428
- ):
427
+ ): # pylint: disable=too-many-branches,too-many-locals,too-many-statements
429
428
# Check headers
430
429
self ._check_headers (headers )
431
430
@@ -464,8 +463,9 @@ def _send_request(
464
463
supplied_headers = {header .lower () for header in headers }
465
464
boundary_str = None
466
465
466
+ # pylint: disable=too-many-nested-blocks
467
467
if files is not None and isinstance (files , dict ):
468
- boundary_str = self . _generate_boundary_str ()
468
+ boundary_str = _generate_boundary_str ()
469
469
content_type_header = f"multipart/form-data; boundary={ boundary_str } "
470
470
471
471
for fieldname in files .keys ():
0 commit comments