##// END OF EJS Templates
base85.c: Added support for py3k....
Renato Cunha -
r11362:f42ef949 default
parent child Browse files
Show More
@@ -11,6 +11,8 b''
11
11
12 #include <Python.h>
12 #include <Python.h>
13
13
14 #include "util.h"
15
14 static const char b85chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
16 static const char b85chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
15 "abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
17 "abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
16 static char b85dec[256];
18 static char b85dec[256];
@@ -46,10 +48,10 b' b85encode(PyObject *self, PyObject *args'
46 olen++;
48 olen++;
47 olen += len / 4 * 5;
49 olen += len / 4 * 5;
48 }
50 }
49 if (!(out = PyString_FromStringAndSize(NULL, olen + 3)))
51 if (!(out = PyBytes_FromStringAndSize(NULL, olen + 3)))
50 return NULL;
52 return NULL;
51
53
52 dst = PyString_AS_STRING(out);
54 dst = PyBytes_AsString(out);
53
55
54 while (len) {
56 while (len) {
55 acc = 0;
57 acc = 0;
@@ -68,7 +70,7 b' b85encode(PyObject *self, PyObject *args'
68 }
70 }
69
71
70 if (!pad)
72 if (!pad)
71 _PyString_Resize(&out, olen);
73 _PyBytes_Resize(&out, olen);
72
74
73 return out;
75 return out;
74 }
76 }
@@ -89,10 +91,10 b' b85decode(PyObject *self, PyObject *args'
89 i = len % 5;
91 i = len % 5;
90 if (i)
92 if (i)
91 olen += i - 1;
93 olen += i - 1;
92 if (!(out = PyString_FromStringAndSize(NULL, olen)))
94 if (!(out = PyBytes_FromStringAndSize(NULL, olen)))
93 return NULL;
95 return NULL;
94
96
95 dst = PyString_AS_STRING(out);
97 dst = PyBytes_AsString(out);
96
98
97 i = 0;
99 i = 0;
98 while (i < len)
100 while (i < len)
@@ -153,9 +155,26 b' static PyMethodDef methods[] = {'
153 {NULL, NULL}
155 {NULL, NULL}
154 };
156 };
155
157
158 #ifdef IS_PY3K
159 static struct PyModuleDef base85_module = {
160 PyModuleDef_HEAD_INIT,
161 "base85",
162 base85_doc,
163 -1,
164 methods
165 };
166
167 PyMODINIT_FUNC PyInit_base85(void)
168 {
169 b85prep();
170
171 return PyModule_Create(&base85_module);
172 }
173 #else
156 PyMODINIT_FUNC initbase85(void)
174 PyMODINIT_FUNC initbase85(void)
157 {
175 {
158 Py_InitModule3("base85", methods, base85_doc);
176 Py_InitModule3("base85", methods, base85_doc);
159
177
160 b85prep();
178 b85prep();
161 }
179 }
180 #endif
General Comments 0
You need to be logged in to leave comments. Login now