{"id":437,"date":"2015-03-06T23:20:09","date_gmt":"2015-03-07T07:20:09","guid":{"rendered":"http:\/\/www.isam.ca\/?p=437"},"modified":"2015-03-21T16:49:23","modified_gmt":"2015-03-21T23:49:23","slug":"d-isam-python-module","status":"publish","type":"post","link":"https:\/\/www.isam.ca\/?p=437","title":{"rendered":"D-ISAM Python module"},"content":{"rendered":"<p>This Python module imports D-ISAM as a shared library, and exports three classes.<\/p>\n<p><strong>d7<\/strong> class exports the D-ISAM library itself, and adds &#8220;constant&#8221; values for the standard ISAM defines &#8211; for example <code>d7.isOpen( \"myfile\", d7.ISINOUT + d7.ISAUTOLOCK )<\/code><\/p>\n<p><strong>d7error<\/strong> is a python Exception class, for example <code>raise d7error( isam, \"message text\" )<\/code><\/p>\n<p><strong>d7key<\/strong> is a <code>ctypes<\/code> Structure class, and provides an instance of an ISAM key descriptor.<\/p>\n<p>An example of usage can be found <a href=\"http:\/\/www.isam.ca\/?p=442\">here<\/a><\/p>\n<p>An overview is available <a href=\"http:\/\/www.isam.ca\/?p=434\">here<\/a><\/p>\n<p>Download the module <a title=\"D-ISAM Python module\" href=\"http:\/\/www.isam.ca\/?download=588\">here<\/a><\/p>\n<pre>#!\/bin\/python\r\n\r\nfrom ctypes import CDLL, Structure, c_void_p, c_char_p, c_int, c_short, c_uint\r\n\r\nd7 = CDLL( \"libdisam72.so\" )\r\n\r\n# disam 'constant' values\r\n\r\nd7.ISMAXPARTS = 20\r\nd7.ISINPUT = 0x00\r\nd7.ISOUTPUT = 0x01\r\nd7.ISINOUT = 0x02\r\nd7.ISTRANS = 0x04\r\nd7.ISNOLOG = 0x08\r\nd7.ISFIXLEN = 0x00\r\nd7.ISVARLEN = 0x10\r\nd7.ISVARCMP = 0x30\r\nd7.ISSYNCWR = 0x40\r\nd7.ISMASKED = 0x80\r\nd7.ISNOCARE = 0x8000\r\nd7.ISRDONLY = 0x100\r\nd7.ISAUTOLOCK = 0x200\r\nd7.ISMANULOCK = 0x400\r\nd7.ISEXCLLOCK = 0x800\r\nd7.ISSEMILOCK = 0x1000\r\nd7.ISFIRST = 0\r\nd7.ISLAST = 1\r\nd7.ISNEXT = 2\r\nd7.ISPREV = 3\r\nd7.ISCURR = 4\r\nd7.ISEQUAL = 5\r\nd7.ISGREAT = 6\r\nd7.ISGTEQ = 7\r\nd7.CHARTYPE = 0\r\nd7.DECIMALTYPE = 0\r\nd7.INTTYPE = 1\r\nd7.LONGTYPE = 2\r\nd7.DOUBLETYPE = 3\r\nd7.FLOATTYPE = 4\r\nd7.MINTTYPE = 5\r\nd7.MLONGTYPE = 6\r\nd7.STRINGTYPE = 7\r\nd7.ISDESC = 0x80\r\nd7.CHARSIZE = 1\r\nd7.INTSIZE = 2\r\nd7.LONGSIZE = 4\r\nd7.DOUBLESIZE = 8\r\nd7.FLOATSIZE = 4\r\nd7.MINTSIZE = 2\r\nd7.MLONGSIZE = 4\r\nd7.STRINGSIZE = 1\r\nd7.ISNODUPS = 0x00\r\nd7.ISDUPS = 0x01\r\nd7.DCOMPRESS = 0x02\r\nd7.LCOMPRESS = 0x04\r\nd7.TCOMPRESS = 0x08\r\nd7.COMPRESS = 0x0E\r\nd7.TNULL = 0x10\r\nd7.NULLKEY = 0x20\r\nd7.ISLOCK = 0x100\r\nd7.ISSKIPLOCK = 0x200\r\nd7.ISWAIT = 0x400\r\nd7.ISLCKW = 0x500\r\nd7.ISKEEPLOCK = 0x800\r\nd7.AUDSETNAME = 0\r\nd7.AUDGETNAME = 1\r\nd7.AUDSTART = 2\r\nd7.AUDSTOP = 3\r\nd7.AUDINFO = 4\r\nd7.USERINFOSIZE = 10\r\n\r\n# disam functions return and argument definitions\r\n\r\nd7.isIndexInfo.restype = c_int\r\nd7.isIndexInfo.argtypes = [ c_void_p, c_void_p, c_int ]\r\n\r\nd7.isIsamInfo.restype = c_int\r\nd7.isIsamInfo.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isErase.restype = c_int\r\nd7.isErase.argtypes = [ c_char_p ]\r\n\r\nd7.isRename.restype = c_int\r\nd7.isRename.argtypes = [ c_char_p, c_char_p ]\r\n\r\nd7.isCluster.restype = c_void_p\r\nd7.isCluster.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isClone.restype = c_void_p\r\nd7.isClone.argtypes = [ c_void_p, c_char_p ]\r\n\r\nd7.isCopy.restype = c_int\r\nd7.isCopy.argtypes = [ c_void_p, c_void_p, c_void_p ]\r\n\r\nd7.isBuild.restype = c_void_p\r\nd7.isBuild.argtypes = [ c_char_p, c_int, c_int, c_void_p, c_int ]\r\n\r\nd7.isPrecious.restype = c_int\r\nd7.isPrecious.argtypes = [ c_void_p, c_int ]\r\n\r\nd7.isAddIndex.restype = c_int\r\nd7.isAddIndex.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isDelIndex.restype = c_int\r\nd7.isDelIndex.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isUserInfo.restype = c_int\r\nd7.isUserInfo.argtypes = [ c_void_p, c_int, c_char_p ]\r\n\r\nd7.isOpen.restype = c_void_p\r\nd7.isOpen.argtypes = [ c_char_p, c_int ]\r\n\r\nd7.isClose.restype = c_int\r\nd7.isClose.argtypes = [ c_void_p ]\r\n\r\nd7.isLockCheck.restype = c_int\r\nd7.isLockCheck.argtypes = [ c_void_p, c_int ]\r\n\r\nd7.isSetMode.restype = c_int\r\nd7.isSetMode.argtypes = [ c_void_p, c_int ]\r\n\r\nd7.isWrite.restype = c_int\r\nd7.isWrite.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isWrLock.restype = c_int\r\nd7.isWrLock.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isWrCurr.restype = c_int\r\nd7.isWrCurr.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isRewrite.restype = c_int\r\nd7.isRewrite.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isRewCurr.restype = c_int\r\nd7.isRewCurr.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isRewRec.restype = c_int\r\nd7.isRewRec.argtypes = [ c_void_p, c_uint, c_void_p ]\r\n\r\nd7.isRewNxt.restype = c_int\r\nd7.isRewNxt.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isRead.restype = c_int\r\nd7.isRead.argtypes = [ c_void_p, c_void_p, c_int ]\r\n\r\nd7.isStart.restype = c_int\r\nd7.isStart.argtypes = [ c_void_p, c_void_p, c_int, c_void_p, c_int ]\r\n\r\nd7.isIndex.restype = c_int\r\nd7.isIndex.argtypes = [ c_void_p, c_int ]\r\n\r\nd7.isGoto.restype = c_int\r\nd7.isGoto.argtypes = [ c_void_p, c_uint ]\r\n\r\nd7.isPush.restype = c_int\r\nd7.isPush.argtypes = [ c_void_p, c_void_p, c_void_p ]\r\n\r\nd7.isPop.restype = c_int\r\nd7.isPop.argtypes = [ c_void_p, c_int, c_uint ]\r\n\r\nd7.isData.restype = c_int\r\nd7.isData.argtypes = [ c_void_p, c_void_p, c_uint ]\r\n\r\nd7.isLock.restype = c_int\r\nd7.isLock.argtypes = [ c_void_p ]\r\n\r\nd7.isUnLock.restype = c_int\r\nd7.isUnLock.argtypes = [ c_void_p ]\r\n\r\nd7.isRelease.restype = c_int\r\nd7.isRelease.argtypes = [ c_void_p ]\r\n\r\nd7.isRelRec.restype = c_int\r\nd7.isRelRec.argtypes = [ c_void_p, c_uint ]\r\n\r\nd7.isRelCurr.restype = c_int\r\nd7.isRelCurr.argtypes = [ c_void_p ]\r\n\r\nd7.isDelete.restype = c_int\r\nd7.isDelete.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isDelCurr.restype = c_int\r\nd7.isDelCurr.argtypes = [ c_void_p ]\r\n\r\nd7.isDelRec.restype = c_int\r\nd7.isDelRec.argtypes = [ c_void_p, c_uint ]\r\n\r\nd7.isErrno.restype = c_int\r\nd7.isErrno.argtypes = [ c_void_p ]\r\n\r\nd7.isErrio.restype = c_int\r\nd7.isErrio.argtypes = [ c_void_p ]\r\n\r\nd7.isCount.restype = c_int\r\nd7.isCount.argtypes = [ c_void_p ]\r\n\r\nd7.isRecnum.restype = c_int\r\nd7.isRecnum.argtypes = [ c_void_p ]\r\n\r\nd7.isReclen.restype = c_int\r\nd7.isReclen.argtypes = [ c_void_p ]\r\n\r\nd7.isSetrec.restype = c_int\r\nd7.isSetrec.argtypes = [ c_void_p, c_uint ]\r\n\r\nd7.isSetlen.restype = c_int\r\nd7.isSetlen.argtypes = [ c_void_p, c_short ]\r\n\r\nd7.isLdSchema.restype = c_int\r\nd7.isLdSchema.argtypes = [ c_void_p, c_char_p ]\r\n\r\nd7.isDpSchema.restype = c_int\r\nd7.isDpSchema.argtypes = [ c_void_p ]\r\n\r\nd7.isStSchema.restype = c_int\r\nd7.isStSchema.argtypes = [ c_void_p, c_char_p ]\r\n\r\nd7.isRmSchema.restype = c_int\r\nd7.isRmSchema.argtypes = [ c_void_p ]\r\n\r\nd7.isSetUnique.restype = c_int\r\nd7.isSetUnique.argtypes = [ c_void_p, c_uint ]\r\n\r\nd7.isUniqueId.restype = c_int\r\nd7.isUniqueId.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isGetLastRec.restype = c_int\r\nd7.isGetLastRec.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isSetLastRec.restype = c_int\r\nd7.isSetLastRec.argtypes = [ c_void_p, c_uint ]\r\n\r\nd7.isLastRec.restype = c_int\r\nd7.isLastRec.argtypes = [ c_void_p, c_void_p ]\r\n\r\nd7.isAmSane.restype = c_int\r\nd7.isAmSane.argtypes = [ ]\r\n\r\nd7.isCheckData.restype = c_int\r\nd7.isCheckData.argtypes = [ c_void_p ]\r\n\r\nd7.isCheckIndex.restype = c_int\r\nd7.isCheckIndex.argtypes = [ c_void_p, c_int ]\r\n\r\nd7.isRebuildFree.restype = c_int\r\nd7.isRebuildFree.argtypes = [ c_void_p, c_int ]\r\n\r\nd7.isRebuildIdx.restype = c_int\r\nd7.isRebuildIdx.argtypes = [ c_void_p, c_int ]\r\n\r\nd7.isCheckVarlen.restype = c_int\r\nd7.isCheckVarlen.argtypes = [ c_void_p, c_void_p ]\r\n\r\nclass d7error(Exception):\r\n\r\n  def __init__ ( self, isam, string ):\r\n    self.value = d7.isErrno( isam ) \r\n    self.string = string;\r\n\r\n  def __str__ ( self ):\r\n    return repr( \"[%s] %s\" % ( self.value, self.string ) )\r\n\r\n\r\nclass _d7_key_part(Structure):\r\n  _fields_ = [ (\"kp_start\", c_short),\r\n               (\"kp_leng\", c_short),\r\n               (\"kp_type\", c_short) ]\r\n\r\nclass d7key(Structure):\r\n  _fields_ = [ (\"k_flags\", c_short),\r\n               (\"k_nparts\", c_short),\r\n               (\"k_part\", _d7_key_part * d7.ISMAXPARTS) ]<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This Python module imports D-ISAM as a shared library, and exports three classes. d7 class exports the D-ISAM library itself, and adds &#8220;constant&#8221; values for the standard ISAM defines &#8211; for example d7.isOpen( &#8220;myfile&#8221;, d7.ISINOUT + d7.ISAUTOLOCK ) d7error is a python Exception class, for example raise d7error( isam, &#8220;message text&#8221; ) d7key is a [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[8,7],"_links":{"self":[{"href":"https:\/\/www.isam.ca\/index.php?rest_route=\/wp\/v2\/posts\/437"}],"collection":[{"href":"https:\/\/www.isam.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.isam.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.isam.ca\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.isam.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=437"}],"version-history":[{"count":6,"href":"https:\/\/www.isam.ca\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions"}],"predecessor-version":[{"id":592,"href":"https:\/\/www.isam.ca\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions\/592"}],"wp:attachment":[{"href":"https:\/\/www.isam.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.isam.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.isam.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}