mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1168607 - Add a read() method to File; r=glandium
Passing raw file handles around is a bit dangerous because it could lead to leaking file descriptors. Add a read() method that handles the simple case of obtaining the full contents of a File instance. This should ideally be a method on BaseFile. But this would require extra work and isn't needed. So we've deferred it until bug 1170329.
This commit is contained in:
parent
b4a637bb54
commit
1c6e12f560
@ -189,6 +189,9 @@ class BaseFile(object):
|
||||
assert self.path is not None
|
||||
return open(self.path, 'rb')
|
||||
|
||||
def read(self):
|
||||
raise NotImplementedError('BaseFile.read() not implemented. Bug 1170329.')
|
||||
|
||||
@property
|
||||
def mode(self):
|
||||
'''
|
||||
@ -227,6 +230,12 @@ class File(BaseFile):
|
||||
# - leave away sticky bit, setuid, setgid
|
||||
return ret
|
||||
|
||||
def read(self):
|
||||
'''Return the contents of the file.'''
|
||||
with open(self.path, 'rb') as fh:
|
||||
return fh.read()
|
||||
|
||||
|
||||
class ExecutableFile(File):
|
||||
'''
|
||||
File class for executable and library files on OS/2, OS/X and ELF systems.
|
||||
|
Loading…
Reference in New Issue
Block a user