Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/services/logging_service_v2/pagers.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

152 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# 

16from google.api_core import gapic_v1 

17from google.api_core import retry as retries 

18from google.api_core import retry_async as retries_async 

19from typing import ( 

20 Any, 

21 AsyncIterator, 

22 Awaitable, 

23 Callable, 

24 Sequence, 

25 Tuple, 

26 Optional, 

27 Iterator, 

28 Union, 

29) 

30 

31try: 

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

33 OptionalAsyncRetry = Union[ 

34 retries_async.AsyncRetry, gapic_v1.method._MethodDefault, None 

35 ] 

36except AttributeError: # pragma: NO COVER 

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

38 OptionalAsyncRetry = Union[retries_async.AsyncRetry, object, None] # type: ignore 

39 

40from google.api import monitored_resource_pb2 # type: ignore 

41from google.cloud.logging_v2.types import log_entry 

42from google.cloud.logging_v2.types import logging 

43 

44 

45class ListLogEntriesPager: 

46 """A pager for iterating through ``list_log_entries`` requests. 

47 

48 This class thinly wraps an initial 

49 :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` object, and 

50 provides an ``__iter__`` method to iterate through its 

51 ``entries`` field. 

52 

53 If there are more pages, the ``__iter__`` method will make additional 

54 ``ListLogEntries`` requests and continue to iterate 

55 through the ``entries`` field on the 

56 corresponding responses. 

57 

58 All the usual :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` 

59 attributes are available on the pager. If multiple requests are made, only 

60 the most recent response is retained, and thus used for attribute lookup. 

61 """ 

62 

63 def __init__( 

64 self, 

65 method: Callable[..., logging.ListLogEntriesResponse], 

66 request: logging.ListLogEntriesRequest, 

67 response: logging.ListLogEntriesResponse, 

68 *, 

69 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

70 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

72 ): 

73 """Instantiate the pager. 

74 

75 Args: 

76 method (Callable): The method that was originally called, and 

77 which instantiated this pager. 

78 request (google.cloud.logging_v2.types.ListLogEntriesRequest): 

79 The initial request object. 

80 response (google.cloud.logging_v2.types.ListLogEntriesResponse): 

81 The initial response object. 

82 retry (google.api_core.retry.Retry): Designation of what errors, 

83 if any, should be retried. 

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

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

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

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

88 be of type `bytes`. 

89 """ 

90 self._method = method 

91 self._request = logging.ListLogEntriesRequest(request) 

92 self._response = response 

93 self._retry = retry 

94 self._timeout = timeout 

95 self._metadata = metadata 

96 

97 def __getattr__(self, name: str) -> Any: 

98 return getattr(self._response, name) 

99 

100 @property 

101 def pages(self) -> Iterator[logging.ListLogEntriesResponse]: 

102 yield self._response 

103 while self._response.next_page_token: 

104 self._request.page_token = self._response.next_page_token 

105 self._response = self._method( 

106 self._request, 

107 retry=self._retry, 

108 timeout=self._timeout, 

109 metadata=self._metadata, 

110 ) 

111 yield self._response 

112 

113 def __iter__(self) -> Iterator[log_entry.LogEntry]: 

114 for page in self.pages: 

115 yield from page.entries 

116 

117 def __repr__(self) -> str: 

118 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

119 

120 

121class ListLogEntriesAsyncPager: 

122 """A pager for iterating through ``list_log_entries`` requests. 

123 

124 This class thinly wraps an initial 

125 :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` object, and 

126 provides an ``__aiter__`` method to iterate through its 

127 ``entries`` field. 

128 

129 If there are more pages, the ``__aiter__`` method will make additional 

130 ``ListLogEntries`` requests and continue to iterate 

131 through the ``entries`` field on the 

132 corresponding responses. 

133 

134 All the usual :class:`google.cloud.logging_v2.types.ListLogEntriesResponse` 

135 attributes are available on the pager. If multiple requests are made, only 

136 the most recent response is retained, and thus used for attribute lookup. 

137 """ 

138 

