本文整理匯總了Python中cloudstorage.RetryParams方法的典型用法代碼示例。如果您正苦於以下問題:Python cloudstorage.RetryParams方法的具體用法?Python cloudstorage.RetryParams怎麽用?Python cloudstorage.RetryParams使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloudstorage
的用法示例。
在下文中一共展示了cloudstorage.RetryParams方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import RetryParams [as 別名]
def __init__(self, *args, **kwargs):
# webapp framework invokes initialize after __init__.
# webapp2 framework invokes initialize within __init__.
# Python27 runtime swap webapp with webapp2 underneath us.
# Since initialize will conditionally change this field,
# it needs to be set before calling super's __init__.
self._preprocess_success = False
super(TaskQueueHandler, self).__init__(*args, **kwargs)
if cloudstorage:
cloudstorage.set_default_retry_params(
cloudstorage.RetryParams(
min_retries=5,
max_retries=10,
urlfetch_timeout=parameters._GCS_URLFETCH_TIMEOUT_SEC,
save_access_token=True,
_user_agent=self._DEFAULT_USER_AGENT))
示例2: upload
# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import RetryParams [as 別名]
def upload(self, attachment, content):
''' Uploads a file to the default cloud storage bucket
Args:
attachment - The models.Attachment metadata for the file
content - The file content
'''
filename = '/{}/{}'.format(self.bucket_name,
attachment.stored_filename)
write_retry_params = gcs.RetryParams(backoff_factor=1.1)
gcs_file = gcs.open(
filename,
'w',
content_type=attachment.mime_type,
retry_params=write_retry_params)
gcs_file.write(content)
gcs_file.close()
示例3: create_file
# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import RetryParams [as 別名]
def create_file(self, filename):
"""Create a file."""
self.response.write('Creating file {}\n'.format(filename))
# The retry_params specified in the open call will override the default
# retry params for this particular file handle.
write_retry_params = cloudstorage.RetryParams(backoff_factor=1.1)
with cloudstorage.open(
filename, 'w', content_type='text/plain', options={
'x-goog-meta-foo': 'foo', 'x-goog-meta-bar': 'bar'},
retry_params=write_retry_params) as cloudstorage_file:
cloudstorage_file.write('abcde\n')
cloudstorage_file.write('f'*1024*4 + '\n')
self.tmp_filenames_to_clean_up.append(filename)
# [END write]
# [START read]
示例4: _make_retry_params
# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import RetryParams [as 別名]
def _make_retry_params():
"""RetryParams structure configured to store access token in Datastore."""
# Note that 'cloudstorage.set_default_retry_params' function stores retry
# params in per-request thread local storage, which means it needs to be
# called for each request. Since we are wrapping all cloudstorage library
# calls anyway, it's more convenient just to pass RetryParams explicitly,
# instead of making it a default for request with 'set_default_retry_params'.
return cloudstorage.RetryParams(save_access_token=True)
示例5: post
# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import RetryParams [as 別名]
def post():
form = PhotoForm(CombinedMultiDict((request.files, request.form)))
if request.method == 'POST' and form.validate():
filename = '%s.%s' % (str(uuid.uuid4()),
secure_filename(form.input_photo.data.filename))
content_type = content_types[filename.split('.')[-1]]
write_retry_params = gcs.RetryParams(backoff_factor=1.1)
gcs_file = gcs.open('/%s/%s' % (bucket_name, filename), 'w',
retry_params=write_retry_params,
content_type=content_type,
options={'x-goog-acl': 'authenticated-read'})
for _ in form.input_photo.data.stream:
gcs_file.write(_)
gcs_file.close()
labels = get_labels(filename)
tags = [translate_text(label.description) for label in labels]
entity = Photo(id=filename, tags=tags,
parent=ndb.Key('User', 'default'))
entity.put()
for tag in tags:
entity = ndb.Key('User', 'default', 'Tags', tag).get()
if entity:
entity.count += 1
else:
entity = Tags(count=1, id=tag,
parent=ndb.Key('User', 'default'))
entity.put()
return render_template('post.html', storage_path=storage_path,
filename=filename, tags=tags)
else:
return redirect(url_for('photos'))
示例6: write
# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import RetryParams [as 別名]
def write(self, path, content):
write_retry_params = gcs.RetryParams(backoff_factor=1.1)
gcs_file = gcs.open(path, 'w', options={'x-goog-acl': self.acl}, retry_params=write_retry_params)
gcs_file.write(content)
gcs_file.close()
示例7: delete_file_or_list
# 需要導入模塊: import cloudstorage [as 別名]
# 或者: from cloudstorage import RetryParams [as 別名]
def delete_file_or_list(self, filename_or_list):
if isinstance(filename_or_list, list):
for filename in filename_or_list:
self.delete_file_or_list(filename)
else:
filename = filename_or_list
retry_params = cloudstorage.RetryParams(min_retries=self._MIN_RETRIES,
max_retries=self._MAX_RETRIES)
# pylint: disable=bare-except
try:
cloudstorage.delete(filename, retry_params)
except:
pass