Skip to content

Commit cdec88f

Browse files
committed
support: improve fix for combined Python 2 and 3 support
1 parent 92bc702 commit cdec88f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Xlib/support/connect.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818

1919
import sys
20-
import os
21-
import imp
20+
import importlib
2221

2322
# List the modules which contain the corresponding functions
2423

@@ -49,6 +48,10 @@
4948
del _parts
5049

5150

51+
def _relative_import(modname):
52+
return importlib.import_module('..' + modname, __name__)
53+
54+
5255
def get_display(display):
5356
"""dname, host, dno, screen = get_display(display)
5457
@@ -62,8 +65,7 @@ def get_display(display):
6265
"""
6366

6467
modname = _display_mods.get(platform, _default_display_mod)
65-
mod = imp.load_source(modname, os.path.join(os.path.dirname(__file__), modname + ".py"))
66-
# mod = __import__(modname, globals())
68+
mod = _relative_import(modname)
6769
return mod.get_display(display)
6870

6971

@@ -77,8 +79,7 @@ def get_socket(dname, host, dno):
7779
"""
7880

7981
modname = _socket_mods.get(platform, _default_socket_mod)
80-
mod = imp.load_source(modname, os.path.join(os.path.dirname(__file__), modname + ".py"))
81-
#mod = __import__(modname, globals())
82+
mod = _relative_import(modname)
8283
return mod.get_socket(dname, host, dno)
8384

8485

@@ -93,6 +94,5 @@ def get_auth(sock, dname, host, dno):
9394
"""
9495

9596
modname = _auth_mods.get(platform, _default_auth_mod)
96-
mod = imp.load_source(modname, os.path.join(os.path.dirname(__file__), modname + ".py"))
97-
#mod = __import__(modname, globals())
97+
mod = _relative_import(modname)
9898
return mod.get_auth(sock, dname, host, dno)

0 commit comments

Comments
 (0)