Read in universal newline mode

Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
Dan Ryan
2018-05-03 12:07:02 -04:00
parent a075445367
commit d26e16a539
4 changed files with 5 additions and 14 deletions
+1 -6
View File
@@ -258,7 +258,6 @@ def NamedTemporaryFile(
if os.name == "nt" and delete:
flags |= os.O_TEMPORARY
if six.PY2:
# if newline or 'b' not in mode:
flags = _text_openflags if 'b' not in mode else flags
(fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
else:
@@ -270,10 +269,6 @@ def NamedTemporaryFile(
return _TemporaryFileWrapper(file, name, delete)
except BaseException:
try:
os.unlink(name)
except OSError:
os.close(fd)
os.unlink(name)
os.unlink(name)
os.close(fd)
raise
+2 -2
View File
@@ -395,7 +395,7 @@ class Project(object):
def read_pipfile(self):
# Open the pipfile, read it into memory.
with io.open(self.pipfile_location) as f:
with io.open(self.pipfile_location, newline='') as f:
contents = f.read()
self._pipfile_newlines = preferred_newlines(f)
@@ -769,7 +769,7 @@ class Project(object):
self.write_toml(self.parsed_pipfile)
def load_lockfile(self, expand_env_vars=True):
with io.open(self.lockfile_location) as lock:
with io.open(self.lockfile_location, newline='') as lock:
j = json.load(lock)
self._lockfile_newlines = preferred_newlines(lock)
# lockfile is just a string
-4
View File
@@ -1305,8 +1305,6 @@ def atomic_open_for_write(target, binary=False, newline=None, encoding=None):
target with this new file.
"""
from ._compat import NamedTemporaryFile
if six.PY2 and not binary and newline == u'\n':
binary = True
mode = 'w+b' if binary else 'w'
f = NamedTemporaryFile(
@@ -1335,5 +1333,3 @@ def atomic_open_for_write(target, binary=False, newline=None, encoding=None):
except OSError:
pass
os.rename(f.name, target) # No os.replace() on Python 2.
finally:
f.close()
+2 -2
View File
@@ -87,7 +87,7 @@ def test_maintain_file_line_endings(PipenvInstance, pypi, newlines):
# Rewrite each file with parameterized newlines
for fn in [p.pipfile_path, p.lockfile_path]:
with io.open(fn) as f:
with io.open(fn, newline='') as f:
contents = f.read()
written_newlines = f.newlines
assert written_newlines == u'\n'
@@ -100,7 +100,7 @@ def test_maintain_file_line_endings(PipenvInstance, pypi, newlines):
# Make sure we kept the right newlines
for fn in [p.pipfile_path, p.lockfile_path]:
with io.open(fn) as f:
with io.open(fn, newline='') as f:
contents = f.read()
actual_newlines = f.newlines
assert actual_newlines == newlines