Merge lp:~jderose/microfiber/dbase32 into lp:microfiber

Proposed by Jason Gerard DeRose
Status: Merged
Merged at revision: 175
Proposed branch: lp:~jderose/microfiber/dbase32
Merge into: lp:microfiber
Diff against target: 256 lines (+28/-63)
7 files modified
debian/control (+5/-4)
debian/microfiber-crashdb.conf (+0/-4)
debian/python3-microfiber.install (+0/-1)
debian/source_microfiber.py (+4/-3)
microfiber.py (+4/-30)
setup.py (+2/-2)
test_microfiber.py (+13/-19)
To merge this branch: bzr merge lp:~jderose/microfiber/dbase32
Reviewer Review Type Date Requested Status
xzcvczx (community) Approve
microfiber dev Pending
Review via email: mp+147869@code.launchpad.net

Description of the change

For details, see this bug:

https://bugs.launchpad.net/microfiber/+bug/1122897

Changes include:

 * Replaces `microfiber.random_id()` with `dbase32.random_id()`

 * Updates all tests for D-Base32 encoding

 * Drops the `ssl.OP_NO_COMPRESSION` monkey-patch for Python 3.2 (`dbase32` requires Python 3.3 or newer so we can use the modern Unicode API in the C extension)

 * setup.py now enforces Python >= 3.3

 * Updates debian/control to require Python >= 3.3, Build-Depend and Depend on `python3-dbase32`

 * Removes the "microfiber-crashdb.conf" file as we're only supporting Apport 2.5 and newer now, so we can use the modern way of specifying the same inside the source_microfiber.py hook

To post a comment you must log in.
Revision history for this message
xzcvczx (xzcvczx) wrote :

Looking good.

