summaryrefslogtreecommitdiff
path: root/efl/ecore
diff options
context:
space:
mode:
authorDavide Andreoli <dave@gurumeditation.it>2013-02-17 20:53:51 +0000
committerDavide Andreoli <dave@gurumeditation.it>2013-02-17 20:53:51 +0000
commit50cf3b0a0abd1e364e2b5060eba868c9eaa24d3b (patch)
tree3ed92e39336930172d9ac190365154b709ff412d /efl/ecore
parent53e832d0afff548f246e3717ad564cf2990863d3 (diff)
Python-EFL: make ecore Exe and FdHandler py3 friendly. svn ignore++
SVN revision: 84029
Diffstat (limited to 'efl/ecore')
-rw-r--r--efl/ecore/efl.ecore_exe.pxi29
1 files changed, 25 insertions, 4 deletions
diff --git a/efl/ecore/efl.ecore_exe.pxi b/efl/ecore/efl.ecore_exe.pxi
index 0dd913a..315742b 100644
--- a/efl/ecore/efl.ecore_exe.pxi
+++ b/efl/ecore/efl.ecore_exe.pxi
@@ -16,10 +16,10 @@
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>. 16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17 17
18 18
19# TODO: remove me after usage is update to new buffer api
20cdef extern from "Python.h": 19cdef extern from "Python.h":
21 int PyObject_AsReadBuffer(obj, void **buffer, Py_ssize_t *buffer_len) except -1
22 object PyUnicode_FromStringAndSize(char *s, Py_ssize_t len) 20 object PyUnicode_FromStringAndSize(char *s, Py_ssize_t len)
21 int PyObject_GetBuffer(obj, Py_buffer *view, int flags)
22 void PyBuffer_Release(Py_buffer *view)
23 23
24 24
25cdef exe_flags2str(int value): 25cdef exe_flags2str(int value):
@@ -247,6 +247,7 @@ cdef class Exe(object):
247 def free(self): 247 def free(self):
248 self.delete() 248 self.delete()
249 249
250 """
250 def send(self, buffer, long size=0): 251 def send(self, buffer, long size=0):
251 cdef const_void *b_data 252 cdef const_void *b_data
252 cdef Py_ssize_t b_size 253 cdef Py_ssize_t b_size
@@ -261,7 +262,27 @@ cdef class Exe(object):
261 (size, b_size)) 262 (size, b_size))
262 263
263 return bool(ecore_exe_send(self.exe, b_data, size)) 264 return bool(ecore_exe_send(self.exe, b_data, size))
265
266 """
267 def send(self, buf, long size=0):
268 cdef Py_buffer buf_view
264 269
270 if isinstance(buf, (str, unicode)):
271 buf = buf.encode("UTF-8")
272
273 PyObject_GetBuffer(buf, &buf_view, 0)
274
275 if size <= 0:
276 size = buf_view.len
277 elif size > buf_view.len:
278 raise ValueError(
279 "given size (%d) is larger than buffer size (%d)." %
280 (size, buf_view.len))
281
282 ret = bool(ecore_exe_send(self.exe, <const_void *>buf_view.buf, buf_view.len))
283 PyBuffer_Release(&buf_view)
284 return ret
285
265 def close_stdin(self): 286 def close_stdin(self):
266 ecore_exe_close_stdin(self.exe) 287 ecore_exe_close_stdin(self.exe)
267 288
@@ -417,11 +438,11 @@ cdef class Exe(object):
417 filter.callback_del(func, args, kargs) 438 filter.callback_del(func, args, kargs)
418 439
419 440
420def exe_run(char *exe_cmd, data=None): 441def exe_run(exe_cmd, data=None):
421 return Exe(exe_cmd, data=data) 442 return Exe(exe_cmd, data=data)
422 443
423 444
424def exe_pipe_run(char *exe_cmd, int flags=0, data=None): 445def exe_pipe_run(exe_cmd, int flags=0, data=None):
425 return Exe(exe_cmd, flags, data) 446 return Exe(exe_cmd, flags, data)
426 447
427 448