Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.10/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

628 statements  

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

2# Copyright 2024 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 

26 

27from google.protobuf import json_format 

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

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

30 

31from requests import __version__ as requests_version 

32import dataclasses 

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

34import warnings 

35 

36 

37from google.protobuf import empty_pb2 # type: ignore 

38from google.pubsub_v1.types import pubsub 

39 

40 

41from .rest_base import _BaseSubscriberRestTransport 

42from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO 

43 

44try: 

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

46except AttributeError: # pragma: NO COVER 

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

48 

49try: 

50 from google.api_core import client_logging # type: ignore 

51 

52 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

53except ImportError: # pragma: NO COVER 

54 CLIENT_LOGGING_SUPPORTED = False 

55 

56_LOGGER = logging.getLogger(__name__) 

57 

58DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

59 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, 

60 grpc_version=None, 

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

62) 

63 

64 

65class SubscriberRestInterceptor: 

66 """Interceptor for Subscriber. 

67 

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

69 in arbitrary ways. 

70 Example use cases include: 

71 * Logging 

72 * Verifying requests according to service or custom semantics 

73 * Stripping extraneous information from responses 

74 

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

76 instance of a custom subclass when constructing the SubscriberRestTransport. 

77 

78 .. code-block:: python 

79 class MyCustomSubscriberInterceptor(SubscriberRestInterceptor): 

80 def pre_acknowledge(self, request, metadata): 

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

82 return request, metadata 

83 

84 def pre_create_snapshot(self, request, metadata): 

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

86 return request, metadata 

87 

88 def post_create_snapshot(self, response): 

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

90 return response 

91 

92 def pre_create_subscription(self, request, metadata): 

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

94 return request, metadata 

95 

96 def post_create_subscription(self, response): 

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

98 return response 

99 

100 def pre_delete_snapshot(self, request, metadata): 

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

102 return request, metadata 

103 

104 def pre_delete_subscription(self, request, metadata): 

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

106 return request, metadata 

107 

108 def pre_get_snapshot(self, request, metadata): 

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

110 return request, metadata 

111 

112 def post_get_snapshot(self, response): 

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

114 return response 

115 

116 def pre_get_subscription(self, request, metadata): 

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

118 return request, metadata 

119 

120 def post_get_subscription(self, response): 

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

122 return response 

123 

124 def pre_list_snapshots(self, request, metadata): 

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

126 return request, metadata 

127 

128 def post_list_snapshots(self, response): 

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

130 return response 

131 

132 def pre_list_subscriptions(self, request, metadata): 

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

134 return request, metadata 

135 

136 def post_list_subscriptions(self, response): 

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

138 return response 

139 

140 def pre_modify_ack_deadline(self, request, metadata): 

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

142 return request, metadata 

143 

144 def pre_modify_push_config(self, request, metadata): 

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

146 return request, metadata 

147 

148 def pre_pull(self, request, metadata): 

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

150 return request, metadata 

151 

152 def post_pull(self, response): 

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

154 return response 

155 

156 def pre_seek(self, request, metadata): 

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

158 return request, metadata 

159 

160 def post_seek(self, response): 

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

162 return response 

163 

164 def pre_update_snapshot(self, request, metadata): 

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

166 return request, metadata 

167 

168 def post_update_snapshot(self, response): 

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

170 return response 

171 

172 def pre_update_subscription(self, request, metadata): 

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

174 return request, metadata 

175 

176 def post_update_subscription(self, response): 

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

178 return response 

179 

180 transport = SubscriberRestTransport(interceptor=MyCustomSubscriberInterceptor()) 

181 client = SubscriberClient(transport=transport) 

182 

183 

184 """ 

185 

