Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/pubsub_v1/services/subscriber/transports/rest.py: 33%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

630 statements  

1# -*- coding: utf-8 -*- 

2# Copyright 2025 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16import logging 

17import json # type: ignore 

18 

19from google.auth.transport.requests import AuthorizedSession # type: ignore 

20from google.auth import credentials as ga_credentials # type: ignore 

21from google.api_core import exceptions as core_exceptions 

22from google.api_core import retry as retries 

23from google.api_core import rest_helpers 

24from google.api_core import rest_streaming 

25from google.api_core import gapic_v1 

26import google.protobuf 

27 

28from google.protobuf import json_format 

29from google.iam.v1 import iam_policy_pb2 # type: ignore 

30from google.iam.v1 import policy_pb2 # type: ignore 

31 

32from requests import __version__ as requests_version 

33import dataclasses 

34from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union 

35import warnings 

36 

37 

38from google.protobuf import empty_pb2 # type: ignore 

39from google.pubsub_v1.types import pubsub 

40 

41 

42from .rest_base import _BaseSubscriberRestTransport 

43from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO 

44 

45try: 

46 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] 

47except AttributeError: # pragma: NO COVER 

48 OptionalRetry = Union[retries.Retry, object, None] # type: ignore 

49 

50try: 

51 from google.api_core import client_logging # type: ignore 

52 

53 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

54except ImportError: # pragma: NO COVER 

55 CLIENT_LOGGING_SUPPORTED = False 

56 

57_LOGGER = logging.getLogger(__name__) 

58 

59DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

60 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, 

61 grpc_version=None, 

62 rest_version=f"requests@{requests_version}", 

63) 

64 

65if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER 

66 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

67 

68 

69class SubscriberRestInterceptor: 

70 """Interceptor for Subscriber. 

71 

72 Interceptors are used to manipulate requests, request metadata, and responses 

73 in arbitrary ways. 

74 Example use cases include: 

75 * Logging 

76 * Verifying requests according to service or custom semantics 

77 * Stripping extraneous information from responses 

78 

79 These use cases and more can be enabled by injecting an 

80 instance of a custom subclass when constructing the SubscriberRestTransport. 

81 

82 .. code-block:: python 

83 class MyCustomSubscriberInterceptor(SubscriberRestInterceptor): 

84 def pre_acknowledge(self, request, metadata): 

85 logging.log(f"Received request: {request}") 

86 return request, metadata 

87 

88 def pre_create_snapshot(self, request, metadata): 

89 logging.log(f"Received request: {request}") 

90 return request, metadata 

91 

92 def post_create_snapshot(self, response): 

93 logging.log(f"Received response: {response}") 

94 return response 

95 

96 def pre_create_subscription(self, request, metadata): 

97 logging.log(f"Received request: {request}") 

98 return request, metadata 

99 

100 def post_create_subscription(self, response): 

101 logging.log(f"Received response: {response}") 

102 return response 

103 

104 def pre_delete_snapshot(self, request, metadata): 

105 logging.log(f"Received request: {request}") 

106 return request, metadata 

107 

108 def pre_delete_subscription(self, request, metadata): 

109 logging.log(f"Received request: {request}") 

110 return request, metadata 

111 

112 def pre_get_snapshot(self, request, metadata): 

113 logging.log(f"Received request: {request}") 

114 return request, metadata 

115 

116 def post_get_snapshot(self, response): 

117 logging.log(f"Received response: {response}") 

118 return response 

119 

120 def pre_get_subscription(self, request, metadata): 

121 logging.log(f"Received request: {request}") 

122 return request, metadata 

123 

124 def post_get_subscription(self, response): 

125 logging.log(f"Received response: {response}") 

126 return response 

127 

128 def pre_list_snapshots(self, request, metadata): 

129 logging.log(f"Received request: {request}") 

130 return request, metadata 

131 

132 def post_list_snapshots(self, response): 

133 logging.log(f"Received response: {response}") 

134 return response 

135 

136 def pre_list_subscriptions(self, request, metadata): 

137 logging.log(f"Received request: {request}") 

138 return request, metadata 

139 

140 def post_list_subscriptions(self, response): 

141 logging.log(f"Received response: {response}") 

142 return response 

143 

144 def pre_modify_ack_deadline(self, request, metadata): 

145 logging.log(f"Received request: {request}") 

146 return request, metadata 

147 

148 def pre_modify_push_config(self, request, metadata): 

149 logging.log(f"Received request: {request}") 

150 return request, metadata 

151 

152 def pre_pull(self, request, metadata): 

153 logging.log(f"Received request: {request}") 

154 return request, metadata 

155 

156 def post_pull(self, response): 

157 logging.log(f"Received response: {response}") 

158 return response 

159 

160 def pre_seek(self, request, metadata): 

161 logging.log(f"Received request: {request}") 

162 return request, metadata 

163 

164 def post_seek(self, response): 

165 logging.log(f"Received response: {response}") 

166 return response 

167 

168 def pre_update_snapshot(self, request, metadata): 

169 logging.log(f"Received request: {request}") 

170 return request, metadata 

171 

172 def post_update_snapshot(self, response): 

173 logging.log(f"Received response: {response}") 

174 return response 

175 

176 def pre_update_subscription(self, request, metadata): 

177 logging.log(f"Received request: {request}") 

178 return request, metadata 

179 

180 def post_update_subscription(self, response): 

181 logging.log(f"Received response: {response}") 

182 return response 

183 

184 transport = SubscriberRestTransport(interceptor=MyCustomSubscriberInterceptor()) 

185 client = SubscriberClient(transport=transport) 

186 

187 

188 """ 

189 

