|
1 | | -# $Id: unix_connect.py,v 1.1 2000-09-06 01:51:34 petli Exp $ |
| 1 | +# $Id: unix_connect.py,v 1.2 2002-03-30 00:14:13 petli Exp $ |
2 | 2 | # |
3 | 3 | # Xlib.support.unix_connect -- Unix-type display connection functions |
4 | 4 | # |
5 | | -# Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se> |
| 5 | +# Copyright (C) 2000,2002 Peter Liljenberg <petli@ctrl-c.liu.se> |
6 | 6 | # |
7 | 7 | # This program is free software; you can redistribute it and/or modify |
8 | 8 | # it under the terms of the GNU General Public License as published by |
|
22 | 22 | import string |
23 | 23 | import os |
24 | 24 | import socket |
| 25 | + |
| 26 | +# FCNTL is deprecated from Python 2.2, so only import it if we doesn't |
| 27 | +# get the names we need. Furthermore, FD_CLOEXEC seems to be missing |
| 28 | +# in Python 2.2. |
| 29 | + |
25 | 30 | import fcntl |
26 | | -import FCNTL |
| 31 | + |
| 32 | +if hasattr(fcntl, 'F_SETFD'): |
| 33 | + F_SETFD = fcntl.F_SETFD |
| 34 | + if hasattr(fcntl, 'FD_CLOEXEC'): |
| 35 | + FD_CLOEXEC = fcntl.FD_CLOEXEC |
| 36 | + else: |
| 37 | + FD_CLOEXEC = 1 |
| 38 | +else: |
| 39 | + from FCNTL import F_SETFD, FD_CLOEXEC |
| 40 | + |
27 | 41 |
|
28 | 42 | from Xlib import error |
29 | 43 |
|
@@ -65,7 +79,7 @@ def get_socket(dname, host, dno): |
65 | 79 | raise error.DisplayConnectionError(dname, str(val)) |
66 | 80 |
|
67 | 81 | # Make sure that the connection isn't inherited in child processes |
68 | | - fcntl.fcntl(s.fileno(), FCNTL.F_SETFD, FCNTL.FD_CLOEXEC) |
| 82 | + fcntl.fcntl(s.fileno(), F_SETFD, FD_CLOEXEC) |
69 | 83 |
|
70 | 84 | return s |
71 | 85 |
|
|
0 commit comments