]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Message.clone doesn't return a shallow copy any longer. This fixes a bug with update...
authorArmin Ronacher <armin.ronacher@active-4.com>
Tue, 17 Jun 2008 21:55:14 +0000 (21:55 +0000)
committerArmin Ronacher <armin.ronacher@active-4.com>
Tue, 17 Jun 2008 21:55:14 +0000 (21:55 +0000)
babel/messages/catalog.py
babel/messages/tests/catalog.py

index e6dee3167fb9019a5f05281cd8e84c1762888922..4b54fd8a7419ee45501a595f5de2f6a377b8f54a 100644 (file)
@@ -17,6 +17,7 @@ from cgi import parse_header
 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 @@ class Message(object):
         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
index dbed58ce09f6368e688ba12c89d5e85c29ebcd5b..40159805992f8fe101d36ab9b81dc75519d05c9f 100644 (file)
@@ -34,6 +34,7 @@ class MessageTestCase(unittest.TestCase):
         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 @@ class MessageTestCase(unittest.TestCase):
         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):