mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 02:43:43 +03:00
.connect() port parameter as string or int (closes: #120).
This commit is contained in:
parent
f88b973bd1
commit
ec865ae932
|
@ -1,5 +1,9 @@
|
|||
2006-09-01 Federico Di Gregorio <fog@initd.org>
|
||||
|
||||
* psycopg/psycopgmodule.c: applied patch from jdahlin (#120)
|
||||
to have .connect() accept either a string or int as the port
|
||||
parameter.
|
||||
|
||||
* psycopg/adapter_binary.c: applied patch from jdahlin (#119)
|
||||
to fix the segfault on empty binary buffers.
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ static PyObject *
|
|||
psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
|
||||
{
|
||||
PyObject *conn, *factory = NULL;
|
||||
PyObject *pyport = NULL;
|
||||
|
||||
int idsn=-1, iport=-1;
|
||||
char *dsn=NULL, *database=NULL, *user=NULL, *password=NULL;
|
||||
|
@ -134,15 +135,28 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
|
|||
"user", "password", "sslmode",
|
||||
"connection_factory", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sssisssO", kwlist,
|
||||
&dsn, &database, &host, &iport,
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|sssOsssO", kwlist,
|
||||
&dsn, &database, &host, &pyport,
|
||||
&user, &password, &sslmode, &factory)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (iport > 0)
|
||||
PyOS_snprintf(port, 16, "%d", iport);
|
||||
|
||||
if (pyport && PyString_Check(pyport)) {
|
||||
PyObject *pyint = PyInt_FromString(PyString_AsString(pyport), NULL, 10);
|
||||
if (!pyint) return NULL;
|
||||
iport = PyInt_AsLong(pyint);
|
||||
}
|
||||
else if (pyport && PyInt_Check(pyport)) {
|
||||
iport = PyInt_AsLong(pyport);
|
||||
}
|
||||
else if (pyport != NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "port must be a string or int");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (iport > 0)
|
||||
PyOS_snprintf(port, 16, "%d", iport);
|
||||
|
||||
if (dsn == NULL) {
|
||||
int l = 45; /* len("dbname= user= password= host= port= sslmode=\0") */
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user