~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/pack.py

  • Committer: Aaron Bentley
  • Date: 2007-08-15 11:24:06 UTC
  • mfrom: (2702 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2703.
  • Revision ID: aaron.bentley@utoronto.ca-20070815112406-lyv23omlm0wgsu42
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        """Add a Bytes record with the given names.
87
87
        
88
88
        :param bytes: The bytes to insert.
89
 
        :param names: The names to give the inserted bytes.
 
89
        :param names: The names to give the inserted bytes. Each name is
 
90
            a tuple of bytestrings. The bytestrings may not contain
 
91
            whitespace.
90
92
        :return: An offset, length tuple. The offset is the offset
91
93
            of the record within the container, and the length is the
92
94
            length of data that will need to be read to reconstitute the
100
102
        # Length
101
103
        self.write_func(str(len(bytes)) + "\n")
102
104
        # Names
103
 
        for name in names:
 
105
        for name_tuple in names:
104
106
            # Make sure we're writing valid names.  Note that we will leave a
105
107
            # half-written record if a name is bad!
106
 
            _check_name(name)
107
 
            self.write_func(name + "\n")
 
108
            for name in name_tuple:
 
109
                _check_name(name)
 
110
            self.write_func('\x00'.join(name_tuple) + "\n")
108
111
        # End of headers
109
112
        self.write_func("\n")
110
113
        # Finally, the contents.
262
265
        all_names = set()
263
266
        for record_names, read_bytes in self.iter_records():
264
267
            read_bytes(None)
265
 
            for name in record_names:
266
 
                _check_name_encoding(name)
 
268
            for name_tuple in record_names:
 
269
                for name in name_tuple:
 
270
                    _check_name_encoding(name)
267
271
                # Check that the name is unique.  Note that Python will refuse
268
272
                # to decode non-shortest forms of UTF-8 encoding, so there is no
269
273
                # risk that the same unicode string has been encoded two
270
274
                # different ways.
271
 
                if name in all_names:
272
 
                    raise errors.DuplicateRecordNameError(name)
273
 
                all_names.add(name)
 
275
                if name_tuple in all_names:
 
276
                    raise errors.DuplicateRecordNameError(name_tuple)
 
277
                all_names.add(name_tuple)
274
278
        excess_bytes = self.reader_func(1)
275
279
        if excess_bytes != '':
276
280
            raise errors.ContainerHasExcessDataError(excess_bytes)
300
304
        # Read the list of names.
301
305
        names = []
302
306
        while True:
303
 
            name = self._read_line()
304
 
            if name == '':
 
307
            name_line = self._read_line()
 
308
            if name_line == '':
305
309
                break
306
 
            _check_name(name)
307
 
            names.append(name)
 
310
            name_tuple = tuple(name_line.split('\x00'))
 
311
            for name in name_tuple:
 
312
                _check_name(name)
 
313
            names.append(name_tuple)
308
314
 
309
315
        self._remaining_length = length
310
316
        return names, self._content_reader
328
334
        :raises ContainerError: if this record is invalid.
329
335
        """
330
336
        names, read_bytes = self.read()
331
 
        for name in names:
332
 
            _check_name_encoding(name)
 
337
        for name_tuple in names:
 
338
            for name in name_tuple:
 
339
                _check_name_encoding(name)
333
340
        read_bytes(None)
334
341