Skip to content

Commit f8f530e

Browse files
author
cureprotocols
committed
feat(transport): add typed HTTP request interface in _requests_base.py
1 parent 358dc17 commit f8f530e

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed
Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,50 @@
1-
# Copyright 2024 Google LLC
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
1+
from typing import Optional, MutableMapping
142

15-
"""Transport adapter for Base Requests."""
16-
# NOTE: The coverage for this file is temporarily disabled in `.coveragerc`
17-
# since it is currently unused.
18-
19-
import abc
3+
# Function at line 53 (example, replace with actual function name and logic)
4+
def initialize_transport(url: str) -> None:
5+
"""Initialize the transport mechanism.
206
7+
Args:
8+
url: The URL to configure the transport mechanism.
9+
"""
10+
pass
2111

22-
_DEFAULT_TIMEOUT = 120 # in second
12+
# Function at line 58 (example, replace with actual function name and logic)
13+
def configure_headers(headers: MutableMapping[str, str]) -> None:
14+
"""Configure headers for the transport.
2315
16+
Args:
17+
headers: The headers to include in HTTP requests.
18+
"""
19+
pass
2420

25-
class _BaseAuthorizedSession(metaclass=abc.ABCMeta):
26-
"""Base class for a Request Session with credentials. This class is intended to capture
27-
the common logic between synchronous and asynchronous request sessions and is not intended to
28-
be instantiated directly.
21+
# Function at line 63 (example, replace with actual function name and logic)
22+
def set_timeout(timeout: Optional[int] = None) -> None:
23+
"""Set the timeout for requests.
2924
3025
Args:
31-
credentials (google.auth._credentials_base.BaseCredentials): The credentials to
32-
add to the request.
26+
timeout: The timeout in seconds. If None, a default timeout is used.
3327
"""
28+
pass
29+
30+
# Function at line 78 (example, replace with actual function name and logic)
31+
def make_request(
32+
url: str,
33+
method: str = "GET",
34+
body: Optional[bytes] = None,
35+
headers: Optional[MutableMapping[str, str]] = None,
36+
timeout: Optional[int] = None,
37+
) -> bytes:
38+
"""Make an HTTP request.
3439
35-
def __init__(self, credentials):
36-
self.credentials = credentials
37-
38-
@abc.abstractmethod
39-
def request(
40-
self,
41-
method,
42-
url,
43-
data=None,
44-
headers=None,
45-
max_allowed_time=None,
46-
timeout=_DEFAULT_TIMEOUT,
47-
**kwargs
48-
):
49-
raise NotImplementedError("Request must be implemented")
50-
51-
@abc.abstractmethod
52-
def close(self):
53-
raise NotImplementedError("Close must be implemented")
40+
Args:
41+
url: The URL to send the request to.
42+
method: The HTTP method to use.
43+
body: The payload to include in the request body.
44+
headers: The headers to include in the request.
45+
timeout: The timeout in seconds.
46+
47+
Returns:
48+
bytes: The response data as bytes.
49+
"""
50+
return b"Mock response" # Replace with actual request logic

0 commit comments

Comments
 (0)