Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 #29

Merged
merged 8 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
Changelog
=========

1.2.12 (unreleased)
-------------------
1.3.0 (unreleased)
------------------

Breaking changes:

- *add item here*

New features:

- Python 3 fixes, needs plone.rfc322>=4.0b1.
[jensens]

Bug fixes:

- *add item here*


1.2.12 (unreleased)
-------------------

Bug fixes:

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petschki looks like the merge left some garbage behind - 2x unreleased?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I'd suggest to release my fix in 1.2.12 and update the release date later for 1.3.0 changelog

- purge transform cache when a uid referenced image
Expand Down
35 changes: 28 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Introduction
============

This package provides a zope.schema style field type called RichText which can be used to store a value with a related MIME type.
This package provides a ``zope.schema`` style field type called ``RichText`` which can be used to store a value with a related MIME type.
The value can be transformed to an output MIME type, for example to transform from structured text to HTML.

Basic Usage
Expand All @@ -15,12 +15,12 @@ To use the field, place it in a schema like so::
class ITest(Interface):

bodyText = RichText(
title=u"Body text",
default_mime_type='text/structured',
output_mime_type='text/html',
allowed_mime_types=('text/structured', 'text/plain',),
default=u"Default value"
)
title=u"Body text",
default_mime_type='text/structured',
output_mime_type='text/html',
allowed_mime_types=('text/structured', 'text/plain',),
default=u"Default value"
)

This specifies the default MIME type of text content as well as the default output type,
and a tuple of allowed types.
Expand Down Expand Up @@ -138,3 +138,24 @@ Further Reading

See field.txt for more details about the field's behavior,
and handler.txt for more details about the plone.supermodel handler.

Issue tracker
=============

Please report issues via the `Plone issue tracker`_.

.. _`Plone issue tracker`: https://github.com/plone/plone.namedfile/issues

Support
=======

Questions may be answered via `Plone's support channels`_.

.. _`Plone's support channels`: http://plone.org/support

Contributing
============

Sources are at the `Plone code repository hosted at Github <https://github.com/plone/plone.namedfile>`_.

Contributors please read the document `Process for Plone core's development <http://docs.plone.org/develop/plone-coredev/index.html>`_
178 changes: 0 additions & 178 deletions bootstrap.py

This file was deleted.

7 changes: 0 additions & 7 deletions buildout.cfg

This file was deleted.

4 changes: 2 additions & 2 deletions plone/app/textfield/field.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Or to get the value encoded:
>>> value.encoding
'utf-8'
>>> value.raw_encoded
'Some plain text'
b'Some plain text'

Values are equal as long as they have the same `raw`, `mimeType`, `outputMimeType`,
and `encoding`:
Expand Down Expand Up @@ -153,7 +153,7 @@ default MIME types set on the field.
>>> value.raw
u'A plain text string'
>>> value.raw_encoded
'A plain text string'
b'A plain text string'
>>> value.output
u'A PLAIN TEXT STRING'

Expand Down
5 changes: 3 additions & 2 deletions plone/app/textfield/handler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ First, let's wire up the package.
... </configure>
... """

>>> from StringIO import StringIO
>>> import six
>>> from six import StringIO
>>> from zope.configuration import xmlconfig
>>> xmlconfig.xmlconfig(StringIO(configuration))

Expand All @@ -48,7 +49,7 @@ Then, let's test the field
>>> fieldType = IFieldNameExtractor(field)()
>>> handler = getUtility(IFieldExportImportHandler, name=fieldType)
>>> element = handler.write(field, u'dummy', fieldType) #doctest: +ELLIPSIS
>>> print prettyXML(element)
>>> print(prettyXML(element))
<field name="dummy" type="plone.app.textfield.RichText">
<allowed_mime_types>
<element>text/plain</element>
Expand Down
26 changes: 14 additions & 12 deletions plone/app/textfield/marshaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from zope.component import adapter
from zope.interface import Interface

import six


@adapter(Interface, IRichText)
class RichTextFieldMarshaler(BaseFieldMarshaler):
Expand All @@ -19,21 +21,21 @@ def encode(self, value, charset='utf-8', primary=False):
return value.raw.encode(charset)

def decode(
self,
value,
message=None,
charset='utf-8',
contentType=None,
primary=False):
try:
unicode_value = value.decode(charset)
except UnicodeEncodeError:
unicode_value = value # was already unicode
self,
value,
message=None,
charset='utf-8',
contentType=None,
primary=False
):

if isinstance(value, six.binary_type):
value = value.decode(charset)
return RichTextValue(
raw=unicode_value,
raw=value,
mimeType=contentType or self.field.default_mime_type,
outputMimeType=self.field.output_mime_type,
encoding=charset
encoding=charset,
)

def getContentType(self):
Expand Down