Merge pull request #354 from lunarmodules/linter

This commit is contained in:
Caleb Maclennan
2022-03-19 17:42:53 +03:00
committed by GitHub
24 changed files with 260 additions and 198 deletions

View File

@ -56,7 +56,7 @@ end
function metat.__index:login(user, password)
self.try(self.tp:command("user", user or _M.USER))
local code, reply = self.try(self.tp:check{"2..", 331})
local code, _ = self.try(self.tp:check{"2..", 331})
if code == 331 then
self.try(self.tp:command("pass", password or _M.PASSWORD))
self.try(self.tp:check("2.."))
@ -66,7 +66,7 @@ end
function metat.__index:pasv()
self.try(self.tp:command("pasv"))
local code, reply = self.try(self.tp:check("2.."))
local _, reply = self.try(self.tp:check("2.."))
local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)"
local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern))
self.try(a and b and c and d and p1 and p2, reply)
@ -83,9 +83,9 @@ end
function metat.__index:epsv()
self.try(self.tp:command("epsv"))
local code, reply = self.try(self.tp:check("229"))
local _, reply = self.try(self.tp:check("229"))
local pattern = "%((.)(.-)%1(.-)%1(.-)%1%)"
local d, prt, address, port = string.match(reply, pattern)
local _, _, _, port = string.match(reply, pattern)
self.try(port, "invalid epsv response")
self.pasvt = {
address = self.tp:getpeername(),
@ -102,7 +102,7 @@ end
function metat.__index:port(address, port)
self.pasvt = nil
if not address then
address, port = self.try(self.tp:getsockname())
address = self.try(self.tp:getsockname())
self.server = self.try(socket.bind(address, 0))
address, port = self.try(self.server:getsockname())
self.try(self.server:settimeout(_M.TIMEOUT))
@ -118,7 +118,7 @@ end
function metat.__index:eprt(family, address, port)
self.pasvt = nil
if not address then
address, port = self.try(self.tp:getsockname())
address = self.try(self.tp:getsockname())
self.server = self.try(socket.bind(address, 0))
address, port = self.try(self.server:getsockname())
self.try(self.server:settimeout(_M.TIMEOUT))
@ -142,7 +142,7 @@ function metat.__index:send(sendt)
local command = sendt.command or "stor"
-- send the transfer command and check the reply
self.try(self.tp:command(command, argument))
local code, reply = self.try(self.tp:check{"2..", "1.."})
local code, _ = self.try(self.tp:check{"2..", "1.."})
-- if there is not a pasvt table, then there is a server
-- and we already sent a PORT command
if not self.pasvt then self:portconnect() end

View File

@ -41,9 +41,6 @@ local SCHEMES = {
https.tcp, 'LuaSocket: Function tcp() not available from LuaSec')
return tcp(t) end }}
-- default scheme and port for document retrieval
local SCHEME = 'http'
local PORT = SCHEMES[SCHEME].port
-----------------------------------------------------------------------------
-- Reads MIME headers from a connection, unfolding where needed
-----------------------------------------------------------------------------
@ -92,7 +89,7 @@ socket.sourcet["http-chunked"] = function(sock, headers)
-- was it the last chunk?
if size > 0 then
-- if not, get chunk and skip terminating CRLF
local chunk, err, part = sock:receive(size)
local chunk, err, _ = sock:receive(size)
if chunk then sock:receive() end
return chunk, err
else
@ -166,8 +163,8 @@ function metat.__index:receivestatusline()
if status ~= "HTTP/" then
if ec == "timeout" then
return 408
end
return nil, status
end
return nil, status
end
-- otherwise proceed reading a status line
status = self.try(self.c:receive("*l", status))
@ -366,7 +363,7 @@ end
local headers
-- ignore any 100-continue messages
while code == 100 do
headers = h:receiveheaders()
h:receiveheaders()
code, status = h:receivestatusline()
end
headers = h:receiveheaders()

View File

@ -13,7 +13,7 @@ local unpack = unpack or table.unpack
local base = _G
local _M = {}
if module then -- heuristic for exporting a global package table
ltn12 = _M
ltn12 = _M -- luacheck: ignore
end
local filter,source,sink,pump = {},{},{},{}
@ -23,7 +23,6 @@ _M.sink = sink
_M.pump = pump
local unpack = unpack or table.unpack
local select = base.select
-- 2048 seems to be better in windows...
_M.BLOCKSIZE = 2048

View File

@ -1,8 +1,8 @@
local _M = {}
if module then
mbox = _M
end
mbox = _M -- luacheck: ignore
end
function _M.split_message(message_s)
local message = {}
@ -29,7 +29,7 @@ end
function _M.parse_header(header_s)
header_s = string.gsub(header_s, "\n[ ]+", " ")
header_s = string.gsub(header_s, "\n+", "")
local _, __, name, value = string.find(header_s, "([^%s:]-):%s*(.*)")
local _, _, name, value = string.find(header_s, "([^%s:]-):%s*(.*)")
return name, value
end
@ -49,9 +49,9 @@ function _M.parse_headers(headers_s)
end
function _M.parse_from(from)
local _, __, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>")
local _, _, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>")
if not address then
_, __, address = string.find(from, "%s*(.+)%s*")
_, _, address = string.find(from, "%s*(.+)%s*")
end
name = name or ""
address = address or ""
@ -63,7 +63,8 @@ end
function _M.split_mbox(mbox_s)
local mbox = {}
mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n"
local nj, i, j = 1, 1, 1
local nj, i
local j = 1
while 1 do
i, nj = string.find(mbox_s, "\n\nFrom .-\n", j)
if not i then break end

View File

@ -10,7 +10,6 @@
local base = _G
local ltn12 = require("ltn12")
local mime = require("mime.core")
local string = require("string")
local _M = mime
-- encode, decode and wrap algorithm tables
@ -18,7 +17,7 @@ local encodet, decodet, wrapt = {},{},{}
_M.encodet = encodet
_M.decodet = decodet
_M.wrapt = wrapt
_M.wrapt = wrapt
-- creates a function that chooses a filter by name from a given table
local function choose(table)
@ -27,7 +26,7 @@ local function choose(table)
name, opt1, opt2 = "default", name, opt1
end
local f = table[name or "nil"]
if not f then
if not f then
base.error("unknown key (" .. base.tostring(name) .. ")", 3)
else return f(opt1, opt2) end
end
@ -52,13 +51,6 @@ decodet['quoted-printable'] = function()
return ltn12.filter.cycle(_M.unqp, "")
end
local function format(chunk)
if chunk then
if chunk == "" then return "''"
else return string.len(chunk) end
else return "nil" end
end
-- define the line-wrap filters
wrapt['text'] = function(length)
length = length or 76

View File

@ -179,9 +179,9 @@ function _M.parse(url, default)
function(u) parsed.userinfo = u; return "" end)
authority = string.gsub(authority, ":([^:%]]*)$",
function(p) parsed.port = p; return "" end)
if authority ~= "" then
if authority ~= "" then
-- IPv6?
parsed.host = string.match(authority, "^%[(.+)%]$") or authority
parsed.host = string.match(authority, "^%[(.+)%]$") or authority
end
local userinfo = parsed.userinfo
if not userinfo then return parsed end
@ -264,7 +264,7 @@ function _M.absolute(base_url, relative_url)
relative_parsed.query = base_parsed.query
end
end
else
else
relative_parsed.path = absolute_path(base_parsed.path or "",
relative_parsed.path)
end