Rev 5366: Fix fallouts from replacing '_content' by 'from_bytes' for config files. in file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Aug 24 10:41:06 BST 2010
At file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/
------------------------------------------------------------
revno: 5366
revision-id: v.ladeuil+lp at free.fr-20100824094106-2pd55tl364hyobd9
parent: v.ladeuil+lp at free.fr-20100824081006-8bqbtcdoyx0kvfwr
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: lockable-config-files
timestamp: Tue 2010-08-24 11:41:06 +0200
message:
Fix fallouts from replacing '_content' by 'from_bytes' for config files.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2010-08-24 08:10:06 +0000
+++ b/bzrlib/config.py 2010-08-24 09:41:06 +0000
@@ -377,16 +377,21 @@
self._parser = None
@classmethod
- def from_bytes(cls, unicode_bytes):
+ def from_bytes(cls, unicode_bytes, file_name=None):
"""Create a config object from bytes.
:param unicode_bytes: A string representing the file content. This will
be utf-8 encoded.
+
+ :param file_name: The configuration file path.
"""
- conf = cls()
- conf._content = StringIO(unicode_bytes.encode('utf-8'))
+ conf = cls(file_name=file_name)
+ conf._create_from_bytes(unicode_bytes)
return conf
+ def _create_from_bytes(self, unicode_bytes):
+ self._content = StringIO(unicode_bytes.encode('utf-8'))
+
def _get_parser(self, file=symbol_versioning.DEPRECATED_PARAMETER):
if self._parser is not None:
return self._parser
@@ -564,9 +569,8 @@
lock_name = 'lock'
- def __init__(self, file_name, _content=None):
- super(LockableConfig, self).__init__(file_name=file_name,
- _content=_content)
+ def __init__(self, file_name):
+ super(LockableConfig, self).__init__(file_name=file_name)
self.dir = osutils.dirname(osutils.safe_unicode(self.file_name))
self.transport = transport.get_transport(self.dir)
self._lock = lockdir.LockDir(self.transport, 'lock')
@@ -599,6 +603,17 @@
def __init__(self):
super(GlobalConfig, self).__init__(file_name=config_filename())
+ @classmethod
+ def from_bytes(cls, unicode_bytes):
+ """Create a config object from bytes.
+
+ :param unicode_bytes: A string representing the file content. This will
+ be utf-8 encoded.
+ """
+ conf = cls()
+ conf._create_from_bytes(unicode_bytes)
+ return conf
+
def get_editor(self):
return self._get_user_option('editor')
@@ -658,7 +673,7 @@
:param location: The location url to filter the configuration.
"""
conf = cls(location)
- conf._content = StringIO(unicode_bytes.encode('utf-8'))
+ conf._create_from_bytes(unicode_bytes)
return conf
def _get_matching_sections(self):
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2010-08-24 08:10:06 +0000
+++ b/bzrlib/tests/test_config.py 2010-08-24 09:41:06 +0000
@@ -450,15 +450,15 @@
class TestIniBaseConfigOnDisk(tests.TestCaseInTempDir):
def test_cannot_reload_without_name(self):
- conf = config.IniBasedConfig(_content=sample_config_text)
+ conf = config.IniBasedConfig.from_bytes(sample_config_text)
self.assertRaises(AssertionError, conf.reload)
def test_reload_see_new_value(self):
- c1 = config.IniBasedConfig(file_name='./test/conf',
- _content='editor=vim\n')
+ c1 = config.IniBasedConfig.from_bytes('editor=vim\n',
+ file_name='./test/conf')
c1._write_config_file()
- c2 = config.IniBasedConfig(file_name='./test/conf',
- _content='editor=emacs\n')
+ c2 = config.IniBasedConfig.from_bytes('editor=emacs\n',
+ file_name='./test/conf')
c2._write_config_file()
self.assertEqual('vim', c1.get_user_option('editor'))
self.assertEqual('emacs', c2.get_user_option('editor'))
@@ -483,7 +483,7 @@
return self.config_class(*self.config_args)
def create_config(self, content):
- c = self.config_class(*self.config_args, _content=content)
+ c = self.config_class.from_bytes(content, *self.config_args)
c.lock_write()
c._write_config_file()
c.unlock()
More information about the bazaar-commits
mailing list