190 def pre_acknowledge( 

191 self, 

192 request: pubsub.AcknowledgeRequest, 

193 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

194 ) -> Tuple[pubsub.AcknowledgeRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

195 """Pre-rpc interceptor for acknowledge 

196 

197 Override in a subclass to manipulate the request or metadata 

198 before they are sent to the Subscriber server. 

199 """ 

200 return request, metadata 

201 

202 def pre_create_snapshot( 

203 self, 

204 request: pubsub.CreateSnapshotRequest, 

205 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

206 ) -> Tuple[pubsub.CreateSnapshotRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

207 """Pre-rpc interceptor for create_snapshot 

208 

209 Override in a subclass to manipulate the request or metadata 

210 before they are sent to the Subscriber server. 

211 """ 

212 return request, metadata 

213 

214 def post_create_snapshot(self, response: pubsub.Snapshot) -> pubsub.Snapshot: 

215 """Post-rpc interceptor for create_snapshot 

216 

217 DEPRECATED. Please use the `post_create_snapshot_with_metadata` 

218 interceptor instead. 

219 

220 Override in a subclass to read or manipulate the response 

221 after it is returned by the Subscriber server but before 

222 it is returned to user code. This `post_create_snapshot` interceptor runs 

223 before the `post_create_snapshot_with_metadata` interceptor. 

224 """ 

225 return response 

226 

227 def post_create_snapshot_with_metadata( 

228 self, 

229 response: pubsub.Snapshot, 

230 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

231 ) -> Tuple[pubsub.Snapshot, Sequence[Tuple[str, Union[str, bytes]]]]: 

232 """Post-rpc interceptor for create_snapshot 

233 

234 Override in a subclass to read or manipulate the response or metadata after it 

235 is returned by the Subscriber server but before it is returned to user code. 

236 

237 We recommend only using this `post_create_snapshot_with_metadata` 

238 interceptor in new development instead of the `post_create_snapshot` interceptor. 

239 When both interceptors are used, this `post_create_snapshot_with_metadata` interceptor runs after the 

240 `post_create_snapshot` interceptor. The (possibly modified) response returned by 

241 `post_create_snapshot` will be passed to 

242 `post_create_snapshot_with_metadata`. 

243 """ 

244 return response, metadata 

245 

246 def pre_create_subscription( 

247 self, 

248 request: pubsub.Subscription, 

249 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

250 ) -> Tuple[pubsub.Subscription, Sequence[Tuple[str, Union[str, bytes]]]]: 

251 """Pre-rpc interceptor for create_subscription 

252 

253 Override in a subclass to manipulate the request or metadata 

254 before they are sent to the Subscriber server. 

255 """ 

256 return request, metadata 

257 

258 def post_create_subscription( 

259 self, response: pubsub.Subscription 

260 ) -> pubsub.Subscription: 

261 """Post-rpc interceptor for create_subscription 

262 

263 DEPRECATED. Please use the `post_create_subscription_with_metadata` 

264 interceptor instead. 

265 

266 Override in a subclass to read or manipulate the response 

267 after it is returned by the Subscriber server but before 

268 it is returned to user code. This `post_create_subscription` interceptor runs 

269 before the `post_create_subscription_with_metadata` interceptor. 

270 """ 

271 return response 

272 

273 def post_create_subscription_with_metadata( 

274 self, 

275 response: pubsub.Subscription, 

276 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

277 ) -> Tuple[pubsub.Subscription, Sequence[Tuple[str, Union[str, bytes]]]]: 

278 """Post-rpc interceptor for create_subscription 

279 

280 Override in a subclass to read or manipulate the response or metadata after it 

281 is returned by the Subscriber server but before it is returned to user code. 

282 

283 We recommend only using this `post_create_subscription_with_metadata` 

284 interceptor in new development instead of the `post_create_subscription` interceptor. 

285 When both interceptors are used, this `post_create_subscription_with_metadata` interceptor runs after the 

286 `post_create_subscription` interceptor. The (possibly modified) response returned by 

287 `post_create_subscription` will be passed to 

288 `post_create_subscription_with_metadata`. 

289 """ 

290 return response, metadata 

291 

292 def pre_delete_snapshot( 

293 self, 

294 request: pubsub.DeleteSnapshotRequest, 

295 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

296 ) -> Tuple[pubsub.DeleteSnapshotRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

297 """Pre-rpc interceptor for delete_snapshot 

298 

299 Override in a subclass to manipulate the request or metadata 

300 before they are sent to the Subscriber server. 

301 """ 

302 return request, metadata 

303 

304 def pre_delete_subscription( 

305 self, 

306 request: pubsub.DeleteSubscriptionRequest, 

307 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

308 ) -> Tuple[ 

309 pubsub.DeleteSubscriptionRequest, Sequence[Tuple[str, Union[str, bytes]]] 

310 ]: 

311 """Pre-rpc interceptor for delete_subscription 

312 

313 Override in a subclass to manipulate the request or metadata 

314 before they are sent to the Subscriber server. 

315 """ 

316 return request, metadata 

317 

318 def pre_get_snapshot( 

319 self, 

320 request: pubsub.GetSnapshotRequest, 

321 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

322 ) -> Tuple[pubsub.GetSnapshotRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

323 """Pre-rpc interceptor for get_snapshot 

324 

325 Override in a subclass to manipulate the request or metadata 

326 before they are sent to the Subscriber server. 

327 """ 

328 return request, metadata 

329 

330 def post_get_snapshot(self, response: pubsub.Snapshot) -> pubsub.Snapshot: 

331 """Post-rpc interceptor for get_snapshot 

332 

333 DEPRECATED. Please use the `post_get_snapshot_with_metadata` 

334 interceptor instead. 

335 

336 Override in a subclass to read or manipulate the response 

337 after it is returned by the Subscriber server but before 

338 it is returned to user code. This `post_get_snapshot` interceptor runs 

339 before the `post_get_snapshot_with_metadata` interceptor. 

340 """ 

341 return response 

342 

343 def post_get_snapshot_with_metadata( 

344 self, 

345 response: pubsub.Snapshot, 

346 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

347 ) -> Tuple[pubsub.Snapshot, Sequence[Tuple[str, Union[str, bytes]]]]: 

348 """Post-rpc interceptor for get_snapshot 

349 

350 Override in a subclass to read or manipulate the response or metadata after it 

351 is returned by the Subscriber server but before it is returned to user code. 

352 

353 We recommend only using this `post_get_snapshot_with_metadata` 

354 interceptor in new development instead of the `post_get_snapshot` interceptor. 

355 When both interceptors are used, this `post_get_snapshot_with_metadata` interceptor runs after the 

356 `post_get_snapshot` interceptor. The (possibly modified) response returned by 

357 `post_get_snapshot` will be passed to 

358 `post_get_snapshot_with_metadata`. 

359 """ 

360 return response, metadata 

361 

362 def pre_get_subscription( 

363 self, 

364 request: pubsub.GetSubscriptionRequest, 

365 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

366 ) -> Tuple[pubsub.GetSubscriptionRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

367 """Pre-rpc interceptor for get_subscription 

368 

369 Override in a subclass to manipulate the request or metadata 

370 before they are sent to the Subscriber server. 

371 """ 

372 return request, metadata 

373 

374 def post_get_subscription( 

375 self, response: pubsub.Subscription 

376 ) -> pubsub.Subscription: 

377 """Post-rpc interceptor for get_subscription 

378 

379 DEPRECATED. Please use the `post_get_subscription_with_metadata` 

380 interceptor instead. 

381 

382 Override in a subclass to read or manipulate the response 

383 after it is returned by the Subscriber server but before 

384 it is returned to user code. This `post_get_subscription` interceptor runs 

385 before the `post_get_subscription_with_metadata` interceptor. 

386 """ 

387 return response 

388 

389 def post_get_subscription_with_metadata( 

390 self, 

391 response: pubsub.Subscription, 

392 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

393 ) -> Tuple[pubsub.Subscription, Sequence[Tuple[str, Union[str, bytes]]]]: 

394 """Post-rpc interceptor for get_subscription 

395 

396 Override in a subclass to read or manipulate the response or metadata after it 

397 is returned by the Subscriber server but before it is returned to user code. 

398 

399 We recommend only using this `post_get_subscription_with_metadata` 

400 interceptor in new development instead of the `post_get_subscription` interceptor. 

401 When both interceptors are used, this `post_get_subscription_with_metadata` interceptor runs after the 

402 `post_get_subscription` interceptor. The (possibly modified) response returned by 

403 `post_get_subscription` will be passed to 

404 `post_get_subscription_with_metadata`. 

405 """ 

406 return response, metadata 

407 

408 def pre_list_snapshots( 

409 self, 

410 request: pubsub.ListSnapshotsRequest, 

411 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

412 ) -> Tuple[pubsub.ListSnapshotsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

413 """Pre-rpc interceptor for list_snapshots 

414 

415 Override in a subclass to manipulate the request or metadata 

416 before they are sent to the Subscriber server. 

417 """ 

418 return request, metadata 

419 

420 def post_list_snapshots( 

421 self, response: pubsub.ListSnapshotsResponse 

422 ) -> pubsub.ListSnapshotsResponse: 

423 """Post-rpc interceptor for list_snapshots 

424 

425 DEPRECATED. Please use the `post_list_snapshots_with_metadata` 

426 interceptor instead. 

427 

428 Override in a subclass to read or manipulate the response 

429 after it is returned by the Subscriber server but before 

430 it is returned to user code. This `post_list_snapshots` interceptor runs 

431 before the `post_list_snapshots_with_metadata` interceptor. 

432 """ 

433 return response 

434 

435 def post_list_snapshots_with_metadata( 

436 self, 

437 response: pubsub.ListSnapshotsResponse, 

438 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

439 ) -> Tuple[pubsub.ListSnapshotsResponse, Sequence[Tuple[str, Union[str, bytes]]]]: 

440 """Post-rpc interceptor for list_snapshots 

441 

442 Override in a subclass to read or manipulate the response or metadata after it 

443 is returned by the Subscriber server but before it is returned to user code. 

444 

445 We recommend only using this `post_list_snapshots_with_metadata` 

446 interceptor in new development instead of the `post_list_snapshots` interceptor. 

447 When both interceptors are used, this `post_list_snapshots_with_metadata` interceptor runs after the 

448 `post_list_snapshots` interceptor. The (possibly modified) response returned by 

449 `post_list_snapshots` will be passed to 

450 `post_list_snapshots_with_metadata`. 

451 """ 

452 return response, metadata 

453 

454 def pre_list_subscriptions( 

455 self, 

456 request: pubsub.ListSubscriptionsRequest, 

457 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

458 ) -> Tuple[ 

459 pubsub.ListSubscriptionsRequest, Sequence[Tuple[str, Union[str, bytes]]] 

460 ]: 

461 """Pre-rpc interceptor for list_subscriptions 

462 

463 Override in a subclass to manipulate the request or metadata 

464 before they are sent to the Subscriber server. 

465 """ 

466 return request, metadata 

467 

468 def post_list_subscriptions( 

469 self, response: pubsub.ListSubscriptionsResponse 

470 ) -> pubsub.ListSubscriptionsResponse: 

471 """Post-rpc interceptor for list_subscriptions 

472 

473 DEPRECATED. Please use the `post_list_subscriptions_with_metadata` 

474 interceptor instead. 

475 

476 Override in a subclass to read or manipulate the response 

477 after it is returned by the Subscriber server but before 

478 it is returned to user code. This `post_list_subscriptions` interceptor runs 

479 before the `post_list_subscriptions_with_metadata` interceptor. 

480 """ 

481 return response 

482 

483 def post_list_subscriptions_with_metadata( 

484 self, 

485 response: pubsub.ListSubscriptionsResponse, 

486 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

487 ) -> Tuple[ 

488 pubsub.ListSubscriptionsResponse, Sequence[Tuple[str, Union[str, bytes]]] 

489 ]: 

490 """Post-rpc interceptor for list_subscriptions 

491 

492 Override in a subclass to read or manipulate the response or metadata after it 

493 is returned by the Subscriber server but before it is returned to user code. 

494 

495 We recommend only using this `post_list_subscriptions_with_metadata` 

496 interceptor in new development instead of the `post_list_subscriptions` interceptor. 

497 When both interceptors are used, this `post_list_subscriptions_with_metadata` interceptor runs after the 

498 `post_list_subscriptions` interceptor. The (possibly modified) response returned by 

499 `post_list_subscriptions` will be passed to 

500 `post_list_subscriptions_with_metadata`. 

501 """ 

502 return response, metadata 

503 

504 def pre_modify_ack_deadline( 

505 self, 

506 request: pubsub.ModifyAckDeadlineRequest, 

507 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

508 ) -> Tuple[ 

509 pubsub.ModifyAckDeadlineRequest, Sequence[Tuple[str, Union[str, bytes]]] 

510 ]: 

511 """Pre-rpc interceptor for modify_ack_deadline 

512 

513 Override in a subclass to manipulate the request or metadata 

514 before they are sent to the Subscriber server. 

515 """ 

516 return request, metadata 

517 

518 def pre_modify_push_config( 

519 self, 

520 request: pubsub.ModifyPushConfigRequest, 

521 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

522 ) -> Tuple[pubsub.ModifyPushConfigRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

523 """Pre-rpc interceptor for modify_push_config 

524 

525 Override in a subclass to manipulate the request or metadata 

526 before they are sent to the Subscriber server. 

527 """ 

528 return request, metadata 

529 

530 def pre_pull( 

531 self, 

532 request: pubsub.PullRequest, 

533 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

534 ) -> Tuple[pubsub.PullRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

535 """Pre-rpc interceptor for pull 

536 

537 Override in a subclass to manipulate the request or metadata 

538 before they are sent to the Subscriber server. 

539 """ 

540 return request, metadata 

541 

542 def post_pull(self, response: pubsub.PullResponse) -> pubsub.PullResponse: 

543 """Post-rpc interceptor for pull 

544 

545 DEPRECATED. Please use the `post_pull_with_metadata` 

546 interceptor instead. 

547 

548 Override in a subclass to read or manipulate the response 

549 after it is returned by the Subscriber server but before 

550 it is returned to user code. This `post_pull` interceptor runs 

551 before the `post_pull_with_metadata` interceptor. 

552 """ 

553 return response 

554 

555 def post_pull_with_metadata( 

556 self, 

557 response: pubsub.PullResponse, 

558 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

559 ) -> Tuple[pubsub.PullResponse, Sequence[Tuple[str, Union[str, bytes]]]]: 

560 """Post-rpc interceptor for pull 

561 

562 Override in a subclass to read or manipulate the response or metadata after it 

563 is returned by the Subscriber server but before it is returned to user code. 

564 

565 We recommend only using this `post_pull_with_metadata` 

566 interceptor in new development instead of the `post_pull` interceptor. 

567 When both interceptors are used, this `post_pull_with_metadata` interceptor runs after the 

568 `post_pull` interceptor. The (possibly modified) response returned by 

569 `post_pull` will be passed to 

570 `post_pull_with_metadata`. 

571 """ 

572 return response, metadata 

573 

574 def pre_seek( 

575 self, 

576 request: pubsub.SeekRequest, 

577 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

578 ) -> Tuple[pubsub.SeekRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

579 """Pre-rpc interceptor for seek 

580 

581 Override in a subclass to manipulate the request or metadata 

582 before they are sent to the Subscriber server. 

583 """ 

584 return request, metadata 

585 

586 def post_seek(self, response: pubsub.SeekResponse) -> pubsub.SeekResponse: 

587 """Post-rpc interceptor for seek 

588 

589 DEPRECATED. Please use the `post_seek_with_metadata` 

590 interceptor instead. 

591 

592 Override in a subclass to read or manipulate the response 

593 after it is returned by the Subscriber server but before 

594 it is returned to user code. This `post_seek` interceptor runs 

595 before the `post_seek_with_metadata` interceptor. 

596 """ 

597 return response 

598 

599 def post_seek_with_metadata( 

600 self, 

601 response: pubsub.SeekResponse, 

602 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

603 ) -> Tuple[pubsub.SeekResponse, Sequence[Tuple[str, Union[str, bytes]]]]: 

604 """Post-rpc interceptor for seek 

605 

606 Override in a subclass to read or manipulate the response or metadata after it 

607 is returned by the Subscriber server but before it is returned to user code. 

608 

609 We recommend only using this `post_seek_with_metadata` 

610 interceptor in new development instead of the `post_seek` interceptor. 

611 When both interceptors are used, this `post_seek_with_metadata` interceptor runs after the 

612 `post_seek` interceptor. The (possibly modified) response returned by 

613 `post_seek` will be passed to 

614 `post_seek_with_metadata`. 

615 """ 

616 return response, metadata 

617 

618 def pre_update_snapshot( 

619 self, 

620 request: pubsub.UpdateSnapshotRequest, 

621 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

622 ) -> Tuple[pubsub.UpdateSnapshotRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

623 """Pre-rpc interceptor for update_snapshot 

624 

625 Override in a subclass to manipulate the request or metadata 

626 before they are sent to the Subscriber server. 

627 """ 

628 return request, metadata 

629 

630 def post_update_snapshot(self, response: pubsub.Snapshot) -> pubsub.Snapshot: 

631 """Post-rpc interceptor for update_snapshot 

632 

633 DEPRECATED. Please use the `post_update_snapshot_with_metadata` 

634 interceptor instead. 

635 

636 Override in a subclass to read or manipulate the response 

637 after it is returned by the Subscriber server but before 

638 it is returned to user code. This `post_update_snapshot` interceptor runs 

639 before the `post_update_snapshot_with_metadata` interceptor. 

640 """ 

641 return response 

642 

643 def post_update_snapshot_with_metadata( 

644 self, 

645 response: pubsub.Snapshot, 

646 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

647 ) -> Tuple[pubsub.Snapshot, Sequence[Tuple[str, Union[str, bytes]]]]: 

648 """Post-rpc interceptor for update_snapshot 

649 

650 Override in a subclass to read or manipulate the response or metadata after it 

651 is returned by the Subscriber server but before it is returned to user code. 

652 

653 We recommend only using this `post_update_snapshot_with_metadata` 

654 interceptor in new development instead of the `post_update_snapshot` interceptor. 

655 When both interceptors are used, this `post_update_snapshot_with_metadata` interceptor runs after the 

656 `post_update_snapshot` interceptor. The (possibly modified) response returned by 

657 `post_update_snapshot` will be passed to 

658 `post_update_snapshot_with_metadata`. 

659 """ 

660 return response, metadata 

661 

662 def pre_update_subscription( 

663 self, 

664 request: pubsub.UpdateSubscriptionRequest, 

665 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

666 ) -> Tuple[ 

667 pubsub.UpdateSubscriptionRequest, Sequence[Tuple[str, Union[str, bytes]]] 

668 ]: 

669 """Pre-rpc interceptor for update_subscription 

670 

671 Override in a subclass to manipulate the request or metadata 

672 before they are sent to the Subscriber server. 

673 """ 

674 return request, metadata 

675 

676 def post_update_subscription( 

677 self, response: pubsub.Subscription 

678 ) -> pubsub.Subscription: 

679 """Post-rpc interceptor for update_subscription 

680 

681 DEPRECATED. Please use the `post_update_subscription_with_metadata` 

682 interceptor instead. 

683 

684 Override in a subclass to read or manipulate the response 

685 after it is returned by the Subscriber server but before 

686 it is returned to user code. This `post_update_subscription` interceptor runs 

687 before the `post_update_subscription_with_metadata` interceptor. 

688 """ 

689 return response 

690 

691 def post_update_subscription_with_metadata( 

692 self, 

693 response: pubsub.Subscription, 

694 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

695 ) -> Tuple[pubsub.Subscription, Sequence[Tuple[str, Union[str, bytes]]]]: 

696 """Post-rpc interceptor for update_subscription 

697 

698 Override in a subclass to read or manipulate the response or metadata after it 

699 is returned by the Subscriber server but before it is returned to user code. 

700 

701 We recommend only using this `post_update_subscription_with_metadata` 

702 interceptor in new development instead of the `post_update_subscription` interceptor. 

703 When both interceptors are used, this `post_update_subscription_with_metadata` interceptor runs after the 

704 `post_update_subscription` interceptor. The (possibly modified) response returned by 

705 `post_update_subscription` will be passed to 

706 `post_update_subscription_with_metadata`. 

707 """ 

708 return response, metadata 

709 

710 def pre_get_iam_policy( 

711 self, 

712 request: iam_policy_pb2.GetIamPolicyRequest, 

713 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

714 ) -> Tuple[ 

715 iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] 

716 ]: 

717 """Pre-rpc interceptor for get_iam_policy 

718 

719 Override in a subclass to manipulate the request or metadata 

720 before they are sent to the Subscriber server. 

721 """ 

722 return request, metadata 

723 

724 def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: 

725 """Post-rpc interceptor for get_iam_policy 

726 

727 Override in a subclass to manipulate the response 

728 after it is returned by the Subscriber server but before 

729 it is returned to user code. 

730 """ 

731 return response 

732 

733 def pre_set_iam_policy( 

734 self, 

735 request: iam_policy_pb2.SetIamPolicyRequest, 

736 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

737 ) -> Tuple[ 

738 iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, Union[str, bytes]]] 

739 ]: 

740 """Pre-rpc interceptor for set_iam_policy 

741 

742 Override in a subclass to manipulate the request or metadata 

743 before they are sent to the Subscriber server. 

744 """ 

745 return request, metadata 

746 

747 def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: 

748 """Post-rpc interceptor for set_iam_policy 

749 

750 Override in a subclass to manipulate the response 

751 after it is returned by the Subscriber server but before 

752 it is returned to user code. 

753 """ 

754 return response 

755 

756 def pre_test_iam_permissions( 

757 self, 

758 request: iam_policy_pb2.TestIamPermissionsRequest, 

759 metadata: Sequence[Tuple[str, Union[str, bytes]]], 

760 ) -> Tuple[ 

761 iam_policy_pb2.TestIamPermissionsRequest, 

762 Sequence[Tuple[str, Union[str, bytes]]], 

763 ]: 

764 """Pre-rpc interceptor for test_iam_permissions 

765 

766 Override in a subclass to manipulate the request or metadata 

767 before they are sent to the Subscriber server. 

768 """ 

769 return request, metadata 

770 

771 def post_test_iam_permissions( 

772 self, response: iam_policy_pb2.TestIamPermissionsResponse 

773 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

774 """Post-rpc interceptor for test_iam_permissions 

775 

776 Override in a subclass to manipulate the response 

777 after it is returned by the Subscriber server but before 

778 it is returned to user code. 

779 """ 

780 return response 

781 

782 

783@dataclasses.dataclass 

784class SubscriberRestStub: 

785 _session: AuthorizedSession 

786 _host: str 

787 _interceptor: SubscriberRestInterceptor 

788 

789 

790class SubscriberRestTransport(_BaseSubscriberRestTransport): 

791 """REST backend synchronous transport for Subscriber. 

792 

793 The service that an application uses to manipulate subscriptions and 

794 to consume messages from a subscription via the ``Pull`` method or 

795 by establishing a bi-directional stream using the ``StreamingPull`` 

796 method. 

797 

798 This class defines the same methods as the primary client, so the 

799 primary client can load the underlying transport implementation 

800 and call it. 

801 

802 It sends JSON representations of protocol buffers over HTTP/1.1 

803 """ 

804 

805 def __init__( 

806 self, 

807 *, 

808 host: str = "pubsub.googleapis.com", 

809 credentials: Optional[ga_credentials.Credentials] = None, 

810 credentials_file: Optional[str] = None, 

811 scopes: Optional[Sequence[str]] = None, 

812 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

813 quota_project_id: Optional[str] = None, 

814 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

815 always_use_jwt_access: Optional[bool] = False, 

816 url_scheme: str = "https", 

817 interceptor: Optional[SubscriberRestInterceptor] = None, 

818 api_audience: Optional[str] = None, 

819 ) -> None: 

820 """Instantiate the transport. 

821 

822 Args: 

823 host (Optional[str]): 

824 The hostname to connect to (default: 'pubsub.googleapis.com'). 

825 credentials (Optional[google.auth.credentials.Credentials]): The 

826 authorization credentials to attach to requests. These 

827 credentials identify the application to the service; if none 

828 are specified, the client will attempt to ascertain the 

829 credentials from the environment. 

830 

831 credentials_file (Optional[str]): A file with credentials that can 

832 be loaded with :func:`google.auth.load_credentials_from_file`. 

833 This argument is ignored if ``channel`` is provided. 

834 scopes (Optional(Sequence[str])): A list of scopes. This argument is 

835 ignored if ``channel`` is provided. 

836 client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client 

837 certificate to configure mutual TLS HTTP channel. It is ignored 

838 if ``channel`` is provided. 

839 quota_project_id (Optional[str]): An optional project to use for billing 

840 and quota. 

841 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 

842 The client info used to send a user-agent string along with 

843 API requests. If ``None``, then default info will be used. 

844 Generally, you only need to set this if you are developing 

845 your own client library. 

846 always_use_jwt_access (Optional[bool]): Whether self signed JWT should 

847 be used for service account credentials. 

848 url_scheme: the protocol scheme for the API endpoint. Normally 

849 "https", but for testing or local servers, 

850 "http" can be specified. 

851 """ 

852 # Run the base constructor 

853 # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. 

854 # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the 

855 # credentials object 

856 super().__init__( 

857 host=host, 

858 credentials=credentials, 

859 client_info=client_info, 

860 always_use_jwt_access=always_use_jwt_access, 

861 url_scheme=url_scheme, 

862 api_audience=api_audience, 

863 ) 

864 self._session = AuthorizedSession( 

865 self._credentials, default_host=self.DEFAULT_HOST 

866 ) 

867 if client_cert_source_for_mtls: 

868 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

869 self._interceptor = interceptor or SubscriberRestInterceptor() 

870 self._prep_wrapped_messages(client_info) 

871 

872 class _Acknowledge( 

873 _BaseSubscriberRestTransport._BaseAcknowledge, SubscriberRestStub 

874 ): 

875 def __hash__(self): 

876 return hash("SubscriberRestTransport.Acknowledge") 

877 

878 @staticmethod 

879 def _get_response( 

880 host, 

881 metadata, 

882 query_params, 

883 session, 

884 timeout, 

885 transcoded_request, 

886 body=None, 

887 ): 

888 uri = transcoded_request["uri"] 

889 method = transcoded_request["method"] 

890 headers = dict(metadata) 

891 headers["Content-Type"] = "application/json" 

892 response = getattr(session, method)( 

893 "{host}{uri}".format(host=host, uri=uri), 

894 timeout=timeout, 

895 headers=headers, 

896 params=rest_helpers.flatten_query_params(query_params, strict=True), 

897 data=body, 

898 ) 

899 return response 

900 

901 def __call__( 

902 self, 

903 request: pubsub.AcknowledgeRequest, 

904 *, 

905 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

906 timeout: Optional[float] = None, 

907 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

908 ): 

909 r"""Call the acknowledge method over HTTP. 

910 

911 Args: 

912 request (~.pubsub.AcknowledgeRequest): 

913 The request object. Request for the Acknowledge method. 

914 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

915 should be retried. 

916 timeout (float): The timeout for this request. 

917 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

918 sent along with the request as metadata. Normally, each value must be of type `str`, 

919 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

920 be of type `bytes`. 

921 """ 

922 

923 http_options = ( 

924 _BaseSubscriberRestTransport._BaseAcknowledge._get_http_options() 

925 ) 

926 

927 request, metadata = self._interceptor.pre_acknowledge(request, metadata) 

928 transcoded_request = ( 

929 _BaseSubscriberRestTransport._BaseAcknowledge._get_transcoded_request( 

930 http_options, request 

931 ) 

932 ) 

933 

934 body = _BaseSubscriberRestTransport._BaseAcknowledge._get_request_body_json( 

935 transcoded_request 

936 ) 

937 

938 # Jsonify the query params 

939 query_params = ( 

940 _BaseSubscriberRestTransport._BaseAcknowledge._get_query_params_json( 

941 transcoded_request 

942 ) 

943 ) 

944 

945 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

946 logging.DEBUG 

947 ): # pragma: NO COVER 

948 request_url = "{host}{uri}".format( 

949 host=self._host, uri=transcoded_request["uri"] 

950 ) 

951 method = transcoded_request["method"] 

952 try: 

953 request_payload = json_format.MessageToJson(request) 

954 except: 

955 request_payload = None 

956 http_request = { 

957 "payload": request_payload, 

958 "requestMethod": method, 

959 "requestUrl": request_url, 

960 "headers": dict(metadata), 

961 } 

962 _LOGGER.debug( 

963 f"Sending request for google.pubsub_v1.SubscriberClient.Acknowledge", 

964 extra={ 

965 "serviceName": "google.pubsub.v1.Subscriber", 

966 "rpcName": "Acknowledge", 

967 "httpRequest": http_request, 

968 "metadata": http_request["headers"], 

969 }, 

970 ) 

971 

972 # Send the request 

973 response = SubscriberRestTransport._Acknowledge._get_response( 

974 self._host, 

975 metadata, 

976 query_params, 

977 self._session, 

978 timeout, 

979 transcoded_request, 

980 body, 

981 ) 

982 

983 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

984 # subclass. 

985 if response.status_code >= 400: 

986 raise core_exceptions.from_http_response(response) 

987 

988 class _CreateSnapshot( 

989 _BaseSubscriberRestTransport._BaseCreateSnapshot, SubscriberRestStub 

990 ): 

991 def __hash__(self): 

992 return hash("SubscriberRestTransport.CreateSnapshot") 

993 

994 @staticmethod 

995 def _get_response( 

996 host, 

997 metadata, 

998 query_params, 

999 session, 

1000 timeout, 

1001 transcoded_request, 

1002 body=None, 

1003 ): 

1004 uri = transcoded_request["uri"] 

1005 method = transcoded_request["method"] 

1006 headers = dict(metadata) 

1007 headers["Content-Type"] = "application/json" 

1008 response = getattr(session, method)( 

1009 "{host}{uri}".format(host=host, uri=uri), 

1010 timeout=timeout, 

1011 headers=headers, 

1012 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1013 data=body, 

1014 ) 

1015 return response 

1016 

1017 def __call__( 

1018 self, 

1019 request: pubsub.CreateSnapshotRequest, 

1020 *, 

1021 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1022 timeout: Optional[float] = None, 

1023 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1024 ) -> pubsub.Snapshot: 

1025 r"""Call the create snapshot method over HTTP. 

1026 

1027 Args: 

1028 request (~.pubsub.CreateSnapshotRequest): 

1029 The request object. Request for the ``CreateSnapshot`` method. 

1030 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1031 should be retried. 

1032 timeout (float): The timeout for this request. 

1033 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1034 sent along with the request as metadata. Normally, each value must be of type `str`, 

1035 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1036 be of type `bytes`. 

1037 

1038 Returns: 

1039 ~.pubsub.Snapshot: 

1040 A snapshot resource. Snapshots are used in 

1041 `Seek <https://cloud.google.com/pubsub/docs/replay-overview>`__ 

1042 operations, which allow you to manage message 

1043 acknowledgments in bulk. That is, you can set the 

1044 acknowledgment state of messages in an existing 

1045 subscription to the state captured by a snapshot. 

1046 

1047 """ 

1048 

1049 http_options = ( 

1050 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_http_options() 

1051 ) 

1052 

1053 request, metadata = self._interceptor.pre_create_snapshot(request, metadata) 

1054 transcoded_request = _BaseSubscriberRestTransport._BaseCreateSnapshot._get_transcoded_request( 

1055 http_options, request 

1056 ) 

1057 

1058 body = ( 

1059 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_request_body_json( 

1060 transcoded_request 

1061 ) 

1062 ) 

1063 

1064 # Jsonify the query params 

1065 query_params = ( 

1066 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_query_params_json( 

1067 transcoded_request 

1068 ) 

1069 ) 

1070 

1071 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1072 logging.DEBUG 

1073 ): # pragma: NO COVER 

1074 request_url = "{host}{uri}".format( 

1075 host=self._host, uri=transcoded_request["uri"] 

1076 ) 

1077 method = transcoded_request["method"] 

1078 try: 

1079 request_payload = type(request).to_json(request) 

1080 except: 

1081 request_payload = None 

1082 http_request = { 

1083 "payload": request_payload, 

1084 "requestMethod": method, 

1085 "requestUrl": request_url, 

1086 "headers": dict(metadata), 

1087 } 

1088 _LOGGER.debug( 

1089 f"Sending request for google.pubsub_v1.SubscriberClient.CreateSnapshot", 

1090 extra={ 

1091 "serviceName": "google.pubsub.v1.Subscriber", 

1092 "rpcName": "CreateSnapshot", 

1093 "httpRequest": http_request, 

1094 "metadata": http_request["headers"], 

1095 }, 

1096 ) 

1097 

1098 # Send the request 

1099 response = SubscriberRestTransport._CreateSnapshot._get_response( 

1100 self._host, 

1101 metadata, 

1102 query_params, 

1103 self._session, 

1104 timeout, 

1105 transcoded_request, 

1106 body, 

1107 ) 

1108 

1109 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1110 # subclass. 

1111 if response.status_code >= 400: 

1112 raise core_exceptions.from_http_response(response) 

1113 

1114 # Return the response 

1115 resp = pubsub.Snapshot() 

1116 pb_resp = pubsub.Snapshot.pb(resp) 

1117 

1118 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1119 

1120 resp = self._interceptor.post_create_snapshot(resp) 

1121 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

1122 resp, _ = self._interceptor.post_create_snapshot_with_metadata( 

1123 resp, response_metadata 

1124 ) 

1125 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1126 logging.DEBUG 

1127 ): # pragma: NO COVER 

1128 try: 

1129 response_payload = pubsub.Snapshot.to_json(response) 

1130 except: 

1131 response_payload = None 

1132 http_response = { 

1133 "payload": response_payload, 

1134 "headers": dict(response.headers), 

1135 "status": response.status_code, 

1136 } 

1137 _LOGGER.debug( 

1138 "Received response for google.pubsub_v1.SubscriberClient.create_snapshot", 

1139 extra={ 

1140 "serviceName": "google.pubsub.v1.Subscriber", 

1141 "rpcName": "CreateSnapshot", 

1142 "metadata": http_response["headers"], 

1143 "httpResponse": http_response, 

1144 }, 

1145 ) 

1146 return resp 

1147 

1148 class _CreateSubscription( 

1149 _BaseSubscriberRestTransport._BaseCreateSubscription, SubscriberRestStub 

1150 ): 

1151 def __hash__(self): 

1152 return hash("SubscriberRestTransport.CreateSubscription") 

1153 

1154 @staticmethod 

1155 def _get_response( 

1156 host, 

1157 metadata, 

1158 query_params, 

1159 session, 

1160 timeout, 

1161 transcoded_request, 

1162 body=None, 

1163 ): 

1164 uri = transcoded_request["uri"] 

1165 method = transcoded_request["method"] 

1166 headers = dict(metadata) 

1167 headers["Content-Type"] = "application/json" 

1168 response = getattr(session, method)( 

1169 "{host}{uri}".format(host=host, uri=uri), 

1170 timeout=timeout, 

1171 headers=headers, 

1172 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1173 data=body, 

1174 ) 

1175 return response 

1176 

1177 def __call__( 

1178 self, 

1179 request: pubsub.Subscription, 

1180 *, 

1181 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1182 timeout: Optional[float] = None, 

1183 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1184 ) -> pubsub.Subscription: 

1185 r"""Call the create subscription method over HTTP. 

1186 

1187 Args: 

1188 request (~.pubsub.Subscription): 

1189 The request object. A subscription resource. If none of ``push_config``, 

1190 ``bigquery_config``, or ``cloud_storage_config`` is set, 

1191 then the subscriber will pull and ack messages using API 

1192 methods. At most one of these fields may be set. 

1193 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1194 should be retried. 

1195 timeout (float): The timeout for this request. 

1196 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1197 sent along with the request as metadata. Normally, each value must be of type `str`, 

1198 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1199 be of type `bytes`. 

1200 

1201 Returns: 

1202 ~.pubsub.Subscription: 

1203 A subscription resource. If none of ``push_config``, 

1204 ``bigquery_config``, or ``cloud_storage_config`` is set, 

1205 then the subscriber will pull and ack messages using API 

1206 methods. At most one of these fields may be set. 

1207 

1208 """ 

1209 

1210 http_options = ( 

1211 _BaseSubscriberRestTransport._BaseCreateSubscription._get_http_options() 

1212 ) 

1213 

1214 request, metadata = self._interceptor.pre_create_subscription( 

1215 request, metadata 

1216 ) 

1217 transcoded_request = _BaseSubscriberRestTransport._BaseCreateSubscription._get_transcoded_request( 

1218 http_options, request 

1219 ) 

1220 

1221 body = _BaseSubscriberRestTransport._BaseCreateSubscription._get_request_body_json( 

1222 transcoded_request 

1223 ) 

1224 

1225 # Jsonify the query params 

1226 query_params = _BaseSubscriberRestTransport._BaseCreateSubscription._get_query_params_json( 

1227 transcoded_request 

1228 ) 

1229 

1230 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1231 logging.DEBUG 

1232 ): # pragma: NO COVER 

1233 request_url = "{host}{uri}".format( 

1234 host=self._host, uri=transcoded_request["uri"] 

1235 ) 

1236 method = transcoded_request["method"] 

1237 try: 

1238 request_payload = type(request).to_json(request) 

1239 except: 

1240 request_payload = None 

1241 http_request = { 

1242 "payload": request_payload, 

1243 "requestMethod": method, 

1244 "requestUrl": request_url, 

1245 "headers": dict(metadata), 

1246 } 

1247 _LOGGER.debug( 

1248 f"Sending request for google.pubsub_v1.SubscriberClient.CreateSubscription", 

1249 extra={ 

1250 "serviceName": "google.pubsub.v1.Subscriber", 

1251 "rpcName": "CreateSubscription", 

1252 "httpRequest": http_request, 

1253 "metadata": http_request["headers"], 

1254 }, 

1255 ) 

1256 

1257 # Send the request 

1258 response = SubscriberRestTransport._CreateSubscription._get_response( 

1259 self._host, 

1260 metadata, 

1261 query_params, 

1262 self._session, 

1263 timeout, 

1264 transcoded_request, 

1265 body, 

1266 ) 

1267 

1268 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1269 # subclass. 

1270 if response.status_code >= 400: 

1271 raise core_exceptions.from_http_response(response) 

1272 

1273 # Return the response 

1274 resp = pubsub.Subscription() 

1275 pb_resp = pubsub.Subscription.pb(resp) 

1276 

1277 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1278 

1279 resp = self._interceptor.post_create_subscription(resp) 

1280 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

1281 resp, _ = self._interceptor.post_create_subscription_with_metadata( 

1282 resp, response_metadata 

1283 ) 

1284 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1285 logging.DEBUG 

1286 ): # pragma: NO COVER 

1287 try: 

1288 response_payload = pubsub.Subscription.to_json(response) 

1289 except: 

1290 response_payload = None 

1291 http_response = { 

1292 "payload": response_payload, 

1293 "headers": dict(response.headers), 

1294 "status": response.status_code, 

1295 } 

1296 _LOGGER.debug( 

1297 "Received response for google.pubsub_v1.SubscriberClient.create_subscription", 

1298 extra={ 

1299 "serviceName": "google.pubsub.v1.Subscriber", 

1300 "rpcName": "CreateSubscription", 

1301 "metadata": http_response["headers"], 

1302 "httpResponse": http_response, 

1303 }, 

1304 ) 

1305 return resp 

1306 

1307 class _DeleteSnapshot( 

1308 _BaseSubscriberRestTransport._BaseDeleteSnapshot, SubscriberRestStub 

1309 ): 

1310 def __hash__(self): 

1311 return hash("SubscriberRestTransport.DeleteSnapshot") 

1312 

1313 @staticmethod 

1314 def _get_response( 

1315 host, 

1316 metadata, 

1317 query_params, 

1318 session, 

1319 timeout, 

1320 transcoded_request, 

1321 body=None, 

1322 ): 

1323 uri = transcoded_request["uri"] 

1324 method = transcoded_request["method"] 

1325 headers = dict(metadata) 

1326 headers["Content-Type"] = "application/json" 

1327 response = getattr(session, method)( 

1328 "{host}{uri}".format(host=host, uri=uri), 

1329 timeout=timeout, 

1330 headers=headers, 

1331 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1332 ) 

1333 return response 

1334 

1335 def __call__( 

1336 self, 

1337 request: pubsub.DeleteSnapshotRequest, 

1338 *, 

1339 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1340 timeout: Optional[float] = None, 

1341 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1342 ): 

1343 r"""Call the delete snapshot method over HTTP. 

1344 

1345 Args: 

1346 request (~.pubsub.DeleteSnapshotRequest): 

1347 The request object. Request for the ``DeleteSnapshot`` method. 

1348 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1349 should be retried. 

1350 timeout (float): The timeout for this request. 

1351 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1352 sent along with the request as metadata. Normally, each value must be of type `str`, 

1353 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1354 be of type `bytes`. 

1355 """ 

1356 

1357 http_options = ( 

1358 _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_http_options() 

1359 ) 

1360 

1361 request, metadata = self._interceptor.pre_delete_snapshot(request, metadata) 

1362 transcoded_request = _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_transcoded_request( 

1363 http_options, request 

1364 ) 

1365 

1366 # Jsonify the query params 

1367 query_params = ( 

1368 _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_query_params_json( 

1369 transcoded_request 

1370 ) 

1371 ) 

1372 

1373 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1374 logging.DEBUG 

1375 ): # pragma: NO COVER 

1376 request_url = "{host}{uri}".format( 

1377 host=self._host, uri=transcoded_request["uri"] 

1378 ) 

1379 method = transcoded_request["method"] 

1380 try: 

1381 request_payload = json_format.MessageToJson(request) 

1382 except: 

1383 request_payload = None 

1384 http_request = { 

1385 "payload": request_payload, 

1386 "requestMethod": method, 

1387 "requestUrl": request_url, 

1388 "headers": dict(metadata), 

1389 } 

1390 _LOGGER.debug( 

1391 f"Sending request for google.pubsub_v1.SubscriberClient.DeleteSnapshot", 

1392 extra={ 

1393 "serviceName": "google.pubsub.v1.Subscriber", 

1394 "rpcName": "DeleteSnapshot", 

1395 "httpRequest": http_request, 

1396 "metadata": http_request["headers"], 

1397 }, 

1398 ) 

1399 

1400 # Send the request 

1401 response = SubscriberRestTransport._DeleteSnapshot._get_response( 

1402 self._host, 

1403 metadata, 

1404 query_params, 

1405 self._session, 

1406 timeout, 

1407 transcoded_request, 

1408 ) 

1409 

1410 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1411 # subclass. 

1412 if response.status_code >= 400: 

1413 raise core_exceptions.from_http_response(response) 

1414 

1415 class _DeleteSubscription( 

1416 _BaseSubscriberRestTransport._BaseDeleteSubscription, SubscriberRestStub 

1417 ): 

1418 def __hash__(self): 

1419 return hash("SubscriberRestTransport.DeleteSubscription") 

1420 

1421 @staticmethod 

1422 def _get_response( 

1423 host, 

1424 metadata, 

1425 query_params, 

1426 session, 

1427 timeout, 

1428 transcoded_request, 

1429 body=None, 

1430 ): 

1431 uri = transcoded_request["uri"] 

1432 method = transcoded_request["method"] 

1433 headers = dict(metadata) 

1434 headers["Content-Type"] = "application/json" 

1435 response = getattr(session, method)( 

1436 "{host}{uri}".format(host=host, uri=uri), 

1437 timeout=timeout, 

1438 headers=headers, 

1439 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1440 ) 

1441 return response 

1442 

1443 def __call__( 

1444 self, 

1445 request: pubsub.DeleteSubscriptionRequest, 

1446 *, 

1447 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1448 timeout: Optional[float] = None, 

1449 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1450 ): 

1451 r"""Call the delete subscription method over HTTP. 

1452 

1453 Args: 

1454 request (~.pubsub.DeleteSubscriptionRequest): 

1455 The request object. Request for the DeleteSubscription 

1456 method. 

1457 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1458 should be retried. 

1459 timeout (float): The timeout for this request. 

1460 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1461 sent along with the request as metadata. Normally, each value must be of type `str`, 

1462 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1463 be of type `bytes`. 

1464 """ 

1465 

1466 http_options = ( 

1467 _BaseSubscriberRestTransport._BaseDeleteSubscription._get_http_options() 

1468 ) 

1469 

1470 request, metadata = self._interceptor.pre_delete_subscription( 

1471 request, metadata 

1472 ) 

1473 transcoded_request = _BaseSubscriberRestTransport._BaseDeleteSubscription._get_transcoded_request( 

1474 http_options, request 

1475 ) 

1476 

1477 # Jsonify the query params 

1478 query_params = _BaseSubscriberRestTransport._BaseDeleteSubscription._get_query_params_json( 

1479 transcoded_request 

1480 ) 

1481 

1482 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1483 logging.DEBUG 

1484 ): # pragma: NO COVER 

1485 request_url = "{host}{uri}".format( 

1486 host=self._host, uri=transcoded_request["uri"] 

1487 ) 

1488 method = transcoded_request["method"] 

1489 try: 

1490 request_payload = json_format.MessageToJson(request) 

1491 except: 

1492 request_payload = None 

1493 http_request = { 

1494 "payload": request_payload, 

1495 "requestMethod": method, 

1496 "requestUrl": request_url, 

1497 "headers": dict(metadata), 

1498 } 

1499 _LOGGER.debug( 

1500 f"Sending request for google.pubsub_v1.SubscriberClient.DeleteSubscription", 

1501 extra={ 

1502 "serviceName": "google.pubsub.v1.Subscriber", 

1503 "rpcName": "DeleteSubscription", 

1504 "httpRequest": http_request, 

1505 "metadata": http_request["headers"], 

1506 }, 

1507 ) 

1508 

1509 # Send the request 

1510 response = SubscriberRestTransport._DeleteSubscription._get_response( 

1511 self._host, 

1512 metadata, 

1513 query_params, 

1514 self._session, 

1515 timeout, 

1516 transcoded_request, 

1517 ) 

1518 

1519 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1520 # subclass. 

1521 if response.status_code >= 400: 

1522 raise core_exceptions.from_http_response(response) 

1523 

1524 class _GetSnapshot( 

1525 _BaseSubscriberRestTransport._BaseGetSnapshot, SubscriberRestStub 

1526 ): 

1527 def __hash__(self): 

1528 return hash("SubscriberRestTransport.GetSnapshot") 

1529 

1530 @staticmethod 

1531 def _get_response( 

1532 host, 

1533 metadata, 

1534 query_params, 

1535 session, 

1536 timeout, 

1537 transcoded_request, 

1538 body=None, 

1539 ): 

1540 uri = transcoded_request["uri"] 

1541 method = transcoded_request["method"] 

1542 headers = dict(metadata) 

1543 headers["Content-Type"] = "application/json" 

1544 response = getattr(session, method)( 

1545 "{host}{uri}".format(host=host, uri=uri), 

1546 timeout=timeout, 

1547 headers=headers, 

1548 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1549 ) 

1550 return response 

1551 

1552 def __call__( 

1553 self, 

1554 request: pubsub.GetSnapshotRequest, 

1555 *, 

1556 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1557 timeout: Optional[float] = None, 

1558 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1559 ) -> pubsub.Snapshot: 

1560 r"""Call the get snapshot method over HTTP. 

1561 

1562 Args: 

1563 request (~.pubsub.GetSnapshotRequest): 

1564 The request object. Request for the GetSnapshot method. 

1565 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1566 should be retried. 

1567 timeout (float): The timeout for this request. 

1568 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1569 sent along with the request as metadata. Normally, each value must be of type `str`, 

1570 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1571 be of type `bytes`. 

1572 

1573 Returns: 

1574 ~.pubsub.Snapshot: 

1575 A snapshot resource. Snapshots are used in 

1576 `Seek <https://cloud.google.com/pubsub/docs/replay-overview>`__ 

1577 operations, which allow you to manage message 

1578 acknowledgments in bulk. That is, you can set the 

1579 acknowledgment state of messages in an existing 

1580 subscription to the state captured by a snapshot. 

1581 

1582 """ 

1583 

1584 http_options = ( 

1585 _BaseSubscriberRestTransport._BaseGetSnapshot._get_http_options() 

1586 ) 

1587 

1588 request, metadata = self._interceptor.pre_get_snapshot(request, metadata) 

1589 transcoded_request = ( 

1590 _BaseSubscriberRestTransport._BaseGetSnapshot._get_transcoded_request( 

1591 http_options, request 

1592 ) 

1593 ) 

1594 

1595 # Jsonify the query params 

1596 query_params = ( 

1597 _BaseSubscriberRestTransport._BaseGetSnapshot._get_query_params_json( 

1598 transcoded_request 

1599 ) 

1600 ) 

1601 

1602 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1603 logging.DEBUG 

1604 ): # pragma: NO COVER 

