# -*- coding: utf-8 -*-"""werkzeug.filesystem~~~~~~~~~~~~~~~~~~~Various utilities for the local filesystem.:copyright: 2007 Pallets:license: BSD-3-Clause"""import codecsimport sysimport warnings# We do not trust traditional unixes.has_likely_buggy_unicode_filesystem = (sys.platform.startswith("linux") or "bsd" in sys.platform)def _is_ascii_encoding(encoding):"""Given an encoding this figures out if the encoding is actually ASCII (whichis something we don't actually want in most cases). This is necessarybecause ASCII comes under many names such as ANSI_X3.4-1968."""if encoding is None:return Falsetry:return codecs.lookup(encoding).name == "ascii"except LookupError:return Falseclass BrokenFilesystemWarning(RuntimeWarning, UnicodeWarning):"""The warning used by Werkzeug to signal a broken filesystem. Will only beused once per runtime."""_warned_about_filesystem_encoding = Falsedef get_filesystem_encoding():"""Returns the filesystem encoding that should be used. Note that this isdifferent from the Python understanding of the filesystem encoding whichmight be deeply flawed. Do not use this value against Python's unicode APIsbecause it might be different. See :ref:`filesystem-encoding` for the exactbehavior.The concept of a filesystem encoding in generally is not something youshould rely on. As such if you ever need to use this function except forwriting wrapper code reconsider."""global _warned_about_filesystem_encodingrv = sys.getfilesystemencoding()if has_likely_buggy_unicode_filesystem and not rv or _is_ascii_encoding(rv):if not _warned_about_filesystem_encoding:warnings.warn("Detected a misconfigured UNIX filesystem: Will use"" UTF-8 as filesystem encoding instead of {0!r}".format(rv),BrokenFilesystemWarning,)_warned_about_filesystem_encoding = Truereturn "utf-8"return rv
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。