Software /
code /
prosody
Annotate
tools/http-status-codes.lua @ 11148:1dc49accb58e
core.moduleapi: Return resource path from module:get_directory() (API BC)
:get_directory has so far returned the base directory of the current
module source code. This has worked well so far to load resources which
tend to be included in the same directory, but with the plugin installer
using LuaRocks, extra resources (e.g. templates and other assets) these
are saved in a completely different directory.
In be73df6765b9 core.modulemanager gained some code for finding that
directory and saving it in module.resource_path but now the question is
how this should be reflected in the API.
A survey of community modules suggest the vast majority use the
:get_directory method for locating templates and other assets, rather
than the code (which would use module:require instead).
Therefore this commit changes :get_directory to return the resource_path
when available. This should work for most modules.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 09 Oct 2020 16:37:15 +0200 |
parent | 9166:cce55767004a |
child | 12271:f31bb79f51d7 |
rev | line source |
---|---|
9166
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Generate net/http/codes.lua from IANA HTTP status code registry |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local xml = require "util.xml"; |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local registry = xml.parse(io.read("*a")); |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 io.write([[ |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local response_codes = { |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 -- Source: http://www.iana.org/assignments/http-status-codes |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 ]]); |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 for record in registry:get_child("registry"):childtags("record") do |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 -- Extract values |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local value = record:get_child_text("value"); |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local description = record:get_child_text("description"); |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local ref = record:get_child_text("xref"); |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 local code = tonumber(value); |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 -- Space between major groups |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 if code and code % 100 == 0 then |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 io.write("\n"); |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 end |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 -- Reserved and Unassigned entries should be not be included |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 if description == "Reserved" or description == "Unassigned" or description == "(Unused)" then |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 code = nil; |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 end |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 -- Non-empty references become comments |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 if ref and ref:find("%S") then |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 ref = " -- " .. ref; |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 else |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 ref = ""; |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 io.write((code and "\t[%d] = %q;%s\n" or "\t-- [%s] = %q;%s\n"):format(code or value, description, ref)); |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 end |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 io.write([[}; |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 for k,v in pairs(response_codes) do response_codes[k] = k.." "..v; end |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 return setmetatable(response_codes, { __index = function(_, k) return k.." Unassigned"; end }) |
cce55767004a
tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 ]]); |