Ver Fonte

Clean code and add comments using pylint

Guillaume Ayoub há 15 anos atrás
pai
commit
a2f1e173d6
3 ficheiros alterados com 18 adições e 9 exclusões
  1. 7 1
      radicale/__init__.py
  2. 3 3
      radicale/acl/LDAP.py
  3. 8 5
      radicale/xmlutils.py

+ 7 - 1
radicale/__init__.py

@@ -151,6 +151,7 @@ class Application(object):
         # Get function corresponding to method
         function = getattr(self, environ["REQUEST_METHOD"].lower())
 
+        # Check rights
         if not calendar or not self.acl:
             # No calendar or no acl, don't check rights
             status, headers, answer = function(environ, calendar, content)
@@ -158,7 +159,7 @@ class Application(object):
             # No owner and personal calendars, don't check rights
             status, headers, answer = function(environ, calendar, content)
         else:
-            # Check rights
+            # Ask authentication backend to check rights
             log.LOGGER.info(
                 "Checking rights for calendar owned by %s" % calendar.owner)
             authorization = environ.get("HTTP_AUTHORIZATION", None)
@@ -193,6 +194,9 @@ class Application(object):
         # Return response content
         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):
         """Manage GET request."""
         item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar)
@@ -291,3 +295,5 @@ class Application(object):
         """Manage REPORT request."""
         answer = xmlutils.report(environ["PATH_INFO"], content, calendar)
         return client.MULTI_STATUS, {}, answer
+
+    # pylint: enable=W0612,W0613,R0201

+ 3 - 3
radicale/acl/LDAP.py

@@ -41,10 +41,10 @@ def has_right(owner, user, password):
         # User is not owner and personal calendars, or no user given, forbidden
         return False
 
-    dn = "%s=%s" % (ATTRIBUTE, ldap.dn.escape_dn_chars(user))
-    log.LOGGER.debug("LDAP bind for %s in base %s" % (dn, BASE))
+    distinguished_name = "%s=%s" % (ATTRIBUTE, ldap.dn.escape_dn_chars(user))
+    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:
         log.LOGGER.debug("User %s found" % user)
         try:

+ 8 - 5
radicale/xmlutils.py

@@ -153,22 +153,25 @@ def propfind(path, xml_request, calendar, depth):
                 tag.text = path
                 element.append(tag)
             elif tag == _tag("C", "supported-calendar-component-set"):
+                # This is not a Todo
+                # pylint: disable=W0511
                 for component in ("VTODO", "VEVENT", "VJOURNAL"):
                     comp = ET.Element(_tag("C", "comp"))
                     comp.set("name", component)
                     element.append(comp)
+                # pylint: enable=W0511
             elif tag == _tag("D", "current-user-privilege-set"):
                 privilege = ET.Element(_tag("D", "privilege"))
                 privilege.append(ET.Element(_tag("D", "all")))
                 element.append(privilege)
             elif tag == _tag("D", "supported-report-set"):
                 for report_name in (
-                    "principal-property-search", "principal-search-property-set",
-                    "expand-property", "sync-collection"):
+                    "principal-property-search", "sync-collection"
+                    "expand-property", "principal-search-property-set"):
                     supported = ET.Element(_tag("D", "supported-report"))
-                    report = ET.Element(_tag("D", "report"))
-                    report.text = report_name
-                    supported.append(report)
+                    report_tag = ET.Element(_tag("D", "report"))
+                    report_tag.text = report_name
+                    supported.append(report_tag)
                     element.append(supported)
             prop.append(element)