Products.statusmessages/cleanup: Cleanup flake8 errors

Gil Forcada <jenkins-z4DKO/[email protected]>
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: Products.statusmessages
Branch: refs/heads/cleanup
Date: 2017-07-22T18:17:08+02:00
Author: Gil Forcada (gforcada) <[email protected]>
Commit: https://github.com/plone/Products.statusmessages/commit/6a7506d8623ac396b331097a9a9ff0896b5907d8

Cleanup flake8 errors

Files changed:
M CHANGES.rst
M MANIFEST.in
M Products/__init__.py
M Products/statusmessages/__init__.py
M Products/statusmessages/adapter.py
M Products/statusmessages/interfaces.py
M Products/statusmessages/message.py
M Products/statusmessages/tests/__init__.py
M Products/statusmessages/tests/test_adapter.py
M Products/statusmessages/tests/test_doctests.py
M setup.py

diff --git a/CHANGES.rst b/CHANGES.rst
index eead966..d217beb 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -16,8 +16,8 @@ New features:
 
 Bug fixes:
 
-- *add item here*
-
+- Update code to follow Plone styleguide.
+  [gforcada]
 
 4.1.2 (2017-02-12)
 ------------------
diff --git a/MANIFEST.in b/MANIFEST.in
index 1912acd..037bca9 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,4 +1,6 @@
 include *.rst
+include requirements.txt
+include buildout.cfg
 
 recursive-include docs *
 recursive-include Products *
diff --git a/Products/__init__.py b/Products/__init__.py
index de40ea7..68c04af 100644
--- a/Products/__init__.py
+++ b/Products/__init__.py
@@ -1 +1,2 @@
+# -*- coding: utf-8 -*-
 __import__('pkg_resources').declare_namespace(__name__)
diff --git a/Products/statusmessages/__init__.py b/Products/statusmessages/__init__.py
index b303b49..0d98752 100644
--- a/Products/statusmessages/__init__.py
+++ b/Products/statusmessages/__init__.py
@@ -1 +1,2 @@
+# -*- coding: utf-8 -*-
 STATUSMESSAGEKEY = 'statusmessages'
diff --git a/Products/statusmessages/adapter.py b/Products/statusmessages/adapter.py
index 4395093..02cc196 100644
--- a/Products/statusmessages/adapter.py
+++ b/Products/statusmessages/adapter.py
@@ -1,17 +1,19 @@
-import binascii
-
-from zope.annotation.interfaces import IAnnotations
-from zope.i18n import translate
-from zope.interface import implementer
-
+# -*- coding: utf-8 -*-
 from Products.statusmessages import STATUSMESSAGEKEY
+from Products.statusmessages.interfaces import IStatusMessage
 from Products.statusmessages.message import decode
 from Products.statusmessages.message import Message
-from Products.statusmessages.interfaces import IStatusMessage
+from zope.annotation.interfaces import IAnnotations
+from zope.i18n import translate
+from zope.interface import implementer
 
+import binascii
 import logging
+
+
 logger = logging.getLogger('statusmessages')
 
+
 @implementer(IStatusMessage)
 class StatusMessage(object):
     """Adapter for the BrowserRequest to handle status messages.
@@ -25,7 +27,7 @@ class StatusMessage(object):
     """
 
     def __init__(self, context):
-        self.context = context # the context must be the request
+        self.context = context  # the context must be the request
 
     def add(self, text, type=u'info'):
         """Add a status message.
@@ -34,8 +36,10 @@ def add(self, text, type=u'info'):
         text = translate(text, context=context)
         annotations = IAnnotations(context)
 
-        old = annotations.get(STATUSMESSAGEKEY,
-                              context.cookies.get(STATUSMESSAGEKEY))
+        old = annotations.get(
+            STATUSMESSAGEKEY,
+            context.cookies.get(STATUSMESSAGEKEY),
+        )
         value = _encodeCookieValue(text, type, old=old)
         context.response.setCookie(STATUSMESSAGEKEY, value, path='/')
         annotations[STATUSMESSAGEKEY] = value
@@ -45,8 +49,10 @@ def show(self):
         """
         context = self.context
         annotations = IAnnotations(context)
-        value = annotations.get(STATUSMESSAGEKEY,
-                                context.cookies.get(STATUSMESSAGEKEY))
+        value = annotations.get(
+            STATUSMESSAGEKEY,
+            context.cookies.get(STATUSMESSAGEKEY),
+        )
         if value is None:
             return []
         value = _decodeCookieValue(value)
@@ -77,12 +83,13 @@ def _encodeCookieValue(text, type, old=None):
 
     if old is not None:
         results = _decodeCookieValue(old)
-    if not message in results:
+    if message not in results:
         results.append(message)
 
     messages = ''.join([r.encode() for r in results])
     return binascii.b2a_base64(messages).rstrip()
 
+
 def _decodeCookieValue(string):
     """Decode a cookie value to a list of Messages.
     """
@@ -93,7 +100,7 @@ def _decodeCookieValue(string):
     # Try to decode the cookie value
     try:
         value = binascii.a2b_base64(string)
-        while len(value) > 1: # at least 2 bytes of data
+        while len(value) > 1:  # at least 2 bytes of data
             message, value = decode(value)
             if message is not None:
                 results.append(message)