139 def __init__( 

140 self, 

141 method: Callable[..., Awaitable[logging.ListLogEntriesResponse]], 

142 request: logging.ListLogEntriesRequest, 

143 response: logging.ListLogEntriesResponse, 

144 *, 

145 retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, 

146 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

148 ): 

149 """Instantiates the pager. 

150 

151 Args: 

152 method (Callable): The method that was originally called, and 

153 which instantiated this pager. 

154 request (google.cloud.logging_v2.types.ListLogEntriesRequest): 

155 The initial request object. 

156 response (google.cloud.logging_v2.types.ListLogEntriesResponse): 

157 The initial response object. 

158 retry (google.api_core.retry.AsyncRetry): Designation of what errors, 

159 if any, should be retried. 

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

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

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

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

164 be of type `bytes`. 

165 """ 

166 self._method = method 

167 self._request = logging.ListLogEntriesRequest(request) 

168 self._response = response 

169 self._retry = retry 

170 self._timeout = timeout 

171 self._metadata = metadata 

172 

173 def __getattr__(self, name: str) -> Any: 

174 return getattr(self._response, name) 

175 

176 @property 

177 async def pages(self) -> AsyncIterator[logging.ListLogEntriesResponse]: 

178 yield self._response 

179 while self._response.next_page_token: 

180 self._request.page_token = self._response.next_page_token 

181 self._response = await self._method( 

182 self._request, 

183 retry=self._retry, 

184 timeout=self._timeout, 

185 metadata=self._metadata, 

186 ) 

187 yield self._response 

188 

189 def __aiter__(self) -> AsyncIterator[log_entry.LogEntry]: 

190 async def async_generator(): 

191 async for page in self.pages: 

192 for response in page.entries: 

193 yield response 

194 

195 return async_generator() 

196 

197 def __repr__(self) -> str: 

198 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

199 

200 

201class ListMonitoredResourceDescriptorsPager: 

202 """A pager for iterating through ``list_monitored_resource_descriptors`` requests. 

203 

204 This class thinly wraps an initial 

205 :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` object, and 

206 provides an ``__iter__`` method to iterate through its 

207 ``resource_descriptors`` field. 

208 

209 If there are more pages, the ``__iter__`` method will make additional 

210 ``ListMonitoredResourceDescriptors`` requests and continue to iterate 

211 through the ``resource_descriptors`` field on the 

212 corresponding responses. 

213 

214 All the usual :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` 

215 attributes are available on the pager. If multiple requests are made, only 

216 the most recent response is retained, and thus used for attribute lookup. 

217 """ 

218 

219 def __init__( 

220 self, 

221 method: Callable[..., logging.ListMonitoredResourceDescriptorsResponse], 

222 request: logging.ListMonitoredResourceDescriptorsRequest, 

223 response: logging.ListMonitoredResourceDescriptorsResponse, 

224 *, 

225 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

226 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

228 ): 

229 """Instantiate the pager. 

230 

231 Args: 

232 method (Callable): The method that was originally called, and 

233 which instantiated this pager. 

234 request (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsRequest): 

235 The initial request object. 

236 response (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse): 

237 The initial response object. 

238 retry (google.api_core.retry.Retry): Designation of what errors, 

239 if any, should be retried. 

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

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

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

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

244 be of type `bytes`. 

245 """ 

246 self._method = method 

247 self._request = logging.ListMonitoredResourceDescriptorsRequest(request) 

248 self._response = response 

249 self._retry = retry 

250 self._timeout = timeout 

251 self._metadata = metadata 

252 

253 def __getattr__(self, name: str) -> Any: 

254 return getattr(self._response, name) 

255 

256 @property 

257 def pages(self) -> Iterator[logging.ListMonitoredResourceDescriptorsResponse]: 

258 yield self._response 

259 while self._response.next_page_token: 

260 self._request.page_token = self._response.next_page_token 

261 self._response = self._method( 

262 self._request, 

263 retry=self._retry, 

264 timeout=self._timeout, 

265 metadata=self._metadata, 

266 ) 

