chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpo...@apache.org
Subject svn commit: r1444466 [5/5] - in /chemistry/cmislib/branches/binding_refactor/src: cmislib/ tests/
Date Sun, 10 Feb 2013 00:16:53 GMT
Added: chemistry/cmislib/branches/binding_refactor/src/cmislib/util.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/binding_refactor/src/cmislib/util.py?rev=1444466&view=auto
==============================================================================
--- chemistry/cmislib/branches/binding_refactor/src/cmislib/util.py (added)
+++ chemistry/cmislib/branches/binding_refactor/src/cmislib/util.py Sun Feb 10 00:16:52 2013
@@ -0,0 +1,111 @@
+#
+#      Licensed to the Apache Software Foundation (ASF) under one
+#      or more contributor license agreements.  See the NOTICE file
+#      distributed with this work for additional information
+#      regarding copyright ownership.  The ASF licenses this file
+#      to you under the Apache License, Version 2.0 (the
+#      "License"); you may not use this file except in compliance
+#      with the License.  You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#      Unless required by applicable law or agreed to in writing,
+#      software distributed under the License is distributed on an
+#      "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#      KIND, either express or implied.  See the License for the
+#      specific language governing permissions and limitations
+#      under the License.
+#
+"""
+Module containing handy utility functions.
+"""
+import re
+import iso8601
+import logging
+from cmislib.domain import CmisId, Document, Folder
+
+moduleLogger = logging.getLogger('cmislib.util')
+
+def multiple_replace(aDict, text):
+
+    """
+    Replace in 'text' all occurences of any key in the given
+    dictionary by its corresponding value.  Returns the new string.
+
+    See http://code.activestate.com/recipes/81330/
+    """
+
+    # Create a regular expression  from the dictionary keys
+    regex = re.compile("(%s)" % "|".join(map(re.escape, aDict.keys())))
+
+    # For each match, look-up corresponding value in dictionary
+    return regex.sub(lambda mo: aDict[mo.string[mo.start():mo.end()]], text)
+
+def parsePropValue(value, nodeName):
+
+    """
+    Returns a properly-typed object based on the type as specified in the
+    node's element name.
+    """
+
+    moduleLogger.debug('Inside parsePropValue')
+
+    if nodeName == 'propertyId':
+        return CmisId(value)
+    elif nodeName == 'propertyString':
+        return value
+    elif nodeName == 'propertyBoolean':
+        bDict = {'false': False, 'true': True}
+        return bDict[value.lower()]
+    elif nodeName == 'propertyInteger':
+        return int(value)
+    elif nodeName == 'propertyDecimal':
+        return float(value)
+    elif nodeName == 'propertyDateTime':
+        #%z doesn't seem to work, so I'm going to trunc the offset
+        #not all servers return microseconds, so those go too
+        return parseDateTimeValue(value)
+    else:
+        return value
+
+
+def parseDateTimeValue(value):
+
+    """
+    Utility function to return a datetime from a string.
+    """
+    return iso8601.parse_date(value)
+
+
+def parseBoolValue(value):
+
+    """
+    Utility function to parse booleans and none from strings
+    """
+
+    if value == 'false':
+        return False
+    elif value == 'true':
+        return True
+    elif value == 'none':
+        return None
+    else:
+        return value
+
+
+def toCMISValue(value):
+
+    """
+    Utility function to convert Python values to CMIS string values
+    """
+
+    if value == False:
+        return 'false'
+    elif value == True:
+        return 'true'
+    elif value == None:
+        return 'none'
+    else:
+        return value
+
+

Modified: chemistry/cmislib/branches/binding_refactor/src/tests/cmislibtest.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/binding_refactor/src/tests/cmislibtest.py?rev=1444466&r1=1444465&r2=1444466&view=diff
==============================================================================
--- chemistry/cmislib/branches/binding_refactor/src/tests/cmislibtest.py (original)
+++ chemistry/cmislib/branches/binding_refactor/src/tests/cmislibtest.py Sun Feb 10 00:16:52
2013
@@ -23,7 +23,8 @@ Unit tests for cmislib
 '''
 import unittest
 from unittest import TestSuite, TestLoader
-from cmislib.model import CmisClient, ACE
+from cmislib.model import CmisClient
+from cmislib.domain import ACE
 from cmislib.exceptions import \
                           ObjectNotFoundException, \
                           CmisException, \
@@ -1397,8 +1398,8 @@ class ACLTest(CmisTestBase):
         if not self._repo.getSupportedPermissions() in ['both', 'basic']:
             print 'Repository needs to support either both or basic permissions for this
test'
             return
-        acl = self._testFolder.getACL()
-        acl.addEntry(ACE(settings.TEST_PRINCIPAL_ID, 'cmis:write', 'true'))
+        acl = self._testFolder.getACL()        
+        acl.addEntry(settings.TEST_PRINCIPAL_ID, 'cmis:write', 'true')
         acl = self._testFolder.applyACL(acl)
         # 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

Modified: chemistry/cmislib/branches/binding_refactor/src/tests/settings.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/binding_refactor/src/tests/settings.py?rev=1444466&r1=1444465&r2=1444466&view=diff
==============================================================================
--- chemistry/cmislib/branches/binding_refactor/src/tests/settings.py (original)
+++ chemistry/cmislib/branches/binding_refactor/src/tests/settings.py Sun Feb 10 00:16:52
2013
@@ -22,8 +22,8 @@
 #
 # CMIS repository's service URL
 #REPOSITORY_URL = 'http://cmis.alfresco.com/s/cmis' # Alfresco demo
-#REPOSITORY_URL = 'http://localhost:8080/chemistry/atom' # Apache Chemistry
-REPOSITORY_URL = 'http://localhost:8080/alfresco/cmisatom'  # Alfresco 4.0
+REPOSITORY_URL = 'http://localhost:8080/chemistry/atom' # Apache Chemistry
+#REPOSITORY_URL = 'http://localhost:8080/alfresco/cmisatom'  # Alfresco 4.0
 #REPOSITORY_URL = 'http://localhost:8080/alfresco/s/api/cmis'  # Alfresco
 #REPOSITORY_URL = 'http://cmis.demo.nuxeo.org/nuxeo/atom/cmis' # Nuxeo demo
 #REPOSITORY_URL = 'http://localhost:8080/nuxeo/atom/cmis' # Nuxeo local



Mime
View raw message