Skip to content

Commit

Permalink
- full PEP-8 compliance with the exception of import sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Mar 24, 2019
1 parent 2da2c2c commit b4495eb
Show file tree
Hide file tree
Showing 100 changed files with 558 additions and 544 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -18,6 +18,10 @@ Features
which are deprecated in Python 3.8.
(`#476 <https://github.com/zopefoundation/Zope/pull/476>`_)

Other changes
+++++++++++++
- full PEP-8 compliance with the exception of import sorting


4.0b10 (2019-03-08)
-------------------
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Expand Up @@ -34,9 +34,8 @@ ignore =
# We should remove the following ignored check codes:
T000,
C103,

no-accept-encodings = True

doctests = True
exclude =
bootstrap.py

Expand Down
1 change: 1 addition & 0 deletions src/App/ApplicationManager.py
Expand Up @@ -78,6 +78,7 @@ def __bobo_traverse__(self, request, name):
return self[name]
return getattr(self, name)


InitializeClass(DatabaseChooser)


Expand Down
9 changes: 5 additions & 4 deletions src/App/Extensions.py
Expand Up @@ -33,14 +33,14 @@ def __init__(self, f, im=0):
def __eq__(self, other):
if not isinstance(other, FuncCode):
return False
return ((self.co_argcount, self.co_varnames) ==
(other.co_argcount, other.co_varnames))
return (self.co_argcount, self.co_varnames) == \
(other.co_argcount, other.co_varnames)

def __lt__(self, other):
if not isinstance(other, FuncCode):
return False
return ((self.co_argcount, self.co_varnames) <
(other.co_argcount, other.co_varnames))
return (self.co_argcount, self.co_varnames) < \
(other.co_argcount, other.co_varnames)


def _getPath(home, prefix, name, suffixes):
Expand Down Expand Up @@ -151,6 +151,7 @@ def getPath(prefix, name, checkProduct=1, suffixes=('',), cfg=None):

_modules = {} # cache


def getObject(module, name, reload=0):
# The use of _modules here is not thread safe, however, there is
# no real harm in a race condition here. If two threads
Expand Down
10 changes: 5 additions & 5 deletions src/App/FactoryDispatcher.py
Expand Up @@ -24,7 +24,6 @@
from Acquisition import aq_base
from Acquisition import Implicit
from ExtensionClass import Base
from zExceptions import Redirect

from OFS.metaconfigure import get_registered_packages

Expand Down Expand Up @@ -61,11 +60,12 @@ class Product(Base):
def __init__(self, id):
self.id = id

security.declarePublic('Destination')
@security.public
def Destination(self):
"Return the destination for factory output"
return self


InitializeClass(Product)


Expand Down Expand Up @@ -117,15 +117,15 @@ def __init__(self, product, dest, REQUEST=None):
v = v[:v.rfind('/')]
self._u = v[:v.rfind('/')]

security.declarePublic('Destination')
@security.public
def Destination(self):
"Return the destination for factory output"
return self.__dict__['_d'] # we don't want to wrap the result!

security.declarePublic('this')
security.declarePublic('this') # NOQA: D001
this = Destination

security.declarePublic('DestinationURL')
@security.public
def DestinationURL(self):
"Return the URL for the destination for factory output"
url = getattr(self, '_u', None)
Expand Down
3 changes: 2 additions & 1 deletion src/App/ImageFile.py
Expand Up @@ -120,7 +120,7 @@ def index_html(self, REQUEST, RESPONSE):
return filestream_iterator(self.path, mode='rb')

if bbb.HAS_ZSERVER:
security.declarePublic('HEAD')
@security.public
def HEAD(self, REQUEST, RESPONSE):
""" """
RESPONSE.setHeader('Content-Type', self.content_type)
Expand All @@ -134,4 +134,5 @@ def __len__(self):
def __str__(self):
return '<img src="%s" alt="" />' % self.__name__


InitializeClass(ImageFile)
28 changes: 16 additions & 12 deletions src/App/Management.py
Expand Up @@ -23,7 +23,6 @@
from App.special_dtml import DTMLFile
from ExtensionClass import Base
from six.moves.urllib.parse import quote, unquote
from zExceptions import Redirect
from zope.interface import implementer
import itertools
import six
Expand All @@ -40,12 +39,12 @@ class Tabs(Base):

security = ClassSecurityInfo()

security.declarePublic('manage_tabs')
security.declarePublic('manage_tabs') # NOQA: D001
manage_tabs = DTMLFile('dtml/manage_tabs', globals())

manage_options = ()

security.declarePublic('filtered_manage_options')
@security.public
def filtered_manage_options(self, REQUEST=None):
result = []
try:
Expand Down Expand Up @@ -133,6 +132,7 @@ def tabs_path_info(self, script, path):
out.append(last)
return '/'.join(out)


