Ejemplo n.º 1
0
 def test_unzip(self):
     """
     L{twisted.python.zipstream.unzip} should extract all files from a zip
     archive
     """
     numfiles = 3
     zpfilename = self.makeZipFile([str(i) for i in range(numfiles)])
     zipstream.unzip(zpfilename, self.unzipdir.path)
     self.assertEqual(
         set(self.unzipdir.listdir()),
         set(map(str, range(numfiles))))
     for i in range(numfiles):
         self.assertEqual(self.unzipdir.child(str(i)).getContent(), str(i))
Ejemplo n.º 2
0
 def test_removeAllReturnsRemovedDescriptors(self):
     """
     L{PosixReactorBase._removeAll} returns a list of removed
     L{IReadDescriptor} and L{IWriteDescriptor} objects.
     """
     reactor = TrivialReactor()
     reader = object()
     writer = object()
     reactor.addReader(reader)
     reactor.addWriter(writer)
     removed = reactor._removeAll(reactor._readers, reactor._writers)
     self.assertEqual(set(removed), set([reader, writer]))
     self.assertNotIn(reader, reactor._readers)
     self.assertNotIn(writer, reactor._writers)
Ejemplo n.º 3
0
 def test_removeAllReturnsRemovedDescriptors(self):
     """
     L{PosixReactorBase._removeAll} returns a list of removed
     L{IReadDescriptor} and L{IWriteDescriptor} objects.
     """
     reactor = TrivialReactor()
     reader = object()
     writer = object()
     reactor.addReader(reader)
     reactor.addWriter(writer)
     removed = reactor._removeAll(reactor._readers, reactor._writers)
     self.assertEqual(set(removed), set([reader, writer]))
     self.assertNotIn(reader, reactor._readers)
     self.assertNotIn(writer, reactor._writers)
Ejemplo n.º 4
0
 def test_unzipDirectory(self):
     """
     The path to which a file is extracted by L{zipstream.unzip} is
     determined by joining the C{directory} argument to C{unzip} with the
     path within the archive of the file being extracted.
     """
     numfiles = 3
     zpfilename = self.makeZipFile([str(i) for i in range(numfiles)], 'foo')
     zipstream.unzip(zpfilename, self.unzipdir.path)
     self.assertEqual(
         set(self.unzipdir.child('foo').listdir()),
         set(map(str, range(numfiles))))
     for i in range(numfiles):
         self.assertEqual(
             self.unzipdir.child('foo').child(str(i)).getContent(), str(i))
Ejemplo n.º 5
0
    def test_unzipIterChunky(self):
        """
        L{twisted.python.zipstream.unzipIterChunky} returns an iterator which
        must be exhausted to completely unzip the input archive.
        """
        numfiles = 10
        contents = ['This is test file %d!' % i for i in range(numfiles)]
        zpfilename = self.makeZipFile(contents)
        list(zipstream.unzipIterChunky(zpfilename, self.unzipdir.path))
        self.assertEquals(
            set(self.unzipdir.listdir()),
            set(map(str, range(numfiles))))

        for child in self.unzipdir.children():
            num = int(child.basename())
            self.assertEquals(child.getContent(), contents[num])
Ejemplo n.º 6
0
    def test_unzipIterChunkyDirectory(self):
        """
        The path to which a file is extracted by L{zipstream.unzipIterChunky}
        is determined by joining the C{directory} argument to C{unzip} with the
        path within the archive of the file being extracted.
        """
        numfiles = 10
        contents = ['This is test file %d!' % i for i in range(numfiles)]
        zpfilename = self.makeZipFile(contents, 'foo')
        list(zipstream.unzipIterChunky(zpfilename, self.unzipdir.path))
        self.assertEquals(
            set(self.unzipdir.child('foo').listdir()),
            set(map(str, range(numfiles))))

        for child in self.unzipdir.child('foo').children():
            num = int(child.basename())
            self.assertEquals(child.getContent(), contents[num])
Ejemplo n.º 7
0
 def __init__(self, useGtk=True):
     self._simtag = None
     self._reads = set()
     self._writes = set()
     self._sources = {}
     posixbase.PosixReactorBase.__init__(self)
     # pre 2.3.91 the glib iteration and mainloop functions didn't release
     # global interpreter lock, thus breaking thread and signal support.
     if getattr(gobject, "pygtk_version", ()) >= (2, 3, 91) and not useGtk:
         self.context = gobject.main_context_default()
         self.__pending = self.context.pending
         self.__iteration = self.context.iteration
         self.loop = gobject.MainLoop()
         self.__crash = self.loop.quit
         self.__run = self.loop.run
     else:
         import gtk
         self.__pending = gtk.events_pending
         self.__iteration = gtk.main_iteration
         self.__crash = _our_mainquit
         self.__run = gtk.main
