Skip to content

Commit dc010d0

Browse files
committed
[#782] Run "ruff format --preview"
The formatting pass modified code examples in the README. Those changes were discarded.
1 parent 7e45185 commit dc010d0

81 files changed

Lines changed: 1240 additions & 2725 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

irods/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def derived_auth_filename(env_filename):
3030
if not env_filename:
3131
return ""
3232
default_irods_authentication_file = os.path.expanduser("~/.irods/.irodsA")
33-
return os.environ.get(
34-
"IRODS_AUTHENTICATION_FILE", default_irods_authentication_file
35-
)
33+
return os.environ.get("IRODS_AUTHENTICATION_FILE", default_irods_authentication_file)
3634

3735

3836
logger = logging.getLogger(__name__)
@@ -109,6 +107,4 @@ def get_settings_path():
109107

110108
# If the settings path variable is not set in the environment, a value of None is passed,
111109
# and thus no settings file is auto-loaded.
112-
client_configuration.autoload(
113-
_file_to_load=os.environ.get(settings_path_environment_variable)
114-
)
110+
client_configuration.autoload(_file_to_load=os.environ.get(settings_path_environment_variable))

irods/access.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def items(self):
2020

2121

2222
class iRODSAccess(metaclass=_Access_LookupMeta):
23-
2423
@classmethod
2524
def to_int(cls, key):
2625
return cls.codes[key]
@@ -74,9 +73,7 @@ def to_string(cls, key):
7473
)
7574
)
7675

77-
strings = collections.OrderedDict(
78-
(number, string) for string, number in codes.items()
79-
)
76+
strings = collections.OrderedDict((number, string) for string, number in codes.items())
8077

8178
def __init__(self, access_name, path, user_name="", user_zone="", user_type=None):
8279
self.access_name = access_name
@@ -103,9 +100,7 @@ def __eq__(self, other):
103100
)
104101

105102
def __hash__(self):
106-
return hash(
107-
(self.access_name, iRODSPath(self.path), self.user_name, self.user_zone)
108-
)
103+
return hash((self.access_name, iRODSPath(self.path), self.user_name, self.user_zone))
109104

110105
def copy(self, decanonicalize=False):
111106
other = copy.deepcopy(self)
@@ -116,19 +111,13 @@ def copy(self, decanonicalize=False):
116111
"modify object": "write",
117112
"modify_object": "write",
118113
}.get(self.access_name)
119-
other.access_name = (
120-
replacement_string
121-
if replacement_string is not None
122-
else self.access_name
123-
)
114+
other.access_name = replacement_string if replacement_string is not None else self.access_name
124115
return other
125116

126117
def __repr__(self):
127118
object_dict = vars(self)
128119
access_name = self.access_name.replace(" ", "_")
129-
user_type_hint = (
130-
"({user_type})" if object_dict.get("user_type") is not None else ""
131-
).format(**object_dict)
120+
user_type_hint = ("({user_type})" if object_dict.get("user_type") is not None else "").format(**object_dict)
132121
return f"<iRODSAccess {access_name} {self.path} {self.user_name}{user_type_hint} {self.user_zone}>"
133122

134123

@@ -138,6 +127,4 @@ class _iRODSAccess_pre_4_3_0(iRODSAccess):
138127
for key, value in iRODSAccess.codes.items()
139128
if key in ("own", "write", "modify_object", "read", "read_object", "null")
140129
)
141-
strings = collections.OrderedDict(
142-
(number, string) for string, number in codes.items()
143-
)
130+
strings = collections.OrderedDict((number, string) for string, number in codes.items())

irods/account.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class iRODSAccount:
5-
65
@property
76
def derived_auth_file(self):
87
return derived_auth_filename(self.env_file)
@@ -19,7 +18,7 @@ def __init__(
1918
server_dn=None,
2019
client_zone=None,
2120
env_file="",
22-
**kwargs
21+
**kwargs,
2322
):
2423

2524
# Allowed overrides when cloning sessions. (Currently hostname only.)

irods/auth/__init__.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ def throw_if_request_message_is_missing_key(request, required_keys):
144144

145145
def _auth_api_request(conn, data):
146146
message_body = JSON_Message(data, conn.server_version)
147-
message = iRODSMessage(
148-
"RODS_API_REQ", msg=message_body, int_info=api_number["AUTHENTICATION_APN"]
149-
)
147+
message = iRODSMessage("RODS_API_REQ", msg=message_body, int_info=api_number["AUTHENTICATION_APN"])
150148
conn.send(message)
151149
response = conn.recv()
152150
return response.get_json_encoded_struct()
@@ -162,7 +160,6 @@ def _auth_api_request(conn, data):
162160

163161

