Add a PollConstants class to serve as a layer of indirection for accessing
authorZac Medico <zmedico@gentoo.org>
Fri, 4 Jul 2008 21:27:10 +0000 (21:27 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 4 Jul 2008 21:27:10 +0000 (21:27 -0000)
select.POLL* attributes which do not exist on interix. Thanks to grobian
for reporting.

svn path=/main/trunk/; revision=10930

pym/_emerge/__init__.py

index 72413191b9f7f0f902ef4135b8bc0eeb59fbb227..f270cc6228928b9c1faebdca5552fb02c9266c5a 100644 (file)
@@ -1575,7 +1575,7 @@ class SpawnProcess(SubProcess):
                os.close(slave_fd)
                files.process = os.fdopen(master_fd, 'r')
                self.reg_id = self.scheduler.register(files.process.fileno(),
-                       select.POLLIN, self._output_handler)
+                       PollConstants.POLLIN, self._output_handler)
                self.registered = True
 
        def _output_handler(self, fd, event):
@@ -1974,7 +1974,7 @@ class EbuildPhase(SubProcess):
                os.close(slave_fd)
                files.ebuild = os.fdopen(master_fd, 'r')
                self.reg_id = self.scheduler.register(files.ebuild.fileno(),
-                       select.POLLIN, output_handler)
+                       PollConstants.POLLIN, output_handler)
                self.registered = True
 
        def _output_handler(self, fd, event):
@@ -7019,7 +7019,21 @@ class PackageCounters(object):
                                        (self.blocks - self.blocks_satisfied))
                return "".join(myoutput)
 
-class PollSelectAdapter(object):
+class PollConstants(object):
+
+       """
+       Provides POLL* constants that are equivalent to those from the
+       select module, for use by PollSelectAdapter.
+       """
+
+       names = ("POLLIN", "POLLPRI", "POLLOUT", "POLLERR", "POLLHUP", "POLLNVAL")
+       v = 1
+       for k in names:
+               locals()[k] = getattr(select, k, v)
+               v *= 2
+       del k, v
+
+class PollSelectAdapter(PollConstants):
 
        """
        Use select to emulate a poll object, for
@@ -7032,14 +7046,15 @@ class PollSelectAdapter(object):
 
        def register(self, fd, *args):
                """
-               Only select.POLLIN is currently supported!
+               Only POLLIN is currently supported!
                """
                if len(args) > 1:
                        raise TypeError(
                                "register expected at most 2 arguments, got " + \
                                repr(1 + len(args)))
 
-               eventmask = select.POLLIN | select.POLLPRI | select.POLLOUT
+               eventmask = PollConstants.POLLIN | \
+                       PollConstants.POLLPRI | PollConstants.POLLOUT
                if args:
                        eventmask = args[0]
 
@@ -7071,7 +7086,7 @@ class PollSelectAdapter(object):
                select_events = select.select(*select_args)
                poll_events = []
                for fd in select_events[0]:
-                       poll_events.append((fd, select.POLLIN))
+                       poll_events.append((fd, PollConstants.POLLIN))
                return poll_events
 
 class SequentialTaskQueue(SlotObject):