Пример #1
0
 def getFile(filename):
     with open(filename) as f:
         d = Deferred()
         fd = f.fileno()
         setNonBlocking(fd)
         readFromFD(fd, d.callback)
         return d
Пример #2
0
 def getConf(self):
     try:
         logger.debug("Getting config file")
         with open(self.configPath) as f:
             fd = f.fileno()
             setNonBlocking(fd)
             readFromFD(fd, self.runConf)
     except IOError, e:
         self.d.errback(e)
Пример #3
0
 def getConf(self):
   try:
     logger.debug("Getting config file")
     with open(self.configPath) as f:
       fd = f.fileno()
       setNonBlocking(fd)
       readFromFD(fd, self.runConf)
   except IOError, e:
     self.d.errback(e)
Пример #4
0
 def doRead(self):
     """
     Called when my standard output stream is ready for reading.
     """
     return fdesc.readFromFD(
         self.fd,
         lambda data: self.proto.childDataReceived(1, data))
Пример #5
0
 def doRead(self):
     """
     Called when my standard output stream is ready for reading.
     """
     return fdesc.readFromFD(
         self.fd,
         lambda data: self.proto.childDataReceived(1, data))
Пример #6
0
 def test_readFromEmpty(self):
     """
     Verify that reading from a file descriptor with no data does not raise
     an exception and does not result in the callback function being called.
     """
     l = []
     result = fdesc.readFromFD(self.r, l.append)
     self.assertEqual(l, [])
     self.assertEqual(result, None)
Пример #7
0
 def test_readFromEmpty(self):
     """
     Verify that reading from a file descriptor with no data does not raise
     an exception and does not result in the callback function being called.
     """
     l = []
     result = fdesc.readFromFD(self.r, l.append)
     self.assertEqual(l, [])
     self.assertEqual(result, None)
Пример #8
0
    def doRead(self):
        if self.direction == 'in':

            def _read_cb(data):
                return self.protocol.dataReceived(data.strip())

            f = self._fds['gpio_node']
            f.seek(0)
            return fdesc.readFromFD(f.fileno(), _read_cb)
Пример #9
0
 def get_raw_data(cls, *args):
     if not cls.FILE_OBJ:
         cls.make_non_blocking_fdesc()
     d = Deferred()
     file_obj = cls.FILE_OBJ
     result = readFromFD(file_obj.fileno(), d.callback)
     file_obj.seek(0)
     cls.check_fdesc(result)
     return d
Пример #10
0
 def read(self):
     """
     Read data from the pipe.
     """
     l = []
     res = fdesc.readFromFD(self.r, l.append)
     if res is None:
         if l:
             return l[0]
         else:
             return b""
     else:
         return res
Пример #11
0
 def read(self):
     """
     Read data from the pipe.
     """
     l = []
     res = fdesc.readFromFD(self.r, l.append)
     if res is None:
         if l:
             return l[0]
         else:
             return b""
     else:
         return res
Пример #12
0
    def process(self):

        self.setHeader('Content-Type', 'text/html')

        if self.path[-1] == '/':
            self.path+="index.html"

        cwd = os.path.abspath(os.curdir)
        requested_path = os.path.relpath(self.path[1:], cwd)
        requested_path = os.path.abspath(requested_path)

        if (os.path.commonprefix([requested_path, cwd])!=cwd):
            self.setResponseCode(http.NOT_FOUND)
            self.write("<h1>404 Not Found</h1>")
            return

        if (os.path.islink(s.path[1:])):
            self.setResponseCode(http.NOT_FOUND)
            self.write("<h1>404 Not Found</h1>")
            return

        try:
            self.setResponseCode(200)
            f = open(self.path[1:])
            d = Deferred()
            fd = f.fileno()
            fdesc.setNonBlocking(fd)
            d.addCallback(lambda data: self.write(data))
            fdesc.readFromFD(fd, d.callback)


        except IOError:
            self.setResponseCode(http.NOT_FOUND)
            self.write("<h1>404 Not Found</h1>")

        self.finish()
Пример #13
0
 def doRead(self):
     """
     Read some bytes from the pipe and discard them.
     """
     fdesc.readFromFD(self.fileno(), lambda data: None)
Пример #14
0
 def doRead(self):
     """Some data's readable from serial device.
     """
     return fdesc.readFromFD(self.fileno(), self.protocol.dataReceived)
 def doRead(self):
   fdesc.readFromFD(self._fd, self.protocol.dataReceived)
Пример #16
0
 def doRead(self):
     """
     This is called when the pipe becomes readable.
     """
     return fdesc.readFromFD(self.fd, self.dataReceived)
Пример #17
0
	def doRead(self):
		try:
			setBlocking(False,0)
			return fdesc.readFromFD(0, self.dataReceived)
		finally:
			fdesc.setBlocking(True,0)
 def doRead(self):
     """
     Some data's readable from serial device.
     """
     return fdesc.readFromFD(self.fileno(), self.protocol.dataReceived)
Пример #19
0
 def read_whitelist(self):
     fd = os.open(Conf.static_whitelist, os.O_RDONLY | os.O_CREAT)
     fdesc.readFromFD(fd, self.process_whitelist)
Пример #20
0
 def doRead(self):
     """
     Read some data from the observed file descriptors
     """
     fdesc.readFromFD(self._fd, self._doRead)
Пример #21
0
 def doRead(self):
     print '~~~~~~~~~~~~~~~~~~~~~~~~~'
     fdesc.readFromFD(self.tunfd, self._doRead)
     print '~~~~~~~~~~~~~~~~~~~~~~~~~'
Пример #22
0
 def get_threshold(self):
     '''
     get threshold from file
     '''
     fd = os.open(Conf.data_dir + '/' + Conf.threshold_file, os.O_RDONLY | os.O_CREAT)
     fdesc.readFromFD(fd, self.process_threshold)
Пример #23
0
 def doRead(self):
     # TODO move this back out as soon as such versio of Twisted is
     # packaged.
     from twisted.internet import fdesc
     return fdesc.readFromFD(self.fileno(), self.protocol.dataReceived)
Пример #24
0
 def doRead(self):
     """
     This is called when the pipe becomes readable.
     """
     return fdesc.readFromFD(self.fd, self.dataReceived)
Пример #25
0
 def doRead(self):
     return fdesc.readFromFD(self.fileno(), self.protocol.dataReceived)
Пример #26
0
 def doRead(self):
     # TODO move this back out as soon as such versio of Twisted is
     # packaged.
     from twisted.internet import fdesc
     return fdesc.readFromFD(self.fileno(), self.protocol.dataReceived)
Пример #27
0
 def doRead(self):
     self.trigger()
     return fdesc.readFromFD(self.fp.fileno(), self.dataRead)
Пример #28
0
 def doRead(self):
     return fdesc.readFromFD(self.fileno(), self.dataReceived)
Пример #29
0
 def doRead(self):
     """
     Read some data from the observed file descriptors
     """
     fdesc.readFromFD(self._fd, self._doRead)
Пример #30
0
 def doRead(self):
     """
     Read some bytes from the pipe and discard them.
     """
     fdesc.readFromFD(self.fileno(), lambda data: None)
Пример #31
0
 def doRead(self):
     print '~~~~~~~~~~~~~~~~~~~~~~~~~'
     fdesc.readFromFD(self.tunfd, self._doRead)
     print '~~~~~~~~~~~~~~~~~~~~~~~~~'