Add backwards compatible getfullargspec and TokenType.

This commit is contained in:
Emil Stenström 2020-06-06 09:29:51 +02:00
parent 00c27f2b3e
commit 9811a88904
2 changed files with 30 additions and 5 deletions

View file

@ -1,14 +1,28 @@
from inspect import getfullargspec
from django.forms.widgets import MediaDefiningClass
from django.template import Context
from django.template.base import NodeList, TokenType, TextNode
from django.template.base import NodeList, TextNode
from django.template.loader import get_template
from six import with_metaclass
# Allow "component.AlreadyRegistered" instead of having to import these everywhere
from django_components.component_registry import AlreadyRegistered, ComponentRegistry, NotRegistered # NOQA
# Python 2 compatibility
try:
from inspect import getfullargspec
except ImportError:
from inspect import getargspec as getfullargspec
# Django < 2.1 compatibility
try:
from django.template.base import TokenType
except ImportError:
from django.template.base import TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
class TokenType:
TEXT = TOKEN_TEXT
VAR = TOKEN_VAR
BLOCK = TOKEN_BLOCK
class Component(with_metaclass(MediaDefiningClass)):
def context(self):