Skip to content

Commit

Permalink
Patch zope.interface to remove docstrings and avoid publishing.
Browse files Browse the repository at this point in the history
From Products.PloneHotfix20161129.
  • Loading branch information
mauritsvanrees committed Dec 5, 2016
1 parent 117f676 commit e696d96
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ https://zope.readthedocs.io/en/2.13/CHANGES.html
Bugs Fixed
++++++++++

- Patch zope.interface to remove docstrings and avoid publishing.
From Products.PloneHotfix20161129.

Features Added
++++++++++++++
Expand Down
2 changes: 2 additions & 0 deletions src/Zope2/App/patches/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Import all patches.
import publishing # noqa
57 changes: 57 additions & 0 deletions src/Zope2/App/patches/publishing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
from zope.interface import Attribute
from zope.interface import Interface
from zope.interface.interface import Element
from zope.interface.interface import Method


def delete_method_docstring(klass, method_name):
# Delete the docstring from the class method.
# Objects must have a docstring to be published.
# So this avoids them getting published.
method = getattr(klass, method_name, None)
if (method is not None and hasattr(method, 'im_func') and
hasattr(method.im_func, '__doc__')):
del method.im_func.__doc__


element_methods = [
'getDoc',
'getName',
'getTaggedValue',
'getTaggedValueTags',
'queryTaggedValue',
'setTaggedValue',
]
interface_methods = [
'changed',
'dependents',
'direct',
'extends',
'get',
'getBases',
'getDescriptionFor',
'implementedBy',
'interfaces',
'isEqualOrExtendedBy',
'isOrExtends',
'names',
'namesAndDescriptions',
'providedBy',
'queryDescriptionFor',
'subscribe',
'unsubscribe',
'validateInvariants',
'weakref',
]

for klass in [Element, Attribute, Interface, Method]:
try:
del klass.__doc__
except:
pass
for method_name in element_methods:
delete_method_docstring(klass, method_name)

for method_name in interface_methods:
delete_method_docstring(Interface, method_name)
1 change: 1 addition & 0 deletions src/Zope2/App/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from zope.processlifetime import DatabaseOpenedWithRoot

from App.config import getConfiguration
from Zope2.App import patches # noqa
import App.ZApplication
import OFS.Application
import Zope2
Expand Down

0 comments on commit e696d96

Please sign in to comment.