コード例 #1
0
ファイル: downloader.py プロジェクト: abhianand7/scrapex
    def _write_file(self, file_path, data):

        with open(file_path, 'w') as f:
            # d = Deferred()
            fd = f.fileno()
            setNonBlocking(fd)
            writeToFD(fd, data)
コード例 #2
0
ファイル: fileoperations.py プロジェクト: hellais/GLBackend
    def _dump_file(self, file, submission_gus, file_gus):

        result = {}
        result['file_gus'] = file_gus
        result['name'] = file['filename']
        result['type'] = file['content_type']
        result['size'] = len(file['body'])

        # XXX verify this token what's is it
        result['token'] = submission_gus

        if not os.path.isdir(config.advanced.submissions_dir):
            print "%s does not exist. Creating it." % config.advanced.submissions_dir
            os.mkdir(config.advanced.submissions_dir)

        the_submission_dir = config.advanced.submissions_dir

        # this happen only at the first execution
        if not os.path.isdir(the_submission_dir):
            os.mkdir(the_submission_dir)

        filelocation = os.path.join(the_submission_dir, file_gus)

        print "Saving file \"%s\" of %d byte [%s] type, to %s" % \
              (result['name'], result['size'], result['type'], filelocation )

        with open(filelocation, 'w+') as fd:
            fdesc.setNonBlocking(fd.fileno())
            fdesc.writeToFD(fd.fileno(), file['body'])

        return result
コード例 #3
0
 def updateReport(self, report_filename, data):
     try:
         with open(report_filename, 'a+') as fd:
             fdesc.setNonBlocking(fd.fileno())
             fdesc.writeToFD(fd.fileno(), data)
     except IOError as e:
         web.HTTPError(404, "Report not found")
コード例 #4
0
ファイル: handlers.py プロジェクト: not-the-nsa/ooni-backend
 def updateReport(self, report_filename, data):
     try:
         with open(report_filename, 'a+') as fd:
             fdesc.setNonBlocking(fd.fileno())
             fdesc.writeToFD(fd.fileno(), data)
     except IOError as e:
         e.OONIBError(404, "Report not found")
コード例 #5
0
ファイル: accounts.py プロジェクト: stratosphereips/evpn
    def _create_ipfile(self, username, ip_addr):
        """
        Create configuration file for static IP allocation.

        :param username (str): account username
        :param ip_addr (IPv4Address): IP address allocated for the account.
        """
        log.info("ACCOUNTS:: Creating IP file for client.")

        # OpenVPN will look for files inside this directory. Its filename must
        # be the same as the username
        ip_filename = os.path.join(self.path['client-ips'], username)
        log.debug("ACCOUNTS: Creating {} with {}.".format(
            ip_filename, str(ip_addr)))

        # From `Configuring client-specific rules and access policies` in
        # https://openvpn.net/index.php/open-source/documentation/howto.html
        virtual_client = ip_addr
        server_endpoint = ip_addr + 1

        log.debug("ACCOUNTS:: ifconfig-push {} {}".format(
            virtual_client, server_endpoint))
        data = "ifconfig-push {} {}\n".format(str(virtual_client),
                                              str(server_endpoint))
        with open(ip_filename, 'w+') as f:
            fd = f.fileno()
            setNonBlocking(fd)
            writeToFD(fd, data)

        fp = FilePath(ip_filename)
        fp.chmod(0644)
コード例 #6
0
ファイル: itclient2.py プロジェクト: grodniewicz/zeroD
    def contentReceived(self, chunk):
        #log.msg('Content %s bytes received:', len(chunk))
        fdesc.writeToFD(self.file, chunk)
        
        if self.beginning == 2:
            log.msg('File should be closed here')

        return self.headerReceived, HEADER_LENGTH
