You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by lm...@apache.org on 2018/07/29 16:55:46 UTC

svn commit: r1836994 [2/2] - in /chemistry/cmislib/branches/py3_compat: ./ src/cmislib/ src/cmislib/atompub/ src/cmislib/browser/ src/tests/

Modified: chemistry/cmislib/branches/py3_compat/src/cmislib/exceptions.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/cmislib/exceptions.py?rev=1836994&r1=1836993&r2=1836994&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/cmislib/exceptions.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/cmislib/exceptions.py Sun Jul 29 16:55:46 2018
@@ -29,10 +29,12 @@ class CmisException(Exception):
     Common base class for all exceptions.
     """
 
-    def __init__(self, status=None, url=None):
-        Exception.__init__(self, "Error %s at %s" % (status, url))
+    def __init__(self, status=None, url=None, details=None):
+        Exception.__init__(
+            self, "Error %s at %s \n %s" % (status, url, details))
         self.status = status
         self.url = url
+        self.details = details
 
 
 class InvalidArgumentException(CmisException):

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=1836994&r1=1836993&r2=1836994&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:55:46 2018
@@ -23,6 +23,7 @@ keeping track of connection information.
 really appropriate, but it is kept for backwards compatibility.
 """
 import logging
+import requests
 
 from cmislib.atompub.binding import AtomPubBinding
 from cmislib.cmis_services import Binding
@@ -52,6 +53,9 @@ class CmisClient(object):
         self.username = username
         self.password = password
         self.extArgs = kwargs
+        self.session = requests.session()
+        self.session.auth =(self.username, self.password)
+        self.session.hooks = {'response': self._check_response_status }
         if 'binding' in kwargs and (isinstance(kwargs['binding'],Binding)):
             self.binding = kwargs['binding']
         else:
@@ -63,6 +67,18 @@ class CmisClient(object):
         """To string"""
         return 'CMIS client connection to %s' % self.repositoryUrl
 
