Skip to content

Commit

Permalink
Add blacken-docs pre-commit hook (adamchainz#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz authored Aug 4, 2021
1 parent d539538 commit 2678a21
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ repos:
hooks:
- id: black
language_version: python3

- repo: https://github.com/asottile/blacken-docs
rev: v1.10.0
hooks:
- id: blacken-docs
additional_dependencies:
- black==21.7b0
- repo: https://github.com/pycqa/isort
rev: 5.9.3
hooks:
Expand Down
4 changes: 2 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ History

.. code-block:: python
CORS_ORIGIN_WHITELIST = ['example.com']
CORS_ORIGIN_WHITELIST = ["example.com"]
...to this:

.. code-block:: python
CORS_ORIGIN_WHITELIST = ['https://example.com']
CORS_ORIGIN_WHITELIST = ["https://example.com"]
* Removed the ``CORS_MODEL`` setting, and associated class. It seems very few,
or no users were using it, since there were no bug reports since its move to
Expand Down
77 changes: 41 additions & 36 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ and then add it to your installed apps:
.. code-block:: python
INSTALLED_APPS = [
...
'corsheaders',
...
...,
"corsheaders",
...,
]
Make sure you add the trailing comma or you might get a ``ModuleNotFoundError``
Expand All @@ -80,8 +80,8 @@ You will also need to add a middleware class to listen in on responses:
MIDDLEWARE = [
...,
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
...,
]
Expand Down Expand Up @@ -149,7 +149,7 @@ Example:
"https://example.com",
"https://sub.example.com",
"http://localhost:8080",
"http://127.0.0.1:9000"
"http://127.0.0.1:9000",
]
Previously this setting was called ``CORS_ORIGIN_WHITELIST``, which still works
Expand Down Expand Up @@ -203,7 +203,7 @@ Example:

.. code-block:: python
CORS_URLS_REGEX = r'^/api/.*$'
CORS_URLS_REGEX = r"^/api/.*$"
``CORS_ALLOW_METHODS``
~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -213,12 +213,12 @@ A list of HTTP verbs that are allowed for the actual request. Defaults to:
.. code-block:: python
CORS_ALLOW_METHODS = [
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
"DELETE",
"GET",
"OPTIONS",
"PATCH",
"POST",
"PUT",
]
The default can be imported as ``corsheaders.defaults.default_methods`` so you
Expand All @@ -230,7 +230,7 @@ with any future changes. For example:
from corsheaders.defaults import default_methods
CORS_ALLOW_METHODS = list(default_methods) + [
'POKE',
"POKE",
]
``CORS_ALLOW_HEADERS``
Expand All @@ -242,15 +242,15 @@ request. Defaults to:
.. code-block:: python
CORS_ALLOW_HEADERS = [
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
"accept",
"accept-encoding",
"authorization",
"content-type",
"dnt",
"origin",
"user-agent",
"x-csrftoken",
"x-requested-with",
]
The default can be imported as ``corsheaders.defaults.default_headers`` so you
Expand All @@ -262,7 +262,7 @@ any future changes. For example:
from corsheaders.defaults import default_headers
CORS_ALLOW_HEADERS = list(default_headers) + [
'my-custom-header',
"my-custom-header",
]
``CORS_EXPOSE_HEADERS``
Expand Down Expand Up @@ -312,12 +312,12 @@ For example:
.. code-block:: python
CORS_ALLOWED_ORIGINS = [
'http://read.only.com',
'http://change.allowed.com',
"http://read.only.com",
"http://change.allowed.com",
]
CSRF_TRUSTED_ORIGINS = [
'change.allowed.com',
"change.allowed.com",
]
``CORS_REPLACE_HTTPS_REFERER``
Expand All @@ -341,12 +341,12 @@ undo the ``Referer`` replacement:
.. code-block:: python
MIDDLEWARE_CLASSES = [
...
'corsheaders.middleware.CorsMiddleware',
...
'django.middleware.csrf.CsrfViewMiddleware',
'corsheaders.middleware.CorsPostCsrfMiddleware',
...
...,
"corsheaders.middleware.CorsMiddleware",
...,
"django.middleware.csrf.CsrfViewMiddleware",
"corsheaders.middleware.CorsPostCsrfMiddleware",
...,
]
Signals
Expand All @@ -370,9 +370,11 @@ For example you might define a handler like this:
from myapp.models import MySite
def cors_allow_mysites(sender, request, **kwargs):
return MySite.objects.filter(host=request.host).exists()
check_request_enabled.connect(cors_allow_mysites)
Then connect it at app ready time using a `Django AppConfig
Expand All @@ -382,16 +384,17 @@ Then connect it at app ready time using a `Django AppConfig
# myapp/__init__.py
default_app_config = 'myapp.apps.MyAppConfig'
default_app_config = "myapp.apps.MyAppConfig"
.. code-block:: python
# myapp/apps.py
from django.apps import AppConfig
class MyAppConfig(AppConfig):
name = 'myapp'
name = "myapp"
def ready(self):
# Makes sure all signal handlers are connected
Expand All @@ -412,7 +415,9 @@ unrestricted URL's. For example:
# myapp/handlers.py
from corsheaders.signals import check_request_enabled
def cors_allow_api_to_everyone(sender, request, **kwargs):
return request.path.startswith('/api/')
return request.path.startswith("/api/")
check_request_enabled.connect(cors_allow_api_to_everyone)

0 comments on commit 2678a21

Please sign in to comment.