Skip to content

Commit

Permalink
- PEP-8
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed May 16, 2018
1 parent 67eff8c commit 1a55abd
Show file tree
Hide file tree
Showing 33 changed files with 767 additions and 783 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ New features:

- Finished compatibility with Python 3.5 and 3.6

- Made the code PEP-8 compliant

1.10.0 (2017-12-07)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion Products/GenericSetup/OFSP/exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _importNode(self, node):
def _exportBody(self):
"""Export the object as a file body.
"""
if not self.context.meta_type in ('Folder', 'Folder (Ordered)'):
if self.context.meta_type not in ('Folder', 'Folder (Ordered)'):
return None

return XMLAdapterBase._exportBody(self)
Expand Down
6 changes: 2 additions & 4 deletions Products/GenericSetup/PluginIndexes/exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,13 @@ def _importNode(self, node):
"""Import the object from the DOM node.
"""
_before = {'map': self.context._properties,
'items': self.context.propertyItems(),
}
'items': self.context.propertyItems()}
if self.environ.shouldPurge():
self._purgeProperties()

self._initProperties(node)
_after = {'map': self.context._properties,
'items': self.context.propertyItems(),
}
'items': self.context.propertyItems()}
if _before != _after:
self.context.clear()

Expand Down
60 changes: 37 additions & 23 deletions Products/GenericSetup/PluginIndexes/tests/test_exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,112 +224,126 @@ def test_FieldIndex(self):
from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.PluginIndexes.exportimport \
import PluggableIndexNodeAdapter
import PluggableIndexNodeAdapter
environ = DummySetupEnviron()

def _no_clear(*a):
raise AssertionError("Don't clear me!")

index = FieldIndex('foo_field')
index.indexed_attrs = ['bar']
index.clear = _no_clear
index.clear = _no_clear
adapted = PluggableIndexNodeAdapter(index, environ)
adapted.node = parseString(_FIELD_XML).documentElement # no raise
adapted.node = parseString(_FIELD_XML).documentElement # no raise

def test_KeywordIndex(self):
from xml.dom.minidom import parseString
from Products.PluginIndexes.KeywordIndex.KeywordIndex \
import KeywordIndex
import KeywordIndex
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.PluginIndexes.exportimport \
import PluggableIndexNodeAdapter
import PluggableIndexNodeAdapter
environ = DummySetupEnviron()

def _no_clear(*a):
raise AssertionError("Don't clear me!")

index = KeywordIndex('foo_keyword')
index.indexed_attrs = ['bar']
index.clear = _no_clear
index.clear = _no_clear
adapted = PluggableIndexNodeAdapter(index, environ)
adapted.node = parseString(_KEYWORD_XML).documentElement # no raise
adapted.node = parseString(_KEYWORD_XML).documentElement # no raise

def test_OddballIndex(self):
# Some indexes, e.g. Plone's 'GopipIndex', use ths adapter but don't
# have 'indexed_attrs'.
from xml.dom.minidom import parseString
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.PluginIndexes.exportimport \
import PluggableIndexNodeAdapter
import PluggableIndexNodeAdapter

class Oddball(object):
def clear(*a):
raise AssertionError("Don't clear me!")

index = Oddball()
environ = DummySetupEnviron()
adapted = PluggableIndexNodeAdapter(index, environ)
adapted.node = parseString(_ODDBALL_XML).documentElement # no raise
adapted.node = parseString(_ODDBALL_XML).documentElement # no raise

def test_DateIndex(self):
from xml.dom.minidom import parseString
from Products.PluginIndexes.DateIndex.DateIndex import DateIndex
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.PluginIndexes.exportimport \
import DateIndexNodeAdapter
import DateIndexNodeAdapter
environ = DummySetupEnviron()

def _no_clear(*a):
raise AssertionError("Don't clear me!")

index = DateIndex('foo_date')
index._setPropValue('index_naive_time_as_local', True)
index._setPropValue('precision', 0)
index.clear = _no_clear
index.clear = _no_clear
adapted = DateIndexNodeAdapter(index, environ)
adapted.node = parseString(_DATE_XML).documentElement # no raise
adapted.node = parseString(_DATE_XML).documentElement # no raise

