##// END OF EJS Templates
fsmonitor: layer on another hack in bser.c for os.stat() compat (issue5811)...
Augie Fackler -
r37833:b1f62cd3 default
parent child Browse files
Show More
@@ -128,27 +128,38 b' static PyObject* bserobj_getattrro(PyObj'
128 Py_ssize_t i, n;
128 Py_ssize_t i, n;
129 PyObject* name_bytes = NULL;
129 PyObject* name_bytes = NULL;
130 PyObject* ret = NULL;
130 PyObject* ret = NULL;
131 const char* namestr;
131 const char* namestr = NULL;
132
132
133 if (PyIndex_Check(name)) {
133 if (PyIndex_Check(name)) {
134 i = PyNumber_AsSsize_t(name, PyExc_IndexError);
134 i = PyNumber_AsSsize_t(name, PyExc_IndexError);
135 if (i == -1 && PyErr_Occurred()) {
135 if (i == -1 && PyErr_Occurred()) {
136 goto bail;
136 goto bail;
137 }
137 }
138 ret = PySequence_GetItem(obj->values, i);
139 goto bail;
140 }
141
138
142 // We can be passed in Unicode objects here -- we don't support anything other
139 if (i == 8 && PySequence_Size(obj->values) < 9) {
143 // than UTF-8 for keys.
140 // Hack alert: Python 3 removed support for os.stat().st_mtime
144 if (PyUnicode_Check(name)) {
141 // being an integer.Instead, if you need an integer, you have to
145 name_bytes = PyUnicode_AsUTF8String(name);
142 // use os.stat()[stat.ST_MTIME] instead. stat.ST_MTIME is 8, and
146 if (name_bytes == NULL) {
143 // our stat tuples are shorter than that, so we can detect
144 // requests for index 8 on tuples shorter than that and return
145 // st_mtime instead.
146 namestr = "st_mtime";
147 } else {
148 ret = PySequence_GetItem(obj->values, i);
147 goto bail;
149 goto bail;
148 }
150 }
149 namestr = PyBytes_AsString(name_bytes);
150 } else {
151 } else {
151 namestr = PyBytes_AsString(name);
152 // We can be passed in Unicode objects here -- we don't support anything other
153 // than UTF-8 for keys.
154 if (PyUnicode_Check(name)) {
155 name_bytes = PyUnicode_AsUTF8String(name);
156 if (name_bytes == NULL) {
157 goto bail;
158 }
159 namestr = PyBytes_AsString(name_bytes);
160 } else {
161 namestr = PyBytes_AsString(name);
162 }
152 }
163 }
153
164
154 if (namestr == NULL) {
165 if (namestr == NULL) {
General Comments 0
You need to be logged in to leave comments. Login now