##// END OF EJS Templates
osutil: implement minimal __getitem__ compatibility on our custom listdir type...
Augie Fackler -
r36798:f3c31402 default
parent child Browse files
Show More
@@ -121,6 +121,27 b' static void listdir_stat_dealloc(PyObjec'
121 121 o->ob_type->tp_free(o);
122 122 }
123 123
124 static PyObject *listdir_stat_getitem(PyObject *self, PyObject *key)
125 {
126 long index = PyLong_AsLong(key);
127 if (index == -1 && PyErr_Occurred()) {
128 return NULL;
129 }
130 if (index != 8) {
131 PyErr_Format(PyExc_IndexError, "osutil.stat objects only "
132 "support stat.ST_MTIME in "
133 "__getitem__");
134 return NULL;
135 }
136 return listdir_stat_st_mtime(self, NULL);
137 }
138
139 static PyMappingMethods listdir_stat_type_mapping_methods = {
140 (lenfunc)NULL, /* mp_length */
141 (binaryfunc)listdir_stat_getitem, /* mp_subscript */
142 (objobjargproc)NULL, /* mp_ass_subscript */
143 };
144
124 145 static PyTypeObject listdir_stat_type = {
125 146 PyVarObject_HEAD_INIT(NULL, 0) /* header */
126 147 "osutil.stat", /*tp_name*/
@@ -134,7 +155,7 b' static PyTypeObject listdir_stat_type = '
134 155 0, /*tp_repr*/
135 156 0, /*tp_as_number*/
136 157 0, /*tp_as_sequence*/
137 0, /*tp_as_mapping*/
158 &listdir_stat_type_mapping_methods, /*tp_as_mapping*/
138 159 0, /*tp_hash */
139 160 0, /*tp_call*/
140 161 0, /*tp_str*/
@@ -1352,7 +1373,7 b' static PyMethodDef methods[] = {'
1352 1373 {NULL, NULL}
1353 1374 };
1354 1375
1355 static const int version = 3;
1376 static const int version = 4;
1356 1377
1357 1378 #ifdef IS_PY3K
1358 1379 static struct PyModuleDef osutil_module = {
@@ -69,7 +69,7 b' def _importfrom(pkgname, modname):'
69 69 (r'cext', r'bdiff'): 3,
70 70 (r'cext', r'diffhelpers'): 1,
71 71 (r'cext', r'mpatch'): 1,
72 (r'cext', r'osutil'): 3,
72 (r'cext', r'osutil'): 4,
73 73 (r'cext', r'parsers'): 4,
74 74 }
75 75
General Comments 0
You need to be logged in to leave comments. Login now