def test_DateRangeIndex(self):
from xml.dom.minidom import parseString
from Products.PluginIndexes.DateRangeIndex.DateRangeIndex \
import DateRangeIndex
import DateRangeIndex
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.PluginIndexes.exportimport \
import DateRangeIndexNodeAdapter
import DateRangeIndexNodeAdapter
environ = DummySetupEnviron()

def _no_clear(*a):
raise AssertionError("Don't clear me!")

index = DateRangeIndex('foo_daterange')
index._since_field = 'bar'
index._until_field = 'baz'
index.clear = _no_clear
index.clear = _no_clear
adapted = DateRangeIndexNodeAdapter(index, environ)
adapted.node = parseString(_DATERANGE_XML).documentElement # no raise
adapted.node = parseString(_DATERANGE_XML).documentElement # no raise

def test_FilteredSet(self):
from xml.dom.minidom import parseString
from Products.PluginIndexes.TopicIndex.FilteredSet \
import PythonFilteredSet
import PythonFilteredSet
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.PluginIndexes.exportimport \
import FilteredSetNodeAdapter
import FilteredSetNodeAdapter
environ = DummySetupEnviron()

def _no_clear(*a):
raise AssertionError("Don't clear me!")

index = PythonFilteredSet('bar', 'True')
index.clear = _no_clear
index.clear = _no_clear
adapted = FilteredSetNodeAdapter(index, environ)
adapted.node = parseString(_SET_XML).documentElement # no raise
adapted.node = parseString(_SET_XML).documentElement # no raise

def test_TopicIndex(self):
from xml.dom.minidom import parseString
from Products.PluginIndexes.TopicIndex.TopicIndex import TopicIndex
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.PluginIndexes.exportimport \
import TopicIndexNodeAdapter
import TopicIndexNodeAdapter
environ = DummySetupEnviron()

def _no_clear(*a):
raise AssertionError("Don't clear me!")

index = TopicIndex('topics')
index.addFilteredSet('bar', 'PythonFilteredSet', 'True')
index.addFilteredSet('baz', 'PythonFilteredSet', 'False')
bar = index.filteredSets['bar']
baz = index.filteredSets['baz']
bar.clear = baz.clear = _no_clear
bar.clear = baz.clear = _no_clear
adapted = TopicIndexNodeAdapter(index, environ)
adapted.node = parseString(_SET_XML).documentElement # no raise
adapted.node = parseString(_SET_XML).documentElement # no raise


def test_suite():
Expand Down
21 changes: 12 additions & 9 deletions Products/GenericSetup/ZCTextIndex/tests/test_exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def setUp(self):
catalog.foo_plexicon = PLexicon('foo_plexicon')
extra = _extra()
extra.lexicon_id = 'foo_plexicon'
extra.index_type='Okapi BM25 Rank'
extra.index_type = 'Okapi BM25 Rank'
self._obj = ZCTextIndex('foo_zctext', extra=extra,
caller=catalog).__of__(catalog)
self._XML = _ZCTEXT_XML
Expand All @@ -107,7 +107,7 @@ def test_ZCLexicon(self):
from Products.GenericSetup.testing import DummySetupEnviron
from Products.ZCTextIndex.PipelineFactory import element_factory
from Products.GenericSetup.ZCTextIndex.exportimport \
import ZCLexiconNodeAdapter
import ZCLexiconNodeAdapter

_XML = b"""\
<object name="foo_plexicon" meta_type="ZCTextIndex Lexicon">
Expand All @@ -117,16 +117,17 @@ def test_ZCLexicon(self):
"""
environ = DummySetupEnviron()
_before = object(), object(), object()

class DummyLexicon(object):
_wids, _words, length = _before

lex = DummyLexicon()
lex._pipeline = foo, bar = object(), object()
adapted = ZCLexiconNodeAdapter(lex, environ)
element_factory._groups['gs'] = {'foo': lambda: foo,
'bar': lambda: bar,
}
'bar': lambda: bar}
try:
adapted.node = parseString(_XML).documentElement # no raise
adapted.node = parseString(_XML).documentElement # no raise
finally:
del element_factory._groups['gs']
self.assertTrue(lex._wids is _before[0])
Expand All @@ -139,7 +140,7 @@ def test_ZCTextIndex(self):
from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.ZCTextIndex.exportimport \
import ZCTextIndexNodeAdapter
import ZCTextIndexNodeAdapter
_XML = b"""\
<index name="foo_zctext" meta_type="ZCTextIndex">
<indexed_attr value="bar"/>
Expand All @@ -148,18 +149,20 @@ def test_ZCTextIndex(self):
</index>
"""
environ = DummySetupEnviron()

