refactor: Address issues raised by linter

This commit is contained in:
Thijs Schreijer 2022-03-18 12:12:39 +01:00 committed by Caleb Maclennan
parent 480c052572
commit 601ad8d59f
No known key found for this signature in database
GPG Key ID: B538286DE04ECFE5
21 changed files with 187 additions and 198 deletions

View File

@ -14,7 +14,7 @@ end
local function parse_set_cookie(c, quoted, cookie_table) local function parse_set_cookie(c, quoted, cookie_table)
c = c .. ";$last=last;" c = c .. ";$last=last;"
local _, __, n, v, i = string.find(c, "(" .. token_class .. local _, _, n, v, i = string.find(c, "(" .. token_class ..
"+)%s*=%s*(.-)%s*;%s*()") "+)%s*=%s*(.-)%s*;%s*()")
local cookie = { local cookie = {
name = n, name = n,
@ -22,7 +22,7 @@ local function parse_set_cookie(c, quoted, cookie_table)
attributes = {} attributes = {}
} }
while 1 do while 1 do
_, __, n, v, i = string.find(c, "(" .. token_class .. _, _, n, v, i = string.find(c, "(" .. token_class ..
"+)%s*=?%s*(.-)%s*;%s*()", i) "+)%s*=?%s*(.-)%s*;%s*()", i)
if not n or n == "$last" then break end if not n or n == "$last" then break end
cookie.attributes[#cookie.attributes+1] = { cookie.attributes[#cookie.attributes+1] = {
@ -46,8 +46,8 @@ local function split_set_cookie(s, cookie_table)
-- split into individual cookies -- split into individual cookies
i = 1 i = 1
while 1 do while 1 do
local _, __, cookie, next_token local _, _, cookie, next_token
_, __, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" .. _, _, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" ..
token_class .. "+)%s*=", i) token_class .. "+)%s*=", i)
if not next_token then break end if not next_token then break end
parse_set_cookie(cookie, quoted, cookie_table) parse_set_cookie(cookie, quoted, cookie_table)

View File

@ -56,7 +56,7 @@ end
function metat.__index:login(user, password) function metat.__index:login(user, password)
self.try(self.tp:command("user", user or _M.USER)) 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 if code == 331 then
self.try(self.tp:command("pass", password or _M.PASSWORD)) self.try(self.tp:command("pass", password or _M.PASSWORD))
self.try(self.tp:check("2..")) self.try(self.tp:check("2.."))
@ -66,7 +66,7 @@ end
function metat.__index:pasv() function metat.__index:pasv()
self.try(self.tp:command("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 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)) 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) self.try(a and b and c and d and p1 and p2, reply)
@ -83,9 +83,9 @@ end
function metat.__index:epsv() function metat.__index:epsv()
self.try(self.tp:command("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 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.try(port, "invalid epsv response")
self.pasvt = { self.pasvt = {
address = self.tp:getpeername(), address = self.tp:getpeername(),
@ -102,7 +102,7 @@ end
function metat.__index:port(address, port) function metat.__index:port(address, port)
self.pasvt = nil self.pasvt = nil
if not address then 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)) self.server = self.try(socket.bind(address, 0))
address, port = self.try(self.server:getsockname()) address, port = self.try(self.server:getsockname())
self.try(self.server:settimeout(_M.TIMEOUT)) self.try(self.server:settimeout(_M.TIMEOUT))
@ -118,7 +118,7 @@ end
function metat.__index:eprt(family, address, port) function metat.__index:eprt(family, address, port)
self.pasvt = nil self.pasvt = nil
if not address then 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)) self.server = self.try(socket.bind(address, 0))
address, port = self.try(self.server:getsockname()) address, port = self.try(self.server:getsockname())
self.try(self.server:settimeout(_M.TIMEOUT)) self.try(self.server:settimeout(_M.TIMEOUT))
@ -142,7 +142,7 @@ function metat.__index:send(sendt)
local command = sendt.command or "stor" local command = sendt.command or "stor"
-- send the transfer command and check the reply -- send the transfer command and check the reply
self.try(self.tp:command(command, argument)) 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 -- if there is not a pasvt table, then there is a server
-- and we already sent a PORT command -- and we already sent a PORT command
if not self.pasvt then self:portconnect() end 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') https.tcp, 'LuaSocket: Function tcp() not available from LuaSec')
return tcp(t) end }} 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 -- 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? -- was it the last chunk?
if size > 0 then if size > 0 then
-- if not, get chunk and skip terminating CRLF -- 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 if chunk then sock:receive() end
return chunk, err return chunk, err
else else
@ -366,7 +363,7 @@ end
local headers local headers
-- ignore any 100-continue messages -- ignore any 100-continue messages
while code == 100 do while code == 100 do
headers = h:receiveheaders() h:receiveheaders()
code, status = h:receivestatusline() code, status = h:receivestatusline()
end end
headers = h:receiveheaders() headers = h:receiveheaders()

