Revision f89e3cf4 pithos/lib/client.py

b/pithos/lib/client.py
294 294
    
295 295
    def create_container(self, container, headers=None, **meta):
296 296
        for k,v in meta.items():
297
            headers['X_CONTAINER_META_%s' %k.strip().upper()] = v.strip()
297
            headers['X-Container-Meta-%s' %k.strip().upper()] = v.strip()
298 298
        status, header, data = self.put('/' + container, headers=headers)
299 299
        if status == 202:
300 300
            return False
......
342 342
        h = {'Content-Type':'application/directory'}
343 343
        self.create_object(container, object, f=None, headers=h)
344 344
    
345
    def _set_public(self, headers, public=False):
346
        """
347
        sets the public header
348
        """
349
        if public == None:
350
            return
351
        elif public:
352
            headers['X-Object-Public'] = public
353
        else:
354
            headers['X-Object-Public'] = ''
355
    
345 356
    def create_object(self, container, object, f=stdin, chunked=False,
346
                      blocksize=1024, headers=None, use_hashes=False, **meta):
357
                      blocksize=1024, headers={}, use_hashes=False,
358
                      public=None, **meta):
347 359
        """
348 360
        creates an object
349 361
        if f is None then creates a zero length object
......
351 363
        """
352 364
        path = '/%s/%s' % (container, object)
353 365
        for k,v in meta.items():
354
            headers['X_OBJECT_META_%s' %k.strip().upper()] = v.strip()
366
            headers['X-Object-Meta-%s' %k.strip().upper()] = v.strip()
367
        self._set_public(headers, public)
368
        headers = headers if headers else None
355 369
        if not chunked:
356 370
            format = 'json' if use_hashes else 'text'
357 371
            data = f.read() if f else None
......
365 379
                                   blocksize=1024)
366 380
    
367 381
    def update_object(self, container, object, f=stdin, chunked=False,
368
                      blocksize=1024, headers=None, offset=None, **meta):
382
                      blocksize=1024, headers={}, offset=None, public=None,
383
                      **meta):
384
        print locals()
369 385
        path = '/%s/%s' % (container, object)
370 386
        for k,v in meta.items():
371
            headers['X_OBJECT_META_%s' %k.strip().upper()] = v.strip()
387
            headers['X-Object-Meta-%s' %k.strip().upper()] = v.strip()
372 388
        if offset:
373 389
            headers['Content-Range'] = 'bytes %s-/*' % offset
374 390
        else:
375 391
            headers['Content-Range'] = 'bytes */*'
376
        
392
        self._set_public(headers, public)
393
        headers = headers if headers else None
377 394
        if not chunked and f != stdin:
378 395
            data = f.read() if f else None
379 396
            self.post(path, data, headers=headers)
......
382 399
                                   blocksize=1024)
383 400
    
384 401
    def _change_obj_location(self, src_container, src_object, dst_container,
385
                             dst_object, remove=False, headers=None):
402
                             dst_object, remove=False, public=None, headers={}):
386 403
        path = '/%s/%s' % (dst_container, dst_object)
387 404
        if not headers:
388 405
            headers = {}
......
390 407
            headers['X-Move-From'] = '/%s/%s' % (src_container, src_object)
391 408
        else:
392 409
            headers['X-Copy-From'] = '/%s/%s' % (src_container, src_object)
410
        self._set_public(headers, public)
411
        self.headers = headers if headers else None
393 412
        headers['Content-Length'] = 0
394 413
        self.put(path, headers=headers)
395 414
    
396 415
    def copy_object(self, src_container, src_object, dst_container,
397
                             dst_object, headers=None):
416
                             dst_object, public=False, headers=None):
398 417
        self._change_obj_location(src_container, src_object,
399 418
                                   dst_container, dst_object,
400
                                   headers=headers)
419
                                   public, headers)
401 420
    
402 421
    def move_object(self, src_container, src_object, dst_container,
403 422
                             dst_object, headers=None):
404 423
        self._change_obj_location(src_container, src_object,
405
                                   dst_container, dst_object, True, headers)
424
                                   dst_container, dst_object, True,
425
                                   public, headers)
406 426
    
407 427
    def delete_object(self, container, object):
408 428
        self.delete('/%s/%s' % (container, object))
......
437 457
        actualy removes trash object metadata info
438 458
        """
439 459
        self.delete_object_metadata(container, object, ['trash'])
440

  
460
    
461
    def publish_object(self, container, object):
462
        """
463
        sets a previously created object publicly accessible
464
        """
465
        path = '/%s/%s' % (container, object)
466
        headers = {}
467
        headers['Content-Range'] = 'bytes */*'
468
        self._set_public(headers, public=True)
469
        self.post(path, headers=headers)
470
    
471
    def unpublish_object(self, container, object):
472
        """
473
        unpublish an object
474
        """
475
        path = '/%s/%s' % (container, object)
476
        headers = {}
477
        headers['Content-Range'] = 'bytes */*'
478
        self._set_public(headers, public=False)
479
        self.post(path, headers=headers)

Also available in: Unified diff