MCPcopy
hub / github.com/Nuitka/Nuitka / openTextFile

Function openTextFile

nuitka/utils/FileOperations.py:1192–1218  ·  view source on GitHub ↗

Open a text file with proper handling. Args: filename: Path to file. mode: Open mode. encoding: Encoding to use. errors: Error handling. Returns: file: Opened file object.

(filename, mode, encoding=None, errors=None)

Source from the content-addressed store, hash-verified

1190
1191
1192def openTextFile(filename, mode, encoding=None, errors=None):
1193 """Open a text file with proper handling.
1194
1195 Args:
1196 filename: Path to file.
1197 mode: Open mode.
1198 encoding: Encoding to use.
1199 errors: Error handling.
1200
1201 Returns:
1202 file: Opened file object.
1203 """
1204 # Do not attempt to create files with what we consider
1205 # illegal filenames.
1206 if "w" in mode:
1207 is_legal, illegal_reason = isLegalPath(filename)
1208 if not is_legal:
1209 raise NuitkaFilenameError(illegal_reason)
1210
1211 # Doesn't exist anymore for Python3.7 or later.
1212 if python_version >= 0x370:
1213 mode = mode.replace("U", "")
1214
1215 if str is bytes:
1216 return codecs.open(filename, mode, encoding=encoding, errors=errors)
1217 else:
1218 return io.open(filename, mode, encoding=encoding, errors=errors)
1219
1220
1221def putTextFileContents(filename, contents, encoding=None):

Callers 15

dumpTreeXMLFunction · 0.90
attachLeadingCommentFunction · 0.90
updateManPagesFunction · 0.90
mainFunction · 0.90
putFileHashContentFunction · 0.90
updatePacmanLockFileFunction · 0.90
convertUsing2to3Function · 0.90

Calls 3

NuitkaFilenameErrorClass · 0.90
isLegalPathFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…