mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-18 14:10:30 +00:00
Fix import pycountry on python 3.12 without warning
Fix shadowed "babel" name
This commit is contained in:
parent
2617fa8af4
commit
d0e166140f
@ -34,7 +34,7 @@ from .cli import CliParameter
|
|||||||
from .reverseproxy import ReverseProxied
|
from .reverseproxy import ReverseProxied
|
||||||
from .server import WebServer
|
from .server import WebServer
|
||||||
from .dep_check import dependency_check
|
from .dep_check import dependency_check
|
||||||
from .babel import babel, get_locale
|
# from .babel import babel, get_locale
|
||||||
from .updater import Updater
|
from .updater import Updater
|
||||||
from . import config_sql
|
from . import config_sql
|
||||||
from . import cache_buster
|
from . import cache_buster
|
||||||
@ -182,6 +182,7 @@ def create_app():
|
|||||||
app.secret_key = os.getenv('SECRET_KEY', config_sql.get_flask_session_key(ub.session))
|
app.secret_key = os.getenv('SECRET_KEY', config_sql.get_flask_session_key(ub.session))
|
||||||
|
|
||||||
web_server.init_app(app, config)
|
web_server.init_app(app, config)
|
||||||
|
from .cw_babel import babel, get_locale
|
||||||
if hasattr(babel, "localeselector"):
|
if hasattr(babel, "localeselector"):
|
||||||
babel.init_app(app)
|
babel.init_app(app)
|
||||||
babel.localeselector(get_locale)
|
babel.localeselector(get_locale)
|
||||||
|
@ -42,10 +42,8 @@ opt = dep_check.load_dependencies(True)
|
|||||||
for i in (req + opt):
|
for i in (req + opt):
|
||||||
modules[i[1]] = i[0]
|
modules[i[1]] = i[0]
|
||||||
modules['Jinja2'] = importlib.metadata.version("jinja2")
|
modules['Jinja2'] = importlib.metadata.version("jinja2")
|
||||||
try:
|
if sys.version_info < (3, 12):
|
||||||
modules['pySqlite'] = sqlite3.version
|
modules['pySqlite'] = sqlite3.version
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
modules['SQLite'] = sqlite3.sqlite_version
|
modules['SQLite'] = sqlite3.sqlite_version
|
||||||
sorted_modules = OrderedDict((sorted(modules.items(), key=lambda x: x[0].casefold())))
|
sorted_modules = OrderedDict((sorted(modules.items(), key=lambda x: x[0].casefold())))
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ from .gdriveutils import is_gdrive_ready, gdrive_support
|
|||||||
from .render_template import render_title_template, get_sidebar_config
|
from .render_template import render_title_template, get_sidebar_config
|
||||||
from .services.worker import WorkerThread
|
from .services.worker import WorkerThread
|
||||||
from .usermanagement import user_login_required
|
from .usermanagement import user_login_required
|
||||||
from .babel import get_available_translations, get_available_locale, get_user_locale_language
|
from .cw_babel import get_available_translations, get_available_locale, get_user_locale_language
|
||||||
from . import debug_info
|
from . import debug_info
|
||||||
from .string_helper import strip_whitespaces
|
from .string_helper import strip_whitespaces
|
||||||
|
|
||||||
|
@ -25,26 +25,14 @@ log = logger.create()
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from iso639 import languages
|
|
||||||
# iso_version = importlib.metadata.version("iso639")
|
|
||||||
get = languages.get
|
|
||||||
try:
|
|
||||||
if sys.version_info >= (3, 12):
|
|
||||||
import pkg_resources
|
|
||||||
except ImportError:
|
|
||||||
print("Python 3.12 isn't compatible with iso-639. Please install pycountry.")
|
|
||||||
except ImportError as ex:
|
|
||||||
from pycountry import languages as pyc_languages
|
from pycountry import languages as pyc_languages
|
||||||
#try:
|
|
||||||
# iso_version = importlib.metadata.version("pycountry") + ' (PyCountry)'
|
|
||||||
#except (ImportError, Exception):
|
|
||||||
# iso_version = "?" + ' (PyCountry)'
|
|
||||||
|
|
||||||
def _copy_fields(l):
|
def _copy_fields(l):
|
||||||
l.part1 = getattr(l, 'alpha_2', None)
|
l.part1 = getattr(l, 'alpha_2', None)
|
||||||
l.part3 = getattr(l, 'alpha_3', None)
|
l.part3 = getattr(l, 'alpha_3', None)
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
|
||||||
def get(name=None, part1=None, part3=None):
|
def get(name=None, part1=None, part3=None):
|
||||||
if part3 is not None:
|
if part3 is not None:
|
||||||
return _copy_fields(pyc_languages.get(alpha_3=part3))
|
return _copy_fields(pyc_languages.get(alpha_3=part3))
|
||||||
@ -52,6 +40,11 @@ except ImportError as ex:
|
|||||||
return _copy_fields(pyc_languages.get(alpha_2=part1))
|
return _copy_fields(pyc_languages.get(alpha_2=part1))
|
||||||
if name is not None:
|
if name is not None:
|
||||||
return _copy_fields(pyc_languages.get(name=name))
|
return _copy_fields(pyc_languages.get(name=name))
|
||||||
|
except ImportError as ex:
|
||||||
|
if sys.version_info >= (3, 12):
|
||||||
|
print("Python 3.12 isn't compatible with iso-639. Please install pycountry.")
|
||||||
|
from iso639 import languages
|
||||||
|
get = languages.get
|
||||||
|
|
||||||
|
|
||||||
def get_language_names(locale):
|
def get_language_names(locale):
|
||||||
|
@ -52,7 +52,7 @@ from .helper import check_valid_domain, check_email, check_username, \
|
|||||||
edit_book_read_status, valid_password
|
edit_book_read_status, valid_password
|
||||||
from .pagination import Pagination
|
from .pagination import Pagination
|
||||||
from .redirect import get_redirect_location
|
from .redirect import get_redirect_location
|
||||||
from .babel import get_available_locale
|
from .cw_babel import get_available_locale
|
||||||
from .usermanagement import login_required_if_no_ano
|
from .usermanagement import login_required_if_no_ano
|
||||||
from .kobo_sync_status import remove_synced_book
|
from .kobo_sync_status import remove_synced_book
|
||||||
from .render_template import render_title_template
|
from .render_template import render_title_template
|
||||||
|
Loading…
Reference in New Issue
Block a user