Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with Python 3.10+ and Django 3+ #54

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions django_babel/extract.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# -*- coding: utf-8 -*-
from django.template.base import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
from django.template.base import Lexer, TokenType
from django.utils.translation import trim_whitespace
from django.utils.encoding import smart_text
from django.utils.translation.template import inline_re, block_re, endblock_re, plural_re, constant_re

try:
from django.utils.translation.trans_real import (
inline_re, block_re, endblock_re, plural_re, constant_re)
except ImportError:
# Django 1.11+
from django.utils.translation.template import (
inline_re, block_re, endblock_re, plural_re, constant_re)
TOKEN_TEXT = TokenType.TEXT
TOKEN_VAR = TokenType.VAR
TOKEN_BLOCK = TokenType.BLOCK


def join_tokens(tokens, trim=False):
Expand Down Expand Up @@ -48,13 +45,7 @@ def extract_django(fileobj, keywords, comment_tags, options):

encoding = options.get('encoding', 'utf8')
text = fileobj.read().decode(encoding)

try:
text_lexer = Lexer(text)
except TypeError:
# Django 1.9 changed the way we invoke Lexer; older versions
# require two parameters.
text_lexer = Lexer(text, None)
text_lexer = Lexer(text)

for t in text_lexer.tokenize():
lineno += t.contents.count('\n')
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ def read(*parts):
name='django-babel',
description='Utilities for using Babel in Django',
long_description=read('README.rst') + u'\n\n' + read('CHANGELOG.rst'),
version='0.6.3.dev0',
version='0.6.3',
license='BSD',
author='Christopher Grebs',
author_email='[email protected]',
maintainer='Thomas Grainger',
maintainer_email='[email protected]',
url='https://github.com/python-babel/django-babel/',
maintainer='Nikita Grygoriev',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are replacing the maintainer etc. here. This also changes the URL, not sure that is intended?

maintainer_email='[email protected]',
url='https://github.com/nikitagrygoriev/django-babel',
packages=find_packages(exclude=('tests',)),
install_requires=[
'django>=1.8,<3.0',
'django>=1.8',
'babel>=1.3',
],
classifiers=[
Expand Down