本文整理汇总了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
示例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()
示例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