From 2592f714b7bf436892c330063f8ae197b4662d0b Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Wed, 18 Mar 2009 13:59:22 -0400 Subject: [PATCH] Create an afs.afs module for common functions, like error handling. Signed-off-by: Evan Broder --- .gitignore | 2 ++ afs/afs.pyx | 32 ++++++++++++++++++++++++++++++++ setup.py | 6 ++++++ 3 files changed, 40 insertions(+) create mode 100644 afs/afs.pyx diff --git a/.gitignore b/.gitignore index e5dd526..26bf8d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +afs/afs.c +afs/afs.dep afs/_pts.c afs/_pts.dep diff --git a/afs/afs.pyx b/afs/afs.pyx new file mode 100644 index 0000000..a54a1c9 --- /dev/null +++ b/afs/afs.pyx @@ -0,0 +1,32 @@ +""" +General PyAFS utilities, such as error handling +""" + +import sys + +cdef int _init = 0 + +class AFSException(Exception): + def __init__(self, errno, message): + self.errno = errno + self.strerror = afs_error_message(errno) + self.message = message + + def __repr__(self): + return "AFSException(%s, %s)" % (self.errno, self.message) + + def __str__(self): + return "[%s] (%s) while %s" % (self.errno, self.strerror, self.message) + +def pyafs_error(code, msg): + if not _init: + initialize_ACFG_error_table() + initialize_KTC_error_table() + initialize_PT_error_table() + initialize_RXK_error_table() + initialize_U_error_table() + + _init = 1 + + if code != 0: + raise AFSException(code, msg) diff --git a/setup.py b/setup.py index e368aa9..977deb5 100755 --- a/setup.py +++ b/setup.py @@ -35,6 +35,12 @@ setup( libraries=libraries, include_dirs=include_dirs, library_dirs=library_dirs, + define_macros=define_macros), + Extension("afs.afs", + ["afs/afs.pyx"], + libraries=libraries, + include_dirs=include_dirs, + library_dirs=library_dirs, define_macros=define_macros) ], cmdclass= {"build_ext": build_ext} -- 1.7.9.5