当前位置: 首页>>代码示例>>Python>>正文


Python Document.get_attachment方法代码示例

本文整理汇总了Python中cloudant.document.Document.get_attachment方法的典型用法代码示例。如果您正苦于以下问题:Python Document.get_attachment方法的具体用法?Python Document.get_attachment怎么用?Python Document.get_attachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cloudant.document.Document的用法示例。


在下文中一共展示了Document.get_attachment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_attachment_get

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get_attachment [as 别名]
    def test_attachment_get(self):
        """
        _test_attachment_get_
        """
        doc = Document(self.database, "DUCKUMENT")
        doc_id = 'DUCKUMENT'
        attachment = 'herpderp.txt'

        mock_get = mock.Mock()
        mock_get.raise_for_status = mock.Mock()
        mock_get.status_code = 200
        mock_get.json = mock.Mock()
        mock_get.json.return_value = {'_id': doc_id, '_rev': '1-abc'}

        mock_get_attch = mock.Mock()
        mock_get_attch.raise_for_status = mock.Mock()
        mock_get_attch.status_code = 200
        mock_get_attch.content = 'herp derp foo bar'

        self.mock_session.get.side_effect = [mock_get, mock_get_attch]

        resp = doc.get_attachment(attachment, attachment_type='binary')

        self.assertEqual(resp, mock_get_attch.content)
        self.assertEqual(self.mock_session.get.call_count, 2)
开发者ID:iblis17,项目名称:python-cloudant,代码行数:27,代码来源:document_test.py

示例2: download_file

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get_attachment [as 别名]
 def download_file(self, file_name, version):
     
     selector = {
         "file_name": file_name,
         "version": version
     }
     fields = ["version","_id","last_modified_time"];
     data = self.database.get_query_result(selector=selector, fields=fields)
     for my_doc in data:
         print my_doc;
         id = my_doc["_id"]
         last_modified_time = my_doc["last_modified_time"]
     
     document_val = Document(self.database, id);
     with open(file_name, 'wb') as f:
         document_val.get_attachment(file_name, write_to=file_name, attachment_type='binary')
     fileDecrypt = security.FileEncryption();
     fileDecrypt.decrypt_file(file_name, file_name);
开发者ID:ruchitengse,项目名称:Cloud-Projects,代码行数:20,代码来源:cloudantdb.py

示例3: open_doc

# 需要导入模块: from cloudant.document import Document [as 别名]
# 或者: from cloudant.document.Document import get_attachment [as 别名]
    def open_doc(self, docid, **params):
        """Get document from database

        Args:
        @param docid: str, document id to retrieve
        @param wrapper: callable. function that takes dict as a param.
        Used to wrap an object.
        @param **params: See doc api for parameters to use:
        http://wiki.apache.org/couchdb/HTTP_Document_API

        @return: dict, representation of CouchDB document as
         a dict.
        """
        wrapper = None
        if "wrapper" in params:
            wrapper = params.pop("wrapper")
        elif "schema" in params:
            schema = params.pop("schema")
            if not hasattr(schema, "wrap"):
                raise TypeError("invalid schema")
            wrapper = schema.wrap
        attachments = params.get('attachments', False)

        if six.PY2 and isinstance(docid, six.text_type):
            docid = docid.encode('utf-8')
        if six.PY3 and isinstance(docid, bytes):
            docid = docid.decode('utf-8')
        doc = Document(self.cloudant_database, docid)
        try:
            doc.fetch()
        except HTTPError as e:
            if e.response.status_code == 404:
                raise ResourceNotFound(json.loads(e.response.content.decode('utf-8'))['reason'])
            raise
        doc_dict = dict(doc)

        if attachments and '_attachments' in doc_dict:
            for attachment_name in doc_dict['_attachments']:
                attachment_data = doc.get_attachment(attachment_name, attachment_type='binary')
                doc_dict['_attachments'][attachment_name]['data'] = base64.b64encode(attachment_data)
                del doc_dict['_attachments'][attachment_name]['stub']
                del doc_dict['_attachments'][attachment_name]['length']

        if wrapper is not None:
            if not callable(wrapper):
                raise TypeError("wrapper isn't a callable")

            return wrapper(doc_dict)

        return doc_dict
开发者ID:dimagi,项目名称:couchdbkit,代码行数:52,代码来源:client.py


注:本文中的cloudant.document.Document.get_attachment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。