Revision 76ebf97c kamaki/clients/pithos/__init__.py

b/kamaki/clients/pithos/__init__.py
196 196
            format='json')
197 197
        assert r.json[0] == hash, 'Local hash does not match server'
198 198

  
199
    def _get_file_block_info(self, fileobj, size=None):
200
        meta = self.get_container_info()
199
    def _get_file_block_info(self, fileobj, size=None, cache=None):
200
        """
201
        :param fileobj: (file descriptor) source
202

  
203
        :param size: (int) size of data to upload from source
204

  
205
        :param cache: (dict) if provided, cache container info response to
206
        avoid redundant calls
207
        """
208
        if isinstance(cache, dict):
209
            try:
210
                meta = cache[self.container]
211
            except KeyError:
212
                meta = self.get_container_info()
213
                cache[self.container] = meta
214
        else:
215
            meta = self.get_container_info()
201 216
        blocksize = int(meta['x-container-block-size'])
202 217
        blockhash = meta['x-container-block-hash']
203 218
        size = size if size is not None else fstat(fileobj.fileno()).st_size
......
307 322
            content_disposition=None,
308 323
            content_type=None,
309 324
            sharing=None,
310
            public=None):
325
            public=None,
326
            container_info_cache=None):
311 327
        """Upload an object using multiple connections (threads)
312 328

  
313 329
        :param obj: (str) remote object path
......
338 354
            'write':[usr and/or grp names]}
339 355

  
340 356
        :param public: (bool)
357

  
358
        :param container_info_cache: (dict) if given, avoid redundant calls to
359
        server for container info (block size and hash information)
341 360
        """
342 361
        self._assert_container()
343 362

  
344 363
        #init
345 364
        block_info = (blocksize, blockhash, size, nblocks) =\
346
            self._get_file_block_info(f, size)
365
            self._get_file_block_info(f, size, container_info_cache)
347 366
        (hashes, hmap, offset) = ([], {}, 0)
348 367
        if not content_type:
349 368
            content_type = 'application/octet-stream'

Also available in: Unified diff