/* Generated by Cython 0.12.1 on Fri Mar 11 11:44:46 2011 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#else

#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#if PY_VERSION_HEX < 0x02040000
  #define METH_COEXIST 0
  #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)
  #define PyDict_Contains(d,o)   PySequence_Contains(d,o)
#endif

#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   PyInt_AsLong(o)
  #define PyNumber_Index(o)    PyNumber_Int(o)
  #define PyIndex_Check(o)     PyNumber_Check(o)
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#endif

#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)

  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;

  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)

#endif

#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
#endif

#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif

#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyString_Type                PyUnicode_Type
  #define PyString_CheckExact          PyUnicode_CheckExact
#else
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_CheckExact           PyString_CheckExact
#endif

#if PY_MAJOR_VERSION >= 3
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)

#endif

#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func)
#endif

#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#else
  #define _USE_MATH_DEFINES
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif

#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#define __PYX_HAVE_API__event
#include "sys/types.h"
#include "event.h"
#include "evdns.h"
#include "evhttp.h"

#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #else
    #define CYTHON_INLINE 
  #endif
#endif

typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/


/* Type Conversion Predeclarations */

#if PY_MAJOR_VERSION < 3
#define __Pyx_PyBytes_FromString          PyString_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyString_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyString_AsString
#else
#define __Pyx_PyBytes_FromString          PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize   PyBytes_FromStringAndSize
#define __Pyx_PyBytes_AsString            PyBytes_AsString
#endif

#define __Pyx_PyBytes_FromUString(s)      __Pyx_PyBytes_FromString((char*)s)
#define __Pyx_PyBytes_AsUString(s)        ((unsigned char*) __Pyx_PyBytes_AsString(s))

#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);

#if !defined(T_PYSSIZET)
#if PY_VERSION_HEX < 0x02050000
#define T_PYSSIZET T_INT
#elif !defined(T_LONGLONG)
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))  ? T_INT  : \
        ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1))
#else
#define T_PYSSIZET \
        ((sizeof(Py_ssize_t) == sizeof(int))          ? T_INT      : \
        ((sizeof(Py_ssize_t) == sizeof(long))         ? T_LONG     : \
        ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1)))
#endif
#endif


#if !defined(T_ULONGLONG)
#define __Pyx_T_UNSIGNED_INT(x) \
        ((sizeof(x) == sizeof(unsigned char))  ? T_UBYTE : \
        ((sizeof(x) == sizeof(unsigned short)) ? T_USHORT : \
        ((sizeof(x) == sizeof(unsigned int))   ? T_UINT : \
        ((sizeof(x) == sizeof(unsigned long))  ? T_ULONG : -1))))
#else
#define __Pyx_T_UNSIGNED_INT(x) \
        ((sizeof(x) == sizeof(unsigned char))  ? T_UBYTE : \
        ((sizeof(x) == sizeof(unsigned short)) ? T_USHORT : \
        ((sizeof(x) == sizeof(unsigned int))   ? T_UINT : \
        ((sizeof(x) == sizeof(unsigned long))  ? T_ULONG : \
        ((sizeof(x) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))))
#endif
#if !defined(T_LONGLONG)
#define __Pyx_T_SIGNED_INT(x) \
        ((sizeof(x) == sizeof(char))  ? T_BYTE : \
        ((sizeof(x) == sizeof(short)) ? T_SHORT : \
        ((sizeof(x) == sizeof(int))   ? T_INT : \
        ((sizeof(x) == sizeof(long))  ? T_LONG : -1))))
#else
#define __Pyx_T_SIGNED_INT(x) \
        ((sizeof(x) == sizeof(char))  ? T_BYTE : \
        ((sizeof(x) == sizeof(short)) ? T_SHORT : \
        ((sizeof(x) == sizeof(int))   ? T_INT : \
        ((sizeof(x) == sizeof(long))  ? T_LONG : \
        ((sizeof(x) == sizeof(PY_LONG_LONG))   ? T_LONGLONG : -1)))))
#endif

#define __Pyx_T_FLOATING(x) \
        ((sizeof(x) == sizeof(float)) ? T_FLOAT : \
        ((sizeof(x) == sizeof(double)) ? T_DOUBLE : -1))

#if !defined(T_SIZET)
#if !defined(T_ULONGLONG)
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))  ? T_UINT  : \
        ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1))
#else
#define T_SIZET \
        ((sizeof(size_t) == sizeof(unsigned int))          ? T_UINT      : \
        ((sizeof(size_t) == sizeof(unsigned long))         ? T_ULONG     : \
        ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1)))
#endif
#endif

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))


#ifdef __GNUC__
/* Test for GCC > 2.95 */
#if __GNUC__ > 2 ||               (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) 
#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* __GNUC__ > 2 ... */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ > 2 ... */
#else /* __GNUC__ */
#define likely(x)   (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
    
static PyObject *__pyx_m;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
static const char **__pyx_f;


/* Type declarations */

typedef void (*__pyx_t_5event_event_handler)(int, short, void *);

typedef void (*__pyx_t_5event_evbuffer_handler)(struct bufferevent *, void *);

typedef void (*__pyx_t_5event_everror_handler)(struct bufferevent *, short, void *);

/* "event.pyx":87
 *     (<object>arg).__simple_callback(evtype)
 * 
 * cdef class event:             # <<<<<<<<<<<<<<
 *     """event(callback, arg=None, evtype=0, handle=None) -> event object
 * 
 */

struct __pyx_obj_5event_event {
  PyObject_HEAD
  struct event ev;
  PyObject *handle;
  PyObject *evtype;
  PyObject *callback;
  PyObject *args;
  float timeout;
  struct timeval tv;
};

/* "simple.pxi":2
 * 
 * cdef class read(event):             # <<<<<<<<<<<<<<
 *     """read(handle, callback, *args) -> event object
 * 
 */

struct __pyx_obj_5event_read {
  struct __pyx_obj_5event_event __pyx_base;
};

/* "evhttp.pxi":207
 *     start_response.end()
 * 
 * cdef class wsgi:             # <<<<<<<<<<<<<<
 *     """wsgi(address='0.0.0.0', port=80) -> WSGI server object
 * 
 */

struct __pyx_obj_5event_wsgi {
  PyObject_HEAD
  struct evhttp *_http;
};

/* "simple.pxi":58
 *         self.add()
 * 
 * cdef class timeout(event):             # <<<<<<<<<<<<<<
 *     """timeout(secs, callback, *args) -> event object
 * 
 */

struct __pyx_obj_5event_timeout {
  struct __pyx_obj_5event_event __pyx_base;
};

/* "simple.pxi":20
 *         self.add()
 * 
 * cdef class write(event):             # <<<<<<<<<<<<<<
 *     """write(handle, callback, *args) -> event object
 * 
 */

struct __pyx_obj_5event_write {
  struct __pyx_obj_5event_event __pyx_base;
};

/* "evhttp.pxi":89
 *                                   int cmd_type, char *uri)
 * 
 * cdef class __start_response:             # <<<<<<<<<<<<<<
 *     cdef evhttp_request *req
 *     cdef int headers_sent
 */

struct __pyx_obj_5event___start_response {
  PyObject_HEAD
  struct __pyx_vtabstruct_5event___start_response *__pyx_vtab;
  struct evhttp_request *req;
  int headers_sent;
  PyObject *code;
  PyObject *reason;
};

/* "simple.pxi":38
 *         self.add()
 * 
 * cdef class signal(event):             # <<<<<<<<<<<<<<
 *     """signal(sig, callback, *args) -> event object
 * 
 */

struct __pyx_obj_5event_signal {
  struct __pyx_obj_5event_event __pyx_base;
};

/* "bufferevent.pxi":49
 *     o.errorcb(what, *o.args)
 * 
 * cdef class bufferevent:             # <<<<<<<<<<<<<<
 *     """bufferevent(handle, readcb, writecb, errorcb, *args) -> bufferevent object
 * 
 */

struct __pyx_obj_5event_bufferevent {
  PyObject_HEAD
  struct bufferevent *bufev;
  PyObject *handle;
  PyObject *readcb;
  PyObject *writecb;
  PyObject *errorcb;
  PyObject *args;
};

/* "evhttp.pxi":136
 *         evhttp_send_reply_end(self.req)
 * 
 * cdef class __wsgi_input:             # <<<<<<<<<<<<<<
 *     cdef evbuffer *_buf
 * 
 */

struct __pyx_obj_5event___wsgi_input {
  PyObject_HEAD
  struct __pyx_vtabstruct_5event___wsgi_input *__pyx_vtab;
  struct evbuffer *_buf;
};


struct __pyx_vtabstruct_5event___wsgi_input {
  void (*_set_buf)(struct __pyx_obj_5event___wsgi_input *, struct evbuffer *);
};
static struct __pyx_vtabstruct_5event___wsgi_input *__pyx_vtabptr_5event___wsgi_input;


/* "evhttp.pxi":89
 *                                   int cmd_type, char *uri)
 * 
 * cdef class __start_response:             # <<<<<<<<<<<<<<
 *     cdef evhttp_request *req
 *     cdef int headers_sent
 */

struct __pyx_vtabstruct_5event___start_response {
  void (*_set_req)(struct __pyx_obj_5event___start_response *, struct evhttp_request *);
};
static struct __pyx_vtabstruct_5event___start_response *__pyx_vtabptr_5event___start_response;

#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif

#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct * __Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
  end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
  }
  #define __Pyx_RefNannySetupContext(name)           void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  #define __Pyx_RefNannyFinishContext()           __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0)
#else
  #define __Pyx_RefNannySetupContext(name)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);} } while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r);} } while(0)


static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}


#define __Pyx_GetItemInt_List(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_List_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
            PyObject *r = PyList_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}

#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Tuple_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    if (likely(o != Py_None)) {
        if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, i);
            Py_INCREF(r);
            return r;
        }
        else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) {
            PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i);
            Py_INCREF(r);
            return r;
        }
    }
    return __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
}


#define __Pyx_GetItemInt(o, i, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_GetItemInt_Fast(o, i, size <= sizeof(long)) : \
                                                    __Pyx_GetItemInt_Generic(o, to_py_func(i)))

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int fits_long) {
    PyObject *r;
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (PyTuple_CheckExact(o) && ((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_item && (likely(i >= 0))) {
        r = PySequence_GetItem(o, i);
    }
    else {
        r = __Pyx_GetItemInt_Generic(o, fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i));
    }
    return r;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name, PyObject* kw_name); /*proto*/

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],     PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,     const char* function_name); /*proto*/

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix);

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void);

static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/
static int __Pyx_EndUnpack(PyObject *); /*proto*/

static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (PyList_Append(L, x) < 0) return NULL;
        Py_INCREF(Py_None);
        return Py_None; /* this is just to have an accurate signature */
    }
    else {
        PyObject *r, *m;
        m = __Pyx_GetAttrString(L, "append");
        if (!m) return NULL;
        r = PyObject_CallFunctionObjArgs(m, x, NULL);
        Py_DECREF(m);
        return r;
    }
}

#define __Pyx_SetItemInt(o, i, v, size, to_py_func) ((size <= sizeof(Py_ssize_t)) ? \
                                                    __Pyx_SetItemInt_Fast(o, i, v, size <= sizeof(long)) : \
                                                    __Pyx_SetItemInt_Generic(o, to_py_func(i), v))

static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
    int r;
    if (!j) return -1;
    r = PyObject_SetItem(o, j, v);
    Py_DECREF(j);
    return r;
}

