code: def determine_bucket_and_prefix(
      bucket: Optional[str] = None,
      key_prefix: Optional[str] = None,
      sagemaker_session=None,
  ):
      """Helper function that returns the correct S3 bucket and prefix to use depending on the inputs.
  
      Args:
          bucket (Optional[str]): S3 Bucket to use (if it exists)
          key_prefix (Optional[str]): S3 Object Key Prefix to use or append to (if it exists)
          sagemaker_session (sagemaker.session.Session): Session to fetch a default bucket and
              prefix from, if bucket doesn't exist. Expected to exist
  
      Returns: The correct S3 Bucket and S3 Object Key Prefix that should be used
      """
      if bucket:
          final_bucket = bucket
          final_key_prefix = key_prefix
      else:
          final_bucket = sagemaker_session.default_bucket()
  
          # default_bucket_prefix (if it exists) should be appended if (and only if) 'bucket' does not
          # exist and we are using the Session's default_bucket.
          final_key_prefix = s3_path_join(
              sagemaker_session.default_bucket_prefix, key_prefix
          )
  
      # We should not append default_bucket_prefix even if the bucket exists but is equal to the
      # default_bucket, because either:
      # (1) the bucket was explicitly passed in by the user and just happens to be the same as the
      # default_bucket (in which case we don't want to change the user's input), or
      # (2) the default_bucket was fetched from Session earlier already (and the default prefix
      # should have been fetched then as well), and then this function was
      # called with it. If we appended the default prefix here, we would be appending it more than
      # once in total.
  
      return final_bucket, final_key_prefix
  
imports: from __future__ import print_function, absolute_import
  import logging
  from functools import reduce
  from typing import Optional
  from six.moves.urllib.parse import urlparse
label_desc: Use image node_id 3 for calling a global function with example usage: determine_bucket_and_prefix(bucket, key_prefix, sagemaker_session) and returns: final_bucket,  final_key_prefix