Skip to content

Commit

Permalink
Pre commit tisto (#161)
Browse files Browse the repository at this point in the history
* Run pre-commit.ci, fix three typos

* Use same black version as pre-commit.ci

* Set black version to pre-commit.ci one

* black

* Add isort/black config to pyproject.toml
  • Loading branch information
tisto authored Oct 1, 2023
1 parent 33cbd40 commit 79f1d19
Show file tree
Hide file tree
Showing 31 changed files with 174 additions and 200 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Bugfixes:
[buchi]

- Fallback to regular views during traversal to ensure compatibility with
views beeing called with a specific Accept header.
views being called with a specific Accept header.
[buchi]


Expand Down Expand Up @@ -295,7 +295,7 @@ Bugfixes:

- Refactor traversal of REST requests by using a traversal adapter on the site
root instead of a traversal adapter for each REST service. This prevents
REST services from being overriden by other traversal adapters.
REST services from being overridden by other traversal adapters.
[buchi]


Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ build-plone-6.0: ## Build Plone 6.0
python$(version) -m venv .
bin/pip install --upgrade pip
bin/pip install -r requirements-6.0.x.txt
bin/pip install pip install black==$$(awk '/^black =/{print $$NF}' versions.cfg)
bin/buildout -c plone-6.0.x.cfg

.PHONY: Test
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ allow_origin
allow_methods
A comma separated list of HTTP method names that are allowed by this CORS
policy, e.g. "DELETE,GET,OPTIONS,PATCH,POST,PUT". If not specified, all
methods for which there's a service registerd are allowed.
methods for which there's a service registered are allowed.

allow_credentials
Indicates whether the resource supports user credentials in the request.
Expand Down
2 changes: 1 addition & 1 deletion plone-5.2.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ versions=versions

[versions]
plone.rest =
black = 21.12b0
black = 23.3.0

# Error: The requirement ('virtualenv>=20.0.35') is not allowed by your [versions] constraint (20.0.26)
virtualenv = 20.0.35
Expand Down
2 changes: 1 addition & 1 deletion plone-6.0.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ zodb-temporary-storage = off

[versions]
plone.rest =
black = 21.7b0
black = 23.3.0
pygments = 2.14.0
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ showcontent = true
[[tool.towncrier.type]]
directory = "internal"
name = "Internal:"
showcontent = true
showcontent = true

[tool.isort]
profile = "plone"

[tool.black]
target-version = ["py38"]
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from setuptools import find_packages
from setuptools import setup

from setuptools import find_packages, setup
import os


def read(*rnames):
Expand Down
1 change: 0 additions & 1 deletion src/plone/rest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from plone.rest.service import Service # noqa
4 changes: 2 additions & 2 deletions src/plone/rest/cors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from plone.rest.interfaces import ICORSPolicy
from zope.interface import implementer


# CORS preflight service registry
# A mapping of method -> service_id
_services = {}
Expand All @@ -19,7 +19,7 @@ def lookup_preflight_service_id(method):


@implementer(ICORSPolicy)
class CORSPolicy(object):
class CORSPolicy:
def __init__(self, context, request):
self.context = context
self.request = request
Expand Down
1 change: 0 additions & 1 deletion src/plone/rest/demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.rest import Service

import json
Expand Down
18 changes: 10 additions & 8 deletions src/plone/rest/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from AccessControl import getSecurityManager


try:
from plone.app.redirector.interfaces import IRedirectionStorage
except ImportError:
Expand All @@ -10,10 +11,11 @@
from Products.CMFCore.permissions import ManagePortal
from Products.Five.browser import BrowserView
from six.moves import urllib
from six.moves.urllib.parse import quote
from six.moves.urllib.parse import unquote
from urllib.parse import quote
from urllib.parse import unquote
from zExceptions import NotFound


try:
from ZPublisher.HTTPRequest import WSGIRequest

Expand Down Expand Up @@ -61,7 +63,7 @@ def render_exception(self, exception):
if six.PY2:
name = name.decode("utf-8")
message = message.decode("utf-8")
result = {u"type": name, u"message": message}
result = {"type": name, "message": message}

policy = queryMultiAdapter((self.context, self.request), ICORSPolicy)
if policy is not None:
Expand All @@ -77,10 +79,10 @@ def render_exception(self, exception):
# NotFound exceptions need special handling because their
# exception message gets turned into HTML by ZPublisher
url = self.request.getURL()
result[u"message"] = u"Resource not found: %s" % url
result["message"] = "Resource not found: %s" % url

if getSecurityManager().checkPermission(ManagePortal, getSite()):
result[u"traceback"] = self.render_traceback(exception)
result["traceback"] = self.render_traceback(exception)

return result

Expand All @@ -101,8 +103,8 @@ def render_traceback(self, exception):
pass
else:
return (
u"ERROR: Another exception happened before we could "
u"render the traceback."
"ERROR: Another exception happened before we could "
"render the traceback."
)

raw = "\n".join(traceback.format_tb(exc_traceback))
Expand Down Expand Up @@ -192,7 +194,7 @@ def attempt_redirect(self):

query_string = self.request.QUERY_STRING
if query_string:
new_path = storage.get("%s?%s" % (old_path, query_string))
new_path = storage.get(f"{old_path}?{query_string}")
# if we matched on the query_string we don't want to include it
# in redirect
if new_path:
Expand Down
1 change: 0 additions & 1 deletion src/plone/rest/events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.rest.cors import lookup_preflight_service_id
from plone.rest.interfaces import IAPIRequest
from plone.rest.negotiation import lookup_service_id
Expand Down
1 change: 0 additions & 1 deletion src/plone/rest/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from zope.interface import Interface


Expand Down
4 changes: 1 addition & 3 deletions src/plone/rest/negotiation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Service registry
# A mapping of method -> type name -> subtype name -> service id
_services = {}
Expand Down Expand Up @@ -42,7 +40,7 @@ def register_service(method, media_type):
"""Register a service for the given request method and media type and
return it's service id.
"""
service_id = u"{}_{}_{}_".format(method, media_type[0], media_type[1])
service_id = f"{method}_{media_type[0]}_{media_type[1]}_"
types = _services.setdefault(method, {})
subtypes = types.setdefault(media_type[0], {})
subtypes[media_type[1]] = service_id
Expand Down
1 change: 0 additions & 1 deletion src/plone/rest/patches.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from plone.rest.interfaces import IAPIRequest


Expand Down
5 changes: 2 additions & 3 deletions src/plone/rest/service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
from plone.rest.interfaces import ICORSPolicy
from plone.rest.interfaces import IService
from zope.component import queryMultiAdapter
from zope.interface import implementer


@implementer(IService)
class Service(object):
class Service:
def __call__(self):
policy = queryMultiAdapter((self.context, self.request), ICORSPolicy)
if policy is not None:
Expand All @@ -29,4 +28,4 @@ def __getattribute__(self, name):
# include credentials
if name == "__roles__" and self.request._rest_cors_preflight:
return ["Anonymous"]
return super(Service, self).__getattribute__(name)
return super().__getattribute__(name)
5 changes: 1 addition & 4 deletions src/plone/rest/testing.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# -*- coding: utf-8 -*-
from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import PloneSandboxLayer
from plone.rest.service import Service
from plone.testing import z2

from zope.configuration import xmlconfig


class PloneRestLayer(PloneSandboxLayer):

defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)

