@@ -139,7 +139,7 @@ def list_attr_changes(configuration, path, attr):
139
139
return changes
140
140
141
141
142
- def filter_data_access (configuration , path , access_mode , operation , args = [] ):
142
+ def filter_data_access (configuration , path , access_mode , operation , args ):
143
143
"""Filter access to what operation is allowed to do based on path, args
144
144
and access_mode.
145
145
In read-write mode all operations are allowed to proceed path checks.
@@ -181,7 +181,7 @@ def filter_data_access(configuration, path, access_mode, operation, args=[]):
181
181
182
182
183
183
def check_data_access (configuration , user_id , path , access_mode , operation ,
184
- args = [] ):
184
+ args ):
185
185
"""A simple helper to check if user_id has access to execute operation on path
186
186
under the constraints set by access_mode. Namely, check if operation
187
187
could potentially modify data in a read-only session or lookup/read data
@@ -408,7 +408,7 @@ def _impl(self, *method_args, **method_kwargs):
408
408
% endpos \
409
409
+ " file endpos: %s, '%s'" % \
410
410
(file_endpos , self .sftpserver ._get_fs_path (
411
- path , operation = method .__name__ , args = [] ))
411
+ path , operation = method .__name__ ))
412
412
logger .warning (msg )
413
413
414
414
# close
@@ -856,8 +856,12 @@ def __gdp_log(self, operation, path, dst_path=None, flags=None,
856
856
857
857
# Use shared daemon fs helper functions
858
858
859
- def _get_fs_path (self , sftp_path , operation = None , args = []):
859
+ # NOTE: avoid mutable default arguments with delayed init on None-pattern
860
+ # https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments
861
+ def _get_fs_path (self , sftp_path , operation = None , args = None ):
860
862
"""Wrap helper"""
863
+ if args is None :
864
+ args = []
861
865
# self.logger.debug("get_fs_path: check access to %s" % [sftp_path])
862
866
if not check_data_access (configuration , self .user_name , sftp_path ,
863
867
self .access , operation , args ):
@@ -1127,8 +1131,7 @@ def list_folder(self, path):
1127
1131
"""Handle operations of same name"""
1128
1132
# self.logger.debug('list_folder %s' % [path])
1129
1133
try :
1130
- real_path = self ._get_fs_path (path , operation = 'list_folder' ,
1131
- args = [])
1134
+ real_path = self ._get_fs_path (path , operation = 'list_folder' )
1132
1135
except ValueError as err :
1133
1136
self .logger .warning ('list_folder %s: %s' % ([path ], [err ]))
1134
1137
return paramiko .SFTP_PERMISSION_DENIED
@@ -1176,7 +1179,7 @@ def stat(self, path):
1176
1179
# path = force_utf8(path)
1177
1180
# self.logger.debug('stat %s' % path)
1178
1181
try :
1179
- real_path = self ._get_fs_path (path , operation = 'stat' , args = [] )
1182
+ real_path = self ._get_fs_path (path , operation = 'stat' )
1180
1183
except ValueError as err :
1181
1184
self .logger .warning ('stat %s: %s' % (path , err ))
1182
1185
return paramiko .SFTP_PERMISSION_DENIED
@@ -1204,7 +1207,7 @@ def lstat(self, path):
1204
1207
# path = force_utf8(path)
1205
1208
# self.logger.debug('lstat %s' % path)
1206
1209
try :
1207
- real_path = self ._get_fs_path (path , operation = 'lstat' , args = [] )
1210
+ real_path = self ._get_fs_path (path , operation = 'lstat' )
1208
1211
except ValueError as err :
1209
1212
self .logger .warning ('lstat %s: %s' % (path , err ))
1210
1213
return paramiko .SFTP_PERMISSION_DENIED
@@ -1228,7 +1231,7 @@ def remove(self, path):
1228
1231
# path = force_utf8(path)
1229
1232
# self.logger.debug("remove %s" % path)
1230
1233
try :
1231
- real_path = self ._get_fs_path (path , operation = 'remove' , args = [] )
1234
+ real_path = self ._get_fs_path (path , operation = 'remove' )
1232
1235
except ValueError as err :
1233
1236
self .logger .warning ('remove %s: %s' % (path , err ))
1234
1237
return paramiko .SFTP_PERMISSION_DENIED
@@ -1274,8 +1277,7 @@ def rename(self, oldpath, newpath):
1274
1277
# newpath = force_utf8(newpath)
1275
1278
# self.logger.debug("rename %s %s" % (oldpath, newpath))
1276
1279
try :
1277
- real_oldpath = self ._get_fs_path (oldpath , operation = 'rename' ,
1278
- args = [])
1280
+ real_oldpath = self ._get_fs_path (oldpath , operation = 'rename' )
1279
1281
except ValueError as err :
1280
1282
self .logger .warning ('rename %s %s: %s' % (oldpath , newpath , err ))
1281
1283
return paramiko .SFTP_PERMISSION_DENIED
@@ -1301,7 +1303,7 @@ def rename(self, oldpath, newpath):
1301
1303
self .logger .warning ('move on read-only old path %s :: %s' %
1302
1304
(oldpath , real_oldpath ))
1303
1305
return paramiko .SFTP_PERMISSION_DENIED
1304
- real_newpath = self ._get_fs_path (newpath , operation = 'rename' , args = [] )
1306
+ real_newpath = self ._get_fs_path (newpath , operation = 'rename' )
1305
1307
if not check_write_access (real_newpath , parent_dir = True ):
1306
1308
self .logger .warning ('move on read-only new path %s :: %s' %
1307
1309
(newpath , real_newpath ))
@@ -1359,7 +1361,7 @@ def rmdir(self, path):
1359
1361
# path = force_utf8(path)
1360
1362
# self.logger.debug("rmdir %s" % path)
1361
1363
try :
1362
- real_path = self ._get_fs_path (path , operation = 'rmdir' , args = [] )
1364
+ real_path = self ._get_fs_path (path , operation = 'rmdir' )
1363
1365
except ValueError as err :
1364
1366
self .logger .warning ('rmdir %s: %s' % (path , err ))
1365
1367
return paramiko .SFTP_PERMISSION_DENIED
@@ -1412,7 +1414,7 @@ def readlink(self, path):
1412
1414
# path = force_utf8(path)
1413
1415
# self.logger.debug("readlink %s" % path)
1414
1416
try :
1415
- real_path = self ._get_fs_path (path , operation = 'readlink' , args = [] )
1417
+ real_path = self ._get_fs_path (path , operation = 'readlink' )
1416
1418
except ValueError as err :
1417
1419
self .logger .warning ('readlink %s: %s' % (path , err ))
1418
1420
return paramiko .SFTP_PERMISSION_DENIED
0 commit comments