def check_spark():
    SparkContext = False
    try:
        from pyspark import SparkContext
    finally:
        return SparkContext

def check_path(path, credentials=None):
    """
    Check that specified output path does not already exist

    The ValueError message will suggest calling with overwrite=True; this function is expected to be
    called from the various output methods that accept an 'overwrite' keyword argument.
    """
    from thunder.data.readers import get_file_reader
    reader = get_file_reader(path)(credentials=credentials)
    existing = reader.list(path, directories=True)
    if existing:
        raise ValueError("Path %s appears to already exist. Specify a new directory, "
                         "or call " % path + "with overwrite=True to overwrite.")

def connection_with_anon(credentials, anon=True):
    """
    Connect to S3 with automatic handling for anonymous access.

    Parameters
    ----------
    credentials : dict
        AWS access key ('access') and secret access key ('secret')

    anon : boolean, optional, default = True
        Whether to make an anonymous connection if credentials fail to authenticate
    """
    from boto.s3.connection import S3Connection
    from boto.exception import NoAuthHandlerFound

    try:
        conn = S3Connection(aws_access_key_id=credentials['access'],
                            aws_secret_access_key=credentials['secret'])
        return conn

    except NoAuthHandlerFound:
        if anon:
            conn = S3Connection(anon=True)
            return conn
        else:
            raise
def notsupported(mode):
    raise NotImplementedError("Operation not supported for mode '%s'" % mode)


def check_spark():
    SparkContext = False
    try:
        from pyspark import SparkContext
    finally:
        return SparkContext

def check_path(path, credentials=None):
    """
    Check that specified output path does not already exist

    The ValueError message will suggest calling with overwrite=True; this function is expected to be
    called from the various output methods that accept an 'overwrite' keyword argument.
    """
    from thunder.data.readers import get_file_reader
    reader = get_file_reader(path)(credentials=credentials)
    existing = reader.list(path, directories=True)
    if existing:
        raise ValueError("Path %s appears to already exist. Specify a new directory, "
                         "or call " % path + "with overwrite=True to overwrite.")

def connection_with_anon(credentials, anon=True):
    """
    Connect to S3 with automatic handling for anonymous access.

    Parameters
    ----------
    credentials : dict
        AWS access key ('access') and secret access key ('secret')

    anon : boolean, optional, default = True
        Whether to make an anonymous connection if credentials fail to authenticate
    """
    from boto.s3.connection import S3Connection
    from boto.exception import NoAuthHandlerFound

    try:
        conn = S3Connection(aws_access_key_id=credentials['access'],
                            aws_secret_access_key=credentials['secret'])
        return conn

    except NoAuthHandlerFound:
        if anon:
            conn = S3Connection(anon=True)
            return conn
        else:
            raise
Add method for raising not supported error
Add method for raising not supported error

+ def notsupported(mode):
+     raise NotImplementedError("Operation not supported for mode '%s'" % mode)
+ 
+ 
  def check_spark():
      SparkContext = False
      try:
          from pyspark import SparkContext
      finally:
          return SparkContext
  
  def check_path(path, credentials=None):
      """
      Check that specified output path does not already exist
  
      The ValueError message will suggest calling with overwrite=True; this function is expected to be
      called from the various output methods that accept an 'overwrite' keyword argument.
      """
      from thunder.data.readers import get_file_reader
      reader = get_file_reader(path)(credentials=credentials)
      existing = reader.list(path, directories=True)
      if existing:
          raise ValueError("Path %s appears to already exist. Specify a new directory, "
                           "or call " % path + "with overwrite=True to overwrite.")
  
  def connection_with_anon(credentials, anon=True):
      """
      Connect to S3 with automatic handling for anonymous access.
  
      Parameters
      ----------
      credentials : dict
          AWS access key ('access') and secret access key ('secret')
  
      anon : boolean, optional, default = True
          Whether to make an anonymous connection if credentials fail to authenticate
      """
      from boto.s3.connection import S3Connection
      from boto.exception import NoAuthHandlerFound
  
      try:
          conn = S3Connection(aws_access_key_id=credentials['access'],
                              aws_secret_access_key=credentials['secret'])
          return conn
  
      except NoAuthHandlerFound:
          if anon:
              conn = S3Connection(anon=True)
              return conn
          else:
              raise
Add method for raising not supported error
## Code Before:
def check_spark():
    SparkContext = False
    try:
        from pyspark import SparkContext
    finally:
        return SparkContext

def check_path(path, credentials=None):
    """
    Check that specified output path does not already exist

    The ValueError message will suggest calling with overwrite=True; this function is expected to be
    called from the various output methods that accept an 'overwrite' keyword argument.
    """
    from thunder.data.readers import get_file_reader
    reader = get_file_reader(path)(credentials=credentials)
    existing = reader.list(path, directories=True)
    if existing:
        raise ValueError("Path %s appears to already exist. Specify a new directory, "
                         "or call " % path + "with overwrite=True to overwrite.")

def connection_with_anon(credentials, anon=True):
    """
    Connect to S3 with automatic handling for anonymous access.

    Parameters
    ----------
    credentials : dict
        AWS access key ('access') and secret access key ('secret')

    anon : boolean, optional, default = True
        Whether to make an anonymous connection if credentials fail to authenticate
    """
    from boto.s3.connection import S3Connection
    from boto.exception import NoAuthHandlerFound

    try:
        conn = S3Connection(aws_access_key_id=credentials['access'],
                            aws_secret_access_key=credentials['secret'])
        return conn

    except NoAuthHandlerFound:
        if anon:
            conn = S3Connection(anon=True)
            return conn
        else:
            raise
## Instruction:
Add method for raising not supported error
## Code After:
def notsupported(mode):
    raise NotImplementedError("Operation not supported for mode '%s'" % mode)


def check_spark():
    SparkContext = False
    try:
        from pyspark import SparkContext
    finally:
        return SparkContext

def check_path(path, credentials=None):
    """
    Check that specified output path does not already exist

    The ValueError message will suggest calling with overwrite=True; this function is expected to be
    called from the various output methods that accept an 'overwrite' keyword argument.
    """
    from thunder.data.readers import get_file_reader
    reader = get_file_reader(path)(credentials=credentials)
    existing = reader.list(path, directories=True)
    if existing:
        raise ValueError("Path %s appears to already exist. Specify a new directory, "
                         "or call " % path + "with overwrite=True to overwrite.")

def connection_with_anon(credentials, anon=True):
    """
    Connect to S3 with automatic handling for anonymous access.

    Parameters
    ----------
    credentials : dict
        AWS access key ('access') and secret access key ('secret')

    anon : boolean, optional, default = True
        Whether to make an anonymous connection if credentials fail to authenticate
    """
    from boto.s3.connection import S3Connection
    from boto.exception import NoAuthHandlerFound

    try:
        conn = S3Connection(aws_access_key_id=credentials['access'],
                            aws_secret_access_key=credentials['secret'])
        return conn

    except NoAuthHandlerFound:
        if anon:
            conn = S3Connection(anon=True)
            return conn
        else:
            raise