static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int fits_long) {
    if (PyList_CheckExact(o) && ((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        Py_INCREF(v);
        Py_DECREF(PyList_GET_ITEM(o, i));
        PyList_SET_ITEM(o, i, v);
        return 1;
    }
    else if (Py_TYPE(o)->tp_as_sequence && Py_TYPE(o)->tp_as_sequence->sq_ass_item && (likely(i >= 0)))
        return PySequence_SetItem(o, i, v);
    else {
        PyObject *j = fits_long ? PyInt_FromLong(i) : PyLong_FromLongLong(i);
        return __Pyx_SetItemInt_Generic(o, j, v);
    }
}

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict,
    const char* function_name, int kw_allowed); /*proto*/

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/

static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

#ifndef __PYX_FORCE_INIT_THREADS
  #if PY_VERSION_HEX < 0x02040200
    #define __PYX_FORCE_INIT_THREADS 1
  #else
    #define __PYX_FORCE_INIT_THREADS 0
  #endif
#endif

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

static void __Pyx_WriteUnraisable(const char *name); /*proto*/

static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/

static void __Pyx_AddTraceback(const char *funcname); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
/* Module declarations from event */

static PyTypeObject *__pyx_ptype_5event_event = 0;
static PyTypeObject *__pyx_ptype_5event_read = 0;
static PyTypeObject *__pyx_ptype_5event_write = 0;
static PyTypeObject *__pyx_ptype_5event_signal = 0;
static PyTypeObject *__pyx_ptype_5event_timeout = 0;
static PyTypeObject *__pyx_ptype_5event_bufferevent = 0;
static PyTypeObject *__pyx_ptype_5event___start_response = 0;
static PyTypeObject *__pyx_ptype_5event___wsgi_input = 0;
static PyTypeObject *__pyx_ptype_5event_wsgi = 0;
static void __pyx_f_5event___event_abort(void); /*proto*/
static void __pyx_f_5event___event_handler(int, short, void *); /*proto*/
static void __pyx_f_5event___simple_event_handler(int, short, void *); /*proto*/
static void __pyx_f_5event___bufev_readcb(struct bufferevent *, void *); /*proto*/
static void __pyx_f_5event___bufev_writecb(struct bufferevent *, void *); /*proto*/
static void __pyx_f_5event___bufev_errorcb(struct bufferevent *, short, void *); /*proto*/
static void __pyx_f_5event___evdns_callback(int, char, int, int, void *, void *); /*proto*/
static void __pyx_f_5event___path_handler(struct evhttp_request *, void *); /*proto*/
#define __Pyx_MODULE_NAME "event"
int __pyx_module_is_main_event = 0;

/* Implementation of event */
static PyObject *__pyx_builtin_min;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_id;
static PyObject *__pyx_builtin_AssertionError;
static PyObject *__pyx_builtin_OSError;
static char __pyx_k_1[] = "<event flags=0x%x, handle=%s, callback=%s, arg=%s>";
static char __pyx_k_3[] = "<bufferevent handle=%s, readcb=%s, writecb=%s, errorcb=%s, args=%s>";
static char __pyx_k_4[] = "Headers already set!";
static char __pyx_k_5[] = "";
static char __pyx_k_6[] = "Content-Type";
static char __pyx_k_7[] = "Content-Length";
static char __pyx_k_8[] = ":";
static char __pyx_k_9[] = "wsgi.version";
static char __pyx_k_10[] = "wsgi.url_scheme";
static char __pyx_k_11[] = "wsgi.input";
static char __pyx_k_12[] = "wsgi.errors";
static char __pyx_k_13[] = "wsgi.multithread";
static char __pyx_k_14[] = "wsgi.multiprocess";
static char __pyx_k_15[] = "wsgi.run_once";
static char __pyx_k_16[] = "HTTP/%s.%s";
static char __pyx_k_17[] = "%d";
static char __pyx_k_18[] = "0.0.0.0";
static char __pyx_k_19[] = "event library\n\nThis module provides a mechanism to execute a function when a\nspecific event on a file handle, file descriptor, or signal occurs,\nor after a given time has passed.\n";
static char __pyx_k_20[] = "Dug Song <dugsong@monkey.org>";
static char __pyx_k_21[] = "Martin Murray <mmurray@monkey.org>";
static char __pyx_k_22[] = "Aaron Westendorf <aaron@agoragames.com>";
static char __pyx_k_23[] = "Copyright (c) 2004 Dug Song";
static char __pyx_k_24[] = "Copyright (c) 2003 Martin Murray";
static char __pyx_k_25[] = "https://github.com/agoragames/pyevent";
static char __pyx_k_26[] = "0.4.1";
static char __pyx_k_27[] = "DNS_ERR_SERVERFAILED";
static char __pyx_k_28[] = "event.add (line 146)";
static char __pyx_k_29[] = "event.pending (line 165)";
static char __pyx_k_30[] = "event.delete (line 169)";
static char __pyx_k_31[] = "init (line 182)";
static char __pyx_k_32[] = "dispatch (line 186)";
static char __pyx_k_33[] = "loop (line 200)";
static char __pyx_k_34[] = "abort (line 216)";
static char __pyx_k_35[] = "bufferevent.enable (line 89)";
static char __pyx_k_36[] = "bufferevent.disable (line 98)";
static char __pyx_k_37[] = "bufferevent.read (line 107)";
static char __pyx_k_38[] = "bufferevent.write (line 123)";
static char __pyx_k_39[] = "dns_init (line 40)";
static char __pyx_k_40[] = "dns_resolve_ipv4 (line 66)";
static char __pyx_k_41[] = "dns_resolve_ipv6 (line 82)";
static char __pyx_k_42[] = "dns_resolve_reverse (line 98)";
static char __pyx_k_43[] = "dns_resolve_reverse_ipv6 (line 114)";
static char __pyx_k_44[] = "dns_resolve_reverse_ipv6";
static char __pyx_k_45[] = "dns_shutdown (line 130)";
static char __pyx_k_46[] = "wsgi.register_app (line 224)";
static char __pyx_k_47[] = "wsgi.register_default_app (line 234)";
static char __pyx_k_48[] = "register_default_app";
static char __pyx_k_49[] = "wsgi.unregister_app (line 243)";
static char __pyx_k_50[] = "wsgi.run (line 252)";
static char __pyx_k__80[] = "80";
static char __pyx_k__ev[] = "ev";
static char __pyx_k__id[] = "id";
static char __pyx_k__ip[] = "ip";
static char __pyx_k__tv[] = "tv";
static char __pyx_k__BSD[] = "BSD";
static char __pyx_k__GET[] = "GET";
static char __pyx_k__add[] = "add";
static char __pyx_k__app[] = "app";
static char __pyx_k__arg[] = "arg";
static char __pyx_k__buf[] = "buf";
static char __pyx_k__end[] = "end";
static char __pyx_k__min[] = "min";
static char __pyx_k__off[] = "off";
static char __pyx_k__req[] = "req";
static char __pyx_k__run[] = "run";
static char __pyx_k__sig[] = "sig";
static char __pyx_k__sys[] = "sys";
static char __pyx_k__uri[] = "uri";
static char __pyx_k__HEAD[] = "HEAD";
static char __pyx_k__Host[] = "Host";
static char __pyx_k__POST[] = "POST";
static char __pyx_k___buf[] = "_buf";
static char __pyx_k__args[] = "args";
static char __pyx_k__bind[] = "bind";
static char __pyx_k__code[] = "code";
static char __pyx_k__hint[] = "hint";
static char __pyx_k__http[] = "http";
static char __pyx_k__init[] = "init";
static char __pyx_k__loop[] = "loop";
static char __pyx_k__name[] = "name";
static char __pyx_k__path[] = "path";
static char __pyx_k__port[] = "port";
static char __pyx_k__read[] = "read";
static char __pyx_k__secs[] = "secs";
static char __pyx_k__size[] = "size";
static char __pyx_k__type[] = "type";
static char __pyx_k__wsgi[] = "wsgi";
static char __pyx_k___http[] = "_http";
static char __pyx_k__abort[] = "abort";
static char __pyx_k__bufev[] = "bufev";
static char __pyx_k__clear[] = "clear";
static char __pyx_k__event[] = "event";
static char __pyx_k__flags[] = "flags";
static char __pyx_k__input[] = "input";
static char __pyx_k__major[] = "major";
static char __pyx_k__minor[] = "minor";
static char __pyx_k__split[] = "split";
static char __pyx_k__write[] = "write";
static char __pyx_k__SIGINT[] = "SIGINT";
static char __pyx_k__delete[] = "delete";
static char __pyx_k__enable[] = "enable";
static char __pyx_k__evtype[] = "evtype";
static char __pyx_k__fileno[] = "fileno";
static char __pyx_k__handle[] = "handle";
static char __pyx_k__readcb[] = "readcb";
static char __pyx_k__reason[] = "reason";
static char __pyx_k__signal[] = "signal";
static char __pyx_k__simple[] = "simple";
static char __pyx_k__status[] = "status";
static char __pyx_k__stderr[] = "stderr";
static char __pyx_k__tv_sec[] = "tv_sec";
static char __pyx_k__DNS_PTR[] = "DNS_PTR";
static char __pyx_k__EV_READ[] = "EV_READ";
static char __pyx_k__HTTP_OK[] = "HTTP_OK";
static char __pyx_k__OSError[] = "OSError";
static char __pyx_k__SIGTERM[] = "SIGTERM";
static char __pyx_k____url__[] = "__url__";
static char __pyx_k__address[] = "address";
static char __pyx_k__disable[] = "disable";
static char __pyx_k__errorcb[] = "errorcb";
static char __pyx_k__headers[] = "headers";
static char __pyx_k__pending[] = "pending";
static char __pyx_k__timeout[] = "timeout";
static char __pyx_k__tv_usec[] = "tv_usec";
static char __pyx_k__writecb[] = "writecb";
static char __pyx_k__EV_WRITE[] = "EV_WRITE";
static char __pyx_k____init__[] = "__init__";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k___set_buf[] = "_set_buf";
static char __pyx_k___set_req[] = "_set_req";
static char __pyx_k__callback[] = "callback";
static char __pyx_k__dispatch[] = "dispatch";
static char __pyx_k__dns_init[] = "dns_init";
static char __pyx_k__ev_flags[] = "ev_flags";
static char __pyx_k__exc_info[] = "exc_info";
static char __pyx_k__nonblock[] = "nonblock";
static char __pyx_k__EV_SIGNAL[] = "EV_SIGNAL";
static char __pyx_k__PATH_INFO[] = "PATH_INFO";
static char __pyx_k__TypeError[] = "TypeError";
static char __pyx_k__read_secs[] = "read_secs";
static char __pyx_k__DNS_IPv4_A[] = "DNS_IPv4_A";
static char __pyx_k__EV_PERSIST[] = "EV_PERSIST";
static char __pyx_k__EV_TIMEOUT[] = "EV_TIMEOUT";
static char __pyx_k____author__[] = "__author__";
static char __pyx_k____callback[] = "__callback";
static char __pyx_k__splitlines[] = "splitlines";
static char __pyx_k__write_secs[] = "write_secs";
static char __pyx_k__REMOTE_ADDR[] = "REMOTE_ADDR";
static char __pyx_k__REMOTE_HOST[] = "REMOTE_HOST";
static char __pyx_k__REMOTE_PORT[] = "REMOTE_PORT";
static char __pyx_k__SCRIPT_NAME[] = "SCRIPT_NAME";
static char __pyx_k__SERVER_NAME[] = "SERVER_NAME";
static char __pyx_k__SERVER_PORT[] = "SERVER_PORT";
static char __pyx_k____event_exc[] = "__event_exc";
static char __pyx_k____license__[] = "__license__";
static char __pyx_k____version__[] = "__version__";
static char __pyx_k__bufferevent[] = "bufferevent";
static char __pyx_k__remote_host[] = "remote_host";
static char __pyx_k__remote_port[] = "remote_port";
static char __pyx_k__CONTENT_TYPE[] = "CONTENT_TYPE";
static char __pyx_k__DNS_ERR_NONE[] = "DNS_ERR_NONE";
static char __pyx_k__EVBUFFER_EOF[] = "EVBUFFER_EOF";
static char __pyx_k__QUERY_STRING[] = "QUERY_STRING";
static char __pyx_k__dns_shutdown[] = "dns_shutdown";
static char __pyx_k__headers_sent[] = "headers_sent";
static char __pyx_k__input_buffer[] = "input_buffer";
static char __pyx_k__register_app[] = "register_app";
static char __pyx_k__DNS_IPv6_AAAA[] = "DNS_IPv6_AAAA";
static char __pyx_k__EVBUFFER_READ[] = "EVBUFFER_READ";
static char __pyx_k__HTTP_MOVEPERM[] = "HTTP_MOVEPERM";
static char __pyx_k__HTTP_MOVETEMP[] = "HTTP_MOVETEMP";
static char __pyx_k__HTTP_NOTFOUND[] = "HTTP_NOTFOUND";
static char __pyx_k____copyright__[] = "__copyright__";
static char __pyx_k__fail_requests[] = "fail_requests";
static char __pyx_k__input_headers[] = "input_headers";
static char __pyx_k__AssertionError[] = "AssertionError";
static char __pyx_k__CONTENT_LENGTH[] = "CONTENT_LENGTH";
static char __pyx_k__DNS_ERR_FORMAT[] = "DNS_ERR_FORMAT";
static char __pyx_k__EVBUFFER_ERROR[] = "EVBUFFER_ERROR";
static char __pyx_k__EVBUFFER_WRITE[] = "EVBUFFER_WRITE";
static char __pyx_k__EVHTTP_REQUEST[] = "EVHTTP_REQUEST";
static char __pyx_k__EVHTTP_REQ_GET[] = "EVHTTP_REQ_GET";
static char __pyx_k__HTTP_NOCONTENT[] = "HTTP_NOCONTENT";
static char __pyx_k__REQUEST_METHOD[] = "REQUEST_METHOD";
static char __pyx_k____evdns_cbargs[] = "__evdns_cbargs";
static char __pyx_k__output_headers[] = "output_headers";
static char __pyx_k__unregister_app[] = "unregister_app";
static char __pyx_k__DNS_ERR_NOTIMPL[] = "DNS_ERR_NOTIMPL";
static char __pyx_k__DNS_ERR_REFUSED[] = "DNS_ERR_REFUSED";
static char __pyx_k__DNS_ERR_TIMEOUT[] = "DNS_ERR_TIMEOUT";
static char __pyx_k__DNS_ERR_UNKNOWN[] = "DNS_ERR_UNKNOWN";
static char __pyx_k__EVHTTP_REQ_HEAD[] = "EVHTTP_REQ_HEAD";
static char __pyx_k__EVHTTP_REQ_POST[] = "EVHTTP_REQ_POST";
static char __pyx_k__EVHTTP_RESPONSE[] = "EVHTTP_RESPONSE";
static char __pyx_k__HTTP_BADREQUEST[] = "HTTP_BADREQUEST";
static char __pyx_k__SERVER_PROTOCOL[] = "SERVER_PROTOCOL";
static char __pyx_k__DNS_ERR_NOTEXIST[] = "DNS_ERR_NOTEXIST";
static char __pyx_k__DNS_ERR_SHUTDOWN[] = "DNS_ERR_SHUTDOWN";
static char __pyx_k__EVBUFFER_TIMEOUT[] = "EVBUFFER_TIMEOUT";
static char __pyx_k__HTTP_NOTMODIFIED[] = "HTTP_NOTMODIFIED";
static char __pyx_k__HTTP_SERVUNAVAIL[] = "HTTP_SERVUNAVAIL";
static char __pyx_k__HTTP_method2name[] = "HTTP_method2name";
static char __pyx_k__HTTP_name2method[] = "HTTP_name2method";
static char __pyx_k__dns_resolve_ipv4[] = "dns_resolve_ipv4";
static char __pyx_k__dns_resolve_ipv6[] = "dns_resolve_ipv6";
static char __pyx_k__DNS_ERR_TRUNCATED[] = "DNS_ERR_TRUNCATED";
static char __pyx_k____simple_callback[] = "__simple_callback";
static char __pyx_k__DNS_QUERY_NO_SEARCH[] = "DNS_QUERY_NO_SEARCH";
static char __pyx_k___check_headers_sent[] = "_check_headers_sent";
static char __pyx_k__dns_resolve_reverse[] = "dns_resolve_reverse";
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_10;
static PyObject *__pyx_kp_s_11;
static PyObject *__pyx_kp_s_12;
static PyObject *__pyx_kp_s_13;
static PyObject *__pyx_kp_s_14;
static PyObject *__pyx_kp_s_15;
static PyObject *__pyx_kp_s_16;
static PyObject *__pyx_kp_s_17;
static PyObject *__pyx_kp_s_18;
static PyObject *__pyx_kp_s_20;
static PyObject *__pyx_kp_s_21;
static PyObject *__pyx_kp_s_22;
static PyObject *__pyx_kp_s_23;
static PyObject *__pyx_kp_s_24;
static PyObject *__pyx_kp_s_25;
static PyObject *__pyx_kp_s_26;
static PyObject *__pyx_n_s_27;
static PyObject *__pyx_kp_u_28;
static PyObject *__pyx_kp_u_29;
static PyObject *__pyx_kp_s_3;
static PyObject *__pyx_kp_u_30;
static PyObject *__pyx_kp_u_31;
static PyObject *__pyx_kp_u_32;
static PyObject *__pyx_kp_u_33;
static PyObject *__pyx_kp_u_34;
static PyObject *__pyx_kp_u_35;
static PyObject *__pyx_kp_u_36;
static PyObject *__pyx_kp_u_37;
static PyObject *__pyx_kp_u_38;
static PyObject *__pyx_kp_u_39;
static PyObject *__pyx_kp_s_4;
static PyObject *__pyx_kp_u_40;
static PyObject *__pyx_kp_u_41;
static PyObject *__pyx_kp_u_42;
static PyObject *__pyx_kp_u_43;
static PyObject *__pyx_n_s_44;
static PyObject *__pyx_kp_u_45;
static PyObject *__pyx_kp_u_46;
static PyObject *__pyx_kp_u_47;
static PyObject *__pyx_n_s_48;
static PyObject *__pyx_kp_u_49;
static PyObject *__pyx_kp_s_5;
static PyObject *__pyx_kp_u_50;
static PyObject *__pyx_kp_s_8;
static PyObject *__pyx_kp_s_9;
static PyObject *__pyx_kp_s__80;
static PyObject *__pyx_n_s__AssertionError;
static PyObject *__pyx_n_s__BSD;
static PyObject *__pyx_n_s__CONTENT_LENGTH;
static PyObject *__pyx_n_s__CONTENT_TYPE;
static PyObject *__pyx_n_s__DNS_ERR_FORMAT;
static PyObject *__pyx_n_s__DNS_ERR_NONE;
static PyObject *__pyx_n_s__DNS_ERR_NOTEXIST;
static PyObject *__pyx_n_s__DNS_ERR_NOTIMPL;
static PyObject *__pyx_n_s__DNS_ERR_REFUSED;
static PyObject *__pyx_n_s__DNS_ERR_SHUTDOWN;
static PyObject *__pyx_n_s__DNS_ERR_TIMEOUT;
static PyObject *__pyx_n_s__DNS_ERR_TRUNCATED;
static PyObject *__pyx_n_s__DNS_ERR_UNKNOWN;
static PyObject *__pyx_n_s__DNS_IPv4_A;
static PyObject *__pyx_n_s__DNS_IPv6_AAAA;
static PyObject *__pyx_n_s__DNS_PTR;
static PyObject *__pyx_n_s__DNS_QUERY_NO_SEARCH;
static PyObject *__pyx_n_s__EVBUFFER_EOF;
static PyObject *__pyx_n_s__EVBUFFER_ERROR;
static PyObject *__pyx_n_s__EVBUFFER_READ;
static PyObject *__pyx_n_s__EVBUFFER_TIMEOUT;
static PyObject *__pyx_n_s__EVBUFFER_WRITE;
static PyObject *__pyx_n_s__EVHTTP_REQUEST;
static PyObject *__pyx_n_s__EVHTTP_REQ_GET;
static PyObject *__pyx_n_s__EVHTTP_REQ_HEAD;
static PyObject *__pyx_n_s__EVHTTP_REQ_POST;
static PyObject *__pyx_n_s__EVHTTP_RESPONSE;
static PyObject *__pyx_n_s__EV_PERSIST;
static PyObject *__pyx_n_s__EV_READ;
static PyObject *__pyx_n_s__EV_SIGNAL;
static PyObject *__pyx_n_s__EV_TIMEOUT;
static PyObject *__pyx_n_s__EV_WRITE;
static PyObject *__pyx_n_s__GET;
static PyObject *__pyx_n_s__HEAD;
static PyObject *__pyx_n_s__HTTP_BADREQUEST;
static PyObject *__pyx_n_s__HTTP_MOVEPERM;
static PyObject *__pyx_n_s__HTTP_MOVETEMP;
static PyObject *__pyx_n_s__HTTP_NOCONTENT;
static PyObject *__pyx_n_s__HTTP_NOTFOUND;
static PyObject *__pyx_n_s__HTTP_NOTMODIFIED;
static PyObject *__pyx_n_s__HTTP_OK;
static PyObject *__pyx_n_s__HTTP_SERVUNAVAIL;
static PyObject *__pyx_n_s__HTTP_method2name;
static PyObject *__pyx_n_s__HTTP_name2method;
static PyObject *__pyx_n_s__OSError;
static PyObject *__pyx_n_s__PATH_INFO;
static PyObject *__pyx_n_s__POST;
static PyObject *__pyx_n_s__QUERY_STRING;
static PyObject *__pyx_n_s__REMOTE_ADDR;
static PyObject *__pyx_n_s__REMOTE_HOST;
static PyObject *__pyx_n_s__REMOTE_PORT;
static PyObject *__pyx_n_s__REQUEST_METHOD;
static PyObject *__pyx_n_s__SCRIPT_NAME;
static PyObject *__pyx_n_s__SERVER_NAME;
static PyObject *__pyx_n_s__SERVER_PORT;
static PyObject *__pyx_n_s__SERVER_PROTOCOL;
static PyObject *__pyx_n_s__SIGINT;
static PyObject *__pyx_n_s__SIGTERM;
static PyObject *__pyx_n_s__TypeError;
static PyObject *__pyx_n_s____author__;
static PyObject *__pyx_n_s____callback;
static PyObject *__pyx_n_s____copyright__;
static PyObject *__pyx_n_s____evdns_cbargs;
static PyObject *__pyx_n_s____event_exc;
static PyObject *__pyx_n_s____init__;
static PyObject *__pyx_n_s____license__;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____simple_callback;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s____url__;
static PyObject *__pyx_n_s____version__;
static PyObject *__pyx_n_s___buf;
static PyObject *__pyx_n_s___check_headers_sent;
static PyObject *__pyx_n_s___http;
static PyObject *__pyx_n_s___set_buf;
static PyObject *__pyx_n_s___set_req;
static PyObject *__pyx_n_s__abort;
static PyObject *__pyx_n_s__add;
static PyObject *__pyx_n_s__address;
static PyObject *__pyx_n_s__app;
static PyObject *__pyx_n_s__arg;
static PyObject *__pyx_n_s__args;
static PyObject *__pyx_n_s__bind;
static PyObject *__pyx_n_s__buf;
static PyObject *__pyx_n_s__bufev;
static PyObject *__pyx_n_s__bufferevent;
static PyObject *__pyx_n_s__callback;
static PyObject *__pyx_n_s__clear;
static PyObject *__pyx_n_s__code;
static PyObject *__pyx_n_s__delete;
static PyObject *__pyx_n_s__disable;
static PyObject *__pyx_n_s__dispatch;
static PyObject *__pyx_n_s__dns_init;
static PyObject *__pyx_n_s__dns_resolve_ipv4;
static PyObject *__pyx_n_s__dns_resolve_ipv6;
static PyObject *__pyx_n_s__dns_resolve_reverse;
static PyObject *__pyx_n_s__dns_shutdown;
static PyObject *__pyx_n_s__enable;
static PyObject *__pyx_n_s__end;
static PyObject *__pyx_n_s__errorcb;
static PyObject *__pyx_n_s__ev;
static PyObject *__pyx_n_s__ev_flags;
static PyObject *__pyx_n_s__event;
static PyObject *__pyx_n_s__evtype;
static PyObject *__pyx_n_s__exc_info;
static PyObject *__pyx_n_s__fail_requests;
static PyObject *__pyx_n_s__fileno;
static PyObject *__pyx_n_s__flags;
static PyObject *__pyx_n_s__handle;
static PyObject *__pyx_n_s__headers;
static PyObject *__pyx_n_s__headers_sent;
static PyObject *__pyx_n_s__hint;
static PyObject *__pyx_n_s__http;
static PyObject *__pyx_n_s__id;
static PyObject *__pyx_n_s__init;
static PyObject *__pyx_n_s__input;
static PyObject *__pyx_n_s__input_buffer;
static PyObject *__pyx_n_s__input_headers;
static PyObject *__pyx_n_s__ip;
static PyObject *__pyx_n_s__loop;
static PyObject *__pyx_n_s__major;
static PyObject *__pyx_n_s__min;
static PyObject *__pyx_n_s__minor;
static PyObject *__pyx_n_s__name;
static PyObject *__pyx_n_s__nonblock;
static PyObject *__pyx_n_s__off;
static PyObject *__pyx_n_s__output_headers;
static PyObject *__pyx_n_s__path;
static PyObject *__pyx_n_s__pending;
static PyObject *__pyx_n_s__port;
static PyObject *__pyx_n_s__read;
static PyObject *__pyx_n_s__read_secs;
static PyObject *__pyx_n_s__readcb;
static PyObject *__pyx_n_s__reason;
static PyObject *__pyx_n_s__register_app;
static PyObject *__pyx_n_s__remote_host;
static PyObject *__pyx_n_s__remote_port;
static PyObject *__pyx_n_s__req;
static PyObject *__pyx_n_s__run;
static PyObject *__pyx_n_s__secs;
static PyObject *__pyx_n_s__sig;
static PyObject *__pyx_n_s__signal;
static PyObject *__pyx_n_s__simple;
static PyObject *__pyx_n_s__size;
static PyObject *__pyx_n_s__split;
static PyObject *__pyx_n_s__splitlines;
static PyObject *__pyx_n_s__status;
static PyObject *__pyx_n_s__stderr;
static PyObject *__pyx_n_s__sys;
static PyObject *__pyx_n_s__timeout;
static PyObject *__pyx_n_s__tv;
static PyObject *__pyx_n_s__tv_sec;
static PyObject *__pyx_n_s__tv_usec;
static PyObject *__pyx_n_s__type;
static PyObject *__pyx_n_s__unregister_app;
static PyObject *__pyx_n_s__uri;
static PyObject *__pyx_n_s__write;
static PyObject *__pyx_n_s__write_secs;
static PyObject *__pyx_n_s__writecb;
static PyObject *__pyx_n_s__wsgi;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_4;
static PyObject *__pyx_int_5;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_int_65;
static PyObject *__pyx_int_66;
static PyObject *__pyx_int_67;
static PyObject *__pyx_int_68;
static PyObject *__pyx_int_80;
static PyObject *__pyx_int_200;
static PyObject *__pyx_int_204;
static PyObject *__pyx_int_301;
static PyObject *__pyx_int_302;
static PyObject *__pyx_int_304;
static PyObject *__pyx_int_400;
static PyObject *__pyx_int_404;
static PyObject *__pyx_int_503;
static PyObject *__pyx_int_0x01;
static PyObject *__pyx_int_0x02;
static PyObject *__pyx_int_0x04;
static PyObject *__pyx_int_0x08;
static PyObject *__pyx_int_0x10;
static PyObject *__pyx_int_0x20;
static PyObject *__pyx_int_0x40;
static PyObject *__pyx_k_2;

/* "event.pyx":73
 * __event_exc = None
 * 
 * cdef void __event_abort():             # <<<<<<<<<<<<<<
 *     global __event_exc
 * 
 */

static  void __pyx_f_5event___event_abort(void) {
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("__event_abort");

  /* "event.pyx":76
 *     global __event_exc
 * 
 *     event_loopbreak()             # <<<<<<<<<<<<<<
 *     __event_exc = sys.exc_info()
 *     if __event_exc[0] is None:
 */
  event_loopbreak();

  /* "event.pyx":77
 * 
 *     event_loopbreak()
 *     __event_exc = sys.exc_info()             # <<<<<<<<<<<<<<
 *     if __event_exc[0] is None:
 *         __event_exc = None
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__exc_info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____event_exc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "event.pyx":78
 *     event_loopbreak()
 *     __event_exc = sys.exc_info()
 *     if __event_exc[0] is None:             # <<<<<<<<<<<<<<
 *         __event_exc = None
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s____event_exc); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 == Py_None);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "event.pyx":79
 *     __event_exc = sys.exc_info()
 *     if __event_exc[0] is None:
 *         __event_exc = None             # <<<<<<<<<<<<<<
 * 
 * cdef void __event_handler(int fd, short evtype, void *arg) with gil:
 */
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s____event_exc, Py_None) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_WriteUnraisable("event.__event_abort");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "event.pyx":81
 *         __event_exc = None
 * 
 * cdef void __event_handler(int fd, short evtype, void *arg) with gil:             # <<<<<<<<<<<<<<
 *     (<object>arg).__callback(evtype)
 * 
 */

static  void __pyx_f_5event___event_handler(int __pyx_v_fd, short __pyx_v_evtype, void *__pyx_v_arg) {
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("__event_handler");

  /* "event.pyx":82
 * 
 * cdef void __event_handler(int fd, short evtype, void *arg) with gil:
 *     (<object>arg).__callback(evtype)             # <<<<<<<<<<<<<<
 * 
 * cdef void __simple_event_handler(int fd, short evtype, void *arg) with gil:
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_arg), __pyx_n_s____callback); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_evtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("event.__event_handler");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
}

/* "event.pyx":84
 *     (<object>arg).__callback(evtype)
 * 
 * cdef void __simple_event_handler(int fd, short evtype, void *arg) with gil:             # <<<<<<<<<<<<<<
 *     (<object>arg).__simple_callback(evtype)
 * 
 */

static  void __pyx_f_5event___simple_event_handler(int __pyx_v_fd, short __pyx_v_evtype, void *__pyx_v_arg) {
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("__simple_event_handler");

  /* "event.pyx":85
 * 
 * cdef void __simple_event_handler(int fd, short evtype, void *arg) with gil:
 *     (<object>arg).__simple_callback(evtype)             # <<<<<<<<<<<<<<
 * 
 * cdef class event:
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_arg), __pyx_n_s____simple_callback); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_evtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("event.__simple_event_handler");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
}

/* "event.pyx":105
 *     cdef timeval tv
 * 
 *     def __init__(self, callback, arg=None, short evtype=0, handle=-1,             # <<<<<<<<<<<<<<
 *                  simple=0):
 *         cdef event_handler handler
 */

static int __pyx_pf_5event_5event___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_5event_5event___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_arg = 0;
  short __pyx_v_evtype;
  PyObject *__pyx_v_handle = 0;
  PyObject *__pyx_v_simple = 0;
  __pyx_t_5event_event_handler __pyx_v_handler;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__callback,&__pyx_n_s__arg,&__pyx_n_s__evtype,&__pyx_n_s__handle,&__pyx_n_s__simple,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[5] = {0,0,0,0,0};
    values[1] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)__pyx_int_neg_1);
    values[4] = ((PyObject *)__pyx_int_0);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arg);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
      case  2:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__evtype);
        if (unlikely(value)) { values[2] = value; kw_args--; }
      }
      case  3:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__handle);
        if (unlikely(value)) { values[3] = value; kw_args--; }
      }
      case  4:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__simple);
        if (unlikely(value)) { values[4] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_callback = values[0];
    __pyx_v_arg = values[1];
    if (values[2]) {
      __pyx_v_evtype = __Pyx_PyInt_AsShort(values[2]); if (unlikely((__pyx_v_evtype == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_evtype = ((short)0);
    }
    __pyx_v_handle = values[3];
    __pyx_v_simple = values[4];
  } else {
    __pyx_v_arg = ((PyObject *)Py_None);
    __pyx_v_evtype = ((short)0);
    __pyx_v_handle = ((PyObject *)__pyx_int_neg_1);
    __pyx_v_simple = ((PyObject *)__pyx_int_0);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  5: __pyx_v_simple = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: __pyx_v_handle = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: __pyx_v_evtype = __Pyx_PyInt_AsShort(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_evtype == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  2: __pyx_v_arg = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.event.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_callback);
  __Pyx_INCREF(__pyx_v_arg);
  __Pyx_INCREF(__pyx_v_handle);
  __Pyx_INCREF(__pyx_v_simple);

  /* "event.pyx":109
 *         cdef event_handler handler
 * 
 *         self.callback = callback             # <<<<<<<<<<<<<<
 *         self.args = arg
 *         self.evtype = evtype
 */
  __Pyx_INCREF(__pyx_v_callback);
  __Pyx_GIVEREF(__pyx_v_callback);
  __Pyx_GOTREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->callback);
  __Pyx_DECREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->callback);
  ((struct __pyx_obj_5event_event *)__pyx_v_self)->callback = __pyx_v_callback;

  /* "event.pyx":110
 * 
 *         self.callback = callback
 *         self.args = arg             # <<<<<<<<<<<<<<
 *         self.evtype = evtype
 *         self.handle = handle
 */
  __Pyx_INCREF(__pyx_v_arg);
  __Pyx_GIVEREF(__pyx_v_arg);
  __Pyx_GOTREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->args);
  __Pyx_DECREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->args);
  ((struct __pyx_obj_5event_event *)__pyx_v_self)->args = __pyx_v_arg;

  /* "event.pyx":111
 *         self.callback = callback
 *         self.args = arg
 *         self.evtype = evtype             # <<<<<<<<<<<<<<
 *         self.handle = handle
 *         if simple:
 */
  __pyx_t_1 = PyInt_FromLong(__pyx_v_evtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->evtype);
  __Pyx_DECREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->evtype);
  ((struct __pyx_obj_5event_event *)__pyx_v_self)->evtype = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "event.pyx":112
 *         self.args = arg
 *         self.evtype = evtype
 *         self.handle = handle             # <<<<<<<<<<<<<<
 *         if simple:
 *             handler = __simple_event_handler
 */
  __Pyx_INCREF(__pyx_v_handle);
  __Pyx_GIVEREF(__pyx_v_handle);
  __Pyx_GOTREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->handle);
  __Pyx_DECREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->handle);
  ((struct __pyx_obj_5event_event *)__pyx_v_self)->handle = __pyx_v_handle;

  /* "event.pyx":113
 *         self.evtype = evtype
 *         self.handle = handle
 *         if simple:             # <<<<<<<<<<<<<<
 *             handler = __simple_event_handler
 *         else:
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_simple); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {

    /* "event.pyx":114
 *         self.handle = handle
 *         if simple:
 *             handler = __simple_event_handler             # <<<<<<<<<<<<<<
 *         else:
 *             handler = __event_handler
 */
    __pyx_v_handler = __pyx_f_5event___simple_event_handler;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "event.pyx":116
 *             handler = __simple_event_handler
 *         else:
 *             handler = __event_handler             # <<<<<<<<<<<<<<
 *         if evtype == 0 and not handle:
 *             evtimer_set(&self.ev, handler, <void *>self)
 */
    __pyx_v_handler = __pyx_f_5event___event_handler;
  }
  __pyx_L6:;

  /* "event.pyx":117
 *         else:
 *             handler = __event_handler
 *         if evtype == 0 and not handle:             # <<<<<<<<<<<<<<
 *             evtimer_set(&self.ev, handler, <void *>self)
 *         else:
 */
  __pyx_t_2 = (__pyx_v_evtype == 0);
  if (__pyx_t_2) {
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_handle); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = (!__pyx_t_3);
    __pyx_t_3 = __pyx_t_4;
  } else {
    __pyx_t_3 = __pyx_t_2;
  }
  if (__pyx_t_3) {

    /* "event.pyx":118
 *             handler = __event_handler
 *         if evtype == 0 and not handle:
 *             evtimer_set(&self.ev, handler, <void *>self)             # <<<<<<<<<<<<<<
 *         else:
 *             if not isinstance(handle, int):
 */
    evtimer_set((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), __pyx_v_handler, ((void *)__pyx_v_self));
    goto __pyx_L7;
  }
  /*else*/ {

    /* "event.pyx":120
 *             evtimer_set(&self.ev, handler, <void *>self)
 *         else:
 *             if not isinstance(handle, int):             # <<<<<<<<<<<<<<
 *                 handle = handle.fileno()
 *             event_set(&self.ev, handle, evtype, handler, <void *>self)
 */
    __pyx_t_3 = PyObject_TypeCheck(__pyx_v_handle, ((PyTypeObject *)((PyObject*)&PyInt_Type))); 
    __pyx_t_2 = (!__pyx_t_3);
    if (__pyx_t_2) {

      /* "event.pyx":121
 *         else:
 *             if not isinstance(handle, int):
 *                 handle = handle.fileno()             # <<<<<<<<<<<<<<
 *             event_set(&self.ev, handle, evtype, handler, <void *>self)
 * 
 */
      __pyx_t_1 = PyObject_GetAttr(__pyx_v_handle, __pyx_n_s__fileno); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_v_handle);
      __pyx_v_handle = __pyx_t_5;
      __pyx_t_5 = 0;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "event.pyx":122
 *             if not isinstance(handle, int):
 *                 handle = handle.fileno()
 *             event_set(&self.ev, handle, evtype, handler, <void *>self)             # <<<<<<<<<<<<<<
 * 
 *     def __simple_callback(self, short evtype):
 */
    __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_handle); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    event_set((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), __pyx_t_6, __pyx_v_evtype, __pyx_v_handler, ((void *)__pyx_v_self));
  }
  __pyx_L7:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("event.event.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_callback);
  __Pyx_DECREF(__pyx_v_arg);
  __Pyx_DECREF(__pyx_v_handle);
  __Pyx_DECREF(__pyx_v_simple);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":124
 *             event_set(&self.ev, handle, evtype, handler, <void *>self)
 * 
 *     def __simple_callback(self, short evtype):             # <<<<<<<<<<<<<<
 *         try:
 *             if self.callback(*self.args) != None:
 */

static PyObject *__pyx_pf_5event_5event___simple_callback(PyObject *__pyx_v_self, PyObject *__pyx_arg_evtype); /*proto*/
static PyObject *__pyx_pf_5event_5event___simple_callback(PyObject *__pyx_v_self, PyObject *__pyx_arg_evtype) {
  short __pyx_v_evtype;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  short __pyx_t_6;
  int __pyx_t_7;
  __Pyx_RefNannySetupContext("__simple_callback");
  assert(__pyx_arg_evtype); {
    __pyx_v_evtype = __Pyx_PyInt_AsShort(__pyx_arg_evtype); if (unlikely((__pyx_v_evtype == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.event.__simple_callback");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "event.pyx":125
 * 
 *     def __simple_callback(self, short evtype):
 *         try:             # <<<<<<<<<<<<<<
 *             if self.callback(*self.args) != None:
 *                 if self.tv.tv_sec or self.tv.tv_usec:
 */
  {
    PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
    __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
    __Pyx_XGOTREF(__pyx_save_exc_type);
    __Pyx_XGOTREF(__pyx_save_exc_value);
    __Pyx_XGOTREF(__pyx_save_exc_tb);
    /*try:*/ {

      /* "event.pyx":126
 *     def __simple_callback(self, short evtype):
 *         try:
 *             if self.callback(*self.args) != None:             # <<<<<<<<<<<<<<
 *                 if self.tv.tv_sec or self.tv.tv_usec:
 *                     event_add(&self.ev, &self.tv)
 */
      __pyx_t_1 = PySequence_Tuple(((struct __pyx_obj_5event_event *)__pyx_v_self)->args); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_1));
      __pyx_t_2 = PyObject_Call(((struct __pyx_obj_5event_event *)__pyx_v_self)->callback, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, Py_None, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_3) {

        /* "event.pyx":127
 *         try:
 *             if self.callback(*self.args) != None:
 *                 if self.tv.tv_sec or self.tv.tv_usec:             # <<<<<<<<<<<<<<
 *                     event_add(&self.ev, &self.tv)
 *                 else:
 */
        if (!((struct __pyx_obj_5event_event *)__pyx_v_self)->tv.tv_sec) {
          __pyx_t_3 = ((struct __pyx_obj_5event_event *)__pyx_v_self)->tv.tv_usec;
        } else {
          __pyx_t_3 = ((struct __pyx_obj_5event_event *)__pyx_v_self)->tv.tv_sec;
        }
        if (__pyx_t_3) {

          /* "event.pyx":128
 *             if self.callback(*self.args) != None:
 *                 if self.tv.tv_sec or self.tv.tv_usec:
 *                     event_add(&self.ev, &self.tv)             # <<<<<<<<<<<<<<
 *                 else:
 *                     event_add(&self.ev, NULL)
 */
          event_add((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), (&((struct __pyx_obj_5event_event *)__pyx_v_self)->tv));
          goto __pyx_L14;
        }
        /*else*/ {

          /* "event.pyx":130
 *                     event_add(&self.ev, &self.tv)
 *                 else:
 *                     event_add(&self.ev, NULL)             # <<<<<<<<<<<<<<
 *         except:
 *             __event_abort()
 */
          event_add((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), NULL);
        }
        __pyx_L14:;
        goto __pyx_L13;
      }
      __pyx_L13:;
    }
    __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
    __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
    __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
    goto __pyx_L12_try_end;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "event.pyx":131
 *                 else:
 *                     event_add(&self.ev, NULL)
 *         except:             # <<<<<<<<<<<<<<
 *             __event_abort()
 *         # XXX - account for event.signal() EV_PERSIST
 */
    /*except:*/ {
      __Pyx_AddTraceback("event.event.__simple_callback");
      if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L7_except_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_4);

      /* "event.pyx":132
 *                     event_add(&self.ev, NULL)
 *         except:
 *             __event_abort()             # <<<<<<<<<<<<<<
 *         # XXX - account for event.signal() EV_PERSIST
 *         if not (evtype & EV_SIGNAL) and \
 */
      __pyx_f_5event___event_abort();
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      goto __pyx_L6_exception_handled;
    }
    __pyx_L7_except_error:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L1_error;
    __pyx_L6_exception_handled:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    __pyx_L12_try_end:;
  }

  /* "event.pyx":134
 *             __event_abort()
 *         # XXX - account for event.signal() EV_PERSIST
 *         if not (evtype & EV_SIGNAL) and \             # <<<<<<<<<<<<<<
 *            not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT, NULL):
 *             Py_DECREF(self)
 */
  __pyx_t_4 = PyInt_FromLong(__pyx_v_evtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_SIGNAL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_And(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = (!__pyx_t_3);
  if (__pyx_t_5) {

    /* "event.pyx":135
 *         # XXX - account for event.signal() EV_PERSIST
 *         if not (evtype & EV_SIGNAL) and \
 *            not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT, NULL):             # <<<<<<<<<<<<<<
 *             Py_DECREF(self)
 * 
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_READ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_WRITE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyNumber_Or(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_SIGNAL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyNumber_Or(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_TIMEOUT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyNumber_Or(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_6 = __Pyx_PyInt_AsShort(__pyx_t_4); if (unlikely((__pyx_t_6 == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = (!event_pending((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), __pyx_t_6, NULL));
    __pyx_t_7 = __pyx_t_3;
  } else {
    __pyx_t_7 = __pyx_t_5;
  }
  if (__pyx_t_7) {

    /* "event.pyx":136
 *         if not (evtype & EV_SIGNAL) and \
 *            not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT, NULL):
 *             Py_DECREF(self)             # <<<<<<<<<<<<<<
 * 
 *     def __callback(self, short evtype):
 */
    Py_DECREF(__pyx_v_self);
    goto __pyx_L17;
  }
  __pyx_L17:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.event.__simple_callback");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":138
 *             Py_DECREF(self)
 * 
 *     def __callback(self, short evtype):             # <<<<<<<<<<<<<<
 *         try:
 *             self.callback(self, self.handle, evtype, self.args)
 */

static PyObject *__pyx_pf_5event_5event___callback(PyObject *__pyx_v_self, PyObject *__pyx_arg_evtype); /*proto*/
static PyObject *__pyx_pf_5event_5event___callback(PyObject *__pyx_v_self, PyObject *__pyx_arg_evtype) {
  short __pyx_v_evtype;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  short __pyx_t_4;
  int __pyx_t_5;
  __Pyx_RefNannySetupContext("__callback");
  assert(__pyx_arg_evtype); {
    __pyx_v_evtype = __Pyx_PyInt_AsShort(__pyx_arg_evtype); if (unlikely((__pyx_v_evtype == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.event.__callback");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "event.pyx":139
 * 
 *     def __callback(self, short evtype):
 *         try:             # <<<<<<<<<<<<<<
 *             self.callback(self, self.handle, evtype, self.args)
 *         except:
 */
  {
    PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
    __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
    __Pyx_XGOTREF(__pyx_save_exc_type);
    __Pyx_XGOTREF(__pyx_save_exc_value);
    __Pyx_XGOTREF(__pyx_save_exc_tb);
    /*try:*/ {

      /* "event.pyx":140
 *     def __callback(self, short evtype):
 *         try:
 *             self.callback(self, self.handle, evtype, self.args)             # <<<<<<<<<<<<<<
 *         except:
 *             __event_abort()
 */
      __pyx_t_1 = PyInt_FromLong(__pyx_v_evtype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_v_self);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self);
      __Pyx_GIVEREF(__pyx_v_self);
      __Pyx_INCREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->handle);
      PyTuple_SET_ITEM(__pyx_t_2, 1, ((struct __pyx_obj_5event_event *)__pyx_v_self)->handle);
      __Pyx_GIVEREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->handle);
      PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_INCREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->args);
      PyTuple_SET_ITEM(__pyx_t_2, 3, ((struct __pyx_obj_5event_event *)__pyx_v_self)->args);
      __Pyx_GIVEREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->args);
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(((struct __pyx_obj_5event_event *)__pyx_v_self)->callback, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L5_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
    __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
    __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
    goto __pyx_L12_try_end;
    __pyx_L5_error:;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "event.pyx":141
 *         try:
 *             self.callback(self, self.handle, evtype, self.args)
 *         except:             # <<<<<<<<<<<<<<
 *             __event_abort()
 *         if not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT, NULL):
 */
    /*except:*/ {
      __Pyx_AddTraceback("event.event.__callback");
      if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L7_except_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_3);

      /* "event.pyx":142
 *             self.callback(self, self.handle, evtype, self.args)
 *         except:
 *             __event_abort()             # <<<<<<<<<<<<<<
 *         if not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT, NULL):
 *             Py_DECREF(self)
 */
      __pyx_f_5event___event_abort();
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      goto __pyx_L6_exception_handled;
    }
    __pyx_L7_except_error:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L1_error;
    __pyx_L6_exception_handled:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    __pyx_L12_try_end:;
  }

  /* "event.pyx":143
 *         except:
 *             __event_abort()
 *         if not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT, NULL):             # <<<<<<<<<<<<<<
 *             Py_DECREF(self)
 * 
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_READ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_WRITE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Or(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_SIGNAL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Or(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_TIMEOUT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Or(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyInt_AsShort(__pyx_t_1); if (unlikely((__pyx_t_4 == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = (!event_pending((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), __pyx_t_4, NULL));
  if (__pyx_t_5) {

    /* "event.pyx":144
 *             __event_abort()
 *         if not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT, NULL):
 *             Py_DECREF(self)             # <<<<<<<<<<<<<<
 * 
 *     def add(self, float timeout=-1):
 */
    Py_DECREF(__pyx_v_self);
    goto __pyx_L15;
  }
  __pyx_L15:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("event.event.__callback");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":146
 *             Py_DECREF(self)
 * 
 *     def add(self, float timeout=-1):             # <<<<<<<<<<<<<<
 *         """Add event to be executed after an optional timeout.
 * 
 */

static PyObject *__pyx_pf_5event_5event_add(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5event_5event_add[] = "Add event to be executed after an optional timeout.\n\n        Arguments:\n        \n        timeout -- seconds after which the event will be executed\n        ";
static PyObject *__pyx_pf_5event_5event_add(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  float __pyx_v_timeout;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  short __pyx_t_4;
  int __pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__timeout,0};
  __Pyx_RefNannySetupContext("add");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__timeout);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "add") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    if (values[0]) {
      __pyx_v_timeout = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_timeout == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_timeout = ((float)-1);
    }
  } else {
    __pyx_v_timeout = ((float)-1);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_timeout = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_timeout == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.event.add");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "event.pyx":153
 *         timeout -- seconds after which the event will be executed
 *         """
 *         if not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT,             # <<<<<<<<<<<<<<
 *                              NULL):
 *             Py_INCREF(self)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_READ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_WRITE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Or(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_SIGNAL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Or(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_TIMEOUT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Or(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyInt_AsShort(__pyx_t_3); if (unlikely((__pyx_t_4 == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "event.pyx":154
 *         """
 *         if not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT,
 *                              NULL):             # <<<<<<<<<<<<<<
 *             Py_INCREF(self)
 *         self.timeout = timeout
 */
  __pyx_t_5 = (!event_pending((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), __pyx_t_4, NULL));
  if (__pyx_t_5) {

    /* "event.pyx":155
 *         if not event_pending(&self.ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT,
 *                              NULL):
 *             Py_INCREF(self)             # <<<<<<<<<<<<<<
 *         self.timeout = timeout
 *         if timeout >= 0.0:
 */
    Py_INCREF(__pyx_v_self);
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "event.pyx":156
 *                              NULL):
 *             Py_INCREF(self)
 *         self.timeout = timeout             # <<<<<<<<<<<<<<
 *         if timeout >= 0.0:
 *             self.tv.tv_sec = <long>timeout
 */
  ((struct __pyx_obj_5event_event *)__pyx_v_self)->timeout = __pyx_v_timeout;

  /* "event.pyx":157
 *             Py_INCREF(self)
 *         self.timeout = timeout
 *         if timeout >= 0.0:             # <<<<<<<<<<<<<<
 *             self.tv.tv_sec = <long>timeout
 *             self.tv.tv_usec = <unsigned int>((timeout - <float>self.tv.tv_sec) * 1000000.0)
 */
  __pyx_t_5 = (__pyx_v_timeout >= 0.0);
  if (__pyx_t_5) {

    /* "event.pyx":158
 *         self.timeout = timeout
 *         if timeout >= 0.0:
 *             self.tv.tv_sec = <long>timeout             # <<<<<<<<<<<<<<
 *             self.tv.tv_usec = <unsigned int>((timeout - <float>self.tv.tv_sec) * 1000000.0)
 *             event_add(&self.ev, &self.tv)
 */
    ((struct __pyx_obj_5event_event *)__pyx_v_self)->tv.tv_sec = ((long)__pyx_v_timeout);

    /* "event.pyx":159
 *         if timeout >= 0.0:
 *             self.tv.tv_sec = <long>timeout
 *             self.tv.tv_usec = <unsigned int>((timeout - <float>self.tv.tv_sec) * 1000000.0)             # <<<<<<<<<<<<<<
 *             event_add(&self.ev, &self.tv)
 *         else:
 */
    ((struct __pyx_obj_5event_event *)__pyx_v_self)->tv.tv_usec = ((unsigned int)((__pyx_v_timeout - ((float)((struct __pyx_obj_5event_event *)__pyx_v_self)->tv.tv_sec)) * 1000000.0));

    /* "event.pyx":160
 *             self.tv.tv_sec = <long>timeout
 *             self.tv.tv_usec = <unsigned int>((timeout - <float>self.tv.tv_sec) * 1000000.0)
 *             event_add(&self.ev, &self.tv)             # <<<<<<<<<<<<<<
 *         else:
 *             self.tv.tv_sec = self.tv.tv_usec = 0
 */
    event_add((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), (&((struct __pyx_obj_5event_event *)__pyx_v_self)->tv));
    goto __pyx_L7;
  }
  /*else*/ {

    /* "event.pyx":162
 *             event_add(&self.ev, &self.tv)
 *         else:
 *             self.tv.tv_sec = self.tv.tv_usec = 0             # <<<<<<<<<<<<<<
 *             event_add(&self.ev, NULL)
 * 
 */
    ((struct __pyx_obj_5event_event *)__pyx_v_self)->tv.tv_sec = 0;
    ((struct __pyx_obj_5event_event *)__pyx_v_self)->tv.tv_usec = 0;

    /* "event.pyx":163
 *         else:
 *             self.tv.tv_sec = self.tv.tv_usec = 0
 *             event_add(&self.ev, NULL)             # <<<<<<<<<<<<<<
 * 
 *     def pending(self):
 */
    event_add((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), NULL);
  }
  __pyx_L7:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("event.event.add");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":165
 *             event_add(&self.ev, NULL)
 * 
 *     def pending(self):             # <<<<<<<<<<<<<<
 *         """Return 1 if the event is scheduled to run, or else 0."""
 *         return event_pending(&self.ev, EV_TIMEOUT|EV_SIGNAL|EV_READ|EV_WRITE, NULL)
 */

static PyObject *__pyx_pf_5event_5event_pending(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_5event_5event_pending[] = "Return 1 if the event is scheduled to run, or else 0.";
static PyObject *__pyx_pf_5event_5event_pending(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  short __pyx_t_4;
  __Pyx_RefNannySetupContext("pending");

  /* "event.pyx":167
 *     def pending(self):
 *         """Return 1 if the event is scheduled to run, or else 0."""
 *         return event_pending(&self.ev, EV_TIMEOUT|EV_SIGNAL|EV_READ|EV_WRITE, NULL)             # <<<<<<<<<<<<<<
 * 
 *     def delete(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_TIMEOUT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_SIGNAL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Or(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_READ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyNumber_Or(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_WRITE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_Or(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyInt_AsShort(__pyx_t_3); if (unlikely((__pyx_t_4 == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromLong(event_pending((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev), __pyx_t_4, NULL)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("event.event.pending");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":169
 *         return event_pending(&self.ev, EV_TIMEOUT|EV_SIGNAL|EV_READ|EV_WRITE, NULL)
 * 
 *     def delete(self):             # <<<<<<<<<<<<<<
 *         """Remove event from the event queue."""
 *         if self.pending():
 */

static PyObject *__pyx_pf_5event_5event_delete(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_5event_5event_delete[] = "Remove event from the event queue.";
static PyObject *__pyx_pf_5event_5event_delete(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("delete");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "event.pyx":171
 *     def delete(self):
 *         """Remove event from the event queue."""
 *         if self.pending():             # <<<<<<<<<<<<<<
 *             event_del(&self.ev)
 *             Py_DECREF(self)
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__pending); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "event.pyx":172
 *         """Remove event from the event queue."""
 *         if self.pending():
 *             event_del(&self.ev)             # <<<<<<<<<<<<<<
 *             Py_DECREF(self)
 * 
 */
    event_del((&((struct __pyx_obj_5event_event *)__pyx_v_self)->ev));

    /* "event.pyx":173
 *         if self.pending():
 *             event_del(&self.ev)
 *             Py_DECREF(self)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    Py_DECREF(__pyx_v_self);
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.event.delete");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":175
 *             Py_DECREF(self)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         self.delete()
 * 
 */

static void __pyx_pf_5event_5event___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_5event_5event___dealloc__(PyObject *__pyx_v_self) {
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("__dealloc__");

  /* "event.pyx":176
 * 
 *     def __dealloc__(self):
 *         self.delete()             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__delete); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.event.__dealloc__");
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "event.pyx":178
 *         self.delete()
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return '<event flags=0x%x, handle=%s, callback=%s, arg=%s>' % \
 *                (self.ev.ev_flags, self.handle, self.callback, self.args)
 */

static PyObject *__pyx_pf_5event_5event___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_5event_5event___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("__repr__");

  /* "event.pyx":179
 * 
 *     def __repr__(self):
 *         return '<event flags=0x%x, handle=%s, callback=%s, arg=%s>' % \             # <<<<<<<<<<<<<<
 *                (self.ev.ev_flags, self.handle, self.callback, self.args)
 * 
 */
  __Pyx_XDECREF(__pyx_r);

  /* "event.pyx":180
 *     def __repr__(self):
 *         return '<event flags=0x%x, handle=%s, callback=%s, arg=%s>' % \
 *                (self.ev.ev_flags, self.handle, self.callback, self.args)             # <<<<<<<<<<<<<<
 * 
 * def init():
 */
  __pyx_t_1 = PyInt_FromLong(((struct __pyx_obj_5event_event *)__pyx_v_self)->ev.ev_flags); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->handle);
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((struct __pyx_obj_5event_event *)__pyx_v_self)->handle);
  __Pyx_GIVEREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->handle);
  __Pyx_INCREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->callback);
  PyTuple_SET_ITEM(__pyx_t_2, 2, ((struct __pyx_obj_5event_event *)__pyx_v_self)->callback);
  __Pyx_GIVEREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->callback);
  __Pyx_INCREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->args);
  PyTuple_SET_ITEM(__pyx_t_2, 3, ((struct __pyx_obj_5event_event *)__pyx_v_self)->args);
  __Pyx_GIVEREF(((struct __pyx_obj_5event_event *)__pyx_v_self)->args);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.event.__repr__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":182
 *                (self.ev.ev_flags, self.handle, self.callback, self.args)
 * 
 * def init():             # <<<<<<<<<<<<<<
 *     """Initialize event queue."""
 *     event_init()
 */

static PyObject *__pyx_pf_5event_init(PyObject *__pyx_self, PyObject *unused); /*proto*/
static char __pyx_doc_5event_init[] = "Initialize event queue.";
static PyObject *__pyx_pf_5event_init(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("init");
  __pyx_self = __pyx_self;

  /* "event.pyx":184
 * def init():
 *     """Initialize event queue."""
 *     event_init()             # <<<<<<<<<<<<<<
 * 
 * def dispatch():
 */
  event_init();

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":186
 *     event_init()
 * 
 * def dispatch():             # <<<<<<<<<<<<<<
 *     """Dispatch all events on the event queue.
 *     Returns -1 on error, 0 on success, and 1 if no events are registered.
 */

static PyObject *__pyx_pf_5event_dispatch(PyObject *__pyx_self, PyObject *unused); /*proto*/
static char __pyx_doc_5event_dispatch[] = "Dispatch all events on the event queue.\n    Returns -1 on error, 0 on success, and 1 if no events are registered.\n    ";
static PyObject *__pyx_pf_5event_dispatch(PyObject *__pyx_self, PyObject *unused) {
  int __pyx_v_ret;
  PyObject *__pyx_v_t;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("dispatch");
  __pyx_self = __pyx_self;
  __pyx_v_t = Py_None; __Pyx_INCREF(Py_None);

  /* "event.pyx":192
 *     cdef int ret
 *     global __event_exc
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = event_dispatch()
 *     if __event_exc:
 */
  { PyThreadState *_save;
    Py_UNBLOCK_THREADS
    /*try:*/ {

      /* "event.pyx":193
 *     global __event_exc
 *     with nogil:
 *         ret = event_dispatch()             # <<<<<<<<<<<<<<
 *     if __event_exc:
 *         t = __event_exc
 */
      __pyx_v_ret = event_dispatch();
    }
    /*finally:*/ {

      /* "event.pyx":192
 *     cdef int ret
 *     global __event_exc
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = event_dispatch()
 *     if __event_exc:
 */
      Py_BLOCK_THREADS
    }
  }

  /* "event.pyx":194
 *     with nogil:
 *         ret = event_dispatch()
 *     if __event_exc:             # <<<<<<<<<<<<<<
 *         t = __event_exc
 *         __event_exc = None
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s____event_exc); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "event.pyx":195
 *         ret = event_dispatch()
 *     if __event_exc:
 *         t = __event_exc             # <<<<<<<<<<<<<<
 *         __event_exc = None
 *         raise t[0], t[1], t[2]
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s____event_exc); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_v_t);
    __pyx_v_t = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "event.pyx":196
 *     if __event_exc:
 *         t = __event_exc
 *         __event_exc = None             # <<<<<<<<<<<<<<
 *         raise t[0], t[1], t[2]
 *     return ret
 */
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s____event_exc, Py_None) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "event.pyx":197
 *         t = __event_exc
 *         __event_exc = None
 *         raise t[0], t[1], t[2]             # <<<<<<<<<<<<<<
 *     return ret
 * 
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_t, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_t, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_t, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_1, __pyx_t_3, __pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[3]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "event.pyx":198
 *         __event_exc = None
 *         raise t[0], t[1], t[2]
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * def loop(nonblock=False):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_ret); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.dispatch");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":200
 *     return ret
 * 
 * def loop(nonblock=False):             # <<<<<<<<<<<<<<
 *     """Dispatch all pending events on queue in a single pass.
 *     Returns -1 on error, 0 on success, and 1 if no events are registered."""
 */

static PyObject *__pyx_pf_5event_loop(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5event_loop[] = "Dispatch all pending events on queue in a single pass.\n    Returns -1 on error, 0 on success, and 1 if no events are registered.";
static PyObject *__pyx_pf_5event_loop(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_nonblock = 0;
  int __pyx_v_flags;
  int __pyx_v_ret;
  PyObject *__pyx_v_t;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__nonblock,0};
  __Pyx_RefNannySetupContext("loop");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    values[0] = __pyx_k_2;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__nonblock);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "loop") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_nonblock = values[0];
  } else {
    __pyx_v_nonblock = __pyx_k_2;
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_nonblock = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("loop", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.loop");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_nonblock);
  __pyx_v_t = Py_None; __Pyx_INCREF(Py_None);

  /* "event.pyx":205
 *     cdef int flags, ret
 *     global __event_exc
 *     flags = EVLOOP_ONCE             # <<<<<<<<<<<<<<
 *     if nonblock:
 *         flags = EVLOOP_ONCE|EVLOOP_NONBLOCK
 */
  __pyx_v_flags = EVLOOP_ONCE;

  /* "event.pyx":206
 *     global __event_exc
 *     flags = EVLOOP_ONCE
 *     if nonblock:             # <<<<<<<<<<<<<<
 *         flags = EVLOOP_ONCE|EVLOOP_NONBLOCK
 *     with nogil:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_nonblock); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "event.pyx":207
 *     flags = EVLOOP_ONCE
 *     if nonblock:
 *         flags = EVLOOP_ONCE|EVLOOP_NONBLOCK             # <<<<<<<<<<<<<<
 *     with nogil:
 *         ret = event_loop(flags)
 */
    __pyx_v_flags = (EVLOOP_ONCE | EVLOOP_NONBLOCK);
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "event.pyx":208
 *     if nonblock:
 *         flags = EVLOOP_ONCE|EVLOOP_NONBLOCK
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = event_loop(flags)
 *     if __event_exc:
 */
  { PyThreadState *_save;
    Py_UNBLOCK_THREADS
    /*try:*/ {

      /* "event.pyx":209
 *         flags = EVLOOP_ONCE|EVLOOP_NONBLOCK
 *     with nogil:
 *         ret = event_loop(flags)             # <<<<<<<<<<<<<<
 *     if __event_exc:
 *         t = __event_exc
 */
      __pyx_v_ret = event_loop(__pyx_v_flags);
    }
    /*finally:*/ {

      /* "event.pyx":208
 *     if nonblock:
 *         flags = EVLOOP_ONCE|EVLOOP_NONBLOCK
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = event_loop(flags)
 *     if __event_exc:
 */
      Py_BLOCK_THREADS
    }
  }

  /* "event.pyx":210
 *     with nogil:
 *         ret = event_loop(flags)
 *     if __event_exc:             # <<<<<<<<<<<<<<
 *         t = __event_exc
 *         __event_exc = None
 */
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s____event_exc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_1) {

    /* "event.pyx":211
 *         ret = event_loop(flags)
 *     if __event_exc:
 *         t = __event_exc             # <<<<<<<<<<<<<<
 *         __event_exc = None
 *         raise t[0], t[1], t[2]
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s____event_exc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_v_t);
    __pyx_v_t = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "event.pyx":212
 *     if __event_exc:
 *         t = __event_exc
 *         __event_exc = None             # <<<<<<<<<<<<<<
 *         raise t[0], t[1], t[2]
 *     return ret
 */
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s____event_exc, Py_None) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "event.pyx":213
 *         t = __event_exc
 *         __event_exc = None
 *         raise t[0], t[1], t[2]             # <<<<<<<<<<<<<<
 *     return ret
 * 
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_t, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_t, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_t, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_2, __pyx_t_3, __pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[3]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "event.pyx":214
 *         __event_exc = None
 *         raise t[0], t[1], t[2]
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * def abort():
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_ret); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.loop");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_DECREF(__pyx_v_nonblock);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "event.pyx":216
 *     return ret
 * 
 * def abort():             # <<<<<<<<<<<<<<
 *     """Abort event dispatch loop."""
 *     __event_abort()
 */

static PyObject *__pyx_pf_5event_abort(PyObject *__pyx_self, PyObject *unused); /*proto*/
static char __pyx_doc_5event_abort[] = "Abort event dispatch loop.";
static PyObject *__pyx_pf_5event_abort(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("abort");
  __pyx_self = __pyx_self;

  /* "event.pyx":218
 * def abort():
 *     """Abort event dispatch loop."""
 *     __event_abort()             # <<<<<<<<<<<<<<
 * 
 * include "simple.pxi"
 */
  __pyx_f_5event___event_abort();

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "simple.pxi":15
 *     *args    -- optional callback arguments
 *     """
 *     def __init__(self, handle, callback, *args):             # <<<<<<<<<<<<<<
 *         event.__init__(self, callback, args, EV_READ, handle, simple=1)
 *         self.args = args	# XXX - incref
 */

static int __pyx_pf_5event_4read___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_5event_4read___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_handle = 0;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_args = 0;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__handle,&__pyx_n_s__callback,0};
  __Pyx_RefNannySetupContext("__init__");
  if (PyTuple_GET_SIZE(__pyx_args) > 2) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 2, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return -1;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__handle);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 2) ? PyTuple_GET_SIZE(__pyx_args) : 2;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_handle = values[0];
    __pyx_v_callback = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_handle = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("event.read.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "simple.pxi":16
 *     """
 *     def __init__(self, handle, callback, *args):
 *         event.__init__(self, callback, args, EV_READ, handle, simple=1)             # <<<<<<<<<<<<<<
 *         self.args = args	# XXX - incref
 *         self.add()
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)((PyObject*)__pyx_ptype_5event_event)), __pyx_n_s____init__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_READ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_self);
  __Pyx_GIVEREF(__pyx_v_self);
  __Pyx_INCREF(__pyx_v_callback);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_callback);
  __Pyx_GIVEREF(__pyx_v_callback);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_handle);
  PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_v_handle);
  __Pyx_GIVEREF(__pyx_v_handle);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__simple), __pyx_int_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_1, __pyx_t_3, ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "simple.pxi":17
 *     def __init__(self, handle, callback, *args):
 *         event.__init__(self, callback, args, EV_READ, handle, simple=1)
 *         self.args = args	# XXX - incref             # <<<<<<<<<<<<<<
 *         self.add()
 * 
 */
  __Pyx_INCREF(__pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __Pyx_GOTREF(((struct __pyx_obj_5event_read *)__pyx_v_self)->__pyx_base.args);
  __Pyx_DECREF(((struct __pyx_obj_5event_read *)__pyx_v_self)->__pyx_base.args);
  ((struct __pyx_obj_5event_read *)__pyx_v_self)->__pyx_base.args = __pyx_v_args;

  /* "simple.pxi":18
 *         event.__init__(self, callback, args, EV_READ, handle, simple=1)
 *         self.args = args	# XXX - incref
 *         self.add()             # <<<<<<<<<<<<<<
 * 
 * cdef class write(event):
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__add); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.read.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "simple.pxi":33
 *     *args    -- optional callback arguments
 *     """
 *     def __init__(self, handle, callback, *args):             # <<<<<<<<<<<<<<
 *         event.__init__(self, callback, args, EV_WRITE, handle, simple=1)
 *         self.args = args	# XXX - incref
 */

static int __pyx_pf_5event_5write___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_5event_5write___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_handle = 0;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_args = 0;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__handle,&__pyx_n_s__callback,0};
  __Pyx_RefNannySetupContext("__init__");
  if (PyTuple_GET_SIZE(__pyx_args) > 2) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 2, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return -1;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__handle);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 2) ? PyTuple_GET_SIZE(__pyx_args) : 2;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_handle = values[0];
    __pyx_v_callback = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_handle = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("event.write.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "simple.pxi":34
 *     """
 *     def __init__(self, handle, callback, *args):
 *         event.__init__(self, callback, args, EV_WRITE, handle, simple=1)             # <<<<<<<<<<<<<<
 *         self.args = args	# XXX - incref
 *         self.add()
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)((PyObject*)__pyx_ptype_5event_event)), __pyx_n_s____init__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_WRITE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_self);
  __Pyx_GIVEREF(__pyx_v_self);
  __Pyx_INCREF(__pyx_v_callback);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_callback);
  __Pyx_GIVEREF(__pyx_v_callback);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_handle);
  PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_v_handle);
  __Pyx_GIVEREF(__pyx_v_handle);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__simple), __pyx_int_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_1, __pyx_t_3, ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "simple.pxi":35
 *     def __init__(self, handle, callback, *args):
 *         event.__init__(self, callback, args, EV_WRITE, handle, simple=1)
 *         self.args = args	# XXX - incref             # <<<<<<<<<<<<<<
 *         self.add()
 * 
 */
  __Pyx_INCREF(__pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __Pyx_GOTREF(((struct __pyx_obj_5event_write *)__pyx_v_self)->__pyx_base.args);
  __Pyx_DECREF(((struct __pyx_obj_5event_write *)__pyx_v_self)->__pyx_base.args);
  ((struct __pyx_obj_5event_write *)__pyx_v_self)->__pyx_base.args = __pyx_v_args;

  /* "simple.pxi":36
 *         event.__init__(self, callback, args, EV_WRITE, handle, simple=1)
 *         self.args = args	# XXX - incref
 *         self.add()             # <<<<<<<<<<<<<<
 * 
 * cdef class signal(event):
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__add); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.write.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "simple.pxi":52
 *     *args    -- optional callback arguments
 *     """
 *     def __init__(self, sig, callback, *args):             # <<<<<<<<<<<<<<
 *         event.__init__(self, callback, args, EV_SIGNAL|EV_PERSIST,
 *                        sig, simple=1)
 */

static int __pyx_pf_5event_6signal___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_5event_6signal___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sig = 0;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_args = 0;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sig,&__pyx_n_s__callback,0};
  __Pyx_RefNannySetupContext("__init__");
  if (PyTuple_GET_SIZE(__pyx_args) > 2) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 2, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return -1;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sig);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 2) ? PyTuple_GET_SIZE(__pyx_args) : 2;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_sig = values[0];
    __pyx_v_callback = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_sig = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("event.signal.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "simple.pxi":53
 *     """
 *     def __init__(self, sig, callback, *args):
 *         event.__init__(self, callback, args, EV_SIGNAL|EV_PERSIST,             # <<<<<<<<<<<<<<
 *                        sig, simple=1)
 *         self.args = args	# XXX - incref
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)((PyObject*)__pyx_ptype_5event_event)), __pyx_n_s____init__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_SIGNAL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__EV_PERSIST); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyNumber_Or(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "simple.pxi":54
 *     def __init__(self, sig, callback, *args):
 *         event.__init__(self, callback, args, EV_SIGNAL|EV_PERSIST,
 *                        sig, simple=1)             # <<<<<<<<<<<<<<
 *         self.args = args	# XXX - incref
 *         self.add()
 */
  __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_self);
  __Pyx_GIVEREF(__pyx_v_self);
  __Pyx_INCREF(__pyx_v_callback);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_callback);
  __Pyx_GIVEREF(__pyx_v_callback);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_sig);
  PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_v_sig);
  __Pyx_GIVEREF(__pyx_v_sig);
  __pyx_t_4 = 0;

  /* "simple.pxi":53
 *     """
 *     def __init__(self, sig, callback, *args):
 *         event.__init__(self, callback, args, EV_SIGNAL|EV_PERSIST,             # <<<<<<<<<<<<<<
 *                        sig, simple=1)
 *         self.args = args	# XXX - incref
 */
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__simple), __pyx_int_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyEval_CallObjectWithKeywords(__pyx_t_1, __pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "simple.pxi":55
 *         event.__init__(self, callback, args, EV_SIGNAL|EV_PERSIST,
 *                        sig, simple=1)
 *         self.args = args	# XXX - incref             # <<<<<<<<<<<<<<
 *         self.add()
 * 
 */
  __Pyx_INCREF(__pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __Pyx_GOTREF(((struct __pyx_obj_5event_signal *)__pyx_v_self)->__pyx_base.args);
  __Pyx_DECREF(((struct __pyx_obj_5event_signal *)__pyx_v_self)->__pyx_base.args);
  ((struct __pyx_obj_5event_signal *)__pyx_v_self)->__pyx_base.args = __pyx_v_args;

  /* "simple.pxi":56
 *                        sig, simple=1)
 *         self.args = args	# XXX - incref
 *         self.add()             # <<<<<<<<<<<<<<
 * 
 * cdef class timeout(event):
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__add); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.signal.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "simple.pxi":71
 *     *args    -- optional callback arguments
 *     """
 *     def __init__(self, secs, callback, *args):             # <<<<<<<<<<<<<<
 *         event.__init__(self, callback, args, simple=1)
 *         self.args = args	# XXX - incref
 */

static int __pyx_pf_5event_7timeout___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_5event_7timeout___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_secs = 0;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_args = 0;
  int __pyx_r;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__secs,&__pyx_n_s__callback,0};
  __Pyx_RefNannySetupContext("__init__");
  if (PyTuple_GET_SIZE(__pyx_args) > 2) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 2, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return -1;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__secs);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 2) ? PyTuple_GET_SIZE(__pyx_args) : 2;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_secs = values[0];
    __pyx_v_callback = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_secs = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("event.timeout.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;

  /* "simple.pxi":72
 *     """
 *     def __init__(self, secs, callback, *args):
 *         event.__init__(self, callback, args, simple=1)             # <<<<<<<<<<<<<<
 *         self.args = args	# XXX - incref
 *         self.add(secs)
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)((PyObject*)__pyx_ptype_5event_event)), __pyx_n_s____init__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_self);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self);
  __Pyx_GIVEREF(__pyx_v_self);
  __Pyx_INCREF(__pyx_v_callback);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_callback);
  __Pyx_GIVEREF(__pyx_v_callback);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__simple), __pyx_int_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_1, __pyx_t_2, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "simple.pxi":73
 *     def __init__(self, secs, callback, *args):
 *         event.__init__(self, callback, args, simple=1)
 *         self.args = args	# XXX - incref             # <<<<<<<<<<<<<<
 *         self.add(secs)
 * 
 */
  __Pyx_INCREF(__pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __Pyx_GOTREF(((struct __pyx_obj_5event_timeout *)__pyx_v_self)->__pyx_base.args);
  __Pyx_DECREF(((struct __pyx_obj_5event_timeout *)__pyx_v_self)->__pyx_base.args);
  ((struct __pyx_obj_5event_timeout *)__pyx_v_self)->__pyx_base.args = __pyx_v_args;

  /* "simple.pxi":74
 *         event.__init__(self, callback, args, simple=1)
 *         self.args = args	# XXX - incref
 *         self.add(secs)             # <<<<<<<<<<<<<<
 * 
 */
  __pyx_t_4 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__add); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_secs);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_secs);
  __Pyx_GIVEREF(__pyx_v_secs);
  __pyx_t_2 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.timeout.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bufferevent.pxi":37
 * ctypedef void (*everror_handler)(bufev_t *b, short what, void *arg)
 * 
 * cdef void __bufev_readcb(bufev_t *b, void *arg) with gil:             # <<<<<<<<<<<<<<
 *     o = (<object>arg)
 *     o.readcb(*o.args)
 */

