Python http.HTTPStatus.PARTIAL_CONTENT Examples

The following are 6 code examples of http.HTTPStatus.PARTIAL_CONTENT(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module http.HTTPStatus , or try the search function .
Example #1
Source File: webserver.py    From qutebrowser with GNU General Public License v3.0 6 votes vote down vote up
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))) 
Example #2
Source File: testing_farm.py    From packit-service with MIT License 5 votes vote down vote up
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 
Example #3
Source File: tasks.py    From packit-service with MIT License 5 votes vote down vote up
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 
Example #4
Source File: copr_builds.py    From packit-service with MIT License 5 votes vote down vote up
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 
Example #5
Source File: koji_builds.py    From packit-service with MIT License 5 votes vote down vote up
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 
Example #6
Source File: streaming_pure.py    From nano-dlna with MIT License 4 votes vote down vote up
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