View File

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

View File

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

View File

@ -10,7 +10,6 @@
local base = _G local base = _G
local ltn12 = require("ltn12") local ltn12 = require("ltn12")
local mime = require("mime.core") local mime = require("mime.core")
local string = require("string")
local _M = mime local _M = mime
-- encode, decode and wrap algorithm tables -- encode, decode and wrap algorithm tables
@ -52,13 +51,6 @@ decodet['quoted-printable'] = function()
return ltn12.filter.cycle(_M.unqp, "") return ltn12.filter.cycle(_M.unqp, "")
end 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 -- define the line-wrap filters
wrapt['text'] = function(length) wrapt['text'] = function(length)
length = length or 76 length = length or 76

View File

@ -15,27 +15,27 @@ local eb64test = "b64test.bin2"
local db64test = "b64test.bin3" local db64test = "b64test.bin3"
-- from Machado de Assis, "A Mão e a Rosa" -- from Machado de Assis, "A M<EFBFBD>o e a Rosa"
local mao = [[ local mao = [[
Cursavam estes dois moços a academia de S. Paulo, estando Cursavam estes dois mo<EFBFBD>os a academia de S. Paulo, estando
Luís Alves no quarto ano e Estêvão no terceiro. Lu<EFBFBD>s Alves no quarto ano e Est<EFBFBD>v<EFBFBD>o no terceiro.
Conheceram-se na academia, e ficaram amigos íntimos, tanto Conheceram-se na academia, e ficaram amigos <EFBFBD>ntimos, tanto
quanto podiam sê-lo dois espíritos diferentes, ou talvez por quanto podiam s<EFBFBD>-lo dois esp<EFBFBD>ritos diferentes, ou talvez por
isso mesmo que o eram. Estêvão, dotado de extrema isso mesmo que o eram. Est<EFBFBD>v<EFBFBD>o, dotado de extrema
sensibilidade, e não menor fraqueza de ânimo, afetuoso e sensibilidade, e n<EFBFBD>o menor fraqueza de <EFBFBD>nimo, afetuoso e
bom, não daquela bondade varonil, que é apanágio de uma alma bom, n<EFBFBD>o daquela bondade varonil, que <EFBFBD> apan<EFBFBD>gio de uma alma
forte, mas dessa outra bondade mole e de cera, que vai à forte, mas dessa outra bondade mole e de cera, que vai <EFBFBD>
mercê de todas as circunstâncias, tinha, além de tudo isso, merc<EFBFBD> de todas as circunst<EFBFBD>ncias, tinha, al<EFBFBD>m de tudo isso,
o infortúnio de trazer ainda sobre o nariz os óculos o infort<EFBFBD>nio de trazer ainda sobre o nariz os <EFBFBD>culos
cor-de-rosa de suas virginais ilusões. Luís Alves via bem cor-de-rosa de suas virginais ilus<EFBFBD>es. Lu<EFBFBD>s Alves via bem
com os olhos da cara. Não era mau rapaz, mas tinha o seu com os olhos da cara. N<EFBFBD>o era mau rapaz, mas tinha o seu
grão de egoísmo, e se não era incapaz de afeições, sabia gr<EFBFBD>o de ego<EFBFBD>smo, e se n<EFBFBD>o era incapaz de afei<EFBFBD><EFBFBD>es, sabia
regê-las, moderá-las, e sobretudo guiá-las ao seu próprio reg<EFBFBD>-las, moder<EFBFBD>-las, e sobretudo gui<EFBFBD>-las ao seu pr<EFBFBD>prio
interesse. Entre estes dois homens travara-se amizade interesse. Entre estes dois homens travara-se amizade
íntima, nascida para um na simpatia, para outro no costume. <EFBFBD>ntima, nascida para um na simpatia, para outro no costume.
Eram eles os naturais confidentes um do outro, com a Eram eles os naturais confidentes um do outro, com a
diferença que Luís Alves dava menos do que recebia, e, ainda diferen<EFBFBD>a que Lu<EFBFBD>s Alves dava menos do que recebia, e, ainda
assim, nem tudo o que dava exprimia grande confiança. assim, nem tudo o que dava exprimia grande confian<EFBFBD>a.
]] ]]
local function random(handle, io_err) local function random(handle, io_err)