static  void __pyx_f_5event___bufev_readcb(struct bufferevent *__pyx_v_b, void *__pyx_v_arg) {
  PyObject *__pyx_v_o;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("__bufev_readcb");
  __pyx_v_o = Py_None; __Pyx_INCREF(Py_None);

  /* "bufferevent.pxi":38
 * 
 * cdef void __bufev_readcb(bufev_t *b, void *arg) with gil:
 *     o = (<object>arg)             # <<<<<<<<<<<<<<
 *     o.readcb(*o.args)
 * 
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_arg));
  __Pyx_DECREF(__pyx_v_o);
  __pyx_v_o = ((PyObject *)__pyx_v_arg);

  /* "bufferevent.pxi":39
 * cdef void __bufev_readcb(bufev_t *b, void *arg) with gil:
 *     o = (<object>arg)
 *     o.readcb(*o.args)             # <<<<<<<<<<<<<<
 * 
 * cdef void __bufev_writecb(bufev_t *b, void *arg) with gil:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_o, __pyx_n_s__readcb); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_n_s__args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("event.__bufev_readcb");
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_o);
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
}

/* "bufferevent.pxi":41
 *     o.readcb(*o.args)
 * 
 * cdef void __bufev_writecb(bufev_t *b, void *arg) with gil:             # <<<<<<<<<<<<<<
 *     o = (<object>arg)
 *     o.writecb(*o.args)
 */

static  void __pyx_f_5event___bufev_writecb(struct bufferevent *__pyx_v_b, void *__pyx_v_arg) {
  PyObject *__pyx_v_o;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("__bufev_writecb");
  __pyx_v_o = Py_None; __Pyx_INCREF(Py_None);

  /* "bufferevent.pxi":42
 * 
 * cdef void __bufev_writecb(bufev_t *b, void *arg) with gil:
 *     o = (<object>arg)             # <<<<<<<<<<<<<<
 *     o.writecb(*o.args)
 * 
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_arg));
  __Pyx_DECREF(__pyx_v_o);
  __pyx_v_o = ((PyObject *)__pyx_v_arg);

  /* "bufferevent.pxi":43
 * cdef void __bufev_writecb(bufev_t *b, void *arg) with gil:
 *     o = (<object>arg)
 *     o.writecb(*o.args)             # <<<<<<<<<<<<<<
 * 
 * cdef void __bufev_errorcb(bufev_t *b, short what, void *arg) with gil:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_o, __pyx_n_s__writecb); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_n_s__args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("event.__bufev_writecb");
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_o);
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
}

/* "bufferevent.pxi":45
 *     o.writecb(*o.args)
 * 
 * cdef void __bufev_errorcb(bufev_t *b, short what, void *arg) with gil:             # <<<<<<<<<<<<<<
 *     o = (<object>arg)
 *     o.errorcb(what, *o.args)
 */

static  void __pyx_f_5event___bufev_errorcb(struct bufferevent *__pyx_v_b, short __pyx_v_what, void *__pyx_v_arg) {
  PyObject *__pyx_v_o;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("__bufev_errorcb");
  __pyx_v_o = Py_None; __Pyx_INCREF(Py_None);

  /* "bufferevent.pxi":46
 * 
 * cdef void __bufev_errorcb(bufev_t *b, short what, void *arg) with gil:
 *     o = (<object>arg)             # <<<<<<<<<<<<<<
 *     o.errorcb(what, *o.args)
 * 
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_arg));
  __Pyx_DECREF(__pyx_v_o);
  __pyx_v_o = ((PyObject *)__pyx_v_arg);

  /* "bufferevent.pxi":47
 * cdef void __bufev_errorcb(bufev_t *b, short what, void *arg) with gil:
 *     o = (<object>arg)
 *     o.errorcb(what, *o.args)             # <<<<<<<<<<<<<<
 * 
 * cdef class bufferevent:
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_o, __pyx_n_s__errorcb); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyInt_FromLong(__pyx_v_what); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_n_s__args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Add(__pyx_t_3, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("event.__bufev_errorcb");
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_o);
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
}

/* "bufferevent.pxi":65
 *     cdef public object handle, readcb, writecb, errorcb, args
 * 
 *     def __init__(self, handle, readcb, writecb, errorcb, *args):             # <<<<<<<<<<<<<<
 *         cdef evbuffer_handler rcb, wcb
 *         cdef everror_handler ecb
 */

static int __pyx_pf_5event_11bufferevent___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_5event_11bufferevent___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_handle = 0;
  PyObject *__pyx_v_readcb = 0;
  PyObject *__pyx_v_writecb = 0;
  PyObject *__pyx_v_errorcb = 0;
  PyObject *__pyx_v_args = 0;
  __pyx_t_5event_evbuffer_handler __pyx_v_rcb;
  __pyx_t_5event_evbuffer_handler __pyx_v_wcb;
  __pyx_t_5event_everror_handler __pyx_v_ecb;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__handle,&__pyx_n_s__readcb,&__pyx_n_s__writecb,&__pyx_n_s__errorcb,0};
  __Pyx_RefNannySetupContext("__init__");
  if (PyTuple_GET_SIZE(__pyx_args) > 4) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 4, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return -1;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[4] = {0,0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__handle);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__readcb);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__writecb);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  3:
      values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__errorcb);
      if (likely(values[3])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 4) ? PyTuple_GET_SIZE(__pyx_args) : 4;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_handle = values[0];
    __pyx_v_readcb = values[1];
    __pyx_v_writecb = values[2];
    __pyx_v_errorcb = values[3];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 4) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_handle = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_readcb = PyTuple_GET_ITEM(__pyx_args, 1);
    __pyx_v_writecb = PyTuple_GET_ITEM(__pyx_args, 2);
    __pyx_v_errorcb = PyTuple_GET_ITEM(__pyx_args, 3);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("event.bufferevent.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_handle);
  __Pyx_INCREF(__pyx_v_readcb);
  __Pyx_INCREF(__pyx_v_writecb);
  __Pyx_INCREF(__pyx_v_errorcb);

  /* "bufferevent.pxi":69
 *         cdef everror_handler ecb
 * 
 *         self.handle = handle             # <<<<<<<<<<<<<<
 *         self.readcb = readcb
 *         self.writecb = writecb
 */
  __Pyx_INCREF(__pyx_v_handle);
  __Pyx_GIVEREF(__pyx_v_handle);
  __Pyx_GOTREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->handle);
  __Pyx_DECREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->handle);
  ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->handle = __pyx_v_handle;

  /* "bufferevent.pxi":70
 * 
 *         self.handle = handle
 *         self.readcb = readcb             # <<<<<<<<<<<<<<
 *         self.writecb = writecb
 *         self.errorcb = errorcb
 */
  __Pyx_INCREF(__pyx_v_readcb);
  __Pyx_GIVEREF(__pyx_v_readcb);
  __Pyx_GOTREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->readcb);
  __Pyx_DECREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->readcb);
  ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->readcb = __pyx_v_readcb;

  /* "bufferevent.pxi":71
 *         self.handle = handle
 *         self.readcb = readcb
 *         self.writecb = writecb             # <<<<<<<<<<<<<<
 *         self.errorcb = errorcb
 *         self.args = args
 */
  __Pyx_INCREF(__pyx_v_writecb);
  __Pyx_GIVEREF(__pyx_v_writecb);
  __Pyx_GOTREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->writecb);
  __Pyx_DECREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->writecb);
  ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->writecb = __pyx_v_writecb;

  /* "bufferevent.pxi":72
 *         self.readcb = readcb
 *         self.writecb = writecb
 *         self.errorcb = errorcb             # <<<<<<<<<<<<<<
 *         self.args = args
 * 
 */
  __Pyx_INCREF(__pyx_v_errorcb);
  __Pyx_GIVEREF(__pyx_v_errorcb);
  __Pyx_GOTREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->errorcb);
  __Pyx_DECREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->errorcb);
  ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->errorcb = __pyx_v_errorcb;

  /* "bufferevent.pxi":73
 *         self.writecb = writecb
 *         self.errorcb = errorcb
 *         self.args = args             # <<<<<<<<<<<<<<
 * 
 *         rcb = wcb = ecb = NULL
 */
  __Pyx_INCREF(__pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __Pyx_GOTREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->args);
  __Pyx_DECREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->args);
  ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->args = __pyx_v_args;

  /* "bufferevent.pxi":75
 *         self.args = args
 * 
 *         rcb = wcb = ecb = NULL             # <<<<<<<<<<<<<<
 * 
 *         if readcb is not None:
 */
  __pyx_v_rcb = NULL;
  __pyx_v_wcb = NULL;
  __pyx_v_ecb = NULL;

  /* "bufferevent.pxi":77
 *         rcb = wcb = ecb = NULL
 * 
 *         if readcb is not None:             # <<<<<<<<<<<<<<
 *             rcb = __bufev_readcb
 *         if writecb is not None:
 */
  __pyx_t_1 = (__pyx_v_readcb != Py_None);
  if (__pyx_t_1) {

    /* "bufferevent.pxi":78
 * 
 *         if readcb is not None:
 *             rcb = __bufev_readcb             # <<<<<<<<<<<<<<
 *         if writecb is not None:
 *             wcb = __bufev_writecb
 */
    __pyx_v_rcb = __pyx_f_5event___bufev_readcb;
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "bufferevent.pxi":79
 *         if readcb is not None:
 *             rcb = __bufev_readcb
 *         if writecb is not None:             # <<<<<<<<<<<<<<
 *             wcb = __bufev_writecb
 *         if errorcb is not None:
 */
  __pyx_t_1 = (__pyx_v_writecb != Py_None);
  if (__pyx_t_1) {

    /* "bufferevent.pxi":80
 *             rcb = __bufev_readcb
 *         if writecb is not None:
 *             wcb = __bufev_writecb             # <<<<<<<<<<<<<<
 *         if errorcb is not None:
 *             ecb  = __bufev_errorcb
 */
    __pyx_v_wcb = __pyx_f_5event___bufev_writecb;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "bufferevent.pxi":81
 *         if writecb is not None:
 *             wcb = __bufev_writecb
 *         if errorcb is not None:             # <<<<<<<<<<<<<<
 *             ecb  = __bufev_errorcb
 * 
 */
  __pyx_t_1 = (__pyx_v_errorcb != Py_None);
  if (__pyx_t_1) {

    /* "bufferevent.pxi":82
 *             wcb = __bufev_writecb
 *         if errorcb is not None:
 *             ecb  = __bufev_errorcb             # <<<<<<<<<<<<<<
 * 
 *         if not isinstance(handle, int):
 */
    __pyx_v_ecb = __pyx_f_5event___bufev_errorcb;
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "bufferevent.pxi":84
 *             ecb  = __bufev_errorcb
 * 
 *         if not isinstance(handle, int):             # <<<<<<<<<<<<<<
 *             handle = handle.fileno()
 * 
 */
  __pyx_t_1 = PyObject_TypeCheck(__pyx_v_handle, ((PyTypeObject *)((PyObject*)&PyInt_Type))); 
  __pyx_t_2 = (!__pyx_t_1);
  if (__pyx_t_2) {

    /* "bufferevent.pxi":85
 * 
 *         if not isinstance(handle, int):
 *             handle = handle.fileno()             # <<<<<<<<<<<<<<
 * 
 *         self.bufev = bufferevent_new(handle, rcb, wcb, ecb, <void *>self)
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_handle, __pyx_n_s__fileno); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_handle);
    __pyx_v_handle = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "bufferevent.pxi":87
 *             handle = handle.fileno()
 * 
 *         self.bufev = bufferevent_new(handle, rcb, wcb, ecb, <void *>self)             # <<<<<<<<<<<<<<
 * 
 *     def enable(self, short evtype):
 */
  __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_v_handle); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev = bufferevent_new(__pyx_t_5, __pyx_v_rcb, __pyx_v_wcb, __pyx_v_ecb, ((void *)__pyx_v_self));

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.bufferevent.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_handle);
  __Pyx_DECREF(__pyx_v_readcb);
  __Pyx_DECREF(__pyx_v_writecb);
  __Pyx_DECREF(__pyx_v_errorcb);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bufferevent.pxi":89
 *         self.bufev = bufferevent_new(handle, rcb, wcb, ecb, <void *>self)
 * 
 *     def enable(self, short evtype):             # <<<<<<<<<<<<<<
 *         """Enable a bufferevent.
 * 
 */

static PyObject *__pyx_pf_5event_11bufferevent_enable(PyObject *__pyx_v_self, PyObject *__pyx_arg_evtype); /*proto*/
static char __pyx_doc_5event_11bufferevent_enable[] = "Enable a bufferevent.\n\n        Arguments:\n\n        evtype  -- any combination of EV_READ | EV_WRITE\n        ";
static PyObject *__pyx_pf_5event_11bufferevent_enable(PyObject *__pyx_v_self, PyObject *__pyx_arg_evtype) {
  short __pyx_v_evtype;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("enable");
  assert(__pyx_arg_evtype); {
    __pyx_v_evtype = __Pyx_PyInt_AsShort(__pyx_arg_evtype); if (unlikely((__pyx_v_evtype == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.bufferevent.enable");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "bufferevent.pxi":96
 *         evtype  -- any combination of EV_READ | EV_WRITE
 *         """
 *         bufferevent_enable(self.bufev, evtype)             # <<<<<<<<<<<<<<
 * 
 *     def disable(self, short evtype):
 */
  bufferevent_enable(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev, __pyx_v_evtype);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bufferevent.pxi":98
 *         bufferevent_enable(self.bufev, evtype)
 * 
 *     def disable(self, short evtype):             # <<<<<<<<<<<<<<
 *         """Disable a bufferevent.
 * 
 */

static PyObject *__pyx_pf_5event_11bufferevent_disable(PyObject *__pyx_v_self, PyObject *__pyx_arg_evtype); /*proto*/
static char __pyx_doc_5event_11bufferevent_disable[] = "Disable a bufferevent.\n\n        Arguments:\n\n        evtype  -- any combination of EV_READ | EV_WRITE\n        ";
static PyObject *__pyx_pf_5event_11bufferevent_disable(PyObject *__pyx_v_self, PyObject *__pyx_arg_evtype) {
  short __pyx_v_evtype;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("disable");
  assert(__pyx_arg_evtype); {
    __pyx_v_evtype = __Pyx_PyInt_AsShort(__pyx_arg_evtype); if (unlikely((__pyx_v_evtype == (short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.bufferevent.disable");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "bufferevent.pxi":105
 *         evtype  -- any combination of EV_READ | EV_WRITE
 *         """
 *         bufferevent_disable(self.bufev, evtype)             # <<<<<<<<<<<<<<
 * 
 *     def read(self, int size=-1):
 */
  bufferevent_disable(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev, __pyx_v_evtype);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bufferevent.pxi":107
 *         bufferevent_disable(self.bufev, evtype)
 * 
 *     def read(self, int size=-1):             # <<<<<<<<<<<<<<
 *         """Read data from a bufferevent.
 * 
 */

static PyObject *__pyx_pf_5event_11bufferevent_read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5event_11bufferevent_read[] = "Read data from a bufferevent.\n\n        Optional arguments:\n\n        size  -- number of bytes to read\n        ";
static PyObject *__pyx_pf_5event_11bufferevent_read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_size;
  PyObject *__pyx_v_buf;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,0};
  __Pyx_RefNannySetupContext("read");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "read") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    if (values[0]) {
      __pyx_v_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_size = ((int)-1);
    }
  } else {
    __pyx_v_size = ((int)-1);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_size = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("read", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.bufferevent.read");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_v_buf = Py_None; __Pyx_INCREF(Py_None);

  /* "bufferevent.pxi":114
 *         size  -- number of bytes to read
 *         """
 *         if size < 0:             # <<<<<<<<<<<<<<
 *             size = self.bufev.input.off
 *         else:
 */
  __pyx_t_1 = (__pyx_v_size < 0);
  if (__pyx_t_1) {

    /* "bufferevent.pxi":115
 *         """
 *         if size < 0:
 *             size = self.bufev.input.off             # <<<<<<<<<<<<<<
 *         else:
 *             size = min(self.bufev.input.off, size)
 */
    __pyx_v_size = ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev->input->off;
    goto __pyx_L6;
  }
  /*else*/ {

    /* "bufferevent.pxi":117
 *             size = self.bufev.input.off
 *         else:
 *             size = min(self.bufev.input.off, size)             # <<<<<<<<<<<<<<
 * 
 *         buf = PyString_FromStringAndSize(self.bufev.input.buf, size)
 */
    __pyx_t_2 = PyInt_FromLong(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev->input->off); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyInt_FromLong(__pyx_v_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_min, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_size = __pyx_t_5;
  }
  __pyx_L6:;

  /* "bufferevent.pxi":119
 *             size = min(self.bufev.input.off, size)
 * 
 *         buf = PyString_FromStringAndSize(self.bufev.input.buf, size)             # <<<<<<<<<<<<<<
 *         evbuffer_drain(self.bufev.input, size)
 *         return buf
 */
  __pyx_t_3 = PyString_FromStringAndSize(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev->input->buffer, __pyx_v_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_v_buf);
  __pyx_v_buf = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "bufferevent.pxi":120
 * 
 *         buf = PyString_FromStringAndSize(self.bufev.input.buf, size)
 *         evbuffer_drain(self.bufev.input, size)             # <<<<<<<<<<<<<<
 *         return buf
 * 
 */
  evbuffer_drain(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev->input, __pyx_v_size);

  /* "bufferevent.pxi":121
 *         buf = PyString_FromStringAndSize(self.bufev.input.buf, size)
 *         evbuffer_drain(self.bufev.input, size)
 *         return buf             # <<<<<<<<<<<<<<
 * 
 *     def write(self, buf):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_buf);
  __pyx_r = __pyx_v_buf;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.bufferevent.read");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_buf);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bufferevent.pxi":123
 *         return buf
 * 
 *     def write(self, buf):             # <<<<<<<<<<<<<<
 *         """Write data to a bufferevent. The data is appended to the output
 *         buffer and written to the handle automatically as it becomes available
 */

static PyObject *__pyx_pf_5event_11bufferevent_write(PyObject *__pyx_v_self, PyObject *__pyx_v_buf); /*proto*/
static char __pyx_doc_5event_11bufferevent_write[] = "Write data to a bufferevent. The data is appended to the output\n        buffer and written to the handle automatically as it becomes available\n        for writing. Returns 0 if successful, or -1 on error.\n        \n        Arguments:\n\n        buf  -- data to write\n        ";
static PyObject *__pyx_pf_5event_11bufferevent_write(PyObject *__pyx_v_self, PyObject *__pyx_v_buf) {
  char *__pyx_v_p;
  int __pyx_v_n;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("write");
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_buf);

  /* "bufferevent.pxi":135
 *         cdef int n
 * 
 *         if PyObject_AsCharBuffer(buf, &p, &n) < 0:             # <<<<<<<<<<<<<<
 *             raise TypeError
 *         return bufferevent_write(self.bufev, p, n)
 */
  __pyx_t_1 = (PyObject_AsCharBuffer(__pyx_v_buf, (&__pyx_v_p), (&__pyx_v_n)) < 0);
  if (__pyx_t_1) {

    /* "bufferevent.pxi":136
 * 
 *         if PyObject_AsCharBuffer(buf, &p, &n) < 0:
 *             raise TypeError             # <<<<<<<<<<<<<<
 *         return bufferevent_write(self.bufev, p, n)
 * 
 */
    __Pyx_Raise(__pyx_builtin_TypeError, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "bufferevent.pxi":137
 *         if PyObject_AsCharBuffer(buf, &p, &n) < 0:
 *             raise TypeError
 *         return bufferevent_write(self.bufev, p, n)             # <<<<<<<<<<<<<<
 * 
 *     def set_timeout(self, int read_secs, int write_secs):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyInt_FromLong(bufferevent_write(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev, __pyx_v_p, __pyx_v_n)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.bufferevent.write");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_buf);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bufferevent.pxi":139
 *         return bufferevent_write(self.bufev, p, n)
 * 
 *     def set_timeout(self, int read_secs, int write_secs):             # <<<<<<<<<<<<<<
 *         bufferevent_settimeout(self.bufev, read_secs, write_secs)
 * 
 */

static PyObject *__pyx_pf_5event_11bufferevent_set_timeout(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_5event_11bufferevent_set_timeout(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_read_secs;
  int __pyx_v_write_secs;
  PyObject *__pyx_r = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__read_secs,&__pyx_n_s__write_secs,0};
  __Pyx_RefNannySetupContext("set_timeout");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__read_secs);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__write_secs);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("set_timeout", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "set_timeout") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_read_secs = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_read_secs == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_write_secs = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_write_secs == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_read_secs = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_read_secs == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_write_secs = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_write_secs == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("set_timeout", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.bufferevent.set_timeout");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "bufferevent.pxi":140
 * 
 *     def set_timeout(self, int read_secs, int write_secs):
 *         bufferevent_settimeout(self.bufev, read_secs, write_secs)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  bufferevent_settimeout(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev, __pyx_v_read_secs, __pyx_v_write_secs);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "bufferevent.pxi":142
 *         bufferevent_settimeout(self.bufev, read_secs, write_secs)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bufferevent_free(self.bufev)
 * 
 */

static void __pyx_pf_5event_11bufferevent___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_5event_11bufferevent___dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannySetupContext("__dealloc__");

  /* "bufferevent.pxi":143
 * 
 *     def __dealloc__(self):
 *         bufferevent_free(self.bufev)             # <<<<<<<<<<<<<<
 * 
 *     def __repr__(self):
 */
  bufferevent_free(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->bufev);

  __Pyx_RefNannyFinishContext();
}

/* "bufferevent.pxi":145
 *         bufferevent_free(self.bufev)
 * 
 *     def __repr__(self):             # <<<<<<<<<<<<<<
 *         return '<bufferevent handle=%s, readcb=%s, writecb=%s, errorcb=%s, args=%s>' % (self.handle, self.readcb, self.writecb, self.errorcb, self.args)
 * 
 */

static PyObject *__pyx_pf_5event_11bufferevent___repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pf_5event_11bufferevent___repr__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("__repr__");

  /* "bufferevent.pxi":146
 * 
 *     def __repr__(self):
 *         return '<bufferevent handle=%s, readcb=%s, writecb=%s, errorcb=%s, args=%s>' % (self.handle, self.readcb, self.writecb, self.errorcb, self.args)             # <<<<<<<<<<<<<<
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->handle);
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->handle);
  __Pyx_GIVEREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->handle);
  __Pyx_INCREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->readcb);
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->readcb);
  __Pyx_GIVEREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->readcb);
  __Pyx_INCREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->writecb);
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->writecb);
  __Pyx_GIVEREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->writecb);
  __Pyx_INCREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->errorcb);
  PyTuple_SET_ITEM(__pyx_t_1, 3, ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->errorcb);
  __Pyx_GIVEREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->errorcb);
  __Pyx_INCREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->args);
  PyTuple_SET_ITEM(__pyx_t_1, 4, ((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->args);
  __Pyx_GIVEREF(((struct __pyx_obj_5event_bufferevent *)__pyx_v_self)->args);
  __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.bufferevent.__repr__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evdns.pxi":40
 * __evdns_cbargs = {}
 * 
 * def dns_init():             # <<<<<<<<<<<<<<
 *     """Initialize async DNS resolver."""
 *     evdns_init()
 */

static PyObject *__pyx_pf_5event_dns_init(PyObject *__pyx_self, PyObject *unused); /*proto*/
static char __pyx_doc_5event_dns_init[] = "Initialize async DNS resolver.";
static PyObject *__pyx_pf_5event_dns_init(PyObject *__pyx_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("dns_init");
  __pyx_self = __pyx_self;

  /* "evdns.pxi":42
 * def dns_init():
 *     """Initialize async DNS resolver."""
 *     evdns_init()             # <<<<<<<<<<<<<<
 *     __evdns_cbargs.clear()
 * 
 */
  evdns_init();

  /* "evdns.pxi":43
 *     """Initialize async DNS resolver."""
 *     evdns_init()
 *     __evdns_cbargs.clear()             # <<<<<<<<<<<<<<
 * 
 * cdef void __evdns_callback(int result, char t, int count, int ttl,
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s____evdns_cbargs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__clear); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.dns_init");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evdns.pxi":45
 *     __evdns_cbargs.clear()
 * 
 * cdef void __evdns_callback(int result, char t, int count, int ttl,             # <<<<<<<<<<<<<<
 *                      void *addrs, void *arg) with gil:
 *     cdef int i
 */

static  void __pyx_f_5event___evdns_callback(int __pyx_v_result, char __pyx_v_t, int __pyx_v_count, int __pyx_v_ttl, void *__pyx_v_addrs, void *__pyx_v_arg) {
  int __pyx_v_i;
  PyObject *__pyx_v_callback;
  PyObject *__pyx_v_args;
  PyObject *__pyx_v_x;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("__evdns_callback");
  __pyx_v_callback = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_args = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_x = Py_None; __Pyx_INCREF(Py_None);

  /* "evdns.pxi":48
 *                      void *addrs, void *arg) with gil:
 *     cdef int i
 *     (callback, args) = __evdns_cbargs.pop(<int>arg)             # <<<<<<<<<<<<<<
 *     if t == DNS_IPv4_A:
 *         x = []
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s____evdns_cbargs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_PopIndex(__pyx_t_1, ((int)__pyx_v_arg)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyTuple_CheckExact(__pyx_t_2) && likely(PyTuple_GET_SIZE(__pyx_t_2) == 2)) {
    PyObject* tuple = __pyx_t_2;
    __pyx_t_1 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_1);
    __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_v_callback);
    __pyx_v_callback = __pyx_t_1;
    __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_v_args);
    __pyx_v_args = __pyx_t_3;
    __pyx_t_3 = 0;
  } else {
    __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_UnpackItem(__pyx_t_4, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_4, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_EndUnpack(__pyx_t_4) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_v_callback);
    __pyx_v_callback = __pyx_t_1;
    __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_v_args);
    __pyx_v_args = __pyx_t_3;
    __pyx_t_3 = 0;
  }

  /* "evdns.pxi":49
 *     cdef int i
 *     (callback, args) = __evdns_cbargs.pop(<int>arg)
 *     if t == DNS_IPv4_A:             # <<<<<<<<<<<<<<
 *         x = []
 *         for i from 0 <= i < count:
 */
  __pyx_t_2 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__DNS_IPv4_A); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_5) {

    /* "evdns.pxi":50
 *     (callback, args) = __evdns_cbargs.pop(<int>arg)
 *     if t == DNS_IPv4_A:
 *         x = []             # <<<<<<<<<<<<<<
 *         for i from 0 <= i < count:
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 4), 4))
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __Pyx_DECREF(__pyx_v_x);
    __pyx_v_x = ((PyObject *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "evdns.pxi":51
 *     if t == DNS_IPv4_A:
 *         x = []
 *         for i from 0 <= i < count:             # <<<<<<<<<<<<<<
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 4), 4))
 *     elif t == DNS_IPv6_AAAA:
 */
    __pyx_t_6 = __pyx_v_count;
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_6; __pyx_v_i++) {

      /* "evdns.pxi":52
 *         x = []
 *         for i from 0 <= i < count:
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 4), 4))             # <<<<<<<<<<<<<<
 *     elif t == DNS_IPv6_AAAA:
 *         x = []
 */
      __pyx_t_1 = PyString_FromStringAndSize((((char *)__pyx_v_addrs) + (__pyx_v_i * 4)), 4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_x, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    goto __pyx_L3;
  }

  /* "evdns.pxi":53
 *         for i from 0 <= i < count:
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 4), 4))
 *     elif t == DNS_IPv6_AAAA:             # <<<<<<<<<<<<<<
 *         x = []
 *         for i from 0 <= i < count:
 */
  __pyx_t_3 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__DNS_IPv6_AAAA); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_5) {

    /* "evdns.pxi":54
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 4), 4))
 *     elif t == DNS_IPv6_AAAA:
 *         x = []             # <<<<<<<<<<<<<<
 *         for i from 0 <= i < count:
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 16), 16))
 */
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __Pyx_DECREF(__pyx_v_x);
    __pyx_v_x = ((PyObject *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "evdns.pxi":55
 *     elif t == DNS_IPv6_AAAA:
 *         x = []
 *         for i from 0 <= i < count:             # <<<<<<<<<<<<<<
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 16), 16))
 *     elif t == DNS_PTR and count == 1: # only 1 PTR possible
 */
    __pyx_t_6 = __pyx_v_count;
    for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_6; __pyx_v_i++) {

      /* "evdns.pxi":56
 *         x = []
 *         for i from 0 <= i < count:
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 16), 16))             # <<<<<<<<<<<<<<
 *     elif t == DNS_PTR and count == 1: # only 1 PTR possible
 *         x = PyString_FromString((<char **>addrs)[0])
 */
      __pyx_t_2 = PyString_FromStringAndSize((((char *)__pyx_v_addrs) + (__pyx_v_i * 16)), 16); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyObject_Append(__pyx_v_x, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    goto __pyx_L3;
  }

  /* "evdns.pxi":57
 *         for i from 0 <= i < count:
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 16), 16))
 *     elif t == DNS_PTR and count == 1: # only 1 PTR possible             # <<<<<<<<<<<<<<
 *         x = PyString_FromString((<char **>addrs)[0])
 *     else:
 */
  __pyx_t_1 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__DNS_PTR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_5) {
    __pyx_t_7 = (__pyx_v_count == 1);
    __pyx_t_8 = __pyx_t_7;
  } else {
    __pyx_t_8 = __pyx_t_5;
  }
  if (__pyx_t_8) {

    /* "evdns.pxi":58
 *             x.append(PyString_FromStringAndSize(<char *>addrs + (i * 16), 16))
 *     elif t == DNS_PTR and count == 1: # only 1 PTR possible
 *         x = PyString_FromString((<char **>addrs)[0])             # <<<<<<<<<<<<<<
 *     else:
 *         x = None
 */
    __pyx_t_3 = PyString_FromString((((char **)__pyx_v_addrs)[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_v_x);
    __pyx_v_x = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "evdns.pxi":60
 *         x = PyString_FromString((<char **>addrs)[0])
 *     else:
 *         x = None             # <<<<<<<<<<<<<<
 *     try:
 *         callback(result, t, ttl, x, args)
 */
    __Pyx_INCREF(Py_None);
    __Pyx_DECREF(__pyx_v_x);
    __pyx_v_x = Py_None;
  }
  __pyx_L3:;

  /* "evdns.pxi":61
 *     else:
 *         x = None
 *     try:             # <<<<<<<<<<<<<<
 *         callback(result, t, ttl, x, args)
 *     except:
 */
  {
    PyObject *__pyx_save_exc_type, *__pyx_save_exc_value, *__pyx_save_exc_tb;
    __Pyx_ExceptionSave(&__pyx_save_exc_type, &__pyx_save_exc_value, &__pyx_save_exc_tb);
    __Pyx_XGOTREF(__pyx_save_exc_type);
    __Pyx_XGOTREF(__pyx_save_exc_value);
    __Pyx_XGOTREF(__pyx_save_exc_tb);
    /*try:*/ {

      /* "evdns.pxi":62
 *         x = None
 *     try:
 *         callback(result, t, ttl, x, args)             # <<<<<<<<<<<<<<
 *     except:
 *         __event_abort()
 */
      __pyx_t_3 = PyInt_FromLong(__pyx_v_result); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L8_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L8_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyInt_FromLong(__pyx_v_ttl); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L8_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L8_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_x);
      PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_x);
      __Pyx_GIVEREF(__pyx_v_x);
      __Pyx_INCREF(__pyx_v_args);
      PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_args);
      __Pyx_GIVEREF(__pyx_v_args);
      __pyx_t_3 = 0;
      __pyx_t_2 = 0;
      __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_Call(__pyx_v_callback, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L8_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_XDECREF(__pyx_save_exc_type); __pyx_save_exc_type = 0;
    __Pyx_XDECREF(__pyx_save_exc_value); __pyx_save_exc_value = 0;
    __Pyx_XDECREF(__pyx_save_exc_tb); __pyx_save_exc_tb = 0;
    goto __pyx_L15_try_end;
    __pyx_L8_error:;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "evdns.pxi":63
 *     try:
 *         callback(result, t, ttl, x, args)
 *     except:             # <<<<<<<<<<<<<<
 *         __event_abort()
 * 
 */
    /*except:*/ {
      __Pyx_AddTraceback("event.__evdns_callback");
      if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L10_except_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GOTREF(__pyx_t_2);

      /* "evdns.pxi":64
 *         callback(result, t, ttl, x, args)
 *     except:
 *         __event_abort()             # <<<<<<<<<<<<<<
 * 
 * def dns_resolve_ipv4(char *name, int flags, callback, *args):
 */
      __pyx_f_5event___event_abort();
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      goto __pyx_L9_exception_handled;
    }
    __pyx_L10_except_error:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    goto __pyx_L1_error;
    __pyx_L9_exception_handled:;
    __Pyx_XGIVEREF(__pyx_save_exc_type);
    __Pyx_XGIVEREF(__pyx_save_exc_value);
    __Pyx_XGIVEREF(__pyx_save_exc_tb);
    __Pyx_ExceptionReset(__pyx_save_exc_type, __pyx_save_exc_value, __pyx_save_exc_tb);
    __pyx_L15_try_end:;
  }

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("event.__evdns_callback");
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_callback);
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_x);
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
}

/* "evdns.pxi":66
 *         __event_abort()
 * 
 * def dns_resolve_ipv4(char *name, int flags, callback, *args):             # <<<<<<<<<<<<<<
 *     """Lookup an A record for a given name.
 * 
 */

static PyObject *__pyx_pf_5event_dns_resolve_ipv4(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5event_dns_resolve_ipv4[] = "Lookup an A record for a given name.\n\n    Arguments:\n\n    name     -- DNS hostname\n    flags    -- either 0 or DNS_QUERY_NO_SEARCH\n    callback -- callback with (result, type, ttl, addrs, *args) prototype\n    args     -- option callback arguments\n    ";
static PyObject *__pyx_pf_5event_dns_resolve_ipv4(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  char *__pyx_v_name;
  int __pyx_v_flags;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_args = 0;
  int __pyx_v_i;
  PyObject *__pyx_v_t;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,&__pyx_n_s__flags,&__pyx_n_s__callback,0};
  __Pyx_RefNannySetupContext("dns_resolve_ipv4");
  __pyx_self = __pyx_self;
  if (PyTuple_GET_SIZE(__pyx_args) > 3) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 3, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return NULL;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__flags);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dns_resolve_ipv4", 0, 3, 3, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dns_resolve_ipv4", 0, 3, 3, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 3) ? PyTuple_GET_SIZE(__pyx_args) : 3;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "dns_resolve_ipv4") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_name = __Pyx_PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_flags = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_callback = values[2];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 3) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_name = __Pyx_PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_flags = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 2);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dns_resolve_ipv4", 0, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("event.dns_resolve_ipv4");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_t = Py_None; __Pyx_INCREF(Py_None);

  /* "evdns.pxi":77
 *     """
 *     cdef int i
 *     t = (callback, args)             # <<<<<<<<<<<<<<
 *     i = id(t)
 *     __evdns_cbargs[i] = t
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_callback);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_callback);
  __Pyx_GIVEREF(__pyx_v_callback);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_t);
  __pyx_v_t = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "evdns.pxi":78
 *     cdef int i
 *     t = (callback, args)
 *     i = id(t)             # <<<<<<<<<<<<<<
 *     __evdns_cbargs[i] = t
 *     evdns_resolve_ipv4(name, flags, __evdns_callback, <void *>i)
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_t);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_t);
  __Pyx_GIVEREF(__pyx_v_t);
  __pyx_t_2 = PyObject_Call(__pyx_builtin_id, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_i = __pyx_t_3;

  /* "evdns.pxi":79
 *     t = (callback, args)
 *     i = id(t)
 *     __evdns_cbargs[i] = t             # <<<<<<<<<<<<<<
 *     evdns_resolve_ipv4(name, flags, __evdns_callback, <void *>i)
 * 
 */
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s____evdns_cbargs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemInt(__pyx_t_2, __pyx_v_i, __pyx_v_t, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "evdns.pxi":80
 *     i = id(t)
 *     __evdns_cbargs[i] = t
 *     evdns_resolve_ipv4(name, flags, __evdns_callback, <void *>i)             # <<<<<<<<<<<<<<
 * 
 * def dns_resolve_ipv6(char *name, int flags, callback, *args):
 */
  evdns_resolve_ipv4(__pyx_v_name, __pyx_v_flags, __pyx_f_5event___evdns_callback, ((void *)__pyx_v_i));

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.dns_resolve_ipv4");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evdns.pxi":82
 *     evdns_resolve_ipv4(name, flags, __evdns_callback, <void *>i)
 * 
 * def dns_resolve_ipv6(char *name, int flags, callback, *args):             # <<<<<<<<<<<<<<
 *     """Lookup an AAAA record for a given name.
 * 
 */

static PyObject *__pyx_pf_5event_dns_resolve_ipv6(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5event_dns_resolve_ipv6[] = "Lookup an AAAA record for a given name.\n\n    Arguments:\n\n    name     -- DNS hostname\n    flags    -- either 0 or DNS_QUERY_NO_SEARCH\n    callback -- callback with (result, type, ttl, addrs, *args) prototype\n    args     -- option callback arguments\n    ";
static PyObject *__pyx_pf_5event_dns_resolve_ipv6(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  char *__pyx_v_name;
  int __pyx_v_flags;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_args = 0;
  int __pyx_v_i;
  PyObject *__pyx_v_t;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,&__pyx_n_s__flags,&__pyx_n_s__callback,0};
  __Pyx_RefNannySetupContext("dns_resolve_ipv6");
  __pyx_self = __pyx_self;
  if (PyTuple_GET_SIZE(__pyx_args) > 3) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 3, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return NULL;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__flags);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dns_resolve_ipv6", 0, 3, 3, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dns_resolve_ipv6", 0, 3, 3, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 3) ? PyTuple_GET_SIZE(__pyx_args) : 3;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "dns_resolve_ipv6") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_name = __Pyx_PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_flags = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_callback = values[2];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 3) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_name = __Pyx_PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_flags = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 2);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dns_resolve_ipv6", 0, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("event.dns_resolve_ipv6");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_t = Py_None; __Pyx_INCREF(Py_None);

  /* "evdns.pxi":93
 *     """
 *     cdef int i
 *     t = (callback, args)             # <<<<<<<<<<<<<<
 *     i = id(t)
 *     __evdns_cbargs[i] = t
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_callback);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_callback);
  __Pyx_GIVEREF(__pyx_v_callback);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_t);
  __pyx_v_t = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "evdns.pxi":94
 *     cdef int i
 *     t = (callback, args)
 *     i = id(t)             # <<<<<<<<<<<<<<
 *     __evdns_cbargs[i] = t
 *     evdns_resolve_ipv6(name, flags, __evdns_callback, <void *>i)
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_t);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_t);
  __Pyx_GIVEREF(__pyx_v_t);
  __pyx_t_2 = PyObject_Call(__pyx_builtin_id, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_i = __pyx_t_3;

  /* "evdns.pxi":95
 *     t = (callback, args)
 *     i = id(t)
 *     __evdns_cbargs[i] = t             # <<<<<<<<<<<<<<
 *     evdns_resolve_ipv6(name, flags, __evdns_callback, <void *>i)
 * 
 */
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s____evdns_cbargs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemInt(__pyx_t_2, __pyx_v_i, __pyx_v_t, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "evdns.pxi":96
 *     i = id(t)
 *     __evdns_cbargs[i] = t
 *     evdns_resolve_ipv6(name, flags, __evdns_callback, <void *>i)             # <<<<<<<<<<<<<<
 * 
 * def dns_resolve_reverse(char *ip, int flags, callback, *args):
 */
  evdns_resolve_ipv6(__pyx_v_name, __pyx_v_flags, __pyx_f_5event___evdns_callback, ((void *)__pyx_v_i));

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.dns_resolve_ipv6");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evdns.pxi":98
 *     evdns_resolve_ipv6(name, flags, __evdns_callback, <void *>i)
 * 
 * def dns_resolve_reverse(char *ip, int flags, callback, *args):             # <<<<<<<<<<<<<<
 *     """Lookup a PTR record for a given IPv4 address.
 * 
 */

static PyObject *__pyx_pf_5event_dns_resolve_reverse(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5event_dns_resolve_reverse[] = "Lookup a PTR record for a given IPv4 address.\n\n    Arguments:\n\n    name     -- IPv4 address (as 4-byte binary string)\n    flags    -- either 0 or DNS_QUERY_NO_SEARCH\n    callback -- callback with (result, type, ttl, addrs, *args) prototype\n    args     -- option callback arguments\n    ";
static PyObject *__pyx_pf_5event_dns_resolve_reverse(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  char *__pyx_v_ip;
  int __pyx_v_flags;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_args = 0;
  int __pyx_v_i;
  PyObject *__pyx_v_t;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__ip,&__pyx_n_s__flags,&__pyx_n_s__callback,0};
  __Pyx_RefNannySetupContext("dns_resolve_reverse");
  __pyx_self = __pyx_self;
  if (PyTuple_GET_SIZE(__pyx_args) > 3) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 3, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return NULL;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ip);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__flags);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dns_resolve_reverse", 0, 3, 3, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dns_resolve_reverse", 0, 3, 3, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 3) ? PyTuple_GET_SIZE(__pyx_args) : 3;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "dns_resolve_reverse") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_ip = __Pyx_PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_ip) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_flags = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_callback = values[2];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 3) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_ip = __Pyx_PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_ip) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_flags = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 2);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dns_resolve_reverse", 0, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("event.dns_resolve_reverse");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_t = Py_None; __Pyx_INCREF(Py_None);

  /* "evdns.pxi":109
 *     """
 *     cdef int i
 *     t = (callback, args)             # <<<<<<<<<<<<<<
 *     i = id(t)
 *     __evdns_cbargs[i] = t
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_callback);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_callback);
  __Pyx_GIVEREF(__pyx_v_callback);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_t);
  __pyx_v_t = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "evdns.pxi":110
 *     cdef int i
 *     t = (callback, args)
 *     i = id(t)             # <<<<<<<<<<<<<<
 *     __evdns_cbargs[i] = t
 *     evdns_resolve_reverse(ip, flags, __evdns_callback, <void *>i)
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_t);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_t);
  __Pyx_GIVEREF(__pyx_v_t);
  __pyx_t_2 = PyObject_Call(__pyx_builtin_id, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_i = __pyx_t_3;

  /* "evdns.pxi":111
 *     t = (callback, args)
 *     i = id(t)
 *     __evdns_cbargs[i] = t             # <<<<<<<<<<<<<<
 *     evdns_resolve_reverse(ip, flags, __evdns_callback, <void *>i)
 * 
 */
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s____evdns_cbargs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemInt(__pyx_t_2, __pyx_v_i, __pyx_v_t, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "evdns.pxi":112
 *     i = id(t)
 *     __evdns_cbargs[i] = t
 *     evdns_resolve_reverse(ip, flags, __evdns_callback, <void *>i)             # <<<<<<<<<<<<<<
 * 
 * def dns_resolve_reverse_ipv6(char *ip, int flags, callback, *args):
 */
  evdns_resolve_reverse(__pyx_v_ip, __pyx_v_flags, __pyx_f_5event___evdns_callback, ((void *)__pyx_v_i));

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.dns_resolve_reverse");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evdns.pxi":114
 *     evdns_resolve_reverse(ip, flags, __evdns_callback, <void *>i)
 * 
 * def dns_resolve_reverse_ipv6(char *ip, int flags, callback, *args):             # <<<<<<<<<<<<<<
 *     """Lookup a PTR record for a given IPv6 address.
 * 
 */

static PyObject *__pyx_pf_5event_dns_resolve_reverse_ipv6(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5event_dns_resolve_reverse_ipv6[] = "Lookup a PTR record for a given IPv6 address.\n\n    Arguments:\n\n    name     -- IPv6 address (as 16-byte binary string)\n    flags    -- either 0 or DNS_QUERY_NO_SEARCH\n    callback -- callback with (result, type, ttl, addrs, *args) prototype\n    args     -- option callback arguments\n    ";
static PyObject *__pyx_pf_5event_dns_resolve_reverse_ipv6(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  char *__pyx_v_ip;
  int __pyx_v_flags;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_args = 0;
  int __pyx_v_i;
  PyObject *__pyx_v_t;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__ip,&__pyx_n_s__flags,&__pyx_n_s__callback,0};
  __Pyx_RefNannySetupContext("dns_resolve_reverse_ipv6");
  __pyx_self = __pyx_self;
  if (PyTuple_GET_SIZE(__pyx_args) > 3) {
    __pyx_v_args = PyTuple_GetSlice(__pyx_args, 3, PyTuple_GET_SIZE(__pyx_args)); __Pyx_GOTREF(__pyx_v_args);
    if (unlikely(!__pyx_v_args)) return NULL;
  } else {
    __pyx_v_args = __pyx_empty_tuple; __Pyx_INCREF(__pyx_empty_tuple);
  }
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      default:
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ip);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__flags);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dns_resolve_reverse_ipv6", 0, 3, 3, 1); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__callback);
      if (likely(values[2])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dns_resolve_reverse_ipv6", 0, 3, 3, 2); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      const Py_ssize_t used_pos_args = (PyTuple_GET_SIZE(__pyx_args) < 3) ? PyTuple_GET_SIZE(__pyx_args) : 3;
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, used_pos_args, "dns_resolve_reverse_ipv6") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_ip = __Pyx_PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_ip) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_flags = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_callback = values[2];
  } else if (PyTuple_GET_SIZE(__pyx_args) < 3) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_ip = __Pyx_PyBytes_AsString(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((!__pyx_v_ip) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_flags = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_callback = PyTuple_GET_ITEM(__pyx_args, 2);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dns_resolve_reverse_ipv6", 0, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_AddTraceback("event.dns_resolve_reverse_ipv6");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_v_t = Py_None; __Pyx_INCREF(Py_None);

  /* "evdns.pxi":125
 *     """
 *     cdef int i
 *     t = (callback, args)             # <<<<<<<<<<<<<<
 *     i = id(t)
 *     __evdns_cbargs[i] = t
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_callback);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_callback);
  __Pyx_GIVEREF(__pyx_v_callback);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_t);
  __pyx_v_t = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "evdns.pxi":126
 *     cdef int i
 *     t = (callback, args)
 *     i = id(t)             # <<<<<<<<<<<<<<
 *     __evdns_cbargs[i] = t
 *     evdns_resolve_reverse(ip, flags, __evdns_callback, <void *>i)
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_t);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_t);
  __Pyx_GIVEREF(__pyx_v_t);
  __pyx_t_2 = PyObject_Call(__pyx_builtin_id, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_i = __pyx_t_3;

  /* "evdns.pxi":127
 *     t = (callback, args)
 *     i = id(t)
 *     __evdns_cbargs[i] = t             # <<<<<<<<<<<<<<
 *     evdns_resolve_reverse(ip, flags, __evdns_callback, <void *>i)
 * 
 */
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s____evdns_cbargs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemInt(__pyx_t_2, __pyx_v_i, __pyx_v_t, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "evdns.pxi":128
 *     i = id(t)
 *     __evdns_cbargs[i] = t
 *     evdns_resolve_reverse(ip, flags, __evdns_callback, <void *>i)             # <<<<<<<<<<<<<<
 * 
 * def dns_shutdown(int fail_requests=0):
 */
  evdns_resolve_reverse(__pyx_v_ip, __pyx_v_flags, __pyx_f_5event___evdns_callback, ((void *)__pyx_v_i));

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.dns_resolve_reverse_ipv6");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evdns.pxi":130
 *     evdns_resolve_reverse(ip, flags, __evdns_callback, <void *>i)
 * 
 * def dns_shutdown(int fail_requests=0):             # <<<<<<<<<<<<<<
 *     """Shutdown the async DNS resolver and terminate all active requests."""
 *     evdns_shutdown(fail_requests)
 */

static PyObject *__pyx_pf_5event_dns_shutdown(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5event_dns_shutdown[] = "Shutdown the async DNS resolver and terminate all active requests.";
static PyObject *__pyx_pf_5event_dns_shutdown(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_fail_requests;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fail_requests,0};
  __Pyx_RefNannySetupContext("dns_shutdown");
  __pyx_self = __pyx_self;
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fail_requests);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "dns_shutdown") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    if (values[0]) {
      __pyx_v_fail_requests = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_fail_requests == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_fail_requests = ((int)0);
    }
  } else {
    __pyx_v_fail_requests = ((int)0);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_fail_requests = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_fail_requests == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("dns_shutdown", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.dns_shutdown");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "evdns.pxi":132
 * def dns_shutdown(int fail_requests=0):
 *     """Shutdown the async DNS resolver and terminate all active requests."""
 *     evdns_shutdown(fail_requests)             # <<<<<<<<<<<<<<
 *     __evdns_cbargs.clear()
 * 
 */
  evdns_shutdown(__pyx_v_fail_requests);

  /* "evdns.pxi":133
 *     """Shutdown the async DNS resolver and terminate all active requests."""
 *     evdns_shutdown(fail_requests)
 *     __evdns_cbargs.clear()             # <<<<<<<<<<<<<<
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s____evdns_cbargs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__clear); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.dns_shutdown");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":94
 *     cdef object code, reason
 * 
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         self.headers_sent = 0
 *         self.code = self.reason = None
 */

static int __pyx_pf_5event_16__start_response___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_5event_16__start_response___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;

  /* "evhttp.pxi":95
 * 
 *     def __init__(self):
 *         self.headers_sent = 0             # <<<<<<<<<<<<<<
 *         self.code = self.reason = None
 * 
 */
  ((struct __pyx_obj_5event___start_response *)__pyx_v_self)->headers_sent = 0;

  /* "evhttp.pxi":96
 *     def __init__(self):
 *         self.headers_sent = 0
 *         self.code = self.reason = None             # <<<<<<<<<<<<<<
 * 
 *     cdef void _set_req(self, evhttp_request *req):
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code);
  __Pyx_DECREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code);
  ((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code = Py_None;
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason);
  __Pyx_DECREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason);
  ((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason = Py_None;

  __pyx_r = 0;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":98
 *         self.code = self.reason = None
 * 
 *     cdef void _set_req(self, evhttp_request *req):             # <<<<<<<<<<<<<<
 *         self.req = req
 * 
 */

static  void __pyx_f_5event_16__start_response__set_req(struct __pyx_obj_5event___start_response *__pyx_v_self, struct evhttp_request *__pyx_v_req) {
  __Pyx_RefNannySetupContext("_set_req");

  /* "evhttp.pxi":99
 * 
 *     cdef void _set_req(self, evhttp_request *req):
 *         self.req = req             # <<<<<<<<<<<<<<
 * 
 *     def __call__(self, status, headers, exc_info=None):
 */
  __pyx_v_self->req = __pyx_v_req;

  __Pyx_RefNannyFinishContext();
}

/* "evhttp.pxi":101
 *         self.req = req
 * 
 *     def __call__(self, status, headers, exc_info=None):             # <<<<<<<<<<<<<<
 *         if exc_info is not None:
 *             try:
 */

static PyObject *__pyx_pf_5event_16__start_response___call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_5event_16__start_response___call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_status = 0;
  PyObject *__pyx_v_headers = 0;
  PyObject *__pyx_v_exc_info = 0;
  PyObject *__pyx_v_name;
  PyObject *__pyx_v_val;
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  char *__pyx_t_8;
  char *__pyx_t_9;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__status,&__pyx_n_s__headers,&__pyx_n_s__exc_info,0};
  __Pyx_RefNannySetupContext("__call__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[3] = {0,0,0};
    values[2] = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__status);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__headers);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("__call__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
      case  2:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__exc_info);
        if (unlikely(value)) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__call__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_status = values[0];
    __pyx_v_headers = values[1];
    __pyx_v_exc_info = values[2];
  } else {
    __pyx_v_exc_info = ((PyObject *)Py_None);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3:
      __pyx_v_exc_info = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2:
      __pyx_v_headers = PyTuple_GET_ITEM(__pyx_args, 1);
      __pyx_v_status = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__call__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.__start_response.__call__");
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_status);
  __Pyx_INCREF(__pyx_v_headers);
  __Pyx_INCREF(__pyx_v_exc_info);
  __pyx_v_name = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_val = Py_None; __Pyx_INCREF(Py_None);

  /* "evhttp.pxi":102
 * 
 *     def __call__(self, status, headers, exc_info=None):
 *         if exc_info is not None:             # <<<<<<<<<<<<<<
 *             try:
 *                 if self.headers_sent != 0:
 */
  __pyx_t_1 = (__pyx_v_exc_info != Py_None);
  if (__pyx_t_1) {

    /* "evhttp.pxi":103
 *     def __call__(self, status, headers, exc_info=None):
 *         if exc_info is not None:
 *             try:             # <<<<<<<<<<<<<<
 *                 if self.headers_sent != 0:
 *                     # Re-raise original exception if headers sent
 */
    /*try:*/ {

      /* "evhttp.pxi":104
 *         if exc_info is not None:
 *             try:
 *                 if self.headers_sent != 0:             # <<<<<<<<<<<<<<
 *                     # Re-raise original exception if headers sent
 *                     raise exc_info[0], exc_info[1], exc_info[2]
 */
      __pyx_t_1 = (((struct __pyx_obj_5event___start_response *)__pyx_v_self)->headers_sent != 0);
      if (__pyx_t_1) {

        /* "evhttp.pxi":106
 *                 if self.headers_sent != 0:
 *                     # Re-raise original exception if headers sent
 *                     raise exc_info[0], exc_info[1], exc_info[2]             # <<<<<<<<<<<<<<
 *             finally:
 *                 exc_info = None
 */
        __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_exc_info, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L8;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_exc_info, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L8;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_exc_info, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L8;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_Raise(__pyx_t_2, __pyx_t_3, __pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        {__pyx_filename = __pyx_f[2]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L8;}
        goto __pyx_L10;
      }
      __pyx_L10:;
    }
    /*finally:*/ {
      int __pyx_why;
      PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
      int __pyx_exc_lineno;
      __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0;
      __pyx_why = 0; goto __pyx_L9;
      __pyx_L8: {
        __pyx_why = 4;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
        __pyx_exc_lineno = __pyx_lineno;
        goto __pyx_L9;
      }
      __pyx_L9:;

      /* "evhttp.pxi":108
 *                     raise exc_info[0], exc_info[1], exc_info[2]
 *             finally:
 *                 exc_info = None             # <<<<<<<<<<<<<<
 *         elif self.code is not None:
 *             raise AssertionError("Headers already set!")
 */
      __Pyx_INCREF(Py_None);
      __Pyx_DECREF(__pyx_v_exc_info);
      __pyx_v_exc_info = Py_None;
      switch (__pyx_why) {
        case 4: {
          __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
          __pyx_lineno = __pyx_exc_lineno;
          __pyx_exc_type = 0;
          __pyx_exc_value = 0;
          __pyx_exc_tb = 0;
          goto __pyx_L1_error;
        }
      }
    }
    goto __pyx_L6;
  }

  /* "evhttp.pxi":109
 *             finally:
 *                 exc_info = None
 *         elif self.code is not None:             # <<<<<<<<<<<<<<
 *             raise AssertionError("Headers already set!")
 * 
 */
  __pyx_t_1 = (((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code != Py_None);
  if (__pyx_t_1) {

    /* "evhttp.pxi":110
 *                 exc_info = None
 *         elif self.code is not None:
 *             raise AssertionError("Headers already set!")             # <<<<<<<<<<<<<<
 * 
 *         self.code, self.reason = status.split(None, 1)
 */
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4));
    __pyx_t_3 = PyObject_Call(__pyx_builtin_AssertionError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "evhttp.pxi":112
 *             raise AssertionError("Headers already set!")
 * 
 *         self.code, self.reason = status.split(None, 1)             # <<<<<<<<<<<<<<
 *         for name, val in headers:
 *             evhttp_add_header(self.req.output_headers, name, val)
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_status, __pyx_n_s__split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_4, 0, Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_INCREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyTuple_CheckExact(__pyx_t_2) && likely(PyTuple_GET_SIZE(__pyx_t_2) == 2)) {
    PyObject* tuple = __pyx_t_2;
    __pyx_t_4 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_4);
    __pyx_t_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GIVEREF(__pyx_t_4);
    __Pyx_GOTREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code);
    __Pyx_DECREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code);
    ((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code = __pyx_t_4;
    __pyx_t_4 = 0;
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason);
    __Pyx_DECREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason);
    ((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason = __pyx_t_3;
    __pyx_t_3 = 0;
  } else {
    __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_UnpackItem(__pyx_t_5, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_UnpackItem(__pyx_t_5, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if (__Pyx_EndUnpack(__pyx_t_5) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GIVEREF(__pyx_t_4);
    __Pyx_GOTREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code);
    __Pyx_DECREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code);
    ((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code = __pyx_t_4;
    __pyx_t_4 = 0;
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_GOTREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason);
    __Pyx_DECREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason);
    ((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason = __pyx_t_3;
    __pyx_t_3 = 0;
  }

  /* "evhttp.pxi":113
 * 
 *         self.code, self.reason = status.split(None, 1)
 *         for name, val in headers:             # <<<<<<<<<<<<<<
 *             evhttp_add_header(self.req.output_headers, name, val)
 *         return self.write
 */
  if (PyList_CheckExact(__pyx_v_headers) || PyTuple_CheckExact(__pyx_v_headers)) {
    __pyx_t_6 = 0; __pyx_t_2 = __pyx_v_headers; __Pyx_INCREF(__pyx_t_2);
  } else {
    __pyx_t_6 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_headers); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
  }
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_2))) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_2))) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++;
    } else {
      __pyx_t_3 = PyIter_Next(__pyx_t_2);
      if (!__pyx_t_3) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if (PyTuple_CheckExact(__pyx_t_3) && likely(PyTuple_GET_SIZE(__pyx_t_3) == 2)) {
      PyObject* tuple = __pyx_t_3;
      __pyx_t_4 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_t_4);
      __pyx_t_5 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_v_name);
      __pyx_v_name = __pyx_t_4;
      __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_v_val);
      __pyx_v_val = __pyx_t_5;
      __pyx_t_5 = 0;
    } else {
      __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_4 = __Pyx_UnpackItem(__pyx_t_7, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_UnpackItem(__pyx_t_7, 1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      if (__Pyx_EndUnpack(__pyx_t_7) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_v_name);
      __pyx_v_name = __pyx_t_4;
      __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_v_val);
      __pyx_v_val = __pyx_t_5;
      __pyx_t_5 = 0;
    }

    /* "evhttp.pxi":114
 *         self.code, self.reason = status.split(None, 1)
 *         for name, val in headers:
 *             evhttp_add_header(self.req.output_headers, name, val)             # <<<<<<<<<<<<<<
 *         return self.write
 * 
 */
    __pyx_t_8 = __Pyx_PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = __Pyx_PyBytes_AsString(__pyx_v_val); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    evhttp_add_header(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->req->output_headers, __pyx_t_8, __pyx_t_9);
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "evhttp.pxi":115
 *         for name, val in headers:
 *             evhttp_add_header(self.req.output_headers, name, val)
 *         return self.write             # <<<<<<<<<<<<<<
 * 
 *     def _check_headers_sent(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("event.__start_response.__call__");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_name);
  __Pyx_DECREF(__pyx_v_val);
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_status);
  __Pyx_DECREF(__pyx_v_headers);
  __Pyx_DECREF(__pyx_v_exc_info);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":117
 *         return self.write
 * 
 *     def _check_headers_sent(self):             # <<<<<<<<<<<<<<
 *         # Only start sending response after we've gotten data to write
 *         if self.headers_sent == 0:
 */