186 def pre_acknowledge( 

187 self, 

188 request: pubsub.AcknowledgeRequest, 

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

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

191 """Pre-rpc interceptor for acknowledge 

192 

193 Override in a subclass to manipulate the request or metadata 

194 before they are sent to the Subscriber server. 

195 """ 

196 return request, metadata 

197 

198 def pre_create_snapshot( 

199 self, 

200 request: pubsub.CreateSnapshotRequest, 

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

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

203 """Pre-rpc interceptor for create_snapshot 

204 

205 Override in a subclass to manipulate the request or metadata 

206 before they are sent to the Subscriber server. 

207 """ 

208 return request, metadata 

209 

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

211 """Post-rpc interceptor for create_snapshot 

212 

213 DEPRECATED. Please use the `post_create_snapshot_with_metadata` 

214 interceptor instead. 

215 

216 Override in a subclass to read or manipulate the response 

217 after it is returned by the Subscriber server but before 

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

219 before the `post_create_snapshot_with_metadata` interceptor. 

220 """ 

221 return response 

222 

223 def post_create_snapshot_with_metadata( 

224 self, 

225 response: pubsub.Snapshot, 

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

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

228 """Post-rpc interceptor for create_snapshot 

229 

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

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

232 

233 We recommend only using this `post_create_snapshot_with_metadata` 

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

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

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

237 `post_create_snapshot` will be passed to 

238 `post_create_snapshot_with_metadata`. 

239 """ 

240 return response, metadata 

241 

242 def pre_create_subscription( 

243 self, 

244 request: pubsub.Subscription, 

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

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

247 """Pre-rpc interceptor for create_subscription 

248 

249 Override in a subclass to manipulate the request or metadata 

250 before they are sent to the Subscriber server. 

251 """ 

252 return request, metadata 

253 

254 def post_create_subscription( 

255 self, response: pubsub.Subscription 

256 ) -> pubsub.Subscription: 

257 """Post-rpc interceptor for create_subscription 

258 

259 DEPRECATED. Please use the `post_create_subscription_with_metadata` 

260 interceptor instead. 

261 

262 Override in a subclass to read or manipulate the response 

263 after it is returned by the Subscriber server but before 

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

265 before the `post_create_subscription_with_metadata` interceptor. 

266 """ 

267 return response 

268 

269 def post_create_subscription_with_metadata( 

270 self, 

271 response: pubsub.Subscription, 

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

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

274 """Post-rpc interceptor for create_subscription 

275 

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

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

278 

279 We recommend only using this `post_create_subscription_with_metadata` 

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

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

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

283 `post_create_subscription` will be passed to 

284 `post_create_subscription_with_metadata`. 

285 """ 

286 return response, metadata 

287 

288 def pre_delete_snapshot( 

289 self, 

290 request: pubsub.DeleteSnapshotRequest, 

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

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

293 """Pre-rpc interceptor for delete_snapshot 

294 

295 Override in a subclass to manipulate the request or metadata 

296 before they are sent to the Subscriber server. 

297 """ 

298 return request, metadata 

299 

300 def pre_delete_subscription( 

301 self, 

302 request: pubsub.DeleteSubscriptionRequest, 

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

304 ) -> Tuple[ 

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

306 ]: 

307 """Pre-rpc interceptor for delete_subscription 

308 

309 Override in a subclass to manipulate the request or metadata 

310 before they are sent to the Subscriber server. 

311 """ 

312 return request, metadata 

313 

314 def pre_get_snapshot( 

315 self, 

316 request: pubsub.GetSnapshotRequest, 

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

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

319 """Pre-rpc interceptor for get_snapshot 

320 

321 Override in a subclass to manipulate the request or metadata 

322 before they are sent to the Subscriber server. 

323 """ 

324 return request, metadata 

325 

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

327 """Post-rpc interceptor for get_snapshot 

328 

329 DEPRECATED. Please use the `post_get_snapshot_with_metadata` 

330 interceptor instead. 

331 

332 Override in a subclass to read or manipulate the response 

333 after it is returned by the Subscriber server but before 

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

335 before the `post_get_snapshot_with_metadata` interceptor. 

336 """ 

337 return response 

338 

339 def post_get_snapshot_with_metadata( 

340 self, 

341 response: pubsub.Snapshot, 

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

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

344 """Post-rpc interceptor for get_snapshot 

345 

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

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

348 

349 We recommend only using this `post_get_snapshot_with_metadata` 

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

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

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

353 `post_get_snapshot` will be passed to 

354 `post_get_snapshot_with_metadata`. 

355 """ 

356 return response, metadata 

357 

358 def pre_get_subscription( 

359 self, 

360 request: pubsub.GetSubscriptionRequest, 

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

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

363 """Pre-rpc interceptor for get_subscription 

364 

365 Override in a subclass to manipulate the request or metadata 

366 before they are sent to the Subscriber server. 

367 """ 

368 return request, metadata 

369 

370 def post_get_subscription( 

371 self, response: pubsub.Subscription 

372 ) -> pubsub.Subscription: 

373 """Post-rpc interceptor for get_subscription 

374 

375 DEPRECATED. Please use the `post_get_subscription_with_metadata` 

376 interceptor instead. 

377 

378 Override in a subclass to read or manipulate the response 

379 after it is returned by the Subscriber server but before 

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

381 before the `post_get_subscription_with_metadata` interceptor. 

382 """ 

383 return response 

384 

385 def post_get_subscription_with_metadata( 

386 self, 

387 response: pubsub.Subscription, 

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

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

390 """Post-rpc interceptor for get_subscription 

391 

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

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

394 

395 We recommend only using this `post_get_subscription_with_metadata` 

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

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

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

399 `post_get_subscription` will be passed to 

400 `post_get_subscription_with_metadata`. 

401 """ 

402 return response, metadata 

403 

404 def pre_list_snapshots( 

405 self, 

406 request: pubsub.ListSnapshotsRequest, 

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

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

409 """Pre-rpc interceptor for list_snapshots 

410 

411 Override in a subclass to manipulate the request or metadata 

412 before they are sent to the Subscriber server. 

413 """ 

414 return request, metadata 

415 

416 def post_list_snapshots( 

417 self, response: pubsub.ListSnapshotsResponse 

418 ) -> pubsub.ListSnapshotsResponse: 

419 """Post-rpc interceptor for list_snapshots 

420 

421 DEPRECATED. Please use the `post_list_snapshots_with_metadata` 

422 interceptor instead. 

423 

424 Override in a subclass to read or manipulate the response 

425 after it is returned by the Subscriber server but before 

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

427 before the `post_list_snapshots_with_metadata` interceptor. 

428 """ 

429 return response 

430 

431 def post_list_snapshots_with_metadata( 

432 self, 

433 response: pubsub.ListSnapshotsResponse, 

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

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

436 """Post-rpc interceptor for list_snapshots 

437 

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

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

440 

441 We recommend only using this `post_list_snapshots_with_metadata` 

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

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

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

445 `post_list_snapshots` will be passed to 

446 `post_list_snapshots_with_metadata`. 

447 """ 

448 return response, metadata 

449 

450 def pre_list_subscriptions( 

451 self, 

452 request: pubsub.ListSubscriptionsRequest, 

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

454 ) -> Tuple[ 

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

456 ]: 

457 """Pre-rpc interceptor for list_subscriptions 

458 

459 Override in a subclass to manipulate the request or metadata 

460 before they are sent to the Subscriber server. 

461 """ 

462 return request, metadata 

463 

464 def post_list_subscriptions( 

465 self, response: pubsub.ListSubscriptionsResponse 

466 ) -> pubsub.ListSubscriptionsResponse: 

467 """Post-rpc interceptor for list_subscriptions 

468 

469 DEPRECATED. Please use the `post_list_subscriptions_with_metadata` 

470 interceptor instead. 

471 

472 Override in a subclass to read or manipulate the response 

473 after it is returned by the Subscriber server but before 

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

475 before the `post_list_subscriptions_with_metadata` interceptor. 

476 """ 

477 return response 

478 

479 def post_list_subscriptions_with_metadata( 

480 self, 

481 response: pubsub.ListSubscriptionsResponse, 

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

483 ) -> Tuple[ 

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

485 ]: 

486 """Post-rpc interceptor for list_subscriptions 

487 

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

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

490 

491 We recommend only using this `post_list_subscriptions_with_metadata` 

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

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

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

495 `post_list_subscriptions` will be passed to 

496 `post_list_subscriptions_with_metadata`. 

497 """ 

498 return response, metadata 

499 

500 def pre_modify_ack_deadline( 

501 self, 

502 request: pubsub.ModifyAckDeadlineRequest, 

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

504 ) -> Tuple[ 

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

506 ]: 

507 """Pre-rpc interceptor for modify_ack_deadline 

508 

509 Override in a subclass to manipulate the request or metadata 

510 before they are sent to the Subscriber server. 

511 """ 

512 return request, metadata 

513 

514 def pre_modify_push_config( 

515 self, 

516 request: pubsub.ModifyPushConfigRequest, 

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

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

519 """Pre-rpc interceptor for modify_push_config 

520 

521 Override in a subclass to manipulate the request or metadata 

522 before they are sent to the Subscriber server. 

523 """ 

524 return request, metadata 

525 

526 def pre_pull( 

527 self, 

528 request: pubsub.PullRequest, 

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

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

531 """Pre-rpc interceptor for pull 

532 

533 Override in a subclass to manipulate the request or metadata 

534 before they are sent to the Subscriber server. 

535 """ 

536 return request, metadata 

537 

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

539 """Post-rpc interceptor for pull 

540 

541 DEPRECATED. Please use the `post_pull_with_metadata` 

542 interceptor instead. 

543 

544 Override in a subclass to read or manipulate the response 

545 after it is returned by the Subscriber server but before 

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

547 before the `post_pull_with_metadata` interceptor. 

548 """ 

549 return response 

550 

551 def post_pull_with_metadata( 

552 self, 

553 response: pubsub.PullResponse, 

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

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

556 """Post-rpc interceptor for pull 

557 

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

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

560 

561 We recommend only using this `post_pull_with_metadata` 

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

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

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

565 `post_pull` will be passed to 

566 `post_pull_with_metadata`. 

567 """ 

568 return response, metadata 

569 

570 def pre_seek( 

571 self, 

572 request: pubsub.SeekRequest, 

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

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

575 """Pre-rpc interceptor for seek 

576 

577 Override in a subclass to manipulate the request or metadata 

578 before they are sent to the Subscriber server. 

579 """ 

580 return request, metadata 

581 

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

583 """Post-rpc interceptor for seek 

584 

585 DEPRECATED. Please use the `post_seek_with_metadata` 

586 interceptor instead. 

587 

588 Override in a subclass to read or manipulate the response 

589 after it is returned by the Subscriber server but before 

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

591 before the `post_seek_with_metadata` interceptor. 

592 """ 

593 return response 

594 

595 def post_seek_with_metadata( 

596 self, 

597 response: pubsub.SeekResponse, 

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

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

600 """Post-rpc interceptor for seek 

601 

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

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

604 

605 We recommend only using this `post_seek_with_metadata` 

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

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

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

609 `post_seek` will be passed to 

610 `post_seek_with_metadata`. 

611 """ 

612 return response, metadata 

613 

614 def pre_update_snapshot( 

615 self, 

616 request: pubsub.UpdateSnapshotRequest, 

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

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

619 """Pre-rpc interceptor for update_snapshot 

620 

621 Override in a subclass to manipulate the request or metadata 

622 before they are sent to the Subscriber server. 

623 """ 

624 return request, metadata 

625 

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

627 """Post-rpc interceptor for update_snapshot 

628 

629 DEPRECATED. Please use the `post_update_snapshot_with_metadata` 

630 interceptor instead. 

631 

632 Override in a subclass to read or manipulate the response 

633 after it is returned by the Subscriber server but before 

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

635 before the `post_update_snapshot_with_metadata` interceptor. 

636 """ 

637 return response 

638 

639 def post_update_snapshot_with_metadata( 

640 self, 

641 response: pubsub.Snapshot, 

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

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

644 """Post-rpc interceptor for update_snapshot 

645 

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

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

648 

649 We recommend only using this `post_update_snapshot_with_metadata` 

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

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

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

653 `post_update_snapshot` will be passed to 

654 `post_update_snapshot_with_metadata`. 

655 """ 

656 return response, metadata 

657 

658 def pre_update_subscription( 

659 self, 

660 request: pubsub.UpdateSubscriptionRequest, 

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

662 ) -> Tuple[ 

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

664 ]: 

665 """Pre-rpc interceptor for update_subscription 

666 

667 Override in a subclass to manipulate the request or metadata 

668 before they are sent to the Subscriber server. 

669 """ 

670 return request, metadata 

671 

672 def post_update_subscription( 

673 self, response: pubsub.Subscription 

674 ) -> pubsub.Subscription: 

675 """Post-rpc interceptor for update_subscription 

676 

677 DEPRECATED. Please use the `post_update_subscription_with_metadata` 

678 interceptor instead. 

679 

680 Override in a subclass to read or manipulate the response 

681 after it is returned by the Subscriber server but before 

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

683 before the `post_update_subscription_with_metadata` interceptor. 

684 """ 

685 return response 

686 

687 def post_update_subscription_with_metadata( 

688 self, 

689 response: pubsub.Subscription, 

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

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

692 """Post-rpc interceptor for update_subscription 

693 

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

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

696 

697 We recommend only using this `post_update_subscription_with_metadata` 

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

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

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

701 `post_update_subscription` will be passed to 

702 `post_update_subscription_with_metadata`. 

703 """ 

704 return response, metadata 

705 

706 def pre_get_iam_policy( 

707 self, 

708 request: iam_policy_pb2.GetIamPolicyRequest, 

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

710 ) -> Tuple[ 

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

712 ]: 

713 """Pre-rpc interceptor for get_iam_policy 

714 

715 Override in a subclass to manipulate the request or metadata 

716 before they are sent to the Subscriber server. 

717 """ 

718 return request, metadata 

719 

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

721 """Post-rpc interceptor for get_iam_policy 

722 

723 Override in a subclass to manipulate the response 

724 after it is returned by the Subscriber server but before 

725 it is returned to user code. 

726 """ 

727 return response 

728 

729 def pre_set_iam_policy( 

730 self, 

731 request: iam_policy_pb2.SetIamPolicyRequest, 

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

733 ) -> Tuple[ 

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

735 ]: 

736 """Pre-rpc interceptor for set_iam_policy 

737 

738 Override in a subclass to manipulate the request or metadata 

739 before they are sent to the Subscriber server. 

740 """ 

741 return request, metadata 

742 

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

744 """Post-rpc interceptor for set_iam_policy 

745 

746 Override in a subclass to manipulate the response 

747 after it is returned by the Subscriber server but before 

748 it is returned to user code. 

749 """ 

750 return response 

751 

752 def pre_test_iam_permissions( 

753 self, 

754 request: iam_policy_pb2.TestIamPermissionsRequest, 

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

756 ) -> Tuple[ 

757 iam_policy_pb2.TestIamPermissionsRequest, 

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

759 ]: 

760 """Pre-rpc interceptor for test_iam_permissions 

761 

762 Override in a subclass to manipulate the request or metadata 

763 before they are sent to the Subscriber server. 

764 """ 

765 return request, metadata 

766 

767 def post_test_iam_permissions( 

768 self, response: iam_policy_pb2.TestIamPermissionsResponse 

769 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

770 """Post-rpc interceptor for test_iam_permissions 

771 

772 Override in a subclass to manipulate the response 

773 after it is returned by the Subscriber server but before 

774 it is returned to user code. 

775 """ 

776 return response 

777 

778 

779@dataclasses.dataclass 

780class SubscriberRestStub: 

781 _session: AuthorizedSession 

782 _host: str 

783 _interceptor: SubscriberRestInterceptor 

784 

785 

786class SubscriberRestTransport(_BaseSubscriberRestTransport): 

787 """REST backend synchronous transport for Subscriber. 

788 

789 The service that an application uses to manipulate subscriptions and 

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

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

792 method. 

793 

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

795 primary client can load the underlying transport implementation 

796 and call it. 

797 

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

799 """ 

800 

801 def __init__( 

802 self, 

803 *, 

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

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

806 credentials_file: Optional[str] = None, 

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

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

809 quota_project_id: Optional[str] = None, 

810 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

811 always_use_jwt_access: Optional[bool] = False, 

812 url_scheme: str = "https", 

813 interceptor: Optional[SubscriberRestInterceptor] = None, 

814 api_audience: Optional[str] = None, 

815 ) -> None: 

816 """Instantiate the transport. 

817 

818 Args: 

819 host (Optional[str]): 

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

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

822 authorization credentials to attach to requests. These 

823 credentials identify the application to the service; if none 

824 are specified, the client will attempt to ascertain the 

825 credentials from the environment. 

826 

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

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

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

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

831 ignored if ``channel`` is provided. 

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

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

834 if ``channel`` is provided. 

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

836 and quota. 

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

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

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

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

841 your own client library. 

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

843 be used for service account credentials. 

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

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

846 "http" can be specified. 

847 """ 

848 # Run the base constructor 

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

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

851 # credentials object 

852 super().__init__( 

853 host=host, 

854 credentials=credentials, 

855 client_info=client_info, 

856 always_use_jwt_access=always_use_jwt_access, 

857 url_scheme=url_scheme, 

858 api_audience=api_audience, 

859 ) 

860 self._session = AuthorizedSession( 

861 self._credentials, default_host=self.DEFAULT_HOST 

862 ) 

863 if client_cert_source_for_mtls: 

864 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

865 self._interceptor = interceptor or SubscriberRestInterceptor() 

866 self._prep_wrapped_messages(client_info) 

867 

868 class _Acknowledge( 

869 _BaseSubscriberRestTransport._BaseAcknowledge, SubscriberRestStub 

870 ): 

871 def __hash__(self): 

872 return hash("SubscriberRestTransport.Acknowledge") 

873 

874 @staticmethod 

875 def _get_response( 

876 host, 

877 metadata, 

878 query_params, 

879 session, 

880 timeout, 

881 transcoded_request, 

882 body=None, 

883 ): 

884 uri = transcoded_request["uri"] 

885 method = transcoded_request["method"] 

886 headers = dict(metadata) 

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

888 response = getattr(session, method)( 

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

890 timeout=timeout, 

891 headers=headers, 

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

893 data=body, 

894 ) 

895 return response 

896 

897 def __call__( 

898 self, 

899 request: pubsub.AcknowledgeRequest, 

900 *, 

901 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

902 timeout: Optional[float] = None, 

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

904 ): 

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

906 

907 Args: 

908 request (~.pubsub.AcknowledgeRequest): 

909 The request object. Request for the Acknowledge method. 

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

911 should be retried. 

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

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

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

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

916 be of type `bytes`. 

917 """ 

918 

919 http_options = ( 

920 _BaseSubscriberRestTransport._BaseAcknowledge._get_http_options() 

921 ) 

922 

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

924 transcoded_request = ( 

925 _BaseSubscriberRestTransport._BaseAcknowledge._get_transcoded_request( 

926 http_options, request 

927 ) 

928 ) 

929 

930 body = _BaseSubscriberRestTransport._BaseAcknowledge._get_request_body_json( 

931 transcoded_request 

932 ) 

933 

934 # Jsonify the query params 

935 query_params = ( 

936 _BaseSubscriberRestTransport._BaseAcknowledge._get_query_params_json( 

937 transcoded_request 

938 ) 

939 ) 

940 

941 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

942 logging.DEBUG 

943 ): # pragma: NO COVER 

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

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

946 ) 

947 method = transcoded_request["method"] 

948 try: 

949 request_payload = json_format.MessageToJson(request) 

950 except: 

951 request_payload = None 

952 http_request = { 

953 "payload": request_payload, 

954 "requestMethod": method, 

955 "requestUrl": request_url, 

956 "headers": dict(metadata), 

957 } 

958 _LOGGER.debug( 

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

960 extra={ 

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

962 "rpcName": "Acknowledge", 

963 "httpRequest": http_request, 

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

965 }, 

966 ) 

967 

968 # Send the request 

969 response = SubscriberRestTransport._Acknowledge._get_response( 

970 self._host, 

971 metadata, 

972 query_params, 

973 self._session, 

974 timeout, 

975 transcoded_request, 

976 body, 

977 ) 

978 

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

980 # subclass. 

981 if response.status_code >= 400: 

982 raise core_exceptions.from_http_response(response) 

983 

984 class _CreateSnapshot( 

985 _BaseSubscriberRestTransport._BaseCreateSnapshot, SubscriberRestStub 

986 ): 

987 def __hash__(self): 

988 return hash("SubscriberRestTransport.CreateSnapshot") 

989 

990 @staticmethod 

991 def _get_response( 

992 host, 

993 metadata, 

994 query_params, 

995 session, 

996 timeout, 

997 transcoded_request, 

998 body=None, 

999 ): 

1000 uri = transcoded_request["uri"] 

1001 method = transcoded_request["method"] 

1002 headers = dict(metadata) 

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

1004 response = getattr(session, method)( 

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

1006 timeout=timeout, 

1007 headers=headers, 

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

1009 data=body, 

1010 ) 

1011 return response 

1012 

1013 def __call__( 

1014 self, 

1015 request: pubsub.CreateSnapshotRequest, 

1016 *, 

1017 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1018 timeout: Optional[float] = None, 

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

1020 ) -> pubsub.Snapshot: 

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

1022 

1023 Args: 

1024 request (~.pubsub.CreateSnapshotRequest): 

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

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

1027 should be retried. 

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

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

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

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

1032 be of type `bytes`. 

1033 

1034 Returns: 

1035 ~.pubsub.Snapshot: 

1036 A snapshot resource. Snapshots are used in 

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

1038 operations, which allow you to manage message 

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

1040 acknowledgment state of messages in an existing 

1041 subscription to the state captured by a snapshot. 

1042 

1043 """ 

1044 

1045 http_options = ( 

1046 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_http_options() 

1047 ) 

1048 

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

1050 transcoded_request = _BaseSubscriberRestTransport._BaseCreateSnapshot._get_transcoded_request( 

1051 http_options, request 

1052 ) 

1053 

1054 body = ( 

1055 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_request_body_json( 

1056 transcoded_request 

1057 ) 

1058 ) 

1059 

1060 # Jsonify the query params 

1061 query_params = ( 

1062 _BaseSubscriberRestTransport._BaseCreateSnapshot._get_query_params_json( 

1063 transcoded_request 

1064 ) 

1065 ) 

1066 

1067 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1068 logging.DEBUG 

1069 ): # pragma: NO COVER 

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

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

1072 ) 

1073 method = transcoded_request["method"] 

1074 try: 

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

1076 except: 

1077 request_payload = None 

1078 http_request = { 

1079 "payload": request_payload, 

1080 "requestMethod": method, 

1081 "requestUrl": request_url, 

1082 "headers": dict(metadata), 

1083 } 

1084 _LOGGER.debug( 

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

1086 extra={ 

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

1088 "rpcName": "CreateSnapshot", 

1089 "httpRequest": http_request, 

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

1091 }, 

1092 ) 

1093 

1094 # Send the request 

1095 response = SubscriberRestTransport._CreateSnapshot._get_response( 

1096 self._host, 

1097 metadata, 

1098 query_params, 

1099 self._session, 

1100 timeout, 

1101 transcoded_request, 

1102 body, 

1103 ) 

1104 

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

1106 # subclass. 

1107 if response.status_code >= 400: 

1108 raise core_exceptions.from_http_response(response) 

1109 

1110 # Return the response 

1111 resp = pubsub.Snapshot() 

1112 pb_resp = pubsub.Snapshot.pb(resp) 

1113 

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

1115 

1116 resp = self._interceptor.post_create_snapshot(resp) 

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

1118 resp, _ = self._interceptor.post_create_snapshot_with_metadata( 

1119 resp, response_metadata 

1120 ) 

1121 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1122 logging.DEBUG 

1123 ): # pragma: NO COVER 

1124 try: 

1125 response_payload = pubsub.Snapshot.to_json(response) 

1126 except: 

1127 response_payload = None 

1128 http_response = { 

1129 "payload": response_payload, 

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

1131 "status": response.status_code, 

1132 } 

1133 _LOGGER.debug( 

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

1135 extra={ 

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

1137 "rpcName": "CreateSnapshot", 

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

1139 "httpResponse": http_response, 

1140 }, 

1141 ) 

1142 return resp 

1143 

1144 class _CreateSubscription( 

1145 _BaseSubscriberRestTransport._BaseCreateSubscription, SubscriberRestStub 

1146 ): 

1147 def __hash__(self): 

1148 return hash("SubscriberRestTransport.CreateSubscription") 

1149 

1150 @staticmethod 

1151 def _get_response( 

1152 host, 

1153 metadata, 

1154 query_params, 

1155 session, 

1156 timeout, 

1157 transcoded_request, 

1158 body=None, 

1159 ): 

1160 uri = transcoded_request["uri"] 

1161 method = transcoded_request["method"] 

1162 headers = dict(metadata) 

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

1164 response = getattr(session, method)( 

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

1166 timeout=timeout, 

1167 headers=headers, 

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

1169 data=body, 

1170 ) 

1171 return response 

1172 

1173 def __call__( 

1174 self, 

1175 request: pubsub.Subscription, 

1176 *, 

1177 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1178 timeout: Optional[float] = None, 

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

1180 ) -> pubsub.Subscription: 

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

1182 

1183 Args: 

1184 request (~.pubsub.Subscription): 

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

1186 ``bigquery_config``, or ``cloud_storage_config`` is set, 

1187 then the subscriber will pull and ack messages using API 

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

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

1190 should be retried. 

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

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

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

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

1195 be of type `bytes`. 

1196 

1197 Returns: 

1198 ~.pubsub.Subscription: 

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

1200 ``bigquery_config``, or ``cloud_storage_config`` is set, 

1201 then the subscriber will pull and ack messages using API 

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

1203 

1204 """ 

1205 

1206 http_options = ( 

1207 _BaseSubscriberRestTransport._BaseCreateSubscription._get_http_options() 

1208 ) 

1209 

1210 request, metadata = self._interceptor.pre_create_subscription( 

1211 request, metadata 

1212 ) 

1213 transcoded_request = _BaseSubscriberRestTransport._BaseCreateSubscription._get_transcoded_request( 

1214 http_options, request 

1215 ) 

1216 

1217 body = _BaseSubscriberRestTransport._BaseCreateSubscription._get_request_body_json( 

1218 transcoded_request 

1219 ) 

1220 

1221 # Jsonify the query params 

1222 query_params = _BaseSubscriberRestTransport._BaseCreateSubscription._get_query_params_json( 

1223 transcoded_request 

1224 ) 

1225 

1226 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1227 logging.DEBUG 

1228 ): # pragma: NO COVER 

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

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

1231 ) 

1232 method = transcoded_request["method"] 

1233 try: 

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

1235 except: 

1236 request_payload = None 

1237 http_request = { 

1238 "payload": request_payload, 

1239 "requestMethod": method, 

1240 "requestUrl": request_url, 

1241 "headers": dict(metadata), 

1242 } 

1243 _LOGGER.debug( 

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

1245 extra={ 

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

1247 "rpcName": "CreateSubscription", 

1248 "httpRequest": http_request, 

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

1250 }, 

1251 ) 

1252 

1253 # Send the request 

1254 response = SubscriberRestTransport._CreateSubscription._get_response( 

1255 self._host, 

1256 metadata, 

1257 query_params, 

1258 self._session, 

1259 timeout, 

1260 transcoded_request, 

1261 body, 

1262 ) 

1263 

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

1265 # subclass. 

1266 if response.status_code >= 400: 

1267 raise core_exceptions.from_http_response(response) 

1268 

1269 # Return the response 

1270 resp = pubsub.Subscription() 

1271 pb_resp = pubsub.Subscription.pb(resp) 

1272 

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

1274 

1275 resp = self._interceptor.post_create_subscription(resp) 

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

1277 resp, _ = self._interceptor.post_create_subscription_with_metadata( 

1278 resp, response_metadata 

1279 ) 

1280 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1281 logging.DEBUG 

1282 ): # pragma: NO COVER 

1283 try: 

1284 response_payload = pubsub.Subscription.to_json(response) 

1285 except: 

1286 response_payload = None 

1287 http_response = { 

1288 "payload": response_payload, 

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

1290 "status": response.status_code, 

1291 } 

1292 _LOGGER.debug( 

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

1294 extra={ 

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

1296 "rpcName": "CreateSubscription", 

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

1298 "httpResponse": http_response, 

1299 }, 

1300 ) 

1301 return resp 

1302 

1303 class _DeleteSnapshot( 

1304 _BaseSubscriberRestTransport._BaseDeleteSnapshot, SubscriberRestStub 

1305 ): 

1306 def __hash__(self): 

1307 return hash("SubscriberRestTransport.DeleteSnapshot") 

1308 

1309 @staticmethod 

1310 def _get_response( 

1311 host, 

1312 metadata, 

1313 query_params, 

1314 session, 

1315 timeout, 

1316 transcoded_request, 

1317 body=None, 

1318 ): 

1319 uri = transcoded_request["uri"] 

1320 method = transcoded_request["method"] 

1321 headers = dict(metadata) 

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

1323 response = getattr(session, method)( 

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

1325 timeout=timeout, 

1326 headers=headers, 

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

1328 ) 

1329 return response 

1330 

1331 def __call__( 

1332 self, 

1333 request: pubsub.DeleteSnapshotRequest, 

1334 *, 

1335 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1336 timeout: Optional[float] = None, 

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

1338 ): 

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

1340 

1341 Args: 

1342 request (~.pubsub.DeleteSnapshotRequest): 

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

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

1345 should be retried. 

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

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

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

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

1350 be of type `bytes`. 

1351 """ 

1352 

1353 http_options = ( 

1354 _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_http_options() 

1355 ) 

1356 

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

1358 transcoded_request = _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_transcoded_request( 

1359 http_options, request 

1360 ) 

1361 

1362 # Jsonify the query params 

1363 query_params = ( 

1364 _BaseSubscriberRestTransport._BaseDeleteSnapshot._get_query_params_json( 

1365 transcoded_request 

1366 ) 

1367 ) 

1368 

1369 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1370 logging.DEBUG 

1371 ): # pragma: NO COVER 

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

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

1374 ) 

1375 method = transcoded_request["method"] 

1376 try: 

1377 request_payload = json_format.MessageToJson(request) 

1378 except: 

1379 request_payload = None 

1380 http_request = { 

1381 "payload": request_payload, 

1382 "requestMethod": method, 

1383 "requestUrl": request_url, 

1384 "headers": dict(metadata), 

1385 } 

1386 _LOGGER.debug( 

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

1388 extra={ 

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

1390 "rpcName": "DeleteSnapshot", 

1391 "httpRequest": http_request, 

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

1393 }, 

1394 ) 

1395 

1396 # Send the request 

1397 response = SubscriberRestTransport._DeleteSnapshot._get_response( 

1398 self._host, 

1399 metadata, 

1400 query_params, 

1401 self._session, 

1402 timeout, 

1403 transcoded_request, 

1404 ) 

1405 

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

1407 # subclass. 

1408 if response.status_code >= 400: 

1409 raise core_exceptions.from_http_response(response) 

1410 

1411 class _DeleteSubscription( 

1412 _BaseSubscriberRestTransport._BaseDeleteSubscription, SubscriberRestStub 

1413 ): 

1414 def __hash__(self): 

1415 return hash("SubscriberRestTransport.DeleteSubscription") 

1416 

1417 @staticmethod 

1418 def _get_response( 

1419 host, 

1420 metadata, 

1421 query_params, 

1422 session, 

1423 timeout, 

1424 transcoded_request, 

1425 body=None, 

1426 ): 

1427 uri = transcoded_request["uri"] 

1428 method = transcoded_request["method"] 

1429 headers = dict(metadata) 

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

1431 response = getattr(session, method)( 

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

1433 timeout=timeout, 

1434 headers=headers, 

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

1436 ) 

1437 return response 

1438 

1439 def __call__( 

1440 self, 

1441 request: pubsub.DeleteSubscriptionRequest, 

1442 *, 

1443 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1444 timeout: Optional[float] = None, 

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

1446 ): 

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

1448 

1449 Args: 

1450 request (~.pubsub.DeleteSubscriptionRequest): 

1451 The request object. Request for the DeleteSubscription 

1452 method. 

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

1454 should be retried. 

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

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

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

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

1459 be of type `bytes`. 

1460 """ 

1461 

1462 http_options = ( 

1463 _BaseSubscriberRestTransport._BaseDeleteSubscription._get_http_options() 

1464 ) 

1465 

1466 request, metadata = self._interceptor.pre_delete_subscription( 

1467 request, metadata 

1468 ) 

1469 transcoded_request = _BaseSubscriberRestTransport._BaseDeleteSubscription._get_transcoded_request( 

1470 http_options, request 

1471 ) 

1472 

1473 # Jsonify the query params 

1474 query_params = _BaseSubscriberRestTransport._BaseDeleteSubscription._get_query_params_json( 

1475 transcoded_request 

1476 ) 

1477 

1478 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1479 logging.DEBUG 

1480 ): # pragma: NO COVER 

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

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

1483 ) 

1484 method = transcoded_request["method"] 

1485 try: 

1486 request_payload = json_format.MessageToJson(request) 

1487 except: 

1488 request_payload = None 

1489 http_request = { 

1490 "payload": request_payload, 

1491 "requestMethod": method, 

1492 "requestUrl": request_url, 

1493 "headers": dict(metadata), 

1494 } 

1495 _LOGGER.debug( 

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

1497 extra={ 

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

1499 "rpcName": "DeleteSubscription", 

1500 "httpRequest": http_request, 

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

1502 }, 

1503 ) 

1504 

1505 # Send the request 

1506 response = SubscriberRestTransport._DeleteSubscription._get_response( 

1507 self._host, 

1508 metadata, 

1509 query_params, 

1510 self._session, 

1511 timeout, 

1512 transcoded_request, 

1513 ) 

1514 

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

1516 # subclass. 

1517 if response.status_code >= 400: 

1518 raise core_exceptions.from_http_response(response) 

1519 

1520 class _GetSnapshot( 

1521 _BaseSubscriberRestTransport._BaseGetSnapshot, SubscriberRestStub 

1522 ): 

1523 def __hash__(self): 

1524 return hash("SubscriberRestTransport.GetSnapshot") 

1525 

1526 @staticmethod 

1527 def _get_response( 

1528 host, 

1529 metadata, 

1530 query_params, 

1531 session, 

1532 timeout, 

1533 transcoded_request, 

1534 body=None, 

1535 ): 

1536 uri = transcoded_request["uri"] 

1537 method = transcoded_request["method"] 

1538 headers = dict(metadata) 

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

1540 response = getattr(session, method)( 

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

1542 timeout=timeout, 

1543 headers=headers, 

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

1545 ) 

1546 return response 

1547 

1548 def __call__( 

1549 self, 

1550 request: pubsub.GetSnapshotRequest, 

1551 *, 

1552 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1553 timeout: Optional[float] = None, 

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

1555 ) -> pubsub.Snapshot: 

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

1557 

1558 Args: 

1559 request (~.pubsub.GetSnapshotRequest): 

1560 The request object. Request for the GetSnapshot method. 

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

1562 should be retried. 

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

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

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

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

1567 be of type `bytes`. 

1568 

1569 Returns: 

1570 ~.pubsub.Snapshot: 

1571 A snapshot resource. Snapshots are used in 

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

1573 operations, which allow you to manage message 

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

1575 acknowledgment state of messages in an existing 

1576 subscription to the state captured by a snapshot. 

1577 

1578 """ 

1579 

1580 http_options = ( 

1581 _BaseSubscriberRestTransport._BaseGetSnapshot._get_http_options() 

1582 ) 

1583 

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

1585 transcoded_request = ( 

1586 _BaseSubscriberRestTransport._BaseGetSnapshot._get_transcoded_request( 

1587 http_options, request 

1588 ) 

1589 ) 

1590 

1591 # Jsonify the query params 

1592 query_params = ( 

1593 _BaseSubscriberRestTransport._BaseGetSnapshot._get_query_params_json( 

1594 transcoded_request 

1595 ) 

1596 ) 

1597 

1598 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1599 logging.DEBUG 

1600 ): # pragma: NO COVER 

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

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

1603 ) 

1604 method = transcoded_request["method"] 

1605 try: 

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

1607 except: 

1608 request_payload = None 

1609 http_request = { 

1610 "payload": request_payload, 

1611 "requestMethod": method, 

1612 "requestUrl": request_url, 

1613 "headers": dict(metadata), 

1614 } 

1615 _LOGGER.debug( 

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

1617 extra={ 

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

1619 "rpcName": "GetSnapshot", 

1620 "httpRequest": http_request, 

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

1622 }, 

1623 ) 

1624 

1625 # Send the request 

1626 response = SubscriberRestTransport._GetSnapshot._get_response( 

1627 self._host, 

1628 metadata, 

1629 query_params, 

1630 self._session, 

1631 timeout, 

1632 transcoded_request, 

1633 ) 

1634 

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

1636 # subclass. 

1637 if response.status_code >= 400: 

1638 raise core_exceptions.from_http_response(response) 

1639 

1640 # Return the response 

1641 resp = pubsub.Snapshot() 

1642 pb_resp = pubsub.Snapshot.pb(resp) 

1643 

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

1645 

1646 resp = self._interceptor.post_get_snapshot(resp) 

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

1648 resp, _ = self._interceptor.post_get_snapshot_with_metadata( 

1649 resp, response_metadata 

1650 ) 

1651 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1652 logging.DEBUG 

1653 ): # pragma: NO COVER 

1654 try: 

1655 response_payload = pubsub.Snapshot.to_json(response) 

1656 except: 

1657 response_payload = None 

1658 http_response = { 

1659 "payload": response_payload, 

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

1661 "status": response.status_code, 

1662 } 

1663 _LOGGER.debug( 

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

1665 extra={ 

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

1667 "rpcName": "GetSnapshot", 

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

1669 "httpResponse": http_response, 

1670 }, 

1671 ) 

1672 return resp 

1673 

1674 class _GetSubscription( 

1675 _BaseSubscriberRestTransport._BaseGetSubscription, SubscriberRestStub 

1676 ): 

1677 def __hash__(self): 

1678 return hash("SubscriberRestTransport.GetSubscription") 

1679 

1680 @staticmethod 

1681 def _get_response( 

1682 host, 

1683 metadata, 

1684 query_params, 

1685 session, 

1686 timeout, 

1687 transcoded_request, 

1688 body=None, 

1689 ): 

1690 uri = transcoded_request["uri"] 

1691 method = transcoded_request["method"] 

1692 headers = dict(metadata) 

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

1694 response = getattr(session, method)( 

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

1696 timeout=timeout, 

1697 headers=headers, 

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

1699 ) 

1700 return response 

1701 

1702 def __call__( 

1703 self, 

1704 request: pubsub.GetSubscriptionRequest, 

1705 *, 

1706 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1707 timeout: Optional[float] = None, 

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

1709 ) -> pubsub.Subscription: 

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

1711 

1712 Args: 

1713 request (~.pubsub.GetSubscriptionRequest): 

1714 The request object. Request for the GetSubscription 

1715 method. 

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

1717 should be retried. 

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

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

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

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

1722 be of type `bytes`. 

1723 

1724 Returns: 

1725 ~.pubsub.Subscription: 

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

1727 ``bigquery_config``, or ``cloud_storage_config`` is set, 

1728 then the subscriber will pull and ack messages using API 

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

1730 

1731 """ 

1732 

1733 http_options = ( 

1734 _BaseSubscriberRestTransport._BaseGetSubscription._get_http_options() 

1735 ) 

1736 

1737 request, metadata = self._interceptor.pre_get_subscription( 

1738 request, metadata 

1739 ) 

1740 transcoded_request = _BaseSubscriberRestTransport._BaseGetSubscription._get_transcoded_request( 

1741 http_options, request 

1742 ) 

1743 

1744 # Jsonify the query params 

1745 query_params = _BaseSubscriberRestTransport._BaseGetSubscription._get_query_params_json( 

1746 transcoded_request 

1747 ) 

1748 

1749 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1750 logging.DEBUG 

1751 ): # pragma: NO COVER 

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

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

1754 ) 

1755 method = transcoded_request["method"] 

1756 try: 

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

1758 except: 

1759 request_payload = None 

1760 http_request = { 

1761 "payload": request_payload, 

1762 "requestMethod": method, 

1763 "requestUrl": request_url, 

1764 "headers": dict(metadata), 

1765 } 

1766 _LOGGER.debug( 

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

1768 extra={ 

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

1770 "rpcName": "GetSubscription", 

1771 "httpRequest": http_request, 

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

1773 }, 

1774 ) 

1775 

1776 # Send the request 

1777 response = SubscriberRestTransport._GetSubscription._get_response( 

1778 self._host, 

1779 metadata, 

1780 query_params, 

1781 self._session, 

1782 timeout, 

1783 transcoded_request, 

1784 ) 

1785 

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

1787 # subclass. 

1788 if response.status_code >= 400: 

1789 raise core_exceptions.from_http_response(response) 

1790 

1791 # Return the response 

1792 resp = pubsub.Subscription() 

1793 pb_resp = pubsub.Subscription.pb(resp) 

1794 

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

1796 

1797 resp = self._interceptor.post_get_subscription(resp) 

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

1799 resp, _ = self._interceptor.post_get_subscription_with_metadata( 

1800 resp, response_metadata 

1801 ) 

1802 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1803 logging.DEBUG 

1804 ): # pragma: NO COVER 

1805 try: 

1806 response_payload = pubsub.Subscription.to_json(response) 

1807 except: 

1808 response_payload = None 

1809 http_response = { 

1810 "payload": response_payload, 

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

1812 "status": response.status_code, 

1813 } 

1814 _LOGGER.debug( 

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

1816 extra={ 

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

1818 "rpcName": "GetSubscription", 

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

1820 "httpResponse": http_response, 

1821 }, 

1822 ) 

1823 return resp 

1824 

1825 class _ListSnapshots( 

1826 _BaseSubscriberRestTransport._BaseListSnapshots, SubscriberRestStub 

1827 ): 

1828 def __hash__(self): 

1829 return hash("SubscriberRestTransport.ListSnapshots") 

1830 

1831 @staticmethod 

1832 def _get_response( 

1833 host, 

1834 metadata, 

1835 query_params, 

1836 session, 

1837 timeout, 

1838 transcoded_request, 

1839 body=None, 

1840 ): 

1841 uri = transcoded_request["uri"] 

1842 method = transcoded_request["method"] 

1843 headers = dict(metadata) 

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

1845 response = getattr(session, method)( 

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

1847 timeout=timeout, 

1848 headers=headers, 

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

1850 ) 

1851 return response 

1852 

1853 def __call__( 

1854 self, 

1855 request: pubsub.ListSnapshotsRequest, 

1856 *, 

1857 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1858 timeout: Optional[float] = None, 

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

1860 ) -> pubsub.ListSnapshotsResponse: 

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

1862 

1863 Args: 

1864 request (~.pubsub.ListSnapshotsRequest): 

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

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

1867 should be retried. 

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

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

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

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

1872 be of type `bytes`. 

1873 

1874 Returns: 

1875 ~.pubsub.ListSnapshotsResponse: 

1876 Response for the ``ListSnapshots`` method. 

1877 """ 

1878 

1879 http_options = ( 

1880 _BaseSubscriberRestTransport._BaseListSnapshots._get_http_options() 

1881 ) 

1882 

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

1884 transcoded_request = ( 

1885 _BaseSubscriberRestTransport._BaseListSnapshots._get_transcoded_request( 

1886 http_options, request 

1887 ) 

1888 ) 

1889 

1890 # Jsonify the query params 

1891 query_params = ( 

1892 _BaseSubscriberRestTransport._BaseListSnapshots._get_query_params_json( 

1893 transcoded_request 

1894 ) 

1895 ) 

1896 

1897 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1898 logging.DEBUG 

1899 ): # pragma: NO COVER 

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

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

1902 ) 

1903 method = transcoded_request["method"] 

1904 try: 

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

1906 except: 

1907 request_payload = None 

1908 http_request = { 

1909 "payload": request_payload, 

1910 "requestMethod": method, 

1911 "requestUrl": request_url, 

1912 "headers": dict(metadata), 

1913 } 

1914 _LOGGER.debug( 

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

1916 extra={ 

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

1918 "rpcName": "ListSnapshots", 

1919 "httpRequest": http_request, 

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

1921 }, 

1922 ) 

1923 

1924 # Send the request 

1925 response = SubscriberRestTransport._ListSnapshots._get_response( 

1926 self._host, 

1927 metadata, 

1928 query_params, 

1929 self._session, 

1930 timeout, 

1931 transcoded_request, 

1932 ) 

1933 

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

1935 # subclass. 

1936 if response.status_code >= 400: 

1937 raise core_exceptions.from_http_response(response) 

1938 

1939 # Return the response 

1940 resp = pubsub.ListSnapshotsResponse() 

1941 pb_resp = pubsub.ListSnapshotsResponse.pb(resp) 

1942 

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

1944 

1945 resp = self._interceptor.post_list_snapshots(resp) 

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

1947 resp, _ = self._interceptor.post_list_snapshots_with_metadata( 

1948 resp, response_metadata 

1949 ) 

1950 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1951 logging.DEBUG 

1952 ): # pragma: NO COVER 

1953 try: 

1954 response_payload = pubsub.ListSnapshotsResponse.to_json(response) 

1955 except: 

1956 response_payload = None 

1957 http_response = { 

1958 "payload": response_payload, 

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

1960 "status": response.status_code, 

1961 } 

1962 _LOGGER.debug( 

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

1964 extra={ 

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

1966 "rpcName": "ListSnapshots", 

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

1968 "httpResponse": http_response, 

1969 }, 

1970 ) 

1971 return resp 

1972 

1973 class _ListSubscriptions( 

1974 _BaseSubscriberRestTransport._BaseListSubscriptions, SubscriberRestStub 

1975 ): 

1976 def __hash__(self): 

1977 return hash("SubscriberRestTransport.ListSubscriptions") 

1978 

1979 @staticmethod 

1980 def _get_response( 

1981 host, 

1982 metadata, 

1983 query_params, 

1984 session, 

1985 timeout, 

1986 transcoded_request, 

1987 body=None, 

1988 ): 

1989 uri = transcoded_request["uri"] 

1990 method = transcoded_request["method"] 

1991 headers = dict(metadata) 

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

1993 response = getattr(session, method)( 

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

1995 timeout=timeout, 

1996 headers=headers, 

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

1998 ) 

1999 return response 

2000 

2001 def __call__( 

2002 self, 

2003 request: pubsub.ListSubscriptionsRequest, 

2004 *, 

2005 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2006 timeout: Optional[float] = None, 

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

2008 ) -> pubsub.ListSubscriptionsResponse: 

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

2010 

2011 Args: 

2012 request (~.pubsub.ListSubscriptionsRequest): 

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

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

2015 should be retried. 

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

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

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

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

2020 be of type `bytes`. 

2021 

2022 Returns: 

2023 ~.pubsub.ListSubscriptionsResponse: 

2024 Response for the ``ListSubscriptions`` method. 

2025 """ 

2026 

2027 http_options = ( 

2028 _BaseSubscriberRestTransport._BaseListSubscriptions._get_http_options() 

2029 ) 

2030 

2031 request, metadata = self._interceptor.pre_list_subscriptions( 

2032 request, metadata 

2033 ) 

2034 transcoded_request = _BaseSubscriberRestTransport._BaseListSubscriptions._get_transcoded_request( 

2035 http_options, request 

2036 ) 

2037 

2038 # Jsonify the query params 

2039 query_params = _BaseSubscriberRestTransport._BaseListSubscriptions._get_query_params_json( 

2040 transcoded_request 

2041 ) 

2042 

2043 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2044 logging.DEBUG 

2045 ): # pragma: NO COVER 

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

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

2048 ) 

2049 method = transcoded_request["method"] 

2050 try: 

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

2052 except: 

2053 request_payload = None 

2054 http_request = { 

2055 "payload": request_payload, 

2056 "requestMethod": method, 

2057 "requestUrl": request_url, 

2058 "headers": dict(metadata), 

2059 } 

2060 _LOGGER.debug( 

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

2062 extra={ 

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

2064 "rpcName": "ListSubscriptions", 

2065 "httpRequest": http_request, 

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

2067 }, 

2068 ) 

2069 

2070 # Send the request 

2071 response = SubscriberRestTransport._ListSubscriptions._get_response( 

2072 self._host, 

2073 metadata, 

2074 query_params, 

2075 self._session, 

2076 timeout, 

2077 transcoded_request, 

2078 ) 

2079 

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

2081 # subclass. 

2082 if response.status_code >= 400: 

2083 raise core_exceptions.from_http_response(response) 

2084 

2085 # Return the response 

2086 resp = pubsub.ListSubscriptionsResponse() 

2087 pb_resp = pubsub.ListSubscriptionsResponse.pb(resp) 

2088 

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

2090 

2091 resp = self._interceptor.post_list_subscriptions(resp) 

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

2093 resp, _ = self._interceptor.post_list_subscriptions_with_metadata( 

2094 resp, response_metadata 

2095 ) 

2096 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2097 logging.DEBUG 

2098 ): # pragma: NO COVER 

2099 try: 

2100 response_payload = pubsub.ListSubscriptionsResponse.to_json( 

2101 response 

2102 ) 

2103 except: 

2104 response_payload = None 

2105 http_response = { 

2106 "payload": response_payload, 

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

2108 "status": response.status_code, 

2109 } 

2110 _LOGGER.debug( 

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

2112 extra={ 

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

2114 "rpcName": "ListSubscriptions", 

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

2116 "httpResponse": http_response, 

2117 }, 

2118 ) 

2119 return resp 

2120 

2121 class _ModifyAckDeadline( 

2122 _BaseSubscriberRestTransport._BaseModifyAckDeadline, SubscriberRestStub 

2123 ): 

2124 def __hash__(self): 

2125 return hash("SubscriberRestTransport.ModifyAckDeadline") 

2126 

2127 @staticmethod 

2128 def _get_response( 

2129 host, 

2130 metadata, 

2131 query_params, 

2132 session, 

2133 timeout, 

2134 transcoded_request, 

2135 body=None, 

2136 ): 

2137 uri = transcoded_request["uri"] 

2138 method = transcoded_request["method"] 

2139 headers = dict(metadata) 

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

2141 response = getattr(session, method)( 

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

2143 timeout=timeout, 

2144 headers=headers, 

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

2146 data=body, 

2147 ) 

2148 return response 

2149 

2150 def __call__( 

2151 self, 

2152 request: pubsub.ModifyAckDeadlineRequest, 

2153 *, 

2154 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2155 timeout: Optional[float] = None, 

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

2157 ): 

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

2159 

2160 Args: 

2161 request (~.pubsub.ModifyAckDeadlineRequest): 

2162 The request object. Request for the ModifyAckDeadline 

2163 method. 

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

2165 should be retried. 

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

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

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

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

2170 be of type `bytes`. 

2171 """ 

2172 

2173 http_options = ( 

2174 _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_http_options() 

2175 ) 

2176 

2177 request, metadata = self._interceptor.pre_modify_ack_deadline( 

2178 request, metadata 

2179 ) 

2180 transcoded_request = _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_transcoded_request( 

2181 http_options, request 

2182 ) 

2183 

2184 body = _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_request_body_json( 

2185 transcoded_request 

2186 ) 

2187 

2188 # Jsonify the query params 

2189 query_params = _BaseSubscriberRestTransport._BaseModifyAckDeadline._get_query_params_json( 

2190 transcoded_request 

2191 ) 

2192 

2193 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2194 logging.DEBUG 

2195 ): # pragma: NO COVER 

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

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

2198 ) 

2199 method = transcoded_request["method"] 

2200 try: 

2201 request_payload = json_format.MessageToJson(request) 

2202 except: 

2203 request_payload = None 

2204 http_request = { 

2205 "payload": request_payload, 

2206 "requestMethod": method, 

2207 "requestUrl": request_url, 

2208 "headers": dict(metadata), 

2209 } 

2210 _LOGGER.debug( 

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

2212 extra={ 

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

2214 "rpcName": "ModifyAckDeadline", 

2215 "httpRequest": http_request, 

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

2217 }, 

2218 ) 

2219 

2220 # Send the request 

2221 response = SubscriberRestTransport._ModifyAckDeadline._get_response( 

2222 self._host, 

2223 metadata, 

2224 query_params, 

2225 self._session, 

2226 timeout, 

2227 transcoded_request, 

2228 body, 

2229 ) 

2230 

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

2232 # subclass. 

2233 if response.status_code >= 400: 

2234 raise core_exceptions.from_http_response(response) 

2235 

2236 class _ModifyPushConfig( 

2237 _BaseSubscriberRestTransport._BaseModifyPushConfig, SubscriberRestStub 

2238 ): 

2239 def __hash__(self): 

2240 return hash("SubscriberRestTransport.ModifyPushConfig") 

2241 

2242 @staticmethod 

2243 def _get_response( 

2244 host, 

2245 metadata, 

2246 query_params, 

2247 session, 

2248 timeout, 

2249 transcoded_request, 

2250 body=None, 

2251 ): 

2252 uri = transcoded_request["uri"] 

2253 method = transcoded_request["method"] 

2254 headers = dict(metadata) 

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

2256 response = getattr(session, method)( 

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

2258 timeout=timeout, 

2259 headers=headers, 

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

2261 data=body, 

2262 ) 

2263 return response 

2264 

2265 def __call__( 

2266 self, 

2267 request: pubsub.ModifyPushConfigRequest, 

2268 *, 

2269 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2270 timeout: Optional[float] = None, 

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

2272 ): 

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

2274 

2275 Args: 

2276 request (~.pubsub.ModifyPushConfigRequest): 

2277 The request object. Request for the ModifyPushConfig 

2278 method. 

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

2280 should be retried. 

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

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

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

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

2285 be of type `bytes`. 

2286 """ 

2287 

2288 http_options = ( 

2289 _BaseSubscriberRestTransport._BaseModifyPushConfig._get_http_options() 

2290 ) 

2291 

2292 request, metadata = self._interceptor.pre_modify_push_config( 

2293 request, metadata 

2294 ) 

2295 transcoded_request = _BaseSubscriberRestTransport._BaseModifyPushConfig._get_transcoded_request( 

2296 http_options, request 

2297 ) 

2298 

2299 body = _BaseSubscriberRestTransport._BaseModifyPushConfig._get_request_body_json( 

2300 transcoded_request 

2301 ) 

2302 

2303 # Jsonify the query params 

2304 query_params = _BaseSubscriberRestTransport._BaseModifyPushConfig._get_query_params_json( 

2305 transcoded_request 

2306 ) 

2307 

2308 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2309 logging.DEBUG 

2310 ): # pragma: NO COVER 

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

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

2313 ) 

2314 method = transcoded_request["method"] 

2315 try: 

2316 request_payload = json_format.MessageToJson(request) 

2317 except: 

2318 request_payload = None 

2319 http_request = { 

2320 "payload": request_payload, 

2321 "requestMethod": method, 

2322 "requestUrl": request_url, 

2323 "headers": dict(metadata), 

2324 } 

2325 _LOGGER.debug( 

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

2327 extra={ 

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

2329 "rpcName": "ModifyPushConfig", 

2330 "httpRequest": http_request, 

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

2332 }, 

2333 ) 

2334 

2335 # Send the request 

2336 response = SubscriberRestTransport._ModifyPushConfig._get_response( 

2337 self._host, 

2338 metadata, 

2339 query_params, 

2340 self._session, 

2341 timeout, 

2342 transcoded_request, 

2343 body, 

2344 ) 

2345 

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

2347 # subclass. 

2348 if response.status_code >= 400: 

2349 raise core_exceptions.from_http_response(response) 

2350 

2351 class _Pull(_BaseSubscriberRestTransport._BasePull, SubscriberRestStub): 

2352 def __hash__(self): 

2353 return hash("SubscriberRestTransport.Pull") 

2354 

2355 @staticmethod 

2356 def _get_response( 

2357 host, 

2358 metadata, 

2359 query_params, 

2360 session, 

2361 timeout, 

2362 transcoded_request, 

2363 body=None, 

2364 ): 

2365 uri = transcoded_request["uri"] 

2366 method = transcoded_request["method"] 

2367 headers = dict(metadata) 

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

2369 response = getattr(session, method)( 

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

2371 timeout=timeout, 

2372 headers=headers, 

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

2374 data=body, 

2375 ) 

2376 return response 

2377 

2378 def __call__( 

2379 self, 

2380 request: pubsub.PullRequest, 

2381 *, 

2382 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2383 timeout: Optional[float] = None, 

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

2385 ) -> pubsub.PullResponse: 

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

2387 

2388 Args: 

2389 request (~.pubsub.PullRequest): 

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

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

2392 should be retried. 

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

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

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

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

2397 be of type `bytes`. 

2398 

2399 Returns: 

2400 ~.pubsub.PullResponse: 

2401 Response for the ``Pull`` method. 

2402 """ 

2403 

2404 http_options = _BaseSubscriberRestTransport._BasePull._get_http_options() 

2405 

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

2407 transcoded_request = ( 

2408 _BaseSubscriberRestTransport._BasePull._get_transcoded_request( 

2409 http_options, request 

2410 ) 

2411 ) 

2412 

2413 body = _BaseSubscriberRestTransport._BasePull._get_request_body_json( 

2414 transcoded_request 

2415 ) 

2416 

2417 # Jsonify the query params 

2418 query_params = ( 

2419 _BaseSubscriberRestTransport._BasePull._get_query_params_json( 

2420 transcoded_request 

2421 ) 

2422 ) 

2423 

2424 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2425 logging.DEBUG 

2426 ): # pragma: NO COVER 

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

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

2429 ) 

2430 method = transcoded_request["method"] 

2431 try: 

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

2433 except: 

2434 request_payload = None 

2435 http_request = { 

2436 "payload": request_payload, 

2437 "requestMethod": method, 

2438 "requestUrl": request_url, 

2439 "headers": dict(metadata), 

2440 } 

2441 _LOGGER.debug( 

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

2443 extra={ 

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

2445 "rpcName": "Pull", 

2446 "httpRequest": http_request, 

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

2448 }, 

2449 ) 

2450 

2451 # Send the request 

2452 response = SubscriberRestTransport._Pull._get_response( 

2453 self._host, 

2454 metadata, 

2455 query_params, 

2456 self._session, 

2457 timeout, 

2458 transcoded_request, 

2459 body, 

2460 ) 

2461 

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

2463 # subclass. 

2464 if response.status_code >= 400: 

2465 raise core_exceptions.from_http_response(response) 

2466 

2467 # Return the response 

2468 resp = pubsub.PullResponse() 

2469 pb_resp = pubsub.PullResponse.pb(resp) 

2470 

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

2472 

2473 resp = self._interceptor.post_pull(resp) 

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

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

2476 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2477 logging.DEBUG 

2478 ): # pragma: NO COVER 

2479 try: 

2480 response_payload = pubsub.PullResponse.to_json(response) 

2481 except: 

2482 response_payload = None 

2483 http_response = { 

2484 "payload": response_payload, 

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

2486 "status": response.status_code, 

2487 } 

2488 _LOGGER.debug( 

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

2490 extra={ 

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

2492 "rpcName": "Pull", 

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

2494 "httpResponse": http_response, 

2495 }, 

2496 ) 

2497 return resp 

2498 

2499 class _Seek(_BaseSubscriberRestTransport._BaseSeek, SubscriberRestStub): 

2500 def __hash__(self): 

2501 return hash("SubscriberRestTransport.Seek") 

2502 

2503 @staticmethod 

2504 def _get_response( 

2505 host, 

2506 metadata, 

2507 query_params, 

2508 session, 

2509 timeout, 

2510 transcoded_request, 

2511 body=None, 

2512 ): 

2513 uri = transcoded_request["uri"] 

2514 method = transcoded_request["method"] 

2515 headers = dict(metadata) 

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

2517 response = getattr(session, method)( 

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

2519 timeout=timeout, 

2520 headers=headers, 

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

2522 data=body, 

2523 ) 

2524 return response 

2525 

2526 def __call__( 

2527 self, 

2528 request: pubsub.SeekRequest, 

2529 *, 

2530 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2531 timeout: Optional[float] = None, 

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

2533 ) -> pubsub.SeekResponse: 

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

2535 

2536 Args: 

2537 request (~.pubsub.SeekRequest): 

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

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

2540 should be retried. 

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

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

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

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

2545 be of type `bytes`. 

2546 

2547 Returns: 

2548 ~.pubsub.SeekResponse: 

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

2550 empty). 

2551 

2552 """ 

2553 

2554 http_options = _BaseSubscriberRestTransport._BaseSeek._get_http_options() 

2555 

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

2557 transcoded_request = ( 

2558 _BaseSubscriberRestTransport._BaseSeek._get_transcoded_request( 

2559 http_options, request 

2560 ) 

2561 ) 

2562 

2563 body = _BaseSubscriberRestTransport._BaseSeek._get_request_body_json( 

2564 transcoded_request 

2565 ) 

2566 

2567 # Jsonify the query params 

2568 query_params = ( 

2569 _BaseSubscriberRestTransport._BaseSeek._get_query_params_json( 

2570 transcoded_request 

2571 ) 

2572 ) 

2573 

2574 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2575 logging.DEBUG 

2576 ): # pragma: NO COVER 

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

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

2579 ) 

2580 method = transcoded_request["method"] 

2581 try: 

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

2583 except: 

2584 request_payload = None 

2585 http_request = { 

2586 "payload": request_payload, 

2587 "requestMethod": method, 

2588 "requestUrl": request_url, 

2589 "headers": dict(metadata), 

2590 } 

2591 _LOGGER.debug( 

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

2593 extra={ 

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

2595 "rpcName": "Seek", 

2596 "httpRequest": http_request, 

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

2598 }, 

2599 ) 

2600 

2601 # Send the request 

2602 response = SubscriberRestTransport._Seek._get_response( 

2603 self._host, 

2604 metadata, 

2605 query_params, 

2606 self._session, 

2607 timeout, 

2608 transcoded_request, 

2609 body, 

2610 ) 

2611 

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

2613 # subclass. 

2614 if response.status_code >= 400: 

2615 raise core_exceptions.from_http_response(response) 

2616 

2617 # Return the response 

2618 resp = pubsub.SeekResponse() 

2619 pb_resp = pubsub.SeekResponse.pb(resp) 

2620 

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

2622 

2623 resp = self._interceptor.post_seek(resp) 

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

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

2626 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2627 logging.DEBUG 

2628 ): # pragma: NO COVER 

2629 try: 

2630 response_payload = pubsub.SeekResponse.to_json(response) 

2631 except: 

2632 response_payload = None 

2633 http_response = { 

2634 "payload": response_payload, 

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

2636 "status": response.status_code, 

2637 } 

2638 _LOGGER.debug( 

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

2640 extra={ 

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

2642 "rpcName": "Seek", 

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

2644 "httpResponse": http_response, 

2645 }, 

2646 ) 

2647 return resp 

2648 

2649 class _StreamingPull( 

2650 _BaseSubscriberRestTransport._BaseStreamingPull, SubscriberRestStub 

2651 ): 

2652 def __hash__(self): 

2653 return hash("SubscriberRestTransport.StreamingPull") 

2654 

2655 def __call__( 

2656 self, 

2657 request: pubsub.StreamingPullRequest, 

2658 *, 

2659 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2660 timeout: Optional[float] = None, 

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

2662 ) -> rest_streaming.ResponseIterator: 

2663 raise NotImplementedError( 

2664 "Method StreamingPull is not available over REST transport" 

2665 ) 

2666 

2667 class _UpdateSnapshot( 

2668 _BaseSubscriberRestTransport._BaseUpdateSnapshot, SubscriberRestStub 

2669 ): 

2670 def __hash__(self): 

2671 return hash("SubscriberRestTransport.UpdateSnapshot") 

2672 

2673 @staticmethod 

2674 def _get_response( 

2675 host, 

2676 metadata, 

2677 query_params, 

2678 session, 

2679 timeout, 

2680 transcoded_request, 

2681 body=None, 

2682 ): 

2683 uri = transcoded_request["uri"] 

2684 method = transcoded_request["method"] 

2685 headers = dict(metadata) 

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

2687 response = getattr(session, method)( 

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

2689 timeout=timeout, 

2690 headers=headers, 

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

2692 data=body, 

2693 ) 

2694 return response 

2695 

2696 def __call__( 

2697 self, 

2698 request: pubsub.UpdateSnapshotRequest, 

2699 *, 

2700 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2701 timeout: Optional[float] = None, 

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

2703 ) -> pubsub.Snapshot: 

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

2705 

2706 Args: 

2707 request (~.pubsub.UpdateSnapshotRequest): 

2708 The request object. Request for the UpdateSnapshot 

2709 method. 

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

2711 should be retried. 

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

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

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

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

2716 be of type `bytes`. 

2717 

2718 Returns: 

2719 ~.pubsub.Snapshot: 

2720 A snapshot resource. Snapshots are used in 

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

2722 operations, which allow you to manage message 

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

2724 acknowledgment state of messages in an existing 

2725 subscription to the state captured by a snapshot. 

2726 

2727 """ 

2728 

2729 http_options = ( 

2730 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_http_options() 

2731 ) 

2732 

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

2734 transcoded_request = _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_transcoded_request( 

2735 http_options, request 

2736 ) 

2737 

2738 body = ( 

2739 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_request_body_json( 

2740 transcoded_request 

2741 ) 

2742 ) 

2743 

2744 # Jsonify the query params 

2745 query_params = ( 

2746 _BaseSubscriberRestTransport._BaseUpdateSnapshot._get_query_params_json( 

2747 transcoded_request 

2748 ) 

2749 ) 

2750 

2751 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2752 logging.DEBUG 

2753 ): # pragma: NO COVER 

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

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

2756 ) 

2757 method = transcoded_request["method"] 

2758 try: 

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

2760 except: 

2761 request_payload = None 

2762 http_request = { 

2763 "payload": request_payload, 

2764 "requestMethod": method, 

2765 "requestUrl": request_url, 

2766 "headers": dict(metadata), 

2767 } 

2768 _LOGGER.debug( 

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

2770 extra={ 

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

2772 "rpcName": "UpdateSnapshot", 

2773 "httpRequest": http_request, 

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

2775 }, 

2776 ) 

2777 

2778 # Send the request 

2779 response = SubscriberRestTransport._UpdateSnapshot._get_response( 

2780 self._host, 

2781 metadata, 

2782 query_params, 

2783 self._session, 

2784 timeout, 

2785 transcoded_request, 

2786 body, 

2787 ) 

2788 

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

2790 # subclass. 

2791 if response.status_code >= 400: 

2792 raise core_exceptions.from_http_response(response) 

2793 

2794 # Return the response 

2795 resp = pubsub.Snapshot() 

2796 pb_resp = pubsub.Snapshot.pb(resp) 

2797 

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

2799 

2800 resp = self._interceptor.post_update_snapshot(resp) 

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

2802 resp, _ = self._interceptor.post_update_snapshot_with_metadata( 

2803 resp, response_metadata 

2804 ) 

2805 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2806 logging.DEBUG 

2807 ): # pragma: NO COVER 

2808 try: 

2809 response_payload = pubsub.Snapshot.to_json(response) 

2810 except: 

2811 response_payload = None 

2812 http_response = { 

2813 "payload": response_payload, 

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

2815 "status": response.status_code, 

2816 } 

2817 _LOGGER.debug( 

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

2819 extra={ 

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

2821 "rpcName": "UpdateSnapshot", 

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

2823 "httpResponse": http_response, 

2824 }, 

2825 ) 

2826 return resp 

2827 

2828 class _UpdateSubscription( 

2829 _BaseSubscriberRestTransport._BaseUpdateSubscription, SubscriberRestStub 

2830 ): 

2831 def __hash__(self): 

2832 return hash("SubscriberRestTransport.UpdateSubscription") 

2833 

2834 @staticmethod 

2835 def _get_response( 

2836 host, 

2837 metadata, 

2838 query_params, 

2839 session, 

2840 timeout, 

2841 transcoded_request, 

2842 body=None, 

2843 ): 

2844 uri = transcoded_request["uri"] 

2845 method = transcoded_request["method"] 

2846 headers = dict(metadata) 

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

2848 response = getattr(session, method)( 

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

2850 timeout=timeout, 

2851 headers=headers, 

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

2853 data=body, 

2854 ) 

2855 return response 

2856 

2857 def __call__( 

2858 self, 

2859 request: pubsub.UpdateSubscriptionRequest, 

2860 *, 

2861 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2862 timeout: Optional[float] = None, 

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

2864 ) -> pubsub.Subscription: 

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

2866 

2867 Args: 

2868 request (~.pubsub.UpdateSubscriptionRequest): 

2869 The request object. Request for the UpdateSubscription 

2870 method. 

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

2872 should be retried. 

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

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

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

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

2877 be of type `bytes`. 

2878 

2879 Returns: 

2880 ~.pubsub.Subscription: 

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

2882 ``bigquery_config``, or ``cloud_storage_config`` is set, 

2883 then the subscriber will pull and ack messages using API 

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

2885 

2886 """ 

2887 

2888 http_options = ( 

2889 _BaseSubscriberRestTransport._BaseUpdateSubscription._get_http_options() 

2890 ) 

2891 

2892 request, metadata = self._interceptor.pre_update_subscription( 

2893 request, metadata 

2894 ) 

2895 transcoded_request = _BaseSubscriberRestTransport._BaseUpdateSubscription._get_transcoded_request( 

2896 http_options, request 

2897 ) 

2898 

2899 body = _BaseSubscriberRestTransport._BaseUpdateSubscription._get_request_body_json( 

2900 transcoded_request 

2901 ) 

2902 

2903 # Jsonify the query params 

2904 query_params = _BaseSubscriberRestTransport._BaseUpdateSubscription._get_query_params_json( 

2905 transcoded_request 

2906 ) 

2907 

2908 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2909 logging.DEBUG 

2910 ): # pragma: NO COVER 

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

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

2913 ) 

2914 method = transcoded_request["method"] 

2915 try: 

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

2917 except: 

2918 request_payload = None 

2919 http_request = { 

2920 "payload": request_payload, 

2921 "requestMethod": method, 

2922 "requestUrl": request_url, 

2923 "headers": dict(metadata), 

2924 } 

2925 _LOGGER.debug( 

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

2927 extra={ 

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

2929 "rpcName": "UpdateSubscription", 

2930 "httpRequest": http_request, 

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

2932 }, 

2933 ) 

2934 

2935 # Send the request 

2936 response = SubscriberRestTransport._UpdateSubscription._get_response( 

2937 self._host, 

2938 metadata, 

2939 query_params, 

2940 self._session, 

2941 timeout, 

2942 transcoded_request, 

2943 body, 

2944 ) 

2945 

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

2947 # subclass. 

2948 if response.status_code >= 400: 

2949 raise core_exceptions.from_http_response(response) 

2950 

2951 # Return the response 

2952 resp = pubsub.Subscription() 

2953 pb_resp = pubsub.Subscription.pb(resp) 

2954 

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

2956 

2957 resp = self._interceptor.post_update_subscription(resp) 

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

2959 resp, _ = self._interceptor.post_update_subscription_with_metadata( 

2960 resp, response_metadata 

2961 ) 

2962 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2963 logging.DEBUG 

2964 ): # pragma: NO COVER 

2965 try: 

2966 response_payload = pubsub.Subscription.to_json(response) 

2967 except: 

2968 response_payload = None 

2969 http_response = { 

2970 "payload": response_payload, 

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

2972 "status": response.status_code, 

2973 } 

2974 _LOGGER.debug( 

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

2976 extra={ 

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

2978 "rpcName": "UpdateSubscription", 

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

2980 "httpResponse": http_response, 

2981 }, 

2982 ) 

2983 return resp 

2984 

2985 @property 

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

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

2988 # In C++ this would require a dynamic_cast 

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

2990 

2991 @property 

2992 def create_snapshot( 

2993 self, 

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

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

2996 # In C++ this would require a dynamic_cast 

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

2998 

2999 @property 

3000 def create_subscription( 

3001 self, 

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

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

3004 # In C++ this would require a dynamic_cast 

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

3006 

3007 @property 

3008 def delete_snapshot( 

3009 self, 

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

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

3012 # In C++ this would require a dynamic_cast 

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

3014 

3015 @property 

3016 def delete_subscription( 

3017 self, 

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

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

3020 # In C++ this would require a dynamic_cast 

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

3022 

3023 @property 

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

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

3026 # In C++ this would require a dynamic_cast 

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

3028 

3029 @property 

3030 def get_subscription( 

3031 self, 

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

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

3034 # In C++ this would require a dynamic_cast 

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

3036 

3037 @property 

3038 def list_snapshots( 

3039 self, 

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

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

3042 # In C++ this would require a dynamic_cast 

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

3044 

3045 @property 

3046 def list_subscriptions( 

3047 self, 

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

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

3050 # In C++ this would require a dynamic_cast 

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

3052 

3053 @property 

3054 def modify_ack_deadline( 

3055 self, 

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

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

3058 # In C++ this would require a dynamic_cast 

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

3060 

3061 @property 

3062 def modify_push_config( 

3063 self, 

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

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

3066 # In C++ this would require a dynamic_cast 

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

3068 

3069 @property 

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

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

3072 # In C++ this would require a dynamic_cast 

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

3074 

3075 @property 

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

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

3078 # In C++ this would require a dynamic_cast 

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

3080 

3081 @property 

3082 def streaming_pull( 

3083 self, 

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

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

3086 # In C++ this would require a dynamic_cast 

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

3088 

3089 @property 

3090 def update_snapshot( 

3091 self, 

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

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

3094 # In C++ this would require a dynamic_cast 

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

3096 

3097 @property 

3098 def update_subscription( 

3099 self, 

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

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

3102 # In C++ this would require a dynamic_cast 

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

3104 

3105 @property 

3106 def get_iam_policy(self): 

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

3108 

3109 class _GetIamPolicy( 

3110 _BaseSubscriberRestTransport._BaseGetIamPolicy, SubscriberRestStub 

3111 ): 

3112 def __hash__(self): 

3113 return hash("SubscriberRestTransport.GetIamPolicy") 

3114 

3115 @staticmethod 

3116 def _get_response( 

3117 host, 

3118 metadata, 

3119 query_params, 

3120 session, 

3121 timeout, 

3122 transcoded_request, 

3123 body=None, 

3124 ): 

3125 uri = transcoded_request["uri"] 

3126 method = transcoded_request["method"] 

3127 headers = dict(metadata) 

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

3129 response = getattr(session, method)( 

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

3131 timeout=timeout, 

3132 headers=headers, 

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

3134 ) 

3135 return response 

3136 

3137 def __call__( 

3138 self, 

3139 request: iam_policy_pb2.GetIamPolicyRequest, 

3140 *, 

3141 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3142 timeout: Optional[float] = None, 

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

3144 ) -> policy_pb2.Policy: 

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

3146 

3147 Args: 

3148 request (iam_policy_pb2.GetIamPolicyRequest): 

3149 The request object for GetIamPolicy method. 

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

3151 should be retried. 

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

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

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

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

3156 be of type `bytes`. 

3157 

3158 Returns: 

3159 policy_pb2.Policy: Response from GetIamPolicy method. 

3160 """ 

3161 

3162 http_options = ( 

3163 _BaseSubscriberRestTransport._BaseGetIamPolicy._get_http_options() 

3164 ) 

3165 

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

3167 transcoded_request = ( 

3168 _BaseSubscriberRestTransport._BaseGetIamPolicy._get_transcoded_request( 

3169 http_options, request 

3170 ) 

3171 ) 

3172 

3173 # Jsonify the query params 

3174 query_params = ( 

3175 _BaseSubscriberRestTransport._BaseGetIamPolicy._get_query_params_json( 

3176 transcoded_request 

3177 ) 

3178 ) 

3179 

3180 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3181 logging.DEBUG 

3182 ): # pragma: NO COVER 

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

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

