Merge ~cjwatson/lazr.restful:remove-six into lazr.restful:main
- Git
- lp:~cjwatson/lazr.restful
- remove-six
- Merge into main
Status: | Merged |
---|---|
Merged at revision: | 6614e9088b62aca53bfb52ca13259dd34529492a |
Proposed branch: | ~cjwatson/lazr.restful:remove-six |
Merge into: | lazr.restful:main |
Diff against target: |
242 lines (+26/-29) 8 files modified
setup.py (+0/-1) src/lazr/restful/debug.py (+1/-2) src/lazr/restful/declarations.py (+1/-2) src/lazr/restful/docs/webservice.rst (+14/-10) src/lazr/restful/example/base/tests/collection.txt (+1/-3) src/lazr/restful/example/base/tests/entry.txt (+1/-3) src/lazr/restful/testing/helpers.py (+1/-2) src/lazr/restful/testing/webservice.py (+7/-6) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jürgen Gmach | Approve | ||
Review via email: mp+414022@code.launchpad.net |
Commit message
Remove remaining uses of six
Description of the change
Jürgen Gmach (jugmac00) wrote : | # |
Colin Watson (cjwatson) wrote : | # |
All but one of the `six.ensure_*` calls that I removed are themselves in test code, so it's fairly easy to see that they're covered. The one exception is in `lazr.restful.
Coverage seems to work fine for me, but declaring `coverage:run` would help so that it doesn't try to consider coverage of all dependencies as well. I'll propose a separate branch to set up coverage.
Jürgen Gmach (jugmac00) wrote : | # |
Would you please rebase this MP on current main so includes the coverage env?
Colin Watson (cjwatson) wrote : | # |
Done.
Jürgen Gmach (jugmac00) : | # |
Colin Watson (cjwatson) : | # |
Preview Diff
1 | diff --git a/setup.py b/setup.py | |||
2 | index 1017963..c21f37a 100755 | |||
3 | --- a/setup.py | |||
4 | +++ b/setup.py | |||
5 | @@ -62,7 +62,6 @@ setup( | |||
6 | 62 | "pytz", | 62 | "pytz", |
7 | 63 | "setuptools", | 63 | "setuptools", |
8 | 64 | "simplejson>=2.1.0", | 64 | "simplejson>=2.1.0", |
9 | 65 | "six>=1.13.0", | ||
10 | 66 | "testtools", | 65 | "testtools", |
11 | 67 | "van.testing", | 66 | "van.testing", |
12 | 68 | "zope.component [zcml]", | 67 | "zope.component [zcml]", |
13 | diff --git a/src/lazr/restful/debug.py b/src/lazr/restful/debug.py | |||
14 | index ebcf526..3dfb865 100644 | |||
15 | --- a/src/lazr/restful/debug.py | |||
16 | +++ b/src/lazr/restful/debug.py | |||
17 | @@ -4,10 +4,9 @@ | |||
18 | 4 | 4 | ||
19 | 5 | __all__ = ["debug_proxy", "typename"] | 5 | __all__ = ["debug_proxy", "typename"] |
20 | 6 | 6 | ||
21 | 7 | from io import StringIO | ||
22 | 7 | 8 | ||
23 | 8 | from six import StringIO | ||
24 | 9 | import zope.proxy | 9 | import zope.proxy |
25 | 10 | |||
26 | 11 | from zope.security.checker import getChecker, Checker, CheckerPublic, Proxy | 10 | from zope.security.checker import getChecker, Checker, CheckerPublic, Proxy |
27 | 12 | 11 | ||
28 | 13 | 12 | ||
29 | diff --git a/src/lazr/restful/declarations.py b/src/lazr/restful/declarations.py | |||
30 | index 0fca6c1..ecfcc00 100644 | |||
31 | --- a/src/lazr/restful/declarations.py | |||
32 | +++ b/src/lazr/restful/declarations.py | |||
33 | @@ -44,7 +44,6 @@ import copy | |||
34 | 44 | import itertools | 44 | import itertools |
35 | 45 | import sys | 45 | import sys |
36 | 46 | 46 | ||
37 | 47 | import six | ||
38 | 48 | from zope.component import getUtility, getGlobalSiteManager | 47 | from zope.component import getUtility, getGlobalSiteManager |
39 | 49 | from zope.interface import classImplements | 48 | from zope.interface import classImplements |
40 | 50 | from zope.interface.interface import fromFunction, InterfaceClass, TAGGED_DATA | 49 | from zope.interface.interface import fromFunction, InterfaceClass, TAGGED_DATA |
41 | @@ -1943,5 +1942,5 @@ def _versioned_class_name(base_name, version): | |||
42 | 1943 | # runtime. Use a generic string that won't conflict with a | 1942 | # runtime. Use a generic string that won't conflict with a |
43 | 1944 | # real version string. | 1943 | # real version string. |
44 | 1945 | version = "__Earliest" | 1944 | version = "__Earliest" |
46 | 1946 | name = "%s_%s" % (base_name, six.ensure_str(version)) | 1945 | name = "%s_%s" % (base_name, version) |
47 | 1947 | return make_identifier_safe(name) | 1946 | return make_identifier_safe(name) |
48 | diff --git a/src/lazr/restful/docs/webservice.rst b/src/lazr/restful/docs/webservice.rst | |||
49 | index 411d9e8..d10d4a3 100644 | |||
50 | --- a/src/lazr/restful/docs/webservice.rst | |||
51 | +++ b/src/lazr/restful/docs/webservice.rst | |||
52 | @@ -1088,9 +1088,8 @@ top-level collections of authors, cookbooks, and dishes. It's the | |||
53 | 1088 | 'home page' for the web service. | 1088 | 'home page' for the web service. |
54 | 1089 | 1089 | ||
55 | 1090 | >>> import simplejson | 1090 | >>> import simplejson |
56 | 1091 | >>> import six | ||
57 | 1092 | >>> response = app(request) | 1091 | >>> response = app(request) |
59 | 1093 | >>> representation = simplejson.loads(six.ensure_text(response)) | 1092 | >>> representation = simplejson.loads(response) |
60 | 1094 | 1093 | ||
61 | 1095 | >>> print(representation["authors_collection_link"]) | 1094 | >>> print(representation["authors_collection_link"]) |
62 | 1096 | http://api.cookbooks.dev/beta/authors | 1095 | http://api.cookbooks.dev/beta/authors |
63 | @@ -1165,7 +1164,7 @@ parsed with standard tools. | |||
64 | 1165 | 1164 | ||
65 | 1166 | >>> def load_json(s): | 1165 | >>> def load_json(s): |
66 | 1167 | ... """Convert a JSON string to Unicode and then load it.""" | 1166 | ... """Convert a JSON string to Unicode and then load it.""" |
68 | 1168 | ... return simplejson.loads(six.ensure_text(s)) | 1167 | ... return simplejson.loads(s) |
69 | 1169 | 1168 | ||
70 | 1170 | >>> representation = load_json(collection()) | 1169 | >>> representation = load_json(collection()) |
71 | 1171 | >>> print(representation['resource_type_link']) | 1170 | >>> print(representation['resource_type_link']) |
72 | @@ -1678,7 +1677,9 @@ easily accessible data structure. | |||
73 | 1678 | ... headers['HTTP_IF_NONE_MATCH'] = etag | 1677 | ... headers['HTTP_IF_NONE_MATCH'] = etag |
74 | 1679 | ... get_request = create_web_service_request( | 1678 | ... get_request = create_web_service_request( |
75 | 1680 | ... julia_url, environ=headers) | 1679 | ... julia_url, environ=headers) |
77 | 1681 | ... entity_body = six.ensure_text(get_request.traverse(app)()) | 1680 | ... entity_body = get_request.traverse(app)() |
78 | 1681 | ... if isinstance(entity_body, bytes): | ||
79 | 1682 | ... entity_body = entity_body.decode() | ||
80 | 1682 | ... return dict(entity_body=entity_body, | 1683 | ... return dict(entity_body=entity_body, |
81 | 1683 | ... response=get_request.response) | 1684 | ... response=get_request.response) |
82 | 1684 | 1685 | ||
83 | @@ -1820,7 +1821,7 @@ set the field value to 'tag:launchpad.net:2008:redacted'. | |||
84 | 1820 | >>> body = simplejson.dumps(author).encode() | 1821 | >>> body = simplejson.dumps(author).encode() |
85 | 1821 | >>> put_request = create_web_service_request( | 1822 | >>> put_request = create_web_service_request( |
86 | 1822 | ... beard_url, body=body, environ=headers, method='PUT') | 1823 | ... beard_url, body=body, environ=headers, method='PUT') |
88 | 1823 | >>> print(six.ensure_text(put_request.traverse(app)())) | 1824 | >>> print(put_request.traverse(app)().decode()) |
89 | 1824 | {...} | 1825 | {...} |
90 | 1825 | 1826 | ||
91 | 1826 | And since no special permission is necessary to _change_ a person's | 1827 | And since no special permission is necessary to _change_ a person's |
92 | @@ -1833,7 +1834,7 @@ PUT, even when its current value is redacted. | |||
93 | 1833 | >>> body = simplejson.dumps(author).encode() | 1834 | >>> body = simplejson.dumps(author).encode() |
94 | 1834 | >>> put_request = create_web_service_request( | 1835 | >>> put_request = create_web_service_request( |
95 | 1835 | ... beard_url, body=body, environ=headers, method='PUT') | 1836 | ... beard_url, body=body, environ=headers, method='PUT') |
97 | 1836 | >>> print(six.ensure_text(put_request.traverse(app)())) | 1837 | >>> print(put_request.traverse(app)().decode()) |
98 | 1837 | {...} | 1838 | {...} |
99 | 1838 | 1839 | ||
100 | 1839 | After that PUT, James Beard's 'favorite_recipe' attribute is no longer | 1840 | After that PUT, James Beard's 'favorite_recipe' attribute is no longer |
101 | @@ -1897,7 +1898,7 @@ A cookbook can be given a cover with PUT. | |||
102 | 1897 | >>> file_resource = put_request.traverse(app) | 1898 | >>> file_resource = put_request.traverse(app) |
103 | 1898 | >>> file_resource() | 1899 | >>> file_resource() |
104 | 1899 | 1900 | ||
106 | 1900 | >>> print(six.ensure_str(C2.cover.representation)) | 1901 | >>> print(C2.cover.representation.decode()) |
107 | 1901 | Pretend... | 1902 | Pretend... |
108 | 1902 | 1903 | ||
109 | 1903 | At this point it exists: | 1904 | At this point it exists: |
110 | @@ -1934,7 +1935,7 @@ An entry's primitive data fields are exposed as subordinate resources. | |||
111 | 1934 | 1935 | ||
112 | 1935 | >>> field_resource = create_web_service_request( | 1936 | >>> field_resource = create_web_service_request( |
113 | 1936 | ... '/beta/cookbooks/The%20Joy%20of%20Cooking/name').traverse(app) | 1937 | ... '/beta/cookbooks/The%20Joy%20of%20Cooking/name').traverse(app) |
115 | 1937 | >>> print(six.ensure_text(field_resource())) | 1938 | >>> print(field_resource().decode()) |
116 | 1938 | "The Joy of Cooking" | 1939 | "The Joy of Cooking" |
117 | 1939 | 1940 | ||
118 | 1940 | Requesting non available resources | 1941 | Requesting non available resources |
119 | @@ -2059,7 +2060,10 @@ their URLs, we make the change by modifying the cookbook's | |||
120 | 2059 | ... '/beta/cookbooks/The%20Joy%20of%20Cooking', | 2060 | ... '/beta/cookbooks/The%20Joy%20of%20Cooking', |
121 | 2060 | ... body=simplejson.dumps(representation).encode(), | 2061 | ... body=simplejson.dumps(representation).encode(), |
122 | 2061 | ... environ=headers, method='PATCH', hostname=host).traverse(app) | 2062 | ... environ=headers, method='PATCH', hostname=host).traverse(app) |
124 | 2062 | ... return six.ensure_text(resource()) | 2063 | ... result = resource() |
125 | 2064 | ... if isinstance(result, bytes): | ||
126 | 2065 | ... result = result.decode() | ||
127 | 2066 | ... return result | ||
128 | 2063 | >>> path = '/beta/authors/Julia%20Child' | 2067 | >>> path = '/beta/authors/Julia%20Child' |
129 | 2064 | 2068 | ||
130 | 2065 | >>> print(change_joy_author('http://api.cookbooks.dev' + path)) | 2069 | >>> print(change_joy_author('http://api.cookbooks.dev' + path)) |
131 | @@ -2122,7 +2126,7 @@ Now you see it... | |||
132 | 2122 | 2126 | ||
133 | 2123 | >>> resource = create_web_service_request( | 2127 | >>> resource = create_web_service_request( |
134 | 2124 | ... recipe_url, method='GET').traverse(app) | 2128 | ... recipe_url, method='GET').traverse(app) |
136 | 2125 | >>> print(six.ensure_text(resource())) | 2129 | >>> print(resource().decode()) |
137 | 2126 | {...} | 2130 | {...} |
138 | 2127 | 2131 | ||
139 | 2128 | >>> resource = create_web_service_request( | 2132 | >>> resource = create_web_service_request( |
140 | diff --git a/src/lazr/restful/example/base/tests/collection.txt b/src/lazr/restful/example/base/tests/collection.txt | |||
141 | index e156a43..44065aa 100644 | |||
142 | --- a/src/lazr/restful/example/base/tests/collection.txt | |||
143 | +++ b/src/lazr/restful/example/base/tests/collection.txt | |||
144 | @@ -325,8 +325,6 @@ POST operations may involve text fields. These are marshalled via a | |||
145 | 325 | multipart/form-data request, which requires line breaks to be represented as | 325 | multipart/form-data request, which requires line breaks to be represented as |
146 | 326 | CRLF. The server turns these into Unix-style LF. | 326 | CRLF. The server turns these into Unix-style LF. |
147 | 327 | 327 | ||
148 | 328 | >>> import six | ||
149 | 329 | |||
150 | 330 | >>> def create_recipe(id, cookbook_link, dish_link, instructions, | 328 | >>> def create_recipe(id, cookbook_link, dish_link, instructions, |
151 | 331 | ... private=False): | 329 | ... private=False): |
152 | 332 | ... return webservice.named_post( | 330 | ... return webservice.named_post( |
153 | @@ -344,6 +342,6 @@ CRLF. The server turns these into Unix-style LF. | |||
154 | 344 | >>> response.status | 342 | >>> response.status |
155 | 345 | 201 | 343 | 201 |
156 | 346 | >>> recipe = webservice.get(response.getHeader("Location")).jsonBody() | 344 | >>> recipe = webservice.get(response.getHeader("Location")).jsonBody() |
158 | 347 | >>> six.ensure_str(recipe["instructions"]) | 345 | >>> recipe["instructions"] |
159 | 348 | 'Recipe\ncontaining\nsome\nline\n\nbreaks' | 346 | 'Recipe\ncontaining\nsome\nline\n\nbreaks' |
160 | 349 | >>> _ = webservice.delete(recipe["self_link"]) | 347 | >>> _ = webservice.delete(recipe["self_link"]) |
161 | diff --git a/src/lazr/restful/example/base/tests/entry.txt b/src/lazr/restful/example/base/tests/entry.txt | |||
162 | index f24c7a3..decab39 100644 | |||
163 | --- a/src/lazr/restful/example/base/tests/entry.txt | |||
164 | +++ b/src/lazr/restful/example/base/tests/entry.txt | |||
165 | @@ -118,9 +118,7 @@ a simple definition list. | |||
166 | 118 | Getting the XHTML representation works correctly even when some of the fields | 118 | Getting the XHTML representation works correctly even when some of the fields |
167 | 119 | have non-ascii values. | 119 | have non-ascii values. |
168 | 120 | 120 | ||
172 | 121 | >>> import six | 121 | >>> print(str(webservice.get(construsions_url, 'application/xhtml+xml'))) |
170 | 122 | >>> print(six.text_type( | ||
171 | 123 | ... webservice.get(construsions_url, 'application/xhtml+xml'))) | ||
173 | 124 | HTTP/1.1 200 Ok | 122 | HTTP/1.1 200 Ok |
174 | 125 | ... | 123 | ... |
175 | 126 | <dl ...> | 124 | <dl ...> |
176 | diff --git a/src/lazr/restful/testing/helpers.py b/src/lazr/restful/testing/helpers.py | |||
177 | index c0dd63c..bfd8685 100644 | |||
178 | --- a/src/lazr/restful/testing/helpers.py | |||
179 | +++ b/src/lazr/restful/testing/helpers.py | |||
180 | @@ -1,7 +1,6 @@ | |||
181 | 1 | import sys | 1 | import sys |
182 | 2 | from types import ModuleType | 2 | from types import ModuleType |
183 | 3 | 3 | ||
184 | 4 | import six | ||
185 | 5 | from zope.configuration import xmlconfig | 4 | from zope.configuration import xmlconfig |
186 | 6 | from zope.interface import implementer | 5 | from zope.interface import implementer |
187 | 7 | 6 | ||
188 | @@ -63,7 +62,7 @@ def encode_unicode(unicode_string): | |||
189 | 63 | 62 | ||
190 | 64 | :param unicode_string: A Unicode string. | 63 | :param unicode_string: A Unicode string. |
191 | 65 | """ | 64 | """ |
193 | 66 | return six.ensure_str(unicode_string.encode("ascii", "backslashreplace")) | 65 | return unicode_string.encode("ascii", "backslashreplace").decode() |
194 | 67 | 66 | ||
195 | 68 | 67 | ||
196 | 69 | @implementer(IWebServiceConfiguration) | 68 | @implementer(IWebServiceConfiguration) |
197 | diff --git a/src/lazr/restful/testing/webservice.py b/src/lazr/restful/testing/webservice.py | |||
198 | index 97bbc11..af7496b 100644 | |||
199 | --- a/src/lazr/restful/testing/webservice.py | |||
200 | +++ b/src/lazr/restful/testing/webservice.py | |||
201 | @@ -34,7 +34,6 @@ from urllib.parse import ( | |||
202 | 34 | 34 | ||
203 | 35 | import wsgi_intercept | 35 | import wsgi_intercept |
204 | 36 | 36 | ||
205 | 37 | import six | ||
206 | 38 | from zope.component import adapter, getGlobalSiteManager, getUtility | 37 | from zope.component import adapter, getGlobalSiteManager, getUtility |
207 | 39 | from zope.configuration import xmlconfig | 38 | from zope.configuration import xmlconfig |
208 | 40 | from zope.interface import alsoProvides, implementer, Interface | 39 | from zope.interface import alsoProvides, implementer, Interface |
209 | @@ -316,8 +315,8 @@ class WebServiceCaller: | |||
210 | 316 | headers=None, | 315 | headers=None, |
211 | 317 | api_version=None, | 316 | api_version=None, |
212 | 318 | ): | 317 | ): |
215 | 319 | if isinstance(path_or_url, (bytes, str)): | 318 | if isinstance(path_or_url, bytes): |
216 | 320 | path_or_url = six.ensure_str(path_or_url) | 319 | path_or_url = path_or_url.decode() |
217 | 321 | else: | 320 | else: |
218 | 322 | path_or_url = str(path_or_url) | 321 | path_or_url = str(path_or_url) |
219 | 323 | if path_or_url.startswith("/"): | 322 | if path_or_url.startswith("/"): |
220 | @@ -459,9 +458,9 @@ class WebServiceCaller: | |||
221 | 459 | value = simplejson.dumps(value) | 458 | value = simplejson.dumps(value) |
222 | 460 | lines = re.split(r"\r\n|\r|\n", value) | 459 | lines = re.split(r"\r\n|\r|\n", value) |
223 | 461 | for line in lines[:-1]: | 460 | for line in lines[:-1]: |
225 | 462 | buf.write(six.ensure_binary(line)) | 461 | buf.write(line.encode()) |
226 | 463 | buf.write(b"\r\n") | 462 | buf.write(b"\r\n") |
228 | 464 | buf.write(six.ensure_binary(lines[-1])) | 463 | buf.write(lines[-1].encode()) |
229 | 465 | encoded_parts.append(buf.getvalue()) | 464 | encoded_parts.append(buf.getvalue()) |
230 | 466 | 465 | ||
231 | 467 | # Create a suitable boundary. | 466 | # Create a suitable boundary. |
232 | @@ -580,7 +579,9 @@ class WebServiceResponseWrapper(ProxyBase): | |||
233 | 580 | 579 | ||
234 | 581 | def jsonBody(self): | 580 | def jsonBody(self): |
235 | 582 | """Return the body of the web service request as a JSON document.""" | 581 | """Return the body of the web service request as a JSON document.""" |
237 | 583 | body = six.ensure_text(self.body) | 582 | body = self.body |
238 | 583 | if isinstance(body, bytes): | ||
239 | 584 | body = body.decode() | ||
240 | 584 | try: | 585 | try: |
241 | 585 | return simplejson.loads(body, object_pairs_hook=OrderedDict) | 586 | return simplejson.loads(body, object_pairs_hook=OrderedDict) |
242 | 586 | except ValueError: | 587 | except ValueError: |
It is a bit unfortunate that we do not run coverage for this project (and all projects).
Some occurrences of `six.ensure_str` were just removed, some were replaced by xxx.decode().
I cannot say whether this is correct or not.
I quickly tried to setup coverage for the review, the tests ran, but got a "no data collected" error :-/
```
[testenv]
deps =
.[test,xml]
zope.testrunner
coverage
commands =
coverage run -m zope.testrunner --test-path src --tests-pattern ^tests {posargs}
coverage report -m
```
I have no clue what is going wrong here.