1605 request_url = "{host}{uri}".format( 

1606 host=self._host, uri=transcoded_request["uri"] 

1607 ) 

1608 method = transcoded_request["method"] 

1609 try: 

1610 request_payload = type(request).to_json(request) 

1611 except: 

1612 request_payload = None 

1613 http_request = { 

1614 "payload": request_payload, 

1615 "requestMethod": method, 

1616 "requestUrl": request_url, 

1617 "headers": dict(metadata), 

1618 } 

1619 _LOGGER.debug( 

1620 f"Sending request for google.pubsub_v1.SubscriberClient.GetSnapshot", 

1621 extra={ 

1622 "serviceName": "google.pubsub.v1.Subscriber", 

1623 "rpcName": "GetSnapshot", 

1624 "httpRequest": http_request, 

1625 "metadata": http_request["headers"], 

1626 }, 

1627 ) 

1628 

1629 # Send the request 

1630 response = SubscriberRestTransport._GetSnapshot._get_response( 

1631 self._host, 

1632 metadata, 

1633 query_params, 

1634 self._session, 

1635 timeout, 

1636 transcoded_request, 

1637 ) 

1638 

1639 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1640 # subclass. 

1641 if response.status_code >= 400: 

1642 raise core_exceptions.from_http_response(response) 

