chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmig...@apache.org
Subject svn commit: r1836989 - in /chemistry/cmislib/branches/py3_compat/src: cmislib/atompub/binding.py cmislib/browser/binding.py cmislib/model.py tests/test_acl.py tests/test_document.py tests/test_folder.py
Date Sun, 29 Jul 2018 16:52:37 GMT
Author: lmignon
Date: Sun Jul 29 16:52:37 2018
New Revision: 1836989

URL: http://svn.apache.org/viewvc?rev=1836989&view=rev
Log:
py3compat: replace 'has_key' with 'in' for dict

Modified:
    chemistry/cmislib/branches/py3_compat/src/cmislib/atompub/binding.py
    chemistry/cmislib/branches/py3_compat/src/cmislib/browser/binding.py
    chemistry/cmislib/branches/py3_compat/src/cmislib/model.py
    chemistry/cmislib/branches/py3_compat/src/tests/test_acl.py
    chemistry/cmislib/branches/py3_compat/src/tests/test_document.py
    chemistry/cmislib/branches/py3_compat/src/tests/test_folder.py

Modified: chemistry/cmislib/branches/py3_compat/src/cmislib/atompub/binding.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/cmislib/atompub/binding.py?rev=1836989&r1=1836988&r2=1836989&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/cmislib/atompub/binding.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/cmislib/atompub/binding.py Sun Jul 29 16:52:37
2018
@@ -391,7 +391,7 @@ class AtomPubCmisObject(CmisObject):
         # if a returnVersion arg was passed in, it is possible we got back
         # a different object ID than the value we started with, so it needs
         # to be cleared out as well
-        if options.has_key('returnVersion') or addOptions.has_key('returnVersion'):
+        if 'returnVersion' in options or 'returnVersion' in addOptions:
             self._objectId = None
 
     def _initData(self):
@@ -638,13 +638,13 @@ class AtomPubCmisObject(CmisObject):
 
         # if we have a change token, we must pass it back, per the spec
         args = {}
-        if self.properties.has_key('cmis:changeToken') and self.properties['cmis:changeToken']
is not None:
+        if self.properties.get('cmis:changeToken') is not None:
             self.logger.debug('Change token present, adding it to args')
             args = {"changeToken": self.properties['cmis:changeToken']}
 
         # the getEntryXmlDoc function may need the object type
         objectTypeId = None
-        if self.properties.has_key('cmis:objectTypeId') and not properties.has_key('cmis:objectTypeId'):
+        if 'cmis:objectTypeId' in self.properties and 'cmis:objectTypeId' not in properties:
             objectTypeId = self.properties['cmis:objectTypeId']
             self.logger.debug('This object type is:%s', objectTypeId)
 
@@ -1789,7 +1789,7 @@ class AtomPubRepository(object):
 
         # hardcoding to cmis:document if it wasn't
         # passed in via props
-        if not properties.has_key('cmis:objectTypeId'):
+        if 'cmis:objectTypeId' not in properties:
             properties['cmis:objectTypeId'] = CmisId('cmis:document')
         # and if it was passed in, making sure it is a CmisId
         elif not isinstance(properties['cmis:objectTypeId'], CmisId):
@@ -2396,7 +2396,7 @@ class AtomPubDocument(AtomPubCmisObject)
         """
 
         # major = true is supposed to be the default but inmemory 0.9 is throwing an error
500 without it
-        if not kwargs.has_key('major'):
+        if 'major' not in kwargs:
             kwargs['major'] = 'true'
 
         # Add checkin to kwargs and checkinComment, if it exists
@@ -2409,7 +2409,7 @@ class AtomPubDocument(AtomPubCmisObject)
         else:
             # the getEntryXmlDoc function may need the object type
             objectTypeId = None
-            if self.properties.has_key('cmis:objectTypeId') and not properties.has_key('cmis:objectTypeId'):
+            if 'cmis:objectTypeId' in self.properties and 'cmis:objectTypeId'not in properties:
                 objectTypeId = self.properties['cmis:objectTypeId']
                 self.logger.debug('This object type is:%s', objectTypeId)
 
@@ -2455,8 +2455,7 @@ class AtomPubDocument(AtomPubCmisObject)
         u'2.0'
         """
 