3185 ) 

3186 method = transcoded_request["method"] 

3187 try: 

3188 request_payload = json_format.MessageToJson(request) 

3189 except: 

3190 request_payload = None 

3191 http_request = { 

3192 "payload": request_payload, 

3193 "requestMethod": method, 

3194 "requestUrl": request_url, 

3195 "headers": dict(metadata), 

3196 } 

3197 _LOGGER.debug( 

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

3199 extra={ 

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

3201 "rpcName": "GetIamPolicy", 

3202 "httpRequest": http_request, 

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

3204 }, 

3205 ) 

3206 

3207 # Send the request 

3208 response = SubscriberRestTransport._GetIamPolicy._get_response( 

3209 self._host, 

3210 metadata, 

3211 query_params, 

3212 self._session, 

3213 timeout, 

3214 transcoded_request, 

3215 ) 

3216 

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

3218 # subclass. 

3219 if response.status_code >= 400: 

3220 raise core_exceptions.from_http_response(response) 

3221 

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

3223 resp = policy_pb2.Policy() 

3224 resp = json_format.Parse(content, resp) 

3225 resp = self._interceptor.post_get_iam_policy(resp) 

3226 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3227 logging.DEBUG 

3228 ): # pragma: NO COVER 

3229 try: 

3230 response_payload = json_format.MessageToJson(resp) 