1643 

1644 # Return the response 

1645 resp = pubsub.Snapshot() 

1646 pb_resp = pubsub.Snapshot.pb(resp) 

1647 

1648 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1649 

1650 resp = self._interceptor.post_get_snapshot(resp) 

1651 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

1652 resp, _ = self._interceptor.post_get_snapshot_with_metadata( 

1653 resp, response_metadata 

1654 ) 

1655 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1656 logging.DEBUG 

1657 ): # pragma: NO COVER 

1658 try: 

1659 response_payload = pubsub.Snapshot.to_json(response) 

1660 except: 

1661 response_payload = None 

1662 http_response = { 

1663 "payload": response_payload, 

1664 "headers": dict(response.headers), 

1665 "status": response.status_code, 

1666 } 

1667 _LOGGER.debug( 

1668 "Received response for google.pubsub_v1.SubscriberClient.get_snapshot", 

1669 extra={ 

1670 "serviceName": "google.pubsub.v1.Subscriber", 

1671 "rpcName": "GetSnapshot", 

1672 "metadata": http_response["headers"], 

1673 "httpResponse": http_response, 

1674 }, 

1675 ) 

1676 return resp 

1677 

1678 class _GetSubscription( 

1679 _BaseSubscriberRestTransport._BaseGetSubscription, SubscriberRestStub 

1680 ): 

1681 def __hash__(self): 

1682 return hash("SubscriberRestTransport.GetSubscription") 

1683 

1684 @staticmethod 

1685 def _get_response( 

1686 host, 

1687 metadata, 

1688 query_params, 

1689 session, 

1690 timeout, 

1691 transcoded_request, 

1692 body=None, 

1693 ): 

1694 uri = transcoded_request["uri"] 

1695 method = transcoded_request["method"] 

1696 headers = dict(metadata) 

1697 headers["Content-Type"] = "application/json" 

1698 response = getattr(session, method)( 

1699 "{host}{uri}".format(host=host, uri=uri), 

1700 timeout=timeout, 

1701 headers=headers, 

1702 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1703 ) 

1704 return response 

1705 

1706 def __call__( 

1707 self, 

1708 request: pubsub.GetSubscriptionRequest, 

1709 *, 

1710 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1711 timeout: Optional[float] = None, 

1712 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1713 ) -> pubsub.Subscription: 

1714 r"""Call the get subscription method over HTTP. 

1715 

1716 Args: 

1717 request (~.pubsub.GetSubscriptionRequest): 

1718 The request object. Request for the GetSubscription 

1719 method. 

1720 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1721 should be retried. 

1722 timeout (float): The timeout for this request. 

1723 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1724 sent along with the request as metadata. Normally, each value must be of type `str`, 

1725 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1726 be of type `bytes`. 

1727 

1728 Returns: 

1729 ~.pubsub.Subscription: 

1730 A subscription resource. If none of ``push_config``, 

1731 ``bigquery_config``, or ``cloud_storage_config`` is set, 

1732 then the subscriber will pull and ack messages using API 

1733 methods. At most one of these fields may be set. 

1734 

1735 """ 

1736 

1737 http_options = ( 

1738 _BaseSubscriberRestTransport._BaseGetSubscription._get_http_options() 

1739 ) 

1740 

1741 request, metadata = self._interceptor.pre_get_subscription( 

1742 request, metadata 

1743 ) 

1744 transcoded_request = _BaseSubscriberRestTransport._BaseGetSubscription._get_transcoded_request( 

1745 http_options, request 

1746 ) 

1747 

1748 # Jsonify the query params 

1749 query_params = _BaseSubscriberRestTransport._BaseGetSubscription._get_query_params_json( 

1750 transcoded_request 

1751 ) 

1752 

1753 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1754 logging.DEBUG 

1755 ): # pragma: NO COVER 

1756 request_url = "{host}{uri}".format( 

1757 host=self._host, uri=transcoded_request["uri"] 

1758 ) 

1759 method = transcoded_request["method"] 

1760 try: 

