We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove SubfieldBase from MultiStringField
In django 1.9 SubFieldBase is deprecated, and removed in 1.10

Related Stackoverflow - http://stackoverflow.com/questions/35166085/how-to-deal-with-subfieldbase-has-been-deprecated-use-field-from-db-value-inst

https://docs.djangoproject.com/en/1.9/ref/models/fields/#field-api-reference

afaict we can just safely remove - it seems it just needs to have to/from db methods


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pootle/apps/pootle_store/fields.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) Pootle contributors.
4 #
5 # This file is a part of the Pootle project. It is distributed under the GPL3
6 # or later license. See the LICENSE file for a copy of the license and the
7 # AUTHORS file for copyright and authorship information.
8 
9 """Fields required for handling translation files"""
10 
11 import logging
12 import os
13 
14 from translate.misc.multistring import multistring
15 
16 from django.db import models
17 from django.db.models.fields.files import FieldFile, FileField
18 
19 from pootle.core.utils.multistring import (parse_multistring,
20                                            unparse_multistring)
21 
22 
23 # # # # # # # # # String # # # # # # # # # # # # # # #
24 
25 
26 def to_db(value):
27     """Flatten the given value (string, list of plurals or multistring) into
28     the database string representation.
29     """
30     if value is None:
31         return None
32 
33     return unparse_multistring(value)
34 
35 
36 def to_python(value):
37     """Reconstruct a multistring from the database string representation."""
38     if not value:
39         return multistring("", encoding="UTF-8")
40     elif isinstance(value, multistring):
41         return value
42     elif isinstance(value, basestring):
43         return parse_multistring(value)
44     elif isinstance(value, dict):
45         return multistring([val for __, val in sorted(value.items())],
46                            encoding="UTF-8")
47     else:
48         return multistring(value, encoding="UTF-8")
49 
50 
51 class MultiStringField(models.Field):
52     description = \
53         "a field imitating translate.misc.multistring used for plurals"
54     __metaclass__ = models.SubfieldBase
55 
56     def __init__(self, *args, **kwargs):
57         super(MultiStringField, self).__init__(*args, **kwargs)
58 
59     def get_internal_type(self):
60         return "TextField"
61 
62     def to_python(self, value):
63         return to_python(value)
64 
65     def get_prep_value(self, value):
66         return to_db(value)
67 
68     def get_prep_lookup(self, lookup_type, value):
69         if (lookup_type in ('exact', 'iexact') or
70             not isinstance(value, basestring)):
71             value = self.get_prep_value(value)
72         return super(MultiStringField, self).get_prep_lookup(lookup_type,
73                                                              value)
74 
75 
76 # # # # # # # # # File # # # # # # # # # # # # # # # #
77 
78 
79 class StoreTuple(object):
80     """Encapsulates toolkit stores in the in memory cache, needed
81     since LRUCachingDict is based on a weakref.WeakValueDictionary
82     which cannot reference normal tuples
83     """
84 
85     def __init__(self, store, mod_info, realpath):
86         self.store = store
87         self.mod_info = mod_info
88         self.realpath = realpath
89 
90 
91 class TranslationStoreFieldFile(FieldFile):
92     """FieldFile is the file-like object of a FileField, that is found in a
93     TranslationStoreField.
94     """
95 
96     from translate.misc.lru import LRUCachingDict
97     from django.conf import settings
98 
99     _store_cache = LRUCachingDict(settings.PARSE_POOL_SIZE,
100                                   settings.PARSE_POOL_CULL_FREQUENCY)
101 
102     def getpomtime(self):
103         file_stat = os.stat(self.realpath)
104         return file_stat.st_mtime, file_stat.st_size
105 
106     @property
107     def filename(self):
108         return os.path.basename(self.name)
109 
110     def _get_realpath(self):
111         """Return realpath resolving symlinks if necessary."""
112         if not hasattr(self, "_realpath"):
113             # Django's db.models.fields.files.FieldFile raises ValueError if
114             # if the file field has no name - and tests "if self" to check
115             if self:
116                 self._realpath = os.path.realpath(self.path)
117             else:
118                 self._realpath = ''
119         return self._realpath
120 
121     @property
122     def realpath(self):
123         """Get real path from cache before attempting to check for symlinks."""
124         if not hasattr(self, "_store_tuple"):
125             return self._get_realpath()
126         else:
127             return self._store_tuple.realpath
128 
129     @property
130     def store(self):
131         """Get translation store from dictionary cache, populate if store not
132         already cached.
133         """
134         self._update_store_cache()
135         return self._store_tuple.store
136 
137     def _update_store_cache(self):
138         """Add translation store to dictionary cache, replace old cached
139         version if needed.
140         """
141         if self.exists():
142             mod_info = self.getpomtime()
143         else:
144             mod_info = 0
145         if (not hasattr(self, "_store_tuple") or
146             self._store_tuple.mod_info != mod_info):
147             try:
148                 self._store_tuple = self._store_cache[self.path]
149                 if self._store_tuple.mod_info != mod_info:
150                     # if file is modified act as if it doesn't exist in cache
151                     raise KeyError
152             except KeyError:
153                 logging.debug(u"Cache miss for %s", self.path)
154                 from translate.storage import factory
155 
156                 fileclass = self.instance.syncer.file_class
157                 classes = {
158                     str(self.instance.filetype.extension): fileclass,
159                     str(self.instance.filetype.template_extension): fileclass}
160                 store_obj = factory.getobject(self.path,
161                                               ignore=self.field.ignore,
162                                               classes=classes)
163                 self._store_tuple = StoreTuple(store_obj, mod_info,
164                                                self.realpath)
165                 self._store_cache[self.path] = self._store_tuple
166 
167     def _touch_store_cache(self):
168         """Update stored mod_info without reparsing file."""
169         if hasattr(self, "_store_tuple"):
170             mod_info = self.getpomtime()
171             if self._store_tuple.mod_info != mod_info:
172                 self._store_tuple.mod_info = mod_info
173         else:
174             # FIXME: do we really need that?
175             self._update_store_cache()
176 
177     def _delete_store_cache(self):
178         """Remove translation store from cache."""
179         try:
180             del self._store_cache[self.path]
181         except KeyError:
182             pass
183 
184         try:
185             del self._store_tuple
186         except AttributeError:
187             pass
188 
189     def exists(self):
190         return os.path.exists(self.realpath)
191 
192     def savestore(self):
193         """Saves to temporary file then moves over original file. This way we
194         avoid the need for locking.
195         """
196         import shutil
197         from pootle.core.utils import ptempfile as tempfile
198         tmpfile, tmpfilename = tempfile.mkstemp(suffix=self.filename)
199         os.close(tmpfile)
200         self.store.savefile(tmpfilename)
201         shutil.move(tmpfilename, self.realpath)
202         self._touch_store_cache()
203 
204     def save(self, name, content, save=True):
205         # FIXME: implement save to tmp file then move instead of directly
206         # saving
207         super(TranslationStoreFieldFile, self).save(name, content, save)
208         self._delete_store_cache()
209 
210     def delete(self, save=True):
211         self._delete_store_cache()
212         if save:
213             super(TranslationStoreFieldFile, self).delete(save)
214 
215 
216 class TranslationStoreField(FileField):
217     """This is the field class to represent a FileField in a model that
218     represents a translation store.
219     """
220 
221     attr_class = TranslationStoreFieldFile
222 
223     def __init__(self, ignore=None, **kwargs):
224         """ignore: postfix to be stripped from filename when trying to
225         determine file format for parsing, useful for .pending files
226         """
227         self.ignore = ignore
228         super(TranslationStoreField, self).__init__(**kwargs)
229 
230     def deconstruct(self):
231         name, path, args, kwargs = super(TranslationStoreField,
232                                          self).deconstruct()
233         if self.ignore is not None:
234             kwargs['ignore'] = self.ignore
235         return name, path, args, kwargs
236
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pootle/apps/pootle_store/fields.py b/pootle/apps/pootle_store/fields.py
--- a/pootle/apps/pootle_store/fields.py
+++ b/pootle/apps/pootle_store/fields.py
@@ -48,10 +48,30 @@
         return multistring(value, encoding="UTF-8")
 
 