+    def _check_response_status(self, response, *ags, **kwargs):
+        """
+        A callback function called by 'requests' after a call to the cmis
+        container
+        :param response: the response object
+        :param ags:
+        :param kwargs:
+        :return:
+        """
+        if not response.ok:
+            self.binding._processCommonErrors(response)
+
     def getRepositories(self):
 
         """

Modified: chemistry/cmislib/branches/py3_compat/src/cmislib/util.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/cmislib/util.py?rev=1836994&r1=1836993&r2=1836994&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/cmislib/util.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/cmislib/util.py Sun Jul 29 16:55:46 2018
@@ -30,20 +30,47 @@ from cmislib.domain import CmisId
 if sys.version_info >= (3,):
     from urllib.parse import urlencode, quote
 
+    text_type = str
+
+    def to_native(source, encoding='utf-8', falsy_empty=False):
+        if not source and falsy_empty:
+            return ''
+
+        if isinstance(source, bytes):
+            return source.decode(encoding)
+
+        return str(source)
+
     def itervalues(d):
         return iter(d.values())
 
     def iteritems(d):
         return iter(d.items())
+
+    def is_unicode(value):
+        return type(value) == str
 else:
     from urllib import urlencode, quote
 
+    text_type = unicode
+
+    def to_native(source, encoding='utf-8', falsy_empty=False):
+        if not source and falsy_empty:
+            return ''
+
+        if isinstance(source, text_type):
+            return source.encode(encoding)
+
+        return str(source)
+
     def itervalues(d):
         return d.itervalues()
 
     def iteritems(d):
         return d.iteritems()
 
+    def is_unicode(value):
+        return isinstance(value, unicode)
 
 moduleLogger = logging.getLogger('cmislib.util')
 
@@ -52,7 +79,7 @@ def to_utf8(value):
 
     """ Safe encodng of value to utf-8 taking care of unicode values
     """
-    if isinstance(value, unicode):
+    if is_unicode(value):
         value = value.encode('utf8')
     return value
 
@@ -179,7 +206,7 @@ def parseDateTimeValue(value):
     """
     Utility function to return a datetime from a string.
     """
-    if type(value) == str or type(value) == unicode:
+    if type(value) == str or is_unicode(value):
         return iso8601.parse_date(value)
     elif type(value) == int:
         return datetime.datetime.fromtimestamp(value / 1000)

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=1836994&r1=1836993&r2=1836994&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:55:46 2018
@@ -28,7 +28,7 @@ from cmislib.exceptions import \
     NotSupportedException
 from .tools import skipIfAlfrescoPubBinding
 from .tools import skipIfAlfrescoBrowserBinding
-
+from cmislib import util
 
 @pytest.mark.usefixtures('cmis_env', 'binary_files')
 class TestDocument:
@@ -470,7 +470,7 @@ class TestDocument:
         newDoc = self._testFolder.createDocumentFromString(documentName,
             contentString=contentString, contentType='text/plain')
         assert documentName == newDoc.getName()
-        assert newDoc.getContentStream().read() == contentString
+        assert util.to_native(newDoc.getContentStream().read()) == contentString
 
     def testCreateDocumentPlain(self):
         """Create a plain document using a file from the file system"""
@@ -480,7 +480,7 @@ class TestDocument:
             testFile.write('This is a sample text file line 2.\n')
             testFile.write('This is a sample text file line 3.\n')
 
-        with open(testFilename, 'r') as contentFile:
+        with open(testFilename, 'rb') as contentFile:
             newDoc = self._testFolder.createDocument(
                 testFilename, contentFile=contentFile)
         assert testFilename == newDoc.getName()
@@ -489,7 +489,7 @@ class TestDocument:
         # file we sent
         result = newDoc.getContentStream()
         exportFilename = testFilename.replace('txt', 'export.txt')
-        with closing(result), open(exportFilename, 'w') as outfile:
+        with closing(result), open(exportFilename, 'wb') as outfile:
             outfile.write(result.read())
         assert os.path.getsize(testFilename) == \
                           os.path.getsize(exportFilename)

Modified: chemistry/cmislib/branches/py3_compat/src/tests/test_query.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/tests/test_query.py?rev=1836994&r1=1836993&r2=1836994&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/tests/test_query.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/tests/test_query.py Sun Jul 29 16:55:46 2018
@@ -67,6 +67,15 @@ class TestQuery:
         resultSet = self._repo.query(querySimpleSelect)
         assert isInResultSet(resultSet, self._testContent2)
 
+    def testPropertyWithAccent(self):
+        """Find content matching cmis:name property"""
+        name = self._testContent2.getProperties()['cmis:name']
+        new_name = u'éà€ô' + name
+        self._testContent2.updateProperties({'cmis:name': name})
+        querySimpleSelect = "SELECT * FROM cmis:document where cmis:name = '" + name + "'"
+        resultSet = self._repo.query(querySimpleSelect)
+        assert isInResultSet(resultSet, self._testContent2)
+
     @skipIfAlfrescoBrowserBinding
     def testFullText(self):
         """Find content using a full-text query"""

Modified: chemistry/cmislib/branches/py3_compat/src/tests/test_repository.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/src/tests/test_repository.py?rev=1836994&r1=1836993&r2=1836994&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/src/tests/test_repository.py (original)
+++ chemistry/cmislib/branches/py3_compat/src/tests/test_repository.py Sun Jul 29 16:55:46 2018
@@ -21,6 +21,7 @@ import pytest
 
 from cmislib.exceptions import \
     ObjectNotFoundException
+from cmislib import util
 
 
 @pytest.mark.usefixtures('cmis_env', 'binary_files')
@@ -86,7 +87,8 @@ class TestRepository:
                                            contentString=contentString,
                                            contentType='text/plain')
         assert documentName == newDoc.getName()
-        assert newDoc.getContentStream().read() == contentString
+        assert util.to_native(
+            newDoc.getContentStream().read()) == contentString
 
     # CMIS-279
     def testCreateDocumentUnicode(self):

Modified: chemistry/cmislib/branches/py3_compat/tox.ini
URL: http://svn.apache.org/viewvc/chemistry/cmislib/branches/py3_compat/tox.ini?rev=1836994&r1=1836993&r2=1836994&view=diff
==============================================================================
--- chemistry/cmislib/branches/py3_compat/tox.ini (original)
+++ chemistry/cmislib/branches/py3_compat/tox.ini Sun Jul 29 16:55:46 2018
@@ -6,6 +6,9 @@
 [tox]
 envlist = 
   py27
+  py34
+  py35
+  py36
 
 [testenv]
 usedevelop = True