Import error codes directly from libmailutils to Python.
* python/libmu_py/Makefile.am (libmu_py_la_SOURCES): Add errno.c * python/libmu_py/errno.c: New file. * python/libmu_py/libmu_py.c (_mu_py_module_name): New function. (_mu_py_attach_module): Use _mu_py_module_name to allocate FQ module name instead of taking the risk of using fixed size buffer. Don't call Py_InitModule if methods is NULL. (mu_py_attach_modules): Call _mu_py_attach_errno. * python/libmu_py/libmu_py.h (_mu_py_attach_errno): New proto. * python/mailutils/error.py: Re-export everything from c_api.errno. Remove hardcoded definitions of error codes.
Showing
5 changed files
with
55 additions
and
85 deletions
... | @@ -19,6 +19,7 @@ INCLUDES = @MU_LIB_COMMON_INCLUDES@ $(PYTHON_INCLUDES) | ... | @@ -19,6 +19,7 @@ INCLUDES = @MU_LIB_COMMON_INCLUDES@ $(PYTHON_INCLUDES) |
19 | lib_LTLIBRARIES=libmu_py.la | 19 | lib_LTLIBRARIES=libmu_py.la |
20 | libmu_py_la_SOURCES = \ | 20 | libmu_py_la_SOURCES = \ |
21 | error.c \ | 21 | error.c \ |
22 | errno.c \ | ||
22 | address.c \ | 23 | address.c \ |
23 | attribute.c \ | 24 | attribute.c \ |
24 | auth.c \ | 25 | auth.c \ | ... | ... |
python/libmu_py/errno.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 3 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General | ||
15 | Public License along with this library. If not, see | ||
16 | <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #include "libmu_py.h" | ||
19 | #include <mailutils/errno.h> | ||
20 | |||
21 | #define PY_MODULE "errno" | ||
22 | |||
23 | void | ||
24 | _mu_py_attach_errno (void) | ||
25 | { | ||
26 | int i; | ||
27 | PyObject *module = _mu_py_attach_module (PY_MODULE, NULL); | ||
28 | |||
29 | for (i = MU_ERR_BASE; i < MU_ERR_LAST; i++) | ||
30 | { | ||
31 | const char *en = mu_errname (i); | ||
32 | PyModule_AddIntConstant (module, en, i); | ||
33 | } | ||
34 | } |
... | @@ -42,14 +42,23 @@ status_object (int status, PyObject *py_obj) | ... | @@ -42,14 +42,23 @@ status_object (int status, PyObject *py_obj) |
42 | static PyObject *package; | 42 | static PyObject *package; |
43 | static PyObject *all; | 43 | static PyObject *all; |
44 | 44 | ||
45 | #define MU_MODULE_ROOT PY_PACKAGE_NAME "." PY_ROOT_NAME "." | ||
46 | |||
47 | static char * | ||
48 | _mu_py_module_name (const char *nm) | ||
49 | { | ||
50 | char *buf = malloc (sizeof (MU_MODULE_ROOT) + strlen (nm)); | ||
51 | if (!buf) | ||
52 | abort (); | ||
53 | return strcat (strcpy (buf, MU_MODULE_ROOT), nm); | ||
54 | } | ||
55 | |||
45 | PyObject * | 56 | PyObject * |
46 | _mu_py_attach_module (const char *name, PyMethodDef *methods) | 57 | _mu_py_attach_module (const char *name, PyMethodDef *methods) |
47 | { | 58 | { |
48 | PyObject *module, *m; | 59 | PyObject *module; |
49 | 60 | char *ns = _mu_py_module_name (name); | |
50 | char ns[64] = PY_PACKAGE_NAME "." PY_ROOT_NAME "."; | 61 | |
51 | strcat (ns, name); | ||
52 | |||
53 | if (!(module = PyImport_AddModule (ns))) | 62 | if (!(module = PyImport_AddModule (ns))) |
54 | return NULL; | 63 | return NULL; |
55 | 64 | ||
... | @@ -58,11 +67,12 @@ _mu_py_attach_module (const char *name, PyMethodDef *methods) | ... | @@ -58,11 +67,12 @@ _mu_py_attach_module (const char *name, PyMethodDef *methods) |
58 | 67 | ||
59 | Py_INCREF (module); | 68 | Py_INCREF (module); |
60 | 69 | ||
61 | if (!(m = Py_InitModule (ns, methods))) | 70 | if (methods && !Py_InitModule (ns, methods)) |
62 | return NULL; | 71 | return NULL; |
63 | 72 | ||
64 | PyList_Append (all, PyString_FromString (name)); | 73 | PyList_Append (all, PyString_FromString (name)); |
65 | return m; | 74 | free (ns); |
75 | return module; | ||
66 | } | 76 | } |
67 | 77 | ||
68 | void | 78 | void |
... | @@ -111,6 +121,7 @@ mu_py_attach_modules (void) | ... | @@ -111,6 +121,7 @@ mu_py_attach_modules (void) |
111 | _mu_py_attach_auth (); | 121 | _mu_py_attach_auth (); |
112 | _mu_py_attach_body (); | 122 | _mu_py_attach_body (); |
113 | _mu_py_attach_envelope (); | 123 | _mu_py_attach_envelope (); |
124 | _mu_py_attach_errno (); | ||
114 | _mu_py_attach_header (); | 125 | _mu_py_attach_header (); |
115 | _mu_py_attach_filter (); | 126 | _mu_py_attach_filter (); |
116 | _mu_py_attach_folder (); | 127 | _mu_py_attach_folder (); | ... | ... |
... | @@ -65,6 +65,7 @@ extern void _mu_py_attach_attribute (void); | ... | @@ -65,6 +65,7 @@ extern void _mu_py_attach_attribute (void); |
65 | extern void _mu_py_attach_auth (void); | 65 | extern void _mu_py_attach_auth (void); |
66 | extern void _mu_py_attach_body (void); | 66 | extern void _mu_py_attach_body (void); |
67 | extern void _mu_py_attach_envelope (void); | 67 | extern void _mu_py_attach_envelope (void); |
68 | extern void _mu_py_attach_errno (void); | ||
68 | extern void _mu_py_attach_header (void); | 69 | extern void _mu_py_attach_header (void); |
69 | extern void _mu_py_attach_filter (void); | 70 | extern void _mu_py_attach_filter (void); |
70 | extern void _mu_py_attach_folder (void); | 71 | extern void _mu_py_attach_folder (void); | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | # <http://www.gnu.org/licenses/>. | 16 | # <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | from mailutils.c_api import error | 18 | from mailutils.c_api import error |
19 | from mailutils.c_api.errno import * | ||
19 | 20 | ||
20 | def strerror (status): | 21 | def strerror (status): |
21 | return error.strerror (status) | 22 | return error.strerror (status) |
... | @@ -44,81 +45,3 @@ class SieveMachineError (Error): pass | ... | @@ -44,81 +45,3 @@ class SieveMachineError (Error): pass |
44 | class StreamError (Error): pass | 45 | class StreamError (Error): pass |
45 | class UrlError (Error): pass | 46 | class UrlError (Error): pass |
46 | 47 | ||
47 | MU_ERR_BASE = 0x1000 | ||
48 | |||
49 | MU_ERR_FAILURE = (MU_ERR_BASE+0) | ||
50 | MU_ERR_CANCELED = (MU_ERR_BASE+1) | ||
51 | MU_ERR_EMPTY_VFN = (MU_ERR_BASE+2) | ||
52 | MU_ERR_OUT_PTR_NULL = (MU_ERR_BASE+3) | ||
53 | MU_ERR_MBX_REMOVED = (MU_ERR_BASE+4) | ||
54 | MU_ERR_NOT_OPEN = (MU_ERR_BASE+5) | ||
55 | MU_ERR_OPEN = (MU_ERR_BASE+6) | ||
56 | MU_ERR_INVALID_EMAIL = (MU_ERR_BASE+7) | ||
57 | MU_ERR_EMPTY_ADDRESS = (MU_ERR_BASE+8) | ||
58 | MU_ERR_LOCKER_NULL = (MU_ERR_BASE+9) | ||
59 | MU_ERR_LOCK_CONFLICT = (MU_ERR_BASE+10) | ||
60 | MU_ERR_LOCK_BAD_LOCK = (MU_ERR_BASE+11) | ||
61 | MU_ERR_LOCK_BAD_FILE = (MU_ERR_BASE+12) | ||
62 | MU_ERR_LOCK_NOT_HELD = (MU_ERR_BASE+13) | ||
63 | MU_ERR_LOCK_EXT_FAIL = (MU_ERR_BASE+14) | ||
64 | MU_ERR_LOCK_EXT_ERR = (MU_ERR_BASE+15) | ||
65 | MU_ERR_LOCK_EXT_KILLED = (MU_ERR_BASE+16) | ||
66 | MU_ERR_NO_SUCH_USER = (MU_ERR_BASE+17) | ||
67 | MU_ERR_GETHOSTBYNAME = (MU_ERR_BASE+18) | ||
68 | MU_ERR_MAILER_BAD_FROM = (MU_ERR_BASE+19) | ||
69 | MU_ERR_MAILER_BAD_TO = (MU_ERR_BASE+20) | ||
70 | MU_ERR_MAILER_NO_RCPT_TO = (MU_ERR_BASE+21) | ||
71 | MU_ERR_MAILER_BAD_URL = (MU_ERR_BASE+22) | ||
72 | MU_ERR_SMTP_RCPT_FAILED = (MU_ERR_BASE+23) | ||
73 | MU_ERR_TCP_NO_HOST = (MU_ERR_BASE+24) | ||
74 | MU_ERR_TCP_NO_PORT = (MU_ERR_BASE+25) | ||
75 | MU_ERR_BAD_2047_INPUT = (MU_ERR_BASE+26) | ||
76 | MU_ERR_BAD_2047_ENCODING = (MU_ERR_BASE+27) | ||
77 | MU_ERR_NOUSERNAME = (MU_ERR_BASE+28) | ||
78 | MU_ERR_NOPASSWORD = (MU_ERR_BASE+29) | ||
79 | MU_ERR_BADREPLY = (MU_ERR_BASE+30) | ||
80 | MU_ERR_SEQ = (MU_ERR_BASE+31) | ||
81 | MU_ERR_REPLY = (MU_ERR_BASE+32) | ||
82 | MU_ERR_BAD_AUTH_SCHEME = (MU_ERR_BASE+33) | ||
83 | MU_ERR_AUTH_FAILURE = (MU_ERR_BASE+34) | ||
84 | MU_ERR_PROCESS_NOEXEC = (MU_ERR_BASE+35) | ||
85 | MU_ERR_PROCESS_EXITED = (MU_ERR_BASE+36) | ||
86 | MU_ERR_PROCESS_SIGNALED = (MU_ERR_BASE+37) | ||
87 | MU_ERR_PROCESS_UNKNOWN_FAILURE = (MU_ERR_BASE+38) | ||
88 | MU_ERR_CONN_CLOSED = (MU_ERR_BASE+39) | ||
89 | MU_ERR_PARSE = (MU_ERR_BASE+40) | ||
90 | MU_ERR_NOENT = (MU_ERR_BASE+41) | ||
91 | MU_ERR_EXISTS = (MU_ERR_BASE+42) | ||
92 | MU_ERR_BUFSPACE = (MU_ERR_BASE+43) | ||
93 | MU_ERR_SQL = (MU_ERR_BASE+44) | ||
94 | MU_ERR_DB_ALREADY_CONNECTED = (MU_ERR_BASE+45) | ||
95 | MU_ERR_DB_NOT_CONNECTED = (MU_ERR_BASE+46) | ||
96 | MU_ERR_RESULT_NOT_RELEASED = (MU_ERR_BASE+47) | ||
97 | MU_ERR_NO_QUERY = (MU_ERR_BASE+48) | ||
98 | MU_ERR_BAD_COLUMN = (MU_ERR_BASE+49) | ||
99 | MU_ERR_NO_RESULT = (MU_ERR_BASE+50) | ||
100 | MU_ERR_NO_INTERFACE = (MU_ERR_BASE+51) | ||
101 | MU_ERR_BADOP = (MU_ERR_BASE+52) | ||
102 | MU_ERR_BAD_FILENAME = (MU_ERR_BASE+53) | ||
103 | MU_ERR_READ = (MU_ERR_BASE+54) | ||
104 | MU_ERR_NO_TRANSPORT = (MU_ERR_BASE+55) | ||
105 | MU_ERR_AUTH_NO_CRED = (MU_ERR_BASE+56) | ||
106 | MU_ERR_URL_MISS_PARTS = (MU_ERR_BASE+57) | ||
107 | MU_ERR_URL_EXTRA_PARTS = (MU_ERR_BASE+58) | ||
108 | MU_ERR_URL_INVALID_PARAMETER = (MU_ERR_BASE+59) | ||
109 | MU_ERR_INFO_UNAVAILABLE = (MU_ERR_BASE+60) | ||
110 | MU_ERR_NONAME = (MU_ERR_BASE+61) | ||
111 | MU_ERR_BADFLAGS = (MU_ERR_BASE+62) | ||
112 | MU_ERR_SOCKTYPE = (MU_ERR_BASE+63) | ||
113 | MU_ERR_FAMILY = (MU_ERR_BASE+64) | ||
114 | MU_ERR_SERVICE = (MU_ERR_BASE+65) | ||
115 | MU_ERR_PERM_OWNER_MISMATCH = (MU_ERR_BASE+66) | ||
116 | MU_ERR_PERM_GROUP_WRITABLE = (MU_ERR_BASE+67) | ||
117 | MU_ERR_PERM_WORLD_WRITABLE = (MU_ERR_BASE+68) | ||
118 | MU_ERR_PERM_GROUP_READABLE = (MU_ERR_BASE+69) | ||
119 | MU_ERR_PERM_WORLD_READABLE = (MU_ERR_BASE+70) | ||
120 | MU_ERR_PERM_LINKED_WRDIR = (MU_ERR_BASE+71) | ||
121 | MU_ERR_PERM_DIR_IWGRP = (MU_ERR_BASE+72) | ||
122 | MU_ERR_PERM_DIR_IWOTH = (MU_ERR_BASE+73) | ||
123 | MU_ERR_DISABLED = (MU_ERR_BASE+74) | ||
124 | MU_ERR_LAST = (MU_ERR_BASE+75) | ... | ... |
-
Please register or sign in to post a comment