[
https://issues.apache.org/jira/browse/CMIS-996?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Laurent Mignon updated CMIS-996:
--------------------------------
Description:
The function getObjectByPath use urllib.quote to quote the path into the url.
urllib.quote doesn't support unicode values.
see https://github.com/apache/chemistry-cmislib/pull/4
{code}
diff --git a/src/cmislib/browser/binding.py b/src/cmislib/browser/binding.py
index 7d7d758..fa20281 100644
--- a/src/cmislib/browser/binding.py
+++ b/src/cmislib/browser/binding.py
@@ -715,7 +715,7 @@ class BrowserRepository(object):
- includeAllowableActions
"""
- byPathUrl = self.getRootFolderUrl() + quote(path) +
"?cmisselector=object"
+ byPathUrl = self.getRootFolderUrl() + safe_quote(path) +
"?cmisselector=object"
result = self._cmisClient.binding.get(byPathUrl.encode('utf-8'),
self._cmisClient.username,
self._cmisClient.password,
@@ -926,7 +926,7 @@ class BrowserRepository(object):
typesUrl = self.getRepositoryUrl() + "?cmisselector=typeChildren"
if typeId is not None:
- typesUrl += "&typeId=%s" % (quote(typeId))
+ typesUrl += "&typeId=%s" % (safe_quote(typeId))
result = self._cmisClient.binding.get(typesUrl,
self._cmisClient.username,
@@ -986,7 +986,7 @@ class BrowserRepository(object):
typesUrl = self.getRepositoryUrl() + "?cmisselector=typeDescendants"
if typeId is not None:
- typesUrl += "&typeId=%s" % (quote(typeId))
+ typesUrl += "&typeId=%s" % (safe_quote(typeId))
if depth is not None:
typesUrl += "&depth=%s" % (depth)
print typesUrl
@@ -1180,7 +1180,7 @@ class BrowserRepository(object):
"""
# build the CMIS query XML that we're going to POST
- queryUrl = self.getRepositoryUrl() + "?cmisaction=query&q=" +
quote(statement)
+ queryUrl = self.getRepositoryUrl() + "?cmisaction=query&q=" +
safe_quote(statement)
# do the POST
result = self._cmisClient.binding.post(queryUrl.encode('utf-8'),
@@ -3182,6 +3182,21 @@ def safe_urlencode(in_dict):
return urlencode(encoded_dict(in_dict))
+def safe_quote(value):
+
+ """
+ Safe encoding of value taking care of unicode value
+ urllib.quote doesn't like unicode values
+ """
+
+ if isinstance(value, unicode):
+ value = value.encode('utf8')
+ elif isinstance(value, str):
+ # Must be encoded in UTF-8
+ value.decode('utf8')
+ return quote(value)
+
+
class ResultsSerializer(object):
"""
diff --git a/src/tests/cmislibtest.py b/src/tests/cmislibtest.py
index a81be56..2ec128d 100644
--- a/src/tests/cmislibtest.py
+++ b/src/tests/cmislibtest.py
@@ -374,6 +374,38 @@ class RepositoryTest(CmisTestBase):
subFolder = self._repo.getObjectByPath(subFolderPath)
self.assertEquals(len(subFolder.getChildren().getResults()), 1)
+ def testGetObjectByPathUnicode(self):
+ """Create test objects (one folder, one document) then try to get
+ them by path"""
+ # names of folders and test docs
+ parentFolderName = 'testGetObjectByPath folder'
+ subFolderName = u'subfolder_éà'
+ docName = u'testdoc_éà'
+
+ # create the folder structure
+ parentFolder = self._testFolder.createFolder(parentFolderName)
+ subFolder = parentFolder.createFolder(subFolderName)
+ # use the subfolder path to get the folder by path
+ subFolderPath = subFolder.getProperties().get("cmis:path")
+ searchFolder = self._repo.getObjectByPath(subFolderPath)
+ self.assertEquals(subFolder.getObjectId(), searchFolder.getObjectId())
+
+ # create a test doc
+ doc = subFolder.createDocument(docName)
+ # ask the doc for its paths
+ searchDocPaths = doc.getPaths()
+ # for each path in the list, try to get the object by path
+ # this is better than building a path with the doc's name b/c the name
+ # isn't guaranteed to be used as the path segment (see CMIS-232)
+ for path in searchDocPaths:
+ searchDoc = self._repo.getObjectByPath(path)
+ self.assertEquals(doc.getObjectId(), searchDoc.getObjectId())
+
+ # get the subfolder by path, then ask for its children
+ subFolder = self._repo.getObjectByPath(subFolderPath)
+ self.assertEquals(len(subFolder.getChildren().getResults()), 1)
+
+
# getting unfiled documents may work for the atom pub binding for some
servers
# but it isn't part of the spec so removing this test for now
'''
{code}
was:The function getObjectByPath use urllib.quote to quote the path into the
url. urllib.quote doesn't support unicode values. A patch will follow.
> BrowserBinding getObjecyByPath: unicode is not supported by urllib.quote
> ------------------------------------------------------------------------
>
> Key: CMIS-996
> URL: https://issues.apache.org/jira/browse/CMIS-996
> Project: Chemistry
> Issue Type: Bug
> Components: python-cmislib
> Reporter: Laurent Mignon
> Assignee: Jeff Potts
>
> The function getObjectByPath use urllib.quote to quote the path into the url.
> urllib.quote doesn't support unicode values.
> see https://github.com/apache/chemistry-cmislib/pull/4
> {code}
> diff --git a/src/cmislib/browser/binding.py b/src/cmislib/browser/binding.py
> index 7d7d758..fa20281 100644
> --- a/src/cmislib/browser/binding.py
> +++ b/src/cmislib/browser/binding.py
> @@ -715,7 +715,7 @@ class BrowserRepository(object):
> - includeAllowableActions
> """
>
> - byPathUrl = self.getRootFolderUrl() + quote(path) +
> "?cmisselector=object"
> + byPathUrl = self.getRootFolderUrl() + safe_quote(path) +
> "?cmisselector=object"
> result = self._cmisClient.binding.get(byPathUrl.encode('utf-8'),
> self._cmisClient.username,
> self._cmisClient.password,
> @@ -926,7 +926,7 @@ class BrowserRepository(object):
> typesUrl = self.getRepositoryUrl() + "?cmisselector=typeChildren"
>
> if typeId is not None:
> - typesUrl += "&typeId=%s" % (quote(typeId))
> + typesUrl += "&typeId=%s" % (safe_quote(typeId))
>
> result = self._cmisClient.binding.get(typesUrl,
> self._cmisClient.username,
> @@ -986,7 +986,7 @@ class BrowserRepository(object):
> typesUrl = self.getRepositoryUrl() + "?cmisselector=typeDescendants"
>
> if typeId is not None:
> - typesUrl += "&typeId=%s" % (quote(typeId))
> + typesUrl += "&typeId=%s" % (safe_quote(typeId))
> if depth is not None:
> typesUrl += "&depth=%s" % (depth)
> print typesUrl
> @@ -1180,7 +1180,7 @@ class BrowserRepository(object):
> """
>
> # build the CMIS query XML that we're going to POST
> - queryUrl = self.getRepositoryUrl() + "?cmisaction=query&q=" +
> quote(statement)
> + queryUrl = self.getRepositoryUrl() + "?cmisaction=query&q=" +
> safe_quote(statement)
>
> # do the POST
> result = self._cmisClient.binding.post(queryUrl.encode('utf-8'),
> @@ -3182,6 +3182,21 @@ def safe_urlencode(in_dict):
> return urlencode(encoded_dict(in_dict))
>
>
> +def safe_quote(value):
> +
> + """
> + Safe encoding of value taking care of unicode value
> + urllib.quote doesn't like unicode values
> + """
> +
> + if isinstance(value, unicode):
> + value = value.encode('utf8')
> + elif isinstance(value, str):
> + # Must be encoded in UTF-8
> + value.decode('utf8')
> + return quote(value)
> +
> +
> class ResultsSerializer(object):
>
> """
> diff --git a/src/tests/cmislibtest.py b/src/tests/cmislibtest.py
> index a81be56..2ec128d 100644
> --- a/src/tests/cmislibtest.py
> +++ b/src/tests/cmislibtest.py
> @@ -374,6 +374,38 @@ class RepositoryTest(CmisTestBase):
> subFolder = self._repo.getObjectByPath(subFolderPath)
> self.assertEquals(len(subFolder.getChildren().getResults()), 1)
>
> + def testGetObjectByPathUnicode(self):
> + """Create test objects (one folder, one document) then try to get
> + them by path"""
> + # names of folders and test docs
> + parentFolderName = 'testGetObjectByPath folder'
> + subFolderName = u'subfolder_éà'
> + docName = u'testdoc_éà'
> +
> + # create the folder structure
> + parentFolder = self._testFolder.createFolder(parentFolderName)
> + subFolder = parentFolder.createFolder(subFolderName)
> + # use the subfolder path to get the folder by path
> + subFolderPath = subFolder.getProperties().get("cmis:path")
> + searchFolder = self._repo.getObjectByPath(subFolderPath)
> + self.assertEquals(subFolder.getObjectId(),
> searchFolder.getObjectId())
> +
> + # create a test doc
> + doc = subFolder.createDocument(docName)
> + # ask the doc for its paths
> + searchDocPaths = doc.getPaths()
> + # for each path in the list, try to get the object by path
> + # this is better than building a path with the doc's name b/c the
> name
> + # isn't guaranteed to be used as the path segment (see CMIS-232)
> + for path in searchDocPaths:
> + searchDoc = self._repo.getObjectByPath(path)
> + self.assertEquals(doc.getObjectId(), searchDoc.getObjectId())
> +
> + # get the subfolder by path, then ask for its children
> + subFolder = self._repo.getObjectByPath(subFolderPath)
> + self.assertEquals(len(subFolder.getChildren().getResults()), 1)
> +
> +
> # getting unfiled documents may work for the atom pub binding for some
> servers
> # but it isn't part of the spec so removing this test for now
> '''
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)