164162
class authentication_base:
165-
166163
def __init__(self, connection, scheme):
167164
self.conn = connection
168165
self.loggedIn = 0
@@ -181,9 +178,7 @@ def call(self, next_operation, request):
181178
_logger.debug("resp = %r", resp)
182179
return resp
183180

184-
def authenticate_client(
185-
self, next_operation="auth_client_start", initial_request=()
186-
):
181+
def authenticate_client(self, next_operation="auth_client_start", initial_request=()):
187182
if not isinstance(initial_request, dict):
188183
initial_request = dict(initial_request)
189184

@@ -196,13 +191,9 @@ def authenticate_client(
196191
break
197192
next_operation = resp.get(__NEXT_OPERATION__)
198193
if next_operation is None:
199-
raise ClientAuthError(
200-
"next_operation key missing; cannot determine next operation"
201-
)
194+
raise ClientAuthError("next_operation key missing; cannot determine next operation")
202195
if next_operation in (__FLOW_COMPLETE__, ""):
203-
raise ClientAuthError(
204-
f"authentication flow stopped without success: scheme = {self.scheme}"
205-
)
196+
raise ClientAuthError(f"authentication flow stopped without success: scheme = {self.scheme}")
206197
to_send = resp
207198

208199
_logger.debug("fully authenticated")

irods/auth/native.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ class _native_ClientAuthState(authentication_base):
6161
def auth_client_start(self, request):
6262
resp = request.copy()
6363
# user_name and zone_name keys injected by authenticate_client() method
64-
resp[__NEXT_OPERATION__] = (
65-
self.AUTH_CLIENT_AUTH_REQUEST
66-
) # native_auth_client_request
64+
resp[__NEXT_OPERATION__] = self.AUTH_CLIENT_AUTH_REQUEST # native_auth_client_request
6765
return resp
6866

6967
def native_auth_client_request(self, request):
@@ -76,9 +74,7 @@ def native_auth_client_request(self, request):
7674
return resp
7775

7876
def native_auth_establish_context(self, request):
79-
throw_if_request_message_is_missing_key(
80-
request, ["user_name", "zone_name", "request_result"]
81-
)
77+
throw_if_request_message_is_missing_key(request, ["user_name", "zone_name", "request_result"])
8278
request = request.copy()
8379

8480
password = ""
@@ -91,13 +87,9 @@ def native_auth_establish_context(self, request):
9187
password = self.conn.account.password or ""
9288

9389
challenge = request["request_result"].encode("utf-8")
94-
self.conn._client_signature = "".join(
95-
"{:02x}".format(c) for c in challenge[:16]
96-
)
90+
self.conn._client_signature = "".join("{:02x}".format(c) for c in challenge[:16])
9791

98-
padded_pwd = struct.pack(
99-
"%ds" % MAX_PASSWORD_LENGTH, password.encode("utf-8").strip()
100-
)
92+
padded_pwd = struct.pack("%ds" % MAX_PASSWORD_LENGTH, password.encode("utf-8").strip())
10193

10294
m = hashlib.md5()
10395
m.update(challenge)
@@ -113,9 +105,7 @@ def native_auth_establish_context(self, request):
113105
return request
114106

115107
def native_auth_client_response(self, request):
116-
throw_if_request_message_is_missing_key(
117-
request, ["user_name", "zone_name", "digest"]
118-
)
108+
throw_if_request_message_is_missing_key(request, ["user_name", "zone_name", "digest"])
119109

120110
server_req = request.copy()
121111
server_req[__NEXT_OPERATION__] = self.AUTH_AGENT_AUTH_RESPONSE

irods/auth/pam_interactive.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
throw_if_request_message_is_missing_key,
88
AuthStorage,
99
STORE_PASSWORD_IN_MEMORY,
10-
CLIENT_GET_REQUEST_RESULT
10+
CLIENT_GET_REQUEST_RESULT,
1111
)
1212
from .native import _authenticate_native
1313

@@ -17,7 +17,7 @@
1717
import logging
1818
import sys
1919

20-
# Constants defining the states and operations for the pam_interactive authentication flow
20+
# Constants defining the states and operations for the pam_interactive authentication flow
2121
AUTH_CLIENT_AUTH_REQUEST = "pam_auth_client_request"
2222
AUTH_CLIENT_AUTH_RESPONSE = "pam_auth_response"
2323
PERFORM_RUNNING = "running"
@@ -38,16 +38,16 @@
3838

3939
_logger = logging.getLogger(__name__)
4040

41+
4142
def login(conn, **extra_opt):
4243
"""The entry point for the pam_interactive authentication scheme."""
4344

4445
# The AuthStorage object holds the token generated by the server for the native auth step
4546
depot = AuthStorage.create_temp_pw_storage(conn)
4647

