Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/firestore_v1/services/firestore/transports/rest.py: 34%

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

656 statements  

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

2# Copyright 2025 Google LLC 

3# 

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

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

6# You may obtain a copy of the License at 

7# 

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

9# 

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

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

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

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

14# limitations under the License. 

15# 

16import logging 

17import json # type: ignore 

18 

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

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

21from google.api_core import exceptions as core_exceptions 

22from google.api_core import retry as retries 

23from google.api_core import rest_helpers 

24from google.api_core import rest_streaming 

25from google.api_core import gapic_v1 

26import google.protobuf 

27 

28from google.protobuf import json_format 

29from google.cloud.location import locations_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.cloud.firestore_v1.types import document 

38from google.cloud.firestore_v1.types import document as gf_document 

39from google.cloud.firestore_v1.types import firestore 

40from google.protobuf import empty_pb2 # type: ignore 

41from google.longrunning import operations_pb2 # type: ignore 

42 

43 

44from .rest_base import _BaseFirestoreRestTransport 

45from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO 

46 

47try: 

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

49except AttributeError: # pragma: NO COVER 

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

51 

52try: 

53 from google.api_core import client_logging # type: ignore 

54 

55 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

56except ImportError: # pragma: NO COVER 

57 CLIENT_LOGGING_SUPPORTED = False 

58 

59_LOGGER = logging.getLogger(__name__) 

60 

61DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

62 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, 

63 grpc_version=None, 

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

65) 

66 

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

68 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

69 

70 

71class FirestoreRestInterceptor: 

72 """Interceptor for Firestore. 

73 

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

75 in arbitrary ways. 

76 Example use cases include: 

77 * Logging 

78 * Verifying requests according to service or custom semantics 

79 * Stripping extraneous information from responses 

80 

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

82 instance of a custom subclass when constructing the FirestoreRestTransport. 

83 

84 .. code-block:: python 

85 class MyCustomFirestoreInterceptor(FirestoreRestInterceptor): 

86 def pre_batch_get_documents(self, request, metadata): 

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

88 return request, metadata 

89 

90 def post_batch_get_documents(self, response): 

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

92 return response 

93 

94 def pre_batch_write(self, request, metadata): 

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

96 return request, metadata 

97 

98 def post_batch_write(self, response): 

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

100 return response 

101 

102 def pre_begin_transaction(self, request, metadata): 

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

104 return request, metadata 

105 

106 def post_begin_transaction(self, response): 

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

108 return response 

109 

110 def pre_commit(self, request, metadata): 

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

112 return request, metadata 

113 

114 def post_commit(self, response): 

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

116 return response 

117 

118 def pre_create_document(self, request, metadata): 

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

120 return request, metadata 

121 

122 def post_create_document(self, response): 

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

124 return response 

125 

126 def pre_delete_document(self, request, metadata): 

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

128 return request, metadata 

129 

130 def pre_get_document(self, request, metadata): 

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

132 return request, metadata 

133 

134 def post_get_document(self, response): 

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

136 return response 

137 

138 def pre_list_collection_ids(self, request, metadata): 

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

140 return request, metadata 

141 

142 def post_list_collection_ids(self, response): 

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

144 return response 

145 

146 def pre_list_documents(self, request, metadata): 

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

148 return request, metadata 

149 

150 def post_list_documents(self, response): 

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

152 return response 

153 

154 def pre_partition_query(self, request, metadata): 

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

156 return request, metadata 

157 

158 def post_partition_query(self, response): 

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

160 return response 

161 

162 def pre_rollback(self, request, metadata): 

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

164 return request, metadata 

165 

166 def pre_run_aggregation_query(self, request, metadata): 

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

168 return request, metadata 

169 

170 def post_run_aggregation_query(self, response): 

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

172 return response 

173 

174 def pre_run_query(self, request, metadata): 

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

176 return request, metadata 

177 

178 def post_run_query(self, response): 

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

180 return response 

181 

182 def pre_update_document(self, request, metadata): 

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

184 return request, metadata 

185 

186 def post_update_document(self, response): 

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

188 return response 

189 

190 transport = FirestoreRestTransport(interceptor=MyCustomFirestoreInterceptor()) 

191 client = FirestoreClient(transport=transport) 

192 

193 

194 """ 

195 

196 def pre_batch_get_documents( 

197 self, 

198 request: firestore.BatchGetDocumentsRequest, 

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

200 ) -> Tuple[ 

201 firestore.BatchGetDocumentsRequest, Sequence[Tuple[str, Union[str, bytes]]] 

202 ]: 

203 """Pre-rpc interceptor for batch_get_documents 

204 

205 Override in a subclass to manipulate the request or metadata 

206 before they are sent to the Firestore server. 

207 """ 

208 return request, metadata 

209 

210 def post_batch_get_documents( 

211 self, response: rest_streaming.ResponseIterator 

212 ) -> rest_streaming.ResponseIterator: 

213 """Post-rpc interceptor for batch_get_documents 

214 

215 DEPRECATED. Please use the `post_batch_get_documents_with_metadata` 

216 interceptor instead. 

217 

218 Override in a subclass to read or manipulate the response 

219 after it is returned by the Firestore server but before 

220 it is returned to user code. This `post_batch_get_documents` interceptor runs 

221 before the `post_batch_get_documents_with_metadata` interceptor. 

222 """ 

223 return response 

224 

225 def post_batch_get_documents_with_metadata( 

226 self, 

227 response: rest_streaming.ResponseIterator, 

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

229 ) -> Tuple[ 

230 rest_streaming.ResponseIterator, Sequence[Tuple[str, Union[str, bytes]]] 

231 ]: 

232 """Post-rpc interceptor for batch_get_documents 

233 

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

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

236 

237 We recommend only using this `post_batch_get_documents_with_metadata` 

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

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

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

241 `post_batch_get_documents` will be passed to 

242 `post_batch_get_documents_with_metadata`. 

243 """ 

244 return response, metadata 

245 

