110 lines
6.1 KiB
Python
110 lines
6.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
from typing import Iterable
|
|
import albert
|
|
|
|
md_iid = '5.0'
|
|
md_name = "HTTP Status Codes"
|
|
md_description = "Show the list of HTTP Status Codes"
|
|
md_version = "1.0.0"
|
|
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}".casefold()
|
|
|
|
def is_match(self, query: str) -> bool:
|
|
return query.casefold() in self.match
|
|
|
|
codes = [
|
|
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: str) -> Iterable[albert.StandardItem]:
|
|
for code in codes:
|
|
if not query or code.is_match(query):
|
|
# https://albertlauncher.github.io/reference/classalbert_1_1util_1_1StandardItem.html
|
|
yield albert.StandardItem(
|
|
id=str(code.code),
|
|
text=f"{code.code} {code.name}",
|
|
icon_factory=lambda: albert.Icon.grapheme("‣"),
|
|
subtext=code.description,
|
|
actions=[]
|
|
)
|
|
|
|
class Plugin(albert.PluginInstance, albert.GeneratorQueryHandler):
|
|
|
|
def __init__(self):
|
|
albert.PluginInstance.__init__(self)
|
|
albert.GeneratorQueryHandler.__init__(self)
|
|
|
|
def defaultTrigger(self):
|
|
return 'http '
|
|
|
|
# https://albertlauncher.github.io/reference/classalbert_1_1Query.html
|
|
def items(self, ctx):
|
|
yield [i for i in build_query_items(ctx.query.strip())] |