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

951 removed in the next major version of this library. 

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

953 ignored if ``channel`` is provided. 

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

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

956 if ``channel`` is provided. 

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

958 and quota. 

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

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

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

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

963 your own client library. 

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

965 be used for service account credentials. 

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

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

968 "http" can be specified. 

969 """ 

970 # Run the base constructor 

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

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

973 # credentials object 

974 super().__init__( 

975 host=host, 

976 credentials=credentials, 

977 client_info=client_info, 

978 always_use_jwt_access=always_use_jwt_access, 

979 url_scheme=url_scheme, 

980 api_audience=api_audience, 

981 ) 

982 self._session = AuthorizedSession( 

983 self._credentials, default_host=self.DEFAULT_HOST 

984 ) 

985 if client_cert_source_for_mtls: 

986 self._session.configure_mtls_channel(client_cert_source_for_mtls) 

987 self._interceptor = interceptor or FirestoreRestInterceptor() 

988 self._prep_wrapped_messages(client_info) 

989 

990 class _BatchGetDocuments( 

991 _BaseFirestoreRestTransport._BaseBatchGetDocuments, FirestoreRestStub 

992 ): 

993 def __hash__(self): 

994 return hash("FirestoreRestTransport.BatchGetDocuments") 

995 

996 @staticmethod 

997 def _get_response( 

998 host, 

999 metadata, 

1000 query_params, 

1001 session, 

1002 timeout, 

1003 transcoded_request, 

1004 body=None, 

1005 ): 

1006 uri = transcoded_request["uri"] 

1007 method = transcoded_request["method"] 

1008 headers = dict(metadata) 

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

1010 response = getattr(session, method)( 

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

1012 timeout=timeout, 

1013 headers=headers, 

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

1015 data=body, 

1016 stream=True, 

1017 ) 

1018 return response 

1019 

1020 def __call__( 

1021 self, 

1022 request: firestore.BatchGetDocumentsRequest, 

1023 *, 

1024 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1025 timeout: Optional[float] = None, 

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

1027 ) -> rest_streaming.ResponseIterator: 

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

1029 

1030 Args: 

1031 request (~.firestore.BatchGetDocumentsRequest): 

1032 The request object. The request for 

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

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

1035 should be retried. 

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

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

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

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

1040 be of type `bytes`. 

1041 

1042 Returns: 

1043 ~.firestore.BatchGetDocumentsResponse: 

1044 The streamed response for 

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

1046 

1047 """ 

1048 

1049 http_options = ( 

1050 _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_http_options() 

1051 ) 

1052 

1053 request, metadata = self._interceptor.pre_batch_get_documents( 

1054 request, metadata 

1055 ) 

1056 transcoded_request = _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_transcoded_request( 

1057 http_options, request 

1058 ) 

1059 

1060 body = _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_request_body_json( 

1061 transcoded_request 

1062 ) 

1063 

1064 # Jsonify the query params 

1065 query_params = _BaseFirestoreRestTransport._BaseBatchGetDocuments._get_query_params_json( 

1066 transcoded_request 

1067 ) 

1068 

1069 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1070 logging.DEBUG 

1071 ): # pragma: NO COVER 

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

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

1074 ) 

1075 method = transcoded_request["method"] 

1076 try: 

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

1078 except: 

1079 request_payload = None 

1080 http_request = { 

1081 "payload": request_payload, 

1082 "requestMethod": method, 

1083 "requestUrl": request_url, 

1084 "headers": dict(metadata), 

1085 } 

1086 _LOGGER.debug( 

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

1088 extra={ 

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

1090 "rpcName": "BatchGetDocuments", 

1091 "httpRequest": http_request, 

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

1093 }, 

1094 ) 

1095 

1096 # Send the request 

1097 response = FirestoreRestTransport._BatchGetDocuments._get_response( 

1098 self._host, 

1099 metadata, 

1100 query_params, 

1101 self._session, 

1102 timeout, 

1103 transcoded_request, 

1104 body, 

1105 ) 

1106 

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

1108 # subclass. 

1109 if response.status_code >= 400: 

1110 raise core_exceptions.from_http_response(response) 

1111 

1112 # Return the response 

1113 resp = rest_streaming.ResponseIterator( 

1114 response, firestore.BatchGetDocumentsResponse 

1115 ) 

1116 

1117 resp = self._interceptor.post_batch_get_documents(resp) 

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

1119 resp, _ = self._interceptor.post_batch_get_documents_with_metadata( 

1120 resp, response_metadata 

1121 ) 

1122 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1123 logging.DEBUG 

1124 ): # pragma: NO COVER 

1125 http_response = { 

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

1127 "status": response.status_code, 

1128 } 

1129 _LOGGER.debug( 

1130 "Received response for google.firestore_v1.FirestoreClient.batch_get_documents", 

1131 extra={ 

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

1133 "rpcName": "BatchGetDocuments", 

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

1135 "httpResponse": http_response, 

1136 }, 

1137 ) 

1138 return resp 

1139 

1140 class _BatchWrite(_BaseFirestoreRestTransport._BaseBatchWrite, FirestoreRestStub): 

1141 def __hash__(self): 

1142 return hash("FirestoreRestTransport.BatchWrite") 

1143 

1144 @staticmethod 

1145 def _get_response( 

1146 host, 

1147 metadata, 

1148 query_params, 

1149 session, 

1150 timeout, 

1151 transcoded_request, 

1152 body=None, 

1153 ): 

1154 uri = transcoded_request["uri"] 

1155 method = transcoded_request["method"] 

1156 headers = dict(metadata) 

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

1158 response = getattr(session, method)( 

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

1160 timeout=timeout, 

1161 headers=headers, 

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

1163 data=body, 

1164 ) 

1165 return response 

1166 

1167 def __call__( 

1168 self, 

1169 request: firestore.BatchWriteRequest, 

1170 *, 

1171 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1172 timeout: Optional[float] = None, 

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

1174 ) -> firestore.BatchWriteResponse: 

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

1176 

1177 Args: 

1178 request (~.firestore.BatchWriteRequest): 

1179 The request object. The request for 

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

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

1182 should be retried. 

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

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

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

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

1187 be of type `bytes`. 

1188 

1189 Returns: 

1190 ~.firestore.BatchWriteResponse: 

1191 The response from 

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

1193 

1194 """ 

1195 

1196 http_options = ( 

1197 _BaseFirestoreRestTransport._BaseBatchWrite._get_http_options() 

1198 ) 

1199 

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

1201 transcoded_request = ( 

1202 _BaseFirestoreRestTransport._BaseBatchWrite._get_transcoded_request( 

1203 http_options, request 

1204 ) 

1205 ) 

1206 

1207 body = _BaseFirestoreRestTransport._BaseBatchWrite._get_request_body_json( 

1208 transcoded_request 

1209 ) 

1210 

1211 # Jsonify the query params 

1212 query_params = ( 

1213 _BaseFirestoreRestTransport._BaseBatchWrite._get_query_params_json( 

1214 transcoded_request 

1215 ) 

1216 ) 

1217 

1218 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1219 logging.DEBUG 

1220 ): # pragma: NO COVER 

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

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

1223 ) 

1224 method = transcoded_request["method"] 

1225 try: 

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

1227 except: 

1228 request_payload = None 

1229 http_request = { 

1230 "payload": request_payload, 

1231 "requestMethod": method, 

1232 "requestUrl": request_url, 

1233 "headers": dict(metadata), 

1234 } 

1235 _LOGGER.debug( 

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

1237 extra={ 

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

1239 "rpcName": "BatchWrite", 

1240 "httpRequest": http_request, 

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

1242 }, 

1243 ) 

1244 

1245 # Send the request 

1246 response = FirestoreRestTransport._BatchWrite._get_response( 

1247 self._host, 

1248 metadata, 

1249 query_params, 

1250 self._session, 

1251 timeout, 

1252 transcoded_request, 

1253 body, 

1254 ) 

1255 

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

1257 # subclass. 

1258 if response.status_code >= 400: 

1259 raise core_exceptions.from_http_response(response) 

1260 

1261 # Return the response 

1262 resp = firestore.BatchWriteResponse() 

1263 pb_resp = firestore.BatchWriteResponse.pb(resp) 

1264 

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

1266 

1267 resp = self._interceptor.post_batch_write(resp) 

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

1269 resp, _ = self._interceptor.post_batch_write_with_metadata( 

1270 resp, response_metadata 

1271 ) 

1272 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1273 logging.DEBUG 

1274 ): # pragma: NO COVER 

1275 try: 

1276 response_payload = firestore.BatchWriteResponse.to_json(response) 

1277 except: 

1278 response_payload = None 

1279 http_response = { 

1280 "payload": response_payload, 

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

1282 "status": response.status_code, 

1283 } 

1284 _LOGGER.debug( 

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

1286 extra={ 

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

1288 "rpcName": "BatchWrite", 

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

1290 "httpResponse": http_response, 

1291 }, 

1292 ) 

1293 return resp 

1294 

1295 class _BeginTransaction( 

1296 _BaseFirestoreRestTransport._BaseBeginTransaction, FirestoreRestStub 

1297 ): 

1298 def __hash__(self): 

1299 return hash("FirestoreRestTransport.BeginTransaction") 

1300 

1301 @staticmethod 

1302 def _get_response( 

1303 host, 

1304 metadata, 

1305 query_params, 

1306 session, 

1307 timeout, 

1308 transcoded_request, 

1309 body=None, 

1310 ): 

1311 uri = transcoded_request["uri"] 

1312 method = transcoded_request["method"] 

1313 headers = dict(metadata) 

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

1315 response = getattr(session, method)( 

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

1317 timeout=timeout, 

1318 headers=headers, 

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

1320 data=body, 

1321 ) 

1322 return response 

1323 

1324 def __call__( 

1325 self, 

1326 request: firestore.BeginTransactionRequest, 

1327 *, 

1328 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1329 timeout: Optional[float] = None, 

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

1331 ) -> firestore.BeginTransactionResponse: 

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

1333 

1334 Args: 

1335 request (~.firestore.BeginTransactionRequest): 

1336 The request object. The request for 

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

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

1339 should be retried. 

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

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

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

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

1344 be of type `bytes`. 

1345 

1346 Returns: 

1347 ~.firestore.BeginTransactionResponse: 

1348 The response for 

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

1350 

1351 """ 

