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]): Deprecated. 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. This argument will be 

834 removed in the next major version of this library. 

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

836 ignored if ``channel`` is provided. 

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

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

839 if ``channel`` is provided. 

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

841 and quota. 

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

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

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

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

846 your own client library. 

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

848 be used for service account credentials. 

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

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

851 "http" can be specified. 

852 """ 

853 # Run the base constructor 

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

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

856 # credentials object 

857 super().__init__( 

858 host=host, 

859 credentials=credentials, 

860 client_info=client_info, 

861 always_use_jwt_access=always_use_jwt_access, 

862 url_scheme=url_scheme, 

863 api_audience=api_audience, 

864 ) 

865 self._session = AuthorizedSession( 

866 self._credentials, default_host=self.DEFAULT_HOST 

867 ) 

868 if client_cert_source_for_mtls: 

869 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

870 self._interceptor = interceptor or SubscriberRestInterceptor() 

871 self._prep_wrapped_messages(client_info) 

872 

873 class _Acknowledge( 

874 _BaseSubscriberRestTransport._BaseAcknowledge, SubscriberRestStub 

875 ): 

876 def __hash__(self): 

877 return hash("SubscriberRestTransport.Acknowledge") 

878 

879 @staticmethod 

880 def _get_response( 

881 host, 

882 metadata, 

883 query_params, 

884 session, 

885 timeout, 

886 transcoded_request, 

887 body=None, 

888 ): 

889 uri = transcoded_request["uri"] 

890 method = transcoded_request["method"] 

891 headers = dict(metadata) 

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

893 response = getattr(session, method)( 

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

895 timeout=timeout, 

896 headers=headers, 

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

898 data=body, 

899 ) 

900 return response 

901 

902 def __call__( 

903 self, 

904 request: pubsub.AcknowledgeRequest, 

905 *, 

906 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

907 timeout: Optional[float] = None, 

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

909 ): 

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

911 

912 Args: 

913 request (~.pubsub.AcknowledgeRequest): 

914 The request object. Request for the Acknowledge method. 

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

916 should be retried. 

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

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

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

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

921 be of type `bytes`. 

922 """ 

923 

924 http_options = ( 

925 _BaseSubscriberRestTransport._BaseAcknowledge._get_http_options() 

926 ) 

927 

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

929 transcoded_request = ( 

930 _BaseSubscriberRestTransport._BaseAcknowledge._get_transcoded_request( 

931 http_options, request 

932 ) 

933 ) 

934 

935 body = _BaseSubscriberRestTransport._BaseAcknowledge._get_request_body_json( 

936 transcoded_request 

937 ) 

938 

939 # Jsonify the query params 

940 query_params = ( 

941 _BaseSubscriberRestTransport._BaseAcknowledge._get_query_params_json( 

942 transcoded_request 

943 ) 

944 ) 

945 

946 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

947 logging.DEBUG 

948 ): # pragma: NO COVER 

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

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

951 ) 

952 method = transcoded_request["method"] 

953 try: 

954 request_payload = json_format.MessageToJson(request) 

955 except: 

956 request_payload = None 

957 http_request = { 

958 "payload": request_payload, 

959 "requestMethod": method, 

960 "requestUrl": request_url, 

961 "headers": dict(metadata), 

962 } 

963 _LOGGER.debug( 

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

965 extra={ 

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

967 "rpcName": "Acknowledge", 

968 "httpRequest": http_request, 

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

970 }, 

971 ) 

972 

973 # Send the request 

974 response = SubscriberRestTransport._Acknowledge._get_response( 

975 self._host, 

976 metadata, 

977 query_params, 

978 self._session, 

979 timeout, 

980 transcoded_request, 

981 body, 

982 ) 

983 

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

985 # subclass. 

986 if response.status_code >= 400: 

987 raise core_exceptions.from_http_response(response) 

988 

989 class _CreateSnapshot( 

990 _BaseSubscriberRestTransport._BaseCreateSnapshot, SubscriberRestStub 

991 ): 

992 def __hash__(self): 

993 return hash("SubscriberRestTransport.CreateSnapshot") 

994 

995 @staticmethod 

996 def _get_response( 

997 host, 

998 metadata, 

999 query_params, 

1000 session, 

1001 timeout, 

1002 transcoded_request, 

1003 body=None, 

1004 ): 

1005 uri = transcoded_request["uri"] 

1006 method = transcoded_request["method"] 

1007 headers = dict(metadata) 

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

1009 response = getattr(session, method)( 

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

1011 timeout=timeout, 

1012 headers=headers, 

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

1014 data=body, 

1015 ) 

1016 return response 

1017 

1018 def __call__( 

1019 self, 

1020 request: pubsub.CreateSnapshotRequest, 

1021 *, 

1022 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1023 timeout: Optional[float] = None, 

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

1025 ) -> pubsub.Snapshot: 

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

1027 

1028 Args: 

1029 request (~.pubsub.CreateSnapshotRequest): 

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

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

1032 should be retried. 

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

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

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

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

1037 be of type `bytes`. 

1038 

1039 Returns: 

1040 ~.pubsub.Snapshot: 

1041 A snapshot resource. Snapshots are used in 

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

1043 operations, which allow you to manage message 

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

1045 acknowledgment state of messages in an existing 

1046 subscription to the state captured by a snapshot. 

1047 

1048 """ 

1049 

1050 http_options = ( 

1051 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_http_options() 

1052 ) 

1053 

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

1055 transcoded_request = _BaseSubscriberRestTransport._BaseCreateSnapshot._get_transcoded_request( 

1056 http_options, request 

1057 ) 

1058 

1059 body = ( 

1060 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_request_body_json( 

1061 transcoded_request 

1062 ) 

1063 ) 

1064 

1065 # Jsonify the query params 

1066 query_params = ( 

1067 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_query_params_json( 

1068 transcoded_request 

1069 ) 

1070 ) 

1071 

1072 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1073 logging.DEBUG 

1074 ): # pragma: NO COVER 

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

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

1077 ) 

1078 method = transcoded_request["method"] 

1079 try: 

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

1081 except: 

1082 request_payload = None 

1083 http_request = { 

1084 "payload": request_payload, 

1085 "requestMethod": method, 

1086 "requestUrl": request_url, 

1087 "headers": dict(metadata), 

1088 } 

1089 _LOGGER.debug( 

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

1091 extra={ 

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

1093 "rpcName": "CreateSnapshot", 

1094 "httpRequest": http_request, 

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

1096 }, 

1097 ) 

1098 

1099 # Send the request 

1100 response = SubscriberRestTransport._CreateSnapshot._get_response( 

1101 self._host, 

1102 metadata, 

1103 query_params, 

1104 self._session, 

1105 timeout, 

1106 transcoded_request, 

1107 body, 

1108 ) 

1109 

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

1111 # subclass. 

1112 if response.status_code >= 400: 

1113 raise core_exceptions.from_http_response(response) 

1114 

1115 # Return the response 

1116 resp = pubsub.Snapshot() 

1117 pb_resp = pubsub.Snapshot.pb(resp) 

1118 

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

1120 

1121 resp = self._interceptor.post_create_snapshot(resp) 

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

1123 resp, _ = self._interceptor.post_create_snapshot_with_metadata( 

1124 resp, response_metadata 

1125 ) 

1126 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1127 logging.DEBUG 

1128 ): # pragma: NO COVER 

1129 try: 

1130 response_payload = pubsub.Snapshot.to_json(response) 

1131 except: 

1132 response_payload = None 

1133 http_response = { 

1134 "payload": response_payload, 

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

1136 "status": response.status_code, 

1137 } 

1138 _LOGGER.debug( 

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

1140 extra={ 

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

1142 "rpcName": "CreateSnapshot", 

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

1144 "httpResponse": http_response, 

1145 }, 

1146 ) 

1147 return resp 

1148 

1149 class _CreateSubscription( 

1150 _BaseSubscriberRestTransport._BaseCreateSubscription, SubscriberRestStub 

1151 ): 

1152 def __hash__(self): 

1153 return hash("SubscriberRestTransport.CreateSubscription") 

1154 

1155 @staticmethod 

1156 def _get_response( 

1157 host, 

1158 metadata, 

1159 query_params, 

1160 session, 

1161 timeout, 

1162 transcoded_request, 

1163 body=None, 

1164 ): 

1165 uri = transcoded_request["uri"] 

1166 method = transcoded_request["method"] 

1167 headers = dict(metadata) 

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

1169 response = getattr(session, method)( 

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

1171 timeout=timeout, 

1172 headers=headers, 

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

1174 data=body, 

1175 ) 

1176 return response 

1177 

1178 def __call__( 

1179 self, 

1180 request: pubsub.Subscription, 

1181 *, 

1182 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1183 timeout: Optional[float] = None, 

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

1185 ) -> pubsub.Subscription: 

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

1187 

1188 Args: 

1189 request (~.pubsub.Subscription): 

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

1191 ``bigquery_config``, or ``cloud_storage_config`` is set, 

1192 then the subscriber will pull and ack messages using API 

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

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

1195 should be retried. 

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

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

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

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

1200 be of type `bytes`. 

1201 

1202 Returns: 

1203 ~.pubsub.Subscription: 

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

1205 ``bigquery_config``, or ``cloud_storage_config`` is set, 

1206 then the subscriber will pull and ack messages using API 

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

1208 

1209 """ 