267 yield self._response 

268 

269 def __iter__(self) -> Iterator[monitored_resource_pb2.MonitoredResourceDescriptor]: 

270 for page in self.pages: 

271 yield from page.resource_descriptors 

272 

273 def __repr__(self) -> str: 

274 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

275 

276 

277class ListMonitoredResourceDescriptorsAsyncPager: 

278 """A pager for iterating through ``list_monitored_resource_descriptors`` requests. 

279 

280 This class thinly wraps an initial 

281 :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` object, and 

282 provides an ``__aiter__`` method to iterate through its 

283 ``resource_descriptors`` field. 

284 

285 If there are more pages, the ``__aiter__`` method will make additional 

286 ``ListMonitoredResourceDescriptors`` requests and continue to iterate 

287 through the ``resource_descriptors`` field on the 

288 corresponding responses. 

289 

290 All the usual :class:`google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse` 

291 attributes are available on the pager. If multiple requests are made, only 

292 the most recent response is retained, and thus used for attribute lookup. 

293 """ 

294 

295 def __init__( 

296 self, 

297 method: Callable[ 

298 ..., Awaitable[logging.ListMonitoredResourceDescriptorsResponse] 

299 ], 

300 request: logging.ListMonitoredResourceDescriptorsRequest, 

301 response: logging.ListMonitoredResourceDescriptorsResponse, 

302 *, 

303 retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, 

304 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

306 ): 

307 """Instantiates the pager. 

308 

309 Args: 

310 method (Callable): The method that was originally called, and 

311 which instantiated this pager. 

312 request (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsRequest): 

313 The initial request object. 

314 response (google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsResponse): 

315 The initial response object. 

316 retry (google.api_core.retry.AsyncRetry): Designation of what errors, 

317 if any, should be retried. 

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

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

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

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

322 be of type `bytes`. 

323 """ 

324 self._method = method 

325 self._request = logging.ListMonitoredResourceDescriptorsRequest(request) 

326 self._response = response 

327 self._retry = retry 

328 self._timeout = timeout 

329 self._metadata = metadata 

330 

331 def __getattr__(self, name: str) -> Any: 

332 return getattr(self._response, name) 

333 

334 @property 

335 async def pages( 

336 self, 

337 ) -> AsyncIterator[logging.ListMonitoredResourceDescriptorsResponse]: 

338 yield self._response 

339 while self._response.next_page_token: 

340 self._request.page_token = self._response.next_page_token 

341 self._response = await self._method( 

342 self._request, 

343 retry=self._retry, 

344 timeout=self._timeout, 

345 metadata=self._metadata, 

346 ) 

347 yield self._response 

348 

349 def __aiter__( 

350 self, 

351 ) -> AsyncIterator[monitored_resource_pb2.MonitoredResourceDescriptor]: 

352 async def async_generator(): 

353 async for page in self.pages: 

354 for response in page.resource_descriptors: 

355 yield response 

356 

357 return async_generator() 

358 

359 def __repr__(self) -> str: 

360 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

361 

362 

363class ListLogsPager: 

364 """A pager for iterating through ``list_logs`` requests. 

365 

366 This class thinly wraps an initial 

367 :class:`google.cloud.logging_v2.types.ListLogsResponse` object, and 

368 provides an ``__iter__`` method to iterate through its 

369 ``log_names`` field. 

370 

371 If there are more pages, the ``__iter__`` method will make additional 

372 ``ListLogs`` requests and continue to iterate 

373 through the ``log_names`` field on the 

374 corresponding responses. 

375 

376 All the usual :class:`google.cloud.logging_v2.types.ListLogsResponse` 

377 attributes are available on the pager. If multiple requests are made, only 

378 the most recent response is retained, and thus used for attribute lookup. 

379 """ 

380 

381 def __init__( 

382 self, 

383 method: Callable[..., logging.ListLogsResponse], 

384 request: logging.ListLogsRequest, 

385 response: logging.ListLogsResponse, 

386 *, 

387 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

388 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

390 ): 

