Skip to content

Commit

Permalink
Merge pull request #9 from ojuba-org/revert-8-python3
Browse files Browse the repository at this point in the history
Revert "Migrate to Python3"
  • Loading branch information
moceap authored Jan 8, 2017
2 parents 10eecd3 + 84a6cca commit df0e7c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions othman/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import sys, os, os.path, time
import sqlite3
import array
from itertools import imap
import threading
from functools import reduce
import univaruints

data_dir = None
Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self, load_ix=True):

def _getConnection(self):
n = threading.current_thread().name
if n in self._cn:
if self._cn.has_key(n):
r = self._cn[n]
else:
r = sqlite3.connect(self.db_fn)
Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(self, unlink = False, normalize = normalize):

def _getConnection(self):
n = threading.current_thread().name
if n in self._cn:
if self._cn.has_key(n):
r = self._cn[n]
else:
r = sqlite3.connect(self.db_fn)
Expand Down Expand Up @@ -233,7 +233,7 @@ def getPartial(self, w, withWords=False):
r = cn.execute('SELECT w, i FROM ix WHERE w LIKE ?', (W, ))
if not r:
return []
return map(lambda i: f(i), r)
return imap(lambda i: f(i), r)

def find(self, words):
if not words:
Expand Down Expand Up @@ -264,7 +264,7 @@ def addWord(self, word, ayaId):
w = self.normalize(word)
#if not w: print word; return
self.maxWordLen = max(self.maxWordLen,len(w))
if w in self.d:
if self.d.has_key(w):
self.d[w].add(ayaId)
else:
self.d[w] = searchIndexerItem((ayaId,))
Expand Down
6 changes: 3 additions & 3 deletions othman/gtkUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def find(self, txt, backward = False):
if not txt:
self.hide()
return
#if type(txt) == str:
# txt = txt.decode('utf-8')
if type(txt) == str:
txt = txt.decode('utf-8')
if txt == self.last_txt:
# TODO: just move cursor to next/prev result before showing it
pass
Expand Down Expand Up @@ -415,7 +415,7 @@ def main():
ld = os.path.join(exedir,'..', 'share', 'locale')
if not os.path.exists(ld):
ld = os.path.join(exedir, 'locale')
gettext.install('othman', ld)
gettext.install('othman', ld, unicode = 0)
w = othmanUi()
Gtk.main()

Expand Down
28 changes: 14 additions & 14 deletions othman/univaruints.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,22 @@ def incremental_decode(s, unique=1, last=0):
boundary=[(i-1,i,i+1) for i in shifts[1:]]
boundary=list(itertools.chain(*boundary))
boundary.insert(0,0)
print("simple unit tests...")
print "simple unit tests..."
l1=[0,1,100,200,300,500,1000,10000]
for i in l1:
print('before dec:', i, ', hex:', hex(i), ', bin:', bin(i))
print 'before dec:', i, ', hex:', hex(i), ', bin:', bin(i)
e=encode_single(i)
print('after len:',len(e), ', str:', repr(e))
print 'after len:',len(e), ', str:', repr(e)
assert i == decode_single(encode_single(i))[1]
f=StringIO()
write(f, l1)
f.seek(0)
assert l1==list(read(f))
print("boundary unit tests...")
print "boundary unit tests..."
for i in boundary:
print('before dec:', i, ', hex:', hex(i), ', bin:', bin(i))
print 'before dec:', i, ', hex:', hex(i), ', bin:', bin(i)
e=encode_single(i)
print('after len:',len(e), ', str:', repr(e))
print 'after len:',len(e), ', str:', repr(e)
assert i == decode_single(encode_single(i))[1]
assert boundary == list(decode(encode(boundary)))
assert boundary == list(incremental_decode(incremental_encode(boundary, unique=0), unique=0))
Expand All @@ -238,7 +238,7 @@ def incremental_decode(s, unique=1, last=0):
assert boundary == list(read(f, 0, 1, 1))


print("random unit tests...")
print "random unit tests..."
l=[random.randint(0, 5000000) for i in range(1000)]
s=encode(l)
l2=list(decode(s))
Expand All @@ -259,8 +259,8 @@ def incremental_decode(s, unique=1, last=0):
l2=list(incremental_decode(incremental_encode(l, unique=1), unique=1))
assert l2==l

print("pass")
print("performance tests")
print "pass"
print "performance tests"
q=struct.Struct('>Q')
pack=lambda l: ''.join(itertools.imap(lambda i: q.pack(i), l))
def unpack(s):
Expand All @@ -270,7 +270,7 @@ def unpack(s):
for i in range(1000): list(unpack(pack(boundary)))
t2=time.time()
delta_pack=t2-t1
print('struct-based done in ', delta_pack)
print 'struct-based done in ', delta_pack

f=StringIO()
t1=time.time()
Expand All @@ -280,23 +280,23 @@ def unpack(s):
f.seek(0)
list(read(f))
t2=time.time()
print('file-like done in ', t2-t1)
print 'file-like done in ', t2-t1


t1=time.time()
for i in range(1000): list(decode(encode(boundary)))
t2=time.time()
delta_our=t2-t1
print('we are done in ', delta_our)
print 'we are done in ', delta_our
t1=time.time()
for i in range(1000): encode(boundary)
t2=time.time()
delta_our=t2-t1
print('we are done in encoding in ', delta_our)
print 'we are done in encoding in ', delta_our
e=encode(boundary)
t1=time.time()
for i in range(1000): list(decode(e))
t2=time.time()
delta_our=t2-t1
print('we are done in decoding in ', delta_our)
print 'we are done in decoding in ', delta_our

0 comments on commit df0e7c1

Please sign in to comment.