-        doc = None
-        if kwargs.has_key('major') and kwargs['major'] == 'true':
+        if kwargs.get('major') == 'true':
             doc = self._repository.getObject(self.getObjectId(), returnVersion='latestmajor')
         else:
             doc = self._repository.getObject(self.getObjectId(), returnVersion='latest')
@@ -2577,7 +2576,7 @@ class AtomPubDocument(AtomPubCmisObject)
 
         # if we have a change token, we must pass it back, per the spec
         args = {}
-        if self.properties.has_key('cmis:changeToken') and self.properties['cmis:changeToken']
is not None:
+        if self.properties.get('cmis:changeToken') is not None:
             self.logger.debug('Change token present, adding it to args')
             args = {"changeToken": self.properties['cmis:changeToken']}
 
@@ -2616,7 +2615,7 @@ class AtomPubDocument(AtomPubCmisObject)
 
         # if we have a change token, we must pass it back, per the spec
         args = {}
-        if self.properties.has_key('cmis:changeToken') and self.properties['cmis:changeToken']
is not None:
+        if self.properties.get('cmis:changeToken') is not None:
             self.logger.debug('Change token present, adding it to args')
             args = {"changeToken": self.properties['cmis:changeToken']}
 
@@ -2698,7 +2697,7 @@ class AtomPubFolder(AtomPubCmisObject):
         properties['cmis:name'] = name
 
         # hardcoding to cmis:folder if it wasn't passed in via props
-        if not properties.has_key('cmis:objectTypeId'):
+        if 'cmis:objectTypeId' not in properties:
             properties['cmis:objectTypeId'] = CmisId('cmis:folder')
         # and checking to make sure the object type ID is an instance of CmisId
         elif not isinstance(properties['cmis:objectTypeId'], CmisId):
@@ -3478,7 +3477,7 @@ class AtomPubACL(ACL):
         if not self._entries:
             self._entries = {ace.principalId: ace}
         else:
-            if self._entries.has_key(principalId):
+            if principalId in self._entries:
                 if access not in self._entries[principalId].permissions:
                     perms = self._entries[principalId].permissions
                     perms.append(access)