コード例 #7
0
ファイル: cacher.py プロジェクト: Frowse/openross
    def process_image(self, payload, **kwargs):
        """ Writes images to the cache """

        filecache_loc = settings.CACHE_LOCATION
        webcache_loc = settings.WEB_CACHE_LOCATION
        cache_filename_parts = payload['image_path'].split('.')
        filefront = cache_filename_parts[0]
        fileend = cache_filename_parts[1]
        cache_filename = ''

        original_filename = '%s.%s' % (
            filefront,
            fileend,
        )
        cache_filename = '%s_%sx%s_%s.%s' % (
            filefront,
            payload['width'],
            payload['height'],
            payload['mode'],
            fileend,
        )

        file_cache = os.path.join(filecache_loc, cache_filename)
        web_cache = os.path.join(webcache_loc, cache_filename)

        # Files are normally binned in subdir, create them in cache
        dirs = os.path.dirname(file_cache)
        try:
            os.makedirs(dirs)
        except os.error:
            pass

        if 'skip_resize' in payload.keys():
            # Just save/servwe original image as there is no resized image
            file_cache = os.path.join(filecache_loc, original_filename)
            web_cache = os.path.join(webcache_loc, original_filename)

        # Save image to be served
        fd = open(file_cache, 'w')
        fdesc.setNonBlocking(fd.fileno())
        yield fdesc.writeToFD(fd.fileno(), payload['image'])
        fd.close()

        if 'skip_resize' not in payload.keys():
            # If image to be served has beenr esized, also cache full size image
            file_cache = os.path.join(filecache_loc, original_filename)
            fd = open(file_cache, 'w')
            fdesc.setNonBlocking(fd.fileno())
            yield fdesc.writeToFD(fd.fileno(), payload['original_image'])
            fd.close()

        if settings.DEBUG:
            log.msg(
                "[%s] Cached image location: %s" % (datetime.now().isoformat(), file_cache),
                logLevel=logging.DEBUG
            )

        defer.returnValue(web_cache)
コード例 #8
0
    def process_image(self, payload, **kwargs):
        """ Writes images to the cache """

        filecache_loc = settings.CACHE_LOCATION
        webcache_loc = settings.WEB_CACHE_LOCATION
        cache_filename_parts = payload['image_path'].split('.')
        filefront = cache_filename_parts[0]
        fileend = cache_filename_parts[1]
        cache_filename = ''

        original_filename = '%s.%s' % (
            filefront,
            fileend,
        )
        cache_filename = '%s_%sx%s_%s.%s' % (
            filefront,
            payload['width'],
            payload['height'],
            payload['mode'],
            fileend,
        )

        file_cache = os.path.join(filecache_loc, cache_filename)
        web_cache = os.path.join(webcache_loc, cache_filename)

        # Files are normally binned in subdir, create them in cache
        dirs = os.path.dirname(file_cache)
        try:
            os.makedirs(dirs)
        except os.error:
            pass

        if 'skip_resize' in payload.keys():
            # Just save/servwe original image as there is no resized image
            file_cache = os.path.join(filecache_loc, original_filename)
            web_cache = os.path.join(webcache_loc, original_filename)

        # Save image to be served
        fd = open(file_cache, 'w')
        fdesc.setNonBlocking(fd.fileno())
        yield fdesc.writeToFD(fd.fileno(), payload['image'])
        fd.close()

        if 'skip_resize' not in payload.keys():
            # If image to be served has beenr esized, also cache full size image
            file_cache = os.path.join(filecache_loc, original_filename)
            fd = open(file_cache, 'w')
            fdesc.setNonBlocking(fd.fileno())
            yield fdesc.writeToFD(fd.fileno(), payload['original_image'])
            fd.close()

        if settings.DEBUG:
            log.msg("[%s] Cached image location: %s" %
                    (datetime.now().isoformat(), file_cache),
                    logLevel=logging.DEBUG)

        defer.returnValue(web_cache)
コード例 #9
0
ファイル: server.py プロジェクト: alexsunday/pyvpn
 def writeSomeData(self, data):
     self._write_buf += data
     while True:
         length = self.get_frame(self._write_buf)
         if length == -1:
             break
         frame = self._write_buf[:length]
         self._write_buf = self._write_buf[length:]
         fdesc.writeToFD(self.tunfd, frame)
コード例 #10
0
ファイル: server.py プロジェクト: wellkang/pyvpn
 def writeSomeData(self, data):
     self._write_buf += data
     while True:
         length = self.get_frame(self._write_buf)
         if length == -1:
             break
         frame = self._write_buf[:length]
         self._write_buf = self._write_buf[length:]
         fdesc.writeToFD(self.tunfd, frame)
コード例 #11
0
ファイル: base.py プロジェクト: rowanthorpe/GLBackend
    def do_verbose_log(self, content):
        """
        Record in the verbose log the content as defined by Cyclone wrappers.
        """
        content = sanitize_str(content)

        try:
            with open(GLSetting.httplogfile, "a+") as fd:
                fdesc.writeToFD(fd.fileno(), content + "\n")
        except Exception as excep:
            log.err("Unable to open %s: %s" % (GLSetting.httplogfile, excep))
コード例 #12
0
    def do_verbose_log(self, content):
        """
        Record in the verbose log the content as defined by Cyclone wrappers.
        """
        content = log_remove_escapes(content)
        content = log_encode_html(content)

        try:
            with open(GLSetting.httplogfile, 'a+') as fd:
                fdesc.writeToFD(fd.fileno(), content + "\n")
        except Exception as excep:
            log.err("Unable to open %s: %s" % (GLSetting.httplogfile, excep))