391 """Instantiate the pager. 

392 

393 Args: 

394 method (Callable): The method that was originally called, and 

395 which instantiated this pager. 

396 request (google.cloud.logging_v2.types.ListLogsRequest): 

397 The initial request object. 

398 response (google.cloud.logging_v2.types.ListLogsResponse): 

399 The initial response object. 

400 retry (google.api_core.retry.Retry): Designation of what errors, 

401 if any, should be retried. 

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

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

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

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

406 be of type `bytes`. 

407 """ 

408 self._method = method 

409 self._request = logging.ListLogsRequest(request) 

410 self._response = response 

411 self._retry = retry 

412 self._timeout = timeout 

413 self._metadata = metadata 

414 

415 def __getattr__(self, name: str) -> Any: 

416 return getattr(self._response, name) 

417 

418 @property 

419 def pages(self) -> Iterator[logging.ListLogsResponse]: 

420 yield self._response 

421 while self._response.next_page_token: 

422 self._request.page_token = self._response.next_page_token 

423 self._response = self._method( 

424 self._request, 

425 retry=self._retry, 

426 timeout=self._timeout, 

427 metadata=self._metadata, 

428 ) 

429 yield self._response 

430 

431 def __iter__(self) -> Iterator[str]: 

432 for page in self.pages: 

433 yield from page.log_names 

434 

435 def __repr__(self) -> str: 

436 return "{0}<{1!r}>".format(self.__class__.__name__, self._response) 

437 

438 

439class ListLogsAsyncPager: 

440 """A pager for iterating through ``list_logs`` requests. 

441 

442 This class thinly wraps an initial 

443 :class:`google.cloud.logging_v2.types.ListLogsResponse` object, and 

444 provides an ``__aiter__`` method to iterate through its 

445 ``log_names`` field. 

446 

447 If there are more pages, the ``__aiter__`` method will make additional 

448 ``ListLogs`` requests and continue to iterate 

449 through the ``log_names`` field on the 

450 corresponding responses. 

451 

452 All the usual :class:`google.cloud.logging_v2.types.ListLogsResponse` 

453 attributes are available on the pager. If multiple requests are made, only 

454 the most recent response is retained, and thus used for attribute lookup. 

455 """ 

456 

457 def __init__( 

458 self, 

459 method: Callable[..., Awaitable[logging.ListLogsResponse]], 

460 request: logging.ListLogsRequest, 

461 response: logging.ListLogsResponse, 

462 *, 

463 retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, 

464 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

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

466 ): 

467 """Instantiates the pager. 

468 

469 Args: 

470 method (Callable): The method that was originally called, and 

471 which instantiated this pager. 

472 request (google.cloud.logging_v2.types.ListLogsRequest): 

473 The initial request object. 

474 response (google.cloud.logging_v2.types.ListLogsResponse): 

475 The initial response object. 

476 retry (google.api_core.retry.AsyncRetry): Designation of what errors, 

477 if any, should be retried. 

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

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

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

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

482 be of type `bytes`. 

483 """ 

484 self._method = method 

485 self._request = logging.ListLogsRequest(request) 

486 self._response = response 

487 self._retry = retry 

488 self._timeout = timeout 

489 self._metadata = metadata 

490 

491 def __getattr__(self, name: str) -> Any: 

492 return getattr(self._response, name) 

493 

494 @property 

495 async def pages(self) -> AsyncIterator[logging.ListLogsResponse]: 

496 yield self._response 

497 while self._response.next_page_token: 

498 self._request.page_token = self._response.next_page_token 

499 self._response = await self._method( 

500 self._request, 

501 retry=self._retry, 

502 timeout=self._timeout, 

503 metadata=self._metadata, 

504 ) 

505 yield self._response 

506 

507 def __aiter__(self) -> AsyncIterator[str]: 

508 async def async_generator(): 

509 async for page in self.pages: 

510 for response in page.log_names: 

511 yield response 

512 

513 return async_generator() 

514 

515 def __repr__(self) -> str: 

516 return "{0}<{1!r}>".format(self.__class__.__name__, self._response)