File: rwobject.rst

package info (click to toggle)
pygame 2.6.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,076 kB
  • sloc: ansic: 66,932; python: 48,797; javascript: 1,153; objc: 224; sh: 121; makefile: 59; cpp: 25
file content (65 lines) | stat: -rw-r--r-- 3,003 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
.. include:: ../common.txt

.. highlight:: c

***********************************
  API exported by pygame.rwobject
***********************************

src_c/rwobject.c
================

This extension module implements functions for wrapping a Python file like
object in a :c:type:`SDL_RWops` struct for SDL file access.

Header file: src_c/include/pygame.h


.. c:function:: SDL_RWops* pgRWops_FromObject(PyObject *obj, char **extptr)

   Return a SDL_RWops struct filled to access *obj*.
   If *obj* is a string then let SDL open the file it names.
   Otherwise, if *obj* is a Python file-like object then use its ``read``, ``write``,
   ``seek``, ``tell``, and ``close`` methods. If threads are available,
   the Python GIL is acquired before calling any of the *obj* methods.
   If you want to see the file extension, you can pass in a char double pointer
   that will be populated to a dynamically allocated string or NULL. Caller is
   responsible for freeing the extension string. It is safe to pass NULL if you
   don't care about the file extension. On error raise a Python exception and
   return ``NULL``. If NULL is returned, the extptr will not be populated with
   dynamic memory, it is not necessary to free in that error handling.

.. c:function:: SDL_RWops* pgRWops_FromFileObject(PyObject *obj)

   Return a SDL_RWops struct filled to access the Python file-like object *obj*.
   Uses its ``read``, ``write``, ``seek``, ``tell``, and ``close`` methods.
   If threads are available, the Python GIL is acquired before calling any of the *obj* methods.
   On error raise a Python exception and return ``NULL``.

.. c:function:: int pgRWops_IsFileObject(SDL_RWops *rw)

   Return true if *rw* is a Python file-like object wrapper returned by :c:func:`pgRWops_FromObject`
   or :c:func:`pgRWops_FromFileObject`.

.. c:function:: int pgRWops_ReleaseObject(SDL_RWops *context)

   Free a SDL_RWops struct. If it is attached to a Python file-like object, decrement its
   refcount. Otherwise, close the file handle.
   Return 0 on success. On error, raise a Python exception and return a negative value.

.. c:function:: PyObject* pg_EncodeFilePath(PyObject *obj, PyObject *eclass)

   Return the file path *obj* as a byte string properly encoded for the OS.
   Null bytes are forbidden in the encoded file path.
   On error raise a Python exception and return ``NULL``,
   using *eclass* as the exception type if it is not ``NULL``.
   If *obj* is ``NULL`` assume an exception was already raised and pass it on.

.. c:function:: PyObject* pg_EncodeString(PyObject *obj, const char *encoding, const char *errors, PyObject *eclass)

   Return string *obj* as an encoded byte string.
   The C string arguments *encoding* and *errors* are the same as for
   :c:func:`PyUnicode_AsEncodedString`.
   On error raise a Python exception and return ``NULL``,
   using *eclass* as the exception type if it is not ``NULL``.
   If *obj* is ``NULL`` assume an exception was already raised and pass it on.