Class decorator that allows the decorated class to be serialized
    by the migrations subsystem.

    The `path` kwarg specifies the import path.
517025
def deconstructible(*args, path=None):
    
    def decorator(klass):
        def __new__(cls, *args, **kwargs):
            # We capture the arguments to make returning them trivial
            obj = super(klass, cls).__new__(cls)
            obj._constructor_args = (args, kwargs)
            return obj
        klass.__new__ = staticmethod(__new__)

        return klass

    if not args:
        return decorator

    return decorator(*args)
652553
def import_class(import_path):
    
    if not '.' in import_path:
        raise IncorrectImportPath(
            "Invalid Python-style import path provided: {0}.".format(
                import_path
            )
        )

    path_bits = import_path.split('.')
    mod_path = '.'.join(path_bits[:-1])
    klass_name = path_bits[-1]

    try:
        mod = importlib.import_module(mod_path)
    except ImportError:
        raise IncorrectImportPath(
            "Could not import module '{0}'.".format(mod_path)
        )

    try:
        klass = getattr(mod, klass_name)
    except AttributeError:
        raise IncorrectImportPath(
            "Imported module '{0}' but could not find class '{1}'.".format(
                mod_path,
                klass_name
            )
        )

    return klass
403177
def from_path(cls, path, origin=MISSING, **kwargs):
        
        origin, relpath = cls._key_from_path(path, origin)

        # Open in binary mode so we can reliably detect the encoding
        with path.open('rb') as f:
            return cls.from_file(f, origin, relpath, **kwargs)
352635
def path_to_reference(path):
    """"""

    # By default JSON decodes strings as unicode. The Python __import__ does
    # not like that choice. So we'll just cast all function paths to a string.
    # NOTE: that there is no corresponding unit test for the classmethod
    # version of this problem.  It only impacts importing modules.
    path = str(path)

    if '.' not in path:
        try:
            return globals()["__builtins__"][path]
        except KeyError:
            try:
                return getattr(globals()["__builtins__"], path)
            except AttributeError:
                pass

        try:
            return globals()[path]
        except KeyError:
            pass

        raise errors.BadObjectPathError(
            'Unable to find function "%s".' % (path,))

    module_path, function_name = path.rsplit('.', 1)

    try:
        module = __import__(name=module_path,
                            fromlist=[function_name])
    except ImportError:
        module_path, class_name = module_path.rsplit('.', 1)

        module = __import__(name=module_path, fromlist=[class_name])
        module = getattr(module, class_name)

    try:
        return getattr(module, function_name)
    except AttributeError:
        raise errors.BadObjectPathError(
            'Unable to find function "%s".' % (path,))
570733
def path_to_module(path, base=nil)
      if base
        path = ::File.expand_path(path, base)
        raise PoisePython::Error.new("Path #{path} is not inside base path #{base}") unless path.start_with?(base)
        path = path[base.length+1..-1]
      end
      path = path[0..-4] if path.end_with?('.py')
      path.gsub(/#{::File::SEPARATOR}/, '.')
    end
684014
def __ConstructRelativePath(self, method_config, request,
                                relative_path=None):
        """"""
        python_param_names = util.MapParamNames(
            method_config.path_params, type(request))
        params = dict([(param, getattr(request, param, None))
                       for param in python_param_names])
        params = util.MapRequestParams(params, type(request))
        return util.ExpandRelativePath(method_config, params,
                                       relative_path=relative_path)
626341
def route(app_or_blueprint, context=default_context, **kwargs):
    
    def decorator(fn):
        fn = describe(**kwargs)(fn)
        transmute_func = TransmuteFunction(fn)
        routes, handler = create_routes_and_handler(transmute_func, context)
        for r in routes:
            # push swagger info.
            if not hasattr(app_or_blueprint, SWAGGER_ATTR_NAME):
                setattr(app_or_blueprint, SWAGGER_ATTR_NAME, SwaggerSpec())
            swagger_obj = getattr(app_or_blueprint, SWAGGER_ATTR_NAME)
            swagger_obj.add_func(transmute_func, context)
            app_or_blueprint.route(r, methods=transmute_func.methods)(handler)
        return handler
    return decorator
2173
def import_field(field_classpath):
    
    if '.' in field_classpath:
        fully_qualified = field_classpath
    else:
        fully_qualified = "django.db.models.%s" % field_classpath
    try:
        return import_dotted_path(fully_qualified)
    except ImportError:
        raise ImproperlyConfigured("The EXTRA_MODEL_FIELDS setting contains "
                                   "the field '%s' which could not be "
                                   "imported." % field_classpath)
1190358
def joinpath(self, *args):
        
        return self.__class__(os.path.join(self, *args))
431308
@PublicAPI(usage = ACCESS)
    public JavaClasses importPaths(Path... paths) {
        return importPaths(ImmutableSet.copyOf(paths));
    }
270677
def get_path(self, path):
        
        mapping = self.get_path_mapping(path)
        return self.path_class(api=self, path=path, mapping=mapping)
837944
def import_module(self, module_path = 'ambry.build', **kwargs):
        
        from fs.errors import NoSysPathError

        if module_path in sys.modules:
            module = sys.modules[module_path]
        else:
            module = imp.new_module(module_path)
            sys.modules[module_path] = module

        bf = self.record

        if not bf.contents:
            return module

        module.__dict__.update(**kwargs)

        try:
            abs_path = self._fs.getsyspath(self.file_name)
        except NoSysPathError:
            abs_path = '<string>'

        import re

        if re.search(r'-\*-\s+coding:', bf.contents):
            # Has encoding, so don't decode
            contents = bf.contents
        else:
            contents = bf.unpacked_contents  # Assumes utf-8

        exec(compile(contents, abs_path, 'exec'), module.__dict__)

        return module
1084527
def _imported_symbol(import_path):
    
    module_name, symbol_name = import_path.rsplit('.', 1)
    module = import_module(module_name)
    return getattr(module, symbol_name)
757980
def import_class(klass):
    
    path = klass.rfind(".")
    class_name = klass[path + 1: len(klass)]
    try:
        module = __import__(klass[0:path], globals(), locals(), [class_name])
        klass = getattr(module, class_name)
    except ImportError as e:
        raise ImportError('%s: %s' % (klass, str(e)))
    except AttributeError:
        raise ImportError(klass)
    else:
        return klass
801588
def migration(resource, version, previous_version=''):
    """"""
    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            migrated = func(*args, **kwargs)

            return migrated

        m = Migration(wrapper, resource, version, previous_version)
        m.register()

        return m

    return decorator
28389
def fileImport(filepath, ignore=None):
        
        basepath, package = EnvManager.packageSplit(filepath)
        if not (basepath and package):
            return None

        # make sure this is not part of the ignored package list
        if ignore and package in ignore:
            return None

        basepath = os.path.normcase(basepath)
        if basepath not in sys.path:
            sys.path.insert(0, basepath)

        logger.debug('Importing: %s' % package)

        try:
            __import__(package)
            module = sys.modules[package]
        except ImportError:
            logger.exception('ImportError: %s' % package)
            return None
        except KeyError:
            logger.exception('Could not find sys.modules package: %s' % package)
            return None
        except StandardError:
            logger.exception('Unknown error occurred not import %s' % package)
            return None

        return module
1295878
def import_from_path(path):
    
    if path is None:
        return

    obj = locate(path)
    if obj is None:
        raise ImportError(
            "`{}` could not be imported".format(path)
        )

    return obj