Commit 90dc2b7d authored by Ivan Tyagov's avatar Ivan Tyagov

Define legacy ITextConvertable interface and proper implementation with...

Define legacy ITextConvertable interface and proper implementation with deprecation warning. Add method security definition and update doc strings.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37046 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9115cec4
......@@ -29,7 +29,23 @@
from zope.interface import Interface
class ITextConvertable(Interface):
class ITextConvertableLegacy(Interface):
"""
Legacy ITextConvertable interface specification
Documents which implement the ITextConvertable interface
can be converted to plain text.
"""
def asTextContent(**kw):
"""
Converts the current document to plain text
kw -- optional parameters which can be passed to the
conversion engine
"""
class ITextConvertable(ITextConvertableLegacy):
"""
Text Convertable interface specification
......
......@@ -27,14 +27,35 @@
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions
from warnings import warn
class TextConvertableMixin:
"""
This class provides a generic implementation of ITextConvertable.
"""
# Declarative security
security = ClassSecurityInfo()
security.declareProtected(Permissions.AccessContentsInformation,
'asText')
def asText(self, **kw):
"""
Converts the current document to plain text
"""
kw.pop('format', None)
mime, data = self.convert(format='txt', **kw)
return str(data)
security.declareProtected(Permissions.AccessContentsInformation,
'asTextContent')
def asTextContent(self, **kw):
"""
Converts the current document to plain text
Backward (legacy) compatibility
"""
warn("asTextContent() function is deprecated. Use asText() instead.", \
DeprecationWarning, stacklevel=2)
return self.asText(**kw)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment