Update of /cvsroot/pywin32/pywin32/win32/Demos/win32wnet
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9900/win32/Demos/win32wnet
Modified Files:
testwnet.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: testwnet.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/win32wnet/testwnet.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** testwnet.py 27 Nov 2008 03:53:25 -0000 1.5
--- testwnet.py 10 Dec 2008 11:13:51 -0000 1.6
***************
*** 1,2 ****
--- 1,3 ----
+ import win32api
import win32wnet
import sys
***************
*** 39,47 ****
print "Finished dumping all resources."
def TestConnection():
if len(possible_shares)==0:
print "Couldn't find any potential shares to connect to"
return
! localName = "Z:" # need better way!
for share in possible_shares:
print "Attempting connection of", localName, "to", share.lpRemoteName
--- 40,65 ----
print "Finished dumping all resources."
+ def findUnusedDriveLetter():
+ existing = [x[0].lower() for x in win32api.GetLogicalDriveStrings().split('\0') if x]
+ handle = win32wnet.WNetOpenEnum(RESOURCE_REMEMBERED,RESOURCETYPE_DISK,0,None)
+ try:
+ while 1:
+ items = win32wnet.WNetEnumResource(handle, 0)
+ if len(items)==0:
+ break
+ xtra = [i.lpLocalName[0].lower() for i in items if i.lpLocalName]
+ existing.extend(xtra)
+ finally:
+ handle.Close()
+ for maybe in 'defghijklmnopqrstuvwxyz':
+ if maybe not in existing:
+ return maybe
+ raise RuntimeError("All drive mappings are taken?")
+
def TestConnection():
if len(possible_shares)==0:
print "Couldn't find any potential shares to connect to"
return
! localName = findUnusedDriveLetter() + ':'
for share in possible_shares:
print "Attempting connection of", localName, "to", share.lpRemoteName
***************
*** 61,66 ****
finally:
win32wnet.WNetCancelConnection2(localName, 0, 0)
! # Only do the first share that succeeds.
! break
def TestGetUser():
--- 79,93 ----
finally:
win32wnet.WNetCancelConnection2(localName, 0, 0)
! # and do it again, but this time by using the more modern
! # NETRESOURCE way.
! nr = win32wnet.NETRESOURCE()
! nr.dwType = share.dwType
! nr.lpLocalName = localName
! nr.lpRemoteName = share.lpRemoteName
! win32wnet.WNetAddConnection2(nr)
! win32wnet.WNetCancelConnection2(localName, 0, 0)
!
! # Only do the first share that succeeds.
! break
def TestGetUser():
|