當前位置: 首頁>>代碼示例>>Python>>正文


Python GLSecureTemporaryFile.write方法代碼示例

本文整理匯總了Python中globaleaks.security.GLSecureTemporaryFile.write方法的典型用法代碼示例。如果您正苦於以下問題:Python GLSecureTemporaryFile.write方法的具體用法?Python GLSecureTemporaryFile.write怎麽用?Python GLSecureTemporaryFile.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在globaleaks.security.GLSecureTemporaryFile的用法示例。


在下文中一共展示了GLSecureTemporaryFile.write方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_temporary_file_write_after_read

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
 def test_temporary_file_write_after_read(self):
     a = GLSecureTemporaryFile(GLSettings.tmp_upload_path)
     antani = "0123456789" * 10000
     a.write(antani)
     self.assertTrue(antani == a.read())
     self.assertRaises(AssertionError, a.write, antani)
     a.close()
開發者ID:br1n0,項目名稱:GlobaLeaks,代碼行數:9,代碼來源:test_security.py

示例2: get_file_upload

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
    def get_file_upload(self):
        try:
            if (int(self.request.arguments['flowTotalSize'][0]) / (1024 * 1024)) > GLSetting.defaults.maximum_filesize:
                log.err("File upload request rejected: file too big")
                raise errors.FileTooBig

            if self.request.arguments['flowIdentifier'][0] not in GLUploads:
                f = GLSecureTemporaryFile(GLSetting.tmp_upload_path)
                GLUploads[self.request.arguments['flowIdentifier'][0]] = f
            else:
                f = GLUploads[self.request.arguments['flowIdentifier'][0]]

            f.write(self.request.files['file'][0]['body'])

            if self.request.arguments['flowChunkNumber'][0] != self.request.arguments['flowTotalChunks'][0]:
                return None

            uploaded_file = {}
            uploaded_file['filename'] = self.request.files['file'][0]['filename']
            uploaded_file['content_type'] = self.request.files['file'][0]['content_type']
            uploaded_file['body_len'] = int(self.request.arguments['flowTotalSize'][0])
            uploaded_file['body_filepath'] = f.filepath
            uploaded_file['body'] = f

            return uploaded_file

        except errors.FileTooBig:
            raise # propagate the exception

        except Exception as exc:
            log.err("Error while handling file upload %s" % exc)
            return None
開發者ID:tonegas,項目名稱:GlobaLeaks,代碼行數:34,代碼來源:base.py

示例3: test_temporary_file

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
 def test_temporary_file(self):
     a = GLSecureTemporaryFile(GLSettings.tmp_upload_path)
     antani = "0123456789" * 10000
     a.write(antani)
     self.assertTrue(antani == a.read())
     a.close()
     self.assertFalse(os.path.exists(a.filepath))
開發者ID:br1n0,項目名稱:GlobaLeaks,代碼行數:9,代碼來源:test_security.py

示例4: get_dummy_file

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
    def get_dummy_file(self, filename=None, content_type=None, content=None):

        if filename is None:
            filename = ''.join(unichr(x) for x in range(0x400, 0x40A))

        if content_type is None:
            content_type = 'application/octet'

        if content is None:
            content = "ANTANI"

        temporary_file = GLSecureTemporaryFile(GLSetting.tmp_upload_path)

        temporary_file.write(content)
        temporary_file.avoid_delete()

        dummy_file = {
            'body': temporary_file,
            'body_len': len(content),
            'body_filepath': temporary_file.filepath,
            'filename': filename,
            'content_type': content_type,
        }

        return dummy_file
開發者ID:globaleaks,項目名稱:GLBackend-outdated,代碼行數:27,代碼來源:helpers.py

示例5: get_dummy_file

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
    def get_dummy_file(self, filename=None, content_type=None, content=None):
        if filename is None:
            filename = ''.join(unichr(x) for x in range(0x400, 0x40A))

        if content_type is None:
            content_type = 'application/octet'

        if content is None:
            content = 'LA VEDI LA SUPERCAZZOLA ? PREMATURA ? unicode €'

        temporary_file = GLSecureTemporaryFile(GLSettings.tmp_upload_path)

        temporary_file.write(content)
        temporary_file.avoid_delete()

        dummy_file = {
            'body': temporary_file,
            'body_len': len(content),
            'body_filepath': temporary_file.filepath,
            'filename': filename,
            'content_type': content_type,
            'submission': False
        }

        return dummy_file
開發者ID:corvolino,項目名稱:GlobaLeaks,代碼行數:27,代碼來源:helpers.py