@@ -3504,7 +3503,7 @@ class AtomPubACL(ACL):
         {u'GROUP_EVERYONE': <cmislib.model.ACE object at 0x100731410>, u'jdoe': <cmislib.model.ACE
object at 0x100731150>, 'jpotts': <cmislib.model.ACE object at 0x1005a22d0>}
         """
 
-        if self._entries.has_key(principalId):
+        if principalId in self._entries:
             del self._entries[principalId]
             if len(self._entries) == 0:
                 self.clearEntries()
@@ -4021,7 +4020,7 @@ def getEntryXmlDoc(repo=None, objectType
 
     if properties:
         # a name is required for most things, but not for a checkout
-        if properties.has_key('cmis:name'):
+        if 'cmis:name' in properties:
             titleElement = entryXmlDoc.createElementNS(ATOM_NS, "title")
             titleText = entryXmlDoc.createTextNode(properties['cmis:name'])
             titleElement.appendChild(titleText)

Modified: chemistry/cmislib/branches/py3_compat/src/cmislib/browser/binding.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/cmislib/browser/binding.py?rev=1836989&r1=1836988&r2=1836989&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/cmislib/browser/binding.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/cmislib/browser/binding.py Sun Jul 29 16:52:37
2018
@@ -221,7 +221,7 @@ class BrowserCmisObject(object):
         # if a returnVersion arg was passed in, it is possible we got back
         # a different object ID than the value we started with, so it needs
         # to be cleared out as well
-        if self._extArgs.has_key('returnVersion'):
+        if 'returnVersion' in self._extArgs:
             self._objectId = None
 
     def getObjectId(self):
@@ -294,7 +294,7 @@ class BrowserCmisObject(object):
 
         if self._allowableActions == {}:
             self.reload(includeAllowableActions=True)
-            assert self.data.has_key('allowableActions'), "Expected object data to have an
allowableActions key"
+            assert 'allowableActions' in self.data, "Expected object data to have an allowableActions
key"
             allowableActions = self.data['allowableActions']
             self._allowableActions = allowableActions
 
@@ -732,9 +732,9 @@ class BrowserRepository(object):
                         'changesOnType': self.data['changesOnType'],
                         'principalIdAnonymous': self.data['principalIdAnonymous'],
                         'principalIdAnyone': self.data['principalIdAnyone']}
-            if self.data.has_key('thinClientURI'):
+            if 'thinClientURI' in self.data:
                 repoInfo['thinClientURI'] = self.data['thinClientURI']
-            if self.data.has_key('extendedFeatures'):
+            if 'extendedFeatures' in self.data:
                 repoInfo['extendedFeatures'] = self.data['extendedFeatures']
             self._repositoryInfo = repoInfo
         return self._repositoryInfo
@@ -795,8 +795,8 @@ class BrowserRepository(object):
         if not self._permissions:
             if self.data is None:
                 self.reload()
-            if self.data.has_key('aclCapabilities'):
-                if self.data['aclCapabilities'].has_key('supportedPermissions'):
+            if 'aclCapabilities' in self.data:
+                if 'supportedPermissions' in self.data['aclCapabilities']:
                     self._permissions = self.data['aclCapabilities']['supportedPermissions']
         return self._permissions
 
@@ -915,7 +915,7 @@ class BrowserRepository(object):
             if self.data is None:
                 self.reload()
             caps = {}
-            if self.data.has_key('capabilities'):
+            if 'capabilities' in self.data:
                 for cap in self.data['capabilities'].keys():
                     key = cap.replace('capability', '')
                     caps[key] = self.data['capabilities'][cap]
@@ -1364,7 +1364,7 @@ class BrowserRepository(object):
                  "propertyValue[0]": name}
 
         props["propertyId[1]"] = "cmis:objectTypeId"
-        if properties.has_key('cmis:objectTypeId'):
+        if 'cmis:objectTypeId' in properties:
             props["propertyValue[1]"] = properties['cmis:objectTypeId']
             del properties['cmis:objectTypeId']
         else:
@@ -1805,7 +1805,7 @@ class BrowserDocument(BrowserCmisObject)
         """
         # TODO implement optional arguments
         # major = true is supposed to be the default but inmemory 0.9 is throwing an error
500 without it
-        if not kwargs.has_key('major'):
+        if 'major' not in kwargs:
             kwargs['major'] = 'true'
         else:
             kwargs['major'] = 'false'
@@ -1861,7 +1861,7 @@ class BrowserDocument(BrowserCmisObject)
         """
 
         doc = None
-        if kwargs.has_key('major') and kwargs['major'] == 'true':
+        if kwargs.get('major') == 'true':
             doc = self._repository.getObject(self.getObjectId(), returnVersion='latestmajor')
         else:
             doc = self._repository.getObject(self.getObjectId(), returnVersion='latest')
@@ -1972,7 +1972,7 @@ class BrowserDocument(BrowserCmisObject)
         props = {"objectId": self.id,
                  "cmisaction": "deleteContent"}
 
-        if self.properties.has_key('cmis:changeToken'):
+        if 'cmis:changeToken' in self.properties:
             props["changeToken"] = self.properties['cmis:changeToken']
 
         # invoke the URL
@@ -2085,7 +2085,7 @@ class BrowserFolder(BrowserCmisObject):
                  "propertyValue[0]": name}
 
         props["propertyId[1]"] = "cmis:objectTypeId"
-        if properties.has_key('cmis:objectTypeId'):
+        if 'cmis:objectTypeId' in properties:
             props["propertyValue[1]"] = properties['cmis:objectTypeId']
             del properties['cmis:objectTypeId']
         else:
@@ -2287,7 +2287,7 @@ class BrowserFolder(BrowserCmisObject):
         """
         The optional filter argument is not yet supported.
         """
-        if self.properties.has_key('cmis:parentId') and self.properties['cmis:parentId']
is not None:
+        if self.properties.get('cmis:parentId') is not None:
             return BrowserFolder(self._cmisClient, self._repository, objectId=self.properties['cmis:parentId'])
 
     def deleteTree(self, **kwargs):
@@ -2596,7 +2596,7 @@ class BrowserObjectType(ObjectType):
         ...    print 'Open choice:%s' % prop.openChoice
         """
 
