Skip to content

Commit

Permalink
ad-here to new ruff rules
Browse files Browse the repository at this point in the history
Signed-off-by: Giampaolo Rodola <[email protected]>
  • Loading branch information
giampaolo committed Jun 2, 2024
1 parent a73a7eb commit 3408daa
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fix-black:
git ls-files '*.py' | xargs $(PYTHON) -m black

fix-ruff:
@git ls-files '*.py' | xargs $(PYTHON) -m ruff --config=pyproject.toml --no-cache --fix
@git ls-files '*.py' | xargs $(PYTHON) -m ruff --config=pyproject.toml --no-cache --fix $(ARGS)

fix-toml: ## Fix pyproject.toml
@git ls-files '*.toml' | xargs toml-sort
Expand Down
12 changes: 7 additions & 5 deletions pyftpdlib/_asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,13 @@ def compact_traceback():
if not tb: # Must have a traceback
raise AssertionError("traceback does not exist")
while tb:
tbinfo.append((
tb.tb_frame.f_code.co_filename,
tb.tb_frame.f_code.co_name,
str(tb.tb_lineno),
))
tbinfo.append(
(
tb.tb_frame.f_code.co_filename,
tb.tb_frame.f_code.co_name,
str(tb.tb_lineno),
)
)
tb = tb.tb_next

# just to be safe
Expand Down
4 changes: 1 addition & 3 deletions pyftpdlib/authorizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,7 @@ def _is_rejected_user(self, username):
"""
if self.allowed_users and username not in self.allowed_users:
return True
if self.rejected_users and username in self.rejected_users:
return True
return False
return bool(self.rejected_users and username in self.rejected_users)


# ===================================================================
Expand Down
4 changes: 1 addition & 3 deletions pyftpdlib/filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ def validpath(self, path):
root = root + os.sep
if not path.endswith(os.sep):
path = path + os.sep
if path[0 : len(root)] == root:
return True
return False
return path[0 : len(root)] == root

# --- Wrapper methods around open() and tempfile.mkstemp

Expand Down
63 changes: 34 additions & 29 deletions pyftpdlib/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def use_sendfile(self):
self.file_obj.fileno()
except (OSError, ValueError):
return False
if self.cmd_channel._current_type != 'i':
if self.cmd_channel._current_type != 'i': # noqa: SIM103
# text file transfer (need to transform file content on the fly)
return False
return True
Expand Down Expand Up @@ -3195,11 +3195,13 @@ def ftp_STAT(self, path):
def ftp_FEAT(self, line):
"""List all new features supported as defined in RFC-2398."""
features = set(['UTF8', 'TVFS'])
features.update([
feat
for feat in ('EPRT', 'EPSV', 'MDTM', 'MFMT', 'SIZE')
if feat in self.proto_cmds
])
features.update(
[
feat
for feat in ('EPRT', 'EPSV', 'MDTM', 'MFMT', 'SIZE')
if feat in self.proto_cmds
]
)
features.update(self._extra_feats)
if 'MLST' in self.proto_cmds or 'MLSD' in self.proto_cmds:
facts = ''
Expand Down Expand Up @@ -3805,31 +3807,34 @@ class TLS_FTPHandler(SSLConnection, FTPHandler):
# overridden attributes
dtp_handler = TLS_DTPHandler
proto_cmds = FTPHandler.proto_cmds.copy()
proto_cmds.update({
'AUTH': dict(
perm=None,
auth=False,
arg=True,
help=(
'Syntax: AUTH <SP> TLS|SSL (set up secure control '
'channel).'
proto_cmds.update(
{
'AUTH': dict(
perm=None,
auth=False,
arg=True,
help=(
'Syntax: AUTH <SP> TLS|SSL (set up secure control '
'channel).'
),
),
),
'PBSZ': dict(
perm=None,
auth=False,
arg=True,
help='Syntax: PBSZ <SP> 0 (negotiate TLS buffer).',
),
'PROT': dict(
perm=None,
auth=False,
arg=True,
help=(
'Syntax: PROT <SP> [C|P] (set up un/secure data channel).'
'PBSZ': dict(
perm=None,
auth=False,
arg=True,
help='Syntax: PBSZ <SP> 0 (negotiate TLS buffer).',
),
),
})
'PROT': dict(
perm=None,
auth=False,
arg=True,
help=(
'Syntax: PROT <SP> [C|P] (set up un/secure data'
' channel).'
),
),
}
)

def __init__(self, conn, server, ioloop=None):
super().__init__(conn, server, ioloop)
Expand Down
20 changes: 11 additions & 9 deletions pyftpdlib/ioloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ def handle_accepted(self, sock, addr):
_write = asyncore.write

# These errnos indicate that a connection has been abruptly terminated.
_ERRNOS_DISCONNECTED = set((
errno.ECONNRESET,
errno.ENOTCONN,
errno.ESHUTDOWN,
errno.ECONNABORTED,
errno.EPIPE,
errno.EBADF,
errno.ETIMEDOUT,
))
_ERRNOS_DISCONNECTED = set(
(
errno.ECONNRESET,
errno.ENOTCONN,
errno.ESHUTDOWN,
errno.ECONNABORTED,
errno.EPIPE,
errno.EBADF,
errno.ETIMEDOUT,
)
)
if hasattr(errno, "WSAECONNRESET"):
_ERRNOS_DISCONNECTED.add(errno.WSAECONNRESET)
if hasattr(errno, "WSAECONNABORTED"):
Expand Down
4 changes: 1 addition & 3 deletions pyftpdlib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ def debug(s, inst=None):
def is_logging_configured():
if logging.getLogger('pyftpdlib').handlers:
return True
if logging.root.handlers:
return True
return False
return bool(logging.root.handlers)


# TODO: write tests
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ignore = [
"FIX", # Line contains TODO / XXX / ..., consider resolving the issue
"FLY", # flynt (PYTHON2.7 COMPAT)
"FURB101", # `open` and `read` should be replaced by `Path(x).read_text()`
"FURB103", # `open` and `write` should be replaced by `Path(...).write_bytes(data)`
"FURB113", # Use `s.extend(...)` instead of repeatedly calling `s.append()`
"INP", # flake8-no-pep420
"N801", # Class name `async_chat` should use CapWords convention (ASYNCORE COMPAT)
Expand Down
2 changes: 1 addition & 1 deletion scripts/internal/print_announce.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_changes():
break
lines.pop(0)

for line in lines:
while lines:
line = lines.pop(0)
line = line.rstrip()
if re.match(r"^- \d+_: ", line):
Expand Down
10 changes: 6 additions & 4 deletions scripts/internal/winmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
"wmi",
]
if sys.version_info[:2] == (2, 7):
DEPS.extend([
"ipaddress",
"mock",
])
DEPS.extend(
[
"ipaddress",
"mock",
]
)

_cmds = {}
if PY3:
Expand Down

0 comments on commit 3408daa

Please sign in to comment.