4748
auth_client_object = _pam_interactive_ClientAuthState(conn, depot, scheme=PAM_INTERACTIVE_SCHEME)
48-
auth_client_object.authenticate_client(
49-
initial_request=extra_opt
50-
)
49+
auth_client_object.authenticate_client(initial_request=extra_opt)
50+
5151

5252
class _pam_interactive_ClientAuthState(authentication_base):
5353
def __init__(self, conn, depot, *_, **_kw):
@@ -64,7 +64,7 @@ def auth_client_start(self, request):
6464
# to recall previous inputs through JSON pointers. "pdirty" flags if pstate has changed and needs syncing.
6565
# The server side implementation can be found here: https://github.com/irods/irods_auth_plugin_pam_interactive
6666
# The plugin is built on the authentication framework described here:
67-
# https://github.com/irods-contrib/irods_working_group_authentication/tree/e83e84df8ea4a732e5de894fb28aae281c3b3d29/development
67+
# https://github.com/irods-contrib/irods_working_group_authentication/tree/e83e84df8ea4a732e5de894fb28aae281c3b3d29/development
6868

6969
resp["pstate"] = resp.get("pstate", {})
7070
resp["pdirty"] = resp.get("pdirty", False)
@@ -123,7 +123,7 @@ def _patch_state(self, req):
123123

124124
# If the patch operation is an add or replace without a value, use the response value (following json patch RFC)
125125
for op in patch_ops:
126-
if op.get("op") in ["add", "replace"] and "value" not in op:
126+
if op.get("op") in ["add", "replace"] and "value" not in op:
127127
op["value"] = resp
128128

129129
req["pstate"] = jsonpatch.apply_patch(req.get("pstate", {}), patch_ops)
@@ -266,4 +266,4 @@ def timeout(self, request):
266266
return self._auth_failure(request, "Authentication timed out.")
267267

268268
def not_authenticated(self, request):
269-
return self._auth_failure(request, "Authentication failed possibly due to incorrect credentials.")
269+
return self._auth_failure(request, "Authentication failed possibly due to incorrect credentials.")

irods/auth/pam_password.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,16 @@ def _authenticate_pam_password(conn, req):
5353

5454
_ = AuthStorage.create_temp_pw_storage(conn)
5555

56-
_pam_password_ClientAuthState(conn, scheme=_scheme).authenticate_client(
57-
initial_request=req
58-
)
56+
_pam_password_ClientAuthState(conn, scheme=_scheme).authenticate_client(initial_request=req)
5957

6058
_logger.debug("----------- %s (end)", _scheme)
6159

6260

63-
def _get_pam_password_from_stdin(
64-
file_like_object=None, prompt="Enter your current PAM password: "
65-
):
61+
def _get_pam_password_from_stdin(file_like_object=None, prompt="Enter your current PAM password: "):
6662
try:
6763
if file_like_object:
6864
if not getattr(file_like_object, "readline", None):
69-
msg = (
70-
"The file_like_object, if provided, must have a 'readline' method."
71-
)
65+
msg = "The file_like_object, if provided, must have a 'readline' method."
7266
raise RuntimeError(msg)
7367
sys.stdin = file_like_object
7468
if sys.stdin.isatty():
@@ -84,7 +78,6 @@ def _get_pam_password_from_stdin(
8478

8579

8680
class _pam_password_ClientAuthState(authentication_base):
87-
8881
# Client define
8982
AUTH_CLIENT_AUTH_REQUEST = "pam_password_auth_client_request"
9083

@@ -100,9 +93,7 @@ def auth_client_start(self, request):
10093

10194
# This list reference is popped and cached for the purpose of returning the request_result value
10295
# to the caller upon request.
103-
self._list_for_request_result_return = request.pop(
104-
CLIENT_GET_REQUEST_RESULT, False
105-
)
96+
self._list_for_request_result_return = request.pop(CLIENT_GET_REQUEST_RESULT, False)
10697

10798
ensure_ssl = request.pop(ENSURE_SSL_IS_ACTIVE, None)
10899
if ensure_ssl is not None:
@@ -121,9 +112,7 @@ def auth_client_start(self, request):
121112
if isinstance(password_input_obj, (int, bool)):
122113
password_input_obj = None
123114
# Like with the C++ plugin, we offer the user a chance to enter a password.
124-
resp[AUTH_PASSWORD_KEY] = _get_pam_password_from_stdin(
125-
file_like_object=password_input_obj
126-
)
115+
resp[AUTH_PASSWORD_KEY] = _get_pam_password_from_stdin(file_like_object=password_input_obj)
127116
else:
128117
# Password from .irodsA in environment.
129118
if self.conn.account._auth_file:

0 commit comments

Comments
 (0)