Add isort and fix errors

This commit is contained in:
ekmartin 2015-11-07 21:03:31 +01:00
parent 1804d66b85
commit cf2de79d64
22 changed files with 74 additions and 43 deletions

View File

@ -2,8 +2,10 @@ __version__ = "0.8"
# Load backends, using settings if available (else falling back to a default) # Load backends, using settings if available (else falling back to a default)
DEFAULT_CHANNEL_BACKEND = "default" DEFAULT_CHANNEL_BACKEND = "default"
from .backends import BackendManager
from django.conf import settings from .backends import BackendManager # isort:skip
from django.conf import settings # isort:skip
channel_backends = BackendManager( channel_backends = BackendManager(
getattr(settings, "CHANNEL_BACKENDS", { getattr(settings, "CHANNEL_BACKENDS", {
DEFAULT_CHANNEL_BACKEND: { DEFAULT_CHANNEL_BACKEND: {
@ -16,4 +18,4 @@ channel_backends = BackendManager(
default_app_config = 'channels.apps.ChannelsConfig' default_app_config = 'channels.apps.ChannelsConfig'
# Promote channel to top-level (down here to avoid circular import errs) # Promote channel to top-level (down here to avoid circular import errs)
from .channel import Channel, Group # NOQA from .channel import Channel, Group # NOQA isort:skip

View File

@ -1,6 +1,7 @@
import functools import functools
from django.contrib import auth from django.contrib import auth
from .decorators import channel_session, http_session from .decorators import channel_session, http_session

View File

@ -21,11 +21,12 @@ class BackendManager(object):
except KeyError: except KeyError:
raise InvalidChannelBackendError("No BACKEND specified for %s" % name) raise InvalidChannelBackendError("No BACKEND specified for %s" % name)
except ImportError: except ImportError:
raise InvalidChannelBackendError("Cannot import BACKEND %r specified for %s" % raise InvalidChannelBackendError(
(self.configs[name]['BACKEND'], name)) "Cannot import BACKEND %r specified for %s" % (self.configs[name]['BACKEND'], name)
)
# Initialise and pass config # Initialise and pass config
instance = backend_class( instance = backend_class(**{k.lower(): v for k, v in self.configs[name].items() if k != "BACKEND"})
**{k.lower(): v for k, v in self.configs[name].items() if k != "BACKEND"})
instance.alias = name instance.alias = name
return instance return instance

View File

@ -1,4 +1,5 @@
import time import time
from channels.consumer_registry import ConsumerRegistry from channels.consumer_registry import ConsumerRegistry

View File

@ -1,8 +1,8 @@
import json
import datetime import datetime
import json
from django.apps.registry import Apps from django.apps.registry import Apps
from django.db import models, connections, DEFAULT_DB_ALIAS, IntegrityError from django.db import DEFAULT_DB_ALIAS, IntegrityError, connections, models
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.timezone import now from django.utils.timezone import now

View File

@ -1,6 +1,7 @@
import time
import json import json
import time
from collections import deque from collections import deque
from .base import BaseChannelBackend from .base import BaseChannelBackend
queues = {} queues = {}

View File

@ -1,11 +1,11 @@
import time import binascii
import json import json
import math import math
import redis
import random import random
import binascii import time
import uuid import uuid
import redis
from django.utils import six from django.utils import six
from .base import BaseChannelBackend from .base import BaseChannelBackend

View File

@ -1,7 +1,7 @@
import random import random
import string import string
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND from channels import DEFAULT_CHANNEL_BACKEND, channel_backends
class Channel(object): class Channel(object):

View File

@ -1,6 +1,8 @@
import importlib import importlib
from django.utils import six
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils import six
from .utils import name_that_thing from .utils import name_that_thing

View File

@ -18,8 +18,10 @@ def linearize(func):
def inner(message, *args, **kwargs): def inner(message, *args, **kwargs):
# Make sure there's a reply channel # Make sure there's a reply channel
if not message.reply_channel: if not message.reply_channel:
raise ValueError("No reply_channel sent to consumer; " raise ValueError(
"@no_overlap can only be used on messages containing it.") "No reply_channel sent to consumer; @no_overlap can only be used on messages containing it."
)
# Get the lock, or re-queue # Get the lock, or re-queue
locked = message.channel_backend.lock_channel(message.reply_channel) locked = message.channel_backend.lock_channel(message.reply_channel)
if not locked: if not locked:
@ -44,12 +46,14 @@ def channel_session(func):
def inner(message, *args, **kwargs): def inner(message, *args, **kwargs):
# Make sure there's a reply_channel # Make sure there's a reply_channel
if not message.reply_channel: if not message.reply_channel:
raise ValueError("No reply_channel sent to consumer; " raise ValueError(
"@channel_session can only be used on messages containing it.") "No reply_channel sent to consumer; @no_overlap can only be used on messages containing it."
)
# Make sure there's NOT a channel_session already # Make sure there's NOT a channel_session already
if hasattr(message, "channel_session"): if hasattr(message, "channel_session"):
raise ValueError("channel_session decorator wrapped " raise ValueError("channel_session decorator wrapped inside another channel_session decorator")
"inside another channel_session decorator")
# Turn the reply_channel into a valid session key length thing. # Turn the reply_channel into a valid session key length thing.
# We take the last 24 bytes verbatim, as these are the random section, # We take the last 24 bytes verbatim, as these are the random section,
# and then hash the remaining ones onto the start, and add a prefix # and then hash the remaining ones onto the start, and add a prefix

View File

@ -1,8 +1,9 @@
from django.core.handlers.base import BaseHandler
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.http.response import HttpResponseBase from django.http.response import HttpResponseBase
from django.core.handlers.base import BaseHandler
from .request import encode_request, decode_request from .request import decode_request, encode_request
from .response import encode_response, decode_response, ResponseLater from .response import ResponseLater, decode_response, encode_response
def monkeypatch_django(): def monkeypatch_django():

View File

@ -1,9 +1,11 @@
import asyncio
import time import time
from autobahn.asyncio.websocket import WebSocketServerProtocol, WebSocketServerFactory import asyncio
from autobahn.asyncio.websocket import (
WebSocketServerFactory, WebSocketServerProtocol,
)
from .websocket_autobahn import get_protocol, get_factory from .websocket_autobahn import get_factory, get_protocol
class WebsocketAsyncioInterface(object): class WebsocketAsyncioInterface(object):

View File

@ -1,6 +1,6 @@
import time import time
from channels import Channel, channel_backends, DEFAULT_CHANNEL_BACKEND from channels import DEFAULT_CHANNEL_BACKEND, Channel, channel_backends
def get_protocol(base): def get_protocol(base):

View File

@ -1,9 +1,11 @@
import time import time
from autobahn.twisted.websocket import WebSocketServerProtocol, WebSocketServerFactory from autobahn.twisted.websocket import (
WebSocketServerFactory, WebSocketServerProtocol,
)
from twisted.internet import reactor from twisted.internet import reactor
from .websocket_autobahn import get_protocol, get_factory from .websocket_autobahn import get_factory, get_protocol
class WebsocketTwistedInterface(object): class WebsocketTwistedInterface(object):

View File

@ -1,6 +1,7 @@
import django import django
from django.core.handlers.wsgi import WSGIHandler from django.core.handlers.wsgi import WSGIHandler
from django.http import HttpResponse from django.http import HttpResponse
from channels import Channel from channels import Channel

View File

@ -1,7 +1,9 @@
import threading import threading
from django.core.management.commands.runserver import Command as RunserverCommand from django.core.management.commands.runserver import \
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND Command as RunserverCommand
from channels import DEFAULT_CHANNEL_BACKEND, channel_backends
from channels.adapters import UrlConsumer from channels.adapters import UrlConsumer
from channels.interfaces.wsgi import WSGIInterface from channels.interfaces.wsgi import WSGIInterface
from channels.log import setup_logger from channels.log import setup_logger

View File

@ -1,6 +1,7 @@
from django.core.management import BaseCommand, CommandError from django.core.management import BaseCommand, CommandError
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND from channels import DEFAULT_CHANNEL_BACKEND, channel_backends
from channels.log import setup_logger from channels.log import setup_logger
from channels.worker import Worker from channels.worker import Worker
@ -14,8 +15,7 @@ class Command(BaseCommand):
channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND] channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
if channel_backend.local_only: if channel_backend.local_only:
raise CommandError( raise CommandError(
"You have a process-local channel backend configured, " "You have a process-local channel backend configured, and so cannot run separate workers.\n"
"and so cannot run separate workers.\n"
"Configure a network-based backend in CHANNEL_BACKENDS to use this command." "Configure a network-based backend in CHANNEL_BACKENDS to use this command."
) )
# Launch a worker # Launch a worker

View File

@ -1,6 +1,6 @@
from django.core.management import BaseCommand, CommandError from django.core.management import BaseCommand, CommandError
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND from channels import DEFAULT_CHANNEL_BACKEND, channel_backends
from channels.log import setup_logger from channels.log import setup_logger

View File

@ -1,6 +1,6 @@
from django.http import HttpRequest from django.http import HttpRequest
from django.utils.datastructures import MultiValueDict
from django.http.request import QueryDict from django.http.request import QueryDict
from django.utils.datastructures import MultiValueDict
def encode_request(request): def encode_request(request):

View File

@ -2,9 +2,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase from django.test import TestCase
from ..backends.database import DatabaseChannelBackend from ..backends.database import DatabaseChannelBackend
from ..backends.redis_py import RedisChannelBackend
from ..backends.memory import InMemoryChannelBackend from ..backends.memory import InMemoryChannelBackend
from ..backends.redis_py import RedisChannelBackend
class MemoryBackendTests(TestCase): class MemoryBackendTests(TestCase):

12
setup.cfg Normal file
View File

@ -0,0 +1,12 @@
[flake8]
exclude = venv/*,tox/*,docs/*,testproject/*
ignore = E123,E128,E402,W503,E731,W601
max-line-length = 119
[isort]
combine_as_imports = true
default_section = THIRDPARTY
include_trailing_comma = true
known_first_party = channels
multi_line_output = 5
not_skip = __init__.py

View File

@ -4,11 +4,7 @@ envlist =
{py27}-django-{17,18,19} {py27}-django-{17,18,19}
{py35}-django-{18,19} {py35}-django-{18,19}
{py27,py35}-flake8 {py27,py35}-flake8
isort
[flake8]
exclude = venv/*,tox/*,docs/*,testproject/*
ignore = E123,E128,E402,W503,E731,W601
max-line-length = 119
[testenv] [testenv]
setenv = setenv =
@ -17,10 +13,12 @@ deps =
six six
redis==2.10.5 redis==2.10.5
flake8: flake8 flake8: flake8
isort: isort
django-16: Django>=1.6,<1.7 django-16: Django>=1.6,<1.7
django-17: Django>=1.7,<1.8 django-17: Django>=1.7,<1.8
django-18: Django>=1.8,<1.9 django-18: Django>=1.8,<1.9
django-19: Django==1.9b1 django-19: Django==1.9b1
commands = commands =
flake8: flake8 flake8: flake8
isort: isort -c -rc channels
django: python {toxinidir}/runtests.py django: python {toxinidir}/runtests.py