1352 

1353 http_options = ( 

1354 _BaseFirestoreRestTransport._BaseBeginTransaction._get_http_options() 

1355 ) 

1356 

1357 request, metadata = self._interceptor.pre_begin_transaction( 

1358 request, metadata 

1359 ) 

1360 transcoded_request = _BaseFirestoreRestTransport._BaseBeginTransaction._get_transcoded_request( 

1361 http_options, request 

1362 ) 

1363 

1364 body = _BaseFirestoreRestTransport._BaseBeginTransaction._get_request_body_json( 

1365 transcoded_request 

1366 ) 

1367 

1368 # Jsonify the query params 

1369 query_params = _BaseFirestoreRestTransport._BaseBeginTransaction._get_query_params_json( 

1370 transcoded_request 

1371 ) 

1372 

1373 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1374 logging.DEBUG 

1375 ): # pragma: NO COVER 

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

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

1378 ) 

1379 method = transcoded_request["method"] 

1380 try: 

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

1382 except: 

1383 request_payload = None 

1384 http_request = { 

1385 "payload": request_payload, 

1386 "requestMethod": method, 

1387 "requestUrl": request_url, 

1388 "headers": dict(metadata), 

1389 } 

1390 _LOGGER.debug( 

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

1392 extra={ 

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

1394 "rpcName": "BeginTransaction", 

1395 "httpRequest": http_request, 

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

1397 }, 

1398 ) 

1399 

1400 # Send the request 

1401 response = FirestoreRestTransport._BeginTransaction._get_response( 

1402 self._host, 

1403 metadata, 

1404 query_params, 

1405 self._session, 

1406 timeout, 

1407 transcoded_request, 

1408 body, 

1409 ) 

1410 

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

1412 # subclass. 

1413 if response.status_code >= 400: 

1414 raise core_exceptions.from_http_response(response) 

1415 

1416 # Return the response 

1417 resp = firestore.BeginTransactionResponse() 

1418 pb_resp = firestore.BeginTransactionResponse.pb(resp) 

1419 

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

1421 

1422 resp = self._interceptor.post_begin_transaction(resp) 

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

1424 resp, _ = self._interceptor.post_begin_transaction_with_metadata( 

1425 resp, response_metadata 

1426 ) 

1427 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1428 logging.DEBUG 

1429 ): # pragma: NO COVER 

1430 try: 

1431 response_payload = firestore.BeginTransactionResponse.to_json( 

1432 response 

1433 ) 

1434 except: 

1435 response_payload = None 

1436 http_response = { 

1437 "payload": response_payload, 

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

1439 "status": response.status_code, 

1440 } 

1441 _LOGGER.debug( 

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

1443 extra={ 

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

1445 "rpcName": "BeginTransaction", 

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

1447 "httpResponse": http_response, 

1448 }, 

1449 ) 

1450 return resp 

1451 

1452 class _Commit(_BaseFirestoreRestTransport._BaseCommit, FirestoreRestStub): 

1453 def __hash__(self): 

1454 return hash("FirestoreRestTransport.Commit") 

1455 

1456 @staticmethod 

1457 def _get_response( 

1458 host, 

1459 metadata, 

1460 query_params, 

1461 session, 

1462 timeout, 

1463 transcoded_request, 

1464 body=None, 

1465 ): 

1466 uri = transcoded_request["uri"] 

1467 method = transcoded_request["method"] 

1468 headers = dict(metadata) 

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

1470 response = getattr(session, method)( 

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

1472 timeout=timeout, 

1473 headers=headers, 

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

1475 data=body, 

1476 ) 

1477 return response 

1478 

1479 def __call__( 

1480 self, 

1481 request: firestore.CommitRequest, 

1482 *, 

1483 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1484 timeout: Optional[float] = None, 

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

1486 ) -> firestore.CommitResponse: 

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

1488 

1489 Args: 

1490 request (~.firestore.CommitRequest): 

1491 The request object. The request for 

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

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

1494 should be retried. 

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

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

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

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

1499 be of type `bytes`. 

1500 

1501 Returns: 

1502 ~.firestore.CommitResponse: 

1503 The response for 

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

1505 

1506 """ 

1507 

1508 http_options = _BaseFirestoreRestTransport._BaseCommit._get_http_options() 

1509 

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

1511 transcoded_request = ( 

1512 _BaseFirestoreRestTransport._BaseCommit._get_transcoded_request( 

1513 http_options, request 

1514 ) 

1515 ) 

1516 

1517 body = _BaseFirestoreRestTransport._BaseCommit._get_request_body_json( 

1518 transcoded_request 

1519 ) 

1520 

1521 # Jsonify the query params 

1522 query_params = ( 

1523 _BaseFirestoreRestTransport._BaseCommit._get_query_params_json( 

1524 transcoded_request 

1525 ) 

1526 ) 

1527 

1528 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1529 logging.DEBUG 

1530 ): # pragma: NO COVER 

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

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

1533 ) 

1534 method = transcoded_request["method"] 

1535 try: 

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

1537 except: 

1538 request_payload = None 

1539 http_request = { 

1540 "payload": request_payload, 

1541 "requestMethod": method, 

1542 "requestUrl": request_url, 

1543 "headers": dict(metadata), 

1544 } 

1545 _LOGGER.debug( 

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

1547 extra={ 

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

1549 "rpcName": "Commit", 

1550 "httpRequest": http_request, 

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

1552 }, 

1553 ) 

1554 

1555 # Send the request 

1556 response = FirestoreRestTransport._Commit._get_response( 

1557 self._host, 

1558 metadata, 

1559 query_params, 

1560 self._session, 

1561 timeout, 

1562 transcoded_request, 

1563 body, 

1564 ) 

1565 

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

1567 # subclass. 

1568 if response.status_code >= 400: 

1569 raise core_exceptions.from_http_response(response) 

1570 

1571 # Return the response 

1572 resp = firestore.CommitResponse() 

1573 pb_resp = firestore.CommitResponse.pb(resp) 

1574 

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

1576 

1577 resp = self._interceptor.post_commit(resp) 

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

1579 resp, _ = self._interceptor.post_commit_with_metadata( 

1580 resp, response_metadata 

1581 ) 

1582 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1583 logging.DEBUG 

1584 ): # pragma: NO COVER 

1585 try: 

1586 response_payload = firestore.CommitResponse.to_json(response) 

1587 except: 

1588 response_payload = None 

1589 http_response = { 

1590 "payload": response_payload, 

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

1592 "status": response.status_code, 

1593 } 

1594 _LOGGER.debug( 

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

1596 extra={ 

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

1598 "rpcName": "Commit", 

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

1600 "httpResponse": http_response, 

1601 }, 

1602 ) 

1603 return resp 

1604 

1605 class _CreateDocument( 

1606 _BaseFirestoreRestTransport._BaseCreateDocument, FirestoreRestStub 

1607 ): 

1608 def __hash__(self): 

1609 return hash("FirestoreRestTransport.CreateDocument") 

1610 

1611 @staticmethod 

1612 def _get_response( 

1613 host, 

1614 metadata, 

1615 query_params, 

1616 session, 

1617 timeout, 

1618 transcoded_request, 

1619 body=None, 

1620 ): 

1621 uri = transcoded_request["uri"] 

1622 method = transcoded_request["method"] 

1623 headers = dict(metadata) 

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

1625 response = getattr(session, method)( 

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

1627 timeout=timeout, 

1628 headers=headers, 

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

1630 data=body, 

1631 ) 

1632 return response 

1633 

1634 def __call__( 

1635 self, 

1636 request: firestore.CreateDocumentRequest, 

1637 *, 

1638 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1639 timeout: Optional[float] = None, 

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

1641 ) -> document.Document: 

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

1643 

1644 Args: 

1645 request (~.firestore.CreateDocumentRequest): 

1646 The request object. The request for 

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

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

1649 should be retried. 

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

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

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

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

1654 be of type `bytes`. 

1655 

1656 Returns: 

1657 ~.document.Document: 

1658 A Firestore document. 

1659 

1660 Must not exceed 1 MiB - 4 bytes. 

1661 

1662 """ 

