/usr/lib/python2.7/dist-packages/model_mommy/utils.py is in python-model-mommy 1.5.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # -*- coding: utf-8 -*-
import importlib
from six import string_types
def import_if_str(import_string_or_obj):
"""
Import and return an object defined as import string in the form of
path.to.module.object_name
or just return the object if it isn't a string.
"""
if isinstance(import_string_or_obj, string_types):
return import_from_str(import_string_or_obj)
return import_string_or_obj
def import_from_str(import_string):
"""
Import and return an object defined as import string in the form of
path.to.module.object_name
"""
path, field_name = import_string.rsplit('.', 1)
module = importlib.import_module(path)
return getattr(module, field_name)
|