summaryrefslogtreecommitdiff
path: root/lib/socket_wrapper/socket.py
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2011-10-14 17:24:16 +1100
committerKai Blin <kai@samba.org>2011-11-17 08:42:45 +0100
commitbd8aafc530ba473acefd53665b73a47d1ebbb3a5 (patch)
tree3472039c38fcf4fc54dba0e3ab1612d0dace923e /lib/socket_wrapper/socket.py
parentf7c8af759909e472a5f9dcaa7f738c7151a57afc (diff)
downloadsamba-bd8aafc530ba473acefd53665b73a47d1ebbb3a5.tar.gz
samba-bd8aafc530ba473acefd53665b73a47d1ebbb3a5.tar.bz2
samba-bd8aafc530ba473acefd53665b73a47d1ebbb3a5.zip
socket_wrapper: Added python interface to socket_wrapper
The socket_wrapper does not support setting blocking flag or timeouts on the sockets. To use socket module in python, use from samba import socket Signed-off-by: Kai Blin <kai@samba.org>
Diffstat (limited to 'lib/socket_wrapper/socket.py')
-rw-r--r--lib/socket_wrapper/socket.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/socket_wrapper/socket.py b/lib/socket_wrapper/socket.py
new file mode 100644
index 0000000000..bba96653af
--- /dev/null
+++ b/lib/socket_wrapper/socket.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+#
+# Wrapper for socket wrapper (based on python socket wrapper)
+# Copyright (C) Amitay Isaacs 2011
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import _socket
+from _socket import *
+
+from samba.socket_wrapper import socket
+
+
+def getfqdn(name=''):
+ """Get fully qualified domain name from name.
+
+ An empty argument is interpreted as meaning the local host.
+
+ First the hostname returned by gethostbyaddr() is checked, then
+ possibly existing aliases. In case no FQDN is available, hostname
+ from gethostname() is returned.
+ """
+ name = name.strip()
+ if not name or name == '0.0.0.0':
+ name = gethostname()
+ try:
+ hostname, aliases, ipaddrs = gethostbyaddr(name)
+ except error:
+ pass
+ else:
+ aliases.insert(0, hostname)
+ for name in aliases:
+ if '.' in name:
+ break
+ else:
+ name = hostname
+ return name
+
+
+_GLOBAL_DEFAULT_TIMEOUT = object()