def create_new_cassette_library()

in cassette/cassette_library.py [0:0]


    def create_new_cassette_library(cls, path, file_format, config=None):
        """Return an instantiated CassetteLibrary.

        Use this method to create new a CassetteLibrary. It will
        automatically determine if it should use a file or directory to
        back the cassette based on the filename. The method assumes that
        all file names with an extension (e.g. ``/file.json``) are files,
        and all file names without extensions are directories (e.g.
        ``/requests``).

        :param str path: filename of file or directory for storing requests
        :param str file_format: the file_format to use for storing requests
        :param dict config: configuration
        """
        if not Encoder.is_supported_format(file_format):
            raise KeyError('%r is not a supported file_format.' % file_format)

        _, extension = os.path.splitext(path)
        if file_format:
            encoder = Encoder.get_encoder_from_file_format(file_format)
        else:
            encoder = Encoder.get_encoder_from_extension(extension)

        # Check if file has extension
        if extension:
            if os.path.isdir(path):
                raise IOError('Expected a file, but found a directory at %s'
                              % path)
            klass = FileCassetteLibrary
        else:
            if os.path.isfile(path):
                raise IOError('Expected a directory, but found a file at %r' %
                              path)
            klass = DirectoryCassetteLibrary

        return klass(path, encoder, config)