def ParseBucketAndPath(gcs_path, default_bucket=None):
  """Parse a Cloud Storage path.

  If bucket name is missing, the default bucket name is used.

  Args:
    gcs_path: A path to a location on the Cloud Storage.
    default_bucket: The default bucket name.

  Returns:
    bucket: Name of the Cloud Storage bucket.
    path: Path within the bucket.

  Raises:
    ValueError: Raised when the bucket name is missing.
  """
  gcs_path = gcs_path.strip()
  gs_prefix = 'gs://'
  if default_bucket is not None and not gcs_path.startswith(gs_prefix):
    return default_bucket, gcs_path

  if gcs_path.startswith(gs_prefix):
    full_path = gcs_path[len(gs_prefix):]
    path_parts = full_path.split('/', 1)
    if len(path_parts) == 2 and path_parts[0]:
      bucket, path = path_parts
    else:
      raise ValueError('Cannot identify the bucket name in %s.'
                       % gcs_path)
  else:
    raise ValueError('Path "%s" ' % gcs_path
                     + 'requires a default bucket that is missing.')
  return bucket, path