示例6: test_004_temporary_file_lost_key_due_to_eventual_bug_or_reboot

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
 def test_004_temporary_file_lost_key_due_to_eventual_bug_or_reboot(self):
     a = GLSecureTemporaryFile(GLSetting.tmp_upload_path)
     a.avoid_delete()
     antani = "0123456789" * 10000
     a.write(antani)
     a.close()
     self.assertTrue(os.path.exists(a.filepath))
     os.remove(a.keypath)
     self.assertRaises(IOError, GLSecureFile, a.filepath)
開發者ID:Acidburn0zzz,項目名稱:GLBackend,代碼行數:11,代碼來源:test_security.py

示例7: test_003_temporary_file_avoid_delete

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
 def test_003_temporary_file_avoid_delete(self):
     a = GLSecureTemporaryFile(GLSetting.tmp_upload_path)
     a.avoid_delete()
     antani = "0123456789" * 10000
     a.write(antani)
     a.close()
     self.assertTrue(os.path.exists(a.filepath))
     b = GLSecureFile(a.filepath)
     self.assertTrue(antani == b.read())
開發者ID:Acidburn0zzz,項目名稱:GLBackend,代碼行數:11,代碼來源:test_security.py

示例8: get_file_upload

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
    def get_file_upload(self):
        try:
            if len(self.request.files) != 1:
                raise errors.InvalidInputFormat("cannot accept more than a file upload at once")

            ###############################################################
            # checks needed in order to offer compatibility with flow.js/fusty-flow.js
            chunk_size = len(self.request.files['file'][0]['body'])
            total_file_size = int(self.request.arguments['flowTotalSize'][0]) if 'flowTotalSize' in self.request.arguments else chunk_size
            flow_identifier = self.request.arguments['flowIdentifier'][0] if 'flowIdentifier' in self.request.arguments else os.random()
            if 'flowChunkNumber' in self.request.arguments and 'flowTotalChunks' in self.request.arguments:
                if self.request.arguments['flowChunkNumber'][0] != self.request.arguments['flowTotalChunks'][0]:
                    return None
            ###############################################################

            if ((chunk_size / (1024 * 1024)) > GLSettings.memory_copy.maximum_filesize or
                (total_file_size / (1024 * 1024)) > GLSettings.memory_copy.maximum_filesize):
                log.err("File upload request rejected: file too big")
                raise errors.FileTooBig(GLSettings.memory_copy.maximum_filesize)

            if flow_identifier not in GLUploads:
                f = GLSecureTemporaryFile(GLSettings.tmp_upload_path)
                GLUploads[flow_identifier] = f
            else:
                f = GLUploads[flow_identifier]

            f.write(self.request.files['file'][0]['body'])

            uploaded_file = {}
            uploaded_file['filename'] = self.request.files['file'][0]['filename']
            uploaded_file['content_type'] = self.request.files['file'][0]['content_type']
            uploaded_file['body_len'] = total_file_size
            uploaded_file['body_filepath'] = f.filepath
            uploaded_file['body'] = f

            upload_time = time.time() - f.creation_date

            # file uploads works on chunk basis so that we count 1 the file upload
            # as a whole in function get_file_upload()
            for event in outcoming_event_monitored:
                if event['status_checker'](self._status_code) and \
                        event['method'] == self.request.method and \
                        event['handler_check'](self.request.uri):
                    EventTrack(event, upload_time)

            return uploaded_file

        except errors.FileTooBig:
            raise  # propagate the exception

        except Exception as exc:
            log.err("Error while handling file upload %s" % exc)
            return None
開發者ID:br1n0,項目名稱:GlobaLeaks,代碼行數:55,代碼來源:base.py

示例9: get_file_upload

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
    def get_file_upload(self):
        try:
            if (int(self.request.arguments['flowTotalSize'][0]) / (1024 * 1024)) > GLSettings.memory_copy.maximum_filesize:
                log.err("File upload request rejected: file too big")
                raise errors.FileTooBig(GLSettings.memory_copy.maximum_filesize)

            if self.request.arguments['flowIdentifier'][0] not in GLUploads:
                f = GLSecureTemporaryFile(GLSettings.tmp_upload_path)
                GLUploads[self.request.arguments['flowIdentifier'][0]] = f
            else:
                f = GLUploads[self.request.arguments['flowIdentifier'][0]]

            f.write(self.request.files['file'][0]['body'])

            if self.request.arguments['flowChunkNumber'][0] != self.request.arguments['flowTotalChunks'][0]:
                return None

            uploaded_file = {}
            uploaded_file['filename'] = self.request.files['file'][0]['filename']
            uploaded_file['content_type'] = self.request.files['file'][0]['content_type']
            uploaded_file['body_len'] = int(self.request.arguments['flowTotalSize'][0])
            uploaded_file['body_filepath'] = f.filepath
            uploaded_file['body'] = f

            upload_time = time.time() - f.creation_date

            # file uploads works on chunk basis so that we count 1 the file upload
            # as a whole in function get_file_upload()
            for event in outcoming_event_monitored:
                if event['status_checker'](self._status_code) and \
                        event['method'] == self.request.method and \
                        event['handler_check'](self.request.uri):
                    EventTrack(event, upload_time)

            return uploaded_file

        except errors.FileTooBig:
            raise  # propagate the exception

        except Exception as exc:
            log.err("Error while handling file upload %s" % exc)
            return None