-        if self.data is None or not self.data.has_key('propertyDefinitions'):
+        if self.data is None or 'propertyDefinitions' not in self.data:
             self.reload()
         props = {}
         for prop in self.data['propertyDefinitions'].keys():
@@ -2816,7 +2816,7 @@ class BrowserACL(ACL):
         {u'GROUP_EVERYONE': <cmislib.model.ACE object at 0x100731410>, u'jdoe': <cmislib.model.ACE
object at 0x100731150>, 'jpotts': <cmislib.model.ACE object at 0x1005a22d0>}
         """
 
-        if self._entries.has_key(principalId):
+        if principalId in self._entries:
             del self._entries[principalId]
 
     def clearEntries(self):
@@ -3385,7 +3385,7 @@ class TreeSerializer(object):
             entries.append(cmisThing)
             try:
                 dataObj = obj['children']
-                # if obj['object'].has_key('children'):
+                # if 'children' in obj['object']:
                 #    for child in obj['object']['children']:
                 childEntries = self.getEntries(client, repo, dataObj)
                 entries = entries + childEntries

Modified: chemistry/cmislib/branches/py3_compat/src/cmislib/model.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/cmislib/model.py?rev=1836989&r1=1836988&r2=1836989&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/cmislib/model.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/cmislib/model.py Sun Jul 29 16:52:37 2018
@@ -52,7 +52,7 @@ class CmisClient(object):
         self.username = username
         self.password = password
         self.extArgs = kwargs
-        if kwargs.has_key('binding') and (isinstance(kwargs['binding'], Binding)):
+        if 'binding' in kwargs and (isinstance(kwargs['binding'],Binding)):
             self.binding = kwargs['binding']
         else:
             self.binding = AtomPubBinding(**kwargs)

Modified: chemistry/cmislib/branches/py3_compat/src/tests/test_acl.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/tests/test_acl.py?rev=1836989&r1=1836988&r2=1836989&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/tests/test_acl.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/tests/test_acl.py Sun Jul 29 16:52:37 2018
@@ -42,7 +42,7 @@ class TestACL:
             print messages.NO_ACL_SUPPORT
             return
         supportedPerms = self._repo.getPermissionDefinitions()
-        assert supportedPerms.has_key('cmis:write')
+        assert 'cmis:write' in supportedPerms
 
     def testPermissionMap(self):
         """Test the permission mapping"""
@@ -50,7 +50,7 @@ class TestACL:
             print messages.NO_ACL_SUPPORT
             return
         permMap = self._repo.getPermissionMap()
-        assert permMap.has_key('canGetProperties.Object')
+        assert 'canGetProperties.Object' in permMap
         assert len(permMap['canGetProperties.Object']) > 0
 
     def testPropagation(self):
@@ -88,4 +88,4 @@ class TestACL:
         # would be good to check that the permission we get back is what we set
         # but at least one server (Alf) appears to map the basic perm to a
         # repository-specific perm
-        assert acl.getEntries().has_key(self.acl_principal_id)
+        assert self.acl_principal_id in acl.getEntries()

Modified: chemistry/cmislib/branches/py3_compat/src/tests/test_document.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/tests/test_document.py?rev=1836989&r1=1836988&r2=1836989&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/tests/test_document.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/tests/test_document.py Sun Jul 29 16:52:37 2018
@@ -318,8 +318,7 @@ class TestDocument:
         assert testFile1Size == os.path.getsize(exportFile1)
 
         # checkout the file
-        if newDoc.allowableActions.has_key('canCheckOut') and \
-                newDoc.allowableActions['canCheckOut'] == True:
+        if newDoc.allowableActions.get('canCheckOut') == True:
             pass
         else:
             pytest.skip('The test doc cannot be checked out...skipping')
@@ -584,14 +583,13 @@ class TestDocument:
 
     def testRenditions(self):
         """Get the renditions for a document"""
-        if not self._repo.getCapabilities().has_key('Renditions'):
+        if 'Renditions' not in self._repo.getCapabilities():
             pytest.skip('Repo does not support unfiling, skipping')
 
         testDoc = self._testFolder.createDocumentFromString(
             'testdoc.txt', contentString='test', contentType='text/plain')
         sleep(10)
-        if (testDoc.getAllowableActions().has_key('canGetRenditions') and
-            testDoc.getAllowableActions()['canGetRenditions'] == True):
+        if testDoc.getAllowableActions().get('canGetRenditions') == True:
             rends = testDoc.getRenditions()
             assert len(rends) >= 1
         else:

Modified: chemistry/cmislib/branches/py3_compat/src/tests/test_folder.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/tests/test_folder.py?rev=1836989&r1=1836988&r2=1836989&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/tests/test_folder.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/tests/test_folder.py Sun Jul 29 16:52:37 2018
@@ -162,42 +162,42 @@ class TestFolder:
         searchFolder = self._repo.getObjectByPath(subFolderPath,
                         filter='cmis:objectId,cmis:objectTypeId,cmis:baseTypeId')
         assert subFolder.getObjectId() == searchFolder.getObjectId()
-        assert searchFolder.getProperties().has_key('cmis:objectId')
-        assert searchFolder.getProperties().has_key('cmis:objectTypeId')
-        assert searchFolder.getProperties().has_key('cmis:baseTypeId')
+        assert 'cmis:objectId' in searchFolder.getProperties()
+        assert 'cmis:objectTypeId' in searchFolder.getProperties()
+        assert 'cmis:baseTypeId' in searchFolder.getProperties()
 
         # test when used with getObjectByPath + reload
         searchFolder = self._repo.getObjectByPath(subFolderPath,
                         filter='cmis:objectId,cmis:objectTypeId,cmis:baseTypeId')
         searchFolder.reload()
         assert subFolder.getObjectId() == searchFolder.getObjectId()
-        assert searchFolder.getProperties().has_key('cmis:objectId')
-        assert searchFolder.getProperties().has_key('cmis:objectTypeId')
-        assert searchFolder.getProperties().has_key('cmis:baseTypeId')
+        assert 'cmis:objectId' in searchFolder.getProperties()
+        assert 'cmis:objectTypeId' in searchFolder.getProperties()
+        assert 'cmis:baseTypeId' in searchFolder.getProperties()
 
         # test when used with getObject
         searchFolder = self._repo.getObject(subFolder.getObjectId(),
                         filter='cmis:objectId,cmis:objectTypeId,cmis:baseTypeId')
         assert subFolder.getObjectId() == searchFolder.getObjectId()
-        assert searchFolder.getProperties().has_key('cmis:objectId')
-        assert searchFolder.getProperties().has_key('cmis:objectTypeId')
-        assert searchFolder.getProperties().has_key('cmis:baseTypeId')
+        assert 'cmis:objectId' in searchFolder.getProperties()
+        assert 'cmis:objectTypeId' in searchFolder.getProperties()
+        assert 'cmis:baseTypeId' in searchFolder.getProperties()
 
         # test when used with getObject + reload
         searchFolder = self._repo.getObject(subFolder.getObjectId(),
                         filter='cmis:objectId,cmis:objectTypeId,cmis:baseTypeId')
         searchFolder.reload()
         assert subFolder.getObjectId() == searchFolder.getObjectId()
-        assert searchFolder.getProperties().has_key('cmis:objectId')
-        assert searchFolder.getProperties().has_key('cmis:objectTypeId')
-        assert searchFolder.getProperties().has_key('cmis:baseTypeId')
+        assert 'cmis:objectId' in searchFolder.getProperties()
+        assert 'cmis:objectTypeId' in searchFolder.getProperties()
+        assert 'cmis:baseTypeId' in searchFolder.getProperties()
 
         # test that you can do a reload with a reset filter
         searchFolder.reload(filter='*')
-        assert searchFolder.getProperties().has_key('cmis:objectId')
-        assert searchFolder.getProperties().has_key('cmis:objectTypeId')
-        assert searchFolder.getProperties().has_key('cmis:baseTypeId')
-        assert searchFolder.getProperties().has_key('cmis:name')
+        assert 'cmis:objectId' in searchFolder.getProperties()
+        assert 'cmis:objectTypeId' in searchFolder.getProperties()
+        assert 'cmis:baseTypeId' in searchFolder.getProperties()
+        assert 'cmis:name' in searchFolder.getProperties()
 
     def testUpdateProperties(self):
         """Create a test folder, then update its properties"""



Mime
View raw message