1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-13 13:15:53 +01:00

Sorted out mime initialization.

Every mime related function in main __init__.py has a flag check for the
check if initialization has already done. This is nonsense, since it
should be done implicitly early on the converter is starting.

This commit straight the things out, and initialization is done in cli
module.

Also, function guess_type was removed, since it's just a proxy for
mimetypes.guess_type function.
This commit is contained in:
2020-06-14 15:41:18 +02:00
parent b23a59f223
commit 1465e4267f
22 changed files with 94 additions and 112 deletions

View File

@@ -1,12 +1,10 @@
import math
import os
import pkg_resources
import random
import re
import sys
import time
import urllib.parse
import urllib.request
import mimetypes
from functools import partial
@@ -28,35 +26,17 @@ if False:
fcntl, win32event, isfrozen, __author__
winerror, win32api, isbsd, config_dir
_mt_inited = False
def _init_mimetypes():
global _mt_inited
import mimetypes
def init_mimetypes():
mimetypes.init([pkg_resources.resource_filename('ebook_converter',
'data/mime.types')])
_mt_inited = True
def guess_type(*args, **kwargs):
import mimetypes
if not _mt_inited:
_init_mimetypes()
return mimetypes.guess_type(*args, **kwargs)
def guess_all_extensions(*args, **kwargs):
import mimetypes
if not _mt_inited:
_init_mimetypes()
return mimetypes.guess_all_extensions(*args, **kwargs)
def guess_extension(*args, **kwargs):
import mimetypes
if not _mt_inited:
_init_mimetypes()
ext = mimetypes.guess_extension(*args, **kwargs)
if not ext and args and args[0] == 'application/x-palmreader':
ext = '.pdb'
@@ -64,9 +44,6 @@ def guess_extension(*args, **kwargs):
def get_types_map():
import mimetypes
if not _mt_inited:
_init_mimetypes()
return mimetypes.types_map