1210 

1211 http_options = ( 

1212 _BaseSubscriberRestTransport._BaseCreateSubscription._get_http_options() 

1213 ) 

1214 

1215 request, metadata = self._interceptor.pre_create_subscription( 

1216 request, metadata 

1217 ) 

1218 transcoded_request = _BaseSubscriberRestTransport._BaseCreateSubscription._get_transcoded_request( 

1219 http_options, request 

1220 ) 

1221 

1222 body = _BaseSubscriberRestTransport._BaseCreateSubscription._get_request_body_json( 

1223 transcoded_request 

1224 ) 

1225 

1226 # Jsonify the query params 

1227 query_params = _BaseSubscriberRestTransport._BaseCreateSubscription._get_query_params_json( 

1228 transcoded_request 

1229 ) 

1230 

1231 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1232 logging.DEBUG 

1233 ): # pragma: NO COVER 

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

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

1236 ) 

1237 method = transcoded_request["method"] 

1238 try: 

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

1240 except: 

1241 request_payload = None 

1242 http_request = { 

1243 "payload": request_payload, 

1244 "requestMethod": method, 

1245 "requestUrl": request_url, 

1246 "headers": dict(metadata), 

1247 } 

1248 _LOGGER.debug( 

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

1250 extra={ 

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

1252 "rpcName": "CreateSubscription", 

1253 "httpRequest": http_request, 

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

1255 }, 

1256 ) 

1257 

1258 # Send the request 

1259 response = SubscriberRestTransport._CreateSubscription._get_response( 

1260 self._host, 

1261 metadata, 

1262 query_params, 

1263 self._session, 

1264 timeout, 

1265 transcoded_request, 

1266 body, 

1267 ) 

1268 

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

1270 # subclass. 

1271 if response.status_code >= 400: 

1272 raise core_exceptions.from_http_response(response) 

1273 

1274 # Return the response 

1275 resp = pubsub.Subscription() 

1276 pb_resp = pubsub.Subscription.pb(resp) 

1277 

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

1279 

1280 resp = self._interceptor.post_create_subscription(resp) 

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

1282 resp, _ = self._interceptor.post_create_subscription_with_metadata( 

1283 resp, response_metadata 

1284 ) 

1285 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1286 logging.DEBUG 

1287 ): # pragma: NO COVER 

1288 try: 

1289 response_payload = pubsub.Subscription.to_json(response) 

1290 except: 

1291 response_payload = None 

1292 http_response = { 

1293 "payload": response_payload, 

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

1295 "status": response.status_code, 

1296 } 

1297 _LOGGER.debug( 

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

1299 extra={ 

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

1301 "rpcName": "CreateSubscription", 

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

1303 "httpResponse": http_response, 

1304 }, 

1305 ) 

1306 return resp 

1307 

1308 class _DeleteSnapshot( 

1309 _BaseSubscriberRestTransport._BaseDeleteSnapshot, SubscriberRestStub 

1310 ): 

1311 def __hash__(self): 

1312 return hash("SubscriberRestTransport.DeleteSnapshot") 

1313 

1314 @staticmethod 

1315 def _get_response( 

1316 host, 

1317 metadata, 

1318 query_params, 

1319 session, 

1320 timeout, 

1321 transcoded_request, 

1322 body=None, 

1323 ): 

1324 uri = transcoded_request["uri"] 

1325 method = transcoded_request["method"] 

1326 headers = dict(metadata) 

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

1328 response = getattr(session, method)( 

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

1330 timeout=timeout, 

1331 headers=headers, 

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

1333 ) 

1334 return response 

1335 

1336 def __call__( 

1337 self, 

1338 request: pubsub.DeleteSnapshotRequest, 

1339 *, 

1340 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1341 timeout: Optional[float] = None, 

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

1343 ): 

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

1345 

1346 Args: 

1347 request (~.pubsub.DeleteSnapshotRequest): 

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

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

1350 should be retried. 

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

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

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

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

1355 be of type `bytes`. 

1356 """ 

1357 

1358 http_options = ( 

1359 _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_http_options() 

1360 ) 

1361 

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

1363 transcoded_request = _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_transcoded_request( 

1364 http_options, request 

1365 ) 

1366 

1367 # Jsonify the query params 

1368 query_params = ( 

1369 _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_query_params_json( 

1370 transcoded_request 

1371 ) 

1372 ) 

1373 

1374 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1375 logging.DEBUG 

1376 ): # pragma: NO COVER 

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

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

1379 ) 

1380 method = transcoded_request["method"] 

1381 try: 

1382 request_payload = json_format.MessageToJson(request) 

1383 except: 

1384 request_payload = None 

1385 http_request = { 

1386 "payload": request_payload, 

1387 "requestMethod": method, 

1388 "requestUrl": request_url, 

1389 "headers": dict(metadata), 

1390 } 

1391 _LOGGER.debug( 

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

1393 extra={ 

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

1395 "rpcName": "DeleteSnapshot", 

1396 "httpRequest": http_request, 

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

1398 }, 

1399 ) 

1400 

1401 # Send the request 

1402 response = SubscriberRestTransport._DeleteSnapshot._get_response( 

1403 self._host, 

1404 metadata, 

1405 query_params, 

1406 self._session, 

1407 timeout, 

1408 transcoded_request, 

1409 ) 

1410 

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

1412 # subclass. 

1413 if response.status_code >= 400: 

1414 raise core_exceptions.from_http_response(response) 

1415 

1416 class _DeleteSubscription( 

1417 _BaseSubscriberRestTransport._BaseDeleteSubscription, SubscriberRestStub 

1418 ): 

1419 def __hash__(self): 

1420 return hash("SubscriberRestTransport.DeleteSubscription") 

1421 

1422 @staticmethod 

1423 def _get_response( 

1424 host, 

1425 metadata, 

1426 query_params, 

1427 session, 

1428 timeout, 

1429 transcoded_request, 

1430 body=None, 

1431 ): 

1432 uri = transcoded_request["uri"] 

1433 method = transcoded_request["method"] 

1434 headers = dict(metadata) 

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

1436 response = getattr(session, method)( 

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

1438 timeout=timeout, 

1439 headers=headers, 

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

1441 ) 

1442 return response 

1443 

1444 def __call__( 

1445 self, 

1446 request: pubsub.DeleteSubscriptionRequest, 

1447 *, 

1448 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1449 timeout: Optional[float] = None, 

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

1451 ): 

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

1453 

1454 Args: 

1455 request (~.pubsub.DeleteSubscriptionRequest): 

1456 The request object. Request for the DeleteSubscription 

1457 method. 

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

1459 should be retried. 

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

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

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

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

1464 be of type `bytes`. 

1465 """ 

1466 

1467 http_options = ( 

1468 _BaseSubscriberRestTransport._BaseDeleteSubscription._get_http_options() 

1469 ) 

1470 

1471 request, metadata = self._interceptor.pre_delete_subscription( 

1472 request, metadata 

1473 ) 

1474 transcoded_request = _BaseSubscriberRestTransport._BaseDeleteSubscription._get_transcoded_request( 

1475 http_options, request 

1476 ) 

1477 

1478 # Jsonify the query params 

1479 query_params = _BaseSubscriberRestTransport._BaseDeleteSubscription._get_query_params_json( 

1480 transcoded_request 

1481 ) 

1482 

1483 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1484 logging.DEBUG 

1485 ): # pragma: NO COVER 

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

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

1488 ) 

1489 method = transcoded_request["method"] 

1490 try: 

1491 request_payload = json_format.MessageToJson(request) 

1492 except: 

1493 request_payload = None 

1494 http_request = { 

1495 "payload": request_payload, 

1496 "requestMethod": method, 

1497 "requestUrl": request_url, 

1498 "headers": dict(metadata), 

1499 } 

1500 _LOGGER.debug( 

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

1502 extra={ 

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

1504 "rpcName": "DeleteSubscription", 

1505 "httpRequest": http_request, 

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

1507 }, 

1508 ) 

1509 

1510 # Send the request 

1511 response = SubscriberRestTransport._DeleteSubscription._get_response( 

1512 self._host, 

1513 metadata, 

1514 query_params, 

1515 self._session, 

1516 timeout, 

1517 transcoded_request, 

1518 ) 

1519 

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

1521 # subclass. 