review: Approve

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 2012-11-22 00:02:31 +0000
3+++ debian/control 2013-02-12 09:46:22 +0000
4@@ -3,16 +3,17 @@
5 Priority: optional
6 Maintainer: Jason Gerard DeRose <jderose@novacut.com>
7 Build-Depends: debhelper (>= 9),
8- python3-all (>= 3.2),
9+ python3-all (>= 3.3),
10 python3-sphinx,
11- python3-usercouch (>= 12.11),
12+ python3-dbase32,
13+ python3-usercouch (>= 13.02),
14 Standards-Version: 3.9.3
15-X-Python3-Version: >= 3.2
16+X-Python3-Version: >= 3.3
17 Homepage: https://launchpad.net/microfiber
18
19 Package: python3-microfiber
20 Architecture: all
21-Depends: ${python3:Depends}, ${misc:Depends}
22+Depends: ${python3:Depends}, ${misc:Depends}, python3-dbase32
23 Suggests: python3-usercouch, python3-microfiber-doc
24 Description: fabric for a lightweight Couch
25 Microfiber is an abstract adapter for making HTTP requests to an arbitrary JSON
26
27=== removed file 'debian/microfiber-crashdb.conf'
28--- debian/microfiber-crashdb.conf 2012-09-05 05:19:07 +0000
29+++ debian/microfiber-crashdb.conf 1970-01-01 00:00:00 +0000
30@@ -1,4 +0,0 @@
31-microfiber = {
32- 'impl': 'launchpad',
33- 'project': 'microfiber',
34-}
35
36=== modified file 'debian/python3-microfiber.install'
37--- debian/python3-microfiber.install 2012-09-05 07:51:05 +0000
38+++ debian/python3-microfiber.install 2013-02-12 09:46:22 +0000
39@@ -1,2 +1,1 @@
40-debian/microfiber-crashdb.conf etc/apport/crashdb.conf.d/
41 debian/source_microfiber.py usr/share/apport/package-hooks/
42
43=== modified file 'debian/source_microfiber.py'
44--- debian/source_microfiber.py 2012-09-05 07:51:05 +0000
45+++ debian/source_microfiber.py 2013-02-12 09:46:22 +0000
46@@ -1,9 +1,10 @@
47-'''apport package hook for microfiber.
48+"""
49+Apport package hook for microfiber (requires Apport 2.5 or newer).
50
51 (c) 2012 Novacut Inc
52 Author: Jason Gerard DeRose <jderose@novacut.com>
53-'''
54+"""
55
56 def add_info(report):
57- report['CrashDB'] = 'microfiber'
58+ report['CrashDB'] = "{'impl': 'launchpad', 'project': 'microfiber'}"
59
60
61=== modified file 'microfiber.py'
62--- microfiber.py 2013-01-28 13:38:33 +0000
63+++ microfiber.py 2013-02-12 09:46:22 +0000
64@@ -43,9 +43,8 @@
65 https://launchpad.net/microfiber
66 """
67
68-from os import urandom
69 from io import BufferedReader, TextIOWrapper
70-from base64 import b32encode, b64encode
71+from base64 import b64encode
72 import json
73 from gzip import GzipFile
74 import time
75@@ -60,9 +59,7 @@
76 import platform
77 from collections import namedtuple
78
79-# Monkey patch python3.2 to add ssl.OP_NO_COMPRESSION available in python3.3:
80-if not hasattr(ssl, 'OP_NO_COMPRESSION'):
81- ssl.OP_NO_COMPRESSION = 131072
82+from dbase32 import random_id, RANDOM_BITS, RANDOM_BYTES, RANDOM_B32LEN
83
84
85 __all__ = (
86@@ -95,10 +92,6 @@
87 DC3_CMD = ('/usr/bin/dc3', 'GetEnv')
88 DMEDIA_CMD = ('/usr/bin/dmedia-cli', 'GetEnv')
89
90-RANDOM_BITS = 120
91-RANDOM_BYTES = RANDOM_BITS // 8
92-RANDOM_B32LEN = RANDOM_BITS // 5
93-
94 HTTP_IPv4_URL = 'http://127.0.0.1:5984/'
95 HTTPS_IPv4_URL = 'https://127.0.0.1:6984/'
96 HTTP_IPv6_URL = 'http://[::1]:5984/'
97@@ -213,21 +206,6 @@
98 }
99
100
101-def random_id(numbytes=RANDOM_BYTES):
102- """
103- Returns a 120-bit base32-encoded random ID.
104-
105- The ID will be 24-characters long, URL and filesystem safe. For example:
106-
107- >>> random_id() #doctest: +SKIP
108- 'OVRHK3TUOUQCWIDMNFXGC4TP'
109-
110- This is how dmedia/Novacut random IDs are created, so this is "Jason
111- approved", for what that's worth.
112- """
113- return b32encode(urandom(numbytes)).decode('utf-8')
114-
115-
116 def random_id2():
117 """
118 Returns a random ID with timestamp + 80 bits of base32-encoded random data.
119@@ -238,11 +216,7 @@
120 '1313567384.67DFPERIOU66CT56'
121
122 """
123- return '-'.join([
124- str(int(time.time())),
125- b32encode(urandom(10)).decode('utf-8')
126- ])
127-
128+ return '-'.join([str(int(time.time())), random_id(10)])
129
130
131 def dc3_env():
132@@ -392,7 +366,7 @@
133 def _oauth_header(oauth, method, baseurl, query, testing=None):
134 if testing is None:
135 timestamp = str(int(time.time()))
136- nonce = b32encode(urandom(10)).decode('utf-8')
137+ nonce = random_id()
138 else:
139 (timestamp, nonce) = testing
140 o = {
141
142=== modified file 'setup.py'
143--- setup.py 2013-01-16 09:12:55 +0000
144+++ setup.py 2013-02-12 09:46:22 +0000
145@@ -30,8 +30,8 @@
146 """
147
148 import sys
149-if sys.version_info < (3, 2):
150- sys.exit('Microfiber requires Python 3.2 or newer')
151+if sys.version_info < (3, 3):
152+ sys.exit('Microfiber requires Python 3.3 or newer')
153
154 from distutils.core import setup
155 from distutils.cmd import Command
156
157=== modified file 'test_microfiber.py'
158--- test_microfiber.py 2012-12-20 10:28:47 +0000
159+++ test_microfiber.py 2013-02-12 09:46:22 +0000
160@@ -31,7 +31,7 @@
161 from unittest import TestCase
162 import os
163 from os import path
164-from base64 import b64encode, b64decode, b32encode, b32decode
165+from base64 import b64encode, b64decode
166 from copy import deepcopy
167 import json
168 import gzip
169@@ -45,16 +45,15 @@
170 import ssl
171 import threading
172 from random import SystemRandom
173+
174 from usercouch.misc import TempCouch, TempPKI
175+from dbase32 import db32dec, isdb32, random_id
176
177 import microfiber
178-from microfiber import random_id
179 from microfiber import NotFound, MethodNotAllowed, Conflict, PreconditionFailed
180
181
182 random = SystemRandom()
183-B32ALPHABET = frozenset('234567ABCDEFGHIJKLMNOPQRSTUVWXYZ')
184-
185
186 # OAuth 1.0a test vector from http://oauth.net/core/1.0a/#anchor46
187
188@@ -101,25 +100,21 @@
189
190 def test_id():
191 """
192- So we can tell our random test IDs from the ones microfiber.random_id()
193+ So we can tell our random test IDs from the ones random_id()
194 makes, we use 160-bit IDs instead of 120-bit.
195 """
196- return b32encode(os.urandom(20)).decode('ascii')
197+ return random_id(20)
198
199
200 def is_microfiber_id(_id):
201- assert isinstance(_id, str)
202- return (
203- len(_id) == microfiber.RANDOM_B32LEN
204- and set(_id).issubset(B32ALPHABET)
205- )
206+ return len(_id) == microfiber.RANDOM_B32LEN and isdb32(_id)
207
208-assert is_microfiber_id(microfiber.random_id())
209+assert is_microfiber_id(random_id())
210 assert not is_microfiber_id(test_id())
211
212
213 def random_dbname():
214- return 'db-' + microfiber.random_id().lower()
215+ return 'db-' + random_id().lower()
216
217
218 def random_oauth():
219@@ -147,14 +142,13 @@
220
221
222 class TestFunctions(TestCase):
223-
224 def test_random_id(self):
225 _id = microfiber.random_id()
226 self.assertIsInstance(_id, str)
227 self.assertEqual(len(_id), 24)
228- b = b32decode(_id.encode('ascii'))
229+ b = db32dec(_id)
230 self.assertIsInstance(b, bytes)
231- self.assertEqual(len(b) * 8, 120)
232+ self.assertEqual(len(b), 15)
233
234 def test_random_id2(self):
235 _id = microfiber.random_id2()
236@@ -164,9 +158,9 @@
237 self.assertEqual(len(t), 10)
238 self.assertTrue(int(t) > 1234567890)
239 self.assertEqual(len(r), 16)
240- b = b32decode(r.encode('ascii'))
241+ b = db32dec(r)
242 self.assertIsInstance(b, bytes)
243- self.assertEqual(len(b) * 8, 80)
244+ self.assertEqual(len(b), 10)
245
246 def test_json(self):
247 """
248@@ -1029,7 +1023,7 @@
249 url = '/restful?and=awesome'
250 for (status, klass) in microfiber.errors.items():
251 self.assertTrue(klass.__doc__.startswith('{} '.format(status)))
252- reason = b32encode(os.urandom(10))
253+ reason = random_id(10)
254 data = os.urandom(20)
255 r = FakeResponse(status, reason, data)
256 inst = klass(r, method, url)

Subscribers

People subscribed via source and target branches