|
26 | 26 | import aiohttp |
27 | 27 | import cachetools |
28 | 28 | import fsspec.implementations.http as fshttp |
29 | | -from aiowebdav2.client import Client |
| 29 | +from aiowebdav2.client import ( |
| 30 | + Client, |
| 31 | + Urn, |
| 32 | +) |
30 | 33 | from aiowebdav2.exceptions import ( |
31 | 34 | MethodNotSupportedError, |
32 | 35 | RemoteResourceNotFoundError, |
33 | 36 | ResponseErrorCodeError, |
34 | 37 | ) |
| 38 | +from aiowebdav2.parser import WebDavXmlUtils |
35 | 39 | from fsspec.asyn import AsyncFileSystem, sync |
36 | 40 | from fsspec.utils import glob_translate |
37 | 41 |
|
@@ -570,18 +574,33 @@ async def _ls_real(self, url, detail=True): |
570 | 574 |
|
571 | 575 | async def get_item_detail(item): |
572 | 576 | full_path = f"{base_url}{item}" |
573 | | - try: |
574 | | - is_directory = await client.is_dir(item) |
575 | | - type_ = "directory" if is_directory else "file" |
576 | | - except MethodNotSupportedError as e: |
577 | | - if getattr(e, "name", "") == "is_dir": |
578 | | - type_ = "file" |
579 | | - else: |
580 | | - raise |
| 577 | + urn = Urn(item) |
| 578 | + path = client.get_full_path(urn) |
| 579 | + response = await client.execute_request( |
| 580 | + action="info", |
| 581 | + path=urn.path(), |
| 582 | + headers_ext=["Depth: 0"], |
| 583 | + ) |
| 584 | + content = await response.read() |
| 585 | + is_directory = WebDavXmlUtils.parse_is_dir_response( |
| 586 | + content=content, |
| 587 | + path=path, |
| 588 | + hostname=client._url, |
| 589 | + ) |
| 590 | + info = WebDavXmlUtils.parse_info_response( |
| 591 | + content=content, |
| 592 | + path=path, |
| 593 | + hostname=client._url, |
| 594 | + ) |
| 595 | + import datetime |
581 | 596 | return { |
582 | 597 | "name": full_path, |
583 | | - "size": None, |
584 | | - "type": type_, |
| 598 | + "size": info["size"], |
| 599 | + "type": "directory" if is_directory else "file", |
| 600 | + "mod_time": datetime.datetime.strptime( |
| 601 | + info["modified"], |
| 602 | + "%a, %d %b %Y %H:%M:%S %Z", |
| 603 | + ), |
585 | 604 | } |
586 | 605 |
|
587 | 606 | return await asyncio.gather(*(get_item_detail(item) for item in items)) |
|
0 commit comments