(root)/
Python-3.11.7/
Modules/
clinic/
_gdbmmodule.c.h
       1  /*[clinic input]
       2  preserve
       3  [clinic start generated code]*/
       4  
       5  PyDoc_STRVAR(_gdbm_gdbm_get__doc__,
       6  "get($self, key, default=None, /)\n"
       7  "--\n"
       8  "\n"
       9  "Get the value for key, or default if not present.");
      10  
      11  #define _GDBM_GDBM_GET_METHODDEF    \
      12      {"get", _PyCFunction_CAST(_gdbm_gdbm_get), METH_FASTCALL, _gdbm_gdbm_get__doc__},
      13  
      14  static PyObject *
      15  _gdbm_gdbm_get_impl(gdbmobject *self, PyObject *key, PyObject *default_value);
      16  
      17  static PyObject *
      18  _gdbm_gdbm_get(gdbmobject *self, PyObject *const *args, Py_ssize_t nargs)
      19  {
      20      PyObject *return_value = NULL;
      21      PyObject *key;
      22      PyObject *default_value = Py_None;
      23  
      24      if (!_PyArg_CheckPositional("get", nargs, 1, 2)) {
      25          goto exit;
      26      }
      27      key = args[0];
      28      if (nargs < 2) {
      29          goto skip_optional;
      30      }
      31      default_value = args[1];
      32  skip_optional:
      33      return_value = _gdbm_gdbm_get_impl(self, key, default_value);
      34  
      35  exit:
      36      return return_value;
      37  }
      38  
      39  PyDoc_STRVAR(_gdbm_gdbm_setdefault__doc__,
      40  "setdefault($self, key, default=None, /)\n"
      41  "--\n"
      42  "\n"
      43  "Get value for key, or set it to default and return default if not present.");
      44  
      45  #define _GDBM_GDBM_SETDEFAULT_METHODDEF    \
      46      {"setdefault", _PyCFunction_CAST(_gdbm_gdbm_setdefault), METH_FASTCALL, _gdbm_gdbm_setdefault__doc__},
      47  
      48  static PyObject *
      49  _gdbm_gdbm_setdefault_impl(gdbmobject *self, PyObject *key,
      50                             PyObject *default_value);
      51  
      52  static PyObject *
      53  _gdbm_gdbm_setdefault(gdbmobject *self, PyObject *const *args, Py_ssize_t nargs)
      54  {
      55      PyObject *return_value = NULL;
      56      PyObject *key;
      57      PyObject *default_value = Py_None;
      58  
      59      if (!_PyArg_CheckPositional("setdefault", nargs, 1, 2)) {
      60          goto exit;
      61      }
      62      key = args[0];
      63      if (nargs < 2) {
      64          goto skip_optional;
      65      }
      66      default_value = args[1];
      67  skip_optional:
      68      return_value = _gdbm_gdbm_setdefault_impl(self, key, default_value);
      69  
      70  exit:
      71      return return_value;
      72  }
      73  
      74  PyDoc_STRVAR(_gdbm_gdbm_close__doc__,
      75  "close($self, /)\n"
      76  "--\n"
      77  "\n"
      78  "Close the database.");
      79  
      80  #define _GDBM_GDBM_CLOSE_METHODDEF    \
      81      {"close", (PyCFunction)_gdbm_gdbm_close, METH_NOARGS, _gdbm_gdbm_close__doc__},
      82  
      83  static PyObject *
      84  _gdbm_gdbm_close_impl(gdbmobject *self);
      85  
      86  static PyObject *
      87  _gdbm_gdbm_close(gdbmobject *self, PyObject *Py_UNUSED(ignored))
      88  {
      89      return _gdbm_gdbm_close_impl(self);
      90  }
      91  
      92  PyDoc_STRVAR(_gdbm_gdbm_keys__doc__,
      93  "keys($self, /)\n"
      94  "--\n"
      95  "\n"
      96  "Get a list of all keys in the database.");
      97  
      98  #define _GDBM_GDBM_KEYS_METHODDEF    \
      99      {"keys", _PyCFunction_CAST(_gdbm_gdbm_keys), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_keys__doc__},
     100  
     101  static PyObject *
     102  _gdbm_gdbm_keys_impl(gdbmobject *self, PyTypeObject *cls);
     103  
     104  static PyObject *
     105  _gdbm_gdbm_keys(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     106  {
     107      if (nargs) {
     108          PyErr_SetString(PyExc_TypeError, "keys() takes no arguments");
     109          return NULL;
     110      }
     111      return _gdbm_gdbm_keys_impl(self, cls);
     112  }
     113  
     114  PyDoc_STRVAR(_gdbm_gdbm_firstkey__doc__,
     115  "firstkey($self, /)\n"
     116  "--\n"
     117  "\n"
     118  "Return the starting key for the traversal.\n"
     119  "\n"
     120  "It\'s possible to loop over every key in the database using this method\n"
     121  "and the nextkey() method.  The traversal is ordered by GDBM\'s internal\n"
     122  "hash values, and won\'t be sorted by the key values.");
     123  
     124  #define _GDBM_GDBM_FIRSTKEY_METHODDEF    \
     125      {"firstkey", _PyCFunction_CAST(_gdbm_gdbm_firstkey), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_firstkey__doc__},
     126  
     127  static PyObject *
     128  _gdbm_gdbm_firstkey_impl(gdbmobject *self, PyTypeObject *cls);
     129  
     130  static PyObject *
     131  _gdbm_gdbm_firstkey(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     132  {
     133      if (nargs) {
     134          PyErr_SetString(PyExc_TypeError, "firstkey() takes no arguments");
     135          return NULL;
     136      }
     137      return _gdbm_gdbm_firstkey_impl(self, cls);
     138  }
     139  
     140  PyDoc_STRVAR(_gdbm_gdbm_nextkey__doc__,
     141  "nextkey($self, key, /)\n"
     142  "--\n"
     143  "\n"
     144  "Returns the key that follows key in the traversal.\n"
     145  "\n"
     146  "The following code prints every key in the database db, without having\n"
     147  "to create a list in memory that contains them all:\n"
     148  "\n"
     149  "      k = db.firstkey()\n"
     150  "      while k is not None:\n"
     151  "          print(k)\n"
     152  "          k = db.nextkey(k)");
     153  
     154  #define _GDBM_GDBM_NEXTKEY_METHODDEF    \
     155      {"nextkey", _PyCFunction_CAST(_gdbm_gdbm_nextkey), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_nextkey__doc__},
     156  
     157  static PyObject *
     158  _gdbm_gdbm_nextkey_impl(gdbmobject *self, PyTypeObject *cls, const char *key,
     159                          Py_ssize_t key_length);
     160  
     161  static PyObject *
     162  _gdbm_gdbm_nextkey(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     163  {
     164      PyObject *return_value = NULL;
     165      static const char * const _keywords[] = {"", NULL};
     166      static _PyArg_Parser _parser = {"s#:nextkey", _keywords, 0};
     167      const char *key;
     168      Py_ssize_t key_length;
     169  
     170      if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
     171          &key, &key_length)) {
     172          goto exit;
     173      }
     174      return_value = _gdbm_gdbm_nextkey_impl(self, cls, key, key_length);
     175  
     176  exit:
     177      return return_value;
     178  }
     179  
     180  PyDoc_STRVAR(_gdbm_gdbm_reorganize__doc__,
     181  "reorganize($self, /)\n"
     182  "--\n"
     183  "\n"
     184  "Reorganize the database.\n"
     185  "\n"
     186  "If you have carried out a lot of deletions and would like to shrink\n"
     187  "the space used by the GDBM file, this routine will reorganize the\n"
     188  "database.  GDBM will not shorten the length of a database file except\n"
     189  "by using this reorganization; otherwise, deleted file space will be\n"
     190  "kept and reused as new (key,value) pairs are added.");
     191  
     192  #define _GDBM_GDBM_REORGANIZE_METHODDEF    \
     193      {"reorganize", _PyCFunction_CAST(_gdbm_gdbm_reorganize), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_reorganize__doc__},
     194  
     195  static PyObject *
     196  _gdbm_gdbm_reorganize_impl(gdbmobject *self, PyTypeObject *cls);
     197  
     198  static PyObject *
     199  _gdbm_gdbm_reorganize(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     200  {
     201      if (nargs) {
     202          PyErr_SetString(PyExc_TypeError, "reorganize() takes no arguments");
     203          return NULL;
     204      }
     205      return _gdbm_gdbm_reorganize_impl(self, cls);
     206  }
     207  
     208  PyDoc_STRVAR(_gdbm_gdbm_sync__doc__,
     209  "sync($self, /)\n"
     210  "--\n"
     211  "\n"
     212  "Flush the database to the disk file.\n"
     213  "\n"
     214  "When the database has been opened in fast mode, this method forces\n"
     215  "any unwritten data to be written to the disk.");
     216  
     217  #define _GDBM_GDBM_SYNC_METHODDEF    \
     218      {"sync", _PyCFunction_CAST(_gdbm_gdbm_sync), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _gdbm_gdbm_sync__doc__},
     219  
     220  static PyObject *
     221  _gdbm_gdbm_sync_impl(gdbmobject *self, PyTypeObject *cls);
     222  
     223  static PyObject *
     224  _gdbm_gdbm_sync(gdbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     225  {
     226      if (nargs) {
     227          PyErr_SetString(PyExc_TypeError, "sync() takes no arguments");
     228          return NULL;
     229      }
     230      return _gdbm_gdbm_sync_impl(self, cls);
     231  }
     232  
     233  PyDoc_STRVAR(dbmopen__doc__,
     234  "open($module, filename, flags=\'r\', mode=0o666, /)\n"
     235  "--\n"
     236  "\n"
     237  "Open a dbm database and return a dbm object.\n"
     238  "\n"
     239  "The filename argument is the name of the database file.\n"
     240  "\n"
     241  "The optional flags argument can be \'r\' (to open an existing database\n"
     242  "for reading only -- default), \'w\' (to open an existing database for\n"
     243  "reading and writing), \'c\' (which creates the database if it doesn\'t\n"
     244  "exist), or \'n\' (which always creates a new empty database).\n"
     245  "\n"
     246  "Some versions of gdbm support additional flags which must be\n"
     247  "appended to one of the flags described above.  The module constant\n"
     248  "\'open_flags\' is a string of valid additional flags.  The \'f\' flag\n"
     249  "opens the database in fast mode; altered data will not automatically\n"
     250  "be written to the disk after every change.  This results in faster\n"
     251  "writes to the database, but may result in an inconsistent database\n"
     252  "if the program crashes while the database is still open.  Use the\n"
     253  "sync() method to force any unwritten data to be written to the disk.\n"
     254  "The \'s\' flag causes all database operations to be synchronized to\n"
     255  "disk.  The \'u\' flag disables locking of the database file.\n"
     256  "\n"
     257  "The optional mode argument is the Unix mode of the file, used only\n"
     258  "when the database has to be created.  It defaults to octal 0o666.");
     259  
     260  #define DBMOPEN_METHODDEF    \
     261      {"open", _PyCFunction_CAST(dbmopen), METH_FASTCALL, dbmopen__doc__},
     262  
     263  static PyObject *
     264  dbmopen_impl(PyObject *module, PyObject *filename, const char *flags,
     265               int mode);
     266  
     267  static PyObject *
     268  dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     269  {
     270      PyObject *return_value = NULL;
     271      PyObject *filename;
     272      const char *flags = "r";
     273      int mode = 438;
     274  
     275      if (!_PyArg_CheckPositional("open", nargs, 1, 3)) {
     276          goto exit;
     277      }
     278      filename = args[0];
     279      if (nargs < 2) {
     280          goto skip_optional;
     281      }
     282      if (!PyUnicode_Check(args[1])) {
     283          _PyArg_BadArgument("open", "argument 2", "str", args[1]);
     284          goto exit;
     285      }
     286      Py_ssize_t flags_length;
     287      flags = PyUnicode_AsUTF8AndSize(args[1], &flags_length);
     288      if (flags == NULL) {
     289          goto exit;
     290      }
     291      if (strlen(flags) != (size_t)flags_length) {
     292          PyErr_SetString(PyExc_ValueError, "embedded null character");
     293          goto exit;
     294      }
     295      if (nargs < 3) {
     296          goto skip_optional;
     297      }
     298      mode = _PyLong_AsInt(args[2]);
     299      if (mode == -1 && PyErr_Occurred()) {
     300          goto exit;
     301      }
     302  skip_optional:
     303      return_value = dbmopen_impl(module, filename, flags, mode);
     304  
     305  exit:
     306      return return_value;
     307  }
     308  /*[clinic end generated code: output=617117d16956ac4d input=a9049054013a1b77]*/