1761 request_payload = type(request).to_json(request) 

1762 except: 

1763 request_payload = None 

1764 http_request = { 

1765 "payload": request_payload, 

1766 "requestMethod": method, 

1767 "requestUrl": request_url, 

1768 "headers": dict(metadata), 

1769 } 

1770 _LOGGER.debug( 

1771 f"Sending request for google.pubsub_v1.SubscriberClient.GetSubscription", 

1772 extra={ 

1773 "serviceName": "google.pubsub.v1.Subscriber", 

1774 "rpcName": "GetSubscription", 

1775 "httpRequest": http_request, 

1776 "metadata": http_request["headers"], 

1777 }, 

1778 ) 

1779 

1780 # Send the request 

1781 response = SubscriberRestTransport._GetSubscription._get_response( 

1782 self._host, 

1783 metadata, 

1784 query_params, 

1785 self._session, 

1786 timeout, 

1787 transcoded_request, 

1788 ) 

1789 

1790 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1791 # subclass. 

1792 if response.status_code >= 400: 

1793 raise core_exceptions.from_http_response(response) 

1794 

1795 # Return the response 

1796 resp = pubsub.Subscription() 

1797 pb_resp = pubsub.Subscription.pb(resp) 

1798 

1799 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1800 

1801 resp = self._interceptor.post_get_subscription(resp) 

1802 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

1803 resp, _ = self._interceptor.post_get_subscription_with_metadata( 

1804 resp, response_metadata 

1805 ) 

1806 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1807 logging.DEBUG 

1808 ): # pragma: NO COVER 

1809 try: 

1810 response_payload = pubsub.Subscription.to_json(response) 

1811 except: 

1812 response_payload = None 

1813 http_response = { 

1814 "payload": response_payload, 

1815 "headers": dict(response.headers), 

1816 "status": response.status_code, 

1817 } 

1818 _LOGGER.debug( 

1819 "Received response for google.pubsub_v1.SubscriberClient.get_subscription", 

1820 extra={ 

1821 "serviceName": "google.pubsub.v1.Subscriber", 

1822 "rpcName": "GetSubscription", 

1823 "metadata": http_response["headers"], 

1824 "httpResponse": http_response, 

1825 }, 

1826 ) 

1827 return resp 

1828 

1829 class _ListSnapshots( 

1830 _BaseSubscriberRestTransport._BaseListSnapshots, SubscriberRestStub 

1831 ): 

1832 def __hash__(self): 

1833 return hash("SubscriberRestTransport.ListSnapshots") 

1834 

1835 @staticmethod 

1836 def _get_response( 

1837 host, 

1838 metadata, 

1839 query_params, 

1840 session, 

1841 timeout, 

1842 transcoded_request, 

1843 body=None, 

1844 ): 

1845 uri = transcoded_request["uri"] 

1846 method = transcoded_request["method"] 

1847 headers = dict(metadata) 

1848 headers["Content-Type"] = "application/json" 

1849 response = getattr(session, method)( 

1850 "{host}{uri}".format(host=host, uri=uri), 

1851 timeout=timeout, 

1852 headers=headers, 

1853 params=rest_helpers.flatten_query_params(query_params, strict=True), 

1854 ) 

1855 return response 

1856 

1857 def __call__( 

1858 self, 

1859 request: pubsub.ListSnapshotsRequest, 

1860 *, 

1861 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1862 timeout: Optional[float] = None, 

1863 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1864 ) -> pubsub.ListSnapshotsResponse: 

1865 r"""Call the list snapshots method over HTTP. 

1866 

1867 Args: 

1868 request (~.pubsub.ListSnapshotsRequest): 

1869 The request object. Request for the ``ListSnapshots`` method. 

1870 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1871 should be retried. 

1872 timeout (float): The timeout for this request. 

1873 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1874 sent along with the request as metadata. Normally, each value must be of type `str`, 

1875 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1876 be of type `bytes`. 

1877 

1878 Returns: 

1879 ~.pubsub.ListSnapshotsResponse: 

1880 Response for the ``ListSnapshots`` method. 

1881 """ 

1882 

1883 http_options = ( 

1884 _BaseSubscriberRestTransport._BaseListSnapshots._get_http_options() 

1885 ) 

1886 

1887 request, metadata = self._interceptor.pre_list_snapshots(request, metadata) 

1888 transcoded_request = ( 

1889 _BaseSubscriberRestTransport._BaseListSnapshots._get_transcoded_request( 

1890 http_options, request 

1891 ) 

1892 ) 

1893 

1894 # Jsonify the query params 

1895 query_params = ( 

1896 _BaseSubscriberRestTransport._BaseListSnapshots._get_query_params_json( 

1897 transcoded_request 

1898 ) 

1899 ) 

1900 

1901 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1902 logging.DEBUG 

1903 ): # pragma: NO COVER 

1904 request_url = "{host}{uri}".format( 

1905 host=self._host, uri=transcoded_request["uri"] 

1906 ) 

1907 method = transcoded_request["method"] 

1908 try: 

1909 request_payload = type(request).to_json(request) 

1910 except: 

1911 request_payload = None 

1912 http_request = { 

1913 "payload": request_payload, 

1914 "requestMethod": method, 

1915 "requestUrl": request_url, 

1916 "headers": dict(metadata), 

1917 } 

1918 _LOGGER.debug( 

1919 f"Sending request for google.pubsub_v1.SubscriberClient.ListSnapshots", 

1920 extra={ 

1921 "serviceName": "google.pubsub.v1.Subscriber", 

1922 "rpcName": "ListSnapshots", 

1923 "httpRequest": http_request, 

1924 "metadata": http_request["headers"], 

1925 }, 

1926 ) 

1927 

1928 # Send the request 

1929 response = SubscriberRestTransport._ListSnapshots._get_response( 

1930 self._host, 

1931 metadata, 

1932 query_params, 

1933 self._session, 

1934 timeout, 

1935 transcoded_request, 

1936 ) 

1937 

1938 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

1939 # subclass. 

1940 if response.status_code >= 400: 

1941 raise core_exceptions.from_http_response(response) 

1942 

1943 # Return the response 

1944 resp = pubsub.ListSnapshotsResponse() 

1945 pb_resp = pubsub.ListSnapshotsResponse.pb(resp) 

1946 

1947 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

1948 

1949 resp = self._interceptor.post_list_snapshots(resp) 

1950 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

1951 resp, _ = self._interceptor.post_list_snapshots_with_metadata( 

1952 resp, response_metadata 

1953 ) 

1954 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1955 logging.DEBUG 

1956 ): # pragma: NO COVER 

1957 try: 

1958 response_payload = pubsub.ListSnapshotsResponse.to_json(response) 

1959 except: 

1960 response_payload = None 

1961 http_response = { 

1962 "payload": response_payload, 

1963 "headers": dict(response.headers), 

1964 "status": response.status_code, 

1965 } 

1966 _LOGGER.debug( 

1967 "Received response for google.pubsub_v1.SubscriberClient.list_snapshots", 

1968 extra={ 

1969 "serviceName": "google.pubsub.v1.Subscriber", 

1970 "rpcName": "ListSnapshots", 

1971 "metadata": http_response["headers"], 

1972 "httpResponse": http_response, 

1973 }, 

1974 ) 

1975 return resp 

1976 

1977 class _ListSubscriptions( 

1978 _BaseSubscriberRestTransport._BaseListSubscriptions, SubscriberRestStub 

1979 ): 

1980 def __hash__(self): 

1981 return hash("SubscriberRestTransport.ListSubscriptions") 

1982 

1983 @staticmethod 

1984 def _get_response( 

1985 host, 

1986 metadata, 

1987 query_params, 

1988 session, 

1989 timeout, 

1990 transcoded_request, 

1991 body=None, 

1992 ): 

1993 uri = transcoded_request["uri"] 

1994 method = transcoded_request["method"] 

1995 headers = dict(metadata) 

1996 headers["Content-Type"] = "application/json" 

1997 response = getattr(session, method)( 

1998 "{host}{uri}".format(host=host, uri=uri), 

1999 timeout=timeout, 

2000 headers=headers, 

2001 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2002 ) 

2003 return response 

2004 

2005 def __call__( 

2006 self, 

2007 request: pubsub.ListSubscriptionsRequest, 

2008 *, 

2009 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2010 timeout: Optional[float] = None, 

2011 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2012 ) -> pubsub.ListSubscriptionsResponse: 

2013 r"""Call the list subscriptions method over HTTP. 

2014 

2015 Args: 

2016 request (~.pubsub.ListSubscriptionsRequest): 

2017 The request object. Request for the ``ListSubscriptions`` method. 

2018 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2019 should be retried. 

2020 timeout (float): The timeout for this request. 

2021 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2022 sent along with the request as metadata. Normally, each value must be of type `str`, 

2023 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2024 be of type `bytes`. 

2025 

2026 Returns: 

2027 ~.pubsub.ListSubscriptionsResponse: 

2028 Response for the ``ListSubscriptions`` method. 

2029 """ 

2030 

2031 http_options = ( 

2032 _BaseSubscriberRestTransport._BaseListSubscriptions._get_http_options() 

2033 ) 

2034 

2035 request, metadata = self._interceptor.pre_list_subscriptions( 

2036 request, metadata 

2037 ) 

2038 transcoded_request = _BaseSubscriberRestTransport._BaseListSubscriptions._get_transcoded_request( 

2039 http_options, request 

2040 ) 

2041 

2042 # Jsonify the query params 

2043 query_params = _BaseSubscriberRestTransport._BaseListSubscriptions._get_query_params_json( 

2044 transcoded_request 

2045 ) 

2046 

2047 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2048 logging.DEBUG 

2049 ): # pragma: NO COVER 

2050 request_url = "{host}{uri}".format( 

2051 host=self._host, uri=transcoded_request["uri"] 

2052 ) 

2053 method = transcoded_request["method"] 

2054 try: 

2055 request_payload = type(request).to_json(request) 

2056 except: 

2057 request_payload = None 

2058 http_request = { 

2059 "payload": request_payload, 

2060 "requestMethod": method, 

2061 "requestUrl": request_url, 

2062 "headers": dict(metadata), 

2063 } 

2064 _LOGGER.debug( 

2065 f"Sending request for google.pubsub_v1.SubscriberClient.ListSubscriptions", 

2066 extra={ 

2067 "serviceName": "google.pubsub.v1.Subscriber", 

2068 "rpcName": "ListSubscriptions", 

2069 "httpRequest": http_request, 

2070 "metadata": http_request["headers"], 

2071 }, 

2072 ) 

2073 

2074 # Send the request 

2075 response = SubscriberRestTransport._ListSubscriptions._get_response( 

2076 self._host, 

2077 metadata, 

2078 query_params, 

2079 self._session, 

2080 timeout, 

2081 transcoded_request, 

2082 ) 

2083 

2084 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2085 # subclass. 

2086 if response.status_code >= 400: 

2087 raise core_exceptions.from_http_response(response) 

2088 

2089 # Return the response 

2090 resp = pubsub.ListSubscriptionsResponse() 

2091 pb_resp = pubsub.ListSubscriptionsResponse.pb(resp) 

2092 

2093 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2094 

2095 resp = self._interceptor.post_list_subscriptions(resp) 

2096 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2097 resp, _ = self._interceptor.post_list_subscriptions_with_metadata( 

2098 resp, response_metadata 

2099 ) 

2100 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2101 logging.DEBUG 

2102 ): # pragma: NO COVER 

2103 try: 

2104 response_payload = pubsub.ListSubscriptionsResponse.to_json( 

2105 response 

2106 ) 

2107 except: 

2108 response_payload = None 

2109 http_response = { 

2110 "payload": response_payload, 

2111 "headers": dict(response.headers), 

2112 "status": response.status_code, 

2113 } 

2114 _LOGGER.debug( 

2115 "Received response for google.pubsub_v1.SubscriberClient.list_subscriptions", 

2116 extra={ 

2117 "serviceName": "google.pubsub.v1.Subscriber", 

2118 "rpcName": "ListSubscriptions", 

2119 "metadata": http_response["headers"], 

2120 "httpResponse": http_response, 

2121 }, 

2122 ) 

2123 return resp 

2124 

2125 class _ModifyAckDeadline( 

2126 _BaseSubscriberRestTransport._BaseModifyAckDeadline, SubscriberRestStub 

2127 ): 

2128 def __hash__(self): 

2129 return hash("SubscriberRestTransport.ModifyAckDeadline") 

2130 

2131 @staticmethod 

2132 def _get_response( 

2133 host, 

2134 metadata, 

2135 query_params, 

2136 session, 

2137 timeout, 

2138 transcoded_request, 

2139 body=None, 

2140 ): 

2141 uri = transcoded_request["uri"] 

2142 method = transcoded_request["method"] 

2143 headers = dict(metadata) 

2144 headers["Content-Type"] = "application/json" 

2145 response = getattr(session, method)( 

2146 "{host}{uri}".format(host=host, uri=uri), 

2147 timeout=timeout, 

2148 headers=headers, 

2149 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2150 data=body, 

2151 ) 

2152 return response 

2153 

2154 def __call__( 

2155 self, 

2156 request: pubsub.ModifyAckDeadlineRequest, 

2157 *, 

2158 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2159 timeout: Optional[float] = None, 

2160 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2161 ): 

2162 r"""Call the modify ack deadline method over HTTP. 

2163 

2164 Args: 

2165 request (~.pubsub.ModifyAckDeadlineRequest): 

2166 The request object. Request for the ModifyAckDeadline 

2167 method. 

2168 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2169 should be retried. 

2170 timeout (float): The timeout for this request. 

2171 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2172 sent along with the request as metadata. Normally, each value must be of type `str`, 

2173 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2174 be of type `bytes`. 

2175 """ 

2176 

2177 http_options = ( 

2178 _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_http_options() 

2179 ) 

2180 

2181 request, metadata = self._interceptor.pre_modify_ack_deadline( 

2182 request, metadata 

2183 ) 

2184 transcoded_request = _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_transcoded_request( 

2185 http_options, request 

2186 ) 

2187 

2188 body = _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_request_body_json( 

2189 transcoded_request 

2190 ) 

2191 

2192 # Jsonify the query params 

2193 query_params = _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_query_params_json( 

2194 transcoded_request 

2195 ) 

2196 

2197 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2198 logging.DEBUG 

2199 ): # pragma: NO COVER 

2200 request_url = "{host}{uri}".format( 

2201 host=self._host, uri=transcoded_request["uri"] 

2202 ) 

2203 method = transcoded_request["method"] 

2204 try: 

2205 request_payload = json_format.MessageToJson(request) 

2206 except: 

2207 request_payload = None 

2208 http_request = { 

2209 "payload": request_payload, 

2210 "requestMethod": method, 

2211 "requestUrl": request_url, 

2212 "headers": dict(metadata), 

2213 } 

2214 _LOGGER.debug( 

2215 f"Sending request for google.pubsub_v1.SubscriberClient.ModifyAckDeadline", 

2216 extra={ 

2217 "serviceName": "google.pubsub.v1.Subscriber", 

2218 "rpcName": "ModifyAckDeadline", 

2219 "httpRequest": http_request, 

2220 "metadata": http_request["headers"], 

2221 }, 

2222 ) 

