|
24 | 24 | import uuid |
25 | 25 | from platform import machine, processor, system |
26 | 26 | from types import MappingProxyType |
27 | | -from typing import Any, Callable, Generic, Iterable, Optional, TypeVar, Union |
| 27 | +from typing import Any, Callable, Generic, Iterable, Optional, Sized, TypeVar, Union |
28 | 28 |
|
29 | 29 | from reportportal_client.core.rp_file import RPFile |
30 | 30 |
|
@@ -260,7 +260,10 @@ def verify_value_length(attributes: Optional[Union[list[dict], dict]]) -> Option |
260 | 260 |
|
261 | 261 | my_attributes = attributes |
262 | 262 | if isinstance(my_attributes, dict): |
263 | | - my_attributes = dict_to_payload(my_attributes) |
| 263 | + converted_attributes = dict_to_payload(my_attributes) |
| 264 | + if converted_attributes is None: |
| 265 | + return None |
| 266 | + my_attributes = converted_attributes |
264 | 267 |
|
265 | 268 | result = [] |
266 | 269 | for pair in my_attributes: |
@@ -312,7 +315,7 @@ def root_uri_join(*uri_parts: str) -> str: |
312 | 315 | return "/" + uri_join(*uri_parts) |
313 | 316 |
|
314 | 317 |
|
315 | | -def get_function_params(func: Callable, args: tuple, kwargs: dict[str, Any]) -> dict[str, Any]: |
| 318 | +def get_function_params(func: Callable, args: tuple, kwargs: dict[str, Any]) -> Optional[dict[str, Any]]: |
316 | 319 | """Extract argument names from the function and combine them with values. |
317 | 320 |
|
318 | 321 | :param func: the function to get arg names |
@@ -379,7 +382,9 @@ def calculate_file_part_size(file: Optional[RPFile]) -> int: |
379 | 382 | if file is None: |
380 | 383 | return 0 |
381 | 384 | size = len(TYPICAL_FILE_PART_HEADER.format(file.name, file.content_type)) |
382 | | - size += len(file.content) |
| 385 | + content = file.content |
| 386 | + if isinstance(content, Sized): |
| 387 | + size += len(content) |
383 | 388 | return size |
384 | 389 |
|
385 | 390 |
|
@@ -435,9 +440,10 @@ def guess_content_type_from_bytes(data: Union[bytes, bytearray, list[int]]) -> s |
435 | 440 | :param data: bytes or bytearray |
436 | 441 | :return: content type |
437 | 442 | """ |
438 | | - my_data = data |
439 | 443 | if isinstance(data, list): |
440 | | - my_data = bytes(my_data) |
| 444 | + my_data: Union[bytes, bytearray] = bytes(data) |
| 445 | + else: |
| 446 | + my_data = data |
441 | 447 |
|
442 | 448 | if len(my_data) >= BYTES_TO_READ_FOR_DETECTION: |
443 | 449 | my_data = my_data[:BYTES_TO_READ_FOR_DETECTION] |
|
0 commit comments