3
3
import logging
4
4
import re
5
5
import weakref
6
- from copy import copy
7
6
from urllib .parse import urlparse
8
7
9
8
import aiohttp
@@ -58,6 +57,7 @@ def __init__(
58
57
client_kwargs = None ,
59
58
get_client = get_client ,
60
59
encoded = False ,
60
+ listings_cache_options = None ,
61
61
** storage_options ,
62
62
):
63
63
"""
@@ -83,11 +83,39 @@ def __init__(
83
83
A callable which takes keyword arguments and constructs
84
84
an aiohttp.ClientSession. It's state will be managed by
85
85
the HTTPFileSystem class.
86
+ listings_cache_options: dict
87
+ Options for the listings cache.
86
88
storage_options: key-value
87
89
Any other parameters passed on to requests
88
90
cache_type, cache_options: defaults used in open
89
91
"""
90
- super ().__init__ (self , asynchronous = asynchronous , loop = loop , ** storage_options )
92
+ # TODO: remove in future release
93
+ # Clean caching-related parameters from `storage_options`
94
+ # before propagating them as `request_options` through `self.kwargs`.
95
+ old_listings_cache_kwargs = {
96
+ "use_listings_cache" ,
97
+ "listings_expiry_time" ,
98
+ "max_paths" ,
99
+ "skip_instance_cache" ,
100
+ }
101
+ # intersection of old_listings_cache_kwargs and storage_options
102
+ old_listings_cache_kwargs = old_listings_cache_kwargs .intersection (
103
+ storage_options
104
+ )
105
+ if old_listings_cache_kwargs :
106
+ logger .warning (
107
+ f"The following parameters are not used anymore and will be ignored: { old_listings_cache_kwargs } . "
108
+ f"Use new `listings_cache_options` instead."
109
+ )
110
+ for key in old_listings_cache_kwargs :
111
+ del storage_options [key ]
112
+ super ().__init__ (
113
+ self ,
114
+ asynchronous = asynchronous ,
115
+ loop = loop ,
116
+ listings_cache_options = listings_cache_options ,
117
+ ** storage_options ,
118
+ )
91
119
self .block_size = block_size if block_size is not None else DEFAULT_BLOCK_SIZE
92
120
self .simple_links = simple_links
93
121
self .same_schema = same_scheme
@@ -96,19 +124,10 @@ def __init__(
96
124
self .client_kwargs = client_kwargs or {}
97
125
self .get_client = get_client
98
126
self .encoded = encoded
99
- self .kwargs = storage_options
100
- self ._session = None
101
-
102
- # Clean caching-related parameters from `storage_options`
103
- # before propagating them as `request_options` through `self.kwargs`.
104
127
# TODO: Maybe rename `self.kwargs` to `self.request_options` to make
105
128
# it clearer.
106
- request_options = copy (storage_options )
107
- self .use_listings_cache = request_options .pop ("use_listings_cache" , False )
108
- request_options .pop ("listings_expiry_time" , None )
109
- request_options .pop ("max_paths" , None )
110
- request_options .pop ("skip_instance_cache" , None )
111
- self .kwargs = request_options
129
+ self .kwargs = storage_options
130
+ self ._session = None
112
131
113
132
@property
114
133
def fsid (self ):
@@ -201,7 +220,7 @@ async def _ls_real(self, url, detail=True, **kwargs):
201
220
return sorted (out )
202
221
203
222
async def _ls (self , url , detail = True , ** kwargs ):
204
- if self . use_listings_cache and url in self .dircache :
223
+ if url in self .dircache :
205
224
out = self .dircache [url ]
206
225
else :
207
226
out = await self ._ls_real (url , detail = detail , ** kwargs )
0 commit comments