Merge lp:~jderose/microfiber/python3 into lp:microfiber
- python3
- Merge into trunk
Proposed by
Jason Gerard DeRose
Status: | Merged |
---|---|
Merged at revision: | 83 |
Proposed branch: | lp:~jderose/microfiber/python3 |
Merge into: | lp:microfiber |
Diff against target: |
377 lines (+41/-165) 5 files modified
debian/control (+3/-14) debian/rules (+1/-7) microfiber.py (+29/-115) setup.py (+2/-6) test_microfiber.py (+6/-23) |
To merge this branch: | bzr merge lp:~jderose/microfiber/python3 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Jordan | Approve | ||
Review via email:
|
Commit message
Description of the change
Okay, Python2 support dropped.
I didn't realize this, but unlike 2to3, 3to2 isn't included with Python itself, isn't packaged in Debian/Ubuntu. So that's a no-go in my book. Microfiber 11.09 is a perfectly good release with Python2 support that we can use to cover our limited remaining Python2 needs.
Viva la Python3!
:^)
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jason Gerard DeRose (jderose) wrote : | # |
As always, thanks for the review, David! :^)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'debian/control' |
2 | --- debian/control 2011-09-02 08:22:33 +0000 |
3 | +++ debian/control 2011-09-30 06:51:26 +0000 |
4 | @@ -2,9 +2,9 @@ |
5 | Section: python |
6 | Priority: optional |
7 | Maintainer: Jason Gerard DeRose <jderose@novacut.com> |
8 | -Build-Depends: debhelper (>= 8.1), python3 (>= 3.2), python (>= 2.7), python-sphinx |
9 | -Standards-Version: 3.9.1 |
10 | -X-Python-Version: 2.7 |
11 | +Build-Depends: debhelper (>= 8.9), python3 (>= 3.2), python-sphinx |
12 | +Standards-Version: 3.9.2 |
13 | +X-Python-Version: 3.2 |
14 | X-Python3-Version: 3.2 |
15 | Homepage: https://launchpad.net/microfiber |
16 | |
17 | @@ -19,17 +19,6 @@ |
18 | very simple and basically maintenance free as it requires no changes to support |
19 | new additions to the CouchDB API. |
20 | |
21 | -Package: python-microfiber |
22 | -Architecture: all |
23 | -Depends: ${misc:Depends}, python (>= 2.7) |
24 | -Description: fabric for a lightweight Couch |
25 | - microfiber is an abstract adapter for making HTTP requests to an arbitrary JSON |
26 | - loving REST API like CouchDB. Rather than wrapping the API in a bunch of |
27 | - one-off methods, microfiber just makes it super easy to call any part of the |
28 | - CouchDB REST API, current or future. This approach allows microfiber to be |
29 | - very simple and basically maintenance free as it requires no changes to support |
30 | - new additions to the CouchDB API. |
31 | - |
32 | Package: python3-microfiber-doc |
33 | Architecture: all |
34 | Section: doc |
35 | |
36 | === removed file 'debian/python-microfiber.install' |
37 | === modified file 'debian/rules' |
38 | --- debian/rules 2011-08-24 05:53:20 +0000 |
39 | +++ debian/rules 2011-09-30 06:51:26 +0000 |
40 | @@ -3,11 +3,10 @@ |
41 | PYTHON3=$(shell py3versions -vr) |
42 | |
43 | %: |
44 | - dh $@ --with=python3 --with=python2 |
45 | + dh $@ --with=python3 |
46 | |
47 | test-python%: |
48 | python$* setup.py test -vv |
49 | - python2.7 setup.py test -vv |
50 | |
51 | override_dh_auto_install: |
52 | for pyvers in $(shell py3versions -vr); do \ |
53 | @@ -15,10 +14,5 @@ |
54 | --install-layout=deb \ |
55 | --root $(CURDIR)/debian/python3-microfiber; \ |
56 | done |
57 | - for pyvers in $(shell pyversions -vr); do \ |
58 | - python$$pyvers setup.py install \ |
59 | - --install-layout=deb \ |
60 | - --root $(CURDIR)/debian/python-microfiber; \ |
61 | - done |
62 | |
63 | override_dh_auto_test: $(PYTHON3:%=test-python%) |
64 | |
65 | === modified file 'microfiber.py' |
66 | --- microfiber.py 2011-09-30 02:15:11 +0000 |
67 | +++ microfiber.py 2011-09-30 06:51:26 +0000 |
68 | @@ -22,84 +22,22 @@ |
69 | """ |
70 | `microfiber` - fabric for a lightweight Couch. |
71 | |
72 | -microfiber is an abstract adapter for making HTTP requests to an arbitrary JSON |
73 | +Microfiber is an generic adapter for making HTTP requests to an arbitrary JSON |
74 | loving REST API like CouchDB. Rather than wrapping the API in a bunch of |
75 | -one-off methods, microfiber just makes it super easy to call any part of the |
76 | -CouchDB REST API, current or future. This approach allows microfiber to be very |
77 | +one-off methods, Microfiber just makes it super easy to call any part of the |
78 | +CouchDB REST API, current or future. This approach allows Microfiber to be very |
79 | simple and basically maintenance free as it requires no changes to support new |
80 | additions to the CouchDB API. |
81 | |
82 | -For example, with python-couchdb you compact the database like this: |
83 | - |
84 | ->>> database.compact() #doctest: +SKIP |
85 | - |
86 | - |
87 | -With microfiber, you can accomplish the same thing one of two ways: |
88 | - |
89 | ->>> database.post(None, '_compact') #doctest: +SKIP |
90 | ->>> server.post(None, 'mydb', '_compact') #doctest: +SKIP |
91 | - |
92 | - |
93 | -Depending on your situation, python-couchdb may still be a better fit, so to |
94 | -each their own. If you're new to CouchDB, you will probably find it much easier |
95 | -to get started with python-couchdb. Likewise, if you're coming from the SQL |
96 | -world and like an ORM-style API, you will probably feel more at home with |
97 | -python-couchdb. |
98 | - |
99 | -However, if you know the CouchDB REST API or want to learn it, you will find |
100 | -microfiber a more harmonious experience. Also, microfiber is *very* lightweight |
101 | -(1 Python file), fast, and memory efficient. Unlike python-couchdb, microfiber |
102 | -doesn't use any wrappers around the results returned from CouchDB, so it's less |
103 | -prone to high memory usage and memory fragmentation problems in, say, a long |
104 | -running server process. |
105 | - |
106 | -Long story short, the microfiber API is the CouchDB REST API, and nothing more. |
107 | -For example: |
108 | - |
109 | ->>> from microfiber import Server |
110 | ->>> s = Server() |
111 | ->>> s |
112 | -Server('http://localhost:5984/') |
113 | - |
114 | - |
115 | -Create a database: |
116 | - |
117 | ->>> s.put(None, 'mydb') #doctest: +SKIP |
118 | -{'ok': True} |
119 | - |
120 | - |
121 | -Create a doc: |
122 | - |
123 | ->>> s.post({'_id': 'foo'}, 'mydb') #doctest: +SKIP |
124 | -{'rev': '1-967a00dff5e02add41819138abb3284d', 'ok': True, 'id': 'foo'} |
125 | - |
126 | - |
127 | -Also create a doc: |
128 | - |
129 | ->>> s.put({}, 'mydb', 'bar') #doctest: +SKIP |
130 | -{'rev': '1-967a00dff5e02add41819138abb3284d', 'ok': True, 'id': 'bar'} |
131 | - |
132 | - |
133 | -Upload attachment: |
134 | - |
135 | ->>> s.put_att('image/png', b'da picture', 'mydb', 'baz', 'pic') #doctest: +SKIP |
136 | -{'rev': '1-7c17d20f43962e360062659b4bcd8aea', 'ok': True, 'id': 'baz'} |
137 | - |
138 | - |
139 | -For CouchDB API documentation, see: |
140 | - |
141 | - http://techzone.couchbase.com/sites/default/files/uploads/all/documentation/couchbase-api.html |
142 | - |
143 | -For python-couchdb documentation, see: |
144 | - |
145 | - http://packages.python.org/CouchDB/ |
146 | +Documentation: |
147 | + |
148 | + http://docs.novacut.com/microfiber/index.html |
149 | + |
150 | +Launchpad project: |
151 | + |
152 | + https://launchpad.net/microfiber |
153 | """ |
154 | |
155 | -# FIXME: There is some rather hacky crap in here to support both Python2 and |
156 | -# Python3... but once we migrate dmedia to Python3, we'll drop Python2 support |
157 | -# in microfiber and clean this up a bit. |
158 | - |
159 | -import sys |
160 | from os import urandom |
161 | import io |
162 | from base64 import b32encode, b64encode |
163 | @@ -107,16 +45,8 @@ |
164 | import time |
165 | from hashlib import sha1 |
166 | import hmac |
167 | -import subprocess |
168 | -if sys.version_info >= (3, 0): |
169 | - from urllib.parse import urlparse, urlencode, quote_plus |
170 | - from http.client import HTTPConnection, HTTPSConnection, BadStatusLine |
171 | - strtype = str |
172 | -else: |
173 | - from urlparse import urlparse |
174 | - from urllib import urlencode, quote_plus |
175 | - from httplib import HTTPConnection, HTTPSConnection, BadStatusLine |
176 | - strtype = basestring |
177 | +from urllib.parse import urlparse, urlencode, quote_plus |
178 | +from http.client import HTTPConnection, HTTPSConnection, BadStatusLine |
179 | |
180 | |
181 | __all__ = ( |
182 | @@ -182,32 +112,18 @@ |
183 | ]) |
184 | |
185 | |
186 | -if sys.version_info >= (3, 0): |
187 | - def dc3_env(): |
188 | - env_s = subprocess.check_output(DC3_CMD) |
189 | - return loads(env_s.decode('utf-8')) |
190 | -else: |
191 | - def dc3_env(): |
192 | - env_s = subprocess.check_output(DC3_CMD) |
193 | - env = loads(env_s) |
194 | - env['url'] = env['url'].encode('utf-8') |
195 | - return env |
196 | - |
197 | - |
198 | -if sys.version_info >= (3, 0): |
199 | - def _json_body(obj): |
200 | - if obj is None: |
201 | - return None |
202 | - if isinstance(obj, (bytes, io.BufferedReader, io.BytesIO)): |
203 | - return obj |
204 | - return dumps(obj, sort_keys=True, separators=(',',':')).encode('utf-8') |
205 | -else: |
206 | - def _json_body(obj): |
207 | - if obj is None: |
208 | - return None |
209 | - if isinstance(obj, (file, io.BytesIO)): |
210 | - return obj |
211 | - return dumps(obj, sort_keys=True, separators=(',',':')).encode('utf-8') |
212 | +def dc3_env(): |
213 | + import subprocess |
214 | + env_s = subprocess.check_output(DC3_CMD) |
215 | + return loads(env_s.decode('utf-8')) |
216 | + |
217 | + |
218 | +def _json_body(obj): |
219 | + if obj is None: |
220 | + return None |
221 | + if isinstance(obj, (bytes, io.BufferedReader, io.BytesIO)): |
222 | + return obj |
223 | + return dumps(obj, sort_keys=True, separators=(',',':')).encode('utf-8') |
224 | |
225 | |
226 | def _queryiter(options): |
227 | @@ -219,7 +135,7 @@ |
228 | """ |
229 | for key in sorted(options): |
230 | value = options[key] |
231 | - if key in ('key', 'startkey', 'endkey') or not isinstance(value, strtype): |
232 | + if key in ('key', 'startkey', 'endkey') or not isinstance(value, str): |
233 | value = dumps(value) |
234 | yield (key, value) |
235 | |
236 | @@ -234,9 +150,7 @@ |
237 | oauth[k] for k in ('consumer_secret', 'token_secret') |
238 | ).encode('utf-8') |
239 | h = hmac.new(key, base_string.encode('utf-8'), sha1) |
240 | - if sys.version_info >= (3, 0): |
241 | - return b64encode(h.digest()).decode('utf-8') |
242 | - return b64encode(h.digest()) |
243 | + return b64encode(h.digest()).decode('utf-8') |
244 | |
245 | |
246 | def _oauth_header(oauth, method, baseurl, query, testing=None): |
247 | @@ -279,7 +193,7 @@ |
248 | self.data = data |
249 | self.method = method |
250 | self.url = url |
251 | - super(HTTPError, self).__init__() |
252 | + super().__init__() |
253 | |
254 | def __str__(self): |
255 | return '{} {}: {} {}'.format( |
256 | @@ -638,7 +552,7 @@ |
257 | """ |
258 | |
259 | def __init__(self, env=SERVER): |
260 | - super(Server, self).__init__(env) |
261 | + super().__init__(env) |
262 | |
263 | def __repr__(self): |
264 | return '{}({!r})'.format(self.__class__.__name__, self.url) |
265 | @@ -679,7 +593,7 @@ |
266 | * `Datebase.view(design, view, **options)` - shortcut method, that's all |
267 | """ |
268 | def __init__(self, name, env=SERVER): |
269 | - super(Database, self).__init__(env) |
270 | + super().__init__(env) |
271 | self.name = name |
272 | self.basepath += (name + '/') |
273 | |
274 | |
275 | === modified file 'setup.py' |
276 | --- setup.py 2011-09-30 02:15:11 +0000 |
277 | +++ setup.py 2011-09-30 06:51:26 +0000 |
278 | @@ -25,7 +25,6 @@ |
279 | Install `microfiber`. |
280 | """ |
281 | |
282 | -import sys |
283 | from distutils.core import setup |
284 | from distutils.cmd import Command |
285 | from distutils.command.build import build |
286 | @@ -34,10 +33,7 @@ |
287 | import os |
288 | from os import path |
289 | import subprocess |
290 | -if sys.version_info >= (3, 0): |
291 | - from urllib.parse import urlparse |
292 | -else: |
293 | - from urlparse import urlparse |
294 | +from urllib.parse import urlparse |
295 | |
296 | import microfiber |
297 | |
298 | @@ -111,7 +107,7 @@ |
299 | return None |
300 | |
301 | def run(self): |
302 | - build.run(self) |
303 | + super().run() |
304 | sphinx = self.find_sphinx_path() |
305 | if sphinx is None: |
306 | print("WARNING: Documentation not generated. python-sphinx missing") |
307 | |
308 | === modified file 'test_microfiber.py' |
309 | --- test_microfiber.py 2011-09-12 22:08:16 +0000 |
310 | +++ test_microfiber.py 2011-09-30 06:51:26 +0000 |
311 | @@ -23,11 +23,6 @@ |
312 | Unit tests for `microfiber` module. |
313 | """ |
314 | |
315 | -# FIXME: There is some rather hacky crap in here to support both Python2 and |
316 | -# Python3... but once we migrate dmedia to Python3, we'll drop Python2 support |
317 | -# in microfiber and clean this up a bit. |
318 | - |
319 | -import sys |
320 | from unittest import TestCase |
321 | import os |
322 | from os import path |
323 | @@ -40,16 +35,13 @@ |
324 | import tempfile |
325 | import shutil |
326 | from hashlib import md5 |
327 | -if sys.version_info >= (3, 0): |
328 | - from urllib.parse import urlparse, urlencode |
329 | - from http.client import HTTPConnection, HTTPSConnection |
330 | -else: |
331 | - from urlparse import urlparse |
332 | - from httplib import HTTPConnection, HTTPSConnection |
333 | +from urllib.parse import urlparse, urlencode |
334 | +from http.client import HTTPConnection, HTTPSConnection |
335 | |
336 | import microfiber |
337 | from microfiber import NotFound, MethodNotAllowed, Conflict, PreconditionFailed |
338 | |
339 | + |
340 | # OAuth test string from http://oauth.net/core/1.0a/#anchor46 |
341 | BASE_STRING = 'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal' |
342 | |
343 | @@ -68,10 +60,7 @@ |
344 | |
345 | def test_random_id(self): |
346 | _id = microfiber.random_id() |
347 | - if sys.version_info >= (3, 0): |
348 | - self.assertIsInstance(_id, str) |
349 | - else: |
350 | - self.assertIsInstance(_id, unicode) |
351 | + self.assertIsInstance(_id, str) |
352 | self.assertEqual(len(_id), 24) |
353 | b = b32decode(_id.encode('ascii')) |
354 | self.assertIsInstance(b, bytes) |
355 | @@ -79,10 +68,7 @@ |
356 | |
357 | def test_random_id2(self): |
358 | _id = microfiber.random_id2() |
359 | - if sys.version_info >= (3, 0): |
360 | - self.assertIsInstance(_id, str) |
361 | - else: |
362 | - self.assertIsInstance(_id, unicode) |
363 | + self.assertIsInstance(_id, str) |
364 | self.assertEqual(len(_id), 27) |
365 | (t, r) = _id.split('.') |
366 | self.assertEqual(len(t), 10) |
367 | @@ -139,10 +125,7 @@ |
368 | self.assertIs(microfiber._json_body(fp), fp) |
369 | finally: |
370 | shutil.rmtree(d) |
371 | - |
372 | - # FIXME: There is no way to do this correctly in Python2 |
373 | - if sys.version_info < (3, 0): |
374 | - return |
375 | + |
376 | # Test when obj is pre-encoded bytes |
377 | self.assertEqual(microfiber._json_body(json_bytes), json_bytes) |
378 |
Okay, seems like a good plan not to keep supporting a python2 version of Microfiber. Since DC3 doesn't need much of Microfiber, I'd say the bast option is to deprecate python2 for Microfiber and put what functionality is needed directly in DC3 rather than require a basically unmaintained package until the PyGI DBus issues are sorted out. Approved.