- Timestamp:
- 09/12/07 15:39:13 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkipplib/trunk/pkipplib/pkipplib.py
r40 r41 491 491 self._curattributes = None 492 492 493 self.setVersion((ord(self._data[0]), ord(self._data[1])))494 self.setOperationId(unpack(">H", self._data[2:4])[0])495 self.setRequestId(unpack(">I", self._data[4:8])[0])496 self.position = 8497 endofattributes = self.tagvalues["end-of-attributes-tag"]498 maxdelimiter = self.tagvalues["event_notification-attributes-tag"]499 nulloffset = lambda : 0500 493 try : 494 self.setVersion((ord(self._data[0]), ord(self._data[1]))) 495 self.setOperationId(unpack(">H", self._data[2:4])[0]) 496 self.setRequestId(unpack(">I", self._data[4:8])[0]) 497 self.position = 8 498 endofattributes = self.tagvalues["end-of-attributes-tag"] 499 maxdelimiter = self.tagvalues["event_notification-attributes-tag"] 500 nulloffset = lambda : 0 501 501 tag = ord(self._data[self.position]) 502 502 while tag != endofattributes : … … 608 608 # it seems it's a unix domain socket. 609 609 # we can't handle this right now, so we use the default instead. 610 return "http://localhost:%s" % port 610 # return "http://localhost:%s" % port 611 return "socket:%s" % server 611 612 else : 612 613 return "http://%s:%s" % (server, port) … … 640 641 returns a new IPPRequest object, containing the parsed answer. 641 642 """ 642 connexion = urllib2.Request(url=url or self.url, \ 643 url = url or self.url 644 connexion = urllib2.Request(url=url, \ 643 645 data=req.dump()) 644 646 connexion.add_header("Content-Type", "application/ipp") … … 652 654 opener = urllib2.build_opener(authhandler) 653 655 urllib2.install_opener(opener) 656 else : # TODO : also do this in the 'if' part 657 if url.startswith("socket:") : 658 class SocketHandler(urllib2.HTTPHandler) : 659 """A class to handle IPP connections over an Unix domain socket.""" 660 def socket_open(self, req) : 661 """Opens an Unix domain socket for IPP.""" 662 req.host = "localhost" 663 req.geturl = lambda : req.get_full_url()[7:] 664 req.info = lambda : "Unix domain socket %s" % req.geturl() 665 req.get_selector = req.geturl 666 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 667 s.connect(req.get_selector()) 668 s.settimeout(5.0) 669 sys.stderr.write("Opened [%s]\n" % req.get_selector()) 670 return s 671 #return s.makefile("r+b") 672 673 opener = urllib2.build_opener(SocketHandler()) 674 urllib2.install_opener(opener) 675 sys.stderr.write("Opener installed\n") 654 676 self.lastError = None 655 677 self.lastErrorMessage = None … … 661 683 return None 662 684 else : 663 datas = response.read() 685 bytes = [] 686 try : 687 try : 688 while True : 689 byte = response.read(1) 690 if not byte : 691 break 692 else : 693 bytes.append(byte) 694 except socket.timeout : 695 pass 696 finally : 697 datas = "".join(bytes) 698 #datas = response.read() 664 699 ippresponse = IPPRequest(datas) 665 700 ippresponse.parse()