4 # A python module that maps printerdata to a dictionary. We define
5 # two classes. The printerdata class maps to Get/Set/Enum/DeletePrinterData
6 # and the printerdata_ex class maps to Get/Set/Enum/DeletePrinterDataEx
12 # - Implement __delitem__
15 from samba import spoolss
18 def __init__(self, host, creds = {}, access = 0x02000000):
19 # For read access, use MAXIMUM_ALLOWED_ACCESS = 0x02000000
20 # For write access, use PRINTER_ACCESS_ADMINISTER = 0x00000004
21 self.hnd = spoolss.openprinter(host, creds = creds, access = access)
24 return self.hnd.enumprinterdata().keys()
26 def __getitem__(self, key):
27 return self.hnd.getprinterdata(key)['data']
29 def __setitem__(self, key, value):
30 # Store as REG_BINARY for now
31 self.hnd.setprinterdata({"key": "", "value": key, "type": 3,
35 def __init__(self, host, creds = {}, access = 0x02000000):
36 # For read access, use MAXIMUM_ALLOWED_ACCESS = 0x02000000
37 # For write access, use PRINTER_ACCESS_ADMINISTER = 0x00000004
39 self.top_level_keys = ["PrinterDriverData", "DsSpooler", "DsDriver",
45 return self.top_level_keys
47 def has_key(self, key):
48 for k in self.top_level_keys:
53 class printerdata_ex_subkey:
54 def __init__(self, host, key, creds, access):
55 self.hnd = spoolss.openprinter(host, creds, access)
59 return self.hnd.enumprinterdataex(self.key).keys()
61 def __getitem__(self, key):
62 return self.hnd.getprinterdataex(self.key, key)['data']
64 def __getitem__(self, key):
65 return self.printerdata_ex_subkey(
66 self.host, key, self.creds, self.access)