Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #31

Merged
merged 4 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion news/26.feature.txt → news/26.feature
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Creating per-user keyrings in order to have session invalidation on log-out (server-side logout). [david-batranu]
Creating per-user keyrings in order to have session invalidation on log-out (server-side logout). [david-batranu]
4 changes: 2 additions & 2 deletions plone/session/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from AccessControl.Permissions import add_user_folders
from plone.session.plugins import session
from Products.PluggableAuthService.PluggableAuthService import \
registerMultiPlugin
from Products.PluggableAuthService.PluggableAuthService import registerMultiPlugin


registerMultiPlugin(session.SessionPlugin.meta_type)

Expand Down
2 changes: 1 addition & 1 deletion plone/session/hiddenprofiles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer
from Products.CMFPlone.interfaces import INonInstallable
from zope.interface import implementer


@implementer(INonInstallable)
Expand Down
14 changes: 10 additions & 4 deletions plone/session/plugins/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
from plone.session import tktauth
from plone.session.interfaces import ISessionPlugin
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.PluggableAuthService.interfaces.plugins import IAuthenticationPlugin # noqa
from Products.PluggableAuthService.interfaces.plugins import ICredentialsResetPlugin # noqa
from Products.PluggableAuthService.interfaces.plugins import ICredentialsUpdatePlugin # noqa
from Products.PluggableAuthService.interfaces.plugins import (
IAuthenticationPlugin,
)
from Products.PluggableAuthService.interfaces.plugins import (
ICredentialsResetPlugin,
)
from Products.PluggableAuthService.interfaces.plugins import (
ICredentialsUpdatePlugin,
)
from Products.PluggableAuthService.interfaces.plugins import IExtractionPlugin
from Products.PluggableAuthService.permissions import ManageUsers
from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin
from zope.component import getUtility
from zope.component import queryUtility
from zope.interface import implementer
from zope.interface import alsoProvides

import binascii
import time


EMPTY_GIF = (
'GIF89a\x01\x00\x01\x00\xf0\x01\x00\xff\xff\xff'
'\x00\x00\x00!\xf9\x04\x01\n\x00\x00\x00'
Expand Down
7 changes: 4 additions & 3 deletions plone/session/tests/testDocTests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# coding=utf-8
from plone.session import tktauth

import doctest
import unittest
import six
import re
import six
import unittest

from plone.session import tktauth

optionflags = doctest.ELLIPSIS

Expand Down
4 changes: 2 additions & 2 deletions plone/session/tests/testPAS.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from DateTime import DateTime
from plone.app.testing import logout
from zope.publisher.browser import TestRequest
from plone.session.interfaces import ISessionPlugin
from plone.session.testing import PLONE_SEESION_FUNCTIONAL_TESTING
from zope.publisher.browser import TestRequest

import base64
import six
Expand Down Expand Up @@ -208,4 +208,4 @@ def testCookieValidAfterLogout(self):

creds = session.extractCredentials(request)
auth = session._validateTicket(creds["cookie"])
self.assertIsNotNone(auth)
self.assertIsNotNone(auth)
7 changes: 5 additions & 2 deletions plone/session/tktauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
>>> data is not None
True

"""
""" # noqa: E501

from socket import inet_aton
from struct import pack
Expand All @@ -153,6 +153,7 @@ def safe_encode(value, encoding='utf-8'):
value = value.encode(encoding)
return value


def safe_text(value, encoding='utf-8'):
"""Converts a value to text, even it is already a text string.

Expand All @@ -177,6 +178,7 @@ def safe_text(value, encoding='utf-8'):
value = value.decode('utf-8', 'replace')
return value


def is_equal(val1, val2):
# constant time comparison
if not isinstance(val1, six.binary_type) or \
Expand Down Expand Up @@ -300,8 +302,9 @@ def validateTicket(secret, ticket, ip='0.0.0.0', timeout=0, now=None,

# doctest runner
def _test():
import doctest
from plone.session.tests.testDocTests import Py23DocChecker
Copy link
Member

Choose a reason for hiding this comment

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

Py23DocChecker could also be removed. But can be done later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Py23DocChecker is removed in #32


import doctest
doctest.testmod(
optionflags=doctest.ELLIPSIS + doctest.NORMALIZE_WHITESPACE,
checker=Py23DocChecker(),
Expand Down
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
[bdist_wheel]
universal = 0

[flake8]
max-line-length = 88
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we are running flake8 anymore. Just black. But it does not hurt.
I myself have a small custom script to call flake8 and ignore a few common problems:

$ cat ~/bin/pychecker3
#! /bin/sh
#infile = $1
if test "x$1" = "x--stdlib"; then
    # --stdlib gets passed by some python-mode.el versions.  pep8 and
    # pyflakes and flake8 cannot handle this, so we ignore this argument, by
    # shifting the rest of the arguments.
    #shift
    # Actually, we suddenly get passed 'pychecker --stdlib /Volumes/Macintosh /Volumes/Macintosh /Volumes/Macintosh /Volumes/Macintosh /Volumes/Macintosh /Users/mauritsvanrees/myfile.py'
    # So we shift to the last argument and pass only that
    shift $(($# - 1))
fi
# Check with Python 3.
# E203 Whitespace before ':' (false positives when using black)
# E231 missing whitespace after ',' (conflicts with black)
# E501 line too long
# W503 Line break occurred before a binary operator [outdated]
flake8 --ignore=E203,E231,E501,W503 $1 | sort-flake8

And then sort-flake8:

#!/usr/bin/env python
# Example: flake8 zest/releaser/utils.py | ./pychecker-sort
# Sorts with Failures first.
import sys
lines = sys.stdin.read().splitlines()


def get_code(line):
    """Extract error code from line.

    Example line:
    'zest/releaser/utils.py:797:1: E302 expected 2 blank lines, found 1'
    """
    if line.count(':') != 3:
        return ''
    filename, lineno, pos, error = line.split(':')
    # Example error:
    # ' E302 expected 2 blank lines, found 1'
    code = error.strip().split(' ', 1)[0]
    if not code:
        return ''
    return code


def sortable_code(code):
    """Make code sortable.

    First failures, then errors, then warnings, then any others.
    """
    if not code:
        # sort last
        return '9'
    first = code[0]
    if first == 'F':
        value = 0
    elif first == 'E':
        value = 1
    elif first == 'W':
        value = 2
    else:
        value = 3
    return '{}{}'.format(value, code)


def error_value(line):
    return sortable_code(get_code(line))


for line in sorted(lines, key=error_value):
    print(line)


[isort]
profile = black
force_alphabetical_sort=True
force_single_line=True
lines_after_imports=2
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from setuptools import find_packages
from setuptools import setup


version = '4.0.0b2.dev0'
longdescription = open('README.rst').read()
longdescription += '\n'
Expand Down