File: uhttpConnection.py

package info (click to toggle)
subuser 0.6.2-3
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 4,208 kB
  • sloc: python: 5,201; sh: 380; makefile: 73
file content (30 lines) | stat: -rwxr-xr-x 713 bytes parent folder | download
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