Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Commit

Permalink
Added compatibility with python 3.7 (celery#4902)
Browse files Browse the repository at this point in the history
  • Loading branch information
kidoz authored and jesse-sempre committed Oct 18, 2018
1 parent ab13cab commit fefdc35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion celery/app/routes.py
Expand Up @@ -17,6 +17,12 @@
from celery.utils.functional import maybe_evaluate, mlazy
from celery.utils.imports import symbol_by_name

try:
Pattern = re._pattern_type
except AttributeError: # pragma: no cover
# for support Python 3.7
Pattern = re.Pattern

__all__ = ('MapRoute', 'Router', 'prepare')


Expand All @@ -33,7 +39,7 @@ def __init__(self, map):
self.map = {}
self.patterns = OrderedDict()
for k, v in map:
if isinstance(k, re._pattern_type):
if isinstance(k, Pattern):
self.patterns[k] = v
elif '*' in k:
self.patterns[re.compile(glob_to_re(k))] = v
Expand Down
5 changes: 5 additions & 0 deletions t/unit/app/test_routes.py
Expand Up @@ -78,12 +78,17 @@ def test_route_for_task(self):
assert route('celery.awesome') is None

def test_route_for_task__glob(self):
from re import compile

route = routes.MapRoute([
('proj.tasks.*', 'routeA'),
('demoapp.tasks.bar.*', {'exchange': 'routeB'}),
(compile(r'(video|image)\.tasks\..*'), {'queue': 'media'}),
])
assert route('proj.tasks.foo') == {'queue': 'routeA'}
assert route('demoapp.tasks.bar.moo') == {'exchange': 'routeB'}
assert route('video.tasks.foo') == {'queue': 'media'}
assert route('image.tasks.foo') == {'queue': 'media'}
assert route('demoapp.foo.bar.moo') is None

def test_expand_route_not_found(self):
Expand Down

0 comments on commit fefdc35

Please sign in to comment.