Compare commits

...

5 Commits

Author SHA1 Message Date
Ben Finney 2a7e4fcd6e Remove a statement using a name that is never defined in scope.
The intention may have been to close the “current” database cursor; but
there is no reference to that at this point in the code.
2022-12-19 09:52:20 +11:00
Ben Finney 1ad357ba4a Specify the ‘Exception’ catch-all exception class, not a bare ‘except’.
PEP 8 specifies:

* When catching exceptions, mention specific exceptions whenever possible
  instead of using a bare `except:` clause […]

  A bare `except:` clause will catch `SystemExit` and `KeyboardInterrupt`
  exceptions, making it harder to interrupt a program with Control-C, and
  can disguise other problems. If you want to catch all exceptions that
  signal program errors, use `except Exception:` (bare except is equivalent
  to `except BaseException:`).
2022-12-19 09:50:30 +11:00
Ben Finney 6a4de62467 Remove an assignment to an unused name. 2022-12-19 09:50:30 +11:00
Ben Finney 7118641d78 Use identity operators for comparison to None singleton.
PEP 8 specifies:

* Comparisons to singletons like None should always be done with `is` or
  `is not`, never the equality operators.
2022-12-19 09:49:01 +11:00
Ben Finney 4bed400c7d Use equality operator for comparison to integer value. 2022-12-19 09:49:01 +11:00
1 changed files with 6 additions and 7 deletions

View File

@ -61,7 +61,7 @@ try:
)
database.set_session(readonly=True, autocommit=True)
logging.debug(database.get_dsn_parameters())
except:
except Exception:
logging.error("Unable to initialize database, check settings!")
time.sleep(10)
sys.exit(1)
@ -69,7 +69,6 @@ except:
@atexit.register
def close_db():
cursor.close()
database.close()
@ -94,7 +93,7 @@ def ejabberd_in():
input_length = sys.stdin.buffer.read(2)
if len(input_length) is not 2:
if len(input_length) != 2:
logging.debug("ejabberd sent us wrong things!")
raise EjabberdInputError('Wrong input from ejabberd!')
@ -138,16 +137,16 @@ def get_password(user, host):
cursor.execute(db_query_getpass, {"user": user.lower(), "host": host})
data = cursor.fetchone()
cursor.close()
return data[0] if data != None else None
return data[0] if data is not None else None
def isuser(user, host):
return get_password(user, host) != None
return get_password(user, host) is not None
def auth(user, host, password):
db_password = get_password(user, host)
if db_password == None:
if db_password is None:
logging.debug("Wrong username: %s@%s" % (user, host))
return False
else:
@ -172,7 +171,7 @@ while True:
ejab_request = ejabberd_in().split(':', 3)
except EOFError:
break
except Exception as e:
except Exception:
logging.exception("Exception occured while reading stdin")
raise