Merge lp:~cjwatson/lazr.restful/py3-dict-methods into lp:lazr.restful

Proposed by Colin Watson
Status: Merged
Merged at revision: 248
Proposed branch: lp:~cjwatson/lazr.restful/py3-dict-methods
Merge into: lp:lazr.restful
Diff against target: 202 lines (+22/-22)
10 files modified
src/lazr/restful/_resource.py (+3/-3)
src/lazr/restful/declarations.py (+2/-2)
src/lazr/restful/docs/webservice-declarations.rst (+1/-1)
src/lazr/restful/docs/webservice-marshallers.rst (+1/-1)
src/lazr/restful/docs/webservice.rst (+2/-3)
src/lazr/restful/example/base/tests/representation-cache.txt (+6/-5)
src/lazr/restful/metazcml.py (+1/-1)
src/lazr/restful/simple.py (+1/-1)
src/lazr/restful/tales.py (+1/-1)
src/lazr/restful/tests/test_declarations.py (+4/-4)
To merge this branch: bzr merge lp:~cjwatson/lazr.restful/py3-dict-methods
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+387905@code.launchpad.net

Commit message

Handle dict method changes in Python 3.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restful/_resource.py'
2--- src/lazr/restful/_resource.py 2020-06-30 15:52:03 +0000
3+++ src/lazr/restful/_resource.py 2020-07-22 23:32:54 +0000
4@@ -1221,7 +1221,7 @@
5 # The changeset contained new values for some of this object's
6 # fields, and the notification event may have changed others.
7 # Clear out any fields that changed.
8- for name, cached in self._unmarshalled_field_cache.items():
9+ for name, cached in list(self._unmarshalled_field_cache.items()):
10 cached, (field, old_value, flag) = cached
11 if flag is IUnmarshallingDoesntNeedValue:
12 continue
13@@ -1986,14 +1986,14 @@
14 schema, self.request)
15
16 singular = adapter.singular_type
17- assert not singular_names.has_key(singular), (
18+ assert singular not in singular_names, (
19 "Both %s and %s expose the singular name '%s'."
20 % (singular_names[singular].__name__,
21 schema.__name__, singular))
22 singular_names[singular] = schema
23
24 plural = adapter.plural_type
25- assert not plural_names.has_key(plural), (
26+ assert plural not in plural_names, (
27 "Both %s and %s expose the plural name '%s'."
28 % (plural_names[plural].__name__,
29 schema.__name__, plural))
30
31=== modified file 'src/lazr/restful/declarations.py'
32--- src/lazr/restful/declarations.py 2020-02-05 10:46:46 +0000
33+++ src/lazr/restful/declarations.py 2020-07-22 23:32:54 +0000
34@@ -405,7 +405,7 @@
35 # If any keywords are left over, raise an exception.
36 if len(kwparams) > 0:
37 raise TypeError("exported got an unexpected keyword "
38- "argument '%s'" % kwparams.keys()[0])
39+ "argument '%s'" % list(kwparams)[0])
40
41 # Now incorporate the list of named dicts into the VersionedDict.
42 for version, annotations in reversed(versioned_annotations):
43@@ -1254,7 +1254,7 @@
44 # Go through the fields and build up a picture of what this entry looks
45 # like for every version.
46 adapters_by_version = {}
47- fields = getFields(content_interface).items()
48+ fields = list(getFields(content_interface).items())
49 for version, iface in webservice_interfaces:
50 fields.extend(getFields(iface).items())
51 for name, field in fields:
52
53=== modified file 'src/lazr/restful/docs/webservice-declarations.rst'
54--- src/lazr/restful/docs/webservice-declarations.rst 2020-06-30 13:33:53 +0000
55+++ src/lazr/restful/docs/webservice-declarations.rst 2020-07-22 23:32:54 +0000
56@@ -2352,7 +2352,7 @@
57
58 >>> attrs['params']['arg']
59 <zope.schema._field.Float object...>
60- >>> attrs['params'].keys()
61+ >>> list(attrs['params'])
62 ['arg']
63
64 >>> attrs['return_type']
65
66=== modified file 'src/lazr/restful/docs/webservice-marshallers.rst'
67--- src/lazr/restful/docs/webservice-marshallers.rst 2020-06-30 15:52:03 +0000
68+++ src/lazr/restful/docs/webservice-marshallers.rst 2020-07-22 23:32:54 +0000
69@@ -928,7 +928,7 @@
70 ['Dessert', 'Vegetarian']
71
72 >>> unmarshalled = dict_marshaller.unmarshall(None, marshalled_dict)
73- >>> sorted(unmarshalled.iteritems())
74+ >>> sorted(unmarshalled.items())
75 [(u'bar', 'General'), (u'foo', 'Vegetarian')]
76
77 The unmarshall() method will return None when given None.
78
79=== modified file 'src/lazr/restful/docs/webservice.rst'
80--- src/lazr/restful/docs/webservice.rst 2020-02-04 13:17:32 +0000
81+++ src/lazr/restful/docs/webservice.rst 2020-07-22 23:32:54 +0000
82@@ -652,10 +652,9 @@
83 >>> from lazr.restful import Entry
84 >>> from lazr.restful.testing.webservice import FakeRequest
85
86- >>> from UserDict import UserDict
87- >>> class FakeDict(UserDict):
88+ >>> class FakeDict(dict):
89 ... def __init__(self, interface):
90- ... UserDict.__init__(self)
91+ ... super(FakeDict, self).__init__()
92 ... self.interface = interface
93 ... def __getitem__(self, key):
94 ... return self.interface
95
96=== modified file 'src/lazr/restful/example/base/tests/representation-cache.txt'
97--- src/lazr/restful/example/base/tests/representation-cache.txt 2020-02-04 13:17:32 +0000
98+++ src/lazr/restful/example/base/tests/representation-cache.txt 2020-07-22 23:32:54 +0000
99@@ -94,8 +94,9 @@
100
101 >>> test_cache.set("Cache this.", json, "1.0", "representation")
102 >>> test_cache.set("Don't cache this.", json, "1.0", "representation")
103- >>> test_dict.keys()
104- ['Cache this.,application/json,1.0']
105+ >>> for key in test_dict:
106+ ... print(key)
107+ Cache this.,application/json,1.0
108
109 ...UNLESS the representation being cached is for the version "cache
110 everything!"
111@@ -206,7 +207,7 @@
112 >>> cookbook = [cookbook for cookbook in COOKBOOKS
113 ... if cookbook.name == "Everyday Greens"][0]
114 >>> cache.set(cookbook, json, 'devel', "Dummy value.")
115- >>> print(dictionary.keys()[0])
116+ >>> print(list(dictionary.keys())[0])
117 http://.../devel/cookbooks/Everyday%20Greens,application/json
118
119 >>> from six.moves.urllib.parse import quote
120@@ -239,7 +240,7 @@
121
122 >>> print(cache.get(recipe, json, 'devel'))
123 None
124- >>> dictionary.keys()
125+ >>> list(dictionary)
126 []
127
128 Data visibility
129@@ -254,7 +255,7 @@
130 >>> print(greens['confirmed'])
131 tag:launchpad.net:2008:redacted
132
133- >>> dictionary.keys()
134+ >>> list(dictionary)
135 []
136
137 This means that if your entry resources typically contain data that's
138
139=== modified file 'src/lazr/restful/metazcml.py'
140--- src/lazr/restful/metazcml.py 2020-02-04 19:02:02 +0000
141+++ src/lazr/restful/metazcml.py 2020-07-22 23:32:54 +0000
142@@ -479,7 +479,7 @@
143 registered_adapters = set()
144 block_mutator_operations = set()
145
146- methods = interface.namesAndDescriptions(True)
147+ methods = list(interface.namesAndDescriptions(True))
148 for iface in REGISTERED_CONTRIBUTORS[interface]:
149 methods.extend(iface.namesAndDescriptions(True))
150
151
152=== modified file 'src/lazr/restful/simple.py'
153--- src/lazr/restful/simple.py 2020-02-04 13:17:32 +0000
154+++ src/lazr/restful/simple.py 2020-07-22 23:32:54 +0000
155@@ -207,7 +207,7 @@
156
157 @property
158 def top_level_names(self):
159- return self.top_level_objects.keys()
160+ return list(self.top_level_objects.keys())
161
162 def get(self, request, name):
163 """Traverse to a top-level object."""
164
165=== modified file 'src/lazr/restful/tales.py'
166--- src/lazr/restful/tales.py 2020-02-05 12:16:44 +0000
167+++ src/lazr/restful/tales.py 2020-07-22 23:32:54 +0000
168@@ -222,7 +222,7 @@
169 # iterate through attributes one at a time because some
170 # versions of docutils don't case-normalize attributes.
171 for attr_dict in attr_dicts:
172- for (key, val) in attr_dict.items():
173+ for (key, val) in list(attr_dict.items()):
174 # Prefix all CSS classes with "rst-"; and prefix all
175 # names with "rst-" to avoid conflicts.
176 if key.lower() in ('class', 'id', 'name'):
177
178=== modified file 'src/lazr/restful/tests/test_declarations.py'
179--- src/lazr/restful/tests/test_declarations.py 2020-02-19 16:09:10 +0000
180+++ src/lazr/restful/tests/test_declarations.py 2020-07-22 23:32:54 +0000
181@@ -948,8 +948,8 @@
182 *self.utility.active_versions)
183 interface_10 = interfaces[0].object
184 interface_20 = interfaces[1].object
185- self.assertEqual(interface_10.names(), ['field'])
186- self.assertEqual(interface_20.names(), ['field'])
187+ self.assertEqual(list(interface_10.names()), ['field'])
188+ self.assertEqual(list(interface_20.names()), ['field'])
189
190 def test_field_exported_as_of_later_version_is_not_exported_in_earlier_versions(self):
191 # If you export a field as_of version 2.0, it's not present in
192@@ -959,8 +959,8 @@
193 *self.utility.active_versions)
194 interface_10 = interfaces[0].object
195 interface_20 = interfaces[1].object
196- self.assertEqual(interface_10.names(), [])
197- self.assertEqual(interface_20.names(), ['field'])
198+ self.assertEqual(list(interface_10.names()), [])
199+ self.assertEqual(list(interface_20.names()), ['field'])
200
201 def test_field_not_exported_using_as_of_fails(self):
202 # If you export a field without specifying as_of, you get an

Subscribers

People subscribed via source and target branches