コード例 #13
0
ファイル: base.py プロジェクト: tonegas/GlobaLeaks
    def do_verbose_log(self, content):
        """
        Record in the verbose log the content as defined by Cyclone wrappers.
        """
        content = log_remove_escapes(content)
        content = log_encode_html(content)

        try:
            with open(GLSetting.httplogfile, 'a+') as fd:
                fdesc.writeToFD(fd.fileno(), content + "\n")
        except Exception as excep:
            log.err("Unable to open %s: %s" % (GLSetting.httplogfile, excep))
コード例 #14
0
    def do_verbose_log(self, content):
        """
        Record in the verbose log the content as defined by Cyclone wrappers.

        This option is only available in devel mode and intentionally does not filter
        any input/output; It should be used only for debug purposes.
        """

        try:
            with open(GLSettings.httplogfile, 'a+') as fd:
                fdesc.writeToFD(fd.fileno(), content + "\n")
        except Exception as excep:
            log.err("Unable to open %s: %s" % (GLSettings.httplogfile, excep))
コード例 #15
0
ファイル: base.py プロジェクト: corvolino/GlobaLeaks
    def do_verbose_log(self, content):
        """
        Record in the verbose log the content as defined by Cyclone wrappers.

        This option is only available in devel mode and intentionally does not filter
        any input/output; It should be used only for debug purposes.
        """

        try:
            with open(GLSettings.httplogfile, "a+") as fd:
                fdesc.writeToFD(fd.fileno(), content + "\n")
        except Exception as excep:
            log.err("Unable to open %s: %s" % (GLSettings.httplogfile, excep))
コード例 #16
0
ファイル: itprotocol.py プロジェクト: grodniewicz/zeroD
    def receiveContent(self, chunk):

        start = time.time()
        log.msg('Content %s bytes received:', len(chunk))
        fdesc.writeToFD(self.file, chunk)

        if self.beginning == 2:
            log.msg('Last chunk go to processing')
            for websock in self.factory.browsers:
                websock.write(self.path.split('/')[-1].encode('utf-8')) 
            self.startProcessing()
        stop = time.time()
        return self.receiveHeader, HEADER_LENGTH
コード例 #17
0
    def updateReport(self, report_id, parsed_request):

        log.debug("Got this request %s" % parsed_request)
        report_filename = os.path.join(config.main.report_dir,
                report_id)
        
        config.reports[report_id].refresh()

        try:
            with open(report_filename, 'a+') as fd:
                fdesc.setNonBlocking(fd.fileno())
                fdesc.writeToFD(fd.fileno(), parsed_request['content'])
        except IOError as exc:
            e.OONIBError(404, "Report not found")
        self.write({})
コード例 #18
0
ファイル: process.py プロジェクト: axray/dataware.dreamplug
 def writeSomeData(self, data):
     """
     Write some data to the open process.
     """
     rv = fdesc.writeToFD(self.fd, data)
     if rv == len(data) and self.enableReadHack:
         self.startReading()
     return rv
コード例 #19
0
ファイル: process.py プロジェクト: kusoof/wprof
 def writeSomeData(self, data):
     """
     Write some data to the open process.
     """
     rv = fdesc.writeToFD(self.fd, data)
     if rv == len(data) and self.enableReadHack:
         self.startReading()
     return rv
コード例 #20
0
 def writeSomeData(self, data):
     """
     Write some data to the open process.
     """
     rv = fdesc.writeToFD(self.fd, data)
     if rv == len(data) and self.enableReadHack:
         # If the send buffer is now empty and it is necessary to monitor
         # this descriptor for readability to detect close, try detecting
         # readability now.
         self.startReading()
     return rv
コード例 #21
0
ファイル: process.py プロジェクト: antong/twisted
 def writeSomeData(self, data):
     """
     Write some data to the open process.
     """
     rv = fdesc.writeToFD(self.fd, data)
     if rv == len(data) and self.enableReadHack:
         # If the send buffer is now empty and it is necessary to monitor
         # this descriptor for readability to detect close, try detecting
         # readability now.
         self.startReading()
     return rv
コード例 #22
0
ファイル: fileoperations.py プロジェクト: vecna/GLBackend
    def _dump_file(self, file, submission_gus, file_gus):

        result = {}
        result['file_gus'] = file_gus
        result['name'] = file['filename']
        result['type'] = file['content_type']
        result['size'] = len(file['body'])

        # XXX verify this token what's is it
        # TODO, remind the also ReceiverTip can upload file, not just Submission
        result['token'] = submission_gus

        if not os.path.isdir(config.advanced.submissions_dir):
            print "%s does not exist. Creating it." % config.advanced.submissions_dir
            os.mkdir(config.advanced.submissions_dir)

        the_submission_dir = config.advanced.submissions_dir

        # this happen only at the first execution
        if not os.path.isdir(the_submission_dir):
            os.mkdir(the_submission_dir)

        filelocation = os.path.join(the_submission_dir, file_gus)

        print "Saving file \"%s\" of %d byte [%s] type, to %s" % \
              (result['name'], result['size'], result['type'], filelocation )

        # *The file is complete*
        # because Cyclone cache them before pass to the handler.
        # This mean that need to be limited client and Cyclone side,
        # and we here can't track about incomplete file.
        with open(filelocation, 'w+') as fd:
            fdesc.setNonBlocking(fd.fileno())
            fdesc.writeToFD(fd.fileno(), file['body'])

        return result
