# HG changeset patch # User aronacher # Date 1213739714 0 # Node ID 36408f0681386ef3d6fc4cb712db308337679d42 # Parent 44637ad19c3502c9c06b993b7605458bd0452a2f Message.clone doesn't return a shallow copy any longer. This fixes a bug with update where flags where shared. diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py --- a/babel/messages/catalog.py +++ b/babel/messages/catalog.py @@ -17,6 +17,7 @@ from datetime import datetime from difflib import get_close_matches from email import message_from_string +from copy import copy import re try: set @@ -104,9 +105,10 @@ return cmp(self.id, obj.id) def clone(self): - return Message(self.id, self.string, self.locations, self.flags, - self.auto_comments, self.user_comments, - self.previous_id, self.lineno, self.context) + return Message(*map(copy, (self.id, self.string, self.locations, + self.flags, self.auto_comments, + self.user_comments, self.previous_id, + self.lineno, self.context))) def check(self, catalog=None): """Run various validation checks on the message. Some validations diff --git a/babel/messages/tests/catalog.py b/babel/messages/tests/catalog.py --- a/babel/messages/tests/catalog.py +++ b/babel/messages/tests/catalog.py @@ -34,6 +34,7 @@ assert catalog.PYTHON_FORMAT.search('foo %(name).*f') assert catalog.PYTHON_FORMAT.search('foo %(name)3.*f') assert catalog.PYTHON_FORMAT.search('foo %(name)*.*f') + assert catalog.PYTHON_FORMAT.search('foo %()s') def test_translator_comments(self): mess = catalog.Message('foo', user_comments=['Comment About `foo`']) @@ -44,6 +45,12 @@ self.assertEqual(mess.auto_comments, ['Comment 1 About `foo`', 'Comment 2 About `foo`']) + def test_clone_message_object(self): + msg = catalog.Message('foo', locations=[('foo.py', 42)]) + clone = msg.clone() + clone.locations.append(('bar.py', 42)) + self.assertEqual(msg.locations, [('foo.py', 42)]) + class CatalogTestCase(unittest.TestCase):