diff --git a/Products/statusmessages/interfaces.py b/Products/statusmessages/interfaces.py
index 66c8abc..fa19f88 100644
--- a/Products/statusmessages/interfaces.py
+++ b/Products/statusmessages/interfaces.py
@@ -1,4 +1,7 @@
-from zope.interface import Interface, Attribute
+# -*- coding: utf-8 -*-
+from zope.interface import Attribute
+from zope.interface import Interface
+
 
 class IMessage(Interface):
     """A single status message."""
diff --git a/Products/statusmessages/message.py b/Products/statusmessages/message.py
index 7df3cb1..b55862b 100644
--- a/Products/statusmessages/message.py
+++ b/Products/statusmessages/message.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 from Products.statusmessages.interfaces import IMessage
 from zope.interface import implementer
@@ -76,12 +77,17 @@ def encode(self):
         The format consists of a two bytes length header of 11 bits for the
         message length and 5 bits for the type length followed by two values.
         """
-        message = _utf8(self.message)[:0x3FF] # we can store 2^11 bytes
-        type = _utf8(self.type)[:0x1F]        # we can store 2^5 bytes
-        size = (len(message) << 5) + (len(type) & 31) # pack into 16 bits
+        message = _utf8(self.message)[:0x3FF]  # we can store 2^11 bytes
+        type = _utf8(self.type)[:0x1F]         # we can store 2^5 bytes
+        size = (len(message) << 5) + (len(type) & 31)  # pack into 16 bits
+
+        return struct.pack(
+            '!H{0}s{1}s'.format(len(message), len(type)),
+            size,
+            message,
+            type,
+        )
 
-        return struct.pack('!H%ds%ds' % (len(message), len(type)),
-                           size, message, type)
 
 def decode(value):
     """
@@ -95,7 +101,9 @@ def decode(value):
     if len(value) >= 2:
         size = struct.unpack('!H', value[:2])[0]
         msize, tsize = (size >> 5, size & 31)
-        message = Message(_unicode(value[2:msize+2]),
-                          _unicode(value[msize+2:msize+tsize+2]))
+        message = Message(
+            _unicode(value[2:msize+2]),
+            _unicode(value[msize+2:msize+tsize+2]),
+        )
         return message, value[msize+tsize+2:]
     return None, ''
diff --git a/Products/statusmessages/tests/__init__.py b/Products/statusmessages/tests/__init__.py
index 792d600..e69de29 100644
--- a/Products/statusmessages/tests/__init__.py
+++ b/Products/statusmessages/tests/__init__.py
@@ -1 +0,0 @@
-#
diff --git a/Products/statusmessages/tests/test_adapter.py b/Products/statusmessages/tests/test_adapter.py
index c86bd3f..ee3304f 100644
--- a/Products/statusmessages/tests/test_adapter.py
+++ b/Products/statusmessages/tests/test_adapter.py
@@ -266,9 +266,9 @@ def test_301(self):
 
           >>> status.add(u'test', type=u'info')
 
-        Publish a redirect response that also happened to call show(). This could
-        happen if the redirect (unnecessarily) rendered a template showing the
-        status message, for example.
+        Publish a redirect response that also happened to call show().
+        This could happen if the redirect (unnecessarily)
+        rendered a template showing the status message, for example.
 
           >>> fakePublish(request, 302)
           >>> messages = status.show()
@@ -287,8 +287,8 @@ def test_301(self):
           >>> len(status.show())
           1
 
-        Let's now fake redirection. The message should still be there, but will
-        then be expired.
+        Let's now fake redirection. The message should still be there,
+        but will then be expired.
 
           >>> fakePublish(request, 200)
           >>> messages = status.show()
diff --git a/Products/statusmessages/tests/test_doctests.py b/Products/statusmessages/tests/test_doctests.py
index ba63829..face234 100644
--- a/Products/statusmessages/tests/test_doctests.py
+++ b/Products/statusmessages/tests/test_doctests.py
@@ -1,9 +1,13 @@
+# -*- coding: utf-8 -*-
 from doctest import DocTestSuite
 from unittest import TestSuite
 
 
+test_list = (
+    DocTestSuite('Products.statusmessages.adapter'),
+    DocTestSuite('Products.statusmessages.message'),
+)
+
+
 def test_suite():
-    return TestSuite((
-        DocTestSuite('Products.statusmessages.adapter'),
-        DocTestSuite('Products.statusmessages.message'),
-        ))
+    return TestSuite(test_list)
diff --git a/setup.py b/setup.py
index 3b1e53f..ae9afef 100644
--- a/setup.py
+++ b/setup.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 from setuptools import find_packages
 from setuptools import setup
 
@@ -34,15 +35,15 @@
     include_package_data=True,
     zip_safe=False,
     extras_require=dict(
-      test=[
-          'zope.component',
-          'Zope2',
-      ]
+        test=[
+            'zope.component',
+            'Zope2',
+        ],
     ),
     install_requires=[
-      'setuptools',
-      'zope.annotation',
-      'zope.i18n',
-      'zope.interface',
+        'setuptools',
+        'zope.annotation',
+        'zope.i18n',
+        'zope.interface',
     ],
 )



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.