246 def pre_batch_write( 

247 self, 

248 request: firestore.BatchWriteRequest, 

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

250 ) -> Tuple[firestore.BatchWriteRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

251 """Pre-rpc interceptor for batch_write 

252 

253 Override in a subclass to manipulate the request or metadata 

254 before they are sent to the Firestore server. 

255 """ 

256 return request, metadata 

257 

258 def post_batch_write( 

259 self, response: firestore.BatchWriteResponse 

260 ) -> firestore.BatchWriteResponse: 

261 """Post-rpc interceptor for batch_write 

262 

263 DEPRECATED. Please use the `post_batch_write_with_metadata` 

264 interceptor instead. 

265 

266 Override in a subclass to read or manipulate the response 

267 after it is returned by the Firestore server but before 

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

269 before the `post_batch_write_with_metadata` interceptor. 

270 """ 

271 return response 

272 

273 def post_batch_write_with_metadata( 

274 self, 

275 response: firestore.BatchWriteResponse, 

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

277 ) -> Tuple[firestore.BatchWriteResponse, Sequence[Tuple[str, Union[str, bytes]]]]: 

278 """Post-rpc interceptor for batch_write 

279 

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

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

282 

283 We recommend only using this `post_batch_write_with_metadata` 

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

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

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

287 `post_batch_write` will be passed to 

288 `post_batch_write_with_metadata`. 

289 """ 

290 return response, metadata 

291 

292 def pre_begin_transaction( 

293 self, 

294 request: firestore.BeginTransactionRequest, 

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

296 ) -> Tuple[ 

297 firestore.BeginTransactionRequest, Sequence[Tuple[str, Union[str, bytes]]] 

298 ]: 

299 """Pre-rpc interceptor for begin_transaction 

300 

301 Override in a subclass to manipulate the request or metadata 

302 before they are sent to the Firestore server. 

303 """ 

304 return request, metadata 

305 

306 def post_begin_transaction( 

307 self, response: firestore.BeginTransactionResponse 

308 ) -> firestore.BeginTransactionResponse: 

309 """Post-rpc interceptor for begin_transaction 

310 

311 DEPRECATED. Please use the `post_begin_transaction_with_metadata` 

312 interceptor instead. 

313 

314 Override in a subclass to read or manipulate the response 

315 after it is returned by the Firestore server but before 

316 it is returned to user code. This `post_begin_transaction` interceptor runs 

317 before the `post_begin_transaction_with_metadata` interceptor. 

318 """ 

319 return response 

320 

321 def post_begin_transaction_with_metadata( 

322 self, 

323 response: firestore.BeginTransactionResponse, 

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

325 ) -> Tuple[ 

326 firestore.BeginTransactionResponse, Sequence[Tuple[str, Union[str, bytes]]] 

327 ]: 

328 """Post-rpc interceptor for begin_transaction 

329 

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

331 is returned by the Firestore server but before it is returned to user code. 

332 

333 We recommend only using this `post_begin_transaction_with_metadata` 

334 interceptor in new development instead of the `post_begin_transaction` interceptor. 

335 When both interceptors are used, this `post_begin_transaction_with_metadata` interceptor runs after the 

336 `post_begin_transaction` interceptor. The (possibly modified) response returned by 

337 `post_begin_transaction` will be passed to 

338 `post_begin_transaction_with_metadata`. 

339 """ 

340 return response, metadata 

341 

342 def pre_commit( 

343 self, 

344 request: firestore.CommitRequest, 

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

346 ) -> Tuple[firestore.CommitRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

347 """Pre-rpc interceptor for commit 

348 

349 Override in a subclass to manipulate the request or metadata 

350 before they are sent to the Firestore server. 

351 """ 

352 return request, metadata 

353 

354 def post_commit( 

355 self, response: firestore.CommitResponse 

356 ) -> firestore.CommitResponse: 

357 """Post-rpc interceptor for commit 

358 

359 DEPRECATED. Please use the `post_commit_with_metadata` 

360 interceptor instead. 

361 

362 Override in a subclass to read or manipulate the response 

363 after it is returned by the Firestore server but before 

364 it is returned to user code. This `post_commit` interceptor runs 

365 before the `post_commit_with_metadata` interceptor. 

366 """ 

367 return response 

368 

369 def post_commit_with_metadata( 

370 self, 

371 response: firestore.CommitResponse, 

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

373 ) -> Tuple[firestore.CommitResponse, Sequence[Tuple[str, Union[str, bytes]]]]: 

374 """Post-rpc interceptor for commit 

375 

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

377 is returned by the Firestore server but before it is returned to user code. 

378 

379 We recommend only using this `post_commit_with_metadata` 

380 interceptor in new development instead of the `post_commit` interceptor. 

381 When both interceptors are used, this `post_commit_with_metadata` interceptor runs after the 

382 `post_commit` interceptor. The (possibly modified) response returned by 

383 `post_commit` will be passed to 

384 `post_commit_with_metadata`. 

385 """ 

386 return response, metadata 

387 

388 def pre_create_document( 

389 self, 

390 request: firestore.CreateDocumentRequest, 

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

392 ) -> Tuple[ 

393 firestore.CreateDocumentRequest, Sequence[Tuple[str, Union[str, bytes]]] 

394 ]: 

395 """Pre-rpc interceptor for create_document 

396 

397 Override in a subclass to manipulate the request or metadata 

398 before they are sent to the Firestore server. 

399 """ 

400 return request, metadata 

401 

402 def post_create_document(self, response: document.Document) -> document.Document: 

403 """Post-rpc interceptor for create_document 

404 

405 DEPRECATED. Please use the `post_create_document_with_metadata` 

406 interceptor instead. 

407 

408 Override in a subclass to read or manipulate the response 

409 after it is returned by the Firestore server but before 

410 it is returned to user code. This `post_create_document` interceptor runs 

411 before the `post_create_document_with_metadata` interceptor. 

412 """ 

413 return response 

414 

415 def post_create_document_with_metadata( 

416 self, 

417 response: document.Document, 

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

419 ) -> Tuple[document.Document, Sequence[Tuple[str, Union[str, bytes]]]]: 

420 """Post-rpc interceptor for create_document 

421 

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

423 is returned by the Firestore server but before it is returned to user code. 

424 

425 We recommend only using this `post_create_document_with_metadata` 

426 interceptor in new development instead of the `post_create_document` interceptor. 

427 When both interceptors are used, this `post_create_document_with_metadata` interceptor runs after the 

428 `post_create_document` interceptor. The (possibly modified) response returned by 

429 `post_create_document` will be passed to 

430 `post_create_document_with_metadata`. 

431 """ 

432 return response, metadata 

433 

434 def pre_delete_document( 

435 self, 

436 request: firestore.DeleteDocumentRequest, 

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

438 ) -> Tuple[ 

439 firestore.DeleteDocumentRequest, Sequence[Tuple[str, Union[str, bytes]]] 

440 ]: 

441 """Pre-rpc interceptor for delete_document 

442 

443 Override in a subclass to manipulate the request or metadata 

444 before they are sent to the Firestore server. 

445 """ 

446 return request, metadata 

447 

448 def pre_get_document( 

449 self, 

450 request: firestore.GetDocumentRequest, 

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

452 ) -> Tuple[firestore.GetDocumentRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

453 """Pre-rpc interceptor for get_document 

454 

455 Override in a subclass to manipulate the request or metadata 

456 before they are sent to the Firestore server. 

457 """ 

458 return request, metadata 

459 

460 def post_get_document(self, response: document.Document) -> document.Document: 

461 """Post-rpc interceptor for get_document 

462 

463 DEPRECATED. Please use the `post_get_document_with_metadata` 

464 interceptor instead. 

465 

466 Override in a subclass to read or manipulate the response 

467 after it is returned by the Firestore server but before 

468 it is returned to user code. This `post_get_document` interceptor runs 

469 before the `post_get_document_with_metadata` interceptor. 

470 """ 

471 return response 

472 

473 def post_get_document_with_metadata( 

474 self, 

475 response: document.Document, 

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

477 ) -> Tuple[document.Document, Sequence[Tuple[str, Union[str, bytes]]]]: 

478 """Post-rpc interceptor for get_document 

479 

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

481 is returned by the Firestore server but before it is returned to user code. 

482 

483 We recommend only using this `post_get_document_with_metadata` 

484 interceptor in new development instead of the `post_get_document` interceptor. 

485 When both interceptors are used, this `post_get_document_with_metadata` interceptor runs after the 

486 `post_get_document` interceptor. The (possibly modified) response returned by 

487 `post_get_document` will be passed to 

488 `post_get_document_with_metadata`. 

489 """ 

490 return response, metadata 

491 

492 def pre_list_collection_ids( 

493 self, 

494 request: firestore.ListCollectionIdsRequest, 

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

496 ) -> Tuple[ 

497 firestore.ListCollectionIdsRequest, Sequence[Tuple[str, Union[str, bytes]]] 

498 ]: 

499 """Pre-rpc interceptor for list_collection_ids 

500 

501 Override in a subclass to manipulate the request or metadata 

502 before they are sent to the Firestore server. 

503 """ 

504 return request, metadata 

505 

506 def post_list_collection_ids( 

507 self, response: firestore.ListCollectionIdsResponse 

508 ) -> firestore.ListCollectionIdsResponse: 

509 """Post-rpc interceptor for list_collection_ids 

510 

511 DEPRECATED. Please use the `post_list_collection_ids_with_metadata` 

512 interceptor instead. 

513 

514 Override in a subclass to read or manipulate the response 

515 after it is returned by the Firestore server but before 

516 it is returned to user code. This `post_list_collection_ids` interceptor runs 

517 before the `post_list_collection_ids_with_metadata` interceptor. 

518 """ 

519 return response 

520 

521 def post_list_collection_ids_with_metadata( 

522 self, 

523 response: firestore.ListCollectionIdsResponse, 

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

525 ) -> Tuple[ 

526 firestore.ListCollectionIdsResponse, Sequence[Tuple[str, Union[str, bytes]]] 

527 ]: 

528 """Post-rpc interceptor for list_collection_ids 

529 

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

531 is returned by the Firestore server but before it is returned to user code. 

532 

533 We recommend only using this `post_list_collection_ids_with_metadata` 

534 interceptor in new development instead of the `post_list_collection_ids` interceptor. 

535 When both interceptors are used, this `post_list_collection_ids_with_metadata` interceptor runs after the 

536 `post_list_collection_ids` interceptor. The (possibly modified) response returned by 

537 `post_list_collection_ids` will be passed to 

538 `post_list_collection_ids_with_metadata`. 

539 """ 

540 return response, metadata 

541 

542 def pre_list_documents( 

543 self, 

544 request: firestore.ListDocumentsRequest, 

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

546 ) -> Tuple[firestore.ListDocumentsRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

547 """Pre-rpc interceptor for list_documents 

548 

549 Override in a subclass to manipulate the request or metadata 

550 before they are sent to the Firestore server. 

551 """ 

552 return request, metadata 

553 

554 def post_list_documents( 

555 self, response: firestore.ListDocumentsResponse 

556 ) -> firestore.ListDocumentsResponse: 

557 """Post-rpc interceptor for list_documents 

558 

559 DEPRECATED. Please use the `post_list_documents_with_metadata` 

560 interceptor instead. 

561 

562 Override in a subclass to read or manipulate the response 

563 after it is returned by the Firestore server but before 

564 it is returned to user code. This `post_list_documents` interceptor runs 

565 before the `post_list_documents_with_metadata` interceptor. 

566 """ 

567 return response 

568 

569 def post_list_documents_with_metadata( 

570 self, 

571 response: firestore.ListDocumentsResponse, 

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

573 ) -> Tuple[ 

574 firestore.ListDocumentsResponse, Sequence[Tuple[str, Union[str, bytes]]] 

575 ]: 

576 """Post-rpc interceptor for list_documents 

577 

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

579 is returned by the Firestore server but before it is returned to user code. 

580 

581 We recommend only using this `post_list_documents_with_metadata` 

582 interceptor in new development instead of the `post_list_documents` interceptor. 

583 When both interceptors are used, this `post_list_documents_with_metadata` interceptor runs after the 

584 `post_list_documents` interceptor. The (possibly modified) response returned by 

585 `post_list_documents` will be passed to 

586 `post_list_documents_with_metadata`. 

587 """ 

588 return response, metadata 

589 

590 def pre_partition_query( 

591 self, 

592 request: firestore.PartitionQueryRequest, 

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

594 ) -> Tuple[ 

595 firestore.PartitionQueryRequest, Sequence[Tuple[str, Union[str, bytes]]] 

596 ]: 

597 """Pre-rpc interceptor for partition_query 

598 

599 Override in a subclass to manipulate the request or metadata 

600 before they are sent to the Firestore server. 

601 """ 

602 return request, metadata 

603 

604 def post_partition_query( 

605 self, response: firestore.PartitionQueryResponse 

606 ) -> firestore.PartitionQueryResponse: 

607 """Post-rpc interceptor for partition_query 

608 

609 DEPRECATED. Please use the `post_partition_query_with_metadata` 

610 interceptor instead. 

611 

612 Override in a subclass to read or manipulate the response 

613 after it is returned by the Firestore server but before 

614 it is returned to user code. This `post_partition_query` interceptor runs 

615 before the `post_partition_query_with_metadata` interceptor. 

616 """ 

617 return response 

618 

619 def post_partition_query_with_metadata( 

620 self, 

621 response: firestore.PartitionQueryResponse, 

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

623 ) -> Tuple[ 

624 firestore.PartitionQueryResponse, Sequence[Tuple[str, Union[str, bytes]]] 

625 ]: 

626 """Post-rpc interceptor for partition_query 

627 

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

629 is returned by the Firestore server but before it is returned to user code. 

630 

631 We recommend only using this `post_partition_query_with_metadata` 

632 interceptor in new development instead of the `post_partition_query` interceptor. 

633 When both interceptors are used, this `post_partition_query_with_metadata` interceptor runs after the 

634 `post_partition_query` interceptor. The (possibly modified) response returned by 

635 `post_partition_query` will be passed to 

636 `post_partition_query_with_metadata`. 

637 """ 

638 return response, metadata 

639 

640 def pre_rollback( 

641 self, 

642 request: firestore.RollbackRequest, 

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

644 ) -> Tuple[firestore.RollbackRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

645 """Pre-rpc interceptor for rollback 

646 

647 Override in a subclass to manipulate the request or metadata 

648 before they are sent to the Firestore server. 

649 """ 

650 return request, metadata 

651 

652 def pre_run_aggregation_query( 

653 self, 

654 request: firestore.RunAggregationQueryRequest, 

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

656 ) -> Tuple[ 

657 firestore.RunAggregationQueryRequest, Sequence[Tuple[str, Union[str, bytes]]] 

658 ]: 

659 """Pre-rpc interceptor for run_aggregation_query 

660 

661 Override in a subclass to manipulate the request or metadata 

662 before they are sent to the Firestore server. 

663 """ 

664 return request, metadata 

665 

666 def post_run_aggregation_query( 

667 self, response: rest_streaming.ResponseIterator 

668 ) -> rest_streaming.ResponseIterator: 

669 """Post-rpc interceptor for run_aggregation_query 

670 

671 DEPRECATED. Please use the `post_run_aggregation_query_with_metadata` 

672 interceptor instead. 

673 

674 Override in a subclass to read or manipulate the response 

675 after it is returned by the Firestore server but before 

676 it is returned to user code. This `post_run_aggregation_query` interceptor runs 

677 before the `post_run_aggregation_query_with_metadata` interceptor. 

678 """ 

679 return response 

680 

681 def post_run_aggregation_query_with_metadata( 

682 self, 

683 response: rest_streaming.ResponseIterator, 

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

685 ) -> Tuple[ 

686 rest_streaming.ResponseIterator, Sequence[Tuple[str, Union[str, bytes]]] 

687 ]: 

688 """Post-rpc interceptor for run_aggregation_query 

689 

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

691 is returned by the Firestore server but before it is returned to user code. 

692 

693 We recommend only using this `post_run_aggregation_query_with_metadata` 

694 interceptor in new development instead of the `post_run_aggregation_query` interceptor. 

695 When both interceptors are used, this `post_run_aggregation_query_with_metadata` interceptor runs after the 

696 `post_run_aggregation_query` interceptor. The (possibly modified) response returned by 

697 `post_run_aggregation_query` will be passed to 

698 `post_run_aggregation_query_with_metadata`. 

699 """ 

700 return response, metadata 

701 

702 def pre_run_query( 

703 self, 

704 request: firestore.RunQueryRequest, 

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

706 ) -> Tuple[firestore.RunQueryRequest, Sequence[Tuple[str, Union[str, bytes]]]]: 

707 """Pre-rpc interceptor for run_query 

708 

709 Override in a subclass to manipulate the request or metadata 

710 before they are sent to the Firestore server. 

711 """ 

712 return request, metadata 

713 

714 def post_run_query( 

715 self, response: rest_streaming.ResponseIterator 

716 ) -> rest_streaming.ResponseIterator: 

717 """Post-rpc interceptor for run_query 

718 

719 DEPRECATED. Please use the `post_run_query_with_metadata` 

720 interceptor instead. 

721 

722 Override in a subclass to read or manipulate the response 

723 after it is returned by the Firestore server but before 

724 it is returned to user code. This `post_run_query` interceptor runs 

725 before the `post_run_query_with_metadata` interceptor. 

726 """ 

727 return response 

728 

729 def post_run_query_with_metadata( 

730 self, 

731 response: rest_streaming.ResponseIterator, 

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

733 ) -> Tuple[ 

734 rest_streaming.ResponseIterator, Sequence[Tuple[str, Union[str, bytes]]] 

735 ]: 

736 """Post-rpc interceptor for run_query 

737 

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

739 is returned by the Firestore server but before it is returned to user code. 

740 

741 We recommend only using this `post_run_query_with_metadata` 

742 interceptor in new development instead of the `post_run_query` interceptor. 

743 When both interceptors are used, this `post_run_query_with_metadata` interceptor runs after the 

744 `post_run_query` interceptor. The (possibly modified) response returned by 

745 `post_run_query` will be passed to 

746 `post_run_query_with_metadata`. 

747 """ 

748 return response, metadata 

749 

750 def pre_update_document( 

751 self, 

752 request: firestore.UpdateDocumentRequest, 

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

754 ) -> Tuple[ 

755 firestore.UpdateDocumentRequest, Sequence[Tuple[str, Union[str, bytes]]] 

756 ]: 

757 """Pre-rpc interceptor for update_document 

758 

759 Override in a subclass to manipulate the request or metadata 

760 before they are sent to the Firestore server. 

761 """ 

762 return request, metadata 

763 

764 def post_update_document( 

765 self, response: gf_document.Document 

766 ) -> gf_document.Document: 

767 """Post-rpc interceptor for update_document 

768 

769 DEPRECATED. Please use the `post_update_document_with_metadata` 

770 interceptor instead. 

771 

772 Override in a subclass to read or manipulate the response 

773 after it is returned by the Firestore server but before 

774 it is returned to user code. This `post_update_document` interceptor runs 

775 before the `post_update_document_with_metadata` interceptor. 

776 """ 

777 return response 

778 

779 def post_update_document_with_metadata( 

780 self, 

781 response: gf_document.Document, 

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

783 ) -> Tuple[gf_document.Document, Sequence[Tuple[str, Union[str, bytes]]]]: 

784 """Post-rpc interceptor for update_document 

785 

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

787 is returned by the Firestore server but before it is returned to user code. 

788 

789 We recommend only using this `post_update_document_with_metadata` 

790 interceptor in new development instead of the `post_update_document` interceptor. 

791 When both interceptors are used, this `post_update_document_with_metadata` interceptor runs after the 

792 `post_update_document` interceptor. The (possibly modified) response returned by 

793 `post_update_document` will be passed to 

794 `post_update_document_with_metadata`. 

795 """ 

796 return response, metadata 

797 

798 def pre_cancel_operation( 

799 self, 

800 request: operations_pb2.CancelOperationRequest, 

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

802 ) -> Tuple[ 

803 operations_pb2.CancelOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] 

804 ]: 

805 """Pre-rpc interceptor for cancel_operation 

806 

807 Override in a subclass to manipulate the request or metadata 

808 before they are sent to the Firestore server. 

809 """ 

810 return request, metadata 

811 

812 def post_cancel_operation(self, response: None) -> None: 

813 """Post-rpc interceptor for cancel_operation 

814 

815 Override in a subclass to manipulate the response 

816 after it is returned by the Firestore server but before 

817 it is returned to user code. 

818 """ 

819 return response 

820 

821 def pre_delete_operation( 

822 self, 

823 request: operations_pb2.DeleteOperationRequest, 

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

825 ) -> Tuple[ 

826 operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] 

827 ]: 

828 """Pre-rpc interceptor for delete_operation 

829 

830 Override in a subclass to manipulate the request or metadata 

831 before they are sent to the Firestore server. 

832 """ 

833 return request, metadata 

834 

835 def post_delete_operation(self, response: None) -> None: 

836 """Post-rpc interceptor for delete_operation 

837 

838 Override in a subclass to manipulate the response 

839 after it is returned by the Firestore server but before 

840 it is returned to user code. 

841 """ 

842 return response 

843 

844 def pre_get_operation( 

845 self, 

846 request: operations_pb2.GetOperationRequest, 

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

848 ) -> Tuple[ 

849 operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] 

850 ]: 

851 """Pre-rpc interceptor for get_operation 

852 

853 Override in a subclass to manipulate the request or metadata 

854 before they are sent to the Firestore server. 

855 """ 

856 return request, metadata 

857 

858 def post_get_operation( 

859 self, response: operations_pb2.Operation 

860 ) -> operations_pb2.Operation: 

861 """Post-rpc interceptor for get_operation 

862 

863 Override in a subclass to manipulate the response 

864 after it is returned by the Firestore server but before 

865 it is returned to user code. 

866 """ 

867 return response 

868 

869 def pre_list_operations( 

870 self, 

871 request: operations_pb2.ListOperationsRequest, 

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

873 ) -> Tuple[ 

874 operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]] 

875 ]: 

