1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
# -*- coding: utf-8 -*-
# Taken from: http://www.openpanel.com/2007/08/http-on-unix-sockets-with-python/
"""
This module allows us to communicate using http over standard unix sockets.
"""
#external imports
import socket
try:
import httplib
except ImportError:
import http.client
httplib = http.client
#internal imports
#import ...
class UHTTPConnection(httplib.HTTPConnection):
"""
Subclass of Python library HTTPConnection that uses a unix-domain socket.
"""
def __init__(self, path):
httplib.HTTPConnection.__init__(self, 'localhost')
self.path = path
def connect(self):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(self.path)
self.sock = sock
|