1663 

1664 http_options = ( 

1665 _BaseFirestoreRestTransport._BaseCreateDocument._get_http_options() 

1666 ) 

1667 

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

1669 transcoded_request = ( 

1670 _BaseFirestoreRestTransport._BaseCreateDocument._get_transcoded_request( 

1671 http_options, request 

1672 ) 

1673 ) 

1674 

1675 body = ( 

1676 _BaseFirestoreRestTransport._BaseCreateDocument._get_request_body_json( 

1677 transcoded_request 

1678 ) 

1679 ) 

1680 

1681 # Jsonify the query params 

1682 query_params = ( 

1683 _BaseFirestoreRestTransport._BaseCreateDocument._get_query_params_json( 

1684 transcoded_request 

1685 ) 

1686 ) 

1687 

1688 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1689 logging.DEBUG 

1690 ): # pragma: NO COVER 

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

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

1693 ) 

1694 method = transcoded_request["method"] 

1695 try: 

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

1697 except: 

1698 request_payload = None 

1699 http_request = { 

1700 "payload": request_payload, 

1701 "requestMethod": method, 

1702 "requestUrl": request_url, 

1703 "headers": dict(metadata), 

1704 } 

1705 _LOGGER.debug( 

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

1707 extra={ 

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

1709 "rpcName": "CreateDocument", 

1710 "httpRequest": http_request, 

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

1712 }, 

1713 ) 

1714 

1715 # Send the request 

1716 response = FirestoreRestTransport._CreateDocument._get_response( 

1717 self._host, 

1718 metadata, 

1719 query_params, 

1720 self._session, 

1721 timeout, 

1722 transcoded_request, 

1723 body, 

1724 ) 

1725 

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

1727 # subclass. 

1728 if response.status_code >= 400: 

1729 raise core_exceptions.from_http_response(response) 

1730 

1731 # Return the response 

1732 resp = document.Document() 

1733 pb_resp = document.Document.pb(resp) 

1734 

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

1736 

1737 resp = self._interceptor.post_create_document(resp) 

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

1739 resp, _ = self._interceptor.post_create_document_with_metadata( 

1740 resp, response_metadata 

1741 ) 

1742 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1743 logging.DEBUG 

1744 ): # pragma: NO COVER 

1745 try: 

1746 response_payload = document.Document.to_json(response) 

1747 except: 

1748 response_payload = None 

1749 http_response = { 

1750 "payload": response_payload, 

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

1752 "status": response.status_code, 

1753 } 

1754 _LOGGER.debug( 

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

1756 extra={ 

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

1758 "rpcName": "CreateDocument", 

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

1760 "httpResponse": http_response, 

1761 }, 

1762 ) 

1763 return resp 

1764 

1765 class _DeleteDocument( 

1766 _BaseFirestoreRestTransport._BaseDeleteDocument, FirestoreRestStub 

1767 ): 

1768 def __hash__(self): 

1769 return hash("FirestoreRestTransport.DeleteDocument") 

1770 

1771 @staticmethod 

1772 def _get_response( 

1773 host, 

1774 metadata, 

1775 query_params, 

1776 session, 

1777 timeout, 

1778 transcoded_request, 

1779 body=None, 

1780 ): 

1781 uri = transcoded_request["uri"] 

1782 method = transcoded_request["method"] 

1783 headers = dict(metadata) 

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

1785 response = getattr(session, method)( 

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

1787 timeout=timeout, 

1788 headers=headers, 

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

1790 ) 

1791 return response 

1792 

1793 def __call__( 

1794 self, 

1795 request: firestore.DeleteDocumentRequest, 

1796 *, 

1797 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1798 timeout: Optional[float] = None, 

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

1800 ): 

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

1802 

1803 Args: 

1804 request (~.firestore.DeleteDocumentRequest): 

1805 The request object. The request for 

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

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

1808 should be retried. 

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

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

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

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

1813 be of type `bytes`. 

1814 """ 

1815 

1816 http_options = ( 

1817 _BaseFirestoreRestTransport._BaseDeleteDocument._get_http_options() 

1818 ) 

1819 

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

1821 transcoded_request = ( 

1822 _BaseFirestoreRestTransport._BaseDeleteDocument._get_transcoded_request( 

1823 http_options, request 

1824 ) 

1825 ) 

1826 

1827 # Jsonify the query params 

1828 query_params = ( 

1829 _BaseFirestoreRestTransport._BaseDeleteDocument._get_query_params_json( 

1830 transcoded_request 

1831 ) 

1832 ) 

1833 

1834 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1835 logging.DEBUG 

1836 ): # pragma: NO COVER 

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

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

1839 ) 

1840 method = transcoded_request["method"] 

1841 try: 

1842 request_payload = json_format.MessageToJson(request) 

1843 except: 

1844 request_payload = None 

1845 http_request = { 

1846 "payload": request_payload, 

1847 "requestMethod": method, 

1848 "requestUrl": request_url, 

1849 "headers": dict(metadata), 

1850 } 

1851 _LOGGER.debug( 

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

1853 extra={ 

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

1855 "rpcName": "DeleteDocument", 

1856 "httpRequest": http_request, 

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

1858 }, 

1859 ) 

1860 

1861 # Send the request 

1862 response = FirestoreRestTransport._DeleteDocument._get_response( 

1863 self._host, 

1864 metadata, 

1865 query_params, 

1866 self._session, 

1867 timeout, 

1868 transcoded_request, 

1869 ) 

1870 

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

1872 # subclass. 

1873 if response.status_code >= 400: 

1874 raise core_exceptions.from_http_response(response) 

1875 

1876 class _GetDocument(_BaseFirestoreRestTransport._BaseGetDocument, FirestoreRestStub): 

1877 def __hash__(self): 

1878 return hash("FirestoreRestTransport.GetDocument") 

1879 

1880 @staticmethod 

1881 def _get_response( 

1882 host, 

1883 metadata, 

1884 query_params, 

1885 session, 

1886 timeout, 

1887 transcoded_request, 

1888 body=None, 

1889 ): 

1890 uri = transcoded_request["uri"] 

1891 method = transcoded_request["method"] 

1892 headers = dict(metadata) 

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

1894 response = getattr(session, method)( 

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

1896 timeout=timeout, 

1897 headers=headers, 

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

1899 ) 

1900 return response 

1901 

1902 def __call__( 

1903 self, 

1904 request: firestore.GetDocumentRequest, 

1905 *, 

1906 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1907 timeout: Optional[float] = None, 

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

1909 ) -> document.Document: 

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

1911 

1912 Args: 

1913 request (~.firestore.GetDocumentRequest): 

1914 The request object. The request for 

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

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

1917 should be retried. 

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

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

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

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

1922 be of type `bytes`. 

1923 

1924 Returns: 

1925 ~.document.Document: 

1926 A Firestore document. 

1927 

1928 Must not exceed 1 MiB - 4 bytes. 

1929 

1930 """ 

1931 

1932 http_options = ( 

1933 _BaseFirestoreRestTransport._BaseGetDocument._get_http_options() 

1934 ) 

1935 

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

1937 transcoded_request = ( 

1938 _BaseFirestoreRestTransport._BaseGetDocument._get_transcoded_request( 

1939 http_options, request 

1940 ) 

1941 ) 

1942 

1943 # Jsonify the query params 

1944 query_params = ( 

1945 _BaseFirestoreRestTransport._BaseGetDocument._get_query_params_json( 

1946 transcoded_request 

1947 ) 

1948 ) 

1949 

1950 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

1951 logging.DEBUG 

1952 ): # pragma: NO COVER 

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

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

1955 ) 

1956 method = transcoded_request["method"] 

1957 try: 

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

1959 except: 

1960 request_payload = None 

1961 http_request = { 

1962 "payload": request_payload, 

1963 "requestMethod": method, 

1964 "requestUrl": request_url, 

1965 "headers": dict(metadata), 

1966 } 

1967 _LOGGER.debug( 

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

1969 extra={ 

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

1971 "rpcName": "GetDocument", 

1972 "httpRequest": http_request, 

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

1974 }, 

1975 ) 

1976 

1977 # Send the request 

1978 response = FirestoreRestTransport._GetDocument._get_response( 

1979 self._host, 

1980 metadata, 

1981 query_params, 

1982 self._session, 

1983 timeout, 

1984 transcoded_request, 

1985 ) 

1986 

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

1988 # subclass. 

1989 if response.status_code >= 400: 

1990 raise core_exceptions.from_http_response(response) 

1991 

1992 # Return the response 

1993 resp = document.Document() 

1994 pb_resp = document.Document.pb(resp) 

1995 

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

1997 

1998 resp = self._interceptor.post_get_document(resp) 

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

2000 resp, _ = self._interceptor.post_get_document_with_metadata( 

2001 resp, response_metadata 

2002 ) 

2003 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2004 logging.DEBUG 

2005 ): # pragma: NO COVER 

2006 try: 

2007 response_payload = document.Document.to_json(response) 

2008 except: 