InitializeClass(Tabs)


Expand All @@ -142,16 +142,18 @@ class Navigation(Base):

security = ClassSecurityInfo()

security.declareProtected(view_management_screens, 'manage')
security.declareProtected(view_management_screens, 'manage') # NOQA: D001
manage = DTMLFile('dtml/manage', globals())

security.declareProtected(view_management_screens, 'manage_menu')
security.declareProtected(view_management_screens, # NOQA: D001
'manage_menu')
manage_menu = DTMLFile('dtml/menu', globals())

security.declareProtected(view_management_screens, 'manage_page_footer')
security.declareProtected(view_management_screens, # NOQA: D001
'manage_page_footer')
manage_page_footer = DTMLFile('dtml/manage_page_footer', globals())

security.declarePublic('manage_form_title')
security.declarePublic('manage_form_title') # NOQA: D001
manage_form_title = DTMLFile('dtml/manage_form_title', globals(),
form_title='Add Form',
help_product=None,
Expand All @@ -160,7 +162,8 @@ class Navigation(Base):
varnames=('form_title', 'help_product', 'help_topic'))

_manage_page_header = DTMLFile('dtml/manage_page_header', globals())
security.declareProtected(view_management_screens, 'manage_page_header')

@security.protected(view_management_screens)
def manage_page_header(self, *args, **kw):
"""manage_page_header."""
kw['css_urls'] = itertools.chain(
Expand All @@ -171,13 +174,14 @@ def manage_page_header(self, *args, **kw):
self._get_zmi_additionals('zmi_additional_js_paths'))
return self._manage_page_header(*args, **kw)

security.declareProtected(view_management_screens, 'manage_navbar')
security.declareProtected(view_management_screens, # NOQA: D001
'manage_navbar')
manage_navbar = DTMLFile('dtml/manage_navbar', globals())

security.declarePublic('zope_copyright')
security.declarePublic('zope_copyright') # NOQA: D001
zope_copyright = DTMLFile('dtml/copyright', globals())

security.declarePublic('manage_zmi_logout')
@security.public
def manage_zmi_logout(self, REQUEST, RESPONSE):
"""Logout current user"""
p = getattr(REQUEST, '_logout_path', None)
Expand All @@ -204,7 +208,7 @@ def _get_zmi_additionals(self, attrib):
additionals = (additionals, )
return additionals


# Navigation doesn't have an inherited __class_init__ so doesn't get
# initialized automatically.

InitializeClass(Navigation)
6 changes: 3 additions & 3 deletions src/App/Undo.py
Expand Up @@ -34,7 +34,7 @@ class UndoSupport(Tabs, Implicit):
{'label': 'Undo', 'action': 'manage_UndoForm'},
)

security.declareProtected(undo_changes, 'manage_UndoForm')
security.declareProtected(undo_changes, 'manage_UndoForm') # NOQA: D001
manage_UndoForm = DTMLFile(
'dtml/undo',
globals(),
Expand All @@ -61,7 +61,7 @@ def _get_request_var_or_attr(self, name, default):
v = default
return v

security.declareProtected(undo_changes, 'undoable_transactions')
@security.protected(undo_changes)
def undoable_transactions(self, first_transaction=None,
last_transaction=None,
PrincipiaUndoBatchSize=None):
Expand Down Expand Up @@ -98,7 +98,7 @@ def undoable_transactions(self, first_transaction=None,

return r

security.declareProtected(undo_changes, 'manage_undo_transactions')
@security.protected(undo_changes)
def manage_undo_transactions(self, transaction_info=(), REQUEST=None):
"""
"""
Expand Down
2 changes: 1 addition & 1 deletion src/App/special_dtml.py
Expand Up @@ -12,7 +12,6 @@
##############################################################################

import os
import sys
from logging import getLogger

import DocumentTemplate
Expand Down Expand Up @@ -93,6 +92,7 @@ def __call__(self, *args, **kw):
return HTMLFile.inheritedAttribute('__call__')(
*(self,) + args[1:], **kw)


defaultBindings = {'name_context': 'context',
'name_container': 'container',
'name_m_self': 'self',
Expand Down
4 changes: 2 additions & 2 deletions src/App/tests/test_getZopeVersion.py
Expand Up @@ -18,12 +18,12 @@
from pkg_resources import get_distribution
from App.version_txt import getZopeVersion


class Test(unittest.TestCase):
def test_major(self):
self.assertEqual(
getZopeVersion().major,
int(get_distribution("Zope").version.split(".")[0])
)
int(get_distribution("Zope").version.split(".")[0]))

def test_types(self):
zv = getZopeVersion()
Expand Down
9 changes: 3 additions & 6 deletions src/App/version_txt.py
Expand Up @@ -21,8 +21,7 @@

ZopeVersion = collections.namedtuple(
"ZopeVersion",
["major", "minor", "micro", "status", "release"]
)
["major", "minor", "micro", "status", "release"])


def _prep_version_data():
Expand All @@ -42,16 +41,14 @@ def _prep_version_data():
int(version_dict.get('minor') or -1),
int(version_dict.get('micro') or -1),
version_dict.get('status') or '',
int(version_dict.get('release') or -1),
)


