Skip to content

Commit 112e6fc

Browse files
matthewdeanmartinacdha
authored andcommitted
set utf-8, strict
1 parent e2a669a commit 112e6fc

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

src/bagit/__init__.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,9 @@ def find_locale_dir():
131131
#: Block size used when reading files for hashing:
132132
HASH_BLOCK_SIZE = 512 * 1024
133133

134-
135-
def open_text_file(filename, mode="r", encoding="utf-8", errors="strict"):
136-
# Open the underlying file in binary mode so the codec wrapper keeps codecs.open() behavior without its deprecation.
137-
binary_mode = mode.replace("t", "")
138-
if "b" not in binary_mode:
139-
binary_mode += "b"
140-
141-
stream = open(filename, binary_mode)
142-
if "r" in mode and all(flag not in mode for flag in ("w", "a", "+")):
143-
wrapped = codecs.getreader(encoding)(stream, errors=errors)
144-
else:
145-
wrapped = codecs.getwriter(encoding)(stream, errors=errors)
146-
147-
wrapped.encoding = codecs.lookup(encoding).name.upper()
148-
return wrapped
149-
150-
151134
#: Convenience function used everywhere we want to open a file to read text
152135
#: rather than undecoded bytes:
136+
open_text_file = partial(open, encoding="utf-8", errors="strict")
153137

154138
# This is the same as decoding the byte values in codecs.BOM:
155139
UNICODE_BYTE_ORDER_MARK = "\ufeff"

0 commit comments

Comments
 (0)