def setUpZope(self, app, configurationContext):
Expand All @@ -31,7 +28,7 @@ def setUpZope(self, app, configurationContext):

class InternalServerErrorService(Service):
def __call__(self):
from six.moves.urllib.error import HTTPError
from urllib.error import HTTPError

raise HTTPError(
"http://nohost/plone/500-internal-server-error",
Expand Down
1 change: 0 additions & 1 deletion src/plone/rest/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
7 changes: 2 additions & 5 deletions src/plone/rest/tests/test_cors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from ZPublisher.pubevents import PubStart
from plone.app.testing import popGlobalRegistry
from plone.app.testing import pushGlobalRegistry
from plone.rest.cors import CORSPolicy
Expand All @@ -10,12 +8,12 @@
from zope.event import notify
from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from ZPublisher.pubevents import PubStart

import unittest


class TestCORSPolicy(unittest.TestCase):

layer = PLONE_REST_INTEGRATION_TESTING

def setUp(self):
Expand Down Expand Up @@ -195,7 +193,6 @@ def test_preflight_cors_sets_status_code_200(self):


class TestCORS(unittest.TestCase):

layer = PLONE_REST_INTEGRATION_TESTING

def setUp(self):
Expand Down Expand Up @@ -231,7 +228,7 @@ def test_simple_cors_gets_processed(self):

def test_preflight_request_without_cors_policy_doesnt_render_service(self):
# "Unregister" the current CORS policy
class NoCORSPolicy(object):
class NoCORSPolicy:
def __new__(cls, context, request):
return None

Expand Down
Loading

0 comments on commit 79f1d19

Please sign in to comment.