/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/pack.py

Add validate method to ContainerReader and BytesRecordReader.

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
                # Unknown record type.
149
149
                raise errors.UnknownRecordTypeError(record_kind)
150
150
 
 
151
    def validate(self):
 
152
        """Validate this container and its records.
 
153
 
 
154
        You can either validate or iter_records, you can't do both.
 
155
 
 
156
        :raises ContainerError: if something is invalid.
 
157
        """
 
158
        for names, bytes in self.iter_records():
 
159
            # XXX: bytes is str, should be callable to get bytes.
 
160
            # callable()
 
161
            pass
 
162
        excess_bytes = self.reader_func(1)
 
163
        if excess_bytes != '':
 
164
            raise errors.ContainerHasExcessDataError(excess_bytes)
 
165
 
151
166
 
152
167
class BytesRecordReader(BaseReader):
153
168
 
154
169
    def read(self):
 
170
        """Read this record.
 
171
 
 
172
        You can either validate or read, you can't do both.
 
173
 
 
174
        :returns: (names, bytes)
 
175
        """
155
176
        # Read the content length.
156
177
        length_line = self._read_line()
157
178
        try:
173
194
            raise errors.UnexpectedEndOfContainerError()
174
195
        return names, bytes
175
196
 
 
197
    def validate(self):
 
198
        """Validate this record.
 
199
 
 
200
        You can either validate or read, you can't do both.
 
201
 
 
202
        :raises ContainerError: if this record is invalid.
 
203
        """
 
204
        self.read()