1522 if response.status_code >= 400: 

1523 raise core_exceptions.from_http_response(response) 

1524 

1525 class _GetSnapshot( 

1526 _BaseSubscriberRestTransport._BaseGetSnapshot, SubscriberRestStub 

1527 ): 

1528 def __hash__(self): 

1529 return hash("SubscriberRestTransport.GetSnapshot") 

1530 

1531 @staticmethod 

1532 def _get_response( 

1533 host, 

1534 metadata, 

1535 query_params, 

1536 session, 

1537 timeout, 

1538 transcoded_request, 

1539 body=None, 

1540 ): 

1541 uri = transcoded_request["uri"] 

1542 method = transcoded_request["method"] 

1543 headers = dict(metadata) 

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

1545 response = getattr(session, method)( 

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

1547 timeout=timeout, 

1548 headers=headers, 

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

1550 ) 

1551 return response 

1552 

1553 def __call__( 

1554 self, 

1555 request: pubsub.GetSnapshotRequest, 

1556 *, 

1557 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1558 timeout: Optional[float] = None, 

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

1560 ) -> pubsub.Snapshot: 

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

1562 

1563 Args: 

1564 request (~.pubsub.GetSnapshotRequest): 

1565 The request object. Request for the GetSnapshot method. 

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

1567 should be retried. 

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

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

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

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

1572 be of type `bytes`. 

1573 

1574 Returns: 

1575 ~.pubsub.Snapshot: 

1576 A snapshot resource. Snapshots are used in 

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

1578 operations, which allow you to manage message 

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

1580 acknowledgment state of messages in an existing 

1581 subscription to the state captured by a snapshot. 

1582 

1583 """ 

1584 

1585 http_options = ( 

1586 _BaseSubscriberRestTransport._BaseGetSnapshot._get_http_options() 

1587 ) 

1588 

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

1590 transcoded_request = ( 

1591 _BaseSubscriberRestTransport._BaseGetSnapshot._get_transcoded_request( 

1592 http_options, request 

1593 ) 

1594 ) 

1595 

1596 # Jsonify the query params 

1597 query_params = ( 

1598 _BaseSubscriberRestTransport._BaseGetSnapshot._get_query_params_json( 

1599 transcoded_request 

1600 ) 

1601 ) 

1602 

1603 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1604 logging.DEBUG 

1605 ): # pragma: NO COVER 

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

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

1608 ) 

1609 method = transcoded_request["method"] 

1610 try: 

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

1612 except: 

1613 request_payload = None 

1614 http_request = { 

1615 "payload": request_payload, 

1616 "requestMethod": method, 

1617 "requestUrl": request_url, 

1618 "headers": dict(metadata), 

1619 } 

1620 _LOGGER.debug( 

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

1622 extra={ 

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

1624 "rpcName": "GetSnapshot", 

1625 "httpRequest": http_request, 

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

1627 }, 

1628 ) 

1629 

1630 # Send the request 

1631 response = SubscriberRestTransport._GetSnapshot._get_response( 

1632 self._host, 

1633 metadata, 

1634 query_params, 

1635 self._session, 

1636 timeout, 

1637 transcoded_request, 

1638 ) 

1639 

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

1641 # subclass. 

1642 if response.status_code >= 400: 

1643 raise core_exceptions.from_http_response(response) 

1644 

1645 # Return the response 

1646 resp = pubsub.Snapshot() 

1647 pb_resp = pubsub.Snapshot.pb(resp) 

1648 

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

1650 

1651 resp = self._interceptor.post_get_snapshot(resp) 

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

1653 resp, _ = self._interceptor.post_get_snapshot_with_metadata( 

1654 resp, response_metadata 

1655 ) 

1656 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1657 logging.DEBUG 

1658 ): # pragma: NO COVER 

1659 try: 

1660 response_payload = pubsub.Snapshot.to_json(response) 

1661 except: 

1662 response_payload = None 

1663 http_response = { 

1664 "payload": response_payload, 

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

1666 "status": response.status_code, 

1667 } 

1668 _LOGGER.debug( 

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

1670 extra={ 

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

1672 "rpcName": "GetSnapshot", 

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

1674 "httpResponse": http_response, 

1675 }, 

1676 ) 

1677 return resp 

1678 

1679 class _GetSubscription( 

1680 _BaseSubscriberRestTransport._BaseGetSubscription, SubscriberRestStub 

1681 ): 

1682 def __hash__(self): 

1683 return hash("SubscriberRestTransport.GetSubscription") 

1684 

1685 @staticmethod 

1686 def _get_response( 

1687 host, 

1688 metadata, 

1689 query_params, 

1690 session, 

1691 timeout, 

1692 transcoded_request, 

1693 body=None, 

1694 ): 

1695 uri = transcoded_request["uri"] 

1696 method = transcoded_request["method"] 

1697 headers = dict(metadata) 

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

1699 response = getattr(session, method)( 

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

1701 timeout=timeout, 

1702 headers=headers, 

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

1704 ) 

1705 return response 

1706 

1707 def __call__( 

1708 self, 

1709 request: pubsub.GetSubscriptionRequest, 

1710 *, 

1711 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1712 timeout: Optional[float] = None, 

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

1714 ) -> pubsub.Subscription: 

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

1716 

1717 Args: 

1718 request (~.pubsub.GetSubscriptionRequest): 

1719 The request object. Request for the GetSubscription 

1720 method. 

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

1722 should be retried. 

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

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

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

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

1727 be of type `bytes`. 

1728 

1729 Returns: 

1730 ~.pubsub.Subscription: 

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

1732 ``bigquery_config``, or ``cloud_storage_config`` is set, 

1733 then the subscriber will pull and ack messages using API 

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

1735 

1736 """ 

1737 

1738 http_options = ( 

1739 _BaseSubscriberRestTransport._BaseGetSubscription._get_http_options() 

1740 ) 

1741 

1742 request, metadata = self._interceptor.pre_get_subscription( 

1743 request, metadata 

1744 ) 

1745 transcoded_request = _BaseSubscriberRestTransport._BaseGetSubscription._get_transcoded_request( 

1746 http_options, request 

1747 ) 

1748 

1749 # Jsonify the query params 

1750 query_params = _BaseSubscriberRestTransport._BaseGetSubscription._get_query_params_json( 

1751 transcoded_request 

1752 ) 

1753 

1754 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1755 logging.DEBUG 

1756 ): # pragma: NO COVER 

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

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

1759 ) 

1760 method = transcoded_request["method"] 

1761 try: 

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

1763 except: 

1764 request_payload = None 

1765 http_request = { 

1766 "payload": request_payload, 

1767 "requestMethod": method, 

1768 "requestUrl": request_url, 

1769 "headers": dict(metadata), 

1770 } 

1771 _LOGGER.debug( 

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

1773 extra={ 

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

1775 "rpcName": "GetSubscription", 

1776 "httpRequest": http_request, 

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

1778 }, 

1779 ) 

1780 

1781 # Send the request 

1782 response = SubscriberRestTransport._GetSubscription._get_response( 

1783 self._host, 

1784 metadata, 

1785 query_params, 

1786 self._session, 

1787 timeout, 

1788 transcoded_request, 

1789 ) 

1790 

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

1792 # subclass. 

1793 if response.status_code >= 400: 

1794 raise core_exceptions.from_http_response(response) 

1795 

1796 # Return the response 

1797 resp = pubsub.Subscription() 

1798 pb_resp = pubsub.Subscription.pb(resp) 

1799 

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

1801 

1802 resp = self._interceptor.post_get_subscription(resp) 

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

1804 resp, _ = self._interceptor.post_get_subscription_with_metadata( 

1805 resp, response_metadata 

1806 ) 

1807 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1808 logging.DEBUG 

1809 ): # pragma: NO COVER 

1810 try: 

1811 response_payload = pubsub.Subscription.to_json(response) 

1812 except: 

1813 response_payload = None 

1814 http_response = { 

1815 "payload": response_payload, 

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

1817 "status": response.status_code, 

1818 } 

1819 _LOGGER.debug( 

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

1821 extra={ 

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

1823 "rpcName": "GetSubscription", 

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

1825 "httpResponse": http_response, 

1826 }, 

1827 ) 

1828 return resp 

1829 

1830 class _ListSnapshots( 

1831 _BaseSubscriberRestTransport._BaseListSnapshots, SubscriberRestStub 

1832 ): 

1833 def __hash__(self): 

1834 return hash("SubscriberRestTransport.ListSnapshots") 

1835 

1836 @staticmethod 

1837 def _get_response( 

1838 host, 

1839 metadata, 

1840 query_params, 

1841 session, 

1842 timeout, 

1843 transcoded_request, 

1844 body=None, 

1845 ): 

1846 uri = transcoded_request["uri"] 

1847 method = transcoded_request["method"] 

1848 headers = dict(metadata) 

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