Ejemplo n.º 8
0
 def __init__(self, useGtk=True):
     self._simtag = None
     self._reads = set()
     self._writes = set()
     self._sources = {}
     posixbase.PosixReactorBase.__init__(self)
     # pre 2.3.91 the glib iteration and mainloop functions didn't release
     # global interpreter lock, thus breaking thread and signal support.
     if getattr(gobject, "pygtk_version", ()) >= (2, 3, 91) and not useGtk:
         self.context = gobject.main_context_default()
         self.__pending = self.context.pending
         self.__iteration = self.context.iteration
         self.loop = gobject.MainLoop()
         self.__crash = self.loop.quit
         self.__run = self.loop.run
     else:
         import gtk
         self.__pending = gtk.events_pending
         self.__iteration = gtk.main_iteration
         self.__crash = _our_mainquit
         self.__run = gtk.main
Ejemplo n.º 9
0
    def _removeAll(self, readers, writers):
        """
        Remove all readers and writers, and list of removed L{IReadDescriptor}s
        and L{IWriteDescriptor}s.

        Meant for calling from subclasses, to implement removeAll, like::

          def removeAll(self):
              return self._removeAll(self._reads, self._writes)

        where C{self._reads} and C{self._writes} are iterables.
        """
        removedReaders = set(readers) - self._internalReaders
        for reader in removedReaders:
            self.removeReader(reader)

        removedWriters = set(writers)
        for writer in removedWriters:
            self.removeWriter(writer)

        return list(removedReaders | removedWriters)
Ejemplo n.º 10
0
    def __init__(self):
        self.threadCallQueue = []
        self._eventTriggers = {}
        self._pendingTimedCalls = []
        self._newTimedCalls = []
        self._cancellations = 0
        self.running = False
        self._started = False
        self._justStopped = False
        # reactor internal readers, e.g. the waker.
        self._internalReaders = set()
        self.waker = None

        # Arrange for the running attribute to change to True at the right time
        # and let a subclass possibly do other things at that time (eg install
        # signal handlers).
        self.addSystemEventTrigger(
            'during', 'startup', self._reallyStartRunning)
        self.addSystemEventTrigger('during', 'shutdown', self.crash)
        self.addSystemEventTrigger('during', 'shutdown', self.disconnectAll)

        if platform.supportsThreads():
            self._initThreads()
        self.installWaker()
Ejemplo n.º 11
0
    def __init__(self):
        self.threadCallQueue = []
        self._eventTriggers = {}
        self._pendingTimedCalls = []
        self._newTimedCalls = []
        self._cancellations = 0
        self.running = False
        self._started = False
        self._justStopped = False
        # reactor internal readers, e.g. the waker.
        self._internalReaders = set()
        self.waker = None

        # Arrange for the running attribute to change to True at the right time
        # and let a subclass possibly do other things at that time (eg install
        # signal handlers).
        self.addSystemEventTrigger('during', 'startup',
                                   self._reallyStartRunning)
        self.addSystemEventTrigger('during', 'shutdown', self.crash)
        self.addSystemEventTrigger('during', 'shutdown', self.disconnectAll)

        if platform.supportsThreads():
            self._initThreads()
        self.installWaker()
Ejemplo n.º 12
0
 def cbEnded((failure, )):
     failure.trap(ProcessDone)
     self.assertEqual(set(lost), set([0, 1, 2]))
Ejemplo n.º 13
0
 def cbEnded((failure,)):
     failure.trap(ProcessDone)
     self.assertEqual(set(lost), set([0, 1, 2]))
Ejemplo n.º 14
0
 def cbAllLost(ignored):
     self.assertEqual(set(lost), set([0, 1, 2]))
Ejemplo n.º 15
0
 def __init__(self):
     base.ReactorBase.__init__(self)
     self.port = _iocp.CompletionPort()
     self.handles = set()
Ejemplo n.º 16
0
 def setUp(self):
     self.database = pwd
     self._users = iter(self.database.getpwall())
     self._uids = set()
Ejemplo n.º 17
0
 def setUp(self):
     self.database = pwd
     self._users = iter(self.database.getpwall())
     self._uids = set()
Ejemplo n.º 18
0
 def cbAllLost(ignored):
     self.assertEqual(set(lost), set([0, 1, 2]))
Ejemplo n.º 19
0
 def __init__(self):
     base.ReactorBase.__init__(self)
     self.port = _iocp.CompletionPort()
     self.handles = set()