開發者ID:nsfw,項目名稱:GlobaLeaks,代碼行數:44,代碼來源:base.py

示例10: get_dummy_file

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
def get_dummy_file(filename=None, content_type=None, content=None):
    filename = ''.join(unichr(x) for x in range(0x400, 0x40A))

    content_type = 'application/octet'

    content = ''.join(unichr(x) for x in range(0x400, 0x40A))

    temporary_file = GLSecureTemporaryFile(GLSettings.tmp_upload_path)

    temporary_file.write(content)
    temporary_file.avoid_delete()

    return {
        'body': temporary_file,
        'body_len': len(content),
        'body_filepath': temporary_file.filepath,
        'filename': filename,
        'content_type': content_type,
        'submission': False
    }
開發者ID:Taipo,項目名稱:GlobaLeaks,代碼行數:22,代碼來源:helpers.py

示例11: test_post

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
    def test_post(self):

        temporary_file = GLSecureTemporaryFile(GLSetting.tmp_upload_path)
        temporary_file.write("ANTANI")
        temporary_file.avoid_delete()

        request_body = {
            'body': temporary_file,
            'body_len': len("ANTANI"),
            'body_filepath': temporary_file.filepath,
            'filename': 'en.json',
            'content_type': 'application/json'
        }

        handler = self.request({}, role='admin', kwargs={'path': GLSetting.static_path}, body=request_body)

        yield handler.post(lang='en')

        self.assertTrue(isinstance(self.responses, list))
        self.assertEqual(len(self.responses), 1)
        self._handler.validate_message(json.dumps(self.responses[0]), requests.staticFile)
開發者ID:Acidburn0zzz,項目名稱:GLBackend,代碼行數:23,代碼來源:test_admlangfiles.py

示例12: get_file_upload

# 需要導入模塊: from globaleaks.security import GLSecureTemporaryFile [as 別名]
# 或者: from globaleaks.security.GLSecureTemporaryFile import write [as 別名]
    def get_file_upload(self):
        try:
            if len(self.request.files) != 1:
                raise errors.InvalidInputFormat("cannot accept more than a file upload at once")

            chunk_size = len(self.request.files["file"][0]["body"])
            total_file_size = (
                int(self.request.arguments["flowTotalSize"][0])
                if "flowTotalSize" in self.request.arguments
                else chunk_size
            )
            flow_identifier = (
                self.request.arguments["flowIdentifier"][0]
                if "flowIdentifier" in self.request.arguments
                else generateRandomKey(10)
            )

            if (chunk_size / (1024 * 1024)) > GLSettings.memory_copy.maximum_filesize or (
                total_file_size / (1024 * 1024)
            ) > GLSettings.memory_copy.maximum_filesize:
                log.err("File upload request rejected: file too big")
                raise errors.FileTooBig(GLSettings.memory_copy.maximum_filesize)

            if flow_identifier not in GLUploads:
                f = GLSecureTemporaryFile(GLSettings.tmp_upload_path)
                GLUploads[flow_identifier] = f
            else:
                f = GLUploads[flow_identifier]

            f.write(self.request.files["file"][0]["body"])

            if "flowChunkNumber" in self.request.arguments and "flowTotalChunks" in self.request.arguments:
                if self.request.arguments["flowChunkNumber"][0] != self.request.arguments["flowTotalChunks"][0]:
                    return None

            uploaded_file = {}
            uploaded_file["filename"] = self.request.files["file"][0]["filename"]
            uploaded_file["content_type"] = self.request.files["file"][0]["content_type"]
            uploaded_file["body_len"] = total_file_size
            uploaded_file["body_filepath"] = f.filepath
            uploaded_file["body"] = f

            upload_time = time.time() - f.creation_date

            # file uploads works on chunk basis so that we count 1 the file upload
            # as a whole in function get_file_upload()
            for event in outcoming_event_monitored:
                if (
                    event["status_checker"](self._status_code)
                    and event["method"] == self.request.method
                    and event["handler_check"](self.request.uri)
                ):
                    EventTrack(event, upload_time)

            return uploaded_file

        except errors.FileTooBig:
            raise  # propagate the exception

        except Exception as exc:
            log.err("Error while handling file upload %s" % exc)
            return None
開發者ID:corvolino,項目名稱:GlobaLeaks,代碼行數:64,代碼來源:base.py


注:本文中的globaleaks.security.GLSecureTemporaryFile.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。