From 1b0b2b0cf1dd328c4fe5f2c5fe015adf43e53e65 Mon Sep 17 00:00:00 2001 From: Felix Boers Date: Thu, 18 Dec 2025 11:56:32 +0100 Subject: [PATCH] initial --- .gitignore | 2 + .vscode/settings.json | 3 ++ LICENSE | 21 ++++++++ Makefile | 7 +++ README.md | 31 ++++++++++++ __init__.py | 114 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 178 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 __init__.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cafd598 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +.venv/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7e68766 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python-envs.pythonProjects": [] +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2ea48aa --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Peter De Bruycker + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c97cc83 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +INSTALL_DIR:=$(HOME)/.local/share/albert/python/plugins + +install: + ln -fs $(ROOT_DIR)/ $(INSTALL_DIR)/albert-plugin-python-http-status-codes + echo $(ROOT_DIR) + echo $(INSTALL_DIR) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a2eb8ac --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# albert-http-status-codes + +## Installation + +1. Locate the `modules` directory in the Python extension data directory. + +The data directories reside in the data directories of the application defined by Qt. + +``` +~/.local/share/albert/python/plugins +``` + +2. Clone this repository into your `modules` directory. + +```bash +cd /path/to/modules + +git clone https://gitea.felix-boers.de/fboers/albert-plugin-python-http-status-codes.git +``` + +3. Enable the extension in the settings under `Extensions`. + +## Usage + +Show the HTTP status codes in a popup. + +Synopsis: `http 200` + +## Contributing + +If you have any questions, suggestions, or issues, please feel free to open an issue or pull request. diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..9885a30 --- /dev/null +++ b/__init__.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +from typing import List +import albert + +md_iid = '4.0' +md_name = "HTTP Status Codes" +md_description = "Show the list of HTTP Status Codes" +md_version = "0.0.1" +md_license = "MIT" +md_url = "https://gitea.felix-boers.de/fboers/albert-plugin-python-http-status-codes" +md_authors = ["@felixboers"] +md_maintainers = ["@felixboers"] + +class Code: + def __init__(self, code: int, name: str, description: str): + self.code = code + self.name = name + self.description = description + self.match = f"{code} {name}" + +def build_code_list(): + return [ + Code(100, "Continue", "The client should continue the request."), + Code(101, "Switching Protocols", "The transmission protocol is changed according to the client's request."), + Code(102, "Processing", "A time-consuming request is being processed."), + Code(200, "OK", "The request was successful."), + Code(201, "Created", "A new resource was created."), + Code(202, "Accepted", "The request has been accepted but not yet processed."), + Code(203, "Non-Authoritative Information", "Meta information from a cache rather than the origin server."), + Code(204, "No Content", "The request was successful but there is no content."), + Code(205, "Reset Content", "The request was successful and the document should be reset."), + Code(206, "Partial Content", "Partial resource delivered successfully."), + Code(207, "Multi-Status", "Multiple operations performed; statuses in body."), + Code(208, "Already Reported", "Some WebDAV members were already reported."), + Code(301, "Moved Permanently", "The resource has a new permanent URL."), + Code(302, "Found", "The resource is temporarily under a different URL."), + Code(305, "Use Proxy", "Client should retrieve resource via proxy (deprecated)."), + Code(307, "Temporary Redirect", "Temporary location, same method must be used."), + Code(308, "Permanent Redirect", "Permanent redirect; same method used for future."), + Code(400, "Bad Request", "The request is invalid."), + Code(401, "Unauthorized", "Authentication is required."), + Code(402, "Payment Required", "Payment is required."), + Code(403, "Forbidden", "The request is forbidden."), + Code(404, "Not Found", "The server could not find the requested resource."), + Code(405, "Method Not Allowed", "The method is known but not allowed."), + Code(406, "Not Acceptable", "No acceptable representation available."), + Code(407, "Proxy Authentication Required", "Proxy authentication needed."), + Code(408, "Request Timeout", "Server timed out waiting for full request."), + Code(409, "Conflict", "Request conflicts with current state."), + Code(410, "Gone", "The resource is no longer available."), + Code(411, "Length Required", "Content-Length header required."), + Code(412, "Precondition Failed", "A precondition failed."), + Code(413, "Payload Too Large", "Payload is too large."), + Code(414, "URI Too Long", "Request-URI is too long."), + Code(415, "Unsupported Media Type", "Media type not supported."), + Code(416, "Range Not Satisfiable", "Requested range not satisfiable."), + Code(417, "Expectation Failed", "Expectation given in headers could not be met."), + Code(418, "I'm a teapot", "Teapot refuses to brew coffee."), + Code(420, "Enhance Your Calm", "Connection limit per user exceeded."), + Code(421, "Misdirected Request", "Request directed at incapable server."), + Code(422, "Unprocessable Entity", "Semantic errors prevent processing."), + Code(423, "Locked", "Resource is currently locked."), + Code(424, "Failed Dependency", "Request failed due to previous failure."), + Code(426, "Upgrade Required", "Protocol upgrade required."), + Code(428, "Precondition Required", "Precondition required for processing."), + Code(429, "Too Many Requests", "Too many requests from the client."), + Code(431, "Request Header Fields Too Large", "Header fields too large."), + Code(444, "Connection Closed Without Response", "Server closed connection without response."), + Code(451, "Unavailable For Legal Reasons", "Resource unavailable for legal reasons."), + Code(499, "Client Closed Request", "Client closed connection before response."), + Code(500, "Internal Server Error", "Server encountered an internal error."), + Code(501, "Not Implemented", "Server does not support the functionality."), + Code(502, "Bad Gateway", "Upstream server returned an invalid response."), + Code(503, "Service Unavailable", "Service is unavailable."), + Code(504, "Gateway Timeout", "Upstream server did not respond in time."), + Code(505, "HTTP Version Not Supported", "HTTP version is not supported."), + Code(506, "Variant Also Negotiates", "Negotiation error."), + Code(507, "Insufficient Storage", "Insufficient storage for the request."), + Code(508, "Loop Detected", "Infinite loop detected."), + Code(510, "Not Extended", "Further extensions required."), + Code(511, "Network Authentication Required", "Network authentication required."), + Code(599, "Network Connect Timeout Error", "Network connection timeout error."), + ] + +def build_query_items(query, codes: List[Code]): + results = [] + for code in codes: + if query.string.casefold() in code.match.casefold(): + results.append( + albert.StandardItem( + id='uuid', + text=f"{code.code} {code.name}", + subtext=code.description, + actions=[] + ) + ) + return results + +class Plugin(albert.PluginInstance, albert.TriggerQueryHandler): + + def __init__(self): + albert.PluginInstance.__init__(self) + albert.TriggerQueryHandler.__init__(self) + + def defaultTrigger(self): + return 'http ' + + # https://albertlauncher.github.io/reference/classalbert_1_1Query.html + def handleTriggerQuery(self, query): + if not query.isValid: + return + + codes = build_code_list() + query.add(build_query_items(query, codes)) \ No newline at end of file