本文整理汇总了Python中httplib.PRECONDITION_FAILED属性的典型用法代码示例。如果您正苦于以下问题:Python httplib.PRECONDITION_FAILED属性的具体用法?Python httplib.PRECONDITION_FAILED怎么用?Python httplib.PRECONDITION_FAILED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类httplib
的用法示例。
在下文中一共展示了httplib.PRECONDITION_FAILED属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disable_chrome_device
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import PRECONDITION_FAILED [as 别名]
def disable_chrome_device(self, device_id):
"""Disable a Chrome device within an organization.
Args:
device_id: String, The unique Chrome device id.
Raises:
DirectoryRPCError: An error when the RPC call to the directory API fails.
"""
logging.info('Disabling chrome device %s.', device_id)
try:
self._client.chromeosdevices().action(
customerId=constants.CUSTOMER_ID,
resourceId=device_id,
body={
'action': 'disable'
}).execute()
except errors.HttpError as err:
if err.resp.status == httplib.PRECONDITION_FAILED:
raise DeviceAlreadyDisabledError(err.resp.reason)
logging.error(
'Directory API call to disable Chrome device failed with a %s '
'exception because %s.', str(type(err)), err.resp.reason)
raise DirectoryRPCError(err.resp.reason)
示例2: Dispatch
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import PRECONDITION_FAILED [as 别名]
def Dispatch(self, request, outfile, base_env_dict=None):
"""Reads the file and returns the response status and data."""
full_path = self._path_adjuster.AdjustPath(request.path)
status, data = self._read_data_file(full_path)
content_type = self._static_file_config_matcher.GetMimeType(request.path)
static_file = self._static_file_config_matcher.IsStaticFile(request.path)
expiration = self._static_file_config_matcher.GetExpiration(request.path)
current_etag = self.CreateEtag(data)
if_match_etag = request.headers.get('if-match', None)
if_none_match_etag = request.headers.get('if-none-match', '').split(',')
http_headers = self._static_file_config_matcher.GetHttpHeaders(request.path)
def WriteHeader(name, value):
if http_headers.Get(name) is None:
outfile.write('%s: %s\r\n' % (name, value))
if if_match_etag and not self._CheckETagMatches(if_match_etag.split(','),
current_etag,
False):
outfile.write('Status: %s\r\n' % httplib.PRECONDITION_FAILED)
WriteHeader('ETag', current_etag)
outfile.write('\r\n')
elif self._CheckETagMatches(if_none_match_etag, current_etag, True):
outfile.write('Status: %s\r\n' % httplib.NOT_MODIFIED)
WriteHeader('ETag', current_etag)
outfile.write('\r\n')
else:
outfile.write('Status: %d\r\n' % status)
WriteHeader('Content-Type', content_type)
if expiration:
fmt = email.Utils.formatdate
WriteHeader('Expires', fmt(time.time() + expiration, usegmt=True))
WriteHeader('Cache-Control', 'public, max-age=%i' % expiration)
if static_file:
WriteHeader('ETag', '"%s"' % current_etag)
for header in http_headers.iteritems():
outfile.write('%s: %s\r\n' % header)
outfile.write('\r\n')
outfile.write(data)
示例3: _handle_put
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import PRECONDITION_FAILED [as 别名]
def _handle_put(gcs_stub, filename, param_dict, headers, payload):
"""Handle PUT."""
if _iscopy(headers):
return _copy(gcs_stub, filename, headers)
token = _get_param('upload_id', param_dict)
content_range = _ContentRange(headers)
if _is_query_progress(content_range):
return _find_progress(gcs_stub, filename, token)
if not content_range.value:
raise ValueError('Missing header content-range.', httplib.BAD_REQUEST)
if (headers.get('x-goog-if-generation-match', None) == '0' and
gcs_stub.head_object(filename) is not None):
return _FakeUrlFetchResult(httplib.PRECONDITION_FAILED, {}, '')
if not token:
if content_range.length is None:
raise ValueError('Content-Range must have a final length.',
httplib.BAD_REQUEST)
elif not content_range.no_data and content_range.range[0] != 0:
raise ValueError('Content-Range must specify complete object.',
httplib.BAD_REQUEST)
else:
token = gcs_stub.post_start_creation(filename, headers)
try:
gcs_stub.put_continue_creation(token,
payload,
content_range.range,
content_range.length)
except ValueError, e:
return _FakeUrlFetchResult(e.args[1], {}, e.args[0])