2009 response_payload = None 

2010 http_response = { 

2011 "payload": response_payload, 

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

2013 "status": response.status_code, 

2014 } 

2015 _LOGGER.debug( 

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

2017 extra={ 

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

2019 "rpcName": "GetDocument", 

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

2021 "httpResponse": http_response, 

2022 }, 

2023 ) 

2024 return resp 

2025 

2026 class _ListCollectionIds( 

2027 _BaseFirestoreRestTransport._BaseListCollectionIds, FirestoreRestStub 

2028 ): 

2029 def __hash__(self): 

2030 return hash("FirestoreRestTransport.ListCollectionIds") 

2031 

2032 @staticmethod 

2033 def _get_response( 

2034 host, 

2035 metadata, 

2036 query_params, 

2037 session, 

2038 timeout, 

2039 transcoded_request, 

2040 body=None, 

2041 ): 

2042 uri = transcoded_request["uri"] 

2043 method = transcoded_request["method"] 

2044 headers = dict(metadata) 

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

2046 response = getattr(session, method)( 

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

2048 timeout=timeout, 

2049 headers=headers, 

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

2051 data=body, 

2052 ) 

2053 return response 

2054 

2055 def __call__( 

2056 self, 

2057 request: firestore.ListCollectionIdsRequest, 

2058 *, 

2059 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2060 timeout: Optional[float] = None, 

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

2062 ) -> firestore.ListCollectionIdsResponse: 

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

2064 

2065 Args: 

2066 request (~.firestore.ListCollectionIdsRequest): 

2067 The request object. The request for 

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

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

2070 should be retried. 

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

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

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

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

2075 be of type `bytes`. 

2076 

2077 Returns: 

2078 ~.firestore.ListCollectionIdsResponse: 

2079 The response from 

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

2081 

2082 """ 

2083 

2084 http_options = ( 

2085 _BaseFirestoreRestTransport._BaseListCollectionIds._get_http_options() 

2086 ) 

2087 

2088 request, metadata = self._interceptor.pre_list_collection_ids( 

2089 request, metadata 

2090 ) 

2091 transcoded_request = _BaseFirestoreRestTransport._BaseListCollectionIds._get_transcoded_request( 

2092 http_options, request 

2093 ) 

2094 

2095 body = _BaseFirestoreRestTransport._BaseListCollectionIds._get_request_body_json( 

2096 transcoded_request 

2097 ) 

2098 

2099 # Jsonify the query params 

2100 query_params = _BaseFirestoreRestTransport._BaseListCollectionIds._get_query_params_json( 

2101 transcoded_request 

2102 ) 

2103 

2104 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2105 logging.DEBUG 

2106 ): # pragma: NO COVER 

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

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

2109 ) 

2110 method = transcoded_request["method"] 

2111 try: 

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

2113 except: 

2114 request_payload = None 

2115 http_request = { 

2116 "payload": request_payload, 

2117 "requestMethod": method, 

2118 "requestUrl": request_url, 

2119 "headers": dict(metadata), 

2120 } 

2121 _LOGGER.debug( 

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

2123 extra={ 

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

2125 "rpcName": "ListCollectionIds", 

2126 "httpRequest": http_request, 

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

2128 }, 

2129 ) 

2130 

2131 # Send the request 

2132 response = FirestoreRestTransport._ListCollectionIds._get_response( 

2133 self._host, 

2134 metadata, 

2135 query_params, 

2136 self._session, 

2137 timeout, 

2138 transcoded_request, 

2139 body, 

2140 ) 

2141 

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

2143 # subclass. 

2144 if response.status_code >= 400: 

2145 raise core_exceptions.from_http_response(response) 

2146 

2147 # Return the response 

2148 resp = firestore.ListCollectionIdsResponse() 

2149 pb_resp = firestore.ListCollectionIdsResponse.pb(resp) 

2150 

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

2152 

2153 resp = self._interceptor.post_list_collection_ids(resp) 

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

2155 resp, _ = self._interceptor.post_list_collection_ids_with_metadata( 

2156 resp, response_metadata 

2157 ) 

2158 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2159 logging.DEBUG 

2160 ): # pragma: NO COVER 

2161 try: 

2162 response_payload = firestore.ListCollectionIdsResponse.to_json( 

2163 response 

2164 ) 

2165 except: 

2166 response_payload = None 

2167 http_response = { 

2168 "payload": response_payload, 

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

2170 "status": response.status_code, 

2171 } 

2172 _LOGGER.debug( 

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

2174 extra={ 

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

2176 "rpcName": "ListCollectionIds", 

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

2178 "httpResponse": http_response, 

2179 }, 

2180 ) 

2181 return resp 

2182 

2183 class _ListDocuments( 

2184 _BaseFirestoreRestTransport._BaseListDocuments, FirestoreRestStub 

2185 ): 

2186 def __hash__(self): 

2187 return hash("FirestoreRestTransport.ListDocuments") 

2188 

2189 @staticmethod 

2190 def _get_response( 

2191 host, 

2192 metadata, 

2193 query_params, 

2194 session, 

2195 timeout, 

2196 transcoded_request, 

2197 body=None, 

2198 ): 

2199 uri = transcoded_request["uri"] 

2200 method = transcoded_request["method"] 

2201 headers = dict(metadata) 

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

2203 response = getattr(session, method)( 

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

2205 timeout=timeout, 

2206 headers=headers, 

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

2208 ) 

2209 return response 

2210 

2211 def __call__( 

2212 self, 

2213 request: firestore.ListDocumentsRequest, 

2214 *, 

2215 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2216 timeout: Optional[float] = None, 

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

2218 ) -> firestore.ListDocumentsResponse: 

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

2220 

2221 Args: 

2222 request (~.firestore.ListDocumentsRequest): 

2223 The request object. The request for 

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

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

2226 should be retried. 

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

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

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

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

2231 be of type `bytes`. 

2232 

2233 Returns: 

2234 ~.firestore.ListDocumentsResponse: 

2235 The response for 

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

2237 

2238 """ 

2239 

2240 http_options = ( 

2241 _BaseFirestoreRestTransport._BaseListDocuments._get_http_options() 

2242 ) 

2243 

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

2245 transcoded_request = ( 

2246 _BaseFirestoreRestTransport._BaseListDocuments._get_transcoded_request( 

2247 http_options, request 

2248 ) 

2249 ) 

2250 

2251 # Jsonify the query params 

2252 query_params = ( 

2253 _BaseFirestoreRestTransport._BaseListDocuments._get_query_params_json( 

2254 transcoded_request 

2255 ) 

2256 ) 

2257 

2258 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2259 logging.DEBUG 

2260 ): # pragma: NO COVER 

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

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

2263 ) 

2264 method = transcoded_request["method"] 

2265 try: 

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

2267 except: 

2268 request_payload = None 

2269 http_request = { 

2270 "payload": request_payload, 

2271 "requestMethod": method, 

2272 "requestUrl": request_url, 

2273 "headers": dict(metadata), 

2274 } 

2275 _LOGGER.debug( 

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

2277 extra={ 

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

2279 "rpcName": "ListDocuments", 

2280 "httpRequest": http_request, 

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

2282 }, 

2283 ) 

2284 

2285 # Send the request 

2286 response = FirestoreRestTransport._ListDocuments._get_response( 

2287 self._host, 

2288 metadata, 

2289 query_params, 

2290 self._session, 

2291 timeout, 

2292 transcoded_request, 

2293 ) 

2294 

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

2296 # subclass. 

2297 if response.status_code >= 400: 

2298 raise core_exceptions.from_http_response(response) 

2299 

2300 # Return the response 

2301 resp = firestore.ListDocumentsResponse() 

2302 pb_resp = firestore.ListDocumentsResponse.pb(resp) 

2303 

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

2305 

2306 resp = self._interceptor.post_list_documents(resp) 

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

2308 resp, _ = self._interceptor.post_list_documents_with_metadata( 

2309 resp, response_metadata 

2310 ) 

2311 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2312 logging.DEBUG 

2313 ): # pragma: NO COVER 

2314 try: 

2315 response_payload = firestore.ListDocumentsResponse.to_json(response) 

2316 except: 

2317 response_payload = None 

2318 http_response = { 

2319 "payload": response_payload, 

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

2321 "status": response.status_code, 

2322 } 

2323 _LOGGER.debug( 

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

2325 extra={ 

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

2327 "rpcName": "ListDocuments", 

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

2329 "httpResponse": http_response, 

2330 }, 

2331 ) 

2332 return resp 

2333 

2334 class _Listen(_BaseFirestoreRestTransport._BaseListen, FirestoreRestStub): 

2335 def __hash__(self): 

2336 return hash("FirestoreRestTransport.Listen") 

2337 

2338 def __call__( 

2339 self, 

2340 request: firestore.ListenRequest, 

2341 *, 

2342 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2343 timeout: Optional[float] = None, 

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

2345 ) -> rest_streaming.ResponseIterator: 

2346 raise NotImplementedError( 

2347 "Method Listen is not available over REST transport" 

2348 ) 

2349 

2350 class _PartitionQuery( 

2351 _BaseFirestoreRestTransport._BasePartitionQuery, FirestoreRestStub 

2352 ): 

