Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def map(self):
'''Memory map the file'''
if self.fileref == False and not self.compressed:
raise laspy.util.LaspyException("File not opened.")
if self.mode in ("r", "r-"):
if self.compressed and self.mode != "r-" and not HAVE_LAZPERF:
self._mmap = FakeMmap(self.filename)
else:
self._mmap = mmap.mmap(self.fileref.fileno(), 0, access = mmap.ACCESS_READ)
elif self.mode in ("w", "rw"):
self._mmap = mmap.mmap(self.fileref.fileno(), 0, access = mmap.ACCESS_WRITE)
else:
raise laspy.util.LaspyException("Invalid Mode: " + str(self.mode))
def _prepare_np_frombuffer_data(data):
# convert data according to `numpy` changes:
# https://github.com/numpy/numpy/blob/a9bb517554004cf2ce7a4be93bcbfb63ee149844/doc/source/release/1.17.0-notes.rst#do-not-lookup-__buffer__-attribute-in-numpyfrombuffer
change_data = isinstance(data, FakeMmap) and \
LooseVersion(np.version.version) >= LooseVersion('1.17.0')
return data.view if change_data else data