comparison sat/memory/memory.py @ 2924:59aea54e74a8

memory: minor style change
author Goffi <goffi@goffi.org>
date Fri, 26 Apr 2019 11:57:26 +0200
parents 90146552cde5
children 4cd7545c4ebb
comparison
equal deleted inserted replaced
2923:1fd3ecb3351a 2924:59aea54e74a8
1313 parent = directory[u"id"] 1313 parent = directory[u"id"]
1314 defer.returnValue((parent, [])) 1314 defer.returnValue((parent, []))
1315 1315
1316 @defer.inlineCallbacks 1316 @defer.inlineCallbacks
1317 def getFiles( 1317 def getFiles(
1318 self, 1318 self, client, peer_jid, file_id=None, version=None, parent=None, path=None,
1319 client, 1319 type_=None, file_hash=None, hash_algo=None, name=None, namespace=None,
1320 peer_jid, 1320 mime_type=None, owner=None, access=None, projection=None, unique=False,
1321 file_id=None, 1321 perms_to_check=(C.ACCESS_PERM_READ,)):
1322 version=None, 1322 """Retrieve files with with given filters
1323 parent=None,
1324 path=None,
1325 type_=None,
1326 file_hash=None,
1327 hash_algo=None,
1328 name=None,
1329 namespace=None,
1330 mime_type=None,
1331 owner=None,
1332 access=None,
1333 projection=None,
1334 unique=False,
1335 perms_to_check=(C.ACCESS_PERM_READ,),
1336 ):
1337 """retrieve files with with given filters
1338 1323
1339 @param peer_jid(jid.JID, None): jid trying to access the file 1324 @param peer_jid(jid.JID, None): jid trying to access the file
1340 needed to check permission. 1325 needed to check permission.
1341 Use None to ignore permission (perms_to_check must be None too) 1326 Use None to ignore permission (perms_to_check must be None too)
1342 @param file_id(unicode, None): id of the file 1327 @param file_id(unicode, None): id of the file
1345 None to ignore 1330 None to ignore
1346 empty string to look for current version 1331 empty string to look for current version
1347 @param parent(unicode, None): id of the directory containing the files 1332 @param parent(unicode, None): id of the directory containing the files
1348 None to ignore 1333 None to ignore
1349 empty string to look for root files/directories 1334 empty string to look for root files/directories
1335 @param path(unicode, None): path to the directory containing the files
1336 @param type_(unicode, None): type of file filter, can be one of C.FILE_TYPE_*
1337 @param file_hash(unicode, None): hash of the file to retrieve
1338 @param hash_algo(unicode, None): algorithm use for file_hash
1339 @param name(unicode, None): name of the file to retrieve
1340 @param namespace(unicode, None): namespace of the files to retrieve
1341 @param mime_type(unicode, None): filter on this mime type
1342 @param owner(jid.JID, None): if not None, only get files from this owner
1343 @param access(dict, None): get file with given access (see [setFile])
1350 @param projection(list[unicode], None): name of columns to retrieve 1344 @param projection(list[unicode], None): name of columns to retrieve
1351 None to retrieve all 1345 None to retrieve all
1352 @param unique(bool): if True will remove duplicates 1346 @param unique(bool): if True will remove duplicates
1353 @param perms_to_check(tuple[unicode],None): permission to check 1347 @param perms_to_check(tuple[unicode],None): permission to check
1354 must be a tuple of C.ACCESS_PERM_* or None 1348 must be a tuple of C.ACCESS_PERM_* or None
1355 if None, permission will no be checked (peer_jid must be None too in this case) 1349 if None, permission will no be checked (peer_jid must be None too in this case)
1356 other params are the same as for [setFile] 1350 other params are the same as for [setFile]
1357 @return (list[dict]): files corresponding to filters 1351 @return (list[dict]): files corresponding to filters
1358 @raise exceptions.NotFound: parent directory not found (when path is specified) 1352 @raise exceptions.NotFound: parent directory not found (when path is specified)
1359 @raise exceptions.PermissionError: peer_jid can't use perms_to_check for one of the file 1353 @raise exceptions.PermissionError: peer_jid can't use perms_to_check for one of
1354 the file
1360 on the path 1355 on the path
1361 """ 1356 """
1362 if peer_jid is None and perms_to_check or perms_to_check is None and peer_jid: 1357 if peer_jid is None and perms_to_check or perms_to_check is None and peer_jid:
1363 raise exceptions.InternalError( 1358 raise exceptions.InternalError(
1364 "if you want to disable permission check, both peer_jid and perms_to_check must be None" 1359 u"if you want to disable permission check, both peer_jid and "
1360 u"perms_to_check must be None"
1365 ) 1361 )
1366 if owner is not None: 1362 if owner is not None:
1367 owner = owner.userhostJID() 1363 owner = owner.userhostJID()
1368 if path is not None: 1364 if path is not None:
1369 # permission are checked by _getParentDir 1365 # permission are checked by _getParentDir
1373 if remaining_path_elts: 1369 if remaining_path_elts:
1374 # if we have remaining path elements, 1370 # if we have remaining path elements,
1375 # the parent directory is not found 1371 # the parent directory is not found
1376 raise failure.Failure(exceptions.NotFound()) 1372 raise failure.Failure(exceptions.NotFound())
1377 if parent and peer_jid: 1373 if parent and peer_jid:
1378 # if parent is given directly and permission check is need, 1374 # if parent is given directly and permission check is requested,
1379 # we need to check all the parents 1375 # we need to check all the parents
1380 parent_data = yield self.storage.getFiles(client, file_id=parent) 1376 parent_data = yield self.storage.getFiles(client, file_id=parent)
1381 try: 1377 try:
1382 parent_data = parent_data[0] 1378 parent_data = parent_data[0]
1383 except IndexError: 1379 except IndexError:
1402 projection=projection, 1398 projection=projection,
1403 unique=unique, 1399 unique=unique,
1404 ) 1400 )
1405 1401
1406 if peer_jid: 1402 if peer_jid:
1407 #  if permission are checked, we must remove all file tha use can't access 1403 # if permission are checked, we must remove all file that user can't access
1408 to_remove = [] 1404 to_remove = []
1409 for file_data in files: 1405 for file_data in files:
1410 try: 1406 try:
1411 self.checkFilePermission(file_data, peer_jid, perms_to_check) 1407 self.checkFilePermission(file_data, peer_jid, perms_to_check)
1412 except exceptions.PermissionError: 1408 except exceptions.PermissionError:
1420 self, client, name, file_id=None, version=u"", parent=None, path=None, 1416 self, client, name, file_id=None, version=u"", parent=None, path=None,
1421 type_=C.FILE_TYPE_FILE, file_hash=None, hash_algo=None, size=None, 1417 type_=C.FILE_TYPE_FILE, file_hash=None, hash_algo=None, size=None,
1422 namespace=None, mime_type=None, created=None, modified=None, owner=None, 1418 namespace=None, mime_type=None, created=None, modified=None, owner=None,
1423 access=None, extra=None, peer_jid=None, perms_to_check=(C.ACCESS_PERM_WRITE,) 1419 access=None, extra=None, peer_jid=None, perms_to_check=(C.ACCESS_PERM_WRITE,)
1424 ): 1420 ):
1425 """set a file metadata 1421 """Set a file metadata
1426 1422
1427 @param name(unicode): basename of the file 1423 @param name(unicode): basename of the file
1428 @param file_id(unicode): unique id of the file 1424 @param file_id(unicode): unique id of the file
1429 @param version(unicode): version of this file 1425 @param version(unicode): version of this file
1430 empty string for current version or when there is no versioning 1426 empty string for current version or when there is no versioning