[Calypso] [PATCH 1/4] Use 'in' instead of 'has_key'

Guido Günther agx at sigxcpu.org
Sat Apr 8 11:59:17 PDT 2017


Makes the code shorter and pyflake happy
---
 calypso/webdav.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/calypso/webdav.py b/calypso/webdav.py
index cdeffe3..f472e1a 100644
--- a/calypso/webdav.py
+++ b/calypso/webdav.py
@@ -82,17 +82,16 @@ class Item(object):
             self.log.exception("Parse error in %s %s", name, path)
             raise
 
-
-        if not self.object.contents.has_key('x-calypso-name'):
+        if 'x-calypso-name' not in self.object.contents:
             if not name:
                 if self.object.name == 'VCARD' or self.object.name == 'VEVENT':
-                    if not self.object.contents.has_key('uid'):
+                    if 'uid' not in self.object.contents:
                         self.object.add('UID').value = hashlib.sha1(text).hexdigest()
                     name = self.object.uid.value
                 else:
                     for child in self.object.getChildren():
                         if child.name == 'VEVENT' or child.name == 'VCARD':
-                            if not child.contents.has_key('uid'):
+                            if 'uid' not in child.contents:
                                 child.add('UID').value = hashlib.sha1(text).hexdigest()
                             name = child.uid.value
                             break
@@ -575,7 +574,7 @@ class Collection(object):
                     for ve in events:
                         # Check for events with both dtstart and duration entries and
                         # delete the duration one
-                        if ve.contents.has_key('dtstart') and ve.contents.has_key('duration'):
+                        if 'dtstart' in ve.contents and 'duration' in ve.contents:
                             del ve.contents['duration']
                         new_ics.vevent_list = [ve]
                         new_item = Item(new_ics.serialize().decode('utf-8'), None, path, self.urlpath)
-- 
2.11.0



More information about the Calypso mailing list