Skip to content

Commit

Permalink
Add Python 2 / 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
davilima6 committed Jan 27, 2018
1 parent b6f0810 commit b6257ee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
20 changes: 19 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Breaking changes:

New features:

- *add item here*
- Add Python 2 / 3 compatibility
[davilima6]

Bug fixes:

Expand Down Expand Up @@ -46,6 +47,7 @@ Bug fixes:
- Update code to follow Plone styleguide.
[gforcada]


4.1.2 (2017-02-12)
------------------

Expand All @@ -63,6 +65,7 @@ Bug fixes:
- Use zope.interface decorator.
[gforcada]


4.1.0 (2016-05-25)
------------------

Expand All @@ -71,12 +74,14 @@ New features:
- Convert tests to plone.app.testing.
[do3cc]


4.0 - 2010-07-18
----------------

- Use the standard libraries doctest module.
[hannosch]


4.0b1 - 2010-03-01
------------------

Expand All @@ -86,12 +91,14 @@ New features:
won't lose the message.
[optilude]


4.0a2 - 2009-12-17
------------------

- Changed the default type of a new message from the empty string to info.
[hannosch]


4.0a1 - 2009-12-17
------------------

Expand All @@ -115,6 +122,7 @@ New features:
- Declare package and test dependencies.
[hannosch]


3.0.3 - 2007-11-24
------------------

Expand All @@ -123,6 +131,7 @@ New features:
last one (slightly faster). This fixes tickets #7323 and #7325.
[mj]


3.0.2 - 2007-11-06
------------------

Expand All @@ -132,25 +141,29 @@ New features:
http://dev.plone.org/plone/ticket/6943.
[hannosch, witsch, mj]


3.0.1 - 2007-10-07
------------------

- Added the IAttributeAnnotatable interface assignment for the request to this
package as well as the inclusion of the zope.annotation, as we rely on it.
[hannosch]


3.0 - 2007-08-09
----------------

- No changes.
[hannosch]


3.0rc1 - 2007-07-10
-------------------

- Removed useless setup.cfg.
[hannosch]


3.0b2 - 2007-03-23
------------------

Expand All @@ -164,6 +177,7 @@ New features:
sneaking those in via query strings.
[tomster, hannosch]


3.0b1 - 2007-03-05
------------------

Expand All @@ -179,6 +193,7 @@ New features:
in Archetypes.
[hannosch]


2.1 - 2006-10-25
----------------

Expand All @@ -188,6 +203,7 @@ New features:
- Fixed deprecation warning for the zcml content directive.
[hannosch]


2.0 - 2006-05-15
----------------

Expand All @@ -198,6 +214,7 @@ New features:
are able to identify users and keep them connected to the same ZEO server).
[hannosch]


1.1 - 2006-02-13
----------------

Expand All @@ -207,6 +224,7 @@ New features:
- Fixed serious memory leak and did some code improvements.
[hannosch, alecm]


1.0 - 2006-01-26
----------------

Expand Down
11 changes: 6 additions & 5 deletions Products/statusmessages/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
from Products.statusmessages.interfaces import IMessage
from zope.interface import implementer

import six
import struct


def _utf8(value):
if isinstance(value, unicode):
if isinstance(value, six.text_type):
return value.encode('utf-8')
elif isinstance(value, str):
return value
return ''


def _unicode(value):
return unicode(value, 'utf-8', 'ignore')
return six.text_type(value, 'utf-8', 'ignore')


@implementer(IMessage)
Expand Down Expand Up @@ -102,8 +103,8 @@ def decode(value):
size = struct.unpack(b'!H', value[:2])[0]
msize, tsize = (size >> 5, size & 31)
message = Message(
_unicode(value[2:msize+2]),
_unicode(value[msize+2:msize+tsize+2]),
_unicode(value[2:msize + 2]),
_unicode(value[msize + 2:msize + tsize + 2]),
)
return message, value[msize+tsize+2:]
return message, value[msize + tsize + 2:]
return None, ''
7 changes: 3 additions & 4 deletions Products/statusmessages/tests/test_adapter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: UTF-8 -*-
"""
StatusMessage adapter tests.
"""
""" StatusMessage adapter tests. """

import six
import unittest


Expand Down Expand Up @@ -214,7 +213,7 @@ def test_directives(self):
>>> status.add(u'test' * 40, type=u'info')
>>> cookies = [c['value'] for c in request.response.cookies.values()]
>>> cookies = ''.join(cookies)
>>> cookies == unicode(cookies).encode('ASCII')
>>> cookies == six.text_type(cookies).encode('ASCII')
True
>>> '\\n' in cookies
False
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
),
install_requires=[
'setuptools',
'six',
'zope.annotation',
'zope.i18n',
'zope.interface',
Expand Down

1 comment on commit b6257ee

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davilima6 Jenkins CI reporting about code analysis
See the full report here: http://jenkins.plone.org/job/package-Products.statusmessages/19/violations

Products/statusmessages/tests/test_adapter.py:4:1: F401 'six' imported but unused
Products/statusmessages/tests/test_adapter.py:37:15: D001 found directlyProvides( replace it with zope.interface.provider
Products/statusmessages/tests/test_adapter.py:223:0: P102 docstring does contain unindexed parameters
Products/statusmessages/tests/test_adapter.py:243:15: D001 found directlyProvides( replace it with zope.interface.provider
Products/statusmessages/tests/test_adapter.py:310:0: P102 docstring does contain unindexed parameters

Follow these instructions to reproduce it locally.

Please sign in to comment.