Black again, with the right version this time..

This commit is contained in:
Alexandre Aubin 2021-01-20 05:59:24 +01:00
parent 677efcf6d6
commit 0de154678c
5 changed files with 61 additions and 35 deletions

View file

@ -288,7 +288,10 @@ class _ActionsMapPlugin(object):
# Append messages route # Append messages route
app.route( app.route(
"/messages", name="messages", callback=self.messages, skip=["actionsmap"], "/messages",
name="messages",
callback=self.messages,
skip=["actionsmap"],
) )
# Append routes from the actions map # Append routes from the actions map
@ -815,7 +818,9 @@ class Interface(BaseInterface):
""" """
logger.debug( logger.debug(
"starting the server instance in %s:%d", host, port, "starting the server instance in %s:%d",
host,
port,
) )
try: try:

View file

@ -22,9 +22,11 @@ def read_file(file_path):
Keyword argument: Keyword argument:
file_path -- Path to the text file file_path -- Path to the text file
""" """
assert isinstance(file_path, str), ( assert isinstance(
"Error: file_path '%s' should be a string but is of type '%s' instead" file_path, str
% (file_path, type(file_path)) ), "Error: file_path '%s' should be a string but is of type '%s' instead" % (
file_path,
type(file_path),
) )
# Check file exists # Check file exists
@ -151,24 +153,30 @@ def write_to_file(file_path, data, file_mode="w"):
file_mode -- Mode used when writing the file. Option meant to be used file_mode -- Mode used when writing the file. Option meant to be used
by append_to_file to avoid duplicating the code of this function. by append_to_file to avoid duplicating the code of this function.
""" """
assert isinstance(data, str) or isinstance(data, list), ( assert isinstance(data, str) or isinstance(
"Error: data '%s' should be either a string or a list but is of type '%s'" data, list
% (data, type(data)) ), "Error: data '%s' should be either a string or a list but is of type '%s'" % (
data,
type(data),
) )
assert not os.path.isdir(file_path), ( assert not os.path.isdir(file_path), (
"Error: file_path '%s' point to a dir, it should be a file" % file_path "Error: file_path '%s' point to a dir, it should be a file" % file_path
) )
assert os.path.isdir(os.path.dirname(file_path)), ( assert os.path.isdir(
"Error: the path ('%s') base dir ('%s') is not a dir" os.path.dirname(file_path)
% (file_path, os.path.dirname(file_path),) ), "Error: the path ('%s') base dir ('%s') is not a dir" % (
file_path,
os.path.dirname(file_path),
) )
# If data is a list, check elements are strings and build a single string # If data is a list, check elements are strings and build a single string
if not isinstance(data, str): if not isinstance(data, str):
for element in data: for element in data:
assert isinstance(element, str), ( assert isinstance(
"Error: element '%s' should be a string but is of type '%s' instead" element, str
% (element, type(element)) ), "Error: element '%s' should be a string but is of type '%s' instead" % (
element,
type(element),
) )
data = "\n".join(data) data = "\n".join(data)
@ -203,20 +211,26 @@ def write_to_json(file_path, data, sort_keys=False, indent=None):
""" """
# Assumptions # Assumptions
assert isinstance(file_path, str), ( assert isinstance(
"Error: file_path '%s' should be a string but is of type '%s' instead" file_path, str
% (file_path, type(file_path)) ), "Error: file_path '%s' should be a string but is of type '%s' instead" % (
file_path,
type(file_path),
) )
assert isinstance(data, dict) or isinstance(data, list), ( assert isinstance(data, dict) or isinstance(
"Error: data '%s' should be a dict or a list but is of type '%s' instead" data, list
% (data, type(data),) ), "Error: data '%s' should be a dict or a list but is of type '%s' instead" % (
data,
type(data),
) )
assert not os.path.isdir(file_path), ( assert not os.path.isdir(file_path), (
"Error: file_path '%s' point to a dir, it should be a file" % file_path "Error: file_path '%s' point to a dir, it should be a file" % file_path
) )
assert os.path.isdir(os.path.dirname(file_path)), ( assert os.path.isdir(
"Error: the path ('%s') base dir ('%s') is not a dir" os.path.dirname(file_path)
% (file_path, os.path.dirname(file_path),) ), "Error: the path ('%s') base dir ('%s') is not a dir" % (
file_path,
os.path.dirname(file_path),
) )
# Write dict to file # Write dict to file