876 """Pre-rpc interceptor for list_operations 

877 

878 Override in a subclass to manipulate the request or metadata 

879 before they are sent to the Firestore server. 

880 """ 

881 return request, metadata 

882 

883 def post_list_operations( 

884 self, response: operations_pb2.ListOperationsResponse 

885 ) -> operations_pb2.ListOperationsResponse: 

886 """Post-rpc interceptor for list_operations 

887 

888 Override in a subclass to manipulate the response 

889 after it is returned by the Firestore server but before 

890 it is returned to user code. 

891 """ 

892 return response 

893 

894 

895@dataclasses.dataclass 

896class FirestoreRestStub: 

897 _session: AuthorizedSession 

898 _host: str 

899 _interceptor: FirestoreRestInterceptor 

900 

901 

902class FirestoreRestTransport(_BaseFirestoreRestTransport): 

903 """REST backend synchronous transport for Firestore. 

904 

905 The Cloud Firestore service. 

906 

907 Cloud Firestore is a fast, fully managed, serverless, 

908 cloud-native NoSQL document database that simplifies storing, 

909 syncing, and querying data for your mobile, web, and IoT apps at 

910 global scale. Its client libraries provide live synchronization 

911 and offline support, while its security features and 

912 integrations with Firebase and Google Cloud Platform accelerate 

913 building truly serverless apps. 

914 

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

916 primary client can load the underlying transport implementation 

917 and call it. 

918 

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

920 """ 

921 

922 def __init__( 

923 self, 

924 *, 

925 host: str = "firestore.googleapis.com", 

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

927 credentials_file: Optional[str] = None, 

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

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

930 quota_project_id: Optional[str] = None, 

931 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

932 always_use_jwt_access: Optional[bool] = False, 

933 url_scheme: str = "https", 

934 interceptor: Optional[FirestoreRestInterceptor] = None, 

935 api_audience: Optional[str] = None, 

936 ) -> None: 

937 """Instantiate the transport. 

938 

939 Args: 

940 host (Optional[str]): 

941 The hostname to connect to (default: 'firestore.googleapis.com'). 

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

943 authorization credentials to attach to requests. These 

944 credentials identify the application to the service; if none 

945 are specified, the client will attempt to ascertain the 

946 credentials from the environment. 

947 

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

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

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

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

952 ignored if ``channel`` is provided. 

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

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

955 if ``channel`` is provided. 

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

957 and quota. 

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

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

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

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

962 your own client library. 

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

964 be used for service account credentials. 

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

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

967 "http" can be specified. 

968 """ 

969 # Run the base constructor 

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

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

972 # credentials object 

973 super().__init__( 

974 host=host, 

975 credentials=credentials, 

976 client_info=client_info, 

977 always_use_jwt_access=always_use_jwt_access, 

978 url_scheme=url_scheme, 

979 api_audience=api_audience, 

980 ) 

981 self._session = AuthorizedSession( 

982 self._credentials, default_host=self.DEFAULT_HOST 

983 ) 

984 if client_cert_source_for_mtls: 

985 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

986 self._interceptor = interceptor or FirestoreRestInterceptor() 

987 self._prep_wrapped_messages(client_info) 

988 

989 class _BatchGetDocuments( 

990 _BaseFirestoreRestTransport._BaseBatchGetDocuments, FirestoreRestStub 

991 ): 

992 def __hash__(self): 

993 return hash("FirestoreRestTransport.BatchGetDocuments") 

994 

995 @staticmethod 

996 def _get_response( 

997 host, 

998 metadata, 

999 query_params, 

1000 session, 

1001 timeout, 

1002 transcoded_request, 

1003 body=None, 

1004 ): 

1005 uri = transcoded_request["uri"] 

1006 method = transcoded_request["method"] 

1007 headers = dict(metadata) 

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

1009 response = getattr(session, method)( 

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

1011 timeout=timeout, 

1012 headers=headers, 

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

1014 data=body, 

1015 stream=True, 

1016 ) 

1017 return response 

1018 

1019 def __call__( 

1020 self, 

1021 request: firestore.BatchGetDocumentsRequest, 

1022 *, 

1023 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1024 timeout: Optional[float] = None, 

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

1026 ) -> rest_streaming.ResponseIterator: 

1027 r"""Call the batch get documents method over HTTP. 

1028 

1029 Args: 

1030 request (~.firestore.BatchGetDocumentsRequest): 

1031 The request object. The request for 

1032 [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments]. 

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

1034 should be retried. 

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

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

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

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

1039 be of type `bytes`. 

1040 

1041 Returns: 

1042 ~.firestore.BatchGetDocumentsResponse: 

1043 The streamed response for 

1044 [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments]. 

1045 

1046 """ 

1047 

1048 http_options = ( 

1049 _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_http_options() 

1050 ) 

1051 

1052 request, metadata = self._interceptor.pre_batch_get_documents( 

1053 request, metadata 

1054 ) 

1055 transcoded_request = _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_transcoded_request( 

1056 http_options, request 

1057 ) 

1058 

1059 body = _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_request_body_json( 

1060 transcoded_request 

1061 ) 

1062 

1063 # Jsonify the query params 

1064 query_params = _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_query_params_json( 

1065 transcoded_request 

1066 ) 

1067 

1068 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1069 logging.DEBUG 

1070 ): # pragma: NO COVER 

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

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

1073 ) 

1074 method = transcoded_request["method"] 

1075 try: 

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

1077 except: 

1078 request_payload = None 

1079 http_request = { 

1080 "payload": request_payload, 

1081 "requestMethod": method, 

1082 "requestUrl": request_url, 

1083 "headers": dict(metadata), 

1084 } 

1085 _LOGGER.debug( 

1086 f"Sending request for google.firestore_v1.FirestoreClient.BatchGetDocuments", 

1087 extra={ 

1088 "serviceName": "google.firestore.v1.Firestore", 

1089 "rpcName": "BatchGetDocuments", 

1090 "httpRequest": http_request, 

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

1092 }, 

1093 ) 

1094 

1095 # Send the request 

1096 response = FirestoreRestTransport._BatchGetDocuments._get_response( 

1097 self._host, 

1098 metadata, 

1099 query_params, 

1100 self._session, 

1101 timeout, 

1102 transcoded_request, 

1103 body, 

1104 ) 

1105 

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

1107 # subclass. 

1108 if response.status_code >= 400: 

1109 raise core_exceptions.from_http_response(response) 

1110 

1111 # Return the response 

1112 resp = rest_streaming.ResponseIterator( 

1113 response, firestore.BatchGetDocumentsResponse 

1114 ) 

1115 

1116 resp = self._interceptor.post_batch_get_documents(resp) 

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

1118 resp, _ = self._interceptor.post_batch_get_documents_with_metadata( 

1119 resp, response_metadata 

1120 ) 

1121 return resp 

1122 

1123 class _BatchWrite(_BaseFirestoreRestTransport._BaseBatchWrite, FirestoreRestStub): 

1124 def __hash__(self): 

1125 return hash("FirestoreRestTransport.BatchWrite") 

1126 

1127 @staticmethod 

1128 def _get_response( 

1129 host, 

1130 metadata, 

1131 query_params, 

1132 session, 

1133 timeout, 

1134 transcoded_request, 

1135 body=None, 

1136 ): 

1137 uri = transcoded_request["uri"] 

1138 method = transcoded_request["method"] 

1139 headers = dict(metadata) 

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

1141 response = getattr(session, method)( 

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

1143 timeout=timeout, 

1144 headers=headers, 

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

1146 data=body, 

1147 ) 

1148 return response 

1149 

1150 def __call__( 

1151 self, 

1152 request: firestore.BatchWriteRequest, 

1153 *, 

1154 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1155 timeout: Optional[float] = None, 

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

1157 ) -> firestore.BatchWriteResponse: 

1158 r"""Call the batch write method over HTTP. 

1159 

1160 Args: 

1161 request (~.firestore.BatchWriteRequest): 

1162 The request object. The request for 

1163 [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite]. 

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

1165 should be retried. 

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

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

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

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

1170 be of type `bytes`. 

1171 

1172 Returns: 

1173 ~.firestore.BatchWriteResponse: 

1174 The response from 

1175 [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite]. 

1176 

1177 """ 

1178 

1179 http_options = ( 

1180 _BaseFirestoreRestTransport._BaseBatchWrite._get_http_options() 

1181 ) 

1182 

1183 request, metadata = self._interceptor.pre_batch_write(request, metadata) 

1184 transcoded_request = ( 

1185 _BaseFirestoreRestTransport._BaseBatchWrite._get_transcoded_request( 

1186 http_options, request 

1187 ) 

1188 ) 

1189 

1190 body = _BaseFirestoreRestTransport._BaseBatchWrite._get_request_body_json( 

1191 transcoded_request 

1192 ) 

1193 

1194 # Jsonify the query params 

1195 query_params = ( 

1196 _BaseFirestoreRestTransport._BaseBatchWrite._get_query_params_json( 

1197 transcoded_request 

1198 ) 

1199 ) 

1200 

1201 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1202 logging.DEBUG 

1203 ): # pragma: NO COVER 

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

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

1206 ) 

1207 method = transcoded_request["method"] 

1208 try: 

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

1210 except: 

1211 request_payload = None 

1212 http_request = { 

1213 "payload": request_payload, 

1214 "requestMethod": method, 

1215 "requestUrl": request_url, 

1216 "headers": dict(metadata), 

1217 } 

1218 _LOGGER.debug( 

1219 f"Sending request for google.firestore_v1.FirestoreClient.BatchWrite", 

1220 extra={ 

1221 "serviceName": "google.firestore.v1.Firestore", 

1222 "rpcName": "BatchWrite", 

1223 "httpRequest": http_request, 

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

1225 }, 

1226 ) 

1227 

1228 # Send the request 

1229 response = FirestoreRestTransport._BatchWrite._get_response( 

1230 self._host, 

1231 metadata, 

1232 query_params, 

1233 self._session, 

1234 timeout, 

1235 transcoded_request, 

1236 body, 

1237 ) 

1238 

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

1240 # subclass. 

1241 if response.status_code >= 400: 

1242 raise core_exceptions.from_http_response(response) 

1243 

1244 # Return the response 

1245 resp = firestore.BatchWriteResponse() 

1246 pb_resp = firestore.BatchWriteResponse.pb(resp) 

1247 

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

1249 

1250 resp = self._interceptor.post_batch_write(resp) 

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

1252 resp, _ = self._interceptor.post_batch_write_with_metadata( 

1253 resp, response_metadata 

1254 ) 

1255 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1256 logging.DEBUG 

1257 ): # pragma: NO COVER 

1258 try: 

1259 response_payload = firestore.BatchWriteResponse.to_json(response) 

1260 except: 

1261 response_payload = None 

1262 http_response = { 

1263 "payload": response_payload, 

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

1265 "status": response.status_code, 

1266 } 

1267 _LOGGER.debug( 

1268 "Received response for google.firestore_v1.FirestoreClient.batch_write", 

1269 extra={ 

1270 "serviceName": "google.firestore.v1.Firestore", 

1271 "rpcName": "BatchWrite", 

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

1273 "httpResponse": http_response, 

1274 }, 

1275 ) 

1276 return resp 

1277 

1278 class _BeginTransaction( 

1279 _BaseFirestoreRestTransport._BaseBeginTransaction, FirestoreRestStub 

1280 ): 

1281 def __hash__(self): 

1282 return hash("FirestoreRestTransport.BeginTransaction") 

1283 

1284 @staticmethod 

1285 def _get_response( 

1286 host, 

1287 metadata, 

1288 query_params, 

1289 session, 

1290 timeout, 

1291 transcoded_request, 

1292 body=None, 

1293 ): 

1294 uri = transcoded_request["uri"] 

1295 method = transcoded_request["method"] 

1296 headers = dict(metadata) 

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

1298 response = getattr(session, method)( 

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

1300 timeout=timeout, 

1301 headers=headers, 

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

1303 data=body, 

1304 ) 

1305 return response 

1306 

1307 def __call__( 

1308 self, 

1309 request: firestore.BeginTransactionRequest, 

1310 *, 

1311 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1312 timeout: Optional[float] = None, 

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

1314 ) -> firestore.BeginTransactionResponse: 

1315 r"""Call the begin transaction method over HTTP. 

1316 

1317 Args: 

1318 request (~.firestore.BeginTransactionRequest): 

1319 The request object. The request for 

1320 [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction]. 

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

1322 should be retried. 

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

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

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

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

1327 be of type `bytes`. 

1328 

1329 Returns: 

1330 ~.firestore.BeginTransactionResponse: 

1331 The response for 

1332 [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction]. 

1333 

1334 """ 

1335 

1336 http_options = ( 

1337 _BaseFirestoreRestTransport._BaseBeginTransaction._get_http_options() 

1338 ) 

1339 

1340 request, metadata = self._interceptor.pre_begin_transaction( 

1341 request, metadata 

1342 ) 

1343 transcoded_request = _BaseFirestoreRestTransport._BaseBeginTransaction._get_transcoded_request( 

1344 http_options, request 

1345 ) 

1346 

