summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/zope/schema/_bootstrapfields.py4
-rw-r--r--src/zope/schema/tests/test__bootstrapfields.py18
2 files changed, 21 insertions, 1 deletions
diff --git a/src/zope/schema/_bootstrapfields.py b/src/zope/schema/_bootstrapfields.py
index 7152b82..9a64a2d 100644
--- a/src/zope/schema/_bootstrapfields.py
+++ b/src/zope/schema/_bootstrapfields.py
@@ -505,9 +505,11 @@ class MinMaxLen(object):
class Text(MinMaxLen, Field):
"""A field containing text used for human discourse."""
_type = text_type
+ unicode_normalization = 'NFC'
def __init__(self, *args, **kw):
- self.unicode_normalization = kw.pop('unicode_normalization', 'NFC')
+ self.unicode_normalization = kw.pop(
+ 'unicode_normalization', self.unicode_normalization)
super(Text, self).__init__(*args, **kw)
def fromUnicode(self, value):
diff --git a/src/zope/schema/tests/test__bootstrapfields.py b/src/zope/schema/tests/test__bootstrapfields.py
index 34bdfc8..027944c 100644
--- a/src/zope/schema/tests/test__bootstrapfields.py
+++ b/src/zope/schema/tests/test__bootstrapfields.py
@@ -967,6 +967,7 @@ class TextTests(EqualityTestsMixin,
def test_normalization(self):
deadbeef = unicodedata.normalize('NFD', b'\xc3\x84\xc3\x96\xc3\x9c'.decode('utf-8'))
txt = self._makeOne()
+ self.assertEqual(txt.unicode_normalization, 'NFC')
self.assertEqual(
[unicodedata.name(c) for c in txt.fromUnicode(deadbeef)],
[
@@ -976,6 +977,7 @@ class TextTests(EqualityTestsMixin,
]
)
txt = self._makeOne(unicode_normalization=None)
+ self.assertEqual(txt.unicode_normalization, None)
self.assertEqual(
[unicodedata.name(c) for c in txt.fromUnicode(deadbeef)],
[
@@ -988,6 +990,22 @@ class TextTests(EqualityTestsMixin,
]
)
+ def test_normalization_after_pickle(self):
+ # test an edge case where `Text` is persisted
+ # see https://github.com/zopefoundation/zope.schema/issues/90
+ import pickle
+ orig_makeOne = self._makeOne
+ def makeOne(**kwargs):
+ result = orig_makeOne(**kwargs)
+ if not kwargs:
+ # We should have no state to preserve
+ result.__dict__.clear()
+
+ result = pickle.loads(pickle.dumps(result))
+ return result
+
+ self._makeOne = makeOne
+ self.test_normalization()
class TextLineTests(EqualityTestsMixin,