diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2022-03-18 12:12:39 +0100 |
---|---|---|
committer | Caleb Maclennan <caleb@alerque.com> | 2022-03-19 17:13:15 +0300 |
commit | 601ad8d59f11d7180015d0ecfb9d0a8d67f6f5c1 (patch) | |
tree | e3b9c152b9ff8a431d1431edb0a42d051d256f13 /src | |
parent | 480c05257211b3e566f33fdf8cf051233e2dab30 (diff) | |
download | luasocket-601ad8d59f11d7180015d0ecfb9d0a8d67f6f5c1.tar.gz luasocket-601ad8d59f11d7180015d0ecfb9d0a8d67f6f5c1.tar.bz2 luasocket-601ad8d59f11d7180015d0ecfb9d0a8d67f6f5c1.zip |
refactor: Address issues raised by linter
Diffstat (limited to 'src')
-rw-r--r-- | src/ftp.lua | 14 | ||||
-rw-r--r-- | src/http.lua | 11 | ||||
-rw-r--r-- | src/ltn12.lua | 3 | ||||
-rw-r--r-- | src/mbox.lua | 13 | ||||
-rw-r--r-- | src/mime.lua | 12 | ||||
-rw-r--r-- | src/url.lua | 6 |
6 files changed, 24 insertions, 35 deletions
diff --git a/src/ftp.lua b/src/ftp.lua index bd528ca..0ebc508 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
@@ -56,7 +56,7 @@ end | |||
56 | 56 | ||
57 | function metat.__index:login(user, password) | 57 | function metat.__index:login(user, password) |
58 | self.try(self.tp:command("user", user or _M.USER)) | 58 | self.try(self.tp:command("user", user or _M.USER)) |
59 | local code, reply = self.try(self.tp:check{"2..", 331}) | 59 | local code, _ = self.try(self.tp:check{"2..", 331}) |
60 | if code == 331 then | 60 | if code == 331 then |
61 | self.try(self.tp:command("pass", password or _M.PASSWORD)) | 61 | self.try(self.tp:command("pass", password or _M.PASSWORD)) |
62 | self.try(self.tp:check("2..")) | 62 | self.try(self.tp:check("2..")) |
@@ -66,7 +66,7 @@ end | |||
66 | 66 | ||
67 | function metat.__index:pasv() | 67 | function metat.__index:pasv() |
68 | self.try(self.tp:command("pasv")) | 68 | self.try(self.tp:command("pasv")) |
69 | local code, reply = self.try(self.tp:check("2..")) | 69 | local _, reply = self.try(self.tp:check("2..")) |
70 | local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)" | 70 | local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)" |
71 | local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern)) | 71 | local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern)) |
72 | self.try(a and b and c and d and p1 and p2, reply) | 72 | self.try(a and b and c and d and p1 and p2, reply) |
@@ -83,9 +83,9 @@ end | |||
83 | 83 | ||
84 | function metat.__index:epsv() | 84 | function metat.__index:epsv() |
85 | self.try(self.tp:command("epsv")) | 85 | self.try(self.tp:command("epsv")) |
86 | local code, reply = self.try(self.tp:check("229")) | 86 | local _, reply = self.try(self.tp:check("229")) |
87 | local pattern = "%((.)(.-)%1(.-)%1(.-)%1%)" | 87 | local pattern = "%((.)(.-)%1(.-)%1(.-)%1%)" |
88 | local d, prt, address, port = string.match(reply, pattern) | 88 | local _, _, _, port = string.match(reply, pattern) |
89 | self.try(port, "invalid epsv response") | 89 | self.try(port, "invalid epsv response") |
90 | self.pasvt = { | 90 | self.pasvt = { |
91 | address = self.tp:getpeername(), | 91 | address = self.tp:getpeername(), |
@@ -102,7 +102,7 @@ end | |||
102 | function metat.__index:port(address, port) | 102 | function metat.__index:port(address, port) |
103 | self.pasvt = nil | 103 | self.pasvt = nil |
104 | if not address then | 104 | if not address then |
105 | address, port = self.try(self.tp:getsockname()) | 105 | address = self.try(self.tp:getsockname()) |
106 | self.server = self.try(socket.bind(address, 0)) | 106 | self.server = self.try(socket.bind(address, 0)) |
107 | address, port = self.try(self.server:getsockname()) | 107 | address, port = self.try(self.server:getsockname()) |
108 | self.try(self.server:settimeout(_M.TIMEOUT)) | 108 | self.try(self.server:settimeout(_M.TIMEOUT)) |
@@ -118,7 +118,7 @@ end | |||
118 | function metat.__index:eprt(family, address, port) | 118 | function metat.__index:eprt(family, address, port) |
119 | self.pasvt = nil | 119 | self.pasvt = nil |
120 | if not address then | 120 | if not address then |
121 | address, port = self.try(self.tp:getsockname()) | 121 | address = self.try(self.tp:getsockname()) |
122 | self.server = self.try(socket.bind(address, 0)) | 122 | self.server = self.try(socket.bind(address, 0)) |
123 | address, port = self.try(self.server:getsockname()) | 123 | address, port = self.try(self.server:getsockname()) |
124 | self.try(self.server:settimeout(_M.TIMEOUT)) | 124 | self.try(self.server:settimeout(_M.TIMEOUT)) |
@@ -142,7 +142,7 @@ function metat.__index:send(sendt) | |||
142 | local command = sendt.command or "stor" | 142 | local command = sendt.command or "stor" |
143 | -- send the transfer command and check the reply | 143 | -- send the transfer command and check the reply |
144 | self.try(self.tp:command(command, argument)) | 144 | self.try(self.tp:command(command, argument)) |
145 | local code, reply = self.try(self.tp:check{"2..", "1.."}) | 145 | local code, _ = self.try(self.tp:check{"2..", "1.."}) |
146 | -- if there is not a pasvt table, then there is a server | 146 | -- if there is not a pasvt table, then there is a server |
147 | -- and we already sent a PORT command | 147 | -- and we already sent a PORT command |
148 | if not self.pasvt then self:portconnect() end | 148 | if not self.pasvt then self:portconnect() end |
diff --git a/src/http.lua b/src/http.lua index 6a3416e..e3a1742 100644 --- a/src/http.lua +++ b/src/http.lua | |||
@@ -41,9 +41,6 @@ local SCHEMES = { | |||
41 | https.tcp, 'LuaSocket: Function tcp() not available from LuaSec') | 41 | https.tcp, 'LuaSocket: Function tcp() not available from LuaSec') |
42 | return tcp(t) end }} | 42 | return tcp(t) end }} |
43 | 43 | ||
44 | -- default scheme and port for document retrieval | ||
45 | local SCHEME = 'http' | ||
46 | local PORT = SCHEMES[SCHEME].port | ||
47 | ----------------------------------------------------------------------------- | 44 | ----------------------------------------------------------------------------- |
48 | -- Reads MIME headers from a connection, unfolding where needed | 45 | -- Reads MIME headers from a connection, unfolding where needed |
49 | ----------------------------------------------------------------------------- | 46 | ----------------------------------------------------------------------------- |
@@ -92,7 +89,7 @@ socket.sourcet["http-chunked"] = function(sock, headers) | |||
92 | -- was it the last chunk? | 89 | -- was it the last chunk? |
93 | if size > 0 then | 90 | if size > 0 then |
94 | -- if not, get chunk and skip terminating CRLF | 91 | -- if not, get chunk and skip terminating CRLF |
95 | local chunk, err, part = sock:receive(size) | 92 | local chunk, err, _ = sock:receive(size) |
96 | if chunk then sock:receive() end | 93 | if chunk then sock:receive() end |
97 | return chunk, err | 94 | return chunk, err |
98 | else | 95 | else |
@@ -166,8 +163,8 @@ function metat.__index:receivestatusline() | |||
166 | if status ~= "HTTP/" then | 163 | if status ~= "HTTP/" then |
167 | if ec == "timeout" then | 164 | if ec == "timeout" then |
168 | return 408 | 165 | return 408 |
169 | end | 166 | end |
170 | return nil, status | 167 | return nil, status |
171 | end | 168 | end |
172 | -- otherwise proceed reading a status line | 169 | -- otherwise proceed reading a status line |
173 | status = self.try(self.c:receive("*l", status)) | 170 | status = self.try(self.c:receive("*l", status)) |
@@ -366,7 +363,7 @@ end | |||
366 | local headers | 363 | local headers |
367 | -- ignore any 100-continue messages | 364 | -- ignore any 100-continue messages |
368 | while code == 100 do | 365 | while code == 100 do |
369 | headers = h:receiveheaders() | 366 | h:receiveheaders() |
370 | code, status = h:receivestatusline() | 367 | code, status = h:receivestatusline() |
371 | end | 368 | end |
372 | headers = h:receiveheaders() | 369 | headers = h:receiveheaders() |
diff --git a/src/ltn12.lua b/src/ltn12.lua index afa735d..f1e05e1 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua | |||
@@ -13,7 +13,7 @@ local unpack = unpack or table.unpack | |||
13 | local base = _G | 13 | local base = _G |
14 | local _M = {} | 14 | local _M = {} |
15 | if module then -- heuristic for exporting a global package table | 15 | if module then -- heuristic for exporting a global package table |
16 | ltn12 = _M | 16 | ltn12 = _M -- luacheck: ignore |
17 | end | 17 | end |
18 | local filter,source,sink,pump = {},{},{},{} | 18 | local filter,source,sink,pump = {},{},{},{} |
19 | 19 | ||
@@ -23,7 +23,6 @@ _M.sink = sink | |||
23 | _M.pump = pump | 23 | _M.pump = pump |
24 | 24 | ||
25 | local unpack = unpack or table.unpack | 25 | local unpack = unpack or table.unpack |
26 | local select = base.select | ||
27 | 26 | ||
28 | -- 2048 seems to be better in windows... | 27 | -- 2048 seems to be better in windows... |
29 | _M.BLOCKSIZE = 2048 | 28 | _M.BLOCKSIZE = 2048 |
diff --git a/src/mbox.lua b/src/mbox.lua index ed9e781..12823b0 100644 --- a/src/mbox.lua +++ b/src/mbox.lua | |||
@@ -1,8 +1,8 @@ | |||
1 | local _M = {} | 1 | local _M = {} |
2 | 2 | ||
3 | if module then | 3 | if module then |
4 | mbox = _M | 4 | mbox = _M -- luacheck: ignore |
5 | end | 5 | end |
6 | 6 | ||
7 | function _M.split_message(message_s) | 7 | function _M.split_message(message_s) |
8 | local message = {} | 8 | local message = {} |
@@ -29,7 +29,7 @@ end | |||
29 | function _M.parse_header(header_s) | 29 | function _M.parse_header(header_s) |
30 | header_s = string.gsub(header_s, "\n[ ]+", " ") | 30 | header_s = string.gsub(header_s, "\n[ ]+", " ") |
31 | header_s = string.gsub(header_s, "\n+", "") | 31 | header_s = string.gsub(header_s, "\n+", "") |
32 | local _, __, name, value = string.find(header_s, "([^%s:]-):%s*(.*)") | 32 | local _, _, name, value = string.find(header_s, "([^%s:]-):%s*(.*)") |
33 | return name, value | 33 | return name, value |
34 | end | 34 | end |
35 | 35 | ||
@@ -49,9 +49,9 @@ function _M.parse_headers(headers_s) | |||
49 | end | 49 | end |
50 | 50 | ||
51 | function _M.parse_from(from) | 51 | function _M.parse_from(from) |
52 | local _, __, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>") | 52 | local _, _, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>") |
53 | if not address then | 53 | if not address then |
54 | _, __, address = string.find(from, "%s*(.+)%s*") | 54 | _, _, address = string.find(from, "%s*(.+)%s*") |
55 | end | 55 | end |
56 | name = name or "" | 56 | name = name or "" |
57 | address = address or "" | 57 | address = address or "" |
@@ -63,7 +63,8 @@ end | |||
63 | function _M.split_mbox(mbox_s) | 63 | function _M.split_mbox(mbox_s) |
64 | local mbox = {} | 64 | local mbox = {} |
65 | mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n" | 65 | mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n" |
66 | local nj, i, j = 1, 1, 1 | 66 | local nj, i |
67 | local j = 1 | ||
67 | while 1 do | 68 | while 1 do |
68 | i, nj = string.find(mbox_s, "\n\nFrom .-\n", j) | 69 | i, nj = string.find(mbox_s, "\n\nFrom .-\n", j) |
69 | if not i then break end | 70 | if not i then break end |
diff --git a/src/mime.lua b/src/mime.lua index d3abac5..93539de 100644 --- a/src/mime.lua +++ b/src/mime.lua | |||
@@ -10,7 +10,6 @@ | |||
10 | local base = _G | 10 | local base = _G |
11 | local ltn12 = require("ltn12") | 11 | local ltn12 = require("ltn12") |
12 | local mime = require("mime.core") | 12 | local mime = require("mime.core") |
13 | local string = require("string") | ||
14 | local _M = mime | 13 | local _M = mime |
15 | 14 | ||
16 | -- encode, decode and wrap algorithm tables | 15 | -- encode, decode and wrap algorithm tables |
@@ -18,7 +17,7 @@ local encodet, decodet, wrapt = {},{},{} | |||
18 | 17 | ||
19 | _M.encodet = encodet | 18 | _M.encodet = encodet |
20 | _M.decodet = decodet | 19 | _M.decodet = decodet |
21 | _M.wrapt = wrapt | 20 | _M.wrapt = wrapt |
22 | 21 | ||
23 | -- creates a function that chooses a filter by name from a given table | 22 | -- creates a function that chooses a filter by name from a given table |
24 | local function choose(table) | 23 | local function choose(table) |
@@ -27,7 +26,7 @@ local function choose(table) | |||
27 | name, opt1, opt2 = "default", name, opt1 | 26 | name, opt1, opt2 = "default", name, opt1 |
28 | end | 27 | end |
29 | local f = table[name or "nil"] | 28 | local f = table[name or "nil"] |
30 | if not f then | 29 | if not f then |
31 | base.error("unknown key (" .. base.tostring(name) .. ")", 3) | 30 | base.error("unknown key (" .. base.tostring(name) .. ")", 3) |
32 | else return f(opt1, opt2) end | 31 | else return f(opt1, opt2) end |
33 | end | 32 | end |
@@ -52,13 +51,6 @@ decodet['quoted-printable'] = function() | |||
52 | return ltn12.filter.cycle(_M.unqp, "") | 51 | return ltn12.filter.cycle(_M.unqp, "") |
53 | end | 52 | end |
54 | 53 | ||
55 | local function format(chunk) | ||
56 | if chunk then | ||
57 | if chunk == "" then return "''" | ||
58 | else return string.len(chunk) end | ||
59 | else return "nil" end | ||
60 | end | ||
61 | |||
62 | -- define the line-wrap filters | 54 | -- define the line-wrap filters |
63 | wrapt['text'] = function(length) | 55 | wrapt['text'] = function(length) |
64 | length = length or 76 | 56 | length = length or 76 |
diff --git a/src/url.lua b/src/url.lua index 0a3a80a..8e0dc5c 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -179,9 +179,9 @@ function _M.parse(url, default) | |||
179 | function(u) parsed.userinfo = u; return "" end) | 179 | function(u) parsed.userinfo = u; return "" end) |
180 | authority = string.gsub(authority, ":([^:%]]*)$", | 180 | authority = string.gsub(authority, ":([^:%]]*)$", |
181 | function(p) parsed.port = p; return "" end) | 181 | function(p) parsed.port = p; return "" end) |
182 | if authority ~= "" then | 182 | if authority ~= "" then |
183 | -- IPv6? | 183 | -- IPv6? |
184 | parsed.host = string.match(authority, "^%[(.+)%]$") or authority | 184 | parsed.host = string.match(authority, "^%[(.+)%]$") or authority |
185 | end | 185 | end |
186 | local userinfo = parsed.userinfo | 186 | local userinfo = parsed.userinfo |
187 | if not userinfo then return parsed end | 187 | if not userinfo then return parsed end |
@@ -264,7 +264,7 @@ function _M.absolute(base_url, relative_url) | |||
264 | relative_parsed.query = base_parsed.query | 264 | relative_parsed.query = base_parsed.query |
265 | end | 265 | end |
266 | end | 266 | end |
267 | else | 267 | else |
268 | relative_parsed.path = absolute_path(base_parsed.path or "", | 268 | relative_parsed.path = absolute_path(base_parsed.path or "", |
269 | relative_parsed.path) | 269 | relative_parsed.path) |
270 | end | 270 | end |