3231 except: 

3232 response_payload = None 

3233 http_response = { 

3234 "payload": response_payload, 

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

3236 "status": response.status_code, 

3237 } 

3238 _LOGGER.debug( 

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

3240 extra={ 

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

3242 "rpcName": "GetIamPolicy", 

3243 "httpResponse": http_response, 

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

3245 }, 

3246 ) 

3247 return resp 

3248 

3249 @property 

3250 def set_iam_policy(self): 

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

3252 

3253 class _SetIamPolicy( 

3254 _BaseSubscriberRestTransport._BaseSetIamPolicy, SubscriberRestStub 

3255 ): 

3256 def __hash__(self): 

3257 return hash("SubscriberRestTransport.SetIamPolicy") 

3258 

3259 @staticmethod 

3260 def _get_response( 

3261 host, 

3262 metadata, 

3263 query_params, 

3264 session, 

3265 timeout, 

3266 transcoded_request, 

3267 body=None, 

3268 ): 

3269 uri = transcoded_request["uri"] 

3270 method = transcoded_request["method"] 

3271 headers = dict(metadata) 

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

3273 response = getattr(session, method)( 

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

3275 timeout=timeout, 

3276 headers=headers, 

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

3278 data=body, 

3279 ) 

3280 return response 

3281 

3282 def __call__( 

3283 self, 

3284 request: iam_policy_pb2.SetIamPolicyRequest, 

3285 *, 

3286 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3287 timeout: Optional[float] = None, 

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

3289 ) -> policy_pb2.Policy: 

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