1850 response = getattr(session, method)( 

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

1852 timeout=timeout, 

1853 headers=headers, 

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

1855 ) 

1856 return response 

1857 

1858 def __call__( 

1859 self, 

1860 request: pubsub.ListSnapshotsRequest, 

1861 *, 

1862 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1863 timeout: Optional[float] = None, 

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

1865 ) -> pubsub.ListSnapshotsResponse: 

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

1867 

1868 Args: 

1869 request (~.pubsub.ListSnapshotsRequest): 

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

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

1872 should be retried. 

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

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

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

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

1877 be of type `bytes`. 

1878 

1879 Returns: 

1880 ~.pubsub.ListSnapshotsResponse: 

1881 Response for the ``ListSnapshots`` method. 

1882 """ 

1883 

1884 http_options = ( 

1885 _BaseSubscriberRestTransport._BaseListSnapshots._get_http_options() 

1886 ) 

1887 

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

1889 transcoded_request = ( 

1890 _BaseSubscriberRestTransport._BaseListSnapshots._get_transcoded_request( 

1891 http_options, request 

1892 ) 

1893 ) 

1894 

1895 # Jsonify the query params 

1896 query_params = ( 

1897 _BaseSubscriberRestTransport._BaseListSnapshots._get_query_params_json( 

1898 transcoded_request 

1899 ) 

1900 ) 

1901 

1902 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1903 logging.DEBUG 

1904 ): # pragma: NO COVER 

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

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

1907 ) 

1908 method = transcoded_request["method"] 

1909 try: 

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

1911 except: 

1912 request_payload = None 

1913 http_request = { 

1914 "payload": request_payload, 

1915 "requestMethod": method, 

1916 "requestUrl": request_url, 

1917 "headers": dict(metadata), 

1918 } 

1919 _LOGGER.debug( 

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

1921 extra={ 

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

1923 "rpcName": "ListSnapshots", 

1924 "httpRequest": http_request, 

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

1926 }, 

1927 ) 

1928 

1929 # Send the request 

1930 response = SubscriberRestTransport._ListSnapshots._get_response( 

1931 self._host, 

1932 metadata, 

1933 query_params, 

1934 self._session, 

1935 timeout, 

1936 transcoded_request, 

1937 ) 

1938 

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

1940 # subclass. 

1941 if response.status_code >= 400: 

1942 raise core_exceptions.from_http_response(response) 

1943 

1944 # Return the response 

1945 resp = pubsub.ListSnapshotsResponse() 

1946 pb_resp = pubsub.ListSnapshotsResponse.pb(resp) 

1947 

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

1949 

1950 resp = self._interceptor.post_list_snapshots(resp) 

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

1952 resp, _ = self._interceptor.post_list_snapshots_with_metadata( 

1953 resp, response_metadata 

1954 ) 

1955 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1956 logging.DEBUG 

1957 ): # pragma: NO COVER 

1958 try: 

1959 response_payload = pubsub.ListSnapshotsResponse.to_json(response) 

1960 except: 

1961 response_payload = None 

1962 http_response = { 

1963 "payload": response_payload, 

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

1965 "status": response.status_code, 

1966 } 

1967 _LOGGER.debug( 

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

1969 extra={ 

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

1971 "rpcName": "ListSnapshots", 

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

1973 "httpResponse": http_response, 

1974 }, 

1975 ) 

1976 return resp 

1977 

1978 class _ListSubscriptions( 

1979 _BaseSubscriberRestTransport._BaseListSubscriptions, SubscriberRestStub 

1980 ): 

1981 def __hash__(self): 

1982 return hash("SubscriberRestTransport.ListSubscriptions") 

1983 

1984 @staticmethod 

1985 def _get_response( 

1986 host, 

1987 metadata, 

1988 query_params, 

1989 session, 

1990 timeout, 

1991 transcoded_request, 

1992 body=None, 

1993 ): 

1994 uri = transcoded_request["uri"] 

1995 method = transcoded_request["method"] 

1996 headers = dict(metadata) 

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

1998 response = getattr(session, method)( 

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

2000 timeout=timeout, 

2001 headers=headers, 

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

2003 ) 

2004 return response 

2005 

2006 def __call__( 

2007 self, 

2008 request: pubsub.ListSubscriptionsRequest, 

2009 *, 

2010 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2011 timeout: Optional[float] = None, 

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

2013 ) -> pubsub.ListSubscriptionsResponse: 

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

2015 

2016 Args: 

2017 request (~.pubsub.ListSubscriptionsRequest): 

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

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

2020 should be retried. 

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

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

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

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

2025 be of type `bytes`. 

2026 

2027 Returns: 

2028 ~.pubsub.ListSubscriptionsResponse: 

2029 Response for the ``ListSubscriptions`` method. 

2030 """ 

2031 

2032 http_options = ( 

2033 _BaseSubscriberRestTransport._BaseListSubscriptions._get_http_options() 

2034 ) 

2035 

2036 request, metadata = self._interceptor.pre_list_subscriptions( 

2037 request, metadata 

2038 ) 

2039 transcoded_request = _BaseSubscriberRestTransport._BaseListSubscriptions._get_transcoded_request( 

2040 http_options, request 

2041 ) 

2042 

2043 # Jsonify the query params 

2044 query_params = _BaseSubscriberRestTransport._BaseListSubscriptions._get_query_params_json( 

2045 transcoded_request 

2046 ) 

2047 

2048 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2049 logging.DEBUG 

2050 ): # pragma: NO COVER 

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

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

2053 ) 

2054 method = transcoded_request["method"] 

2055 try: 

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

2057 except: 

2058 request_payload = None 

2059 http_request = { 

2060 "payload": request_payload, 

2061 "requestMethod": method, 

2062 "requestUrl": request_url, 

2063 "headers": dict(metadata), 

2064 } 

2065 _LOGGER.debug( 

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

2067 extra={ 

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

2069 "rpcName": "ListSubscriptions", 

2070 "httpRequest": http_request, 

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

2072 }, 

2073 ) 

2074 

2075 # Send the request 

2076 response = SubscriberRestTransport._ListSubscriptions._get_response( 

2077 self._host, 

2078 metadata, 

2079 query_params, 

2080 self._session, 

2081 timeout, 

2082 transcoded_request, 

2083 ) 

2084 

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

2086 # subclass. 

2087 if response.status_code >= 400: 

2088 raise core_exceptions.from_http_response(response) 

2089 

2090 # Return the response 

2091 resp = pubsub.ListSubscriptionsResponse() 

2092 pb_resp = pubsub.ListSubscriptionsResponse.pb(resp) 

2093 

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

2095 

2096 resp = self._interceptor.post_list_subscriptions(resp) 

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

2098 resp, _ = self._interceptor.post_list_subscriptions_with_metadata( 

2099 resp, response_metadata 

2100 ) 

2101 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2102 logging.DEBUG 

2103 ): # pragma: NO COVER 

2104 try: 

2105 response_payload = pubsub.ListSubscriptionsResponse.to_json( 

2106 response 

2107 ) 

2108 except: 

2109 response_payload = None 

2110 http_response = { 

2111 "payload": response_payload, 

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

2113 "status": response.status_code, 

2114 } 

2115 _LOGGER.debug( 

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

2117 extra={ 

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

2119 "rpcName": "ListSubscriptions", 

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

2121 "httpResponse": http_response, 

2122 }, 

2123 ) 

2124 return resp 

2125 

2126 class _ModifyAckDeadline( 

2127 _BaseSubscriberRestTransport._BaseModifyAckDeadline, SubscriberRestStub 

2128 ): 

2129 def __hash__(self): 

2130 return hash("SubscriberRestTransport.ModifyAckDeadline") 

2131 

2132 @staticmethod 

2133 def _get_response( 

2134 host, 

2135 metadata, 

2136 query_params, 

2137 session, 

2138 timeout, 

2139 transcoded_request, 

2140 body=None, 

2141 ): 

2142 uri = transcoded_request["uri"] 

2143 method = transcoded_request["method"] 

2144 headers = dict(metadata) 

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

2146 response = getattr(session, method)( 

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

2148 timeout=timeout, 

2149 headers=headers, 

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

2151 data=body, 

2152 ) 

2153 return response 

2154 

2155 def __call__( 

2156 self, 

2157 request: pubsub.ModifyAckDeadlineRequest, 

2158 *, 

2159 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2160 timeout: Optional[float] = None, 

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

2162 ): 

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

2164 

2165 Args: 

2166 request (~.pubsub.ModifyAckDeadlineRequest): 

2167 The request object. Request for the ModifyAckDeadline 

2168 method. 

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

2170 should be retried. 

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

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

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

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

2175 be of type `bytes`. 

