зеркало из https://github.com/mozilla/gecko-dev.git
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. --HG-- extra : commitid : 82qw76XmpjC extra : rebase_source : 422b16c5a3b1577f080097925aeaeb560aa3e798
This commit is contained in:
Родитель
ab11dfb209
Коммит
4bee702035
|
@ -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.
|
||||
|
|
Загрузка…
Ссылка в новой задаче