Fix variable naming to conform with PEP-8

Originally proposed by @ZipFile in #998
This commit is contained in:
Unrud 2020-01-12 23:32:28 +01:00
parent d3d11d0ec8
commit 6202257fc2
10 changed files with 48 additions and 49 deletions

View File

@ -69,9 +69,9 @@ class Application(
"""Initialize application.""" """Initialize application."""
super().__init__() super().__init__()
self.configuration = configuration self.configuration = configuration
self.Auth = auth.load(configuration) self.auth = auth.load(configuration)
self.Collection = storage.load(configuration) self.storage = storage.load(configuration)
self.Rights = rights.load(configuration) self.rights = rights.load(configuration)
self.Web = web.load(configuration) self.Web = web.load(configuration)
self.encoding = configuration.get("encoding", "request") self.encoding = configuration.get("encoding", "request")
@ -224,7 +224,7 @@ class Application(
# Ask authentication backend to check rights # Ask authentication backend to check rights
login = password = "" login = password = ""
external_login = self.Auth.get_external_login(environ) external_login = self.auth.get_external_login(environ)
authorization = environ.get("HTTP_AUTHORIZATION", "") authorization = environ.get("HTTP_AUTHORIZATION", "")
if external_login: if external_login:
login, password = external_login login, password = external_login
@ -234,7 +234,7 @@ class Application(
login, password = self.decode(base64.b64decode( login, password = self.decode(base64.b64decode(
authorization.encode("ascii")), environ).split(":", 1) 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: if user and login == user:
logger.info("Successful login: %r", user) logger.info("Successful login: %r", user)
elif user: elif user:
@ -256,15 +256,15 @@ class Application(
# Create principal collection # Create principal collection
if user: if user:
principal_path = "/%s/" % user principal_path = "/%s/" % user
if self.Rights.authorized(user, principal_path, "W"): if self.rights.authorized(user, principal_path, "W"):
with self.Collection.acquire_lock("r", user): with self.storage.acquire_lock("r", user):
principal = next( principal = next(
self.Collection.discover(principal_path, depth="1"), self.storage.discover(principal_path, depth="1"),
None) None)
if not principal: if not principal:
with self.Collection.acquire_lock("w", user): with self.storage.acquire_lock("w", user):
try: try:
self.Collection.create_collection(principal_path) self.storage.create_collection(principal_path)
except ValueError as e: except ValueError as e:
logger.warning("Failed to create principal " logger.warning("Failed to create principal "
"collection %r: %s", user, e) "collection %r: %s", user, e)
@ -320,12 +320,12 @@ class Application(
else: else:
permissions = "" permissions = ""
parent_permissions = permission parent_permissions = permission
if permissions and self.Rights.authorized(user, path, permissions): if permissions and self.rights.authorized(user, path, permissions):
return True return True
if parent_permissions: if parent_permissions:
parent_path = pathutils.unstrip_path( parent_path = pathutils.unstrip_path(
posixpath.dirname(pathutils.strip_path(path)), True) 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 True
return False return False

View File

@ -51,8 +51,8 @@ class ApplicationDeleteMixin:
"""Manage DELETE request.""" """Manage DELETE request."""
if not self.access(user, path, "w"): if not self.access(user, path, "w"):
return httputils.NOT_ALLOWED return httputils.NOT_ALLOWED
with self.Collection.acquire_lock("w", user): with self.storage.acquire_lock("w", user):
item = next(self.Collection.discover(path), None) item = next(self.storage.discover(path), None)
if not item: if not item:
return httputils.NOT_FOUND return httputils.NOT_FOUND
if not self.access(user, path, "w", item): if not self.access(user, path, "w", item):

View File

@ -72,8 +72,8 @@ class ApplicationGetMixin:
return self.Web.get(environ, base_prefix, path, user) return self.Web.get(environ, base_prefix, path, user)
if not self.access(user, path, "r"): if not self.access(user, path, "r"):
return httputils.NOT_ALLOWED return httputils.NOT_ALLOWED
with self.Collection.acquire_lock("r", user): with self.storage.acquire_lock("r", user):
item = next(self.Collection.discover(path), None) item = next(self.storage.discover(path), None)
if not item: if not item:
return httputils.NOT_FOUND return httputils.NOT_FOUND
if not self.access(user, path, "r", item): if not self.access(user, path, "r", item):

View File

@ -30,7 +30,7 @@ from radicale.log import logger
class ApplicationMkcalendarMixin: class ApplicationMkcalendarMixin:
def do_MKCALENDAR(self, environ, base_prefix, path, user): def do_MKCALENDAR(self, environ, base_prefix, path, user):
"""Manage MKCALENDAR request.""" """Manage MKCALENDAR request."""
if not self.Rights.authorized(user, path, "w"): if not self.rights.authorized(user, path, "w"):
return httputils.NOT_ALLOWED return httputils.NOT_ALLOWED
try: try:
xml_content = self.read_xml_content(environ) xml_content = self.read_xml_content(environ)
@ -51,21 +51,21 @@ class ApplicationMkcalendarMixin:
except ValueError as e: except ValueError as e:
logger.warning( logger.warning(
"Bad MKCALENDAR request on %r: %s", path, e, exc_info=True) "Bad MKCALENDAR request on %r: %s", path, e, exc_info=True)
with self.Collection.acquire_lock("w", user): with self.storage.acquire_lock("w", user):
item = next(self.Collection.discover(path), None) item = next(self.storage.discover(path), None)
if item: if item:
return self.webdav_error_response( return self.webdav_error_response(
"D", "resource-must-be-null") "D", "resource-must-be-null")
parent_path = pathutils.unstrip_path( parent_path = pathutils.unstrip_path(
posixpath.dirname(pathutils.strip_path(path)), True) 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: if not parent_item:
return httputils.CONFLICT return httputils.CONFLICT
if (not isinstance(parent_item, storage.BaseCollection) or if (not isinstance(parent_item, storage.BaseCollection) or
parent_item.get_meta("tag")): parent_item.get_meta("tag")):
return httputils.FORBIDDEN return httputils.FORBIDDEN
try: try:
self.Collection.create_collection(path, props=props) self.storage.create_collection(path, props=props)
except ValueError as e: except ValueError as e:
logger.warning( logger.warning(
"Bad MKCALENDAR request on %r: %s", path, e, exc_info=True) "Bad MKCALENDAR request on %r: %s", path, e, exc_info=True)

View File

@ -30,7 +30,7 @@ from radicale.log import logger
class ApplicationMkcolMixin: class ApplicationMkcolMixin:
def do_MKCOL(self, environ, base_prefix, path, user): def do_MKCOL(self, environ, base_prefix, path, user):
"""Manage MKCOL request.""" """Manage MKCOL request."""
permissions = self.Rights.authorized(user, path, "Ww") permissions = self.rights.authorized(user, path, "Ww")
if not permissions: if not permissions:
return httputils.NOT_ALLOWED return httputils.NOT_ALLOWED
try: try:
@ -53,20 +53,20 @@ class ApplicationMkcolMixin:
if (props.get("tag") and "w" not in permissions or if (props.get("tag") and "w" not in permissions or
not props.get("tag") and "W" not in permissions): not props.get("tag") and "W" not in permissions):
return httputils.NOT_ALLOWED return httputils.NOT_ALLOWED
with self.Collection.acquire_lock("w", user): with self.storage.acquire_lock("w", user):
item = next(self.Collection.discover(path), None) item = next(self.storage.discover(path), None)
if item: if item:
return httputils.METHOD_NOT_ALLOWED return httputils.METHOD_NOT_ALLOWED
parent_path = pathutils.unstrip_path( parent_path = pathutils.unstrip_path(
posixpath.dirname(pathutils.strip_path(path)), True) 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: if not parent_item:
return httputils.CONFLICT return httputils.CONFLICT
if (not isinstance(parent_item, storage.BaseCollection) or if (not isinstance(parent_item, storage.BaseCollection) or
parent_item.get_meta("tag")): parent_item.get_meta("tag")):
return httputils.FORBIDDEN return httputils.FORBIDDEN
try: try:
self.Collection.create_collection(path, props=props) self.storage.create_collection(path, props=props)
except ValueError as e: except ValueError as e:
logger.warning( logger.warning(
"Bad MKCOL request on %r: %s", path, e, exc_info=True) "Bad MKCOL request on %r: %s", path, e, exc_info=True)

View File

@ -45,8 +45,8 @@ class ApplicationMoveMixin:
if not self.access(user, to_path, "w"): if not self.access(user, to_path, "w"):
return httputils.NOT_ALLOWED return httputils.NOT_ALLOWED
with self.Collection.acquire_lock("w", user): with self.storage.acquire_lock("w", user):
item = next(self.Collection.discover(path), None) item = next(self.storage.discover(path), None)
if not item: if not item:
return httputils.NOT_FOUND return httputils.NOT_FOUND
if (not self.access(user, path, "w", item) or if (not self.access(user, path, "w", item) or
@ -56,13 +56,13 @@ class ApplicationMoveMixin:
# TODO: support moving collections # TODO: support moving collections
return httputils.METHOD_NOT_ALLOWED 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): if isinstance(to_item, storage.BaseCollection):
return httputils.FORBIDDEN return httputils.FORBIDDEN
to_parent_path = pathutils.unstrip_path( to_parent_path = pathutils.unstrip_path(
posixpath.dirname(pathutils.strip_path(to_path)), True) posixpath.dirname(pathutils.strip_path(to_path)), True)
to_collection = next( to_collection = next(
self.Collection.discover(to_parent_path), None) self.storage.discover(to_parent_path), None)
if not to_collection: if not to_collection:
return httputils.CONFLICT return httputils.CONFLICT
tag = item.collection.get_meta("tag") tag = item.collection.get_meta("tag")
@ -78,7 +78,7 @@ class ApplicationMoveMixin:
"C" if tag == "VCALENDAR" else "CR", "no-uid-conflict") "C" if tag == "VCALENDAR" else "CR", "no-uid-conflict")
to_href = posixpath.basename(pathutils.strip_path(to_path)) to_href = posixpath.basename(pathutils.strip_path(to_path))
try: try:
self.Collection.move(item, to_collection, to_href) self.storage.move(item, to_collection, to_href)
except ValueError as e: except ValueError as e:
logger.warning( logger.warning(
"Bad MOVE request on %r: %s", path, e, exc_info=True) "Bad MOVE request on %r: %s", path, e, exc_info=True)

View File

@ -331,14 +331,14 @@ class ApplicationPropfindMixin:
if isinstance(item, storage.BaseCollection): if isinstance(item, storage.BaseCollection):
path = pathutils.unstrip_path(item.path, True) path = pathutils.unstrip_path(item.path, True)
if item.get_meta("tag"): 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 target = "collection with tag %r" % item.path
else: else:
permissions = self.Rights.authorized(user, path, "RW") permissions = self.rights.authorized(user, path, "RW")
target = "collection %r" % item.path target = "collection %r" % item.path
else: else:
path = pathutils.unstrip_path(item.collection.path, True) 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) target = "item %r from %r" % (item.href, item.collection.path)
if rights.intersect_permissions(permissions, "Ww"): if rights.intersect_permissions(permissions, "Ww"):
permission = "w" permission = "w"
@ -368,9 +368,8 @@ class ApplicationPropfindMixin:
except socket.timeout: except socket.timeout:
logger.debug("client timed out", exc_info=True) logger.debug("client timed out", exc_info=True)
return httputils.REQUEST_TIMEOUT return httputils.REQUEST_TIMEOUT
with self.Collection.acquire_lock("r", user): with self.storage.acquire_lock("r", user):
items = self.Collection.discover( items = self.storage.discover(path, environ.get("HTTP_DEPTH", "0"))
path, environ.get("HTTP_DEPTH", "0"))
# take root item for rights checking # take root item for rights checking
item = next(items, None) item = next(items, None)
if not item: if not item:

View File

@ -98,8 +98,8 @@ class ApplicationProppatchMixin:
except socket.timeout: except socket.timeout:
logger.debug("client timed out", exc_info=True) logger.debug("client timed out", exc_info=True)
return httputils.REQUEST_TIMEOUT return httputils.REQUEST_TIMEOUT
with self.Collection.acquire_lock("w", user): with self.storage.acquire_lock("w", user):
item = next(self.Collection.discover(path), None) item = next(self.storage.discover(path), None)
if not item: if not item:
return httputils.NOT_FOUND return httputils.NOT_FOUND
if not self.access(user, path, "w", item): if not self.access(user, path, "w", item):

View File

@ -47,8 +47,8 @@ class ApplicationPutMixin:
# Prepare before locking # Prepare before locking
parent_path = pathutils.unstrip_path( parent_path = pathutils.unstrip_path(
posixpath.dirname(pathutils.strip_path(path)), True) posixpath.dirname(pathutils.strip_path(path)), True)
permissions = self.Rights.authorized(user, path, "Ww") permissions = self.rights.authorized(user, path, "Ww")
parent_permissions = self.Rights.authorized(user, parent_path, "w") parent_permissions = self.rights.authorized(user, parent_path, "w")
def prepare(vobject_items, tag=None, write_whole_collection=None): def prepare(vobject_items, tag=None, write_whole_collection=None):
if (write_whole_collection or if (write_whole_collection or
@ -149,9 +149,9 @@ class ApplicationPutMixin:
(prepared_items, prepared_tag, prepared_write_whole_collection, (prepared_items, prepared_tag, prepared_write_whole_collection,
prepared_props, prepared_exc_info) = prepare(vobject_items) prepared_props, prepared_exc_info) = prepare(vobject_items)
with self.Collection.acquire_lock("w", user): with self.storage.acquire_lock("w", user):
item = next(self.Collection.discover(path), None) item = next(self.storage.discover(path), None)
parent_item = next(self.Collection.discover(parent_path), None) parent_item = next(self.storage.discover(parent_path), None)
if not parent_item: if not parent_item:
return httputils.CONFLICT return httputils.CONFLICT
@ -165,9 +165,9 @@ class ApplicationPutMixin:
tag = parent_item.get_meta("tag") tag = parent_item.get_meta("tag")
if write_whole_collection: 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 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 return httputils.NOT_ALLOWED
etag = environ.get("HTTP_IF_MATCH", "") etag = environ.get("HTTP_IF_MATCH", "")
@ -197,7 +197,7 @@ class ApplicationPutMixin:
if write_whole_collection: if write_whole_collection:
try: try:
etag = self.Collection.create_collection( etag = self.storage.create_collection(
path, prepared_items, props).etag path, prepared_items, props).etag
except ValueError as e: except ValueError as e:
logger.warning( logger.warning(

View File

@ -270,8 +270,8 @@ class ApplicationReportMixin:
logger.debug("client timed out", exc_info=True) logger.debug("client timed out", exc_info=True)
return httputils.REQUEST_TIMEOUT return httputils.REQUEST_TIMEOUT
with contextlib.ExitStack() as lock_stack: with contextlib.ExitStack() as lock_stack:
lock_stack.enter_context(self.Collection.acquire_lock("r", user)) lock_stack.enter_context(self.storage.acquire_lock("r", user))
item = next(self.Collection.discover(path), None) item = next(self.storage.discover(path), None)
if not item: if not item:
return httputils.NOT_FOUND return httputils.NOT_FOUND
if not self.access(user, path, "r", item): if not self.access(user, path, "r", item):