[Zope-CMF] Re: [CMF-checkins] SVN: CMF/trunk/CMFDefault/formlib/schema. - added Pdata support

Chris Withers chris at simplistix.co.uk
Thu Feb 15 03:47:25 EST 2007


PData is there for a reason, unravelling it into a string is often not 
the best thing to do.

That said, I can't see much context here, but just thought I'd mention it..

Chris

Yvo Schubbe wrote:
> Log message for revision 72567:
>   - added Pdata support
> 
> Changed:
>   U   CMF/trunk/CMFDefault/formlib/schema.py
>   U   CMF/trunk/CMFDefault/formlib/schema.txt
> 
> -=-
> Modified: CMF/trunk/CMFDefault/formlib/schema.py
> ===================================================================
> --- CMF/trunk/CMFDefault/formlib/schema.py	2007-02-14 03:44:40 UTC (rev 72566)
> +++ CMF/trunk/CMFDefault/formlib/schema.py	2007-02-14 12:19:25 UTC (rev 72567)
> @@ -18,6 +18,7 @@
>  from datetime import datetime
>  
>  from DateTime.DateTime import DateTime
> +from OFS.Image import Pdata
>  from zope.datetime import parseDatetimetz
>  from zope.interface import implements
>  from zope.schema import BytesLine
> @@ -62,14 +63,18 @@
>              attribute = getattr(field, 'default', _marker)
>              if attribute is _marker:
>                  raise AttributeError(self._field.__name__)
> +        elif isinstance(attribute, Pdata):
> +            attribute = str(attribute)
>          elif callable(attribute):
>              attribute = attribute()
>  
> +        if self._field._type == str:
> +            return attribute
>          if isinstance(attribute, str) and inst.encoding:
>              return attribute.decode(inst.encoding)
> -        elif isinstance(attribute, DateTime):
> +        if isinstance(attribute, DateTime):
>              return parseDatetimetz(attribute.ISO8601())
> -        elif isinstance(attribute, (tuple, list)):
> +        if isinstance(attribute, (tuple, list)):
>              if inst.encoding:
>                  attribute = [ isinstance(v, str)
>                                and v.decode(inst.encoding) or v
> 
> Modified: CMF/trunk/CMFDefault/formlib/schema.txt
> ===================================================================
> --- CMF/trunk/CMFDefault/formlib/schema.txt	2007-02-14 03:44:40 UTC (rev 72566)
> +++ CMF/trunk/CMFDefault/formlib/schema.txt	2007-02-14 12:19:25 UTC (rev 72567)
> @@ -9,6 +9,7 @@
>        >>> class FooContent(PropertyManager):
>        ...     _properties=({'id':'foo_prop', 'type': 'string'},)
>        ...     foo_text = ''
> +      ...     foo_bytes = ''
>        ...     foo_datetime = None
>        ...     foo_set = ()
>        ...     foo_list = []
> @@ -19,6 +20,7 @@
>        >>> from zope import schema
>        >>> class IFooContentView(Interface):
>        ...     foo_text = schema.Text()
> +      ...     foo_bytes = schema.Bytes()
>        ...     foo_datetime = schema.Datetime()
>        ...     foo_set = schema.Set()
>        ...     foo_list = schema.List()
> @@ -29,6 +31,7 @@
>        >>> class FooContentAdapter(object):
>        ... 
>        ...     foo_text = ProxyFieldProperty(IFooContentView['foo_text'])
> +      ...     foo_bytes = ProxyFieldProperty(IFooContentView['foo_bytes'])
>        ...     foo_datetime = ProxyFieldProperty(IFooContentView['foo_datetime'])
>        ...     foo_set = ProxyFieldProperty(IFooContentView['foo_set'])
>        ...     foo_list = ProxyFieldProperty(IFooContentView['foo_list'])
> @@ -51,6 +54,18 @@
>        >>> adapter.foo_text == foo_text
>        True
>  
> +    Pdata is read as str::
> +
> +      >>> from OFS.Image import Pdata
> +      >>> foo_bytes = 'foo'
> +      >>> content.foo_bytes = Pdata(foo_bytes)
> +      >>> isinstance(content.foo_bytes, Pdata)
> +      True
> +      >>> isinstance(adapter.foo_bytes, Pdata)
> +      False
> +      >>> adapter.foo_bytes == foo_bytes
> +      True
> +
>      datetime is mapped to DateTime::
>  
>        >>> from datetime import datetime
> 
> _______________________________________________
> CMF-checkins mailing list
> CMF-checkins at zope.org
> http://mail.zope.org/mailman/listinfo/cmf-checkins
> 

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the Zope-CMF mailing list