3291 

3292 Args: 

3293 request (iam_policy_pb2.SetIamPolicyRequest): 

3294 The request object for SetIamPolicy method. 

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

3296 should be retried. 

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

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

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

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

3301 be of type `bytes`. 

3302 

3303 Returns: 

3304 policy_pb2.Policy: Response from SetIamPolicy method. 

3305 """ 

3306 

3307 http_options = ( 

3308 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_http_options() 

3309 ) 

3310 

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

3312 transcoded_request = ( 

3313 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_transcoded_request( 

3314 http_options, request 

3315 ) 

3316 ) 

3317 

3318 body = ( 

3319 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_request_body_json( 

3320 transcoded_request 

3321 ) 

3322 ) 

3323 

3324 # Jsonify the query params 

3325 query_params = ( 

3326 _BaseSubscriberRestTransport._BaseSetIamPolicy._get_query_params_json( 

3327 transcoded_request 

3328 ) 

3329 ) 

3330 

3331 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3332 logging.DEBUG 

3333 ): # pragma: NO COVER 

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

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

3336 ) 

3337 method = transcoded_request["method"] 

3338 try: 

3339 request_payload = json_format.MessageToJson(request) 

3340 except: 

3341 request_payload = None 

3342 http_request = { 

3343 "payload": request_payload, 

3344 "requestMethod": method, 

3345 "requestUrl": request_url, 

3346 "headers": dict(metadata), 

3347 } 

3348 _LOGGER.debug( 

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

3350 extra={ 

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

3352 "rpcName": "SetIamPolicy", 

3353 "httpRequest": http_request, 

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

3355 }, 

3356 ) 

3357 

3358 # Send the request 

3359 response = SubscriberRestTransport._SetIamPolicy._get_response( 

3360 self._host, 

3361 metadata, 

3362 query_params, 

3363 self._session, 

3364 timeout, 

3365 transcoded_request, 

3366 body, 

3367 ) 

3368 

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

3370 # subclass. 

3371 if response.status_code >= 400: 

3372 raise core_exceptions.from_http_response(response) 

3373 

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

3375 resp = policy_pb2.Policy() 

3376 resp = json_format.Parse(content, resp) 

3377 resp = self._interceptor.post_set_iam_policy(resp) 

3378 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3379 logging.DEBUG 

3380 ): # pragma: NO COVER 

3381 try: 

3382 response_payload = json_format.MessageToJson(resp) 

3383 except: 

3384 response_payload = None 

3385 http_response = { 

3386 "payload": response_payload, 

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

3388 "status": response.status_code, 

3389 } 

3390 _LOGGER.debug( 

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

3392 extra={ 

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

3394 "rpcName": "SetIamPolicy", 

3395 "httpResponse": http_response, 

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

3397 }, 

3398 ) 

3399 return resp 

3400 

3401 @property 

3402 def test_iam_permissions(self): 

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

3404 

3405 class _TestIamPermissions( 

3406 _BaseSubscriberRestTransport._BaseTestIamPermissions, SubscriberRestStub 

3407 ): 

3408 def __hash__(self): 

3409 return hash("SubscriberRestTransport.TestIamPermissions") 

3410 

3411 @staticmethod 

3412 def _get_response( 

3413 host, 

3414 metadata, 

3415 query_params, 

3416 session, 

3417 timeout, 

3418 transcoded_request, 

3419 body=None, 

3420 ): 

3421 uri = transcoded_request["uri"] 

3422 method = transcoded_request["method"] 

3423 headers = dict(metadata) 

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

3425 response = getattr(session, method)( 

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

3427 timeout=timeout, 

3428 headers=headers, 

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

3430 data=body, 

3431 ) 

3432 return response 

3433 

3434 def __call__( 

3435 self, 

3436 request: iam_policy_pb2.TestIamPermissionsRequest, 

3437 *, 

3438 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3439 timeout: Optional[float] = None, 

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

3441 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

3443 

3444 Args: 

3445 request (iam_policy_pb2.TestIamPermissionsRequest): 

3446 The request object for TestIamPermissions method. 

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

3448 should be retried. 

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

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

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

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

3453 be of type `bytes`. 

3454 

3455 Returns: 

3456 iam_policy_pb2.TestIamPermissionsResponse: Response from TestIamPermissions method. 

3457 """ 

