Refs #23919 -- Removed usage of django.utils.decorators.ContextDecorator.
This commit is contained in:
parent
4c5ed3e683
commit
41e0033caf
|
@ -1,7 +1,8 @@
|
||||||
|
from contextlib import ContextDecorator
|
||||||
|
|
||||||
from django.db import (
|
from django.db import (
|
||||||
DEFAULT_DB_ALIAS, DatabaseError, Error, ProgrammingError, connections,
|
DEFAULT_DB_ALIAS, DatabaseError, Error, ProgrammingError, connections,
|
||||||
)
|
)
|
||||||
from django.utils.decorators import ContextDecorator
|
|
||||||
|
|
||||||
|
|
||||||
class TransactionManagementError(ProgrammingError):
|
class TransactionManagementError(ProgrammingError):
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
"Functions that help with dynamically creating decorators for views."
|
"Functions that help with dynamically creating decorators for views."
|
||||||
|
|
||||||
try:
|
# For backwards compatibility in Django 2.0.
|
||||||
from contextlib import ContextDecorator
|
from contextlib import ContextDecorator # noqa
|
||||||
except ImportError:
|
|
||||||
ContextDecorator = None
|
|
||||||
|
|
||||||
from functools import WRAPPER_ASSIGNMENTS, update_wrapper, wraps
|
from functools import WRAPPER_ASSIGNMENTS, update_wrapper, wraps
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,21 +163,6 @@ def make_middleware_decorator(middleware_class):
|
||||||
return _make_decorator
|
return _make_decorator
|
||||||
|
|
||||||
|
|
||||||
if ContextDecorator is None:
|
|
||||||
# ContextDecorator was introduced in Python 3.2
|
|
||||||
# See https://docs.python.org/3/library/contextlib.html#contextlib.ContextDecorator
|
|
||||||
class ContextDecorator:
|
|
||||||
"""
|
|
||||||
A base class that enables a context manager to also be used as a decorator.
|
|
||||||
"""
|
|
||||||
def __call__(self, func):
|
|
||||||
@wraps(func, assigned=available_attrs(func))
|
|
||||||
def inner(*args, **kwargs):
|
|
||||||
with self:
|
|
||||||
return func(*args, **kwargs)
|
|
||||||
return inner
|
|
||||||
|
|
||||||
|
|
||||||
class classproperty:
|
class classproperty:
|
||||||
def __init__(self, method=None):
|
def __init__(self, method=None):
|
||||||
self.fget = method
|
self.fget = method
|
||||||
|
|
|
@ -3,13 +3,13 @@ Timezone-related classes and functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
from contextlib import ContextDecorator
|
||||||
from datetime import datetime, timedelta, tzinfo
|
from datetime import datetime, timedelta, tzinfo
|
||||||
from threading import local
|
from threading import local
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.decorators import ContextDecorator
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'utc', 'get_fixed_timezone',
|
'utc', 'get_fixed_timezone',
|
||||||
|
|
|
@ -3,8 +3,8 @@ Internationalization support.
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
|
from contextlib import ContextDecorator
|
||||||
|
|
||||||
from django.utils.decorators import ContextDecorator
|
|
||||||
from django.utils.deprecation import RemovedInDjango21Warning
|
from django.utils.deprecation import RemovedInDjango21Warning
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.functional import lazy
|
from django.utils.functional import lazy
|
||||||
|
|
Loading…
Reference in New Issue