r46809 - initial porting
hawkowl-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: hawkowl
Date: Tue Feb 16 21:37:11 2016
New Revision: 46809
Modified:
branches/inotify-py3-8211/twisted/internet/inotify.py
branches/inotify-py3-8211/twisted/internet/test/test_inotify.py
branches/inotify-py3-8211/twisted/python/_inotify.py
Log:
initial porting
Modified: branches/inotify-py3-8211/twisted/internet/inotify.py
==============================================================================
--- branches/inotify-py3-8211/twisted/internet/inotify.py (original)
+++ branches/inotify-py3-8211/twisted/internet/inotify.py Tue Feb 16 21:37:11 2016
@@ -29,6 +29,8 @@
@since: 10.1
"""
+from __future__ import absolute_import, division
+
import os
import struct
@@ -39,27 +41,27 @@
# from /usr/src/linux/include/linux/inotify.h
-IN_ACCESS = 0x00000001L # File was accessed
-IN_MODIFY = 0x00000002L # File was modified
-IN_ATTRIB = 0x00000004L # Metadata changed
-IN_CLOSE_WRITE = 0x00000008L # Writeable file was closed
-IN_CLOSE_NOWRITE = 0x00000010L # Unwriteable file closed
-IN_OPEN = 0x00000020L # File was opened
-IN_MOVED_FROM = 0x00000040L # File was moved from X
-IN_MOVED_TO = 0x00000080L # File was moved to Y
-IN_CREATE = 0x00000100L # Subfile was created
-IN_DELETE = 0x00000200L # Subfile was delete
-IN_DELETE_SELF = 0x00000400L # Self was deleted
-IN_MOVE_SELF = 0x00000800L # Self was moved
-IN_UNMOUNT = 0x00002000L # Backing fs was unmounted
-IN_Q_OVERFLOW = 0x00004000L # Event queued overflowed
-IN_IGNORED = 0x00008000L # File was ignored
-
-IN_ONLYDIR = 0x01000000 # only watch the path if it is a directory
-IN_DONT_FOLLOW = 0x02000000 # don't follow a sym link
-IN_MASK_ADD = 0x20000000 # add to the mask of an already existing watch
-IN_ISDIR = 0x40000000 # event occurred against dir
-IN_ONESHOT = 0x80000000 # only send event once
+IN_ACCESS = long(0x00000001) # File was accessed
+IN_MODIFY = long(0x00000002) # File was modified
+IN_ATTRIB = long(0x00000004) # Metadata changed
+IN_CLOSE_WRITE = long(0x00000008) # Writeable file was closed
+IN_CLOSE_NOWRITE = long(0x00000010) # Unwriteable file closed
+IN_OPEN = long(0x00000020) # File was opened
+IN_MOVED_FROM = long(0x00000040) # File was moved from X
+IN_MOVED_TO = long(0x00000080) # File was moved to Y
+IN_CREATE = long(0x00000100) # Subfile was created
+IN_DELETE = long(0x00000200) # Subfile was delete
+IN_DELETE_SELF = long(0x00000400) # Self was deleted
+IN_MOVE_SELF = long(0x00000800) # Self was moved
+IN_UNMOUNT = long(0x00002000) # Backing fs was unmounted
+IN_Q_OVERFLOW = long(0x00004000) # Event queued overflowed
+IN_IGNORED = long(0x00008000) # File was ignored
+
+IN_ONLYDIR = long(0x01000000) # only watch the path if it is a directory
+IN_DONT_FOLLOW = long(0x02000000) # don't follow a sym link
+IN_MASK_ADD = long(0x20000000) # add to the mask of an already existing watch
+IN_ISDIR = long(0x40000000) # event occurred against dir
+IN_ONESHOT = long(0x80000000) # only send event once
IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE # closes
IN_MOVED = IN_MOVED_FROM | IN_MOVED_TO # moves
@@ -172,7 +174,7 @@
self.connected = 1
self._writeDisconnected = True
- self._buffer = ''
+ self._buffer = b''
self._watchpoints = {}
self._watchpaths = {}
@@ -187,7 +189,7 @@
adding a watchpath for inverse lookup of the file descriptor from the
path.
"""
- wd = self._inotify.add(self._fd, path.path, mask)
+ wd = self._inotify.add(self._fd, path.asBytesMode().path, mask)
iwp = _Watch(path, mask, autoAdd, callbacks)
@@ -207,7 +209,7 @@
"""
self._inotify.remove(self._fd, wd)
iwp = self._watchpoints.pop(wd)
- self._watchpaths.pop(iwp.path)
+ self._watchpaths.pop(iwp.asBytesMode().path)
def connectionLost(self, reason):
@@ -218,7 +220,7 @@
if self._fd >= 0:
try:
os.close(self._fd)
- except OSError, e:
+ except OSError as e:
log.err(e, "Couldn't close INotify file descriptor.")
@@ -258,7 +260,7 @@
except KeyError:
continue
- path = iwp.path
+ path = iwp.asBytesMode().path
if name:
path = path.child(name)
iwp._notify(path, mask)
@@ -294,7 +296,7 @@
meaning that we generate double events, your app must be resistant.
"""
try:
- listdir = iwp.path.children()
+ listdir = iwp.asBytesMode().path.children()
except OSError:
# Somebody or something (like a test) removed this directory while
# we were in the callLater(0...) waiting. It doesn't make sense to
@@ -347,6 +349,7 @@
@param recursive: Also add all the subdirectories in this path
@type recursive: C{boolean}
"""
+ path = path.asBytesMode()
if recursive:
# This behavior is needed to be compatible with the windows
# interface for filesystem changes:
@@ -390,6 +393,7 @@
@param path: The path that should be checked
@type path: L{FilePath}
"""
+ path = path.asBytesMode()
return self._watchpaths.get(path, None)
Modified: branches/inotify-py3-8211/twisted/internet/test/test_inotify.py
==============================================================================
--- branches/inotify-py3-8211/twisted/internet/test/test_inotify.py (original)
+++ branches/inotify-py3-8211/twisted/internet/test/test_inotify.py Tue Feb 16 21:37:11 2016
@@ -5,11 +5,16 @@
Tests for the inotify wrapper in L{twisted.internet.inotify}.
"""
+from __future__ import absolute_import, division
+
from twisted.internet import defer, reactor
from twisted.python import filepath, runtime
from twisted.python.reflect import requireModule
from twisted.trial import unittest
+from twisted.python import _inotify
+from twisted.internet import inotify
+
if requireModule('twisted.python._inotify') is not None:
from twisted.internet import inotify
else:
@@ -70,7 +75,8 @@
if expectedPath is None:
expectedPath = self.dirname.child("foo.bar")
notified = defer.Deferred()
- def cbNotified((watch, filename, events)):
+ def cbNotified(*args):
+ watch, filename, events = args
self.assertEqual(filename, expectedPath)
self.assertTrue(events & mask)
notified.addCallback(cbNotified)
@@ -387,7 +393,8 @@
expectedPath.touch()
notified = defer.Deferred()
- def cbNotified((ignored, filename, events)):
+ def cbNotified(*args):
+ ignored, filename, events = args
self.assertEqual(filename, expectedPath)
self.assertTrue(events & inotify.IN_DELETE_SELF)
@@ -423,7 +430,8 @@
expectedPath2.touch()
notified = defer.Deferred()
- def cbNotified((ignored, filename, events)):
+ def cbNotified(*args):
+ ignored, filename, events = args
self.assertEqual(filename, expectedPath2)
self.assertTrue(events & inotify.IN_DELETE_SELF)
Modified: branches/inotify-py3-8211/twisted/python/_inotify.py
==============================================================================
--- branches/inotify-py3-8211/twisted/python/_inotify.py (original)
+++ branches/inotify-py3-8211/twisted/python/_inotify.py Tue Feb 16 21:37:11 2016
@@ -9,6 +9,8 @@
required.
"""
+from __future__ import absolute_import, division
+
import ctypes
import ctypes.util