1347 body = _BaseFirestoreRestTransport._BaseBeginTransaction._get_request_body_json( 

1348 transcoded_request 

1349 ) 

1350 

1351 # Jsonify the query params 

1352 query_params = _BaseFirestoreRestTransport._BaseBeginTransaction._get_query_params_json( 

1353 transcoded_request 

1354 ) 

1355 

1356 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1357 logging.DEBUG 

1358 ): # pragma: NO COVER 

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

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

1361 ) 

1362 method = transcoded_request["method"] 

1363 try: 

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

1365 except: 

1366 request_payload = None 

1367 http_request = { 

1368 "payload": request_payload, 

1369 "requestMethod": method, 

1370 "requestUrl": request_url, 

1371 "headers": dict(metadata), 

1372 } 

1373 _LOGGER.debug( 

1374 f"Sending request for google.firestore_v1.FirestoreClient.BeginTransaction", 

1375 extra={ 

1376 "serviceName": "google.firestore.v1.Firestore", 

1377 "rpcName": "BeginTransaction", 

1378 "httpRequest": http_request, 

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

1380 }, 

1381 ) 

1382 

1383 # Send the request 

1384 response = FirestoreRestTransport._BeginTransaction._get_response( 

1385 self._host, 

1386 metadata, 

1387 query_params, 

1388 self._session, 

1389 timeout, 

1390 transcoded_request, 

1391 body, 

1392 ) 

1393 

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

1395 # subclass. 

1396 if response.status_code >= 400: 

1397 raise core_exceptions.from_http_response(response) 

1398 

1399 # Return the response 

1400 resp = firestore.BeginTransactionResponse() 

1401 pb_resp = firestore.BeginTransactionResponse.pb(resp) 

1402 

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

1404 

1405 resp = self._interceptor.post_begin_transaction(resp) 

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

1407 resp, _ = self._interceptor.post_begin_transaction_with_metadata( 

1408 resp, response_metadata 

1409 ) 

1410 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1411 logging.DEBUG 

1412 ): # pragma: NO COVER 

1413 try: 

1414 response_payload = firestore.BeginTransactionResponse.to_json( 

1415 response 

1416 ) 

1417 except: 

1418 response_payload = None 

1419 http_response = { 

1420 "payload": response_payload, 

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

1422 "status": response.status_code, 

1423 } 

1424 _LOGGER.debug( 

1425 "Received response for google.firestore_v1.FirestoreClient.begin_transaction", 

1426 extra={ 

1427 "serviceName": "google.firestore.v1.Firestore", 

1428 "rpcName": "BeginTransaction", 

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

1430 "httpResponse": http_response, 

1431 }, 

1432 ) 

1433 return resp 

1434 

1435 class _Commit(_BaseFirestoreRestTransport._BaseCommit, FirestoreRestStub): 

1436 def __hash__(self): 

1437 return hash("FirestoreRestTransport.Commit") 

1438 

1439 @staticmethod 

1440 def _get_response( 

1441 host, 

1442 metadata, 

1443 query_params, 

1444 session, 

1445 timeout, 

1446 transcoded_request, 

1447 body=None, 

1448 ): 

1449 uri = transcoded_request["uri"] 

1450 method = transcoded_request["method"] 

1451 headers = dict(metadata) 

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

1453 response = getattr(session, method)( 

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

1455 timeout=timeout, 

1456 headers=headers, 

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

1458 data=body, 

1459 ) 

1460 return response 

1461 

1462 def __call__( 

1463 self, 

1464 request: firestore.CommitRequest, 

1465 *, 

1466 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1467 timeout: Optional[float] = None, 

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

1469 ) -> firestore.CommitResponse: 

1470 r"""Call the commit method over HTTP. 

1471 

1472 Args: 

1473 request (~.firestore.CommitRequest): 

1474 The request object. The request for 

1475 [Firestore.Commit][google.firestore.v1.Firestore.Commit]. 

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

1477 should be retried. 

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

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

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

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

1482 be of type `bytes`. 

1483 

1484 Returns: 

1485 ~.firestore.CommitResponse: 

1486 The response for 

1487 [Firestore.Commit][google.firestore.v1.Firestore.Commit]. 

1488 

1489 """ 

1490 

1491 http_options = _BaseFirestoreRestTransport._BaseCommit._get_http_options() 

1492 

1493 request, metadata = self._interceptor.pre_commit(request, metadata) 

1494 transcoded_request = ( 

1495 _BaseFirestoreRestTransport._BaseCommit._get_transcoded_request( 

1496 http_options, request 

1497 ) 

1498 ) 

1499 

1500 body = _BaseFirestoreRestTransport._BaseCommit._get_request_body_json( 

1501 transcoded_request 

1502 ) 

1503 

1504 # Jsonify the query params 

1505 query_params = ( 

1506 _BaseFirestoreRestTransport._BaseCommit._get_query_params_json( 

1507 transcoded_request 

1508 ) 

1509 ) 

1510 

1511 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1512 logging.DEBUG 

1513 ): # pragma: NO COVER 

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

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

1516 ) 

1517 method = transcoded_request["method"] 

1518 try: 

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

1520 except: 

1521 request_payload = None 

1522 http_request = { 

1523 "payload": request_payload, 

1524 "requestMethod": method, 

1525 "requestUrl": request_url, 

1526 "headers": dict(metadata), 

1527 } 

1528 _LOGGER.debug( 

1529 f"Sending request for google.firestore_v1.FirestoreClient.Commit", 

1530 extra={ 

1531 "serviceName": "google.firestore.v1.Firestore", 

1532 "rpcName": "Commit", 

1533 "httpRequest": http_request, 

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

1535 }, 

1536 ) 

1537 

1538 # Send the request 

1539 response = FirestoreRestTransport._Commit._get_response( 

1540 self._host, 

1541 metadata, 

1542 query_params, 

1543 self._session, 

1544 timeout, 

1545 transcoded_request, 

1546 body, 

1547 ) 

1548 

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

1550 # subclass. 

1551 if response.status_code >= 400: 

1552 raise core_exceptions.from_http_response(response) 

1553 

1554 # Return the response 

1555 resp = firestore.CommitResponse() 

1556 pb_resp = firestore.CommitResponse.pb(resp) 

1557 

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

1559 

1560 resp = self._interceptor.post_commit(resp) 

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

1562 resp, _ = self._interceptor.post_commit_with_metadata( 

1563 resp, response_metadata 

1564 ) 

1565 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1566 logging.DEBUG 

1567 ): # pragma: NO COVER 

1568 try: 

1569 response_payload = firestore.CommitResponse.to_json(response) 

1570 except: 

1571 response_payload = None 

1572 http_response = { 

1573 "payload": response_payload, 

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

1575 "status": response.status_code, 

1576 } 

1577 _LOGGER.debug( 

1578 "Received response for google.firestore_v1.FirestoreClient.commit", 

1579 extra={ 

1580 "serviceName": "google.firestore.v1.Firestore", 

1581 "rpcName": "Commit", 

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

1583 "httpResponse": http_response, 

1584 }, 

1585 ) 

1586 return resp 

1587 

1588 class _CreateDocument( 

1589 _BaseFirestoreRestTransport._BaseCreateDocument, FirestoreRestStub 

1590 ): 

1591 def __hash__(self): 

1592 return hash("FirestoreRestTransport.CreateDocument") 

1593 

1594 @staticmethod 

1595 def _get_response( 

1596 host, 

1597 metadata, 

1598 query_params, 

1599 session, 

1600 timeout, 

1601 transcoded_request, 

1602 body=None, 

1603 ): 

1604 uri = transcoded_request["uri"] 

1605 method = transcoded_request["method"] 

1606 headers = dict(metadata) 

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

1608 response = getattr(session, method)( 

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

1610 timeout=timeout, 

1611 headers=headers, 

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

1613 data=body, 

1614 ) 

1615 return response 

1616 

1617 def __call__( 

1618 self, 

1619 request: firestore.CreateDocumentRequest, 

1620 *, 

1621 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1622 timeout: Optional[float] = None, 

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

1624 ) -> document.Document: 

1625 r"""Call the create document method over HTTP. 

1626 

1627 Args: 

1628 request (~.firestore.CreateDocumentRequest): 

1629 The request object. The request for 

1630 [Firestore.CreateDocument][google.firestore.v1.Firestore.CreateDocument]. 

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

1632 should be retried. 

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

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

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

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

1637 be of type `bytes`. 

1638 

1639 Returns: 

1640 ~.document.Document: 

1641 A Firestore document. 

1642 

1643 Must not exceed 1 MiB - 4 bytes. 

1644 

1645 """ 

1646 

1647 http_options = ( 

1648 _BaseFirestoreRestTransport._BaseCreateDocument._get_http_options() 

1649 ) 

1650 

1651 request, metadata = self._interceptor.pre_create_document(request, metadata) 

1652 transcoded_request = ( 

1653 _BaseFirestoreRestTransport._BaseCreateDocument._get_transcoded_request( 

1654 http_options, request 

1655 ) 

1656 ) 

1657 

1658 body = ( 

1659 _BaseFirestoreRestTransport._BaseCreateDocument._get_request_body_json( 

1660 transcoded_request 

1661 ) 

1662 ) 

1663 

1664 # Jsonify the query params 

1665 query_params = ( 

1666 _BaseFirestoreRestTransport._BaseCreateDocument._get_query_params_json( 

1667 transcoded_request 

1668 ) 

1669 ) 

1670 

1671 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1672 logging.DEBUG 

1673 ): # pragma: NO COVER 

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

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

1676 ) 

1677 method = transcoded_request["method"] 

1678 try: 

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

1680 except: 

1681 request_payload = None 

1682 http_request = { 

1683 "payload": request_payload, 

1684 "requestMethod": method, 

1685 "requestUrl": request_url, 

1686 "headers": dict(metadata), 

1687 } 

1688 _LOGGER.debug( 

1689 f"Sending request for google.firestore_v1.FirestoreClient.CreateDocument", 

1690 extra={ 

1691 "serviceName": "google.firestore.v1.Firestore", 

1692 "rpcName": "CreateDocument", 

1693 "httpRequest": http_request, 

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

1695 }, 

1696 ) 

1697 

1698 # Send the request 

1699 response = FirestoreRestTransport._CreateDocument._get_response( 

1700 self._host, 

1701 metadata, 

1702 query_params, 

1703 self._session, 

1704 timeout, 

1705 transcoded_request, 

1706 body, 

1707 ) 

1708 

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

1710 # subclass. 

1711 if response.status_code >= 400: 

1712 raise core_exceptions.from_http_response(response) 

1713 

1714 # Return the response 

1715 resp = document.Document() 

1716 pb_resp = document.Document.pb(resp) 

1717 

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

1719 

1720 resp = self._interceptor.post_create_document(resp) 

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

1722 resp, _ = self._interceptor.post_create_document_with_metadata( 

1723 resp, response_metadata 

1724 ) 

1725 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1726 logging.DEBUG 

1727 ): # pragma: NO COVER 

1728 try: 

1729 response_payload = document.Document.to_json(response) 

1730 except: 

1731 response_payload = None 

1732 http_response = { 

1733 "payload": response_payload, 

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

1735 "status": response.status_code, 

1736 } 

1737 _LOGGER.debug( 

1738 "Received response for google.firestore_v1.FirestoreClient.create_document", 

1739 extra={ 

1740 "serviceName": "google.firestore.v1.Firestore", 

1741 "rpcName": "CreateDocument", 

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

1743 "httpResponse": http_response, 

1744 }, 

1745 ) 

1746 return resp 

1747 

1748 class _DeleteDocument( 

1749 _BaseFirestoreRestTransport._BaseDeleteDocument, FirestoreRestStub 

1750 ): 

1751 def __hash__(self): 

1752 return hash("FirestoreRestTransport.DeleteDocument") 

1753 

1754 @staticmethod 

1755 def _get_response( 

1756 host, 

1757 metadata, 

1758 query_params, 

1759 session, 

1760 timeout, 

1761 transcoded_request, 

1762 body=None, 

1763 ): 

1764 uri = transcoded_request["uri"] 

1765 method = transcoded_request["method"] 

1766 headers = dict(metadata) 

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

1768 response = getattr(session, method)( 

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

1770 timeout=timeout, 

1771 headers=headers, 

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

1773 ) 

1774 return response 

1775 

1776 def __call__( 

1777 self, 

1778 request: firestore.DeleteDocumentRequest, 

1779 *, 

1780 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1781 timeout: Optional[float] = None, 

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

1783 ): 

1784 r"""Call the delete document method over HTTP. 

1785 

1786 Args: 

1787 request (~.firestore.DeleteDocumentRequest): 

1788 The request object. The request for 

1789 [Firestore.DeleteDocument][google.firestore.v1.Firestore.DeleteDocument]. 

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

1791 should be retried. 

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

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

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

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

1796 be of type `bytes`. 

1797 """ 

1798 

1799 http_options = ( 

1800 _BaseFirestoreRestTransport._BaseDeleteDocument._get_http_options() 

1801 ) 

1802 

1803 request, metadata = self._interceptor.pre_delete_document(request, metadata) 

1804 transcoded_request = ( 

1805 _BaseFirestoreRestTransport._BaseDeleteDocument._get_transcoded_request( 

1806 http_options, request 

1807 ) 

1808 ) 

1809 

1810 # Jsonify the query params 

1811 query_params = ( 

1812 _BaseFirestoreRestTransport._BaseDeleteDocument._get_query_params_json( 

1813 transcoded_request 

1814 ) 

1815 ) 

1816 

1817 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1818 logging.DEBUG 

1819 ): # pragma: NO COVER 

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

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

1822 ) 

1823 method = transcoded_request["method"] 

1824 try: 

1825 request_payload = json_format.MessageToJson(request) 

