[pywin32-checkins] pywin32/win32/Demos/win32wnet testwnet.py, 1.2, 1.2.4.1
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2008-08-29 04:59:45
|
Update of /cvsroot/pywin32/pywin32/win32/Demos/win32wnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15490/Demos/win32wnet Modified Files: Tag: py3k testwnet.py Log Message: Changes to build for Python 3.0 Index: testwnet.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/Demos/win32wnet/testwnet.py,v retrieving revision 1.2 retrieving revision 1.2.4.1 diff -C2 -d -r1.2 -r1.2.4.1 *** testwnet.py 9 Feb 2001 07:25:57 -0000 1.2 --- testwnet.py 29 Aug 2008 04:59:25 -0000 1.2.4.1 *************** *** 1,5 **** import win32wnet import sys ! from winnetwk import * import os --- 1,5 ---- import win32wnet import sys ! from .winnetwk import * import os *************** *** 15,34 **** try: if item.dwDisplayType == RESOURCEDISPLAYTYPE_SHARE: ! print indent + "Have share with name:", item.lpRemoteName possible_shares.append(item) elif item.dwDisplayType == RESOURCEDISPLAYTYPE_GENERIC: ! print indent + "Have generic resource with name:", item.lpRemoteName else: # Try generic! ! print indent + "Enumerating " + item.lpRemoteName, k = win32wnet.WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY,0,item) ! print _doDumpHandle(k, level + 1) win32wnet.WNetCloseEnum(k) # could do k.Close(), but this is a good test! ! except win32wnet.error, details: ! print indent + "Couldn't enumerate this resource: " + details[2] def TestOpenEnum(): ! print "Enumerating all resources on the network - this may take some time..." handle = win32wnet.WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,None) --- 15,34 ---- try: if item.dwDisplayType == RESOURCEDISPLAYTYPE_SHARE: ! print(indent + "Have share with name:", item.lpRemoteName) possible_shares.append(item) elif item.dwDisplayType == RESOURCEDISPLAYTYPE_GENERIC: ! print(indent + "Have generic resource with name:", item.lpRemoteName) else: # Try generic! ! print(indent + "Enumerating " + item.lpRemoteName, end=' ') k = win32wnet.WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY,0,item) ! print() _doDumpHandle(k, level + 1) win32wnet.WNetCloseEnum(k) # could do k.Close(), but this is a good test! ! except win32wnet.error as details: ! print(indent + "Couldn't enumerate this resource: " + details[2]) def TestOpenEnum(): ! print("Enumerating all resources on the network - this may take some time...") handle = win32wnet.WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,None) *************** *** 37,53 **** finally: handle.Close() ! 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 try: win32wnet.WNetAddConnection2(share.dwType, localName, share.lpRemoteName) ! except win32wnet.error, details: ! print "Couldn't connect: " + details[2] continue # Have a connection. --- 37,53 ---- finally: handle.Close() ! 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) try: win32wnet.WNetAddConnection2(share.dwType, localName, share.lpRemoteName) ! except win32wnet.error as details: ! print("Couldn't connect: " + details[2]) continue # Have a connection. *************** *** 55,62 **** fname = os.path.join(localName + "\\", os.listdir(localName + "\\")[0]) try: ! print "Universal name of '%s' is '%s'" % (fname, win32wnet.WNetGetUniversalName(fname)) ! except win32wnet.error, details: ! print "Couldn't get universal name of '%s': %s" % (fname, details[2]) ! print "User name for this connection is", win32wnet.WNetGetUser(localName) finally: win32wnet.WNetCancelConnection2(localName, 0, 0) --- 55,62 ---- fname = os.path.join(localName + "\\", os.listdir(localName + "\\")[0]) try: ! print("Universal name of '%s' is '%s'" % (fname, win32wnet.WNetGetUniversalName(fname))) ! except win32wnet.error as details: ! print("Couldn't get universal name of '%s': %s" % (fname, details[2])) ! print("User name for this connection is", win32wnet.WNetGetUser(localName)) finally: win32wnet.WNetCancelConnection2(localName, 0, 0) *************** *** 66,72 **** def TestGetUser(): u = win32wnet.WNetGetUser() ! print "Current global user is", `u` if u != win32wnet.WNetGetUser(None): ! raise RuntimeError, "Default value didnt seem to work!" TestGetUser() --- 66,72 ---- def TestGetUser(): u = win32wnet.WNetGetUser() ! print("Current global user is", repr(u)) if u != win32wnet.WNetGetUser(None): ! raise RuntimeError("Default value didnt seem to work!") TestGetUser() |