Skip to content

Commit

Permalink
[_480] use format-strings where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
d-w-moore committed Oct 16, 2024
1 parent 79558eb commit 41b4824
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions irods/manager/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def create(self, user_name, user_type, user_zone="", auth_str=""):
"add",
"user",
user_name if not user_zone or user_zone == self.sess.zone \
else "{}#{}".format(user_name,user_zone),
else f"{user_name}#{user_zone}",
user_type,
user_zone,
auth_str
Expand Down Expand Up @@ -188,8 +188,8 @@ def modify_password(self, old_value, new_value, modify_irods_authentication_file
with open(auth_file) as f:
stored_pw = obf.decode(f.read())
if stored_pw != old_value:
message = "Not changing contents of '{}' - "\
"stored password is non-native or false match to old password".format(auth_file)
message = f"Not changing contents of '{auth_file}' - "\
"stored password is non-native or false match to old password"
raise UserManager.EnvStoredPasswordNotEdited(message)
with open(auth_file,'w') as f:
f.write(obf.encode(new_value))
Expand Down
23 changes: 12 additions & 11 deletions irods/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,20 @@ def get_connection(self):
# created more than 'connection_refresh_time' seconds ago,
# release the connection (as its stale) and create a new one
if self.refresh_connection and (curr_time - conn.create_time).total_seconds() > self.connection_refresh_time:
logger.debug('Connection with id {} was created more than {} seconds ago. Releasing the connection and creating a new one.'.format(id(conn), self.connection_refresh_time))
logger.debug(f"Connection with id {id(conn)} was created more than {self.connection_refresh_time} seconds ago. "
"Releasing the connection and creating a new one.")
# Since calling disconnect() repeatedly is safe, we call disconnect()
# here explicitly, instead of relying on the garbage collector to clean
# up the object and call disconnect(). This makes the behavior of the
# code more predictable as we are not relying on when garbage collector is called
conn.disconnect()
conn = Connection(self, self.account)
new_conn = True
logger.debug("Created new connection with id: {}".format(id(conn)))
logger.debug(f"Created new connection with id: {id(conn)}")
except KeyError:
conn = Connection(self, self.account)
new_conn = True
logger.debug("No connection found in idle set. Created a new connection with id: {}".format(id(conn)))
logger.debug(f"No connection found in idle set. Created a new connection with id: {id(conn)}")

self.active.add(conn)

Expand All @@ -94,32 +95,32 @@ def get_connection(self):
Ticket._lowlevel_api_request(conn, "session", sess.ticket__)
sess.ticket_applied[conn] = True

logger.debug("Adding connection with id {} to active set".format(id(conn)))
logger.debug(f"Adding connection with id {id(conn)} to active set")

# If the connection we're about to make active was cached, it already has a socket object internal to it,
# so we potentially have to modify it to have the desired timeout.
if not new_conn:
_adjust_timeout_to_pool_default(conn)

logger.debug('num active: {}'.format(len(self.active)))
logger.debug('num idle: {}'.format(len(self.idle)))
logger.debug(f'num active: {len(self.active)}')
logger.debug(f'num idle: {len(self.idle)}')

return conn

def release_connection(self, conn, destroy=False):
with self._lock:
if conn in self.active:
self.active.remove(conn)
logger.debug("Removed connection with id: {} from active set".format(id(conn)))
logger.debug(f"Removed connection with id: {id(conn)} from active set")
if not destroy:
# If 'refresh_connection' flag is True, update connection's 'last_used_time'
if self.refresh_connection:
conn.last_used_time = datetime.datetime.now()
self.idle.add(conn)
logger.debug("Added connection with id: {} to idle set".format(id(conn)))
logger.debug(f"Added connection with id: {id(conn)} to idle set")
elif conn in self.idle and destroy:
logger.debug("Destroyed connection with id: {}".format(id(conn)))
logger.debug(f"Destroying connection with id: {id(conn)}")
self.idle.remove(conn)
logger.debug('num active: {}'.format(len(self.active)))
logger.debug('num idle: {}'.format(len(self.idle)))
logger.debug(f'num active: {len(self.active)}')
logger.debug(f'num idle: {len(self.idle)}')

0 comments on commit 41b4824

Please sign in to comment.