1919import re
2020import string
2121import os
22+ import platform
2223import socket
2324
2425# FCNTL is deprecated from Python 2.2, so only import it if we doesn't
3940
4041from 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
4452def get_display (display ):
4553 # Use $DISPLAY if display isn't provided
@@ -64,8 +72,13 @@ def get_display(display):
6472
6573def 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
8598def 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