2176 """ 

2177 

2178 http_options = ( 

2179 _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_http_options() 

2180 ) 

2181 

2182 request, metadata = self._interceptor.pre_modify_ack_deadline( 

2183 request, metadata 

2184 ) 

2185 transcoded_request = _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_transcoded_request( 

2186 http_options, request 

2187 ) 

2188 

2189 body = _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_request_body_json( 

2190 transcoded_request 

2191 ) 

2192 

2193 # Jsonify the query params 

2194 query_params = _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_query_params_json( 

2195 transcoded_request 

2196 ) 

2197 

2198 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2199 logging.DEBUG 

2200 ): # pragma: NO COVER 

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

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

2203 ) 

2204 method = transcoded_request["method"] 

2205 try: 

2206 request_payload = json_format.MessageToJson(request) 

2207 except: 

2208 request_payload = None 

2209 http_request = { 

2210 "payload": request_payload, 

2211 "requestMethod": method, 

2212 "requestUrl": request_url, 

2213 "headers": dict(metadata), 

2214 } 

2215 _LOGGER.debug( 

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

2217 extra={ 

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

2219 "rpcName": "ModifyAckDeadline", 

2220 "httpRequest": http_request, 

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

2222 }, 

2223 ) 

2224 

2225 # Send the request 

2226 response = SubscriberRestTransport._ModifyAckDeadline._get_response( 

2227 self._host, 

2228 metadata, 

2229 query_params, 

2230 self._session, 

2231 timeout, 

2232 transcoded_request, 

2233 body, 

2234 ) 

2235 

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

2237 # subclass. 

2238 if response.status_code >= 400: 

2239 raise core_exceptions.from_http_response(response) 

2240 

2241 class _ModifyPushConfig( 

2242 _BaseSubscriberRestTransport._BaseModifyPushConfig, SubscriberRestStub 

2243 ): 

2244 def __hash__(self): 

2245 return hash("SubscriberRestTransport.ModifyPushConfig") 

2246 

2247 @staticmethod 

2248 def _get_response( 

2249 host, 

2250 metadata, 

2251 query_params, 

2252 session, 

2253 timeout, 

2254 transcoded_request, 

2255 body=None, 

2256 ): 

2257 uri = transcoded_request["uri"] 

2258 method = transcoded_request["method"] 

2259 headers = dict(metadata) 

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

2261 response = getattr(session, method)( 

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

2263 timeout=timeout, 

2264 headers=headers, 

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

2266 data=body, 

2267 ) 

2268 return response 

2269 

2270 def __call__( 

2271 self, 

2272 request: pubsub.ModifyPushConfigRequest, 

2273 *, 

2274 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2275 timeout: Optional[float] = None, 

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

2277 ): 

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

2279 

2280 Args: 

2281 request (~.pubsub.ModifyPushConfigRequest): 

2282 The request object. Request for the ModifyPushConfig 

2283 method. 

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

2285 should be retried. 

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

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

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

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

2290 be of type `bytes`. 

2291 """ 

2292 

2293 http_options = ( 

2294 _BaseSubscriberRestTransport._BaseModifyPushConfig._get_http_options() 

2295 ) 

2296 

2297 request, metadata = self._interceptor.pre_modify_push_config( 

2298 request, metadata 

2299 ) 

2300 transcoded_request = _BaseSubscriberRestTransport._BaseModifyPushConfig._get_transcoded_request( 

2301 http_options, request 

2302 ) 

2303 

2304 body = _BaseSubscriberRestTransport._BaseModifyPushConfig._get_request_body_json( 

2305 transcoded_request 

2306 ) 

2307 

2308 # Jsonify the query params 

2309 query_params = _BaseSubscriberRestTransport._BaseModifyPushConfig._get_query_params_json( 

2310 transcoded_request 

2311 ) 

2312 

2313 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2314 logging.DEBUG 

2315 ): # pragma: NO COVER 

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

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

2318 ) 

2319 method = transcoded_request["method"] 

2320 try: 

2321 request_payload = json_format.MessageToJson(request) 

2322 except: 

2323 request_payload = None 

2324 http_request = { 

2325 "payload": request_payload, 

2326 "requestMethod": method, 

2327 "requestUrl": request_url, 

2328 "headers": dict(metadata), 

2329 } 

2330 _LOGGER.debug( 

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

2332 extra={ 

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

2334 "rpcName": "ModifyPushConfig", 

2335 "httpRequest": http_request, 

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

2337 }, 

2338 ) 

2339 

2340 # Send the request 

2341 response = SubscriberRestTransport._ModifyPushConfig._get_response( 

2342 self._host, 

2343 metadata, 

2344 query_params, 

2345 self._session, 

2346 timeout, 

2347 transcoded_request, 

2348 body, 

2349 ) 

2350 

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

2352 # subclass. 

2353 if response.status_code >= 400: 

2354 raise core_exceptions.from_http_response(response) 

2355 

2356 class _Pull(_BaseSubscriberRestTransport._BasePull, SubscriberRestStub): 

2357 def __hash__(self): 

2358 return hash("SubscriberRestTransport.Pull") 

2359 

2360 @staticmethod 

2361 def _get_response( 

2362 host, 

2363 metadata, 

2364 query_params, 

2365 session, 

2366 timeout, 

2367 transcoded_request, 

2368 body=None, 

2369 ): 

2370 uri = transcoded_request["uri"] 

2371 method = transcoded_request["method"] 

2372 headers = dict(metadata) 

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

2374 response = getattr(session, method)( 

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

2376 timeout=timeout, 

2377 headers=headers, 

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

2379 data=body, 

2380 ) 

2381 return response 

2382 

2383 def __call__( 

2384 self, 

2385 request: pubsub.PullRequest, 

2386 *, 

2387 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2388 timeout: Optional[float] = None, 

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

2390 ) -> pubsub.PullResponse: 

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

2392 

2393 Args: 

2394 request (~.pubsub.PullRequest): 

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

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

2397 should be retried. 

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

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

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

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

2402 be of type `bytes`. 

2403 

2404 Returns: 

2405 ~.pubsub.PullResponse: 

2406 Response for the ``Pull`` method. 

2407 """ 

2408 

2409 http_options = _BaseSubscriberRestTransport._BasePull._get_http_options() 

2410 

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

2412 transcoded_request = ( 

2413 _BaseSubscriberRestTransport._BasePull._get_transcoded_request( 

2414 http_options, request 

2415 ) 

2416 ) 

2417 

2418 body = _BaseSubscriberRestTransport._BasePull._get_request_body_json( 

2419 transcoded_request 

2420 ) 

2421 

2422 # Jsonify the query params 

2423 query_params = ( 

2424 _BaseSubscriberRestTransport._BasePull._get_query_params_json( 

2425 transcoded_request 

2426 ) 

2427 ) 

2428 

2429 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2430 logging.DEBUG 

2431 ): # pragma: NO COVER 

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

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

2434 ) 

2435 method = transcoded_request["method"] 

2436 try: 

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

2438 except: 

2439 request_payload = None 

2440 http_request = { 

2441 "payload": request_payload, 

2442 "requestMethod": method, 

2443 "requestUrl": request_url, 

2444 "headers": dict(metadata), 

2445 } 

2446 _LOGGER.debug( 

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

2448 extra={ 

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

2450 "rpcName": "Pull", 

2451 "httpRequest": http_request, 

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

2453 }, 

2454 ) 

2455 

2456 # Send the request 

2457 response = SubscriberRestTransport._Pull._get_response( 

2458 self._host, 

2459 metadata, 

2460 query_params, 

2461 self._session, 

2462 timeout, 

2463 transcoded_request, 

2464 body, 

2465 ) 

2466 

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

2468 # subclass. 

2469 if response.status_code >= 400: 

2470 raise core_exceptions.from_http_response(response) 

2471 

2472 # Return the response 

2473 resp = pubsub.PullResponse() 

2474 pb_resp = pubsub.PullResponse.pb(resp) 

2475 

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

2477 

2478 resp = self._interceptor.post_pull(resp) 

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

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

2481 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2482 logging.DEBUG 

2483 ): # pragma: NO COVER 

2484 try: 

2485 response_payload = pubsub.PullResponse.to_json(response) 

2486 except: 

2487 response_payload = None 

2488 http_response = { 

2489 "payload": response_payload, 

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

2491 "status": response.status_code, 

2492 } 

2493 _LOGGER.debug( 

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

2495 extra={ 

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

2497 "rpcName": "Pull", 

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

2499 "httpResponse": http_response, 

2500 }, 

2501 ) 

2502 return resp 

2503 

2504 class _Seek(_BaseSubscriberRestTransport._BaseSeek, SubscriberRestStub): 

2505 def __hash__(self): 

2506 return hash("SubscriberRestTransport.Seek") 

2507 

2508 @staticmethod 

2509 def _get_response( 

2510 host, 

2511 metadata, 

2512 query_params, 

2513 session, 

2514 timeout, 

2515 transcoded_request, 

2516 body=None, 

2517 ): 

2518 uri = transcoded_request["uri"] 

2519 method = transcoded_request["method"] 

2520 headers = dict(metadata) 

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

2522 response = getattr(session, method)( 

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

2524 timeout=timeout, 

2525 headers=headers, 

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

2527 data=body, 

2528 ) 

2529 return response 

2530 

2531 def __call__( 

2532 self, 

2533 request: pubsub.SeekRequest, 

2534 *, 

2535 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2536 timeout: Optional[float] = None, 

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

2538 ) -> pubsub.SeekResponse: 

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

2540 

2541 Args: 

2542 request (~.pubsub.SeekRequest): 

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

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

2545 should be retried. 

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

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

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

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

2550 be of type `bytes`. 

2551 

2552 Returns: 

2553 ~.pubsub.SeekResponse: 

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

2555 empty). 

2556 

2557 """ 

