diff options
author | Sayamindu Dasgupta <sayamindu@gmail.com> | 2009-04-24 16:03:57 (GMT) |
---|---|---|
committer | Sayamindu Dasgupta <sayamindu@gmail.com> | 2009-04-24 16:03:57 (GMT) |
commit | ec66e468442726540a532c012a5e6d329a5b9d1e (patch) | |
tree | 6893fe19ade169c2b8b73a64a0f582fd1b1c075d | |
parent | 95cc52a7b3851b0804ab2d65484eb4ed8ab5d04d (diff) |
Fix copy() behaviour in pypo.py: Upstream bug 870
-rw-r--r-- | translate-toolkit-1.3.0/translate/lang/common.py | 4 | ||||
-rw-r--r-- | translate-toolkit-1.3.0/translate/storage/pypo.py | 23 |
2 files changed, 27 insertions, 0 deletions
diff --git a/translate-toolkit-1.3.0/translate/lang/common.py b/translate-toolkit-1.3.0/translate/lang/common.py index 8741eee..10b7de0 100644 --- a/translate-toolkit-1.3.0/translate/lang/common.py +++ b/translate-toolkit-1.3.0/translate/lang/common.py @@ -197,6 +197,10 @@ class Common(object): pass return language + def __deepcopy__(self, memo={}): + memo[id(self)] = self + return self + def __repr__(self): """Give a simple string representation without address information to be able to store it in text for comparison later.""" diff --git a/translate-toolkit-1.3.0/translate/storage/pypo.py b/translate-toolkit-1.3.0/translate/storage/pypo.py index 915d9c5..9830cd0 100644 --- a/translate-toolkit-1.3.0/translate/storage/pypo.py +++ b/translate-toolkit-1.3.0/translate/storage/pypo.py @@ -150,6 +150,10 @@ class pounit(pocommon.pounit): # msgid = [] # msgstr = [] + # Our homegrown way to indicate what must be copied in a shallow + # fashion + __shallow__ = ['_store'] + def __init__(self, source=None, encoding="UTF-8"): self._encoding = encodingToUse(encoding) self.obsolete = False @@ -314,6 +318,25 @@ class pounit(pocommon.pounit): """Remove all the translator's notes (other comments)""" self.othercomments = [] + def __deepcopy__(self, memo={}): + # Make an instance to serve as the copy + new_unit = self.__class__() + # We'll be testing membership frequently, so make a set from + # self.__shallow__ + shallow = set(self.__shallow__) + # Make deep copies of all members which are not in shallow + for key, value in self.__dict__.iteritems(): + if key not in shallow: + setattr(new_unit, key, copy.deepcopy(value)) + # Make shallow copies of all members which are in shallow + for key in set(shallow): + setattr(new_unit, key, getattr(self, key)) + # Mark memo with ourself, so that we won't get deep copied + # again + memo[id(self)] = self + # Return our copied unit + return new_unit + def copy(self): return copy.deepcopy(self) |