diff options
-rw-r--r-- | ryu/services/protocols/bgp/application.py | 6 | ||||
-rw-r--r-- | ryu/utils.py | 19 |
2 files changed, 22 insertions, 3 deletions
diff --git a/ryu/services/protocols/bgp/application.py b/ryu/services/protocols/bgp/application.py index a1f4291b..14279c4e 100644 --- a/ryu/services/protocols/bgp/application.py +++ b/ryu/services/protocols/bgp/application.py @@ -15,14 +15,14 @@ """ Defines bases classes to create a BGP application. """ -import imp import logging import traceback + from oslo_config import cfg from ryu.lib import hub +from ryu.utils import load_source from ryu.base.app_manager import RyuApp - from ryu.services.protocols.bgp.api.base import call from ryu.services.protocols.bgp.base import add_bgp_error_metadata from ryu.services.protocols.bgp.base import BGPSException @@ -138,7 +138,7 @@ class RyuBGPSpeaker(RyuApp): # Check if file can be read try: - return imp.load_source('settings', config_file) + return load_source('settings', config_file) except Exception as e: raise ApplicationException(desc=str(e)) diff --git a/ryu/utils.py b/ryu/utils.py index 3f6260ef..57eb9b0a 100644 --- a/ryu/utils.py +++ b/ryu/utils.py @@ -36,9 +36,28 @@ import os import sys import re +import six + LOG = logging.getLogger('ryu.utils') +def load_source(name, pathname): + """ + This function provides the backward compatibility for 'imp.load_source' + in Python 2. + + :param name: Name used to create or access a module object. + :param pathname: Path pointing to the source file. + :return: Loaded and initialized module. + """ + if six.PY2: + import imp + return imp.load_source(name, pathname) + else: + loader = importlib.machinery.SourceFileLoader(name, pathname) + return loader.load_module(name) + + def chop_py_suffix(p): for suf in ['.py', '.pyc', '.pyo']: if p.endswith(suf): |