|
24 | 24 | import time |
25 | 25 | from typing import Optional, Set, TYPE_CHECKING |
26 | 26 |
|
27 | | - |
28 | 27 | # PEP 0810: Explicit Lazy Imports |
29 | 28 | # Python 3.15+ natively intercepts and defers these imports. |
30 | 29 | # Developers can disable this behavior and force eager imports. |
|
54 | 53 | create_urllib3_context, |
55 | 54 | ) # pylint: disable=ungrouped-imports |
56 | 55 |
|
57 | | -from google.auth import _helpers |
58 | | -from google.auth import exceptions |
59 | | -from google.auth import transport |
| 56 | +from google.auth import _helpers, exceptions, transport |
60 | 57 | from google.auth.transport import _mtls_helper |
61 | 58 | import google.auth.transport._mtls_helper |
62 | 59 | from google.oauth2 import service_account |
63 | 60 |
|
| 61 | +if TYPE_CHECKING: |
| 62 | + _HTTPAdapterBase = requests.adapters.HTTPAdapter |
| 63 | + _SessionBase = requests.Session |
| 64 | +else: |
| 65 | + _HTTPAdapterBase = _helpers.HeapDummy |
| 66 | + _SessionBase = _helpers.HeapDummy |
| 67 | + |
64 | 68 |
|
65 | 69 | class _LazyBasesMeta(_helpers.LazyBasesMeta): |
66 | 70 | def _perform_resolve_bases(cls): |
@@ -194,7 +198,7 @@ def __call__( |
194 | 198 | body=None, |
195 | 199 | headers=None, |
196 | 200 | timeout=_DEFAULT_TIMEOUT, |
197 | | - **kwargs |
| 201 | + **kwargs, |
198 | 202 | ): |
199 | 203 | """Make an HTTP request using requests. |
200 | 204 |
|
@@ -242,9 +246,10 @@ class _MutualTlsAdapter(_HTTPAdapterBase, metaclass=_LazyBasesMeta): |
242 | 246 | """ |
243 | 247 |
|
244 | 248 | def __init__(self, cert, key): |
245 | | - import certifi |
246 | 249 | import ssl |
247 | 250 |
|
| 251 | + import certifi |
| 252 | + |
248 | 253 | ctx_poolmanager = create_urllib3_context() |
249 | 254 | ctx_poolmanager.load_verify_locations(cafile=certifi.where()) |
250 | 255 |
|
@@ -318,6 +323,7 @@ class _MutualTlsOffloadAdapter(_HTTPAdapterBase, metaclass=_LazyBasesMeta): |
318 | 323 |
|
319 | 324 | def __init__(self, enterprise_cert_file_path): |
320 | 325 | import certifi |
| 326 | + |
321 | 327 | from google.auth.transport import _custom_tls_signer |
322 | 328 |
|
323 | 329 | self.signer = _custom_tls_signer.CustomTlsSigner(enterprise_cert_file_path) |
@@ -537,7 +543,7 @@ def request( |
537 | 543 | headers=None, |
538 | 544 | max_allowed_time=None, |
539 | 545 | timeout=_DEFAULT_TIMEOUT, |
540 | | - **kwargs |
| 546 | + **kwargs, |
541 | 547 | ): |
542 | 548 | """Implementation of Requests' request. |
543 | 549 |
|
@@ -599,7 +605,7 @@ def request( |
599 | 605 | data=data, |
600 | 606 | headers=request_headers, |
601 | 607 | timeout=timeout, |
602 | | - **kwargs |
| 608 | + **kwargs, |
603 | 609 | ) |
604 | 610 | remaining_time = guard.remaining_timeout |
605 | 611 |
|
@@ -671,7 +677,7 @@ def request( |
671 | 677 | max_allowed_time=remaining_time, |
672 | 678 | timeout=timeout, |
673 | 679 | _credential_refresh_attempt=_credential_refresh_attempt + 1, |
674 | | - **kwargs |
| 680 | + **kwargs, |
675 | 681 | ) |
676 | 682 |
|
677 | 683 | return response |
|
0 commit comments