2558 

2559 http_options = _BaseSubscriberRestTransport._BaseSeek._get_http_options() 

2560 

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

2562 transcoded_request = ( 

2563 _BaseSubscriberRestTransport._BaseSeek._get_transcoded_request( 

2564 http_options, request 

2565 ) 

2566 ) 

2567 

2568 body = _BaseSubscriberRestTransport._BaseSeek._get_request_body_json( 

2569 transcoded_request 

2570 ) 

2571 

2572 # Jsonify the query params 

2573 query_params = ( 

2574 _BaseSubscriberRestTransport._BaseSeek._get_query_params_json( 

2575 transcoded_request 

2576 ) 

2577 ) 

2578 

2579 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2580 logging.DEBUG 

2581 ): # pragma: NO COVER 

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

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

2584 ) 

2585 method = transcoded_request["method"] 

2586 try: 

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

2588 except: 

2589 request_payload = None 

2590 http_request = { 

2591 "payload": request_payload, 

2592 "requestMethod": method, 

2593 "requestUrl": request_url, 

2594 "headers": dict(metadata), 

2595 } 

2596 _LOGGER.debug( 

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

2598 extra={ 

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

2600 "rpcName": "Seek", 

2601 "httpRequest": http_request, 

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

2603 }, 

2604 ) 

2605 

2606 # Send the request 

2607 response = SubscriberRestTransport._Seek._get_response( 

2608 self._host, 

2609 metadata, 

2610 query_params, 

2611 self._session, 

2612 timeout, 

2613 transcoded_request, 

2614 body, 

2615 ) 

2616 

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

2618 # subclass. 

2619 if response.status_code >= 400: 

2620 raise core_exceptions.from_http_response(response) 

2621 

2622 # Return the response 

2623 resp = pubsub.SeekResponse() 

2624 pb_resp = pubsub.SeekResponse.pb(resp) 

2625 

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

2627 

2628 resp = self._interceptor.post_seek(resp) 

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

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

2631 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2632 logging.DEBUG 

2633 ): # pragma: NO COVER 

2634 try: 

2635 response_payload = pubsub.SeekResponse.to_json(response) 

2636 except: 

2637 response_payload = None 

2638 http_response = { 

2639 "payload": response_payload, 

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

2641 "status": response.status_code, 

2642 } 

2643 _LOGGER.debug( 

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

2645 extra={ 

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

2647 "rpcName": "Seek", 

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

2649 "httpResponse": http_response, 

2650 }, 

2651 ) 

2652 return resp 

2653 

2654 class _StreamingPull( 

2655 _BaseSubscriberRestTransport._BaseStreamingPull, SubscriberRestStub 

2656 ): 

2657 def __hash__(self): 

2658 return hash("SubscriberRestTransport.StreamingPull") 

2659 

2660 def __call__( 

2661 self, 

2662 request: pubsub.StreamingPullRequest, 

2663 *, 

2664 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2665 timeout: Optional[float] = None, 

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

2667 ) -> rest_streaming.ResponseIterator: 

2668 raise NotImplementedError( 

2669 "Method StreamingPull is not available over REST transport" 

2670 ) 

2671 

2672 class _UpdateSnapshot( 

2673 _BaseSubscriberRestTransport._BaseUpdateSnapshot, SubscriberRestStub 

2674 ): 

2675 def __hash__(self): 

2676 return hash("SubscriberRestTransport.UpdateSnapshot") 

2677 

2678 @staticmethod 

2679 def _get_response( 

2680 host, 

2681 metadata, 

2682 query_params, 

2683 session, 

2684 timeout, 

2685 transcoded_request, 

2686 body=None, 

2687 ): 

2688 uri = transcoded_request["uri"] 

2689 method = transcoded_request["method"] 

2690 headers = dict(metadata) 

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

2692 response = getattr(session, method)( 

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

2694 timeout=timeout, 

2695 headers=headers, 

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

2697 data=body, 

2698 ) 

2699 return response 

2700 

2701 def __call__( 

2702 self, 

2703 request: pubsub.UpdateSnapshotRequest, 

2704 *, 

2705 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2706 timeout: Optional[float] = None, 

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

2708 ) -> pubsub.Snapshot: 

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

2710 

2711 Args: 

2712 request (~.pubsub.UpdateSnapshotRequest): 

2713 The request object. Request for the UpdateSnapshot 

2714 method. 

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

2716 should be retried. 

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

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

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

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

2721 be of type `bytes`. 

2722 

2723 Returns: 

2724 ~.pubsub.Snapshot: 

2725 A snapshot resource. Snapshots are used in 

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

2727 operations, which allow you to manage message 

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

2729 acknowledgment state of messages in an existing 

2730 subscription to the state captured by a snapshot. 

2731 

2732 """ 

2733 

2734 http_options = ( 

2735 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_http_options() 

2736 ) 

2737 

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

2739 transcoded_request = _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_transcoded_request( 

2740 http_options, request 

2741 ) 

2742 

2743 body = ( 

2744 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_request_body_json( 

2745 transcoded_request 

2746 ) 

2747 ) 

2748 

2749 # Jsonify the query params 

2750 query_params = ( 

2751 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_query_params_json( 

2752 transcoded_request 

2753 ) 

2754 ) 

2755 

2756 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2757 logging.DEBUG 

2758 ): # pragma: NO COVER 

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

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

2761 ) 

2762 method = transcoded_request["method"] 

2763 try: 

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

2765 except: 

2766 request_payload = None 

2767 http_request = { 

2768 "payload": request_payload, 

2769 "requestMethod": method, 

2770 "requestUrl": request_url, 

2771 "headers": dict(metadata), 

2772 } 

2773 _LOGGER.debug( 

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

2775 extra={ 

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

2777 "rpcName": "UpdateSnapshot", 

2778 "httpRequest": http_request, 

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

2780 }, 

2781 ) 

2782 

2783 # Send the request 

2784 response = SubscriberRestTransport._UpdateSnapshot._get_response( 

2785 self._host, 

2786 metadata, 

2787 query_params, 

2788 self._session, 

2789 timeout, 

2790 transcoded_request, 

2791 body, 

2792 ) 

2793 

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

2795 # subclass. 

2796 if response.status_code >= 400: 

2797 raise core_exceptions.from_http_response(response) 

2798 

2799 # Return the response 

2800 resp = pubsub.Snapshot() 

2801 pb_resp = pubsub.Snapshot.pb(resp) 

2802 

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

2804 

2805 resp = self._interceptor.post_update_snapshot(resp) 

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

2807 resp, _ = self._interceptor.post_update_snapshot_with_metadata( 

2808 resp, response_metadata 

2809 ) 

2810 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2811 logging.DEBUG 

2812 ): # pragma: NO COVER 

2813 try: 

2814 response_payload = pubsub.Snapshot.to_json(response) 

2815 except: 

2816 response_payload = None 

2817 http_response = { 

2818 "payload": response_payload, 

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

2820 "status": response.status_code, 

2821 } 

2822 _LOGGER.debug( 

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

2824 extra={ 

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

2826 "rpcName": "UpdateSnapshot", 

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

2828 "httpResponse": http_response, 

2829 }, 

2830 ) 

2831 return resp 

2832 

2833 class _UpdateSubscription( 

2834 _BaseSubscriberRestTransport._BaseUpdateSubscription, SubscriberRestStub 

2835 ): 

2836 def __hash__(self): 

2837 return hash("SubscriberRestTransport.UpdateSubscription") 

2838 

2839 @staticmethod 

2840 def _get_response( 

2841 host, 

2842 metadata, 

2843 query_params, 

2844 session, 

2845 timeout, 

2846 transcoded_request, 

2847 body=None, 

2848 ): 

2849 uri = transcoded_request["uri"] 

2850 method = transcoded_request["method"] 

2851 headers = dict(metadata) 

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

2853 response = getattr(session, method)( 

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

2855 timeout=timeout, 

2856 headers=headers, 

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

2858 data=body, 

2859 ) 

2860 return response 

2861 

2862 def __call__( 

2863 self, 

2864 request: pubsub.UpdateSubscriptionRequest, 

2865 *, 

2866 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2867 timeout: Optional[float] = None, 

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

2869 ) -> pubsub.Subscription: 

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

2871 

2872 Args: 

2873 request (~.pubsub.UpdateSubscriptionRequest): 

2874 The request object. Request for the UpdateSubscription 

2875 method. 

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

2877 should be retried. 

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

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

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

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

2882 be of type `bytes`. 

2883 

2884 Returns: 

2885 ~.pubsub.Subscription: 

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

2887 ``bigquery_config``, or ``cloud_storage_config`` is set, 

2888 then the subscriber will pull and ack messages using API 

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

2890 

2891 """ 