1826 except: 

1827 request_payload = None 

1828 http_request = { 

1829 "payload": request_payload, 

1830 "requestMethod": method, 

1831 "requestUrl": request_url, 

1832 "headers": dict(metadata), 

1833 } 

1834 _LOGGER.debug( 

1835 f"Sending request for google.firestore_v1.FirestoreClient.DeleteDocument", 

1836 extra={ 

1837 "serviceName": "google.firestore.v1.Firestore", 

1838 "rpcName": "DeleteDocument", 

1839 "httpRequest": http_request, 

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

1841 }, 

1842 ) 

1843 

1844 # Send the request 

1845 response = FirestoreRestTransport._DeleteDocument._get_response( 

1846 self._host, 

1847 metadata, 

1848 query_params, 

1849 self._session, 

1850 timeout, 

1851 transcoded_request, 

1852 ) 

1853 

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

1855 # subclass. 

1856 if response.status_code >= 400: 

1857 raise core_exceptions.from_http_response(response) 

1858 

1859 class _GetDocument(_BaseFirestoreRestTransport._BaseGetDocument, FirestoreRestStub): 

1860 def __hash__(self): 

1861 return hash("FirestoreRestTransport.GetDocument") 

1862 

1863 @staticmethod 

1864 def _get_response( 

1865 host, 

1866 metadata, 

1867 query_params, 

1868 session, 

1869 timeout, 

1870 transcoded_request, 

1871 body=None, 

1872 ): 

1873 uri = transcoded_request["uri"] 

1874 method = transcoded_request["method"] 

1875 headers = dict(metadata) 

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

1877 response = getattr(session, method)( 

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

1879 timeout=timeout, 

1880 headers=headers, 

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

1882 ) 

1883 return response 

1884 

1885 def __call__( 

1886 self, 

1887 request: firestore.GetDocumentRequest, 

1888 *, 

1889 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1890 timeout: Optional[float] = None, 

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

1892 ) -> document.Document: 

1893 r"""Call the get document method over HTTP. 

1894 

1895 Args: 

1896 request (~.firestore.GetDocumentRequest): 

1897 The request object. The request for 

1898 [Firestore.GetDocument][google.firestore.v1.Firestore.GetDocument]. 

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

1900 should be retried. 

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

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

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

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

1905 be of type `bytes`. 

1906 

1907 Returns: 

1908 ~.document.Document: 

1909 A Firestore document. 

1910 

1911 Must not exceed 1 MiB - 4 bytes. 

1912 

1913 """ 

1914 

1915 http_options = ( 

1916 _BaseFirestoreRestTransport._BaseGetDocument._get_http_options() 

1917 ) 

1918 

1919 request, metadata = self._interceptor.pre_get_document(request, metadata) 

1920 transcoded_request = ( 

1921 _BaseFirestoreRestTransport._BaseGetDocument._get_transcoded_request( 

1922 http_options, request 

1923 ) 

1924 ) 

1925 

1926 # Jsonify the query params 

1927 query_params = ( 

1928 _BaseFirestoreRestTransport._BaseGetDocument._get_query_params_json( 

1929 transcoded_request 

1930 ) 

1931 ) 

1932 

1933 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1934 logging.DEBUG 

1935 ): # pragma: NO COVER 

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

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

1938 ) 

1939 method = transcoded_request["method"] 

1940 try: 

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

1942 except: 

1943 request_payload = None 

1944 http_request = { 

1945 "payload": request_payload, 

1946 "requestMethod": method, 

1947 "requestUrl": request_url, 

1948 "headers": dict(metadata), 

1949 } 

1950 _LOGGER.debug( 

1951 f"Sending request for google.firestore_v1.FirestoreClient.GetDocument", 

1952 extra={ 

1953 "serviceName": "google.firestore.v1.Firestore", 

1954 "rpcName": "GetDocument", 

1955 "httpRequest": http_request, 

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

1957 }, 

1958 ) 

1959 

1960 # Send the request 

1961 response = FirestoreRestTransport._GetDocument._get_response( 

1962 self._host, 

1963 metadata, 

1964 query_params, 

1965 self._session, 

1966 timeout, 

1967 transcoded_request, 

1968 ) 

1969 

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

1971 # subclass. 

1972 if response.status_code >= 400: 

1973 raise core_exceptions.from_http_response(response) 

1974 

1975 # Return the response 

1976 resp = document.Document() 

1977 pb_resp = document.Document.pb(resp) 

1978 

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

1980 

1981 resp = self._interceptor.post_get_document(resp) 

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

1983 resp, _ = self._interceptor.post_get_document_with_metadata( 

1984 resp, response_metadata 

1985 ) 

1986 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1987 logging.DEBUG 

1988 ): # pragma: NO COVER 

1989 try: 

1990 response_payload = document.Document.to_json(response) 

1991 except: 

1992 response_payload = None 

1993 http_response = { 

1994 "payload": response_payload, 

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

1996 "status": response.status_code, 

1997 } 

1998 _LOGGER.debug( 

1999 "Received response for google.firestore_v1.FirestoreClient.get_document", 

2000 extra={ 

2001 "serviceName": "google.firestore.v1.Firestore", 

2002 "rpcName": "GetDocument", 

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

2004 "httpResponse": http_response, 

2005 }, 

2006 ) 

2007 return resp 

2008 

2009 class _ListCollectionIds( 

2010 _BaseFirestoreRestTransport._BaseListCollectionIds, FirestoreRestStub 

2011 ): 

2012 def __hash__(self): 

2013 return hash("FirestoreRestTransport.ListCollectionIds") 

2014 

2015 @staticmethod 

2016 def _get_response( 

2017 host, 

2018 metadata, 

2019 query_params, 

2020 session, 

2021 timeout, 

2022 transcoded_request, 

2023 body=None, 

2024 ): 

2025 uri = transcoded_request["uri"] 

2026 method = transcoded_request["method"] 

2027 headers = dict(metadata) 

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

2029 response = getattr(session, method)( 

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

2031 timeout=timeout, 

2032 headers=headers, 

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

2034 data=body, 

2035 ) 

2036 return response 

2037 

2038 def __call__( 

2039 self, 

2040 request: firestore.ListCollectionIdsRequest, 

2041 *, 

2042 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2043 timeout: Optional[float] = None, 

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

2045 ) -> firestore.ListCollectionIdsResponse: 

2046 r"""Call the list collection ids method over HTTP. 

2047 

2048 Args: 

2049 request (~.firestore.ListCollectionIdsRequest): 

2050 The request object. The request for 

2051 [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds]. 

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

2053 should be retried. 

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

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

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

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

2058 be of type `bytes`. 

2059 

2060 Returns: 

2061 ~.firestore.ListCollectionIdsResponse: 

2062 The response from 

2063 [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds]. 

2064 

2065 """ 

2066 

2067 http_options = ( 

2068 _BaseFirestoreRestTransport._BaseListCollectionIds._get_http_options() 

2069 ) 

2070 

2071 request, metadata = self._interceptor.pre_list_collection_ids( 

2072 request, metadata 

2073 ) 

2074 transcoded_request = _BaseFirestoreRestTransport._BaseListCollectionIds._get_transcoded_request( 

2075 http_options, request 

2076 ) 

2077 

2078 body = _BaseFirestoreRestTransport._BaseListCollectionIds._get_request_body_json( 

2079 transcoded_request 

2080 ) 

2081 

2082 # Jsonify the query params 

2083 query_params = _BaseFirestoreRestTransport._BaseListCollectionIds._get_query_params_json( 

2084 transcoded_request 

2085 ) 

2086 

2087 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2088 logging.DEBUG 

2089 ): # pragma: NO COVER 

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

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

2092 ) 

2093 method = transcoded_request["method"] 

2094 try: 

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

2096 except: 

2097 request_payload = None 

2098 http_request = { 

2099 "payload": request_payload, 

2100 "requestMethod": method, 

2101 "requestUrl": request_url, 

2102 "headers": dict(metadata), 

2103 } 

2104 _LOGGER.debug( 

2105 f"Sending request for google.firestore_v1.FirestoreClient.ListCollectionIds", 

2106 extra={ 

2107 "serviceName": "google.firestore.v1.Firestore", 

2108 "rpcName": "ListCollectionIds", 

2109 "httpRequest": http_request, 

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

2111 }, 

2112 ) 

2113 

2114 # Send the request 

2115 response = FirestoreRestTransport._ListCollectionIds._get_response( 

2116 self._host, 

2117 metadata, 

2118 query_params, 

2119 self._session, 

2120 timeout, 

2121 transcoded_request, 

2122 body, 

2123 ) 

2124 

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

2126 # subclass. 

2127 if response.status_code >= 400: 

2128 raise core_exceptions.from_http_response(response) 

2129 

2130 # Return the response 

2131 resp = firestore.ListCollectionIdsResponse() 

2132 pb_resp = firestore.ListCollectionIdsResponse.pb(resp) 

2133 

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

2135 

2136 resp = self._interceptor.post_list_collection_ids(resp) 

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

2138 resp, _ = self._interceptor.post_list_collection_ids_with_metadata( 

2139 resp, response_metadata 

2140 ) 

2141 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2142 logging.DEBUG 

2143 ): # pragma: NO COVER 

2144 try: 

2145 response_payload = firestore.ListCollectionIdsResponse.to_json( 

2146 response 

2147 ) 

2148 except: 

2149 response_payload = None 

2150 http_response = { 

2151 "payload": response_payload, 

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

2153 "status": response.status_code, 

2154 } 

2155 _LOGGER.debug( 

2156 "Received response for google.firestore_v1.FirestoreClient.list_collection_ids", 

2157 extra={ 

2158 "serviceName": "google.firestore.v1.Firestore", 

2159 "rpcName": "ListCollectionIds", 

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

2161 "httpResponse": http_response, 

2162 }, 

2163 ) 

2164 return resp 

2165 

2166 class _ListDocuments( 

2167 _BaseFirestoreRestTransport._BaseListDocuments, FirestoreRestStub 

2168 ): 

2169 def __hash__(self): 

2170 return hash("FirestoreRestTransport.ListDocuments") 

2171 

2172 @staticmethod 

2173 def _get_response( 

2174 host, 

2175 metadata, 

2176 query_params, 

2177 session, 

2178 timeout, 

2179 transcoded_request, 

2180 body=None, 

2181 ): 

2182 uri = transcoded_request["uri"] 

2183 method = transcoded_request["method"] 

2184 headers = dict(metadata) 

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

2186 response = getattr(session, method)( 

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

2188 timeout=timeout, 

2189 headers=headers, 

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

2191 ) 

2192 return response 

2193 

2194 def __call__( 

2195 self, 

2196 request: firestore.ListDocumentsRequest, 

2197 *, 

2198 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2199 timeout: Optional[float] = None, 

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

2201 ) -> firestore.ListDocumentsResponse: 

2202 r"""Call the list documents method over HTTP. 

2203 

2204 Args: 

2205 request (~.firestore.ListDocumentsRequest): 

2206 The request object. The request for 

2207 [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments]. 

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

2209 should be retried. 

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

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

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

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

2214 be of type `bytes`. 

2215 

2216 Returns: 

2217 ~.firestore.ListDocumentsResponse: 

2218 The response for 

2219 [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments]. 

2220 

2221 """ 

2222 

2223 http_options = ( 

2224 _BaseFirestoreRestTransport._BaseListDocuments._get_http_options() 

2225 ) 

2226 

2227 request, metadata = self._interceptor.pre_list_documents(request, metadata) 

2228 transcoded_request = ( 

2229 _BaseFirestoreRestTransport._BaseListDocuments._get_transcoded_request( 

2230 http_options, request 

2231 ) 

2232 ) 

2233 

2234 # Jsonify the query params 

2235 query_params = ( 

2236 _BaseFirestoreRestTransport._BaseListDocuments._get_query_params_json( 

2237 transcoded_request 

2238 ) 

2239 ) 

2240 

2241 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2242 logging.DEBUG 

2243 ): # pragma: NO COVER 

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

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

2246 ) 

2247 method = transcoded_request["method"] 

2248 try: 

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

2250 except: 

2251 request_payload = None 

2252 http_request = { 

2253 "payload": request_payload, 

2254 "requestMethod": method, 

2255 "requestUrl": request_url, 

2256 "headers": dict(metadata), 

2257 } 

2258 _LOGGER.debug( 

2259 f"Sending request for google.firestore_v1.FirestoreClient.ListDocuments", 

2260 extra={ 

2261 "serviceName": "google.firestore.v1.Firestore", 

2262 "rpcName": "ListDocuments", 

2263 "httpRequest": http_request, 

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

2265 }, 

2266 ) 

2267 

2268 # Send the request 

2269 response = FirestoreRestTransport._ListDocuments._get_response( 

2270 self._host, 

2271 metadata, 

2272 query_params, 

2273 self._session, 

2274 timeout, 

2275 transcoded_request, 

2276 ) 

2277 

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

2279 # subclass. 

2280 if response.status_code >= 400: 

2281 raise core_exceptions.from_http_response(response) 

2282 

2283 # Return the response 

2284 resp = firestore.ListDocumentsResponse() 

2285 pb_resp = firestore.ListDocumentsResponse.pb(resp) 

2286 

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

2288 

2289 resp = self._interceptor.post_list_documents(resp) 

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

2291 resp, _ = self._interceptor.post_list_documents_with_metadata( 

2292 resp, response_metadata 

2293 ) 

2294 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2295 logging.DEBUG 

2296 ): # pragma: NO COVER 

2297 try: 

2298 response_payload = firestore.ListDocumentsResponse.to_json(response) 

2299 except: 

2300 response_payload = None 

2301 http_response = { 

2302 "payload": response_payload, 

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

2304 "status": response.status_code, 

2305 } 

