本文整理匯總了Python中http.HTTPStatus.PARTIAL_CONTENT屬性的典型用法代碼示例。如果您正苦於以下問題:Python HTTPStatus.PARTIAL_CONTENT屬性的具體用法?Python HTTPStatus.PARTIAL_CONTENT怎麽用?Python HTTPStatus.PARTIAL_CONTENT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類http.HTTPStatus
的用法示例。
在下文中一共展示了HTTPStatus.PARTIAL_CONTENT屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _check_status
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import PARTIAL_CONTENT [as 別名]
def _check_status(self):
"""Check if the http status is what we expected."""
path_to_statuses = {
'/favicon.ico': [HTTPStatus.OK, HTTPStatus.PARTIAL_CONTENT],
'/does-not-exist': [HTTPStatus.NOT_FOUND],
'/does-not-exist-2': [HTTPStatus.NOT_FOUND],
'/404': [HTTPStatus.NOT_FOUND],
'/redirect-later': [HTTPStatus.FOUND],
'/redirect-self': [HTTPStatus.FOUND],
'/redirect-to': [HTTPStatus.FOUND],
'/relative-redirect': [HTTPStatus.FOUND],
'/absolute-redirect': [HTTPStatus.FOUND],
'/cookies/set': [HTTPStatus.FOUND],
'/500-inline': [HTTPStatus.INTERNAL_SERVER_ERROR],
'/500': [HTTPStatus.INTERNAL_SERVER_ERROR],
}
for i in range(15):
path_to_statuses['/redirect/{}'.format(i)] = [HTTPStatus.FOUND]
for suffix in ['', '1', '2', '3', '4', '5', '6']:
key = ('/basic-auth/user{suffix}/password{suffix}'
.format(suffix=suffix))
path_to_statuses[key] = [HTTPStatus.UNAUTHORIZED, HTTPStatus.OK]
default_statuses = [HTTPStatus.OK, HTTPStatus.NOT_MODIFIED]
sanitized = QUrl('http://localhost' + self.path).path() # Remove ?foo
expected_statuses = path_to_statuses.get(sanitized, default_statuses)
if self.status not in expected_statuses:
raise AssertionError(
"{} loaded with status {} but expected {}".format(
sanitized, self.status,
' / '.join(repr(e) for e in expected_statuses)))
示例2: get
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import PARTIAL_CONTENT [as 別名]
def get(self):
""" List all Testing Farm results. """
result = []
first, last = indices()
# results have nothing other than ref in common, so it doesnt make sense to
# merge them like copr builds
for tf_result in TFTTestRunModel.get_range(first, last):
result_dict = {
"pipeline_id": tf_result.pipeline_id,
"ref": tf_result.commit_sha,
"status": tf_result.status,
"target": tf_result.target,
"web_url": tf_result.web_url,
"pr_id": tf_result.get_pr_id(),
}
project = tf_result.get_project()
result_dict["repo_namespace"] = project.namespace
result_dict["repo_name"] = project.repo_name
result.append(result_dict)
resp = make_response(dumps(result), HTTPStatus.PARTIAL_CONTENT)
resp.headers["Content-Range"] = f"test-results {first + 1}-{last}/*"
resp.headers["Content-Type"] = "application/json"
resp.headers["Access-Control-Allow-Origin"] = "*"
return resp
示例3: get
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import PARTIAL_CONTENT [as 別名]
def get(self):
""" List all Celery tasks / jobs """
first, last = indices()
tasks = []
for task in islice(TaskResultModel.get_all(), first, last):
data = task.to_dict()
data["event"] = Event.ts2str(data["event"])
tasks.append(data)
resp = make_response(dumps(tasks), HTTPStatus.PARTIAL_CONTENT)
resp.headers["Content-Range"] = f"tasks {first+1}-{last}/{len(tasks)}"
resp.headers["Content-Type"] = "application/json"
return resp
示例4: get
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import PARTIAL_CONTENT [as 別名]
def get(self):
""" List all Copr builds. """
# Return relevant info thats concise
# Usecases like the packit-dashboard copr-builds table
result = []
first, last = indices()
for build in CoprBuildModel.get_merged_chroots(first, last):
build_info = CoprBuildModel.get_by_build_id(build.build_id, None)
project_info = build_info.get_project()
build_dict = {
"project": build_info.project_name,
"build_id": build.build_id,
"status_per_chroot": {},
"build_submitted_time": optional_time(build_info.build_submitted_time),
"web_url": build_info.web_url,
"ref": build_info.commit_sha,
"pr_id": build_info.get_pr_id(),
"repo_namespace": project_info.namespace,
"repo_name": project_info.repo_name,
}
for count, chroot in enumerate(build.target):
# [0] because sqlalchemy returns a single element sub-list
build_dict["status_per_chroot"][chroot[0]] = build.status[count][0]
result.append(build_dict)
resp = make_response(dumps(result), HTTPStatus.PARTIAL_CONTENT)
resp.headers["Content-Range"] = f"copr-builds {first + 1}-{last}/*"
resp.headers["Content-Type"] = "application/json"
resp.headers["Access-Control-Allow-Origin"] = "*"
return resp
示例5: get
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import PARTIAL_CONTENT [as 別名]
def get(self):
""" List all Koji builds. """
result = []
first, last = indices()
for build in islice(KojiBuildModel.get_all(), first, last):
result.append(build.api_structure)
resp = make_response(dumps(result), HTTPStatus.PARTIAL_CONTENT)
resp.headers["Content-Range"] = f"koji-builds {first + 1}-{last}/{len(result)}"
resp.headers["Content-Type"] = "application/json"
resp.headers["Access-Control-Allow-Origin"] = "*"
return resp
示例6: send_head
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import PARTIAL_CONTENT [as 別名]
def send_head(self):
file_name = self.path[1:]
ctype = self.guess_type(file_name)
f = None
try:
file_path = self.files_serve[file_name]
f = open(file_path, 'rb')
except Exception:
self.send_error(HTTPStatus.NOT_FOUND, "File not found")
return (None, 0, 0)
try:
fs = os.fstat(f.fileno())
size_full = fs[6]
if "Range" in self.headers:
range_value = re.search("bytes=(?P<start>\d+)?-(?P<end>\d+)?",
self.headers["Range"])
start_range = max(int(range_value.group("start") or 0), 0)
end_range = min(int(range_value.group("end")
or (size_full - 1)), (size_full - 1))
size_partial = end_range - start_range + 1
assert size_partial > 0
self.send_response(HTTPStatus.PARTIAL_CONTENT)
self.send_header(
"Content-Range",
"bytes "
"{0}-{1}/{2}".format(start_range, end_range, size_full))
else:
start_range = 0
end_range = size_full - 1
size_partial = size_full
self.send_response(HTTPStatus.OK)
self.send_header("Accept-Ranges", "bytes")
# self.send_header("Cache-Control", "public, max-age=0")
self.send_header(
"Last-Modified", self.date_time_string(fs.st_mtime))
self.send_header("Content-type", ctype)
self.send_header("Content-Length", str(size_partial))
self.send_header("Connection", "close")
self.end_headers()
return (f, start_range, end_range)
except Exception:
f.close()
raise