2892 

2893 http_options = ( 

2894 _BaseSubscriberRestTransport._BaseUpdateSubscription._get_http_options() 

2895 ) 

2896 

2897 request, metadata = self._interceptor.pre_update_subscription( 

2898 request, metadata 

2899 ) 

2900 transcoded_request = _BaseSubscriberRestTransport._BaseUpdateSubscription._get_transcoded_request( 

2901 http_options, request 

2902 ) 

2903 

2904 body = _BaseSubscriberRestTransport._BaseUpdateSubscription._get_request_body_json( 

2905 transcoded_request 

2906 ) 

2907 

2908 # Jsonify the query params 

2909 query_params = _BaseSubscriberRestTransport._BaseUpdateSubscription._get_query_params_json( 

2910 transcoded_request 

2911 ) 

2912 

2913 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2914 logging.DEBUG 

2915 ): # pragma: NO COVER 

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

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

2918 ) 

2919 method = transcoded_request["method"] 

2920 try: 

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

2922 except: 

2923 request_payload = None 

2924 http_request = { 

2925 "payload": request_payload, 

2926 "requestMethod": method, 

2927 "requestUrl": request_url, 

2928 "headers": dict(metadata), 

2929 } 

2930 _LOGGER.debug( 

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

2932 extra={ 

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

2934 "rpcName": "UpdateSubscription", 

2935 "httpRequest": http_request, 

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

2937 }, 

2938 ) 

2939 

2940 # Send the request 

2941 response = SubscriberRestTransport._UpdateSubscription._get_response( 

2942 self._host, 

2943 metadata, 

2944 query_params, 

2945 self._session, 

2946 timeout, 

2947 transcoded_request, 

2948 body, 

2949 ) 

2950 

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

2952 # subclass. 

2953 if response.status_code >= 400: 

2954 raise core_exceptions.from_http_response(response) 

2955 

2956 # Return the response 

2957 resp = pubsub.Subscription() 

2958 pb_resp = pubsub.Subscription.pb(resp) 

2959 

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

2961 

2962 resp = self._interceptor.post_update_subscription(resp) 

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

2964 resp, _ = self._interceptor.post_update_subscription_with_metadata( 

2965 resp, response_metadata 

2966 ) 

2967 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2968 logging.DEBUG 

2969 ): # pragma: NO COVER 

2970 try: 

2971 response_payload = pubsub.Subscription.to_json(response) 

2972 except: 

2973 response_payload = None 

2974 http_response = { 

2975 "payload": response_payload, 

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

2977 "status": response.status_code, 

2978 } 

2979 _LOGGER.debug( 

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

2981 extra={ 

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

2983 "rpcName": "UpdateSubscription", 

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

2985 "httpResponse": http_response, 

2986 }, 

2987 ) 

2988 return resp 

2989 

2990 @property 

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

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

2993 # In C++ this would require a dynamic_cast 

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

2995 

2996 @property 