+class CastOnAssignDescriptor(object):
+    """
+    A property descriptor which ensures that `field.to_python()` is called on
+    _every_ assignment to the field.  This used to be provided by the
+    `django.db.models.subclassing.Creator` class, which in turn was used by the
+    deprecated-in-Django-1.10 `SubfieldBase` class, hence the reimplementation
+    here.
+    """
+
+    def __init__(self, field):
+        self.field = field
+
+    def __get__(self, obj, type=None):
+        if obj is None:
+            return self
+        return obj.__dict__[self.field.name]
+
+    def __set__(self, obj, value):
+        obj.__dict__[self.field.name] = self.field.to_python(value)
+
+
 class MultiStringField(models.Field):
     description = \
         "a field imitating translate.misc.multistring used for plurals"
-    __metaclass__ = models.SubfieldBase
 
     def __init__(self, *args, **kwargs):
         super(MultiStringField, self).__init__(*args, **kwargs)
@@ -62,6 +82,9 @@
     def to_python(self, value):
         return to_python(value)
 
+    def from_db_value(self, value, expression, connection, context):
+        return to_python(value)
+
     def get_prep_value(self, value):
         return to_db(value)
 
@@ -72,6 +95,10 @@
         return super(MultiStringField, self).get_prep_lookup(lookup_type,
                                                              value)
 
