Revision 3f7e4e14

b/kamaki/clients/storage/__init__.py
280 280
        if r.status_code == 404:
281 281
            raise ClientError("Object %s not found" % obj, r.status_code)
282 282

  
283
    def list_objects(self):
283
    def list_objects(
284
            self,
285
            limit=None,
286
            marker=None,
287
            prefix=None,
288
            format=None,
289
            delimiter=None,
290
            path=None):
284 291
        """
292
        :param limit: (integer) The amount of results requested
293

  
294
        :param marker: (string) Return containers with name lexicographically
295
            after marker
296

  
297
        :param prefix: (string) Return objects starting with prefix
298

  
299
        :param format: (string) reply format can be json or xml (default:json)
300

  
301
        :param delimiter: (string) Return objects up to the delimiter
302

  
303
        :param path: (string) assume prefix = path and delimiter = /
304
            (overwrites prefix and delimiter)
305

  
285 306
        :returns: (dict)
286 307

  
287 308
        :raises ClientError: 404 Invalid account
288 309
        """
289 310
        self._assert_container()
290
        path = path4url(self.account, self.container)
291
        self.set_param('format', 'json')
292
        r = self.get(path, success=(200, 204, 304, 404), )
311
        restpath = path4url(self.account, self.container)
312

  
313
        self.set_param('format', format or 'json')
314

  
315
        self.set_param('limit', limit, iff=limit)
316
        self.set_param('marker', marker, iff=marker)
317
        if path:
318
            self.set_param('path', path)
319
        else:
320
            self.set_param('prefix', prefix, iff=prefix)
321
            self.set_param('delimiter', delimiter, iff=delimiter)
322

  
323
        r = self.get(restpath, success=(200, 204, 304, 404), )
293 324
        if r.status_code == 404:
294 325
            raise ClientError(
295 326
                "Invalid account (%s) for that container" % self.account,
b/kamaki/clients/storage/test.py
386 386
            self.assert_dicts_are_equal(r[i], object_list[i])
387 387
        exp = '/%s/%s' % (acc, cont)
388 388
        get.assert_called_once_with(exp, success=(200, 204, 304, 404))
389
        SP.assert_called_once_with('format', 'json')
389
        self.assertEqual(SP.mock_calls, [
390
            call('format', 'json'),
391
            call('limit', None, iff=None),
392
            call('marker', None, iff=None),
393
            call('prefix', None, iff=None),
394
            call('delimiter', None, iff=None)])
395
        self.client.list_objects(
396
            format='xml', limit=10, marker='X', path='/lala')
397
        self.assertEqual(SP.mock_calls[-4:], [
398
            call('format', 'xml'),
399
            call('limit', 10, iff=10),
400
            call('marker', 'X', iff='X'),
401
            call('path', '/lala')])
402
        self.client.list_objects(delimiter='X', prefix='/lala')
403
        self.assertEqual(SP.mock_calls[-5:], [
404
            call('format', 'json'),
405
            call('limit', None, iff=None),
406
            call('marker', None, iff=None),
407
            call('prefix', '/lala', iff='/lala'),
408
            call('delimiter', 'X', iff='X'),
409
            ])
390 410
        FR.status_code = 304
391 411
        self.assertEqual(self.client.list_objects(), [])
392 412
        FR.status_code = 404

Also available in: Unified diff