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
=== modified file 'debian/control'
--- debian/control 2012-11-22 00:02:31 +0000
+++ debian/control 2013-02-12 09:46:22 +0000
@@ -3,16 +3,17 @@
3Priority: optional3Priority: optional
4Maintainer: Jason Gerard DeRose <jderose@novacut.com>4Maintainer: Jason Gerard DeRose <jderose@novacut.com>
5Build-Depends: debhelper (>= 9),5Build-Depends: debhelper (>= 9),
6 python3-all (>= 3.2),6 python3-all (>= 3.3),
7 python3-sphinx,7 python3-sphinx,
8 python3-usercouch (>= 12.11), 8 python3-dbase32,
9 python3-usercouch (>= 13.02),
9Standards-Version: 3.9.310Standards-Version: 3.9.3
10X-Python3-Version: >= 3.211X-Python3-Version: >= 3.3
11Homepage: https://launchpad.net/microfiber12Homepage: https://launchpad.net/microfiber
1213
13Package: python3-microfiber14Package: python3-microfiber
14Architecture: all15Architecture: all
15Depends: ${python3:Depends}, ${misc:Depends}16Depends: ${python3:Depends}, ${misc:Depends}, python3-dbase32
16Suggests: python3-usercouch, python3-microfiber-doc17Suggests: python3-usercouch, python3-microfiber-doc
17Description: fabric for a lightweight Couch18Description: fabric for a lightweight Couch
18 Microfiber is an abstract adapter for making HTTP requests to an arbitrary JSON19 Microfiber is an abstract adapter for making HTTP requests to an arbitrary JSON
1920
=== removed file 'debian/microfiber-crashdb.conf'
--- debian/microfiber-crashdb.conf 2012-09-05 05:19:07 +0000
+++ debian/microfiber-crashdb.conf 1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
1microfiber = {
2 'impl': 'launchpad',
3 'project': 'microfiber',
4}
50
=== modified file 'debian/python3-microfiber.install'
--- debian/python3-microfiber.install 2012-09-05 07:51:05 +0000
+++ debian/python3-microfiber.install 2013-02-12 09:46:22 +0000
@@ -1,2 +1,1 @@
1debian/microfiber-crashdb.conf etc/apport/crashdb.conf.d/
2debian/source_microfiber.py usr/share/apport/package-hooks/1debian/source_microfiber.py usr/share/apport/package-hooks/
32
=== modified file 'debian/source_microfiber.py'
--- debian/source_microfiber.py 2012-09-05 07:51:05 +0000
+++ debian/source_microfiber.py 2013-02-12 09:46:22 +0000
@@ -1,9 +1,10 @@
1'''apport package hook for microfiber.1"""
2Apport package hook for microfiber (requires Apport 2.5 or newer).
23
3(c) 2012 Novacut Inc4(c) 2012 Novacut Inc
4Author: Jason Gerard DeRose <jderose@novacut.com>5Author: Jason Gerard DeRose <jderose@novacut.com>
5'''6"""
67
7def add_info(report):8def add_info(report):
8 report['CrashDB'] = 'microfiber'9 report['CrashDB'] = "{'impl': 'launchpad', 'project': 'microfiber'}"
910
1011
=== modified file 'microfiber.py'
--- microfiber.py 2013-01-28 13:38:33 +0000
+++ microfiber.py 2013-02-12 09:46:22 +0000
@@ -43,9 +43,8 @@
43 https://launchpad.net/microfiber43 https://launchpad.net/microfiber
44"""44"""
4545
46from os import urandom
47from io import BufferedReader, TextIOWrapper46from io import BufferedReader, TextIOWrapper
48from base64 import b32encode, b64encode47from base64 import b64encode
49import json48import json
50from gzip import GzipFile49from gzip import GzipFile
51import time50import time
@@ -60,9 +59,7 @@
60import platform59import platform
61from collections import namedtuple60from collections import namedtuple
6261
63# Monkey patch python3.2 to add ssl.OP_NO_COMPRESSION available in python3.3:62from dbase32 import random_id, RANDOM_BITS, RANDOM_BYTES, RANDOM_B32LEN
64if not hasattr(ssl, 'OP_NO_COMPRESSION'):
65 ssl.OP_NO_COMPRESSION = 131072
6663
6764
68__all__ = (65__all__ = (
@@ -95,10 +92,6 @@
95DC3_CMD = ('/usr/bin/dc3', 'GetEnv')92DC3_CMD = ('/usr/bin/dc3', 'GetEnv')
96DMEDIA_CMD = ('/usr/bin/dmedia-cli', 'GetEnv')93DMEDIA_CMD = ('/usr/bin/dmedia-cli', 'GetEnv')
9794
98RANDOM_BITS = 120
99RANDOM_BYTES = RANDOM_BITS // 8
100RANDOM_B32LEN = RANDOM_BITS // 5
101
102HTTP_IPv4_URL = 'http://127.0.0.1:5984/'95HTTP_IPv4_URL = 'http://127.0.0.1:5984/'
103HTTPS_IPv4_URL = 'https://127.0.0.1:6984/'96HTTPS_IPv4_URL = 'https://127.0.0.1:6984/'
104HTTP_IPv6_URL = 'http://[::1]:5984/'97HTTP_IPv6_URL = 'http://[::1]:5984/'
@@ -213,21 +206,6 @@
213}206}
214207
215208
216def random_id(numbytes=RANDOM_BYTES):
217 """
218 Returns a 120-bit base32-encoded random ID.
219
220 The ID will be 24-characters long, URL and filesystem safe. For example:
221
222 >>> random_id() #doctest: +SKIP
223 'OVRHK3TUOUQCWIDMNFXGC4TP'
224
225 This is how dmedia/Novacut random IDs are created, so this is "Jason
226 approved", for what that's worth.
227 """
228 return b32encode(urandom(numbytes)).decode('utf-8')
229
230
231def random_id2():209def random_id2():
232 """210 """
233 Returns a random ID with timestamp + 80 bits of base32-encoded random data.211 Returns a random ID with timestamp + 80 bits of base32-encoded random data.
@@ -238,11 +216,7 @@
238 '1313567384.67DFPERIOU66CT56'216 '1313567384.67DFPERIOU66CT56'
239217
240 """218 """
241 return '-'.join([219 return '-'.join([str(int(time.time())), random_id(10)])
242 str(int(time.time())),
243 b32encode(urandom(10)).decode('utf-8')
244 ])
245
246220
247221
248def dc3_env():222def dc3_env():
@@ -392,7 +366,7 @@
392def _oauth_header(oauth, method, baseurl, query, testing=None):366def _oauth_header(oauth, method, baseurl, query, testing=None):
393 if testing is None:367 if testing is None:
394 timestamp = str(int(time.time()))368 timestamp = str(int(time.time()))
395 nonce = b32encode(urandom(10)).decode('utf-8')369 nonce = random_id()
396 else:370 else:
397 (timestamp, nonce) = testing371 (timestamp, nonce) = testing
398 o = {372 o = {
399373
=== modified file 'setup.py'
--- setup.py 2013-01-16 09:12:55 +0000
+++ setup.py 2013-02-12 09:46:22 +0000
@@ -30,8 +30,8 @@
30"""30"""
3131
32import sys32import sys
33if sys.version_info < (3, 2):33if sys.version_info < (3, 3):
34 sys.exit('Microfiber requires Python 3.2 or newer')34 sys.exit('Microfiber requires Python 3.3 or newer')
3535
36from distutils.core import setup36from distutils.core import setup
37from distutils.cmd import Command37from distutils.cmd import Command
3838
=== modified file 'test_microfiber.py'
--- test_microfiber.py 2012-12-20 10:28:47 +0000
+++ test_microfiber.py 2013-02-12 09:46:22 +0000
@@ -31,7 +31,7 @@
31from unittest import TestCase31from unittest import TestCase
32import os32import os
33from os import path33from os import path
34from base64 import b64encode, b64decode, b32encode, b32decode34from base64 import b64encode, b64decode
35from copy import deepcopy35from copy import deepcopy
36import json36import json
37import gzip37import gzip
@@ -45,16 +45,15 @@
45import ssl45import ssl
46import threading46import threading
47from random import SystemRandom47from random import SystemRandom
48
48from usercouch.misc import TempCouch, TempPKI49from usercouch.misc import TempCouch, TempPKI
50from dbase32 import db32dec, isdb32, random_id
4951
50import microfiber52import microfiber
51from microfiber import random_id
52from microfiber import NotFound, MethodNotAllowed, Conflict, PreconditionFailed53from microfiber import NotFound, MethodNotAllowed, Conflict, PreconditionFailed
5354
5455
55random = SystemRandom()56random = SystemRandom()
56B32ALPHABET = frozenset('234567ABCDEFGHIJKLMNOPQRSTUVWXYZ')
57
5857
59# OAuth 1.0a test vector from http://oauth.net/core/1.0a/#anchor4658# OAuth 1.0a test vector from http://oauth.net/core/1.0a/#anchor46
6059
@@ -101,25 +100,21 @@
101100
102def test_id():101def test_id():
103 """102 """
104 So we can tell our random test IDs from the ones microfiber.random_id()103 So we can tell our random test IDs from the ones random_id()
105 makes, we use 160-bit IDs instead of 120-bit.104 makes, we use 160-bit IDs instead of 120-bit.
106 """105 """
107 return b32encode(os.urandom(20)).decode('ascii')106 return random_id(20)
108107
109108
110def is_microfiber_id(_id):109def is_microfiber_id(_id):
111 assert isinstance(_id, str)110 return len(_id) == microfiber.RANDOM_B32LEN and isdb32(_id)
112 return (
113 len(_id) == microfiber.RANDOM_B32LEN
114 and set(_id).issubset(B32ALPHABET)
115 )
116111
117assert is_microfiber_id(microfiber.random_id())112assert is_microfiber_id(random_id())
118assert not is_microfiber_id(test_id())113assert not is_microfiber_id(test_id())
119114
120115
121def random_dbname():116def random_dbname():
122 return 'db-' + microfiber.random_id().lower()117 return 'db-' + random_id().lower()
123118
124119
125def random_oauth():120def random_oauth():
@@ -147,14 +142,13 @@
147142
148143
149class TestFunctions(TestCase):144class TestFunctions(TestCase):
150
151 def test_random_id(self):145 def test_random_id(self):
152 _id = microfiber.random_id()146 _id = microfiber.random_id()
153 self.assertIsInstance(_id, str)147 self.assertIsInstance(_id, str)
154 self.assertEqual(len(_id), 24)148 self.assertEqual(len(_id), 24)
155 b = b32decode(_id.encode('ascii'))149 b = db32dec(_id)
156 self.assertIsInstance(b, bytes)150 self.assertIsInstance(b, bytes)
157 self.assertEqual(len(b) * 8, 120)151 self.assertEqual(len(b), 15)
158152
159 def test_random_id2(self):153 def test_random_id2(self):
160 _id = microfiber.random_id2()154 _id = microfiber.random_id2()
@@ -164,9 +158,9 @@
164 self.assertEqual(len(t), 10)158 self.assertEqual(len(t), 10)
165 self.assertTrue(int(t) > 1234567890)159 self.assertTrue(int(t) > 1234567890)
166 self.assertEqual(len(r), 16)160 self.assertEqual(len(r), 16)
167 b = b32decode(r.encode('ascii'))161 b = db32dec(r)
168 self.assertIsInstance(b, bytes)162 self.assertIsInstance(b, bytes)
169 self.assertEqual(len(b) * 8, 80)163 self.assertEqual(len(b), 10)
170164
171 def test_json(self):165 def test_json(self):
172 """166 """
@@ -1029,7 +1023,7 @@
1029 url = '/restful?and=awesome'1023 url = '/restful?and=awesome'
1030 for (status, klass) in microfiber.errors.items():1024 for (status, klass) in microfiber.errors.items():
1031 self.assertTrue(klass.__doc__.startswith('{} '.format(status)))1025 self.assertTrue(klass.__doc__.startswith('{} '.format(status)))
1032 reason = b32encode(os.urandom(10))1026 reason = random_id(10)
1033 data = os.urandom(20)1027 data = os.urandom(20)
1034 r = FakeResponse(status, reason, data)1028 r = FakeResponse(status, reason, data)
1035 inst = klass(r, method, url)1029 inst = klass(r, method, url)

Subscribers

People subscribed via source and target branches