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


Python Server.put_attachment方法代码示例

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


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

示例1: OnScreenshot

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import put_attachment [as 别名]
	def OnScreenshot(self, event):

		wx.MessageBox("You got 5 seconds to go", "Screenshot Warning") 
		time.sleep(5)
		sfile = REGEXP.sub("","screenshot{0}".format(datetime.now()))
		sfile = "{0}.png".format(sfile)
		screenshot = Screenshot(filename = sfile)
		try:
			blog = Server(self.URL)[BLOG]
			doc = blog[self.blogpost]
			f = open(sfile,"rb")
			blog.put_attachment(doc,f, sfile)
			f.close()
			self.OnLCtrl(None)
		except:
			pass
开发者ID:batok,项目名称:couchdb-wxpython,代码行数:18,代码来源:couchdbgui.py

示例2: CouchDBUploadBackend

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import put_attachment [as 别名]
class CouchDBUploadBackend(AbstractUploadBackend):
    """Stores the file in a CouchDB Backend

    Requirements: couchdb

    Settings:
    AJAXUPLOAD_COUCHDB_HOST:  Specify the host of your MongoDB server.
     Defaults to http://localhost:5984 if not specified.

    Arguments:
    db (required): Specify the database within CouchDB you wish to use

    Context returned:
    None

    """
    def __init__(self, *args, **kwargs):
        self.database = kwargs.pop('db')
        self.connection = None
        self._dest = None

        super(CouchDBUploadBackend, self).__init__(*args, **kwargs)

    def setup(self, request, filename, *args, **kwargs):
        self.connection = Server(getattr(settings,
                                         'AJAXUPLOAD_COUCHDB_HOST',
                                         'http://localhost:5984')
        )[self.database]
        self._dest = TemporaryFile()

    def upload_chunk(self, chunk, *args, **kwargs):
        self._dest.write(chunk)

    def upload_complete(self, request, filename, *args, **kwargs):
        self._dest.seek(0)
        doc_id = uuid4().hex
        # create doc by self defined uuid. We need the _rev for attachment
        doc = self.connection[doc_id] = {'_id':doc_id,
                                         # append anything you like maybe from
                                         # request
                                         }
        # mimetype is guessed by extension.
        # We don't put the whole document back in the put_attachment request
        self.connection.put_attachment({'_id':doc['_id'], '_rev':doc['_rev']},
                                        self._dest,
                                        filename=filename)
        self._dest.close()
开发者ID:bashu,项目名称:django-ajax-uploader,代码行数:49,代码来源:couch.py

示例3: OnScreenshotSeries

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import put_attachment [as 别名]
	def OnScreenshotSeries(self, event):
		scnumber = wx.GetTextFromUser("How many screenshots every 3 seconds you want", "Screen Shot Series", default_value = "10")
		time.sleep(5)
		scseries = []
		try:
			for i in range(int(scnumber)):
				sfile = REGEXP.sub("","screenshot{0}".format(datetime.now()))
				sfile = "{0}.png".format(sfile)
				screenshot = Screenshot(filename = sfile)
				scseries.append( sfile )
				time.sleep(3)
		except:
			pass
		try:
			blog = Server(self.URL)[BLOG]
			doc = blog[self.blogpost]
			for fname in scseries:
				f = open(fname,"rb")
				blog.put_attachment(doc,f, fname)
				f.close()
			self.OnLCtrl(None)
		except:
			pass
开发者ID:batok,项目名称:couchdb-wxpython,代码行数:25,代码来源:couchdbgui.py


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