def _no_clear(*a):
raise AssertionError("Don't clear me!")

catalog = DummyCatalog()
catalog.foo_plexicon = PLexicon('foo_plexicon')
extra = _extra()
extra.lexicon_id = 'foo_plexicon'
extra.index_type='Okapi BM25 Rank'
extra.index_type = 'Okapi BM25 Rank'
index = ZCTextIndex('foo_field', extra=extra, field_name='bar',
caller=catalog).__of__(catalog)
index.clear = _no_clear
index.clear = _no_clear
adapted = ZCTextIndexNodeAdapter(index, environ)
adapted.node = parseString(_XML).documentElement # no raise
adapted.node = parseString(_XML).documentElement # no raise


def test_suite():
Expand Down
2 changes: 0 additions & 2 deletions Products/GenericSetup/ZCatalog/exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
"""ZCatalog export / import support.
"""

from functools import cmp_to_key

from zope.component import adapts
from zope.component import queryMultiAdapter

Expand Down
10 changes: 5 additions & 5 deletions Products/GenericSetup/ZCatalog/tests/test_exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

import unittest
from Testing import ZopeTestCase
ZopeTestCase.installProduct('ZCTextIndex', 1)
ZopeTestCase.installProduct('PluginIndexes', 1)

from zope.component import getMultiAdapter

from Products.GenericSetup.interfaces import IBody
from Products.GenericSetup.testing import BodyAdapterTestCase
from Products.GenericSetup.testing import DummySetupEnviron
from Products.GenericSetup.testing import ExportImportZCMLLayer

ZopeTestCase.installProduct('ZCTextIndex', 1)
ZopeTestCase.installProduct('PluginIndexes', 1)


class _extra:

Expand Down Expand Up @@ -191,8 +191,8 @@ def test_body_get_special(self):
self._populate_special(self._obj)
context = DummySetupEnviron()
adapted = getMultiAdapter((self._obj, context), IBody)
self.assertEqual(adapted.body,
_CATALOG_BODY % (_LEXICON_XML, _TEXT_XML, _COLUMN_XML))
expected = _CATALOG_BODY % (_LEXICON_XML, _TEXT_XML, _COLUMN_XML)
self.assertEqual(adapted.body, expected)

def test_body_set_update(self):
# Assert that the catalog ends up the way we expect it to.
Expand Down
3 changes: 1 addition & 2 deletions Products/GenericSetup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ def initialize(context):
constructors=(tool.addSetupTool,),
permissions=(ManagePortal,),
interfaces=None,
icon='www/tool.png',
)
icon='www/tool.png')
20 changes: 10 additions & 10 deletions Products/GenericSetup/browser/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
class ImportStepsView(BrowserView):
def __init__(self, context, request):
BrowserView.__init__(self, context, request)
self.global_registry=_import_step_registry
self.tool_registry=context.getImportStepRegistry()
self.global_registry = _import_step_registry
self.tool_registry = context.getImportStepRegistry()

def invalidSteps(self):
steps=self.tool_registry.listStepMetadata()
steps=[step for step in steps if step['invalid']]
steps = self.tool_registry.listStepMetadata()
steps = [step for step in steps if step['invalid']]
return steps

def doubleSteps(self):
steps=set(self.tool_registry.listSteps())
globals=set(self.global_registry.listSteps())
steps=steps.intersection(globals)
steps=[self.tool_registry.getStepMetadata(step) for step in steps]
steps = set(self.tool_registry.listSteps())
globals = set(self.global_registry.listSteps())
steps = steps.intersection(globals)
steps = [self.tool_registry.getStepMetadata(step) for step in steps]
steps.sort()
return steps


class ExportStepsView(ImportStepsView):
def __init__(self, context, request):
BrowserView.__init__(self, context, request)
self.global_registry=_export_step_registry
self.tool_registry=context.getExportStepRegistry()
self.global_registry = _export_step_registry
self.tool_registry = context.getExportStepRegistry()

0 comments on commit 1a55abd

Please sign in to comment.