@@@ lbuf needs test
[mLib-python] / utils.pyx
index a8a4406..4d7d06f 100644 (file)
--- a/utils.pyx
+++ b/utils.pyx
 ### along with mLib/Python; if not, write to the Free Software Foundation,
 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-cdef object _u32(uint32 x):
-  if x <= LONG_MAX:
-    return PyInt_FromLong(x)
-  else:
-    return PyLong_FromUnsignedLong(x)
+cdef const char *_text_strlen(object s, Py_ssize_t *sz) except NULL:
+  cdef const char *p
+  TEXT_PTRLEN(s, &p, sz)
+  return p
 
 cdef object _oserror():
-  raise OSError, (errno, strerror(errno))
-
-cdef object _tobool(int i):
-  if i:
-    return True
-  else:
-    return False
+  raise OSError(errno, strerror(errno))
 
 cdef int _getfd(object fdobj):
   try:
-    return fdobj
+    fd = int(fdobj)
   except TypeError:
-    return fdobj.fileno()
+    fd = fdobj.fileno()
+  return fd
 
-cdef object _checkcallable(f, what):
+cdef object _checkcallable(object f, object what):
   if f is not None and not callable(f):
-    raise TypeError, '%s must be callable' % what
+    raise TypeError('%s must be callable' % what)
   return f
 
-cdef object _maybecall(f, args):
+cdef object _maybecall(object f, object args):
   if f is None:
     return None
   return f(*args)