chemistry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Potts (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (CMIS-995) UnicodeEncodeError when calling urlencode method with a dict that contains accented characters
Date Fri, 02 Sep 2016 18:28:21 GMT

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

Jeff Potts resolved CMIS-995.
-----------------------------
    Resolution: Fixed

Checked in. Thanks for another patch, Laurent!

> 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)

Mime
View raw message