~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2005-07-11 21:19:12 UTC
  • mto: (1185.11.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050711211912-df0f83fb6034440d
Removed Transport.open(), making get + put encode/decode to utf-8

Show diffs side-by-side

added added

removed removed

Lines of Context:
294
294
        if mode == 'rb': 
295
295
            return self._transport.get(relpath)
296
296
        elif mode == 'wb':
297
 
            return self._transport.open(relpath)
 
297
            raise BzrError("Branch.controlfile(mode='wb') is not supported, use put_controlfile")
298
298
        elif mode == 'r':
299
 
            return codecs.getreader('utf-8')(self._transport.get(relpath))
 
299
            return self._transport.get(relpath, decode=True)
300
300
        elif mode == 'w':
301
 
            return codecs.getwriter(bzrlib.user_encoding)(
302
 
                    self._transport.open(relpath), errors='replace')
 
301
            raise BzrError("Branch.controlfile(mode='w') is not supported, use put_controlfile")
 
302
            #return codecs.getwriter('utf-8')(
 
303
            #        self._transport.open(relpath), errors='replace')
303
304
        else:
304
305
            raise BzrError("invalid controlfile mode %r" % mode)
305
306
 
 
307
    def put_controlfile(self, file_or_path, f, encode=True):
 
308
        """Write an entry as a controlfile.
 
309
 
 
310
        :param file_or_path: This is the sub-path underneath the bzr control directory
 
311
        :param f: A file-like or string object whose contents should be placed
 
312
                  in the appropriate location.
 
313
        :param encode:  If true, encode the contents as utf-8
 
314
        """
 
315
        self._transport.put(self._rel_controlfilename(file_or_path), f, encode=encode)
306
316
 
307
317
    def _make_control(self):
308
318
        from bzrlib.inventory import Inventory
309
319
        from bzrlib.xml import pack_xml
 
320
        from cStringIO import StringIO
310
321
        
311
322
        self._transport.mkdir(self.controlfilename([]))
312
323
        self._transport.put(self._rel_controlfilename('README'),
324
335
        mutter('created control directory in ' + self._transport.base)
325
336
 
326
337
        # TODO: Try and do this with self._transport.put() instead
327
 
        pack_xml(Inventory(), self.controlfile('inventory','w'))
 
338
        sio = StringIO()
 
339
        pack_xml(Inventory(), sio)
 
340
        self.put_controlfile('inventory', sio)
328
341
 
329
342
 
330
343
    def _check_format(self):