MCPcopy Create free account
hub / github.com/numpy/numpy / unix2dos

Function unix2dos

numpy/distutils/line_endings.py:43–62  ·  view source on GitHub ↗

Replace LF with CRLF in argument files. Print names of changed files.

(file)

Source from the content-addressed store, hash-verified

41#----------------------------------
42
43def unix2dos(file):
44 "Replace LF with CRLF in argument files. Print names of changed files."
45 if os.path.isdir(file):
46 print(file, "Directory!")
47 return
48
49 with open(file, "rb") as fp:
50 data = fp.read()
51 if '\0' in data:
52 print(file, "Binary!")
53 return
54 newdata = re.sub("\r\n", "\n", data)
55 newdata = re.sub("\n", "\r\n", newdata)
56 if newdata != data:
57 print('unix2dos:', file)
58 with open(file, "wb") as f:
59 f.write(newdata)
60 return file
61 else:
62 print(file, 'ok')
63
64def unix2dos_one_dir(modified_files, dir_name, file_names):
65 for file in file_names:

Callers 1

unix2dos_one_dirFunction · 0.85

Calls 4

printFunction · 0.85
openFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected