X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=python%2Fashd%2Fproto.py;h=e18023dea6e792819e9b9333275ae24ba7bf397a;hb=313bd505f6aa74c239154d7899bcc81a4a06b956;hp=c1ae1b0a2686b5e02df739a3c08fba8eafedd46c;hpb=4d2dc22a9a68395a5788ae66c84ae0ced2d0e733;p=ashd.git diff --git a/python/ashd/proto.py b/python/ashd/proto.py index c1ae1b0..e18023d 100644 --- a/python/ashd/proto.py +++ b/python/ashd/proto.py @@ -10,6 +10,8 @@ ashd.util module provides an easier-to-use interface. import os, socket import htlib +__all__ = ["req", "recvreq", "sendreq"] + class protoerr(Exception): pass @@ -44,12 +46,14 @@ class req(object): self.ver = ver self.rest = rest self.headers = headers - self.sk = socket.fromfd(fd, socket.AF_UNIX, socket.SOCK_STREAM).makefile('r+') + self.bsk = socket.fromfd(fd, socket.AF_UNIX, socket.SOCK_STREAM) + self.sk = self.bsk.makefile('r+') os.close(fd) def close(self): "Close this request's response socket." self.sk.close() + self.bsk.close() def __getitem__(self, header): """Find a HTTP header case-insensitively. For example, @@ -77,7 +81,7 @@ class req(object): """Creates a duplicate of this request, referring to a duplicate of the response socket. """ - return req(self.method, self.url, self.ver, self.rest, self.headers, os.dup(self.sk.fileno())) + return req(self.method, self.url, self.ver, self.rest, self.headers, os.dup(self.bsk.fileno())) def match(self, match): """If the `match' argument matches exactly the leading part of @@ -117,8 +121,8 @@ def recvreq(sock = 0): done, to avoid leaking response sockets. If end-of-file is received on the socket, None is returned. - This function may either raise on OSError if an error occurs on - the socket, or a ashd.proto.protoerr if the incoming request is + This function may either raise an OSError if an error occurs on + the socket, or an ashd.proto.protoerr if the incoming request is invalidly encoded. """ data, fd = htlib.recvfd(sock)