static PyObject *__pyx_pf_5event_16__start_response__check_headers_sent(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_5event_16__start_response__check_headers_sent(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  char *__pyx_t_5;
  __Pyx_RefNannySetupContext("_check_headers_sent");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "evhttp.pxi":119
 *     def _check_headers_sent(self):
 *         # Only start sending response after we've gotten data to write
 *         if self.headers_sent == 0:             # <<<<<<<<<<<<<<
 *             evhttp_send_reply_start(self.req, int(self.code), self.reason)
 *             self.headers_sent = 1
 */
  __pyx_t_1 = (((struct __pyx_obj_5event___start_response *)__pyx_v_self)->headers_sent == 0);
  if (__pyx_t_1) {

    /* "evhttp.pxi":120
 *         # Only start sending response after we've gotten data to write
 *         if self.headers_sent == 0:
 *             evhttp_send_reply_start(self.req, int(self.code), self.reason)             # <<<<<<<<<<<<<<
 *             self.headers_sent = 1
 * 
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code);
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code);
    __Pyx_GIVEREF(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->code);
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)&PyInt_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyBytes_AsString(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->reason); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    evhttp_send_reply_start(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->req, __pyx_t_4, __pyx_t_5);

    /* "evhttp.pxi":121
 *         if self.headers_sent == 0:
 *             evhttp_send_reply_start(self.req, int(self.code), self.reason)
 *             self.headers_sent = 1             # <<<<<<<<<<<<<<
 * 
 *     def write(self, data):
 */
    ((struct __pyx_obj_5event___start_response *)__pyx_v_self)->headers_sent = 1;
    goto __pyx_L5;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("event.__start_response._check_headers_sent");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":123
 *             self.headers_sent = 1
 * 
 *     def write(self, data):             # <<<<<<<<<<<<<<
 *         cdef evbuffer *buf
 * 
 */

static PyObject *__pyx_pf_5event_16__start_response_write(PyObject *__pyx_v_self, PyObject *__pyx_v_data); /*proto*/
static PyObject *__pyx_pf_5event_16__start_response_write(PyObject *__pyx_v_self, PyObject *__pyx_v_data) {
  struct evbuffer *__pyx_v_buf;
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  __Pyx_RefNannySetupContext("write");

  /* "evhttp.pxi":126
 *         cdef evbuffer *buf
 * 
 *         buf = evbuffer_new()             # <<<<<<<<<<<<<<
 *         evbuffer_add(buf, data, len(data))
 *         self._check_headers_sent()
 */
  __pyx_v_buf = evbuffer_new();

  /* "evhttp.pxi":127
 * 
 *         buf = evbuffer_new()
 *         evbuffer_add(buf, data, len(data))             # <<<<<<<<<<<<<<
 *         self._check_headers_sent()
 *         evhttp_send_reply_chunk(self.req, buf)
 */
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_data); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  evbuffer_add(__pyx_v_buf, __pyx_t_1, __pyx_t_2);

  /* "evhttp.pxi":128
 *         buf = evbuffer_new()
 *         evbuffer_add(buf, data, len(data))
 *         self._check_headers_sent()             # <<<<<<<<<<<<<<
 *         evhttp_send_reply_chunk(self.req, buf)
 *         evbuffer_free(buf)
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___check_headers_sent); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "evhttp.pxi":129
 *         evbuffer_add(buf, data, len(data))
 *         self._check_headers_sent()
 *         evhttp_send_reply_chunk(self.req, buf)             # <<<<<<<<<<<<<<
 *         evbuffer_free(buf)
 * 
 */
  evhttp_send_reply_chunk(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->req, __pyx_v_buf);

  /* "evhttp.pxi":130
 *         self._check_headers_sent()
 *         evhttp_send_reply_chunk(self.req, buf)
 *         evbuffer_free(buf)             # <<<<<<<<<<<<<<
 * 
 *     def end(self):
 */
  evbuffer_free(__pyx_v_buf);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("event.__start_response.write");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":132
 *         evbuffer_free(buf)
 * 
 *     def end(self):             # <<<<<<<<<<<<<<
 *         self._check_headers_sent()
 *         evhttp_send_reply_end(self.req)
 */

static PyObject *__pyx_pf_5event_16__start_response_end(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_5event_16__start_response_end(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __Pyx_RefNannySetupContext("end");

  /* "evhttp.pxi":133
 * 
 *     def end(self):
 *         self._check_headers_sent()             # <<<<<<<<<<<<<<
 *         evhttp_send_reply_end(self.req)
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s___check_headers_sent); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "evhttp.pxi":134
 *     def end(self):
 *         self._check_headers_sent()
 *         evhttp_send_reply_end(self.req)             # <<<<<<<<<<<<<<
 * 
 * cdef class __wsgi_input:
 */
  evhttp_send_reply_end(((struct __pyx_obj_5event___start_response *)__pyx_v_self)->req);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("event.__start_response.end");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":139
 *     cdef evbuffer *_buf
 * 
 *     cdef void _set_buf(self, evbuffer *buf):             # <<<<<<<<<<<<<<
 *         self._buf = buf
 * 
 */

static  void __pyx_f_5event_12__wsgi_input__set_buf(struct __pyx_obj_5event___wsgi_input *__pyx_v_self, struct evbuffer *__pyx_v_buf) {
  __Pyx_RefNannySetupContext("_set_buf");

  /* "evhttp.pxi":140
 * 
 *     cdef void _set_buf(self, evbuffer *buf):
 *         self._buf = buf             # <<<<<<<<<<<<<<
 * 
 *     def read(self, size=-1):
 */
  __pyx_v_self->_buf = __pyx_v_buf;

  __Pyx_RefNannyFinishContext();
}

/* "evhttp.pxi":142
 *         self._buf = buf
 * 
 *     def read(self, size=-1):             # <<<<<<<<<<<<<<
 *         return PyString_FromStringAndSize(EVBUFFER_DATA(self._buf),
 *                                           EVBUFFER_LENGTH(self._buf))
 */

static PyObject *__pyx_pf_5event_12__wsgi_input_read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_5event_12__wsgi_input_read(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_size = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,0};
  __Pyx_RefNannySetupContext("read");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    values[0] = ((PyObject *)__pyx_int_neg_1);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "read") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_size = values[0];
  } else {
    __pyx_v_size = ((PyObject *)__pyx_int_neg_1);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_size = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("read", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.__wsgi_input.read");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "evhttp.pxi":143
 * 
 *     def read(self, size=-1):
 *         return PyString_FromStringAndSize(EVBUFFER_DATA(self._buf),             # <<<<<<<<<<<<<<
 *                                           EVBUFFER_LENGTH(self._buf))
 *     def readline(self):
 */
  __Pyx_XDECREF(__pyx_r);

  /* "evhttp.pxi":144
 *     def read(self, size=-1):
 *         return PyString_FromStringAndSize(EVBUFFER_DATA(self._buf),
 *                                           EVBUFFER_LENGTH(self._buf))             # <<<<<<<<<<<<<<
 *     def readline(self):
 *         return evbuffer_readline(self._buf) or ''
 */
  __pyx_t_1 = PyString_FromStringAndSize(EVBUFFER_DATA(((struct __pyx_obj_5event___wsgi_input *)__pyx_v_self)->_buf), EVBUFFER_LENGTH(((struct __pyx_obj_5event___wsgi_input *)__pyx_v_self)->_buf)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("event.__wsgi_input.read");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":145
 *         return PyString_FromStringAndSize(EVBUFFER_DATA(self._buf),
 *                                           EVBUFFER_LENGTH(self._buf))
 *     def readline(self):             # <<<<<<<<<<<<<<
 *         return evbuffer_readline(self._buf) or ''
 * 
 */

static PyObject *__pyx_pf_5event_12__wsgi_input_readline(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static PyObject *__pyx_pf_5event_12__wsgi_input_readline(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("readline");

  /* "evhttp.pxi":146
 *                                           EVBUFFER_LENGTH(self._buf))
 *     def readline(self):
 *         return evbuffer_readline(self._buf) or ''             # <<<<<<<<<<<<<<
 * 
 *     def readlines(self, hint=-1):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBytes_FromString(evbuffer_readline(((struct __pyx_obj_5event___wsgi_input *)__pyx_v_self)->_buf)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_2 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_2) {
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_5));
    __pyx_t_3 = __pyx_kp_s_5;
  } else {
    __pyx_t_3 = __pyx_t_1;
    __pyx_t_1 = 0;
  }
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("event.__wsgi_input.readline");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":148
 *         return evbuffer_readline(self._buf) or ''
 * 
 *     def readlines(self, hint=-1):             # <<<<<<<<<<<<<<
 *         return self.read().splitlines(1)
 * 
 */

static PyObject *__pyx_pf_5event_12__wsgi_input_readlines(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pf_5event_12__wsgi_input_readlines(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_hint = 0;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hint,0};
  __Pyx_RefNannySetupContext("readlines");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[1] = {0};
    values[0] = ((PyObject *)__pyx_int_neg_1);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hint);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "readlines") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_hint = values[0];
  } else {
    __pyx_v_hint = ((PyObject *)__pyx_int_neg_1);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  1: __pyx_v_hint = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("readlines", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.__wsgi_input.readlines");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "evhttp.pxi":149
 * 
 *     def readlines(self, hint=-1):
 *         return self.read().splitlines(1)             # <<<<<<<<<<<<<<
 * 
 * cdef void __path_handler(evhttp_request *req, void *arg) with gil:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_n_s__read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__splitlines); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("event.__wsgi_input.readlines");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":151
 *         return self.read().splitlines(1)
 * 
 * cdef void __path_handler(evhttp_request *req, void *arg) with gil:             # <<<<<<<<<<<<<<
 *     cdef __start_response start_response
 *     cdef __wsgi_input wsgi_input
 */

static  void __pyx_f_5event___path_handler(struct evhttp_request *__pyx_v_req, void *__pyx_v_arg) {
  struct __pyx_obj_5event___start_response *__pyx_v_start_response;
  struct __pyx_obj_5event___wsgi_input *__pyx_v_wsgi_input;
  char *__pyx_v_content_type;
  char *__pyx_v_content_len;
  char *__pyx_v_host;
  PyObject *__pyx_v_app;
  PyObject *__pyx_v_server_name;
  PyObject *__pyx_v_server_port;
  PyObject *__pyx_v_l;
  PyObject *__pyx_v_environ;
  PyObject *__pyx_v_buf;
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyGILState_STATE _save = PyGILState_Ensure();
  __Pyx_RefNannySetupContext("__path_handler");
  __pyx_v_start_response = ((struct __pyx_obj_5event___start_response *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_wsgi_input = ((struct __pyx_obj_5event___wsgi_input *)Py_None); __Pyx_INCREF(Py_None);
  __pyx_v_app = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_server_name = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_server_port = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_l = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_environ = Py_None; __Pyx_INCREF(Py_None);
  __pyx_v_buf = Py_None; __Pyx_INCREF(Py_None);

  /* "evhttp.pxi":156
 *     cdef char *content_type, *content_len, *host
 * 
 *     app = (<object>arg)             # <<<<<<<<<<<<<<
 *     if app is None:
 *         return
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_arg));
  __Pyx_DECREF(__pyx_v_app);
  __pyx_v_app = ((PyObject *)__pyx_v_arg);

  /* "evhttp.pxi":157
 * 
 *     app = (<object>arg)
 *     if app is None:             # <<<<<<<<<<<<<<
 *         return
 *     start_response = __start_response()
 */
  __pyx_t_1 = (__pyx_v_app == Py_None);
  if (__pyx_t_1) {

    /* "evhttp.pxi":158
 *     app = (<object>arg)
 *     if app is None:
 *         return             # <<<<<<<<<<<<<<
 *     start_response = __start_response()
 *     start_response._set_req(req)
 */
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "evhttp.pxi":159
 *     if app is None:
 *         return
 *     start_response = __start_response()             # <<<<<<<<<<<<<<
 *     start_response._set_req(req)
 *     wsgi_input = __wsgi_input()
 */
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5event___start_response)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_v_start_response));
  __pyx_v_start_response = ((struct __pyx_obj_5event___start_response *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "evhttp.pxi":160
 *         return
 *     start_response = __start_response()
 *     start_response._set_req(req)             # <<<<<<<<<<<<<<
 *     wsgi_input = __wsgi_input()
 *     wsgi_input._set_buf(req.input_buffer)
 */
  ((struct __pyx_vtabstruct_5event___start_response *)__pyx_v_start_response->__pyx_vtab)->_set_req(__pyx_v_start_response, __pyx_v_req);

  /* "evhttp.pxi":161
 *     start_response = __start_response()
 *     start_response._set_req(req)
 *     wsgi_input = __wsgi_input()             # <<<<<<<<<<<<<<
 *     wsgi_input._set_buf(req.input_buffer)
 *     content_type = evhttp_find_header(req.input_headers, 'Content-Type')
 */
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5event___wsgi_input)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_v_wsgi_input));
  __pyx_v_wsgi_input = ((struct __pyx_obj_5event___wsgi_input *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "evhttp.pxi":162
 *     start_response._set_req(req)
 *     wsgi_input = __wsgi_input()
 *     wsgi_input._set_buf(req.input_buffer)             # <<<<<<<<<<<<<<
 *     content_type = evhttp_find_header(req.input_headers, 'Content-Type')
 *     if not content_type: content_type = ''
 */
  ((struct __pyx_vtabstruct_5event___wsgi_input *)__pyx_v_wsgi_input->__pyx_vtab)->_set_buf(__pyx_v_wsgi_input, __pyx_v_req->input_buffer);

  /* "evhttp.pxi":163
 *     wsgi_input = __wsgi_input()
 *     wsgi_input._set_buf(req.input_buffer)
 *     content_type = evhttp_find_header(req.input_headers, 'Content-Type')             # <<<<<<<<<<<<<<
 *     if not content_type: content_type = ''
 *     content_len = evhttp_find_header(req.input_headers, 'Content-Length')
 */
  __pyx_v_content_type = evhttp_find_header(__pyx_v_req->input_headers, __pyx_k_6);

  /* "evhttp.pxi":164
 *     wsgi_input._set_buf(req.input_buffer)
 *     content_type = evhttp_find_header(req.input_headers, 'Content-Type')
 *     if not content_type: content_type = ''             # <<<<<<<<<<<<<<
 *     content_len = evhttp_find_header(req.input_headers, 'Content-Length')
 *     if not content_len: content_len = ''
 */
  __pyx_t_1 = (!(__pyx_v_content_type != 0));
  if (__pyx_t_1) {
    __pyx_v_content_type = __pyx_k_5;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "evhttp.pxi":165
 *     content_type = evhttp_find_header(req.input_headers, 'Content-Type')
 *     if not content_type: content_type = ''
 *     content_len = evhttp_find_header(req.input_headers, 'Content-Length')             # <<<<<<<<<<<<<<
 *     if not content_len: content_len = ''
 *     host = evhttp_find_header(req.input_headers, 'Host')
 */
  __pyx_v_content_len = evhttp_find_header(__pyx_v_req->input_headers, __pyx_k_7);

  /* "evhttp.pxi":166
 *     if not content_type: content_type = ''
 *     content_len = evhttp_find_header(req.input_headers, 'Content-Length')
 *     if not content_len: content_len = ''             # <<<<<<<<<<<<<<
 *     host = evhttp_find_header(req.input_headers, 'Host')
 *     if not host:
 */
  __pyx_t_1 = (!(__pyx_v_content_len != 0));
  if (__pyx_t_1) {
    __pyx_v_content_len = __pyx_k_5;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "evhttp.pxi":167
 *     content_len = evhttp_find_header(req.input_headers, 'Content-Length')
 *     if not content_len: content_len = ''
 *     host = evhttp_find_header(req.input_headers, 'Host')             # <<<<<<<<<<<<<<
 *     if not host:
 *         server_name = ''
 */
  __pyx_v_host = evhttp_find_header(__pyx_v_req->input_headers, __pyx_k__Host);

  /* "evhttp.pxi":168
 *     if not content_len: content_len = ''
 *     host = evhttp_find_header(req.input_headers, 'Host')
 *     if not host:             # <<<<<<<<<<<<<<
 *         server_name = ''
 *         server_port = '80'
 */
  __pyx_t_1 = (!(__pyx_v_host != 0));
  if (__pyx_t_1) {

    /* "evhttp.pxi":169
 *     host = evhttp_find_header(req.input_headers, 'Host')
 *     if not host:
 *         server_name = ''             # <<<<<<<<<<<<<<
 *         server_port = '80'
 *     else:
 */
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_5));
    __Pyx_DECREF(__pyx_v_server_name);
    __pyx_v_server_name = ((PyObject *)__pyx_kp_s_5);

    /* "evhttp.pxi":170
 *     if not host:
 *         server_name = ''
 *         server_port = '80'             # <<<<<<<<<<<<<<
 *     else:
 *         l = host.split(':')
 */
    __Pyx_INCREF(((PyObject *)__pyx_kp_s__80));
    __Pyx_DECREF(__pyx_v_server_port);
    __pyx_v_server_port = ((PyObject *)__pyx_kp_s__80);
    goto __pyx_L6;
  }
  /*else*/ {

    /* "evhttp.pxi":172
 *         server_port = '80'
 *     else:
 *         l = host.split(':')             # <<<<<<<<<<<<<<
 *         server_name = l[0]
 *         if len(l) > 1:
 */
    __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_host); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_t_2), __pyx_n_s__split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_kp_s_8));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_8));
    __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_8));
    __pyx_t_4 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_v_l);
    __pyx_v_l = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "evhttp.pxi":173
 *     else:
 *         l = host.split(':')
 *         server_name = l[0]             # <<<<<<<<<<<<<<
 *         if len(l) > 1:
 *             server_port = l[1]
 */
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_l, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_v_server_name);
    __pyx_v_server_name = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "evhttp.pxi":174
 *         l = host.split(':')
 *         server_name = l[0]
 *         if len(l) > 1:             # <<<<<<<<<<<<<<
 *             server_port = l[1]
 *         else:
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_l); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = (__pyx_t_5 > 1);
    if (__pyx_t_1) {

      /* "evhttp.pxi":175
 *         server_name = l[0]
 *         if len(l) > 1:
 *             server_port = l[1]             # <<<<<<<<<<<<<<
 *         else:
 *             server_port = '80'
 */
      __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_l, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_v_server_port);
      __pyx_v_server_port = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "evhttp.pxi":177
 *             server_port = l[1]
 *         else:
 *             server_port = '80'             # <<<<<<<<<<<<<<
 *     environ = {
 *         # WSGI/1.0
 */
      __Pyx_INCREF(((PyObject *)__pyx_kp_s__80));
      __Pyx_DECREF(__pyx_v_server_port);
      __pyx_v_server_port = ((PyObject *)__pyx_kp_s__80);
    }
    __pyx_L7:;
  }
  __pyx_L6:;

  /* "evhttp.pxi":178
 *         else:
 *             server_port = '80'
 *     environ = {             # <<<<<<<<<<<<<<
 *         # WSGI/1.0
 *         'wsgi.version': (1,0),
 */
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));

  /* "evhttp.pxi":180
 *     environ = {
 *         # WSGI/1.0
 *         'wsgi.version': (1,0),             # <<<<<<<<<<<<<<
 *         'wsgi.url_scheme': 'http',
 *         'wsgi.input': wsgi_input,
 */
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_int_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_s_9), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_s_10), ((PyObject *)__pyx_n_s__http)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":182
 *         'wsgi.version': (1,0),
 *         'wsgi.url_scheme': 'http',
 *         'wsgi.input': wsgi_input,             # <<<<<<<<<<<<<<
 *         'wsgi.errors': sys.stderr,
 *         'wsgi.multithread': False,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_s_11), ((PyObject *)__pyx_v_wsgi_input)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":183
 *         'wsgi.url_scheme': 'http',
 *         'wsgi.input': wsgi_input,
 *         'wsgi.errors': sys.stderr,             # <<<<<<<<<<<<<<
 *         'wsgi.multithread': False,
 *         'wsgi.multiprocess': False,
 */
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_s_12), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "evhttp.pxi":184
 *         'wsgi.input': wsgi_input,
 *         'wsgi.errors': sys.stderr,
 *         'wsgi.multithread': False,             # <<<<<<<<<<<<<<
 *         'wsgi.multiprocess': False,
 *         'wsgi.run_once': False,
 */
  __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_s_13), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "evhttp.pxi":185
 *         'wsgi.errors': sys.stderr,
 *         'wsgi.multithread': False,
 *         'wsgi.multiprocess': False,             # <<<<<<<<<<<<<<
 *         'wsgi.run_once': False,
 *         # CGI/1.1
 */
  __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_s_14), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "evhttp.pxi":186
 *         'wsgi.multithread': False,
 *         'wsgi.multiprocess': False,
 *         'wsgi.run_once': False,             # <<<<<<<<<<<<<<
 *         # CGI/1.1
 *         'REQUEST_METHOD': HTTP_method2name[req.type],
 */
  __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_kp_s_15), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "evhttp.pxi":188
 *         'wsgi.run_once': False,
 *         # CGI/1.1
 *         'REQUEST_METHOD': HTTP_method2name[req.type],             # <<<<<<<<<<<<<<
 *         'SCRIPT_NAME': req.uri,
 *         'PATH_INFO': '',
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__HTTP_method2name); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, __pyx_v_req->type, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__REQUEST_METHOD), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "evhttp.pxi":189
 *         # CGI/1.1
 *         'REQUEST_METHOD': HTTP_method2name[req.type],
 *         'SCRIPT_NAME': req.uri,             # <<<<<<<<<<<<<<
 *         'PATH_INFO': '',
 *         'QUERY_STRING':'',
 */
  __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_req->uri); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SCRIPT_NAME), ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__PATH_INFO), ((PyObject *)__pyx_kp_s_5)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__QUERY_STRING), ((PyObject *)__pyx_kp_s_5)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":192
 *         'PATH_INFO': '',
 *         'QUERY_STRING':'',
 *         'CONTENT_TYPE': content_type,             # <<<<<<<<<<<<<<
 *         'CONTENT_LENGTH': content_len,
 *         'SERVER_NAME': server_name,
 */
  __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_content_type); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__CONTENT_TYPE), ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;

  /* "evhttp.pxi":193
 *         'QUERY_STRING':'',
 *         'CONTENT_TYPE': content_type,
 *         'CONTENT_LENGTH': content_len,             # <<<<<<<<<<<<<<
 *         'SERVER_NAME': server_name,
 *         'SERVER_PORT': server_port,
 */
  __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_content_len); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__CONTENT_LENGTH), ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;

  /* "evhttp.pxi":194
 *         'CONTENT_TYPE': content_type,
 *         'CONTENT_LENGTH': content_len,
 *         'SERVER_NAME': server_name,             # <<<<<<<<<<<<<<
 *         'SERVER_PORT': server_port,
 *         'SERVER_PROTOCOL':'HTTP/%s.%s' % (req.major, req.minor),
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SERVER_NAME), __pyx_v_server_name) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":195
 *         'CONTENT_LENGTH': content_len,
 *         'SERVER_NAME': server_name,
 *         'SERVER_PORT': server_port,             # <<<<<<<<<<<<<<
 *         'SERVER_PROTOCOL':'HTTP/%s.%s' % (req.major, req.minor),
 *         'REMOTE_HOST': req.remote_host, # XXX
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SERVER_PORT), __pyx_v_server_port) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":196
 *         'SERVER_NAME': server_name,
 *         'SERVER_PORT': server_port,
 *         'SERVER_PROTOCOL':'HTTP/%s.%s' % (req.major, req.minor),             # <<<<<<<<<<<<<<
 *         'REMOTE_HOST': req.remote_host, # XXX
 *         # Extras
 */
  __pyx_t_2 = PyInt_FromLong(__pyx_v_req->major); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyInt_FromLong(__pyx_v_req->minor); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_16), __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__SERVER_PROTOCOL), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "evhttp.pxi":197
 *         'SERVER_PORT': server_port,
 *         'SERVER_PROTOCOL':'HTTP/%s.%s' % (req.major, req.minor),
 *         'REMOTE_HOST': req.remote_host, # XXX             # <<<<<<<<<<<<<<
 *         # Extras
 *         'REMOTE_ADDR': req.remote_host,
 */
  __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_req->remote_host); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__REMOTE_HOST), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;

  /* "evhttp.pxi":199
 *         'REMOTE_HOST': req.remote_host, # XXX
 *         # Extras
 *         'REMOTE_ADDR': req.remote_host,             # <<<<<<<<<<<<<<
 *         'REMOTE_PORT': '%d' % req.remote_port,
 *         }
 */
  __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_req->remote_host); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__REMOTE_ADDR), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;

  /* "evhttp.pxi":200
 *         # Extras
 *         'REMOTE_ADDR': req.remote_host,
 *         'REMOTE_PORT': '%d' % req.remote_port,             # <<<<<<<<<<<<<<
 *         }
 *     for buf in app(environ, start_response):
 */
  __pyx_t_3 = PyInt_FromLong(__pyx_v_req->remote_port); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_17), __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__REMOTE_PORT), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_v_environ);
  __pyx_v_environ = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "evhttp.pxi":202
 *         'REMOTE_PORT': '%d' % req.remote_port,
 *         }
 *     for buf in app(environ, start_response):             # <<<<<<<<<<<<<<
 *         if buf:
 *             start_response.write(buf)
 */
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_environ);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_environ);
  __Pyx_GIVEREF(__pyx_v_environ);
  __Pyx_INCREF(((PyObject *)__pyx_v_start_response));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_start_response));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_start_response));
  __pyx_t_6 = PyObject_Call(__pyx_v_app, __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) {
    __pyx_t_5 = 0; __pyx_t_4 = __pyx_t_6; __Pyx_INCREF(__pyx_t_4);
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  for (;;) {
    if (likely(PyList_CheckExact(__pyx_t_4))) {
      if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++;
    } else if (likely(PyTuple_CheckExact(__pyx_t_4))) {
      if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
      __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++;
    } else {
      __pyx_t_6 = PyIter_Next(__pyx_t_4);
      if (!__pyx_t_6) {
        if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        break;
      }
      __Pyx_GOTREF(__pyx_t_6);
    }
    __Pyx_DECREF(__pyx_v_buf);
    __pyx_v_buf = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "evhttp.pxi":203
 *         }
 *     for buf in app(environ, start_response):
 *         if buf:             # <<<<<<<<<<<<<<
 *             start_response.write(buf)
 *     start_response.end()
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_buf); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_1) {

      /* "evhttp.pxi":204
 *     for buf in app(environ, start_response):
 *         if buf:
 *             start_response.write(buf)             # <<<<<<<<<<<<<<
 *     start_response.end()
 * 
 */
      __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_start_response), __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_buf);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_buf);
      __Pyx_GIVEREF(__pyx_v_buf);
      __pyx_t_2 = PyObject_Call(__pyx_t_6, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      goto __pyx_L10;
    }
    __pyx_L10:;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "evhttp.pxi":205
 *         if buf:
 *             start_response.write(buf)
 *     start_response.end()             # <<<<<<<<<<<<<<
 * 
 * cdef class wsgi:
 */
  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_start_response), __pyx_n_s__end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_WriteUnraisable("event.__path_handler");
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_start_response);
  __Pyx_DECREF((PyObject *)__pyx_v_wsgi_input);
  __Pyx_DECREF(__pyx_v_app);
  __Pyx_DECREF(__pyx_v_server_name);
  __Pyx_DECREF(__pyx_v_server_port);
  __Pyx_DECREF(__pyx_v_l);
  __Pyx_DECREF(__pyx_v_environ);
  __Pyx_DECREF(__pyx_v_buf);
  __Pyx_RefNannyFinishContext();
  PyGILState_Release(_save);
}