+    def contribute_to_class(self, cls, name):
+        super(MultiStringField, self).contribute_to_class(cls, name)
+        setattr(cls, name, CastOnAssignDescriptor(self))
+
 
 # # # # # # # # # File # # # # # # # # # # # # # # # #

{"golden_diff": "diff --git a/pootle/apps/pootle_store/fields.py b/pootle/apps/pootle_store/fields.py\n--- a/pootle/apps/pootle_store/fields.py\n+++ b/pootle/apps/pootle_store/fields.py\n@@ -48,10 +48,30 @@\n         return multistring(value, encoding=\"UTF-8\")\n \n \n+class CastOnAssignDescriptor(object):\n+    \"\"\"\n+    A property descriptor which ensures that `field.to_python()` is called on\n+    _every_ assignment to the field.  This used to be provided by the\n+    `django.db.models.subclassing.Creator` class, which in turn was used by the\n+    deprecated-in-Django-1.10 `SubfieldBase` class, hence the reimplementation\n+    here.\n+    \"\"\"\n+\n+    def __init__(self, field):\n+        self.field = field\n+\n+    def __get__(self, obj, type=None):\n+        if obj is None:\n+            return self\n+        return obj.__dict__[self.field.name]\n+\n+    def __set__(self, obj, value):\n+        obj.__dict__[self.field.name] = self.field.to_python(value)\n+\n+\n class MultiStringField(models.Field):\n     description = \\\n         \"a field imitating translate.misc.multistring used for plurals\"\n-    __metaclass__ = models.SubfieldBase\n \n     def __init__(self, *args, **kwargs):\n         super(MultiStringField, self).__init__(*args, **kwargs)\n@@ -62,6 +82,9 @@\n     def to_python(self, value):\n         return to_python(value)\n \n+    def from_db_value(self, value, expression, connection, context):\n+        return to_python(value)\n+\n     def get_prep_value(self, value):\n         return to_db(value)\n \n@@ -72,6 +95,10 @@\n         return super(MultiStringField, self).get_prep_lookup(lookup_type,\n                                                              value)\n \n+    def contribute_to_class(self, cls, name):\n+        super(MultiStringField, self).contribute_to_class(cls, name)\n+        setattr(cls, name, CastOnAssignDescriptor(self))\n+\n \n # # # # # # # # # File # # # # # # # # # # # # # # # #\n", "issue": "Remove SubfieldBase from MultiStringField\nIn django 1.9 SubFieldBase is deprecated, and removed in 1.10\n\nRelated Stackoverflow - http://stackoverflow.com/questions/35166085/how-to-deal-with-subfieldbase-has-been-deprecated-use-field-from-db-value-inst\n\nhttps://docs.djangoproject.com/en/1.9/ref/models/fields/#field-api-reference\n\nafaict we can just safely remove - it seems it just needs to have to/from db methods\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\n\"\"\"Fields required for handling translation files\"\"\"\n\nimport logging\nimport os\n\nfrom translate.misc.multistring import multistring\n\nfrom django.db import models\nfrom django.db.models.fields.files import FieldFile, FileField\n\nfrom pootle.core.utils.multistring import (parse_multistring,\n                                           unparse_multistring)\n\n\n# # # # # # # # # String # # # # # # # # # # # # # # #\n\n\ndef to_db(value):\n    \"\"\"Flatten the given value (string, list of plurals or multistring) into\n    the database string representation.\n    \"\"\"\n    if value is None:\n        return None\n\n    return unparse_multistring(value)\n\n\ndef to_python(value):\n    \"\"\"Reconstruct a multistring from the database string representation.\"\"\"\n    if not value:\n        return multistring(\"\", encoding=\"UTF-8\")\n    elif isinstance(value, multistring):\n        return value\n    elif isinstance(value, basestring):\n        return parse_multistring(value)\n    elif isinstance(value, dict):\n        return multistring([val for __, val in sorted(value.items())],\n                           encoding=\"UTF-8\")\n    else:\n        return multistring(value, encoding=\"UTF-8\")\n\n\nclass MultiStringField(models.Field):\n    description = \\\n        \"a field imitating translate.misc.multistring used for plurals\"\n    __metaclass__ = models.SubfieldBase\n\n    def __init__(self, *args, **kwargs):\n        super(MultiStringField, self).__init__(*args, **kwargs)\n\n    def get_internal_type(self):\n        return \"TextField\"\n\n    def to_python(self, value):\n        return to_python(value)\n\n    def get_prep_value(self, value):\n        return to_db(value)\n\n    def get_prep_lookup(self, lookup_type, value):\n        if (lookup_type in ('exact', 'iexact') or\n            not isinstance(value, basestring)):\n            value = self.get_prep_value(value)\n        return super(MultiStringField, self).get_prep_lookup(lookup_type,\n                                                             value)\n\n\n# # # # # # # # # File # # # # # # # # # # # # # # # #\n\n\nclass StoreTuple(object):\n    \"\"\"Encapsulates toolkit stores in the in memory cache, needed\n    since LRUCachingDict is based on a weakref.WeakValueDictionary\n    which cannot reference normal tuples\n    \"\"\"\n\n    def __init__(self, store, mod_info, realpath):\n        self.store = store\n        self.mod_info = mod_info\n        self.realpath = realpath\n\n\nclass TranslationStoreFieldFile(FieldFile):\n    \"\"\"FieldFile is the file-like object of a FileField, that is found in a\n    TranslationStoreField.\n    \"\"\"\n\n    from translate.misc.lru import LRUCachingDict\n    from django.conf import settings\n\n    _store_cache = LRUCachingDict(settings.PARSE_POOL_SIZE,\n                                  settings.PARSE_POOL_CULL_FREQUENCY)\n\n    def getpomtime(self):\n        file_stat = os.stat(self.realpath)\n        return file_stat.st_mtime, file_stat.st_size\n\n    @property\n    def filename(self):\n        return os.path.basename(self.name)\n\n    def _get_realpath(self):\n        \"\"\"Return realpath resolving symlinks if necessary.\"\"\"\n        if not hasattr(self, \"_realpath\"):\n            # Django's db.models.fields.files.FieldFile raises ValueError if\n            # if the file field has no name - and tests \"if self\" to check\n            if self:\n                self._realpath = os.path.realpath(self.path)\n            else:\n                self._realpath = ''\n        return self._realpath\n\n    @property\n    def realpath(self):\n        \"\"\"Get real path from cache before attempting to check for symlinks.\"\"\"\n        if not hasattr(self, \"_store_tuple\"):\n            return self._get_realpath()\n        else:\n            return self._store_tuple.realpath\n\n    @property\n    def store(self):\n        \"\"\"Get translation store from dictionary cache, populate if store not\n        already cached.\n        \"\"\"\n        self._update_store_cache()\n        return self._store_tuple.store\n\n    def _update_store_cache(self):\n        \"\"\"Add translation store to dictionary cache, replace old cached\n        version if needed.\n        \"\"\"\n        if self.exists():\n            mod_info = self.getpomtime()\n        else:\n            mod_info = 0\n        if (not hasattr(self, \"_store_tuple\") or\n            self._store_tuple.mod_info != mod_info):\n            try:\n                self._store_tuple = self._store_cache[self.path]\n                if self._store_tuple.mod_info != mod_info:\n                    # if file is modified act as if it doesn't exist in cache\n                    raise KeyError\n            except KeyError:\n                logging.debug(u\"Cache miss for %s\", self.path)\n                from translate.storage import factory\n\n                fileclass = self.instance.syncer.file_class\n                classes = {\n                    str(self.instance.filetype.extension): fileclass,\n                    str(self.instance.filetype.template_extension): fileclass}\n                store_obj = factory.getobject(self.path,\n                                              ignore=self.field.ignore,\n                                              classes=classes)\n                self._store_tuple = StoreTuple(store_obj, mod_info,\n                                               self.realpath)\n                self._store_cache[self.path] = self._store_tuple\n\n    def _touch_store_cache(self):\n        \"\"\"Update stored mod_info without reparsing file.\"\"\"\n        if hasattr(self, \"_store_tuple\"):\n            mod_info = self.getpomtime()\n            if self._store_tuple.mod_info != mod_info:\n                self._store_tuple.mod_info = mod_info\n        else:\n            # FIXME: do we really need that?\n            self._update_store_cache()\n\n    def _delete_store_cache(self):\n        \"\"\"Remove translation store from cache.\"\"\"\n        try:\n            del self._store_cache[self.path]\n        except KeyError:\n            pass\n\n        try:\n            del self._store_tuple\n        except AttributeError:\n            pass\n\n    def exists(self):\n        return os.path.exists(self.realpath)\n\n    def savestore(self):\n        \"\"\"Saves to temporary file then moves over original file. This way we\n        avoid the need for locking.\n        \"\"\"\n        import shutil\n        from pootle.core.utils import ptempfile as tempfile\n        tmpfile, tmpfilename = tempfile.mkstemp(suffix=self.filename)\n        os.close(tmpfile)\n        self.store.savefile(tmpfilename)\n        shutil.move(tmpfilename, self.realpath)\n        self._touch_store_cache()\n\n    def save(self, name, content, save=True):\n        # FIXME: implement save to tmp file then move instead of directly\n        # saving\n        super(TranslationStoreFieldFile, self).save(name, content, save)\n        self._delete_store_cache()\n\n    def delete(self, save=True):\n        self._delete_store_cache()\n        if save:\n            super(TranslationStoreFieldFile, self).delete(save)\n\n\nclass TranslationStoreField(FileField):\n    \"\"\"This is the field class to represent a FileField in a model that\n    represents a translation store.\n    \"\"\"\n\n    attr_class = TranslationStoreFieldFile\n\n    def __init__(self, ignore=None, **kwargs):\n        \"\"\"ignore: postfix to be stripped from filename when trying to\n        determine file format for parsing, useful for .pending files\n        \"\"\"\n        self.ignore = ignore\n        super(TranslationStoreField, self).__init__(**kwargs)\n\n    def deconstruct(self):\n        name, path, args, kwargs = super(TranslationStoreField,\n                                         self).deconstruct()\n        if self.ignore is not None:\n            kwargs['ignore'] = self.ignore\n        return name, path, args, kwargs\n", "path": "pootle/apps/pootle_store/fields.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\n\"\"\"Fields required for handling translation files\"\"\"\n\nimport logging\nimport os\n\nfrom translate.misc.multistring import multistring\n\nfrom django.db import models\nfrom django.db.models.fields.files import FieldFile, FileField\n\nfrom pootle.core.utils.multistring import (parse_multistring,\n                                           unparse_multistring)\n\n\n# # # # # # # # # String # # # # # # # # # # # # # # #\n\n\ndef to_db(value):\n    \"\"\"Flatten the given value (string, list of plurals or multistring) into\n    the database string representation.\n    \"\"\"\n    if value is None:\n        return None\n\n    return unparse_multistring(value)\n\n\ndef to_python(value):\n    \"\"\"Reconstruct a multistring from the database string representation.\"\"\"\n    if not value:\n        return multistring(\"\", encoding=\"UTF-8\")\n    elif isinstance(value, multistring):\n        return value\n    elif isinstance(value, basestring):\n        return parse_multistring(value)\n    elif isinstance(value, dict):\n        return multistring([val for __, val in sorted(value.items())],\n                           encoding=\"UTF-8\")\n    else:\n        return multistring(value, encoding=\"UTF-8\")\n\n\nclass CastOnAssignDescriptor(object):\n    \"\"\"\n    A property descriptor which ensures that `field.to_python()` is called on\n    _every_ assignment to the field.  This used to be provided by the\n    `django.db.models.subclassing.Creator` class, which in turn was used by the\n    deprecated-in-Django-1.10 `SubfieldBase` class, hence the reimplementation\n    here.\n    \"\"\"\n\n    def __init__(self, field):\n        self.field = field\n\n    def __get__(self, obj, type=None):\n        if obj is None:\n            return self\n        return obj.__dict__[self.field.name]\n\n    def __set__(self, obj, value):\n        obj.__dict__[self.field.name] = self.field.to_python(value)\n\n\nclass MultiStringField(models.Field):\n    description = \\\n        \"a field imitating translate.misc.multistring used for plurals\"\n\n    def __init__(self, *args, **kwargs):\n        super(MultiStringField, self).__init__(*args, **kwargs)\n\n    def get_internal_type(self):\n        return \"TextField\"\n\n    def to_python(self, value):\n        return to_python(value)\n\n    def from_db_value(self, value, expression, connection, context):\n        return to_python(value)\n\n    def get_prep_value(self, value):\n        return to_db(value)\n\n    def get_prep_lookup(self, lookup_type, value):\n        if (lookup_type in ('exact', 'iexact') or\n            not isinstance(value, basestring)):\n            value = self.get_prep_value(value)\n        return super(MultiStringField, self).get_prep_lookup(lookup_type,\n                                                             value)\n\n    def contribute_to_class(self, cls, name):\n        super(MultiStringField, self).contribute_to_class(cls, name)\n        setattr(cls, name, CastOnAssignDescriptor(self))\n\n\n# # # # # # # # # File # # # # # # # # # # # # # # # #\n\n\nclass StoreTuple(object):\n    \"\"\"Encapsulates toolkit stores in the in memory cache, needed\n    since LRUCachingDict is based on a weakref.WeakValueDictionary\n    which cannot reference normal tuples\n    \"\"\"\n\n    def __init__(self, store, mod_info, realpath):\n        self.store = store\n        self.mod_info = mod_info\n        self.realpath = realpath\n\n\nclass TranslationStoreFieldFile(FieldFile):\n    \"\"\"FieldFile is the file-like object of a FileField, that is found in a\n    TranslationStoreField.\n    \"\"\"\n\n    from translate.misc.lru import LRUCachingDict\n    from django.conf import settings\n\n    _store_cache = LRUCachingDict(settings.PARSE_POOL_SIZE,\n                                  settings.PARSE_POOL_CULL_FREQUENCY)\n\n    def getpomtime(self):\n        file_stat = os.stat(self.realpath)\n        return file_stat.st_mtime, file_stat.st_size\n\n    @property\n    def filename(self):\n        return os.path.basename(self.name)\n\n    def _get_realpath(self):\n        \"\"\"Return realpath resolving symlinks if necessary.\"\"\"\n        if not hasattr(self, \"_realpath\"):\n            # Django's db.models.fields.files.FieldFile raises ValueError if\n            # if the file field has no name - and tests \"if self\" to check\n            if self:\n                self._realpath = os.path.realpath(self.path)\n            else:\n                self._realpath = ''\n        return self._realpath\n\n    @property\n    def realpath(self):\n        \"\"\"Get real path from cache before attempting to check for symlinks.\"\"\"\n        if not hasattr(self, \"_store_tuple\"):\n            return self._get_realpath()\n        else:\n            return self._store_tuple.realpath\n\n    @property\n    def store(self):\n        \"\"\"Get translation store from dictionary cache, populate if store not\n        already cached.\n        \"\"\"\n        self._update_store_cache()\n        return self._store_tuple.store\n\n    def _update_store_cache(self):\n        \"\"\"Add translation store to dictionary cache, replace old cached\n        version if needed.\n        \"\"\"\n        if self.exists():\n            mod_info = self.getpomtime()\n        else:\n            mod_info = 0\n        if (not hasattr(self, \"_store_tuple\") or\n            self._store_tuple.mod_info != mod_info):\n            try:\n                self._store_tuple = self._store_cache[self.path]\n                if self._store_tuple.mod_info != mod_info:\n                    # if file is modified act as if it doesn't exist in cache\n                    raise KeyError\n            except KeyError:\n                logging.debug(u\"Cache miss for %s\", self.path)\n                from translate.storage import factory\n\n                fileclass = self.instance.syncer.file_class\n                classes = {\n                    str(self.instance.filetype.extension): fileclass,\n                    str(self.instance.filetype.template_extension): fileclass}\n                store_obj = factory.getobject(self.path,\n                                              ignore=self.field.ignore,\n                                              classes=classes)\n                self._store_tuple = StoreTuple(store_obj, mod_info,\n                                               self.realpath)\n                self._store_cache[self.path] = self._store_tuple\n\n    def _touch_store_cache(self):\n        \"\"\"Update stored mod_info without reparsing file.\"\"\"\n        if hasattr(self, \"_store_tuple\"):\n            mod_info = self.getpomtime()\n            if self._store_tuple.mod_info != mod_info:\n                self._store_tuple.mod_info = mod_info\n        else:\n            # FIXME: do we really need that?\n            self._update_store_cache()\n\n    def _delete_store_cache(self):\n        \"\"\"Remove translation store from cache.\"\"\"\n        try:\n            del self._store_cache[self.path]\n        except KeyError:\n            pass\n\n        try:\n            del self._store_tuple\n        except AttributeError:\n            pass\n\n    def exists(self):\n        return os.path.exists(self.realpath)\n\n    def savestore(self):\n        \"\"\"Saves to temporary file then moves over original file. This way we\n        avoid the need for locking.\n        \"\"\"\n        import shutil\n        from pootle.core.utils import ptempfile as tempfile\n        tmpfile, tmpfilename = tempfile.mkstemp(suffix=self.filename)\n        os.close(tmpfile)\n        self.store.savefile(tmpfilename)\n        shutil.move(tmpfilename, self.realpath)\n        self._touch_store_cache()\n\n    def save(self, name, content, save=True):\n        # FIXME: implement save to tmp file then move instead of directly\n        # saving\n        super(TranslationStoreFieldFile, self).save(name, content, save)\n        self._delete_store_cache()\n\n    def delete(self, save=True):\n        self._delete_store_cache()\n        if save:\n            super(TranslationStoreFieldFile, self).delete(save)\n\n\nclass TranslationStoreField(FileField):\n    \"\"\"This is the field class to represent a FileField in a model that\n    represents a translation store.\n    \"\"\"\n\n    attr_class = TranslationStoreFieldFile\n\n    def __init__(self, ignore=None, **kwargs):\n        \"\"\"ignore: postfix to be stripped from filename when trying to\n        determine file format for parsing, useful for .pending files\n        \"\"\"\n        self.ignore = ignore\n        super(TranslationStoreField, self).__init__(**kwargs)\n\n    def deconstruct(self):\n        name, path, args, kwargs = super(TranslationStoreField,\n                                         self).deconstruct()\n        if self.ignore is not None:\n            kwargs['ignore'] = self.ignore\n        return name, path, args, kwargs\n", "path": "pootle/apps/pootle_store/fields.py"}]}