8000 Patch from bug #2002917 to fix display instantiation on OS X 10.5. · python-xlib/python-xlib@f3cc7dc · GitHub
[go: up one dir, main page]

Skip to content

Commit f3cc7dc

Browse files
committed
Patch from bug #2002917 to fix display instantiation on OS X 10.5.
1 parent 95e7bbe commit f3cc7dc

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Xlib/support/unix_connect.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import re
2020
import string
2121
import os
22+
import platform
2223
import socket
2324

2425
# FCNTL is deprecated from Python 2.2, so only import it if we doesn't
@@ -39,7 +40,14 @@
3940

4041
from Xlib import error, xauth
4142

42-
display_re = re.compile(r'^([-a-zA-Z0-9._]*):([0-9]+)(\.([0-9]+))?$')
43+
uname = platform.uname()
44+
if (uname[0] == 'Darwin') and ([int(x) for x in uname[2].split('.')] >= [9, 0]):
45+
46+
display_re = re.compile(r'^([-a-zA-Z0-9._/]*):([0-9]+)(\.([0-9]+))?$')
47+
48+
else:
49+
50+
display_re = re.compile(r'^([-a-zA-Z0-9._]*):([0-9]+)(\.([0-9]+))?$')
4351

4452
def get_display(display):
4553
# Use $DISPLAY if display isn't provided
@@ -64,8 +72,13 @@ def get_display(display):
6472

6573
def get_socket(dname, host, dno):
6674
try:
75+
# Darwin funky socket
76+
if (uname[0] == 'Darwin') and host.startswith('/tmp/'):
77+
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
78+
s.connect(dname)
79+
6780
# If hostname (or IP) is provided, use TCP socket
68-
if host:
81+
elif host:
6982
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7083
s.connect((host, 6000 + dno))
7184

@@ -84,7 +97,11 @@ def get_socket(dname, host, dno):
8497

8598
def new_get_auth(sock, dname, host, dno):
8699
# Translate socket address into the xauth domain
87-
if host:
100+
if (uname[0] == 'Darwin') and host.startswith('/tmp/'):
101+
family = xauth.FamilyLocal
102+
addr = socket.gethostname()
103+
104+
elif host:
88105
family = xauth.FamilyInternet
89106

90107
# Convert the prettyprinted IP number into 4-octet string.

0 commit comments

Comments
 (0)
0