/* "evhttp.pxi":219
 *     cdef evhttp_t *_http
 * 
 *     def __init__(self, address='0.0.0.0', port=80):             # <<<<<<<<<<<<<<
 *         self._http = evhttp_start(address, port)
 *         if self._http == NULL:
 */

static int __pyx_pf_5event_4wsgi___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pf_5event_4wsgi___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_address = 0;
  PyObject *__pyx_v_port = 0;
  int __pyx_r;
  char *__pyx_t_1;
  unsigned short __pyx_t_2;
  int __pyx_t_3;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__address,&__pyx_n_s__port,0};
  __Pyx_RefNannySetupContext("__init__");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject *)__pyx_kp_s_18);
    values[1] = ((PyObject *)__pyx_int_80);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__address);
        if (unlikely(value)) { values[0] = value; kw_args--; }
      }
      case  1:
      if (kw_args > 1) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__port);
        if (unlikely(value)) { values[1] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_address = values[0];
    __pyx_v_port = values[1];
  } else {
    __pyx_v_address = ((PyObject *)__pyx_kp_s_18);
    __pyx_v_port = ((PyObject *)__pyx_int_80);
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: __pyx_v_port = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: __pyx_v_address = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.wsgi.__init__");
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_INCREF(__pyx_v_address);
  __Pyx_INCREF(__pyx_v_port);

  /* "evhttp.pxi":220
 * 
 *     def __init__(self, address='0.0.0.0', port=80):
 *         self._http = evhttp_start(address, port)             # <<<<<<<<<<<<<<
 *         if self._http == NULL:
 *             raise OSError, 'bind'	# XXX - libevent should event_warn
 */
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_address); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_AsUnsignedShort(__pyx_v_port); if (unlikely((__pyx_t_2 == (unsigned short)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  ((struct __pyx_obj_5event_wsgi *)__pyx_v_self)->_http = evhttp_start(__pyx_t_1, __pyx_t_2);

  /* "evhttp.pxi":221
 *     def __init__(self, address='0.0.0.0', port=80):
 *         self._http = evhttp_start(address, port)
 *         if self._http == NULL:             # <<<<<<<<<<<<<<
 *             raise OSError, 'bind'	# XXX - libevent should event_warn
 * 
 */
  __pyx_t_3 = (((struct __pyx_obj_5event_wsgi *)__pyx_v_self)->_http == NULL);
  if (__pyx_t_3) {

    /* "evhttp.pxi":222
 *         self._http = evhttp_start(address, port)
 *         if self._http == NULL:
 *             raise OSError, 'bind'	# XXX - libevent should event_warn             # <<<<<<<<<<<<<<
 * 
 *     def register_app(self, path, app):
 */
    __Pyx_Raise(__pyx_builtin_OSError, ((PyObject *)__pyx_n_s__bind), 0);
    {__pyx_filename = __pyx_f[2]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("event.wsgi.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_DECREF(__pyx_v_address);
  __Pyx_DECREF(__pyx_v_port);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":224
 *             raise OSError, 'bind'	# XXX - libevent should event_warn
 * 
 *     def register_app(self, path, app):             # <<<<<<<<<<<<<<
 *         """Register a WSGI application
 * 
 */

static PyObject *__pyx_pf_5event_4wsgi_register_app(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5event_4wsgi_register_app[] = "Register a WSGI application\n\n        Arguments:\n\n        path -- URI path for the application to be bound to\n        app  -- WSGI application object\n        ";
static PyObject *__pyx_pf_5event_4wsgi_register_app(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_path = 0;
  PyObject *__pyx_v_app = 0;
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__path,&__pyx_n_s__app,0};
  __Pyx_RefNannySetupContext("register_app");
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
    PyObject* values[2] = {0,0};
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  0:
      values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__path);
      if (likely(values[0])) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__app);
      if (likely(values[1])) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("register_app", 1, 2, 2, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "register_app") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    }
    __pyx_v_path = values[0];
    __pyx_v_app = values[1];
  } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
    goto __pyx_L5_argtuple_error;
  } else {
    __pyx_v_path = PyTuple_GET_ITEM(__pyx_args, 0);
    __pyx_v_app = PyTuple_GET_ITEM(__pyx_args, 1);
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("register_app", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("event.wsgi.register_app");
  return NULL;
  __pyx_L4_argument_unpacking_done:;

  /* "evhttp.pxi":232
 *         app  -- WSGI application object
 *         """
 *         evhttp_set_cb(self._http, path, __path_handler, <void *>app)             # <<<<<<<<<<<<<<
 * 
 *     def register_default_app(self, app):
 */
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_path); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  evhttp_set_cb(((struct __pyx_obj_5event_wsgi *)__pyx_v_self)->_http, __pyx_t_1, __pyx_f_5event___path_handler, ((void *)__pyx_v_app));

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("event.wsgi.register_app");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":234
 *         evhttp_set_cb(self._http, path, __path_handler, <void *>app)
 * 
 *     def register_default_app(self, app):             # <<<<<<<<<<<<<<
 *         """Register a default WSGI application
 * 
 */

static PyObject *__pyx_pf_5event_4wsgi_register_default_app(PyObject *__pyx_v_self, PyObject *__pyx_v_app); /*proto*/
static char __pyx_doc_5event_4wsgi_register_default_app[] = "Register a default WSGI application\n\n        Arguments:\n\n        app  -- WSGI application object\n        ";
static PyObject *__pyx_pf_5event_4wsgi_register_default_app(PyObject *__pyx_v_self, PyObject *__pyx_v_app) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannySetupContext("register_default_app");

  /* "evhttp.pxi":241
 *         app  -- WSGI application object
 *         """
 *         evhttp_set_gencb(self._http, __path_handler, <void *>app)             # <<<<<<<<<<<<<<
 * 
 *     def unregister_app(self, path):
 */
  evhttp_set_gencb(((struct __pyx_obj_5event_wsgi *)__pyx_v_self)->_http, __pyx_f_5event___path_handler, ((void *)__pyx_v_app));

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":243
 *         evhttp_set_gencb(self._http, __path_handler, <void *>app)
 * 
 *     def unregister_app(self, path):             # <<<<<<<<<<<<<<
 *         """Unregister a WSGI application
 * 
 */

static PyObject *__pyx_pf_5event_4wsgi_unregister_app(PyObject *__pyx_v_self, PyObject *__pyx_v_path); /*proto*/
static char __pyx_doc_5event_4wsgi_unregister_app[] = "Unregister a WSGI application\n\n        Arguments:\n\n        path -- URI path of bound WSGI application\n        ";
static PyObject *__pyx_pf_5event_4wsgi_unregister_app(PyObject *__pyx_v_self, PyObject *__pyx_v_path) {
  PyObject *__pyx_r = NULL;
  char *__pyx_t_1;
  __Pyx_RefNannySetupContext("unregister_app");

  /* "evhttp.pxi":250
 *         path -- URI path of bound WSGI application
 *         """
 *         evhttp_del_cb(self._http, path)             # <<<<<<<<<<<<<<
 * 
 *     def run(self):
 */
  __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_path); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  evhttp_del_cb(((struct __pyx_obj_5event_wsgi *)__pyx_v_self)->_http, __pyx_t_1);

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("event.wsgi.unregister_app");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":252
 *         evhttp_del_cb(self._http, path)
 * 
 *     def run(self):             # <<<<<<<<<<<<<<
 *         """Run WSGI server."""
 *         import signal as _signal
 */

static PyObject *__pyx_pf_5event_4wsgi_run(PyObject *__pyx_v_self, PyObject *unused); /*proto*/
static char __pyx_doc_5event_4wsgi_run[] = "Run WSGI server.";
static PyObject *__pyx_pf_5event_4wsgi_run(PyObject *__pyx_v_self, PyObject *unused) {
  PyObject *__pyx_v__signal;
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("run");
  __pyx_v__signal = Py_None; __Pyx_INCREF(Py_None);

  /* "evhttp.pxi":254
 *     def run(self):
 *         """Run WSGI server."""
 *         import signal as _signal             # <<<<<<<<<<<<<<
 *         signal(_signal.SIGINT, abort)
 *         signal(_signal.SIGTERM, abort)
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__signal), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_v__signal);
  __pyx_v__signal = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "evhttp.pxi":255
 *         """Run WSGI server."""
 *         import signal as _signal
 *         signal(_signal.SIGINT, abort)             # <<<<<<<<<<<<<<
 *         signal(_signal.SIGTERM, abort)
 *         dispatch()
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v__signal, __pyx_n_s__SIGINT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__abort); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5event_signal)), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "evhttp.pxi":256
 *         import signal as _signal
 *         signal(_signal.SIGINT, abort)
 *         signal(_signal.SIGTERM, abort)             # <<<<<<<<<<<<<<
 *         dispatch()
 * 
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_v__signal, __pyx_n_s__SIGTERM); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__abort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5event_signal)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "evhttp.pxi":257
 *         signal(_signal.SIGINT, abort)
 *         signal(_signal.SIGTERM, abort)
 *         dispatch()             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__dispatch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("event.wsgi.run");
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v__signal);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "evhttp.pxi":259
 *         dispatch()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self._http != NULL:
 *             evhttp_free(self._http)
 */

static void __pyx_pf_5event_4wsgi___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pf_5event_4wsgi___dealloc__(PyObject *__pyx_v_self) {
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__dealloc__");
  __Pyx_INCREF((PyObject *)__pyx_v_self);

  /* "evhttp.pxi":260
 * 
 *     def __dealloc__(self):
 *         if self._http != NULL:             # <<<<<<<<<<<<<<
 *             evhttp_free(self._http)
 *         self._http = NULL
 */
  __pyx_t_1 = (((struct __pyx_obj_5event_wsgi *)__pyx_v_self)->_http != NULL);
  if (__pyx_t_1) {

    /* "evhttp.pxi":261
 *     def __dealloc__(self):
 *         if self._http != NULL:
 *             evhttp_free(self._http)             # <<<<<<<<<<<<<<
 *         self._http = NULL
 * 
 */
    evhttp_free(((struct __pyx_obj_5event_wsgi *)__pyx_v_self)->_http);
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "evhttp.pxi":262
 *         if self._http != NULL:
 *             evhttp_free(self._http)
 *         self._http = NULL             # <<<<<<<<<<<<<<
 * 
 */
  ((struct __pyx_obj_5event_wsgi *)__pyx_v_self)->_http = NULL;

  __Pyx_DECREF((PyObject *)__pyx_v_self);
  __Pyx_RefNannyFinishContext();
}

static PyObject *__pyx_tp_new_5event_event(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5event_event *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_5event_event *)o);
  p->handle = Py_None; Py_INCREF(Py_None);
  p->evtype = Py_None; Py_INCREF(Py_None);
  p->callback = Py_None; Py_INCREF(Py_None);
  p->args = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5event_event(PyObject *o) {
  struct __pyx_obj_5event_event *p = (struct __pyx_obj_5event_event *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_5event_5event___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(p->handle);
  Py_XDECREF(p->evtype);
  Py_XDECREF(p->callback);
  Py_XDECREF(p->args);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5event_event(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5event_event *p = (struct __pyx_obj_5event_event *)o;
  if (p->handle) {
    e = (*v)(p->handle, a); if (e) return e;
  }
  if (p->evtype) {
    e = (*v)(p->evtype, a); if (e) return e;
  }
  if (p->callback) {
    e = (*v)(p->callback, a); if (e) return e;
  }
  if (p->args) {
    e = (*v)(p->args, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5event_event(PyObject *o) {
  struct __pyx_obj_5event_event *p = (struct __pyx_obj_5event_event *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->handle);
  p->handle = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->evtype);
  p->evtype = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->callback);
  p->callback = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->args);
  p->args = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static struct PyMethodDef __pyx_methods_5event_event[] = {
  {__Pyx_NAMESTR("__simple_callback"), (PyCFunction)__pyx_pf_5event_5event___simple_callback, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("__callback"), (PyCFunction)__pyx_pf_5event_5event___callback, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("add"), (PyCFunction)__pyx_pf_5event_5event_add, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5event_5event_add)},
  {__Pyx_NAMESTR("pending"), (PyCFunction)__pyx_pf_5event_5event_pending, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5event_5event_pending)},
  {__Pyx_NAMESTR("delete"), (PyCFunction)__pyx_pf_5event_5event_delete, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5event_5event_delete)},
  {__Pyx_NAMESTR("__repr__"), (PyCFunction)__pyx_pf_5event_5event___repr__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_event = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_event = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_event = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_event = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_5event_event = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("event.event"), /*tp_name*/
  sizeof(struct __pyx_obj_5event_event), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5event_event, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  __pyx_pf_5event_5event___repr__, /*tp_repr*/
  &__pyx_tp_as_number_event, /*tp_as_number*/
  &__pyx_tp_as_sequence_event, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_event, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_event, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("event(callback, arg=None, evtype=0, handle=None) -> event object\n    \n    Create a new event object with a user callback.\n\n    Arguments:\n\n    callback -- user callback with (ev, handle, evtype, arg) prototype\n    arg      -- optional callback arguments\n    evtype   -- bitmask of EV_READ or EV_WRITE, or EV_SIGNAL\n    handle   -- for EV_READ or EV_WRITE, a file handle, descriptor, or socket\n                for EV_SIGNAL, a signal number\n    "), /*tp_doc*/
  __pyx_tp_traverse_5event_event, /*tp_traverse*/
  __pyx_tp_clear_5event_event, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5event_event, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_5event_5event___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5event_event, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_5event_read(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = __pyx_tp_new_5event_event(t, a, k);
  if (!o) return 0;
  return o;
}

static struct PyMethodDef __pyx_methods_5event_read[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_read = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_read = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_read = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_read = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_5event_read = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("event.read"), /*tp_name*/
  sizeof(struct __pyx_obj_5event_read), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5event_event, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_read, /*tp_as_number*/
  &__pyx_tp_as_sequence_read, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_read, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_read, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("read(handle, callback, *args) -> event object\n    \n    Simplified event interface:\n    Create a new read event, and add it to the event queue.\n    \n    Arguments:\n\n    handle   -- file handle, descriptor, or socket\n    callback -- user callback with (*args) prototype, which can return\n                a non-None value to be rescheduled\n    *args    -- optional callback arguments\n    "), /*tp_doc*/
  __pyx_tp_traverse_5event_event, /*tp_traverse*/
  __pyx_tp_clear_5event_event, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5event_read, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_5event_4read___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5event_read, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_5event_write(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = __pyx_tp_new_5event_event(t, a, k);
  if (!o) return 0;
  return o;
}

static struct PyMethodDef __pyx_methods_5event_write[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_write = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_write = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_write = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_write = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_5event_write = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("event.write"), /*tp_name*/
  sizeof(struct __pyx_obj_5event_write), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5event_event, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_write, /*tp_as_number*/
  &__pyx_tp_as_sequence_write, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_write, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_write, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("write(handle, callback, *args) -> event object\n\n    Simplified event interface:\n    Create a new write event, and add it to the event queue.\n    \n    Arguments:\n\n    handle   -- file handle, descriptor, or socket\n    callback -- user callback with (*args) prototype, which can return\n                a non-None value to be rescheduled\n    *args    -- optional callback arguments\n    "), /*tp_doc*/
  __pyx_tp_traverse_5event_event, /*tp_traverse*/
  __pyx_tp_clear_5event_event, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5event_write, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_5event_5write___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5event_write, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_5event_signal(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = __pyx_tp_new_5event_event(t, a, k);
  if (!o) return 0;
  return o;
}

static struct PyMethodDef __pyx_methods_5event_signal[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_signal = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_signal = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_signal = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_signal = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_5event_signal = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("event.signal"), /*tp_name*/
  sizeof(struct __pyx_obj_5event_signal), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5event_event, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_signal, /*tp_as_number*/
  &__pyx_tp_as_sequence_signal, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_signal, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_signal, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("signal(sig, callback, *args) -> event object\n\n    Simplified event interface:\n    Create a new signal event, and add it to the event queue.\n    XXX - persistent event is added with EV_PERSIST, like signal_set()\n    \n    Arguments:\n\n    sig      -- signal number\n    callback -- user callback with (*args) prototype, which can return\n                a non-None value to be rescheduled\n    *args    -- optional callback arguments\n    "), /*tp_doc*/
  __pyx_tp_traverse_5event_event, /*tp_traverse*/
  __pyx_tp_clear_5event_event, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5event_signal, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_5event_6signal___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5event_signal, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_5event_timeout(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = __pyx_tp_new_5event_event(t, a, k);
  if (!o) return 0;
  return o;
}

static struct PyMethodDef __pyx_methods_5event_timeout[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_timeout = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_timeout = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_timeout = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_timeout = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_5event_timeout = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("event.timeout"), /*tp_name*/
  sizeof(struct __pyx_obj_5event_timeout), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5event_event, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_timeout, /*tp_as_number*/
  &__pyx_tp_as_sequence_timeout, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_timeout, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_timeout, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("timeout(secs, callback, *args) -> event object\n\n    Simplified event interface:\n    Create a new timer event, and add it to the event queue.\n\n    Arguments:\n\n    secs     -- event timeout in seconds\n    callback -- user callback with (*args) prototype, which can return\n                a non-None value to be rescheduled\n    *args    -- optional callback arguments\n    "), /*tp_doc*/
  __pyx_tp_traverse_5event_event, /*tp_traverse*/
  __pyx_tp_clear_5event_event, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5event_timeout, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_5event_7timeout___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5event_timeout, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_5event_bufferevent(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5event_bufferevent *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_5event_bufferevent *)o);
  p->handle = Py_None; Py_INCREF(Py_None);
  p->readcb = Py_None; Py_INCREF(Py_None);
  p->writecb = Py_None; Py_INCREF(Py_None);
  p->errorcb = Py_None; Py_INCREF(Py_None);
  p->args = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5event_bufferevent(PyObject *o) {
  struct __pyx_obj_5event_bufferevent *p = (struct __pyx_obj_5event_bufferevent *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_5event_11bufferevent___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(p->handle);
  Py_XDECREF(p->readcb);
  Py_XDECREF(p->writecb);
  Py_XDECREF(p->errorcb);
  Py_XDECREF(p->args);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5event_bufferevent(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5event_bufferevent *p = (struct __pyx_obj_5event_bufferevent *)o;
  if (p->handle) {
    e = (*v)(p->handle, a); if (e) return e;
  }
  if (p->readcb) {
    e = (*v)(p->readcb, a); if (e) return e;
  }
  if (p->writecb) {
    e = (*v)(p->writecb, a); if (e) return e;
  }
  if (p->errorcb) {
    e = (*v)(p->errorcb, a); if (e) return e;
  }
  if (p->args) {
    e = (*v)(p->args, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5event_bufferevent(PyObject *o) {
  struct __pyx_obj_5event_bufferevent *p = (struct __pyx_obj_5event_bufferevent *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->handle);
  p->handle = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->readcb);
  p->readcb = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->writecb);
  p->writecb = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->errorcb);
  p->errorcb = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->args);
  p->args = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static struct PyMethodDef __pyx_methods_5event_bufferevent[] = {
  {__Pyx_NAMESTR("enable"), (PyCFunction)__pyx_pf_5event_11bufferevent_enable, METH_O, __Pyx_DOCSTR(__pyx_doc_5event_11bufferevent_enable)},
  {__Pyx_NAMESTR("disable"), (PyCFunction)__pyx_pf_5event_11bufferevent_disable, METH_O, __Pyx_DOCSTR(__pyx_doc_5event_11bufferevent_disable)},
  {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pf_5event_11bufferevent_read, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5event_11bufferevent_read)},
  {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pf_5event_11bufferevent_write, METH_O, __Pyx_DOCSTR(__pyx_doc_5event_11bufferevent_write)},
  {__Pyx_NAMESTR("set_timeout"), (PyCFunction)__pyx_pf_5event_11bufferevent_set_timeout, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("__repr__"), (PyCFunction)__pyx_pf_5event_11bufferevent___repr__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static struct PyMemberDef __pyx_members_5event_bufferevent[] = {
  {(char *)"handle", T_OBJECT, offsetof(struct __pyx_obj_5event_bufferevent, handle), 0, 0},
  {(char *)"readcb", T_OBJECT, offsetof(struct __pyx_obj_5event_bufferevent, readcb), 0, 0},
  {(char *)"writecb", T_OBJECT, offsetof(struct __pyx_obj_5event_bufferevent, writecb), 0, 0},
  {(char *)"errorcb", T_OBJECT, offsetof(struct __pyx_obj_5event_bufferevent, errorcb), 0, 0},
  {(char *)"args", T_OBJECT, offsetof(struct __pyx_obj_5event_bufferevent, args), 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_bufferevent = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_bufferevent = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_bufferevent = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_bufferevent = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_5event_bufferevent = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("event.bufferevent"), /*tp_name*/
  sizeof(struct __pyx_obj_5event_bufferevent), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5event_bufferevent, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  __pyx_pf_5event_11bufferevent___repr__, /*tp_repr*/
  &__pyx_tp_as_number_bufferevent, /*tp_as_number*/
  &__pyx_tp_as_sequence_bufferevent, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_bufferevent, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_bufferevent, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  __Pyx_DOCSTR("bufferevent(handle, readcb, writecb, errorcb, *args) -> bufferevent object\n\n    Create a new buffered event\n\n    Arguments:\n\n    handle   -- file handle, descriptor, or socket\n    readcb   -- callback to invoke when there is data to be read, or None\n    writecb  -- callback to invoke when ready for writing, or None\n    errorcb  -- callback to invoke on error, or None\n    *args    -- optional arguments to be passed to each of the callbacks\n    "), /*tp_doc*/
  __pyx_tp_traverse_5event_bufferevent, /*tp_traverse*/
  __pyx_tp_clear_5event_bufferevent, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5event_bufferevent, /*tp_methods*/
  __pyx_members_5event_bufferevent, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_5event_11bufferevent___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5event_bufferevent, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_5event___start_response __pyx_vtable_5event___start_response;

static PyObject *__pyx_tp_new_5event___start_response(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5event___start_response *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_5event___start_response *)o);
  p->__pyx_vtab = __pyx_vtabptr_5event___start_response;
  p->code = Py_None; Py_INCREF(Py_None);
  p->reason = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5event___start_response(PyObject *o) {
  struct __pyx_obj_5event___start_response *p = (struct __pyx_obj_5event___start_response *)o;
  Py_XDECREF(p->code);
  Py_XDECREF(p->reason);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5event___start_response(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5event___start_response *p = (struct __pyx_obj_5event___start_response *)o;
  if (p->code) {
    e = (*v)(p->code, a); if (e) return e;
  }
  if (p->reason) {
    e = (*v)(p->reason, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5event___start_response(PyObject *o) {
  struct __pyx_obj_5event___start_response *p = (struct __pyx_obj_5event___start_response *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->code);
  p->code = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->reason);
  p->reason = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static struct PyMethodDef __pyx_methods_5event___start_response[] = {
  {__Pyx_NAMESTR("__call__"), (PyCFunction)__pyx_pf_5event_16__start_response___call__, METH_VARARGS|METH_KEYWORDS|METH_COEXIST, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("_check_headers_sent"), (PyCFunction)__pyx_pf_5event_16__start_response__check_headers_sent, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pf_5event_16__start_response_write, METH_O, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("end"), (PyCFunction)__pyx_pf_5event_16__start_response_end, METH_NOARGS, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___start_response = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___start_response = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___start_response = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___start_response = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_5event___start_response = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("event.__start_response"), /*tp_name*/
  sizeof(struct __pyx_obj_5event___start_response), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5event___start_response, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number___start_response, /*tp_as_number*/
  &__pyx_tp_as_sequence___start_response, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___start_response, /*tp_as_mapping*/
  0, /*tp_hash*/
  __pyx_pf_5event_16__start_response___call__, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___start_response, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5event___start_response, /*tp_traverse*/
  __pyx_tp_clear_5event___start_response, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5event___start_response, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_5event_16__start_response___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5event___start_response, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};
static struct __pyx_vtabstruct_5event___wsgi_input __pyx_vtable_5event___wsgi_input;

static PyObject *__pyx_tp_new_5event___wsgi_input(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5event___wsgi_input *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_5event___wsgi_input *)o);
  p->__pyx_vtab = __pyx_vtabptr_5event___wsgi_input;
  return o;
}

static void __pyx_tp_dealloc_5event___wsgi_input(PyObject *o) {
  (*Py_TYPE(o)->tp_free)(o);
}

static struct PyMethodDef __pyx_methods_5event___wsgi_input[] = {
  {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pf_5event_12__wsgi_input_read, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("readline"), (PyCFunction)__pyx_pf_5event_12__wsgi_input_readline, METH_NOARGS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("readlines"), (PyCFunction)__pyx_pf_5event_12__wsgi_input_readlines, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___wsgi_input = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___wsgi_input = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___wsgi_input = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___wsgi_input = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_5event___wsgi_input = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("event.__wsgi_input"), /*tp_name*/
  sizeof(struct __pyx_obj_5event___wsgi_input), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5event___wsgi_input, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number___wsgi_input, /*tp_as_number*/
  &__pyx_tp_as_sequence___wsgi_input, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___wsgi_input, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___wsgi_input, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  0, /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5event___wsgi_input, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5event___wsgi_input, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_5event_wsgi(PyTypeObject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  return o;
}

static void __pyx_tp_dealloc_5event_wsgi(PyObject *o) {
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pf_5event_4wsgi___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static struct PyMethodDef __pyx_methods_5event_wsgi[] = {
  {__Pyx_NAMESTR("register_app"), (PyCFunction)__pyx_pf_5event_4wsgi_register_app, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5event_4wsgi_register_app)},
  {__Pyx_NAMESTR("register_default_app"), (PyCFunction)__pyx_pf_5event_4wsgi_register_default_app, METH_O, __Pyx_DOCSTR(__pyx_doc_5event_4wsgi_register_default_app)},
  {__Pyx_NAMESTR("unregister_app"), (PyCFunction)__pyx_pf_5event_4wsgi_unregister_app, METH_O, __Pyx_DOCSTR(__pyx_doc_5event_4wsgi_unregister_app)},
  {__Pyx_NAMESTR("run"), (PyCFunction)__pyx_pf_5event_4wsgi_run, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5event_4wsgi_run)},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_wsgi = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION >= 3
  0, /*reserved*/
  #else
  0, /*nb_long*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX)
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_wsgi = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_wsgi = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_wsgi = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

PyTypeObject __pyx_type_5event_wsgi = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("event.wsgi"), /*tp_name*/
  sizeof(struct __pyx_obj_5event_wsgi), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5event_wsgi, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_wsgi, /*tp_as_number*/
  &__pyx_tp_as_sequence_wsgi, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_wsgi, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_wsgi, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/
  __Pyx_DOCSTR("wsgi(address='0.0.0.0', port=80) -> WSGI server object\n\n    Create a WSGI/1.0 application server object.\n\n    Arguments:\n\n    address -- IP address to bind to (defaults to any)\n    port    -- port to listen on (defaults to 80)\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5event_wsgi, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pf_5event_4wsgi___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5event_wsgi, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static struct PyMethodDef __pyx_methods[] = {
  {__Pyx_NAMESTR("init"), (PyCFunction)__pyx_pf_5event_init, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5event_init)},
  {__Pyx_NAMESTR("dispatch"), (PyCFunction)__pyx_pf_5event_dispatch, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5event_dispatch)},
  {__Pyx_NAMESTR("loop"), (PyCFunction)__pyx_pf_5event_loop, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5event_loop)},
  {__Pyx_NAMESTR("abort"), (PyCFunction)__pyx_pf_5event_abort, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5event_abort)},
  {__Pyx_NAMESTR("dns_init"), (PyCFunction)__pyx_pf_5event_dns_init, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_5event_dns_init)},
  {__Pyx_NAMESTR("dns_resolve_ipv4"), (PyCFunction)__pyx_pf_5event_dns_resolve_ipv4, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5event_dns_resolve_ipv4)},
  {__Pyx_NAMESTR("dns_resolve_ipv6"), (PyCFunction)__pyx_pf_5event_dns_resolve_ipv6, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5event_dns_resolve_ipv6)},
  {__Pyx_NAMESTR("dns_resolve_reverse"), (PyCFunction)__pyx_pf_5event_dns_resolve_reverse, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5event_dns_resolve_reverse)},
  {__Pyx_NAMESTR("dns_resolve_reverse_ipv6"), (PyCFunction)__pyx_pf_5event_dns_resolve_reverse_ipv6, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5event_dns_resolve_reverse_ipv6)},
  {__Pyx_NAMESTR("dns_shutdown"), (PyCFunction)__pyx_pf_5event_dns_shutdown, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_5event_dns_shutdown)},
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("event"),
    __Pyx_DOCSTR(__pyx_k_19), /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0},
  {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0},
  {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0},
  {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0},
  {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0},
  {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0},
  {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0},
  {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0},
  {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0},
  {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0},
  {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0},
  {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0},
  {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0},
  {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0},
  {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0},
  {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0},
  {&__pyx_n_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 1},
  {&__pyx_kp_u_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 1, 0, 0},
  {&__pyx_kp_u_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 1, 0, 0},
  {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0},
  {&__pyx_kp_u_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 1, 0, 0},
  {&__pyx_kp_u_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 1, 0, 0},
  {&__pyx_kp_u_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 1, 0, 0},
  {&__pyx_kp_u_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 1, 0, 0},
  {&__pyx_kp_u_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 1, 0, 0},
  {&__pyx_kp_u_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 1, 0, 0},
  {&__pyx_kp_u_36, __pyx_k_36, sizeof(__pyx_k_36), 0, 1, 0, 0},
  {&__pyx_kp_u_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 1, 0, 0},
  {&__pyx_kp_u_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 1, 0, 0},
  {&__pyx_kp_u_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 1, 0, 0},
  {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0},
  {&__pyx_kp_u_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 1, 0, 0},
  {&__pyx_kp_u_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 1, 0, 0},
  {&__pyx_kp_u_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 1, 0, 0},
  {&__pyx_kp_u_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 1, 0, 0},
  {&__pyx_n_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 1},
  {&__pyx_kp_u_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 1, 0, 0},
  {&__pyx_kp_u_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 1, 0, 0},
  {&__pyx_kp_u_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 1, 0, 0},
  {&__pyx_n_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 1},
  {&__pyx_kp_u_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 1, 0, 0},
  {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0},
  {&__pyx_kp_u_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 1, 0, 0},
  {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0},
  {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0},
  {&__pyx_kp_s__80, __pyx_k__80, sizeof(__pyx_k__80), 0, 0, 1, 0},
  {&__pyx_n_s__AssertionError, __pyx_k__AssertionError, sizeof(__pyx_k__AssertionError), 0, 0, 1, 1},
  {&__pyx_n_s__BSD, __pyx_k__BSD, sizeof(__pyx_k__BSD), 0, 0, 1, 1},
  {&__pyx_n_s__CONTENT_LENGTH, __pyx_k__CONTENT_LENGTH, sizeof(__pyx_k__CONTENT_LENGTH), 0, 0, 1, 1},
  {&__pyx_n_s__CONTENT_TYPE, __pyx_k__CONTENT_TYPE, sizeof(__pyx_k__CONTENT_TYPE), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_ERR_FORMAT, __pyx_k__DNS_ERR_FORMAT, sizeof(__pyx_k__DNS_ERR_FORMAT), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_ERR_NONE, __pyx_k__DNS_ERR_NONE, sizeof(__pyx_k__DNS_ERR_NONE), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_ERR_NOTEXIST, __pyx_k__DNS_ERR_NOTEXIST, sizeof(__pyx_k__DNS_ERR_NOTEXIST), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_ERR_NOTIMPL, __pyx_k__DNS_ERR_NOTIMPL, sizeof(__pyx_k__DNS_ERR_NOTIMPL), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_ERR_REFUSED, __pyx_k__DNS_ERR_REFUSED, sizeof(__pyx_k__DNS_ERR_REFUSED), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_ERR_SHUTDOWN, __pyx_k__DNS_ERR_SHUTDOWN, sizeof(__pyx_k__DNS_ERR_SHUTDOWN), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_ERR_TIMEOUT, __pyx_k__DNS_ERR_TIMEOUT, sizeof(__pyx_k__DNS_ERR_TIMEOUT), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_ERR_TRUNCATED, __pyx_k__DNS_ERR_TRUNCATED, sizeof(__pyx_k__DNS_ERR_TRUNCATED), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_ERR_UNKNOWN, __pyx_k__DNS_ERR_UNKNOWN, sizeof(__pyx_k__DNS_ERR_UNKNOWN), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_IPv4_A, __pyx_k__DNS_IPv4_A, sizeof(__pyx_k__DNS_IPv4_A), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_IPv6_AAAA, __pyx_k__DNS_IPv6_AAAA, sizeof(__pyx_k__DNS_IPv6_AAAA), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_PTR, __pyx_k__DNS_PTR, sizeof(__pyx_k__DNS_PTR), 0, 0, 1, 1},
  {&__pyx_n_s__DNS_QUERY_NO_SEARCH, __pyx_k__DNS_QUERY_NO_SEARCH, sizeof(__pyx_k__DNS_QUERY_NO_SEARCH), 0, 0, 1, 1},
  {&__pyx_n_s__EVBUFFER_EOF, __pyx_k__EVBUFFER_EOF, sizeof(__pyx_k__EVBUFFER_EOF), 0, 0, 1, 1},
  {&__pyx_n_s__EVBUFFER_ERROR, __pyx_k__EVBUFFER_ERROR, sizeof(__pyx_k__EVBUFFER_ERROR), 0, 0, 1, 1},
  {&__pyx_n_s__EVBUFFER_READ, __pyx_k__EVBUFFER_READ, sizeof(__pyx_k__EVBUFFER_READ), 0, 0, 1, 1},
  {&__pyx_n_s__EVBUFFER_TIMEOUT, __pyx_k__EVBUFFER_TIMEOUT, sizeof(__pyx_k__EVBUFFER_TIMEOUT), 0, 0, 1, 1},
  {&__pyx_n_s__EVBUFFER_WRITE, __pyx_k__EVBUFFER_WRITE, sizeof(__pyx_k__EVBUFFER_WRITE), 0, 0, 1, 1},
  {&__pyx_n_s__EVHTTP_REQUEST, __pyx_k__EVHTTP_REQUEST, sizeof(__pyx_k__EVHTTP_REQUEST), 0, 0, 1, 1},
  {&__pyx_n_s__EVHTTP_REQ_GET, __pyx_k__EVHTTP_REQ_GET, sizeof(__pyx_k__EVHTTP_REQ_GET), 0, 0, 1, 1},
  {&__pyx_n_s__EVHTTP_REQ_HEAD, __pyx_k__EVHTTP_REQ_HEAD, sizeof(__pyx_k__EVHTTP_REQ_HEAD), 0, 0, 1, 1},
  {&__pyx_n_s__EVHTTP_REQ_POST, __pyx_k__EVHTTP_REQ_POST, sizeof(__pyx_k__EVHTTP_REQ_POST), 0, 0, 1, 1},
  {&__pyx_n_s__EVHTTP_RESPONSE, __pyx_k__EVHTTP_RESPONSE, sizeof(__pyx_k__EVHTTP_RESPONSE), 0, 0, 1, 1},
  {&__pyx_n_s__EV_PERSIST, __pyx_k__EV_PERSIST, sizeof(__pyx_k__EV_PERSIST), 0, 0, 1, 1},
  {&__pyx_n_s__EV_READ, __pyx_k__EV_READ, sizeof(__pyx_k__EV_READ), 0, 0, 1, 1},
  {&__pyx_n_s__EV_SIGNAL, __pyx_k__EV_SIGNAL, sizeof(__pyx_k__EV_SIGNAL), 0, 0, 1, 1},
  {&__pyx_n_s__EV_TIMEOUT, __pyx_k__EV_TIMEOUT, sizeof(__pyx_k__EV_TIMEOUT), 0, 0, 1, 1},
  {&__pyx_n_s__EV_WRITE, __pyx_k__EV_WRITE, sizeof(__pyx_k__EV_WRITE), 0, 0, 1, 1},
  {&__pyx_n_s__GET, __pyx_k__GET, sizeof(__pyx_k__GET), 0, 0, 1, 1},
  {&__pyx_n_s__HEAD, __pyx_k__HEAD, sizeof(__pyx_k__HEAD), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_BADREQUEST, __pyx_k__HTTP_BADREQUEST, sizeof(__pyx_k__HTTP_BADREQUEST), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_MOVEPERM, __pyx_k__HTTP_MOVEPERM, sizeof(__pyx_k__HTTP_MOVEPERM), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_MOVETEMP, __pyx_k__HTTP_MOVETEMP, sizeof(__pyx_k__HTTP_MOVETEMP), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_NOCONTENT, __pyx_k__HTTP_NOCONTENT, sizeof(__pyx_k__HTTP_NOCONTENT), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_NOTFOUND, __pyx_k__HTTP_NOTFOUND, sizeof(__pyx_k__HTTP_NOTFOUND), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_NOTMODIFIED, __pyx_k__HTTP_NOTMODIFIED, sizeof(__pyx_k__HTTP_NOTMODIFIED), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_OK, __pyx_k__HTTP_OK, sizeof(__pyx_k__HTTP_OK), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_SERVUNAVAIL, __pyx_k__HTTP_SERVUNAVAIL, sizeof(__pyx_k__HTTP_SERVUNAVAIL), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_method2name, __pyx_k__HTTP_method2name, sizeof(__pyx_k__HTTP_method2name), 0, 0, 1, 1},
  {&__pyx_n_s__HTTP_name2method, __pyx_k__HTTP_name2method, sizeof(__pyx_k__HTTP_name2method), 0, 0, 1, 1},
  {&__pyx_n_s__OSError, __pyx_k__OSError, sizeof(__pyx_k__OSError), 0, 0, 1, 1},
  {&__pyx_n_s__PATH_INFO, __pyx_k__PATH_INFO, sizeof(__pyx_k__PATH_INFO), 0, 0, 1, 1},
  {&__pyx_n_s__POST, __pyx_k__POST, sizeof(__pyx_k__POST), 0, 0, 1, 1},
  {&__pyx_n_s__QUERY_STRING, __pyx_k__QUERY_STRING, sizeof(__pyx_k__QUERY_STRING), 0, 0, 1, 1},
  {&__pyx_n_s__REMOTE_ADDR, __pyx_k__REMOTE_ADDR, sizeof(__pyx_k__REMOTE_ADDR), 0, 0, 1, 1},
  {&__pyx_n_s__REMOTE_HOST, __pyx_k__REMOTE_HOST, sizeof(__pyx_k__REMOTE_HOST), 0, 0, 1, 1},
  {&__pyx_n_s__REMOTE_PORT, __pyx_k__REMOTE_PORT, sizeof(__pyx_k__REMOTE_PORT), 0, 0, 1, 1},
  {&__pyx_n_s__REQUEST_METHOD, __pyx_k__REQUEST_METHOD, sizeof(__pyx_k__REQUEST_METHOD), 0, 0, 1, 1},
  {&__pyx_n_s__SCRIPT_NAME, __pyx_k__SCRIPT_NAME, sizeof(__pyx_k__SCRIPT_NAME), 0, 0, 1, 1},
  {&__pyx_n_s__SERVER_NAME, __pyx_k__SERVER_NAME, sizeof(__pyx_k__SERVER_NAME), 0, 0, 1, 1},
  {&__pyx_n_s__SERVER_PORT, __pyx_k__SERVER_PORT, sizeof(__pyx_k__SERVER_PORT), 0, 0, 1, 1},
  {&__pyx_n_s__SERVER_PROTOCOL, __pyx_k__SERVER_PROTOCOL, sizeof(__pyx_k__SERVER_PROTOCOL), 0, 0, 1, 1},
  {&__pyx_n_s__SIGINT, __pyx_k__SIGINT, sizeof(__pyx_k__SIGINT), 0, 0, 1, 1},
  {&__pyx_n_s__SIGTERM, __pyx_k__SIGTERM, sizeof(__pyx_k__SIGTERM), 0, 0, 1, 1},
  {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1},
  {&__pyx_n_s____author__, __pyx_k____author__, sizeof(__pyx_k____author__), 0, 0, 1, 1},
  {&__pyx_n_s____callback, __pyx_k____callback, sizeof(__pyx_k____callback), 0, 0, 1, 1},
  {&__pyx_n_s____copyright__, __pyx_k____copyright__, sizeof(__pyx_k____copyright__), 0, 0, 1, 1},
  {&__pyx_n_s____evdns_cbargs, __pyx_k____evdns_cbargs, sizeof(__pyx_k____evdns_cbargs), 0, 0, 1, 1},
  {&__pyx_n_s____event_exc, __pyx_k____event_exc, sizeof(__pyx_k____event_exc), 0, 0, 1, 1},
  {&__pyx_n_s____init__, __pyx_k____init__, sizeof(__pyx_k____init__), 0, 0, 1, 1},
  {&__pyx_n_s____license__, __pyx_k____license__, sizeof(__pyx_k____license__), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____simple_callback, __pyx_k____simple_callback, sizeof(__pyx_k____simple_callback), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s____url__, __pyx_k____url__, sizeof(__pyx_k____url__), 0, 0, 1, 1},
  {&__pyx_n_s____version__, __pyx_k____version__, sizeof(__pyx_k____version__), 0, 0, 1, 1},
  {&__pyx_n_s___buf, __pyx_k___buf, sizeof(__pyx_k___buf), 0, 0, 1, 1},
  {&__pyx_n_s___check_headers_sent, __pyx_k___check_headers_sent, sizeof(__pyx_k___check_headers_sent), 0, 0, 1, 1},
  {&__pyx_n_s___http, __pyx_k___http, sizeof(__pyx_k___http), 0, 0, 1, 1},
  {&__pyx_n_s___set_buf, __pyx_k___set_buf, sizeof(__pyx_k___set_buf), 0, 0, 1, 1},
  {&__pyx_n_s___set_req, __pyx_k___set_req, sizeof(__pyx_k___set_req), 0, 0, 1, 1},
  {&__pyx_n_s__abort, __pyx_k__abort, sizeof(__pyx_k__abort), 0, 0, 1, 1},
  {&__pyx_n_s__add, __pyx_k__add, sizeof(__pyx_k__add), 0, 0, 1, 1},
  {&__pyx_n_s__address, __pyx_k__address, sizeof(__pyx_k__address), 0, 0, 1, 1},
  {&__pyx_n_s__app, __pyx_k__app, sizeof(__pyx_k__app), 0, 0, 1, 1},
  {&__pyx_n_s__arg, __pyx_k__arg, sizeof(__pyx_k__arg), 0, 0, 1, 1},
  {&__pyx_n_s__args, __pyx_k__args, sizeof(__pyx_k__args), 0, 0, 1, 1},
  {&__pyx_n_s__bind, __pyx_k__bind, sizeof(__pyx_k__bind), 0, 0, 1, 1},
  {&__pyx_n_s__buf, __pyx_k__buf, sizeof(__pyx_k__buf), 0, 0, 1, 1},
  {&__pyx_n_s__bufev, __pyx_k__bufev, sizeof(__pyx_k__bufev), 0, 0, 1, 1},
  {&__pyx_n_s__bufferevent, __pyx_k__bufferevent, sizeof(__pyx_k__bufferevent), 0, 0, 1, 1},
  {&__pyx_n_s__callback, __pyx_k__callback, sizeof(__pyx_k__callback), 0, 0, 1, 1},
  {&__pyx_n_s__clear, __pyx_k__clear, sizeof(__pyx_k__clear), 0, 0, 1, 1},
  {&__pyx_n_s__code, __pyx_k__code, sizeof(__pyx_k__code), 0, 0, 1, 1},
  {&__pyx_n_s__delete, __pyx_k__delete, sizeof(__pyx_k__delete), 0, 0, 1, 1},
  {&__pyx_n_s__disable, __pyx_k__disable, sizeof(__pyx_k__disable), 0, 0, 1, 1},
  {&__pyx_n_s__dispatch, __pyx_k__dispatch, sizeof(__pyx_k__dispatch), 0, 0, 1, 1},
  {&__pyx_n_s__dns_init, __pyx_k__dns_init, sizeof(__pyx_k__dns_init), 0, 0, 1, 1},
  {&__pyx_n_s__dns_resolve_ipv4, __pyx_k__dns_resolve_ipv4, sizeof(__pyx_k__dns_resolve_ipv4), 0, 0, 1, 1},
  {&__pyx_n_s__dns_resolve_ipv6, __pyx_k__dns_resolve_ipv6, sizeof(__pyx_k__dns_resolve_ipv6), 0, 0, 1, 1},
  {&__pyx_n_s__dns_resolve_reverse, __pyx_k__dns_resolve_reverse, sizeof(__pyx_k__dns_resolve_reverse), 0, 0, 1, 1},
  {&__pyx_n_s__dns_shutdown, __pyx_k__dns_shutdown, sizeof(__pyx_k__dns_shutdown), 0, 0, 1, 1},
  {&__pyx_n_s__enable, __pyx_k__enable, sizeof(__pyx_k__enable), 0, 0, 1, 1},
  {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1},
  {&__pyx_n_s__errorcb, __pyx_k__errorcb, sizeof(__pyx_k__errorcb), 0, 0, 1, 1},
  {&__pyx_n_s__ev, __pyx_k__ev, sizeof(__pyx_k__ev), 0, 0, 1, 1},
  {&__pyx_n_s__ev_flags, __pyx_k__ev_flags, sizeof(__pyx_k__ev_flags), 0, 0, 1, 1},
  {&__pyx_n_s__event, __pyx_k__event, sizeof(__pyx_k__event), 0, 0, 1, 1},
  {&__pyx_n_s__evtype, __pyx_k__evtype, sizeof(__pyx_k__evtype), 0, 0, 1, 1},
  {&__pyx_n_s__exc_info, __pyx_k__exc_info, sizeof(__pyx_k__exc_info), 0, 0, 1, 1},
  {&__pyx_n_s__fail_requests, __pyx_k__fail_requests, sizeof(__pyx_k__fail_requests), 0, 0, 1, 1},
  {&__pyx_n_s__fileno, __pyx_k__fileno, sizeof(__pyx_k__fileno), 0, 0, 1, 1},
  {&__pyx_n_s__flags, __pyx_k__flags, sizeof(__pyx_k__flags), 0, 0, 1, 1},
  {&__pyx_n_s__handle, __pyx_k__handle, sizeof(__pyx_k__handle), 0, 0, 1, 1},
  {&__pyx_n_s__headers, __pyx_k__headers, sizeof(__pyx_k__headers), 0, 0, 1, 1},
  {&__pyx_n_s__headers_sent, __pyx_k__headers_sent, sizeof(__pyx_k__headers_sent), 0, 0, 1, 1},
  {&__pyx_n_s__hint, __pyx_k__hint, sizeof(__pyx_k__hint), 0, 0, 1, 1},
  {&__pyx_n_s__http, __pyx_k__http, sizeof(__pyx_k__http), 0, 0, 1, 1},
  {&__pyx_n_s__id, __pyx_k__id, sizeof(__pyx_k__id), 0, 0, 1, 1},
  {&__pyx_n_s__init, __pyx_k__init, sizeof(__pyx_k__init), 0, 0, 1, 1},
  {&__pyx_n_s__input, __pyx_k__input, sizeof(__pyx_k__input), 0, 0, 1, 1},
  {&__pyx_n_s__input_buffer, __pyx_k__input_buffer, sizeof(__pyx_k__input_buffer), 0, 0, 1, 1},
  {&__pyx_n_s__input_headers, __pyx_k__input_headers, sizeof(__pyx_k__input_headers), 0, 0, 1, 1},
  {&__pyx_n_s__ip, __pyx_k__ip, sizeof(__pyx_k__ip), 0, 0, 1, 1},
  {&__pyx_n_s__loop, __pyx_k__loop, sizeof(__pyx_k__loop), 0, 0, 1, 1},
  {&__pyx_n_s__major, __pyx_k__major, sizeof(__pyx_k__major), 0, 0, 1, 1},
  {&__pyx_n_s__min, __pyx_k__min, sizeof(__pyx_k__min), 0, 0, 1, 1},
  {&__pyx_n_s__minor, __pyx_k__minor, sizeof(__pyx_k__minor), 0, 0, 1, 1},
  {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1},
  {&__pyx_n_s__nonblock, __pyx_k__nonblock, sizeof(__pyx_k__nonblock), 0, 0, 1, 1},
  {&__pyx_n_s__off, __pyx_k__off, sizeof(__pyx_k__off), 0, 0, 1, 1},
  {&__pyx_n_s__output_headers, __pyx_k__output_headers, sizeof(__pyx_k__output_headers), 0, 0, 1, 1},
  {&__pyx_n_s__path, __pyx_k__path, sizeof(__pyx_k__path), 0, 0, 1, 1},
  {&__pyx_n_s__pending, __pyx_k__pending, sizeof(__pyx_k__pending), 0, 0, 1, 1},
  {&__pyx_n_s__port, __pyx_k__port, sizeof(__pyx_k__port), 0, 0, 1, 1},
  {&__pyx_n_s__read, __pyx_k__read, sizeof(__pyx_k__read), 0, 0, 1, 1},
  {&__pyx_n_s__read_secs, __pyx_k__read_secs, sizeof(__pyx_k__read_secs), 0, 0, 1, 1},
  {&__pyx_n_s__readcb, __pyx_k__readcb, sizeof(__pyx_k__readcb), 0, 0, 1, 1},
  {&__pyx_n_s__reason, __pyx_k__reason, sizeof(__pyx_k__reason), 0, 0, 1, 1},
  {&__pyx_n_s__register_app, __pyx_k__register_app, sizeof(__pyx_k__register_app), 0, 0, 1, 1},
  {&__pyx_n_s__remote_host, __pyx_k__remote_host, sizeof(__pyx_k__remote_host), 0, 0, 1, 1},
  {&__pyx_n_s__remote_port, __pyx_k__remote_port, sizeof(__pyx_k__remote_port), 0, 0, 1, 1},
  {&__pyx_n_s__req, __pyx_k__req, sizeof(__pyx_k__req), 0, 0, 1, 1},
  {&__pyx_n_s__run, __pyx_k__run, sizeof(__pyx_k__run), 0, 0, 1, 1},
  {&__pyx_n_s__secs, __pyx_k__secs, sizeof(__pyx_k__secs), 0, 0, 1, 1},
  {&__pyx_n_s__sig, __pyx_k__sig, sizeof(__pyx_k__sig), 0, 0, 1, 1},
  {&__pyx_n_s__signal, __pyx_k__signal, sizeof(__pyx_k__signal), 0, 0, 1, 1},
  {&__pyx_n_s__simple, __pyx_k__simple, sizeof(__pyx_k__simple), 0, 0, 1, 1},
  {&__pyx_n_s__size, __pyx_k__size, sizeof(__pyx_k__size), 0, 0, 1, 1},
  {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1},
  {&__pyx_n_s__splitlines, __pyx_k__splitlines, sizeof(__pyx_k__splitlines), 0, 0, 1, 1},
  {&__pyx_n_s__status, __pyx_k__status, sizeof(__pyx_k__status), 0, 0, 1, 1},
  {&__pyx_n_s__stderr, __pyx_k__stderr, sizeof(__pyx_k__stderr), 0, 0, 1, 1},
  {&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
  {&__pyx_n_s__timeout, __pyx_k__timeout, sizeof(__pyx_k__timeout), 0, 0, 1, 1},
  {&__pyx_n_s__tv, __pyx_k__tv, sizeof(__pyx_k__tv), 0, 0, 1, 1},
  {&__pyx_n_s__tv_sec, __pyx_k__tv_sec, sizeof(__pyx_k__tv_sec), 0, 0, 1, 1},
  {&__pyx_n_s__tv_usec, __pyx_k__tv_usec, sizeof(__pyx_k__tv_usec), 0, 0, 1, 1},
  {&__pyx_n_s__type, __pyx_k__type, sizeof(__pyx_k__type), 0, 0, 1, 1},
  {&__pyx_n_s__unregister_app, __pyx_k__unregister_app, sizeof(__pyx_k__unregister_app), 0, 0, 1, 1},
  {&__pyx_n_s__uri, __pyx_k__uri, sizeof(__pyx_k__uri), 0, 0, 1, 1},
  {&__pyx_n_s__write, __pyx_k__write, sizeof(__pyx_k__write), 0, 0, 1, 1},
  {&__pyx_n_s__write_secs, __pyx_k__write_secs, sizeof(__pyx_k__write_secs), 0, 0, 1, 1},
  {&__pyx_n_s__writecb, __pyx_k__writecb, sizeof(__pyx_k__writecb), 0, 0, 1, 1},
  {&__pyx_n_s__wsgi, __pyx_k__wsgi, sizeof(__pyx_k__wsgi), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_min = __Pyx_GetName(__pyx_b, __pyx_n_s__min); if (!__pyx_builtin_min) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_id = __Pyx_GetName(__pyx_b, __pyx_n_s__id); if (!__pyx_builtin_id) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_AssertionError = __Pyx_GetName(__pyx_b, __pyx_n_s__AssertionError); if (!__pyx_builtin_AssertionError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_OSError = __Pyx_GetName(__pyx_b, __pyx_n_s__OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_65 = PyInt_FromLong(65); if (unlikely(!__pyx_int_65)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_66 = PyInt_FromLong(66); if (unlikely(!__pyx_int_66)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_67 = PyInt_FromLong(67); if (unlikely(!__pyx_int_67)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_68 = PyInt_FromLong(68); if (unlikely(!__pyx_int_68)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_80 = PyInt_FromLong(80); if (unlikely(!__pyx_int_80)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_200 = PyInt_FromLong(200); if (unlikely(!__pyx_int_200)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_204 = PyInt_FromLong(204); if (unlikely(!__pyx_int_204)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_301 = PyInt_FromLong(301); if (unlikely(!__pyx_int_301)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_302 = PyInt_FromLong(302); if (unlikely(!__pyx_int_302)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_304 = PyInt_FromLong(304); if (unlikely(!__pyx_int_304)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_400 = PyInt_FromLong(400); if (unlikely(!__pyx_int_400)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_404 = PyInt_FromLong(404); if (unlikely(!__pyx_int_404)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_503 = PyInt_FromLong(503); if (unlikely(!__pyx_int_503)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x01 = PyInt_FromLong(0x01); if (unlikely(!__pyx_int_0x01)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x02 = PyInt_FromLong(0x02); if (unlikely(!__pyx_int_0x02)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x04 = PyInt_FromLong(0x04); if (unlikely(!__pyx_int_0x04)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x08 = PyInt_FromLong(0x08); if (unlikely(!__pyx_int_0x08)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x10 = PyInt_FromLong(0x10); if (unlikely(!__pyx_int_0x10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x20 = PyInt_FromLong(0x20); if (unlikely(!__pyx_int_0x20)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0x40 = PyInt_FromLong(0x40); if (unlikely(!__pyx_int_0x40)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initevent(void); /*proto*/
PyMODINIT_FUNC initevent(void)
#else
PyMODINIT_FUNC PyInit_event(void); /*proto*/
PyMODINIT_FUNC PyInit_event(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  #if CYTHON_REFNANNY
  void* __pyx_refnanny = NULL;
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  __pyx_refnanny = __Pyx_RefNanny->SetupContext("PyMODINIT_FUNC PyInit_event(void)", __LINE__, __FILE__);
  #endif
  __pyx_init_filenames();
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION < 3
  __pyx_empty_bytes = PyString_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #else
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("event"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_19), 0, PYTHON_API_VERSION);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (!__pyx_m) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  #if PY_MAJOR_VERSION < 3
  Py_INCREF(__pyx_m);
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME));
  if (!__pyx_b) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_event) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  if (PyType_Ready(&__pyx_type_5event_event) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "event", (PyObject *)&__pyx_type_5event_event) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5event_event = &__pyx_type_5event_event;
  __pyx_type_5event_read.tp_base = __pyx_ptype_5event_event;
  if (PyType_Ready(&__pyx_type_5event_read) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "read", (PyObject *)&__pyx_type_5event_read) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5event_read = &__pyx_type_5event_read;
  __pyx_type_5event_write.tp_base = __pyx_ptype_5event_event;
  if (PyType_Ready(&__pyx_type_5event_write) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "write", (PyObject *)&__pyx_type_5event_write) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5event_write = &__pyx_type_5event_write;
  __pyx_type_5event_signal.tp_base = __pyx_ptype_5event_event;
  if (PyType_Ready(&__pyx_type_5event_signal) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "signal", (PyObject *)&__pyx_type_5event_signal) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5event_signal = &__pyx_type_5event_signal;
  __pyx_type_5event_timeout.tp_base = __pyx_ptype_5event_event;
  if (PyType_Ready(&__pyx_type_5event_timeout) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "timeout", (PyObject *)&__pyx_type_5event_timeout) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5event_timeout = &__pyx_type_5event_timeout;
  if (PyType_Ready(&__pyx_type_5event_bufferevent) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "bufferevent", (PyObject *)&__pyx_type_5event_bufferevent) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5event_bufferevent = &__pyx_type_5event_bufferevent;
  __pyx_vtabptr_5event___start_response = &__pyx_vtable_5event___start_response;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_5event___start_response._set_req = (void (*)(struct __pyx_obj_5event___start_response *, struct evhttp_request *))__pyx_f_5event_16__start_response__set_req;
  #else
  *(void(**)(void))&__pyx_vtable_5event___start_response._set_req = (void(*)(void))__pyx_f_5event_16__start_response__set_req;
  #endif
  if (PyType_Ready(&__pyx_type_5event___start_response) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_5event___start_response.tp_dict, __pyx_vtabptr_5event___start_response) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "__start_response", (PyObject *)&__pyx_type_5event___start_response) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5event___start_response = &__pyx_type_5event___start_response;
  __pyx_vtabptr_5event___wsgi_input = &__pyx_vtable_5event___wsgi_input;
  #if PY_MAJOR_VERSION >= 3
  __pyx_vtable_5event___wsgi_input._set_buf = (void (*)(struct __pyx_obj_5event___wsgi_input *, struct evbuffer *))__pyx_f_5event_12__wsgi_input__set_buf;
  #else
  *(void(**)(void))&__pyx_vtable_5event___wsgi_input._set_buf = (void(*)(void))__pyx_f_5event_12__wsgi_input__set_buf;
  #endif
  if (PyType_Ready(&__pyx_type_5event___wsgi_input) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetVtable(__pyx_type_5event___wsgi_input.tp_dict, __pyx_vtabptr_5event___wsgi_input) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "__wsgi_input", (PyObject *)&__pyx_type_5event___wsgi_input) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5event___wsgi_input = &__pyx_type_5event___wsgi_input;
  if (PyType_Ready(&__pyx_type_5event_wsgi) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_SetAttrString(__pyx_m, "wsgi", (PyObject *)&__pyx_type_5event_wsgi) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5event_wsgi = &__pyx_type_5event_wsgi;
  /*--- Type import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "event.pyx":18
 * """
 * 
 * __author__ = ( 'Dug Song <dugsong@monkey.org>',             # <<<<<<<<<<<<<<
 *                'Martin Murray <mmurray@monkey.org>',
 *                'Aaron Westendorf <aaron@agoragames.com>' )
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_20));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_20));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_20));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_21));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_kp_s_21));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_21));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_kp_s_22));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____author__, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "event.pyx":21
 *                'Martin Murray <mmurray@monkey.org>',
 *                'Aaron Westendorf <aaron@agoragames.com>' )
 * __copyright__ = ( 'Copyright (c) 2004 Dug Song',             # <<<<<<<<<<<<<<
 *                   'Copyright (c) 2003 Martin Murray' )
 * __license__ = 'BSD'
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_23));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_23));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_23));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_24));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_kp_s_24));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_24));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____copyright__, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "event.pyx":23
 * __copyright__ = ( 'Copyright (c) 2004 Dug Song',
 *                   'Copyright (c) 2003 Martin Murray' )
 * __license__ = 'BSD'             # <<<<<<<<<<<<<<
 * __url__ = 'https://github.com/agoragames/pyevent'
 * __version__ = '0.4.1'
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____license__, ((PyObject *)__pyx_n_s__BSD)) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "event.pyx":24
 *                   'Copyright (c) 2003 Martin Murray' )
 * __license__ = 'BSD'
 * __url__ = 'https://github.com/agoragames/pyevent'             # <<<<<<<<<<<<<<
 * __version__ = '0.4.1'
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____url__, ((PyObject *)__pyx_kp_s_25)) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "event.pyx":25
 * __license__ = 'BSD'
 * __url__ = 'https://github.com/agoragames/pyevent'
 * __version__ = '0.4.1'             # <<<<<<<<<<<<<<
 * 
 * import sys
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_26)) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "event.pyx":27
 * __version__ = '0.4.1'
 * 
 * import sys             # <<<<<<<<<<<<<<
 * 
 * cdef extern from "sys/types.h":
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "event.pyx":65
 *     int EVLOOP_NONBLOCK
 * 
 * EV_TIMEOUT = 0x01             # <<<<<<<<<<<<<<
 * EV_READ    = 0x02
 * EV_WRITE   = 0x04
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EV_TIMEOUT, __pyx_int_0x01) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "event.pyx":66
 * 
 * EV_TIMEOUT = 0x01
 * EV_READ    = 0x02             # <<<<<<<<<<<<<<
 * EV_WRITE   = 0x04
 * EV_SIGNAL  = 0x08
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EV_READ, __pyx_int_0x02) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "event.pyx":67
 * EV_TIMEOUT = 0x01
 * EV_READ    = 0x02
 * EV_WRITE   = 0x04             # <<<<<<<<<<<<<<
 * EV_SIGNAL  = 0x08
 * EV_PERSIST = 0x10
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EV_WRITE, __pyx_int_0x04) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "event.pyx":68
 * EV_READ    = 0x02
 * EV_WRITE   = 0x04
 * EV_SIGNAL  = 0x08             # <<<<<<<<<<<<<<
 * EV_PERSIST = 0x10
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EV_SIGNAL, __pyx_int_0x08) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "event.pyx":69
 * EV_WRITE   = 0x04
 * EV_SIGNAL  = 0x08
 * EV_PERSIST = 0x10             # <<<<<<<<<<<<<<
 * 
 * __event_exc = None
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EV_PERSIST, __pyx_int_0x10) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "event.pyx":71
 * EV_PERSIST = 0x10
 * 
 * __event_exc = None             # <<<<<<<<<<<<<<
 * 
 * cdef void __event_abort():
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____event_exc, Py_None) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "event.pyx":200
 *     return ret
 * 
 * def loop(nonblock=False):             # <<<<<<<<<<<<<<
 *     """Dispatch all pending events on queue in a single pass.
 *     Returns -1 on error, 0 on success, and 1 if no events are registered."""
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_2 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "bufferevent.pxi":28
 *     void bufferevent_settimeout(bufev_t *b, int read_secs, int write_secs)
 * 
 * EVBUFFER_READ     = 0x01             # <<<<<<<<<<<<<<
 * EVBUFFER_WRITE    = 0x02
 * EVBUFFER_EOF      = 0x10
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVBUFFER_READ, __pyx_int_0x01) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "bufferevent.pxi":29
 * 
 * EVBUFFER_READ     = 0x01
 * EVBUFFER_WRITE    = 0x02             # <<<<<<<<<<<<<<
 * EVBUFFER_EOF      = 0x10
 * EVBUFFER_ERROR    = 0x20
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVBUFFER_WRITE, __pyx_int_0x02) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "bufferevent.pxi":30
 * EVBUFFER_READ     = 0x01
 * EVBUFFER_WRITE    = 0x02
 * EVBUFFER_EOF      = 0x10             # <<<<<<<<<<<<<<
 * EVBUFFER_ERROR    = 0x20
 * EVBUFFER_TIMEOUT  = 0x40
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVBUFFER_EOF, __pyx_int_0x10) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "bufferevent.pxi":31
 * EVBUFFER_WRITE    = 0x02
 * EVBUFFER_EOF      = 0x10
 * EVBUFFER_ERROR    = 0x20             # <<<<<<<<<<<<<<
 * EVBUFFER_TIMEOUT  = 0x40
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVBUFFER_ERROR, __pyx_int_0x20) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "bufferevent.pxi":32
 * EVBUFFER_EOF      = 0x10
 * EVBUFFER_ERROR    = 0x20
 * EVBUFFER_TIMEOUT  = 0x40             # <<<<<<<<<<<<<<
 * 
 * ctypedef void (*evbuffer_handler)(bufev_t *b, void *arg)
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVBUFFER_TIMEOUT, __pyx_int_0x40) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":19
 * 
 * # Result codes
 * DNS_ERR_NONE		= 0             # <<<<<<<<<<<<<<
 * DNS_ERR_FORMAT		= 1
 * DNS_ERR_SERVERFAILED	= 2
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_ERR_NONE, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":20
 * # Result codes
 * DNS_ERR_NONE		= 0
 * DNS_ERR_FORMAT		= 1             # <<<<<<<<<<<<<<
 * DNS_ERR_SERVERFAILED	= 2
 * DNS_ERR_NOTEXIST	= 3
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_ERR_FORMAT, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":21
 * DNS_ERR_NONE		= 0
 * DNS_ERR_FORMAT		= 1
 * DNS_ERR_SERVERFAILED	= 2             # <<<<<<<<<<<<<<
 * DNS_ERR_NOTEXIST	= 3
 * DNS_ERR_NOTIMPL		= 4
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_27, __pyx_int_2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":22
 * DNS_ERR_FORMAT		= 1
 * DNS_ERR_SERVERFAILED	= 2
 * DNS_ERR_NOTEXIST	= 3             # <<<<<<<<<<<<<<
 * DNS_ERR_NOTIMPL		= 4
 * DNS_ERR_REFUSED		= 5
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_ERR_NOTEXIST, __pyx_int_3) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":23
 * DNS_ERR_SERVERFAILED	= 2
 * DNS_ERR_NOTEXIST	= 3
 * DNS_ERR_NOTIMPL		= 4             # <<<<<<<<<<<<<<
 * DNS_ERR_REFUSED		= 5
 * DNS_ERR_TRUNCATED	= 65
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_ERR_NOTIMPL, __pyx_int_4) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":24
 * DNS_ERR_NOTEXIST	= 3
 * DNS_ERR_NOTIMPL		= 4
 * DNS_ERR_REFUSED		= 5             # <<<<<<<<<<<<<<
 * DNS_ERR_TRUNCATED	= 65
 * DNS_ERR_UNKNOWN		= 66
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_ERR_REFUSED, __pyx_int_5) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":25
 * DNS_ERR_NOTIMPL		= 4
 * DNS_ERR_REFUSED		= 5
 * DNS_ERR_TRUNCATED	= 65             # <<<<<<<<<<<<<<
 * DNS_ERR_UNKNOWN		= 66
 * DNS_ERR_TIMEOUT		= 67
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_ERR_TRUNCATED, __pyx_int_65) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":26
 * DNS_ERR_REFUSED		= 5
 * DNS_ERR_TRUNCATED	= 65
 * DNS_ERR_UNKNOWN		= 66             # <<<<<<<<<<<<<<
 * DNS_ERR_TIMEOUT		= 67
 * DNS_ERR_SHUTDOWN	= 68
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_ERR_UNKNOWN, __pyx_int_66) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":27
 * DNS_ERR_TRUNCATED	= 65
 * DNS_ERR_UNKNOWN		= 66
 * DNS_ERR_TIMEOUT		= 67             # <<<<<<<<<<<<<<
 * DNS_ERR_SHUTDOWN	= 68
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_ERR_TIMEOUT, __pyx_int_67) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":28
 * DNS_ERR_UNKNOWN		= 66
 * DNS_ERR_TIMEOUT		= 67
 * DNS_ERR_SHUTDOWN	= 68             # <<<<<<<<<<<<<<
 * 
 * # Types
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_ERR_SHUTDOWN, __pyx_int_68) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":31
 * 
 * # Types
 * DNS_IPv4_A		= 1             # <<<<<<<<<<<<<<
 * DNS_PTR			= 2
 * DNS_IPv6_AAAA		= 3
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_IPv4_A, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":32
 * # Types
 * DNS_IPv4_A		= 1
 * DNS_PTR			= 2             # <<<<<<<<<<<<<<
 * DNS_IPv6_AAAA		= 3
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_PTR, __pyx_int_2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":33
 * DNS_IPv4_A		= 1
 * DNS_PTR			= 2
 * DNS_IPv6_AAAA		= 3             # <<<<<<<<<<<<<<
 * 
 * # Flags
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_IPv6_AAAA, __pyx_int_3) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":36
 * 
 * # Flags
 * DNS_QUERY_NO_SEARCH	= 1             # <<<<<<<<<<<<<<
 * 
 * __evdns_cbargs = {}
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__DNS_QUERY_NO_SEARCH, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evdns.pxi":38
 * DNS_QUERY_NO_SEARCH	= 1
 * 
 * __evdns_cbargs = {}             # <<<<<<<<<<<<<<
 * 
 * def dns_init():
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____evdns_cbargs, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "evhttp.pxi":12
 *     int	      EVBUFFER_LENGTH(evbuffer *buf)
 * 
 * HTTP_OK			= 200             # <<<<<<<<<<<<<<
 * HTTP_NOCONTENT		= 204
 * HTTP_MOVEPERM		= 301
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_OK, __pyx_int_200) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":13
 * 
 * HTTP_OK			= 200
 * HTTP_NOCONTENT		= 204             # <<<<<<<<<<<<<<
 * HTTP_MOVEPERM		= 301
 * HTTP_MOVETEMP		= 302
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_NOCONTENT, __pyx_int_204) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":14
 * HTTP_OK			= 200
 * HTTP_NOCONTENT		= 204
 * HTTP_MOVEPERM		= 301             # <<<<<<<<<<<<<<
 * HTTP_MOVETEMP		= 302
 * HTTP_NOTMODIFIED	= 304
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_MOVEPERM, __pyx_int_301) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":15
 * HTTP_NOCONTENT		= 204
 * HTTP_MOVEPERM		= 301
 * HTTP_MOVETEMP		= 302             # <<<<<<<<<<<<<<
 * HTTP_NOTMODIFIED	= 304
 * HTTP_BADREQUEST		= 400
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_MOVETEMP, __pyx_int_302) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":16
 * HTTP_MOVEPERM		= 301
 * HTTP_MOVETEMP		= 302
 * HTTP_NOTMODIFIED	= 304             # <<<<<<<<<<<<<<
 * HTTP_BADREQUEST		= 400
 * HTTP_NOTFOUND		= 404
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_NOTMODIFIED, __pyx_int_304) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":17
 * HTTP_MOVETEMP		= 302
 * HTTP_NOTMODIFIED	= 304
 * HTTP_BADREQUEST		= 400             # <<<<<<<<<<<<<<
 * HTTP_NOTFOUND		= 404
 * HTTP_SERVUNAVAIL	= 503
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_BADREQUEST, __pyx_int_400) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":18
 * HTTP_NOTMODIFIED	= 304
 * HTTP_BADREQUEST		= 400
 * HTTP_NOTFOUND		= 404             # <<<<<<<<<<<<<<
 * HTTP_SERVUNAVAIL	= 503
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_NOTFOUND, __pyx_int_404) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":19
 * HTTP_BADREQUEST		= 400
 * HTTP_NOTFOUND		= 404
 * HTTP_SERVUNAVAIL	= 503             # <<<<<<<<<<<<<<
 * 
 * EVHTTP_REQUEST		= 0
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_SERVUNAVAIL, __pyx_int_503) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":21
 * HTTP_SERVUNAVAIL	= 503
 * 
 * EVHTTP_REQUEST		= 0             # <<<<<<<<<<<<<<
 * EVHTTP_RESPONSE		= 1
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVHTTP_REQUEST, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":22
 * 
 * EVHTTP_REQUEST		= 0
 * EVHTTP_RESPONSE		= 1             # <<<<<<<<<<<<<<
 * 
 * EVHTTP_REQ_GET		= 0
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVHTTP_RESPONSE, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":24
 * EVHTTP_RESPONSE		= 1
 * 
 * EVHTTP_REQ_GET		= 0             # <<<<<<<<<<<<<<
 * EVHTTP_REQ_POST		= 1
 * EVHTTP_REQ_HEAD		= 2
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVHTTP_REQ_GET, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":25
 * 
 * EVHTTP_REQ_GET		= 0
 * EVHTTP_REQ_POST		= 1             # <<<<<<<<<<<<<<
 * EVHTTP_REQ_HEAD		= 2
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVHTTP_REQ_POST, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":26
 * EVHTTP_REQ_GET		= 0
 * EVHTTP_REQ_POST		= 1
 * EVHTTP_REQ_HEAD		= 2             # <<<<<<<<<<<<<<
 * 
 * HTTP_method2name = { 0: 'GET', 1: 'POST', 2: 'HEAD' }
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__EVHTTP_REQ_HEAD, __pyx_int_2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "evhttp.pxi":28
 * EVHTTP_REQ_HEAD		= 2
 * 
 * HTTP_method2name = { 0: 'GET', 1: 'POST', 2: 'HEAD' }             # <<<<<<<<<<<<<<
 * HTTP_name2method = { 'GET': 0, 'POST': 1, 'HEAD': 2 }
 * 
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, __pyx_int_0, ((PyObject *)__pyx_n_s__GET)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_int_1, ((PyObject *)__pyx_n_s__POST)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_int_2, ((PyObject *)__pyx_n_s__HEAD)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_method2name, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "evhttp.pxi":29
 * 
 * HTTP_method2name = { 0: 'GET', 1: 'POST', 2: 'HEAD' }
 * HTTP_name2method = { 'GET': 0, 'POST': 1, 'HEAD': 2 }             # <<<<<<<<<<<<<<
 * 
 * cdef extern from "evhttp.h":
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__GET), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__POST), __pyx_int_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__HEAD), __pyx_int_2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__HTTP_name2method, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;

  /* "event.pyx":229
 * 
 * # XXX - make sure event queue is always initialized.
 * init()             # <<<<<<<<<<<<<<
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "event.pyx":1
 * #             # <<<<<<<<<<<<<<
 * # event.pyx
 * #
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__event); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__add); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_28), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__event); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__pending); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_29), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__event); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__delete); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_30), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_1, "__doc__");
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_31), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__dispatch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_32), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__loop); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_1, "__doc__");
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_33), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__abort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_34), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__bufferevent); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__enable); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_35), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__bufferevent); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__disable); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_36), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__bufferevent); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__read); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_37), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__bufferevent); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__write); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_38), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__dns_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_1, "__doc__");
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_39), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__dns_resolve_ipv4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_40), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__dns_resolve_ipv6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_1, "__doc__");
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_41), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__dns_resolve_reverse); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_42), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s_44); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetAttrString(__pyx_t_1, "__doc__");
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_43), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_m, __pyx_n_s__dns_shutdown); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_45), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__wsgi); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__register_app); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_46), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__wsgi); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s_48); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_47), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__wsgi); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__unregister_app); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_49), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_m, __pyx_n_s__wsgi); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__run); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetAttrString(__pyx_t_3, "__doc__");
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_kp_u_50), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    __Pyx_AddTraceback("init event");
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init event");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

static const char *__pyx_filenames[] = {
  "bufferevent.pxi",
  "evdns.pxi",
  "evhttp.pxi",
  "event.pyx",
  "simple.pxi",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}


static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AS_STRING(kw_name));
        #endif
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *number, *more_or_less;

    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    number = (num_expected == 1) ? "" : "s";
    PyErr_Format(PyExc_TypeError,
        #if PY_VERSION_HEX < 0x02050000
            "%s() takes %s %d positional argument%s (%d given)",
        #else
            "%s() takes %s %zd positional argument%s (%zd given)",
        #endif
        func_name, more_or_less, num_expected, number, num_found);
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;

    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
        } else {
            #if PY_MAJOR_VERSION < 3
            if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) {
            #else
            if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) {
            #endif
                goto invalid_keyword_type;
            } else {
                for (name = first_kw_arg; *name; name++) {
                    #if PY_MAJOR_VERSION >= 3
                    if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                        PyUnicode_Compare(**name, key) == 0) break;
                    #else
                    if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                        _PyString_Eq(**name, key)) break;
                    #endif
                }
                if (*name) {
                    values[name-argnames] = value;
                } else {
                    /* unexpected keyword found */
                    for (name=argnames; name != first_kw_arg; name++) {
                        if (**name == key) goto arg_passed_twice;
                        #if PY_MAJOR_VERSION >= 3
                        if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) &&
                            PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
                        #else
                        if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
                            _PyString_Eq(**name, key)) goto arg_passed_twice;
                        #endif
                    }
                    if (kwds2) {
                        if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
                    } else {
                        goto invalid_keyword;
                    }
                }
            }
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, **name);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
    if (unlikely(tstate->curexc_type))
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
        goto bad;
    #endif
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
    Py_INCREF(local_type);
    Py_INCREF(local_value);
    Py_INCREF(local_tb);
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    /* Make sure tstate is in a consistent state when we XDECREF
       these objects (XDECREF may run arbitrary code). */
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}


static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix) {
    PyObject *r, *m, *t, *py_ix;
    if (likely(PyList_CheckExact(L))) {
        Py_ssize_t size = PyList_GET_SIZE(L);
        if (likely(size > (((PyListObject*)L)->allocated >> 1))) {
            if (ix < 0) {
                ix += size;
            }
            if (likely(0 <= ix && ix < size)) {
                Py_ssize_t i;
                PyObject* v = PyList_GET_ITEM(L, ix);
                Py_SIZE(L) -= 1;
                size -= 1;
                for(i=ix; i<size; i++) {
                    PyList_SET_ITEM(L, i, PyList_GET_ITEM(L, i+1));
                }
                return v;
            }
        }
    }
    py_ix = t = NULL;
    m = __Pyx_GetAttrString(L, "pop");
    if (!m) goto bad;
    py_ix = PyInt_FromSsize_t(ix);
    if (!py_ix) goto bad;
    t = PyTuple_New(1);
    if (!t) goto bad;
    PyTuple_SET_ITEM(t, 0, py_ix);
    py_ix = NULL;
    r = PyObject_CallObject(m, t);
    Py_DECREF(m);
    Py_DECREF(t);
    return r;
bad:
    Py_XDECREF(m);
    Py_XDECREF(t);
    Py_XDECREF(py_ix);
    return NULL;
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
        #if PY_VERSION_HEX < 0x02050000
                 "need more than %d value%s to unpack", (int)index,
        #else
                 "need more than %zd value%s to unpack", index,
        #endif
                 (index == 1) ? "" : "s");
}

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(void) {
    PyErr_SetString(PyExc_ValueError, "too many values to unpack");
}

static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) {
    PyObject *item;
    if (!(item = PyIter_Next(iter))) {
        if (!PyErr_Occurred()) {
            __Pyx_RaiseNeedMoreValuesError(index);
        }
    }
    return item;
}

static int __Pyx_EndUnpack(PyObject *iter) {
    PyObject *item;
    if ((item = PyIter_Next(iter))) {
        Py_DECREF(item);
        __Pyx_RaiseTooManyValuesError();
        return -1;
    }
    else if (!PyErr_Occurred())
        return 0;
    else
        return -1;
}


static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #else
        if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key)))
        #endif
            goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    return 0;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();

    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;

    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}


static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}

static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *__import__ = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    __import__ = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!__import__)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunctionObjArgs(__import__,
        name, global_dict, empty_dict, list, NULL);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(__import__);
    Py_XDECREF(empty_dict);
    return module;
}

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(type);
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }

    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

#else /* Python 3+ */

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;

    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (!PyExceptionClass_Check(type)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }

    PyErr_SetObject(type, value);

    if (tb) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }

bad:
    return;
}
#endif

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return PyLong_AsUnsignedLong(x);
        } else {
            return PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return PyLong_AsUnsignedLongLong(x);
        } else {
            return PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static void __Pyx_WriteUnraisable(const char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX < 0x03010000
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#else
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(const char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;

    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(__pyx_filename);
    #else
    py_srcfile = PyUnicode_FromString(__pyx_filename);
    #endif
    if (!py_srcfile) goto bad;
    if (__pyx_clineno) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        #if PY_MAJOR_VERSION >= 3
        0,            /*int kwonlyargcount,*/
        #endif
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple,  /*PyObject *consts,*/
        __pyx_empty_tuple,  /*PyObject *names,*/
        __pyx_empty_tuple,  /*PyObject *varnames,*/
        __pyx_empty_tuple,  /*PyObject *freevars,*/
        __pyx_empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

/* Type Conversion Functions */

static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   if (x == Py_True) return 1;
   else if ((x == Py_False) | (x == Py_None)) return 0;
   else return PyObject_IsTrue(x);
}

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
