Changeset 21 for pkipplib/trunk
- Timestamp:
- 06/02/06 21:10:02 (18 years ago)
- Location:
- pkipplib/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pkipplib/trunk/pkipplib/pkipplib.py
r18 r21 25 25 import sys 26 26 import urllib2 27 import socket 27 28 from struct import pack, unpack 28 29 … … 293 294 debug : a boolean value to output debug info on stderr. 294 295 """ 295 self.url = url 296 if url.endswith("/") : 297 url = url[:-1] 298 self.url = url.replace("ipp://", "http://") 296 299 self.username = username 297 300 self.password = password … … 299 302 self._data = data 300 303 self.parsed = False 304 self.error = None 301 305 302 306 # Initializes message … … 571 575 if not samerequestid : 572 576 self.nextRequestId() 573 cx = urllib2.Request(url=url or self.url or "http://localhost:631/", 577 578 url = url or self.url or "http://localhost:631" 579 cx = urllib2.Request(url=url, \ 574 580 data=self.dump()) 575 581 cx.add_header("Content-Type", "application/ipp") 576 response = urllib2.urlopen(cx) 577 datas = response.read() 578 ippresponse = IPPRequest(datas) 579 ippresponse.parse() 580 return ippresponse 582 583 username = username or self.username 584 password = password or self.password 585 if username : 586 password = password or "" 587 pwmanager = urllib2.HTTPPasswordMgrWithDefaultRealm() 588 pwmanager.add_password(None, \ 589 "%s%s" % (cx.get_host(), cx.get_selector()), \ 590 username, \ 591 password) 592 authhandler = urllib2.HTTPBasicAuthHandler(pwmanager) 593 opener = urllib2.build_opener(authhandler) 594 urllib2.install_opener(opener) 595 596 try : 597 response = urllib2.urlopen(cx) 598 except (urllib2.HTTPError, socket.error), error : 599 self.error = error 600 return None 601 else : 602 self.error = None 603 datas = response.read() 604 ippresponse = IPPRequest(datas) 605 ippresponse.parse() 606 return ippresponse 581 607 582 608 -
pkipplib/trunk/pkipplib/version.py
r14 r21 21 21 # 22 22 23 __version__ = "0.0 3"23 __version__ = "0.04" 24 24 25 25 __doc__ = "pkipplib : IPP and CUPS support for Python." -
pkipplib/trunk/README
r19 r21 109 109 from pkipplib import pkipplib 110 110 111 # By default, connects to http://localhost:631 111 # Create a CUPS client instance 112 # cups = pkipplib.CUPS(url="http://server:631", username="john", password="blah!") 112 113 cups = pkipplib.CUPS() 113 114 -
pkipplib/trunk/tests/test.py
r13 r21 26 26 import pkipplib 27 27 28 cups = pkipplib.CUPS() 29 answer = cups.getPPD("HL6050DN") 30 #answer = cups.getJobAttributes(566) 28 # cups = pkipplib.CUPS() 29 cups = pkipplib.CUPS(url="http://localhost:631", \ 30 username="jerome", \ 31 password="9!kijd.7") 32 # answer = cups.getPPD("HP2100") 33 answer = cups.getJobAttributes(150) 34 31 35 print answer 36 32 37 #print answer.operation["attributes-charset"] 33 38