3458 

3459 http_options = ( 

3460 _BaseSubscriberRestTransport._BaseTestIamPermissions._get_http_options() 

3461 ) 

3462 

3463 request, metadata = self._interceptor.pre_test_iam_permissions( 

3464 request, metadata 

3465 ) 

3466 transcoded_request = _BaseSubscriberRestTransport._BaseTestIamPermissions._get_transcoded_request( 

3467 http_options, request 

3468 ) 

3469 

3470 body = _BaseSubscriberRestTransport._BaseTestIamPermissions._get_request_body_json( 

3471 transcoded_request 

3472 ) 

3473 

3474 # Jsonify the query params 

3475 query_params = _BaseSubscriberRestTransport._BaseTestIamPermissions._get_query_params_json( 

3476 transcoded_request 

3477 ) 

3478 

3479 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3480 logging.DEBUG 

3481 ): # pragma: NO COVER 

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

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

3484 ) 

3485 method = transcoded_request["method"] 

3486 try: 

3487 request_payload = json_format.MessageToJson(request) 

3488 except: 

3489 request_payload = None 

3490 http_request = { 

3491 "payload": request_payload, 

3492 "requestMethod": method, 

3493 "requestUrl": request_url, 

3494 "headers": dict(metadata), 

3495 } 

3496 _LOGGER.debug( 

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

3498 extra={ 

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

3500 "rpcName": "TestIamPermissions", 

3501 "httpRequest": http_request, 

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

3503 }, 

3504 ) 

