signature: Add keyword argument parsing to Signature().
Now you can specify `encoding` without bothering with `time` or `offset`.
This commit is contained in:
@@ -36,32 +36,26 @@
|
|||||||
int
|
int
|
||||||
Signature_init(Signature *self, PyObject *args, PyObject *kwds)
|
Signature_init(Signature *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
|
const char *keywords[] = {
|
||||||
|
"name", "email", "time", "offset", "encoding", NULL};
|
||||||
PyObject *py_name;
|
PyObject *py_name;
|
||||||
char *name, *email, *encoding = NULL;
|
char *name, *email, *encoding = "ascii";
|
||||||
long long time;
|
long long time = -1;
|
||||||
int offset;
|
int offset = 0;
|
||||||
int err;
|
int err;
|
||||||
git_signature *signature;
|
git_signature *signature;
|
||||||
|
|
||||||
if (kwds) {
|
if (!PyArg_ParseTupleAndKeywords(
|
||||||
PyErr_SetString(PyExc_TypeError,
|
args, kwds, "Os|Lis", keywords,
|
||||||
"Signature takes no keyword arguments");
|
&py_name, &email, &time, &offset, &encoding))
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "Os|Lis",
|
|
||||||
&py_name, &email, &time, &offset, &encoding))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
name = py_str_to_c_str(py_name, encoding);
|
name = py_str_to_c_str(py_name, encoding);
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (PySequence_Length(args) == 2) {
|
if (time == -1) {
|
||||||
err = git_signature_now(&signature, name, email);
|
err = git_signature_now(&signature, name, email);
|
||||||
} else if (PySequence_Length(args) == 3) {
|
|
||||||
PyErr_SetString(PyExc_TypeError, "offset must be specified with time");
|
|
||||||
return -1;
|
|
||||||
} else {
|
} else {
|
||||||
err = git_signature_new(&signature, name, email, time, offset);
|
err = git_signature_new(&signature, name, email, time, offset);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user