LCOV - code coverage report
Current view: top level - source4/librpc/ndr - py_lsa.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 29 32 90.6 %
Date: 2021-09-23 10:06:22 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Samba utility functions
       4             : 
       5             :    Copyright (C) Catalyst IT 2017
       6             : 
       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.
      11             : 
      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.
      16             : 
      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/>.
      19             : */
      20             : #include <Python.h>
      21             : #include "librpc/gen_ndr/lsa.h"
      22             : 
      23         961 : static PyObject *py_lsa_String_str(PyObject *py_self)
      24             : {
      25         961 :         struct lsa_String *self = pytalloc_get_ptr(py_self);
      26         961 :         PyObject *ret = NULL;
      27         961 :         if (self->string == NULL) {
      28           1 :                 const char *empty = "";
      29           1 :                 ret = PyUnicode_FromString(empty);
      30             :         } else {
      31         960 :                 ret = PyUnicode_FromString(self->string);
      32             :         }
      33         961 :         return ret;
      34             : }
      35             : 
      36          22 : static PyObject *py_lsa_String_repr(PyObject *py_self)
      37             : {
      38          22 :         struct lsa_String *self = pytalloc_get_ptr(py_self);
      39          22 :         PyObject *ret = NULL;
      40          22 :         if (self->string == NULL) {
      41           1 :                 const char *empty = "lsaString(None)";
      42           1 :                 ret = PyUnicode_FromString(empty);
      43             :         } else {
      44          21 :                 ret = PyUnicode_FromFormat("lsaString('%s')", self->string);
      45             :         }
      46          22 :         return ret;
      47             : }
      48             : 
      49         316 : static int py_lsa_String_init(PyObject *self, PyObject *args, PyObject *kwargs)
      50             : {
      51         316 :         struct lsa_String *string = pytalloc_get_ptr(self);
      52         316 :         const char *str = NULL;
      53         316 :         const char *kwnames[] = { "str", NULL };
      54             : 
      55         316 :         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", discard_const_p(char *, kwnames), &str))
      56           0 :                 return -1;
      57             : 
      58         316 :         string->string = talloc_strdup(string, str);
      59             : 
      60         316 :         if (str != NULL && string->string == NULL) {
      61           0 :                 PyErr_NoMemory();
      62           0 :                 return -1;
      63             :         }
      64             : 
      65         309 :         return 0;
      66             : }
      67             : 
      68             : 
      69        4727 : static void py_lsa_String_patch(PyTypeObject *type)
      70             : {
      71        4898 :         type->tp_init = py_lsa_String_init;
      72        4898 :         type->tp_str = py_lsa_String_str;
      73        4898 :         type->tp_repr = py_lsa_String_repr;
      74        4727 : }
      75             : 
      76             : #define PY_STRING_PATCH py_lsa_String_patch
      77             : 

Generated by: LCOV version 1.13