Update of /cvsroot/pywin32/pywin32/win32/src/win32wnet
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv8712/src/win32wnet
Modified Files:
Tag: py3k
Netres.h PyNCB.cpp PyNCB.h PyNetresource.cpp win32wnet.cpp
Log Message:
* re-instate b/w compatible arg list for WNetAddConnection2
* 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: win32wnet.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/win32wnet.cpp,v
retrieving revision 1.13.2.2
retrieving revision 1.13.2.3
diff -C2 -d -r1.13.2.2 -r1.13.2.3
*** win32wnet.cpp 9 Dec 2008 12:38:52 -0000 1.13.2.2
--- win32wnet.cpp 10 Dec 2008 11:01:22 -0000 1.13.2.3
***************
*** 129,134 ****
// @pymethod |win32wnet|WNetAddConnection2|Creates a connection to a network resource. The function can redirect
// a local device to the network resource.
! // @comm This function previously accepted separate parameters to construct a <o PyNETRESOURCE>. It has been
! // changed to accept a NETRESOURCE object instead of the individual elements.
// @comm Accepts keyword arguments.
// @pyseeapi WNetAddConnection2
--- 129,134 ----
// @pymethod |win32wnet|WNetAddConnection2|Creates a connection to a network resource. The function can redirect
// a local device to the network resource.
! // @comm This function also accepts backwards-compatible, positional-only
! // arguments of (dwType, lpLocalName, lpRemoteName[, lpProviderName, Username, Password, flags])
// @comm Accepts keyword arguments.
// @pyseeapi WNetAddConnection2
***************
*** 136,171 ****
{
LPTSTR Username = NULL;
! LPTSTR Password = NULL;
PyObject *obnr, *obPassword=Py_None, *obUsername=Py_None, *ret=NULL;
DWORD ErrorNo; // holds the returned error number, if any
DWORD flags = 0;
! NETRESOURCE * pNetResource;
! static char *keywords[] = {"NetResource","Password","UserName","Flags", NULL};
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOk", keywords,
! &obnr, // @pyparm <o PyNETRESOURCE>|NetResource||Describes the network resource for the connection.
! &obPassword, // @pyparm str|Password|None|The password to use. Use None for default credentials.
! &obUsername, // @pyparm str|UserName|None|The user name to connect as. Use None for default credentials.
! &flags)) // @pyparm int|Flags|0|Combination win32netcon.CONNECT_* flags
! return NULL;
! if (PyWinObject_AsNETRESOURCE(obnr, &pNetResource, FALSE)
! && PyWinObject_AsTCHAR(obPassword, &Password, TRUE)
! && PyWinObject_AsTCHAR(obUsername, &Username, TRUE)){
! Py_BEGIN_ALLOW_THREADS
! #ifdef _WIN32_WCE_ // Windows CE only has the #3 version...use NULL for HWND to simulate #2
! ErrorNo = WNetAddConnection3(NULL, pNetResource, Password, Username, flags);
! #else
! ErrorNo = WNetAddConnection2(pNetResource, Password, Username, flags);
! #endif
! Py_END_ALLOW_THREADS
! if (ErrorNo != NO_ERROR)
! ReturnNetError("WNetAddConnection2", ErrorNo);
! else{
! Py_INCREF(Py_None);
! ret = Py_None;
! }
! }
PyWinObject_FreeTCHAR(Password);
PyWinObject_FreeTCHAR(Username);
return ret;
};
--- 136,196 ----
{
LPTSTR Username = NULL;
! LPTSTR Password = NULL;
! // values used for b/w compat args.
! DWORD Type;
! PyObject *obLocalName, *obRemoteName, *obProviderName = Py_None;
!
PyObject *obnr, *obPassword=Py_None, *obUsername=Py_None, *ret=NULL;
DWORD ErrorNo; // holds the returned error number, if any
DWORD flags = 0;
! NETRESOURCE *pNetResource;
! NETRESOURCE tempNetResource;
! memset(&tempNetResource, 0, sizeof(tempNetResource));
! if (PyArg_ParseTuple(args,"iOO|OOOi",&Type,&obLocalName,&obRemoteName,&obProviderName,&obUsername,&obPassword, &flags)) {
! // the b/w compat args have been used - build the NETRESOURCE structure
! memset((void *)&tempNetResource, '\0', sizeof(NETRESOURCE));
! tempNetResource.dwType = Type;
! if (!PyWinObject_AsTCHAR(obLocalName, &tempNetResource.lpLocalName, TRUE)
! || !PyWinObject_AsTCHAR(obRemoteName, &tempNetResource.lpRemoteName, FALSE)
! || !PyWinObject_AsTCHAR(obProviderName, &tempNetResource.lpProvider, TRUE))
! goto done;
! pNetResource = &tempNetResource;
! } else {
! PyErr_Clear();
! static char *keywords[] = {"NetResource","Password","UserName","Flags", NULL};
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOk", keywords,
! &obnr, // @pyparm <o PyNETRESOURCE>|NetResource||Describes the network resource for the connection.
! &obPassword, // @pyparm str|Password|None|The password to use. Use None for default credentials.
! &obUsername, // @pyparm str|UserName|None|The user name to connect as. Use None for default credentials.
! &flags)) // @pyparm int|Flags|0|Combination win32netcon.CONNECT_* flags
! return NULL;
! if (!PyWinObject_AsNETRESOURCE(obnr, &pNetResource, FALSE))
! return NULL;
! }
!
! if (!PyWinObject_AsTCHAR(obPassword, &Password, TRUE)
! || !PyWinObject_AsTCHAR(obUsername, &Username, TRUE))
! goto done;
!
! Py_BEGIN_ALLOW_THREADS
! #ifdef _WIN32_WCE_ // Windows CE only has the #3 version...use NULL for HWND to simulate #2
! ErrorNo = WNetAddConnection3(NULL, pNetResource, Password, Username, flags);
! #else
! ErrorNo = WNetAddConnection2(pNetResource, Password, Username, flags);
! #endif
! Py_END_ALLOW_THREADS
! if (ErrorNo != NO_ERROR)
! ReturnNetError("WNetAddConnection2", ErrorNo);
! else{
! Py_INCREF(Py_None);
! ret = Py_None;
! }
! done:
PyWinObject_FreeTCHAR(Password);
PyWinObject_FreeTCHAR(Username);
+ PyWinObject_FreeTCHAR(tempNetResource.lpLocalName);
+ PyWinObject_FreeTCHAR(tempNetResource.lpRemoteName);
+ PyWinObject_FreeTCHAR(tempNetResource.lpProvider);
return ret;
};
***************
*** 601,608 ****
// @module win32wnet|A module that exposes the Windows Networking API.
static PyMethodDef win32wnet_functions[] = {
! // @pymeth NETRESOURCE|Creates a new <o NETRESOURCE> object
! {"NETRESOURCE", PyWinMethod_NewNETRESOURCE, 1, "NETRESOURCE Structure Object. x=NETRESOURCE() to instantiate"},
! // @pymeth NCB|Creates a new <o NCB> object
! {"NCB", PyWinMethod_NewNCB, 1, "NCB Netbios command structure Object"},
// @pymeth NCBBuffer|Creates a new buffer
{"NCBBuffer", PyWinMethod_NCBBuffer, 1, "Creates a memory buffer"},
--- 626,631 ----
// @module win32wnet|A module that exposes the Windows Networking API.
static PyMethodDef win32wnet_functions[] = {
! // @pymeth NETRESOURCE|The <o PyNETRESOURCE> type - can be used to create a new <o PyNETRESOURCE> object.
! // @pymeth NCB|The <o PyNCB> type - can be used to create a new <o PyNCB> object.
// @pymeth NCBBuffer|Creates a new buffer
{"NCBBuffer", PyWinMethod_NCBBuffer, 1, "Creates a memory buffer"},
***************
*** 637,641 ****
"A module that exposes the Windows Networking API.");
-
PyDict_SetItemString(dict, "error", PyWinExc_ApiError);
--- 660,663 ----
***************
*** 644,650 ****
--- 666,676 ----
PYWIN_MODULE_INIT_RETURN_ERROR;
+ // old "deprecated" names, before types could create instances.
PyDict_SetItemString(dict, "NETRESOURCEType", (PyObject *)&PyNETRESOURCEType);
PyDict_SetItemString(dict, "NCBType", (PyObject *)&PyNCBType);
+ PyDict_SetItemString(dict, "NETRESOURCE", (PyObject *)&PyNETRESOURCEType);
+ PyDict_SetItemString(dict, "NCB", (PyObject *)&PyNCBType);
+
PYWIN_MODULE_INIT_RETURN_SUCCESS;
}
Index: PyNetresource.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/PyNetresource.cpp,v
retrieving revision 1.3.4.1
retrieving revision 1.3.4.2
diff -C2 -d -r1.3.4.1 -r1.3.4.2
*** PyNetresource.cpp 29 Aug 2008 05:00:24 -0000 1.3.4.1
--- PyNetresource.cpp 10 Dec 2008 11:01:22 -0000 1.3.4.2
***************
*** 36,46 ****
! /* Main PYTHON entry point for creating a new reference. Registered by win32wnet module */
!
! // @pymethod <o PyNETRESOURCE>|win32wnet|NETRESOURCE|Creates a new <o NETRESOURCE> object.
!
! PyObject *PyWinMethod_NewNETRESOURCE(PyObject *self, PyObject *args)
{
! if (!PyArg_ParseTuple(args, ":NETRESOURCE")) // no arguments
return NULL;
return new PyNETRESOURCE(); // call the C++ constructor
--- 36,43 ----
! static PyObject *NETRESOURCE_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
! static char *kwlist[] = {0};
! if (!PyArg_ParseTupleAndKeywords(args, kwds, ":NETRESOURCE", kwlist)) // no arguments
return NULL;
return new PyNETRESOURCE(); // call the C++ constructor
***************
*** 122,126 ****
0, /* tp_init */
0, /* tp_alloc */
! 0, /* tp_new */
};
--- 119,123 ----
0, /* tp_init */
0, /* tp_alloc */
! NETRESOURCE_new, /* tp_new */
};
***************
*** 140,143 ****
--- 137,144 ----
{"lpProvider", T_STRING, OFF(m_nr.lpProvider), 0},// @prop string|provider|
{NULL}
+ // @comm Note that in pywin32-212 and earlier, the string attributes
+ // were always strings, but empty strings when the underlying Windows
+ // structure had NULL. On later pywin32 builds, these string attributes will
+ // return None in such cases.
};
Index: PyNCB.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/PyNCB.h,v
retrieving revision 1.2.4.1
retrieving revision 1.2.4.2
diff -C2 -d -r1.2.4.1 -r1.2.4.2
*** PyNCB.h 29 Aug 2008 05:00:24 -0000 1.2.4.1
--- PyNCB.h 10 Dec 2008 11:01:22 -0000 1.2.4.2
***************
*** 47,52 ****
#define PyNCB_Check(ob) ((ob)->ob_type == &PyNCBType)
- __declspec(dllexport) PyObject *PyWinMethod_NewNCB(PyObject *self, PyObject *args);
-
-
#endif // end of _WIN32_WCE exclude
--- 47,49 ----
Index: PyNCB.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/PyNCB.cpp,v
retrieving revision 1.4.4.1
retrieving revision 1.4.4.2
diff -C2 -d -r1.4.4.1 -r1.4.4.2
*** PyNCB.cpp 29 Aug 2008 05:00:24 -0000 1.4.4.1
--- PyNCB.cpp 10 Dec 2008 11:01:22 -0000 1.4.4.2
***************
*** 37,40 ****
--- 37,51 ----
#include <crtdbg.h>
+ /***************************************************************************
+ ** Create a new NCB Object
+ ***************************************************************************/
+ static PyObject *NCB_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+ {
+ static char *kwlist[] = {0};
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, ":NCB", kwlist)) // no arguments
+ return NULL;
+ return new PyNCB(); // call the C++ constructor
+ }
+
__declspec(dllexport)PyTypeObject PyNCBType =
***************
*** 77,81 ****
0, /* tp_init */
0, /* tp_alloc */
! 0, /* tp_new */
};
--- 88,92 ----
0, /* tp_init */
0, /* tp_alloc */
! NCB_new, /* tp_new */
};
***************
*** 193,207 ****
};
- /***************************************************************************
- ** Create a new NCB Object
- ***************************************************************************/
- // @pymethod <o NCB>|win32wnet|NCB|Creates a new <o NCB> object.
- PyObject *PyWinMethod_NewNCB(PyObject *self, PyObject *args)
- {
- if (!PyArg_ParseTuple(args, ":NCB")) // no arguments
- return NULL;
- return new PyNCB(); // call the C++ constructor
- }
-
/*********************************************************************/
PyObject *PyNCB::getattro(PyObject *self, PyObject *obname)
--- 204,207 ----
***************
*** 211,214 ****
--- 211,217 ----
if (name==NULL)
return NULL;
+ // Our string attributes still need special handling as the NCB isn't
+ // unicode aware.
+ // These 2 string attributes are logically "strings" rather than "bytes"
if (strcmp(name, "Callname") == 0) // these "strings" are not null terminated so build
// a local representation of them and return
***************
*** 217,221 ****
char TempString[17];
TempString[16] = '\0';
! return(PyString_FromString(strncpy((char *)TempString,(char *)This->m_ncb.ncb_callname,NCBNAMSZ)));
}
else if(strcmp(name, "Name") == 0)
--- 220,224 ----
char TempString[17];
TempString[16] = '\0';
! return(PyWinCoreString_FromString(strncpy((char *)TempString,(char *)This->m_ncb.ncb_callname,NCBNAMSZ)));
}
else if(strcmp(name, "Name") == 0)
***************
*** 223,230 ****
char TempString[17];
TempString[16] = '\0';
! return(PyString_FromString(strncpy((char *)TempString,(char *)This->m_ncb.ncb_name,NCBNAMSZ)));
}
else if(strcmp(name, "Buffer") == 0)
{
if (This->m_obuserbuffer != NULL) {
Py_INCREF(This->m_obuserbuffer);
--- 226,234 ----
char TempString[17];
TempString[16] = '\0';
! return(PyWinCoreString_FromString(strncpy((char *)TempString,(char *)This->m_ncb.ncb_name,NCBNAMSZ)));
}
else if(strcmp(name, "Buffer") == 0)
{
+ // This is logically bytes
if (This->m_obuserbuffer != NULL) {
Py_INCREF(This->m_obuserbuffer);
***************
*** 254,259 ****
if (strcmp(name, "Callname") == 0){
char *value;
! Py_ssize_t valuelen;
! if (PyString_AsStringAndSize(v, &value, &valuelen)==-1)
return -1;
if (valuelen > NCBNAMSZ) // cap string length at NCBNAMSZ(16)
--- 258,264 ----
if (strcmp(name, "Callname") == 0){
char *value;
! DWORD valuelen;
!
! if (!PyWinObject_AsString(v, &value, FALSE, &valuelen))
return -1;
if (valuelen > NCBNAMSZ) // cap string length at NCBNAMSZ(16)
***************
*** 264,267 ****
--- 269,273 ----
if (valuelen == 0) // source was null string
This->m_ncb.ncb_callname[0] = '\0';
+ PyWinObject_FreeString(value);
return 0;
}
***************
*** 269,274 ****
if (strcmp(name, "Name") == 0){
char *value;
! Py_ssize_t valuelen;
! if (PyString_AsStringAndSize(v, &value, &valuelen)==-1)
return -1;
if (valuelen > NCBNAMSZ) // cap string length at NCBNAMSZ(16)
--- 275,280 ----
if (strcmp(name, "Name") == 0){
char *value;
! DWORD valuelen;
! if (!PyWinObject_AsString(v, &value, FALSE, &valuelen))
return -1;
if (valuelen > NCBNAMSZ) // cap string length at NCBNAMSZ(16)
***************
*** 279,282 ****
--- 285,289 ----
if (valuelen == 0) // source was null string
This->m_ncb.ncb_callname[0] = '\0';
+ PyWinObject_FreeString(value);
return 0;
}
Index: Netres.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/Netres.h,v
retrieving revision 1.2.4.1
retrieving revision 1.2.4.2
diff -C2 -d -r1.2.4.1 -r1.2.4.2
*** Netres.h 29 Aug 2008 05:00:24 -0000 1.2.4.1
--- Netres.h 10 Dec 2008 11:01:22 -0000 1.2.4.2
***************
*** 54,58 ****
#define PyNETRESOURCE_Check(ob) ((ob)->ob_type == &PyNETRESOURCEType)
- __declspec(dllexport) PyObject *PyWinMethod_NewNETRESOURCE(PyObject *self, PyObject *args);
__declspec(dllexport) BOOL PyWinObject_AsNETRESOURCE(PyObject *ob, NETRESOURCE **ppNetresource, BOOL bNoneOK = TRUE);
__declspec(dllexport) PyObject *PyWinObject_FromNETRESOURCE(const NETRESOURCE *pNetresource);
--- 54,57 ----
|