| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,6 @@ | |||
| 8 | 8 | ||
| 9 | 9 | import requests | |
| 10 | 10 | import requests.utils | |
| 11 | - from requests_toolbelt.multipart.encoder import MultipartEncoder # type: ignore | ||
| 12 | 11 | ||
| 13 | 12 | import gitlab | |
| 14 | 13 | import gitlab.config | |
@@ -637,38 +636,6 @@ def _check_redirects(result: requests.Response) -> None: | |||
| 637 | 636 | ) | |
| 638 | 637 | ) | |
| 639 | 638 | ||
| 640 | - @staticmethod | ||
| 641 | - def _prepare_send_data( | ||
| 642 | - files: Optional[Dict[str, Any]] = None, | ||
| 643 | - post_data: Optional[Union[Dict[str, Any], bytes]] = None, | ||
| 644 | - raw: bool = False, | ||
| 645 | - ) -> Tuple[ | ||
| 646 | - Optional[Union[Dict[str, Any], bytes]], | ||
| 647 | - Optional[Union[Dict[str, Any], MultipartEncoder]], | ||
| 648 | - str, | ||
| 649 | - ]: | ||
| 650 | - if files: | ||
| 651 | - if post_data is None: | ||
| 652 | - post_data = {} | ||
| 653 | - else: | ||
| 654 | - # booleans does not exists for data (neither for MultipartEncoder): | ||
| 655 | - # cast to string int to avoid: 'bool' object has no attribute 'encode' | ||
| 656 | - if TYPE_CHECKING: | ||
| 657 | - assert isinstance(post_data, dict) | ||
| 658 | - for k, v in post_data.items(): | ||
| 659 | - if isinstance(v, bool): | ||
| 660 | - post_data[k] = str(int(v)) | ||
| 661 | - post_data["file"] = files.get("file") | ||
| 662 | - post_data["avatar"] = files.get("avatar") | ||
| 663 | - | ||
| 664 | - data = MultipartEncoder(post_data) | ||
| 665 | - return (None, data, data.content_type) | ||
| 666 | - | ||
| 667 | - if raw and post_data: | ||
| 668 | - return (None, post_data, "application/octet-stream") | ||
| 669 | - | ||
| 670 | - return (post_data, None, "application/json") | ||
| 671 | - | ||
| 672 | 639 | def http_request( | |
| 673 | 640 | self, | |
| 674 | 641 | verb: str, | |
@@ -746,7 +713,9 @@ def http_request( | |||
| 746 | 713 | retry_transient_errors = self.retry_transient_errors | |
| 747 | 714 | ||
| 748 | 715 | # We need to deal with json vs. data when uploading files | |
| 749 | - json, data, content_type = self._prepare_send_data(files, post_data, raw) | ||
| 716 | + json, data, content_type = self.http_backend.prepare_send_data( | ||
| 717 | + files, post_data, raw | ||
| 718 | + ) | ||
| 750 | 719 | opts["headers"]["Content-type"] = content_type | |
| 751 | 720 | ||
| 752 | 721 | cur_retries = 0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | from __future__ import annotations | |
| 2 | 2 | ||
| 3 | - from typing import Any, Dict, Optional, Union | ||
| 3 | + from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union | ||
| 4 | 4 | ||
| 5 | 5 | import requests | |
| 6 | 6 | from requests.structures import CaseInsensitiveDict | |
@@ -39,6 +39,38 @@ def __init__(self, session: Optional[requests.Session] = None) -> None: | |||
| 39 | 39 | def client(self) -> requests.Session: | |
| 40 | 40 | return self._client | |
| 41 | 41 | ||
| 42 | + @staticmethod | ||
| 43 | + def prepare_send_data( | ||
| 44 | + files: Optional[Dict[str, Any]] = None, | ||
| 45 | + post_data: Optional[Union[Dict[str, Any], bytes]] = None, | ||
| 46 | + raw: bool = False, | ||
| 47 | + ) -> Tuple[ | ||
| 48 | + Optional[Union[Dict[str, Any], bytes]], | ||
| 49 | + Optional[Union[Dict[str, Any], MultipartEncoder]], | ||
| 50 | + str, | ||
| 51 | + ]: | ||
| 52 | + if files: | ||
| 53 | + if post_data is None: | ||
| 54 | + post_data = {} | ||
| 55 | + else: | ||
| 56 | + # booleans does not exists for data (neither for MultipartEncoder): | ||
| 57 | + # cast to string int to avoid: 'bool' object has no attribute 'encode' | ||
| 58 | + if TYPE_CHECKING: | ||
| 59 | + assert isinstance(post_data, dict) | ||
| 60 | + for k, v in post_data.items(): | ||
| 61 | + if isinstance(v, bool): | ||
| 62 | + post_data[k] = str(int(v)) | ||
| 63 | + post_data["file"] = files.get("file") | ||
| 64 | + post_data["avatar"] = files.get("avatar") | ||
| 65 | + | ||
| 66 | + data = MultipartEncoder(post_data) | ||
| 67 | + return (None, data, data.content_type) | ||
| 68 | + | ||
| 69 | + if raw and post_data: | ||
| 70 | + return (None, post_data, "application/octet-stream") | ||
| 71 | + | ||
| 72 | + return (post_data, None, "application/json") | ||
| 73 | + | ||
| 42 | 74 | def http_request( | |
| 43 | 75 | self, | |
| 44 | 76 | method: str, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments