From 247a1fed3a609e11dd76b905cc0a2247dd6d3541 Mon Sep 17 00:00:00 2001 From: kakwa Date: Sat, 6 Jun 2015 22:23:21 +0200 Subject: [PATCH] removing trailling spaces --- ldapcherry/__init__.py | 16 ++++++++-------- ldapcherry/attributes.py | 2 +- ldapcherry/backend/__init__.py | 4 ++-- ldapcherry/backend/backendLdap.py | 16 ++++++++-------- ldapcherry/exceptions.py | 4 ++-- ldapcherry/pyyamlwrapper.py | 2 +- ldapcherry/roles.py | 9 ++++----- resources/templates/base.tmpl | 6 +++--- resources/templates/error.tmpl | 2 +- resources/templates/searchadmin.tmpl | 2 +- scripts/ldapcherryd | 22 +++++++++++----------- 11 files changed, 42 insertions(+), 43 deletions(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index 1998dcc..a5655aa 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -31,14 +31,14 @@ SESSION_KEY = '_cp_username' # Custom log function to overrige weird error.log function # of cherrypy -def syslog_error(msg='', context='', +def syslog_error(msg='', context='', severity=logging.INFO, traceback=False): if traceback: msg += cherrypy._cperror.format_exc() if context == '': cherrypy.log.error_log.log(severity, msg) else: - cherrypy.log.error_log.log(severity, + cherrypy.log.error_log.log(severity, ' '.join((context, msg))) class LdapCherry(object): @@ -120,7 +120,7 @@ class LdapCherry(object): try: bc = __import__(module, globals(), locals(), ['Backend'], -1) except: - raise BackendModuleLoadingFail(module) + raise BackendModuleLoadingFail(module) try: attrslist = self.attributes.get_backend_attributes(backend) key = self.attributes.get_backend_key(backend) @@ -190,8 +190,8 @@ class LdapCherry(object): cherrypy.log.error_log.handlers = [] # redefining log.error method because cherrypy does weird - # things like adding the date inside the message - # or adding space even if context is empty + # things like adding the date inside the message + # or adding space even if context is empty # (by the way, what's the use of "context"?) cherrypy.log.error = syslog_error @@ -263,7 +263,7 @@ class LdapCherry(object): """ try: # log configuration handling - # get log level + # get log level # (if not in configuration file, log level is set to debug) level = self._get_loglevel(self._get_param('global', 'log.level', config, 'debug')) # configure access log @@ -322,7 +322,7 @@ class LdapCherry(object): def _search(self, searchstring): if searchstring is None: return {} - ret = {} + ret = {} for b in self.backends: tmp = self.backends[b].search(searchstring) for u in tmp: @@ -395,7 +395,7 @@ class LdapCherry(object): @cherrypy.expose def logout(self): - """ logout page + """ logout page """ sess = cherrypy.session username = sess.get(SESSION_KEY, None) diff --git a/ldapcherry/attributes.py b/ldapcherry/attributes.py index 3575131..ae5913e 100644 --- a/ldapcherry/attributes.py +++ b/ldapcherry/attributes.py @@ -21,7 +21,7 @@ class Attributes: def __init__(self, attributes_file): self.attributes_file = attributes_file self.backends = Set([]) - self.self_attributes = {} + self.self_attributes = {} self.backend_attributes = {} self.displayed_attributes = {} self.key = None diff --git a/ldapcherry/backend/__init__.py b/ldapcherry/backend/__init__.py index ee3e9fc..3db9712 100644 --- a/ldapcherry/backend/__init__.py +++ b/ldapcherry/backend/__init__.py @@ -12,7 +12,7 @@ class Backend: def __init__(self): pass - def auth(self, username, password): + def auth(self, username, password): return False def add_user(self, attrs): @@ -44,6 +44,6 @@ class Backend: return self.config[param] elif not default is None: return default - else: + else: raise MissingParameter('backends', self.backend_name+'.'+param) diff --git a/ldapcherry/backend/backendLdap.py b/ldapcherry/backend/backendLdap.py index 867f46b..ab8d0a8 100644 --- a/ldapcherry/backend/backendLdap.py +++ b/ldapcherry/backend/backendLdap.py @@ -62,7 +62,7 @@ class Backend(ldapcherry.backend.Backend): ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_ALLOW) else: ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_DEMAND) - if self.starttls == 'on': + if self.starttls == 'on': try: ldap_client.start_tls_s() except ldap.OPERATIONS_ERROR as e: @@ -91,7 +91,7 @@ class Backend(ldapcherry.backend.Backend): msg = "Unable to contact ldap server '" + self.uri + "', check 'auth.ldap.uri' and ssl/tls configuration", ) ldap_client.unbind_s() - raise e + raise e return ldap_client def _search(self, searchfilter, attrs, basedn): @@ -225,31 +225,31 @@ class Backend(ldapcherry.backend.Backend): for u in self._search(searchfilter, None, self.userdn): attrs = {} attrs_tmp = u[1] - for attr in attrs_tmp: + for attr in attrs_tmp: value_tmp = attrs_tmp[attr] if len(value_tmp) == 1: attrs[attr] = value_tmp[0] else: attrs[attr] = value_tmp - + if self.key in attrs: ret[attrs[self.key]] = attrs - return ret + return ret def get_user(self, username): ret = {} attrs_tmp = self._get_user(username)[1] - for attr in attrs_tmp: + for attr in attrs_tmp: value_tmp = attrs_tmp[attr] if len(value_tmp) == 1: ret[attr] = value_tmp[0] else: ret[attr] = value_tmp - return ret + return ret def get_groups(self, username): userdn = self._get_user(username, False) - + searchfilter = self.group_filter_tmpl % { 'userdn': userdn, 'username': username diff --git a/ldapcherry/exceptions.py b/ldapcherry/exceptions.py index 4932725..146aa7a 100644 --- a/ldapcherry/exceptions.py +++ b/ldapcherry/exceptions.py @@ -18,7 +18,7 @@ class MissingKey(Exception): self.key = key self.section = section self.ymlfile = ymlfile - self.log = "missing key <%(key)s> in section <%(section)s> inside file <%(ymlfile)s>" % {'key': key, 'section': section, 'ymlfile': ymlfile } + self.log = "missing key <%(key)s> in section <%(section)s> inside file <%(ymlfile)s>" % {'key': key, 'section': section, 'ymlfile': ymlfile } class DumplicateRoleKey(Exception): def __init__(self, role): @@ -94,4 +94,4 @@ class WrongAttributeType(Exception): self.key = key self.section = section self.ymlfile = ymlfile - self.log = "wrong attribute type <%(key)s> in section <%(section)s> inside file <%(ymlfile)s>" % {'key': key, 'section': section, 'ymlfile': ymlfile } + self.log = "wrong attribute type <%(key)s> in section <%(section)s> inside file <%(ymlfile)s>" % {'key': key, 'section': section, 'ymlfile': ymlfile } diff --git a/ldapcherry/pyyamlwrapper.py b/ldapcherry/pyyamlwrapper.py index e0af1c9..d087e19 100644 --- a/ldapcherry/pyyamlwrapper.py +++ b/ldapcherry/pyyamlwrapper.py @@ -29,7 +29,7 @@ try: except ImportError: from yaml import Loader, Dumper -# PyYaml wrapper that loads yaml files throwing an exception +# PyYaml wrapper that loads yaml files throwing an exception #if a key is dumplicated class MyLoader(Reader, Scanner, Parser, Composer, Constructor, Resolver): diff --git a/ldapcherry/roles.py b/ldapcherry/roles.py index 8e8b40e..a6e8610 100644 --- a/ldapcherry/roles.py +++ b/ldapcherry/roles.py @@ -65,7 +65,7 @@ class Roles: if not groups is None: role['backends_groups'] = self._merge_groups([role['backends_groups'], groups]) if 'subroles' in role: - self._flatten(role['subroles'], + self._flatten(role['subroles'], role['backends_groups']) del role['subroles'] @@ -75,7 +75,6 @@ class Roles: self.admin_roles.append(r) self._set_admin(role['subroles'][r]) - def _is_parent(self, roleid1, roleid2): """Test if roleid1 is contained inside roleid2""" @@ -105,7 +104,7 @@ class Roles: def _nest(self): """nests the roles (creates roles hierarchy)""" self._flatten() - parents = {} + parents = {} for roleid in self.flatten: role = copy.deepcopy(self.flatten[roleid]) @@ -143,7 +142,7 @@ class Roles: if len(parents[p]) == 0: return ret else: - for i in parents[p]: + for i in parents[p]: sub = nest(i) ret['subroles'][i] = sub return ret @@ -205,7 +204,7 @@ class Roles: # if not, add role to the list of roles if flag: roles.add(role) - # else remove it from the list of roles and add + # else remove it from the list of roles and add # it to the list of parentroles else: if role in roles: diff --git a/resources/templates/base.tmpl b/resources/templates/base.tmpl index 30d40d9..42a3ec0 100644 --- a/resources/templates/base.tmpl +++ b/resources/templates/base.tmpl @@ -11,7 +11,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -38,7 +38,7 @@ diff --git a/resources/templates/error.tmpl b/resources/templates/error.tmpl index c0fcea4..a59a667 100644 --- a/resources/templates/error.tmpl +++ b/resources/templates/error.tmpl @@ -5,7 +5,7 @@

- ${message} + ${message}

Return diff --git a/resources/templates/searchadmin.tmpl b/resources/templates/searchadmin.tmpl index 79f2112..09f903f 100644 --- a/resources/templates/searchadmin.tmpl +++ b/resources/templates/searchadmin.tmpl @@ -52,7 +52,7 @@ - + diff --git a/scripts/ldapcherryd b/scripts/ldapcherryd index 1433d2b..337e2d3 100755 --- a/scripts/ldapcherryd +++ b/scripts/ldapcherryd @@ -21,7 +21,7 @@ def start(configfile=None, daemonize=False, environment=None, cgi=False): """Subscribe all engine plugins and start the engine.""" sys.path = [''] + sys.path - + # monkey patching cherrypy to disable config interpolation def new_as_dict(self, raw=True, vars=None): """Convert an INI file to a dictionary""" @@ -50,24 +50,24 @@ def start(configfile=None, daemonize=False, environment=None, instance.reload(app.config) engine = cherrypy.engine - + if environment is not None: cherrypy.config.update({'environment': environment}) - + # Only daemonize if asked to. if daemonize: # Don't print anything to stdout/sterr. cherrypy.config.update({'log.screen': False}) plugins.Daemonizer(engine).subscribe() - + if pidfile: plugins.PIDFile(engine, pidfile).subscribe() - + if hasattr(engine, "signal_handler"): engine.signal_handler.subscribe() if hasattr(engine, "console_control_handler"): engine.console_control_handler.subscribe() - + if (fastcgi and (scgi or cgi)) or (scgi and cgi): cherrypy.log.error("You may only specify one of the cgi, fastcgi, and " "scgi options.", 'ENGINE') @@ -77,7 +77,7 @@ def start(configfile=None, daemonize=False, environment=None, cherrypy.config.update({'engine.autoreload_on': False}) # Turn off the default HTTP server (which is subscribed by default). cherrypy.server.unsubscribe() - + addr = cherrypy.server.bind_addr if fastcgi: f = servers.FlupFCGIServer(application=cherrypy.tree, @@ -90,7 +90,7 @@ def start(configfile=None, daemonize=False, environment=None, bindAddress=addr) s = servers.ServerAdapter(engine, httpserver=f, bind_addr=addr) s.subscribe() - + # Always start the engine; this will start all other services try: engine.start() @@ -103,7 +103,7 @@ def start(configfile=None, daemonize=False, environment=None, if __name__ == '__main__': from optparse import OptionParser - + p = OptionParser() p.add_option('-c', '--config', dest='config', help="specify config file") @@ -122,7 +122,7 @@ if __name__ == '__main__': p.add_option('-P', '--Path', action="append", dest='Path', help="add the given paths to sys.path") options, args = p.parse_args() - + if options.Path: for p in options.Path: sys.path.insert(0, p) @@ -134,7 +134,7 @@ if __name__ == '__main__': if not os.path.isfile(options.config): print('configuration file "'+ options.config + '" doesn\'t exist' ) exit(1) - + start(options.config, options.daemonize, options.environment, options.fastcgi, options.scgi, options.pidfile, options.cgi)