Remove in-method imports from inotify

This commit is contained in:
ZyX 2014-08-16 15:00:49 +04:00
parent cb99c06027
commit 39251ce1cb
2 changed files with 5 additions and 8 deletions

View File

@ -7,6 +7,10 @@ __docformat__ = 'restructuredtext en'
import sys
import os
import errno
import ctypes
import struct
from ctypes.util import find_library
class INotifyError(Exception):
@ -28,10 +32,8 @@ def load_inotify():
raise INotifyError('INotify not available on windows')
if sys.platform == 'darwin':
raise INotifyError('INotify not available on OS X')
import ctypes
if not hasattr(ctypes, 'c_ssize_t'):
raise INotifyError('You need python >= 2.7 to use inotify')
from ctypes.util import find_library
name = find_library('c')
if not name:
raise INotifyError('Cannot find C library')
@ -107,8 +109,6 @@ class INotify(object):
NONBLOCK = 0x800
def __init__(self, cloexec=True, nonblock=True):
import ctypes
import struct
self._init1, self._add_watch, self._rm_watch, self._read = load_inotify()
flags = 0
if cloexec:
@ -130,7 +130,6 @@ class INotify(object):
self.os = os
def handle_error(self):
import ctypes
eno = ctypes.get_errno()
extra = ''
if eno == errno.ENOSPC:
@ -155,7 +154,6 @@ class INotify(object):
del self._inotify_fd
def read(self, get_name=True):
import ctypes
buf = []
while True:
num = self._read(self._inotify_fd, self._buf, len(self._buf))

View File

@ -3,6 +3,7 @@ from __future__ import unicode_literals, absolute_import
import errno
import os
import ctypes
from threading import RLock
@ -80,7 +81,6 @@ class INotifyFileWatcher(INotify):
def watch(self, path):
''' Register a watch for the file/directory named path. Raises an OSError if path
does not exist. '''
import ctypes
path = realpath(path)
with self.lock:
if path not in self.watches:
@ -212,7 +212,6 @@ class INotifyTreeWatcher(INotify):
raise NoSuchDir('The dir {0} does not exist'.format(base))
def add_watch(self, path):
import ctypes
bpath = path if isinstance(path, bytes) else path.encode(self.fenc)
wd = self._add_watch(self._inotify_fd, ctypes.c_char_p(bpath),
# Ignore symlinks and watch only directories