2353 def __hash__(self): 

2354 return hash("FirestoreRestTransport.PartitionQuery") 

2355 

2356 @staticmethod 

2357 def _get_response( 

2358 host, 

2359 metadata, 

2360 query_params, 

2361 session, 

2362 timeout, 

2363 transcoded_request, 

2364 body=None, 

2365 ): 

2366 uri = transcoded_request["uri"] 

2367 method = transcoded_request["method"] 

2368 headers = dict(metadata) 

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

2370 response = getattr(session, method)( 

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

2372 timeout=timeout, 

2373 headers=headers, 

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

2375 data=body, 

2376 ) 

2377 return response 

2378 

2379 def __call__( 

2380 self, 

2381 request: firestore.PartitionQueryRequest, 

2382 *, 

2383 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2384 timeout: Optional[float] = None, 

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

2386 ) -> firestore.PartitionQueryResponse: 

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

2388 

2389 Args: 

2390 request (~.firestore.PartitionQueryRequest): 

2391 The request object. The request for 

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

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

2394 should be retried. 

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

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

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

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

2399 be of type `bytes`. 

2400 

2401 Returns: 

2402 ~.firestore.PartitionQueryResponse: 

2403 The response for 

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

2405 

2406 """ 

2407 

2408 http_options = ( 

2409 _BaseFirestoreRestTransport._BasePartitionQuery._get_http_options() 

2410 ) 

2411 

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

2413 transcoded_request = ( 

2414 _BaseFirestoreRestTransport._BasePartitionQuery._get_transcoded_request( 

2415 http_options, request 

2416 ) 

2417 ) 

2418 

2419 body = ( 

2420 _BaseFirestoreRestTransport._BasePartitionQuery._get_request_body_json( 

2421 transcoded_request 

2422 ) 

2423 ) 

2424 

2425 # Jsonify the query params 

2426 query_params = ( 

2427 _BaseFirestoreRestTransport._BasePartitionQuery._get_query_params_json( 

2428 transcoded_request 

2429 ) 

2430 ) 

2431 

2432 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2433 logging.DEBUG 

2434 ): # pragma: NO COVER 

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

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

2437 ) 

2438 method = transcoded_request["method"] 

2439 try: 

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

2441 except: 

2442 request_payload = None 

2443 http_request = { 

2444 "payload": request_payload, 

2445 "requestMethod": method, 

2446 "requestUrl": request_url, 

2447 "headers": dict(metadata), 

2448 } 

2449 _LOGGER.debug( 

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

2451 extra={ 

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

2453 "rpcName": "PartitionQuery", 

2454 "httpRequest": http_request, 

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

2456 }, 

2457 ) 

2458 

2459 # Send the request 

2460 response = FirestoreRestTransport._PartitionQuery._get_response( 

2461 self._host, 

2462 metadata, 

2463 query_params, 

2464 self._session, 

2465 timeout, 

2466 transcoded_request, 

2467 body, 

2468 ) 

2469 

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

2471 # subclass. 

2472 if response.status_code >= 400: 

2473 raise core_exceptions.from_http_response(response) 

2474 

2475 # Return the response 

2476 resp = firestore.PartitionQueryResponse() 

2477 pb_resp = firestore.PartitionQueryResponse.pb(resp) 

2478 

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

2480 

2481 resp = self._interceptor.post_partition_query(resp) 

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

2483 resp, _ = self._interceptor.post_partition_query_with_metadata( 

2484 resp, response_metadata 

2485 ) 

2486 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2487 logging.DEBUG 

2488 ): # pragma: NO COVER 

2489 try: 

2490 response_payload = firestore.PartitionQueryResponse.to_json( 

2491 response 

2492 ) 

2493 except: 

2494 response_payload = None 

2495 http_response = { 

2496 "payload": response_payload, 

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

2498 "status": response.status_code, 

2499 } 

2500 _LOGGER.debug( 

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

2502 extra={ 

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

2504 "rpcName": "PartitionQuery", 

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

2506 "httpResponse": http_response, 

2507 }, 

2508 ) 

2509 return resp 

2510 

2511 class _Rollback(_BaseFirestoreRestTransport._BaseRollback, FirestoreRestStub): 

2512 def __hash__(self): 

2513 return hash("FirestoreRestTransport.Rollback") 

2514 

2515 @staticmethod 

2516 def _get_response( 

2517 host, 

2518 metadata, 

2519 query_params, 

2520 session, 

2521 timeout, 

2522 transcoded_request, 

2523 body=None, 

2524 ): 

2525 uri = transcoded_request["uri"] 

2526 method = transcoded_request["method"] 

2527 headers = dict(metadata) 

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

2529 response = getattr(session, method)( 

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

2531 timeout=timeout, 

2532 headers=headers, 

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

2534 data=body, 

2535 ) 

2536 return response 

2537 

2538 def __call__( 

2539 self, 

2540 request: firestore.RollbackRequest, 

2541 *, 

2542 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2543 timeout: Optional[float] = None, 

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

2545 ): 

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

2547 

2548 Args: 

2549 request (~.firestore.RollbackRequest): 

2550 The request object. The request for 

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

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

2553 should be retried. 

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

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

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

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

2558 be of type `bytes`. 

2559 """ 

2560 

2561 http_options = _BaseFirestoreRestTransport._BaseRollback._get_http_options() 

2562 

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

2564 transcoded_request = ( 

2565 _BaseFirestoreRestTransport._BaseRollback._get_transcoded_request( 

2566 http_options, request 

2567 ) 

2568 ) 

2569 

2570 body = _BaseFirestoreRestTransport._BaseRollback._get_request_body_json( 

2571 transcoded_request 

2572 ) 

2573 

2574 # Jsonify the query params 

2575 query_params = ( 

2576 _BaseFirestoreRestTransport._BaseRollback._get_query_params_json( 

2577 transcoded_request 

2578 ) 

2579 ) 

2580 

2581 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2582 logging.DEBUG 

2583 ): # pragma: NO COVER 

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

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

2586 ) 

2587 method = transcoded_request["method"] 

2588 try: 

2589 request_payload = json_format.MessageToJson(request) 

2590 except: 

2591 request_payload = None 

2592 http_request = { 

2593 "payload": request_payload, 

2594 "requestMethod": method, 

2595 "requestUrl": request_url, 

2596 "headers": dict(metadata), 

2597 } 

2598 _LOGGER.debug( 

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

2600 extra={ 

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

2602 "rpcName": "Rollback", 

2603 "httpRequest": http_request, 

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

2605 }, 

2606 ) 

2607 

2608 # Send the request 

2609 response = FirestoreRestTransport._Rollback._get_response( 

2610 self._host, 

2611 metadata, 

2612 query_params, 

2613 self._session, 

2614 timeout, 

2615 transcoded_request, 

2616 body, 

2617 ) 

2618 

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

2620 # subclass. 

2621 if response.status_code >= 400: 

2622 raise core_exceptions.from_http_response(response) 

2623 

2624 class _RunAggregationQuery( 

2625 _BaseFirestoreRestTransport._BaseRunAggregationQuery, FirestoreRestStub 

2626 ): 

2627 def __hash__(self): 

2628 return hash("FirestoreRestTransport.RunAggregationQuery") 

2629 

2630 @staticmethod 

2631 def _get_response( 

2632 host, 

2633 metadata, 

2634 query_params, 

2635 session, 

2636 timeout, 

2637 transcoded_request, 

2638 body=None, 

2639 ): 

2640 uri = transcoded_request["uri"] 

2641 method = transcoded_request["method"] 

2642 headers = dict(metadata) 

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

2644 response = getattr(session, method)( 

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

2646 timeout=timeout, 

2647 headers=headers, 

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

2649 data=body, 

2650 stream=True, 

2651 ) 

2652 return response 

2653 

2654 def __call__( 

2655 self, 

2656 request: firestore.RunAggregationQueryRequest, 

2657 *, 

2658 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2659 timeout: Optional[float] = None, 

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

2661 ) -> rest_streaming.ResponseIterator: 

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

2663 

2664 Args: 

2665 request (~.firestore.RunAggregationQueryRequest): 

2666 The request object. The request for 

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

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

2669 should be retried. 

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

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

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

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

2674 be of type `bytes`. 

2675 

2676 Returns: 

2677 ~.firestore.RunAggregationQueryResponse: 

2678 The response for 

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

2680 

