Skip to content

Commit

Permalink
Merge remote-tracking branch 'piannucci/python3'
Browse files Browse the repository at this point in the history
  • Loading branch information
zanellia committed Apr 2, 2020
2 parents dc474f7 + 19fcdf3 commit 96eef3e
Show file tree
Hide file tree
Showing 46 changed files with 825 additions and 1,396 deletions.
8 changes: 4 additions & 4 deletions examples/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def c_int_search(seq,t,chk=1):
#line 33 "binary_search.py"
if (!PyList_Check(py_seq))
py::fail(PyExc_TypeError, "seq must be a list");
if (!PyInt_Check(py_t))
if (!PyLong_Check(py_t))
py::fail(PyExc_TypeError, "t must be an integer");
int val, m, min = 0;
int max = seq.len()- 1;
long val, m, min = 0;
long max = seq.len()- 1;
for(;;)
{
if (max < min )
Expand All @@ -45,7 +45,7 @@ def c_int_search(seq,t,chk=1):
break;
}
m = (min + max) / 2;
val = py_to_int(PyList_GET_ITEM(py_seq,m),"val");
val = PyLong_AsLong(PyList_GET_ITEM(py_seq,m));
if (val < t)
min = m + 1;
else if (val > t)
Expand Down
10 changes: 1 addition & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
import subprocess
import os


# if not sys.version_info[:2] in [(2, 6), (2, 7)]:
# raise RuntimeError("Python version 2.6 or 2.7 required.")


CLASSIFIERS = """\
Development Status :: 4 - Beta
Intended Audience :: Science/Research
Expand Down Expand Up @@ -112,14 +107,11 @@ def write_version_py(filename='weave/version.py'):
"""
FULLVERSION, GIT_REVISION = get_version_info()

a = open(filename, 'w')
try:
with open(filename, 'w') as a:
a.write(cnt % {'version': VERSION,
'full_version' : FULLVERSION,
'git_revision' : GIT_REVISION,
'isrelease': str(ISRELEASED)})
finally:
a.close()


try:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

[tox]
toxworkdir = {homedir}/.tox/weave/
envlist = py26,py27
envlist = py26,py27,py34

[testenv]
deps=
Expand Down
5 changes: 0 additions & 5 deletions weave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@

import sys


# if not sys.version_info[:2] in [(2, 6), (2, 7)]:
# raise RuntimeError("Weave only supports Python 2.6 and 2.7")


from weave.version import version as __version__

from .blitz_tools import blitz, BlitzWarning
Expand Down
64 changes: 33 additions & 31 deletions weave/_dumb_shelve.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@


from shelve import Shelf
import collections
try:
import zlib
except ImportError:
# Some python installations don't have zlib.
pass
zlib = None

import pickle
class ZlibMapping(collections.MutableMapping):
"""Mapping adapter that applies zlib compression.
"""

def __init__(self, dict):
self.dict = dict
if hasattr(dict, 'close'):
self.close = dict.close
if hasattr(dict, 'sync'):
self.sync = dict.sync
if hasattr(dict, 'keys'):
self.keys = dict.keys

class DbfilenameShelf(Shelf):
"""Shelf implementation using the "anydbm" generic dbm interface.
def __iter__(self):
return iter(self.dict)

This is initialized with the filename for the dbm database.
See the module's __doc__ string for an overview of the interface.
"""
def __len__(self):
return len(self.dict)

def __init__(self, filename, flag='c'):
from . import _dumbdbm_patched
Shelf.__init__(self, _dumbdbm_patched.open(filename, flag))
def __contains__(self, key):
return key in self.dict

def __getitem__(self, key):
compressed = self.dict[key]
try:
r = zlib.decompress(compressed)
except zlib.error:
r = compressed
except NameError:
r = compressed

return pickle.loads(r)
return zlib.decompress(self.dict[key])

def __setitem__(self, key, value):
s = pickle.dumps(value,1)
try:
self.dict[key] = zlib.compress(s)
except NameError:
#zlib doesn't exist, leave it uncompressed.
self.dict[key] = s
self.dict[key] = zlib.compress(value)

def __delitem__(self, key):
del self.dict[key]


def open(filename, flag='c'):
"""Open a persistent dictionary for reading and writing.
Argument is the filename for the dbm database.
See the module's __doc__ string for an overview of the interface.
The filename parameter is the base filename for the underlying
database. As a side-effect, an extension may be added to the
filename and more than one file may be created. The optional flag
parameter has the same interpretation as the flag parameter of
dbm.open().
"""
writeback = False

return DbfilenameShelf(filename, flag)
from . import _dumbdbm_patched
d = _dumbdbm_patched.open(filename, flag)
return Shelf(ZlibMapping(d) if zlib is not None else d)
Loading

0 comments on commit 96eef3e

Please sign in to comment.