本文整理汇总了Python中qiniu.config.get_default函数的典型用法代码示例。如果您正苦于以下问题:Python get_default函数的具体用法?Python get_default怎么用?Python get_default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_default函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _form_put
def _form_put(up_token, key, data, params, mime_type, crc, progress_handler=None):
fields = {}
if params:
for k, v in params.items():
fields[k] = str(v)
if crc:
fields['crc32'] = crc
if key is not None:
fields['key'] = key
fields['token'] = up_token
url = 'http://' + config.get_default('default_up_host') + '/'
name = key if key else 'filename'
r, info = http._post_file(url, data=fields, files={'file': (name, data, mime_type)})
if r is None and info.need_retry():
if info.connect_failed:
url = 'http://' + config.get_default('default_up_host_backup') + '/'
if hasattr(data, 'read') is False:
pass
elif hasattr(data, 'seek') and (not hasattr(data, 'seekable') or data.seekable()):
data.seek(0)
else:
return r, info
r, info = http._post_file(url, data=fields, files={'file': (name, data, mime_type)})
return r, info
示例2: _init
def _init():
global _session
_session = requests.Session()
adapter = requests.adapters.HTTPAdapter(
pool_connections=config.get_default('connection_pool'), pool_maxsize=config.get_default('connection_pool'),
max_retries=config.get_default('connection_retries'))
_session.mount('http://', adapter)
示例3: _init
def _init():
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(
pool_connections=config.get_default("connection_pool"),
pool_maxsize=config.get_default("connection_pool"),
max_retries=config.get_default("connection_retries"),
)
session.mount("http://", adapter)
global _session
_session = session
示例4: _put
def _put(up_token, key, data, params, mime_type, crc32, is_file=False):
fields = {}
if params:
for k, v in params.items():
fields[k] = str(v)
if crc32:
fields['crc32'] = crc32
if key is not None:
fields['key'] = key
fields['token'] = up_token
url = 'http://' + config.get_default('default_up_host') + '/'
name = key if key else 'filename'
r = None
exception = None
headers = {'User-Agent': config.USER_AGENT}
try:
r = _post(url, data=fields, files={'file': (name, data, mime_type)}, headers=headers)
except Exception as e:
exception = e
finally:
retry = _need_retry(r, exception)
if retry:
url = 'http://' + config.UPBACKUP_HOST + '/'
if is_file:
data.seek(0)
try:
r = _post(url, data=fields, files={'file': (name, data, mime_type)}, headers=headers)
except Exception as e:
raise QiniuClientException(str(e))
return _ret(r)
示例5: make_block
def make_block(self, block, block_size):
crc = crc32(block)
url = self.block_url(config.get_default('default_up_host'), block_size)
r = None
exception = None
try:
r = self.post(url, block)
except Exception as e:
exception = e
finally:
retry = _need_retry(r, exception)
if retry:
url = self.block_url(config.UPBACKUP_HOST, block_size)
try:
r = self.post(url, block)
except Exception as e:
raise QiniuClientException(str(e))
ret = _ret(r)
if ret['crc32'] != crc:
raise QiniuServiceException(
r.status_code, 'unmatch crc checksum', r.headers['X-Reqid'])
return ret
示例6: _get_with_qiniu_mac
def _get_with_qiniu_mac(url, params, auth):
try:
r = requests.get(
url, params=params, auth=qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None,
timeout=config.get_default('connection_timeout'), headers=_headers)
except Exception as e:
return None, ResponseInfo(None, e)
return __return_wrapper(r)
示例7: _get
def _get(url, params, auth):
try:
r = requests.get(
url, params=params, auth=RequestsAuth(auth),
timeout=config.get_default('connection_timeout'), headers=_headers)
except Exception as e:
return None, ResponseInfo(None, e)
return __return_wrapper(r)
示例8: _post_with_qiniu_mac
def _post_with_qiniu_mac(url, data, auth):
qn_auth = qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None
timeout = config.get_default('connection_timeout')
try:
r = requests.post(url, json=data, auth=qn_auth, timeout=timeout, headers=_headers)
except Exception as e:
return None, ResponseInfo(None, e)
return __return_wrapper(r)
示例9: _post
def _post(url, data, files, auth):
if _session is None:
_init()
try:
r = _session.post(
url, data=data, files=files, auth=auth, headers=_headers, timeout=config.get_default('connection_timeout'))
except Exception as e:
return None, ResponseInfo(None, e)
return __return_wrapper(r)
示例10: upload
def upload(self):
"""上传操作"""
self.blockStatus = []
host = config.get_default('default_up_host')
for block in _file_iter(self.input_stream, config._BLOCK_SIZE):
length = len(block)
crc = crc32(block)
ret, info = self.make_block(block, length, host)
if ret is None and not info.need_retry:
return ret, info
if info.connect_failed:
host = config.get_default('default_up_host_backup')
if info.need_retry or crc != ret['crc32']:
ret, info = self.make_block(block, length, host)
if ret is None or crc != ret['crc32']:
return ret, info
self.blockStatus.append(ret)
if(callable(self.progress_handler)):
self.progress_handler(((len(self.blockStatus) - 1) * config._BLOCK_SIZE)+length, self.size)
return self.make_file(host)
示例11: upload
def upload(self):
"""上传操作"""
self.blockStatus = []
host = config.get_default('default_zone').get_up_host_by_token(self.up_token)
offset = self.recovery_from_record()
for block in _file_iter(self.input_stream, config._BLOCK_SIZE, offset):
length = len(block)
crc = crc32(block)
ret, info = self.make_block(block, length, host)
if ret is None and not info.need_retry():
return ret, info
if info.connect_failed():
host = config.get_default('default_zone').get_up_host_backup_by_token(self.up_token)
if info.need_retry() or crc != ret['crc32']:
ret, info = self.make_block(block, length, host)
if ret is None or crc != ret['crc32']:
return ret, info
self.blockStatus.append(ret)
offset += length
self.record_upload_progress(offset)
if(callable(self.progress_handler)):
self.progress_handler(((len(self.blockStatus) - 1) * config._BLOCK_SIZE)+length, self.size)
return self.make_file(host)
示例12: _post
def _post(url, data, files, auth, headers=None):
if _session is None:
_init()
try:
post_headers = _headers.copy()
if headers is not None:
for k, v in headers.items():
post_headers.update({k: v})
r = _session.post(
url, data=data, files=files, auth=auth, headers=post_headers,
timeout=config.get_default('connection_timeout'))
except Exception as e:
return None, ResponseInfo(None, e)
return __return_wrapper(r)
示例13: pfop
def pfop(auth, bucket, key, fops, pipeline=None, notify_url=None):
ops = '|'.join(fops)
data = {'bucket': bucket, 'key': key, 'fops': ops}
if pipeline:
data['pipeline'] = pipeline
if notify_url:
data['notifyURL'] = notify_url
headers = {'User-Agent': config.USER_AGENT}
url = 'http://{0}/pfop'.format(config.API_HOST)
r = requests.post(
url, data=data, auth=RequestsAuth(auth),
timeout=config.get_default('connection_timeout'), headers=headers)
return _ret(r)
示例14: list
def list(self, bucket, prefix=None, marker=None, limit=None, delimiter=None):
"""前缀查询:
1. 首次请求 marker = None
2. 无论 err 值如何,均应该先看 ret.get('items') 是否有内容
3. 如果后续没有更多数据,err 返回 EOF,marker 返回 None(但不通过该特征来判断是否结束)
具体规格参考:
http://developer.qiniu.com/docs/v6/api/reference/rs/list.html
Args:
bucket: 空间名
prefix: 列举前缀
marker: 列举标识符
limit: 单次列举个数限制
delimiter: 指定目录分隔符
Returns:
一个dict变量,类似 {"hash": "<Hash string>", "key": "<Key string>"}
一个ResponseInfo对象
一个EOF信息。
"""
options = {
'bucket': bucket,
}
if marker is not None:
options['marker'] = marker
if limit is not None:
options['limit'] = limit
if prefix is not None:
options['prefix'] = prefix
if delimiter is not None:
options['delimiter'] = delimiter
url = '{0}/list'.format(config.get_default('default_rsf_host'))
ret, info = self.__get(url, options)
eof = False
if ret and not ret.get('marker'):
eof = True
return ret, eof, info
示例15: make_file
def make_file(self):
url = self.make_file_url(config.get_default('default_up_host'))
body = ','.join([status['ctx'] for status in self.blockStatus])
r = None
exception = None
try:
r = self.post(url, body)
except Exception as e:
exception = e
finally:
retry = _need_retry(r, exception)
if retry:
url = self.make_file_url(config.UPBACKUP_HOST)
try:
r = self.post(url, body)
except Exception as e:
raise QiniuClientException(str(e))
return _ret(r)