int(version_dict.get('release') or -1))


def version_txt():
_prep_version_data()
return '(%s)' % _version_string


def getZopeVersion():
"""return information about the Zope version as a named tuple.
Expand Down
6 changes: 3 additions & 3 deletions src/OFS/Application.py
Expand Up @@ -339,9 +339,9 @@ def _is_package(product_dir, product_name):
return False

init_py = os.path.join(package_dir, '__init__.py')
if (not os.path.exists(init_py) and
not os.path.exists(init_py + 'c') and
not os.path.exists(init_py + 'o')):
if not os.path.exists(init_py) and \
not os.path.exists(init_py + 'c') and \
not os.path.exists(init_py + 'o'):
return False
return True

Expand Down
4 changes: 2 additions & 2 deletions src/OFS/Cache.py
Expand Up @@ -58,8 +58,8 @@ def filterCacheManagers(orig, container, name, value, extra):
It causes objects to be found only if they are
in the list of cache managers.
"""
if (hasattr(aq_base(container), ZCM_MANAGERS) and
name in getattr(container, ZCM_MANAGERS)):
if hasattr(aq_base(container), ZCM_MANAGERS) and \
name in getattr(container, ZCM_MANAGERS):
return 1
return 0

Expand Down
14 changes: 4 additions & 10 deletions src/OFS/DTMLDocument.py
Expand Up @@ -24,11 +24,7 @@
from OFS.DTMLMethod import safe_file_data
from OFS.PropertyManager import PropertyManager
from six import binary_type
from six import PY2
from six import PY3
from six import text_type
from six.moves.urllib.parse import quote
from zExceptions import ResourceLockedError
from zExceptions.TracebackSupplement import PathTracebackSupplement
from zope.contenttype import guess_content_type

Expand All @@ -45,15 +41,13 @@ class DTMLDocument(PropertyManager, DTMLMethod):
zmi_icon = 'far fa-file-alt'
_locked_error_text = 'This document has been locked.'

manage_options = (
DTMLMethod.manage_options[:2] +
PropertyManager.manage_options +
DTMLMethod.manage_options[2:]
)
manage_options = (DTMLMethod.manage_options[:2]
+ PropertyManager.manage_options
+ DTMLMethod.manage_options[2:])

# Replace change_dtml_methods by change_dtml_documents
__ac_permissions__ = tuple([
(perms[0] == change_dtml_methods) and
(perms[0] == change_dtml_methods) and # NOQA: W504
(change_dtml_documents, perms[1]) or perms
for perms in DTMLMethod.__ac_permissions__])

Expand Down
17 changes: 8 additions & 9 deletions src/OFS/DTMLMethod.py
Expand Up @@ -93,8 +93,7 @@ class DTMLMethod(
'label': 'Proxy',
'action': 'manage_proxyForm',
},
) +
RoleManager.manage_options
) + RoleManager.manage_options
+ Item_w__name__.manage_options
+ Cacheable.manage_options
)
Expand All @@ -119,19 +118,19 @@ def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
if not self._cache_namespace_keys:
data = self.ZCacheable_get(default=_marker)
if data is not _marker:
if (IStreamIterator.isImplementedBy(data) and
RESPONSE is not None):
if IStreamIterator.isImplementedBy(data) and \
RESPONSE is not None:
# This is a stream iterator and we need to set some
# headers now before giving it to medusa
headers_get = RESPONSE.headers.get

if headers_get('content-length', None) is None:
RESPONSE.setHeader('content-length', len(data))

if (headers_get('content-type', None) is None and
headers_get('Content-type', None) is None):
ct = (self.__dict__.get('content_type') or
self.default_content_type)
if headers_get('content-type', None) is None and \
headers_get('Content-type', None) is None:
ct = (self.__dict__.get('content_type')
or self.default_content_type)
RESPONSE.setHeader('content-type', ct)

# Return cached results.
Expand Down Expand Up @@ -386,7 +385,7 @@ def manage_FTPget(self):

InitializeClass(DTMLMethod)

token = "[a-zA-Z0-9!#$%&'*+\-.\\\\^_`|~]+"
token = r"[a-zA-Z0-9!#$%&'*+\-.\\\\^_`|~]+"
hdr_start = re.compile(r'(%s):(.*)' % token).match


Expand Down

0 comments on commit b4495eb

Please sign in to comment.