diff options
| author | Jason Madden <jamadden@gmail.com> | 2018-09-18 11:30:18 -0500 |
|---|---|---|
| committer | Jason Madden <jamadden@gmail.com> | 2018-09-18 11:30:18 -0500 |
| commit | 9631faaf42465d7bb4a7e89a6ffee4f7dd9c98af (patch) | |
| tree | ced594c4a9c89c976833b248ac45aeff4790ad13 /src/zope/schema/_bootstrapinterfaces.py | |
| parent | 7d715edc318479445d6666c872c1cd8d714251c9 (diff) | |
| download | zope-schema-9631faaf42465d7bb4a7e89a6ffee4f7dd9c98af.tar.gz | |
Add IFromBytes
As a counterpoint to IFromUnicode.
This is useful when you know the type of data you're dealing with, and conversions are either trivially non-lossy (or will fail anyway) or are not necessary.
The numeric fields as well as Bytes/Line and URI, DottedName and Id implement this, the last three because they are native string lines that want to accept bytes on Python 2 anyway.
On Python 2, lxml likes to produce byte strings "to save memory" even when parsing unicode and given proper XML encoding information, so this can be very helpful there.
Diffstat (limited to 'src/zope/schema/_bootstrapinterfaces.py')
| -rw-r--r-- | src/zope/schema/_bootstrapinterfaces.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/zope/schema/_bootstrapinterfaces.py b/src/zope/schema/_bootstrapinterfaces.py index 110aa4f..4f0419e 100644 --- a/src/zope/schema/_bootstrapinterfaces.py +++ b/src/zope/schema/_bootstrapinterfaces.py @@ -282,11 +282,23 @@ class IFromUnicode(zope.interface.Interface): values. """ - def fromUnicode(str): + def fromUnicode(value): """Convert a unicode string to a value. """ +class IFromBytes(zope.interface.Interface): + """ + Parse a byte string to a value. + + If the string needs to be decoded, decoding is done using UTF-8. + """ + + def fromBytes(value): + """Convert a byte string to a value. + """ + + class IContextAwareDefaultFactory(zope.interface.Interface): """A default factory that requires a context. |
