[pywin32-checkins] pywin32/win32/Lib netbios.py,1.6,1.7
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-12-10 11:13:56
|
Update of /cvsroot/pywin32/pywin32/win32/Lib In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9900/win32/Lib Modified Files: netbios.py Log Message: Modernization of win32wnet, via the py3k branch: * Move to getattro/setattro * Add support for WNetAddConnection2 taking a NETRESOURCE as the first param. * Add tp_new slots for the type, so the type can be used in-place of global functions. * Replace NCB and NETRESOURCE methods with the actual types. * Treat CallName and Name attributes as true strings. * Many more tests. Index: netbios.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Lib/netbios.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** netbios.py 27 Nov 2008 06:40:00 -0000 1.6 --- netbios.py 10 Dec 2008 11:13:51 -0000 1.7 *************** *** 1,2 **** --- 1,3 ---- + import sys import win32wnet import struct *************** *** 257,260 **** --- 258,268 ---- return NCBStruct(ACTION_HEADER_ITEMS) + def byte_to_int(b): + """Given an element in a binary buffer, return its integer value""" + if sys.version_info >= (3,0): + # a byte is already an int in py3k + return b + return ord(b) # its a char from a string in py2k. + if __name__=='__main__': # code ported from "HOWTO: Get the MAC Address for an Ethernet Adapter" *************** *** 269,279 **** ncb.Reset() ncb.Command = NCBRESET ! ncb.Lana_num = ord(la_enum.lana[i]) rc = Netbios(ncb) if rc != 0: raise RuntimeError("Unexpected result %d" % (rc,)) ncb.Reset() ncb.Command = NCBASTAT ! ncb.Lana_num = ord(la_enum.lana[i]) ! ncb.Callname = "* " adapter = ADAPTER_STATUS() ncb.Buffer = adapter --- 277,287 ---- ncb.Reset() ncb.Command = NCBRESET ! ncb.Lana_num = byte_to_int(la_enum.lana[i]) rc = Netbios(ncb) if rc != 0: raise RuntimeError("Unexpected result %d" % (rc,)) ncb.Reset() ncb.Command = NCBASTAT ! ncb.Lana_num = byte_to_int(la_enum.lana[i]) ! ncb.Callname = "* ".encode("ascii") # ensure bytes on py2x and 3k adapter = ADAPTER_STATUS() ncb.Buffer = adapter *************** *** 281,284 **** print "Adapter address:", for ch in adapter.adapter_address: ! print "%02x" % (ord(ch),) , print --- 289,292 ---- print "Adapter address:", for ch in adapter.adapter_address: ! print "%02x" % (byte_to_int(ch),) , print |