home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / system-config-printer / probe_printer.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2008-10-29  |  3.3 KB  |  140 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import socket
  5. import time
  6.  
  7. class LpdServer:
  8.     
  9.     def __init__(self, hostname):
  10.         self.hostname = hostname
  11.         self.max_lpt_com = 8
  12.  
  13.     
  14.     def _open_socket(self):
  15.         port = 515
  16.         
  17.         try:
  18.             (host, port) = self.hostname.split(':', 1)
  19.         except ValueError:
  20.             host = self.hostname
  21.  
  22.         s = None
  23.         
  24.         try:
  25.             ai = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
  26.         except socket.gaierror:
  27.             ai = []
  28.  
  29.         for res in ai:
  30.             (af, socktype, proto, canonname, sa) = res
  31.             
  32.             try:
  33.                 s = socket.socket(af, socktype, proto)
  34.             except socket.error:
  35.                 msg = None
  36.                 s = None
  37.                 continue
  38.  
  39.             
  40.             try:
  41.                 s.connect(sa)
  42.             except socket.error:
  43.                 msg = None
  44.                 s.close()
  45.                 s = None
  46.                 continue
  47.  
  48.         
  49.         return s
  50.  
  51.     
  52.     def _probe_queue(self, name, result):
  53.         s = self._open_socket()
  54.         if not s:
  55.             return False
  56.         
  57.         print name
  58.         
  59.         try:
  60.             s.send('\x00x02%s\n' % name)
  61.             data = s.recv(1024)
  62.             print repr(data)
  63.         except socket.error:
  64.             msg = None
  65.             print msg
  66.             
  67.             try:
  68.                 s.close()
  69.             except:
  70.                 pass
  71.  
  72.             return False
  73.  
  74.         if len(data) > 0 and data[0] == 0:
  75.             
  76.             try:
  77.                 s.send('\x00x01\n')
  78.                 s.close()
  79.             except:
  80.                 pass
  81.  
  82.             result.append(name)
  83.             return True
  84.         
  85.         
  86.         try:
  87.             s.close()
  88.         except:
  89.             pass
  90.  
  91.         return False
  92.  
  93.     
  94.     def probe(self):
  95.         result = []
  96.         for name in [
  97.             'PASSTHRU',
  98.             'ps',
  99.             'lp',
  100.             'PORT1',
  101.             '']:
  102.             self._probe_queue(name, result)
  103.             time.sleep(0.1)
  104.         
  105.         for nr in range(self.max_lpt_com):
  106.             self._probe_queue('LPT%d' % nr, result)
  107.             time.sleep(0.1)
  108.             self._probe_queue('LPT%d_PASSTHRU' % nr, result)
  109.             time.sleep(0.1)
  110.             self._probe_queue('COM%d' % nr, result)
  111.             time.sleep(0.1)
  112.             self._probe_queue('COM%d_PASSTHRU' % nr, result)
  113.             time.sleep(0.1)
  114.         
  115.         nr = 1
  116.         while nr < 50:
  117.             found = self._probe_queue('pr%d' % nr, result)
  118.             time.sleep(0.1)
  119.             if not found:
  120.                 break
  121.             
  122.             nr += 1
  123.         return result
  124.  
  125.  
  126.  
  127. class SocketServer:
  128.     
  129.     def __init__(self, hostname):
  130.         self.hostname = hostname
  131.  
  132.  
  133.  
  134. class IppServer:
  135.     
  136.     def __init__(self, hostname):
  137.         self.hostname = hostname
  138.  
  139.  
  140.