train-travel 0.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. train_travel/__init__.py +17 -0
  2. train_travel/_hooks/__init__.py +6 -0
  3. train_travel/_hooks/oauth2scopes.py +16 -0
  4. train_travel/_hooks/registration.py +13 -0
  5. train_travel/_hooks/sdkhooks.py +76 -0
  6. train_travel/_hooks/types.py +112 -0
  7. train_travel/_version.py +15 -0
  8. train_travel/basesdk.py +388 -0
  9. train_travel/bookings.py +1190 -0
  10. train_travel/errors/__init__.py +63 -0
  11. train_travel/errors/no_response_error.py +17 -0
  12. train_travel/errors/responsevalidationerror.py +27 -0
  13. train_travel/errors/traintraveldefaulterror.py +40 -0
  14. train_travel/errors/traintravelerror.py +30 -0
  15. train_travel/httpclient.py +125 -0
  16. train_travel/models/__init__.py +416 -0
  17. train_travel/models/booking.py +59 -0
  18. train_travel/models/booking_input.py +52 -0
  19. train_travel/models/bookingpayment.py +221 -0
  20. train_travel/models/create_booking_paymentop.py +269 -0
  21. train_travel/models/create_booking_rawop.py +144 -0
  22. train_travel/models/create_bookingop.py +144 -0
  23. train_travel/models/delete_bookingop.py +30 -0
  24. train_travel/models/get_bookingop.py +159 -0
  25. train_travel/models/get_bookingsop.py +198 -0
  26. train_travel/models/get_stationsop.py +230 -0
  27. train_travel/models/get_tripsop.py +324 -0
  28. train_travel/models/links_booking.py +35 -0
  29. train_travel/models/links_self.py +36 -0
  30. train_travel/models/new_bookingop.py +92 -0
  31. train_travel/models/security.py +39 -0
  32. train_travel/models/station.py +57 -0
  33. train_travel/models/trip.py +90 -0
  34. train_travel/payments.py +262 -0
  35. train_travel/py.typed +1 -0
  36. train_travel/sdk.py +213 -0
  37. train_travel/sdkconfiguration.py +51 -0
  38. train_travel/stations.py +284 -0
  39. train_travel/trips.py +291 -0
  40. train_travel/types/__init__.py +21 -0
  41. train_travel/types/basemodel.py +77 -0
  42. train_travel/utils/__init__.py +206 -0
  43. train_travel/utils/annotations.py +79 -0
  44. train_travel/utils/datetimes.py +23 -0
  45. train_travel/utils/enums.py +134 -0
  46. train_travel/utils/eventstreaming.py +248 -0
  47. train_travel/utils/forms.py +234 -0
  48. train_travel/utils/headers.py +136 -0
  49. train_travel/utils/logger.py +27 -0
  50. train_travel/utils/metadata.py +118 -0
  51. train_travel/utils/queryparams.py +217 -0
  52. train_travel/utils/requestbodies.py +66 -0
  53. train_travel/utils/retries.py +281 -0
  54. train_travel/utils/security.py +192 -0
  55. train_travel/utils/serializers.py +229 -0
  56. train_travel/utils/unmarshal_json_response.py +38 -0
  57. train_travel/utils/url.py +155 -0
  58. train_travel/utils/values.py +137 -0
  59. train_travel-0.0.7.dist-info/METADATA +567 -0
  60. train_travel-0.0.7.dist-info/RECORD +62 -0
  61. train_travel-0.0.7.dist-info/WHEEL +5 -0
  62. train_travel-0.0.7.dist-info/top_level.txt +1 -0
