@@ -180,13 +180,17 @@ def gateway_from_file(gateway_path, protocol="ipfs"):
180
180
181
181
182
182
@lru_cache
183
- def get_gateway (protocol = "ipfs" ):
183
+ def get_gateway (protocol = "ipfs" , gateway_addr = None ):
184
184
"""
185
185
Get IPFS gateway according to IPIP-280
186
186
187
187
see: https://github.com/ipfs/specs/pull/280
188
188
"""
189
189
190
+ if gateway_addr :
191
+ logger .debug ("using IPFS gateway as specified via function argument: %s" , gateway_addr )
192
+ return AsyncIPFSGateway (gateway_addr , protocol )
193
+
190
194
# IPFS_GATEWAY environment variable should override everything
191
195
ipfs_gateway = os .environ .get ("IPFS_GATEWAY" , "" )
192
196
if ipfs_gateway :
@@ -263,19 +267,20 @@ class AsyncIPFSFileSystem(AsyncFileSystem):
263
267
sep = "/"
264
268
protocol = "ipfs"
265
269
266
- def __init__ (self , asynchronous = False , loop = None , client_kwargs = None , ** storage_options ):
270
+ def __init__ (self , asynchronous = False , loop = None , client_kwargs = None , gateway_addr = None , ** storage_options ):
267
271
super ().__init__ (self , asynchronous = asynchronous , loop = loop , ** storage_options )
268
272
self ._session = None
269
273
270
274
self .client_kwargs = client_kwargs or {}
271
275
self .get_client = get_client
276
+ self .gateway_addr = gateway_addr
272
277
273
278
if not asynchronous :
274
279
sync (self .loop , self .set_session )
275
280
276
281
@property
277
282
def gateway (self ):
278
- return get_gateway (self .protocol )
283
+ return get_gateway (self .protocol , gateway_addr = self . gateway_addr )
279
284
280
285
@staticmethod
281
286
def close_session (loop , session ):
0 commit comments