2223 

2224 # Send the request 

2225 response = SubscriberRestTransport._ModifyAckDeadline._get_response( 

2226 self._host, 

2227 metadata, 

2228 query_params, 

2229 self._session, 

2230 timeout, 

2231 transcoded_request, 

2232 body, 

2233 ) 

2234 

2235 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2236 # subclass. 

2237 if response.status_code >= 400: 

2238 raise core_exceptions.from_http_response(response) 

2239 

2240 class _ModifyPushConfig( 

2241 _BaseSubscriberRestTransport._BaseModifyPushConfig, SubscriberRestStub 

2242 ): 

2243 def __hash__(self): 

2244 return hash("SubscriberRestTransport.ModifyPushConfig") 

2245 

2246 @staticmethod 

2247 def _get_response( 

2248 host, 

2249 metadata, 

2250 query_params, 

2251 session, 

2252 timeout, 

2253 transcoded_request, 

2254 body=None, 

2255 ): 

2256 uri = transcoded_request["uri"] 

2257 method = transcoded_request["method"] 

2258 headers = dict(metadata) 

2259 headers["Content-Type"] = "application/json" 

2260 response = getattr(session, method)( 

2261 "{host}{uri}".format(host=host, uri=uri), 

2262 timeout=timeout, 

2263 headers=headers, 

2264 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2265 data=body, 

2266 ) 

2267 return response 

2268 

2269 def __call__( 

2270 self, 

2271 request: pubsub.ModifyPushConfigRequest, 

2272 *, 

2273 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2274 timeout: Optional[float] = None, 

2275 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2276 ): 

2277 r"""Call the modify push config method over HTTP. 

2278 

2279 Args: 

2280 request (~.pubsub.ModifyPushConfigRequest): 

2281 The request object. Request for the ModifyPushConfig 

2282 method. 

2283 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2284 should be retried. 

2285 timeout (float): The timeout for this request. 

2286 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2287 sent along with the request as metadata. Normally, each value must be of type `str`, 

2288 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2289 be of type `bytes`. 

2290 """ 

2291 

2292 http_options = ( 

2293 _BaseSubscriberRestTransport._BaseModifyPushConfig._get_http_options() 

2294 ) 

2295 

2296 request, metadata = self._interceptor.pre_modify_push_config( 

2297 request, metadata 

2298 ) 

2299 transcoded_request = _BaseSubscriberRestTransport._BaseModifyPushConfig._get_transcoded_request( 

2300 http_options, request 

2301 ) 

2302 

2303 body = _BaseSubscriberRestTransport._BaseModifyPushConfig._get_request_body_json( 

2304 transcoded_request 

2305 ) 

2306 

2307 # Jsonify the query params 

2308 query_params = _BaseSubscriberRestTransport._BaseModifyPushConfig._get_query_params_json( 

2309 transcoded_request 

2310 ) 

2311 

2312 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2313 logging.DEBUG 

2314 ): # pragma: NO COVER 

2315 request_url = "{host}{uri}".format( 

2316 host=self._host, uri=transcoded_request["uri"] 

2317 ) 

2318 method = transcoded_request["method"] 

2319 try: 

2320 request_payload = json_format.MessageToJson(request) 

2321 except: 

2322 request_payload = None 

2323 http_request = { 

2324 "payload": request_payload, 

2325 "requestMethod": method, 

2326 "requestUrl": request_url, 

2327 "headers": dict(metadata), 

2328 } 

2329 _LOGGER.debug( 

2330 f"Sending request for google.pubsub_v1.SubscriberClient.ModifyPushConfig", 

2331 extra={ 

2332 "serviceName": "google.pubsub.v1.Subscriber", 

2333 "rpcName": "ModifyPushConfig", 

2334 "httpRequest": http_request, 

2335 "metadata": http_request["headers"], 

2336 }, 

2337 ) 

2338 

2339 # Send the request 

2340 response = SubscriberRestTransport._ModifyPushConfig._get_response( 

2341 self._host, 

2342 metadata, 

2343 query_params, 

2344 self._session, 

2345 timeout, 

2346 transcoded_request, 

2347 body, 

2348 ) 

2349 

2350 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2351 # subclass. 

2352 if response.status_code >= 400: 

2353 raise core_exceptions.from_http_response(response) 

2354 

2355 class _Pull(_BaseSubscriberRestTransport._BasePull, SubscriberRestStub): 

2356 def __hash__(self): 

2357 return hash("SubscriberRestTransport.Pull") 

2358 

2359 @staticmethod 

2360 def _get_response( 

2361 host, 

2362 metadata, 

2363 query_params, 

2364 session, 

2365 timeout, 

2366 transcoded_request, 

2367 body=None, 

2368 ): 

2369 uri = transcoded_request["uri"] 

2370 method = transcoded_request["method"] 

2371 headers = dict(metadata) 

2372 headers["Content-Type"] = "application/json" 

2373 response = getattr(session, method)( 

2374 "{host}{uri}".format(host=host, uri=uri), 

2375 timeout=timeout, 

2376 headers=headers, 

2377 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2378 data=body, 

2379 ) 

2380 return response 

2381 

2382 def __call__( 

2383 self, 

2384 request: pubsub.PullRequest, 

2385 *, 

2386 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2387 timeout: Optional[float] = None, 

2388 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2389 ) -> pubsub.PullResponse: 

2390 r"""Call the pull method over HTTP. 

2391 

2392 Args: 

2393 request (~.pubsub.PullRequest): 

2394 The request object. Request for the ``Pull`` method. 

2395 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2396 should be retried. 

2397 timeout (float): The timeout for this request. 

2398 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2399 sent along with the request as metadata. Normally, each value must be of type `str`, 

2400 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2401 be of type `bytes`. 

2402 

2403 Returns: 

2404 ~.pubsub.PullResponse: 

2405 Response for the ``Pull`` method. 

2406 """ 

2407 

2408 http_options = _BaseSubscriberRestTransport._BasePull._get_http_options() 

2409 

2410 request, metadata = self._interceptor.pre_pull(request, metadata) 

2411 transcoded_request = ( 

2412 _BaseSubscriberRestTransport._BasePull._get_transcoded_request( 

2413 http_options, request 

2414 ) 

2415 ) 

2416 

2417 body = _BaseSubscriberRestTransport._BasePull._get_request_body_json( 

2418 transcoded_request 

2419 ) 

2420 

2421 # Jsonify the query params 

2422 query_params = ( 

2423 _BaseSubscriberRestTransport._BasePull._get_query_params_json( 

2424 transcoded_request 

2425 ) 

2426 ) 

2427 

2428 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2429 logging.DEBUG 

2430 ): # pragma: NO COVER 

2431 request_url = "{host}{uri}".format( 

2432 host=self._host, uri=transcoded_request["uri"] 

2433 ) 

2434 method = transcoded_request["method"] 

2435 try: 

2436 request_payload = type(request).to_json(request) 

2437 except: 

2438 request_payload = None 

2439 http_request = { 

2440 "payload": request_payload, 

2441 "requestMethod": method, 

2442 "requestUrl": request_url, 

2443 "headers": dict(metadata), 

2444 } 

2445 _LOGGER.debug( 

2446 f"Sending request for google.pubsub_v1.SubscriberClient.Pull", 

2447 extra={ 

2448 "serviceName": "google.pubsub.v1.Subscriber", 

2449 "rpcName": "Pull", 

2450 "httpRequest": http_request, 

2451 "metadata": http_request["headers"], 

2452 }, 

2453 ) 

2454 

2455 # Send the request 

2456 response = SubscriberRestTransport._Pull._get_response( 

2457 self._host, 

2458 metadata, 

2459 query_params, 

2460 self._session, 

2461 timeout, 

2462 transcoded_request, 

2463 body, 

2464 ) 

2465 

2466 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2467 # subclass. 

2468 if response.status_code >= 400: 

2469 raise core_exceptions.from_http_response(response) 

2470 

2471 # Return the response 

2472 resp = pubsub.PullResponse() 

2473 pb_resp = pubsub.PullResponse.pb(resp) 

2474 

2475 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2476 

2477 resp = self._interceptor.post_pull(resp) 

2478 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2479 resp, _ = self._interceptor.post_pull_with_metadata(resp, response_metadata) 

2480 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2481 logging.DEBUG 

2482 ): # pragma: NO COVER 

2483 try: 

2484 response_payload = pubsub.PullResponse.to_json(response) 

2485 except: 

2486 response_payload = None 

2487 http_response = { 

2488 "payload": response_payload, 

2489 "headers": dict(response.headers), 

2490 "status": response.status_code, 

2491 } 

2492 _LOGGER.debug( 

2493 "Received response for google.pubsub_v1.SubscriberClient.pull", 

2494 extra={ 

2495 "serviceName": "google.pubsub.v1.Subscriber", 

2496 "rpcName": "Pull", 

2497 "metadata": http_response["headers"], 

2498 "httpResponse": http_response, 

2499 }, 

2500 ) 

2501 return resp 

2502 

2503 class _Seek(_BaseSubscriberRestTransport._BaseSeek, SubscriberRestStub): 

2504 def __hash__(self): 

2505 return hash("SubscriberRestTransport.Seek") 

2506 

2507 @staticmethod 

2508 def _get_response( 

2509 host, 

2510 metadata, 

2511 query_params, 

2512 session, 

2513 timeout, 

2514 transcoded_request, 

2515 body=None, 

2516 ): 

2517 uri = transcoded_request["uri"] 

2518 method = transcoded_request["method"] 

2519 headers = dict(metadata) 

2520 headers["Content-Type"] = "application/json" 

2521 response = getattr(session, method)( 

2522 "{host}{uri}".format(host=host, uri=uri), 

2523 timeout=timeout, 

2524 headers=headers, 

2525 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2526 data=body, 

2527 ) 

2528 return response 

2529 

2530 def __call__( 

2531 self, 

2532 request: pubsub.SeekRequest, 

2533 *, 

2534 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2535 timeout: Optional[float] = None, 

2536 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2537 ) -> pubsub.SeekResponse: 

2538 r"""Call the seek method over HTTP. 

2539 

2540 Args: 

2541 request (~.pubsub.SeekRequest): 

2542 The request object. Request for the ``Seek`` method. 

2543 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2544 should be retried. 

2545 timeout (float): The timeout for this request. 

2546 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2547 sent along with the request as metadata. Normally, each value must be of type `str`, 

2548 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2549 be of type `bytes`. 

2550 

2551 Returns: 

2552 ~.pubsub.SeekResponse: 

2553 Response for the ``Seek`` method (this response is 

2554 empty). 

2555 

2556 """ 

2557 

2558 http_options = _BaseSubscriberRestTransport._BaseSeek._get_http_options() 

2559 

2560 request, metadata = self._interceptor.pre_seek(request, metadata) 

2561 transcoded_request = ( 

2562 _BaseSubscriberRestTransport._BaseSeek._get_transcoded_request( 

2563 http_options, request 

2564 ) 

2565 ) 

2566 

2567 body = _BaseSubscriberRestTransport._BaseSeek._get_request_body_json( 

2568 transcoded_request 

2569 ) 

2570 

2571 # Jsonify the query params 

2572 query_params = ( 

2573 _BaseSubscriberRestTransport._BaseSeek._get_query_params_json( 

2574 transcoded_request 

2575 ) 

2576 ) 

2577 

2578 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2579 logging.DEBUG 

2580 ): # pragma: NO COVER 

2581 request_url = "{host}{uri}".format( 

2582 host=self._host, uri=transcoded_request["uri"] 

2583 ) 

2584 method = transcoded_request["method"] 

2585 try: 

2586 request_payload = type(request).to_json(request) 

2587 except: 

2588 request_payload = None 

2589 http_request = { 

2590 "payload": request_payload, 

2591 "requestMethod": method, 

2592 "requestUrl": request_url, 

2593 "headers": dict(metadata), 

2594 } 

2595 _LOGGER.debug( 

2596 f"Sending request for google.pubsub_v1.SubscriberClient.Seek", 

2597 extra={ 

2598 "serviceName": "google.pubsub.v1.Subscriber", 

2599 "rpcName": "Seek", 

2600 "httpRequest": http_request, 

2601 "metadata": http_request["headers"], 

2602 }, 

2603 ) 

2604 

2605 # Send the request 

2606 response = SubscriberRestTransport._Seek._get_response( 

2607 self._host, 

2608 metadata, 

2609 query_params, 

2610 self._session, 

2611 timeout, 

2612 transcoded_request, 

2613 body, 

2614 ) 

2615 

2616 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2617 # subclass. 

2618 if response.status_code >= 400: 

2619 raise core_exceptions.from_http_response(response) 

2620 

2621 # Return the response 

2622 resp = pubsub.SeekResponse() 

2623 pb_resp = pubsub.SeekResponse.pb(resp) 

2624 

2625 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2626 

2627 resp = self._interceptor.post_seek(resp) 

2628 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2629 resp, _ = self._interceptor.post_seek_with_metadata(resp, response_metadata) 

2630 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2631 logging.DEBUG 

2632 ): # pragma: NO COVER 

2633 try: 

2634 response_payload = pubsub.SeekResponse.to_json(response) 

2635 except: 

2636 response_payload = None 

2637 http_response = { 

2638 "payload": response_payload, 

2639 "headers": dict(response.headers), 

2640 "status": response.status_code, 

2641 } 

2642 _LOGGER.debug( 

2643 "Received response for google.pubsub_v1.SubscriberClient.seek", 

2644 extra={ 

2645 "serviceName": "google.pubsub.v1.Subscriber", 

2646 "rpcName": "Seek", 

2647 "metadata": http_response["headers"], 

2648 "httpResponse": http_response, 

2649 }, 

2650 ) 

2651 return resp 

2652 

2653 class _StreamingPull( 

2654 _BaseSubscriberRestTransport._BaseStreamingPull, SubscriberRestStub 

2655 ): 

2656 def __hash__(self): 

2657 return hash("SubscriberRestTransport.StreamingPull") 

2658 

2659 def __call__( 

2660 self, 

2661 request: pubsub.StreamingPullRequest, 

2662 *, 

2663 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2664 timeout: Optional[float] = None, 

2665 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2666 ) -> rest_streaming.ResponseIterator: 

2667 raise NotImplementedError( 

2668 "Method StreamingPull is not available over REST transport" 

2669 ) 

2670 

2671 class _UpdateSnapshot( 

2672 _BaseSubscriberRestTransport._BaseUpdateSnapshot, SubscriberRestStub 

2673 ): 

2674 def __hash__(self): 

2675 return hash("SubscriberRestTransport.UpdateSnapshot") 

2676 

2677 @staticmethod 

2678 def _get_response( 

2679 host, 

2680 metadata, 

2681 query_params, 

2682 session, 

2683 timeout, 

2684 transcoded_request, 

2685 body=None, 

2686 ): 

2687 uri = transcoded_request["uri"] 

2688 method = transcoded_request["method"] 

