33import logging
44import re
55import weakref
6- from copy import copy
76from urllib .parse import urlparse
87
98import aiohttp
@@ -58,6 +57,7 @@ def __init__(
5857 client_kwargs = None ,
5958 get_client = get_client ,
6059 encoded = False ,
60+ listings_cache_options = None ,
6161 ** storage_options ,
6262 ):
6363 """
@@ -83,11 +83,39 @@ def __init__(
8383 A callable which takes keyword arguments and constructs
8484 an aiohttp.ClientSession. It's state will be managed by
8585 the HTTPFileSystem class.
86+ listings_cache_options: dict
87+ Options for the listings cache.
8688 storage_options: key-value
8789 Any other parameters passed on to requests
8890 cache_type, cache_options: defaults used in open
8991 """
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+ )
91119 self .block_size = block_size if block_size is not None else DEFAULT_BLOCK_SIZE
92120 self .simple_links = simple_links
93121 self .same_schema = same_scheme
@@ -96,19 +124,10 @@ def __init__(
96124 self .client_kwargs = client_kwargs or {}
97125 self .get_client = get_client
98126 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`.
104127 # TODO: Maybe rename `self.kwargs` to `self.request_options` to make
105128 # 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
112131
113132 @property
114133 def fsid (self ):
@@ -201,7 +220,7 @@ async def _ls_real(self, url, detail=True, **kwargs):
201220 return sorted (out )
202221
203222 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 :
205224 out = self .dircache [url ]
206225 else :
207226 out = await self ._ls_real (url , detail = detail , ** kwargs )
0 commit comments