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


Python DataFileElement.get_bytes方法代碼示例

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


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

示例1: test_get_bytes_no_file

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import get_bytes [as 別名]
 def test_get_bytes_no_file(self):
     e = DataFileElement("/not/a/valid/path.txt", readonly=True)
     # We currently expect, in the case where the filepath doesn't exist, to
     # get the same bytes as if the file existed and were empty.
     self.assertEqual(e.get_bytes(), six.b(""))
     # read-only status should have no effect.
     e = DataFileElement("/not/a/valid/path.txt", readonly=True)
     self.assertEqual(e.get_bytes(), six.b(""))
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:10,代碼來源:test_DataFileElement.py

示例2: iqr_ingest_file

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import get_bytes [as 別名]
        def iqr_ingest_file():
            """
            Ingest the file with the given UID, getting the path from the
            uploader.

            :return: string of data/descriptor element's UUID
            :rtype: str

            """
            # TODO: Add status dict with a "GET" method branch for getting that
            #       status information.

            fid = flask.request.form['fid']

            sid = self.get_current_iqr_session()

            self._log.debug("[%s::%s] Getting temporary filepath from "
                            "uploader module", sid, fid)
            upload_filepath = self.mod_upload.get_path_for_id(fid)
            self.mod_upload.clear_completed(fid)

            self._log.debug("[%s::%s] Moving uploaded file",
                            sid, fid)
            sess_upload = osp.join(self._iqr_work_dirs[sid],
                                   osp.basename(upload_filepath))
            os.rename(upload_filepath, sess_upload)

            # Record uploaded data as user example data for this session.
            upload_data = DataFileElement(sess_upload)
            uuid = upload_data.uuid()
            self._iqr_example_data[sid][uuid] = upload_data

            # Extend session ingest -- modifying
            self._log.debug("[%s::%s] Adding new data to session "
                            "external positives", sid, fid)
            data_b64 = base64.b64encode(upload_data.get_bytes())
            data_ct = upload_data.content_type()
            r = self._iqr_service.post('add_external_pos', sid=sid,
                                       base64=data_b64, content_type=data_ct)
            r.raise_for_status()

            return str(uuid)
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:44,代碼來源:iqr_search.py

示例3: test_get_bytes

# 需要導入模塊: from smqtk.representation.data_element.file_element import DataFileElement [as 別名]
# 或者: from smqtk.representation.data_element.file_element.DataFileElement import get_bytes [as 別名]
 def test_get_bytes(self):
     # Test with a known real file.
     test_file_path = os.path.join(TEST_DATA_DIR, 'text_file')
     e = DataFileElement(test_file_path)
     self.assertEqual(e.get_bytes(), six.b("Some text content.\n"))
開發者ID:Kitware,項目名稱:SMQTK,代碼行數:7,代碼來源:test_DataFileElement.py


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