2689 headers = dict(metadata) 

2690 headers["Content-Type"] = "application/json" 

2691 response = getattr(session, method)( 

2692 "{host}{uri}".format(host=host, uri=uri), 

2693 timeout=timeout, 

2694 headers=headers, 

2695 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2696 data=body, 

2697 ) 

2698 return response 

2699 

2700 def __call__( 

2701 self, 

2702 request: pubsub.UpdateSnapshotRequest, 

2703 *, 

2704 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2705 timeout: Optional[float] = None, 

2706 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2707 ) -> pubsub.Snapshot: 

2708 r"""Call the update snapshot method over HTTP. 

2709 

2710 Args: 

2711 request (~.pubsub.UpdateSnapshotRequest): 

2712 The request object. Request for the UpdateSnapshot 

2713 method. 

2714 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2715 should be retried. 

2716 timeout (float): The timeout for this request. 

2717 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2718 sent along with the request as metadata. Normally, each value must be of type `str`, 

2719 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2720 be of type `bytes`. 

2721 

2722 Returns: 

2723 ~.pubsub.Snapshot: 

2724 A snapshot resource. Snapshots are used in 

2725 `Seek <https://cloud.google.com/pubsub/docs/replay-overview>`__ 

2726 operations, which allow you to manage message 

2727 acknowledgments in bulk. That is, you can set the 

2728 acknowledgment state of messages in an existing 

2729 subscription to the state captured by a snapshot. 

2730 

2731 """ 

2732 

2733 http_options = ( 

2734 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_http_options() 

2735 ) 

2736 

2737 request, metadata = self._interceptor.pre_update_snapshot(request, metadata) 

2738 transcoded_request = _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_transcoded_request( 

2739 http_options, request 

2740 ) 

2741 

2742 body = ( 

2743 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_request_body_json( 

2744 transcoded_request 

2745 ) 

2746 ) 

2747 

2748 # Jsonify the query params 

2749 query_params = ( 

2750 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_query_params_json( 

2751 transcoded_request 

2752 ) 

2753 ) 

2754 

2755 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2756 logging.DEBUG 

2757 ): # pragma: NO COVER 

2758 request_url = "{host}{uri}".format( 

2759 host=self._host, uri=transcoded_request["uri"] 

2760 ) 

2761 method = transcoded_request["method"] 

2762 try: 

2763 request_payload = type(request).to_json(request) 

2764 except: 

2765 request_payload = None 

2766 http_request = { 

2767 "payload": request_payload, 

2768 "requestMethod": method, 

2769 "requestUrl": request_url, 

2770 "headers": dict(metadata), 

2771 } 

2772 _LOGGER.debug( 

2773 f"Sending request for google.pubsub_v1.SubscriberClient.UpdateSnapshot", 

2774 extra={ 

2775 "serviceName": "google.pubsub.v1.Subscriber", 

2776 "rpcName": "UpdateSnapshot", 

2777 "httpRequest": http_request, 

2778 "metadata": http_request["headers"], 

2779 }, 

2780 ) 

2781 

2782 # Send the request 

2783 response = SubscriberRestTransport._UpdateSnapshot._get_response( 

2784 self._host, 

2785 metadata, 

2786 query_params, 

2787 self._session, 

2788 timeout, 

2789 transcoded_request, 

2790 body, 

2791 ) 

2792 

2793 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2794 # subclass. 

2795 if response.status_code >= 400: 

2796 raise core_exceptions.from_http_response(response) 

2797 

2798 # Return the response 

2799 resp = pubsub.Snapshot() 

2800 pb_resp = pubsub.Snapshot.pb(resp) 

2801 

2802 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2803 

2804 resp = self._interceptor.post_update_snapshot(resp) 

2805 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2806 resp, _ = self._interceptor.post_update_snapshot_with_metadata( 

2807 resp, response_metadata 

2808 ) 

2809 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2810 logging.DEBUG 

2811 ): # pragma: NO COVER 

2812 try: 

2813 response_payload = pubsub.Snapshot.to_json(response) 

2814 except: 

2815 response_payload = None 

2816 http_response = { 

2817 "payload": response_payload, 

2818 "headers": dict(response.headers), 

2819 "status": response.status_code, 

2820 } 

2821 _LOGGER.debug( 

2822 "Received response for google.pubsub_v1.SubscriberClient.update_snapshot", 

2823 extra={ 

2824 "serviceName": "google.pubsub.v1.Subscriber", 

2825 "rpcName": "UpdateSnapshot", 

2826 "metadata": http_response["headers"], 

2827 "httpResponse": http_response, 

2828 }, 

2829 ) 

2830 return resp 

2831 

2832 class _UpdateSubscription( 

2833 _BaseSubscriberRestTransport._BaseUpdateSubscription, SubscriberRestStub 

2834 ): 

2835 def __hash__(self): 

2836 return hash("SubscriberRestTransport.UpdateSubscription") 

2837 

2838 @staticmethod 

2839 def _get_response( 

2840 host, 

2841 metadata, 

2842 query_params, 

2843 session, 

2844 timeout, 

2845 transcoded_request, 

2846 body=None, 

2847 ): 

2848 uri = transcoded_request["uri"] 

2849 method = transcoded_request["method"] 

2850 headers = dict(metadata) 

2851 headers["Content-Type"] = "application/json" 

2852 response = getattr(session, method)( 

2853 "{host}{uri}".format(host=host, uri=uri), 

2854 timeout=timeout, 

2855 headers=headers, 

2856 params=rest_helpers.flatten_query_params(query_params, strict=True), 

2857 data=body, 

2858 ) 

2859 return response 

2860 

2861 def __call__( 

2862 self, 

2863 request: pubsub.UpdateSubscriptionRequest, 

2864 *, 

2865 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2866 timeout: Optional[float] = None, 

2867 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2868 ) -> pubsub.Subscription: 

2869 r"""Call the update subscription method over HTTP. 

2870 

2871 Args: 

2872 request (~.pubsub.UpdateSubscriptionRequest): 

2873 The request object. Request for the UpdateSubscription 

2874 method. 

2875 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

2876 should be retried. 

2877 timeout (float): The timeout for this request. 

2878 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2879 sent along with the request as metadata. Normally, each value must be of type `str`, 

2880 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2881 be of type `bytes`. 

2882 

2883 Returns: 

2884 ~.pubsub.Subscription: 

2885 A subscription resource. If none of ``push_config``, 

2886 ``bigquery_config``, or ``cloud_storage_config`` is set, 

2887 then the subscriber will pull and ack messages using API 

2888 methods. At most one of these fields may be set. 

2889 

2890 """ 

2891 

2892 http_options = ( 

2893 _BaseSubscriberRestTransport._BaseUpdateSubscription._get_http_options() 

2894 ) 

2895 

2896 request, metadata = self._interceptor.pre_update_subscription( 

2897 request, metadata 

2898 ) 

2899 transcoded_request = _BaseSubscriberRestTransport._BaseUpdateSubscription._get_transcoded_request( 

2900 http_options, request 

2901 ) 

2902 

2903 body = _BaseSubscriberRestTransport._BaseUpdateSubscription._get_request_body_json( 

2904 transcoded_request 

2905 ) 

2906 

2907 # Jsonify the query params 

2908 query_params = _BaseSubscriberRestTransport._BaseUpdateSubscription._get_query_params_json( 

2909 transcoded_request 

2910 ) 

2911 

2912 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2913 logging.DEBUG 

2914 ): # pragma: NO COVER 

2915 request_url = "{host}{uri}".format( 

2916 host=self._host, uri=transcoded_request["uri"] 

2917 ) 

2918 method = transcoded_request["method"] 

2919 try: 

2920 request_payload = type(request).to_json(request) 

2921 except: 

2922 request_payload = None 

2923 http_request = { 

2924 "payload": request_payload, 

2925 "requestMethod": method, 

2926 "requestUrl": request_url, 

2927 "headers": dict(metadata), 

2928 } 

2929 _LOGGER.debug( 

2930 f"Sending request for google.pubsub_v1.SubscriberClient.UpdateSubscription", 

2931 extra={ 

2932 "serviceName": "google.pubsub.v1.Subscriber", 

2933 "rpcName": "UpdateSubscription", 

2934 "httpRequest": http_request, 

2935 "metadata": http_request["headers"], 

2936 }, 

2937 ) 

2938 

2939 # Send the request 

2940 response = SubscriberRestTransport._UpdateSubscription._get_response( 

2941 self._host, 

2942 metadata, 

2943 query_params, 

2944 self._session, 

2945 timeout, 

2946 transcoded_request, 

2947 body, 

2948 ) 

2949 

2950 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

2951 # subclass. 

2952 if response.status_code >= 400: 

2953 raise core_exceptions.from_http_response(response) 

2954 

2955 # Return the response 

2956 resp = pubsub.Subscription() 

2957 pb_resp = pubsub.Subscription.pb(resp) 

2958 

2959 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) 

2960 

2961 resp = self._interceptor.post_update_subscription(resp) 

2962 response_metadata = [(k, str(v)) for k, v in response.headers.items()] 

2963 resp, _ = self._interceptor.post_update_subscription_with_metadata( 

2964 resp, response_metadata 

2965 ) 

2966 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2967 logging.DEBUG 

2968 ): # pragma: NO COVER 

2969 try: 

2970 response_payload = pubsub.Subscription.to_json(response) 

2971 except: 

2972 response_payload = None 

2973 http_response = { 

2974 "payload": response_payload, 

2975 "headers": dict(response.headers), 

2976 "status": response.status_code, 

2977 } 

2978 _LOGGER.debug( 

2979 "Received response for google.pubsub_v1.SubscriberClient.update_subscription", 

2980 extra={ 

2981 "serviceName": "google.pubsub.v1.Subscriber", 

2982 "rpcName": "UpdateSubscription", 

2983 "metadata": http_response["headers"], 

2984 "httpResponse": http_response, 

2985 }, 

2986 ) 

2987 return resp 

2988 

2989 @property 

2990 def acknowledge(self) -> Callable[[pubsub.AcknowledgeRequest], empty_pb2.Empty]: 

2991 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

2992 # In C++ this would require a dynamic_cast 

2993 return self._Acknowledge(self._session, self._host, self._interceptor) # type: ignore 

2994 

2995 @property 

2996 def create_snapshot( 

2997 self, 

2998 ) -> Callable[[pubsub.CreateSnapshotRequest], pubsub.Snapshot]: 

2999 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3000 # In C++ this would require a dynamic_cast 

3001 return self._CreateSnapshot(self._session, self._host, self._interceptor) # type: ignore 

3002 

3003 @property 

3004 def create_subscription( 

3005 self, 

3006 ) -> Callable[[pubsub.Subscription], pubsub.Subscription]: 

3007 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3008 # In C++ this would require a dynamic_cast 

3009 return self._CreateSubscription(self._session, self._host, self._interceptor) # type: ignore 

3010 

3011 @property 

3012 def delete_snapshot( 

3013 self, 

3014 ) -> Callable[[pubsub.DeleteSnapshotRequest], empty_pb2.Empty]: 

3015 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3016 # In C++ this would require a dynamic_cast 

3017 return self._DeleteSnapshot(self._session, self._host, self._interceptor) # type: ignore 

3018 

3019 @property 

3020 def delete_subscription( 

3021 self, 

3022 ) -> Callable[[pubsub.DeleteSubscriptionRequest], empty_pb2.Empty]: 

3023 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3024 # In C++ this would require a dynamic_cast 

3025 return self._DeleteSubscription(self._session, self._host, self._interceptor) # type: ignore 

3026 

3027 @property 

3028 def get_snapshot(self) -> Callable[[pubsub.GetSnapshotRequest], pubsub.Snapshot]: 

3029 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3030 # In C++ this would require a dynamic_cast 

3031 return self._GetSnapshot(self._session, self._host, self._interceptor) # type: ignore 

3032 

3033 @property 

3034 def get_subscription( 

3035 self, 

3036 ) -> Callable[[pubsub.GetSubscriptionRequest], pubsub.Subscription]: 

3037 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3038 # In C++ this would require a dynamic_cast 

3039 return self._GetSubscription(self._session, self._host, self._interceptor) # type: ignore 

3040 

3041 @property 

3042 def list_snapshots( 

3043 self, 

3044 ) -> Callable[[pubsub.ListSnapshotsRequest], pubsub.ListSnapshotsResponse]: 

3045 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3046 # In C++ this would require a dynamic_cast 

3047 return self._ListSnapshots(self._session, self._host, self._interceptor) # type: ignore 

3048 

3049 @property 

3050 def list_subscriptions( 

3051 self, 

3052 ) -> Callable[[pubsub.ListSubscriptionsRequest], pubsub.ListSubscriptionsResponse]: 

3053 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3054 # In C++ this would require a dynamic_cast 

3055 return self._ListSubscriptions(self._session, self._host, self._interceptor) # type: ignore 

3056 

3057 @property 

3058 def modify_ack_deadline( 

3059 self, 

3060 ) -> Callable[[pubsub.ModifyAckDeadlineRequest], empty_pb2.Empty]: 

3061 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3062 # In C++ this would require a dynamic_cast 

3063 return self._ModifyAckDeadline(self._session, self._host, self._interceptor) # type: ignore 

3064 

3065 @property 

3066 def modify_push_config( 

3067 self, 

3068 ) -> Callable[[pubsub.ModifyPushConfigRequest], empty_pb2.Empty]: 

3069 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3070 # In C++ this would require a dynamic_cast 

3071 return self._ModifyPushConfig(self._session, self._host, self._interceptor) # type: ignore 

3072 

3073 @property 

3074 def pull(self) -> Callable[[pubsub.PullRequest], pubsub.PullResponse]: 

3075 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3076 # In C++ this would require a dynamic_cast 

3077 return self._Pull(self._session, self._host, self._interceptor) # type: ignore 

3078 

3079 @property 

3080 def seek(self) -> Callable[[pubsub.SeekRequest], pubsub.SeekResponse]: 

3081 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3082 # In C++ this would require a dynamic_cast 

3083 return self._Seek(self._session, self._host, self._interceptor) # type: ignore 

3084 

3085 @property 

3086 def streaming_pull( 

3087 self, 

3088 ) -> Callable[[pubsub.StreamingPullRequest], pubsub.StreamingPullResponse]: 

3089 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3090 # In C++ this would require a dynamic_cast 

3091 return self._StreamingPull(self._session, self._host, self._interceptor) # type: ignore 

3092 

3093 @property 

3094 def update_snapshot( 

3095 self, 

3096 ) -> Callable[[pubsub.UpdateSnapshotRequest], pubsub.Snapshot]: 

3097 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3098 # In C++ this would require a dynamic_cast 

3099 return self._UpdateSnapshot(self._session, self._host, self._interceptor) # type: ignore 

3100 

3101 @property 

3102 def update_subscription( 

3103 self, 

3104 ) -> Callable[[pubsub.UpdateSubscriptionRequest], pubsub.Subscription]: 

3105 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. 

3106 # In C++ this would require a dynamic_cast 

3107 return self._UpdateSubscription(self._session, self._host, self._interceptor) # type: ignore 

