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.forms.widgets import MediaDefiningClass
from django.template import Context 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 django.template.loader import get_template
from six import with_metaclass from six import with_metaclass
# Allow "component.AlreadyRegistered" instead of having to import these everywhere # Allow "component.AlreadyRegistered" instead of having to import these everywhere
from django_components.component_registry import AlreadyRegistered, ComponentRegistry, NotRegistered # NOQA 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)): class Component(with_metaclass(MediaDefiningClass)):
def context(self): def context(self):

View file

@ -1,10 +1,21 @@
from django import template from django import template
from django.utils.safestring import mark_safe from django.template.base import Node, NodeList, TemplateSyntaxError, token_kwargs
from django.template.base import Node, NodeList, TokenType, TemplateSyntaxError, token_kwargs
from django.template.library import parse_bits from django.template.library import parse_bits
from django.utils.safestring import mark_safe
from django_components.component import registry from django_components.component import registry
# 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
register = template.Library() register = template.Library()
COMPONENT_CONTEXT_KEY = "component_context" COMPONENT_CONTEXT_KEY = "component_context"