@@ -139,7 +139,7 @@ def list_attr_changes(configuration, path, attr):
139139 return changes
140140
141141
142- def filter_data_access (configuration , path , access_mode , operation , args = [] ):
142+ def filter_data_access (configuration , path , access_mode , operation , args ):
143143 """Filter access to what operation is allowed to do based on path, args
144144 and access_mode.
145145 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=[]):
181181
182182
183183def check_data_access (configuration , user_id , path , access_mode , operation ,
184- args = [] ):
184+ args ):
185185 """A simple helper to check if user_id has access to execute operation on path
186186 under the constraints set by access_mode. Namely, check if operation
187187 could potentially modify data in a read-only session or lookup/read data
@@ -408,7 +408,7 @@ def _impl(self, *method_args, **method_kwargs):
408408 % endpos \
409409 + " file endpos: %s, '%s'" % \
410410 (file_endpos , self .sftpserver ._get_fs_path (
411- path , operation = method .__name__ , args = [] ))
411+ path , operation = method .__name__ ))
412412 logger .warning (msg )
413413
414414 # close
@@ -856,8 +856,12 @@ def __gdp_log(self, operation, path, dst_path=None, flags=None,
856856
857857 # Use shared daemon fs helper functions
858858
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 ):
860862 """Wrap helper"""
863+ if args is None :
864+ args = []
861865 # self.logger.debug("get_fs_path: check access to %s" % [sftp_path])
862866 if not check_data_access (configuration , self .user_name , sftp_path ,
863867 self .access , operation , args ):
@@ -1127,8 +1131,7 @@ def list_folder(self, path):
11271131 """Handle operations of same name"""
11281132 # self.logger.debug('list_folder %s' % [path])
11291133 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' )
11321135 except ValueError as err :
11331136 self .logger .warning ('list_folder %s: %s' % ([path ], [err ]))
11341137 return paramiko .SFTP_PERMISSION_DENIED
@@ -1176,7 +1179,7 @@ def stat(self, path):
11761179 # path = force_utf8(path)
11771180 # self.logger.debug('stat %s' % path)
11781181 try :
1179- real_path = self ._get_fs_path (path , operation = 'stat' , args = [] )
1182+ real_path = self ._get_fs_path (path , operation = 'stat' )
11801183 except ValueError as err :
11811184 self .logger .warning ('stat %s: %s' % (path , err ))
11821185 return paramiko .SFTP_PERMISSION_DENIED
@@ -1204,7 +1207,7 @@ def lstat(self, path):
12041207 # path = force_utf8(path)
12051208 # self.logger.debug('lstat %s' % path)
12061209 try :
1207- real_path = self ._get_fs_path (path , operation = 'lstat' , args = [] )
1210+ real_path = self ._get_fs_path (path , operation = 'lstat' )
12081211 except ValueError as err :
12091212 self .logger .warning ('lstat %s: %s' % (path , err ))
12101213 return paramiko .SFTP_PERMISSION_DENIED
@@ -1228,7 +1231,7 @@ def remove(self, path):
12281231 # path = force_utf8(path)
12291232 # self.logger.debug("remove %s" % path)
12301233 try :
1231- real_path = self ._get_fs_path (path , operation = 'remove' , args = [] )
1234+ real_path = self ._get_fs_path (path , operation = 'remove' )
12321235 except ValueError as err :
12331236 self .logger .warning ('remove %s: %s' % (path , err ))
12341237 return paramiko .SFTP_PERMISSION_DENIED
@@ -1274,8 +1277,7 @@ def rename(self, oldpath, newpath):
12741277 # newpath = force_utf8(newpath)
12751278 # self.logger.debug("rename %s %s" % (oldpath, newpath))
12761279 try :
1277- real_oldpath = self ._get_fs_path (oldpath , operation = 'rename' ,
1278- args = [])
1280+ real_oldpath = self ._get_fs_path (oldpath , operation = 'rename' )
12791281 except ValueError as err :
12801282 self .logger .warning ('rename %s %s: %s' % (oldpath , newpath , err ))
12811283 return paramiko .SFTP_PERMISSION_DENIED
@@ -1301,7 +1303,7 @@ def rename(self, oldpath, newpath):
13011303 self .logger .warning ('move on read-only old path %s :: %s' %
13021304 (oldpath , real_oldpath ))
13031305 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' )
13051307 if not check_write_access (real_newpath , parent_dir = True ):
13061308 self .logger .warning ('move on read-only new path %s :: %s' %
13071309 (newpath , real_newpath ))
@@ -1359,7 +1361,7 @@ def rmdir(self, path):
13591361 # path = force_utf8(path)
13601362 # self.logger.debug("rmdir %s" % path)
13611363 try :
1362- real_path = self ._get_fs_path (path , operation = 'rmdir' , args = [] )
1364+ real_path = self ._get_fs_path (path , operation = 'rmdir' )
13631365 except ValueError as err :
13641366 self .logger .warning ('rmdir %s: %s' % (path , err ))
13651367 return paramiko .SFTP_PERMISSION_DENIED
@@ -1412,7 +1414,7 @@ def readlink(self, path):
14121414 # path = force_utf8(path)
14131415 # self.logger.debug("readlink %s" % path)
14141416 try :
1415- real_path = self ._get_fs_path (path , operation = 'readlink' , args = [] )
1417+ real_path = self ._get_fs_path (path , operation = 'readlink' )
14161418 except ValueError as err :
14171419 self .logger .warning ('readlink %s: %s' % (path , err ))
14181420 return paramiko .SFTP_PERMISSION_DENIED
0 commit comments