<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def dump_pk(obj, abspath, pk_protocol=pk_protocol, replace=False, compress=False, enable_verbose=True):
 """Dump Picklable Python Object to file. Provides multiple choice to customize the behavior. :param obj: Picklable Python Object. :param abspath: ``save as`` path, file extension has to be ``.pickle`` or ``.gz`` (for compressed Pickle). :type abspath: string :param pk_protocol: (default your python version) use 2, to make a py2.x/3.x compatible pickle file. But 3 is faster. :type pk_protocol: int :param replace: (default False) If ``True``, when you dump Pickle to a existing path, it silently overwrite it. If False, an exception will be raised. Default False setting is to prevent overwrite file by mistake. :type replace: boolean :param compress: (default False) If ``True``, use GNU program gzip to compress the Pickle file. Disk usage can be greatly reduced. But you have to use :func:`load_pk(abspath, compress=True)<load_pk>` in loading. :type compress: boolean :param enable_verbose: (default True) Trigger for message. :type enable_verbose: boolean Usage:: Complete! Elapse 0.001763 sec **中文文档** 将Python对象以Pickle的方式序列化, 保存至本地文件。(有些自定义类无法被序列化) 参数列表 :param obj: 可Pickle化的Python对象 :param abspath: 写入文件的路径。扩展名必须为 ``.pickle`` 或 ``.gz``, 其中gz用于被压 缩的Pickle :type abspath: ``字符串`` :param pk_protocol: (默认 等于你Python的大版本号) 使用2可以使得保存的文件能被 py2.x/3.x都能读取。但是协议3的速度更快, 体积更小, 性能更高。 :type pk_protocol: ``整数`` :param replace: (默认 False) 当为``True``时, 如果写入路径已经存在, 则会自动覆盖 原文件。而为``False``时, 则会抛出异常。防止误操作覆盖源文件。 :type replace: ``布尔值`` :param compress: (默认 False) 当为``True``时, 使用开源压缩标准gzip压缩Pickle文件。 通常能让文件大小缩小10-20倍不等。如要读取文件, 则需要使用函数 :func:`load_pk(abspath, compress=True)<load_pk>`. :type compress: ``布尔值`` :param enable_verbose: (默认 True) 是否打开信息提示开关, 批处理时建议关闭. :type enable_verbose: ``布尔值`` """

    abspath = str(abspath)  # try stringlize

    msg = Messenger(enable_verbose=enable_verbose)

    if compress:  # check extension name
        root, ext = os.path.splitext(abspath)
        if ext != ".gz":
            if ext != ".tmp":
                raise Exception(
                    "compressed pickle has to use extension '.gz'!")
            else:
                _, ext = os.path.splitext(root)
                if ext != ".gz":
                    raise Exception(
                        "compressed pickle has to use extension '.gz'!")
    else:
        root, ext = os.path.splitext(abspath)
        if ext != ".pickle":
            if ext != ".tmp":
                raise Exception("file extension are not '.pickle'!")
            else:
                _, ext = os.path.splitext(root)
                if ext != ".pickle":
                    raise Exception("file extension are not '.pickle'!")

    msg.show("\nDumping to %s..." % abspath)
    st = time.clock()

    if os.path.exists(abspath):  # if exists, check replace option
        if replace:  # replace existing file
            if compress:
                with gzip.open(abspath, "wb") as f:
                    f.write(pickle.dumps(obj, protocol=pk_protocol))
            else:
                with open(abspath, "wb") as f:
                    pickle.dump(obj, f, protocol=pk_protocol)
        else:  # stop, print error message
            raise Exception("\tCANNOT WRITE to %s, "
                            "it's already exists" % abspath)
    else:  # if not exists, just write to it
        if compress:
            with gzip.open(abspath, "wb") as f:
                f.write(pickle.dumps(obj, protocol=pk_protocol))
        else:
            with open(abspath, "wb") as f:
                pickle.dump(obj, f, protocol=pk_protocol)

    msg.show("    Complete! Elapse %.6f sec" % (time.clock() - st))