def ComposeObjects(self, bucket, src_objects, dest_obj, content_type):
    src_objects_len = len(src_objects)
    if src_objects_len < 1:
      return {}
    elif src_objects_len <= self.MAX_COMPOSABLE_OBJECTS:
      body = {'sourceObjects': [{'name': s} for s in src_objects],
              'destination': {'contentType': content_type}}
      logging.info('calling gcs composit with %d objects', len(src_objects))
      req = self._AcquireService().objects().compose(destinationBucket=bucket,
                                                     destinationObject=dest_obj,
                                                     body=body)
      return req.execute()
    elif src_objects_len <= self.MAX_TOTAL_COMPOSABLE_OBJECTS:
      # A composed object can store all these src_objects
      tmp = []
      for chunk in SplitEvenly(src_objects, self.MAX_COMPOSABLE_OBJECTS):
        tmp.append(self.UrlToBucketAndName(self.UrlCreator(bucket)())[1])
        self.ComposeObjects(bucket, chunk, tmp[-1], content_type)
      r = self.ComposeObjects(bucket, tmp, dest_obj, content_type)
      # Clean up temporary objects
      for t in tmp:
        self.DeleteObject(bucket, t)
      return r
    else:
      # A composed object will have too many parts to make this in one compose.
      # So we make a few objects, then copy them to reset the component count.
      tmp = []
      for chunk in SplitEvenly(src_objects, self.MAX_TOTAL_COMPOSABLE_OBJECTS):
        tmp.append(self.UrlToBucketAndName(self.UrlCreator(bucket)())[1])
        self.ComposeObjects(bucket, chunk, tmp[-1], content_type)
      # now compress those temp files to reset the composed object count
      for dest_obj in tmp:
        self.CompressObject(self.MakeUrl(*dest_obj))
      r = self.ComposeObjects(bucket, tmp, dest_obj, content_type)
      # Clean up temporary objects
      for t in tmp:
        self.DeleteObject(bucket, t)
      return r
Composes multiple objects into a one.
dataset/ETHPy150Open GoogleCloudPlatform/Data-Pipeline/app/src/clients/gcs.py/Gcs.ComposeObjects