Clean code and add comments using pylint
This commit is contained in:
parent
2be5af3ad0
commit
a2f1e173d6
@ -151,6 +151,7 @@ class Application(object):
|
|||||||
# Get function corresponding to method
|
# Get function corresponding to method
|
||||||
function = getattr(self, environ["REQUEST_METHOD"].lower())
|
function = getattr(self, environ["REQUEST_METHOD"].lower())
|
||||||
|
|
||||||
|
# Check rights
|
||||||
if not calendar or not self.acl:
|
if not calendar or not self.acl:
|
||||||
# No calendar or no acl, don't check rights
|
# No calendar or no acl, don't check rights
|
||||||
status, headers, answer = function(environ, calendar, content)
|
status, headers, answer = function(environ, calendar, content)
|
||||||
@ -158,7 +159,7 @@ class Application(object):
|
|||||||
# No owner and personal calendars, don't check rights
|
# No owner and personal calendars, don't check rights
|
||||||
status, headers, answer = function(environ, calendar, content)
|
status, headers, answer = function(environ, calendar, content)
|
||||||
else:
|
else:
|
||||||
# Check rights
|
# Ask authentication backend to check rights
|
||||||
log.LOGGER.info(
|
log.LOGGER.info(
|
||||||
"Checking rights for calendar owned by %s" % calendar.owner)
|
"Checking rights for calendar owned by %s" % calendar.owner)
|
||||||
authorization = environ.get("HTTP_AUTHORIZATION", None)
|
authorization = environ.get("HTTP_AUTHORIZATION", None)
|
||||||
@ -193,6 +194,9 @@ class Application(object):
|
|||||||
# Return response content
|
# Return response content
|
||||||
return [answer] if answer else []
|
return [answer] if answer else []
|
||||||
|
|
||||||
|
# All these functions must have the same parameters, some are useless
|
||||||
|
# pylint: disable=W0612,W0613,R0201
|
||||||
|
|
||||||
def get(self, environ, calendar, content):
|
def get(self, environ, calendar, content):
|
||||||
"""Manage GET request."""
|
"""Manage GET request."""
|
||||||
item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar)
|
item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar)
|
||||||
@ -291,3 +295,5 @@ class Application(object):
|
|||||||
"""Manage REPORT request."""
|
"""Manage REPORT request."""
|
||||||
answer = xmlutils.report(environ["PATH_INFO"], content, calendar)
|
answer = xmlutils.report(environ["PATH_INFO"], content, calendar)
|
||||||
return client.MULTI_STATUS, {}, answer
|
return client.MULTI_STATUS, {}, answer
|
||||||
|
|
||||||
|
# pylint: enable=W0612,W0613,R0201
|
||||||
|
@ -41,10 +41,10 @@ def has_right(owner, user, password):
|
|||||||
# User is not owner and personal calendars, or no user given, forbidden
|
# User is not owner and personal calendars, or no user given, forbidden
|
||||||
return False
|
return False
|
||||||
|
|
||||||
dn = "%s=%s" % (ATTRIBUTE, ldap.dn.escape_dn_chars(user))
|
distinguished_name = "%s=%s" % (ATTRIBUTE, ldap.dn.escape_dn_chars(user))
|
||||||
log.LOGGER.debug("LDAP bind for %s in base %s" % (dn, BASE))
|
log.LOGGER.debug("LDAP bind for %s in base %s" % (distinguished_name, BASE))
|
||||||
|
|
||||||
users = CONNEXION.search_s(BASE, ldap.SCOPE_ONELEVEL, dn)
|
users = CONNEXION.search_s(BASE, ldap.SCOPE_ONELEVEL, distinguished_name)
|
||||||
if users:
|
if users:
|
||||||
log.LOGGER.debug("User %s found" % user)
|
log.LOGGER.debug("User %s found" % user)
|
||||||
try:
|
try:
|
||||||
|
@ -153,22 +153,25 @@ def propfind(path, xml_request, calendar, depth):
|
|||||||
tag.text = path
|
tag.text = path
|
||||||
element.append(tag)
|
element.append(tag)
|
||||||
elif tag == _tag("C", "supported-calendar-component-set"):
|
elif tag == _tag("C", "supported-calendar-component-set"):
|
||||||
|
# This is not a Todo
|
||||||
|
# pylint: disable=W0511
|
||||||
for component in ("VTODO", "VEVENT", "VJOURNAL"):
|
for component in ("VTODO", "VEVENT", "VJOURNAL"):
|
||||||
comp = ET.Element(_tag("C", "comp"))
|
comp = ET.Element(_tag("C", "comp"))
|
||||||
comp.set("name", component)
|
comp.set("name", component)
|
||||||
element.append(comp)
|
element.append(comp)
|
||||||
|
# pylint: enable=W0511
|
||||||
elif tag == _tag("D", "current-user-privilege-set"):
|
elif tag == _tag("D", "current-user-privilege-set"):
|
||||||
privilege = ET.Element(_tag("D", "privilege"))
|
privilege = ET.Element(_tag("D", "privilege"))
|
||||||
privilege.append(ET.Element(_tag("D", "all")))
|
privilege.append(ET.Element(_tag("D", "all")))
|
||||||
element.append(privilege)
|
element.append(privilege)
|
||||||
elif tag == _tag("D", "supported-report-set"):
|
elif tag == _tag("D", "supported-report-set"):
|
||||||
for report_name in (
|
for report_name in (
|
||||||
"principal-property-search", "principal-search-property-set",
|
"principal-property-search", "sync-collection"
|
||||||
"expand-property", "sync-collection"):
|
"expand-property", "principal-search-property-set"):
|
||||||
supported = ET.Element(_tag("D", "supported-report"))
|
supported = ET.Element(_tag("D", "supported-report"))
|
||||||
report = ET.Element(_tag("D", "report"))
|
report_tag = ET.Element(_tag("D", "report"))
|
||||||
report.text = report_name
|
report_tag.text = report_name
|
||||||
supported.append(report)
|
supported.append(report_tag)
|
||||||
element.append(supported)
|
element.append(supported)
|
||||||
prop.append(element)
|
prop.append(element)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user