~bennabiy/+junk/python-xlib

« back to all changes in this revision

Viewing changes to Xlib/support/unix_connect.py

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura, Ramkumar Ramachandra, Andrew Shadura
  • Date: 2015-08-13 08:14:19 UTC
  • mfrom: (6.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20150813081419-hdefinnghp2iydkx
Tags: 0.14+20091101-3
[ Ramkumar Ramachandra ]
* Remove useless debugging output (Closes: #565996)

[ Andrew Shadura ]
* Switch to 3.0 (quilt) format.
* Rename patches.
* Use debhelper 9 in its short form.
* Use pybuild.
* Bump Standards-Version.
* Don't build or install PostScript documentation and info files.
* Use system-provided texi2html instead of a shipped version
  (Closes: #795057).
* Update debian/copyright (Closes: #795057).
* Don't install Makefile or texi2html with the documentation.
* Set executable bit for examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
19
import re
20
 
import string
21
20
import os
22
21
import platform
23
22
import socket
60
59
 
61
60
    name = display
62
61
    host = m.group(1)
 
62
    if host == 'unix':
 
63
        host = ''
63
64
    dno = int(m.group(2))
64
65
    screen = m.group(4)
65
66
    if screen:
86
87
        else:
87
88
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
88
89
            s.connect('/tmp/.X11-unix/X%d' % dno)
89
 
    except socket.error, val:
 
90
    except socket.error as val:
90
91
        raise error.DisplayConnectionError(dname, str(val))
91
92
 
92
93
    # Make sure that the connection isn't inherited in child processes
106
107
 
107
108
        # Convert the prettyprinted IP number into 4-octet string.
108
109
        # Sometimes these modules are too damn smart...
109
 
        octets = string.split(sock.getpeername()[0], '.')
110
 
        addr = string.join(map(lambda x: chr(int(x)), octets), '')
 
110
        octets = sock.getpeername()[0].split('.')
 
111
        addr = ''.join(map(lambda x: chr(int(x)), octets))
111
112
    else:
112
113
        family = xauth.FamilyLocal
113
114
        addr = socket.gethostname()
143
144
        #      DISPLAY SCHEME COOKIE
144
145
        # We're interested in the two last parts for the
145
146
        # connection establishment
146
 
        lines = string.split(data, '\n')
 
147
        lines = data.split('\n')
147
148
        if len(lines) >= 1:
148
 
            parts = string.split(lines[0], None, 2)
 
149
            parts = lines[0].split(None, 2)
149
150
            if len(parts) == 3:
150
151
                auth_name = parts[1]
151
152
                hexauth = parts[2]
153
154
 
154
155
                # Translate hexcode into binary
155
156
                for i in range(0, len(hexauth), 2):
156
 
                    auth = auth + chr(string.atoi(hexauth[i:i+2], 16))
 
157
                    auth = auth + chr(int(hexauth[i:i+2], 16))
157
158
 
158
159
                auth_data = auth
159
160
    except os.error:
160
161
        pass
161
162
 
 
163
    if not auth_data and host=='localhost':
 
164
        # 127.0.0.1 counts as FamilyLocal, not FamilyInternet
 
165
        # See Xtransutil.c:ConvertAddress.
 
166
        # There might be more ways to spell 127.0.0.1 but
 
167
        # 'localhost', yet this code fixes a the case of
 
168
        # OpenSSH tunneling X.
 
169
        return get_auth('unix:%d' % dno, 'unix', dno)
 
170
 
162
171
    return auth_name, auth_data
163
172
 
164
173
get_auth = new_get_auth