View file

@ -19,19 +19,16 @@ class LogPipe(threading.Thread):
self.start() self.start()
def fileno(self): def fileno(self):
"""Return the write file descriptor of the pipe """Return the write file descriptor of the pipe"""
"""
return self.fdWrite return self.fdWrite
def run(self): def run(self):
"""Run the thread, logging everything. """Run the thread, logging everything."""
"""
for line in iter(self.pipeReader.readline, ""): for line in iter(self.pipeReader.readline, ""):
self.log_callback(line.strip("\n")) self.log_callback(line.strip("\n"))
self.pipeReader.close() self.pipeReader.close()
def close(self): def close(self):
"""Close the write end of the pipe. """Close the write end of the pipe."""
"""
os.close(self.fdWrite) os.close(self.fdWrite)

View file

@ -199,7 +199,8 @@ def combined_logger(
fmt=" ".join((log_name, sys_log_format)) fmt=" ".join((log_name, sys_log_format))
) )
my_syslog_handler = logging.handlers.SysLogHandler( my_syslog_handler = logging.handlers.SysLogHandler(
address="/dev/log", facility=SysLogHandler.LOG_DAEMON, address="/dev/log",
facility=SysLogHandler.LOG_DAEMON,
) )
my_syslog_handler.setFormatter(my_syslog_formatter) my_syslog_handler.setFormatter(my_syslog_formatter)
new_logger.addHandler(my_syslog_handler) new_logger.addHandler(my_syslog_handler)
@ -371,7 +372,8 @@ class SlapdObject(object):
""" """
include_directives = "\n".join( include_directives = "\n".join(
'include "{schema_prefix}/{schema_file}"'.format( 'include "{schema_prefix}/{schema_file}"'.format(
schema_prefix=self._schema_prefix, schema_file=schema_file, schema_prefix=self._schema_prefix,
schema_file=schema_file,
) )
for schema_file in self.openldap_schema_files for schema_file in self.openldap_schema_files
) )
@ -561,7 +563,13 @@ class SlapdObject(object):
if ldap_uri is None: if ldap_uri is None:
ldap_uri = self.default_ldap_uri ldap_uri = self.default_ldap_uri
args = ( args = (
[ldapcommand, "-H", ldap_uri,] + self._cli_auth_args() + (extra_args or []) [
ldapcommand,
"-H",
ldap_uri,
]
+ self._cli_auth_args()
+ (extra_args or [])
) )
self._log.debug("Run command: %r", " ".join(args)) self._log.debug("Run command: %r", " ".join(args))
proc = subprocess.Popen( proc = subprocess.Popen(

View file

@ -58,9 +58,11 @@ class TestLDAP:
def test_authenticate_sasl_non_interactive_bind(self, ldap_server): def test_authenticate_sasl_non_interactive_bind(self, ldap_server):
self.ldap_conf["parameters"]["uri"] = ldap_server.uri self.ldap_conf["parameters"]["uri"] = ldap_server.uri
self.ldap_conf["parameters"]["user_rdn"] = ( self.ldap_conf["parameters"][
"gidNumber=%s+uidNumber=%s,cn=peercred,cn=external,cn=auth" "user_rdn"
% (os.getgid(), os.getuid(),) ] = "gidNumber=%s+uidNumber=%s,cn=peercred,cn=external,cn=auth" % (
os.getgid(),
os.getuid(),
) )
ldap_interface = m_ldap.Authenticator(**self.ldap_conf) ldap_interface = m_ldap.Authenticator(**self.ldap_conf)