File: _internal.py

package info (click to toggle)
pysdl2 0.9.9%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,276 kB
  • sloc: python: 18,592; makefile: 148; sh: 40
file content (25 lines) | stat: -rw-r--r-- 835 bytes parent folder | download | duplicates (2)
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
import warnings
from ctypes import POINTER, cast, addressof


# Defines a type of dict that allows getting (but not setting) keys as attributes
class AttributeDict(dict):
    def __getattr__(self, key):
        return self[key]


# Gets a usable pointer from an SDL2 ctypes object
def get_pointer(ctypes_obj):
    pointer_type = POINTER(type(ctypes_obj))
    return cast(addressof(ctypes_obj), pointer_type)


# Prints warning without stack or line info
def prettywarn(msg, warntype):
    """Prints a suppressable warning without stack or line info."""
    original = warnings.formatwarning
    def _pretty_fmt(message, category, filename, lineno, line=None):
        return "{0}: {1}\n".format(category.__name__, message)
    warnings.formatwarning = _pretty_fmt
    warnings.warn(msg, warntype)
    warnings.formatwarning = original