Merge ~cjwatson/lazr.restful:manual-pyupgrade into lazr.restful:main
- Git
- lp:~cjwatson/lazr.restful
- manual-pyupgrade
- Merge into main
Proposed by
Colin Watson
Status: | Merged |
---|---|
Merged at revision: | 1c2491a879912f55c3f088cb2628e839ba91ccc1 |
Proposed branch: | ~cjwatson/lazr.restful:manual-pyupgrade |
Merge into: | lazr.restful:main |
Diff against target: |
877 lines (+117/-125) 17 files modified
src/lazr/restful/_bytestorage.py (+1/-1) src/lazr/restful/_resource.py (+10/-10) src/lazr/restful/docs/checker-utilities.rst (+5/-5) src/lazr/restful/docs/django.rst (+1/-1) src/lazr/restful/docs/fields.rst (+3/-3) src/lazr/restful/docs/interface.rst (+7/-7) src/lazr/restful/docs/multiversion.rst (+8/-12) src/lazr/restful/docs/utils.rst (+4/-4) src/lazr/restful/docs/webservice-declarations.rst (+20/-20) src/lazr/restful/docs/webservice.rst (+38/-42) src/lazr/restful/example/base/tests/collection.txt (+2/-2) src/lazr/restful/example/base/tests/entry.txt (+10/-10) src/lazr/restful/example/base/tests/field.txt (+1/-1) src/lazr/restful/marshallers.py (+2/-2) src/lazr/restful/simple.py (+1/-1) src/lazr/restful/testing/webservice.py (+3/-3) src/lazr/restful/tests/test_webservice.py (+1/-1) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jürgen Gmach | Approve | ||
Review via email: mp+413877@code.launchpad.net |
Commit message
Apply some more pyupgrade-like changes
Description of the change
pyupgrade itself missed these either because they were in doctests or due to cautiousness.
To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/src/lazr/restful/_bytestorage.py b/src/lazr/restful/_bytestorage.py |
2 | index b25369c..45c6f2d 100644 |
3 | --- a/src/lazr/restful/_bytestorage.py |
4 | +++ b/src/lazr/restful/_bytestorage.py |
5 | @@ -62,7 +62,7 @@ class ByteStorageResource(HTTPResource): |
6 | """See `IByteStorageResource`.""" |
7 | media_type = self.getPreferredSupportedContentType() |
8 | if media_type in [self.WADL_TYPE, self.DEPRECATED_WADL_TYPE]: |
9 | - result = self.toWADL().encode("utf-8") |
10 | + result = self.toWADL().encode() |
11 | self.request.response.setHeader("Content-Type", media_type) |
12 | return result |
13 | if not self.context.is_stored: |
14 | diff --git a/src/lazr/restful/_resource.py b/src/lazr/restful/_resource.py |
15 | index 2d4a486..89c005b 100644 |
16 | --- a/src/lazr/restful/_resource.py |
17 | +++ b/src/lazr/restful/_resource.py |
18 | @@ -435,9 +435,9 @@ class HTTPResource: |
19 | |
20 | # Append the media type, so that web browsers won't treat |
21 | # different representations of a resource interchangeably. |
22 | - core_hashes[-1].update(("\0" + media_type).encode("UTF-8")) |
23 | + core_hashes[-1].update(("\0" + media_type).encode()) |
24 | |
25 | - etag = '"%s"' % "-".join([core.hexdigest() for core in core_hashes]) |
26 | + etag = '"%s"' % "-".join(core.hexdigest() for core in core_hashes) |
27 | self.etags_by_media_type[media_type] = etag |
28 | return etag |
29 | |
30 | @@ -1144,7 +1144,7 @@ class EntryManipulatingResource(ReadWriteResource): |
31 | # storage resource as a str, but |
32 | # BytesFieldMarshaller.marshall_from_json_data returns |
33 | # bytes. |
34 | - if value != current_value.encode("UTF-8"): |
35 | + if value != current_value.encode(): |
36 | if field.readonly: |
37 | errors.append(modified_read_only_attribute % repr_name) |
38 | else: |
39 | @@ -1279,7 +1279,7 @@ class EntryManipulatingResource(ReadWriteResource): |
40 | self.request.response.setStatus(209) |
41 | media_type = self.getPreferredSupportedContentType() |
42 | self.request.response.setHeader("Content-type", media_type) |
43 | - return self._representation(media_type).encode("UTF-8") |
44 | + return self._representation(media_type).encode() |
45 | else: |
46 | # The object moved. Serve a redirect to its new location. |
47 | # This might not necessarily be the location of the entry! |
48 | @@ -1319,7 +1319,7 @@ class EntryFieldResource(FieldUnmarshallerMixin, EntryManipulatingResource): |
49 | return b"" |
50 | else: |
51 | self.request.response.setHeader("Content-Type", media_type) |
52 | - return self._representation(media_type).encode("UTF-8") |
53 | + return self._representation(media_type).encode() |
54 | |
55 | def do_PUT(self, media_type, representation): |
56 | """Overwrite the field's existing value with a new value.""" |
57 | @@ -1344,7 +1344,7 @@ class EntryFieldResource(FieldUnmarshallerMixin, EntryManipulatingResource): |
58 | # generating the representation might itself change across |
59 | # versions. |
60 | revno = getUtility(IWebServiceConfiguration).code_revision |
61 | - return [core.encode("utf-8") for core in [revno, str(value)]] |
62 | + return [core.encode() for core in [revno, str(value)]] |
63 | |
64 | def _representation(self, media_type): |
65 | """Create a representation of the field value.""" |
66 | @@ -1408,8 +1408,8 @@ def make_entry_etag_cores(field_details): |
67 | bucket = unwritable_values |
68 | bucket.append(decode_value(details["value"])) |
69 | |
70 | - unwritable = "\0".join(unwritable_values).encode("utf-8") |
71 | - writable = "\0".join(writable_values).encode("utf-8") |
72 | + unwritable = "\0".join(unwritable_values).encode() |
73 | + writable = "\0".join(writable_values).encode() |
74 | return [unwritable, writable] |
75 | |
76 | |
77 | @@ -1608,7 +1608,7 @@ class EntryResource( |
78 | return b"" |
79 | else: |
80 | self.request.response.setHeader("Content-Type", media_type) |
81 | - return self._representation(media_type).encode("UTF-8") |
82 | + return self._representation(media_type).encode() |
83 | |
84 | def do_PUT(self, media_type, representation): |
85 | """Modify the entry's state to match the given representation. |
86 | @@ -1940,7 +1940,7 @@ class ServiceRootResource(HTTPResource): |
87 | itself changes. |
88 | """ |
89 | revno = getUtility(IWebServiceConfiguration).code_revision |
90 | - return [revno.encode("utf-8")] |
91 | + return [revno.encode()] |
92 | |
93 | def __call__(self, REQUEST=None): |
94 | """Handle a GET request.""" |
95 | diff --git a/src/lazr/restful/docs/checker-utilities.rst b/src/lazr/restful/docs/checker-utilities.rst |
96 | index 56ad615..1836f02 100644 |
97 | --- a/src/lazr/restful/docs/checker-utilities.rst |
98 | +++ b/src/lazr/restful/docs/checker-utilities.rst |
99 | @@ -15,18 +15,18 @@ the schema passed in as parameter. |
100 | >>> from zope.schema import TextLine |
101 | |
102 | >>> class MySchema(Interface): |
103 | - ... an_attr = Attribute(u'An attribute.') |
104 | + ... an_attr = Attribute('An attribute.') |
105 | ... |
106 | - ... a_field = TextLine(title=u'A property that can be set.') |
107 | + ... a_field = TextLine(title='A property that can be set.') |
108 | ... |
109 | ... a_read_only_field = TextLine( |
110 | - ... title=u'A read only property', readonly=True) |
111 | + ... title='A read only property', readonly=True) |
112 | ... |
113 | ... def aMethod(): |
114 | ... "A simple method." |
115 | |
116 | >>> @implementer(MySchema) |
117 | - ... class MyContent(object): |
118 | + ... class MyContent: |
119 | ... def __init__(self, an_attr, a_field, a_read_only_field): |
120 | ... self.an_attr = an_attr |
121 | ... self.a_field = a_field |
122 | @@ -42,7 +42,7 @@ attributes defined in the schema. |
123 | |
124 | >>> from lazr.restful.debug import debug_proxy |
125 | >>> from zope.security.checker import undefineChecker, ProxyFactory |
126 | - >>> content = MyContent(1, u'Mutable Field', u'RO Field') |
127 | + >>> content = MyContent(1, 'Mutable Field', 'RO Field') |
128 | |
129 | ProxyFactory wraps the content using the defined checker. |
130 | |
131 | diff --git a/src/lazr/restful/docs/django.rst b/src/lazr/restful/docs/django.rst |
132 | index 2ad1df2..503737c 100644 |
133 | --- a/src/lazr/restful/docs/django.rst |
134 | +++ b/src/lazr/restful/docs/django.rst |
135 | @@ -43,7 +43,7 @@ sorts of Django code that we can't handle. |
136 | >>> import django.core.exceptions |
137 | >>> django.core.exceptions.ObjectDoesNotExist = ObjectDoesNotExist |
138 | |
139 | - >>> class Manager(object): |
140 | + >>> class Manager: |
141 | ... """A fake version of Django's Manager class.""" |
142 | ... def __init__(self, l): |
143 | ... self.list = l |
144 | diff --git a/src/lazr/restful/docs/fields.rst b/src/lazr/restful/docs/fields.rst |
145 | index a91761f..869eb20 100644 |
146 | --- a/src/lazr/restful/docs/fields.rst |
147 | +++ b/src/lazr/restful/docs/fields.rst |
148 | @@ -14,7 +14,7 @@ field provides ICollectionField which is an extension of ISequence. |
149 | >>> from lazr.restful.fields import CollectionField |
150 | |
151 | >>> int_collection = CollectionField( |
152 | - ... title=u'A collection', value_type=Int()) |
153 | + ... title='A collection', value_type=Int()) |
154 | |
155 | >>> from zope.interface.verify import verifyObject |
156 | >>> verifyObject(ICollectionField, int_collection) |
157 | @@ -31,7 +31,7 @@ By default, such fields are readonly. |
158 | But it can be made read-write. |
159 | |
160 | >>> rw_collection = CollectionField( |
161 | - ... title=u'A writable collection.', readonly=False) |
162 | + ... title='A writable collection.', readonly=False) |
163 | >>> rw_collection.readonly |
164 | False |
165 | |
166 | @@ -75,7 +75,7 @@ by value, but only check that the value provides the proper schema. |
167 | >>> verifyObject(IReference, reference) |
168 | True |
169 | |
170 | - >>> class Fake(object): |
171 | + >>> class Fake: |
172 | ... pass |
173 | >>> fake = Fake() |
174 | >>> reference.validate(fake) |
175 | diff --git a/src/lazr/restful/docs/interface.rst b/src/lazr/restful/docs/interface.rst |
176 | index a2d100e..afcd439 100644 |
177 | --- a/src/lazr/restful/docs/interface.rst |
178 | +++ b/src/lazr/restful/docs/interface.rst |
179 | @@ -26,13 +26,13 @@ Let's define a "model" schema: |
180 | >>> class MyModel(Interface): |
181 | ... """A very simple model.""" |
182 | ... |
183 | - ... age = Int(title=u"Number of years since birth") |
184 | - ... name = Text(title=u"Identifier") |
185 | + ... age = Int(title="Number of years since birth") |
186 | + ... name = Text(title="Identifier") |
187 | |
188 | >>> class Initiated(MyModel): |
189 | ... illuminated = Choice( |
190 | - ... title=u"Has seen the fnords?", values=('yes', 'no', 'maybe')) |
191 | - ... fancy_value = Attribute(u"Some other fancy value.") |
192 | + ... title="Has seen the fnords?", values=('yes', 'no', 'maybe')) |
193 | + ... fancy_value = Attribute("Some other fancy value.") |
194 | |
195 | The use_template() helper takes as first parameter the interface to use |
196 | as a template and either a 'include' or 'exclude' parameter taking the |
197 | @@ -44,8 +44,8 @@ So to create a form for UI with more appropriate labels you would use: |
198 | >>> class MyForm1(Interface): |
199 | ... "Form schema for a MyModel." |
200 | ... use_template(MyModel, include=['age', 'name']) |
201 | - ... age.title = u'Your age:' |
202 | - ... name.title = u'Your name:' |
203 | + ... age.title = 'Your age:' |
204 | + ... name.title = 'Your name:' |
205 | |
206 | The MyForm1 interface now has an age and name fields that have a |
207 | distinct titles than their original: |
208 | @@ -157,7 +157,7 @@ schema field and override some of the copy attributes at the same time. |
209 | |
210 | >>> from lazr.restful.interface import copy_field |
211 | >>> age = copy_field( |
212 | - ... MyModel['age'], title=u'The age.', required=False, |
213 | + ... MyModel['age'], title='The age.', required=False, |
214 | ... arbitrary=1) |
215 | >>> age.__class__.__name__ |
216 | 'Int' |
217 | diff --git a/src/lazr/restful/docs/multiversion.rst b/src/lazr/restful/docs/multiversion.rst |
218 | index 8a3faca..baeef02 100644 |
219 | --- a/src/lazr/restful/docs/multiversion.rst |
220 | +++ b/src/lazr/restful/docs/multiversion.rst |
221 | @@ -135,17 +135,13 @@ Now let's define the data model. The model in webservice.txt is |
222 | pretty complicated; this model will be just complicated enough to |
223 | illustrate how to publish multiple versions of a web service. |
224 | |
225 | -All classes defined in this test are new-style classes. |
226 | - |
227 | - >>> __metaclass__ = type |
228 | - |
229 | >>> from zope.interface import Interface, Attribute |
230 | >>> from zope.schema import Bool, Bytes, Int, Text, TextLine, Object |
231 | |
232 | >>> class IContact(Interface): |
233 | - ... name = TextLine(title=u"Name", required=True) |
234 | - ... phone = TextLine(title=u"Phone number", required=True) |
235 | - ... fax = TextLine(title=u"Fax number", required=False) |
236 | + ... name = TextLine(title="Name", required=True) |
237 | + ... phone = TextLine(title="Phone number", required=True) |
238 | + ... fax = TextLine(title="Fax number", required=False) |
239 | |
240 | Here's an interface for the 'set' object that manages the |
241 | contacts. |
242 | @@ -267,9 +263,9 @@ The "1.0" version publishes the IContact interface as is, but renames |
243 | two of the fields. |
244 | |
245 | >>> class IContactEntry10(IContactEntry): |
246 | - ... name = TextLine(title=u"Name", required=True) |
247 | - ... phone_number = TextLine(title=u"Phone number", required=True) |
248 | - ... fax_number = TextLine(title=u"Fax number", required=False) |
249 | + ... name = TextLine(title="Name", required=True) |
250 | + ... phone_number = TextLine(title="Phone number", required=True) |
251 | + ... fax_number = TextLine(title="Fax number", required=False) |
252 | ... taggedValue(LAZR_WEBSERVICE_NAME, |
253 | ... dict(singular="contact", plural="contacts")) |
254 | |
255 | @@ -290,8 +286,8 @@ The "dev" version drops the "fax_number" field because fax machines |
256 | are obsolete. |
257 | |
258 | >>> class IContactEntryDev(IContactEntry): |
259 | - ... name = TextLine(title=u"Name", required=True) |
260 | - ... phone_number = TextLine(title=u"Phone number", required=True) |
261 | + ... name = TextLine(title="Name", required=True) |
262 | + ... phone_number = TextLine(title="Phone number", required=True) |
263 | ... taggedValue(LAZR_WEBSERVICE_NAME, |
264 | ... dict(singular="contact", plural="contacts")) |
265 | >>> IContactEntryDev['phone_number'].setTaggedValue( |
266 | diff --git a/src/lazr/restful/docs/utils.rst b/src/lazr/restful/docs/utils.rst |
267 | index 82cdf43..ea1636a 100644 |
268 | --- a/src/lazr/restful/docs/utils.rst |
269 | +++ b/src/lazr/restful/docs/utils.rst |
270 | @@ -179,8 +179,8 @@ that implements as much of the interface as possible. |
271 | >>> from zope.schema import TextLine |
272 | >>> from zope.interface import Interface |
273 | >>> class ITwoFields(Interface): |
274 | - ... field_1 = TextLine(title=u"field 1", default=u"field_1 default") |
275 | - ... field_2 = TextLine(title=u"field 2") |
276 | + ... field_1 = TextLine(title="field 1", default="field_1 default") |
277 | + ... field_2 = TextLine(title="field 2") |
278 | ... def a_method(): |
279 | ... pass |
280 | |
281 | @@ -233,7 +233,7 @@ not define that attribute. |
282 | The 'superclass' argument lets you specify a superclass for the |
283 | generated class. |
284 | |
285 | - >>> class TwoFieldsSuperclass(object): |
286 | + >>> class TwoFieldsSuperclass: |
287 | ... def a_method(self): |
288 | ... return "superclass result" |
289 | |
290 | @@ -302,7 +302,7 @@ makes problems harder to diagnose. |
291 | >>> import sys |
292 | >>> from lazr.restful.utils import safe_hasattr |
293 | |
294 | - >>> class Oracle(object): |
295 | + >>> class Oracle: |
296 | ... @property |
297 | ... def is_full_moon(self): |
298 | ... return full_moon |
299 | diff --git a/src/lazr/restful/docs/webservice-declarations.rst b/src/lazr/restful/docs/webservice-declarations.rst |
300 | index 8c66e30..447aa49 100644 |
301 | --- a/src/lazr/restful/docs/webservice-declarations.rst |
302 | +++ b/src/lazr/restful/docs/webservice-declarations.rst |
303 | @@ -41,15 +41,15 @@ field, but not the inventory_number field. |
304 | ... class IBook(Interface): |
305 | ... """A simple book data model.""" |
306 | ... |
307 | - ... title = exported(TextLine(title=u'The book title')) |
308 | + ... title = exported(TextLine(title='The book title')) |
309 | ... |
310 | - ... author = exported(TextLine(title=u"The book's author.")) |
311 | + ... author = exported(TextLine(title="The book's author.")) |
312 | ... |
313 | ... base_price = exported(Float( |
314 | - ... title=u"The regular price of the book."), |
315 | + ... title="The regular price of the book."), |
316 | ... exported_as='price') |
317 | ... |
318 | - ... inventory_number = TextLine(title=u'The inventory part number.') |
319 | + ... inventory_number = TextLine(title='The inventory part number.') |
320 | |
321 | These declarations add tagged values to the original interface elements. |
322 | The tags are in the lazr.restful namespace and are dictionaries of |
323 | @@ -125,7 +125,7 @@ In the same vein, exported_as_webservice_entry() can only be used on |
324 | Interface. |
325 | |
326 | >>> @exported_as_webservice_entry() |
327 | - ... class NotAnInterface(object): |
328 | + ... class NotAnInterface: |
329 | ... pass |
330 | Traceback (most recent call last): |
331 | ... |
332 | @@ -144,7 +144,7 @@ this by passing in False for the `publish_web_link` argument to |
333 | >>> from zope.interface import Attribute |
334 | >>> @exported_as_webservice_entry(publish_web_link=False) |
335 | ... class INotOnTheWebsite(Interface): |
336 | - ... field = exported(TextLine(title=u"A field.")) |
337 | + ... field = exported(TextLine(title="A field.")) |
338 | >>> print_export_tag(INotOnTheWebsite) |
339 | _as_of_was_used: False |
340 | contributes_to: None |
341 | @@ -161,7 +161,7 @@ items: |
342 | |
343 | >>> class ISimpleComment(Interface): |
344 | ... """A simple comment.""" |
345 | - ... comment = TextLine(title=u'Comment') |
346 | + ... comment = TextLine(title='Comment') |
347 | |
348 | >>> from zope.schema import Object |
349 | >>> from lazr.restful.fields import CollectionField |
350 | @@ -269,7 +269,7 @@ As it is an error, to mark more than one method: |
351 | exported_as_webservice_collection() can only be used on Interface. |
352 | |
353 | >>> @exported_as_webservice_collection(ISampleInterface) |
354 | - ... class NotAnInterface(object): |
355 | + ... class NotAnInterface: |
356 | ... pass |
357 | Traceback (most recent call last): |
358 | ... |
359 | @@ -347,14 +347,14 @@ operation returns a collection of entries. |
360 | ... |
361 | ... @collection_default_content() |
362 | ... @operation_parameters( |
363 | - ... text=copy_field(IBook['title'], title=u'Text to search for.')) |
364 | + ... text=copy_field(IBook['title'], title='Text to search for.')) |
365 | ... @operation_returns_collection_of(IBook) |
366 | ... @export_read_operation() |
367 | ... def searchBookTitles(text): |
368 | ... """Return list of books whose titles contain 'text'.""" |
369 | ... |
370 | ... @operation_parameters( |
371 | - ... text=copy_field(IBook['title'], title=u'Text to search for.')) |
372 | + ... text=copy_field(IBook['title'], title='Text to search for.')) |
373 | ... @operation_returns_entry(IBook) |
374 | ... @export_read_operation() |
375 | ... def bestMatch(text): |
376 | @@ -481,7 +481,7 @@ on the method signature. |
377 | ... class ComplexParameterDefinition(Interface): |
378 | ... @operation_parameters( |
379 | ... required1=TextLine(), |
380 | - ... required2=TextLine(default=u'Not required'), |
381 | + ... required2=TextLine(default='Not required'), |
382 | ... optional1=TextLine(required=True), |
383 | ... optional2=TextLine(), |
384 | ... ) |
385 | @@ -792,7 +792,7 @@ we can have an IDeveloper interface contributing to IUser. |
386 | >>> @exported_as_webservice_entry(contributes_to=[IUser]) |
387 | ... class IDeveloper(Interface): |
388 | ... programming_languages = exported(List( |
389 | - ... title=u'Programming Languages spoken by this developer')) |
390 | + ... title='Programming Languages spoken by this developer')) |
391 | |
392 | This will cause all the fields/methods of IDeveloper to be exported as part of |
393 | the IBook entry instead of exporting a new entry for IDeveloper. For this to |
394 | @@ -996,7 +996,7 @@ interface, and proxies all attributes to the underlying object. |
395 | >>> from zope.interface.verify import verifyObject |
396 | >>> from zope.interface import implementer |
397 | >>> @implementer(IBook) |
398 | - ... class Book(object): |
399 | + ... class Book: |
400 | ... """Simple IBook implementation.""" |
401 | ... def __init__(self, author, title, base_price, |
402 | ... inventory_number): |
403 | @@ -1009,7 +1009,7 @@ Now we can turn a Book object into something that implements |
404 | IBookEntry. |
405 | |
406 | >>> entry_adapter = entry_adapter_factory( |
407 | - ... Book(u'Aldous Huxley', u'Island', 10.0, '12345'), |
408 | + ... Book('Aldous Huxley', 'Island', 10.0, '12345'), |
409 | ... request) |
410 | |
411 | >>> entry_adapter.schema is entry_interface |
412 | @@ -1059,7 +1059,7 @@ The find() method will return the result of calling the method tagged |
413 | with the @collection_default_content decorator. |
414 | |
415 | >>> @implementer(IBookSet) |
416 | - ... class BookSet(object): |
417 | + ... class BookSet: |
418 | ... """Simple IBookSet implementation.""" |
419 | ... |
420 | ... def __init__(self, books=()): |
421 | @@ -1087,7 +1087,7 @@ find(). The REQUEST_USER marker value will be replaced by the logged in |
422 | user. |
423 | |
424 | >>> @implementer(ICheckedOutBookSet) |
425 | - ... class CheckedOutBookSet(object): |
426 | + ... class CheckedOutBookSet: |
427 | ... """Simple ICheckedOutBookSet implementation.""" |
428 | ... |
429 | ... def getByTitle(self, title, user): |
430 | @@ -1278,7 +1278,7 @@ adapter and set the request as the current interaction.) |
431 | >>> from zope.traversing.browser.interfaces import IAbsoluteURL |
432 | >>> from zope.publisher.interfaces.http import IHTTPApplicationRequest |
433 | >>> @implementer(IAbsoluteURL) |
434 | - ... class BookAbsoluteURL(object): |
435 | + ... class BookAbsoluteURL: |
436 | ... """Returns a believable absolute URL for a book.""" |
437 | ... |
438 | ... def __init__(self, context, request): |
439 | @@ -1417,7 +1417,7 @@ The implementation of set_text() applies a standardized transform to the |
440 | incoming text. |
441 | |
442 | >>> @implementer(IHasText) |
443 | - ... class HasText(object): |
444 | + ... class HasText: |
445 | ... |
446 | ... def __init__(self): |
447 | ... self.text = '' |
448 | @@ -1580,7 +1580,7 @@ call methods that declare at least one of the corresponding scopes. |
449 | ... pass |
450 | |
451 | >>> @implementer(IScopedEntry) |
452 | - ... class ScopedEntry(object): |
453 | + ... class ScopedEntry: |
454 | ... |
455 | ... value = 'initial' |
456 | ... |
457 | @@ -2764,7 +2764,7 @@ After the registration, adapters from IBook to IEntry, and IBookSet to |
458 | ICollection are available: |
459 | |
460 | >>> from zope.component import getMultiAdapter |
461 | - >>> book = Book(u'George Orwell', u'1984', 10.0, u'12345-1984') |
462 | + >>> book = Book('George Orwell', '1984', 10.0, '12345-1984') |
463 | >>> bookset = BookSet([book]) |
464 | |
465 | >>> entry_adapter = getMultiAdapter((book, request), IEntry) |
466 | diff --git a/src/lazr/restful/docs/webservice.rst b/src/lazr/restful/docs/webservice.rst |
467 | index 5289633..411d9e8 100644 |
468 | --- a/src/lazr/restful/docs/webservice.rst |
469 | +++ b/src/lazr/restful/docs/webservice.rst |
470 | @@ -18,10 +18,6 @@ cookbook contains multiple recipes. A recipe is a recipe _for_ a dish, |
471 | and two or more cookbooks may provide different recipes for the same |
472 | dish. Users may comment on cookbooks and on individual recipes. |
473 | |
474 | -All classes defined in this test are new-style classes. |
475 | - |
476 | - >>> __metaclass__ = type |
477 | - |
478 | >>> from zope.interface import Interface, Attribute |
479 | >>> from zope.schema import Bool, Bytes, Int, Text, TextLine |
480 | >>> from lazr.restful.fields import Reference |
481 | @@ -32,7 +28,7 @@ All classes defined in this test are new-style classes. |
482 | ... "Defined here for simplicity of testing.") |
483 | |
484 | >>> class IAuthor(ITestDataObject): |
485 | - ... name = TextLine(title=u"Name", required=True) |
486 | + ... name = TextLine(title="Name", required=True) |
487 | ... # favorite_recipe.schema will be set to IRecipe once |
488 | ... # IRecipe is defined. |
489 | ... favorite_recipe = Reference(schema=Interface) |
490 | @@ -43,30 +39,30 @@ All classes defined in this test are new-style classes. |
491 | |
492 | >>> class IComment(ITestDataObject): |
493 | ... target = Attribute('The object containing this comment.') |
494 | - ... text = TextLine(title=u"Text", required=True) |
495 | + ... text = TextLine(title="Text", required=True) |
496 | |
497 | >>> class ICookbook(ICommentTarget): |
498 | - ... name = TextLine(title=u"Name", required=True) |
499 | + ... name = TextLine(title="Name", required=True) |
500 | ... author = Reference(schema=IAuthor) |
501 | - ... cuisine = TextLine(title=u"Cuisine", required=False, default=None) |
502 | + ... cuisine = TextLine(title="Cuisine", required=False, default=None) |
503 | ... recipes = Attribute("List of recipes published in this cookbook.") |
504 | - ... cover = Bytes(0, 5000, title=u"An image of the cookbook's cover.") |
505 | + ... cover = Bytes(0, 5000, title="An image of the cookbook's cover.") |
506 | ... def removeRecipe(recipe): |
507 | ... """Remove a recipe from this cookbook.""" |
508 | |
509 | >>> class IDish(ITestDataObject): |
510 | - ... name = TextLine(title=u"Name", required=True) |
511 | + ... name = TextLine(title="Name", required=True) |
512 | ... recipes = Attribute("List of recipes for this dish.") |
513 | ... def removeRecipe(recipe): |
514 | ... """Remove one of the recipes for this dish.""" |
515 | |
516 | >>> class IRecipe(ICommentTarget): |
517 | - ... id = Int(title=u"Unique ID", required=True) |
518 | + ... id = Int(title="Unique ID", required=True) |
519 | ... dish = Reference(schema=IDish) |
520 | ... cookbook = Reference(schema=ICookbook) |
521 | - ... instructions = Text(title=u"How to prepare the recipe.", |
522 | + ... instructions = Text(title="How to prepare the recipe.", |
523 | ... required=True) |
524 | - ... private = Bool(title=u"Whether the public can see this recipe.", |
525 | + ... private = Bool(title="Whether the public can see this recipe.", |
526 | ... default=False) |
527 | ... def delete(): |
528 | ... """Delete this recipe.""" |
529 | @@ -309,20 +305,20 @@ interface. |
530 | |
531 | Here are the "model objects" themselves: |
532 | |
533 | - >>> A1 = Author(u"Julia Child") |
534 | - >>> A2 = Author(u"Irma S. Rombauer") |
535 | - >>> A3 = Author(u"James Beard") |
536 | + >>> A1 = Author("Julia Child") |
537 | + >>> A2 = Author("Irma S. Rombauer") |
538 | + >>> A3 = Author("James Beard") |
539 | >>> AUTHORS = [A1, A2, A3] |
540 | |
541 | - >>> C1 = Cookbook(u"Mastering the Art of French Cooking", A1) |
542 | - >>> C2 = Cookbook(u"The Joy of Cooking", A2) |
543 | - >>> C3 = Cookbook(u"James Beard's American Cookery", A3) |
544 | + >>> C1 = Cookbook("Mastering the Art of French Cooking", A1) |
545 | + >>> C2 = Cookbook("The Joy of Cooking", A2) |
546 | + >>> C3 = Cookbook("James Beard's American Cookery", A3) |
547 | >>> COOKBOOKS = [C1, C2, C3] |
548 | |
549 | >>> D1 = Dish("Roast chicken") |
550 | - >>> C1_D1 = Recipe(1, C1, D1, u"You can always judge...") |
551 | - >>> C2_D1 = Recipe(2, C2, D1, u"Draw, singe, stuff, and truss...") |
552 | - >>> C3_D1 = Recipe(3, C3, D1, u"A perfectly roasted chicken is...") |
553 | + >>> C1_D1 = Recipe(1, C1, D1, "You can always judge...") |
554 | + >>> C2_D1 = Recipe(2, C2, D1, "Draw, singe, stuff, and truss...") |
555 | + >>> C3_D1 = Recipe(3, C3, D1, "A perfectly roasted chicken is...") |
556 | |
557 | >>> D2 = Dish("Baked beans") |
558 | >>> C2_D2 = Recipe(4, C2, D2, "Preheat oven to...") |
559 | @@ -601,7 +597,7 @@ makes it possible to serve a link from a recipe to its cookbook. |
560 | ... "The part of a recipe that we expose through the web service." |
561 | ... cookbook = Reference(schema=ICookbook) |
562 | ... dish = Reference(schema=IDish) |
563 | - ... instructions = Text(title=u"Name", required=True) |
564 | + ... instructions = Text(title="Name", required=True) |
565 | ... comments = CollectionField(value_type=Reference(schema=IComment)) |
566 | ... taggedValue( |
567 | ... LAZR_WEBSERVICE_NAME, |
568 | @@ -611,13 +607,13 @@ makes it possible to serve a link from a recipe to its cookbook. |
569 | |
570 | >>> from lazr.restful.fields import ReferenceChoice |
571 | >>> class ICookbookEntry(IEntry): |
572 | - ... name = TextLine(title=u"Name", required=True) |
573 | - ... cuisine = TextLine(title=u"Cuisine", required=False, default=None) |
574 | + ... name = TextLine(title="Name", required=True) |
575 | + ... cuisine = TextLine(title="Cuisine", required=False, default=None) |
576 | ... author = ReferenceChoice( |
577 | ... schema=IAuthor, vocabulary=AuthorVocabulary()) |
578 | ... recipes = CollectionField(value_type=Reference(schema=IRecipe)) |
579 | ... comments = CollectionField(value_type=Reference(schema=IComment)) |
580 | - ... cover = Bytes(0, 5000, title=u"An image of the cookbook's cover.") |
581 | + ... cover = Bytes(0, 5000, title="An image of the cookbook's cover.") |
582 | ... taggedValue( |
583 | ... LAZR_WEBSERVICE_NAME, |
584 | ... dict( |
585 | @@ -654,7 +650,7 @@ more on ``delegate_to()``.) |
586 | |
587 | >>> class FakeDict(dict): |
588 | ... def __init__(self, interface): |
589 | - ... super(FakeDict, self).__init__() |
590 | + ... super().__init__() |
591 | ... self.interface = interface |
592 | ... def __getitem__(self, key): |
593 | ... return self.interface |
594 | @@ -975,7 +971,7 @@ a named factory operation for creating a new cookbook. |
595 | ... TextLine(__name__='author_name'), |
596 | ... TextLine(__name__='title'), |
597 | ... TextLine( |
598 | - ... __name__='cuisine', default=u'Brazilian', required=False), |
599 | + ... __name__='cuisine', default='Brazilian', required=False), |
600 | ... ) |
601 | ... return_type = Reference(schema=IRecipe) |
602 | ... |
603 | @@ -1579,7 +1575,7 @@ results. In this case we do the same thing we do when serving a |
604 | collection resource. We fetch one batch of results and represent it as |
605 | a JSON hash containing a list of entries. |
606 | |
607 | - >>> class StubResultSet(object): |
608 | + >>> class StubResultSet: |
609 | ... results = [C1_D1, C2_D1] |
610 | ... |
611 | ... def __iter__(self): |
612 | @@ -1821,7 +1817,7 @@ server. The server will know that the client isn't actually trying to |
613 | set the field value to 'tag:launchpad.net:2008:redacted'. |
614 | |
615 | >>> headers = {'CONTENT_TYPE' : 'application/json'} |
616 | - >>> body = simplejson.dumps(author).encode('UTF-8') |
617 | + >>> body = simplejson.dumps(author).encode() |
618 | >>> put_request = create_web_service_request( |
619 | ... beard_url, body=body, environ=headers, method='PUT') |
620 | >>> print(six.ensure_text(put_request.traverse(app)())) |
621 | @@ -1834,7 +1830,7 @@ PUT, even when its current value is redacted. |
622 | >>> author['favorite_recipe_link'] = 'http://' + quote( |
623 | ... 'api.cookbooks.dev/beta/cookbooks/' |
624 | ... 'The Joy of Cooking/recipes/Roast chicken') |
625 | - >>> body = simplejson.dumps(author).encode('UTF-8') |
626 | + >>> body = simplejson.dumps(author).encode() |
627 | >>> put_request = create_web_service_request( |
628 | ... beard_url, body=body, environ=headers, method='PUT') |
629 | >>> print(six.ensure_text(put_request.traverse(app)())) |
630 | @@ -1854,7 +1850,7 @@ permission to see: |
631 | |
632 | >>> author['favorite_recipe_link'] = ( |
633 | ... 'http://api.cookbooks.dev' + private_recipe_url) |
634 | - >>> body = simplejson.dumps(author).encode('UTF-8') |
635 | + >>> body = simplejson.dumps(author).encode() |
636 | >>> put_request = create_web_service_request( |
637 | ... beard_url, body=body, environ=headers, method='PUT') |
638 | >>> print(put_request.traverse(app)()) |
639 | @@ -2022,7 +2018,7 @@ server. Note also that another modification event is sent out and |
640 | intercepted by the modified_cookbook() listener. |
641 | |
642 | >>> joy['name'] = 'The Joy of Cooking' |
643 | - >>> body = simplejson.dumps(joy).encode('UTF-8') |
644 | + >>> body = simplejson.dumps(joy).encode() |
645 | >>> put_request = create_web_service_request( |
646 | ... '/beta/cookbooks/The%20Joy%20of%20Cooking%20%28revised%29', |
647 | ... body=body, environ=headers, method='PUT') |
648 | @@ -2061,12 +2057,12 @@ their URLs, we make the change by modifying the cookbook's |
649 | ... representation = {'author_link' : new_author_link} |
650 | ... resource = create_web_service_request( |
651 | ... '/beta/cookbooks/The%20Joy%20of%20Cooking', |
652 | - ... body=simplejson.dumps(representation).encode('UTF-8'), |
653 | + ... body=simplejson.dumps(representation).encode(), |
654 | ... environ=headers, method='PATCH', hostname=host).traverse(app) |
655 | ... return six.ensure_text(resource()) |
656 | >>> path = '/beta/authors/Julia%20Child' |
657 | |
658 | - >>> print(change_joy_author(u'http://api.cookbooks.dev' + path)) |
659 | + >>> print(change_joy_author('http://api.cookbooks.dev' + path)) |
660 | {...} |
661 | |
662 | >>> joy_resource = create_web_service_request( |
663 | @@ -2079,38 +2075,38 @@ When identifying an object by URL, make sure the hostname of your URL |
664 | matches the hostname you're requesting. If they don't match, your |
665 | request will fail. |
666 | |
667 | - >>> print(change_joy_author(u'http://not.the.same.host' + path)) |
668 | + >>> print(change_joy_author('http://not.the.same.host' + path)) |
669 | author_link: No such object... |
670 | |
671 | One possible source of hostname mismatches is the HTTP port. If the |
672 | web service is served from a strange port, you'll need to specify that |
673 | port in the URLs you send. |
674 | |
675 | - >>> print(change_joy_author(u'http://api.cookbooks.dev' + path, |
676 | + >>> print(change_joy_author('http://api.cookbooks.dev' + path, |
677 | ... host='api.cookbooks.dev:9000')) |
678 | author_link: No such object... |
679 | |
680 | - >>> print(change_joy_author(u'http://api.cookbooks.dev:9000' + path, |
681 | + >>> print(change_joy_author('http://api.cookbooks.dev:9000' + path, |
682 | ... host='api.cookbooks.dev:9000')) |
683 | {...} |
684 | |
685 | You don't have to specify the default port in the URLs you send, even |
686 | if you specified it when you made the request. |
687 | |
688 | - >>> print(change_joy_author(u'http://api.cookbooks.dev' + path, |
689 | + >>> print(change_joy_author('http://api.cookbooks.dev' + path, |
690 | ... host='api.cookbooks.dev:80')) |
691 | {...} |
692 | |
693 | - >>> print(change_joy_author(u'http://api.cookbooks.dev:80' + path, |
694 | + >>> print(change_joy_author('http://api.cookbooks.dev:80' + path, |
695 | ... host='api.cookbooks.dev')) |
696 | {...} |
697 | |
698 | - >>> print(change_joy_author(u'https://api.cookbooks.dev' + path, |
699 | + >>> print(change_joy_author('https://api.cookbooks.dev' + path, |
700 | ... host='api.cookbooks.dev:443')) |
701 | author_link: No such object... |
702 | |
703 | >>> webservice_configuration.use_https = True |
704 | - >>> print(change_joy_author(u'https://api.cookbooks.dev' + path, |
705 | + >>> print(change_joy_author('https://api.cookbooks.dev' + path, |
706 | ... host='api.cookbooks.dev:443')) |
707 | {...} |
708 | >>> webservice_configuration.use_https = False |
709 | diff --git a/src/lazr/restful/example/base/tests/collection.txt b/src/lazr/restful/example/base/tests/collection.txt |
710 | index c2a47dc..e156a43 100644 |
711 | --- a/src/lazr/restful/example/base/tests/collection.txt |
712 | +++ b/src/lazr/restful/example/base/tests/collection.txt |
713 | @@ -251,8 +251,8 @@ handling is in the validate() method of the 'search' field. |
714 | The error message may contain Unicode characters: |
715 | |
716 | >>> from lazr.restful.testing.helpers import encode_response |
717 | - >>> url = u"/cookbooks?ws.op=find_for_cuisine&cuisine=%E2%98%83" |
718 | - >>> response = webservice.get(url.encode("utf-8")) |
719 | + >>> url = b"/cookbooks?ws.op=find_for_cuisine&cuisine=%E2%98%83" |
720 | + >>> response = webservice.get(url) |
721 | >>> print(encode_response(response)) |
722 | HTTP/1.1 400 Bad Request |
723 | ... |
724 | diff --git a/src/lazr/restful/example/base/tests/entry.txt b/src/lazr/restful/example/base/tests/entry.txt |
725 | index c260361..f24c7a3 100644 |
726 | --- a/src/lazr/restful/example/base/tests/entry.txt |
727 | +++ b/src/lazr/restful/example/base/tests/entry.txt |
728 | @@ -870,46 +870,46 @@ the assertion. The string used in the assertion might not be a date. |
729 | |
730 | Or it might be a date that's not in UTC. |
731 | |
732 | - >>> print(patch_greens_copyright_date(u'2005-06-06T00:00:00.000000+05:00')) |
733 | + >>> print(patch_greens_copyright_date('2005-06-06T00:00:00.000000+05:00')) |
734 | HTTP/1.1 400 Bad Request |
735 | ... |
736 | copyright_date: Time not in UTC. |
737 | |
738 | There are five ways to specify UTC: |
739 | |
740 | - >>> print(patch_greens_copyright_date(u'2003-01-01T00:00:00.000000Z')) |
741 | + >>> print(patch_greens_copyright_date('2003-01-01T00:00:00.000000Z')) |
742 | HTTP/1.1 209 Content Returned |
743 | ... |
744 | |
745 | - >>> print(patch_greens_copyright_date(u'2003-01-01T00:00:00.000000+00:00')) |
746 | + >>> print(patch_greens_copyright_date('2003-01-01T00:00:00.000000+00:00')) |
747 | HTTP/1.1 209 Content Returned |
748 | ... |
749 | |
750 | - >>> print(patch_greens_copyright_date(u'2003-01-01T00:00:00.000000+0000')) |
751 | + >>> print(patch_greens_copyright_date('2003-01-01T00:00:00.000000+0000')) |
752 | HTTP/1.1 209 Content Returned |
753 | ... |
754 | |
755 | - >>> print(patch_greens_copyright_date(u'2003-01-01T00:00:00.000000-00:00')) |
756 | + >>> print(patch_greens_copyright_date('2003-01-01T00:00:00.000000-00:00')) |
757 | HTTP/1.1 209 Content Returned |
758 | ... |
759 | |
760 | - >>> print(patch_greens_copyright_date(u'2003-01-01T00:00:00.000000-0000')) |
761 | + >>> print(patch_greens_copyright_date('2003-01-01T00:00:00.000000-0000')) |
762 | HTTP/1.1 209 Content Returned |
763 | ... |
764 | |
765 | A value with a missing timezone is treated as UTC. |
766 | |
767 | - >>> print(patch_greens_copyright_date(u'2003-01-01T00:00:00.000000')) |
768 | + >>> print(patch_greens_copyright_date('2003-01-01T00:00:00.000000')) |
769 | HTTP/1.1 209 Content Returned |
770 | ... |
771 | |
772 | Less precise time measurements may also be acceptable. |
773 | |
774 | - >>> print(patch_greens_copyright_date(u'2003-01-01T00:00:00Z')) |
775 | + >>> print(patch_greens_copyright_date('2003-01-01T00:00:00Z')) |
776 | HTTP/1.1 209 Content Returned |
777 | ... |
778 | |
779 | - >>> print(patch_greens_copyright_date(u'2003-01-01')) |
780 | + >>> print(patch_greens_copyright_date('2003-01-01')) |
781 | HTTP/1.1 209 Content Returned |
782 | ... |
783 | |
784 | @@ -942,7 +942,7 @@ An entry's read-only attributes can't be modified. |
785 | |
786 | >>> print(modify_cookbook( |
787 | ... 'Everyday Greens', |
788 | - ... {'copyright_date' : u'2001-01-01T01:01:01+00:00Z'}, 'PATCH')) |
789 | + ... {'copyright_date' : '2001-01-01T01:01:01+00:00Z'}, 'PATCH')) |
790 | HTTP/1.1 400 Bad Request |
791 | ... |
792 | copyright_date: You tried to modify a read-only attribute. |
793 | diff --git a/src/lazr/restful/example/base/tests/field.txt b/src/lazr/restful/example/base/tests/field.txt |
794 | index a1e51c7..0f6951f 100644 |
795 | --- a/src/lazr/restful/example/base/tests/field.txt |
796 | +++ b/src/lazr/restful/example/base/tests/field.txt |
797 | @@ -410,7 +410,7 @@ a view on ICookbook called "description". |
798 | ... def fake_renderer(context, field, request): |
799 | ... """Bold the original string, add a snowman, and encode UTF-8.""" |
800 | ... def render(value): |
801 | - ... return (u"\N{SNOWMAN} <b>%s</b>" % value).encode("utf-8") |
802 | + ... return ("\N{SNOWMAN} <b>%s</b>" % value).encode() |
803 | ... return render |
804 | >>> manager.registerAdapter(fake_renderer, name='description') |
805 | |
806 | diff --git a/src/lazr/restful/marshallers.py b/src/lazr/restful/marshallers.py |
807 | index 20f6f9e..e8b38fe 100644 |
808 | --- a/src/lazr/restful/marshallers.py |
809 | +++ b/src/lazr/restful/marshallers.py |
810 | @@ -314,7 +314,7 @@ class BytesFieldMarshaller(SimpleFieldMarshaller): |
811 | value.seek(0) |
812 | value = value.read() |
813 | elif not isinstance(value, (bytes, str)): |
814 | - value = str(value).encode("UTF-8") |
815 | + value = str(value).encode() |
816 | else: |
817 | # Leave string conversion to _marshall_from_json_data. |
818 | pass |
819 | @@ -326,7 +326,7 @@ class BytesFieldMarshaller(SimpleFieldMarshaller): |
820 | Convert all strings to byte strings. |
821 | """ |
822 | if isinstance(value, str): |
823 | - value = value.encode("utf-8") |
824 | + value = value.encode() |
825 | return super()._marshall_from_json_data(value) |
826 | |
827 | |
828 | diff --git a/src/lazr/restful/simple.py b/src/lazr/restful/simple.py |
829 | index 3a2b271..fb85f40 100644 |
830 | --- a/src/lazr/restful/simple.py |
831 | +++ b/src/lazr/restful/simple.py |
832 | @@ -396,7 +396,7 @@ class MultiplePathPartAbsoluteURL: |
833 | "Expected an iterable of strings for __path_parts__." |
834 | ) |
835 | |
836 | - escaped_parts = [quote(part.encode("utf-8"), _safe) for part in parts] |
837 | + escaped_parts = [quote(part.encode(), _safe) for part in parts] |
838 | return start_url + "/" + "/".join(escaped_parts) |
839 | |
840 | __call__ = __str__ |
841 | diff --git a/src/lazr/restful/testing/webservice.py b/src/lazr/restful/testing/webservice.py |
842 | index 193ada8..97bbc11 100644 |
843 | --- a/src/lazr/restful/testing/webservice.py |
844 | +++ b/src/lazr/restful/testing/webservice.py |
845 | @@ -398,16 +398,16 @@ class WebServiceCaller: |
846 | def _writeHeaders(self, buf, headers): |
847 | """Write MIME headers to a file object.""" |
848 | for key, value in headers: |
849 | - buf.write(key.encode("UTF-8")) |
850 | + buf.write(key.encode()) |
851 | buf.write(b": ") |
852 | - buf.write(value.encode("UTF-8")) |
853 | + buf.write(value.encode()) |
854 | buf.write(b"\r\n") |
855 | buf.write(b"\r\n") |
856 | |
857 | def _writeBoundary(self, buf, boundary, closing=False): |
858 | """Write a multipart boundary to a file object.""" |
859 | buf.write(b"--") |
860 | - buf.write(boundary.encode("UTF-8")) |
861 | + buf.write(boundary.encode()) |
862 | if closing: |
863 | buf.write(b"--") |
864 | buf.write(b"\r\n") |
865 | diff --git a/src/lazr/restful/tests/test_webservice.py b/src/lazr/restful/tests/test_webservice.py |
866 | index e8c8010..b762b2c 100644 |
867 | --- a/src/lazr/restful/tests/test_webservice.py |
868 | +++ b/src/lazr/restful/tests/test_webservice.py |
869 | @@ -540,7 +540,7 @@ class HTMLRepresentationTest(EntryTestCase): |
870 | super().setUp() |
871 | self._register_url_adapter(IHasOneField) |
872 | self.unicode_message = "Hello from a \N{SNOWMAN}" |
873 | - self.utf8_message = self.unicode_message.encode("utf-8") |
874 | + self.utf8_message = self.unicode_message.encode() |
875 | |
876 | def test_entry_html_representation_is_utf8(self): |
877 | with self.entry_resource( |