[ 
https://issues.apache.org/jira/browse/CMIS-995?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Laurent Mignon updated CMIS-995:
--------------------------------
    Description: 
{code}
diff --git a/src/cmislib/browser/binding.py b/src/cmislib/browser/binding.py
index 800223c..0371cba 100644
--- a/src/cmislib/browser/binding.py
+++ b/src/cmislib/browser/binding.py
@@ -364,7 +364,7 @@ class BrowserCmisObject(object):
 
         # invoke the URL
         result = self._cmisClient.binding.post(updateUrl.encode('utf-8'),
-                                               urlencode(props),
+                                               safe_urlencode(props),
                                                
'application/x-www-form-urlencoded',
                                                self._cmisClient.username,
                                                self._cmisClient.password)
@@ -393,7 +393,7 @@ class BrowserCmisObject(object):
 
         # invoke the URL
         self._cmisClient.binding.post(moveUrl.encode('utf-8'),
-                                      urlencode(props),
+                                      safe_urlencode(props),
                                       'application/x-www-form-urlencoded',
                                       self._cmisClient.username,
                                       self._cmisClient.password)
@@ -421,7 +421,7 @@ class BrowserCmisObject(object):
 
         # invoke the URL
         self._cmisClient.binding.post(delUrl.encode('utf-8'),
-                                      urlencode(props),
+                                      safe_urlencode(props),
                                       'application/x-www-form-urlencoded',
                                       self._cmisClient.username,
                                       self._cmisClient.password,
@@ -1655,7 +1655,7 @@ class BrowserDocument(BrowserCmisObject):
 
         # invoke the URL
         result = self._cmisClient.binding.post(coUrl.encode('utf-8'),
-                                               urlencode(props),
+                                               safe_urlencode(props),
                                                
'application/x-www-form-urlencoded',
                                                self._cmisClient.username,
                                                self._cmisClient.password)
@@ -1682,7 +1682,7 @@ class BrowserDocument(BrowserCmisObject):
 
         # invoke the URL
         self._cmisClient.binding.post(coUrl.encode('utf-8'),
-                                      urlencode(props),
+                                      safe_urlencode(props),
                                       'application/x-www-form-urlencoded',
                                       self._cmisClient.username,
                                       self._cmisClient.password)
@@ -1933,7 +1933,7 @@ class BrowserDocument(BrowserCmisObject):
 
         # invoke the URL
         self._cmisClient.binding.post(delUrl.encode('utf-8'),
-                                      urlencode(props),
+                                      safe_urlencode(props),
                                       'application/x-www-form-urlencoded',
                                       self._cmisClient.username,
                                       self._cmisClient.password)
@@ -2051,7 +2051,7 @@ class BrowserFolder(BrowserCmisObject):
 
         # invoke the URL
         result = self._cmisClient.binding.post(createFolderUrl.encode('utf-8'),
-                                               urlencode(props),
+                                               safe_urlencode(props),
                                                
'application/x-www-form-urlencoded',
                                                self._cmisClient.username,
                                                self._cmisClient.password,
@@ -2269,7 +2269,7 @@ class BrowserFolder(BrowserCmisObject):
 
         # invoke the URL
         self._cmisClient.binding.post(delUrl.encode('utf-8'),
-                                      urlencode(props),
+                                      safe_urlencode(props),
                                       'application/x-www-form-urlencoded',
                                       self._cmisClient.username,
                                       self._cmisClient.password,
@@ -2309,7 +2309,7 @@ class BrowserFolder(BrowserCmisObject):
 
         # invoke the URL
         result = self._cmisClient.binding.post(addUrl.encode('utf-8'),
-                                               urlencode(props),
+                                               safe_urlencode(props),
                                                
'application/x-www-form-urlencoded',
                                                self._cmisClient.username,
                                                self._cmisClient.password,
@@ -2332,7 +2332,7 @@ class BrowserFolder(BrowserCmisObject):
 
         # invoke the URL
         result = self._cmisClient.binding.post(remUrl.encode('utf-8'),
-                                               urlencode(props),
+                                               safe_urlencode(props),
                                                
'application/x-www-form-urlencoded',
                                                self._cmisClient.username,
                                                self._cmisClient.password)
@@ -3101,6 +3101,23 @@ def encode_multipart_formdata(fields, contentFile, 
contentType):
     return content_type, body
 
 
+def safe_urlencode(in_dict):
+    """ Safe encoding of values taking care of unicode values
+    urllib.urlencode doesn't like unicode values
+    """
+    def encoded_dict(in_dict):
+        out_dict = {}
+        for k, v in in_dict.iteritems():
+            if isinstance(v, unicode):
+                v = v.encode('utf8')
+            elif isinstance(v, str):
+                # Must be encoded in UTF-8
+                v.decode('utf8')
+            out_dict[k] = v
+        return out_dict
+    return urlencode(encoded_dict(in_dict))
+
+
 class ResultsSerializer(object):
 

{code}

https://github.com/lmignon/python-cmislib/commit/159f0202d7dd012230b31a42ef13ef0d03b46f96?diff=unified

  was:
{code}
diff --git a/src/cmislib/net.py b/src/cmislib/net.py
index 59b3038..9a3db18 100644
--- a/src/cmislib/net.py
+++ b/src/cmislib/net.py
@@ -51,7 +51,7 @@ class RESTService(object):
             if 'headers' in kwargs:
                 headers = kwargs['headers']
                 del kwargs['headers']
-                self.logger.debug('Headers passed in:' + headers)
+                self.logger.debug('Headers passed in: %s', headers)
             if url.find('?') >= 0:
                 url = url + '&' + urlencode(kwargs)
             else:
@@ -74,7 +74,7 @@ class RESTService(object):
             if 'headers' in kwargs:
                 headers = kwargs['headers']
                 del kwargs['headers']
-                self.logger.debug('Headers passed in:' + headers)
+                self.logger.debug('Headers passed in %s', headers)
             if url.find('?') >= 0:
                 url = url + '&' + urlencode(kwargs)
             else:
@@ -107,7 +107,7 @@ class RESTService(object):
             if 'headers' in kwargs:
                 headers = kwargs['headers']
                 del kwargs['headers']
-                self.logger.debug('Headers passed in:' + headers)
+                self.logger.debug('Headers passed in: %s',  headers)
             if url.find('?') >= 0:
                 url = url + '&' + urlencode(kwargs)
             else:
@@ -141,7 +141,7 @@ class RESTService(object):
             if 'headers' in kwargs:
                 headers = kwargs['headers']
                 del kwargs['headers']
-                self.logger.debug('Headers passed in:' + headers)
+                self.logger.debug('Headers passed in: %s' % headers)
             if url.find('?') >= 0:
                 url = url + '&' + urlencode(kwargs)
             else:

{code}

https://github.com/lmignon/python-cmislib/commit/159f0202d7dd012230b31a42ef13ef0d03b46f96?diff=unified


> UnicodeEncodeError when calling urlencode method with a dict that contains 
> accented characters
> ----------------------------------------------------------------------------------------------
>
>                 Key: CMIS-995
>                 URL: https://issues.apache.org/jira/browse/CMIS-995
>             Project: Chemistry
>          Issue Type: Bug
>          Components: python-cmislib
>         Environment: Linux, python 2.7x, Alfresco 5.0.x, cmislib dev
>            Reporter: Laurent Mignon
>            Assignee: Jeff Potts
>
> {code}
> diff --git a/src/cmislib/browser/binding.py b/src/cmislib/browser/binding.py
> index 800223c..0371cba 100644
> --- a/src/cmislib/browser/binding.py
> +++ b/src/cmislib/browser/binding.py
> @@ -364,7 +364,7 @@ class BrowserCmisObject(object):
>  
>          # invoke the URL
>          result = self._cmisClient.binding.post(updateUrl.encode('utf-8'),
> -                                               urlencode(props),
> +                                               safe_urlencode(props),
>                                                 
> 'application/x-www-form-urlencoded',
>                                                 self._cmisClient.username,
>                                                 self._cmisClient.password)
> @@ -393,7 +393,7 @@ class BrowserCmisObject(object):
>  
>          # invoke the URL
>          self._cmisClient.binding.post(moveUrl.encode('utf-8'),
> -                                      urlencode(props),
> +                                      safe_urlencode(props),
>                                        'application/x-www-form-urlencoded',
>                                        self._cmisClient.username,
>                                        self._cmisClient.password)
> @@ -421,7 +421,7 @@ class BrowserCmisObject(object):
>  
>          # invoke the URL
>          self._cmisClient.binding.post(delUrl.encode('utf-8'),
> -                                      urlencode(props),
> +                                      safe_urlencode(props),
>                                        'application/x-www-form-urlencoded',
>                                        self._cmisClient.username,
>                                        self._cmisClient.password,
> @@ -1655,7 +1655,7 @@ class BrowserDocument(BrowserCmisObject):
>  
>          # invoke the URL
>          result = self._cmisClient.binding.post(coUrl.encode('utf-8'),
> -                                               urlencode(props),
> +                                               safe_urlencode(props),
>                                                 
> 'application/x-www-form-urlencoded',
>                                                 self._cmisClient.username,
>                                                 self._cmisClient.password)
> @@ -1682,7 +1682,7 @@ class BrowserDocument(BrowserCmisObject):
>  
>          # invoke the URL
>          self._cmisClient.binding.post(coUrl.encode('utf-8'),
> -                                      urlencode(props),
> +                                      safe_urlencode(props),
>                                        'application/x-www-form-urlencoded',
>                                        self._cmisClient.username,
>                                        self._cmisClient.password)
> @@ -1933,7 +1933,7 @@ class BrowserDocument(BrowserCmisObject):
>  
>          # invoke the URL
>          self._cmisClient.binding.post(delUrl.encode('utf-8'),
> -                                      urlencode(props),
> +                                      safe_urlencode(props),
>                                        'application/x-www-form-urlencoded',
>                                        self._cmisClient.username,
>                                        self._cmisClient.password)
> @@ -2051,7 +2051,7 @@ class BrowserFolder(BrowserCmisObject):
>  
>          # invoke the URL
>          result = 
> self._cmisClient.binding.post(createFolderUrl.encode('utf-8'),
> -                                               urlencode(props),
> +                                               safe_urlencode(props),
>                                                 
> 'application/x-www-form-urlencoded',
>                                                 self._cmisClient.username,
>                                                 self._cmisClient.password,
> @@ -2269,7 +2269,7 @@ class BrowserFolder(BrowserCmisObject):
>  
>          # invoke the URL
>          self._cmisClient.binding.post(delUrl.encode('utf-8'),
> -                                      urlencode(props),
> +                                      safe_urlencode(props),
>                                        'application/x-www-form-urlencoded',
>                                        self._cmisClient.username,
>                                        self._cmisClient.password,
> @@ -2309,7 +2309,7 @@ class BrowserFolder(BrowserCmisObject):
>  
>          # invoke the URL
>          result = self._cmisClient.binding.post(addUrl.encode('utf-8'),
> -                                               urlencode(props),
> +                                               safe_urlencode(props),
>                                                 
> 'application/x-www-form-urlencoded',
>                                                 self._cmisClient.username,
>                                                 self._cmisClient.password,
> @@ -2332,7 +2332,7 @@ class BrowserFolder(BrowserCmisObject):
>  
>          # invoke the URL
>          result = self._cmisClient.binding.post(remUrl.encode('utf-8'),
> -                                               urlencode(props),
> +                                               safe_urlencode(props),
>                                                 
> 'application/x-www-form-urlencoded',
>                                                 self._cmisClient.username,
>                                                 self._cmisClient.password)
> @@ -3101,6 +3101,23 @@ def encode_multipart_formdata(fields, contentFile, 
> contentType):
>      return content_type, body
>  
>  
> +def safe_urlencode(in_dict):
> +    """ Safe encoding of values taking care of unicode values
> +    urllib.urlencode doesn't like unicode values
> +    """
> +    def encoded_dict(in_dict):
> +        out_dict = {}
> +        for k, v in in_dict.iteritems():
> +            if isinstance(v, unicode):
> +                v = v.encode('utf8')
> +            elif isinstance(v, str):
> +                # Must be encoded in UTF-8
> +                v.decode('utf8')
> +            out_dict[k] = v
> +        return out_dict
> +    return urlencode(encoded_dict(in_dict))
> +
> +
>  class ResultsSerializer(object):
>  
> {code}
> https://github.com/lmignon/python-cmislib/commit/159f0202d7dd012230b31a42ef13ef0d03b46f96?diff=unified



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to