3505 

3506 # Send the request 

3507 response = SubscriberRestTransport._TestIamPermissions._get_response( 

3508 self._host, 

3509 metadata, 

3510 query_params, 

3511 self._session, 

3512 timeout, 

3513 transcoded_request, 

3514 body, 

3515 ) 

3516 

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

3518 # subclass. 

3519 if response.status_code >= 400: 

3520 raise core_exceptions.from_http_response(response) 

3521 

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

3523 resp = iam_policy_pb2.TestIamPermissionsResponse() 

3524 resp = json_format.Parse(content, resp) 

3525 resp = self._interceptor.post_test_iam_permissions(resp) 

3526 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3527 logging.DEBUG 

3528 ): # pragma: NO COVER 

3529 try: 

3530 response_payload = json_format.MessageToJson(resp) 

3531 except: 

3532 response_payload = None 

3533 http_response = { 

3534 "payload": response_payload, 

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

3536 "status": response.status_code, 

3537 } 

3538 _LOGGER.debug( 

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

3540 extra={ 

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

3542 "rpcName": "TestIamPermissions", 

3543 "httpResponse": http_response, 

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

3545 }, 

3546 ) 

3547 return resp 

3548 

3549 @property 

3550 def kind(self) -> str: 

3551 return "rest" 

3552 

3553 def close(self): 

3554 self._session.close() 

3555 

3556 

3557__all__ = ("SubscriberRestTransport",)