py3 compat

This commit is contained in:
Michael Davidsaver
2013-12-10 22:26:23 -05:00
parent 17436ceffb
commit 8a575f183e
4 changed files with 13 additions and 5 deletions

View File

@ -14,9 +14,9 @@ __all__ = [
"debugHooks",
]
hooknames = _dbapi._hooks.keys()
hooknames = list(_dbapi._hooks.keys())
_revnames = dict([(v,k) for k,v in _dbapi._hooks.iteritems()])
_revnames = dict([(v,k) for k,v in _dbapi._hooks.items()])
_hooktable = defaultdict(list)

View File

@ -211,7 +211,11 @@ static struct PyModuleDef inotifymodule = {
# define MODINIT_RET(VAL) return
#endif
#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC PyInit__inotifyy(void)
#else
PyMODINIT_FUNC init_inotifyy(void)
#endif
{
PyObject *mod = NULL;

View File

@ -42,7 +42,7 @@ class INotify(_inotifyy.INotify):
def close(self):
self.__done = True
os.write(self.__wake,'*')
os.write(self.__wake,b'*')
def add(self, callback, path, mask=IN_ALL_EVENTS):
wd = super(INotify, self).add(path, mask)

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import os.path, errno, time
import os.path, errno, time, sys
import numpy as np
@ -11,6 +11,8 @@ from devsup.hooks import addHook
from devsup.util import importmod, StoppableThread
from devsup.db import IOScanListThread
py3 = sys.version_info[0]>=3
mask=inot.IN_CREATE|inot.IN_DELETE|inot.IN_MOVED_FROM|inot.IN_MODIFY
class LogWatcher(StoppableThread):
@ -50,6 +52,8 @@ class LogWatcher(StoppableThread):
if reason is None:
return
ts, reason = reason
if py3:
reason = reason.encode('ascii')
buf = np.frombuffer(reason, dtype=self.arr.dtype)
buf = buf[:rec.NELM-1]
self.arr[:buf.size] = buf
@ -96,7 +100,7 @@ class LogWatcher(StoppableThread):
try:
self.fd = open(self.fname, 'r')
self.pos = self.fd.tell()
except IOError, e:
except IOError as e:
if e.errno==errno.ENOENT:
return
raise