2 Unix SMB/CIFS implementation.
3 Samba utility functions
5 Copyright (C) Catalyst IT 2017
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "lib/replace/system/python.h"
21 #include "librpc/gen_ndr/lsa.h"
23 static PyObject
*py_lsa_String_str(PyObject
*py_self
)
25 struct lsa_String
*self
= pytalloc_get_ptr(py_self
);
27 if (self
->string
== NULL
) {
28 const char *empty
= "";
29 ret
= PyUnicode_FromString(empty
);
31 ret
= PyUnicode_FromString(self
->string
);
36 static PyObject
*py_lsa_String_repr(PyObject
*py_self
)
38 struct lsa_String
*self
= pytalloc_get_ptr(py_self
);
40 if (self
->string
== NULL
) {
41 const char *empty
= "lsaString(None)";
42 ret
= PyUnicode_FromString(empty
);
44 ret
= PyUnicode_FromFormat("lsaString('%s')", self
->string
);
49 static int py_lsa_String_init(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
51 struct lsa_String
*string
= pytalloc_get_ptr(self
);
52 const char *str
= NULL
;
53 const char *kwnames
[] = { "str", NULL
};
55 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|s", discard_const_p(char *, kwnames
), &str
))
58 string
->string
= talloc_strdup(string
, str
);
60 if (str
!= NULL
&& string
->string
== NULL
) {
69 static void py_lsa_String_patch(PyTypeObject
*type
)
71 type
->tp_init
= py_lsa_String_init
;
72 type
->tp_str
= py_lsa_String_str
;
73 type
->tp_repr
= py_lsa_String_repr
;
76 #define PY_STRING_PATCH py_lsa_String_patch