[Zope3-checkins]
SVN: Zope3/branches/jhauser-filefieldwidget/src/zope/schema/
Added initial Field interfaces and Fields for IMime
Roger Ineichen
roger at projekt01.ch
Thu Jan 20 12:06:31 EST 2005
Log message for revision 28896:
Added initial Field interfaces and Fields for IMime
Changed:
U Zope3/branches/jhauser-filefieldwidget/src/zope/schema/__init__.py
U Zope3/branches/jhauser-filefieldwidget/src/zope/schema/_field.py
U Zope3/branches/jhauser-filefieldwidget/src/zope/schema/interfaces.py
-=-
Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/schema/__init__.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/schema/__init__.py 2005-01-20 17:03:12 UTC (rev 28895)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/schema/__init__.py 2005-01-20 17:06:26 UTC (rev 28896)
@@ -17,7 +17,8 @@
"""
from zope.schema._field import Field, Container, Iterable, Orderable
from zope.schema._field import MinMaxLen, Choice
-from zope.schema._field import Bytes, Mime, ASCII, BytesLine
+from zope.schema._field import Bytes, ASCII, BytesLine
+from zope.schema._field import Mime, MimeData, MimeDataEncoding, MimeType
from zope.schema._field import Text, TextLine, Bool, Int, Float
from zope.schema._field import Tuple, List, Set
from zope.schema._field import Password, Dict, Datetime, Date, SourceText
Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/schema/_field.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/schema/_field.py 2005-01-20 17:03:12 UTC (rev 28895)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/schema/_field.py 2005-01-20 17:06:26 UTC (rev 28896)
@@ -28,7 +28,8 @@
from zope.schema.interfaces import IMinMaxLen, IText, ITextLine
from zope.schema.interfaces import ISourceText
from zope.schema.interfaces import IInterfaceField
-from zope.schema.interfaces import IBytes, IMime, IASCII, IBytesLine
+from zope.schema.interfaces import IBytes, IASCII, IBytesLine
+from zope.schema.interfaces import IMime, IMimeData, IMimeDataEncoding, IMimeType
from zope.schema.interfaces import IBool, IInt, IFloat, IDatetime
from zope.schema.interfaces import IChoice, ITuple, IList, ISet, IDict
from zope.schema.interfaces import IPassword, IObject, IDate
@@ -101,8 +102,29 @@
__doc__ = IMime.__doc__
implements(IMime)
- _type = str # Is this needed for the WrongType exception?
+ # TODO: this is just a copy paste form Object field below
+ def __init__(self, **kw):
+
+ self.schema = IMime
+ super(Mime, self).__init__(**kw)
+
+ def _validate(self, value):
+ super(Mime, self)._validate(value)
+
+ # schema has to be provided by value
+ if not self.schema.providedBy(value):
+ raise SchemaNotProvided
+
+ # check the value against schema
+ errors = _validate_fields(self.schema, value)
+ if errors:
+ raise WrongContainedType(errors)
+
+class MimeData(Field):
+ __doc__ = IMimeData.__doc__
+ implements(IMimeData)
+
def set(self, obj, value):
"""
Do a two phase save, first create an empty file-like object, make it
@@ -154,6 +176,20 @@
return ''
+class MimeDataEncoding(Field):
+ __doc__ = IMimeDataEncoding.__doc__
+ implements(IMimeDataEncoding)
+
+ _type = str
+
+
+class MimeType(Field):
+ __doc__ = IMimeType.__doc__
+ implements(IMimeType)
+
+ _type = str
+
+
class ASCII(Bytes):
__doc__ = IASCII.__doc__
implements(IASCII)
Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/schema/interfaces.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/schema/interfaces.py 2005-01-20 17:03:12 UTC (rev 28895)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/schema/interfaces.py 2005-01-20 17:06:26 UTC (rev 28896)
@@ -274,11 +274,23 @@
The value might be constrained to be with length limits.
"""
-class IMime(IBytes):
+class IMime(IField):
+ u"""Field describing the subwidgets of IMime used in IFile."""
+
+# TODO: perhaps we should use TextLine for prevent inheriting IMinMaxLen
+class IMimeData(IBytes):
u"""Field holding a byte string (in an efficient data structure).
The type of the data is described by it's mime type.
"""
+
+# TODO: perhaps we should use TextLine for prevent inheriting IMinMaxLen
+class IMimeDataEncoding(IBytes):
+ u"""Field containing the encoding used for text-based files."""
+
+# TODO: perhaps we should use TextLine for prevent inheriting IMinMaxLen
+class IMimeType(IBytes):
+ u"""Field containing the mime-type for a file."""
class IASCII(IBytes):
u"""Field containing a 7-bit ASCII string. No characters > DEL
More information about the Zope3-Checkins
mailing list