Bug 1253110 - Implement DeflatedFile.read() and ManifestFile.read(); r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Mon, 18 Apr 2016 16:33:23 -0700
changeset 363133 5d02c4451a926f256885a94b783ebaad80086bb3
parent 362943 0a25833062a880f369e6f9f622413a94cc671bf4
child 363134 8988e990dda08c2329d87eb39de8a075f617a0ef
push id17107
push usergszorc@mozilla.com
push dateWed, 04 May 2016 00:54:14 +0000
reviewersglandium
bugs1253110
milestone49.0a1
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
python/mozbuild/mozpack/files.py
--- 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):
         '''