3108 

3109 @property 

3110 def get_iam_policy(self): 

3111 return self._GetIamPolicy(self._session, self._host, self._interceptor) # type: ignore 

3112 

3113 class _GetIamPolicy( 

3114 _BaseSubscriberRestTransport._BaseGetIamPolicy, SubscriberRestStub 

3115 ): 

3116 def __hash__(self): 

3117 return hash("SubscriberRestTransport.GetIamPolicy") 

3118 

3119 @staticmethod 

3120 def _get_response( 

3121 host, 

3122 metadata, 

3123 query_params, 

3124 session, 

3125 timeout, 

3126 transcoded_request, 

3127 body=None, 

3128 ): 

3129 uri = transcoded_request["uri"] 

3130 method = transcoded_request["method"] 

3131 headers = dict(metadata) 

3132 headers["Content-Type"] = "application/json" 

3133 response = getattr(session, method)( 

3134 "{host}{uri}".format(host=host, uri=uri), 

3135 timeout=timeout, 

3136 headers=headers, 

3137 params=rest_helpers.flatten_query_params(query_params, strict=True), 

3138 ) 

3139 return response 

3140 

3141 def __call__( 

3142 self, 

3143 request: iam_policy_pb2.GetIamPolicyRequest, 

3144 *, 

3145 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3146 timeout: Optional[float] = None, 

3147 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

3148 ) -> policy_pb2.Policy: 

3149 r"""Call the get iam policy method over HTTP. 

3150 

3151 Args: 

3152 request (iam_policy_pb2.GetIamPolicyRequest): 

3153 The request object for GetIamPolicy method. 

3154 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

3155 should be retried. 

3156 timeout (float): The timeout for this request. 

3157 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

3158 sent along with the request as metadata. Normally, each value must be of type `str`, 

3159 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

3160 be of type `bytes`. 

3161 

3162 Returns: 

3163 policy_pb2.Policy: Response from GetIamPolicy method. 

3164 """ 

3165 

3166 http_options = ( 

3167 _BaseSubscriberRestTransport._BaseGetIamPolicy._get_http_options() 

3168 ) 

3169 

3170 request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) 

3171 transcoded_request = ( 

3172 _BaseSubscriberRestTransport._BaseGetIamPolicy._get_transcoded_request( 

3173 http_options, request 

3174 ) 

3175 ) 

3176 

3177 # Jsonify the query params 

3178 query_params = ( 

3179 _BaseSubscriberRestTransport._BaseGetIamPolicy._get_query_params_json( 

3180 transcoded_request 

3181 ) 

3182 ) 

3183 

3184 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3185 logging.DEBUG 

3186 ): # pragma: NO COVER 

3187 request_url = "{host}{uri}".format( 

3188 host=self._host, uri=transcoded_request["uri"] 

3189 ) 

3190 method = transcoded_request["method"] 

3191 try: 

3192 request_payload = json_format.MessageToJson(request) 

3193 except: 

3194 request_payload = None 

3195 http_request = { 

3196 "payload": request_payload, 

3197 "requestMethod": method, 

3198 "requestUrl": request_url, 

3199 "headers": dict(metadata), 

3200 } 

3201 _LOGGER.debug( 

3202 f"Sending request for google.pubsub_v1.SubscriberClient.GetIamPolicy", 

3203 extra={ 

3204 "serviceName": "google.pubsub.v1.Subscriber", 

3205 "rpcName": "GetIamPolicy", 

3206 "httpRequest": http_request, 

3207 "metadata": http_request["headers"], 

3208 }, 

3209 ) 

3210 

3211 # Send the request 

3212 response = SubscriberRestTransport._GetIamPolicy._get_response( 

3213 self._host, 

3214 metadata, 

3215 query_params, 

3216 self._session, 

3217 timeout, 

3218 transcoded_request, 

3219 ) 

3220 

3221 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

3222 # subclass. 

3223 if response.status_code >= 400: 

3224 raise core_exceptions.from_http_response(response) 

3225 

3226 content = response.content.decode("utf-8") 

3227 resp = policy_pb2.Policy() 

3228 resp = json_format.Parse(content, resp) 

3229 resp = self._interceptor.post_get_iam_policy(resp) 

3230 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3231 logging.DEBUG 

3232 ): # pragma: NO COVER 

3233 try: 

3234 response_payload = json_format.MessageToJson(resp) 

3235 except: 

3236 response_payload = None 

3237 http_response = { 

3238 "payload": response_payload, 

3239 "headers": dict(response.headers), 

3240 "status": response.status_code, 

3241 } 

3242 _LOGGER.debug( 

3243 "Received response for google.pubsub_v1.SubscriberAsyncClient.GetIamPolicy", 

3244 extra={ 

3245 "serviceName": "google.pubsub.v1.Subscriber", 

3246 "rpcName": "GetIamPolicy", 

3247 "httpResponse": http_response, 

3248 "metadata": http_response["headers"], 

3249 }, 

3250 ) 

3251 return resp 

3252 

3253 @property 

3254 def set_iam_policy(self): 

3255 return self._SetIamPolicy(self._session, self._host, self._interceptor) # type: ignore 

3256 

3257 class _SetIamPolicy( 

3258 _BaseSubscriberRestTransport._BaseSetIamPolicy, SubscriberRestStub 

3259 ): 

3260 def __hash__(self): 

3261 return hash("SubscriberRestTransport.SetIamPolicy") 

3262 

3263 @staticmethod 

3264 def _get_response( 

3265 host, 

3266 metadata, 

3267 query_params, 

3268 session, 

3269 timeout, 

3270 transcoded_request, 

3271 body=None, 

3272 ): 

3273 uri = transcoded_request["uri"] 

3274 method = transcoded_request["method"] 

3275 headers = dict(metadata) 

3276 headers["Content-Type"] = "application/json" 

3277 response = getattr(session, method)( 

3278 "{host}{uri}".format(host=host, uri=uri), 

3279 timeout=timeout, 

3280 headers=headers, 

3281 params=rest_helpers.flatten_query_params(query_params, strict=True), 

3282 data=body, 

3283 ) 

3284 return response 

3285 

3286 def __call__( 

3287 self, 

3288 request: iam_policy_pb2.SetIamPolicyRequest, 

3289 *, 

3290 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3291 timeout: Optional[float] = None, 

3292 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

3293 ) -> policy_pb2.Policy: 

3294 r"""Call the set iam policy method over HTTP. 

3295 

3296 Args: 

3297 request (iam_policy_pb2.SetIamPolicyRequest): 

3298 The request object for SetIamPolicy method. 

3299 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

3300 should be retried. 

3301 timeout (float): The timeout for this request. 

3302 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

3303 sent along with the request as metadata. Normally, each value must be of type `str`, 

3304 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

3305 be of type `bytes`. 

3306 

3307 Returns: 

3308 policy_pb2.Policy: Response from SetIamPolicy method. 

3309 """ 

3310 

3311 http_options = ( 

3312 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_http_options() 

3313 ) 

3314 

3315 request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) 

3316 transcoded_request = ( 

3317 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_transcoded_request( 

3318 http_options, request 

3319 ) 

3320 ) 

3321 

3322 body = ( 

3323 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_request_body_json( 

3324 transcoded_request 

3325 ) 

3326 ) 

3327 

3328 # Jsonify the query params 

3329 query_params = ( 

3330 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_query_params_json( 

3331 transcoded_request 

3332 ) 

3333 ) 

3334 

3335 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3336 logging.DEBUG 

3337 ): # pragma: NO COVER 

3338 request_url = "{host}{uri}".format( 

3339 host=self._host, uri=transcoded_request["uri"] 

3340 ) 

3341 method = transcoded_request["method"] 

3342 try: 

3343 request_payload = json_format.MessageToJson(request) 

3344 except: 

3345 request_payload = None 

3346 http_request = { 

3347 "payload": request_payload, 

3348 "requestMethod": method, 

3349 "requestUrl": request_url, 

3350 "headers": dict(metadata), 

3351 } 

3352 _LOGGER.debug( 

3353 f"Sending request for google.pubsub_v1.SubscriberClient.SetIamPolicy", 

3354 extra={ 

3355 "serviceName": "google.pubsub.v1.Subscriber", 

3356 "rpcName": "SetIamPolicy", 

3357 "httpRequest": http_request, 

3358 "metadata": http_request["headers"], 

3359 }, 

3360 ) 

3361 

3362 # Send the request 

3363 response = SubscriberRestTransport._SetIamPolicy._get_response( 

3364 self._host, 

3365 metadata, 

3366 query_params, 

3367 self._session, 

3368 timeout, 

3369 transcoded_request, 

3370 body, 

3371 ) 

3372 

3373 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

3374 # subclass. 

3375 if response.status_code >= 400: 

3376 raise core_exceptions.from_http_response(response) 

3377 

3378 content = response.content.decode("utf-8") 

3379 resp = policy_pb2.Policy() 

3380 resp = json_format.Parse(content, resp) 

3381 resp = self._interceptor.post_set_iam_policy(resp) 

3382 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3383 logging.DEBUG 

3384 ): # pragma: NO COVER 

3385 try: 

3386 response_payload = json_format.MessageToJson(resp) 

3387 except: 

3388 response_payload = None 

3389 http_response = { 

3390 "payload": response_payload, 

3391 "headers": dict(response.headers), 

3392 "status": response.status_code, 

3393 } 

3394 _LOGGER.debug( 

3395 "Received response for google.pubsub_v1.SubscriberAsyncClient.SetIamPolicy", 

3396 extra={ 

3397 "serviceName": "google.pubsub.v1.Subscriber", 

3398 "rpcName": "SetIamPolicy", 

3399 "httpResponse": http_response, 

3400 "metadata": http_response["headers"], 

3401 }, 

3402 ) 

3403 return resp 

3404 

3405 @property 

3406 def test_iam_permissions(self): 

3407 return self._TestIamPermissions(self._session, self._host, self._interceptor) # type: ignore 

3408 

3409 class _TestIamPermissions( 

3410 _BaseSubscriberRestTransport._BaseTestIamPermissions, SubscriberRestStub 

3411 ): 

3412 def __hash__(self): 

3413 return hash("SubscriberRestTransport.TestIamPermissions") 

3414 

3415 @staticmethod 

3416 def _get_response( 

3417 host, 

3418 metadata, 

3419 query_params, 

3420 session, 

3421 timeout, 

3422 transcoded_request, 

3423 body=None, 

3424 ): 

3425 uri = transcoded_request["uri"] 

3426 method = transcoded_request["method"] 

3427 headers = dict(metadata) 

3428 headers["Content-Type"] = "application/json" 

3429 response = getattr(session, method)( 

3430 "{host}{uri}".format(host=host, uri=uri), 

3431 timeout=timeout, 

3432 headers=headers, 

3433 params=rest_helpers.flatten_query_params(query_params, strict=True), 

3434 data=body, 

3435 ) 

3436 return response 

3437 

3438 def __call__( 

3439 self, 

3440 request: iam_policy_pb2.TestIamPermissionsRequest, 

3441 *, 

3442 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3443 timeout: Optional[float] = None, 

3444 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

3445 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

3446 r"""Call the test iam permissions method over HTTP. 

3447 

3448 Args: 

3449 request (iam_policy_pb2.TestIamPermissionsRequest): 

3450 The request object for TestIamPermissions method. 

3451 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

3452 should be retried. 

3453 timeout (float): The timeout for this request. 

3454 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

3455 sent along with the request as metadata. Normally, each value must be of type `str`, 

3456 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

3457 be of type `bytes`. 

3458 

3459 Returns: 

3460 iam_policy_pb2.TestIamPermissionsResponse: Response from TestIamPermissions method. 

3461 """ 

3462 

3463 http_options = ( 

3464 _BaseSubscriberRestTransport._BaseTestIamPermissions._get_http_options() 

3465 ) 

3466 

3467 request, metadata = self._interceptor.pre_test_iam_permissions( 

3468 request, metadata 

3469 ) 

3470 transcoded_request = _BaseSubscriberRestTransport._BaseTestIamPermissions._get_transcoded_request( 

3471 http_options, request 

3472 ) 

3473 

3474 body = _BaseSubscriberRestTransport._BaseTestIamPermissions._get_request_body_json( 

3475 transcoded_request 

3476 ) 

3477 

3478 # Jsonify the query params 

3479 query_params = _BaseSubscriberRestTransport._BaseTestIamPermissions._get_query_params_json( 

3480 transcoded_request 

3481 ) 

3482 

3483 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3484 logging.DEBUG 

3485 ): # pragma: NO COVER 

3486 request_url = "{host}{uri}".format( 

3487 host=self._host, uri=transcoded_request["uri"] 

3488 ) 

3489 method = transcoded_request["method"] 

3490 try: 

3491 request_payload = json_format.MessageToJson(request) 

3492 except: 

3493 request_payload = None 

3494 http_request = { 

3495 "payload": request_payload, 

3496 "requestMethod": method, 

3497 "requestUrl": request_url, 

3498 "headers": dict(metadata), 

3499 } 

3500 _LOGGER.debug( 

3501 f"Sending request for google.pubsub_v1.SubscriberClient.TestIamPermissions", 

3502 extra={ 

3503 "serviceName": "google.pubsub.v1.Subscriber", 

3504 "rpcName": "TestIamPermissions", 

3505 "httpRequest": http_request, 

3506 "metadata": http_request["headers"], 

3507 }, 

3508 ) 

3509 

3510 # Send the request 

3511 response = SubscriberRestTransport._TestIamPermissions._get_response( 

3512 self._host, 

3513 metadata, 

3514 query_params, 

3515 self._session, 

3516 timeout, 

3517 transcoded_request, 

3518 body, 

3519 ) 

3520 

3521 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception 

3522 # subclass. 

3523 if response.status_code >= 400: 

3524 raise core_exceptions.from_http_response(response) 

3525 

3526 content = response.content.decode("utf-8") 

3527 resp = iam_policy_pb2.TestIamPermissionsResponse() 

3528 resp = json_format.Parse(content, resp) 

3529 resp = self._interceptor.post_test_iam_permissions(resp) 

3530 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3531 logging.DEBUG 

3532 ): # pragma: NO COVER 

3533 try: 

3534 response_payload = json_format.MessageToJson(resp) 

3535 except: 

3536 response_payload = None 

3537 http_response = { 

3538 "payload": response_payload, 

3539 "headers": dict(response.headers), 

3540 "status": response.status_code, 

3541 } 

3542 _LOGGER.debug( 

3543 "Received response for google.pubsub_v1.SubscriberAsyncClient.TestIamPermissions", 

3544 extra={ 

3545 "serviceName": "google.pubsub.v1.Subscriber", 

3546 "rpcName": "TestIamPermissions", 

3547 "httpResponse": http_response, 

3548 "metadata": http_response["headers"], 

3549 }, 

3550 ) 

3551 return resp 

3552 

3553 @property 

3554 def kind(self) -> str: 

3555 return "rest" 

3556 

3557 def close(self): 

3558 self._session.close() 

3559 

3560 

3561__all__ = ("SubscriberRestTransport",)