2681 """ 

2682 

2683 http_options = ( 

2684 _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_http_options() 

2685 ) 

2686 

2687 request, metadata = self._interceptor.pre_run_aggregation_query( 

2688 request, metadata 

2689 ) 

2690 transcoded_request = _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_transcoded_request( 

2691 http_options, request 

2692 ) 

2693 

2694 body = _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_request_body_json( 

2695 transcoded_request 

2696 ) 

2697 

2698 # Jsonify the query params 

2699 query_params = _BaseFirestoreRestTransport._BaseRunAggregationQuery._get_query_params_json( 

2700 transcoded_request 

2701 ) 

2702 

2703 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2704 logging.DEBUG 

2705 ): # pragma: NO COVER 

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

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

2708 ) 

2709 method = transcoded_request["method"] 

2710 try: 

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

2712 except: 

2713 request_payload = None 

2714 http_request = { 

2715 "payload": request_payload, 

2716 "requestMethod": method, 

2717 "requestUrl": request_url, 

2718 "headers": dict(metadata), 

2719 } 

2720 _LOGGER.debug( 

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

2722 extra={ 

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

2724 "rpcName": "RunAggregationQuery", 

2725 "httpRequest": http_request, 

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

2727 }, 

2728 ) 

2729 

2730 # Send the request 

2731 response = FirestoreRestTransport._RunAggregationQuery._get_response( 

2732 self._host, 

2733 metadata, 

2734 query_params, 

2735 self._session, 

2736 timeout, 

2737 transcoded_request, 

2738 body, 

2739 ) 

2740 

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

2742 # subclass. 

2743 if response.status_code >= 400: 

2744 raise core_exceptions.from_http_response(response) 

2745 

2746 # Return the response 

2747 resp = rest_streaming.ResponseIterator( 

2748 response, firestore.RunAggregationQueryResponse 

2749 ) 

2750 

2751 resp = self._interceptor.post_run_aggregation_query(resp) 

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

2753 resp, _ = self._interceptor.post_run_aggregation_query_with_metadata( 

2754 resp, response_metadata 

2755 ) 

2756 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2757 logging.DEBUG 

2758 ): # pragma: NO COVER 

2759 http_response = { 

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

2761 "status": response.status_code, 

2762 } 

2763 _LOGGER.debug( 

2764 "Received response for google.firestore_v1.FirestoreClient.run_aggregation_query", 

2765 extra={ 

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

2767 "rpcName": "RunAggregationQuery", 

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

2769 "httpResponse": http_response, 

2770 }, 

2771 ) 

2772 return resp 

2773 

2774 class _RunQuery(_BaseFirestoreRestTransport._BaseRunQuery, FirestoreRestStub): 

2775 def __hash__(self): 

2776 return hash("FirestoreRestTransport.RunQuery") 

2777 

2778 @staticmethod 

2779 def _get_response( 

2780 host, 

2781 metadata, 

2782 query_params, 

2783 session, 

2784 timeout, 

2785 transcoded_request, 

2786 body=None, 

2787 ): 

2788 uri = transcoded_request["uri"] 

2789 method = transcoded_request["method"] 

2790 headers = dict(metadata) 

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

2792 response = getattr(session, method)( 

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

2794 timeout=timeout, 

2795 headers=headers, 

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

2797 data=body, 

2798 stream=True, 

2799 ) 

2800 return response 

2801 

2802 def __call__( 

2803 self, 

2804 request: firestore.RunQueryRequest, 

2805 *, 

2806 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2807 timeout: Optional[float] = None, 

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

2809 ) -> rest_streaming.ResponseIterator: 

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

2811 

2812 Args: 

2813 request (~.firestore.RunQueryRequest): 

2814 The request object. The request for 

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

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

2817 should be retried. 

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

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

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

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

2822 be of type `bytes`. 

2823 

2824 Returns: 

2825 ~.firestore.RunQueryResponse: 

2826 The response for 

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

2828 

2829 """ 

2830 

2831 http_options = _BaseFirestoreRestTransport._BaseRunQuery._get_http_options() 

2832 

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

2834 transcoded_request = ( 

2835 _BaseFirestoreRestTransport._BaseRunQuery._get_transcoded_request( 

2836 http_options, request 

2837 ) 

2838 ) 

2839 

2840 body = _BaseFirestoreRestTransport._BaseRunQuery._get_request_body_json( 

2841 transcoded_request 

2842 ) 

2843 

2844 # Jsonify the query params 

2845 query_params = ( 

2846 _BaseFirestoreRestTransport._BaseRunQuery._get_query_params_json( 

2847 transcoded_request 

2848 ) 

2849 ) 

2850 

2851 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2852 logging.DEBUG 

2853 ): # pragma: NO COVER 

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

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

2856 ) 

2857 method = transcoded_request["method"] 

2858 try: 

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

2860 except: 

2861 request_payload = None 

2862 http_request = { 

2863 "payload": request_payload, 

2864 "requestMethod": method, 

2865 "requestUrl": request_url, 

2866 "headers": dict(metadata), 

2867 } 

2868 _LOGGER.debug( 

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

2870 extra={ 

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

2872 "rpcName": "RunQuery", 

2873 "httpRequest": http_request, 

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

2875 }, 

2876 ) 

2877 

2878 # Send the request 

2879 response = FirestoreRestTransport._RunQuery._get_response( 

2880 self._host, 

2881 metadata, 

2882 query_params, 

2883 self._session, 

2884 timeout, 

2885 transcoded_request, 

2886 body, 

2887 ) 

2888 

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

2890 # subclass. 

2891 if response.status_code >= 400: 

2892 raise core_exceptions.from_http_response(response) 

2893 

2894 # Return the response 

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

2896 

2897 resp = self._interceptor.post_run_query(resp) 

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

2899 resp, _ = self._interceptor.post_run_query_with_metadata( 

2900 resp, response_metadata 

2901 ) 

2902 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

2903 logging.DEBUG 

2904 ): # pragma: NO COVER 

2905 http_response = { 

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

2907 "status": response.status_code, 

2908 } 

2909 _LOGGER.debug( 

2910 "Received response for google.firestore_v1.FirestoreClient.run_query", 

2911 extra={ 

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

2913 "rpcName": "RunQuery", 

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

2915 "httpResponse": http_response, 

2916 }, 

2917 ) 

2918 return resp 

2919 

2920 class _UpdateDocument( 

2921 _BaseFirestoreRestTransport._BaseUpdateDocument, FirestoreRestStub 

2922 ): 

2923 def __hash__(self): 

2924 return hash("FirestoreRestTransport.UpdateDocument") 

2925 

2926 @staticmethod 

2927 def _get_response( 

2928 host, 

2929 metadata, 

2930 query_params, 

2931 session, 

2932 timeout, 

2933 transcoded_request, 

2934 body=None, 

2935 ): 

2936 uri = transcoded_request["uri"] 

2937 method = transcoded_request["method"] 

2938 headers = dict(metadata) 

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

2940 response = getattr(session, method)( 

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

2942 timeout=timeout, 

2943 headers=headers, 

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

2945 data=body, 

2946 ) 

2947 return response 

2948 

2949 def __call__( 

2950 self, 

2951 request: firestore.UpdateDocumentRequest, 

2952 *, 

2953 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

2954 timeout: Optional[float] = None, 

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

2956 ) -> gf_document.Document: 

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

2958 

2959 Args: 

2960 request (~.firestore.UpdateDocumentRequest): 

2961 The request object. The request for 

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

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

2964 should be retried. 

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

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

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

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

2969 be of type `bytes`. 

2970 

2971 Returns: 

2972 ~.gf_document.Document: 

2973 A Firestore document. 

2974 

2975 Must not exceed 1 MiB - 4 bytes. 

2976 

