當前位置: 首頁>>代碼示例>>Python>>正文


Python util.open_for_csv方法代碼示例

本文整理匯總了Python中wheel.util.open_for_csv方法的典型用法代碼示例。如果您正苦於以下問題:Python util.open_for_csv方法的具體用法?Python util.open_for_csv怎麽用?Python util.open_for_csv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wheel.util的用法示例。


在下文中一共展示了util.open_for_csv方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: write_record

# 需要導入模塊: from wheel import util [as 別名]
# 或者: from wheel.util import open_for_csv [as 別名]
def write_record(self, bdist_dir, distinfo_dir):
        from wheel.util import urlsafe_b64encode

        record_path = os.path.join(distinfo_dir, "RECORD")
        record_relpath = os.path.relpath(record_path, bdist_dir)

        def walk():
            for dir, dirs, files in os.walk(bdist_dir):
                dirs.sort()
                for f in sorted(files):
                    yield os.path.join(dir, f)

        def skip(path):
            """Wheel hashes every possible file."""
            return path == record_relpath

        with open_for_csv(record_path, "w+") as record_file:
            writer = csv.writer(record_file)
            for path in walk():
                relpath = os.path.relpath(path, bdist_dir)
                if skip(relpath):
                    hash = ""
                    size = ""
                else:
                    with open(path, "rb") as f:
                        data = f.read()
                    digest = hashlib.sha256(data).digest()
                    hash = "sha256=" + native(urlsafe_b64encode(digest))
                    size = len(data)
                record_path = os.path.relpath(path, bdist_dir).replace(os.path.sep, "/")
                writer.writerow((record_path, hash, size))


# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------- 
開發者ID:microsoft,項目名稱:botbuilder-python,代碼行數:40,代碼來源:azure_bdist_wheel.py


注:本文中的wheel.util.open_for_csv方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。