Corect code style for main Python module. #2

Merged
mike merged 17 commits from bignose/ejabberd-auth-mastodon:wip/maintenance/code-style into master 2023-01-01 21:50:41 +11:00
Showing only changes of commit 237abe539a - Show all commits

View file

@ -13,15 +13,15 @@ import psycopg2
# Database connection details. The credentials here need access to the Mastodon database, which "ejabberd" is unlikely # Database connection details. The credentials here need access to the Mastodon database, which "ejabberd" is unlikely
# to have on your system by default. You shoud grant SELECT privileges to ejabberd on the "accounts" and "users" tables, # to have on your system by default. You shoud grant SELECT privileges to ejabberd on the "accounts" and "users" tables,
# to play it safe, or include the Mastodon DB user credentials here (don't). # to play it safe, or include the Mastodon DB user credentials here (don't).
db_host="localhost" db_host = "localhost"
db_port=5432 db_port = 5432
db_user="ejabberd" db_user = "ejabberd"
db_pass="" db_pass = ""
db_name="mastodon" db_name = "mastodon"
# This is the query that pulls the password hash for the given user. Mastodon doesn't store the domain for local accounts in # This is the query that pulls the password hash for the given user. Mastodon doesn't store the domain for local accounts in
# the database, so we ignore the host component and try to match username where the domain is NULL. # the database, so we ignore the host component and try to match username where the domain is NULL.
db_query_getpass="select users.encrypted_password as password from accounts inner join users on accounts.id=users.account_id where lower(accounts.username) = %(user)s and accounts.domain is null" db_query_getpass = "select users.encrypted_password as password from accounts inner join users on accounts.id=users.account_id where lower(accounts.username) = %(user)s and accounts.domain is null"
######################################################################## ########################################################################
# Setup # Setup
@ -39,7 +39,7 @@ try:
# Connect to the DB, set autocommit and readonly otherwise postgresql seems to have a # Connect to the DB, set autocommit and readonly otherwise postgresql seems to have a
# tendency to keep things "idle in transaction" and table locks eventually grind # tendency to keep things "idle in transaction" and table locks eventually grind
# Mastodon to a halt. We don't make any changes anyway. # Mastodon to a halt. We don't make any changes anyway.
database=psycopg2.connect(host = db_host, user = db_user, password = db_pass, database = db_name, port = db_port) database = psycopg2.connect(host=db_host, user=db_user, password=db_pass, database=db_name, port=db_port)
database.set_session(readonly=True, autocommit=True) database.set_session(readonly=True, autocommit=True)
logging.debug(database.get_dsn_parameters()) logging.debug(database.get_dsn_parameters())
except: except:
@ -79,13 +79,13 @@ def ejabberd_in():
logging.debug("ejabberd sent us wrong things!") logging.debug("ejabberd sent us wrong things!")
raise EjabberdInputError('Wrong input from ejabberd!') raise EjabberdInputError('Wrong input from ejabberd!')
logging.debug('got 2 bytes via stdin: %s'%input_length) logging.debug('got 2 bytes via stdin: %s' % input_length)
(size,) = struct.unpack('>h', input_length) (size,) = struct.unpack('>h', input_length)
logging.debug('size of data: %i'%size) logging.debug('size of data: %i' % size)
income=sys.stdin.read(size) income = sys.stdin.read(size)
logging.debug("incoming data: %s"%income) logging.debug("incoming data: %s" % income)
return income return income
@ -141,7 +141,7 @@ def auth(user, host, password):
# Main Loop # Main Loop
######################################################################## ########################################################################
exitcode=0 exitcode = 0
while True: while True:
logging.debug("start of infinite loop") logging.debug("start of infinite loop")