/[thuban]/branches/WIP-pyshapelib-bramz/libraries/pyshapelib/dbflibmodule.c
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/libraries/pyshapelib/dbflibmodule.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2742 by bramz, Wed Mar 14 16:26:14 2007 UTC revision 2744 by bramz, Thu Mar 15 13:48:58 2007 UTC
# Line 43  static int dbffile_init(DBFFileObject* s Line 43  static int dbffile_init(DBFFileObject* s
43                  PyErr_Format(PyExc_TypeError, "dbflib.DBFFile.__init__ takes no keyword arguments");                  PyErr_Format(PyExc_TypeError, "dbflib.DBFFile.__init__ takes no keyword arguments");
44                  return -1;                  return -1;
45          }          }
46          if (!PyArg_ParseTuple(args, "s|s", &file, &mode)) return -1;  
47            if (!PyArg_ParseTuple(args, "et|s:__init__", Py_FileSystemDefaultEncoding, &file, &mode)) return -1;
48                    
49          self->handle = DBFOpen(file, mode);          self->handle = DBFOpen(file, mode);
50            PyMem_Free(file);
51            
52          return self->handle ? 0 : -1;          return self->handle ? 0 : -1;
53  }  }
54    
# Line 79  static PyObject* dbffile_field_info(DBFF Line 82  static PyObject* dbffile_field_info(DBFF
82          char field_name[12];          char field_name[12];
83          int field, width = 0, decimals = 0, field_type;          int field, width = 0, decimals = 0, field_type;
84                    
85          if (!PyArg_ParseTuple(args, "i", &field)) return NULL;          if (!PyArg_ParseTuple(args, "i:field_info", &field)) return NULL;
86                    
87          field_name[0] = '\0';          field_name[0] = '\0';
88          field_type = DBFGetFieldInfo(self->handle, field, field_name, &width, &decimals);          field_type = DBFGetFieldInfo(self->handle, field, field_name, &width, &decimals);
# Line 95  static PyObject* dbffile_add_field(DBFFi Line 98  static PyObject* dbffile_add_field(DBFFi
98          int type, width, decimals;          int type, width, decimals;
99          int field;          int field;
100                    
101          if (!PyArg_ParseTuple(args, "siii", &name, &type, &width, &decimals)) return NULL;          if (!PyArg_ParseTuple(args, "siii:add_field", &name, &type, &width, &decimals)) return NULL;
102                    
103          field = DBFAddField(self->handle, name, (DBFFieldType)type, width, decimals);          field = DBFAddField(self->handle, name, (DBFFieldType)type, width, decimals);
104                    
# Line 170  static PyObject* dbffile_read_attribute( Line 173  static PyObject* dbffile_read_attribute(
173  {  {
174          int record, field;          int record, field;
175    
176          if (!PyArg_ParseTuple(args, "ii", &record, &field)) return NULL;          if (!PyArg_ParseTuple(args, "ii:read_field", &record, &field)) return NULL;
177                    
178          if (record < 0 || record >= DBFGetRecordCount(self->handle))          if (record < 0 || record >= DBFGetRecordCount(self->handle))
179          {          {
# Line 206  static PyObject* dbffile_read_record(DBF Line 209  static PyObject* dbffile_read_record(DBF
209          PyObject *dict;          PyObject *dict;
210          PyObject *value = NULL;          PyObject *value = NULL;
211    
212          if (!PyArg_ParseTuple(args, "i", &record)) return NULL;          if (!PyArg_ParseTuple(args, "i:read_record", &record)) return NULL;
213    
214          if (record < 0 || record >= DBFGetRecordCount(self->handle))          if (record < 0 || record >= DBFGetRecordCount(self->handle))
215          {          {
# Line 312  static PyObject* dbffile_write_field(DBF Line 315  static PyObject* dbffile_write_field(DBF
315          PyObject* value;          PyObject* value;
316          int type;          int type;
317    
318          if (!PyArg_ParseTuple(args, "iiO", &record, &field, &value)) return NULL;          if (!PyArg_ParseTuple(args, "iiO:write_field", &record, &field, &value)) return NULL;
319                    
320          if (field < 0 || field >= DBFGetFieldCount(self->handle))          if (field < 0 || field >= DBFGetFieldCount(self->handle))
321          {          {
# Line 339  static PyObject* dbffile_write_record(DB Line 342  static PyObject* dbffile_write_record(DB
342          char name[12];          char name[12];
343          PyObject* value = NULL;          PyObject* value = NULL;
344                    
345          if (!PyArg_ParseTuple(args, "iO", &record, &record_object)) return NULL;          if (!PyArg_ParseTuple(args, "iO:write_record", &record, &record_object)) return NULL;
346                    
347          num_fields = DBFGetFieldCount(self->handle);          num_fields = DBFGetFieldCount(self->handle);
348                    
# Line 418  static PyObject* dbffile_commit(DBFFileO Line 421  static PyObject* dbffile_commit(DBFFileO
421    
422  static struct PyMethodDef dbffile_methods[] =  static struct PyMethodDef dbffile_methods[] =
423  {  {
424          {"close", (PyCFunction)dbffile_close, METH_NOARGS, "close DBFFile"},          {"close", (PyCFunction)dbffile_close, METH_NOARGS,
425          {"field_count", (PyCFunction)dbffile_field_count, METH_NOARGS, "return number of fields currently defined"},                  "close()\n"
426          {"record_count", (PyCFunction)dbffile_record_count, METH_NOARGS, "return number of records that currently exist"},                  "close DBFFile"},
427          {"field_info", (PyCFunction)dbffile_field_info, METH_VARARGS,          {"field_count", (PyCFunction)dbffile_field_count, METH_NOARGS,
428                    "field_count()\n"
429                    "returns number of fields currently defined"},
430            {"record_count", (PyCFunction)dbffile_record_count, METH_NOARGS,
431                    "record_count()\n"
432                    "returns number of records that currently exist"},
433            {"field_info", (PyCFunction)dbffile_field_info, METH_VARARGS,
434                    "field_info(field_index)\n"
435                  "returns info of a field as a tuple (type, name, width, decimals) with:\n"                  "returns info of a field as a tuple (type, name, width, decimals) with:\n"
436                  "-type: the type of the field corresponding to the integer value of one of the constants FTString, FTInteger, ...\n"                  "-type: the type of the field corresponding to the integer value of one of the constants FTString, FTInteger, ...\n"
437                  "-name: the name of the field as a string\n"                  "-name: the name of the field as a string\n"
438                  "-width: the width of the field as a number of characters\n"                  "-width: the width of the field as a number of characters\n"
439                  "-decimals: the number of decimal digits" },                  "-decimals: the number of decimal digits" },
440          {"add_field", (PyCFunction)dbffile_add_field, METH_VARARGS,          {"add_field", (PyCFunction)dbffile_add_field, METH_VARARGS,
441                    "add_field(type, name, width, decimals)\n"
442                  "adds a new field and returns field index if successful\n"                  "adds a new field and returns field index if successful\n"
443                  "-type: the type of the field corresponding to the integer value of one of the constants FTString, FTInteger, ...\n"                  "-type: the type of the field corresponding to the integer value of one of the constants FTString, FTInteger, ...\n"
444                  "-name: the name of the field as a string\n"                  "-name: the name of the field as a string\n"
445                  "-width: the width of the field as a number of characters\n"                  "-width: the width of the field as a number of characters\n"
446                  "-decimals: the number of decimal digits" },                  "-decimals: the number of decimal digits" },
447          {"read_attribute", (PyCFunction)dbffile_read_attribute, METH_VARARGS, "return the value of one field of a record"},          {"read_attribute", (PyCFunction)dbffile_read_attribute, METH_VARARGS,
448          {"read_record", (PyCFunction)dbffile_read_record, METH_VARARGS, "return an entire record as a dict of field names and values"},                  "read_attribute(record_index, field_index)\n"
449          {"write_field", (PyCFunction)dbffile_write_field, METH_VARARGS, "write a single field of a record"},                  "return the value of one field of a record"},
450          {"write_record", (PyCFunction)dbffile_write_record, METH_VARARGS, "write an entire record as a dict or a sequence"},          {"read_record", (PyCFunction)dbffile_read_record, METH_VARARGS,
451                    "read_record(record_index)\n"
452                    "return an entire record as a dict of field names and values"},
453            {"write_field", (PyCFunction)dbffile_write_field, METH_VARARGS,
454                    "write_field(record_index, field_index, new_value)\n"
455                    "write a single field of a record"},
456            {"write_record", (PyCFunction)dbffile_write_record, METH_VARARGS,
457                    "write_record(record_index, record)\n"
458                    "write an entire record as a dict or a sequence\n"
459                    "record can either be a dictionary in which case the keys are used as field names, "
460                    "or a sequence that must have an item for every field (length = field_count())"},
461  #if HAVE_UPDATE_HEADER  #if HAVE_UPDATE_HEADER
462          {"commit", (PyCFunction)dbffile_read_record, METH_NOARGS, NULL},          {"commit", (PyCFunction)dbffile_read_record, METH_NOARGS,
463                    "commit()"},
464  #endif  #endif
465          {NULL}          {NULL}
466  };  };
# Line 470  static PyObject* dbflib_create(PyObject* Line 492  static PyObject* dbflib_create(PyObject*
492          char* file;          char* file;
493          DBFFileObject* result;          DBFFileObject* result;
494                    
495          if (!PyArg_ParseTuple(args, "s", &file)) return NULL;          if (!PyArg_ParseTuple(args, "et:create", Py_FileSystemDefaultEncoding, &file)) return NULL;
496                    
497          result = PyObject_New(DBFFileObject, &DBFFileType);          result = PyObject_New(DBFFileObject, &DBFFileType);
498          if (!result)          if (!result)
# Line 493  static PyObject* dbflib_create(PyObject* Line 515  static PyObject* dbflib_create(PyObject*
515    
516  static struct PyMethodDef dbflib_methods[] =  static struct PyMethodDef dbflib_methods[] =
517  {  {
518          {"open", (PyCFunction)dbflib_open, METH_VARARGS, "open a DBFFile" },          {"open", (PyCFunction)dbflib_open, METH_VARARGS,
519          {"create", (PyCFunction)dbflib_create, METH_VARARGS, "create a DBFFile" },                  "open(filename [, mode])\n"
520                    "open a DBFFile" },
521            {"create", (PyCFunction)dbflib_create, METH_VARARGS,
522                    "create(filename)\n"
523                    "create a DBFFile" },
524          {NULL}          {NULL}
525  };  };
526    

Legend:
Removed from v.2742  
changed lines
  Added in v.2744

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26