Bug 1253110 - Implement DeflatedFile.read() and ManifestFile.read(); r?glandium
BaseFile.read() isn't implemented because each file class needs to do
intelligent things. We're about to introduce a consumer that wants
both DeflatedFile.read() and ManifestFile.read(), so implement them.
As part of this, I snuck in a better error message saying which class
doesn't implement read(), since each class likely has a different
implementation.
MozReview-Commit-ID: AwV1xx8pzUh
--- a/python/mozbuild/mozpack/files.py
+++ b/python/mozbuild/mozpack/files.py
@@ -193,17 +193,18 @@ class BaseFile(object):
Return a file-like object allowing to read() the content of the
associated file. This is meant to be overloaded in subclasses to return
a custom file-like object.
'''
assert self.path is not None
return open(self.path, 'rb')
def read(self):
- raise NotImplementedError('BaseFile.read() not implemented. Bug 1170329.')
+ raise NotImplementedError('%s.read() not implemented. Bug 1170329.' %
+ self.__class__.__name__)
@property
def mode(self):
'''
Return the file's unix mode, or None if it has no meaning.
'''
return None
@@ -500,16 +501,18 @@ class DeflatedFile(BaseFile):
from mozpack.mozjar import JarFileReader
assert isinstance(file, JarFileReader)
self.file = file
def open(self):
self.file.seek(0)
return self.file
+ def read(self):
+ return self.open().read()
class XPTFile(GeneratedFile):
'''
File class for a linked XPT file. It takes several XPT files as input
(using the add() and remove() member functions), and links them at copy()
time.
'''
def __init__(self):
@@ -615,16 +618,19 @@ class ManifestFile(BaseFile):
def open(self):
'''
Return a file-like object allowing to read() the serialized content of
the manifest.
'''
return BytesIO(''.join('%s\n' % e.rebase(self._base)
for e in self._entries))
+ def read(self):
+ return self.open().read()
+
def __iter__(self):
'''
Iterate over entries in the manifest file.
'''
return iter(self._entries)
def isempty(self):
'''