2306 _LOGGER.debug( 

2307 "Received response for google.firestore_v1.FirestoreClient.list_documents", 

2308 extra={ 

2309 "serviceName": "google.firestore.v1.Firestore", 

2310 "rpcName": "ListDocuments", 

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

2312 "httpResponse": http_response, 

2313 }, 

2314 ) 

2315 return resp 

2316 

2317 class _Listen(_BaseFirestoreRestTransport._BaseListen, FirestoreRestStub): 

2318 def __hash__(self): 

2319 return hash("FirestoreRestTransport.Listen") 

2320 

2321 def __call__( 

2322 self, 

2323 request: firestore.ListenRequest, 

2324 *, 

2325 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2326 timeout: Optional[float] = None, 

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

2328 ) -> rest_streaming.ResponseIterator: 

2329 raise NotImplementedError( 

2330 "Method Listen is not available over REST transport" 

2331 ) 

2332 

2333 class _PartitionQuery( 

2334 _BaseFirestoreRestTransport._BasePartitionQuery, FirestoreRestStub 

2335 ): 

2336 def __hash__(self): 

2337 return hash("FirestoreRestTransport.PartitionQuery") 

2338 

2339 @staticmethod 

2340 def _get_response( 

2341 host, 

2342 metadata, 

2343 query_params, 

2344 session, 

2345 timeout, 

2346 transcoded_request, 

2347 body=None, 

2348 ): 

2349 uri = transcoded_request["uri"] 

2350 method = transcoded_request["method"] 

2351 headers = dict(metadata) 

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

2353 response = getattr(session, method)( 

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

2355 timeout=timeout, 

2356 headers=headers, 

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

2358 data=body, 

2359 ) 

2360 return response 

2361 

2362 def __call__( 

2363 self, 

2364 request: firestore.PartitionQueryRequest, 

2365 *, 

2366 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2367 timeout: Optional[float] = None, 

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

2369 ) -> firestore.PartitionQueryResponse: 

2370 r"""Call the partition query method over HTTP. 

2371 

2372 Args: 

2373 request (~.firestore.PartitionQueryRequest): 

2374 The request object. The request for 

2375 [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery]. 

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

2377 should be retried. 

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

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

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

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

2382 be of type `bytes`. 

2383 

2384 Returns: 

2385 ~.firestore.PartitionQueryResponse: 

2386 The response for 

2387 [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery]. 

2388 

2389 """ 

2390 

2391 http_options = ( 

2392 _BaseFirestoreRestTransport._BasePartitionQuery._get_http_options() 

2393 ) 

2394 

2395 request, metadata = self._interceptor.pre_partition_query(request, metadata) 

2396 transcoded_request = ( 

2397 _BaseFirestoreRestTransport._BasePartitionQuery._get_transcoded_request( 

2398 http_options, request 

2399 ) 

2400 ) 

2401 

2402 body = ( 

2403 _BaseFirestoreRestTransport._BasePartitionQuery._get_request_body_json( 

2404 transcoded_request 

2405 ) 

2406 ) 

2407 

2408 # Jsonify the query params 

2409 query_params = ( 

2410 _BaseFirestoreRestTransport._BasePartitionQuery._get_query_params_json( 

2411 transcoded_request 

2412 ) 

2413 ) 

2414 

2415 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2416 logging.DEBUG 

2417 ): # pragma: NO COVER 

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

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

2420 ) 

2421 method = transcoded_request["method"] 

2422 try: 

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

2424 except: 

2425 request_payload = None 

2426 http_request = { 

2427 "payload": request_payload, 

2428 "requestMethod": method, 

2429 "requestUrl": request_url, 

2430 "headers": dict(metadata), 

2431 } 

2432 _LOGGER.debug( 

2433 f"Sending request for google.firestore_v1.FirestoreClient.PartitionQuery", 

2434 extra={ 

2435 "serviceName": "google.firestore.v1.Firestore", 

2436 "rpcName": "PartitionQuery", 

2437 "httpRequest": http_request, 

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

2439 }, 

2440 ) 

2441 

2442 # Send the request 

2443 response = FirestoreRestTransport._PartitionQuery._get_response( 

2444 self._host, 

2445 metadata, 

2446 query_params, 

2447 self._session, 

2448 timeout, 

2449 transcoded_request, 

2450 body, 

2451 ) 

2452 

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

2454 # subclass. 

2455 if response.status_code >= 400: 

2456 raise core_exceptions.from_http_response(response) 

2457 

2458 # Return the response 

2459 resp = firestore.PartitionQueryResponse() 

2460 pb_resp = firestore.PartitionQueryResponse.pb(resp) 

2461 

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

2463 

2464 resp = self._interceptor.post_partition_query(resp) 

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

2466 resp, _ = self._interceptor.post_partition_query_with_metadata( 

2467 resp, response_metadata 

2468 ) 

2469 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2470 logging.DEBUG 

2471 ): # pragma: NO COVER 

2472 try: 

2473 response_payload = firestore.PartitionQueryResponse.to_json( 

2474 response 

2475 ) 

2476 except: 

2477 response_payload = None 

2478 http_response = { 

2479 "payload": response_payload, 

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

2481 "status": response.status_code, 

2482 } 

2483 _LOGGER.debug( 

2484 "Received response for google.firestore_v1.FirestoreClient.partition_query", 

2485 extra={ 

2486 "serviceName": "google.firestore.v1.Firestore", 

2487 "rpcName": "PartitionQuery", 

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

2489 "httpResponse": http_response, 

2490 }, 

2491 ) 

2492 return resp 

2493 

2494 class _Rollback(_BaseFirestoreRestTransport._BaseRollback, FirestoreRestStub): 

2495 def __hash__(self): 

2496 return hash("FirestoreRestTransport.Rollback") 

2497 

2498 @staticmethod 

2499 def _get_response( 

2500 host, 

2501 metadata, 

2502 query_params, 

2503 session, 

2504 timeout, 

2505 transcoded_request, 

2506 body=None, 

2507 ): 

2508 uri = transcoded_request["uri"] 

2509 method = transcoded_request["method"] 

2510 headers = dict(metadata) 

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

2512 response = getattr(session, method)( 

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

2514 timeout=timeout, 

2515 headers=headers, 

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

2517 data=body, 

2518 ) 

2519 return response 

2520 

2521 def __call__( 

2522 self, 

2523 request: firestore.RollbackRequest, 

2524 *, 

2525 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2526 timeout: Optional[float] = None, 

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

2528 ): 

2529 r"""Call the rollback method over HTTP. 

2530 

2531 Args: 

2532 request (~.firestore.RollbackRequest): 

2533 The request object. The request for 

2534 [Firestore.Rollback][google.firestore.v1.Firestore.Rollback]. 

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

2536 should be retried. 

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

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

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

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

2541 be of type `bytes`. 

2542 """ 

2543 

2544 http_options = _BaseFirestoreRestTransport._BaseRollback._get_http_options() 

2545 

2546 request, metadata = self._interceptor.pre_rollback(request, metadata) 

2547 transcoded_request = ( 

2548 _BaseFirestoreRestTransport._BaseRollback._get_transcoded_request( 

2549 http_options, request 

2550 ) 

2551 ) 

2552 

2553 body = _BaseFirestoreRestTransport._BaseRollback._get_request_body_json( 

2554 transcoded_request 

2555 ) 

2556 

2557 # Jsonify the query params 

2558 query_params = ( 

2559 _BaseFirestoreRestTransport._BaseRollback._get_query_params_json( 

2560 transcoded_request 

2561 ) 

2562 ) 

2563 

2564 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2565 logging.DEBUG 

2566 ): # pragma: NO COVER 

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

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

2569 ) 

2570 method = transcoded_request["method"] 

2571 try: 

2572 request_payload = json_format.MessageToJson(request) 

2573 except: 

2574 request_payload = None 

2575 http_request = { 

2576 "payload": request_payload, 

2577 "requestMethod": method, 

2578 "requestUrl": request_url, 

2579 "headers": dict(metadata), 

2580 } 

2581 _LOGGER.debug( 

2582 f"Sending request for google.firestore_v1.FirestoreClient.Rollback", 

2583 extra={ 

2584 "serviceName": "google.firestore.v1.Firestore", 

2585 "rpcName": "Rollback", 

2586 "httpRequest": http_request, 

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

2588 }, 

2589 ) 

2590 

2591 # Send the request 

2592 response = FirestoreRestTransport._Rollback._get_response( 

2593 self._host, 

2594 metadata, 

2595 query_params, 

2596 self._session, 

2597 timeout, 

2598 transcoded_request, 

2599 body, 

2600 ) 

2601 

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

2603 # subclass. 

2604 if response.status_code >= 400: 

2605 raise core_exceptions.from_http_response(response) 

2606 

2607 class _RunAggregationQuery( 

2608 _BaseFirestoreRestTransport._BaseRunAggregationQuery, FirestoreRestStub 

2609 ): 

2610 def __hash__(self): 

2611 return hash("FirestoreRestTransport.RunAggregationQuery") 

2612 

2613 @staticmethod 

2614 def _get_response( 

2615 host, 

2616 metadata, 

2617 query_params, 

2618 session, 

2619 timeout, 

2620 transcoded_request, 

2621 body=None, 

2622 ): 

2623 uri = transcoded_request["uri"] 

2624 method = transcoded_request["method"] 

2625 headers = dict(metadata) 

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

2627 response = getattr(session, method)( 

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

2629 timeout=timeout, 

2630 headers=headers, 

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

2632 data=body, 

2633 stream=True, 

2634 ) 

2635 return response 

2636 

2637 def __call__( 

2638 self, 

2639 request: firestore.RunAggregationQueryRequest, 

2640 *, 

2641 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2642 timeout: Optional[float] = None, 

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

2644 ) -> rest_streaming.ResponseIterator: 

2645 r"""Call the run aggregation query method over HTTP. 

2646 

2647 Args: 

2648 request (~.firestore.RunAggregationQueryRequest): 

2649 The request object. The request for 

2650 [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery]. 

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

2652 should be retried. 

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

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

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

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

2657 be of type `bytes`. 

2658 

2659 Returns: 

2660 ~.firestore.RunAggregationQueryResponse: 

2661 The response for 

2662 [Firestore.RunAggregationQuery][google.firestore.v1.Firestore.RunAggregationQuery]. 

2663 

2664 """ 

2665 

2666 http_options = ( 

2667 _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_http_options() 

2668 ) 

2669 

2670 request, metadata = self._interceptor.pre_run_aggregation_query( 

2671 request, metadata 

2672 ) 

2673 transcoded_request = _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_transcoded_request( 

2674 http_options, request 

2675 ) 

2676 

2677 body = _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_request_body_json( 

2678 transcoded_request 

2679 ) 

2680 

2681 # Jsonify the query params 

2682 query_params = _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_query_params_json( 

2683 transcoded_request 

2684 ) 

2685 

2686 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2687 logging.DEBUG 

2688 ): # pragma: NO COVER 

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

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

2691 ) 

2692 method = transcoded_request["method"] 

2693 try: 

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

2695 except: 

2696 request_payload = None 

2697 http_request = { 

2698 "payload": request_payload, 

2699 "requestMethod": method, 

2700 "requestUrl": request_url, 

2701 "headers": dict(metadata), 

2702 } 

2703 _LOGGER.debug( 

2704 f"Sending request for google.firestore_v1.FirestoreClient.RunAggregationQuery", 

2705 extra={ 

2706 "serviceName": "google.firestore.v1.Firestore", 

2707 "rpcName": "RunAggregationQuery", 

2708 "httpRequest": http_request, 

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

2710 }, 

2711 ) 

2712 

2713 # Send the request 

2714 response = FirestoreRestTransport._RunAggregationQuery._get_response( 

2715 self._host, 

2716 metadata, 

2717 query_params, 

2718 self._session, 

2719 timeout, 

2720 transcoded_request, 

2721 body, 

2722 ) 

2723 

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

2725 # subclass. 

2726 if response.status_code >= 400: 

2727 raise core_exceptions.from_http_response(response) 

2728 

2729 # Return the response 

2730 resp = rest_streaming.ResponseIterator( 

2731 response, firestore.RunAggregationQueryResponse 

2732 ) 

2733 

2734 resp = self._interceptor.post_run_aggregation_query(resp) 

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

2736 resp, _ = self._interceptor.post_run_aggregation_query_with_metadata( 

2737 resp, response_metadata 

2738 ) 

2739 return resp 

2740 

2741 class _RunQuery(_BaseFirestoreRestTransport._BaseRunQuery, FirestoreRestStub): 

2742 def __hash__(self): 

2743 return hash("FirestoreRestTransport.RunQuery") 

2744 

2745 @staticmethod 

2746 def _get_response( 

2747 host, 

2748 metadata, 

2749 query_params, 

2750 session, 

2751 timeout, 

2752 transcoded_request, 

2753 body=None, 

2754 ): 

2755 uri = transcoded_request["uri"] 

2756 method = transcoded_request["method"] 

2757 headers = dict(metadata) 

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

2759 response = getattr(session, method)( 

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

2761 timeout=timeout, 

2762 headers=headers, 

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

2764 data=body, 

2765 stream=True, 

2766 ) 

2767 return response 

2768 

2769 def __call__( 

2770 self, 

2771 request: firestore.RunQueryRequest, 

2772 *, 

2773 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2774 timeout: Optional[float] = None, 

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

2776 ) -> rest_streaming.ResponseIterator: 

2777 r"""Call the run query method over HTTP. 

2778 

2779 Args: 

2780 request (~.firestore.RunQueryRequest): 

2781 The request object. The request for 

2782 [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery]. 

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

2784 should be retried. 

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

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

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

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

2789 be of type `bytes`. 

2790 

2791 Returns: 

2792 ~.firestore.RunQueryResponse: 

2793 The response for 

2794 [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery]. 

2795 

2796 """ 