@@ -0,0 +1,17 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from ._version import (
4
+ __title__,
5
+ __version__,
6
+ __openapi_doc_version__,
7
+ __gen_version__,
8
+ __user_agent__,
9
+ )
10
+ from .sdk import *
11
+ from .sdkconfiguration import *
12
+
13
+
14
+ VERSION: str = __version__
15
+ OPENAPI_DOC_VERSION = __openapi_doc_version__
16
+ SPEAKEASY_GENERATOR_VERSION = __gen_version__
17
+ USER_AGENT = __user_agent__
@@ -0,0 +1,6 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .sdkhooks import *
4
+ from .types import *
5
+ from .registration import *
6
+ from .oauth2scopes import *
@@ -0,0 +1,16 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from enum import Enum
4
+
5
+
6
+ class OAuth2Scope(str, Enum):
7
+ r"""Available scopes for the OAuth2 OAuth 2.0 scheme (authorizationCode flow).
8
+
9
+ OAuth 2.0 authorization code following RFC8725 best practices.
10
+ """
11
+
12
+ READ = "read"
13
+ r"""Read access"""
14
+
15
+ WRITE = "write"
16
+ r"""Write access"""
@@ -0,0 +1,13 @@
1
+ from .types import Hooks
2
+
3
+
4
+ # This file is only ever generated once on the first generation and then is free to be modified.
5
+ # Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
6
+ # in this file or in separate files in the hooks folder.
7
+
8
+
9
+ def init_hooks(hooks: Hooks):
10
+ # pylint: disable=unused-argument
11
+ """Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
12
+ with an instance of a hook that implements that specific Hook interface
13
+ Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
@@ -0,0 +1,76 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import httpx
4
+ from .types import (
5
+ SDKInitHook,
6
+ BeforeRequestContext,
7
+ BeforeRequestHook,
8
+ AfterSuccessContext,
9
+ AfterSuccessHook,
10
+ AfterErrorContext,
11
+ AfterErrorHook,
12
+ Hooks,
13
+ )
14
+ from .registration import init_hooks
15
+ from typing import List, Optional, Tuple
16
+ from train_travel.sdkconfiguration import SDKConfiguration
17
+
18
+
19
+ class SDKHooks(Hooks):
20
+ def __init__(self) -> None:
21
+ self.sdk_init_hooks: List[SDKInitHook] = []
22
+ self.before_request_hooks: List[BeforeRequestHook] = []
23
+ self.after_success_hooks: List[AfterSuccessHook] = []
24
+ self.after_error_hooks: List[AfterErrorHook] = []
25
+ init_hooks(self)
26
+
27
+ def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
28
+ self.sdk_init_hooks.append(hook)
29
+
30
+ def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
31
+ self.before_request_hooks.append(hook)
32
+
33
+ def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
34
+ self.after_success_hooks.append(hook)
35
+
36
+ def register_after_error_hook(self, hook: AfterErrorHook) -> None:
37
+ self.after_error_hooks.append(hook)
38
+
39
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
40
+ for hook in self.sdk_init_hooks:
41
+ config = hook.sdk_init(config)
42
+ return config
43
+
44
+ def before_request(
45
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
46
+ ) -> httpx.Request:
47
+ for hook in self.before_request_hooks:
48
+ out = hook.before_request(hook_ctx, request)
49
+ if isinstance(out, Exception):
50
+ raise out
51
+ request = out
52
+
53
+ return request
54
+
55
+ def after_success(
56
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
57
+ ) -> httpx.Response:
58
+ for hook in self.after_success_hooks:
59
+ out = hook.after_success(hook_ctx, response)
60
+ if isinstance(out, Exception):
61
+ raise out
62
+ response = out
63
+ return response
64
+
65
+ def after_error(
66
+ self,
67
+ hook_ctx: AfterErrorContext,
68
+ response: Optional[httpx.Response],
69
+ error: Optional[Exception],
70
+ ) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
71
+ for hook in self.after_error_hooks:
72
+ result = hook.after_error(hook_ctx, response, error)
73
+ if isinstance(result, Exception):
74
+ raise result
75
+ response, error = result
76
+ return response, error
@@ -0,0 +1,112 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from abc import ABC, abstractmethod
4
+ import httpx
5
+ from train_travel.sdkconfiguration import SDKConfiguration
6
+ from typing import Any, Callable, List, Optional, Tuple, Union
7
+
8
+
9
+ class HookContext:
10
+ config: SDKConfiguration
11
+ base_url: str
12
+ operation_id: str
13
+ oauth2_scopes: Optional[List[str]] = None
14
+ security_source: Optional[Union[Any, Callable[[], Any]]] = None
15
+
16
+ def __init__(
17
+ self,
18
+ config: SDKConfiguration,
19
+ base_url: str,
20
+ operation_id: str,
21
+ oauth2_scopes: Optional[List[str]],
22
+ security_source: Optional[Union[Any, Callable[[], Any]]],
23
+ ):
24
+ self.config = config
25
+ self.base_url = base_url
26
+ self.operation_id = operation_id
27
+ self.oauth2_scopes = oauth2_scopes
28
+ self.security_source = security_source
29
+
30
+
31
+ class BeforeRequestContext(HookContext):
32
+ def __init__(self, hook_ctx: HookContext):
33
+ super().__init__(
34
+ hook_ctx.config,
35
+ hook_ctx.base_url,
36
+ hook_ctx.operation_id,
37
+ hook_ctx.oauth2_scopes,
38
+ hook_ctx.security_source,
39
+ )
40
+
41
+
42
+ class AfterSuccessContext(HookContext):
43
+ def __init__(self, hook_ctx: HookContext):
44
+ super().__init__(
45
+ hook_ctx.config,
46
+ hook_ctx.base_url,
47
+ hook_ctx.operation_id,
48
+ hook_ctx.oauth2_scopes,
49
+ hook_ctx.security_source,
50
+ )
51
+
52
+
53
+ class AfterErrorContext(HookContext):
54
+ def __init__(self, hook_ctx: HookContext):
55
+ super().__init__(
56
+ hook_ctx.config,
57
+ hook_ctx.base_url,
58
+ hook_ctx.operation_id,
59
+ hook_ctx.oauth2_scopes,
60
+ hook_ctx.security_source,
61
+ )
62
+
63
+
64
+ class SDKInitHook(ABC):
65
+ @abstractmethod
66
+ def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
67
+ pass
68
+
69
+
70
+ class BeforeRequestHook(ABC):
71
+ @abstractmethod
72
+ def before_request(
73
+ self, hook_ctx: BeforeRequestContext, request: httpx.Request
74
+ ) -> Union[httpx.Request, Exception]:
75
+ pass
76
+
77
+
78
+ class AfterSuccessHook(ABC):
79
+ @abstractmethod
80
+ def after_success(
81
+ self, hook_ctx: AfterSuccessContext, response: httpx.Response
82
+ ) -> Union[httpx.Response, Exception]:
83
+ pass
84
+
85
+
86
+ class AfterErrorHook(ABC):
87
+ @abstractmethod
88
+ def after_error(
89
+ self,
90
+ hook_ctx: AfterErrorContext,
91
+ response: Optional[httpx.Response],
92
+ error: Optional[Exception],
93
+ ) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
94
+ pass
95
+
96
+
97
+ class Hooks(ABC):
98
+ @abstractmethod
99
+ def register_sdk_init_hook(self, hook: SDKInitHook):
100
+ pass
101
+
102
+ @abstractmethod
103
+ def register_before_request_hook(self, hook: BeforeRequestHook):
104
+ pass
105
+
106
+ @abstractmethod
107
+ def register_after_success_hook(self, hook: AfterSuccessHook):
108
+ pass
109
+
110
+ @abstractmethod
111
+ def register_after_error_hook(self, hook: AfterErrorHook):
112
+ pass
@@ -0,0 +1,15 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import importlib.metadata
4
+
5
+ __title__: str = "train-travel"
6
+ __version__: str = "0.0.7"
7
+ __openapi_doc_version__: str = "1.2.1"
8
+ __gen_version__: str = "2.803.3"
9
+ __user_agent__: str = "speakeasy-sdk/python 0.0.7 2.803.3 1.2.1 train-travel"
10
+
11
+ try:
12
+ if __package__ is not None:
13
+ __version__ = importlib.metadata.version(__package__)
14
+ except importlib.metadata.PackageNotFoundError:
15
+ pass
@@ -0,0 +1,388 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .sdkconfiguration import SDKConfiguration
4
+ import httpx
5
+ from train_travel import errors, models, utils
6
+ from train_travel._hooks import (
7
+ AfterErrorContext,
8
+ AfterSuccessContext,
9
+ BeforeRequestContext,
10
+ )
11
+ from train_travel.utils import (
12
+ RetryConfig,
13
+ SerializedRequestBody,
14
+ get_body_content,
15
+ run_sync_in_thread,
16
+ )
17
+ from typing import Callable, List, Mapping, Optional, Tuple
18
+ from urllib.parse import parse_qs, urlparse
19
+
20
+
21
+ class BaseSDK:
22
+ sdk_configuration: SDKConfiguration
23
+ parent_ref: Optional[object] = None
24
+ """
25
+ Reference to the root SDK instance, if any. This will prevent it from
26
+ being garbage collected while there are active streams.
27
+ """
28
+
29
+ def __init__(
30
+ self,
31
+ sdk_config: SDKConfiguration,
32
+ parent_ref: Optional[object] = None,
33
+ ) -> None:
34
+ self.sdk_configuration = sdk_config
35
+ self.parent_ref = parent_ref
36
+
37
+ def _get_url(self, base_url, url_variables):
38
+ sdk_url, sdk_variables = self.sdk_configuration.get_server_details()
39
+
40
+ if base_url is None:
41
+ base_url = sdk_url
42
+
43
+ if url_variables is None:
44
+ url_variables = sdk_variables
45
+
46
+ return utils.template_url(base_url, url_variables)
47
+
48
+ def _build_request_async(
49
+ self,
50
+ method,
51
+ path,
52
+ base_url,
53
+ url_variables,
54
+ request,
55
+ request_body_required,
56
+ request_has_path_params,
57
+ request_has_query_params,
58
+ user_agent_header,
59
+ accept_header_value,
60
+ _globals=None,
61
+ security=None,
62
+ timeout_ms: Optional[int] = None,
63
+ get_serialized_body: Optional[
64
+ Callable[[], Optional[SerializedRequestBody]]
65
+ ] = None,
66
+ url_override: Optional[str] = None,
67
+ http_headers: Optional[Mapping[str, str]] = None,
68
+ allow_empty_value: Optional[List[str]] = None,
69
+ ) -> httpx.Request:
70
+ client = self.sdk_configuration.async_client
71
+ return self._build_request_with_client(
72
+ client,
73
+ method,
74
+ path,
75
+ base_url,
76
+ url_variables,
77
+ request,
78
+ request_body_required,
79
+ request_has_path_params,
80
+ request_has_query_params,
81
+ user_agent_header,
82
+ accept_header_value,
83
+ _globals,
84
+ security,
85
+ timeout_ms,
86
+ get_serialized_body,
87
+ url_override,
88
+ http_headers,
89
+ allow_empty_value,
90
+ )
91
+
92
+ def _build_request(
93
+ self,
94
+ method,
95
+ path,
96
+ base_url,
97
+ url_variables,
98
+ request,
99
+ request_body_required,
100
+ request_has_path_params,
101
+ request_has_query_params,
102
+ user_agent_header,
103
+ accept_header_value,
104
+ _globals=None,
105
+ security=None,
106
+ timeout_ms: Optional[int] = None,
107
+ get_serialized_body: Optional[
108
+ Callable[[], Optional[SerializedRequestBody]]
109
+ ] = None,
110
+ url_override: Optional[str] = None,
111
+ http_headers: Optional[Mapping[str, str]] = None,
112
+ allow_empty_value: Optional[List[str]] = None,
113
+ ) -> httpx.Request:
114
+ client = self.sdk_configuration.client
115
+ return self._build_request_with_client(
116
+ client,
117
+ method,
118
+ path,
119
+ base_url,
120
+ url_variables,
121
+ request,
122
+ request_body_required,
123
+ request_has_path_params,
124
+ request_has_query_params,
125
+ user_agent_header,
126
+ accept_header_value,
127
+ _globals,
128
+ security,
129
+ timeout_ms,
130
+ get_serialized_body,
131
+ url_override,
132
+ http_headers,
133
+ allow_empty_value,
134
+ )
135
+
136
+ def _build_request_with_client(
137
+ self,
138
+ client,
139
+ method,
140
+ path,
141
+ base_url,
142
+ url_variables,
143
+ request,
144
+ request_body_required,
145
+ request_has_path_params,
146
+ request_has_query_params,
147
+ user_agent_header,
148
+ accept_header_value,
149
+ _globals=None,
150
+ security=None,
151
+ timeout_ms: Optional[int] = None,
152
+ get_serialized_body: Optional[
153
+ Callable[[], Optional[SerializedRequestBody]]
154
+ ] = None,
155
+ url_override: Optional[str] = None,
156
+ http_headers: Optional[Mapping[str, str]] = None,
157
+ allow_empty_value: Optional[List[str]] = None,
158
+ ) -> httpx.Request:
159
+ query_params = {}
160
+
161
+ url = url_override
162
+ if url is None:
163
+ url = utils.generate_url(
164
+ self._get_url(base_url, url_variables),
165
+ path,
166
+ request if request_has_path_params else None,
167
+ _globals if request_has_path_params else None,
168
+ )
169
+
170
+ query_params = utils.get_query_params(
171
+ request if request_has_query_params else None,
172
+ _globals if request_has_query_params else None,
173
+ allow_empty_value,
174
+ )
175
+ else:
176
+ # Pick up the query parameter from the override so they can be
177
+ # preserved when building the request later on (necessary as of
178
+ # httpx 0.28).
179
+ parsed_override = urlparse(str(url_override))
180
+ query_params = parse_qs(parsed_override.query, keep_blank_values=True)
181
+
182
+ headers = utils.get_headers(request, _globals)
183
+ headers["Accept"] = accept_header_value
184
+ headers[user_agent_header] = self.sdk_configuration.user_agent
185
+
186
+ if security is not None:
187
+ if callable(security):
188
+ security = security()
189
+ security = utils.get_security_from_env(security, models.Security)
190
+ if security is not None:
191
+ security_headers, security_query_params = utils.get_security(security)
192
+ headers = {**headers, **security_headers}
193
+ query_params = {**query_params, **security_query_params}
194
+
195
+ serialized_request_body = SerializedRequestBody()
196
+ if get_serialized_body is not None:
197
+ rb = get_serialized_body()
198
+ if request_body_required and rb is None:
199
+ raise ValueError("request body is required")
200
+
201
+ if rb is not None:
202
+ serialized_request_body = rb
203
+
204
+ if (
205
+ serialized_request_body.media_type is not None
206
+ and serialized_request_body.media_type
207
+ not in (
208
+ "multipart/form-data",
209
+ "multipart/mixed",
210
+ )
211
+ ):
212
+ headers["content-type"] = serialized_request_body.media_type
213
+
214
+ if http_headers is not None:
215
+ for header, value in http_headers.items():
216
+ headers[header] = value
217
+
218
+ timeout = timeout_ms / 1000 if timeout_ms is not None else None
219
+
220
+ return client.build_request(
221
+ method,
222
+ url,
223
+ params=query_params,
224
+ content=serialized_request_body.content,
225
+ data=serialized_request_body.data,
226
+ files=serialized_request_body.files,
227
+ headers=headers,
228
+ timeout=timeout,
229
+ )
230
+
231
+ def do_request(
232
+ self,
233
+ hook_ctx,
234
+ request,
235
+ error_status_codes,
236
+ stream=False,
237
+ retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
238
+ ) -> httpx.Response:
239
+ client = self.sdk_configuration.client
240
+ logger = self.sdk_configuration.debug_logger
241
+
242
+ hooks = self.sdk_configuration.__dict__["_hooks"]
243
+
244
+ def do():
245
+ http_res = None
246
+ try:
247
+ req = hooks.before_request(BeforeRequestContext(hook_ctx), request)
248
+ logger.debug(
249
+ "Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
250
+ req.method,
251
+ req.url,
252
+ req.headers,
253
+ get_body_content(req),
254
+ )
255
+
256
+ if client is None:
257
+ raise ValueError("client is required")
258
+
259
+ http_res = client.send(req, stream=stream)
260
+ except Exception as e:
261
+ _, e = hooks.after_error(AfterErrorContext(hook_ctx), None, e)
262
+ if e is not None:
263
+ logger.debug("Request Exception", exc_info=True)
264
+ raise e
265
+
266
+ if http_res is None:
267
+ logger.debug("Raising no response SDK error")
268
+ raise errors.NoResponseError("No response received")
269
+
270
+ logger.debug(
271
+ "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
272
+ http_res.status_code,
273
+ http_res.url,
274
+ http_res.headers,
275
+ "<streaming response>" if stream else http_res.text,
276
+ )
277
+
278
+ if utils.match_status_codes(error_status_codes, http_res.status_code):
279
+ result, err = hooks.after_error(
280
+ AfterErrorContext(hook_ctx), http_res, None
281
+ )
282
+ if err is not None:
283
+ logger.debug("Request Exception", exc_info=True)
284
+ raise err
285
+ if result is not None:
286
+ http_res = result
287
+ else:
288
+ logger.debug("Raising unexpected SDK error")
289
+ raise errors.TrainTravelDefaultError(
290
+ "Unexpected error occurred", http_res
291
+ )
292
+
293
+ return http_res
294
+
295
+ if retry_config is not None:
296
+ http_res = utils.retry(do, utils.Retries(retry_config[0], retry_config[1]))
297
+ else:
298
+ http_res = do()
299
+
300
+ if not utils.match_status_codes(error_status_codes, http_res.status_code):
301
+ http_res = hooks.after_success(AfterSuccessContext(hook_ctx), http_res)
302
+
303
+ return http_res
304
+
305
+ async def do_request_async(
306
+ self,
307
+ hook_ctx,
308
+ request,
309
+ error_status_codes,
310
+ stream=False,
311
+ retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
312
+ ) -> httpx.Response:
313
+ client = self.sdk_configuration.async_client
314
+ logger = self.sdk_configuration.debug_logger
315
+
316
+ hooks = self.sdk_configuration.__dict__["_hooks"]
317
+
318
+ async def do():
319
+ http_res = None
320
+ try:
321
+ req = await run_sync_in_thread(
322
+ hooks.before_request, BeforeRequestContext(hook_ctx), request
323
+ )
324
+
325
+ logger.debug(
326
+ "Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
327
+ req.method,
328
+ req.url,
329
+ req.headers,
330
+ get_body_content(req),
331
+ )
332
+
333
+ if client is None:
334
+ raise ValueError("client is required")
335
+
336
+ http_res = await client.send(req, stream=stream)
337
+ except Exception as e:
338
+ _, e = await run_sync_in_thread(
339
+ hooks.after_error, AfterErrorContext(hook_ctx), None, e
340
+ )
341
+
342
+ if e is not None:
343
+ logger.debug("Request Exception", exc_info=True)
344
+ raise e
345
+
346
+ if http_res is None:
347
+ logger.debug("Raising no response SDK error")
348
+ raise errors.NoResponseError("No response received")
349
+
350
+ logger.debug(
351
+ "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
352
+ http_res.status_code,
353
+ http_res.url,
354
+ http_res.headers,
355
+ "<streaming response>" if stream else http_res.text,
356
+ )
357
+
358
+ if utils.match_status_codes(error_status_codes, http_res.status_code):
359
+ result, err = await run_sync_in_thread(
360
+ hooks.after_error, AfterErrorContext(hook_ctx), http_res, None
361
+ )
362
+
363
+ if err is not None:
364
+ logger.debug("Request Exception", exc_info=True)
365
+ raise err
366
+ if result is not None:
367
+ http_res = result
368
+ else:
369
+ logger.debug("Raising unexpected SDK error")
370
+ raise errors.TrainTravelDefaultError(
371
+ "Unexpected error occurred", http_res
372
+ )
373
+
374
+ return http_res
375
+
376
+ if retry_config is not None:
377
+ http_res = await utils.retry_async(
378
+ do, utils.Retries(retry_config[0], retry_config[1])
379
+ )
380
+ else:
381
+ http_res = await do()
382
+
383
+ if not utils.match_status_codes(error_status_codes, http_res.status_code):
384
+ http_res = await run_sync_in_thread(
385
+ hooks.after_success, AfterSuccessContext(hook_ctx), http_res
386
+ )
387
+
388
+ return http_res