コード例 #23
0
ファイル: files.py プロジェクト: kyrios/atemclient
 def dataReceived(self,data):
     """docstring for writeData"""
     fdesc.writeToFD(self.outfile,data)
コード例 #24
0
ファイル: files.py プロジェクト: kyrios/atemclient
 def writeData(self,data):
     """docstring for writeData"""
     fdesc.writeToFD(self.outfile,data)
コード例 #25
0
 def writeSomeData(self, data):
     """
     Write some data to the serial device.
     """
     return fdesc.writeToFD(self.fileno(), data)
コード例 #26
0
 def writeSomeData(self, data):
     return fdesc.writeToFD(self.fp.fileno(), data)
コード例 #27
0
 def writeSomeData(self, data):
     """
     Write some data to the open process.
     """
     return fdesc.writeToFD(self.fd, data)
コード例 #28
0
 def writeToReport(self, report_filename, data):
     with open(report_filename, 'w+') as fd:
         fdesc.setNonBlocking(fd.fileno())
         fdesc.writeToFD(fd.fileno(), data)
コード例 #29
0
ファイル: serialport.py プロジェクト: xuhao1/mavasync
 def writeSomeData(self, data):
     """
     Write some data to the serial device.
     """
     return fdesc.writeToFD(self.fileno(), data)
コード例 #30
0
 def write(self, data):
     fdesc.writeToFD(self._port.fileno(), data)
コード例 #31
0
ファイル: device.py プロジェクト: buben19/twistedinput
 def writeSomeData(self, data):
     rw = fdesc.writeToFD(self.fileno(), data)
     if rw == len(data) and self.backToReading:
         self.backToReading = False
         self.startReading()
     return rw
コード例 #32
0
 def dataReceived(self, data):
     """docstring for writeData"""
     fdesc.writeToFD(self.outfile, data)
コード例 #33
0
 def writeData(self, data):
     """docstring for writeData"""
     fdesc.writeToFD(self.outfile, data)
コード例 #34
0
ファイル: serialport.py プロジェクト: JvanDalfsen/calvin-base
 def write(self, data):
     fdesc.writeToFD(self._port.fileno(), data)
コード例 #35
0
ファイル: process.py プロジェクト: antong/twisted
 def writeSomeData(self, data):
     """
     Write some data to the open process.
     """
     return fdesc.writeToFD(self.fd, data)
コード例 #36
0
 def writeToFile(self, data):
     if self.outputFile is not None:
         # Write to nonblocking output file descriptor
         fdesc.writeToFD(self.outputFile.fileno(), data)
コード例 #37
0
 def writeSomeData(self, data):
     rw = fdesc.writeToFD(self.fileno(), data)
     if rw == len(data) and self.backToReading:
         self.backToReading = False
         self.startReading()
     return rw
コード例 #38
0
ファイル: test_fdesc.py プロジェクト: steeliter/VTK
 def write(self, d):
     """
     Write data to the pipe.
     """
     return fdesc.writeToFD(self.w, d)
コード例 #39
0
 def writeSomeData(self, data):
     return writeToFD(self.file, data)
コード例 #40
0
ファイル: fifo.py プロジェクト: Valodim/irclogd
 def writeSomeData(self, data):
     """
     Write data to the FIFO. Should not be used by protocols -
     use L{write<twisted.internet.abstract.FileDescriptor.write>} instead.
     """
     return writeToFD(self.fileno(), data)
コード例 #41
0
ファイル: handlers.py プロジェクト: glamrock/ooni-backend
 def writeToReport(self, report_filename, data):
     with open(report_filename, 'w+') as fd:
         fdesc.setNonBlocking(fd.fileno())
         fdesc.writeToFD(fd.fileno(), data)
コード例 #42
0
 def writeSomeData(self, data):
     return fdesc.writeToFD(self.fileno(), data)
コード例 #43
0
ファイル: test_fdesc.py プロジェクト: AmirKhooj/VTK
 def write(self, d):
     """
     Write data to the pipe.
     """
     return fdesc.writeToFD(self.w, d)