2797 

2798 http_options = _BaseFirestoreRestTransport._BaseRunQuery._get_http_options() 

2799 

2800 request, metadata = self._interceptor.pre_run_query(request, metadata) 

2801 transcoded_request = ( 

2802 _BaseFirestoreRestTransport._BaseRunQuery._get_transcoded_request( 

2803 http_options, request 

2804 ) 

2805 ) 

2806 

2807 body = _BaseFirestoreRestTransport._BaseRunQuery._get_request_body_json( 

2808 transcoded_request 

2809 ) 

2810 

2811 # Jsonify the query params 

2812 query_params = ( 

2813 _BaseFirestoreRestTransport._BaseRunQuery._get_query_params_json( 

2814 transcoded_request 

2815 ) 

2816 ) 

2817 

2818 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2819 logging.DEBUG 

2820 ): # pragma: NO COVER 

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

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

2823 ) 

2824 method = transcoded_request["method"] 

2825 try: 

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

2827 except: 

2828 request_payload = None 

2829 http_request = { 

2830 "payload": request_payload, 

2831 "requestMethod": method, 

2832 "requestUrl": request_url, 

2833 "headers": dict(metadata), 

2834 } 

2835 _LOGGER.debug( 

2836 f"Sending request for google.firestore_v1.FirestoreClient.RunQuery", 

2837 extra={ 

2838 "serviceName": "google.firestore.v1.Firestore", 

2839 "rpcName": "RunQuery", 

2840 "httpRequest": http_request, 

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

2842 }, 

2843 ) 

2844 

2845 # Send the request 

2846 response = FirestoreRestTransport._RunQuery._get_response( 

2847 self._host, 

2848 metadata, 

2849 query_params, 

2850 self._session, 

2851 timeout, 

2852 transcoded_request, 

2853 body, 

2854 ) 

2855 

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

2857 # subclass. 

2858 if response.status_code >= 400: 

2859 raise core_exceptions.from_http_response(response) 

2860 

2861 # Return the response 

2862 resp = rest_streaming.ResponseIterator(response, firestore.RunQueryResponse) 

2863 

2864 resp = self._interceptor.post_run_query(resp) 

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

2866 resp, _ = self._interceptor.post_run_query_with_metadata( 

2867 resp, response_metadata 

2868 ) 

2869 return resp 

2870 

2871 class _UpdateDocument( 

2872 _BaseFirestoreRestTransport._BaseUpdateDocument, FirestoreRestStub 

2873 ): 

2874 def __hash__(self): 

2875 return hash("FirestoreRestTransport.UpdateDocument") 

2876 

2877 @staticmethod 

2878 def _get_response( 

2879 host, 

2880 metadata, 

2881 query_params, 

2882 session, 

2883 timeout, 

2884 transcoded_request, 

2885 body=None, 

2886 ): 

2887 uri = transcoded_request["uri"] 

2888 method = transcoded_request["method"] 

2889 headers = dict(metadata) 

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

2891 response = getattr(session, method)( 

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

2893 timeout=timeout, 

2894 headers=headers, 

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

2896 data=body, 

2897 ) 

2898 return response 

2899 

2900 def __call__( 

2901 self, 

2902 request: firestore.UpdateDocumentRequest, 

2903 *, 

2904 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2905 timeout: Optional[float] = None, 

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

2907 ) -> gf_document.Document: 

2908 r"""Call the update document method over HTTP. 

2909 

2910 Args: 

2911 request (~.firestore.UpdateDocumentRequest): 

2912 The request object. The request for 

2913 [Firestore.UpdateDocument][google.firestore.v1.Firestore.UpdateDocument]. 

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

2915 should be retried. 

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

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

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

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

2920 be of type `bytes`. 

2921 

2922 Returns: 

2923 ~.gf_document.Document: 

2924 A Firestore document. 

2925 

2926 Must not exceed 1 MiB - 4 bytes. 

2927 

2928 """ 

2929 

2930 http_options = ( 

2931 _BaseFirestoreRestTransport._BaseUpdateDocument._get_http_options() 

2932 ) 

2933 

2934 request, metadata = self._interceptor.pre_update_document(request, metadata) 

2935 transcoded_request = ( 

2936 _BaseFirestoreRestTransport._BaseUpdateDocument._get_transcoded_request( 

2937 http_options, request 

2938 ) 

2939 ) 

2940 

2941 body = ( 

2942 _BaseFirestoreRestTransport._BaseUpdateDocument._get_request_body_json( 

2943 transcoded_request 

2944 ) 

2945 ) 

2946 

2947 # Jsonify the query params 

2948 query_params = ( 

2949 _BaseFirestoreRestTransport._BaseUpdateDocument._get_query_params_json( 

2950 transcoded_request 

2951 ) 

2952 ) 

2953 

2954 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2955 logging.DEBUG 

2956 ): # pragma: NO COVER 

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

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

2959 ) 

2960 method = transcoded_request["method"] 

2961 try: 

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

2963 except: 

2964 request_payload = None 

2965 http_request = { 

2966 "payload": request_payload, 

2967 "requestMethod": method, 

2968 "requestUrl": request_url, 

2969 "headers": dict(metadata), 

2970 } 

2971 _LOGGER.debug( 

2972 f"Sending request for google.firestore_v1.FirestoreClient.UpdateDocument", 

2973 extra={ 

2974 "serviceName": "google.firestore.v1.Firestore", 

2975 "rpcName": "UpdateDocument", 

2976 "httpRequest": http_request, 

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

2978 }, 

2979 ) 

2980 

2981 # Send the request 

2982 response = FirestoreRestTransport._UpdateDocument._get_response( 

2983 self._host, 

2984 metadata, 

2985 query_params, 

2986 self._session, 

2987 timeout, 

2988 transcoded_request, 

2989 body, 

2990 ) 

2991 

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

2993 # subclass. 

2994 if response.status_code >= 400: 

2995 raise core_exceptions.from_http_response(response) 

2996 

2997 # Return the response 

2998 resp = gf_document.Document() 

2999 pb_resp = gf_document.Document.pb(resp) 

3000 

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

3002 

3003 resp = self._interceptor.post_update_document(resp) 

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

3005 resp, _ = self._interceptor.post_update_document_with_metadata( 

3006 resp, response_metadata 

3007 ) 

3008 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3009 logging.DEBUG 

3010 ): # pragma: NO COVER 

3011 try: 

3012 response_payload = gf_document.Document.to_json(response) 

3013 except: 

3014 response_payload = None 

3015 http_response = { 

3016 "payload": response_payload, 

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

3018 "status": response.status_code, 

3019 } 

3020 _LOGGER.debug( 

3021 "Received response for google.firestore_v1.FirestoreClient.update_document", 

3022 extra={ 

3023 "serviceName": "google.firestore.v1.Firestore", 

3024 "rpcName": "UpdateDocument", 

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

3026 "httpResponse": http_response, 

3027 }, 

3028 ) 

3029 return resp 

3030 

3031 class _Write(_BaseFirestoreRestTransport._BaseWrite, FirestoreRestStub): 

3032 def __hash__(self): 

3033 return hash("FirestoreRestTransport.Write") 

3034 

3035 def __call__( 

3036 self, 

3037 request: firestore.WriteRequest, 

3038 *, 

3039 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3040 timeout: Optional[float] = None, 

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

3042 ) -> rest_streaming.ResponseIterator: 

3043 raise NotImplementedError( 

3044 "Method Write is not available over REST transport" 

3045 ) 

3046 

3047 @property 

3048 def batch_get_documents( 

3049 self, 

3050 ) -> Callable[ 

3051 [firestore.BatchGetDocumentsRequest], firestore.BatchGetDocumentsResponse 

3052 ]: 

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

3054 # In C++ this would require a dynamic_cast 

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

3056 

3057 @property 

3058 def batch_write( 

3059 self, 

3060 ) -> Callable[[firestore.BatchWriteRequest], firestore.BatchWriteResponse]: 

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

3062 # In C++ this would require a dynamic_cast 

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

3064 

3065 @property 

3066 def begin_transaction( 

3067 self, 

3068 ) -> Callable[ 

3069 [firestore.BeginTransactionRequest], firestore.BeginTransactionResponse 

3070 ]: 

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._BeginTransaction(self._session, self._host, self._interceptor) # type: ignore 

3074 

3075 @property 

3076 def commit(self) -> Callable[[firestore.CommitRequest], firestore.CommitResponse]: 

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._Commit(self._session, self._host, self._interceptor) # type: ignore 

3080 

3081 @property 

3082 def create_document( 

3083 self, 

3084 ) -> Callable[[firestore.CreateDocumentRequest], document.Document]: 

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._CreateDocument(self._session, self._host, self._interceptor) # type: ignore 

3088 

3089 @property 

3090 def delete_document( 

3091 self, 

3092 ) -> Callable[[firestore.DeleteDocumentRequest], empty_pb2.Empty]: 

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._DeleteDocument(self._session, self._host, self._interceptor) # type: ignore 

3096 

3097 @property 

3098 def get_document( 

3099 self, 

3100 ) -> Callable[[firestore.GetDocumentRequest], document.Document]: 

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._GetDocument(self._session, self._host, self._interceptor) # type: ignore 

3104 

3105 @property 

3106 def list_collection_ids( 

3107 self, 

3108 ) -> Callable[ 

3109 [firestore.ListCollectionIdsRequest], firestore.ListCollectionIdsResponse 

3110 ]: 

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

3112 # In C++ this would require a dynamic_cast 

3113 return self._ListCollectionIds(self._session, self._host, self._interceptor) # type: ignore 

3114 

3115 @property 

3116 def list_documents( 

3117 self, 

3118 ) -> Callable[[firestore.ListDocumentsRequest], firestore.ListDocumentsResponse]: 

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

3120 # In C++ this would require a dynamic_cast 

3121 return self._ListDocuments(self._session, self._host, self._interceptor) # type: ignore 

3122 

3123 @property 

3124 def listen(self) -> Callable[[firestore.ListenRequest], firestore.ListenResponse]: 

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

3126 # In C++ this would require a dynamic_cast 

3127 return self._Listen(self._session, self._host, self._interceptor) # type: ignore 

3128 

3129 @property 

3130 def partition_query( 

3131 self, 

3132 ) -> Callable[[firestore.PartitionQueryRequest], firestore.PartitionQueryResponse]: 

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

3134 # In C++ this would require a dynamic_cast 

3135 return self._PartitionQuery(self._session, self._host, self._interceptor) # type: ignore 

3136 

3137 @property 

3138 def rollback(self) -> Callable[[firestore.RollbackRequest], empty_pb2.Empty]: 

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

3140 # In C++ this would require a dynamic_cast 

3141 return self._Rollback(self._session, self._host, self._interceptor) # type: ignore 

3142 

3143 @property 

3144 def run_aggregation_query( 

3145 self, 

3146 ) -> Callable[ 

3147 [firestore.RunAggregationQueryRequest], firestore.RunAggregationQueryResponse 

3148 ]: 

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

3150 # In C++ this would require a dynamic_cast 

3151 return self._RunAggregationQuery(self._session, self._host, self._interceptor) # type: ignore 

3152 

3153 @property 

3154 def run_query( 

3155 self, 

3156 ) -> Callable[[firestore.RunQueryRequest], firestore.RunQueryResponse]: 

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

3158 # In C++ this would require a dynamic_cast 

3159 return self._RunQuery(self._session, self._host, self._interceptor) # type: ignore 

3160 

3161 @property 

3162 def update_document( 

3163 self, 

3164 ) -> Callable[[firestore.UpdateDocumentRequest], gf_document.Document]: 

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

3166 # In C++ this would require a dynamic_cast 

3167 return self._UpdateDocument(self._session, self._host, self._interceptor) # type: ignore 

3168 

3169 @property 

3170 def write(self) -> Callable[[firestore.WriteRequest], firestore.WriteResponse]: 

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

3172 # In C++ this would require a dynamic_cast 

3173 return self._Write(self._session, self._host, self._interceptor) # type: ignore 

3174 

3175 @property 

3176 def cancel_operation(self): 

3177 return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore 

3178 

3179 class _CancelOperation( 

3180 _BaseFirestoreRestTransport._BaseCancelOperation, FirestoreRestStub 

3181 ): 

3182 def __hash__(self): 

3183 return hash("FirestoreRestTransport.CancelOperation") 

3184 

3185 @staticmethod 

3186 def _get_response( 

3187 host, 

3188 metadata, 

3189 query_params, 

3190 session, 

3191 timeout, 

3192 transcoded_request, 

3193 body=None, 

3194 ): 

3195 uri = transcoded_request["uri"] 

3196 method = transcoded_request["method"] 

3197 headers = dict(metadata) 

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

3199 response = getattr(session, method)( 

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

3201 timeout=timeout, 

3202 headers=headers, 

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

3204 data=body, 

3205 ) 

3206 return response 

3207 

3208 def __call__( 

3209 self, 

3210 request: operations_pb2.CancelOperationRequest, 

3211 *, 

3212 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3213 timeout: Optional[float] = None, 

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

3215 ) -> None: 

3216 r"""Call the cancel operation method over HTTP. 

3217 

3218 Args: 

3219 request (operations_pb2.CancelOperationRequest): 

3220 The request object for CancelOperation method. 

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

3222 should be retried. 

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

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

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

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

3227 be of type `bytes`. 

3228 """ 

3229 

3230 http_options = ( 

3231 _BaseFirestoreRestTransport._BaseCancelOperation._get_http_options() 

3232 ) 

3233 

3234 request, metadata = self._interceptor.pre_cancel_operation( 

3235 request, metadata 

3236 ) 

