~ubuntu-branches/ubuntu/vivid/lazr.restfulclient/vivid-proposed

« back to all changes in this revision

Viewing changes to debian/patches/lp1403524.patch

  • Committer: Package Import Robot
  • Author(s): Dimitri John Ledkov
  • Date: 2015-01-21 18:58:46 UTC
  • mfrom: (13.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20150121185846-iiei1u3ms56qvj3i
Tags: 0.13.4-3
Fix json loads (LP: #1403524).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: Fix json loads calls bytes vs unicode.
 
2
Origin: commit, revision id: dimitri.j.ledkov@intel.com-20150121185019-7lhyq3goy2dpgvid
 
3
Author: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
 
4
Bug: https://launchpad.net/bugs/1403524
 
5
Last-Update: 2015-01-21
 
6
X-Bzr-Revision-Id: dimitri.j.ledkov@intel.com-20150121185019-7lhyq3goy2dpgvid
 
7
 
 
8
=== modified file 'src/lazr/restfulclient/resource.py'
 
9
--- old/src/lazr/restfulclient/resource.py      2014-07-28 15:35:35 +0000
 
10
+++ new/src/lazr/restfulclient/resource.py      2015-01-21 18:50:19 +0000
 
11
@@ -381,7 +381,7 @@
 
12
             representation = self._root._browser.get(self._wadl_resource)
 
13
             if isinstance(representation, binary_type):
 
14
                 representation = representation.decode('utf-8')
 
15
-            representation = loads(text_type(representation))
 
16
+            representation = loads(representation)
 
17
 
 
18
             # In rare cases, the resource type served by the
 
19
             # server conflicts with the type the client thought
 
20
@@ -530,8 +530,10 @@
 
21
                 url = url[1:]
 
22
             url = str(self._root_uri.append(url))
 
23
         document = self._browser.get(url)
 
24
+        if isinstance(document, binary_type):
 
25
+            document = document.decode('utf-8')
 
26
         try:
 
27
-            representation = loads(text_type(document))
 
28
+            representation = loads(document)
 
29
         except ValueError:
 
30
             raise ValueError("%s doesn't serve a JSON document." % url)
 
31
         type_link = representation.get("resource_type_link")
 
32
@@ -647,13 +649,18 @@
 
33
             # The operation returned a document with nothing
 
34
             # special about it.
 
35
             if content_type == self.JSON_MEDIA_TYPE:
 
36
-                return loads(text_type(content))
 
37
+                if isinstance(content, binary_type):
 
38
+                    content = content.decode('utf-8')
 
39
+                return loads(content)
 
40
             # We don't know how to process the content.
 
41
             return content
 
42
 
 
43
         # The operation returned a representation of some
 
44
         # resource. Instantiate a Resource object for it.
 
45
-        document = loads(text_type(content))
 
46
+        if isinstance(content, binary_type):
 
47
+            content = content.decode('utf-8')
 
48
+        
 
49
+        document = loads(content)
 
50
         if document is None:
 
51
             # The operation returned a null value.
 
52
             return document
 
53
@@ -777,7 +784,9 @@
 
54
         if response.status == 209 and content_type == self.JSON_MEDIA_TYPE:
 
55
             # The server sent back a new representation of the object.
 
56
             # Use it in preference to the existing representation.
 
57
-            new_representation = loads(text_type(content))
 
58
+            if isinstance(content, binary_type):
 
59
+                content = content.decode('utf-8')
 
60
+            new_representation = loads(content)
 
61
             self._wadl_resource.representation = new_representation
 
62
             self._wadl_resource.media_type = content_type
 
63
 
 
64
@@ -822,8 +831,10 @@
 
65
             next_link = current_page.get('next_collection_link')
 
66
             if next_link is None:
 
67
                 break
 
68
-            current_page = loads(
 
69
-                text_type(self._root._browser.get(URI(next_link))))
 
70
+            next_get = self._root._browser.get(URI(next_link))
 
71
+            if isinstance(next_get, binary_type):
 
72
+                next_get = next_get.decode('utf-8')
 
73
+            current_page = loads(next_get)
 
74
 
 
75
     def __getitem__(self, key):
 
76
         """Look up a slice, or a subordinate resource by index.
 
77
@@ -895,8 +906,10 @@
 
78
 
 
79
         # Iterate over pages until we have the correct number of entries.
 
80
         while more_needed > 0 and page_url is not None:
 
81
-            representation = loads(
 
82
-                text_type(self._root._browser.get(page_url)))
 
83
+            page_get = self._root._browser.get(page_url)
 
84
+            if isinstance(page_get, binary_type):
 
85
+                page_get = page_get.decode('utf-8')
 
86
+            representation = loads(page_get)
 
87
             current_page_entries = representation['entries']
 
88
             entry_dicts += current_page_entries[:more_needed]
 
89
             more_needed = desired_size - len(entry_dicts)
 
90
@@ -1020,8 +1033,10 @@
 
91
             # retrieve a representation of the resource and see how
 
92
             # the resource describes itself.
 
93
             try:
 
94
-                representation = loads(
 
95
-                    text_type(self._root._browser.get(url)))
 
96
+                url_get = self._root._browser.get(url)
 
97
+                if isinstance(url_get, binary_type):
 
98
+                    url_get = url_get.decode('utf-8')                
 
99
+                representation = loads(url_get)
 
100
             except HTTPError as error:
 
101
                 # There's no resource corresponding to the given ID.
 
102
                 if error.response.status == 404:
 
103