Skip to content

Commit

Permalink
Issue #298: fix Python 3.10 support: import Callable from collections…
Browse files Browse the repository at this point in the history
….abc
  • Loading branch information
spaceone committed Aug 20, 2021
1 parent 41a029e commit d1bfe00
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion circuits/core/components.py
@@ -1,10 +1,13 @@
"""
This module defines the BaseComponent and its subclass Component.
"""
from collections import Callable
from inspect import getmembers
from itertools import chain
from types import MethodType
try:
from collections import Callable
except ImportError:
from collections.abc import Callable

from .events import Event, registered, unregistered
from .handlers import HandlerMetaClass, handler
Expand Down
5 changes: 4 additions & 1 deletion circuits/core/handlers.py
@@ -1,7 +1,10 @@
"""
This module define the @handler decorator/function and the HandlesType type.
"""
from collections import Callable
try:
from collections import Callable
except ImportError:
from collections.abc import Callable

from circuits.tools import getargspec

Expand Down
5 changes: 4 additions & 1 deletion circuits/web/controllers.py
Expand Up @@ -3,8 +3,11 @@
This module implements ...
"""
import json
from collections import Callable
from functools import update_wrapper
try:
from collections import Callable
except ImportError:
from collections.abc import Callable

from circuits.core import BaseComponent, handler
from circuits.tools import getargspec
Expand Down
7 changes: 5 additions & 2 deletions circuits/web/tools.py
Expand Up @@ -3,7 +3,6 @@
This module implements tools used throughout circuits.web.
These tools can also be used within Controllers and request handlers.
"""
import collections
import hashlib
import mimetypes
import os
Expand All @@ -12,6 +11,10 @@
from email.generator import _make_boundary
from email.utils import formatdate
from time import mktime
try:
from collections import Callable
except ImportError:
from collections.abc import Callable

from circuits import BaseComponent, handler
from circuits.web.wrappers import Host
Expand Down Expand Up @@ -314,7 +317,7 @@ def check_auth(request, response, realm, users, encrypt=None):
if not encrypt:
encrypt = _httpauth.DIGEST_AUTH_ENCODERS[_httpauth.MD5]

if isinstance(users, collections.Callable):
if isinstance(users, Callable):
try:
# backward compatibility
users = users() # expect it to return a dictionary
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
@@ -1,10 +1,13 @@
"""py.test config"""

import collections
import sys
import threading
from collections import deque
from time import sleep
try:
from collections import Callable
except ImportError:
from collections.abc import Callable

import pytest

Expand Down Expand Up @@ -97,7 +100,7 @@ def wait(self):
def wait_for(obj, attr, value=True, timeout=30.0):
from circuits.core.manager import TIMEOUT
for i in range(int(timeout / TIMEOUT)):
if isinstance(value, collections.Callable):
if isinstance(value, Callable):
if value(obj, attr):
return True
elif getattr(obj, attr) == value:
Expand Down

0 comments on commit d1bfe00

Please sign in to comment.