3237 transcoded_request = _BaseFirestoreRestTransport._BaseCancelOperation._get_transcoded_request( 

3238 http_options, request 

3239 ) 

3240 

3241 body = ( 

3242 _BaseFirestoreRestTransport._BaseCancelOperation._get_request_body_json( 

3243 transcoded_request 

3244 ) 

3245 ) 

3246 

3247 # Jsonify the query params 

3248 query_params = ( 

3249 _BaseFirestoreRestTransport._BaseCancelOperation._get_query_params_json( 

3250 transcoded_request 

3251 ) 

3252 ) 

3253 

3254 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3255 logging.DEBUG 

3256 ): # pragma: NO COVER 

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

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

3259 ) 

3260 method = transcoded_request["method"] 

3261 try: 

3262 request_payload = json_format.MessageToJson(request) 

3263 except: 

3264 request_payload = None 

3265 http_request = { 

3266 "payload": request_payload, 

3267 "requestMethod": method, 

3268 "requestUrl": request_url, 

3269 "headers": dict(metadata), 

3270 } 

3271 _LOGGER.debug( 

3272 f"Sending request for google.firestore_v1.FirestoreClient.CancelOperation", 

3273 extra={ 

3274 "serviceName": "google.firestore.v1.Firestore", 

3275 "rpcName": "CancelOperation", 

3276 "httpRequest": http_request, 

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

3278 }, 

3279 ) 

3280 

3281 # Send the request 

3282 response = FirestoreRestTransport._CancelOperation._get_response( 

3283 self._host, 

3284 metadata, 

3285 query_params, 

3286 self._session, 

3287 timeout, 

3288 transcoded_request, 

3289 body, 

3290 ) 

3291 

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

3293 # subclass. 

3294 if response.status_code >= 400: 

3295 raise core_exceptions.from_http_response(response) 

3296 

3297 return self._interceptor.post_cancel_operation(None) 

3298 

3299 @property 

3300 def delete_operation(self): 

3301 return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore 

3302 

3303 class _DeleteOperation( 

3304 _BaseFirestoreRestTransport._BaseDeleteOperation, FirestoreRestStub 

3305 ): 

3306 def __hash__(self): 

3307 return hash("FirestoreRestTransport.DeleteOperation") 

3308 

3309 @staticmethod 

3310 def _get_response( 

3311 host, 

3312 metadata, 

3313 query_params, 

3314 session, 

3315 timeout, 

3316 transcoded_request, 

3317 body=None, 

3318 ): 

3319 uri = transcoded_request["uri"] 

3320 method = transcoded_request["method"] 

3321 headers = dict(metadata) 

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

3323 response = getattr(session, method)( 

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

3325 timeout=timeout, 

3326 headers=headers, 

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

3328 ) 

3329 return response 

3330 

3331 def __call__( 

3332 self, 

3333 request: operations_pb2.DeleteOperationRequest, 

3334 *, 

3335 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3336 timeout: Optional[float] = None, 

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

3338 ) -> None: 

3339 r"""Call the delete operation method over HTTP. 

3340 

3341 Args: 

3342 request (operations_pb2.DeleteOperationRequest): 

3343 The request object for DeleteOperation method. 

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

3345 should be retried. 

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

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

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

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

3350 be of type `bytes`. 

3351 """ 

3352 

3353 http_options = ( 

3354 _BaseFirestoreRestTransport._BaseDeleteOperation._get_http_options() 

3355 ) 

3356 

3357 request, metadata = self._interceptor.pre_delete_operation( 

3358 request, metadata 

3359 ) 

3360 transcoded_request = _BaseFirestoreRestTransport._BaseDeleteOperation._get_transcoded_request( 

3361 http_options, request 

3362 ) 

3363 

3364 # Jsonify the query params 

3365 query_params = ( 

3366 _BaseFirestoreRestTransport._BaseDeleteOperation._get_query_params_json( 

3367 transcoded_request 

3368 ) 

3369 ) 

3370 

3371 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3372 logging.DEBUG 

3373 ): # pragma: NO COVER 

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

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

3376 ) 

3377 method = transcoded_request["method"] 

3378 try: 

3379 request_payload = json_format.MessageToJson(request) 

3380 except: 

3381 request_payload = None 

3382 http_request = { 

3383 "payload": request_payload, 

3384 "requestMethod": method, 

3385 "requestUrl": request_url, 

3386 "headers": dict(metadata), 

3387 } 

3388 _LOGGER.debug( 

3389 f"Sending request for google.firestore_v1.FirestoreClient.DeleteOperation", 

3390 extra={ 

3391 "serviceName": "google.firestore.v1.Firestore", 

3392 "rpcName": "DeleteOperation", 

3393 "httpRequest": http_request, 

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

3395 }, 

3396 ) 

3397 

3398 # Send the request 

3399 response = FirestoreRestTransport._DeleteOperation._get_response( 

3400 self._host, 

3401 metadata, 

3402 query_params, 

3403 self._session, 

3404 timeout, 

3405 transcoded_request, 

3406 ) 

3407 

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

3409 # subclass. 

3410 if response.status_code >= 400: 

3411 raise core_exceptions.from_http_response(response) 

3412 

3413 return self._interceptor.post_delete_operation(None) 

3414 

3415 @property 

3416 def get_operation(self): 

3417 return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore 

3418 

3419 class _GetOperation( 

3420 _BaseFirestoreRestTransport._BaseGetOperation, FirestoreRestStub 

3421 ): 

3422 def __hash__(self): 

3423 return hash("FirestoreRestTransport.GetOperation") 

3424 

3425 @staticmethod 

3426 def _get_response( 

3427 host, 

3428 metadata, 

3429 query_params, 

3430 session, 

3431 timeout, 

3432 transcoded_request, 

3433 body=None, 

3434 ): 

3435 uri = transcoded_request["uri"] 

3436 method = transcoded_request["method"] 

3437 headers = dict(metadata) 

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

3439 response = getattr(session, method)( 

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

3441 timeout=timeout, 

3442 headers=headers, 

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

3444 ) 

3445 return response 

3446 

3447 def __call__( 

3448 self, 

3449 request: operations_pb2.GetOperationRequest, 

3450 *, 

3451 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3452 timeout: Optional[float] = None, 

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

3454 ) -> operations_pb2.Operation: 

3455 r"""Call the get operation method over HTTP. 

3456 

3457 Args: 

3458 request (operations_pb2.GetOperationRequest): 

3459 The request object for GetOperation method. 

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

3461 should be retried. 

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

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

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

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

3466 be of type `bytes`. 

3467 

3468 Returns: 

3469 operations_pb2.Operation: Response from GetOperation method. 

3470 """ 

3471 

3472 http_options = ( 

3473 _BaseFirestoreRestTransport._BaseGetOperation._get_http_options() 

3474 ) 

3475 

3476 request, metadata = self._interceptor.pre_get_operation(request, metadata) 

3477 transcoded_request = ( 

3478 _BaseFirestoreRestTransport._BaseGetOperation._get_transcoded_request( 

3479 http_options, request 

3480 ) 

3481 ) 

3482 

3483 # Jsonify the query params 

3484 query_params = ( 

3485 _BaseFirestoreRestTransport._BaseGetOperation._get_query_params_json( 

3486 transcoded_request 

3487 ) 

3488 ) 

3489 

3490 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3491 logging.DEBUG 

3492 ): # pragma: NO COVER 

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

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

3495 ) 

3496 method = transcoded_request["method"] 

3497 try: 

3498 request_payload = json_format.MessageToJson(request) 

3499 except: 

3500 request_payload = None 

3501 http_request = { 

3502 "payload": request_payload, 

3503 "requestMethod": method, 

3504 "requestUrl": request_url, 

3505 "headers": dict(metadata), 

3506 } 

3507 _LOGGER.debug( 

3508 f"Sending request for google.firestore_v1.FirestoreClient.GetOperation", 

3509 extra={ 

3510 "serviceName": "google.firestore.v1.Firestore", 

3511 "rpcName": "GetOperation", 

3512 "httpRequest": http_request, 

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

3514 }, 

3515 ) 

3516 

3517 # Send the request 

3518 response = FirestoreRestTransport._GetOperation._get_response( 

3519 self._host, 

3520 metadata, 

3521 query_params, 

3522 self._session, 

3523 timeout, 

3524 transcoded_request, 

3525 ) 

3526 

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

3528 # subclass. 

3529 if response.status_code >= 400: 

3530 raise core_exceptions.from_http_response(response) 

3531 

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

3533 resp = operations_pb2.Operation() 

3534 resp = json_format.Parse(content, resp) 

3535 resp = self._interceptor.post_get_operation(resp) 

3536 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3537 logging.DEBUG 

3538 ): # pragma: NO COVER 

3539 try: 

3540 response_payload = json_format.MessageToJson(resp) 

3541 except: 

3542 response_payload = None 

3543 http_response = { 

3544 "payload": response_payload, 

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

3546 "status": response.status_code, 

3547 } 

3548 _LOGGER.debug( 

3549 "Received response for google.firestore_v1.FirestoreAsyncClient.GetOperation", 

3550 extra={ 

3551 "serviceName": "google.firestore.v1.Firestore", 

3552 "rpcName": "GetOperation", 

3553 "httpResponse": http_response, 

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

3555 }, 

3556 ) 

3557 return resp 

3558 

3559 @property 

3560 def list_operations(self): 

3561 return self._ListOperations(self._session, self._host, self._interceptor) # type: ignore 

3562 

3563 class _ListOperations( 

3564 _BaseFirestoreRestTransport._BaseListOperations, FirestoreRestStub 

3565 ): 

3566 def __hash__(self): 

3567 return hash("FirestoreRestTransport.ListOperations") 

3568 

3569 @staticmethod 

3570 def _get_response( 

3571 host, 

3572 metadata, 

3573 query_params, 

3574 session, 

3575 timeout, 

3576 transcoded_request, 

3577 body=None, 

3578 ): 

3579 uri = transcoded_request["uri"] 

3580 method = transcoded_request["method"] 

3581 headers = dict(metadata) 

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

3583 response = getattr(session, method)( 

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

3585 timeout=timeout, 

3586 headers=headers, 

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

3588 ) 

3589 return response 

3590 

3591 def __call__( 

3592 self, 

3593 request: operations_pb2.ListOperationsRequest, 

3594 *, 

3595 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3596 timeout: Optional[float] = None, 

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

3598 ) -> operations_pb2.ListOperationsResponse: 

3599 r"""Call the list operations method over HTTP. 

3600 

3601 Args: 

3602 request (operations_pb2.ListOperationsRequest): 

3603 The request object for ListOperations method. 

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

3605 should be retried. 

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

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

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

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

3610 be of type `bytes`. 

3611 

3612 Returns: 

3613 operations_pb2.ListOperationsResponse: Response from ListOperations method. 

3614 """ 

3615 

3616 http_options = ( 

3617 _BaseFirestoreRestTransport._BaseListOperations._get_http_options() 

3618 ) 

3619 

3620 request, metadata = self._interceptor.pre_list_operations(request, metadata) 

3621 transcoded_request = ( 

3622 _BaseFirestoreRestTransport._BaseListOperations._get_transcoded_request( 

3623 http_options, request 

3624 ) 

3625 ) 

3626 

3627 # Jsonify the query params 

3628 query_params = ( 

3629 _BaseFirestoreRestTransport._BaseListOperations._get_query_params_json( 

3630 transcoded_request 

3631 ) 

3632 ) 

3633 

3634 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3635 logging.DEBUG 

3636 ): # pragma: NO COVER 

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

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

3639 ) 

3640 method = transcoded_request["method"] 

3641 try: 

3642 request_payload = json_format.MessageToJson(request) 

3643 except: 

3644 request_payload = None 

3645 http_request = { 

3646 "payload": request_payload, 

3647 "requestMethod": method, 

3648 "requestUrl": request_url, 

3649 "headers": dict(metadata), 

3650 } 

3651 _LOGGER.debug( 

3652 f"Sending request for google.firestore_v1.FirestoreClient.ListOperations", 

3653 extra={ 

3654 "serviceName": "google.firestore.v1.Firestore", 

3655 "rpcName": "ListOperations", 

3656 "httpRequest": http_request, 

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

3658 }, 

3659 ) 

3660 

3661 # Send the request 

3662 response = FirestoreRestTransport._ListOperations._get_response( 

3663 self._host, 

3664 metadata, 

3665 query_params, 

3666 self._session, 

3667 timeout, 

3668 transcoded_request, 

3669 ) 

3670 

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

3672 # subclass. 

3673 if response.status_code >= 400: 

3674 raise core_exceptions.from_http_response(response) 

3675 

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

3677 resp = operations_pb2.ListOperationsResponse() 

3678 resp = json_format.Parse(content, resp) 

3679 resp = self._interceptor.post_list_operations(resp) 

3680 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3681 logging.DEBUG 

3682 ): # pragma: NO COVER 

3683 try: 

3684 response_payload = json_format.MessageToJson(resp) 

3685 except: 

3686 response_payload = None 

3687 http_response = { 

3688 "payload": response_payload, 

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

3690 "status": response.status_code, 

3691 } 

3692 _LOGGER.debug( 

3693 "Received response for google.firestore_v1.FirestoreAsyncClient.ListOperations", 

3694 extra={ 

3695 "serviceName": "google.firestore.v1.Firestore", 

3696 "rpcName": "ListOperations", 

3697 "httpResponse": http_response, 

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

3699 }, 

3700 ) 

3701 return resp 

3702 

3703 @property 

3704 def kind(self) -> str: 

3705 return "rest" 

3706 

3707 def close(self): 

3708 self._session.close() 

3709 

3710 

3711__all__ = ("FirestoreRestTransport",)