Fix variable naming to conform with PEP-8
Originally proposed by @ZipFile in #998
This commit is contained in:
		| @@ -69,9 +69,9 @@ class Application( | ||||
|         """Initialize application.""" | ||||
|         super().__init__() | ||||
|         self.configuration = configuration | ||||
|         self.Auth = auth.load(configuration) | ||||
|         self.Collection = storage.load(configuration) | ||||
|         self.Rights = rights.load(configuration) | ||||
|         self.auth = auth.load(configuration) | ||||
|         self.storage = storage.load(configuration) | ||||
|         self.rights = rights.load(configuration) | ||||
|         self.Web = web.load(configuration) | ||||
|         self.encoding = configuration.get("encoding", "request") | ||||
|  | ||||
| @@ -224,7 +224,7 @@ class Application( | ||||
|  | ||||
|         # Ask authentication backend to check rights | ||||
|         login = password = "" | ||||
|         external_login = self.Auth.get_external_login(environ) | ||||
|         external_login = self.auth.get_external_login(environ) | ||||
|         authorization = environ.get("HTTP_AUTHORIZATION", "") | ||||
|         if external_login: | ||||
|             login, password = external_login | ||||
| @@ -234,7 +234,7 @@ class Application( | ||||
|             login, password = self.decode(base64.b64decode( | ||||
|                 authorization.encode("ascii")), environ).split(":", 1) | ||||
|  | ||||
|         user = self.Auth.login(login, password) or "" if login else "" | ||||
|         user = self.auth.login(login, password) or "" if login else "" | ||||
|         if user and login == user: | ||||
|             logger.info("Successful login: %r", user) | ||||
|         elif user: | ||||
| @@ -256,15 +256,15 @@ class Application( | ||||
|         # Create principal collection | ||||
|         if user: | ||||
|             principal_path = "/%s/" % user | ||||
|             if self.Rights.authorized(user, principal_path, "W"): | ||||
|                 with self.Collection.acquire_lock("r", user): | ||||
|             if self.rights.authorized(user, principal_path, "W"): | ||||
|                 with self.storage.acquire_lock("r", user): | ||||
|                     principal = next( | ||||
|                         self.Collection.discover(principal_path, depth="1"), | ||||
|                         self.storage.discover(principal_path, depth="1"), | ||||
|                         None) | ||||
|                 if not principal: | ||||
|                     with self.Collection.acquire_lock("w", user): | ||||
|                     with self.storage.acquire_lock("w", user): | ||||
|                         try: | ||||
|                             self.Collection.create_collection(principal_path) | ||||
|                             self.storage.create_collection(principal_path) | ||||
|                         except ValueError as e: | ||||
|                             logger.warning("Failed to create principal " | ||||
|                                            "collection %r: %s", user, e) | ||||
| @@ -320,12 +320,12 @@ class Application( | ||||
|         else: | ||||
|             permissions = "" | ||||
|             parent_permissions = permission | ||||
|         if permissions and self.Rights.authorized(user, path, permissions): | ||||
|         if permissions and self.rights.authorized(user, path, permissions): | ||||
|             return True | ||||
|         if parent_permissions: | ||||
|             parent_path = pathutils.unstrip_path( | ||||
|                 posixpath.dirname(pathutils.strip_path(path)), True) | ||||
|             if self.Rights.authorized(user, parent_path, parent_permissions): | ||||
|             if self.rights.authorized(user, parent_path, parent_permissions): | ||||
|                 return True | ||||
|         return False | ||||
|  | ||||
|   | ||||
| @@ -51,8 +51,8 @@ class ApplicationDeleteMixin: | ||||
|         """Manage DELETE request.""" | ||||
|         if not self.access(user, path, "w"): | ||||
|             return httputils.NOT_ALLOWED | ||||
|         with self.Collection.acquire_lock("w", user): | ||||
|             item = next(self.Collection.discover(path), None) | ||||
|         with self.storage.acquire_lock("w", user): | ||||
|             item = next(self.storage.discover(path), None) | ||||
|             if not item: | ||||
|                 return httputils.NOT_FOUND | ||||
|             if not self.access(user, path, "w", item): | ||||
|   | ||||
| @@ -72,8 +72,8 @@ class ApplicationGetMixin: | ||||
|             return self.Web.get(environ, base_prefix, path, user) | ||||
|         if not self.access(user, path, "r"): | ||||
|             return httputils.NOT_ALLOWED | ||||
|         with self.Collection.acquire_lock("r", user): | ||||
|             item = next(self.Collection.discover(path), None) | ||||
|         with self.storage.acquire_lock("r", user): | ||||
|             item = next(self.storage.discover(path), None) | ||||
|             if not item: | ||||
|                 return httputils.NOT_FOUND | ||||
|             if not self.access(user, path, "r", item): | ||||
|   | ||||
| @@ -30,7 +30,7 @@ from radicale.log import logger | ||||
| class ApplicationMkcalendarMixin: | ||||
|     def do_MKCALENDAR(self, environ, base_prefix, path, user): | ||||
|         """Manage MKCALENDAR request.""" | ||||
|         if not self.Rights.authorized(user, path, "w"): | ||||
|         if not self.rights.authorized(user, path, "w"): | ||||
|             return httputils.NOT_ALLOWED | ||||
|         try: | ||||
|             xml_content = self.read_xml_content(environ) | ||||
| @@ -51,21 +51,21 @@ class ApplicationMkcalendarMixin: | ||||
|         except ValueError as e: | ||||
|             logger.warning( | ||||
|                 "Bad MKCALENDAR request on %r: %s", path, e, exc_info=True) | ||||
|         with self.Collection.acquire_lock("w", user): | ||||
|             item = next(self.Collection.discover(path), None) | ||||
|         with self.storage.acquire_lock("w", user): | ||||
|             item = next(self.storage.discover(path), None) | ||||
|             if item: | ||||
|                 return self.webdav_error_response( | ||||
|                     "D", "resource-must-be-null") | ||||
|             parent_path = pathutils.unstrip_path( | ||||
|                 posixpath.dirname(pathutils.strip_path(path)), True) | ||||
|             parent_item = next(self.Collection.discover(parent_path), None) | ||||
|             parent_item = next(self.storage.discover(parent_path), None) | ||||
|             if not parent_item: | ||||
|                 return httputils.CONFLICT | ||||
|             if (not isinstance(parent_item, storage.BaseCollection) or | ||||
|                     parent_item.get_meta("tag")): | ||||
|                 return httputils.FORBIDDEN | ||||
|             try: | ||||
|                 self.Collection.create_collection(path, props=props) | ||||
|                 self.storage.create_collection(path, props=props) | ||||
|             except ValueError as e: | ||||
|                 logger.warning( | ||||
|                     "Bad MKCALENDAR request on %r: %s", path, e, exc_info=True) | ||||
|   | ||||
| @@ -30,7 +30,7 @@ from radicale.log import logger | ||||
| class ApplicationMkcolMixin: | ||||
|     def do_MKCOL(self, environ, base_prefix, path, user): | ||||
|         """Manage MKCOL request.""" | ||||
|         permissions = self.Rights.authorized(user, path, "Ww") | ||||
|         permissions = self.rights.authorized(user, path, "Ww") | ||||
|         if not permissions: | ||||
|             return httputils.NOT_ALLOWED | ||||
|         try: | ||||
| @@ -53,20 +53,20 @@ class ApplicationMkcolMixin: | ||||
|         if (props.get("tag") and "w" not in permissions or | ||||
|                 not props.get("tag") and "W" not in permissions): | ||||
|             return httputils.NOT_ALLOWED | ||||
|         with self.Collection.acquire_lock("w", user): | ||||
|             item = next(self.Collection.discover(path), None) | ||||
|         with self.storage.acquire_lock("w", user): | ||||
|             item = next(self.storage.discover(path), None) | ||||
|             if item: | ||||
|                 return httputils.METHOD_NOT_ALLOWED | ||||
|             parent_path = pathutils.unstrip_path( | ||||
|                 posixpath.dirname(pathutils.strip_path(path)), True) | ||||
|             parent_item = next(self.Collection.discover(parent_path), None) | ||||
|             parent_item = next(self.storage.discover(parent_path), None) | ||||
|             if not parent_item: | ||||
|                 return httputils.CONFLICT | ||||
|             if (not isinstance(parent_item, storage.BaseCollection) or | ||||
|                     parent_item.get_meta("tag")): | ||||
|                 return httputils.FORBIDDEN | ||||
|             try: | ||||
|                 self.Collection.create_collection(path, props=props) | ||||
|                 self.storage.create_collection(path, props=props) | ||||
|             except ValueError as e: | ||||
|                 logger.warning( | ||||
|                     "Bad MKCOL request on %r: %s", path, e, exc_info=True) | ||||
|   | ||||
| @@ -45,8 +45,8 @@ class ApplicationMoveMixin: | ||||
|         if not self.access(user, to_path, "w"): | ||||
|             return httputils.NOT_ALLOWED | ||||
|  | ||||
|         with self.Collection.acquire_lock("w", user): | ||||
|             item = next(self.Collection.discover(path), None) | ||||
|         with self.storage.acquire_lock("w", user): | ||||
|             item = next(self.storage.discover(path), None) | ||||
|             if not item: | ||||
|                 return httputils.NOT_FOUND | ||||
|             if (not self.access(user, path, "w", item) or | ||||
| @@ -56,13 +56,13 @@ class ApplicationMoveMixin: | ||||
|                 # TODO: support moving collections | ||||
|                 return httputils.METHOD_NOT_ALLOWED | ||||
|  | ||||
|             to_item = next(self.Collection.discover(to_path), None) | ||||
|             to_item = next(self.storage.discover(to_path), None) | ||||
|             if isinstance(to_item, storage.BaseCollection): | ||||
|                 return httputils.FORBIDDEN | ||||
|             to_parent_path = pathutils.unstrip_path( | ||||
|                 posixpath.dirname(pathutils.strip_path(to_path)), True) | ||||
|             to_collection = next( | ||||
|                 self.Collection.discover(to_parent_path), None) | ||||
|                 self.storage.discover(to_parent_path), None) | ||||
|             if not to_collection: | ||||
|                 return httputils.CONFLICT | ||||
|             tag = item.collection.get_meta("tag") | ||||
| @@ -78,7 +78,7 @@ class ApplicationMoveMixin: | ||||
|                     "C" if tag == "VCALENDAR" else "CR", "no-uid-conflict") | ||||
|             to_href = posixpath.basename(pathutils.strip_path(to_path)) | ||||
|             try: | ||||
|                 self.Collection.move(item, to_collection, to_href) | ||||
|                 self.storage.move(item, to_collection, to_href) | ||||
|             except ValueError as e: | ||||
|                 logger.warning( | ||||
|                     "Bad MOVE request on %r: %s", path, e, exc_info=True) | ||||
|   | ||||
| @@ -331,14 +331,14 @@ class ApplicationPropfindMixin: | ||||
|             if isinstance(item, storage.BaseCollection): | ||||
|                 path = pathutils.unstrip_path(item.path, True) | ||||
|                 if item.get_meta("tag"): | ||||
|                     permissions = self.Rights.authorized(user, path, "rw") | ||||
|                     permissions = self.rights.authorized(user, path, "rw") | ||||
|                     target = "collection with tag %r" % item.path | ||||
|                 else: | ||||
|                     permissions = self.Rights.authorized(user, path, "RW") | ||||
|                     permissions = self.rights.authorized(user, path, "RW") | ||||
|                     target = "collection %r" % item.path | ||||
|             else: | ||||
|                 path = pathutils.unstrip_path(item.collection.path, True) | ||||
|                 permissions = self.Rights.authorized(user, path, "rw") | ||||
|                 permissions = self.rights.authorized(user, path, "rw") | ||||
|                 target = "item %r from %r" % (item.href, item.collection.path) | ||||
|             if rights.intersect_permissions(permissions, "Ww"): | ||||
|                 permission = "w" | ||||
| @@ -368,9 +368,8 @@ class ApplicationPropfindMixin: | ||||
|         except socket.timeout: | ||||
|             logger.debug("client timed out", exc_info=True) | ||||
|             return httputils.REQUEST_TIMEOUT | ||||
|         with self.Collection.acquire_lock("r", user): | ||||
|             items = self.Collection.discover( | ||||
|                 path, environ.get("HTTP_DEPTH", "0")) | ||||
|         with self.storage.acquire_lock("r", user): | ||||
|             items = self.storage.discover(path, environ.get("HTTP_DEPTH", "0")) | ||||
|             # take root item for rights checking | ||||
|             item = next(items, None) | ||||
|             if not item: | ||||
|   | ||||
| @@ -98,8 +98,8 @@ class ApplicationProppatchMixin: | ||||
|         except socket.timeout: | ||||
|             logger.debug("client timed out", exc_info=True) | ||||
|             return httputils.REQUEST_TIMEOUT | ||||
|         with self.Collection.acquire_lock("w", user): | ||||
|             item = next(self.Collection.discover(path), None) | ||||
|         with self.storage.acquire_lock("w", user): | ||||
|             item = next(self.storage.discover(path), None) | ||||
|             if not item: | ||||
|                 return httputils.NOT_FOUND | ||||
|             if not self.access(user, path, "w", item): | ||||
|   | ||||
| @@ -47,8 +47,8 @@ class ApplicationPutMixin: | ||||
|         # Prepare before locking | ||||
|         parent_path = pathutils.unstrip_path( | ||||
|             posixpath.dirname(pathutils.strip_path(path)), True) | ||||
|         permissions = self.Rights.authorized(user, path, "Ww") | ||||
|         parent_permissions = self.Rights.authorized(user, parent_path, "w") | ||||
|         permissions = self.rights.authorized(user, path, "Ww") | ||||
|         parent_permissions = self.rights.authorized(user, parent_path, "w") | ||||
|  | ||||
|         def prepare(vobject_items, tag=None, write_whole_collection=None): | ||||
|             if (write_whole_collection or | ||||
| @@ -149,9 +149,9 @@ class ApplicationPutMixin: | ||||
|         (prepared_items, prepared_tag, prepared_write_whole_collection, | ||||
|          prepared_props, prepared_exc_info) = prepare(vobject_items) | ||||
|  | ||||
|         with self.Collection.acquire_lock("w", user): | ||||
|             item = next(self.Collection.discover(path), None) | ||||
|             parent_item = next(self.Collection.discover(parent_path), None) | ||||
|         with self.storage.acquire_lock("w", user): | ||||
|             item = next(self.storage.discover(path), None) | ||||
|             parent_item = next(self.storage.discover(parent_path), None) | ||||
|             if not parent_item: | ||||
|                 return httputils.CONFLICT | ||||
|  | ||||
| @@ -165,9 +165,9 @@ class ApplicationPutMixin: | ||||
|                 tag = parent_item.get_meta("tag") | ||||
|  | ||||
|             if write_whole_collection: | ||||
|                 if not self.Rights.authorized(user, path, "w" if tag else "W"): | ||||
|                 if not self.rights.authorized(user, path, "w" if tag else "W"): | ||||
|                     return httputils.NOT_ALLOWED | ||||
|             elif not self.Rights.authorized(user, parent_path, "w"): | ||||
|             elif not self.rights.authorized(user, parent_path, "w"): | ||||
|                 return httputils.NOT_ALLOWED | ||||
|  | ||||
|             etag = environ.get("HTTP_IF_MATCH", "") | ||||
| @@ -197,7 +197,7 @@ class ApplicationPutMixin: | ||||
|  | ||||
|             if write_whole_collection: | ||||
|                 try: | ||||
|                     etag = self.Collection.create_collection( | ||||
|                     etag = self.storage.create_collection( | ||||
|                         path, prepared_items, props).etag | ||||
|                 except ValueError as e: | ||||
|                     logger.warning( | ||||
|   | ||||
| @@ -270,8 +270,8 @@ class ApplicationReportMixin: | ||||
|             logger.debug("client timed out", exc_info=True) | ||||
|             return httputils.REQUEST_TIMEOUT | ||||
|         with contextlib.ExitStack() as lock_stack: | ||||
|             lock_stack.enter_context(self.Collection.acquire_lock("r", user)) | ||||
|             item = next(self.Collection.discover(path), None) | ||||
|             lock_stack.enter_context(self.storage.acquire_lock("r", user)) | ||||
|             item = next(self.storage.discover(path), None) | ||||
|             if not item: | ||||
|                 return httputils.NOT_FOUND | ||||
|             if not self.access(user, path, "r", item): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Unrud
					Unrud