2977 """ 

2978 

2979 http_options = ( 

2980 _BaseFirestoreRestTransport._BaseUpdateDocument._get_http_options() 

2981 ) 

2982 

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

2984 transcoded_request = ( 

2985 _BaseFirestoreRestTransport._BaseUpdateDocument._get_transcoded_request( 

2986 http_options, request 

2987 ) 

2988 ) 

2989 

2990 body = ( 

2991 _BaseFirestoreRestTransport._BaseUpdateDocument._get_request_body_json( 

2992 transcoded_request 

2993 ) 

2994 ) 

2995 

2996 # Jsonify the query params 

2997 query_params = ( 

2998 _BaseFirestoreRestTransport._BaseUpdateDocument._get_query_params_json( 

2999 transcoded_request 

3000 ) 

3001 ) 

3002 

3003 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3004 logging.DEBUG 

3005 ): # pragma: NO COVER 

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

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

3008 ) 

3009 method = transcoded_request["method"] 

3010 try: 

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

3012 except: 

3013 request_payload = None 

3014 http_request = { 

3015 "payload": request_payload, 

3016 "requestMethod": method, 

3017 "requestUrl": request_url, 

3018 "headers": dict(metadata), 

3019 } 

3020 _LOGGER.debug( 

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

3022 extra={ 

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

3024 "rpcName": "UpdateDocument", 

3025 "httpRequest": http_request, 

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

3027 }, 

3028 ) 

3029 

3030 # Send the request 

3031 response = FirestoreRestTransport._UpdateDocument._get_response( 

3032 self._host, 

3033 metadata, 

3034 query_params, 

3035 self._session, 

3036 timeout, 

3037 transcoded_request, 

3038 body, 

3039 ) 

3040 

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

3042 # subclass. 

3043 if response.status_code >= 400: 

3044 raise core_exceptions.from_http_response(response) 

3045 

3046 # Return the response 

3047 resp = gf_document.Document() 

3048 pb_resp = gf_document.Document.pb(resp) 

3049 

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

3051 

3052 resp = self._interceptor.post_update_document(resp) 

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

3054 resp, _ = self._interceptor.post_update_document_with_metadata( 

3055 resp, response_metadata 

3056 ) 

3057 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3058 logging.DEBUG 

3059 ): # pragma: NO COVER 

3060 try: 

3061 response_payload = gf_document.Document.to_json(response) 

3062 except: 

3063 response_payload = None 

3064 http_response = { 

3065 "payload": response_payload, 

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

3067 "status": response.status_code, 

3068 } 

3069 _LOGGER.debug( 

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

3071 extra={ 

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

3073 "rpcName": "UpdateDocument", 

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

3075 "httpResponse": http_response, 

3076 }, 

3077 ) 

3078 return resp 

3079 

3080 class _Write(_BaseFirestoreRestTransport._BaseWrite, FirestoreRestStub): 

3081 def __hash__(self): 

3082 return hash("FirestoreRestTransport.Write") 

3083 

3084 def __call__( 

3085 self, 

3086 request: firestore.WriteRequest, 

3087 *, 

3088 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3089 timeout: Optional[float] = None, 

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

3091 ) -> rest_streaming.ResponseIterator: 

3092 raise NotImplementedError( 

3093 "Method Write is not available over REST transport" 

3094 ) 

3095 

3096 @property 

3097 def batch_get_documents( 

3098 self, 

3099 ) -> Callable[ 

3100 [firestore.BatchGetDocumentsRequest], firestore.BatchGetDocumentsResponse 

3101 ]: 

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

3103 # In C++ this would require a dynamic_cast 

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

3105 

3106 @property 

3107 def batch_write( 

3108 self, 

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

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

3111 # In C++ this would require a dynamic_cast 

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

3113 

3114 @property 

3115 def begin_transaction( 

3116 self, 

3117 ) -> Callable[ 

3118 [firestore.BeginTransactionRequest], firestore.BeginTransactionResponse 

3119 ]: 

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

3121 # In C++ this would require a dynamic_cast 

3122 return self._BeginTransaction(self._session, self._host, self._interceptor) # type: ignore 

3123 

3124 @property 

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

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

3127 # In C++ this would require a dynamic_cast 

3128 return self._Commit(self._session, self._host, self._interceptor) # type: ignore 

3129 

3130 @property 

3131 def create_document( 

3132 self, 

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

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

3135 # In C++ this would require a dynamic_cast 

3136 return self._CreateDocument(self._session, self._host, self._interceptor) # type: ignore 

3137 

3138 @property 

3139 def delete_document( 

3140 self, 

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

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

3143 # In C++ this would require a dynamic_cast 

3144 return self._DeleteDocument(self._session, self._host, self._interceptor) # type: ignore 

3145 

3146 @property 

3147 def get_document( 

3148 self, 

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

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

3151 # In C++ this would require a dynamic_cast 

3152 return self._GetDocument(self._session, self._host, self._interceptor) # type: ignore 

3153 

3154 @property 

3155 def list_collection_ids( 

3156 self, 

3157 ) -> Callable[ 

3158 [firestore.ListCollectionIdsRequest], firestore.ListCollectionIdsResponse 

3159 ]: 

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

3161 # In C++ this would require a dynamic_cast 

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

3163 

3164 @property 

3165 def list_documents( 

3166 self, 

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

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

3169 # In C++ this would require a dynamic_cast 

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

3171 

3172 @property 

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

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

3175 # In C++ this would require a dynamic_cast 

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

3177 

3178 @property 

3179 def partition_query( 

3180 self, 

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

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

3183 # In C++ this would require a dynamic_cast 

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

3185 

3186 @property 

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

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

3189 # In C++ this would require a dynamic_cast 

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

3191 

3192 @property 

3193 def run_aggregation_query( 

3194 self, 

3195 ) -> Callable[ 

3196 [firestore.RunAggregationQueryRequest], firestore.RunAggregationQueryResponse 

3197 ]: 

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

3199 # In C++ this would require a dynamic_cast 

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

3201 

3202 @property 

3203 def run_query( 

3204 self, 

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

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

3207 # In C++ this would require a dynamic_cast 

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

3209 

3210 @property 

3211 def update_document( 

3212 self, 

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

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

3215 # In C++ this would require a dynamic_cast 

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

3217 

3218 @property 

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

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

3221 # In C++ this would require a dynamic_cast 

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

3223 

3224 @property 

3225 def cancel_operation(self): 

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

3227 

3228 class _CancelOperation( 

3229 _BaseFirestoreRestTransport._BaseCancelOperation, FirestoreRestStub 

3230 ): 

3231 def __hash__(self): 

3232 return hash("FirestoreRestTransport.CancelOperation") 

3233 

3234 @staticmethod 

3235 def _get_response( 

3236 host, 

3237 metadata, 

3238 query_params, 

3239 session, 

3240 timeout, 

3241 transcoded_request, 

3242 body=None, 

3243 ): 

3244 uri = transcoded_request["uri"] 

3245 method = transcoded_request["method"] 

3246 headers = dict(metadata) 

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

3248 response = getattr(session, method)( 

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

3250 timeout=timeout, 

3251 headers=headers, 

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

3253 data=body, 

3254 ) 

3255 return response 

3256 

3257 def __call__( 

3258 self, 

3259 request: operations_pb2.CancelOperationRequest, 

3260 *, 

3261 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3262 timeout: Optional[float] = None, 

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

3264 ) -> None: 

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

3266 

3267 Args: 

3268 request (operations_pb2.CancelOperationRequest): 

3269 The request object for CancelOperation method. 

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

3271 should be retried. 

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

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

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

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

3276 be of type `bytes`. 

3277 """ 

3278 

3279 http_options = ( 

3280 _BaseFirestoreRestTransport._BaseCancelOperation._get_http_options() 

3281 ) 

3282 

3283 request, metadata = self._interceptor.pre_cancel_operation( 

3284 request, metadata 

3285 ) 

3286 transcoded_request = _BaseFirestoreRestTransport._BaseCancelOperation._get_transcoded_request( 

3287 http_options, request 

3288 ) 

3289 

3290 body = ( 

3291 _BaseFirestoreRestTransport._BaseCancelOperation._get_request_body_json( 

3292 transcoded_request 

3293 ) 

3294 ) 

3295 

3296 # Jsonify the query params 

3297 query_params = ( 

3298 _BaseFirestoreRestTransport._BaseCancelOperation._get_query_params_json( 

3299 transcoded_request 

3300 ) 

3301 ) 

3302 

3303 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3304 logging.DEBUG 

3305 ): # pragma: NO COVER 

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

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

3308 ) 

3309 method = transcoded_request["method"] 

3310 try: 

3311 request_payload = json_format.MessageToJson(request) 

3312 except: 

3313 request_payload = None 

3314 http_request = { 

3315 "payload": request_payload, 

3316 "requestMethod": method, 

3317 "requestUrl": request_url, 

3318 "headers": dict(metadata), 

3319 } 

3320 _LOGGER.debug( 

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

3322 extra={ 

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

3324 "rpcName": "CancelOperation", 

3325 "httpRequest": http_request, 

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

3327 }, 

3328 ) 

3329 

3330 # Send the request 

3331 response = FirestoreRestTransport._CancelOperation._get_response( 

3332 self._host, 

3333 metadata, 

3334 query_params, 

3335 self._session, 

3336 timeout, 

3337 transcoded_request, 

3338 body, 

3339 ) 

3340 

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

3342 # subclass. 

3343 if response.status_code >= 400: 

3344 raise core_exceptions.from_http_response(response) 

3345 

3346 return self._interceptor.post_cancel_operation(None) 

3347 

3348 @property 

3349 def delete_operation(self): 

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

3351 

3352 class _DeleteOperation( 

3353 _BaseFirestoreRestTransport._BaseDeleteOperation, FirestoreRestStub 

3354 ): 

3355 def __hash__(self): 

3356 return hash("FirestoreRestTransport.DeleteOperation") 

3357 

3358 @staticmethod 

3359 def _get_response( 

3360 host, 

3361 metadata, 

3362 query_params, 

3363 session, 

3364 timeout, 

3365 transcoded_request, 

3366 body=None, 

3367 ): 

3368 uri = transcoded_request["uri"] 

3369 method = transcoded_request["method"] 

3370 headers = dict(metadata) 

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

3372 response = getattr(session, method)( 

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

3374 timeout=timeout, 

3375 headers=headers, 

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

3377 ) 

3378 return response 

3379 

3380 def __call__( 

3381 self, 

3382 request: operations_pb2.DeleteOperationRequest, 

3383 *, 

3384 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3385 timeout: Optional[float] = None, 

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

3387 ) -> None: 

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

3389 

3390 Args: 

3391 request (operations_pb2.DeleteOperationRequest): 

3392 The request object for DeleteOperation method. 

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

3394 should be retried. 

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

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

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

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

3399 be of type `bytes`. 

