Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

edgify / rook   python

Repository URL to install this package:

Version: 0.1.176 

/ com_ws / eventfd / syscall.py

"""
from https://github.com/quick2wire/quick2wire-python-api/blob/master/quick2wire/syscall.py
"""


import errno
import ctypes

libc = ctypes.CDLL(None, use_errno=True)


def errcheck(result, func, args):
    if result < 0:
        e = ctypes.get_errno()
        raise OSError(e, errno.strerror(e))
    return result


def lookup(restype, name, argtypes):
    f = libc[name]
    f.restye = restype
    f.argtypes = argtypes
    f.errcheck = errcheck
    return f


class SelfClosing(object):
    def __enter__(self):
        return self

    def __exit__(self, *exc):
        self.close()
        return False