mirror of
https://github.com/Hopiu/django-embed-video.git
synced 2026-05-16 00:23:10 +00:00
Move import by path to utils
This commit is contained in:
parent
7e787072ab
commit
9c1149fe22
1 changed files with 1 additions and 38 deletions
|
|
@ -3,15 +3,14 @@ import re
|
|||
import requests
|
||||
import json
|
||||
|
||||
from importlib import import_module
|
||||
|
||||
if sys.version_info >= (3, ):
|
||||
import urllib.parse as urlparse
|
||||
else:
|
||||
import urlparse
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from .utils import import_by_path
|
||||
from .settings import EMBED_VIDEO_BACKENDS
|
||||
|
||||
|
||||
|
|
@ -23,45 +22,9 @@ class UnknownIdException(Exception):
|
|||
pass
|
||||
|
||||
|
||||
def import_by_path(dotted_path, error_prefix=''):
|
||||
"""
|
||||
Import a dotted module path and return the attribute/class designated by
|
||||
the last name in the path. Raise ImproperlyConfigured if something goes
|
||||
wrong.
|
||||
|
||||
.. warning::
|
||||
.. deprecated:: Django 1.6
|
||||
|
||||
Function :py:func:`~django.utils.module_loading.import_by_path`) has
|
||||
been added in Django 1.6.
|
||||
"""
|
||||
try:
|
||||
module_path, class_name = dotted_path.rsplit('.', 1)
|
||||
except ValueError:
|
||||
raise ImproperlyConfigured("%s%s doesn't look like a module path" % (
|
||||
error_prefix, dotted_path))
|
||||
try:
|
||||
module = import_module(module_path)
|
||||
except ImportError as e:
|
||||
msg = '%sError importing module %s: "%s"' % (
|
||||
error_prefix, module_path, e)
|
||||
raise ImproperlyConfigured(msg)
|
||||
try:
|
||||
attr = getattr(module, class_name)
|
||||
except AttributeError:
|
||||
raise ImproperlyConfigured('%sModule "%s" does not define a "%s" \
|
||||
attribute/class' %
|
||||
(error_prefix, module_path, class_name))
|
||||
return attr
|
||||
|
||||
|
||||
def detect_backend(url):
|
||||
"""
|
||||
Detect the right backend for given URL.
|
||||
|
||||
.. todo::
|
||||
|
||||
|
||||
"""
|
||||
|
||||
for backend_name in EMBED_VIDEO_BACKENDS:
|
||||
|
|
|
|||
Loading…
Reference in a new issue