3400 """ 

3401 

3402 http_options = ( 

3403 _BaseFirestoreRestTransport._BaseDeleteOperation._get_http_options() 

3404 ) 

3405 

3406 request, metadata = self._interceptor.pre_delete_operation( 

3407 request, metadata 

3408 ) 

3409 transcoded_request = _BaseFirestoreRestTransport._BaseDeleteOperation._get_transcoded_request( 

3410 http_options, request 

3411 ) 

3412 

3413 # Jsonify the query params 

3414 query_params = ( 

3415 _BaseFirestoreRestTransport._BaseDeleteOperation._get_query_params_json( 

3416 transcoded_request 

3417 ) 

3418 ) 

3419 

3420 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3421 logging.DEBUG 

3422 ): # pragma: NO COVER 

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

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

3425 ) 

3426 method = transcoded_request["method"] 

3427 try: 

3428 request_payload = json_format.MessageToJson(request) 

3429 except: 

3430 request_payload = None 

3431 http_request = { 

3432 "payload": request_payload, 

3433 "requestMethod": method, 

3434 "requestUrl": request_url, 

3435 "headers": dict(metadata), 

3436 } 

3437 _LOGGER.debug( 

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

3439 extra={ 

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

3441 "rpcName": "DeleteOperation", 

3442 "httpRequest": http_request, 

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

3444 }, 

3445 ) 

3446 

3447 # Send the request 

3448 response = FirestoreRestTransport._DeleteOperation._get_response( 

3449 self._host, 

3450 metadata, 

3451 query_params, 

3452 self._session, 

3453 timeout, 

3454 transcoded_request, 

3455 ) 

3456 

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

3458 # subclass. 

3459 if response.status_code >= 400: 

3460 raise core_exceptions.from_http_response(response) 

3461 

3462 return self._interceptor.post_delete_operation(None) 

3463 

3464 @property 

3465 def get_operation(self): 

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

3467 

3468 class _GetOperation( 

3469 _BaseFirestoreRestTransport._BaseGetOperation, FirestoreRestStub 

3470 ): 

3471 def __hash__(self): 

3472 return hash("FirestoreRestTransport.GetOperation") 

3473 

3474 @staticmethod 

3475 def _get_response( 

3476 host, 

3477 metadata, 

3478 query_params, 

3479 session, 

3480 timeout, 

3481 transcoded_request, 

3482 body=None, 

3483 ): 

3484 uri = transcoded_request["uri"] 

3485 method = transcoded_request["method"] 

3486 headers = dict(metadata) 

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

3488 response = getattr(session, method)( 

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

3490 timeout=timeout, 

3491 headers=headers, 

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

3493 ) 

3494 return response 

3495 

3496 def __call__( 

3497 self, 

3498 request: operations_pb2.GetOperationRequest, 

3499 *, 

3500 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3501 timeout: Optional[float] = None, 

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

3503 ) -> operations_pb2.Operation: 

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

3505 

3506 Args: 

3507 request (operations_pb2.GetOperationRequest): 

3508 The request object for GetOperation method. 

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

3510 should be retried. 

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

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

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

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

3515 be of type `bytes`. 

3516 

3517 Returns: 

3518 operations_pb2.Operation: Response from GetOperation method. 

3519 """ 

3520 

3521 http_options = ( 

3522 _BaseFirestoreRestTransport._BaseGetOperation._get_http_options() 

3523 ) 

3524 

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

3526 transcoded_request = ( 

3527 _BaseFirestoreRestTransport._BaseGetOperation._get_transcoded_request( 

3528 http_options, request 

3529 ) 

3530 ) 

3531 

3532 # Jsonify the query params 

3533 query_params = ( 

3534 _BaseFirestoreRestTransport._BaseGetOperation._get_query_params_json( 

3535 transcoded_request 

3536 ) 

3537 ) 

3538 

3539 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3540 logging.DEBUG 

3541 ): # pragma: NO COVER 

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

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

3544 ) 

3545 method = transcoded_request["method"] 

3546 try: 

3547 request_payload = json_format.MessageToJson(request) 

3548 except: 

3549 request_payload = None 

3550 http_request = { 

3551 "payload": request_payload, 

3552 "requestMethod": method, 

3553 "requestUrl": request_url, 

3554 "headers": dict(metadata), 

3555 } 

3556 _LOGGER.debug( 

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

3558 extra={ 

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

3560 "rpcName": "GetOperation", 

3561 "httpRequest": http_request, 

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

3563 }, 

3564 ) 

3565 

3566 # Send the request 

3567 response = FirestoreRestTransport._GetOperation._get_response( 

3568 self._host, 

3569 metadata, 

3570 query_params, 

3571 self._session, 

3572 timeout, 

3573 transcoded_request, 

3574 ) 

3575 

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

3577 # subclass. 

3578 if response.status_code >= 400: 

3579 raise core_exceptions.from_http_response(response) 

3580 

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

3582 resp = operations_pb2.Operation() 

3583 resp = json_format.Parse(content, resp) 

3584 resp = self._interceptor.post_get_operation(resp) 

3585 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3586 logging.DEBUG 

3587 ): # pragma: NO COVER 

3588 try: 

3589 response_payload = json_format.MessageToJson(resp) 

3590 except: 

3591 response_payload = None 

3592 http_response = { 

3593 "payload": response_payload, 

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

3595 "status": response.status_code, 

3596 } 

3597 _LOGGER.debug( 

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

3599 extra={ 

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

3601 "rpcName": "GetOperation", 

3602 "httpResponse": http_response, 

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

3604 }, 

3605 ) 

3606 return resp 

3607 

3608 @property 

3609 def list_operations(self): 

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

3611 

3612 class _ListOperations( 

3613 _BaseFirestoreRestTransport._BaseListOperations, FirestoreRestStub 

3614 ): 

3615 def __hash__(self): 

3616 return hash("FirestoreRestTransport.ListOperations") 

3617 

3618 @staticmethod 

3619 def _get_response( 

3620 host, 

3621 metadata, 

3622 query_params, 

3623 session, 

3624 timeout, 

3625 transcoded_request, 

3626 body=None, 

3627 ): 

3628 uri = transcoded_request["uri"] 

3629 method = transcoded_request["method"] 

3630 headers = dict(metadata) 

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

3632 response = getattr(session, method)( 

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

3634 timeout=timeout, 

3635 headers=headers, 

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

3637 ) 

3638 return response 

3639 

3640 def __call__( 

3641 self, 

3642 request: operations_pb2.ListOperationsRequest, 

3643 *, 

3644 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

3645 timeout: Optional[float] = None, 

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

3647 ) -> operations_pb2.ListOperationsResponse: 

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

3649 

3650 Args: 

3651 request (operations_pb2.ListOperationsRequest): 

3652 The request object for ListOperations method. 

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

3654 should be retried. 

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

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

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

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

3659 be of type `bytes`. 

3660 

3661 Returns: 

3662 operations_pb2.ListOperationsResponse: Response from ListOperations method. 

3663 """ 

3664 

3665 http_options = ( 

3666 _BaseFirestoreRestTransport._BaseListOperations._get_http_options() 

3667 ) 

3668 

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

3670 transcoded_request = ( 

3671 _BaseFirestoreRestTransport._BaseListOperations._get_transcoded_request( 

3672 http_options, request 

3673 ) 

3674 ) 

3675 

3676 # Jsonify the query params 

3677 query_params = ( 

3678 _BaseFirestoreRestTransport._BaseListOperations._get_query_params_json( 

3679 transcoded_request 

3680 ) 

3681 ) 

3682 

3683 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3684 logging.DEBUG 

3685 ): # pragma: NO COVER 

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

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

3688 ) 

3689 method = transcoded_request["method"] 

3690 try: 

3691 request_payload = json_format.MessageToJson(request) 

3692 except: 

3693 request_payload = None 

3694 http_request = { 

3695 "payload": request_payload, 

3696 "requestMethod": method, 

3697 "requestUrl": request_url, 

3698 "headers": dict(metadata), 

3699 } 

3700 _LOGGER.debug( 

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

3702 extra={ 

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

3704 "rpcName": "ListOperations", 

3705 "httpRequest": http_request, 

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

3707 }, 

3708 ) 

3709 

3710 # Send the request 

3711 response = FirestoreRestTransport._ListOperations._get_response( 

3712 self._host, 

3713 metadata, 

3714 query_params, 

3715 self._session, 

3716 timeout, 

3717 transcoded_request, 

3718 ) 

3719 

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

3721 # subclass. 

3722 if response.status_code >= 400: 

3723 raise core_exceptions.from_http_response(response) 

3724 

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

3726 resp = operations_pb2.ListOperationsResponse() 

3727 resp = json_format.Parse(content, resp) 

3728 resp = self._interceptor.post_list_operations(resp) 

3729 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

3730 logging.DEBUG 

3731 ): # pragma: NO COVER 

3732 try: 

3733 response_payload = json_format.MessageToJson(resp) 

3734 except: 

3735 response_payload = None 

3736 http_response = { 

3737 "payload": response_payload, 

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

3739 "status": response.status_code, 

3740 } 

3741 _LOGGER.debug( 

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

3743 extra={ 

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

3745 "rpcName": "ListOperations", 

3746 "httpResponse": http_response, 

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

3748 }, 

3749 ) 

3750 return resp 

3751 

3752 @property 

3753 def kind(self) -> str: 

3754 return "rest" 

3755 

3756 def close(self): 

3757 self._session.close() 

3758 

3759 

3760__all__ = ("FirestoreRestTransport",)