2997 def create_snapshot( 

2998 self, 

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

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

3001 # In C++ this would require a dynamic_cast 

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

3003 

3004 @property 

3005 def create_subscription( 

3006 self, 

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

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

3009 # In C++ this would require a dynamic_cast 

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

3011 

3012 @property 

3013 def delete_snapshot( 

3014 self, 

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

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

3017 # In C++ this would require a dynamic_cast 

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

3019 

3020 @property 

3021 def delete_subscription( 

3022 self, 

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

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

3025 # In C++ this would require a dynamic_cast 

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

3027 

3028 @property 

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

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

3031 # In C++ this would require a dynamic_cast 

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

3033 

3034 @property 

3035 def get_subscription( 

3036 self, 

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

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

3039 # In C++ this would require a dynamic_cast 

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

3041 

3042 @property 

3043 def list_snapshots( 

3044 self, 

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

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

3047 # In C++ this would require a dynamic_cast 

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

3049 

3050 @property 

3051 def list_subscriptions( 

3052 self, 

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

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

3055 # In C++ this would require a dynamic_cast 

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

3057 

3058 @property 

3059 def modify_ack_deadline( 

3060 self, 

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

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

3063 # In C++ this would require a dynamic_cast 

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

3065 

3066 @property 

3067 def modify_push_config( 

3068 self, 

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

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

3071 # In C++ this would require a dynamic_cast 

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

3073 

3074 @property 

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

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

3077 # In C++ this would require a dynamic_cast 

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

3079 

3080 @property 

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

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

3083 # In C++ this would require a dynamic_cast 

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

3085 

3086 @property 

3087 def streaming_pull( 

3088 self, 

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

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

3091 # In C++ this would require a dynamic_cast 

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

3093 

3094 @property 

3095 def update_snapshot( 

3096 self, 

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

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

3099 # In C++ this would require a dynamic_cast 

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

3101 

3102 @property 

3103 def update_subscription( 

3104 self, 

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

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

3107 # In C++ this would require a dynamic_cast 

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

3109 

3110 @property 

3111 def get_iam_policy(self): 

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

3113 

3114 class _GetIamPolicy( 

3115 _BaseSubscriberRestTransport._BaseGetIamPolicy, SubscriberRestStub 

3116 ): 

3117 def __hash__(self): 

3118 return hash("SubscriberRestTransport.GetIamPolicy") 

3119 

3120 @staticmethod 

3121 def _get_response( 

3122 host, 

3123 metadata, 

3124 query_params, 

3125 session, 

3126 timeout, 

3127 transcoded_request, 

3128 body=None, 

3129 ): 

3130 uri = transcoded_request["uri"] 

3131 method = transcoded_request["method"] 

3132 headers = dict(metadata) 

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

3134 response = getattr(session, method)( 

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

3136 timeout=timeout, 

3137 headers=headers, 

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

3139 ) 

3140 return response 

3141 

3142 def __call__( 

3143 self, 

3144 request: iam_policy_pb2.GetIamPolicyRequest, 

3145 *, 

3146 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3147 timeout: Optional[float] = None, 

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

3149 ) -> policy_pb2.Policy: 

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

3151 

3152 Args: 

3153 request (iam_policy_pb2.GetIamPolicyRequest): 

3154 The request object for GetIamPolicy method. 

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

3156 should be retried. 

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

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

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

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

3161 be of type `bytes`. 

3162 

3163 Returns: 

3164 policy_pb2.Policy: Response from GetIamPolicy method. 

3165 """ 

3166 

3167 http_options = ( 

3168 _BaseSubscriberRestTransport._BaseGetIamPolicy._get_http_options() 

3169 ) 

3170 

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

3172 transcoded_request = ( 

3173 _BaseSubscriberRestTransport._BaseGetIamPolicy._get_transcoded_request( 

3174 http_options, request 

3175 ) 

3176 ) 

3177 

3178 # Jsonify the query params 

3179 query_params = ( 

3180 _BaseSubscriberRestTransport._BaseGetIamPolicy._get_query_params_json( 

3181 transcoded_request 

3182 ) 

3183 ) 

3184 

3185 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3186 logging.DEBUG 

3187 ): # pragma: NO COVER 

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

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

3190 ) 

3191 method = transcoded_request["method"] 

3192 try: 

3193 request_payload = json_format.MessageToJson(request) 

3194 except: 

3195 request_payload = None 

3196 http_request = { 

3197 "payload": request_payload, 

3198 "requestMethod": method, 

3199 "requestUrl": request_url, 

3200 "headers": dict(metadata), 

3201 } 

3202 _LOGGER.debug( 

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

3204 extra={ 

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

3206 "rpcName": "GetIamPolicy", 

3207 "httpRequest": http_request, 

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

3209 }, 

3210 ) 

3211 

3212 # Send the request 

3213 response = SubscriberRestTransport._GetIamPolicy._get_response( 

3214 self._host, 

3215 metadata, 

3216 query_params, 

3217 self._session, 

3218 timeout, 

3219 transcoded_request, 

3220 ) 

3221 

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

3223 # subclass. 

3224 if response.status_code >= 400: 

3225 raise core_exceptions.from_http_response(response) 

3226 

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

3228 resp = policy_pb2.Policy() 

3229 resp = json_format.Parse(content, resp) 

3230 resp = self._interceptor.post_get_iam_policy(resp) 

3231 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3232 logging.DEBUG 

3233 ): # pragma: NO COVER 

3234 try: 

3235 response_payload = json_format.MessageToJson(resp) 

3236 except: 

3237 response_payload = None 

3238 http_response = { 

3239 "payload": response_payload, 

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

3241 "status": response.status_code, 

3242 } 

3243 _LOGGER.debug( 

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

3245 extra={ 

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

3247 "rpcName": "GetIamPolicy", 

3248 "httpResponse": http_response, 

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

3250 }, 

3251 ) 

3252 return resp 

3253 

3254 @property 

3255 def set_iam_policy(self): 

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

3257 

3258 class _SetIamPolicy( 

3259 _BaseSubscriberRestTransport._BaseSetIamPolicy, SubscriberRestStub 

3260 ): 

3261 def __hash__(self): 

3262 return hash("SubscriberRestTransport.SetIamPolicy") 

3263 

3264 @staticmethod 

3265 def _get_response( 

3266 host, 

3267 metadata, 

3268 query_params, 

3269 session, 

3270 timeout, 

3271 transcoded_request, 

3272 body=None, 

3273 ): 

3274 uri = transcoded_request["uri"] 

3275 method = transcoded_request["method"] 

3276 headers = dict(metadata) 

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

3278 response = getattr(session, method)( 

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

3280 timeout=timeout, 

3281 headers=headers, 

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

3283 data=body, 

3284 ) 

3285 return response 

3286 

3287 def __call__( 

3288 self, 

3289 request: iam_policy_pb2.SetIamPolicyRequest, 

3290 *, 

3291 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3292 timeout: Optional[float] = None, 

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

3294 ) -> policy_pb2.Policy: 

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

3296 

3297 Args: 

3298 request (iam_policy_pb2.SetIamPolicyRequest): 

3299 The request object for SetIamPolicy method. 

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

3301 should be retried. 

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

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

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

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

3306 be of type `bytes`. 

3307 

3308 Returns: 

3309 policy_pb2.Policy: Response from SetIamPolicy method. 

3310 """ 

3311 

3312 http_options = ( 

3313 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_http_options() 

3314 ) 

3315 

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

3317 transcoded_request = ( 

3318 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_transcoded_request( 

3319 http_options, request 

3320 ) 

3321 ) 

3322 

3323 body = ( 

3324 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_request_body_json( 

3325 transcoded_request 

3326 ) 

3327 ) 

3328 

3329 # Jsonify the query params 

3330 query_params = ( 

3331 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_query_params_json( 

3332 transcoded_request 

3333 ) 

3334 ) 

3335 

3336 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3337 logging.DEBUG 

3338 ): # pragma: NO COVER 

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

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

3341 ) 

3342 method = transcoded_request["method"] 

3343 try: 

3344 request_payload = json_format.MessageToJson(request) 

3345 except: 

3346 request_payload = None 

3347 http_request = { 

3348 "payload": request_payload, 

3349 "requestMethod": method, 

3350 "requestUrl": request_url, 

3351 "headers": dict(metadata), 

3352 } 

3353 _LOGGER.debug( 

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

3355 extra={ 

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

3357 "rpcName": "SetIamPolicy", 

3358 "httpRequest": http_request, 

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

3360 }, 

3361 ) 

3362 

3363 # Send the request 

3364 response = SubscriberRestTransport._SetIamPolicy._get_response( 

3365 self._host, 

3366 metadata, 

3367 query_params, 

3368 self._session, 

3369 timeout, 

3370 transcoded_request, 

3371 body, 

3372 ) 

3373 

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

3375 # subclass. 

3376 if response.status_code >= 400: 

3377 raise core_exceptions.from_http_response(response) 

3378 

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

3380 resp = policy_pb2.Policy() 

3381 resp = json_format.Parse(content, resp) 

3382 resp = self._interceptor.post_set_iam_policy(resp) 

3383 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3384 logging.DEBUG 

3385 ): # pragma: NO COVER 

3386 try: 

3387 response_payload = json_format.MessageToJson(resp) 

3388 except: 

3389 response_payload = None 

3390 http_response = { 

3391 "payload": response_payload, 

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

3393 "status": response.status_code, 

3394 } 

3395 _LOGGER.debug( 

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

3397 extra={ 

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

3399 "rpcName": "SetIamPolicy", 

3400 "httpResponse": http_response, 

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

3402 }, 

3403 ) 

3404 return resp 

3405 

3406 @property 

3407 def test_iam_permissions(self): 

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

3409 

3410 class _TestIamPermissions( 

3411 _BaseSubscriberRestTransport._BaseTestIamPermissions, SubscriberRestStub 

3412 ): 

3413 def __hash__(self): 

3414 return hash("SubscriberRestTransport.TestIamPermissions") 

3415 

3416 @staticmethod 

3417 def _get_response( 

3418 host, 

3419 metadata, 

3420 query_params, 

3421 session, 

3422 timeout, 

3423 transcoded_request, 

3424 body=None, 

3425 ): 

3426 uri = transcoded_request["uri"] 

3427 method = transcoded_request["method"] 

3428 headers = dict(metadata) 

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

3430 response = getattr(session, method)( 

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

3432 timeout=timeout, 

3433 headers=headers, 

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

3435 data=body, 

3436 ) 

3437 return response 

3438 

3439 def __call__( 

3440 self, 

3441 request: iam_policy_pb2.TestIamPermissionsRequest, 

3442 *, 

3443 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3444 timeout: Optional[float] = None, 

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

3446 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

3448 

3449 Args: 

3450 request (iam_policy_pb2.TestIamPermissionsRequest): 

3451 The request object for TestIamPermissions method. 

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

3453 should be retried. 

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

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

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

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

3458 be of type `bytes`. 

3459 

3460 Returns: 

3461 iam_policy_pb2.TestIamPermissionsResponse: Response from TestIamPermissions method. 

3462 """ 

3463 

3464 http_options = ( 

3465 _BaseSubscriberRestTransport._BaseTestIamPermissions._get_http_options() 

3466 ) 

3467 

3468 request, metadata = self._interceptor.pre_test_iam_permissions( 

3469 request, metadata 

3470 ) 

3471 transcoded_request = _BaseSubscriberRestTransport._BaseTestIamPermissions._get_transcoded_request( 

3472 http_options, request 

3473 ) 

3474 

3475 body = _BaseSubscriberRestTransport._BaseTestIamPermissions._get_request_body_json( 

3476 transcoded_request 

3477 ) 

3478 

3479 # Jsonify the query params 

3480 query_params = _BaseSubscriberRestTransport._BaseTestIamPermissions._get_query_params_json( 

3481 transcoded_request 

3482 ) 

3483 

3484 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3485 logging.DEBUG 

3486 ): # pragma: NO COVER 

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

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

3489 ) 

3490 method = transcoded_request["method"] 

3491 try: 

3492 request_payload = json_format.MessageToJson(request) 

3493 except: 

3494 request_payload = None 

3495 http_request = { 

3496 "payload": request_payload, 

3497 "requestMethod": method, 

3498 "requestUrl": request_url, 

3499 "headers": dict(metadata), 

3500 } 

3501 _LOGGER.debug( 

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

3503 extra={ 

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

3505 "rpcName": "TestIamPermissions", 

3506 "httpRequest": http_request, 

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

3508 }, 

3509 ) 

3510 

3511 # Send the request 

3512 response = SubscriberRestTransport._TestIamPermissions._get_response( 

3513 self._host, 

3514 metadata, 

3515 query_params, 

3516 self._session, 

3517 timeout, 

3518 transcoded_request, 

3519 body, 

3520 ) 

3521 

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

3523 # subclass. 

3524 if response.status_code >= 400: 

3525 raise core_exceptions.from_http_response(response) 

3526 

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

3528 resp = iam_policy_pb2.TestIamPermissionsResponse() 

3529 resp = json_format.Parse(content, resp) 

3530 resp = self._interceptor.post_test_iam_permissions(resp) 

3531 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3532 logging.DEBUG 

3533 ): # pragma: NO COVER 

3534 try: 

3535 response_payload = json_format.MessageToJson(resp) 

3536 except: 

3537 response_payload = None 

3538 http_response = { 

3539 "payload": response_payload, 

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

3541 "status": response.status_code, 

3542 } 

3543 _LOGGER.debug( 

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

3545 extra={ 

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

3547 "rpcName": "TestIamPermissions", 

3548 "httpResponse": http_response, 

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

3550 }, 

3551 ) 

3552 return resp 

3553 

3554 @property 

3555 def kind(self) -> str: 

3556 return "rest" 

3557 

3558 def close(self): 

3559 self._session.close() 

3560 

3561 

3562__all__ = ("SubscriberRestTransport",)